cmdline: replace FreeBSD ifdef for IP address parsing
[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 #ifdef RTE_EXEC_ENV_FREEBSD
15 #include <sys/socket.h>
16 #endif
17 #include <netinet/in.h>
18
19 #include <sys/queue.h>
20
21 #include <rte_common.h>
22 #include <rte_byteorder.h>
23 #include <rte_log.h>
24 #include <rte_debug.h>
25 #include <rte_cycles.h>
26 #include <rte_memory.h>
27 #include <rte_memzone.h>
28 #include <rte_malloc.h>
29 #include <rte_launch.h>
30 #include <rte_eal.h>
31 #include <rte_per_lcore.h>
32 #include <rte_lcore.h>
33 #include <rte_atomic.h>
34 #include <rte_branch_prediction.h>
35 #include <rte_ring.h>
36 #include <rte_mempool.h>
37 #include <rte_interrupts.h>
38 #include <rte_pci.h>
39 #include <rte_ether.h>
40 #include <rte_ethdev.h>
41 #include <rte_string_fns.h>
42 #include <rte_devargs.h>
43 #include <rte_flow.h>
44 #include <rte_gro.h>
45
46 #include <cmdline_rdline.h>
47 #include <cmdline_parse.h>
48 #include <cmdline_parse_num.h>
49 #include <cmdline_parse_string.h>
50 #include <cmdline_parse_ipaddr.h>
51 #include <cmdline_parse_etheraddr.h>
52 #include <cmdline_socket.h>
53 #include <cmdline.h>
54 #ifdef RTE_LIBRTE_PMD_BOND
55 #include <rte_eth_bond.h>
56 #include <rte_eth_bond_8023ad.h>
57 #endif
58 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
59 #include <rte_pmd_dpaa.h>
60 #endif
61 #ifdef RTE_LIBRTE_IXGBE_PMD
62 #include <rte_pmd_ixgbe.h>
63 #endif
64 #ifdef RTE_LIBRTE_I40E_PMD
65 #include <rte_pmd_i40e.h>
66 #endif
67 #ifdef RTE_LIBRTE_BNXT_PMD
68 #include <rte_pmd_bnxt.h>
69 #endif
70 #include "testpmd.h"
71 #include "cmdline_mtr.h"
72 #include "cmdline_tm.h"
73 #include "bpf_cmd.h"
74
75 static struct cmdline *testpmd_cl;
76
77 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
78
79 /* *** Help command with introduction. *** */
80 struct cmd_help_brief_result {
81         cmdline_fixed_string_t help;
82 };
83
84 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
85                                   struct cmdline *cl,
86                                   __attribute__((unused)) void *data)
87 {
88         cmdline_printf(
89                 cl,
90                 "\n"
91                 "Help is available for the following sections:\n\n"
92                 "    help control                    : Start and stop forwarding.\n"
93                 "    help display                    : Displaying port, stats and config "
94                 "information.\n"
95                 "    help config                     : Configuration information.\n"
96                 "    help ports                      : Configuring ports.\n"
97                 "    help registers                  : Reading and setting port registers.\n"
98                 "    help filters                    : Filters configuration help.\n"
99                 "    help traffic_management         : Traffic Management commmands.\n"
100                 "    help devices                    : Device related cmds.\n"
101                 "    help all                        : All of the above sections.\n\n"
102         );
103
104 }
105
106 cmdline_parse_token_string_t cmd_help_brief_help =
107         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
108
109 cmdline_parse_inst_t cmd_help_brief = {
110         .f = cmd_help_brief_parsed,
111         .data = NULL,
112         .help_str = "help: Show help",
113         .tokens = {
114                 (void *)&cmd_help_brief_help,
115                 NULL,
116         },
117 };
118
119 /* *** Help command with help sections. *** */
120 struct cmd_help_long_result {
121         cmdline_fixed_string_t help;
122         cmdline_fixed_string_t section;
123 };
124
125 static void cmd_help_long_parsed(void *parsed_result,
126                                  struct cmdline *cl,
127                                  __attribute__((unused)) void *data)
128 {
129         int show_all = 0;
130         struct cmd_help_long_result *res = parsed_result;
131
132         if (!strcmp(res->section, "all"))
133                 show_all = 1;
134
135         if (show_all || !strcmp(res->section, "control")) {
136
137                 cmdline_printf(
138                         cl,
139                         "\n"
140                         "Control forwarding:\n"
141                         "-------------------\n\n"
142
143                         "start\n"
144                         "    Start packet forwarding with current configuration.\n\n"
145
146                         "start tx_first\n"
147                         "    Start packet forwarding with current config"
148                         " after sending one burst of packets.\n\n"
149
150                         "stop\n"
151                         "    Stop packet forwarding, and display accumulated"
152                         " statistics.\n\n"
153
154                         "quit\n"
155                         "    Quit to prompt.\n\n"
156                 );
157         }
158
159         if (show_all || !strcmp(res->section, "display")) {
160
161                 cmdline_printf(
162                         cl,
163                         "\n"
164                         "Display:\n"
165                         "--------\n\n"
166
167                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
168                         "    Display information for port_id, or all.\n\n"
169
170                         "show port X rss reta (size) (mask0,mask1,...)\n"
171                         "    Display the rss redirection table entry indicated"
172                         " by masks on port X. size is used to indicate the"
173                         " hardware supported reta size\n\n"
174
175                         "show port (port_id) rss-hash [key]\n"
176                         "    Display the RSS hash functions and RSS hash key of port\n\n"
177
178                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
179                         "    Clear information for port_id, or all.\n\n"
180
181                         "show (rxq|txq) info (port_id) (queue_id)\n"
182                         "    Display information for configured RX/TX queue.\n\n"
183
184                         "show config (rxtx|cores|fwd|txpkts)\n"
185                         "    Display the given configuration.\n\n"
186
187                         "read rxd (port_id) (queue_id) (rxd_id)\n"
188                         "    Display an RX descriptor of a port RX queue.\n\n"
189
190                         "read txd (port_id) (queue_id) (txd_id)\n"
191                         "    Display a TX descriptor of a port TX queue.\n\n"
192
193                         "ddp get list (port_id)\n"
194                         "    Get ddp profile info list\n\n"
195
196                         "ddp get info (profile_path)\n"
197                         "    Get ddp profile information.\n\n"
198
199                         "show vf stats (port_id) (vf_id)\n"
200                         "    Display a VF's statistics.\n\n"
201
202                         "clear vf stats (port_id) (vf_id)\n"
203                         "    Reset a VF's statistics.\n\n"
204
205                         "show port (port_id) pctype mapping\n"
206                         "    Get flow ptype to pctype mapping on a port\n\n"
207
208                         "show port meter stats (port_id) (meter_id) (clear)\n"
209                         "    Get meter stats on a port\n\n"
210
211                         "show fwd stats all\n"
212                         "    Display statistics for all fwd engines.\n\n"
213
214                         "clear fwd stats all\n"
215                         "    Clear statistics for all fwd engines.\n\n"
216
217                         "show port (port_id) rx_offload capabilities\n"
218                         "    List all per queue and per port Rx offloading"
219                         " capabilities of a port\n\n"
220
221                         "show port (port_id) rx_offload configuration\n"
222                         "    List port level and all queue level"
223                         " Rx offloading configuration\n\n"
224
225                         "show port (port_id) tx_offload capabilities\n"
226                         "    List all per queue and per port"
227                         " Tx offloading capabilities of a port\n\n"
228
229                         "show port (port_id) tx_offload configuration\n"
230                         "    List port level and all queue level"
231                         " Tx offloading configuration\n\n"
232
233                         "show port (port_id) tx_metadata\n"
234                         "    Show Tx metadata value set"
235                         " for a specific port\n\n"
236
237                         "show port (port_id) ptypes\n"
238                         "    Show port supported ptypes"
239                         " for a specific port\n\n"
240
241                         "show device info (<identifier>|all)"
242                         "       Show general information about devices probed.\n\n"
243                 );
244         }
245
246         if (show_all || !strcmp(res->section, "config")) {
247                 cmdline_printf(
248                         cl,
249                         "\n"
250                         "Configuration:\n"
251                         "--------------\n"
252                         "Configuration changes only become active when"
253                         " forwarding is started/restarted.\n\n"
254
255                         "set default\n"
256                         "    Reset forwarding to the default configuration.\n\n"
257
258                         "set verbose (level)\n"
259                         "    Set the debug verbosity level X.\n\n"
260
261                         "set log global|(type) (level)\n"
262                         "    Set the log level.\n\n"
263
264                         "set nbport (num)\n"
265                         "    Set number of ports.\n\n"
266
267                         "set nbcore (num)\n"
268                         "    Set number of cores.\n\n"
269
270                         "set coremask (mask)\n"
271                         "    Set the forwarding cores hexadecimal mask.\n\n"
272
273                         "set portmask (mask)\n"
274                         "    Set the forwarding ports hexadecimal mask.\n\n"
275
276                         "set burst (num)\n"
277                         "    Set number of packets per burst.\n\n"
278
279                         "set burst tx delay (microseconds) retry (num)\n"
280                         "    Set the transmit delay time and number of retries,"
281                         " effective when retry is enabled.\n\n"
282
283                         "set txpkts (x[,y]*)\n"
284                         "    Set the length of each segment of TXONLY"
285                         " and optionally CSUM packets.\n\n"
286
287                         "set txsplit (off|on|rand)\n"
288                         "    Set the split policy for the TX packets."
289                         " Right now only applicable for CSUM and TXONLY"
290                         " modes\n\n"
291
292                         "set corelist (x[,y]*)\n"
293                         "    Set the list of forwarding cores.\n\n"
294
295                         "set portlist (x[,y]*)\n"
296                         "    Set the list of forwarding ports.\n\n"
297
298                         "set port setup on (iterator|event)\n"
299                         "    Select how attached port is retrieved for setup.\n\n"
300
301                         "set tx loopback (port_id) (on|off)\n"
302                         "    Enable or disable tx loopback.\n\n"
303
304                         "set all queues drop (port_id) (on|off)\n"
305                         "    Set drop enable bit for all queues.\n\n"
306
307                         "set vf split drop (port_id) (vf_id) (on|off)\n"
308                         "    Set split drop enable bit for a VF from the PF.\n\n"
309
310                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
311                         "    Set MAC antispoof for a VF from the PF.\n\n"
312
313                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
314                         "    Enable MACsec offload.\n\n"
315
316                         "set macsec offload (port_id) off\n"
317                         "    Disable MACsec offload.\n\n"
318
319                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
320                         "    Configure MACsec secure connection (SC).\n\n"
321
322                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
323                         "    Configure MACsec secure association (SA).\n\n"
324
325                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
326                         "    Set VF broadcast for a VF from the PF.\n\n"
327
328                         "vlan set stripq (on|off) (port_id,queue_id)\n"
329                         "    Set the VLAN strip for a queue on a port.\n\n"
330
331                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
332                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
333
334                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
335                         "    Set VLAN insert for a VF from the PF.\n\n"
336
337                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
338                         "    Set VLAN antispoof for a VF from the PF.\n\n"
339
340                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
341                         "    Set VLAN tag for a VF from the PF.\n\n"
342
343                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
344                         "    Set a VF's max bandwidth(Mbps).\n\n"
345
346                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
348
349                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
350                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
351
352                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
353                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
354
355                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
356                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
357
358                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
359                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
360
361                         "vlan set (inner|outer) tpid (value) (port_id)\n"
362                         "    Set the VLAN TPID for Packet Filtering on"
363                         " a port\n\n"
364
365                         "rx_vlan add (vlan_id|all) (port_id)\n"
366                         "    Add a vlan_id, or all identifiers, to the set"
367                         " of VLAN identifiers filtered by port_id.\n\n"
368
369                         "rx_vlan rm (vlan_id|all) (port_id)\n"
370                         "    Remove a vlan_id, or all identifiers, from the set"
371                         " of VLAN identifiers filtered by port_id.\n\n"
372
373                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
374                         "    Add a vlan_id, to the set of VLAN identifiers"
375                         "filtered for VF(s) from port_id.\n\n"
376
377                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
378                         "    Remove a vlan_id, to the set of VLAN identifiers"
379                         "filtered for VF(s) from port_id.\n\n"
380
381                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   add a tunnel filter of a port.\n\n"
385
386                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
387                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389                         "   remove a tunnel filter of a port.\n\n"
390
391                         "rx_vxlan_port add (udp_port) (port_id)\n"
392                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
393
394                         "rx_vxlan_port rm (udp_port) (port_id)\n"
395                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
396
397                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
398                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
399                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
400
401                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
402                         "    Set port based TX VLAN insertion.\n\n"
403
404                         "tx_vlan reset (port_id)\n"
405                         "    Disable hardware insertion of a VLAN header in"
406                         " packets sent on a port.\n\n"
407
408                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
409                         "    Select hardware or software calculation of the"
410                         " checksum when transmitting a packet using the"
411                         " csum forward engine.\n"
412                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
413                         "    outer-ip concerns the outer IP layer in"
414                         "    outer-udp concerns the outer UDP layer in"
415                         " case the packet is recognized as a tunnel packet by"
416                         " the forward engine (vxlan, gre and ipip are supported)\n"
417                         "    Please check the NIC datasheet for HW limits.\n\n"
418
419                         "csum parse-tunnel (on|off) (tx_port_id)\n"
420                         "    If disabled, treat tunnel packets as non-tunneled"
421                         " packets (treat inner headers as payload). The port\n"
422                         "    argument is the port used for TX in csum forward"
423                         " engine.\n\n"
424
425                         "csum show (port_id)\n"
426                         "    Display tx checksum offload configuration\n\n"
427
428                         "tso set (segsize) (portid)\n"
429                         "    Enable TCP Segmentation Offload in csum forward"
430                         " engine.\n"
431                         "    Please check the NIC datasheet for HW limits.\n\n"
432
433                         "tso show (portid)"
434                         "    Display the status of TCP Segmentation Offload.\n\n"
435
436                         "set port (port_id) gro on|off\n"
437                         "    Enable or disable Generic Receive Offload in"
438                         " csum forwarding engine.\n\n"
439
440                         "show port (port_id) gro\n"
441                         "    Display GRO configuration.\n\n"
442
443                         "set gro flush (cycles)\n"
444                         "    Set the cycle to flush GROed packets from"
445                         " reassembly tables.\n\n"
446
447                         "set port (port_id) gso (on|off)"
448                         "    Enable or disable Generic Segmentation Offload in"
449                         " csum forwarding engine.\n\n"
450
451                         "set gso segsz (length)\n"
452                         "    Set max packet length for output GSO segments,"
453                         " including packet header and payload.\n\n"
454
455                         "show port (port_id) gso\n"
456                         "    Show GSO configuration.\n\n"
457
458                         "set fwd (%s)\n"
459                         "    Set packet forwarding mode.\n\n"
460
461                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Add a MAC address on port_id.\n\n"
463
464                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Remove a MAC address from port_id.\n\n"
466
467                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Set the default MAC address for port_id.\n\n"
469
470                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
471                         "    Add a MAC address for a VF on the port.\n\n"
472
473                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
474                         "    Set the MAC address for a VF from the PF.\n\n"
475
476                         "set eth-peer (port_id) (peer_addr)\n"
477                         "    set the peer address for certain port.\n\n"
478
479                         "set port (port_id) uta (mac_address|all) (on|off)\n"
480                         "    Add/Remove a or all unicast hash filter(s)"
481                         "from port X.\n\n"
482
483                         "set promisc (port_id|all) (on|off)\n"
484                         "    Set the promiscuous mode on port_id, or all.\n\n"
485
486                         "set allmulti (port_id|all) (on|off)\n"
487                         "    Set the allmulti mode on port_id, or all.\n\n"
488
489                         "set vf promisc (port_id) (vf_id) (on|off)\n"
490                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
491
492                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
493                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
494
495                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
496                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
497                         " (on|off) autoneg (on|off) (port_id)\n"
498                         "set flow_ctrl rx (on|off) (portid)\n"
499                         "set flow_ctrl tx (on|off) (portid)\n"
500                         "set flow_ctrl high_water (high_water) (portid)\n"
501                         "set flow_ctrl low_water (low_water) (portid)\n"
502                         "set flow_ctrl pause_time (pause_time) (portid)\n"
503                         "set flow_ctrl send_xon (send_xon) (portid)\n"
504                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
505                         "set flow_ctrl autoneg (on|off) (port_id)\n"
506                         "    Set the link flow control parameter on a port.\n\n"
507
508                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
509                         " (low_water) (pause_time) (priority) (port_id)\n"
510                         "    Set the priority flow control parameter on a"
511                         " port.\n\n"
512
513                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
514                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
515                         " queue on port.\n"
516                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
517                         " on port 0 to mapping 5.\n\n"
518
519                         "set xstats-hide-zero on|off\n"
520                         "    Set the option to hide the zero values"
521                         " for xstats display.\n"
522
523                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
524                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
525
526                         "set port (port_id) vf (vf_id) (mac_addr)"
527                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
528                         "   Add/Remove unicast or multicast MAC addr filter"
529                         " for a VF.\n\n"
530
531                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
532                         "|MPE) (on|off)\n"
533                         "    AUPE:accepts untagged VLAN;"
534                         "ROPE:accept unicast hash\n\n"
535                         "    BAM:accepts broadcast packets;"
536                         "MPE:accepts all multicast packets\n\n"
537                         "    Enable/Disable a VF receive mode of a port\n\n"
538
539                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
540                         "    Set rate limit for a queue of a port\n\n"
541
542                         "set port (port_id) vf (vf_id) rate (rate_num) "
543                         "queue_mask (queue_mask_value)\n"
544                         "    Set rate limit for queues in VF of a port\n\n"
545
546                         "set port (port_id) mirror-rule (rule_id)"
547                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
548                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
549                         "   Set pool or vlan type mirror rule on a port.\n"
550                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
551                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
552                         " to pool 0.\n\n"
553
554                         "set port (port_id) mirror-rule (rule_id)"
555                         " (uplink-mirror|downlink-mirror) dst-pool"
556                         " (pool_id) (on|off)\n"
557                         "   Set uplink or downlink type mirror rule on a port.\n"
558                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
559                         " 0 on' enable mirror income traffic to pool 0.\n\n"
560
561                         "reset port (port_id) mirror-rule (rule_id)\n"
562                         "   Reset a mirror rule.\n\n"
563
564                         "set flush_rx (on|off)\n"
565                         "   Flush (default) or don't flush RX streams before"
566                         " forwarding. Mainly used with PCAP drivers.\n\n"
567
568                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
569                         "   Set the bypass mode for the lowest port on bypass enabled"
570                         " NIC.\n\n"
571
572                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
573                         "mode (normal|bypass|isolate) (port_id)\n"
574                         "   Set the event required to initiate specified bypass mode for"
575                         " the lowest port on a bypass enabled NIC where:\n"
576                         "       timeout   = enable bypass after watchdog timeout.\n"
577                         "       os_on     = enable bypass when OS/board is powered on.\n"
578                         "       os_off    = enable bypass when OS/board is powered off.\n"
579                         "       power_on  = enable bypass when power supply is turned on.\n"
580                         "       power_off = enable bypass when power supply is turned off."
581                         "\n\n"
582
583                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
584                         "   Set the bypass watchdog timeout to 'n' seconds"
585                         " where 0 = instant.\n\n"
586
587                         "show bypass config (port_id)\n"
588                         "   Show the bypass configuration for a bypass enabled NIC"
589                         " using the lowest port on the NIC.\n\n"
590
591 #ifdef RTE_LIBRTE_PMD_BOND
592                         "create bonded device (mode) (socket)\n"
593                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
594
595                         "add bonding slave (slave_id) (port_id)\n"
596                         "       Add a slave device to a bonded device.\n\n"
597
598                         "remove bonding slave (slave_id) (port_id)\n"
599                         "       Remove a slave device from a bonded device.\n\n"
600
601                         "set bonding mode (value) (port_id)\n"
602                         "       Set the bonding mode on a bonded device.\n\n"
603
604                         "set bonding primary (slave_id) (port_id)\n"
605                         "       Set the primary slave for a bonded device.\n\n"
606
607                         "show bonding config (port_id)\n"
608                         "       Show the bonding config for port_id.\n\n"
609
610                         "set bonding mac_addr (port_id) (address)\n"
611                         "       Set the MAC address of a bonded device.\n\n"
612
613                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
614                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
615
616                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
617                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
618
619                         "set bonding mon_period (port_id) (value)\n"
620                         "       Set the bonding link status monitoring polling period in ms.\n\n"
621
622                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
623                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
624
625 #endif
626                         "set link-up port (port_id)\n"
627                         "       Set link up for a port.\n\n"
628
629                         "set link-down port (port_id)\n"
630                         "       Set link down for a port.\n\n"
631
632                         "E-tag set insertion on port-tag-id (value)"
633                         " port (port_id) vf (vf_id)\n"
634                         "    Enable E-tag insertion for a VF on a port\n\n"
635
636                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
637                         "    Disable E-tag insertion for a VF on a port\n\n"
638
639                         "E-tag set stripping (on|off) port (port_id)\n"
640                         "    Enable/disable E-tag stripping on a port\n\n"
641
642                         "E-tag set forwarding (on|off) port (port_id)\n"
643                         "    Enable/disable E-tag based forwarding"
644                         " on a port\n\n"
645
646                         "E-tag set filter add e-tag-id (value) dst-pool"
647                         " (pool_id) port (port_id)\n"
648                         "    Add an E-tag forwarding filter on a port\n\n"
649
650                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
651                         "    Delete an E-tag forwarding filter on a port\n\n"
652
653                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
654                         "    Load a profile package on a port\n\n"
655
656                         "ddp del (port_id) (backup_profile_path)\n"
657                         "    Delete a profile package from a port\n\n"
658
659                         "ptype mapping get (port_id) (valid_only)\n"
660                         "    Get ptype mapping on a port\n\n"
661
662                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
663                         "    Replace target with the pkt_type in ptype mapping\n\n"
664
665                         "ptype mapping reset (port_id)\n"
666                         "    Reset ptype mapping on a port\n\n"
667
668                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
669                         "    Update a ptype mapping item on a port\n\n"
670
671                         "set port (port_id) queue-region region_id (value) "
672                         "queue_start_index (value) queue_num (value)\n"
673                         "    Set a queue region on a port\n\n"
674
675                         "set port (port_id) queue-region region_id (value) "
676                         "flowtype (value)\n"
677                         "    Set a flowtype region index on a port\n\n"
678
679                         "set port (port_id) queue-region UP (value) region_id (value)\n"
680                         "    Set the mapping of User Priority to "
681                         "queue region on a port\n\n"
682
683                         "set port (port_id) queue-region flush (on|off)\n"
684                         "    flush all queue region related configuration\n\n"
685
686                         "show port meter cap (port_id)\n"
687                         "    Show port meter capability information\n\n"
688
689                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
690                         "    meter profile add - srtcm rfc 2697\n\n"
691
692                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
693                         "    meter profile add - trtcm rfc 2698\n\n"
694
695                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
696                         "    meter profile add - trtcm rfc 4115\n\n"
697
698                         "del port meter profile (port_id) (profile_id)\n"
699                         "    meter profile delete\n\n"
700
701                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
702                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
703                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
704                         "(dscp_tbl_entry63)]\n"
705                         "    meter create\n\n"
706
707                         "enable port meter (port_id) (mtr_id)\n"
708                         "    meter enable\n\n"
709
710                         "disable port meter (port_id) (mtr_id)\n"
711                         "    meter disable\n\n"
712
713                         "del port meter (port_id) (mtr_id)\n"
714                         "    meter delete\n\n"
715
716                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
717                         "    meter update meter profile\n\n"
718
719                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
720                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
721                         "    update meter dscp table entries\n\n"
722
723                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
724                         "(action0) [(action1) (action2)]\n"
725                         "    meter update policer action\n\n"
726
727                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
728                         "    meter update stats\n\n"
729
730                         "show port (port_id) queue-region\n"
731                         "    show all queue region related configuration info\n\n"
732
733                         , list_pkt_forwarding_modes()
734                 );
735         }
736
737         if (show_all || !strcmp(res->section, "ports")) {
738
739                 cmdline_printf(
740                         cl,
741                         "\n"
742                         "Port Operations:\n"
743                         "----------------\n\n"
744
745                         "port start (port_id|all)\n"
746                         "    Start all ports or port_id.\n\n"
747
748                         "port stop (port_id|all)\n"
749                         "    Stop all ports or port_id.\n\n"
750
751                         "port close (port_id|all)\n"
752                         "    Close all ports or port_id.\n\n"
753
754                         "port reset (port_id|all)\n"
755                         "    Reset all ports or port_id.\n\n"
756
757                         "port attach (ident)\n"
758                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
759
760                         "port detach (port_id)\n"
761                         "    Detach physical or virtual dev by port_id\n\n"
762
763                         "port config (port_id|all)"
764                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
765                         " duplex (half|full|auto)\n"
766                         "    Set speed and duplex for all ports or port_id\n\n"
767
768                         "port config (port_id|all) loopback (mode)\n"
769                         "    Set loopback mode for all ports or port_id\n\n"
770
771                         "port config all (rxq|txq|rxd|txd) (value)\n"
772                         "    Set number for rxq/txq/rxd/txd.\n\n"
773
774                         "port config all max-pkt-len (value)\n"
775                         "    Set the max packet length.\n\n"
776
777                         "port config all drop-en (on|off)\n"
778                         "    Enable or disable packet drop on all RX queues of all ports when no "
779                         "receive buffers available.\n\n"
780
781                         "port config all rss (all|default|ip|tcp|udp|sctp|"
782                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
783                         "    Set the RSS mode.\n\n"
784
785                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
786                         "    Set the RSS redirection table.\n\n"
787
788                         "port config (port_id) dcb vt (on|off) (traffic_class)"
789                         " pfc (on|off)\n"
790                         "    Set the DCB mode.\n\n"
791
792                         "port config all burst (value)\n"
793                         "    Set the number of packets per burst.\n\n"
794
795                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
796                         " (value)\n"
797                         "    Set the ring prefetch/host/writeback threshold"
798                         " for tx/rx queue.\n\n"
799
800                         "port config all (txfreet|txrst|rxfreet) (value)\n"
801                         "    Set free threshold for rx/tx, or set"
802                         " tx rs bit threshold.\n\n"
803                         "port config mtu X value\n"
804                         "    Set the MTU of port X to a given value\n\n"
805
806                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
807                         "    Set a rx/tx queue's ring size configuration, the new"
808                         " value will take effect after command that (re-)start the port"
809                         " or command that setup the specific queue\n\n"
810
811                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
812                         "    Start/stop a rx/tx queue of port X. Only take effect"
813                         " when port X is started\n\n"
814
815                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
816                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
817                         " take effect when port X is stopped.\n\n"
818
819                         "port (port_id) (rxq|txq) (queue_id) setup\n"
820                         "    Setup a rx/tx queue of port X.\n\n"
821
822                         "port config (port_id|all) l2-tunnel E-tag ether-type"
823                         " (value)\n"
824                         "    Set the value of E-tag ether-type.\n\n"
825
826                         "port config (port_id|all) l2-tunnel E-tag"
827                         " (enable|disable)\n"
828                         "    Enable/disable the E-tag support.\n\n"
829
830                         "port config (port_id) pctype mapping reset\n"
831                         "    Reset flow type to pctype mapping on a port\n\n"
832
833                         "port config (port_id) pctype mapping update"
834                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
835                         "    Update a flow type to pctype mapping item on a port\n\n"
836
837                         "port config (port_id) pctype (pctype_id) hash_inset|"
838                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
839                         " (field_idx)\n"
840                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
841
842                         "port config (port_id) pctype (pctype_id) hash_inset|"
843                         "fdir_inset|fdir_flx_inset clear all"
844                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
845
846                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
847                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
848
849                         "port config <port_id> rx_offload vlan_strip|"
850                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
851                         "outer_ipv4_cksum|macsec_strip|header_split|"
852                         "vlan_filter|vlan_extend|jumbo_frame|"
853                         "scatter|timestamp|security|keep_crc on|off\n"
854                         "     Enable or disable a per port Rx offloading"
855                         " on all Rx queues of a port\n\n"
856
857                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
858                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
859                         "outer_ipv4_cksum|macsec_strip|header_split|"
860                         "vlan_filter|vlan_extend|jumbo_frame|"
861                         "scatter|timestamp|security|keep_crc on|off\n"
862                         "    Enable or disable a per queue Rx offloading"
863                         " only on a specific Rx queue\n\n"
864
865                         "port config (port_id) tx_offload vlan_insert|"
866                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
867                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
868                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
869                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
870                         "security|match_metadata on|off\n"
871                         "    Enable or disable a per port Tx offloading"
872                         " on all Tx queues of a port\n\n"
873
874                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
875                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
876                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
877                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
878                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
879                         " on|off\n"
880                         "    Enable or disable a per queue Tx offloading"
881                         " only on a specific Tx queue\n\n"
882
883                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
884                         "    Load an eBPF program as a callback"
885                         " for particular RX/TX queue\n\n"
886
887                         "bpf-unload rx|tx (port) (queue)\n"
888                         "    Unload previously loaded eBPF program"
889                         " for particular RX/TX queue\n\n"
890
891                         "port config (port_id) tx_metadata (value)\n"
892                         "    Set Tx metadata value per port. Testpmd will add this value"
893                         " to any Tx packet sent from this port\n\n"
894                 );
895         }
896
897         if (show_all || !strcmp(res->section, "registers")) {
898
899                 cmdline_printf(
900                         cl,
901                         "\n"
902                         "Registers:\n"
903                         "----------\n\n"
904
905                         "read reg (port_id) (address)\n"
906                         "    Display value of a port register.\n\n"
907
908                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
909                         "    Display a port register bit field.\n\n"
910
911                         "read regbit (port_id) (address) (bit_x)\n"
912                         "    Display a single port register bit.\n\n"
913
914                         "write reg (port_id) (address) (value)\n"
915                         "    Set value of a port register.\n\n"
916
917                         "write regfield (port_id) (address) (bit_x) (bit_y)"
918                         " (value)\n"
919                         "    Set bit field of a port register.\n\n"
920
921                         "write regbit (port_id) (address) (bit_x) (value)\n"
922                         "    Set single bit value of a port register.\n\n"
923                 );
924         }
925         if (show_all || !strcmp(res->section, "filters")) {
926
927                 cmdline_printf(
928                         cl,
929                         "\n"
930                         "filters:\n"
931                         "--------\n\n"
932
933                         "ethertype_filter (port_id) (add|del)"
934                         " (mac_addr|mac_ignr) (mac_address) ethertype"
935                         " (ether_type) (drop|fwd) queue (queue_id)\n"
936                         "    Add/Del an ethertype filter.\n\n"
937
938                         "2tuple_filter (port_id) (add|del)"
939                         " dst_port (dst_port_value) protocol (protocol_value)"
940                         " mask (mask_value) tcp_flags (tcp_flags_value)"
941                         " priority (prio_value) queue (queue_id)\n"
942                         "    Add/Del a 2tuple filter.\n\n"
943
944                         "5tuple_filter (port_id) (add|del)"
945                         " dst_ip (dst_address) src_ip (src_address)"
946                         " dst_port (dst_port_value) src_port (src_port_value)"
947                         " protocol (protocol_value)"
948                         " mask (mask_value) tcp_flags (tcp_flags_value)"
949                         " priority (prio_value) queue (queue_id)\n"
950                         "    Add/Del a 5tuple filter.\n\n"
951
952                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
953                         "    Add/Del syn filter.\n\n"
954
955                         "flex_filter (port_id) (add|del) len (len_value)"
956                         " bytes (bytes_value) mask (mask_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a flex filter.\n\n"
959
960                         "flow_director_filter (port_id) mode IP (add|del|update)"
961                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
962                         " src (src_ip_address) dst (dst_ip_address)"
963                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an IP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tos (tos_value) ttl (ttl_value)"
974                         " vlan (vlan_value) flexbytes (flexbytes_value)"
975                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
976                         " fd_id (fd_id_value)\n"
977                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
978
979                         "flow_director_filter (port_id) mode IP (add|del|update)"
980                         " flow (ipv4-sctp|ipv6-sctp)"
981                         " src (src_ip_address) (src_port)"
982                         " dst (dst_ip_address) (dst_port)"
983                         " tag (verification_tag) "
984                         " tos (tos_value) ttl (ttl_value)"
985                         " vlan (vlan_value)"
986                         " flexbytes (flexbytes_value) (drop|fwd)"
987                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
988                         "    Add/Del a SCTP type flow director filter.\n\n"
989
990                         "flow_director_filter (port_id) mode IP (add|del|update)"
991                         " flow l2_payload ether (ethertype)"
992                         " flexbytes (flexbytes_value) (drop|fwd)"
993                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
994                         "    Add/Del a l2 payload type flow director filter.\n\n"
995
996                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
997                         " mac (mac_address) vlan (vlan_value)"
998                         " flexbytes (flexbytes_value) (drop|fwd)"
999                         " queue (queue_id) fd_id (fd_id_value)\n"
1000                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1003                         " mac (mac_address) vlan (vlan_value)"
1004                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1005                         " flexbytes (flexbytes_value) (drop|fwd)"
1006                         " queue (queue_id) fd_id (fd_id_value)\n"
1007                         "    Add/Del a Tunnel flow director filter.\n\n"
1008
1009                         "flow_director_filter (port_id) mode raw (add|del|update)"
1010                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1011                         " fd_id (fd_id_value) packet (packet file name)\n"
1012                         "    Add/Del a raw type flow director filter.\n\n"
1013
1014                         "flush_flow_director (port_id)\n"
1015                         "    Flush all flow director entries of a device.\n\n"
1016
1017                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1018                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1019                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1020                         "    Set flow director IP mask.\n\n"
1021
1022                         "flow_director_mask (port_id) mode MAC-VLAN"
1023                         " vlan (vlan_value)\n"
1024                         "    Set flow director MAC-VLAN mask.\n\n"
1025
1026                         "flow_director_mask (port_id) mode Tunnel"
1027                         " vlan (vlan_value) mac (mac_value)"
1028                         " tunnel-type (tunnel_type_value)"
1029                         " tunnel-id (tunnel_id_value)\n"
1030                         "    Set flow director Tunnel mask.\n\n"
1031
1032                         "flow_director_flex_mask (port_id)"
1033                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1034                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1035                         " (mask)\n"
1036                         "    Configure mask of flex payload.\n\n"
1037
1038                         "flow_director_flex_payload (port_id)"
1039                         " (raw|l2|l3|l4) (config)\n"
1040                         "    Configure flex payload selection.\n\n"
1041
1042                         "get_sym_hash_ena_per_port (port_id)\n"
1043                         "    get symmetric hash enable configuration per port.\n\n"
1044
1045                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1046                         "    set symmetric hash enable configuration per port"
1047                         " to enable or disable.\n\n"
1048
1049                         "get_hash_global_config (port_id)\n"
1050                         "    Get the global configurations of hash filters.\n\n"
1051
1052                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1053                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1054                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1055                         " (enable|disable)\n"
1056                         "    Set the global configurations of hash filters.\n\n"
1057
1058                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1059                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1060                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1061                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1062                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1063                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1064                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1065                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1066                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1067                         "fld-8th|none) (select|add)\n"
1068                         "    Set the input set for hash.\n\n"
1069
1070                         "set_fdir_input_set (port_id) "
1071                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1072                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1073                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1074                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1075                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1076                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1077                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1078                         " (select|add)\n"
1079                         "    Set the input set for FDir.\n\n"
1080
1081                         "flow validate {port_id}"
1082                         " [group {group_id}] [priority {level}]"
1083                         " [ingress] [egress]"
1084                         " pattern {item} [/ {item} [...]] / end"
1085                         " actions {action} [/ {action} [...]] / end\n"
1086                         "    Check whether a flow rule can be created.\n\n"
1087
1088                         "flow create {port_id}"
1089                         " [group {group_id}] [priority {level}]"
1090                         " [ingress] [egress]"
1091                         " pattern {item} [/ {item} [...]] / end"
1092                         " actions {action} [/ {action} [...]] / end\n"
1093                         "    Create a flow rule.\n\n"
1094
1095                         "flow destroy {port_id} rule {rule_id} [...]\n"
1096                         "    Destroy specific flow rules.\n\n"
1097
1098                         "flow flush {port_id}\n"
1099                         "    Destroy all flow rules.\n\n"
1100
1101                         "flow query {port_id} {rule_id} {action}\n"
1102                         "    Query an existing flow rule.\n\n"
1103
1104                         "flow list {port_id} [group {group_id}] [...]\n"
1105                         "    List existing flow rules sorted by priority,"
1106                         " filtered by group identifiers.\n\n"
1107
1108                         "flow isolate {port_id} {boolean}\n"
1109                         "    Restrict ingress traffic to the defined"
1110                         " flow rules\n\n"
1111
1112                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1113                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1114                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1115                         "       Configure the VXLAN encapsulation for flows.\n\n"
1116
1117                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1118                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1119                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1120                         " eth-dst (eth-dst)\n"
1121                         "       Configure the VXLAN encapsulation for flows.\n\n"
1122
1123                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1124                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1125                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1126                         " eth-dst (eth-dst)\n"
1127                         "       Configure the VXLAN encapsulation for flows.\n\n"
1128
1129                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1130                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1131                         " (eth-dst)\n"
1132                         "       Configure the NVGRE encapsulation for flows.\n\n"
1133
1134                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1135                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1136                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1137                         "       Configure the NVGRE encapsulation for flows.\n\n"
1138
1139                         "set raw_encap {flow items}\n"
1140                         "       Configure the encapsulation with raw data.\n\n"
1141
1142                         "set raw_decap {flow items}\n"
1143                         "       Configure the decapsulation with raw data.\n\n"
1144
1145                 );
1146         }
1147
1148         if (show_all || !strcmp(res->section, "traffic_management")) {
1149                 cmdline_printf(
1150                         cl,
1151                         "\n"
1152                         "Traffic Management:\n"
1153                         "--------------\n"
1154                         "show port tm cap (port_id)\n"
1155                         "       Display the port TM capability.\n\n"
1156
1157                         "show port tm level cap (port_id) (level_id)\n"
1158                         "       Display the port TM hierarchical level capability.\n\n"
1159
1160                         "show port tm node cap (port_id) (node_id)\n"
1161                         "       Display the port TM node capability.\n\n"
1162
1163                         "show port tm node type (port_id) (node_id)\n"
1164                         "       Display the port TM node type.\n\n"
1165
1166                         "show port tm node stats (port_id) (node_id) (clear)\n"
1167                         "       Display the port TM node stats.\n\n"
1168
1169 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1170                         "set port tm hierarchy default (port_id)\n"
1171                         "       Set default traffic Management hierarchy on a port\n\n"
1172 #endif
1173
1174                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1175                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1176                         " (packet_length_adjust)\n"
1177                         "       Add port tm node private shaper profile.\n\n"
1178
1179                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1180                         "       Delete port tm node private shaper profile.\n\n"
1181
1182                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1183                         " (shaper_profile_id)\n"
1184                         "       Add/update port tm node shared shaper.\n\n"
1185
1186                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1187                         "       Delete port tm node shared shaper.\n\n"
1188
1189                         "set port tm node shaper profile (port_id) (node_id)"
1190                         " (shaper_profile_id)\n"
1191                         "       Set port tm node shaper profile.\n\n"
1192
1193                         "add port tm node wred profile (port_id) (wred_profile_id)"
1194                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1195                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1196                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1197                         "       Add port tm node wred profile.\n\n"
1198
1199                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1200                         "       Delete port tm node wred profile.\n\n"
1201
1202                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1203                         " (priority) (weight) (level_id) (shaper_profile_id)"
1204                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1205                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1206                         "       Add port tm nonleaf node.\n\n"
1207
1208                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1209                         " (priority) (weight) (level_id) (shaper_profile_id)"
1210                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1211                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1212                         "       Add port tm leaf node.\n\n"
1213
1214                         "del port tm node (port_id) (node_id)\n"
1215                         "       Delete port tm node.\n\n"
1216
1217                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1218                         " (priority) (weight)\n"
1219                         "       Set port tm node parent.\n\n"
1220
1221                         "suspend port tm node (port_id) (node_id)"
1222                         "       Suspend tm node.\n\n"
1223
1224                         "resume port tm node (port_id) (node_id)"
1225                         "       Resume tm node.\n\n"
1226
1227                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1228                         "       Commit tm hierarchy.\n\n"
1229
1230                         "set port tm mark ip_ecn (port) (green) (yellow)"
1231                         " (red)\n"
1232                         "    Enables/Disables the traffic management marking"
1233                         " for IP ECN (Explicit Congestion Notification)"
1234                         " packets on a given port\n\n"
1235
1236                         "set port tm mark ip_dscp (port) (green) (yellow)"
1237                         " (red)\n"
1238                         "    Enables/Disables the traffic management marking"
1239                         " on the port for IP dscp packets\n\n"
1240
1241                         "set port tm mark vlan_dei (port) (green) (yellow)"
1242                         " (red)\n"
1243                         "    Enables/Disables the traffic management marking"
1244                         " on the port for VLAN packets with DEI enabled\n\n"
1245                 );
1246         }
1247
1248         if (show_all || !strcmp(res->section, "devices")) {
1249                 cmdline_printf(
1250                         cl,
1251                         "\n"
1252                         "Device Operations:\n"
1253                         "--------------\n"
1254                         "device detach (identifier)\n"
1255                         "       Detach device by identifier.\n\n"
1256                 );
1257         }
1258
1259 }
1260
1261 cmdline_parse_token_string_t cmd_help_long_help =
1262         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1263
1264 cmdline_parse_token_string_t cmd_help_long_section =
1265         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1266                         "all#control#display#config#"
1267                         "ports#registers#filters#traffic_management#devices");
1268
1269 cmdline_parse_inst_t cmd_help_long = {
1270         .f = cmd_help_long_parsed,
1271         .data = NULL,
1272         .help_str = "help all|control|display|config|ports|register|"
1273                 "filters|traffic_management|devices: "
1274                 "Show help",
1275         .tokens = {
1276                 (void *)&cmd_help_long_help,
1277                 (void *)&cmd_help_long_section,
1278                 NULL,
1279         },
1280 };
1281
1282
1283 /* *** start/stop/close all ports *** */
1284 struct cmd_operate_port_result {
1285         cmdline_fixed_string_t keyword;
1286         cmdline_fixed_string_t name;
1287         cmdline_fixed_string_t value;
1288 };
1289
1290 static void cmd_operate_port_parsed(void *parsed_result,
1291                                 __attribute__((unused)) struct cmdline *cl,
1292                                 __attribute__((unused)) void *data)
1293 {
1294         struct cmd_operate_port_result *res = parsed_result;
1295
1296         if (!strcmp(res->name, "start"))
1297                 start_port(RTE_PORT_ALL);
1298         else if (!strcmp(res->name, "stop"))
1299                 stop_port(RTE_PORT_ALL);
1300         else if (!strcmp(res->name, "close"))
1301                 close_port(RTE_PORT_ALL);
1302         else if (!strcmp(res->name, "reset"))
1303                 reset_port(RTE_PORT_ALL);
1304         else
1305                 printf("Unknown parameter\n");
1306 }
1307
1308 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1309         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1310                                                                 "port");
1311 cmdline_parse_token_string_t cmd_operate_port_all_port =
1312         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1313                                                 "start#stop#close#reset");
1314 cmdline_parse_token_string_t cmd_operate_port_all_all =
1315         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1316
1317 cmdline_parse_inst_t cmd_operate_port = {
1318         .f = cmd_operate_port_parsed,
1319         .data = NULL,
1320         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1321         .tokens = {
1322                 (void *)&cmd_operate_port_all_cmd,
1323                 (void *)&cmd_operate_port_all_port,
1324                 (void *)&cmd_operate_port_all_all,
1325                 NULL,
1326         },
1327 };
1328
1329 /* *** start/stop/close specific port *** */
1330 struct cmd_operate_specific_port_result {
1331         cmdline_fixed_string_t keyword;
1332         cmdline_fixed_string_t name;
1333         uint8_t value;
1334 };
1335
1336 static void cmd_operate_specific_port_parsed(void *parsed_result,
1337                         __attribute__((unused)) struct cmdline *cl,
1338                                 __attribute__((unused)) void *data)
1339 {
1340         struct cmd_operate_specific_port_result *res = parsed_result;
1341
1342         if (!strcmp(res->name, "start"))
1343                 start_port(res->value);
1344         else if (!strcmp(res->name, "stop"))
1345                 stop_port(res->value);
1346         else if (!strcmp(res->name, "close"))
1347                 close_port(res->value);
1348         else if (!strcmp(res->name, "reset"))
1349                 reset_port(res->value);
1350         else
1351                 printf("Unknown parameter\n");
1352 }
1353
1354 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1355         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1356                                                         keyword, "port");
1357 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1358         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1359                                                 name, "start#stop#close#reset");
1360 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1361         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1362                                                         value, UINT8);
1363
1364 cmdline_parse_inst_t cmd_operate_specific_port = {
1365         .f = cmd_operate_specific_port_parsed,
1366         .data = NULL,
1367         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1368         .tokens = {
1369                 (void *)&cmd_operate_specific_port_cmd,
1370                 (void *)&cmd_operate_specific_port_port,
1371                 (void *)&cmd_operate_specific_port_id,
1372                 NULL,
1373         },
1374 };
1375
1376 /* *** enable port setup (after attach) via iterator or event *** */
1377 struct cmd_set_port_setup_on_result {
1378         cmdline_fixed_string_t set;
1379         cmdline_fixed_string_t port;
1380         cmdline_fixed_string_t setup;
1381         cmdline_fixed_string_t on;
1382         cmdline_fixed_string_t mode;
1383 };
1384
1385 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1386                                 __attribute__((unused)) struct cmdline *cl,
1387                                 __attribute__((unused)) void *data)
1388 {
1389         struct cmd_set_port_setup_on_result *res = parsed_result;
1390
1391         if (strcmp(res->mode, "event") == 0)
1392                 setup_on_probe_event = true;
1393         else if (strcmp(res->mode, "iterator") == 0)
1394                 setup_on_probe_event = false;
1395         else
1396                 printf("Unknown mode\n");
1397 }
1398
1399 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1400         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1401                         set, "set");
1402 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1403         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1404                         port, "port");
1405 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1406         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1407                         setup, "setup");
1408 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1409         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1410                         on, "on");
1411 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1412         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1413                         mode, "iterator#event");
1414
1415 cmdline_parse_inst_t cmd_set_port_setup_on = {
1416         .f = cmd_set_port_setup_on_parsed,
1417         .data = NULL,
1418         .help_str = "set port setup on iterator|event",
1419         .tokens = {
1420                 (void *)&cmd_set_port_setup_on_set,
1421                 (void *)&cmd_set_port_setup_on_port,
1422                 (void *)&cmd_set_port_setup_on_setup,
1423                 (void *)&cmd_set_port_setup_on_on,
1424                 (void *)&cmd_set_port_setup_on_mode,
1425                 NULL,
1426         },
1427 };
1428
1429 /* *** attach a specified port *** */
1430 struct cmd_operate_attach_port_result {
1431         cmdline_fixed_string_t port;
1432         cmdline_fixed_string_t keyword;
1433         cmdline_fixed_string_t identifier;
1434 };
1435
1436 static void cmd_operate_attach_port_parsed(void *parsed_result,
1437                                 __attribute__((unused)) struct cmdline *cl,
1438                                 __attribute__((unused)) void *data)
1439 {
1440         struct cmd_operate_attach_port_result *res = parsed_result;
1441
1442         if (!strcmp(res->keyword, "attach"))
1443                 attach_port(res->identifier);
1444         else
1445                 printf("Unknown parameter\n");
1446 }
1447
1448 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1449         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1450                         port, "port");
1451 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1452         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1453                         keyword, "attach");
1454 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1455         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1456                         identifier, NULL);
1457
1458 cmdline_parse_inst_t cmd_operate_attach_port = {
1459         .f = cmd_operate_attach_port_parsed,
1460         .data = NULL,
1461         .help_str = "port attach <identifier>: "
1462                 "(identifier: pci address or virtual dev name)",
1463         .tokens = {
1464                 (void *)&cmd_operate_attach_port_port,
1465                 (void *)&cmd_operate_attach_port_keyword,
1466                 (void *)&cmd_operate_attach_port_identifier,
1467                 NULL,
1468         },
1469 };
1470
1471 /* *** detach a specified port *** */
1472 struct cmd_operate_detach_port_result {
1473         cmdline_fixed_string_t port;
1474         cmdline_fixed_string_t keyword;
1475         portid_t port_id;
1476 };
1477
1478 static void cmd_operate_detach_port_parsed(void *parsed_result,
1479                                 __attribute__((unused)) struct cmdline *cl,
1480                                 __attribute__((unused)) void *data)
1481 {
1482         struct cmd_operate_detach_port_result *res = parsed_result;
1483
1484         if (!strcmp(res->keyword, "detach"))
1485                 detach_port_device(res->port_id);
1486         else
1487                 printf("Unknown parameter\n");
1488 }
1489
1490 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1491         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1492                         port, "port");
1493 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1494         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1495                         keyword, "detach");
1496 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1497         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1498                         port_id, UINT16);
1499
1500 cmdline_parse_inst_t cmd_operate_detach_port = {
1501         .f = cmd_operate_detach_port_parsed,
1502         .data = NULL,
1503         .help_str = "port detach <port_id>",
1504         .tokens = {
1505                 (void *)&cmd_operate_detach_port_port,
1506                 (void *)&cmd_operate_detach_port_keyword,
1507                 (void *)&cmd_operate_detach_port_port_id,
1508                 NULL,
1509         },
1510 };
1511
1512 /* *** detach device by identifier *** */
1513 struct cmd_operate_detach_device_result {
1514         cmdline_fixed_string_t device;
1515         cmdline_fixed_string_t keyword;
1516         cmdline_fixed_string_t identifier;
1517 };
1518
1519 static void cmd_operate_detach_device_parsed(void *parsed_result,
1520                                 __attribute__((unused)) struct cmdline *cl,
1521                                 __attribute__((unused)) void *data)
1522 {
1523         struct cmd_operate_detach_device_result *res = parsed_result;
1524
1525         if (!strcmp(res->keyword, "detach"))
1526                 detach_device(res->identifier);
1527         else
1528                 printf("Unknown parameter\n");
1529 }
1530
1531 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1532         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1533                         device, "device");
1534 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1535         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1536                         keyword, "detach");
1537 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1538         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1539                         identifier, NULL);
1540
1541 cmdline_parse_inst_t cmd_operate_detach_device = {
1542         .f = cmd_operate_detach_device_parsed,
1543         .data = NULL,
1544         .help_str = "device detach <identifier>:"
1545                 "(identifier: pci address or virtual dev name)",
1546         .tokens = {
1547                 (void *)&cmd_operate_detach_device_device,
1548                 (void *)&cmd_operate_detach_device_keyword,
1549                 (void *)&cmd_operate_detach_device_identifier,
1550                 NULL,
1551         },
1552 };
1553 /* *** configure speed for all ports *** */
1554 struct cmd_config_speed_all {
1555         cmdline_fixed_string_t port;
1556         cmdline_fixed_string_t keyword;
1557         cmdline_fixed_string_t all;
1558         cmdline_fixed_string_t item1;
1559         cmdline_fixed_string_t item2;
1560         cmdline_fixed_string_t value1;
1561         cmdline_fixed_string_t value2;
1562 };
1563
1564 static int
1565 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1566 {
1567
1568         int duplex;
1569
1570         if (!strcmp(duplexstr, "half")) {
1571                 duplex = ETH_LINK_HALF_DUPLEX;
1572         } else if (!strcmp(duplexstr, "full")) {
1573                 duplex = ETH_LINK_FULL_DUPLEX;
1574         } else if (!strcmp(duplexstr, "auto")) {
1575                 duplex = ETH_LINK_FULL_DUPLEX;
1576         } else {
1577                 printf("Unknown duplex parameter\n");
1578                 return -1;
1579         }
1580
1581         if (!strcmp(speedstr, "10")) {
1582                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1583                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1584         } else if (!strcmp(speedstr, "100")) {
1585                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1586                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1587         } else {
1588                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1589                         printf("Invalid speed/duplex parameters\n");
1590                         return -1;
1591                 }
1592                 if (!strcmp(speedstr, "1000")) {
1593                         *speed = ETH_LINK_SPEED_1G;
1594                 } else if (!strcmp(speedstr, "10000")) {
1595                         *speed = ETH_LINK_SPEED_10G;
1596                 } else if (!strcmp(speedstr, "25000")) {
1597                         *speed = ETH_LINK_SPEED_25G;
1598                 } else if (!strcmp(speedstr, "40000")) {
1599                         *speed = ETH_LINK_SPEED_40G;
1600                 } else if (!strcmp(speedstr, "50000")) {
1601                         *speed = ETH_LINK_SPEED_50G;
1602                 } else if (!strcmp(speedstr, "100000")) {
1603                         *speed = ETH_LINK_SPEED_100G;
1604                 } else if (!strcmp(speedstr, "auto")) {
1605                         *speed = ETH_LINK_SPEED_AUTONEG;
1606                 } else {
1607                         printf("Unknown speed parameter\n");
1608                         return -1;
1609                 }
1610         }
1611
1612         return 0;
1613 }
1614
1615 static void
1616 cmd_config_speed_all_parsed(void *parsed_result,
1617                         __attribute__((unused)) struct cmdline *cl,
1618                         __attribute__((unused)) void *data)
1619 {
1620         struct cmd_config_speed_all *res = parsed_result;
1621         uint32_t link_speed;
1622         portid_t pid;
1623
1624         if (!all_ports_stopped()) {
1625                 printf("Please stop all ports first\n");
1626                 return;
1627         }
1628
1629         if (parse_and_check_speed_duplex(res->value1, res->value2,
1630                         &link_speed) < 0)
1631                 return;
1632
1633         RTE_ETH_FOREACH_DEV(pid) {
1634                 ports[pid].dev_conf.link_speeds = link_speed;
1635         }
1636
1637         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1638 }
1639
1640 cmdline_parse_token_string_t cmd_config_speed_all_port =
1641         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1642 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1644                                                         "config");
1645 cmdline_parse_token_string_t cmd_config_speed_all_all =
1646         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1647 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1648         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1649 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1651                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1652 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1654 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1655         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1656                                                 "half#full#auto");
1657
1658 cmdline_parse_inst_t cmd_config_speed_all = {
1659         .f = cmd_config_speed_all_parsed,
1660         .data = NULL,
1661         .help_str = "port config all speed "
1662                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1663                                                         "half|full|auto",
1664         .tokens = {
1665                 (void *)&cmd_config_speed_all_port,
1666                 (void *)&cmd_config_speed_all_keyword,
1667                 (void *)&cmd_config_speed_all_all,
1668                 (void *)&cmd_config_speed_all_item1,
1669                 (void *)&cmd_config_speed_all_value1,
1670                 (void *)&cmd_config_speed_all_item2,
1671                 (void *)&cmd_config_speed_all_value2,
1672                 NULL,
1673         },
1674 };
1675
1676 /* *** configure speed for specific port *** */
1677 struct cmd_config_speed_specific {
1678         cmdline_fixed_string_t port;
1679         cmdline_fixed_string_t keyword;
1680         portid_t id;
1681         cmdline_fixed_string_t item1;
1682         cmdline_fixed_string_t item2;
1683         cmdline_fixed_string_t value1;
1684         cmdline_fixed_string_t value2;
1685 };
1686
1687 static void
1688 cmd_config_speed_specific_parsed(void *parsed_result,
1689                                 __attribute__((unused)) struct cmdline *cl,
1690                                 __attribute__((unused)) void *data)
1691 {
1692         struct cmd_config_speed_specific *res = parsed_result;
1693         uint32_t link_speed;
1694
1695         if (!all_ports_stopped()) {
1696                 printf("Please stop all ports first\n");
1697                 return;
1698         }
1699
1700         if (port_id_is_invalid(res->id, ENABLED_WARN))
1701                 return;
1702
1703         if (parse_and_check_speed_duplex(res->value1, res->value2,
1704                         &link_speed) < 0)
1705                 return;
1706
1707         ports[res->id].dev_conf.link_speeds = link_speed;
1708
1709         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1710 }
1711
1712
1713 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1715                                                                 "port");
1716 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1717         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1718                                                                 "config");
1719 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1720         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1721 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1722         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1723                                                                 "speed");
1724 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1726                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1727 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1728         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1729                                                                 "duplex");
1730 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1732                                                         "half#full#auto");
1733
1734 cmdline_parse_inst_t cmd_config_speed_specific = {
1735         .f = cmd_config_speed_specific_parsed,
1736         .data = NULL,
1737         .help_str = "port config <port_id> speed "
1738                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1739                                                         "half|full|auto",
1740         .tokens = {
1741                 (void *)&cmd_config_speed_specific_port,
1742                 (void *)&cmd_config_speed_specific_keyword,
1743                 (void *)&cmd_config_speed_specific_id,
1744                 (void *)&cmd_config_speed_specific_item1,
1745                 (void *)&cmd_config_speed_specific_value1,
1746                 (void *)&cmd_config_speed_specific_item2,
1747                 (void *)&cmd_config_speed_specific_value2,
1748                 NULL,
1749         },
1750 };
1751
1752 /* *** configure loopback for all ports *** */
1753 struct cmd_config_loopback_all {
1754         cmdline_fixed_string_t port;
1755         cmdline_fixed_string_t keyword;
1756         cmdline_fixed_string_t all;
1757         cmdline_fixed_string_t item;
1758         uint32_t mode;
1759 };
1760
1761 static void
1762 cmd_config_loopback_all_parsed(void *parsed_result,
1763                         __attribute__((unused)) struct cmdline *cl,
1764                         __attribute__((unused)) void *data)
1765 {
1766         struct cmd_config_loopback_all *res = parsed_result;
1767         portid_t pid;
1768
1769         if (!all_ports_stopped()) {
1770                 printf("Please stop all ports first\n");
1771                 return;
1772         }
1773
1774         RTE_ETH_FOREACH_DEV(pid) {
1775                 ports[pid].dev_conf.lpbk_mode = res->mode;
1776         }
1777
1778         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1779 }
1780
1781 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1783 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1784         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1785                                                         "config");
1786 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1787         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1788 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1790                                                         "loopback");
1791 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1792         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1793
1794 cmdline_parse_inst_t cmd_config_loopback_all = {
1795         .f = cmd_config_loopback_all_parsed,
1796         .data = NULL,
1797         .help_str = "port config all loopback <mode>",
1798         .tokens = {
1799                 (void *)&cmd_config_loopback_all_port,
1800                 (void *)&cmd_config_loopback_all_keyword,
1801                 (void *)&cmd_config_loopback_all_all,
1802                 (void *)&cmd_config_loopback_all_item,
1803                 (void *)&cmd_config_loopback_all_mode,
1804                 NULL,
1805         },
1806 };
1807
1808 /* *** configure loopback for specific port *** */
1809 struct cmd_config_loopback_specific {
1810         cmdline_fixed_string_t port;
1811         cmdline_fixed_string_t keyword;
1812         uint16_t port_id;
1813         cmdline_fixed_string_t item;
1814         uint32_t mode;
1815 };
1816
1817 static void
1818 cmd_config_loopback_specific_parsed(void *parsed_result,
1819                                 __attribute__((unused)) struct cmdline *cl,
1820                                 __attribute__((unused)) void *data)
1821 {
1822         struct cmd_config_loopback_specific *res = parsed_result;
1823
1824         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1825                 return;
1826
1827         if (!port_is_stopped(res->port_id)) {
1828                 printf("Please stop port %u first\n", res->port_id);
1829                 return;
1830         }
1831
1832         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1833
1834         cmd_reconfig_device_queue(res->port_id, 1, 1);
1835 }
1836
1837
1838 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1839         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1840                                                                 "port");
1841 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1843                                                                 "config");
1844 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1845         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1846                                                                 UINT16);
1847 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1848         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1849                                                                 "loopback");
1850 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1851         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1852                               UINT32);
1853
1854 cmdline_parse_inst_t cmd_config_loopback_specific = {
1855         .f = cmd_config_loopback_specific_parsed,
1856         .data = NULL,
1857         .help_str = "port config <port_id> loopback <mode>",
1858         .tokens = {
1859                 (void *)&cmd_config_loopback_specific_port,
1860                 (void *)&cmd_config_loopback_specific_keyword,
1861                 (void *)&cmd_config_loopback_specific_id,
1862                 (void *)&cmd_config_loopback_specific_item,
1863                 (void *)&cmd_config_loopback_specific_mode,
1864                 NULL,
1865         },
1866 };
1867
1868 /* *** configure txq/rxq, txd/rxd *** */
1869 struct cmd_config_rx_tx {
1870         cmdline_fixed_string_t port;
1871         cmdline_fixed_string_t keyword;
1872         cmdline_fixed_string_t all;
1873         cmdline_fixed_string_t name;
1874         uint16_t value;
1875 };
1876
1877 static void
1878 cmd_config_rx_tx_parsed(void *parsed_result,
1879                         __attribute__((unused)) struct cmdline *cl,
1880                         __attribute__((unused)) void *data)
1881 {
1882         struct cmd_config_rx_tx *res = parsed_result;
1883
1884         if (!all_ports_stopped()) {
1885                 printf("Please stop all ports first\n");
1886                 return;
1887         }
1888         if (!strcmp(res->name, "rxq")) {
1889                 if (!res->value && !nb_txq) {
1890                         printf("Warning: Either rx or tx queues should be non zero\n");
1891                         return;
1892                 }
1893                 if (check_nb_rxq(res->value) != 0)
1894                         return;
1895                 nb_rxq = res->value;
1896         }
1897         else if (!strcmp(res->name, "txq")) {
1898                 if (!res->value && !nb_rxq) {
1899                         printf("Warning: Either rx or tx queues should be non zero\n");
1900                         return;
1901                 }
1902                 if (check_nb_txq(res->value) != 0)
1903                         return;
1904                 nb_txq = res->value;
1905         }
1906         else if (!strcmp(res->name, "rxd")) {
1907                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1908                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1909                                         res->value, RTE_TEST_RX_DESC_MAX);
1910                         return;
1911                 }
1912                 nb_rxd = res->value;
1913         } else if (!strcmp(res->name, "txd")) {
1914                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1915                         printf("txd %d invalid - must be > 0 && <= %d\n",
1916                                         res->value, RTE_TEST_TX_DESC_MAX);
1917                         return;
1918                 }
1919                 nb_txd = res->value;
1920         } else {
1921                 printf("Unknown parameter\n");
1922                 return;
1923         }
1924
1925         fwd_config_setup();
1926
1927         init_port_config();
1928
1929         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1930 }
1931
1932 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1933         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1934 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1936 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1938 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1940                                                 "rxq#txq#rxd#txd");
1941 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1942         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1943
1944 cmdline_parse_inst_t cmd_config_rx_tx = {
1945         .f = cmd_config_rx_tx_parsed,
1946         .data = NULL,
1947         .help_str = "port config all rxq|txq|rxd|txd <value>",
1948         .tokens = {
1949                 (void *)&cmd_config_rx_tx_port,
1950                 (void *)&cmd_config_rx_tx_keyword,
1951                 (void *)&cmd_config_rx_tx_all,
1952                 (void *)&cmd_config_rx_tx_name,
1953                 (void *)&cmd_config_rx_tx_value,
1954                 NULL,
1955         },
1956 };
1957
1958 /* *** config max packet length *** */
1959 struct cmd_config_max_pkt_len_result {
1960         cmdline_fixed_string_t port;
1961         cmdline_fixed_string_t keyword;
1962         cmdline_fixed_string_t all;
1963         cmdline_fixed_string_t name;
1964         uint32_t value;
1965 };
1966
1967 static void
1968 cmd_config_max_pkt_len_parsed(void *parsed_result,
1969                                 __attribute__((unused)) struct cmdline *cl,
1970                                 __attribute__((unused)) void *data)
1971 {
1972         struct cmd_config_max_pkt_len_result *res = parsed_result;
1973         portid_t pid;
1974
1975         if (!all_ports_stopped()) {
1976                 printf("Please stop all ports first\n");
1977                 return;
1978         }
1979
1980         RTE_ETH_FOREACH_DEV(pid) {
1981                 struct rte_port *port = &ports[pid];
1982                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1983
1984                 if (!strcmp(res->name, "max-pkt-len")) {
1985                         if (res->value < RTE_ETHER_MIN_LEN) {
1986                                 printf("max-pkt-len can not be less than %d\n",
1987                                                 RTE_ETHER_MIN_LEN);
1988                                 return;
1989                         }
1990                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1991                                 return;
1992
1993                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1994                         if (res->value > RTE_ETHER_MAX_LEN)
1995                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1996                         else
1997                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1998                         port->dev_conf.rxmode.offloads = rx_offloads;
1999                 } else {
2000                         printf("Unknown parameter\n");
2001                         return;
2002                 }
2003         }
2004
2005         init_port_config();
2006
2007         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2008 }
2009
2010 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2011         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2012                                                                 "port");
2013 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2015                                                                 "config");
2016 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2018                                                                 "all");
2019 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2020         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2021                                                                 "max-pkt-len");
2022 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2023         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2024                                                                 UINT32);
2025
2026 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2027         .f = cmd_config_max_pkt_len_parsed,
2028         .data = NULL,
2029         .help_str = "port config all max-pkt-len <value>",
2030         .tokens = {
2031                 (void *)&cmd_config_max_pkt_len_port,
2032                 (void *)&cmd_config_max_pkt_len_keyword,
2033                 (void *)&cmd_config_max_pkt_len_all,
2034                 (void *)&cmd_config_max_pkt_len_name,
2035                 (void *)&cmd_config_max_pkt_len_value,
2036                 NULL,
2037         },
2038 };
2039
2040 /* *** configure port MTU *** */
2041 struct cmd_config_mtu_result {
2042         cmdline_fixed_string_t port;
2043         cmdline_fixed_string_t keyword;
2044         cmdline_fixed_string_t mtu;
2045         portid_t port_id;
2046         uint16_t value;
2047 };
2048
2049 static void
2050 cmd_config_mtu_parsed(void *parsed_result,
2051                       __attribute__((unused)) struct cmdline *cl,
2052                       __attribute__((unused)) void *data)
2053 {
2054         struct cmd_config_mtu_result *res = parsed_result;
2055
2056         if (res->value < RTE_ETHER_MIN_LEN) {
2057                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2058                 return;
2059         }
2060         port_mtu_set(res->port_id, res->value);
2061 }
2062
2063 cmdline_parse_token_string_t cmd_config_mtu_port =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2065                                  "port");
2066 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2068                                  "config");
2069 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2070         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2071                                  "mtu");
2072 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2073         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2074 cmdline_parse_token_num_t cmd_config_mtu_value =
2075         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2076
2077 cmdline_parse_inst_t cmd_config_mtu = {
2078         .f = cmd_config_mtu_parsed,
2079         .data = NULL,
2080         .help_str = "port config mtu <port_id> <value>",
2081         .tokens = {
2082                 (void *)&cmd_config_mtu_port,
2083                 (void *)&cmd_config_mtu_keyword,
2084                 (void *)&cmd_config_mtu_mtu,
2085                 (void *)&cmd_config_mtu_port_id,
2086                 (void *)&cmd_config_mtu_value,
2087                 NULL,
2088         },
2089 };
2090
2091 /* *** configure rx mode *** */
2092 struct cmd_config_rx_mode_flag {
2093         cmdline_fixed_string_t port;
2094         cmdline_fixed_string_t keyword;
2095         cmdline_fixed_string_t all;
2096         cmdline_fixed_string_t name;
2097         cmdline_fixed_string_t value;
2098 };
2099
2100 static void
2101 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2102                                 __attribute__((unused)) struct cmdline *cl,
2103                                 __attribute__((unused)) void *data)
2104 {
2105         struct cmd_config_rx_mode_flag *res = parsed_result;
2106
2107         if (!all_ports_stopped()) {
2108                 printf("Please stop all ports first\n");
2109                 return;
2110         }
2111
2112         if (!strcmp(res->name, "drop-en")) {
2113                 if (!strcmp(res->value, "on"))
2114                         rx_drop_en = 1;
2115                 else if (!strcmp(res->value, "off"))
2116                         rx_drop_en = 0;
2117                 else {
2118                         printf("Unknown parameter\n");
2119                         return;
2120                 }
2121         } else {
2122                 printf("Unknown parameter\n");
2123                 return;
2124         }
2125
2126         init_port_config();
2127
2128         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2129 }
2130
2131 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2133 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2134         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2135                                                                 "config");
2136 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2137         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2138 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2139         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2140                                         "drop-en");
2141 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2142         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2143                                                         "on#off");
2144
2145 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2146         .f = cmd_config_rx_mode_flag_parsed,
2147         .data = NULL,
2148         .help_str = "port config all drop-en on|off",
2149         .tokens = {
2150                 (void *)&cmd_config_rx_mode_flag_port,
2151                 (void *)&cmd_config_rx_mode_flag_keyword,
2152                 (void *)&cmd_config_rx_mode_flag_all,
2153                 (void *)&cmd_config_rx_mode_flag_name,
2154                 (void *)&cmd_config_rx_mode_flag_value,
2155                 NULL,
2156         },
2157 };
2158
2159 /* *** configure rss *** */
2160 struct cmd_config_rss {
2161         cmdline_fixed_string_t port;
2162         cmdline_fixed_string_t keyword;
2163         cmdline_fixed_string_t all;
2164         cmdline_fixed_string_t name;
2165         cmdline_fixed_string_t value;
2166 };
2167
2168 static void
2169 cmd_config_rss_parsed(void *parsed_result,
2170                         __attribute__((unused)) struct cmdline *cl,
2171                         __attribute__((unused)) void *data)
2172 {
2173         struct cmd_config_rss *res = parsed_result;
2174         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2175         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2176         int use_default = 0;
2177         int all_updated = 1;
2178         int diag;
2179         uint16_t i;
2180         int ret;
2181
2182         if (!strcmp(res->value, "all"))
2183                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2184                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2185                                         ETH_RSS_L2_PAYLOAD;
2186         else if (!strcmp(res->value, "ip"))
2187                 rss_conf.rss_hf = ETH_RSS_IP;
2188         else if (!strcmp(res->value, "udp"))
2189                 rss_conf.rss_hf = ETH_RSS_UDP;
2190         else if (!strcmp(res->value, "tcp"))
2191                 rss_conf.rss_hf = ETH_RSS_TCP;
2192         else if (!strcmp(res->value, "sctp"))
2193                 rss_conf.rss_hf = ETH_RSS_SCTP;
2194         else if (!strcmp(res->value, "ether"))
2195                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2196         else if (!strcmp(res->value, "port"))
2197                 rss_conf.rss_hf = ETH_RSS_PORT;
2198         else if (!strcmp(res->value, "vxlan"))
2199                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2200         else if (!strcmp(res->value, "geneve"))
2201                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2202         else if (!strcmp(res->value, "nvgre"))
2203                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2204         else if (!strcmp(res->value, "l3-src-only"))
2205                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2206         else if (!strcmp(res->value, "l3-dst-only"))
2207                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2208         else if (!strcmp(res->value, "l4-src-only"))
2209                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2210         else if (!strcmp(res->value, "l4-dst-only"))
2211                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2212         else if (!strcmp(res->value, "none"))
2213                 rss_conf.rss_hf = 0;
2214         else if (!strcmp(res->value, "default"))
2215                 use_default = 1;
2216         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2217                                                 atoi(res->value) < 64)
2218                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2219         else {
2220                 printf("Unknown parameter\n");
2221                 return;
2222         }
2223         rss_conf.rss_key = NULL;
2224         /* Update global configuration for RSS types. */
2225         RTE_ETH_FOREACH_DEV(i) {
2226                 struct rte_eth_rss_conf local_rss_conf;
2227
2228                 ret = eth_dev_info_get_print_err(i, &dev_info);
2229                 if (ret != 0)
2230                         return;
2231
2232                 if (use_default)
2233                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2234
2235                 local_rss_conf = rss_conf;
2236                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2237                         dev_info.flow_type_rss_offloads;
2238                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2239                         printf("Port %u modified RSS hash function based on hardware support,"
2240                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2241                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2242                 }
2243                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2244                 if (diag < 0) {
2245                         all_updated = 0;
2246                         printf("Configuration of RSS hash at ethernet port %d "
2247                                 "failed with error (%d): %s.\n",
2248                                 i, -diag, strerror(-diag));
2249                 }
2250         }
2251         if (all_updated && !use_default)
2252                 rss_hf = rss_conf.rss_hf;
2253 }
2254
2255 cmdline_parse_token_string_t cmd_config_rss_port =
2256         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2257 cmdline_parse_token_string_t cmd_config_rss_keyword =
2258         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2259 cmdline_parse_token_string_t cmd_config_rss_all =
2260         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2261 cmdline_parse_token_string_t cmd_config_rss_name =
2262         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2263 cmdline_parse_token_string_t cmd_config_rss_value =
2264         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2265
2266 cmdline_parse_inst_t cmd_config_rss = {
2267         .f = cmd_config_rss_parsed,
2268         .data = NULL,
2269         .help_str = "port config all rss "
2270                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2271         .tokens = {
2272                 (void *)&cmd_config_rss_port,
2273                 (void *)&cmd_config_rss_keyword,
2274                 (void *)&cmd_config_rss_all,
2275                 (void *)&cmd_config_rss_name,
2276                 (void *)&cmd_config_rss_value,
2277                 NULL,
2278         },
2279 };
2280
2281 /* *** configure rss hash key *** */
2282 struct cmd_config_rss_hash_key {
2283         cmdline_fixed_string_t port;
2284         cmdline_fixed_string_t config;
2285         portid_t port_id;
2286         cmdline_fixed_string_t rss_hash_key;
2287         cmdline_fixed_string_t rss_type;
2288         cmdline_fixed_string_t key;
2289 };
2290
2291 static uint8_t
2292 hexa_digit_to_value(char hexa_digit)
2293 {
2294         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2295                 return (uint8_t) (hexa_digit - '0');
2296         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2297                 return (uint8_t) ((hexa_digit - 'a') + 10);
2298         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2299                 return (uint8_t) ((hexa_digit - 'A') + 10);
2300         /* Invalid hexa digit */
2301         return 0xFF;
2302 }
2303
2304 static uint8_t
2305 parse_and_check_key_hexa_digit(char *key, int idx)
2306 {
2307         uint8_t hexa_v;
2308
2309         hexa_v = hexa_digit_to_value(key[idx]);
2310         if (hexa_v == 0xFF)
2311                 printf("invalid key: character %c at position %d is not a "
2312                        "valid hexa digit\n", key[idx], idx);
2313         return hexa_v;
2314 }
2315
2316 static void
2317 cmd_config_rss_hash_key_parsed(void *parsed_result,
2318                                __attribute__((unused)) struct cmdline *cl,
2319                                __attribute__((unused)) void *data)
2320 {
2321         struct cmd_config_rss_hash_key *res = parsed_result;
2322         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2323         uint8_t xdgt0;
2324         uint8_t xdgt1;
2325         int i;
2326         struct rte_eth_dev_info dev_info;
2327         uint8_t hash_key_size;
2328         uint32_t key_len;
2329         int ret;
2330
2331         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2332         if (ret != 0)
2333                 return;
2334
2335         if (dev_info.hash_key_size > 0 &&
2336                         dev_info.hash_key_size <= sizeof(hash_key))
2337                 hash_key_size = dev_info.hash_key_size;
2338         else {
2339                 printf("dev_info did not provide a valid hash key size\n");
2340                 return;
2341         }
2342         /* Check the length of the RSS hash key */
2343         key_len = strlen(res->key);
2344         if (key_len != (hash_key_size * 2)) {
2345                 printf("key length: %d invalid - key must be a string of %d"
2346                            " hexa-decimal numbers\n",
2347                            (int) key_len, hash_key_size * 2);
2348                 return;
2349         }
2350         /* Translate RSS hash key into binary representation */
2351         for (i = 0; i < hash_key_size; i++) {
2352                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2353                 if (xdgt0 == 0xFF)
2354                         return;
2355                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2356                 if (xdgt1 == 0xFF)
2357                         return;
2358                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2359         }
2360         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2361                         hash_key_size);
2362 }
2363
2364 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2365         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2366 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2367         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2368                                  "config");
2369 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2370         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2371 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2372         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2373                                  rss_hash_key, "rss-hash-key");
2374 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2375         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2376                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2377                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2378                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2379                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2380                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only");
2381 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2382         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2383
2384 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2385         .f = cmd_config_rss_hash_key_parsed,
2386         .data = NULL,
2387         .help_str = "port config <port_id> rss-hash-key "
2388                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2389                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2390                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2391                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only "
2392                 "<string of hex digits (variable length, NIC dependent)>",
2393         .tokens = {
2394                 (void *)&cmd_config_rss_hash_key_port,
2395                 (void *)&cmd_config_rss_hash_key_config,
2396                 (void *)&cmd_config_rss_hash_key_port_id,
2397                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2398                 (void *)&cmd_config_rss_hash_key_rss_type,
2399                 (void *)&cmd_config_rss_hash_key_value,
2400                 NULL,
2401         },
2402 };
2403
2404 /* *** configure port rxq/txq ring size *** */
2405 struct cmd_config_rxtx_ring_size {
2406         cmdline_fixed_string_t port;
2407         cmdline_fixed_string_t config;
2408         portid_t portid;
2409         cmdline_fixed_string_t rxtxq;
2410         uint16_t qid;
2411         cmdline_fixed_string_t rsize;
2412         uint16_t size;
2413 };
2414
2415 static void
2416 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2417                                  __attribute__((unused)) struct cmdline *cl,
2418                                  __attribute__((unused)) void *data)
2419 {
2420         struct cmd_config_rxtx_ring_size *res = parsed_result;
2421         struct rte_port *port;
2422         uint8_t isrx;
2423
2424         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2425                 return;
2426
2427         if (res->portid == (portid_t)RTE_PORT_ALL) {
2428                 printf("Invalid port id\n");
2429                 return;
2430         }
2431
2432         port = &ports[res->portid];
2433
2434         if (!strcmp(res->rxtxq, "rxq"))
2435                 isrx = 1;
2436         else if (!strcmp(res->rxtxq, "txq"))
2437                 isrx = 0;
2438         else {
2439                 printf("Unknown parameter\n");
2440                 return;
2441         }
2442
2443         if (isrx && rx_queue_id_is_invalid(res->qid))
2444                 return;
2445         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2446                 return;
2447
2448         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2449                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2450                        rx_free_thresh);
2451                 return;
2452         }
2453
2454         if (isrx)
2455                 port->nb_rx_desc[res->qid] = res->size;
2456         else
2457                 port->nb_tx_desc[res->qid] = res->size;
2458
2459         cmd_reconfig_device_queue(res->portid, 0, 1);
2460 }
2461
2462 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2463         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2464                                  port, "port");
2465 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2466         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2467                                  config, "config");
2468 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2469         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2470                                  portid, UINT16);
2471 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2472         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2473                                  rxtxq, "rxq#txq");
2474 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2475         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2476                               qid, UINT16);
2477 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2478         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2479                                  rsize, "ring_size");
2480 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2481         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2482                               size, UINT16);
2483
2484 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2485         .f = cmd_config_rxtx_ring_size_parsed,
2486         .data = NULL,
2487         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2488         .tokens = {
2489                 (void *)&cmd_config_rxtx_ring_size_port,
2490                 (void *)&cmd_config_rxtx_ring_size_config,
2491                 (void *)&cmd_config_rxtx_ring_size_portid,
2492                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2493                 (void *)&cmd_config_rxtx_ring_size_qid,
2494                 (void *)&cmd_config_rxtx_ring_size_rsize,
2495                 (void *)&cmd_config_rxtx_ring_size_size,
2496                 NULL,
2497         },
2498 };
2499
2500 /* *** configure port rxq/txq start/stop *** */
2501 struct cmd_config_rxtx_queue {
2502         cmdline_fixed_string_t port;
2503         portid_t portid;
2504         cmdline_fixed_string_t rxtxq;
2505         uint16_t qid;
2506         cmdline_fixed_string_t opname;
2507 };
2508
2509 static void
2510 cmd_config_rxtx_queue_parsed(void *parsed_result,
2511                         __attribute__((unused)) struct cmdline *cl,
2512                         __attribute__((unused)) void *data)
2513 {
2514         struct cmd_config_rxtx_queue *res = parsed_result;
2515         uint8_t isrx;
2516         uint8_t isstart;
2517         int ret = 0;
2518
2519         if (test_done == 0) {
2520                 printf("Please stop forwarding first\n");
2521                 return;
2522         }
2523
2524         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2525                 return;
2526
2527         if (port_is_started(res->portid) != 1) {
2528                 printf("Please start port %u first\n", res->portid);
2529                 return;
2530         }
2531
2532         if (!strcmp(res->rxtxq, "rxq"))
2533                 isrx = 1;
2534         else if (!strcmp(res->rxtxq, "txq"))
2535                 isrx = 0;
2536         else {
2537                 printf("Unknown parameter\n");
2538                 return;
2539         }
2540
2541         if (isrx && rx_queue_id_is_invalid(res->qid))
2542                 return;
2543         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2544                 return;
2545
2546         if (!strcmp(res->opname, "start"))
2547                 isstart = 1;
2548         else if (!strcmp(res->opname, "stop"))
2549                 isstart = 0;
2550         else {
2551                 printf("Unknown parameter\n");
2552                 return;
2553         }
2554
2555         if (isstart && isrx)
2556                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2557         else if (!isstart && isrx)
2558                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2559         else if (isstart && !isrx)
2560                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2561         else
2562                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2563
2564         if (ret == -ENOTSUP)
2565                 printf("Function not supported in PMD driver\n");
2566 }
2567
2568 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2569         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2570 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2571         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2572 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2573         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2574 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2575         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2576 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2577         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2578                                                 "start#stop");
2579
2580 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2581         .f = cmd_config_rxtx_queue_parsed,
2582         .data = NULL,
2583         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2584         .tokens = {
2585                 (void *)&cmd_config_rxtx_queue_port,
2586                 (void *)&cmd_config_rxtx_queue_portid,
2587                 (void *)&cmd_config_rxtx_queue_rxtxq,
2588                 (void *)&cmd_config_rxtx_queue_qid,
2589                 (void *)&cmd_config_rxtx_queue_opname,
2590                 NULL,
2591         },
2592 };
2593
2594 /* *** configure port rxq/txq deferred start on/off *** */
2595 struct cmd_config_deferred_start_rxtx_queue {
2596         cmdline_fixed_string_t port;
2597         portid_t port_id;
2598         cmdline_fixed_string_t rxtxq;
2599         uint16_t qid;
2600         cmdline_fixed_string_t opname;
2601         cmdline_fixed_string_t state;
2602 };
2603
2604 static void
2605 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2606                         __attribute__((unused)) struct cmdline *cl,
2607                         __attribute__((unused)) void *data)
2608 {
2609         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2610         struct rte_port *port;
2611         uint8_t isrx;
2612         uint8_t ison;
2613         uint8_t needreconfig = 0;
2614
2615         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2616                 return;
2617
2618         if (port_is_started(res->port_id) != 0) {
2619                 printf("Please stop port %u first\n", res->port_id);
2620                 return;
2621         }
2622
2623         port = &ports[res->port_id];
2624
2625         isrx = !strcmp(res->rxtxq, "rxq");
2626
2627         if (isrx && rx_queue_id_is_invalid(res->qid))
2628                 return;
2629         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2630                 return;
2631
2632         ison = !strcmp(res->state, "on");
2633
2634         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2635                 port->rx_conf[res->qid].rx_deferred_start = ison;
2636                 needreconfig = 1;
2637         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2638                 port->tx_conf[res->qid].tx_deferred_start = ison;
2639                 needreconfig = 1;
2640         }
2641
2642         if (needreconfig)
2643                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2644 }
2645
2646 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2647         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2648                                                 port, "port");
2649 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2650         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2651                                                 port_id, UINT16);
2652 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2654                                                 rxtxq, "rxq#txq");
2655 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2656         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2657                                                 qid, UINT16);
2658 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2659         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2660                                                 opname, "deferred_start");
2661 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2662         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2663                                                 state, "on#off");
2664
2665 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2666         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2667         .data = NULL,
2668         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2669         .tokens = {
2670                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2671                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2672                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2673                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2674                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2675                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2676                 NULL,
2677         },
2678 };
2679
2680 /* *** configure port rxq/txq setup *** */
2681 struct cmd_setup_rxtx_queue {
2682         cmdline_fixed_string_t port;
2683         portid_t portid;
2684         cmdline_fixed_string_t rxtxq;
2685         uint16_t qid;
2686         cmdline_fixed_string_t setup;
2687 };
2688
2689 /* Common CLI fields for queue setup */
2690 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2691         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2692 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2693         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2694 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2695         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2696 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2697         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2698 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2699         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2700
2701 static void
2702 cmd_setup_rxtx_queue_parsed(
2703         void *parsed_result,
2704         __attribute__((unused)) struct cmdline *cl,
2705         __attribute__((unused)) void *data)
2706 {
2707         struct cmd_setup_rxtx_queue *res = parsed_result;
2708         struct rte_port *port;
2709         struct rte_mempool *mp;
2710         unsigned int socket_id;
2711         uint8_t isrx = 0;
2712         int ret;
2713
2714         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2715                 return;
2716
2717         if (res->portid == (portid_t)RTE_PORT_ALL) {
2718                 printf("Invalid port id\n");
2719                 return;
2720         }
2721
2722         if (!strcmp(res->rxtxq, "rxq"))
2723                 isrx = 1;
2724         else if (!strcmp(res->rxtxq, "txq"))
2725                 isrx = 0;
2726         else {
2727                 printf("Unknown parameter\n");
2728                 return;
2729         }
2730
2731         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2732                 printf("Invalid rx queue\n");
2733                 return;
2734         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2735                 printf("Invalid tx queue\n");
2736                 return;
2737         }
2738
2739         port = &ports[res->portid];
2740         if (isrx) {
2741                 socket_id = rxring_numa[res->portid];
2742                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2743                         socket_id = port->socket_id;
2744
2745                 mp = mbuf_pool_find(socket_id);
2746                 if (mp == NULL) {
2747                         printf("Failed to setup RX queue: "
2748                                 "No mempool allocation"
2749                                 " on the socket %d\n",
2750                                 rxring_numa[res->portid]);
2751                         return;
2752                 }
2753                 ret = rte_eth_rx_queue_setup(res->portid,
2754                                              res->qid,
2755                                              port->nb_rx_desc[res->qid],
2756                                              socket_id,
2757                                              &port->rx_conf[res->qid],
2758                                              mp);
2759                 if (ret)
2760                         printf("Failed to setup RX queue\n");
2761         } else {
2762                 socket_id = txring_numa[res->portid];
2763                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2764                         socket_id = port->socket_id;
2765
2766                 ret = rte_eth_tx_queue_setup(res->portid,
2767                                              res->qid,
2768                                              port->nb_tx_desc[res->qid],
2769                                              socket_id,
2770                                              &port->tx_conf[res->qid]);
2771                 if (ret)
2772                         printf("Failed to setup TX queue\n");
2773         }
2774 }
2775
2776 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2777         .f = cmd_setup_rxtx_queue_parsed,
2778         .data = NULL,
2779         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2780         .tokens = {
2781                 (void *)&cmd_setup_rxtx_queue_port,
2782                 (void *)&cmd_setup_rxtx_queue_portid,
2783                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2784                 (void *)&cmd_setup_rxtx_queue_qid,
2785                 (void *)&cmd_setup_rxtx_queue_setup,
2786                 NULL,
2787         },
2788 };
2789
2790
2791 /* *** Configure RSS RETA *** */
2792 struct cmd_config_rss_reta {
2793         cmdline_fixed_string_t port;
2794         cmdline_fixed_string_t keyword;
2795         portid_t port_id;
2796         cmdline_fixed_string_t name;
2797         cmdline_fixed_string_t list_name;
2798         cmdline_fixed_string_t list_of_items;
2799 };
2800
2801 static int
2802 parse_reta_config(const char *str,
2803                   struct rte_eth_rss_reta_entry64 *reta_conf,
2804                   uint16_t nb_entries)
2805 {
2806         int i;
2807         unsigned size;
2808         uint16_t hash_index, idx, shift;
2809         uint16_t nb_queue;
2810         char s[256];
2811         const char *p, *p0 = str;
2812         char *end;
2813         enum fieldnames {
2814                 FLD_HASH_INDEX = 0,
2815                 FLD_QUEUE,
2816                 _NUM_FLD
2817         };
2818         unsigned long int_fld[_NUM_FLD];
2819         char *str_fld[_NUM_FLD];
2820
2821         while ((p = strchr(p0,'(')) != NULL) {
2822                 ++p;
2823                 if((p0 = strchr(p,')')) == NULL)
2824                         return -1;
2825
2826                 size = p0 - p;
2827                 if(size >= sizeof(s))
2828                         return -1;
2829
2830                 snprintf(s, sizeof(s), "%.*s", size, p);
2831                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2832                         return -1;
2833                 for (i = 0; i < _NUM_FLD; i++) {
2834                         errno = 0;
2835                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2836                         if (errno != 0 || end == str_fld[i] ||
2837                                         int_fld[i] > 65535)
2838                                 return -1;
2839                 }
2840
2841                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2842                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2843
2844                 if (hash_index >= nb_entries) {
2845                         printf("Invalid RETA hash index=%d\n", hash_index);
2846                         return -1;
2847                 }
2848
2849                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2850                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2851                 reta_conf[idx].mask |= (1ULL << shift);
2852                 reta_conf[idx].reta[shift] = nb_queue;
2853         }
2854
2855         return 0;
2856 }
2857
2858 static void
2859 cmd_set_rss_reta_parsed(void *parsed_result,
2860                         __attribute__((unused)) struct cmdline *cl,
2861                         __attribute__((unused)) void *data)
2862 {
2863         int ret;
2864         struct rte_eth_dev_info dev_info;
2865         struct rte_eth_rss_reta_entry64 reta_conf[8];
2866         struct cmd_config_rss_reta *res = parsed_result;
2867
2868         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2869         if (ret != 0)
2870                 return;
2871
2872         if (dev_info.reta_size == 0) {
2873                 printf("Redirection table size is 0 which is "
2874                                         "invalid for RSS\n");
2875                 return;
2876         } else
2877                 printf("The reta size of port %d is %u\n",
2878                         res->port_id, dev_info.reta_size);
2879         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2880                 printf("Currently do not support more than %u entries of "
2881                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2882                 return;
2883         }
2884
2885         memset(reta_conf, 0, sizeof(reta_conf));
2886         if (!strcmp(res->list_name, "reta")) {
2887                 if (parse_reta_config(res->list_of_items, reta_conf,
2888                                                 dev_info.reta_size)) {
2889                         printf("Invalid RSS Redirection Table "
2890                                         "config entered\n");
2891                         return;
2892                 }
2893                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2894                                 reta_conf, dev_info.reta_size);
2895                 if (ret != 0)
2896                         printf("Bad redirection table parameter, "
2897                                         "return code = %d \n", ret);
2898         }
2899 }
2900
2901 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2903 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2904         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2905 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2906         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2907 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2908         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2909 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2910         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2911 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2912         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2913                                  NULL);
2914 cmdline_parse_inst_t cmd_config_rss_reta = {
2915         .f = cmd_set_rss_reta_parsed,
2916         .data = NULL,
2917         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2918         .tokens = {
2919                 (void *)&cmd_config_rss_reta_port,
2920                 (void *)&cmd_config_rss_reta_keyword,
2921                 (void *)&cmd_config_rss_reta_port_id,
2922                 (void *)&cmd_config_rss_reta_name,
2923                 (void *)&cmd_config_rss_reta_list_name,
2924                 (void *)&cmd_config_rss_reta_list_of_items,
2925                 NULL,
2926         },
2927 };
2928
2929 /* *** SHOW PORT RETA INFO *** */
2930 struct cmd_showport_reta {
2931         cmdline_fixed_string_t show;
2932         cmdline_fixed_string_t port;
2933         portid_t port_id;
2934         cmdline_fixed_string_t rss;
2935         cmdline_fixed_string_t reta;
2936         uint16_t size;
2937         cmdline_fixed_string_t list_of_items;
2938 };
2939
2940 static int
2941 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2942                            uint16_t nb_entries,
2943                            char *str)
2944 {
2945         uint32_t size;
2946         const char *p, *p0 = str;
2947         char s[256];
2948         char *end;
2949         char *str_fld[8];
2950         uint16_t i;
2951         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2952                         RTE_RETA_GROUP_SIZE;
2953         int ret;
2954
2955         p = strchr(p0, '(');
2956         if (p == NULL)
2957                 return -1;
2958         p++;
2959         p0 = strchr(p, ')');
2960         if (p0 == NULL)
2961                 return -1;
2962         size = p0 - p;
2963         if (size >= sizeof(s)) {
2964                 printf("The string size exceeds the internal buffer size\n");
2965                 return -1;
2966         }
2967         snprintf(s, sizeof(s), "%.*s", size, p);
2968         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2969         if (ret <= 0 || ret != num) {
2970                 printf("The bits of masks do not match the number of "
2971                                         "reta entries: %u\n", num);
2972                 return -1;
2973         }
2974         for (i = 0; i < ret; i++)
2975                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2976
2977         return 0;
2978 }
2979
2980 static void
2981 cmd_showport_reta_parsed(void *parsed_result,
2982                          __attribute__((unused)) struct cmdline *cl,
2983                          __attribute__((unused)) void *data)
2984 {
2985         struct cmd_showport_reta *res = parsed_result;
2986         struct rte_eth_rss_reta_entry64 reta_conf[8];
2987         struct rte_eth_dev_info dev_info;
2988         uint16_t max_reta_size;
2989         int ret;
2990
2991         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2992         if (ret != 0)
2993                 return;
2994
2995         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2996         if (res->size == 0 || res->size > max_reta_size) {
2997                 printf("Invalid redirection table size: %u (1-%u)\n",
2998                         res->size, max_reta_size);
2999                 return;
3000         }
3001
3002         memset(reta_conf, 0, sizeof(reta_conf));
3003         if (showport_parse_reta_config(reta_conf, res->size,
3004                                 res->list_of_items) < 0) {
3005                 printf("Invalid string: %s for reta masks\n",
3006                                         res->list_of_items);
3007                 return;
3008         }
3009         port_rss_reta_info(res->port_id, reta_conf, res->size);
3010 }
3011
3012 cmdline_parse_token_string_t cmd_showport_reta_show =
3013         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3014 cmdline_parse_token_string_t cmd_showport_reta_port =
3015         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3016 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3017         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3018 cmdline_parse_token_string_t cmd_showport_reta_rss =
3019         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3020 cmdline_parse_token_string_t cmd_showport_reta_reta =
3021         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3022 cmdline_parse_token_num_t cmd_showport_reta_size =
3023         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3024 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3025         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3026                                         list_of_items, NULL);
3027
3028 cmdline_parse_inst_t cmd_showport_reta = {
3029         .f = cmd_showport_reta_parsed,
3030         .data = NULL,
3031         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3032         .tokens = {
3033                 (void *)&cmd_showport_reta_show,
3034                 (void *)&cmd_showport_reta_port,
3035                 (void *)&cmd_showport_reta_port_id,
3036                 (void *)&cmd_showport_reta_rss,
3037                 (void *)&cmd_showport_reta_reta,
3038                 (void *)&cmd_showport_reta_size,
3039                 (void *)&cmd_showport_reta_list_of_items,
3040                 NULL,
3041         },
3042 };
3043
3044 /* *** Show RSS hash configuration *** */
3045 struct cmd_showport_rss_hash {
3046         cmdline_fixed_string_t show;
3047         cmdline_fixed_string_t port;
3048         portid_t port_id;
3049         cmdline_fixed_string_t rss_hash;
3050         cmdline_fixed_string_t rss_type;
3051         cmdline_fixed_string_t key; /* optional argument */
3052 };
3053
3054 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3055                                 __attribute__((unused)) struct cmdline *cl,
3056                                 void *show_rss_key)
3057 {
3058         struct cmd_showport_rss_hash *res = parsed_result;
3059
3060         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3061 }
3062
3063 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3064         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3065 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3066         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3067 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3068         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3069 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3070         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3071                                  "rss-hash");
3072 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3073         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3074
3075 cmdline_parse_inst_t cmd_showport_rss_hash = {
3076         .f = cmd_showport_rss_hash_parsed,
3077         .data = NULL,
3078         .help_str = "show port <port_id> rss-hash",
3079         .tokens = {
3080                 (void *)&cmd_showport_rss_hash_show,
3081                 (void *)&cmd_showport_rss_hash_port,
3082                 (void *)&cmd_showport_rss_hash_port_id,
3083                 (void *)&cmd_showport_rss_hash_rss_hash,
3084                 NULL,
3085         },
3086 };
3087
3088 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3089         .f = cmd_showport_rss_hash_parsed,
3090         .data = (void *)1,
3091         .help_str = "show port <port_id> rss-hash key",
3092         .tokens = {
3093                 (void *)&cmd_showport_rss_hash_show,
3094                 (void *)&cmd_showport_rss_hash_port,
3095                 (void *)&cmd_showport_rss_hash_port_id,
3096                 (void *)&cmd_showport_rss_hash_rss_hash,
3097                 (void *)&cmd_showport_rss_hash_rss_key,
3098                 NULL,
3099         },
3100 };
3101
3102 /* *** Configure DCB *** */
3103 struct cmd_config_dcb {
3104         cmdline_fixed_string_t port;
3105         cmdline_fixed_string_t config;
3106         portid_t port_id;
3107         cmdline_fixed_string_t dcb;
3108         cmdline_fixed_string_t vt;
3109         cmdline_fixed_string_t vt_en;
3110         uint8_t num_tcs;
3111         cmdline_fixed_string_t pfc;
3112         cmdline_fixed_string_t pfc_en;
3113 };
3114
3115 static void
3116 cmd_config_dcb_parsed(void *parsed_result,
3117                         __attribute__((unused)) struct cmdline *cl,
3118                         __attribute__((unused)) void *data)
3119 {
3120         struct cmd_config_dcb *res = parsed_result;
3121         portid_t port_id = res->port_id;
3122         struct rte_port *port;
3123         uint8_t pfc_en;
3124         int ret;
3125
3126         port = &ports[port_id];
3127         /** Check if the port is not started **/
3128         if (port->port_status != RTE_PORT_STOPPED) {
3129                 printf("Please stop port %d first\n", port_id);
3130                 return;
3131         }
3132
3133         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3134                 printf("The invalid number of traffic class,"
3135                         " only 4 or 8 allowed.\n");
3136                 return;
3137         }
3138
3139         if (nb_fwd_lcores < res->num_tcs) {
3140                 printf("nb_cores shouldn't be less than number of TCs.\n");
3141                 return;
3142         }
3143         if (!strncmp(res->pfc_en, "on", 2))
3144                 pfc_en = 1;
3145         else
3146                 pfc_en = 0;
3147
3148         /* DCB in VT mode */
3149         if (!strncmp(res->vt_en, "on", 2))
3150                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3151                                 (enum rte_eth_nb_tcs)res->num_tcs,
3152                                 pfc_en);
3153         else
3154                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3155                                 (enum rte_eth_nb_tcs)res->num_tcs,
3156                                 pfc_en);
3157
3158
3159         if (ret != 0) {
3160                 printf("Cannot initialize network ports.\n");
3161                 return;
3162         }
3163
3164         cmd_reconfig_device_queue(port_id, 1, 1);
3165 }
3166
3167 cmdline_parse_token_string_t cmd_config_dcb_port =
3168         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3169 cmdline_parse_token_string_t cmd_config_dcb_config =
3170         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3171 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3172         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3173 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3174         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3175 cmdline_parse_token_string_t cmd_config_dcb_vt =
3176         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3177 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3178         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3179 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3180         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3181 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3182         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3183 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3184         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3185
3186 cmdline_parse_inst_t cmd_config_dcb = {
3187         .f = cmd_config_dcb_parsed,
3188         .data = NULL,
3189         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3190         .tokens = {
3191                 (void *)&cmd_config_dcb_port,
3192                 (void *)&cmd_config_dcb_config,
3193                 (void *)&cmd_config_dcb_port_id,
3194                 (void *)&cmd_config_dcb_dcb,
3195                 (void *)&cmd_config_dcb_vt,
3196                 (void *)&cmd_config_dcb_vt_en,
3197                 (void *)&cmd_config_dcb_num_tcs,
3198                 (void *)&cmd_config_dcb_pfc,
3199                 (void *)&cmd_config_dcb_pfc_en,
3200                 NULL,
3201         },
3202 };
3203
3204 /* *** configure number of packets per burst *** */
3205 struct cmd_config_burst {
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         uint16_t value;
3211 };
3212
3213 static void
3214 cmd_config_burst_parsed(void *parsed_result,
3215                         __attribute__((unused)) struct cmdline *cl,
3216                         __attribute__((unused)) void *data)
3217 {
3218         struct cmd_config_burst *res = parsed_result;
3219         struct rte_eth_dev_info dev_info;
3220         uint16_t rec_nb_pkts;
3221         int ret;
3222
3223         if (!all_ports_stopped()) {
3224                 printf("Please stop all ports first\n");
3225                 return;
3226         }
3227
3228         if (!strcmp(res->name, "burst")) {
3229                 if (res->value == 0) {
3230                         /* If user gives a value of zero, query the PMD for
3231                          * its recommended Rx burst size. Testpmd uses a single
3232                          * size for all ports, so assume all ports are the same
3233                          * NIC model and use the values from Port 0.
3234                          */
3235                         ret = eth_dev_info_get_print_err(0, &dev_info);
3236                         if (ret != 0)
3237                                 return;
3238
3239                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3240
3241                         if (rec_nb_pkts == 0) {
3242                                 printf("PMD does not recommend a burst size.\n"
3243                                         "User provided value must be between"
3244                                         " 1 and %d\n", MAX_PKT_BURST);
3245                                 return;
3246                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3247                                 printf("PMD recommended burst size of %d"
3248                                         " exceeds maximum value of %d\n",
3249                                         rec_nb_pkts, MAX_PKT_BURST);
3250                                 return;
3251                         }
3252                         printf("Using PMD-provided burst value of %d\n",
3253                                 rec_nb_pkts);
3254                         nb_pkt_per_burst = rec_nb_pkts;
3255                 } else if (res->value > MAX_PKT_BURST) {
3256                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3257                         return;
3258                 } else
3259                         nb_pkt_per_burst = res->value;
3260         } else {
3261                 printf("Unknown parameter\n");
3262                 return;
3263         }
3264
3265         init_port_config();
3266
3267         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3268 }
3269
3270 cmdline_parse_token_string_t cmd_config_burst_port =
3271         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3272 cmdline_parse_token_string_t cmd_config_burst_keyword =
3273         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3274 cmdline_parse_token_string_t cmd_config_burst_all =
3275         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3276 cmdline_parse_token_string_t cmd_config_burst_name =
3277         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3278 cmdline_parse_token_num_t cmd_config_burst_value =
3279         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3280
3281 cmdline_parse_inst_t cmd_config_burst = {
3282         .f = cmd_config_burst_parsed,
3283         .data = NULL,
3284         .help_str = "port config all burst <value>",
3285         .tokens = {
3286                 (void *)&cmd_config_burst_port,
3287                 (void *)&cmd_config_burst_keyword,
3288                 (void *)&cmd_config_burst_all,
3289                 (void *)&cmd_config_burst_name,
3290                 (void *)&cmd_config_burst_value,
3291                 NULL,
3292         },
3293 };
3294
3295 /* *** configure rx/tx queues *** */
3296 struct cmd_config_thresh {
3297         cmdline_fixed_string_t port;
3298         cmdline_fixed_string_t keyword;
3299         cmdline_fixed_string_t all;
3300         cmdline_fixed_string_t name;
3301         uint8_t value;
3302 };
3303
3304 static void
3305 cmd_config_thresh_parsed(void *parsed_result,
3306                         __attribute__((unused)) struct cmdline *cl,
3307                         __attribute__((unused)) void *data)
3308 {
3309         struct cmd_config_thresh *res = parsed_result;
3310
3311         if (!all_ports_stopped()) {
3312                 printf("Please stop all ports first\n");
3313                 return;
3314         }
3315
3316         if (!strcmp(res->name, "txpt"))
3317                 tx_pthresh = res->value;
3318         else if(!strcmp(res->name, "txht"))
3319                 tx_hthresh = res->value;
3320         else if(!strcmp(res->name, "txwt"))
3321                 tx_wthresh = res->value;
3322         else if(!strcmp(res->name, "rxpt"))
3323                 rx_pthresh = res->value;
3324         else if(!strcmp(res->name, "rxht"))
3325                 rx_hthresh = res->value;
3326         else if(!strcmp(res->name, "rxwt"))
3327                 rx_wthresh = res->value;
3328         else {
3329                 printf("Unknown parameter\n");
3330                 return;
3331         }
3332
3333         init_port_config();
3334
3335         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3336 }
3337
3338 cmdline_parse_token_string_t cmd_config_thresh_port =
3339         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3340 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3341         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3342 cmdline_parse_token_string_t cmd_config_thresh_all =
3343         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3344 cmdline_parse_token_string_t cmd_config_thresh_name =
3345         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3346                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3347 cmdline_parse_token_num_t cmd_config_thresh_value =
3348         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3349
3350 cmdline_parse_inst_t cmd_config_thresh = {
3351         .f = cmd_config_thresh_parsed,
3352         .data = NULL,
3353         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3354         .tokens = {
3355                 (void *)&cmd_config_thresh_port,
3356                 (void *)&cmd_config_thresh_keyword,
3357                 (void *)&cmd_config_thresh_all,
3358                 (void *)&cmd_config_thresh_name,
3359                 (void *)&cmd_config_thresh_value,
3360                 NULL,
3361         },
3362 };
3363
3364 /* *** configure free/rs threshold *** */
3365 struct cmd_config_threshold {
3366         cmdline_fixed_string_t port;
3367         cmdline_fixed_string_t keyword;
3368         cmdline_fixed_string_t all;
3369         cmdline_fixed_string_t name;
3370         uint16_t value;
3371 };
3372
3373 static void
3374 cmd_config_threshold_parsed(void *parsed_result,
3375                         __attribute__((unused)) struct cmdline *cl,
3376                         __attribute__((unused)) void *data)
3377 {
3378         struct cmd_config_threshold *res = parsed_result;
3379
3380         if (!all_ports_stopped()) {
3381                 printf("Please stop all ports first\n");
3382                 return;
3383         }
3384
3385         if (!strcmp(res->name, "txfreet"))
3386                 tx_free_thresh = res->value;
3387         else if (!strcmp(res->name, "txrst"))
3388                 tx_rs_thresh = res->value;
3389         else if (!strcmp(res->name, "rxfreet"))
3390                 rx_free_thresh = res->value;
3391         else {
3392                 printf("Unknown parameter\n");
3393                 return;
3394         }
3395
3396         init_port_config();
3397
3398         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3399 }
3400
3401 cmdline_parse_token_string_t cmd_config_threshold_port =
3402         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3403 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3404         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3405                                                                 "config");
3406 cmdline_parse_token_string_t cmd_config_threshold_all =
3407         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3408 cmdline_parse_token_string_t cmd_config_threshold_name =
3409         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3410                                                 "txfreet#txrst#rxfreet");
3411 cmdline_parse_token_num_t cmd_config_threshold_value =
3412         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3413
3414 cmdline_parse_inst_t cmd_config_threshold = {
3415         .f = cmd_config_threshold_parsed,
3416         .data = NULL,
3417         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3418         .tokens = {
3419                 (void *)&cmd_config_threshold_port,
3420                 (void *)&cmd_config_threshold_keyword,
3421                 (void *)&cmd_config_threshold_all,
3422                 (void *)&cmd_config_threshold_name,
3423                 (void *)&cmd_config_threshold_value,
3424                 NULL,
3425         },
3426 };
3427
3428 /* *** stop *** */
3429 struct cmd_stop_result {
3430         cmdline_fixed_string_t stop;
3431 };
3432
3433 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3434                             __attribute__((unused)) struct cmdline *cl,
3435                             __attribute__((unused)) void *data)
3436 {
3437         stop_packet_forwarding();
3438 }
3439
3440 cmdline_parse_token_string_t cmd_stop_stop =
3441         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3442
3443 cmdline_parse_inst_t cmd_stop = {
3444         .f = cmd_stop_parsed,
3445         .data = NULL,
3446         .help_str = "stop: Stop packet forwarding",
3447         .tokens = {
3448                 (void *)&cmd_stop_stop,
3449                 NULL,
3450         },
3451 };
3452
3453 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3454
3455 unsigned int
3456 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3457                 unsigned int *parsed_items, int check_unique_values)
3458 {
3459         unsigned int nb_item;
3460         unsigned int value;
3461         unsigned int i;
3462         unsigned int j;
3463         int value_ok;
3464         char c;
3465
3466         /*
3467          * First parse all items in the list and store their value.
3468          */
3469         value = 0;
3470         nb_item = 0;
3471         value_ok = 0;
3472         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3473                 c = str[i];
3474                 if ((c >= '0') && (c <= '9')) {
3475                         value = (unsigned int) (value * 10 + (c - '0'));
3476                         value_ok = 1;
3477                         continue;
3478                 }
3479                 if (c != ',') {
3480                         printf("character %c is not a decimal digit\n", c);
3481                         return 0;
3482                 }
3483                 if (! value_ok) {
3484                         printf("No valid value before comma\n");
3485                         return 0;
3486                 }
3487                 if (nb_item < max_items) {
3488                         parsed_items[nb_item] = value;
3489                         value_ok = 0;
3490                         value = 0;
3491                 }
3492                 nb_item++;
3493         }
3494         if (nb_item >= max_items) {
3495                 printf("Number of %s = %u > %u (maximum items)\n",
3496                        item_name, nb_item + 1, max_items);
3497                 return 0;
3498         }
3499         parsed_items[nb_item++] = value;
3500         if (! check_unique_values)
3501                 return nb_item;
3502
3503         /*
3504          * Then, check that all values in the list are differents.
3505          * No optimization here...
3506          */
3507         for (i = 0; i < nb_item; i++) {
3508                 for (j = i + 1; j < nb_item; j++) {
3509                         if (parsed_items[j] == parsed_items[i]) {
3510                                 printf("duplicated %s %u at index %u and %u\n",
3511                                        item_name, parsed_items[i], i, j);
3512                                 return 0;
3513                         }
3514                 }
3515         }
3516         return nb_item;
3517 }
3518
3519 struct cmd_set_list_result {
3520         cmdline_fixed_string_t cmd_keyword;
3521         cmdline_fixed_string_t list_name;
3522         cmdline_fixed_string_t list_of_items;
3523 };
3524
3525 static void cmd_set_list_parsed(void *parsed_result,
3526                                 __attribute__((unused)) struct cmdline *cl,
3527                                 __attribute__((unused)) void *data)
3528 {
3529         struct cmd_set_list_result *res;
3530         union {
3531                 unsigned int lcorelist[RTE_MAX_LCORE];
3532                 unsigned int portlist[RTE_MAX_ETHPORTS];
3533         } parsed_items;
3534         unsigned int nb_item;
3535
3536         if (test_done == 0) {
3537                 printf("Please stop forwarding first\n");
3538                 return;
3539         }
3540
3541         res = parsed_result;
3542         if (!strcmp(res->list_name, "corelist")) {
3543                 nb_item = parse_item_list(res->list_of_items, "core",
3544                                           RTE_MAX_LCORE,
3545                                           parsed_items.lcorelist, 1);
3546                 if (nb_item > 0) {
3547                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3548                         fwd_config_setup();
3549                 }
3550                 return;
3551         }
3552         if (!strcmp(res->list_name, "portlist")) {
3553                 nb_item = parse_item_list(res->list_of_items, "port",
3554                                           RTE_MAX_ETHPORTS,
3555                                           parsed_items.portlist, 1);
3556                 if (nb_item > 0) {
3557                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3558                         fwd_config_setup();
3559                 }
3560         }
3561 }
3562
3563 cmdline_parse_token_string_t cmd_set_list_keyword =
3564         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3565                                  "set");
3566 cmdline_parse_token_string_t cmd_set_list_name =
3567         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3568                                  "corelist#portlist");
3569 cmdline_parse_token_string_t cmd_set_list_of_items =
3570         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3571                                  NULL);
3572
3573 cmdline_parse_inst_t cmd_set_fwd_list = {
3574         .f = cmd_set_list_parsed,
3575         .data = NULL,
3576         .help_str = "set corelist|portlist <list0[,list1]*>",
3577         .tokens = {
3578                 (void *)&cmd_set_list_keyword,
3579                 (void *)&cmd_set_list_name,
3580                 (void *)&cmd_set_list_of_items,
3581                 NULL,
3582         },
3583 };
3584
3585 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3586
3587 struct cmd_setmask_result {
3588         cmdline_fixed_string_t set;
3589         cmdline_fixed_string_t mask;
3590         uint64_t hexavalue;
3591 };
3592
3593 static void cmd_set_mask_parsed(void *parsed_result,
3594                                 __attribute__((unused)) struct cmdline *cl,
3595                                 __attribute__((unused)) void *data)
3596 {
3597         struct cmd_setmask_result *res = parsed_result;
3598
3599         if (test_done == 0) {
3600                 printf("Please stop forwarding first\n");
3601                 return;
3602         }
3603         if (!strcmp(res->mask, "coremask")) {
3604                 set_fwd_lcores_mask(res->hexavalue);
3605                 fwd_config_setup();
3606         } else if (!strcmp(res->mask, "portmask")) {
3607                 set_fwd_ports_mask(res->hexavalue);
3608                 fwd_config_setup();
3609         }
3610 }
3611
3612 cmdline_parse_token_string_t cmd_setmask_set =
3613         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3614 cmdline_parse_token_string_t cmd_setmask_mask =
3615         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3616                                  "coremask#portmask");
3617 cmdline_parse_token_num_t cmd_setmask_value =
3618         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3619
3620 cmdline_parse_inst_t cmd_set_fwd_mask = {
3621         .f = cmd_set_mask_parsed,
3622         .data = NULL,
3623         .help_str = "set coremask|portmask <hexadecimal value>",
3624         .tokens = {
3625                 (void *)&cmd_setmask_set,
3626                 (void *)&cmd_setmask_mask,
3627                 (void *)&cmd_setmask_value,
3628                 NULL,
3629         },
3630 };
3631
3632 /*
3633  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3634  */
3635 struct cmd_set_result {
3636         cmdline_fixed_string_t set;
3637         cmdline_fixed_string_t what;
3638         uint16_t value;
3639 };
3640
3641 static void cmd_set_parsed(void *parsed_result,
3642                            __attribute__((unused)) struct cmdline *cl,
3643                            __attribute__((unused)) void *data)
3644 {
3645         struct cmd_set_result *res = parsed_result;
3646         if (!strcmp(res->what, "nbport")) {
3647                 set_fwd_ports_number(res->value);
3648                 fwd_config_setup();
3649         } else if (!strcmp(res->what, "nbcore")) {
3650                 set_fwd_lcores_number(res->value);
3651                 fwd_config_setup();
3652         } else if (!strcmp(res->what, "burst"))
3653                 set_nb_pkt_per_burst(res->value);
3654         else if (!strcmp(res->what, "verbose"))
3655                 set_verbose_level(res->value);
3656 }
3657
3658 cmdline_parse_token_string_t cmd_set_set =
3659         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3660 cmdline_parse_token_string_t cmd_set_what =
3661         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3662                                  "nbport#nbcore#burst#verbose");
3663 cmdline_parse_token_num_t cmd_set_value =
3664         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3665
3666 cmdline_parse_inst_t cmd_set_numbers = {
3667         .f = cmd_set_parsed,
3668         .data = NULL,
3669         .help_str = "set nbport|nbcore|burst|verbose <value>",
3670         .tokens = {
3671                 (void *)&cmd_set_set,
3672                 (void *)&cmd_set_what,
3673                 (void *)&cmd_set_value,
3674                 NULL,
3675         },
3676 };
3677
3678 /* *** SET LOG LEVEL CONFIGURATION *** */
3679
3680 struct cmd_set_log_result {
3681         cmdline_fixed_string_t set;
3682         cmdline_fixed_string_t log;
3683         cmdline_fixed_string_t type;
3684         uint32_t level;
3685 };
3686
3687 static void
3688 cmd_set_log_parsed(void *parsed_result,
3689                    __attribute__((unused)) struct cmdline *cl,
3690                    __attribute__((unused)) void *data)
3691 {
3692         struct cmd_set_log_result *res;
3693         int ret;
3694
3695         res = parsed_result;
3696         if (!strcmp(res->type, "global"))
3697                 rte_log_set_global_level(res->level);
3698         else {
3699                 ret = rte_log_set_level_regexp(res->type, res->level);
3700                 if (ret < 0)
3701                         printf("Unable to set log level\n");
3702         }
3703 }
3704
3705 cmdline_parse_token_string_t cmd_set_log_set =
3706         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3707 cmdline_parse_token_string_t cmd_set_log_log =
3708         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3709 cmdline_parse_token_string_t cmd_set_log_type =
3710         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3711 cmdline_parse_token_num_t cmd_set_log_level =
3712         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3713
3714 cmdline_parse_inst_t cmd_set_log = {
3715         .f = cmd_set_log_parsed,
3716         .data = NULL,
3717         .help_str = "set log global|<type> <level>",
3718         .tokens = {
3719                 (void *)&cmd_set_log_set,
3720                 (void *)&cmd_set_log_log,
3721                 (void *)&cmd_set_log_type,
3722                 (void *)&cmd_set_log_level,
3723                 NULL,
3724         },
3725 };
3726
3727 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3728
3729 struct cmd_set_txpkts_result {
3730         cmdline_fixed_string_t cmd_keyword;
3731         cmdline_fixed_string_t txpkts;
3732         cmdline_fixed_string_t seg_lengths;
3733 };
3734
3735 static void
3736 cmd_set_txpkts_parsed(void *parsed_result,
3737                       __attribute__((unused)) struct cmdline *cl,
3738                       __attribute__((unused)) void *data)
3739 {
3740         struct cmd_set_txpkts_result *res;
3741         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3742         unsigned int nb_segs;
3743
3744         res = parsed_result;
3745         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3746                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3747         if (nb_segs > 0)
3748                 set_tx_pkt_segments(seg_lengths, nb_segs);
3749 }
3750
3751 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3752         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3753                                  cmd_keyword, "set");
3754 cmdline_parse_token_string_t cmd_set_txpkts_name =
3755         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3756                                  txpkts, "txpkts");
3757 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3758         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3759                                  seg_lengths, NULL);
3760
3761 cmdline_parse_inst_t cmd_set_txpkts = {
3762         .f = cmd_set_txpkts_parsed,
3763         .data = NULL,
3764         .help_str = "set txpkts <len0[,len1]*>",
3765         .tokens = {
3766                 (void *)&cmd_set_txpkts_keyword,
3767                 (void *)&cmd_set_txpkts_name,
3768                 (void *)&cmd_set_txpkts_lengths,
3769                 NULL,
3770         },
3771 };
3772
3773 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3774
3775 struct cmd_set_txsplit_result {
3776         cmdline_fixed_string_t cmd_keyword;
3777         cmdline_fixed_string_t txsplit;
3778         cmdline_fixed_string_t mode;
3779 };
3780
3781 static void
3782 cmd_set_txsplit_parsed(void *parsed_result,
3783                       __attribute__((unused)) struct cmdline *cl,
3784                       __attribute__((unused)) void *data)
3785 {
3786         struct cmd_set_txsplit_result *res;
3787
3788         res = parsed_result;
3789         set_tx_pkt_split(res->mode);
3790 }
3791
3792 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3793         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3794                                  cmd_keyword, "set");
3795 cmdline_parse_token_string_t cmd_set_txsplit_name =
3796         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3797                                  txsplit, "txsplit");
3798 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3799         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3800                                  mode, NULL);
3801
3802 cmdline_parse_inst_t cmd_set_txsplit = {
3803         .f = cmd_set_txsplit_parsed,
3804         .data = NULL,
3805         .help_str = "set txsplit on|off|rand",
3806         .tokens = {
3807                 (void *)&cmd_set_txsplit_keyword,
3808                 (void *)&cmd_set_txsplit_name,
3809                 (void *)&cmd_set_txsplit_mode,
3810                 NULL,
3811         },
3812 };
3813
3814 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3815 struct cmd_rx_vlan_filter_all_result {
3816         cmdline_fixed_string_t rx_vlan;
3817         cmdline_fixed_string_t what;
3818         cmdline_fixed_string_t all;
3819         portid_t port_id;
3820 };
3821
3822 static void
3823 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3824                               __attribute__((unused)) struct cmdline *cl,
3825                               __attribute__((unused)) void *data)
3826 {
3827         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3828
3829         if (!strcmp(res->what, "add"))
3830                 rx_vlan_all_filter_set(res->port_id, 1);
3831         else
3832                 rx_vlan_all_filter_set(res->port_id, 0);
3833 }
3834
3835 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3836         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3837                                  rx_vlan, "rx_vlan");
3838 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3839         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3840                                  what, "add#rm");
3841 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3842         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3843                                  all, "all");
3844 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3845         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3846                               port_id, UINT16);
3847
3848 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3849         .f = cmd_rx_vlan_filter_all_parsed,
3850         .data = NULL,
3851         .help_str = "rx_vlan add|rm all <port_id>: "
3852                 "Add/Remove all identifiers to/from the set of VLAN "
3853                 "identifiers filtered by a port",
3854         .tokens = {
3855                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3856                 (void *)&cmd_rx_vlan_filter_all_what,
3857                 (void *)&cmd_rx_vlan_filter_all_all,
3858                 (void *)&cmd_rx_vlan_filter_all_portid,
3859                 NULL,
3860         },
3861 };
3862
3863 /* *** VLAN OFFLOAD SET ON A PORT *** */
3864 struct cmd_vlan_offload_result {
3865         cmdline_fixed_string_t vlan;
3866         cmdline_fixed_string_t set;
3867         cmdline_fixed_string_t vlan_type;
3868         cmdline_fixed_string_t what;
3869         cmdline_fixed_string_t on;
3870         cmdline_fixed_string_t port_id;
3871 };
3872
3873 static void
3874 cmd_vlan_offload_parsed(void *parsed_result,
3875                           __attribute__((unused)) struct cmdline *cl,
3876                           __attribute__((unused)) void *data)
3877 {
3878         int on;
3879         struct cmd_vlan_offload_result *res = parsed_result;
3880         char *str;
3881         int i, len = 0;
3882         portid_t port_id = 0;
3883         unsigned int tmp;
3884
3885         str = res->port_id;
3886         len = strnlen(str, STR_TOKEN_SIZE);
3887         i = 0;
3888         /* Get port_id first */
3889         while(i < len){
3890                 if(str[i] == ',')
3891                         break;
3892
3893                 i++;
3894         }
3895         str[i]='\0';
3896         tmp = strtoul(str, NULL, 0);
3897         /* If port_id greater that what portid_t can represent, return */
3898         if(tmp >= RTE_MAX_ETHPORTS)
3899                 return;
3900         port_id = (portid_t)tmp;
3901
3902         if (!strcmp(res->on, "on"))
3903                 on = 1;
3904         else
3905                 on = 0;
3906
3907         if (!strcmp(res->what, "strip"))
3908                 rx_vlan_strip_set(port_id,  on);
3909         else if(!strcmp(res->what, "stripq")){
3910                 uint16_t queue_id = 0;
3911
3912                 /* No queue_id, return */
3913                 if(i + 1 >= len) {
3914                         printf("must specify (port,queue_id)\n");
3915                         return;
3916                 }
3917                 tmp = strtoul(str + i + 1, NULL, 0);
3918                 /* If queue_id greater that what 16-bits can represent, return */
3919                 if(tmp > 0xffff)
3920                         return;
3921
3922                 queue_id = (uint16_t)tmp;
3923                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3924         }
3925         else if (!strcmp(res->what, "filter"))
3926                 rx_vlan_filter_set(port_id, on);
3927         else if (!strcmp(res->what, "qinq_strip"))
3928                 rx_vlan_qinq_strip_set(port_id, on);
3929         else
3930                 vlan_extend_set(port_id, on);
3931
3932         return;
3933 }
3934
3935 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3936         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3937                                  vlan, "vlan");
3938 cmdline_parse_token_string_t cmd_vlan_offload_set =
3939         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3940                                  set, "set");
3941 cmdline_parse_token_string_t cmd_vlan_offload_what =
3942         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3943                                 what, "strip#filter#qinq_strip#extend#stripq");
3944 cmdline_parse_token_string_t cmd_vlan_offload_on =
3945         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3946                               on, "on#off");
3947 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3948         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3949                               port_id, NULL);
3950
3951 cmdline_parse_inst_t cmd_vlan_offload = {
3952         .f = cmd_vlan_offload_parsed,
3953         .data = NULL,
3954         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
3955                 "<port_id[,queue_id]>: "
3956                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
3957         .tokens = {
3958                 (void *)&cmd_vlan_offload_vlan,
3959                 (void *)&cmd_vlan_offload_set,
3960                 (void *)&cmd_vlan_offload_what,
3961                 (void *)&cmd_vlan_offload_on,
3962                 (void *)&cmd_vlan_offload_portid,
3963                 NULL,
3964         },
3965 };
3966
3967 /* *** VLAN TPID SET ON A PORT *** */
3968 struct cmd_vlan_tpid_result {
3969         cmdline_fixed_string_t vlan;
3970         cmdline_fixed_string_t set;
3971         cmdline_fixed_string_t vlan_type;
3972         cmdline_fixed_string_t what;
3973         uint16_t tp_id;
3974         portid_t port_id;
3975 };
3976
3977 static void
3978 cmd_vlan_tpid_parsed(void *parsed_result,
3979                           __attribute__((unused)) struct cmdline *cl,
3980                           __attribute__((unused)) void *data)
3981 {
3982         struct cmd_vlan_tpid_result *res = parsed_result;
3983         enum rte_vlan_type vlan_type;
3984
3985         if (!strcmp(res->vlan_type, "inner"))
3986                 vlan_type = ETH_VLAN_TYPE_INNER;
3987         else if (!strcmp(res->vlan_type, "outer"))
3988                 vlan_type = ETH_VLAN_TYPE_OUTER;
3989         else {
3990                 printf("Unknown vlan type\n");
3991                 return;
3992         }
3993         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3994 }
3995
3996 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3997         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3998                                  vlan, "vlan");
3999 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4000         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4001                                  set, "set");
4002 cmdline_parse_token_string_t cmd_vlan_type =
4003         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4004                                  vlan_type, "inner#outer");
4005 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4006         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4007                                  what, "tpid");
4008 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4009         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4010                               tp_id, UINT16);
4011 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4012         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4013                               port_id, UINT16);
4014
4015 cmdline_parse_inst_t cmd_vlan_tpid = {
4016         .f = cmd_vlan_tpid_parsed,
4017         .data = NULL,
4018         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4019                 "Set the VLAN Ether type",
4020         .tokens = {
4021                 (void *)&cmd_vlan_tpid_vlan,
4022                 (void *)&cmd_vlan_tpid_set,
4023                 (void *)&cmd_vlan_type,
4024                 (void *)&cmd_vlan_tpid_what,
4025                 (void *)&cmd_vlan_tpid_tpid,
4026                 (void *)&cmd_vlan_tpid_portid,
4027                 NULL,
4028         },
4029 };
4030
4031 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4032 struct cmd_rx_vlan_filter_result {
4033         cmdline_fixed_string_t rx_vlan;
4034         cmdline_fixed_string_t what;
4035         uint16_t vlan_id;
4036         portid_t port_id;
4037 };
4038
4039 static void
4040 cmd_rx_vlan_filter_parsed(void *parsed_result,
4041                           __attribute__((unused)) struct cmdline *cl,
4042                           __attribute__((unused)) void *data)
4043 {
4044         struct cmd_rx_vlan_filter_result *res = parsed_result;
4045
4046         if (!strcmp(res->what, "add"))
4047                 rx_vft_set(res->port_id, res->vlan_id, 1);
4048         else
4049                 rx_vft_set(res->port_id, res->vlan_id, 0);
4050 }
4051
4052 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4053         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4054                                  rx_vlan, "rx_vlan");
4055 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4056         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4057                                  what, "add#rm");
4058 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4059         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4060                               vlan_id, UINT16);
4061 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4062         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4063                               port_id, UINT16);
4064
4065 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4066         .f = cmd_rx_vlan_filter_parsed,
4067         .data = NULL,
4068         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4069                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4070                 "identifiers filtered by a port",
4071         .tokens = {
4072                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4073                 (void *)&cmd_rx_vlan_filter_what,
4074                 (void *)&cmd_rx_vlan_filter_vlanid,
4075                 (void *)&cmd_rx_vlan_filter_portid,
4076                 NULL,
4077         },
4078 };
4079
4080 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4081 struct cmd_tx_vlan_set_result {
4082         cmdline_fixed_string_t tx_vlan;
4083         cmdline_fixed_string_t set;
4084         portid_t port_id;
4085         uint16_t vlan_id;
4086 };
4087
4088 static void
4089 cmd_tx_vlan_set_parsed(void *parsed_result,
4090                        __attribute__((unused)) struct cmdline *cl,
4091                        __attribute__((unused)) void *data)
4092 {
4093         struct cmd_tx_vlan_set_result *res = parsed_result;
4094
4095         if (!port_is_stopped(res->port_id)) {
4096                 printf("Please stop port %d first\n", res->port_id);
4097                 return;
4098         }
4099
4100         tx_vlan_set(res->port_id, res->vlan_id);
4101
4102         cmd_reconfig_device_queue(res->port_id, 1, 1);
4103 }
4104
4105 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4106         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4107                                  tx_vlan, "tx_vlan");
4108 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4109         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4110                                  set, "set");
4111 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4112         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4113                               port_id, UINT16);
4114 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4115         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4116                               vlan_id, UINT16);
4117
4118 cmdline_parse_inst_t cmd_tx_vlan_set = {
4119         .f = cmd_tx_vlan_set_parsed,
4120         .data = NULL,
4121         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4122                 "Enable hardware insertion of a single VLAN header "
4123                 "with a given TAG Identifier in packets sent on a port",
4124         .tokens = {
4125                 (void *)&cmd_tx_vlan_set_tx_vlan,
4126                 (void *)&cmd_tx_vlan_set_set,
4127                 (void *)&cmd_tx_vlan_set_portid,
4128                 (void *)&cmd_tx_vlan_set_vlanid,
4129                 NULL,
4130         },
4131 };
4132
4133 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4134 struct cmd_tx_vlan_set_qinq_result {
4135         cmdline_fixed_string_t tx_vlan;
4136         cmdline_fixed_string_t set;
4137         portid_t port_id;
4138         uint16_t vlan_id;
4139         uint16_t vlan_id_outer;
4140 };
4141
4142 static void
4143 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4144                             __attribute__((unused)) struct cmdline *cl,
4145                             __attribute__((unused)) void *data)
4146 {
4147         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4148
4149         if (!port_is_stopped(res->port_id)) {
4150                 printf("Please stop port %d first\n", res->port_id);
4151                 return;
4152         }
4153
4154         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4155
4156         cmd_reconfig_device_queue(res->port_id, 1, 1);
4157 }
4158
4159 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4160         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4161                 tx_vlan, "tx_vlan");
4162 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4163         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4164                 set, "set");
4165 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4166         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4167                 port_id, UINT16);
4168 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4169         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4170                 vlan_id, UINT16);
4171 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4172         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4173                 vlan_id_outer, UINT16);
4174
4175 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4176         .f = cmd_tx_vlan_set_qinq_parsed,
4177         .data = NULL,
4178         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4179                 "Enable hardware insertion of double VLAN header "
4180                 "with given TAG Identifiers in packets sent on a port",
4181         .tokens = {
4182                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4183                 (void *)&cmd_tx_vlan_set_qinq_set,
4184                 (void *)&cmd_tx_vlan_set_qinq_portid,
4185                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4186                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4187                 NULL,
4188         },
4189 };
4190
4191 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4192 struct cmd_tx_vlan_set_pvid_result {
4193         cmdline_fixed_string_t tx_vlan;
4194         cmdline_fixed_string_t set;
4195         cmdline_fixed_string_t pvid;
4196         portid_t port_id;
4197         uint16_t vlan_id;
4198         cmdline_fixed_string_t mode;
4199 };
4200
4201 static void
4202 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4203                             __attribute__((unused)) struct cmdline *cl,
4204                             __attribute__((unused)) void *data)
4205 {
4206         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4207
4208         if (strcmp(res->mode, "on") == 0)
4209                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4210         else
4211                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4212 }
4213
4214 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4215         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4216                                  tx_vlan, "tx_vlan");
4217 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4218         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4219                                  set, "set");
4220 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4221         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4222                                  pvid, "pvid");
4223 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4224         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4225                              port_id, UINT16);
4226 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4227         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4228                               vlan_id, UINT16);
4229 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4230         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4231                                  mode, "on#off");
4232
4233 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4234         .f = cmd_tx_vlan_set_pvid_parsed,
4235         .data = NULL,
4236         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4237         .tokens = {
4238                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4239                 (void *)&cmd_tx_vlan_set_pvid_set,
4240                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4241                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4242                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4243                 (void *)&cmd_tx_vlan_set_pvid_mode,
4244                 NULL,
4245         },
4246 };
4247
4248 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4249 struct cmd_tx_vlan_reset_result {
4250         cmdline_fixed_string_t tx_vlan;
4251         cmdline_fixed_string_t reset;
4252         portid_t port_id;
4253 };
4254
4255 static void
4256 cmd_tx_vlan_reset_parsed(void *parsed_result,
4257                          __attribute__((unused)) struct cmdline *cl,
4258                          __attribute__((unused)) void *data)
4259 {
4260         struct cmd_tx_vlan_reset_result *res = parsed_result;
4261
4262         if (!port_is_stopped(res->port_id)) {
4263                 printf("Please stop port %d first\n", res->port_id);
4264                 return;
4265         }
4266
4267         tx_vlan_reset(res->port_id);
4268
4269         cmd_reconfig_device_queue(res->port_id, 1, 1);
4270 }
4271
4272 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4273         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4274                                  tx_vlan, "tx_vlan");
4275 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4276         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4277                                  reset, "reset");
4278 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4279         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4280                               port_id, UINT16);
4281
4282 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4283         .f = cmd_tx_vlan_reset_parsed,
4284         .data = NULL,
4285         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4286                 "VLAN header in packets sent on a port",
4287         .tokens = {
4288                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4289                 (void *)&cmd_tx_vlan_reset_reset,
4290                 (void *)&cmd_tx_vlan_reset_portid,
4291                 NULL,
4292         },
4293 };
4294
4295
4296 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4297 struct cmd_csum_result {
4298         cmdline_fixed_string_t csum;
4299         cmdline_fixed_string_t mode;
4300         cmdline_fixed_string_t proto;
4301         cmdline_fixed_string_t hwsw;
4302         portid_t port_id;
4303 };
4304
4305 static void
4306 csum_show(int port_id)
4307 {
4308         struct rte_eth_dev_info dev_info;
4309         uint64_t tx_offloads;
4310         int ret;
4311
4312         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4313         printf("Parse tunnel is %s\n",
4314                 (ports[port_id].parse_tunnel) ? "on" : "off");
4315         printf("IP checksum offload is %s\n",
4316                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4317         printf("UDP checksum offload is %s\n",
4318                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4319         printf("TCP checksum offload is %s\n",
4320                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4321         printf("SCTP checksum offload is %s\n",
4322                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4323         printf("Outer-Ip checksum offload is %s\n",
4324                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4325         printf("Outer-Udp checksum offload is %s\n",
4326                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4327
4328         /* display warnings if configuration is not supported by the NIC */
4329         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4330         if (ret != 0)
4331                 return;
4332
4333         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4334                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4335                 printf("Warning: hardware IP checksum enabled but not "
4336                         "supported by port %d\n", port_id);
4337         }
4338         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4339                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4340                 printf("Warning: hardware UDP checksum enabled but not "
4341                         "supported by port %d\n", port_id);
4342         }
4343         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4344                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4345                 printf("Warning: hardware TCP checksum enabled but not "
4346                         "supported by port %d\n", port_id);
4347         }
4348         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4349                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4350                 printf("Warning: hardware SCTP checksum enabled but not "
4351                         "supported by port %d\n", port_id);
4352         }
4353         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4354                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4355                 printf("Warning: hardware outer IP checksum enabled but not "
4356                         "supported by port %d\n", port_id);
4357         }
4358         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4359                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4360                         == 0) {
4361                 printf("Warning: hardware outer UDP checksum enabled but not "
4362                         "supported by port %d\n", port_id);
4363         }
4364 }
4365
4366 static void
4367 cmd_config_queue_tx_offloads(struct rte_port *port)
4368 {
4369         int k;
4370
4371         /* Apply queue tx offloads configuration */
4372         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4373                 port->tx_conf[k].offloads =
4374                         port->dev_conf.txmode.offloads;
4375 }
4376
4377 static void
4378 cmd_csum_parsed(void *parsed_result,
4379                        __attribute__((unused)) struct cmdline *cl,
4380                        __attribute__((unused)) void *data)
4381 {
4382         struct cmd_csum_result *res = parsed_result;
4383         int hw = 0;
4384         uint64_t csum_offloads = 0;
4385         struct rte_eth_dev_info dev_info;
4386         int ret;
4387
4388         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4389                 printf("invalid port %d\n", res->port_id);
4390                 return;
4391         }
4392         if (!port_is_stopped(res->port_id)) {
4393                 printf("Please stop port %d first\n", res->port_id);
4394                 return;
4395         }
4396
4397         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4398         if (ret != 0)
4399                 return;
4400
4401         if (!strcmp(res->mode, "set")) {
4402
4403                 if (!strcmp(res->hwsw, "hw"))
4404                         hw = 1;
4405
4406                 if (!strcmp(res->proto, "ip")) {
4407                         if (hw == 0 || (dev_info.tx_offload_capa &
4408                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4409                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4410                         } else {
4411                                 printf("IP checksum offload is not supported "
4412                                        "by port %u\n", res->port_id);
4413                         }
4414                 } else if (!strcmp(res->proto, "udp")) {
4415                         if (hw == 0 || (dev_info.tx_offload_capa &
4416                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4417                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4418                         } else {
4419                                 printf("UDP checksum offload is not supported "
4420                                        "by port %u\n", res->port_id);
4421                         }
4422                 } else if (!strcmp(res->proto, "tcp")) {
4423                         if (hw == 0 || (dev_info.tx_offload_capa &
4424                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4425                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4426                         } else {
4427                                 printf("TCP checksum offload is not supported "
4428                                        "by port %u\n", res->port_id);
4429                         }
4430                 } else if (!strcmp(res->proto, "sctp")) {
4431                         if (hw == 0 || (dev_info.tx_offload_capa &
4432                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4433                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4434                         } else {
4435                                 printf("SCTP checksum offload is not supported "
4436                                        "by port %u\n", res->port_id);
4437                         }
4438                 } else if (!strcmp(res->proto, "outer-ip")) {
4439                         if (hw == 0 || (dev_info.tx_offload_capa &
4440                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4441                                 csum_offloads |=
4442                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4443                         } else {
4444                                 printf("Outer IP checksum offload is not "
4445                                        "supported by port %u\n", res->port_id);
4446                         }
4447                 } else if (!strcmp(res->proto, "outer-udp")) {
4448                         if (hw == 0 || (dev_info.tx_offload_capa &
4449                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4450                                 csum_offloads |=
4451                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4452                         } else {
4453                                 printf("Outer UDP checksum offload is not "
4454                                        "supported by port %u\n", res->port_id);
4455                         }
4456                 }
4457
4458                 if (hw) {
4459                         ports[res->port_id].dev_conf.txmode.offloads |=
4460                                                         csum_offloads;
4461                 } else {
4462                         ports[res->port_id].dev_conf.txmode.offloads &=
4463                                                         (~csum_offloads);
4464                 }
4465                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4466         }
4467         csum_show(res->port_id);
4468
4469         cmd_reconfig_device_queue(res->port_id, 1, 1);
4470 }
4471
4472 cmdline_parse_token_string_t cmd_csum_csum =
4473         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4474                                 csum, "csum");
4475 cmdline_parse_token_string_t cmd_csum_mode =
4476         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4477                                 mode, "set");
4478 cmdline_parse_token_string_t cmd_csum_proto =
4479         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4480                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4481 cmdline_parse_token_string_t cmd_csum_hwsw =
4482         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4483                                 hwsw, "hw#sw");
4484 cmdline_parse_token_num_t cmd_csum_portid =
4485         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4486                                 port_id, UINT16);
4487
4488 cmdline_parse_inst_t cmd_csum_set = {
4489         .f = cmd_csum_parsed,
4490         .data = NULL,
4491         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4492                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4493                 "using csum forward engine",
4494         .tokens = {
4495                 (void *)&cmd_csum_csum,
4496                 (void *)&cmd_csum_mode,
4497                 (void *)&cmd_csum_proto,
4498                 (void *)&cmd_csum_hwsw,
4499                 (void *)&cmd_csum_portid,
4500                 NULL,
4501         },
4502 };
4503
4504 cmdline_parse_token_string_t cmd_csum_mode_show =
4505         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4506                                 mode, "show");
4507
4508 cmdline_parse_inst_t cmd_csum_show = {
4509         .f = cmd_csum_parsed,
4510         .data = NULL,
4511         .help_str = "csum show <port_id>: Show checksum offload configuration",
4512         .tokens = {
4513                 (void *)&cmd_csum_csum,
4514                 (void *)&cmd_csum_mode_show,
4515                 (void *)&cmd_csum_portid,
4516                 NULL,
4517         },
4518 };
4519
4520 /* Enable/disable tunnel parsing */
4521 struct cmd_csum_tunnel_result {
4522         cmdline_fixed_string_t csum;
4523         cmdline_fixed_string_t parse;
4524         cmdline_fixed_string_t onoff;
4525         portid_t port_id;
4526 };
4527
4528 static void
4529 cmd_csum_tunnel_parsed(void *parsed_result,
4530                        __attribute__((unused)) struct cmdline *cl,
4531                        __attribute__((unused)) void *data)
4532 {
4533         struct cmd_csum_tunnel_result *res = parsed_result;
4534
4535         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4536                 return;
4537
4538         if (!strcmp(res->onoff, "on"))
4539                 ports[res->port_id].parse_tunnel = 1;
4540         else
4541                 ports[res->port_id].parse_tunnel = 0;
4542
4543         csum_show(res->port_id);
4544 }
4545
4546 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4547         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4548                                 csum, "csum");
4549 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4550         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4551                                 parse, "parse-tunnel");
4552 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4553         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4554                                 onoff, "on#off");
4555 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4556         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4557                                 port_id, UINT16);
4558
4559 cmdline_parse_inst_t cmd_csum_tunnel = {
4560         .f = cmd_csum_tunnel_parsed,
4561         .data = NULL,
4562         .help_str = "csum parse-tunnel on|off <port_id>: "
4563                 "Enable/Disable parsing of tunnels for csum engine",
4564         .tokens = {
4565                 (void *)&cmd_csum_tunnel_csum,
4566                 (void *)&cmd_csum_tunnel_parse,
4567                 (void *)&cmd_csum_tunnel_onoff,
4568                 (void *)&cmd_csum_tunnel_portid,
4569                 NULL,
4570         },
4571 };
4572
4573 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4574 struct cmd_tso_set_result {
4575         cmdline_fixed_string_t tso;
4576         cmdline_fixed_string_t mode;
4577         uint16_t tso_segsz;
4578         portid_t port_id;
4579 };
4580
4581 static void
4582 cmd_tso_set_parsed(void *parsed_result,
4583                        __attribute__((unused)) struct cmdline *cl,
4584                        __attribute__((unused)) void *data)
4585 {
4586         struct cmd_tso_set_result *res = parsed_result;
4587         struct rte_eth_dev_info dev_info;
4588         int ret;
4589
4590         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4591                 return;
4592         if (!port_is_stopped(res->port_id)) {
4593                 printf("Please stop port %d first\n", res->port_id);
4594                 return;
4595         }
4596
4597         if (!strcmp(res->mode, "set"))
4598                 ports[res->port_id].tso_segsz = res->tso_segsz;
4599
4600         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4601         if (ret != 0)
4602                 return;
4603
4604         if ((ports[res->port_id].tso_segsz != 0) &&
4605                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4606                 printf("Error: TSO is not supported by port %d\n",
4607                        res->port_id);
4608                 return;
4609         }
4610
4611         if (ports[res->port_id].tso_segsz == 0) {
4612                 ports[res->port_id].dev_conf.txmode.offloads &=
4613                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4614                 printf("TSO for non-tunneled packets is disabled\n");
4615         } else {
4616                 ports[res->port_id].dev_conf.txmode.offloads |=
4617                                                 DEV_TX_OFFLOAD_TCP_TSO;
4618                 printf("TSO segment size for non-tunneled packets is %d\n",
4619                         ports[res->port_id].tso_segsz);
4620         }
4621         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4622
4623         /* display warnings if configuration is not supported by the NIC */
4624         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4625         if (ret != 0)
4626                 return;
4627
4628         if ((ports[res->port_id].tso_segsz != 0) &&
4629                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4630                 printf("Warning: TSO enabled but not "
4631                         "supported by port %d\n", res->port_id);
4632         }
4633
4634         cmd_reconfig_device_queue(res->port_id, 1, 1);
4635 }
4636
4637 cmdline_parse_token_string_t cmd_tso_set_tso =
4638         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4639                                 tso, "tso");
4640 cmdline_parse_token_string_t cmd_tso_set_mode =
4641         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4642                                 mode, "set");
4643 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4644         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4645                                 tso_segsz, UINT16);
4646 cmdline_parse_token_num_t cmd_tso_set_portid =
4647         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4648                                 port_id, UINT16);
4649
4650 cmdline_parse_inst_t cmd_tso_set = {
4651         .f = cmd_tso_set_parsed,
4652         .data = NULL,
4653         .help_str = "tso set <tso_segsz> <port_id>: "
4654                 "Set TSO segment size of non-tunneled packets for csum engine "
4655                 "(0 to disable)",
4656         .tokens = {
4657                 (void *)&cmd_tso_set_tso,
4658                 (void *)&cmd_tso_set_mode,
4659                 (void *)&cmd_tso_set_tso_segsz,
4660                 (void *)&cmd_tso_set_portid,
4661                 NULL,
4662         },
4663 };
4664
4665 cmdline_parse_token_string_t cmd_tso_show_mode =
4666         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4667                                 mode, "show");
4668
4669
4670 cmdline_parse_inst_t cmd_tso_show = {
4671         .f = cmd_tso_set_parsed,
4672         .data = NULL,
4673         .help_str = "tso show <port_id>: "
4674                 "Show TSO segment size of non-tunneled packets for csum engine",
4675         .tokens = {
4676                 (void *)&cmd_tso_set_tso,
4677                 (void *)&cmd_tso_show_mode,
4678                 (void *)&cmd_tso_set_portid,
4679                 NULL,
4680         },
4681 };
4682
4683 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4684 struct cmd_tunnel_tso_set_result {
4685         cmdline_fixed_string_t tso;
4686         cmdline_fixed_string_t mode;
4687         uint16_t tso_segsz;
4688         portid_t port_id;
4689 };
4690
4691 static struct rte_eth_dev_info
4692 check_tunnel_tso_nic_support(portid_t port_id)
4693 {
4694         struct rte_eth_dev_info dev_info;
4695
4696         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4697                 return dev_info;
4698
4699         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4700                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4701                        "not enabled for port %d\n", port_id);
4702         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4703                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4704                        "not enabled for port %d\n", port_id);
4705         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4706                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4707                        "not enabled for port %d\n", port_id);
4708         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4709                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4710                        "not enabled for port %d\n", port_id);
4711         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4712                 printf("Warning: IP TUNNEL TSO not supported therefore "
4713                        "not enabled for port %d\n", port_id);
4714         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4715                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4716                        "not enabled for port %d\n", port_id);
4717         return dev_info;
4718 }
4719
4720 static void
4721 cmd_tunnel_tso_set_parsed(void *parsed_result,
4722                           __attribute__((unused)) struct cmdline *cl,
4723                           __attribute__((unused)) void *data)
4724 {
4725         struct cmd_tunnel_tso_set_result *res = parsed_result;
4726         struct rte_eth_dev_info dev_info;
4727
4728         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4729                 return;
4730         if (!port_is_stopped(res->port_id)) {
4731                 printf("Please stop port %d first\n", res->port_id);
4732                 return;
4733         }
4734
4735         if (!strcmp(res->mode, "set"))
4736                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4737
4738         dev_info = check_tunnel_tso_nic_support(res->port_id);
4739         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4740                 ports[res->port_id].dev_conf.txmode.offloads &=
4741                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4742                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4743                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4744                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4745                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4746                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4747                 printf("TSO for tunneled packets is disabled\n");
4748         } else {
4749                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4750                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4751                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4752                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4753                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4754                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4755
4756                 ports[res->port_id].dev_conf.txmode.offloads |=
4757                         (tso_offloads & dev_info.tx_offload_capa);
4758                 printf("TSO segment size for tunneled packets is %d\n",
4759                         ports[res->port_id].tunnel_tso_segsz);
4760
4761                 /* Below conditions are needed to make it work:
4762                  * (1) tunnel TSO is supported by the NIC;
4763                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4764                  * are recognized;
4765                  * (3) for tunneled pkts with outer L3 of IPv4,
4766                  * "csum set outer-ip" must be set to hw, because after tso,
4767                  * total_len of outer IP header is changed, and the checksum
4768                  * of outer IP header calculated by sw should be wrong; that
4769                  * is not necessary for IPv6 tunneled pkts because there's no
4770                  * checksum in IP header anymore.
4771                  */
4772
4773                 if (!ports[res->port_id].parse_tunnel)
4774                         printf("Warning: csum parse_tunnel must be set "
4775                                 "so that tunneled packets are recognized\n");
4776                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4777                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4778                         printf("Warning: csum set outer-ip must be set to hw "
4779                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4780         }
4781
4782         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4783         cmd_reconfig_device_queue(res->port_id, 1, 1);
4784 }
4785
4786 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4787         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4788                                 tso, "tunnel_tso");
4789 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4790         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4791                                 mode, "set");
4792 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4793         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4794                                 tso_segsz, UINT16);
4795 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4796         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4797                                 port_id, UINT16);
4798
4799 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4800         .f = cmd_tunnel_tso_set_parsed,
4801         .data = NULL,
4802         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4803                 "Set TSO segment size of tunneled packets for csum engine "
4804                 "(0 to disable)",
4805         .tokens = {
4806                 (void *)&cmd_tunnel_tso_set_tso,
4807                 (void *)&cmd_tunnel_tso_set_mode,
4808                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4809                 (void *)&cmd_tunnel_tso_set_portid,
4810                 NULL,
4811         },
4812 };
4813
4814 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4815         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4816                                 mode, "show");
4817
4818
4819 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4820         .f = cmd_tunnel_tso_set_parsed,
4821         .data = NULL,
4822         .help_str = "tunnel_tso show <port_id> "
4823                 "Show TSO segment size of tunneled packets for csum engine",
4824         .tokens = {
4825                 (void *)&cmd_tunnel_tso_set_tso,
4826                 (void *)&cmd_tunnel_tso_show_mode,
4827                 (void *)&cmd_tunnel_tso_set_portid,
4828                 NULL,
4829         },
4830 };
4831
4832 /* *** SET GRO FOR A PORT *** */
4833 struct cmd_gro_enable_result {
4834         cmdline_fixed_string_t cmd_set;
4835         cmdline_fixed_string_t cmd_port;
4836         cmdline_fixed_string_t cmd_keyword;
4837         cmdline_fixed_string_t cmd_onoff;
4838         portid_t cmd_pid;
4839 };
4840
4841 static void
4842 cmd_gro_enable_parsed(void *parsed_result,
4843                 __attribute__((unused)) struct cmdline *cl,
4844                 __attribute__((unused)) void *data)
4845 {
4846         struct cmd_gro_enable_result *res;
4847
4848         res = parsed_result;
4849         if (!strcmp(res->cmd_keyword, "gro"))
4850                 setup_gro(res->cmd_onoff, res->cmd_pid);
4851 }
4852
4853 cmdline_parse_token_string_t cmd_gro_enable_set =
4854         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4855                         cmd_set, "set");
4856 cmdline_parse_token_string_t cmd_gro_enable_port =
4857         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4858                         cmd_keyword, "port");
4859 cmdline_parse_token_num_t cmd_gro_enable_pid =
4860         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4861                         cmd_pid, UINT16);
4862 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4863         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4864                         cmd_keyword, "gro");
4865 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4866         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4867                         cmd_onoff, "on#off");
4868
4869 cmdline_parse_inst_t cmd_gro_enable = {
4870         .f = cmd_gro_enable_parsed,
4871         .data = NULL,
4872         .help_str = "set port <port_id> gro on|off",
4873         .tokens = {
4874                 (void *)&cmd_gro_enable_set,
4875                 (void *)&cmd_gro_enable_port,
4876                 (void *)&cmd_gro_enable_pid,
4877                 (void *)&cmd_gro_enable_keyword,
4878                 (void *)&cmd_gro_enable_onoff,
4879                 NULL,
4880         },
4881 };
4882
4883 /* *** DISPLAY GRO CONFIGURATION *** */
4884 struct cmd_gro_show_result {
4885         cmdline_fixed_string_t cmd_show;
4886         cmdline_fixed_string_t cmd_port;
4887         cmdline_fixed_string_t cmd_keyword;
4888         portid_t cmd_pid;
4889 };
4890
4891 static void
4892 cmd_gro_show_parsed(void *parsed_result,
4893                 __attribute__((unused)) struct cmdline *cl,
4894                 __attribute__((unused)) void *data)
4895 {
4896         struct cmd_gro_show_result *res;
4897
4898         res = parsed_result;
4899         if (!strcmp(res->cmd_keyword, "gro"))
4900                 show_gro(res->cmd_pid);
4901 }
4902
4903 cmdline_parse_token_string_t cmd_gro_show_show =
4904         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4905                         cmd_show, "show");
4906 cmdline_parse_token_string_t cmd_gro_show_port =
4907         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4908                         cmd_port, "port");
4909 cmdline_parse_token_num_t cmd_gro_show_pid =
4910         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4911                         cmd_pid, UINT16);
4912 cmdline_parse_token_string_t cmd_gro_show_keyword =
4913         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4914                         cmd_keyword, "gro");
4915
4916 cmdline_parse_inst_t cmd_gro_show = {
4917         .f = cmd_gro_show_parsed,
4918         .data = NULL,
4919         .help_str = "show port <port_id> gro",
4920         .tokens = {
4921                 (void *)&cmd_gro_show_show,
4922                 (void *)&cmd_gro_show_port,
4923                 (void *)&cmd_gro_show_pid,
4924                 (void *)&cmd_gro_show_keyword,
4925                 NULL,
4926         },
4927 };
4928
4929 /* *** SET FLUSH CYCLES FOR GRO *** */
4930 struct cmd_gro_flush_result {
4931         cmdline_fixed_string_t cmd_set;
4932         cmdline_fixed_string_t cmd_keyword;
4933         cmdline_fixed_string_t cmd_flush;
4934         uint8_t cmd_cycles;
4935 };
4936
4937 static void
4938 cmd_gro_flush_parsed(void *parsed_result,
4939                 __attribute__((unused)) struct cmdline *cl,
4940                 __attribute__((unused)) void *data)
4941 {
4942         struct cmd_gro_flush_result *res;
4943
4944         res = parsed_result;
4945         if ((!strcmp(res->cmd_keyword, "gro")) &&
4946                         (!strcmp(res->cmd_flush, "flush")))
4947                 setup_gro_flush_cycles(res->cmd_cycles);
4948 }
4949
4950 cmdline_parse_token_string_t cmd_gro_flush_set =
4951         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4952                         cmd_set, "set");
4953 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4954         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4955                         cmd_keyword, "gro");
4956 cmdline_parse_token_string_t cmd_gro_flush_flush =
4957         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4958                         cmd_flush, "flush");
4959 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4960         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4961                         cmd_cycles, UINT8);
4962
4963 cmdline_parse_inst_t cmd_gro_flush = {
4964         .f = cmd_gro_flush_parsed,
4965         .data = NULL,
4966         .help_str = "set gro flush <cycles>",
4967         .tokens = {
4968                 (void *)&cmd_gro_flush_set,
4969                 (void *)&cmd_gro_flush_keyword,
4970                 (void *)&cmd_gro_flush_flush,
4971                 (void *)&cmd_gro_flush_cycles,
4972                 NULL,
4973         },
4974 };
4975
4976 /* *** ENABLE/DISABLE GSO *** */
4977 struct cmd_gso_enable_result {
4978         cmdline_fixed_string_t cmd_set;
4979         cmdline_fixed_string_t cmd_port;
4980         cmdline_fixed_string_t cmd_keyword;
4981         cmdline_fixed_string_t cmd_mode;
4982         portid_t cmd_pid;
4983 };
4984
4985 static void
4986 cmd_gso_enable_parsed(void *parsed_result,
4987                 __attribute__((unused)) struct cmdline *cl,
4988                 __attribute__((unused)) void *data)
4989 {
4990         struct cmd_gso_enable_result *res;
4991
4992         res = parsed_result;
4993         if (!strcmp(res->cmd_keyword, "gso"))
4994                 setup_gso(res->cmd_mode, res->cmd_pid);
4995 }
4996
4997 cmdline_parse_token_string_t cmd_gso_enable_set =
4998         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4999                         cmd_set, "set");
5000 cmdline_parse_token_string_t cmd_gso_enable_port =
5001         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5002                         cmd_port, "port");
5003 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5004         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5005                         cmd_keyword, "gso");
5006 cmdline_parse_token_string_t cmd_gso_enable_mode =
5007         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5008                         cmd_mode, "on#off");
5009 cmdline_parse_token_num_t cmd_gso_enable_pid =
5010         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5011                         cmd_pid, UINT16);
5012
5013 cmdline_parse_inst_t cmd_gso_enable = {
5014         .f = cmd_gso_enable_parsed,
5015         .data = NULL,
5016         .help_str = "set port <port_id> gso on|off",
5017         .tokens = {
5018                 (void *)&cmd_gso_enable_set,
5019                 (void *)&cmd_gso_enable_port,
5020                 (void *)&cmd_gso_enable_pid,
5021                 (void *)&cmd_gso_enable_keyword,
5022                 (void *)&cmd_gso_enable_mode,
5023                 NULL,
5024         },
5025 };
5026
5027 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5028 struct cmd_gso_size_result {
5029         cmdline_fixed_string_t cmd_set;
5030         cmdline_fixed_string_t cmd_keyword;
5031         cmdline_fixed_string_t cmd_segsz;
5032         uint16_t cmd_size;
5033 };
5034
5035 static void
5036 cmd_gso_size_parsed(void *parsed_result,
5037                        __attribute__((unused)) struct cmdline *cl,
5038                        __attribute__((unused)) void *data)
5039 {
5040         struct cmd_gso_size_result *res = parsed_result;
5041
5042         if (test_done == 0) {
5043                 printf("Before setting GSO segsz, please first"
5044                                 " stop fowarding\n");
5045                 return;
5046         }
5047
5048         if (!strcmp(res->cmd_keyword, "gso") &&
5049                         !strcmp(res->cmd_segsz, "segsz")) {
5050                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5051                         printf("gso_size should be larger than %zu."
5052                                         " Please input a legal value\n",
5053                                         RTE_GSO_SEG_SIZE_MIN);
5054                 else
5055                         gso_max_segment_size = res->cmd_size;
5056         }
5057 }
5058
5059 cmdline_parse_token_string_t cmd_gso_size_set =
5060         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5061                                 cmd_set, "set");
5062 cmdline_parse_token_string_t cmd_gso_size_keyword =
5063         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5064                                 cmd_keyword, "gso");
5065 cmdline_parse_token_string_t cmd_gso_size_segsz =
5066         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5067                                 cmd_segsz, "segsz");
5068 cmdline_parse_token_num_t cmd_gso_size_size =
5069         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5070                                 cmd_size, UINT16);
5071
5072 cmdline_parse_inst_t cmd_gso_size = {
5073         .f = cmd_gso_size_parsed,
5074         .data = NULL,
5075         .help_str = "set gso segsz <length>",
5076         .tokens = {
5077                 (void *)&cmd_gso_size_set,
5078                 (void *)&cmd_gso_size_keyword,
5079                 (void *)&cmd_gso_size_segsz,
5080                 (void *)&cmd_gso_size_size,
5081                 NULL,
5082         },
5083 };
5084
5085 /* *** SHOW GSO CONFIGURATION *** */
5086 struct cmd_gso_show_result {
5087         cmdline_fixed_string_t cmd_show;
5088         cmdline_fixed_string_t cmd_port;
5089         cmdline_fixed_string_t cmd_keyword;
5090         portid_t cmd_pid;
5091 };
5092
5093 static void
5094 cmd_gso_show_parsed(void *parsed_result,
5095                        __attribute__((unused)) struct cmdline *cl,
5096                        __attribute__((unused)) void *data)
5097 {
5098         struct cmd_gso_show_result *res = parsed_result;
5099
5100         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5101                 printf("invalid port id %u\n", res->cmd_pid);
5102                 return;
5103         }
5104         if (!strcmp(res->cmd_keyword, "gso")) {
5105                 if (gso_ports[res->cmd_pid].enable) {
5106                         printf("Max GSO'd packet size: %uB\n"
5107                                         "Supported GSO types: TCP/IPv4, "
5108                                         "UDP/IPv4, VxLAN with inner "
5109                                         "TCP/IPv4 packet, GRE with inner "
5110                                         "TCP/IPv4 packet\n",
5111                                         gso_max_segment_size);
5112                 } else
5113                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5114         }
5115 }
5116
5117 cmdline_parse_token_string_t cmd_gso_show_show =
5118 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5119                 cmd_show, "show");
5120 cmdline_parse_token_string_t cmd_gso_show_port =
5121 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5122                 cmd_port, "port");
5123 cmdline_parse_token_string_t cmd_gso_show_keyword =
5124         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5125                                 cmd_keyword, "gso");
5126 cmdline_parse_token_num_t cmd_gso_show_pid =
5127         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5128                                 cmd_pid, UINT16);
5129
5130 cmdline_parse_inst_t cmd_gso_show = {
5131         .f = cmd_gso_show_parsed,
5132         .data = NULL,
5133         .help_str = "show port <port_id> gso",
5134         .tokens = {
5135                 (void *)&cmd_gso_show_show,
5136                 (void *)&cmd_gso_show_port,
5137                 (void *)&cmd_gso_show_pid,
5138                 (void *)&cmd_gso_show_keyword,
5139                 NULL,
5140         },
5141 };
5142
5143 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5144 struct cmd_set_flush_rx {
5145         cmdline_fixed_string_t set;
5146         cmdline_fixed_string_t flush_rx;
5147         cmdline_fixed_string_t mode;
5148 };
5149
5150 static void
5151 cmd_set_flush_rx_parsed(void *parsed_result,
5152                 __attribute__((unused)) struct cmdline *cl,
5153                 __attribute__((unused)) void *data)
5154 {
5155         struct cmd_set_flush_rx *res = parsed_result;
5156         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5157 }
5158
5159 cmdline_parse_token_string_t cmd_setflushrx_set =
5160         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5161                         set, "set");
5162 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5163         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5164                         flush_rx, "flush_rx");
5165 cmdline_parse_token_string_t cmd_setflushrx_mode =
5166         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5167                         mode, "on#off");
5168
5169
5170 cmdline_parse_inst_t cmd_set_flush_rx = {
5171         .f = cmd_set_flush_rx_parsed,
5172         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5173         .data = NULL,
5174         .tokens = {
5175                 (void *)&cmd_setflushrx_set,
5176                 (void *)&cmd_setflushrx_flush_rx,
5177                 (void *)&cmd_setflushrx_mode,
5178                 NULL,
5179         },
5180 };
5181
5182 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5183 struct cmd_set_link_check {
5184         cmdline_fixed_string_t set;
5185         cmdline_fixed_string_t link_check;
5186         cmdline_fixed_string_t mode;
5187 };
5188
5189 static void
5190 cmd_set_link_check_parsed(void *parsed_result,
5191                 __attribute__((unused)) struct cmdline *cl,
5192                 __attribute__((unused)) void *data)
5193 {
5194         struct cmd_set_link_check *res = parsed_result;
5195         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5196 }
5197
5198 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5199         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5200                         set, "set");
5201 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5202         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5203                         link_check, "link_check");
5204 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5205         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5206                         mode, "on#off");
5207
5208
5209 cmdline_parse_inst_t cmd_set_link_check = {
5210         .f = cmd_set_link_check_parsed,
5211         .help_str = "set link_check on|off: Enable/Disable link status check "
5212                     "when starting/stopping a port",
5213         .data = NULL,
5214         .tokens = {
5215                 (void *)&cmd_setlinkcheck_set,
5216                 (void *)&cmd_setlinkcheck_link_check,
5217                 (void *)&cmd_setlinkcheck_mode,
5218                 NULL,
5219         },
5220 };
5221
5222 /* *** SET NIC BYPASS MODE *** */
5223 struct cmd_set_bypass_mode_result {
5224         cmdline_fixed_string_t set;
5225         cmdline_fixed_string_t bypass;
5226         cmdline_fixed_string_t mode;
5227         cmdline_fixed_string_t value;
5228         portid_t port_id;
5229 };
5230
5231 static void
5232 cmd_set_bypass_mode_parsed(void *parsed_result,
5233                 __attribute__((unused)) struct cmdline *cl,
5234                 __attribute__((unused)) void *data)
5235 {
5236         struct cmd_set_bypass_mode_result *res = parsed_result;
5237         portid_t port_id = res->port_id;
5238         int32_t rc = -EINVAL;
5239
5240 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5241         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5242
5243         if (!strcmp(res->value, "bypass"))
5244                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5245         else if (!strcmp(res->value, "isolate"))
5246                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5247         else
5248                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5249
5250         /* Set the bypass mode for the relevant port. */
5251         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5252 #endif
5253         if (rc != 0)
5254                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5255 }
5256
5257 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5258         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5259                         set, "set");
5260 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5261         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5262                         bypass, "bypass");
5263 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5264         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5265                         mode, "mode");
5266 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5267         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5268                         value, "normal#bypass#isolate");
5269 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5270         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5271                                 port_id, UINT16);
5272
5273 cmdline_parse_inst_t cmd_set_bypass_mode = {
5274         .f = cmd_set_bypass_mode_parsed,
5275         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5276                     "Set the NIC bypass mode for port_id",
5277         .data = NULL,
5278         .tokens = {
5279                 (void *)&cmd_setbypass_mode_set,
5280                 (void *)&cmd_setbypass_mode_bypass,
5281                 (void *)&cmd_setbypass_mode_mode,
5282                 (void *)&cmd_setbypass_mode_value,
5283                 (void *)&cmd_setbypass_mode_port,
5284                 NULL,
5285         },
5286 };
5287
5288 /* *** SET NIC BYPASS EVENT *** */
5289 struct cmd_set_bypass_event_result {
5290         cmdline_fixed_string_t set;
5291         cmdline_fixed_string_t bypass;
5292         cmdline_fixed_string_t event;
5293         cmdline_fixed_string_t event_value;
5294         cmdline_fixed_string_t mode;
5295         cmdline_fixed_string_t mode_value;
5296         portid_t port_id;
5297 };
5298
5299 static void
5300 cmd_set_bypass_event_parsed(void *parsed_result,
5301                 __attribute__((unused)) struct cmdline *cl,
5302                 __attribute__((unused)) void *data)
5303 {
5304         int32_t rc = -EINVAL;
5305         struct cmd_set_bypass_event_result *res = parsed_result;
5306         portid_t port_id = res->port_id;
5307
5308 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5309         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5310         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5311
5312         if (!strcmp(res->event_value, "timeout"))
5313                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5314         else if (!strcmp(res->event_value, "os_on"))
5315                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5316         else if (!strcmp(res->event_value, "os_off"))
5317                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5318         else if (!strcmp(res->event_value, "power_on"))
5319                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5320         else if (!strcmp(res->event_value, "power_off"))
5321                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5322         else
5323                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5324
5325         if (!strcmp(res->mode_value, "bypass"))
5326                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5327         else if (!strcmp(res->mode_value, "isolate"))
5328                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5329         else
5330                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5331
5332         /* Set the watchdog timeout. */
5333         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5334
5335                 rc = -EINVAL;
5336                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5337                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5338                                                            bypass_timeout);
5339                 }
5340                 if (rc != 0) {
5341                         printf("Failed to set timeout value %u "
5342                         "for port %d, errto code: %d.\n",
5343                         bypass_timeout, port_id, rc);
5344                 }
5345         }
5346
5347         /* Set the bypass event to transition to bypass mode. */
5348         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5349                                               bypass_mode);
5350 #endif
5351
5352         if (rc != 0)
5353                 printf("\t Failed to set bypass event for port = %d.\n",
5354                        port_id);
5355 }
5356
5357 cmdline_parse_token_string_t cmd_setbypass_event_set =
5358         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5359                         set, "set");
5360 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5361         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5362                         bypass, "bypass");
5363 cmdline_parse_token_string_t cmd_setbypass_event_event =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5365                         event, "event");
5366 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5367         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5368                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5369 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5370         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5371                         mode, "mode");
5372 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5373         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5374                         mode_value, "normal#bypass#isolate");
5375 cmdline_parse_token_num_t cmd_setbypass_event_port =
5376         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5377                                 port_id, UINT16);
5378
5379 cmdline_parse_inst_t cmd_set_bypass_event = {
5380         .f = cmd_set_bypass_event_parsed,
5381         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5382                 "power_off mode normal|bypass|isolate <port_id>: "
5383                 "Set the NIC bypass event mode for port_id",
5384         .data = NULL,
5385         .tokens = {
5386                 (void *)&cmd_setbypass_event_set,
5387                 (void *)&cmd_setbypass_event_bypass,
5388                 (void *)&cmd_setbypass_event_event,
5389                 (void *)&cmd_setbypass_event_event_value,
5390                 (void *)&cmd_setbypass_event_mode,
5391                 (void *)&cmd_setbypass_event_mode_value,
5392                 (void *)&cmd_setbypass_event_port,
5393                 NULL,
5394         },
5395 };
5396
5397
5398 /* *** SET NIC BYPASS TIMEOUT *** */
5399 struct cmd_set_bypass_timeout_result {
5400         cmdline_fixed_string_t set;
5401         cmdline_fixed_string_t bypass;
5402         cmdline_fixed_string_t timeout;
5403         cmdline_fixed_string_t value;
5404 };
5405
5406 static void
5407 cmd_set_bypass_timeout_parsed(void *parsed_result,
5408                 __attribute__((unused)) struct cmdline *cl,
5409                 __attribute__((unused)) void *data)
5410 {
5411         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5412
5413 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5414         if (!strcmp(res->value, "1.5"))
5415                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5416         else if (!strcmp(res->value, "2"))
5417                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5418         else if (!strcmp(res->value, "3"))
5419                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5420         else if (!strcmp(res->value, "4"))
5421                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5422         else if (!strcmp(res->value, "8"))
5423                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5424         else if (!strcmp(res->value, "16"))
5425                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5426         else if (!strcmp(res->value, "32"))
5427                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5428         else
5429                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5430 #endif
5431 }
5432
5433 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5434         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5435                         set, "set");
5436 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5437         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5438                         bypass, "bypass");
5439 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5440         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5441                         timeout, "timeout");
5442 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5444                         value, "0#1.5#2#3#4#8#16#32");
5445
5446 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5447         .f = cmd_set_bypass_timeout_parsed,
5448         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5449                 "Set the NIC bypass watchdog timeout in seconds",
5450         .data = NULL,
5451         .tokens = {
5452                 (void *)&cmd_setbypass_timeout_set,
5453                 (void *)&cmd_setbypass_timeout_bypass,
5454                 (void *)&cmd_setbypass_timeout_timeout,
5455                 (void *)&cmd_setbypass_timeout_value,
5456                 NULL,
5457         },
5458 };
5459
5460 /* *** SHOW NIC BYPASS MODE *** */
5461 struct cmd_show_bypass_config_result {
5462         cmdline_fixed_string_t show;
5463         cmdline_fixed_string_t bypass;
5464         cmdline_fixed_string_t config;
5465         portid_t port_id;
5466 };
5467
5468 static void
5469 cmd_show_bypass_config_parsed(void *parsed_result,
5470                 __attribute__((unused)) struct cmdline *cl,
5471                 __attribute__((unused)) void *data)
5472 {
5473         struct cmd_show_bypass_config_result *res = parsed_result;
5474         portid_t port_id = res->port_id;
5475         int rc = -EINVAL;
5476 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5477         uint32_t event_mode;
5478         uint32_t bypass_mode;
5479         uint32_t timeout = bypass_timeout;
5480         int i;
5481
5482         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5483                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5484         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5485                 {"UNKNOWN", "normal", "bypass", "isolate"};
5486         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5487                 "NONE",
5488                 "OS/board on",
5489                 "power supply on",
5490                 "OS/board off",
5491                 "power supply off",
5492                 "timeout"};
5493         int num_events = (sizeof events) / (sizeof events[0]);
5494
5495         /* Display the bypass mode.*/
5496         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5497                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5498                 return;
5499         }
5500         else {
5501                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5502                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5503
5504                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5505         }
5506
5507         /* Display the bypass timeout.*/
5508         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5509                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5510
5511         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5512
5513         /* Display the bypass events and associated modes. */
5514         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5515
5516                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5517                         printf("\tFailed to get bypass mode for event = %s\n",
5518                                 events[i]);
5519                 } else {
5520                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5521                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5522
5523                         printf("\tbypass event: %-16s = %s\n", events[i],
5524                                 modes[event_mode]);
5525                 }
5526         }
5527 #endif
5528         if (rc != 0)
5529                 printf("\tFailed to get bypass configuration for port = %d\n",
5530                        port_id);
5531 }
5532
5533 cmdline_parse_token_string_t cmd_showbypass_config_show =
5534         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5535                         show, "show");
5536 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5537         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5538                         bypass, "bypass");
5539 cmdline_parse_token_string_t cmd_showbypass_config_config =
5540         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5541                         config, "config");
5542 cmdline_parse_token_num_t cmd_showbypass_config_port =
5543         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5544                                 port_id, UINT16);
5545
5546 cmdline_parse_inst_t cmd_show_bypass_config = {
5547         .f = cmd_show_bypass_config_parsed,
5548         .help_str = "show bypass config <port_id>: "
5549                     "Show the NIC bypass config for port_id",
5550         .data = NULL,
5551         .tokens = {
5552                 (void *)&cmd_showbypass_config_show,
5553                 (void *)&cmd_showbypass_config_bypass,
5554                 (void *)&cmd_showbypass_config_config,
5555                 (void *)&cmd_showbypass_config_port,
5556                 NULL,
5557         },
5558 };
5559
5560 #ifdef RTE_LIBRTE_PMD_BOND
5561 /* *** SET BONDING MODE *** */
5562 struct cmd_set_bonding_mode_result {
5563         cmdline_fixed_string_t set;
5564         cmdline_fixed_string_t bonding;
5565         cmdline_fixed_string_t mode;
5566         uint8_t value;
5567         portid_t port_id;
5568 };
5569
5570 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5571                 __attribute__((unused))  struct cmdline *cl,
5572                 __attribute__((unused)) void *data)
5573 {
5574         struct cmd_set_bonding_mode_result *res = parsed_result;
5575         portid_t port_id = res->port_id;
5576
5577         /* Set the bonding mode for the relevant port. */
5578         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5579                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5580 }
5581
5582 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5583 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5584                 set, "set");
5585 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5586 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5587                 bonding, "bonding");
5588 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5589 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5590                 mode, "mode");
5591 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5592 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5593                 value, UINT8);
5594 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5595 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5596                 port_id, UINT16);
5597
5598 cmdline_parse_inst_t cmd_set_bonding_mode = {
5599                 .f = cmd_set_bonding_mode_parsed,
5600                 .help_str = "set bonding mode <mode_value> <port_id>: "
5601                         "Set the bonding mode for port_id",
5602                 .data = NULL,
5603                 .tokens = {
5604                                 (void *) &cmd_setbonding_mode_set,
5605                                 (void *) &cmd_setbonding_mode_bonding,
5606                                 (void *) &cmd_setbonding_mode_mode,
5607                                 (void *) &cmd_setbonding_mode_value,
5608                                 (void *) &cmd_setbonding_mode_port,
5609                                 NULL
5610                 }
5611 };
5612
5613 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5614 struct cmd_set_bonding_lacp_dedicated_queues_result {
5615         cmdline_fixed_string_t set;
5616         cmdline_fixed_string_t bonding;
5617         cmdline_fixed_string_t lacp;
5618         cmdline_fixed_string_t dedicated_queues;
5619         portid_t port_id;
5620         cmdline_fixed_string_t mode;
5621 };
5622
5623 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5624                 __attribute__((unused))  struct cmdline *cl,
5625                 __attribute__((unused)) void *data)
5626 {
5627         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5628         portid_t port_id = res->port_id;
5629         struct rte_port *port;
5630
5631         port = &ports[port_id];
5632
5633         /** Check if the port is not started **/
5634         if (port->port_status != RTE_PORT_STOPPED) {
5635                 printf("Please stop port %d first\n", port_id);
5636                 return;
5637         }
5638
5639         if (!strcmp(res->mode, "enable")) {
5640                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5641                         printf("Dedicate queues for LACP control packets"
5642                                         " enabled\n");
5643                 else
5644                         printf("Enabling dedicate queues for LACP control "
5645                                         "packets on port %d failed\n", port_id);
5646         } else if (!strcmp(res->mode, "disable")) {
5647                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5648                         printf("Dedicated queues for LACP control packets "
5649                                         "disabled\n");
5650                 else
5651                         printf("Disabling dedicated queues for LACP control "
5652                                         "traffic on port %d failed\n", port_id);
5653         }
5654 }
5655
5656 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5657 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5658                 set, "set");
5659 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5660 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5661                 bonding, "bonding");
5662 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5663 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5664                 lacp, "lacp");
5665 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5666 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5667                 dedicated_queues, "dedicated_queues");
5668 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5669 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5670                 port_id, UINT16);
5671 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5672 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5673                 mode, "enable#disable");
5674
5675 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5676                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5677                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5678                         "enable|disable: "
5679                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5680                 .data = NULL,
5681                 .tokens = {
5682                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5683                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5684                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5685                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5686                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5687                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5688                         NULL
5689                 }
5690 };
5691
5692 /* *** SET BALANCE XMIT POLICY *** */
5693 struct cmd_set_bonding_balance_xmit_policy_result {
5694         cmdline_fixed_string_t set;
5695         cmdline_fixed_string_t bonding;
5696         cmdline_fixed_string_t balance_xmit_policy;
5697         portid_t port_id;
5698         cmdline_fixed_string_t policy;
5699 };
5700
5701 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5702                 __attribute__((unused))  struct cmdline *cl,
5703                 __attribute__((unused)) void *data)
5704 {
5705         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5706         portid_t port_id = res->port_id;
5707         uint8_t policy;
5708
5709         if (!strcmp(res->policy, "l2")) {
5710                 policy = BALANCE_XMIT_POLICY_LAYER2;
5711         } else if (!strcmp(res->policy, "l23")) {
5712                 policy = BALANCE_XMIT_POLICY_LAYER23;
5713         } else if (!strcmp(res->policy, "l34")) {
5714                 policy = BALANCE_XMIT_POLICY_LAYER34;
5715         } else {
5716                 printf("\t Invalid xmit policy selection");
5717                 return;
5718         }
5719
5720         /* Set the bonding mode for the relevant port. */
5721         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5722                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5723                                 port_id);
5724         }
5725 }
5726
5727 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5728 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5729                 set, "set");
5730 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5731 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5732                 bonding, "bonding");
5733 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5734 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5735                 balance_xmit_policy, "balance_xmit_policy");
5736 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5737 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5738                 port_id, UINT16);
5739 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5740 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5741                 policy, "l2#l23#l34");
5742
5743 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5744                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5745                 .help_str = "set bonding balance_xmit_policy <port_id> "
5746                         "l2|l23|l34: "
5747                         "Set the bonding balance_xmit_policy for port_id",
5748                 .data = NULL,
5749                 .tokens = {
5750                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5751                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5752                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5753                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5754                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5755                                 NULL
5756                 }
5757 };
5758
5759 /* *** SHOW NIC BONDING CONFIGURATION *** */
5760 struct cmd_show_bonding_config_result {
5761         cmdline_fixed_string_t show;
5762         cmdline_fixed_string_t bonding;
5763         cmdline_fixed_string_t config;
5764         portid_t port_id;
5765 };
5766
5767 static void cmd_show_bonding_config_parsed(void *parsed_result,
5768                 __attribute__((unused))  struct cmdline *cl,
5769                 __attribute__((unused)) void *data)
5770 {
5771         struct cmd_show_bonding_config_result *res = parsed_result;
5772         int bonding_mode, agg_mode;
5773         portid_t slaves[RTE_MAX_ETHPORTS];
5774         int num_slaves, num_active_slaves;
5775         int primary_id;
5776         int i;
5777         portid_t port_id = res->port_id;
5778
5779         /* Display the bonding mode.*/
5780         bonding_mode = rte_eth_bond_mode_get(port_id);
5781         if (bonding_mode < 0) {
5782                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5783                 return;
5784         } else
5785                 printf("\tBonding mode: %d\n", bonding_mode);
5786
5787         if (bonding_mode == BONDING_MODE_BALANCE) {
5788                 int balance_xmit_policy;
5789
5790                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5791                 if (balance_xmit_policy < 0) {
5792                         printf("\tFailed to get balance xmit policy for port = %d\n",
5793                                         port_id);
5794                         return;
5795                 } else {
5796                         printf("\tBalance Xmit Policy: ");
5797
5798                         switch (balance_xmit_policy) {
5799                         case BALANCE_XMIT_POLICY_LAYER2:
5800                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5801                                 break;
5802                         case BALANCE_XMIT_POLICY_LAYER23:
5803                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5804                                 break;
5805                         case BALANCE_XMIT_POLICY_LAYER34:
5806                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5807                                 break;
5808                         }
5809                         printf("\n");
5810                 }
5811         }
5812
5813         if (bonding_mode == BONDING_MODE_8023AD) {
5814                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5815                 printf("\tIEEE802.3AD Aggregator Mode: ");
5816                 switch (agg_mode) {
5817                 case AGG_BANDWIDTH:
5818                         printf("bandwidth");
5819                         break;
5820                 case AGG_STABLE:
5821                         printf("stable");
5822                         break;
5823                 case AGG_COUNT:
5824                         printf("count");
5825                         break;
5826                 }
5827                 printf("\n");
5828         }
5829
5830         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5831
5832         if (num_slaves < 0) {
5833                 printf("\tFailed to get slave list for port = %d\n", port_id);
5834                 return;
5835         }
5836         if (num_slaves > 0) {
5837                 printf("\tSlaves (%d): [", num_slaves);
5838                 for (i = 0; i < num_slaves - 1; i++)
5839                         printf("%d ", slaves[i]);
5840
5841                 printf("%d]\n", slaves[num_slaves - 1]);
5842         } else {
5843                 printf("\tSlaves: []\n");
5844
5845         }
5846
5847         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5848                         RTE_MAX_ETHPORTS);
5849
5850         if (num_active_slaves < 0) {
5851                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5852                 return;
5853         }
5854         if (num_active_slaves > 0) {
5855                 printf("\tActive Slaves (%d): [", num_active_slaves);
5856                 for (i = 0; i < num_active_slaves - 1; i++)
5857                         printf("%d ", slaves[i]);
5858
5859                 printf("%d]\n", slaves[num_active_slaves - 1]);
5860
5861         } else {
5862                 printf("\tActive Slaves: []\n");
5863
5864         }
5865
5866         primary_id = rte_eth_bond_primary_get(port_id);
5867         if (primary_id < 0) {
5868                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5869                 return;
5870         } else
5871                 printf("\tPrimary: [%d]\n", primary_id);
5872
5873 }
5874
5875 cmdline_parse_token_string_t cmd_showbonding_config_show =
5876 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5877                 show, "show");
5878 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5879 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5880                 bonding, "bonding");
5881 cmdline_parse_token_string_t cmd_showbonding_config_config =
5882 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5883                 config, "config");
5884 cmdline_parse_token_num_t cmd_showbonding_config_port =
5885 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5886                 port_id, UINT16);
5887
5888 cmdline_parse_inst_t cmd_show_bonding_config = {
5889                 .f = cmd_show_bonding_config_parsed,
5890                 .help_str = "show bonding config <port_id>: "
5891                         "Show the bonding config for port_id",
5892                 .data = NULL,
5893                 .tokens = {
5894                                 (void *)&cmd_showbonding_config_show,
5895                                 (void *)&cmd_showbonding_config_bonding,
5896                                 (void *)&cmd_showbonding_config_config,
5897                                 (void *)&cmd_showbonding_config_port,
5898                                 NULL
5899                 }
5900 };
5901
5902 /* *** SET BONDING PRIMARY *** */
5903 struct cmd_set_bonding_primary_result {
5904         cmdline_fixed_string_t set;
5905         cmdline_fixed_string_t bonding;
5906         cmdline_fixed_string_t primary;
5907         portid_t slave_id;
5908         portid_t port_id;
5909 };
5910
5911 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5912                 __attribute__((unused))  struct cmdline *cl,
5913                 __attribute__((unused)) void *data)
5914 {
5915         struct cmd_set_bonding_primary_result *res = parsed_result;
5916         portid_t master_port_id = res->port_id;
5917         portid_t slave_port_id = res->slave_id;
5918
5919         /* Set the primary slave for a bonded device. */
5920         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5921                 printf("\t Failed to set primary slave for port = %d.\n",
5922                                 master_port_id);
5923                 return;
5924         }
5925         init_port_config();
5926 }
5927
5928 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5929 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5930                 set, "set");
5931 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5932 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5933                 bonding, "bonding");
5934 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5935 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5936                 primary, "primary");
5937 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5938 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5939                 slave_id, UINT16);
5940 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5941 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5942                 port_id, UINT16);
5943
5944 cmdline_parse_inst_t cmd_set_bonding_primary = {
5945                 .f = cmd_set_bonding_primary_parsed,
5946                 .help_str = "set bonding primary <slave_id> <port_id>: "
5947                         "Set the primary slave for port_id",
5948                 .data = NULL,
5949                 .tokens = {
5950                                 (void *)&cmd_setbonding_primary_set,
5951                                 (void *)&cmd_setbonding_primary_bonding,
5952                                 (void *)&cmd_setbonding_primary_primary,
5953                                 (void *)&cmd_setbonding_primary_slave,
5954                                 (void *)&cmd_setbonding_primary_port,
5955                                 NULL
5956                 }
5957 };
5958
5959 /* *** ADD SLAVE *** */
5960 struct cmd_add_bonding_slave_result {
5961         cmdline_fixed_string_t add;
5962         cmdline_fixed_string_t bonding;
5963         cmdline_fixed_string_t slave;
5964         portid_t slave_id;
5965         portid_t port_id;
5966 };
5967
5968 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5969                 __attribute__((unused))  struct cmdline *cl,
5970                 __attribute__((unused)) void *data)
5971 {
5972         struct cmd_add_bonding_slave_result *res = parsed_result;
5973         portid_t master_port_id = res->port_id;
5974         portid_t slave_port_id = res->slave_id;
5975
5976         /* add the slave for a bonded device. */
5977         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5978                 printf("\t Failed to add slave %d to master port = %d.\n",
5979                                 slave_port_id, master_port_id);
5980                 return;
5981         }
5982         init_port_config();
5983         set_port_slave_flag(slave_port_id);
5984 }
5985
5986 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5987 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5988                 add, "add");
5989 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5990 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5991                 bonding, "bonding");
5992 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5993 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5994                 slave, "slave");
5995 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5996 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5997                 slave_id, UINT16);
5998 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5999 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6000                 port_id, UINT16);
6001
6002 cmdline_parse_inst_t cmd_add_bonding_slave = {
6003                 .f = cmd_add_bonding_slave_parsed,
6004                 .help_str = "add bonding slave <slave_id> <port_id>: "
6005                         "Add a slave device to a bonded device",
6006                 .data = NULL,
6007                 .tokens = {
6008                                 (void *)&cmd_addbonding_slave_add,
6009                                 (void *)&cmd_addbonding_slave_bonding,
6010                                 (void *)&cmd_addbonding_slave_slave,
6011                                 (void *)&cmd_addbonding_slave_slaveid,
6012                                 (void *)&cmd_addbonding_slave_port,
6013                                 NULL
6014                 }
6015 };
6016
6017 /* *** REMOVE SLAVE *** */
6018 struct cmd_remove_bonding_slave_result {
6019         cmdline_fixed_string_t remove;
6020         cmdline_fixed_string_t bonding;
6021         cmdline_fixed_string_t slave;
6022         portid_t slave_id;
6023         portid_t port_id;
6024 };
6025
6026 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6027                 __attribute__((unused))  struct cmdline *cl,
6028                 __attribute__((unused)) void *data)
6029 {
6030         struct cmd_remove_bonding_slave_result *res = parsed_result;
6031         portid_t master_port_id = res->port_id;
6032         portid_t slave_port_id = res->slave_id;
6033
6034         /* remove the slave from a bonded device. */
6035         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6036                 printf("\t Failed to remove slave %d from master port = %d.\n",
6037                                 slave_port_id, master_port_id);
6038                 return;
6039         }
6040         init_port_config();
6041         clear_port_slave_flag(slave_port_id);
6042 }
6043
6044 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6045                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6046                                 remove, "remove");
6047 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6048                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6049                                 bonding, "bonding");
6050 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6051                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6052                                 slave, "slave");
6053 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6054                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6055                                 slave_id, UINT16);
6056 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6057                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6058                                 port_id, UINT16);
6059
6060 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6061                 .f = cmd_remove_bonding_slave_parsed,
6062                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6063                         "Remove a slave device from a bonded device",
6064                 .data = NULL,
6065                 .tokens = {
6066                                 (void *)&cmd_removebonding_slave_remove,
6067                                 (void *)&cmd_removebonding_slave_bonding,
6068                                 (void *)&cmd_removebonding_slave_slave,
6069                                 (void *)&cmd_removebonding_slave_slaveid,
6070                                 (void *)&cmd_removebonding_slave_port,
6071                                 NULL
6072                 }
6073 };
6074
6075 /* *** CREATE BONDED DEVICE *** */
6076 struct cmd_create_bonded_device_result {
6077         cmdline_fixed_string_t create;
6078         cmdline_fixed_string_t bonded;
6079         cmdline_fixed_string_t device;
6080         uint8_t mode;
6081         uint8_t socket;
6082 };
6083
6084 static int bond_dev_num = 0;
6085
6086 static void cmd_create_bonded_device_parsed(void *parsed_result,
6087                 __attribute__((unused))  struct cmdline *cl,
6088                 __attribute__((unused)) void *data)
6089 {
6090         struct cmd_create_bonded_device_result *res = parsed_result;
6091         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6092         int port_id;
6093         int ret;
6094
6095         if (test_done == 0) {
6096                 printf("Please stop forwarding first\n");
6097                 return;
6098         }
6099
6100         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6101                         bond_dev_num++);
6102
6103         /* Create a new bonded device. */
6104         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6105         if (port_id < 0) {
6106                 printf("\t Failed to create bonded device.\n");
6107                 return;
6108         } else {
6109                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6110                                 port_id);
6111
6112                 /* Update number of ports */
6113                 nb_ports = rte_eth_dev_count_avail();
6114                 reconfig(port_id, res->socket);
6115                 ret = rte_eth_promiscuous_enable(port_id);
6116                 if (ret != 0)
6117                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6118                                 port_id, rte_strerror(-ret));
6119
6120                 ports[port_id].need_setup = 0;
6121                 ports[port_id].port_status = RTE_PORT_STOPPED;
6122         }
6123
6124 }
6125
6126 cmdline_parse_token_string_t cmd_createbonded_device_create =
6127                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6128                                 create, "create");
6129 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6130                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6131                                 bonded, "bonded");
6132 cmdline_parse_token_string_t cmd_createbonded_device_device =
6133                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6134                                 device, "device");
6135 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6136                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6137                                 mode, UINT8);
6138 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6139                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6140                                 socket, UINT8);
6141
6142 cmdline_parse_inst_t cmd_create_bonded_device = {
6143                 .f = cmd_create_bonded_device_parsed,
6144                 .help_str = "create bonded device <mode> <socket>: "
6145                         "Create a new bonded device with specific bonding mode and socket",
6146                 .data = NULL,
6147                 .tokens = {
6148                                 (void *)&cmd_createbonded_device_create,
6149                                 (void *)&cmd_createbonded_device_bonded,
6150                                 (void *)&cmd_createbonded_device_device,
6151                                 (void *)&cmd_createbonded_device_mode,
6152                                 (void *)&cmd_createbonded_device_socket,
6153                                 NULL
6154                 }
6155 };
6156
6157 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6158 struct cmd_set_bond_mac_addr_result {
6159         cmdline_fixed_string_t set;
6160         cmdline_fixed_string_t bonding;
6161         cmdline_fixed_string_t mac_addr;
6162         uint16_t port_num;
6163         struct rte_ether_addr address;
6164 };
6165
6166 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6167                 __attribute__((unused))  struct cmdline *cl,
6168                 __attribute__((unused)) void *data)
6169 {
6170         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6171         int ret;
6172
6173         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6174                 return;
6175
6176         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6177
6178         /* check the return value and print it if is < 0 */
6179         if (ret < 0)
6180                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6181 }
6182
6183 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6184                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6185 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6186                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6187                                 "bonding");
6188 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6189                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6190                                 "mac_addr");
6191 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6192                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6193                                 port_num, UINT16);
6194 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6195                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6196
6197 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6198                 .f = cmd_set_bond_mac_addr_parsed,
6199                 .data = (void *) 0,
6200                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6201                 .tokens = {
6202                                 (void *)&cmd_set_bond_mac_addr_set,
6203                                 (void *)&cmd_set_bond_mac_addr_bonding,
6204                                 (void *)&cmd_set_bond_mac_addr_mac,
6205                                 (void *)&cmd_set_bond_mac_addr_portnum,
6206                                 (void *)&cmd_set_bond_mac_addr_addr,
6207                                 NULL
6208                 }
6209 };
6210
6211
6212 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6213 struct cmd_set_bond_mon_period_result {
6214         cmdline_fixed_string_t set;
6215         cmdline_fixed_string_t bonding;
6216         cmdline_fixed_string_t mon_period;
6217         uint16_t port_num;
6218         uint32_t period_ms;
6219 };
6220
6221 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6222                 __attribute__((unused))  struct cmdline *cl,
6223                 __attribute__((unused)) void *data)
6224 {
6225         struct cmd_set_bond_mon_period_result *res = parsed_result;
6226         int ret;
6227
6228         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6229
6230         /* check the return value and print it if is < 0 */
6231         if (ret < 0)
6232                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6233 }
6234
6235 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6236                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6237                                 set, "set");
6238 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6239                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6240                                 bonding, "bonding");
6241 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6242                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6243                                 mon_period,     "mon_period");
6244 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6245                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6246                                 port_num, UINT16);
6247 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6248                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6249                                 period_ms, UINT32);
6250
6251 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6252                 .f = cmd_set_bond_mon_period_parsed,
6253                 .data = (void *) 0,
6254                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6255                 .tokens = {
6256                                 (void *)&cmd_set_bond_mon_period_set,
6257                                 (void *)&cmd_set_bond_mon_period_bonding,
6258                                 (void *)&cmd_set_bond_mon_period_mon_period,
6259                                 (void *)&cmd_set_bond_mon_period_portnum,
6260                                 (void *)&cmd_set_bond_mon_period_period_ms,
6261                                 NULL
6262                 }
6263 };
6264
6265
6266
6267 struct cmd_set_bonding_agg_mode_policy_result {
6268         cmdline_fixed_string_t set;
6269         cmdline_fixed_string_t bonding;
6270         cmdline_fixed_string_t agg_mode;
6271         uint16_t port_num;
6272         cmdline_fixed_string_t policy;
6273 };
6274
6275
6276 static void
6277 cmd_set_bonding_agg_mode(void *parsed_result,
6278                 __attribute__((unused)) struct cmdline *cl,
6279                 __attribute__((unused)) void *data)
6280 {
6281         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6282         uint8_t policy = AGG_BANDWIDTH;
6283
6284         if (!strcmp(res->policy, "bandwidth"))
6285                 policy = AGG_BANDWIDTH;
6286         else if (!strcmp(res->policy, "stable"))
6287                 policy = AGG_STABLE;
6288         else if (!strcmp(res->policy, "count"))
6289                 policy = AGG_COUNT;
6290
6291         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6292 }
6293
6294
6295 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6296         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6297                                 set, "set");
6298 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6299         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6300                                 bonding, "bonding");
6301
6302 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6303         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6304                                 agg_mode, "agg_mode");
6305
6306 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6307         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6308                                 port_num, UINT16);
6309
6310 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6311         TOKEN_STRING_INITIALIZER(
6312                         struct cmd_set_bonding_balance_xmit_policy_result,
6313                 policy, "stable#bandwidth#count");
6314
6315 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6316         .f = cmd_set_bonding_agg_mode,
6317         .data = (void *) 0,
6318         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6319         .tokens = {
6320                         (void *)&cmd_set_bonding_agg_mode_set,
6321                         (void *)&cmd_set_bonding_agg_mode_bonding,
6322                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6323                         (void *)&cmd_set_bonding_agg_mode_portnum,
6324                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6325                         NULL
6326                 }
6327 };
6328
6329
6330 #endif /* RTE_LIBRTE_PMD_BOND */
6331
6332 /* *** SET FORWARDING MODE *** */
6333 struct cmd_set_fwd_mode_result {
6334         cmdline_fixed_string_t set;
6335         cmdline_fixed_string_t fwd;
6336         cmdline_fixed_string_t mode;
6337 };
6338
6339 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6340                                     __attribute__((unused)) struct cmdline *cl,
6341                                     __attribute__((unused)) void *data)
6342 {
6343         struct cmd_set_fwd_mode_result *res = parsed_result;
6344
6345         retry_enabled = 0;
6346         set_pkt_forwarding_mode(res->mode);
6347 }
6348
6349 cmdline_parse_token_string_t cmd_setfwd_set =
6350         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6351 cmdline_parse_token_string_t cmd_setfwd_fwd =
6352         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6353 cmdline_parse_token_string_t cmd_setfwd_mode =
6354         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6355                 "" /* defined at init */);
6356
6357 cmdline_parse_inst_t cmd_set_fwd_mode = {
6358         .f = cmd_set_fwd_mode_parsed,
6359         .data = NULL,
6360         .help_str = NULL, /* defined at init */
6361         .tokens = {
6362                 (void *)&cmd_setfwd_set,
6363                 (void *)&cmd_setfwd_fwd,
6364                 (void *)&cmd_setfwd_mode,
6365                 NULL,
6366         },
6367 };
6368
6369 static void cmd_set_fwd_mode_init(void)
6370 {
6371         char *modes, *c;
6372         static char token[128];
6373         static char help[256];
6374         cmdline_parse_token_string_t *token_struct;
6375
6376         modes = list_pkt_forwarding_modes();
6377         snprintf(help, sizeof(help), "set fwd %s: "
6378                 "Set packet forwarding mode", modes);
6379         cmd_set_fwd_mode.help_str = help;
6380
6381         /* string token separator is # */
6382         for (c = token; *modes != '\0'; modes++)
6383                 if (*modes == '|')
6384                         *c++ = '#';
6385                 else
6386                         *c++ = *modes;
6387         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6388         token_struct->string_data.str = token;
6389 }
6390
6391 /* *** SET RETRY FORWARDING MODE *** */
6392 struct cmd_set_fwd_retry_mode_result {
6393         cmdline_fixed_string_t set;
6394         cmdline_fixed_string_t fwd;
6395         cmdline_fixed_string_t mode;
6396         cmdline_fixed_string_t retry;
6397 };
6398
6399 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6400                             __attribute__((unused)) struct cmdline *cl,
6401                             __attribute__((unused)) void *data)
6402 {
6403         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6404
6405         retry_enabled = 1;
6406         set_pkt_forwarding_mode(res->mode);
6407 }
6408
6409 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6410         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6411                         set, "set");
6412 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6413         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6414                         fwd, "fwd");
6415 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6416         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6417                         mode,
6418                 "" /* defined at init */);
6419 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6420         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6421                         retry, "retry");
6422
6423 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6424         .f = cmd_set_fwd_retry_mode_parsed,
6425         .data = NULL,
6426         .help_str = NULL, /* defined at init */
6427         .tokens = {
6428                 (void *)&cmd_setfwd_retry_set,
6429                 (void *)&cmd_setfwd_retry_fwd,
6430                 (void *)&cmd_setfwd_retry_mode,
6431                 (void *)&cmd_setfwd_retry_retry,
6432                 NULL,
6433         },
6434 };
6435
6436 static void cmd_set_fwd_retry_mode_init(void)
6437 {
6438         char *modes, *c;
6439         static char token[128];
6440         static char help[256];
6441         cmdline_parse_token_string_t *token_struct;
6442
6443         modes = list_pkt_forwarding_retry_modes();
6444         snprintf(help, sizeof(help), "set fwd %s retry: "
6445                 "Set packet forwarding mode with retry", modes);
6446         cmd_set_fwd_retry_mode.help_str = help;
6447
6448         /* string token separator is # */
6449         for (c = token; *modes != '\0'; modes++)
6450                 if (*modes == '|')
6451                         *c++ = '#';
6452                 else
6453                         *c++ = *modes;
6454         token_struct = (cmdline_parse_token_string_t *)
6455                 cmd_set_fwd_retry_mode.tokens[2];
6456         token_struct->string_data.str = token;
6457 }
6458
6459 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6460 struct cmd_set_burst_tx_retry_result {
6461         cmdline_fixed_string_t set;
6462         cmdline_fixed_string_t burst;
6463         cmdline_fixed_string_t tx;
6464         cmdline_fixed_string_t delay;
6465         uint32_t time;
6466         cmdline_fixed_string_t retry;
6467         uint32_t retry_num;
6468 };
6469
6470 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6471                                         __attribute__((unused)) struct cmdline *cl,
6472                                         __attribute__((unused)) void *data)
6473 {
6474         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6475
6476         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6477                 && !strcmp(res->tx, "tx")) {
6478                 if (!strcmp(res->delay, "delay"))
6479                         burst_tx_delay_time = res->time;
6480                 if (!strcmp(res->retry, "retry"))
6481                         burst_tx_retry_num = res->retry_num;
6482         }
6483
6484 }
6485
6486 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6487         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6488 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6489         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6490                                  "burst");
6491 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6492         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6493 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6494         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6495 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6496         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6497 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6498         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6499 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6500         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6501
6502 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6503         .f = cmd_set_burst_tx_retry_parsed,
6504         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6505         .tokens = {
6506                 (void *)&cmd_set_burst_tx_retry_set,
6507                 (void *)&cmd_set_burst_tx_retry_burst,
6508                 (void *)&cmd_set_burst_tx_retry_tx,
6509                 (void *)&cmd_set_burst_tx_retry_delay,
6510                 (void *)&cmd_set_burst_tx_retry_time,
6511                 (void *)&cmd_set_burst_tx_retry_retry,
6512                 (void *)&cmd_set_burst_tx_retry_retry_num,
6513                 NULL,
6514         },
6515 };
6516
6517 /* *** SET PROMISC MODE *** */
6518 struct cmd_set_promisc_mode_result {
6519         cmdline_fixed_string_t set;
6520         cmdline_fixed_string_t promisc;
6521         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6522         uint16_t port_num;               /* valid if "allports" argument == 0 */
6523         cmdline_fixed_string_t mode;
6524 };
6525
6526 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6527                                         __attribute__((unused)) struct cmdline *cl,
6528                                         void *allports)
6529 {
6530         struct cmd_set_promisc_mode_result *res = parsed_result;
6531         int enable;
6532         portid_t i;
6533
6534         if (!strcmp(res->mode, "on"))
6535                 enable = 1;
6536         else
6537                 enable = 0;
6538
6539         /* all ports */
6540         if (allports) {
6541                 RTE_ETH_FOREACH_DEV(i)
6542                         eth_set_promisc_mode(i, enable);
6543         } else {
6544                 eth_set_promisc_mode(res->port_num, enable);
6545         }
6546 }
6547
6548 cmdline_parse_token_string_t cmd_setpromisc_set =
6549         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6550 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6551         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6552                                  "promisc");
6553 cmdline_parse_token_string_t cmd_setpromisc_portall =
6554         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6555                                  "all");
6556 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6557         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6558                               UINT16);
6559 cmdline_parse_token_string_t cmd_setpromisc_mode =
6560         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6561                                  "on#off");
6562
6563 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6564         .f = cmd_set_promisc_mode_parsed,
6565         .data = (void *)1,
6566         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6567         .tokens = {
6568                 (void *)&cmd_setpromisc_set,
6569                 (void *)&cmd_setpromisc_promisc,
6570                 (void *)&cmd_setpromisc_portall,
6571                 (void *)&cmd_setpromisc_mode,
6572                 NULL,
6573         },
6574 };
6575
6576 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6577         .f = cmd_set_promisc_mode_parsed,
6578         .data = (void *)0,
6579         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6580         .tokens = {
6581                 (void *)&cmd_setpromisc_set,
6582                 (void *)&cmd_setpromisc_promisc,
6583                 (void *)&cmd_setpromisc_portnum,
6584                 (void *)&cmd_setpromisc_mode,
6585                 NULL,
6586         },
6587 };
6588
6589 /* *** SET ALLMULTI MODE *** */
6590 struct cmd_set_allmulti_mode_result {
6591         cmdline_fixed_string_t set;
6592         cmdline_fixed_string_t allmulti;
6593         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6594         uint16_t port_num;               /* valid if "allports" argument == 0 */
6595         cmdline_fixed_string_t mode;
6596 };
6597
6598 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6599                                         __attribute__((unused)) struct cmdline *cl,
6600                                         void *allports)
6601 {
6602         struct cmd_set_allmulti_mode_result *res = parsed_result;
6603         int enable;
6604         portid_t i;
6605
6606         if (!strcmp(res->mode, "on"))
6607                 enable = 1;
6608         else
6609                 enable = 0;
6610
6611         /* all ports */
6612         if (allports) {
6613                 RTE_ETH_FOREACH_DEV(i) {
6614                         eth_set_allmulticast_mode(i, enable);
6615                 }
6616         }
6617         else {
6618                 eth_set_allmulticast_mode(res->port_num, enable);
6619         }
6620 }
6621
6622 cmdline_parse_token_string_t cmd_setallmulti_set =
6623         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6624 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6625         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6626                                  "allmulti");
6627 cmdline_parse_token_string_t cmd_setallmulti_portall =
6628         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6629                                  "all");
6630 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6631         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6632                               UINT16);
6633 cmdline_parse_token_string_t cmd_setallmulti_mode =
6634         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6635                                  "on#off");
6636
6637 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6638         .f = cmd_set_allmulti_mode_parsed,
6639         .data = (void *)1,
6640         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6641         .tokens = {
6642                 (void *)&cmd_setallmulti_set,
6643                 (void *)&cmd_setallmulti_allmulti,
6644                 (void *)&cmd_setallmulti_portall,
6645                 (void *)&cmd_setallmulti_mode,
6646                 NULL,
6647         },
6648 };
6649
6650 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6651         .f = cmd_set_allmulti_mode_parsed,
6652         .data = (void *)0,
6653         .help_str = "set allmulti <port_id> on|off: "
6654                 "Set allmulti mode on port_id",
6655         .tokens = {
6656                 (void *)&cmd_setallmulti_set,
6657                 (void *)&cmd_setallmulti_allmulti,
6658                 (void *)&cmd_setallmulti_portnum,
6659                 (void *)&cmd_setallmulti_mode,
6660                 NULL,
6661         },
6662 };
6663
6664 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6665 struct cmd_link_flow_ctrl_set_result {
6666         cmdline_fixed_string_t set;
6667         cmdline_fixed_string_t flow_ctrl;
6668         cmdline_fixed_string_t rx;
6669         cmdline_fixed_string_t rx_lfc_mode;
6670         cmdline_fixed_string_t tx;
6671         cmdline_fixed_string_t tx_lfc_mode;
6672         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6673         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6674         cmdline_fixed_string_t autoneg_str;
6675         cmdline_fixed_string_t autoneg;
6676         cmdline_fixed_string_t hw_str;
6677         uint32_t high_water;
6678         cmdline_fixed_string_t lw_str;
6679         uint32_t low_water;
6680         cmdline_fixed_string_t pt_str;
6681         uint16_t pause_time;
6682         cmdline_fixed_string_t xon_str;
6683         uint16_t send_xon;
6684         portid_t port_id;
6685 };
6686
6687 cmdline_parse_token_string_t cmd_lfc_set_set =
6688         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6689                                 set, "set");
6690 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6691         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6692                                 flow_ctrl, "flow_ctrl");
6693 cmdline_parse_token_string_t cmd_lfc_set_rx =
6694         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6695                                 rx, "rx");
6696 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6697         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6698                                 rx_lfc_mode, "on#off");
6699 cmdline_parse_token_string_t cmd_lfc_set_tx =
6700         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6701                                 tx, "tx");
6702 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6703         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6704                                 tx_lfc_mode, "on#off");
6705 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6706         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6707                                 hw_str, "high_water");
6708 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6709         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6710                                 high_water, UINT32);
6711 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6712         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6713                                 lw_str, "low_water");
6714 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6715         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6716                                 low_water, UINT32);
6717 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6718         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6719                                 pt_str, "pause_time");
6720 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6721         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6722                                 pause_time, UINT16);
6723 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6724         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6725                                 xon_str, "send_xon");
6726 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6727         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6728                                 send_xon, UINT16);
6729 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6730         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6731                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6732 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6733         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6734                                 mac_ctrl_frame_fwd_mode, "on#off");
6735 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6736         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6737                                 autoneg_str, "autoneg");
6738 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6739         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6740                                 autoneg, "on#off");
6741 cmdline_parse_token_num_t cmd_lfc_set_portid =
6742         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6743                                 port_id, UINT16);
6744
6745 /* forward declaration */
6746 static void
6747 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6748                               void *data);
6749
6750 cmdline_parse_inst_t cmd_link_flow_control_set = {
6751         .f = cmd_link_flow_ctrl_set_parsed,
6752         .data = NULL,
6753         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6754                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6755                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6756         .tokens = {
6757                 (void *)&cmd_lfc_set_set,
6758                 (void *)&cmd_lfc_set_flow_ctrl,
6759                 (void *)&cmd_lfc_set_rx,
6760                 (void *)&cmd_lfc_set_rx_mode,
6761                 (void *)&cmd_lfc_set_tx,
6762                 (void *)&cmd_lfc_set_tx_mode,
6763                 (void *)&cmd_lfc_set_high_water,
6764                 (void *)&cmd_lfc_set_low_water,
6765                 (void *)&cmd_lfc_set_pause_time,
6766                 (void *)&cmd_lfc_set_send_xon,
6767                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6768                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6769                 (void *)&cmd_lfc_set_autoneg_str,
6770                 (void *)&cmd_lfc_set_autoneg,
6771                 (void *)&cmd_lfc_set_portid,
6772                 NULL,
6773         },
6774 };
6775
6776 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6777         .f = cmd_link_flow_ctrl_set_parsed,
6778         .data = (void *)&cmd_link_flow_control_set_rx,
6779         .help_str = "set flow_ctrl rx on|off <port_id>: "
6780                 "Change rx flow control parameter",
6781         .tokens = {
6782                 (void *)&cmd_lfc_set_set,
6783                 (void *)&cmd_lfc_set_flow_ctrl,
6784                 (void *)&cmd_lfc_set_rx,
6785                 (void *)&cmd_lfc_set_rx_mode,
6786                 (void *)&cmd_lfc_set_portid,
6787                 NULL,
6788         },
6789 };
6790
6791 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6792         .f = cmd_link_flow_ctrl_set_parsed,
6793         .data = (void *)&cmd_link_flow_control_set_tx,
6794         .help_str = "set flow_ctrl tx on|off <port_id>: "
6795                 "Change tx flow control parameter",
6796         .tokens = {
6797                 (void *)&cmd_lfc_set_set,
6798                 (void *)&cmd_lfc_set_flow_ctrl,
6799                 (void *)&cmd_lfc_set_tx,
6800                 (void *)&cmd_lfc_set_tx_mode,
6801                 (void *)&cmd_lfc_set_portid,
6802                 NULL,
6803         },
6804 };
6805
6806 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6807         .f = cmd_link_flow_ctrl_set_parsed,
6808         .data = (void *)&cmd_link_flow_control_set_hw,
6809         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6810                 "Change high water flow control parameter",
6811         .tokens = {
6812                 (void *)&cmd_lfc_set_set,
6813                 (void *)&cmd_lfc_set_flow_ctrl,
6814                 (void *)&cmd_lfc_set_high_water_str,
6815                 (void *)&cmd_lfc_set_high_water,
6816                 (void *)&cmd_lfc_set_portid,
6817                 NULL,
6818         },
6819 };
6820
6821 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6822         .f = cmd_link_flow_ctrl_set_parsed,
6823         .data = (void *)&cmd_link_flow_control_set_lw,
6824         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6825                 "Change low water flow control parameter",
6826         .tokens = {
6827                 (void *)&cmd_lfc_set_set,
6828                 (void *)&cmd_lfc_set_flow_ctrl,
6829                 (void *)&cmd_lfc_set_low_water_str,
6830                 (void *)&cmd_lfc_set_low_water,
6831                 (void *)&cmd_lfc_set_portid,
6832                 NULL,
6833         },
6834 };
6835
6836 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6837         .f = cmd_link_flow_ctrl_set_parsed,
6838         .data = (void *)&cmd_link_flow_control_set_pt,
6839         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6840                 "Change pause time flow control parameter",
6841         .tokens = {
6842                 (void *)&cmd_lfc_set_set,
6843                 (void *)&cmd_lfc_set_flow_ctrl,
6844                 (void *)&cmd_lfc_set_pause_time_str,
6845                 (void *)&cmd_lfc_set_pause_time,
6846                 (void *)&cmd_lfc_set_portid,
6847                 NULL,
6848         },
6849 };
6850
6851 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6852         .f = cmd_link_flow_ctrl_set_parsed,
6853         .data = (void *)&cmd_link_flow_control_set_xon,
6854         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6855                 "Change send_xon flow control parameter",
6856         .tokens = {
6857                 (void *)&cmd_lfc_set_set,
6858                 (void *)&cmd_lfc_set_flow_ctrl,
6859                 (void *)&cmd_lfc_set_send_xon_str,
6860                 (void *)&cmd_lfc_set_send_xon,
6861                 (void *)&cmd_lfc_set_portid,
6862                 NULL,
6863         },
6864 };
6865
6866 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6867         .f = cmd_link_flow_ctrl_set_parsed,
6868         .data = (void *)&cmd_link_flow_control_set_macfwd,
6869         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6870                 "Change mac ctrl fwd flow control parameter",
6871         .tokens = {
6872                 (void *)&cmd_lfc_set_set,
6873                 (void *)&cmd_lfc_set_flow_ctrl,
6874                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6875                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6876                 (void *)&cmd_lfc_set_portid,
6877                 NULL,
6878         },
6879 };
6880
6881 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6882         .f = cmd_link_flow_ctrl_set_parsed,
6883         .data = (void *)&cmd_link_flow_control_set_autoneg,
6884         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6885                 "Change autoneg flow control parameter",
6886         .tokens = {
6887                 (void *)&cmd_lfc_set_set,
6888                 (void *)&cmd_lfc_set_flow_ctrl,
6889                 (void *)&cmd_lfc_set_autoneg_str,
6890                 (void *)&cmd_lfc_set_autoneg,
6891                 (void *)&cmd_lfc_set_portid,
6892                 NULL,
6893         },
6894 };
6895
6896 static void
6897 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6898                               __attribute__((unused)) struct cmdline *cl,
6899                               void *data)
6900 {
6901         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6902         cmdline_parse_inst_t *cmd = data;
6903         struct rte_eth_fc_conf fc_conf;
6904         int rx_fc_en = 0;
6905         int tx_fc_en = 0;
6906         int ret;
6907
6908         /*
6909          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6910          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6911          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6912          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6913          */
6914         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6915                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6916         };
6917
6918         /* Partial command line, retrieve current configuration */
6919         if (cmd) {
6920                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6921                 if (ret != 0) {
6922                         printf("cannot get current flow ctrl parameters, return"
6923                                "code = %d\n", ret);
6924                         return;
6925                 }
6926
6927                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6928                     (fc_conf.mode == RTE_FC_FULL))
6929                         rx_fc_en = 1;
6930                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6931                     (fc_conf.mode == RTE_FC_FULL))
6932                         tx_fc_en = 1;
6933         }
6934
6935         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6936                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6937
6938         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6939                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6940
6941         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6942
6943         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6944                 fc_conf.high_water = res->high_water;
6945
6946         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6947                 fc_conf.low_water = res->low_water;
6948
6949         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6950                 fc_conf.pause_time = res->pause_time;
6951
6952         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6953                 fc_conf.send_xon = res->send_xon;
6954
6955         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6956                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6957                         fc_conf.mac_ctrl_frame_fwd = 1;
6958                 else
6959                         fc_conf.mac_ctrl_frame_fwd = 0;
6960         }
6961
6962         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6963                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6964
6965         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6966         if (ret != 0)
6967                 printf("bad flow contrl parameter, return code = %d \n", ret);
6968 }
6969
6970 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6971 struct cmd_priority_flow_ctrl_set_result {
6972         cmdline_fixed_string_t set;
6973         cmdline_fixed_string_t pfc_ctrl;
6974         cmdline_fixed_string_t rx;
6975         cmdline_fixed_string_t rx_pfc_mode;
6976         cmdline_fixed_string_t tx;
6977         cmdline_fixed_string_t tx_pfc_mode;
6978         uint32_t high_water;
6979         uint32_t low_water;
6980         uint16_t pause_time;
6981         uint8_t  priority;
6982         portid_t port_id;
6983 };
6984
6985 static void
6986 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6987                        __attribute__((unused)) struct cmdline *cl,
6988                        __attribute__((unused)) void *data)
6989 {
6990         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6991         struct rte_eth_pfc_conf pfc_conf;
6992         int rx_fc_enable, tx_fc_enable;
6993         int ret;
6994
6995         /*
6996          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6997          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6998          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6999          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7000          */
7001         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7002                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7003         };
7004
7005         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7006         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7007         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7008         pfc_conf.fc.high_water = res->high_water;
7009         pfc_conf.fc.low_water  = res->low_water;
7010         pfc_conf.fc.pause_time = res->pause_time;
7011         pfc_conf.priority      = res->priority;
7012
7013         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7014         if (ret != 0)
7015                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7016 }
7017
7018 cmdline_parse_token_string_t cmd_pfc_set_set =
7019         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7020                                 set, "set");
7021 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7022         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7023                                 pfc_ctrl, "pfc_ctrl");
7024 cmdline_parse_token_string_t cmd_pfc_set_rx =
7025         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7026                                 rx, "rx");
7027 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7028         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7029                                 rx_pfc_mode, "on#off");
7030 cmdline_parse_token_string_t cmd_pfc_set_tx =
7031         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7032                                 tx, "tx");
7033 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7034         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7035                                 tx_pfc_mode, "on#off");
7036 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7037         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7038                                 high_water, UINT32);
7039 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7040         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7041                                 low_water, UINT32);
7042 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7043         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7044                                 pause_time, UINT16);
7045 cmdline_parse_token_num_t cmd_pfc_set_priority =
7046         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7047                                 priority, UINT8);
7048 cmdline_parse_token_num_t cmd_pfc_set_portid =
7049         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7050                                 port_id, UINT16);
7051
7052 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7053         .f = cmd_priority_flow_ctrl_set_parsed,
7054         .data = NULL,
7055         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7056                 "<pause_time> <priority> <port_id>: "
7057                 "Configure the Ethernet priority flow control",
7058         .tokens = {
7059                 (void *)&cmd_pfc_set_set,
7060                 (void *)&cmd_pfc_set_flow_ctrl,
7061                 (void *)&cmd_pfc_set_rx,
7062                 (void *)&cmd_pfc_set_rx_mode,
7063                 (void *)&cmd_pfc_set_tx,
7064                 (void *)&cmd_pfc_set_tx_mode,
7065                 (void *)&cmd_pfc_set_high_water,
7066                 (void *)&cmd_pfc_set_low_water,
7067                 (void *)&cmd_pfc_set_pause_time,
7068                 (void *)&cmd_pfc_set_priority,
7069                 (void *)&cmd_pfc_set_portid,
7070                 NULL,
7071         },
7072 };
7073
7074 /* *** RESET CONFIGURATION *** */
7075 struct cmd_reset_result {
7076         cmdline_fixed_string_t reset;
7077         cmdline_fixed_string_t def;
7078 };
7079
7080 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7081                              struct cmdline *cl,
7082                              __attribute__((unused)) void *data)
7083 {
7084         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7085         set_def_fwd_config();
7086 }
7087
7088 cmdline_parse_token_string_t cmd_reset_set =
7089         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7090 cmdline_parse_token_string_t cmd_reset_def =
7091         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7092                                  "default");
7093
7094 cmdline_parse_inst_t cmd_reset = {
7095         .f = cmd_reset_parsed,
7096         .data = NULL,
7097         .help_str = "set default: Reset default forwarding configuration",
7098         .tokens = {
7099                 (void *)&cmd_reset_set,
7100                 (void *)&cmd_reset_def,
7101                 NULL,
7102         },
7103 };
7104
7105 /* *** START FORWARDING *** */
7106 struct cmd_start_result {
7107         cmdline_fixed_string_t start;
7108 };
7109
7110 cmdline_parse_token_string_t cmd_start_start =
7111         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7112
7113 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7114                              __attribute__((unused)) struct cmdline *cl,
7115                              __attribute__((unused)) void *data)
7116 {
7117         start_packet_forwarding(0);
7118 }
7119
7120 cmdline_parse_inst_t cmd_start = {
7121         .f = cmd_start_parsed,
7122         .data = NULL,
7123         .help_str = "start: Start packet forwarding",
7124         .tokens = {
7125                 (void *)&cmd_start_start,
7126                 NULL,
7127         },
7128 };
7129
7130 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7131 struct cmd_start_tx_first_result {
7132         cmdline_fixed_string_t start;
7133         cmdline_fixed_string_t tx_first;
7134 };
7135
7136 static void
7137 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7138                           __attribute__((unused)) struct cmdline *cl,
7139                           __attribute__((unused)) void *data)
7140 {
7141         start_packet_forwarding(1);
7142 }
7143
7144 cmdline_parse_token_string_t cmd_start_tx_first_start =
7145         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7146                                  "start");
7147 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7148         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7149                                  tx_first, "tx_first");
7150
7151 cmdline_parse_inst_t cmd_start_tx_first = {
7152         .f = cmd_start_tx_first_parsed,
7153         .data = NULL,
7154         .help_str = "start tx_first: Start packet forwarding, "
7155                 "after sending 1 burst of packets",
7156         .tokens = {
7157                 (void *)&cmd_start_tx_first_start,
7158                 (void *)&cmd_start_tx_first_tx_first,
7159                 NULL,
7160         },
7161 };
7162
7163 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7164 struct cmd_start_tx_first_n_result {
7165         cmdline_fixed_string_t start;
7166         cmdline_fixed_string_t tx_first;
7167         uint32_t tx_num;
7168 };
7169
7170 static void
7171 cmd_start_tx_first_n_parsed(void *parsed_result,
7172                           __attribute__((unused)) struct cmdline *cl,
7173                           __attribute__((unused)) void *data)
7174 {
7175         struct cmd_start_tx_first_n_result *res = parsed_result;
7176
7177         start_packet_forwarding(res->tx_num);
7178 }
7179
7180 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7181         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7182                         start, "start");
7183 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7184         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7185                         tx_first, "tx_first");
7186 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7187         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7188                         tx_num, UINT32);
7189
7190 cmdline_parse_inst_t cmd_start_tx_first_n = {
7191         .f = cmd_start_tx_first_n_parsed,
7192         .data = NULL,
7193         .help_str = "start tx_first <num>: "
7194                 "packet forwarding, after sending <num> bursts of packets",
7195         .tokens = {
7196                 (void *)&cmd_start_tx_first_n_start,
7197                 (void *)&cmd_start_tx_first_n_tx_first,
7198                 (void *)&cmd_start_tx_first_n_tx_num,
7199                 NULL,
7200         },
7201 };
7202
7203 /* *** SET LINK UP *** */
7204 struct cmd_set_link_up_result {
7205         cmdline_fixed_string_t set;
7206         cmdline_fixed_string_t link_up;
7207         cmdline_fixed_string_t port;
7208         portid_t port_id;
7209 };
7210
7211 cmdline_parse_token_string_t cmd_set_link_up_set =
7212         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7213 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7215                                 "link-up");
7216 cmdline_parse_token_string_t cmd_set_link_up_port =
7217         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7218 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7219         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7220
7221 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7222                              __attribute__((unused)) struct cmdline *cl,
7223                              __attribute__((unused)) void *data)
7224 {
7225         struct cmd_set_link_up_result *res = parsed_result;
7226         dev_set_link_up(res->port_id);
7227 }
7228
7229 cmdline_parse_inst_t cmd_set_link_up = {
7230         .f = cmd_set_link_up_parsed,
7231         .data = NULL,
7232         .help_str = "set link-up port <port id>",
7233         .tokens = {
7234                 (void *)&cmd_set_link_up_set,
7235                 (void *)&cmd_set_link_up_link_up,
7236                 (void *)&cmd_set_link_up_port,
7237                 (void *)&cmd_set_link_up_port_id,
7238                 NULL,
7239         },
7240 };
7241
7242 /* *** SET LINK DOWN *** */
7243 struct cmd_set_link_down_result {
7244         cmdline_fixed_string_t set;
7245         cmdline_fixed_string_t link_down;
7246         cmdline_fixed_string_t port;
7247         portid_t port_id;
7248 };
7249
7250 cmdline_parse_token_string_t cmd_set_link_down_set =
7251         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7252 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7253         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7254                                 "link-down");
7255 cmdline_parse_token_string_t cmd_set_link_down_port =
7256         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7257 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7258         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7259
7260 static void cmd_set_link_down_parsed(
7261                                 __attribute__((unused)) void *parsed_result,
7262                                 __attribute__((unused)) struct cmdline *cl,
7263                                 __attribute__((unused)) void *data)
7264 {
7265         struct cmd_set_link_down_result *res = parsed_result;
7266         dev_set_link_down(res->port_id);
7267 }
7268
7269 cmdline_parse_inst_t cmd_set_link_down = {
7270         .f = cmd_set_link_down_parsed,
7271         .data = NULL,
7272         .help_str = "set link-down port <port id>",
7273         .tokens = {
7274                 (void *)&cmd_set_link_down_set,
7275                 (void *)&cmd_set_link_down_link_down,
7276                 (void *)&cmd_set_link_down_port,
7277                 (void *)&cmd_set_link_down_port_id,
7278                 NULL,
7279         },
7280 };
7281
7282 /* *** SHOW CFG *** */
7283 struct cmd_showcfg_result {
7284         cmdline_fixed_string_t show;
7285         cmdline_fixed_string_t cfg;
7286         cmdline_fixed_string_t what;
7287 };
7288
7289 static void cmd_showcfg_parsed(void *parsed_result,
7290                                __attribute__((unused)) struct cmdline *cl,
7291                                __attribute__((unused)) void *data)
7292 {
7293         struct cmd_showcfg_result *res = parsed_result;
7294         if (!strcmp(res->what, "rxtx"))
7295                 rxtx_config_display();
7296         else if (!strcmp(res->what, "cores"))
7297                 fwd_lcores_config_display();
7298         else if (!strcmp(res->what, "fwd"))
7299                 pkt_fwd_config_display(&cur_fwd_config);
7300         else if (!strcmp(res->what, "txpkts"))
7301                 show_tx_pkt_segments();
7302 }
7303
7304 cmdline_parse_token_string_t cmd_showcfg_show =
7305         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7306 cmdline_parse_token_string_t cmd_showcfg_port =
7307         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7308 cmdline_parse_token_string_t cmd_showcfg_what =
7309         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7310                                  "rxtx#cores#fwd#txpkts");
7311
7312 cmdline_parse_inst_t cmd_showcfg = {
7313         .f = cmd_showcfg_parsed,
7314         .data = NULL,
7315         .help_str = "show config rxtx|cores|fwd|txpkts",
7316         .tokens = {
7317                 (void *)&cmd_showcfg_show,
7318                 (void *)&cmd_showcfg_port,
7319                 (void *)&cmd_showcfg_what,
7320                 NULL,
7321         },
7322 };
7323
7324 /* *** SHOW ALL PORT INFO *** */
7325 struct cmd_showportall_result {
7326         cmdline_fixed_string_t show;
7327         cmdline_fixed_string_t port;
7328         cmdline_fixed_string_t what;
7329         cmdline_fixed_string_t all;
7330 };
7331
7332 static void cmd_showportall_parsed(void *parsed_result,
7333                                 __attribute__((unused)) struct cmdline *cl,
7334                                 __attribute__((unused)) void *data)
7335 {
7336         portid_t i;
7337
7338         struct cmd_showportall_result *res = parsed_result;
7339         if (!strcmp(res->show, "clear")) {
7340                 if (!strcmp(res->what, "stats"))
7341                         RTE_ETH_FOREACH_DEV(i)
7342                                 nic_stats_clear(i);
7343                 else if (!strcmp(res->what, "xstats"))
7344                         RTE_ETH_FOREACH_DEV(i)
7345                                 nic_xstats_clear(i);
7346         } else if (!strcmp(res->what, "info"))
7347                 RTE_ETH_FOREACH_DEV(i)
7348                         port_infos_display(i);
7349         else if (!strcmp(res->what, "summary")) {
7350                 port_summary_header_display();
7351                 RTE_ETH_FOREACH_DEV(i)
7352                         port_summary_display(i);
7353         }
7354         else if (!strcmp(res->what, "stats"))
7355                 RTE_ETH_FOREACH_DEV(i)
7356                         nic_stats_display(i);
7357         else if (!strcmp(res->what, "xstats"))
7358                 RTE_ETH_FOREACH_DEV(i)
7359                         nic_xstats_display(i);
7360         else if (!strcmp(res->what, "fdir"))
7361                 RTE_ETH_FOREACH_DEV(i)
7362                         fdir_get_infos(i);
7363         else if (!strcmp(res->what, "stat_qmap"))
7364                 RTE_ETH_FOREACH_DEV(i)
7365                         nic_stats_mapping_display(i);
7366         else if (!strcmp(res->what, "dcb_tc"))
7367                 RTE_ETH_FOREACH_DEV(i)
7368                         port_dcb_info_display(i);
7369         else if (!strcmp(res->what, "cap"))
7370                 RTE_ETH_FOREACH_DEV(i)
7371                         port_offload_cap_display(i);
7372 }
7373
7374 cmdline_parse_token_string_t cmd_showportall_show =
7375         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7376                                  "show#clear");
7377 cmdline_parse_token_string_t cmd_showportall_port =
7378         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7379 cmdline_parse_token_string_t cmd_showportall_what =
7380         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7381                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7382 cmdline_parse_token_string_t cmd_showportall_all =
7383         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7384 cmdline_parse_inst_t cmd_showportall = {
7385         .f = cmd_showportall_parsed,
7386         .data = NULL,
7387         .help_str = "show|clear port "
7388                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7389         .tokens = {
7390                 (void *)&cmd_showportall_show,
7391                 (void *)&cmd_showportall_port,
7392                 (void *)&cmd_showportall_what,
7393                 (void *)&cmd_showportall_all,
7394                 NULL,
7395         },
7396 };
7397
7398 /* *** SHOW PORT INFO *** */
7399 struct cmd_showport_result {
7400         cmdline_fixed_string_t show;
7401         cmdline_fixed_string_t port;
7402         cmdline_fixed_string_t what;
7403         uint16_t portnum;
7404 };
7405
7406 static void cmd_showport_parsed(void *parsed_result,
7407                                 __attribute__((unused)) struct cmdline *cl,
7408                                 __attribute__((unused)) void *data)
7409 {
7410         struct cmd_showport_result *res = parsed_result;
7411         if (!strcmp(res->show, "clear")) {
7412                 if (!strcmp(res->what, "stats"))
7413                         nic_stats_clear(res->portnum);
7414                 else if (!strcmp(res->what, "xstats"))
7415                         nic_xstats_clear(res->portnum);
7416         } else if (!strcmp(res->what, "info"))
7417                 port_infos_display(res->portnum);
7418         else if (!strcmp(res->what, "summary")) {
7419                 port_summary_header_display();
7420                 port_summary_display(res->portnum);
7421         }
7422         else if (!strcmp(res->what, "stats"))
7423                 nic_stats_display(res->portnum);
7424         else if (!strcmp(res->what, "xstats"))
7425                 nic_xstats_display(res->portnum);
7426         else if (!strcmp(res->what, "fdir"))
7427                  fdir_get_infos(res->portnum);
7428         else if (!strcmp(res->what, "stat_qmap"))
7429                 nic_stats_mapping_display(res->portnum);
7430         else if (!strcmp(res->what, "dcb_tc"))
7431                 port_dcb_info_display(res->portnum);
7432         else if (!strcmp(res->what, "cap"))
7433                 port_offload_cap_display(res->portnum);
7434 }
7435
7436 cmdline_parse_token_string_t cmd_showport_show =
7437         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7438                                  "show#clear");
7439 cmdline_parse_token_string_t cmd_showport_port =
7440         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7441 cmdline_parse_token_string_t cmd_showport_what =
7442         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7443                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7444 cmdline_parse_token_num_t cmd_showport_portnum =
7445         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7446
7447 cmdline_parse_inst_t cmd_showport = {
7448         .f = cmd_showport_parsed,
7449         .data = NULL,
7450         .help_str = "show|clear port "
7451                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7452                 "<port_id>",
7453         .tokens = {
7454                 (void *)&cmd_showport_show,
7455                 (void *)&cmd_showport_port,
7456                 (void *)&cmd_showport_what,
7457                 (void *)&cmd_showport_portnum,
7458                 NULL,
7459         },
7460 };
7461
7462 /* *** SHOW DEVICE INFO *** */
7463 struct cmd_showdevice_result {
7464         cmdline_fixed_string_t show;
7465         cmdline_fixed_string_t device;
7466         cmdline_fixed_string_t what;
7467         cmdline_fixed_string_t identifier;
7468 };
7469
7470 static void cmd_showdevice_parsed(void *parsed_result,
7471                                 __attribute__((unused)) struct cmdline *cl,
7472                                 __attribute__((unused)) void *data)
7473 {
7474         struct cmd_showdevice_result *res = parsed_result;
7475         if (!strcmp(res->what, "info")) {
7476                 if (!strcmp(res->identifier, "all"))
7477                         device_infos_display(NULL);
7478                 else
7479                         device_infos_display(res->identifier);
7480         }
7481 }
7482
7483 cmdline_parse_token_string_t cmd_showdevice_show =
7484         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7485                                  "show");
7486 cmdline_parse_token_string_t cmd_showdevice_device =
7487         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7488 cmdline_parse_token_string_t cmd_showdevice_what =
7489         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7490                                  "info");
7491 cmdline_parse_token_string_t cmd_showdevice_identifier =
7492         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7493                         identifier, NULL);
7494
7495 cmdline_parse_inst_t cmd_showdevice = {
7496         .f = cmd_showdevice_parsed,
7497         .data = NULL,
7498         .help_str = "show device info <identifier>|all",
7499         .tokens = {
7500                 (void *)&cmd_showdevice_show,
7501                 (void *)&cmd_showdevice_device,
7502                 (void *)&cmd_showdevice_what,
7503                 (void *)&cmd_showdevice_identifier,
7504                 NULL,
7505         },
7506 };
7507 /* *** SHOW QUEUE INFO *** */
7508 struct cmd_showqueue_result {
7509         cmdline_fixed_string_t show;
7510         cmdline_fixed_string_t type;
7511         cmdline_fixed_string_t what;
7512         uint16_t portnum;
7513         uint16_t queuenum;
7514 };
7515
7516 static void
7517 cmd_showqueue_parsed(void *parsed_result,
7518         __attribute__((unused)) struct cmdline *cl,
7519         __attribute__((unused)) void *data)
7520 {
7521         struct cmd_showqueue_result *res = parsed_result;
7522
7523         if (!strcmp(res->type, "rxq"))
7524                 rx_queue_infos_display(res->portnum, res->queuenum);
7525         else if (!strcmp(res->type, "txq"))
7526                 tx_queue_infos_display(res->portnum, res->queuenum);
7527 }
7528
7529 cmdline_parse_token_string_t cmd_showqueue_show =
7530         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7531 cmdline_parse_token_string_t cmd_showqueue_type =
7532         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7533 cmdline_parse_token_string_t cmd_showqueue_what =
7534         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7535 cmdline_parse_token_num_t cmd_showqueue_portnum =
7536         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7537 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7538         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7539
7540 cmdline_parse_inst_t cmd_showqueue = {
7541         .f = cmd_showqueue_parsed,
7542         .data = NULL,
7543         .help_str = "show rxq|txq info <port_id> <queue_id>",
7544         .tokens = {
7545                 (void *)&cmd_showqueue_show,
7546                 (void *)&cmd_showqueue_type,
7547                 (void *)&cmd_showqueue_what,
7548                 (void *)&cmd_showqueue_portnum,
7549                 (void *)&cmd_showqueue_queuenum,
7550                 NULL,
7551         },
7552 };
7553
7554 /* show/clear fwd engine statistics */
7555 struct fwd_result {
7556         cmdline_fixed_string_t action;
7557         cmdline_fixed_string_t fwd;
7558         cmdline_fixed_string_t stats;
7559         cmdline_fixed_string_t all;
7560 };
7561
7562 cmdline_parse_token_string_t cmd_fwd_action =
7563         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7564 cmdline_parse_token_string_t cmd_fwd_fwd =
7565         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7566 cmdline_parse_token_string_t cmd_fwd_stats =
7567         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7568 cmdline_parse_token_string_t cmd_fwd_all =
7569         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7570
7571 static void
7572 cmd_showfwdall_parsed(void *parsed_result,
7573                       __rte_unused struct cmdline *cl,
7574                       __rte_unused void *data)
7575 {
7576         struct fwd_result *res = parsed_result;
7577
7578         if (!strcmp(res->action, "show"))
7579                 fwd_stats_display();
7580         else
7581                 fwd_stats_reset();
7582 }
7583
7584 static cmdline_parse_inst_t cmd_showfwdall = {
7585         .f = cmd_showfwdall_parsed,
7586         .data = NULL,
7587         .help_str = "show|clear fwd stats all",
7588         .tokens = {
7589                 (void *)&cmd_fwd_action,
7590                 (void *)&cmd_fwd_fwd,
7591                 (void *)&cmd_fwd_stats,
7592                 (void *)&cmd_fwd_all,
7593                 NULL,
7594         },
7595 };
7596
7597 /* *** READ PORT REGISTER *** */
7598 struct cmd_read_reg_result {
7599         cmdline_fixed_string_t read;
7600         cmdline_fixed_string_t reg;
7601         portid_t port_id;
7602         uint32_t reg_off;
7603 };
7604
7605 static void
7606 cmd_read_reg_parsed(void *parsed_result,
7607                     __attribute__((unused)) struct cmdline *cl,
7608                     __attribute__((unused)) void *data)
7609 {
7610         struct cmd_read_reg_result *res = parsed_result;
7611         port_reg_display(res->port_id, res->reg_off);
7612 }
7613
7614 cmdline_parse_token_string_t cmd_read_reg_read =
7615         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7616 cmdline_parse_token_string_t cmd_read_reg_reg =
7617         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7618 cmdline_parse_token_num_t cmd_read_reg_port_id =
7619         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7620 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7621         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7622
7623 cmdline_parse_inst_t cmd_read_reg = {
7624         .f = cmd_read_reg_parsed,
7625         .data = NULL,
7626         .help_str = "read reg <port_id> <reg_off>",
7627         .tokens = {
7628                 (void *)&cmd_read_reg_read,
7629                 (void *)&cmd_read_reg_reg,
7630                 (void *)&cmd_read_reg_port_id,
7631                 (void *)&cmd_read_reg_reg_off,
7632                 NULL,
7633         },
7634 };
7635
7636 /* *** READ PORT REGISTER BIT FIELD *** */
7637 struct cmd_read_reg_bit_field_result {
7638         cmdline_fixed_string_t read;
7639         cmdline_fixed_string_t regfield;
7640         portid_t port_id;
7641         uint32_t reg_off;
7642         uint8_t bit1_pos;
7643         uint8_t bit2_pos;
7644 };
7645
7646 static void
7647 cmd_read_reg_bit_field_parsed(void *parsed_result,
7648                               __attribute__((unused)) struct cmdline *cl,
7649                               __attribute__((unused)) void *data)
7650 {
7651         struct cmd_read_reg_bit_field_result *res = parsed_result;
7652         port_reg_bit_field_display(res->port_id, res->reg_off,
7653                                    res->bit1_pos, res->bit2_pos);
7654 }
7655
7656 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7657         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7658                                  "read");
7659 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7660         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7661                                  regfield, "regfield");
7662 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7663         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7664                               UINT16);
7665 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7666         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7667                               UINT32);
7668 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7669         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7670                               UINT8);
7671 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7672         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7673                               UINT8);
7674
7675 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7676         .f = cmd_read_reg_bit_field_parsed,
7677         .data = NULL,
7678         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7679         "Read register bit field between bit_x and bit_y included",
7680         .tokens = {
7681                 (void *)&cmd_read_reg_bit_field_read,
7682                 (void *)&cmd_read_reg_bit_field_regfield,
7683                 (void *)&cmd_read_reg_bit_field_port_id,
7684                 (void *)&cmd_read_reg_bit_field_reg_off,
7685                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7686                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7687                 NULL,
7688         },
7689 };
7690
7691 /* *** READ PORT REGISTER BIT *** */
7692 struct cmd_read_reg_bit_result {
7693         cmdline_fixed_string_t read;
7694         cmdline_fixed_string_t regbit;
7695         portid_t port_id;
7696         uint32_t reg_off;
7697         uint8_t bit_pos;
7698 };
7699
7700 static void
7701 cmd_read_reg_bit_parsed(void *parsed_result,
7702                         __attribute__((unused)) struct cmdline *cl,
7703                         __attribute__((unused)) void *data)
7704 {
7705         struct cmd_read_reg_bit_result *res = parsed_result;
7706         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7707 }
7708
7709 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7710         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7711 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7712         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7713                                  regbit, "regbit");
7714 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7715         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7716 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7717         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7718 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7719         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7720
7721 cmdline_parse_inst_t cmd_read_reg_bit = {
7722         .f = cmd_read_reg_bit_parsed,
7723         .data = NULL,
7724         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7725         .tokens = {
7726                 (void *)&cmd_read_reg_bit_read,
7727                 (void *)&cmd_read_reg_bit_regbit,
7728                 (void *)&cmd_read_reg_bit_port_id,
7729                 (void *)&cmd_read_reg_bit_reg_off,
7730                 (void *)&cmd_read_reg_bit_bit_pos,
7731                 NULL,
7732         },
7733 };
7734
7735 /* *** WRITE PORT REGISTER *** */
7736 struct cmd_write_reg_result {
7737         cmdline_fixed_string_t write;
7738         cmdline_fixed_string_t reg;
7739         portid_t port_id;
7740         uint32_t reg_off;
7741         uint32_t value;
7742 };
7743
7744 static void
7745 cmd_write_reg_parsed(void *parsed_result,
7746                      __attribute__((unused)) struct cmdline *cl,
7747                      __attribute__((unused)) void *data)
7748 {
7749         struct cmd_write_reg_result *res = parsed_result;
7750         port_reg_set(res->port_id, res->reg_off, res->value);
7751 }
7752
7753 cmdline_parse_token_string_t cmd_write_reg_write =
7754         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7755 cmdline_parse_token_string_t cmd_write_reg_reg =
7756         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7757 cmdline_parse_token_num_t cmd_write_reg_port_id =
7758         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7759 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7760         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7761 cmdline_parse_token_num_t cmd_write_reg_value =
7762         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7763
7764 cmdline_parse_inst_t cmd_write_reg = {
7765         .f = cmd_write_reg_parsed,
7766         .data = NULL,
7767         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7768         .tokens = {
7769                 (void *)&cmd_write_reg_write,
7770                 (void *)&cmd_write_reg_reg,
7771                 (void *)&cmd_write_reg_port_id,
7772                 (void *)&cmd_write_reg_reg_off,
7773                 (void *)&cmd_write_reg_value,
7774                 NULL,
7775         },
7776 };
7777
7778 /* *** WRITE PORT REGISTER BIT FIELD *** */
7779 struct cmd_write_reg_bit_field_result {
7780         cmdline_fixed_string_t write;
7781         cmdline_fixed_string_t regfield;
7782         portid_t port_id;
7783         uint32_t reg_off;
7784         uint8_t bit1_pos;
7785         uint8_t bit2_pos;
7786         uint32_t value;
7787 };
7788
7789 static void
7790 cmd_write_reg_bit_field_parsed(void *parsed_result,
7791                                __attribute__((unused)) struct cmdline *cl,
7792                                __attribute__((unused)) void *data)
7793 {
7794         struct cmd_write_reg_bit_field_result *res = parsed_result;
7795         port_reg_bit_field_set(res->port_id, res->reg_off,
7796                           res->bit1_pos, res->bit2_pos, res->value);
7797 }
7798
7799 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7800         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7801                                  "write");
7802 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7803         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7804                                  regfield, "regfield");
7805 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7806         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7807                               UINT16);
7808 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7809         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7810                               UINT32);
7811 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7812         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7813                               UINT8);
7814 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7815         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7816                               UINT8);
7817 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7818         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7819                               UINT32);
7820
7821 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7822         .f = cmd_write_reg_bit_field_parsed,
7823         .data = NULL,
7824         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7825                 "<reg_value>: "
7826                 "Set register bit field between bit_x and bit_y included",
7827         .tokens = {
7828                 (void *)&cmd_write_reg_bit_field_write,
7829                 (void *)&cmd_write_reg_bit_field_regfield,
7830                 (void *)&cmd_write_reg_bit_field_port_id,
7831                 (void *)&cmd_write_reg_bit_field_reg_off,
7832                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7833                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7834                 (void *)&cmd_write_reg_bit_field_value,
7835                 NULL,
7836         },
7837 };
7838
7839 /* *** WRITE PORT REGISTER BIT *** */
7840 struct cmd_write_reg_bit_result {
7841         cmdline_fixed_string_t write;
7842         cmdline_fixed_string_t regbit;
7843         portid_t port_id;
7844         uint32_t reg_off;
7845         uint8_t bit_pos;
7846         uint8_t value;
7847 };
7848
7849 static void
7850 cmd_write_reg_bit_parsed(void *parsed_result,
7851                          __attribute__((unused)) struct cmdline *cl,
7852                          __attribute__((unused)) void *data)
7853 {
7854         struct cmd_write_reg_bit_result *res = parsed_result;
7855         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7856 }
7857
7858 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7859         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7860                                  "write");
7861 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7862         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7863                                  regbit, "regbit");
7864 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7865         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7866 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7867         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7868 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7869         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7870 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7871         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7872
7873 cmdline_parse_inst_t cmd_write_reg_bit = {
7874         .f = cmd_write_reg_bit_parsed,
7875         .data = NULL,
7876         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7877                 "0 <= bit_x <= 31",
7878         .tokens = {
7879                 (void *)&cmd_write_reg_bit_write,
7880                 (void *)&cmd_write_reg_bit_regbit,
7881                 (void *)&cmd_write_reg_bit_port_id,
7882                 (void *)&cmd_write_reg_bit_reg_off,
7883                 (void *)&cmd_write_reg_bit_bit_pos,
7884                 (void *)&cmd_write_reg_bit_value,
7885                 NULL,
7886         },
7887 };
7888
7889 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7890 struct cmd_read_rxd_txd_result {
7891         cmdline_fixed_string_t read;
7892         cmdline_fixed_string_t rxd_txd;
7893         portid_t port_id;
7894         uint16_t queue_id;
7895         uint16_t desc_id;
7896 };
7897
7898 static void
7899 cmd_read_rxd_txd_parsed(void *parsed_result,
7900                         __attribute__((unused)) struct cmdline *cl,
7901                         __attribute__((unused)) void *data)
7902 {
7903         struct cmd_read_rxd_txd_result *res = parsed_result;
7904
7905         if (!strcmp(res->rxd_txd, "rxd"))
7906                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7907         else if (!strcmp(res->rxd_txd, "txd"))
7908                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7909 }
7910
7911 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7912         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7913 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7914         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7915                                  "rxd#txd");
7916 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7917         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7918 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7919         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7920 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7921         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7922
7923 cmdline_parse_inst_t cmd_read_rxd_txd = {
7924         .f = cmd_read_rxd_txd_parsed,
7925         .data = NULL,
7926         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7927         .tokens = {
7928                 (void *)&cmd_read_rxd_txd_read,
7929                 (void *)&cmd_read_rxd_txd_rxd_txd,
7930                 (void *)&cmd_read_rxd_txd_port_id,
7931                 (void *)&cmd_read_rxd_txd_queue_id,
7932                 (void *)&cmd_read_rxd_txd_desc_id,
7933                 NULL,
7934         },
7935 };
7936
7937 /* *** QUIT *** */
7938 struct cmd_quit_result {
7939         cmdline_fixed_string_t quit;
7940 };
7941
7942 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7943                             struct cmdline *cl,
7944                             __attribute__((unused)) void *data)
7945 {
7946         cmdline_quit(cl);
7947 }
7948
7949 cmdline_parse_token_string_t cmd_quit_quit =
7950         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7951
7952 cmdline_parse_inst_t cmd_quit = {
7953         .f = cmd_quit_parsed,
7954         .data = NULL,
7955         .help_str = "quit: Exit application",
7956         .tokens = {
7957                 (void *)&cmd_quit_quit,
7958                 NULL,
7959         },
7960 };
7961
7962 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7963 struct cmd_mac_addr_result {
7964         cmdline_fixed_string_t mac_addr_cmd;
7965         cmdline_fixed_string_t what;
7966         uint16_t port_num;
7967         struct rte_ether_addr address;
7968 };
7969
7970 static void cmd_mac_addr_parsed(void *parsed_result,
7971                 __attribute__((unused)) struct cmdline *cl,
7972                 __attribute__((unused)) void *data)
7973 {
7974         struct cmd_mac_addr_result *res = parsed_result;
7975         int ret;
7976
7977         if (strcmp(res->what, "add") == 0)
7978                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7979         else if (strcmp(res->what, "set") == 0)
7980                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7981                                                        &res->address);
7982         else
7983                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7984
7985         /* check the return value and print it if is < 0 */
7986         if(ret < 0)
7987                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7988
7989 }
7990
7991 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7992         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7993                                 "mac_addr");
7994 cmdline_parse_token_string_t cmd_mac_addr_what =
7995         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7996                                 "add#remove#set");
7997 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7998                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7999                                         UINT16);
8000 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8001                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8002
8003 cmdline_parse_inst_t cmd_mac_addr = {
8004         .f = cmd_mac_addr_parsed,
8005         .data = (void *)0,
8006         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8007                         "Add/Remove/Set MAC address on port_id",
8008         .tokens = {
8009                 (void *)&cmd_mac_addr_cmd,
8010                 (void *)&cmd_mac_addr_what,
8011                 (void *)&cmd_mac_addr_portnum,
8012                 (void *)&cmd_mac_addr_addr,
8013                 NULL,
8014         },
8015 };
8016
8017 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8018 struct cmd_eth_peer_result {
8019         cmdline_fixed_string_t set;
8020         cmdline_fixed_string_t eth_peer;
8021         portid_t port_id;
8022         cmdline_fixed_string_t peer_addr;
8023 };
8024
8025 static void cmd_set_eth_peer_parsed(void *parsed_result,
8026                         __attribute__((unused)) struct cmdline *cl,
8027                         __attribute__((unused)) void *data)
8028 {
8029                 struct cmd_eth_peer_result *res = parsed_result;
8030
8031                 if (test_done == 0) {
8032                         printf("Please stop forwarding first\n");
8033                         return;
8034                 }
8035                 if (!strcmp(res->eth_peer, "eth-peer")) {
8036                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8037                         fwd_config_setup();
8038                 }
8039 }
8040 cmdline_parse_token_string_t cmd_eth_peer_set =
8041         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8042 cmdline_parse_token_string_t cmd_eth_peer =
8043         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8044 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8045         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8046 cmdline_parse_token_string_t cmd_eth_peer_addr =
8047         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8048
8049 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8050         .f = cmd_set_eth_peer_parsed,
8051         .data = NULL,
8052         .help_str = "set eth-peer <port_id> <peer_mac>",
8053         .tokens = {
8054                 (void *)&cmd_eth_peer_set,
8055                 (void *)&cmd_eth_peer,
8056                 (void *)&cmd_eth_peer_port_id,
8057                 (void *)&cmd_eth_peer_addr,
8058                 NULL,
8059         },
8060 };
8061
8062 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8063 struct cmd_set_qmap_result {
8064         cmdline_fixed_string_t set;
8065         cmdline_fixed_string_t qmap;
8066         cmdline_fixed_string_t what;
8067         portid_t port_id;
8068         uint16_t queue_id;
8069         uint8_t map_value;
8070 };
8071
8072 static void
8073 cmd_set_qmap_parsed(void *parsed_result,
8074                        __attribute__((unused)) struct cmdline *cl,
8075                        __attribute__((unused)) void *data)
8076 {
8077         struct cmd_set_qmap_result *res = parsed_result;
8078         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8079
8080         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8081 }
8082
8083 cmdline_parse_token_string_t cmd_setqmap_set =
8084         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8085                                  set, "set");
8086 cmdline_parse_token_string_t cmd_setqmap_qmap =
8087         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8088                                  qmap, "stat_qmap");
8089 cmdline_parse_token_string_t cmd_setqmap_what =
8090         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8091                                  what, "tx#rx");
8092 cmdline_parse_token_num_t cmd_setqmap_portid =
8093         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8094                               port_id, UINT16);
8095 cmdline_parse_token_num_t cmd_setqmap_queueid =
8096         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8097                               queue_id, UINT16);
8098 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8099         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8100                               map_value, UINT8);
8101
8102 cmdline_parse_inst_t cmd_set_qmap = {
8103         .f = cmd_set_qmap_parsed,
8104         .data = NULL,
8105         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8106                 "Set statistics mapping value on tx|rx queue_id of port_id",
8107         .tokens = {
8108                 (void *)&cmd_setqmap_set,
8109                 (void *)&cmd_setqmap_qmap,
8110                 (void *)&cmd_setqmap_what,
8111                 (void *)&cmd_setqmap_portid,
8112                 (void *)&cmd_setqmap_queueid,
8113                 (void *)&cmd_setqmap_mapvalue,
8114                 NULL,
8115         },
8116 };
8117
8118 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8119 struct cmd_set_xstats_hide_zero_result {
8120         cmdline_fixed_string_t keyword;
8121         cmdline_fixed_string_t name;
8122         cmdline_fixed_string_t on_off;
8123 };
8124
8125 static void
8126 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8127                         __attribute__((unused)) struct cmdline *cl,
8128                         __attribute__((unused)) void *data)
8129 {
8130         struct cmd_set_xstats_hide_zero_result *res;
8131         uint16_t on_off = 0;
8132
8133         res = parsed_result;
8134         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8135         set_xstats_hide_zero(on_off);
8136 }
8137
8138 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8139         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8140                                  keyword, "set");
8141 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8142         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8143                                  name, "xstats-hide-zero");
8144 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8145         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8146                                  on_off, "on#off");
8147
8148 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8149         .f = cmd_set_xstats_hide_zero_parsed,
8150         .data = NULL,
8151         .help_str = "set xstats-hide-zero on|off",
8152         .tokens = {
8153                 (void *)&cmd_set_xstats_hide_zero_keyword,
8154                 (void *)&cmd_set_xstats_hide_zero_name,
8155                 (void *)&cmd_set_xstats_hide_zero_on_off,
8156                 NULL,
8157         },
8158 };
8159
8160 /* *** CONFIGURE UNICAST HASH TABLE *** */
8161 struct cmd_set_uc_hash_table {
8162         cmdline_fixed_string_t set;
8163         cmdline_fixed_string_t port;
8164         portid_t port_id;
8165         cmdline_fixed_string_t what;
8166         struct rte_ether_addr address;
8167         cmdline_fixed_string_t mode;
8168 };
8169
8170 static void
8171 cmd_set_uc_hash_parsed(void *parsed_result,
8172                        __attribute__((unused)) struct cmdline *cl,
8173                        __attribute__((unused)) void *data)
8174 {
8175         int ret=0;
8176         struct cmd_set_uc_hash_table *res = parsed_result;
8177
8178         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8179
8180         if (strcmp(res->what, "uta") == 0)
8181                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8182                                                 &res->address,(uint8_t)is_on);
8183         if (ret < 0)
8184                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8185
8186 }
8187
8188 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8189         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8190                                  set, "set");
8191 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8192         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8193                                  port, "port");
8194 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8195         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8196                               port_id, UINT16);
8197 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8198         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8199                                  what, "uta");
8200 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8201         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8202                                 address);
8203 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8204         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8205                                  mode, "on#off");
8206
8207 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8208         .f = cmd_set_uc_hash_parsed,
8209         .data = NULL,
8210         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8211         .tokens = {
8212                 (void *)&cmd_set_uc_hash_set,
8213                 (void *)&cmd_set_uc_hash_port,
8214                 (void *)&cmd_set_uc_hash_portid,
8215                 (void *)&cmd_set_uc_hash_what,
8216                 (void *)&cmd_set_uc_hash_mac,
8217                 (void *)&cmd_set_uc_hash_mode,
8218                 NULL,
8219         },
8220 };
8221
8222 struct cmd_set_uc_all_hash_table {
8223         cmdline_fixed_string_t set;
8224         cmdline_fixed_string_t port;
8225         portid_t port_id;
8226         cmdline_fixed_string_t what;
8227         cmdline_fixed_string_t value;
8228         cmdline_fixed_string_t mode;
8229 };
8230
8231 static void
8232 cmd_set_uc_all_hash_parsed(void *parsed_result,
8233                        __attribute__((unused)) struct cmdline *cl,
8234                        __attribute__((unused)) void *data)
8235 {
8236         int ret=0;
8237         struct cmd_set_uc_all_hash_table *res = parsed_result;
8238
8239         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8240
8241         if ((strcmp(res->what, "uta") == 0) &&
8242                 (strcmp(res->value, "all") == 0))
8243                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8244         if (ret < 0)
8245                 printf("bad unicast hash table parameter,"
8246                         "return code = %d \n", ret);
8247 }
8248
8249 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8250         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8251                                  set, "set");
8252 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8253         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8254                                  port, "port");
8255 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8256         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8257                               port_id, UINT16);
8258 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8259         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8260                                  what, "uta");
8261 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8262         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8263                                 value,"all");
8264 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8265         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8266                                  mode, "on#off");
8267
8268 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8269         .f = cmd_set_uc_all_hash_parsed,
8270         .data = NULL,
8271         .help_str = "set port <port_id> uta all on|off",
8272         .tokens = {
8273                 (void *)&cmd_set_uc_all_hash_set,
8274                 (void *)&cmd_set_uc_all_hash_port,
8275                 (void *)&cmd_set_uc_all_hash_portid,
8276                 (void *)&cmd_set_uc_all_hash_what,
8277                 (void *)&cmd_set_uc_all_hash_value,
8278                 (void *)&cmd_set_uc_all_hash_mode,
8279                 NULL,
8280         },
8281 };
8282
8283 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8284 struct cmd_set_vf_macvlan_filter {
8285         cmdline_fixed_string_t set;
8286         cmdline_fixed_string_t port;
8287         portid_t port_id;
8288         cmdline_fixed_string_t vf;
8289         uint8_t vf_id;
8290         struct rte_ether_addr address;
8291         cmdline_fixed_string_t filter_type;
8292         cmdline_fixed_string_t mode;
8293 };
8294
8295 static void
8296 cmd_set_vf_macvlan_parsed(void *parsed_result,
8297                        __attribute__((unused)) struct cmdline *cl,
8298                        __attribute__((unused)) void *data)
8299 {
8300         int is_on, ret = 0;
8301         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8302         struct rte_eth_mac_filter filter;
8303
8304         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8305
8306         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8307
8308         /* set VF MAC filter */
8309         filter.is_vf = 1;
8310
8311         /* set VF ID */
8312         filter.dst_id = res->vf_id;
8313
8314         if (!strcmp(res->filter_type, "exact-mac"))
8315                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8316         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8317                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8318         else if (!strcmp(res->filter_type, "hashmac"))
8319                 filter.filter_type = RTE_MAC_HASH_MATCH;
8320         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8321                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8322
8323         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8324
8325         if (is_on)
8326                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8327                                         RTE_ETH_FILTER_MACVLAN,
8328                                         RTE_ETH_FILTER_ADD,
8329                                          &filter);
8330         else
8331                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8332                                         RTE_ETH_FILTER_MACVLAN,
8333                                         RTE_ETH_FILTER_DELETE,
8334                                         &filter);
8335
8336         if (ret < 0)
8337                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8338
8339 }
8340
8341 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8342         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8343                                  set, "set");
8344 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8345         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8346                                  port, "port");
8347 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8348         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8349                               port_id, UINT16);
8350 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8351         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8352                                  vf, "vf");
8353 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8354         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8355                                 vf_id, UINT8);
8356 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8357         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8358                                 address);
8359 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8360         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8361                                 filter_type, "exact-mac#exact-mac-vlan"
8362                                 "#hashmac#hashmac-vlan");
8363 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8364         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8365                                  mode, "on#off");
8366
8367 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8368         .f = cmd_set_vf_macvlan_parsed,
8369         .data = NULL,
8370         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8371                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8372                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8373                 "hash match rule: hash match of MAC and exact match of VLAN",
8374         .tokens = {
8375                 (void *)&cmd_set_vf_macvlan_set,
8376                 (void *)&cmd_set_vf_macvlan_port,
8377                 (void *)&cmd_set_vf_macvlan_portid,
8378                 (void *)&cmd_set_vf_macvlan_vf,
8379                 (void *)&cmd_set_vf_macvlan_vf_id,
8380                 (void *)&cmd_set_vf_macvlan_mac,
8381                 (void *)&cmd_set_vf_macvlan_filter_type,
8382                 (void *)&cmd_set_vf_macvlan_mode,
8383                 NULL,
8384         },
8385 };
8386
8387 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8388 struct cmd_set_vf_traffic {
8389         cmdline_fixed_string_t set;
8390         cmdline_fixed_string_t port;
8391         portid_t port_id;
8392         cmdline_fixed_string_t vf;
8393         uint8_t vf_id;
8394         cmdline_fixed_string_t what;
8395         cmdline_fixed_string_t mode;
8396 };
8397
8398 static void
8399 cmd_set_vf_traffic_parsed(void *parsed_result,
8400                        __attribute__((unused)) struct cmdline *cl,
8401                        __attribute__((unused)) void *data)
8402 {
8403         struct cmd_set_vf_traffic *res = parsed_result;
8404         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8405         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8406
8407         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8408 }
8409
8410 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8411         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8412                                  set, "set");
8413 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8414         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8415                                  port, "port");
8416 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8417         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8418                               port_id, UINT16);
8419 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8420         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8421                                  vf, "vf");
8422 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8423         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8424                               vf_id, UINT8);
8425 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8426         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8427                                  what, "tx#rx");
8428 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8429         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8430                                  mode, "on#off");
8431
8432 cmdline_parse_inst_t cmd_set_vf_traffic = {
8433         .f = cmd_set_vf_traffic_parsed,
8434         .data = NULL,
8435         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8436         .tokens = {
8437                 (void *)&cmd_setvf_traffic_set,
8438                 (void *)&cmd_setvf_traffic_port,
8439                 (void *)&cmd_setvf_traffic_portid,
8440                 (void *)&cmd_setvf_traffic_vf,
8441                 (void *)&cmd_setvf_traffic_vfid,
8442                 (void *)&cmd_setvf_traffic_what,
8443                 (void *)&cmd_setvf_traffic_mode,
8444                 NULL,
8445         },
8446 };
8447
8448 /* *** CONFIGURE VF RECEIVE MODE *** */
8449 struct cmd_set_vf_rxmode {
8450         cmdline_fixed_string_t set;
8451         cmdline_fixed_string_t port;
8452         portid_t port_id;
8453         cmdline_fixed_string_t vf;
8454         uint8_t vf_id;
8455         cmdline_fixed_string_t what;
8456         cmdline_fixed_string_t mode;
8457         cmdline_fixed_string_t on;
8458 };
8459
8460 static void
8461 cmd_set_vf_rxmode_parsed(void *parsed_result,
8462                        __attribute__((unused)) struct cmdline *cl,
8463                        __attribute__((unused)) void *data)
8464 {
8465         int ret = -ENOTSUP;
8466         uint16_t vf_rxmode = 0;
8467         struct cmd_set_vf_rxmode *res = parsed_result;
8468
8469         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8470         if (!strcmp(res->what,"rxmode")) {
8471                 if (!strcmp(res->mode, "AUPE"))
8472                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8473                 else if (!strcmp(res->mode, "ROPE"))
8474                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8475                 else if (!strcmp(res->mode, "BAM"))
8476                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8477                 else if (!strncmp(res->mode, "MPE",3))
8478                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8479         }
8480
8481         RTE_SET_USED(is_on);
8482
8483 #ifdef RTE_LIBRTE_IXGBE_PMD
8484         if (ret == -ENOTSUP)
8485                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8486                                                   vf_rxmode, (uint8_t)is_on);
8487 #endif
8488 #ifdef RTE_LIBRTE_BNXT_PMD
8489         if (ret == -ENOTSUP)
8490                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8491                                                  vf_rxmode, (uint8_t)is_on);
8492 #endif
8493         if (ret < 0)
8494                 printf("bad VF receive mode parameter, return code = %d \n",
8495                 ret);
8496 }
8497
8498 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8499         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8500                                  set, "set");
8501 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8502         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8503                                  port, "port");
8504 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8505         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8506                               port_id, UINT16);
8507 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8508         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8509                                  vf, "vf");
8510 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8511         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8512                               vf_id, UINT8);
8513 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8514         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8515                                  what, "rxmode");
8516 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8517         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8518                                  mode, "AUPE#ROPE#BAM#MPE");
8519 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8521                                  on, "on#off");
8522
8523 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8524         .f = cmd_set_vf_rxmode_parsed,
8525         .data = NULL,
8526         .help_str = "set port <port_id> vf <vf_id> rxmode "
8527                 "AUPE|ROPE|BAM|MPE on|off",
8528         .tokens = {
8529                 (void *)&cmd_set_vf_rxmode_set,
8530                 (void *)&cmd_set_vf_rxmode_port,
8531                 (void *)&cmd_set_vf_rxmode_portid,
8532                 (void *)&cmd_set_vf_rxmode_vf,
8533                 (void *)&cmd_set_vf_rxmode_vfid,
8534                 (void *)&cmd_set_vf_rxmode_what,
8535                 (void *)&cmd_set_vf_rxmode_mode,
8536                 (void *)&cmd_set_vf_rxmode_on,
8537                 NULL,
8538         },
8539 };
8540
8541 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8542 struct cmd_vf_mac_addr_result {
8543         cmdline_fixed_string_t mac_addr_cmd;
8544         cmdline_fixed_string_t what;
8545         cmdline_fixed_string_t port;
8546         uint16_t port_num;
8547         cmdline_fixed_string_t vf;
8548         uint8_t vf_num;
8549         struct rte_ether_addr address;
8550 };
8551
8552 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8553                 __attribute__((unused)) struct cmdline *cl,
8554                 __attribute__((unused)) void *data)
8555 {
8556         struct cmd_vf_mac_addr_result *res = parsed_result;
8557         int ret = -ENOTSUP;
8558
8559         if (strcmp(res->what, "add") != 0)
8560                 return;
8561
8562 #ifdef RTE_LIBRTE_I40E_PMD
8563         if (ret == -ENOTSUP)
8564                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8565                                                    &res->address);
8566 #endif
8567 #ifdef RTE_LIBRTE_BNXT_PMD
8568         if (ret == -ENOTSUP)
8569                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8570                                                 res->vf_num);
8571 #endif
8572
8573         if(ret < 0)
8574                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8575
8576 }
8577
8578 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8579         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8580                                 mac_addr_cmd,"mac_addr");
8581 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8582         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8583                                 what,"add");
8584 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8585         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8586                                 port,"port");
8587 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8588         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8589                                 port_num, UINT16);
8590 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8591         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8592                                 vf,"vf");
8593 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8594         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8595                                 vf_num, UINT8);
8596 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8597         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8598                                 address);
8599
8600 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8601         .f = cmd_vf_mac_addr_parsed,
8602         .data = (void *)0,
8603         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8604                 "Add MAC address filtering for a VF on port_id",
8605         .tokens = {
8606                 (void *)&cmd_vf_mac_addr_cmd,
8607                 (void *)&cmd_vf_mac_addr_what,
8608                 (void *)&cmd_vf_mac_addr_port,
8609                 (void *)&cmd_vf_mac_addr_portnum,
8610                 (void *)&cmd_vf_mac_addr_vf,
8611                 (void *)&cmd_vf_mac_addr_vfnum,
8612                 (void *)&cmd_vf_mac_addr_addr,
8613                 NULL,
8614         },
8615 };
8616
8617 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8618 struct cmd_vf_rx_vlan_filter {
8619         cmdline_fixed_string_t rx_vlan;
8620         cmdline_fixed_string_t what;
8621         uint16_t vlan_id;
8622         cmdline_fixed_string_t port;
8623         portid_t port_id;
8624         cmdline_fixed_string_t vf;
8625         uint64_t vf_mask;
8626 };
8627
8628 static void
8629 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8630                           __attribute__((unused)) struct cmdline *cl,
8631                           __attribute__((unused)) void *data)
8632 {
8633         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8634         int ret = -ENOTSUP;
8635
8636         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8637
8638 #ifdef RTE_LIBRTE_IXGBE_PMD
8639         if (ret == -ENOTSUP)
8640                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8641                                 res->vlan_id, res->vf_mask, is_add);
8642 #endif
8643 #ifdef RTE_LIBRTE_I40E_PMD
8644         if (ret == -ENOTSUP)
8645                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8646                                 res->vlan_id, res->vf_mask, is_add);
8647 #endif
8648 #ifdef RTE_LIBRTE_BNXT_PMD
8649         if (ret == -ENOTSUP)
8650                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8651                                 res->vlan_id, res->vf_mask, is_add);
8652 #endif
8653
8654         switch (ret) {
8655         case 0:
8656                 break;
8657         case -EINVAL:
8658                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8659                                 res->vlan_id, res->vf_mask);
8660                 break;
8661         case -ENODEV:
8662                 printf("invalid port_id %d\n", res->port_id);
8663                 break;
8664         case -ENOTSUP:
8665                 printf("function not implemented or supported\n");
8666                 break;
8667         default:
8668                 printf("programming error: (%s)\n", strerror(-ret));
8669         }
8670 }
8671
8672 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8673         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8674                                  rx_vlan, "rx_vlan");
8675 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8676         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8677                                  what, "add#rm");
8678 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8679         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8680                               vlan_id, UINT16);
8681 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8682         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8683                                  port, "port");
8684 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8685         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8686                               port_id, UINT16);
8687 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8688         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8689                                  vf, "vf");
8690 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8691         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8692                               vf_mask, UINT64);
8693
8694 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8695         .f = cmd_vf_rx_vlan_filter_parsed,
8696         .data = NULL,
8697         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8698                 "(vf_mask = hexadecimal VF mask)",
8699         .tokens = {
8700                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8701                 (void *)&cmd_vf_rx_vlan_filter_what,
8702                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8703                 (void *)&cmd_vf_rx_vlan_filter_port,
8704                 (void *)&cmd_vf_rx_vlan_filter_portid,
8705                 (void *)&cmd_vf_rx_vlan_filter_vf,
8706                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8707                 NULL,
8708         },
8709 };
8710
8711 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8712 struct cmd_queue_rate_limit_result {
8713         cmdline_fixed_string_t set;
8714         cmdline_fixed_string_t port;
8715         uint16_t port_num;
8716         cmdline_fixed_string_t queue;
8717         uint8_t queue_num;
8718         cmdline_fixed_string_t rate;
8719         uint16_t rate_num;
8720 };
8721
8722 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8723                 __attribute__((unused)) struct cmdline *cl,
8724                 __attribute__((unused)) void *data)
8725 {
8726         struct cmd_queue_rate_limit_result *res = parsed_result;
8727         int ret = 0;
8728
8729         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8730                 && (strcmp(res->queue, "queue") == 0)
8731                 && (strcmp(res->rate, "rate") == 0))
8732                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8733                                         res->rate_num);
8734         if (ret < 0)
8735                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8736
8737 }
8738
8739 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8740         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8741                                 set, "set");
8742 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8743         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8744                                 port, "port");
8745 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8746         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8747                                 port_num, UINT16);
8748 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8749         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8750                                 queue, "queue");
8751 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8752         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8753                                 queue_num, UINT8);
8754 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8755         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8756                                 rate, "rate");
8757 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8758         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8759                                 rate_num, UINT16);
8760
8761 cmdline_parse_inst_t cmd_queue_rate_limit = {
8762         .f = cmd_queue_rate_limit_parsed,
8763         .data = (void *)0,
8764         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8765                 "Set rate limit for a queue on port_id",
8766         .tokens = {
8767                 (void *)&cmd_queue_rate_limit_set,
8768                 (void *)&cmd_queue_rate_limit_port,
8769                 (void *)&cmd_queue_rate_limit_portnum,
8770                 (void *)&cmd_queue_rate_limit_queue,
8771                 (void *)&cmd_queue_rate_limit_queuenum,
8772                 (void *)&cmd_queue_rate_limit_rate,
8773                 (void *)&cmd_queue_rate_limit_ratenum,
8774                 NULL,
8775         },
8776 };
8777
8778 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8779 struct cmd_vf_rate_limit_result {
8780         cmdline_fixed_string_t set;
8781         cmdline_fixed_string_t port;
8782         uint16_t port_num;
8783         cmdline_fixed_string_t vf;
8784         uint8_t vf_num;
8785         cmdline_fixed_string_t rate;
8786         uint16_t rate_num;
8787         cmdline_fixed_string_t q_msk;
8788         uint64_t q_msk_val;
8789 };
8790
8791 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8792                 __attribute__((unused)) struct cmdline *cl,
8793                 __attribute__((unused)) void *data)
8794 {
8795         struct cmd_vf_rate_limit_result *res = parsed_result;
8796         int ret = 0;
8797
8798         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8799                 && (strcmp(res->vf, "vf") == 0)
8800                 && (strcmp(res->rate, "rate") == 0)
8801                 && (strcmp(res->q_msk, "queue_mask") == 0))
8802                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8803                                         res->rate_num, res->q_msk_val);
8804         if (ret < 0)
8805                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8806
8807 }
8808
8809 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8810         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8811                                 set, "set");
8812 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8813         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8814                                 port, "port");
8815 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8816         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8817                                 port_num, UINT16);
8818 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8819         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8820                                 vf, "vf");
8821 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8822         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8823                                 vf_num, UINT8);
8824 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8825         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8826                                 rate, "rate");
8827 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8828         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8829                                 rate_num, UINT16);
8830 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8831         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8832                                 q_msk, "queue_mask");
8833 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8834         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8835                                 q_msk_val, UINT64);
8836
8837 cmdline_parse_inst_t cmd_vf_rate_limit = {
8838         .f = cmd_vf_rate_limit_parsed,
8839         .data = (void *)0,
8840         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8841                 "queue_mask <queue_mask_value>: "
8842                 "Set rate limit for queues of VF on port_id",
8843         .tokens = {
8844                 (void *)&cmd_vf_rate_limit_set,
8845                 (void *)&cmd_vf_rate_limit_port,
8846                 (void *)&cmd_vf_rate_limit_portnum,
8847                 (void *)&cmd_vf_rate_limit_vf,
8848                 (void *)&cmd_vf_rate_limit_vfnum,
8849                 (void *)&cmd_vf_rate_limit_rate,
8850                 (void *)&cmd_vf_rate_limit_ratenum,
8851                 (void *)&cmd_vf_rate_limit_q_msk,
8852                 (void *)&cmd_vf_rate_limit_q_msk_val,
8853                 NULL,
8854         },
8855 };
8856
8857 /* *** ADD TUNNEL FILTER OF A PORT *** */
8858 struct cmd_tunnel_filter_result {
8859         cmdline_fixed_string_t cmd;
8860         cmdline_fixed_string_t what;
8861         portid_t port_id;
8862         struct rte_ether_addr outer_mac;
8863         struct rte_ether_addr inner_mac;
8864         cmdline_ipaddr_t ip_value;
8865         uint16_t inner_vlan;
8866         cmdline_fixed_string_t tunnel_type;
8867         cmdline_fixed_string_t filter_type;
8868         uint32_t tenant_id;
8869         uint16_t queue_num;
8870 };
8871
8872 static void
8873 cmd_tunnel_filter_parsed(void *parsed_result,
8874                           __attribute__((unused)) struct cmdline *cl,
8875                           __attribute__((unused)) void *data)
8876 {
8877         struct cmd_tunnel_filter_result *res = parsed_result;
8878         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8879         int ret = 0;
8880
8881         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8882
8883         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8884         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8885         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8886
8887         if (res->ip_value.family == AF_INET) {
8888                 tunnel_filter_conf.ip_addr.ipv4_addr =
8889                         res->ip_value.addr.ipv4.s_addr;
8890                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8891         } else {
8892                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8893                         &(res->ip_value.addr.ipv6),
8894                         sizeof(struct in6_addr));
8895                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8896         }
8897
8898         if (!strcmp(res->filter_type, "imac-ivlan"))
8899                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8900         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8901                 tunnel_filter_conf.filter_type =
8902                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8903         else if (!strcmp(res->filter_type, "imac-tenid"))
8904                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8905         else if (!strcmp(res->filter_type, "imac"))
8906                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8907         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8908                 tunnel_filter_conf.filter_type =
8909                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8910         else if (!strcmp(res->filter_type, "oip"))
8911                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8912         else if (!strcmp(res->filter_type, "iip"))
8913                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8914         else {
8915                 printf("The filter type is not supported");
8916                 return;
8917         }
8918
8919         if (!strcmp(res->tunnel_type, "vxlan"))
8920                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8921         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8922                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8923         else if (!strcmp(res->tunnel_type, "nvgre"))
8924                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8925         else if (!strcmp(res->tunnel_type, "ipingre"))
8926                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8927         else {
8928                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8929                 return;
8930         }
8931
8932         tunnel_filter_conf.tenant_id = res->tenant_id;
8933         tunnel_filter_conf.queue_id = res->queue_num;
8934         if (!strcmp(res->what, "add"))
8935                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8936                                         RTE_ETH_FILTER_TUNNEL,
8937                                         RTE_ETH_FILTER_ADD,
8938                                         &tunnel_filter_conf);
8939         else
8940                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8941                                         RTE_ETH_FILTER_TUNNEL,
8942                                         RTE_ETH_FILTER_DELETE,
8943                                         &tunnel_filter_conf);
8944         if (ret < 0)
8945                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8946                                 strerror(-ret));
8947
8948 }
8949 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8950         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8951         cmd, "tunnel_filter");
8952 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8953         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8954         what, "add#rm");
8955 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8956         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8957         port_id, UINT16);
8958 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8959         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8960         outer_mac);
8961 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8962         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8963         inner_mac);
8964 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8965         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8966         inner_vlan, UINT16);
8967 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8968         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8969         ip_value);
8970 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8971         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8972         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8973
8974 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8975         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8976         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8977                 "imac#omac-imac-tenid");
8978 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8979         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8980         tenant_id, UINT32);
8981 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8982         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8983         queue_num, UINT16);
8984
8985 cmdline_parse_inst_t cmd_tunnel_filter = {
8986         .f = cmd_tunnel_filter_parsed,
8987         .data = (void *)0,
8988         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8989                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8990                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8991                 "<queue_id>: Add/Rm tunnel filter of a port",
8992         .tokens = {
8993                 (void *)&cmd_tunnel_filter_cmd,
8994                 (void *)&cmd_tunnel_filter_what,
8995                 (void *)&cmd_tunnel_filter_port_id,
8996                 (void *)&cmd_tunnel_filter_outer_mac,
8997                 (void *)&cmd_tunnel_filter_inner_mac,
8998                 (void *)&cmd_tunnel_filter_ip_value,
8999                 (void *)&cmd_tunnel_filter_innner_vlan,
9000                 (void *)&cmd_tunnel_filter_tunnel_type,
9001                 (void *)&cmd_tunnel_filter_filter_type,
9002                 (void *)&cmd_tunnel_filter_tenant_id,
9003                 (void *)&cmd_tunnel_filter_queue_num,
9004                 NULL,
9005         },
9006 };
9007
9008 /* *** CONFIGURE TUNNEL UDP PORT *** */
9009 struct cmd_tunnel_udp_config {
9010         cmdline_fixed_string_t cmd;
9011         cmdline_fixed_string_t what;
9012         uint16_t udp_port;
9013         portid_t port_id;
9014 };
9015
9016 static void
9017 cmd_tunnel_udp_config_parsed(void *parsed_result,
9018                           __attribute__((unused)) struct cmdline *cl,
9019                           __attribute__((unused)) void *data)
9020 {
9021         struct cmd_tunnel_udp_config *res = parsed_result;
9022         struct rte_eth_udp_tunnel tunnel_udp;
9023         int ret;
9024
9025         tunnel_udp.udp_port = res->udp_port;
9026
9027         if (!strcmp(res->cmd, "rx_vxlan_port"))
9028                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9029
9030         if (!strcmp(res->what, "add"))
9031                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9032                                                       &tunnel_udp);
9033         else
9034                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9035                                                          &tunnel_udp);
9036
9037         if (ret < 0)
9038                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9039 }
9040
9041 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9042         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9043                                 cmd, "rx_vxlan_port");
9044 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9045         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9046                                 what, "add#rm");
9047 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9048         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9049                                 udp_port, UINT16);
9050 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9051         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9052                                 port_id, UINT16);
9053
9054 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9055         .f = cmd_tunnel_udp_config_parsed,
9056         .data = (void *)0,
9057         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9058                 "Add/Remove a tunneling UDP port filter",
9059         .tokens = {
9060                 (void *)&cmd_tunnel_udp_config_cmd,
9061                 (void *)&cmd_tunnel_udp_config_what,
9062                 (void *)&cmd_tunnel_udp_config_udp_port,
9063                 (void *)&cmd_tunnel_udp_config_port_id,
9064                 NULL,
9065         },
9066 };
9067
9068 struct cmd_config_tunnel_udp_port {
9069         cmdline_fixed_string_t port;
9070         cmdline_fixed_string_t config;
9071         portid_t port_id;
9072         cmdline_fixed_string_t udp_tunnel_port;
9073         cmdline_fixed_string_t action;
9074         cmdline_fixed_string_t tunnel_type;
9075         uint16_t udp_port;
9076 };
9077
9078 static void
9079 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9080                                __attribute__((unused)) struct cmdline *cl,
9081                                __attribute__((unused)) void *data)
9082 {
9083         struct cmd_config_tunnel_udp_port *res = parsed_result;
9084         struct rte_eth_udp_tunnel tunnel_udp;
9085         int ret = 0;
9086
9087         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9088                 return;
9089
9090         tunnel_udp.udp_port = res->udp_port;
9091
9092         if (!strcmp(res->tunnel_type, "vxlan")) {
9093                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9094         } else if (!strcmp(res->tunnel_type, "geneve")) {
9095                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9096         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9097                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9098         } else {
9099                 printf("Invalid tunnel type\n");
9100                 return;
9101         }
9102
9103         if (!strcmp(res->action, "add"))
9104                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9105                                                       &tunnel_udp);
9106         else
9107                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9108                                                          &tunnel_udp);
9109
9110         if (ret < 0)
9111                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9112 }
9113
9114 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9115         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9116                                  "port");
9117 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9118         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9119                                  "config");
9120 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9121         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9122                               UINT16);
9123 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9124         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9125                                  udp_tunnel_port,
9126                                  "udp_tunnel_port");
9127 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9128         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9129                                  "add#rm");
9130 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9131         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9132                                  "vxlan#geneve#vxlan-gpe");
9133 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9134         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9135                               UINT16);
9136
9137 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9138         .f = cmd_cfg_tunnel_udp_port_parsed,
9139         .data = NULL,
9140         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9141         .tokens = {
9142                 (void *)&cmd_config_tunnel_udp_port_port,
9143                 (void *)&cmd_config_tunnel_udp_port_config,
9144                 (void *)&cmd_config_tunnel_udp_port_port_id,
9145                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9146                 (void *)&cmd_config_tunnel_udp_port_action,
9147                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9148                 (void *)&cmd_config_tunnel_udp_port_value,
9149                 NULL,
9150         },
9151 };
9152
9153 /* *** GLOBAL CONFIG *** */
9154 struct cmd_global_config_result {
9155         cmdline_fixed_string_t cmd;
9156         portid_t port_id;
9157         cmdline_fixed_string_t cfg_type;
9158         uint8_t len;
9159 };
9160
9161 static void
9162 cmd_global_config_parsed(void *parsed_result,
9163                          __attribute__((unused)) struct cmdline *cl,
9164                          __attribute__((unused)) void *data)
9165 {
9166         struct cmd_global_config_result *res = parsed_result;
9167         struct rte_eth_global_cfg conf;
9168         int ret;
9169
9170         memset(&conf, 0, sizeof(conf));
9171         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9172         conf.cfg.gre_key_len = res->len;
9173         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9174                                       RTE_ETH_FILTER_SET, &conf);
9175         if (ret != 0)
9176                 printf("Global config error\n");
9177 }
9178
9179 cmdline_parse_token_string_t cmd_global_config_cmd =
9180         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9181                 "global_config");
9182 cmdline_parse_token_num_t cmd_global_config_port_id =
9183         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9184                                UINT16);
9185 cmdline_parse_token_string_t cmd_global_config_type =
9186         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9187                 cfg_type, "gre-key-len");
9188 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9189         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9190                 len, UINT8);
9191
9192 cmdline_parse_inst_t cmd_global_config = {
9193         .f = cmd_global_config_parsed,
9194         .data = (void *)NULL,
9195         .help_str = "global_config <port_id> gre-key-len <key_len>",
9196         .tokens = {
9197                 (void *)&cmd_global_config_cmd,
9198                 (void *)&cmd_global_config_port_id,
9199                 (void *)&cmd_global_config_type,
9200                 (void *)&cmd_global_config_gre_key_len,
9201                 NULL,
9202         },
9203 };
9204
9205 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9206 struct cmd_set_mirror_mask_result {
9207         cmdline_fixed_string_t set;
9208         cmdline_fixed_string_t port;
9209         portid_t port_id;
9210         cmdline_fixed_string_t mirror;
9211         uint8_t rule_id;
9212         cmdline_fixed_string_t what;
9213         cmdline_fixed_string_t value;
9214         cmdline_fixed_string_t dstpool;
9215         uint8_t dstpool_id;
9216         cmdline_fixed_string_t on;
9217 };
9218
9219 cmdline_parse_token_string_t cmd_mirror_mask_set =
9220         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9221                                 set, "set");
9222 cmdline_parse_token_string_t cmd_mirror_mask_port =
9223         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9224                                 port, "port");
9225 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9226         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9227                                 port_id, UINT16);
9228 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9229         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9230                                 mirror, "mirror-rule");
9231 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9232         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9233                                 rule_id, UINT8);
9234 cmdline_parse_token_string_t cmd_mirror_mask_what =
9235         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9236                                 what, "pool-mirror-up#pool-mirror-down"
9237                                       "#vlan-mirror");
9238 cmdline_parse_token_string_t cmd_mirror_mask_value =
9239         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9240                                 value, NULL);
9241 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9242         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9243                                 dstpool, "dst-pool");
9244 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9245         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9246                                 dstpool_id, UINT8);
9247 cmdline_parse_token_string_t cmd_mirror_mask_on =
9248         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9249                                 on, "on#off");
9250
9251 static void
9252 cmd_set_mirror_mask_parsed(void *parsed_result,
9253                        __attribute__((unused)) struct cmdline *cl,
9254                        __attribute__((unused)) void *data)
9255 {
9256         int ret,nb_item,i;
9257         struct cmd_set_mirror_mask_result *res = parsed_result;
9258         struct rte_eth_mirror_conf mr_conf;
9259
9260         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9261
9262         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9263
9264         mr_conf.dst_pool = res->dstpool_id;
9265
9266         if (!strcmp(res->what, "pool-mirror-up")) {
9267                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9268                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9269         } else if (!strcmp(res->what, "pool-mirror-down")) {
9270                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9271                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9272         } else if (!strcmp(res->what, "vlan-mirror")) {
9273                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9274                 nb_item = parse_item_list(res->value, "vlan",
9275                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9276                 if (nb_item <= 0)
9277                         return;
9278
9279                 for (i = 0; i < nb_item; i++) {
9280                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9281                                 printf("Invalid vlan_id: must be < 4096\n");
9282                                 return;
9283                         }
9284
9285                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9286                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9287                 }
9288         }
9289
9290         if (!strcmp(res->on, "on"))
9291                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9292                                                 res->rule_id, 1);
9293         else
9294                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9295                                                 res->rule_id, 0);
9296         if (ret < 0)
9297                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9298 }
9299
9300 cmdline_parse_inst_t cmd_set_mirror_mask = {
9301                 .f = cmd_set_mirror_mask_parsed,
9302                 .data = NULL,
9303                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9304                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9305                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9306                 .tokens = {
9307                         (void *)&cmd_mirror_mask_set,
9308                         (void *)&cmd_mirror_mask_port,
9309                         (void *)&cmd_mirror_mask_portid,
9310                         (void *)&cmd_mirror_mask_mirror,
9311                         (void *)&cmd_mirror_mask_ruleid,
9312                         (void *)&cmd_mirror_mask_what,
9313                         (void *)&cmd_mirror_mask_value,
9314                         (void *)&cmd_mirror_mask_dstpool,
9315                         (void *)&cmd_mirror_mask_poolid,
9316                         (void *)&cmd_mirror_mask_on,
9317                         NULL,
9318                 },
9319 };
9320
9321 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9322 struct cmd_set_mirror_link_result {
9323         cmdline_fixed_string_t set;
9324         cmdline_fixed_string_t port;
9325         portid_t port_id;
9326         cmdline_fixed_string_t mirror;
9327         uint8_t rule_id;
9328         cmdline_fixed_string_t what;
9329         cmdline_fixed_string_t dstpool;
9330         uint8_t dstpool_id;
9331         cmdline_fixed_string_t on;
9332 };
9333
9334 cmdline_parse_token_string_t cmd_mirror_link_set =
9335         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9336                                  set, "set");
9337 cmdline_parse_token_string_t cmd_mirror_link_port =
9338         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9339                                 port, "port");
9340 cmdline_parse_token_num_t cmd_mirror_link_portid =
9341         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9342                                 port_id, UINT16);
9343 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9344         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9345                                 mirror, "mirror-rule");
9346 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9347         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9348                             rule_id, UINT8);
9349 cmdline_parse_token_string_t cmd_mirror_link_what =
9350         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9351                                 what, "uplink-mirror#downlink-mirror");
9352 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9353         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9354                                 dstpool, "dst-pool");
9355 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9356         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9357                                 dstpool_id, UINT8);
9358 cmdline_parse_token_string_t cmd_mirror_link_on =
9359         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9360                                 on, "on#off");
9361
9362 static void
9363 cmd_set_mirror_link_parsed(void *parsed_result,
9364                        __attribute__((unused)) struct cmdline *cl,
9365                        __attribute__((unused)) void *data)
9366 {
9367         int ret;
9368         struct cmd_set_mirror_link_result *res = parsed_result;
9369         struct rte_eth_mirror_conf mr_conf;
9370
9371         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9372         if (!strcmp(res->what, "uplink-mirror"))
9373                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9374         else
9375                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9376
9377         mr_conf.dst_pool = res->dstpool_id;
9378
9379         if (!strcmp(res->on, "on"))
9380                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9381                                                 res->rule_id, 1);
9382         else
9383                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9384                                                 res->rule_id, 0);
9385
9386         /* check the return value and print it if is < 0 */
9387         if (ret < 0)
9388                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9389
9390 }
9391
9392 cmdline_parse_inst_t cmd_set_mirror_link = {
9393                 .f = cmd_set_mirror_link_parsed,
9394                 .data = NULL,
9395                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9396                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9397                 .tokens = {
9398                         (void *)&cmd_mirror_link_set,
9399                         (void *)&cmd_mirror_link_port,
9400                         (void *)&cmd_mirror_link_portid,
9401                         (void *)&cmd_mirror_link_mirror,
9402                         (void *)&cmd_mirror_link_ruleid,
9403                         (void *)&cmd_mirror_link_what,
9404                         (void *)&cmd_mirror_link_dstpool,
9405                         (void *)&cmd_mirror_link_poolid,
9406                         (void *)&cmd_mirror_link_on,
9407                         NULL,
9408                 },
9409 };
9410
9411 /* *** RESET VM MIRROR RULE *** */
9412 struct cmd_rm_mirror_rule_result {
9413         cmdline_fixed_string_t reset;
9414         cmdline_fixed_string_t port;
9415         portid_t port_id;
9416         cmdline_fixed_string_t mirror;
9417         uint8_t rule_id;
9418 };
9419
9420 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9421         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9422                                  reset, "reset");
9423 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9424         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9425                                 port, "port");
9426 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9427         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9428                                 port_id, UINT16);
9429 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9430         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9431                                 mirror, "mirror-rule");
9432 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9433         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9434                                 rule_id, UINT8);
9435
9436 static void
9437 cmd_reset_mirror_rule_parsed(void *parsed_result,
9438                        __attribute__((unused)) struct cmdline *cl,
9439                        __attribute__((unused)) void *data)
9440 {
9441         int ret;
9442         struct cmd_set_mirror_link_result *res = parsed_result;
9443         /* check rule_id */
9444         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9445         if(ret < 0)
9446                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9447 }
9448
9449 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9450                 .f = cmd_reset_mirror_rule_parsed,
9451                 .data = NULL,
9452                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9453                 .tokens = {
9454                         (void *)&cmd_rm_mirror_rule_reset,
9455                         (void *)&cmd_rm_mirror_rule_port,
9456                         (void *)&cmd_rm_mirror_rule_portid,
9457                         (void *)&cmd_rm_mirror_rule_mirror,
9458                         (void *)&cmd_rm_mirror_rule_ruleid,
9459                         NULL,
9460                 },
9461 };
9462
9463 /* ******************************************************************************** */
9464
9465 struct cmd_dump_result {
9466         cmdline_fixed_string_t dump;
9467 };
9468
9469 static void
9470 dump_struct_sizes(void)
9471 {
9472 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9473         DUMP_SIZE(struct rte_mbuf);
9474         DUMP_SIZE(struct rte_mempool);
9475         DUMP_SIZE(struct rte_ring);
9476 #undef DUMP_SIZE
9477 }
9478
9479 static void cmd_dump_parsed(void *parsed_result,
9480                             __attribute__((unused)) struct cmdline *cl,
9481                             __attribute__((unused)) void *data)
9482 {
9483         struct cmd_dump_result *res = parsed_result;
9484
9485         if (!strcmp(res->dump, "dump_physmem"))
9486                 rte_dump_physmem_layout(stdout);
9487         else if (!strcmp(res->dump, "dump_memzone"))
9488                 rte_memzone_dump(stdout);
9489         else if (!strcmp(res->dump, "dump_struct_sizes"))
9490                 dump_struct_sizes();
9491         else if (!strcmp(res->dump, "dump_ring"))
9492                 rte_ring_list_dump(stdout);
9493         else if (!strcmp(res->dump, "dump_mempool"))
9494                 rte_mempool_list_dump(stdout);
9495         else if (!strcmp(res->dump, "dump_devargs"))
9496                 rte_devargs_dump(stdout);
9497         else if (!strcmp(res->dump, "dump_log_types"))
9498                 rte_log_dump(stdout);
9499 }
9500
9501 cmdline_parse_token_string_t cmd_dump_dump =
9502         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9503                 "dump_physmem#"
9504                 "dump_memzone#"
9505                 "dump_struct_sizes#"
9506                 "dump_ring#"
9507                 "dump_mempool#"
9508                 "dump_devargs#"
9509                 "dump_log_types");
9510
9511 cmdline_parse_inst_t cmd_dump = {
9512         .f = cmd_dump_parsed,  /* function to call */
9513         .data = NULL,      /* 2nd arg of func */
9514         .help_str = "Dump status",
9515         .tokens = {        /* token list, NULL terminated */
9516                 (void *)&cmd_dump_dump,
9517                 NULL,
9518         },
9519 };
9520
9521 /* ******************************************************************************** */
9522
9523 struct cmd_dump_one_result {
9524         cmdline_fixed_string_t dump;
9525         cmdline_fixed_string_t name;
9526 };
9527
9528 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9529                                 __attribute__((unused)) void *data)
9530 {
9531         struct cmd_dump_one_result *res = parsed_result;
9532
9533         if (!strcmp(res->dump, "dump_ring")) {
9534                 struct rte_ring *r;
9535                 r = rte_ring_lookup(res->name);
9536                 if (r == NULL) {
9537                         cmdline_printf(cl, "Cannot find ring\n");
9538                         return;
9539                 }
9540                 rte_ring_dump(stdout, r);
9541         } else if (!strcmp(res->dump, "dump_mempool")) {
9542                 struct rte_mempool *mp;
9543                 mp = rte_mempool_lookup(res->name);
9544                 if (mp == NULL) {
9545                         cmdline_printf(cl, "Cannot find mempool\n");
9546                         return;
9547                 }
9548                 rte_mempool_dump(stdout, mp);
9549         }
9550 }
9551
9552 cmdline_parse_token_string_t cmd_dump_one_dump =
9553         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9554                                  "dump_ring#dump_mempool");
9555
9556 cmdline_parse_token_string_t cmd_dump_one_name =
9557         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9558
9559 cmdline_parse_inst_t cmd_dump_one = {
9560         .f = cmd_dump_one_parsed,  /* function to call */
9561         .data = NULL,      /* 2nd arg of func */
9562         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9563         .tokens = {        /* token list, NULL terminated */
9564                 (void *)&cmd_dump_one_dump,
9565                 (void *)&cmd_dump_one_name,
9566                 NULL,
9567         },
9568 };
9569
9570 /* *** Add/Del syn filter *** */
9571 struct cmd_syn_filter_result {
9572         cmdline_fixed_string_t filter;
9573         portid_t port_id;
9574         cmdline_fixed_string_t ops;
9575         cmdline_fixed_string_t priority;
9576         cmdline_fixed_string_t high;
9577         cmdline_fixed_string_t queue;
9578         uint16_t queue_id;
9579 };
9580
9581 static void
9582 cmd_syn_filter_parsed(void *parsed_result,
9583                         __attribute__((unused)) struct cmdline *cl,
9584                         __attribute__((unused)) void *data)
9585 {
9586         struct cmd_syn_filter_result *res = parsed_result;
9587         struct rte_eth_syn_filter syn_filter;
9588         int ret = 0;
9589
9590         ret = rte_eth_dev_filter_supported(res->port_id,
9591                                         RTE_ETH_FILTER_SYN);
9592         if (ret < 0) {
9593                 printf("syn filter is not supported on port %u.\n",
9594                                 res->port_id);
9595                 return;
9596         }
9597
9598         memset(&syn_filter, 0, sizeof(syn_filter));
9599
9600         if (!strcmp(res->ops, "add")) {
9601                 if (!strcmp(res->high, "high"))
9602                         syn_filter.hig_pri = 1;
9603                 else
9604                         syn_filter.hig_pri = 0;
9605
9606                 syn_filter.queue = res->queue_id;
9607                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9608                                                 RTE_ETH_FILTER_SYN,
9609                                                 RTE_ETH_FILTER_ADD,
9610                                                 &syn_filter);
9611         } else
9612                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9613                                                 RTE_ETH_FILTER_SYN,
9614                                                 RTE_ETH_FILTER_DELETE,
9615                                                 &syn_filter);
9616
9617         if (ret < 0)
9618                 printf("syn filter programming error: (%s)\n",
9619                                 strerror(-ret));
9620 }
9621
9622 cmdline_parse_token_string_t cmd_syn_filter_filter =
9623         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9624         filter, "syn_filter");
9625 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9626         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9627         port_id, UINT16);
9628 cmdline_parse_token_string_t cmd_syn_filter_ops =
9629         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9630         ops, "add#del");
9631 cmdline_parse_token_string_t cmd_syn_filter_priority =
9632         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9633                                 priority, "priority");
9634 cmdline_parse_token_string_t cmd_syn_filter_high =
9635         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9636                                 high, "high#low");
9637 cmdline_parse_token_string_t cmd_syn_filter_queue =
9638         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9639                                 queue, "queue");
9640 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9641         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9642                                 queue_id, UINT16);
9643
9644 cmdline_parse_inst_t cmd_syn_filter = {
9645         .f = cmd_syn_filter_parsed,
9646         .data = NULL,
9647         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9648                 "<queue_id>: Add/Delete syn filter",
9649         .tokens = {
9650                 (void *)&cmd_syn_filter_filter,
9651                 (void *)&cmd_syn_filter_port_id,
9652                 (void *)&cmd_syn_filter_ops,
9653                 (void *)&cmd_syn_filter_priority,
9654                 (void *)&cmd_syn_filter_high,
9655                 (void *)&cmd_syn_filter_queue,
9656                 (void *)&cmd_syn_filter_queue_id,
9657                 NULL,
9658         },
9659 };
9660
9661 /* *** queue region set *** */
9662 struct cmd_queue_region_result {
9663         cmdline_fixed_string_t set;
9664         cmdline_fixed_string_t port;
9665         portid_t port_id;
9666         cmdline_fixed_string_t cmd;
9667         cmdline_fixed_string_t region;
9668         uint8_t  region_id;
9669         cmdline_fixed_string_t queue_start_index;
9670         uint8_t  queue_id;
9671         cmdline_fixed_string_t queue_num;
9672         uint8_t  queue_num_value;
9673 };
9674
9675 static void
9676 cmd_queue_region_parsed(void *parsed_result,
9677                         __attribute__((unused)) struct cmdline *cl,
9678                         __attribute__((unused)) void *data)
9679 {
9680         struct cmd_queue_region_result *res = parsed_result;
9681         int ret = -ENOTSUP;
9682 #ifdef RTE_LIBRTE_I40E_PMD
9683         struct rte_pmd_i40e_queue_region_conf region_conf;
9684         enum rte_pmd_i40e_queue_region_op op_type;
9685 #endif
9686
9687         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9688                 return;
9689
9690 #ifdef RTE_LIBRTE_I40E_PMD
9691         memset(&region_conf, 0, sizeof(region_conf));
9692         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9693         region_conf.region_id = res->region_id;
9694         region_conf.queue_num = res->queue_num_value;
9695         region_conf.queue_start_index = res->queue_id;
9696
9697         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9698                                 op_type, &region_conf);
9699 #endif
9700
9701         switch (ret) {
9702         case 0:
9703                 break;
9704         case -ENOTSUP:
9705                 printf("function not implemented or supported\n");
9706                 break;
9707         default:
9708                 printf("queue region config error: (%s)\n", strerror(-ret));
9709         }
9710 }
9711
9712 cmdline_parse_token_string_t cmd_queue_region_set =
9713 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9714                 set, "set");
9715 cmdline_parse_token_string_t cmd_queue_region_port =
9716         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9717 cmdline_parse_token_num_t cmd_queue_region_port_id =
9718         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9719                                 port_id, UINT16);
9720 cmdline_parse_token_string_t cmd_queue_region_cmd =
9721         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9722                                  cmd, "queue-region");
9723 cmdline_parse_token_string_t cmd_queue_region_id =
9724         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9725                                 region, "region_id");
9726 cmdline_parse_token_num_t cmd_queue_region_index =
9727         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9728                                 region_id, UINT8);
9729 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9730         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9731                                 queue_start_index, "queue_start_index");
9732 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9733         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9734                                 queue_id, UINT8);
9735 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9736         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9737                                 queue_num, "queue_num");
9738 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9739         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9740                                 queue_num_value, UINT8);
9741
9742 cmdline_parse_inst_t cmd_queue_region = {
9743         .f = cmd_queue_region_parsed,
9744         .data = NULL,
9745         .help_str = "set port <port_id> queue-region region_id <value> "
9746                 "queue_start_index <value> queue_num <value>: Set a queue region",
9747         .tokens = {
9748                 (void *)&cmd_queue_region_set,
9749                 (void *)&cmd_queue_region_port,
9750                 (void *)&cmd_queue_region_port_id,
9751                 (void *)&cmd_queue_region_cmd,
9752                 (void *)&cmd_queue_region_id,
9753                 (void *)&cmd_queue_region_index,
9754                 (void *)&cmd_queue_region_queue_start_index,
9755                 (void *)&cmd_queue_region_queue_id,
9756                 (void *)&cmd_queue_region_queue_num,
9757                 (void *)&cmd_queue_region_queue_num_value,
9758                 NULL,
9759         },
9760 };
9761
9762 /* *** queue region and flowtype set *** */
9763 struct cmd_region_flowtype_result {
9764         cmdline_fixed_string_t set;
9765         cmdline_fixed_string_t port;
9766         portid_t port_id;
9767         cmdline_fixed_string_t cmd;
9768         cmdline_fixed_string_t region;
9769         uint8_t  region_id;
9770         cmdline_fixed_string_t flowtype;
9771         uint8_t  flowtype_id;
9772 };
9773
9774 static void
9775 cmd_region_flowtype_parsed(void *parsed_result,
9776                         __attribute__((unused)) struct cmdline *cl,
9777                         __attribute__((unused)) void *data)
9778 {
9779         struct cmd_region_flowtype_result *res = parsed_result;
9780         int ret = -ENOTSUP;
9781 #ifdef RTE_LIBRTE_I40E_PMD
9782         struct rte_pmd_i40e_queue_region_conf region_conf;
9783         enum rte_pmd_i40e_queue_region_op op_type;
9784 #endif
9785
9786         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9787                 return;
9788
9789 #ifdef RTE_LIBRTE_I40E_PMD
9790         memset(&region_conf, 0, sizeof(region_conf));
9791
9792         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9793         region_conf.region_id = res->region_id;
9794         region_conf.hw_flowtype = res->flowtype_id;
9795
9796         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9797                         op_type, &region_conf);
9798 #endif
9799
9800         switch (ret) {
9801         case 0:
9802                 break;
9803         case -ENOTSUP:
9804                 printf("function not implemented or supported\n");
9805                 break;
9806         default:
9807                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9808         }
9809 }
9810
9811 cmdline_parse_token_string_t cmd_region_flowtype_set =
9812 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9813                                 set, "set");
9814 cmdline_parse_token_string_t cmd_region_flowtype_port =
9815         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9816                                 port, "port");
9817 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9818         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9819                                 port_id, UINT16);
9820 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9821         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9822                                 cmd, "queue-region");
9823 cmdline_parse_token_string_t cmd_region_flowtype_index =
9824         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9825                                 region, "region_id");
9826 cmdline_parse_token_num_t cmd_region_flowtype_id =
9827         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9828                                 region_id, UINT8);
9829 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9830         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9831                                 flowtype, "flowtype");
9832 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9833         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9834                                 flowtype_id, UINT8);
9835 cmdline_parse_inst_t cmd_region_flowtype = {
9836         .f = cmd_region_flowtype_parsed,
9837         .data = NULL,
9838         .help_str = "set port <port_id> queue-region region_id <value> "
9839                 "flowtype <value>: Set a flowtype region index",
9840         .tokens = {
9841                 (void *)&cmd_region_flowtype_set,
9842                 (void *)&cmd_region_flowtype_port,
9843                 (void *)&cmd_region_flowtype_port_index,
9844                 (void *)&cmd_region_flowtype_cmd,
9845                 (void *)&cmd_region_flowtype_index,
9846                 (void *)&cmd_region_flowtype_id,
9847                 (void *)&cmd_region_flowtype_flow_index,
9848                 (void *)&cmd_region_flowtype_flow_id,
9849                 NULL,
9850         },
9851 };
9852
9853 /* *** User Priority (UP) to queue region (region_id) set *** */
9854 struct cmd_user_priority_region_result {
9855         cmdline_fixed_string_t set;
9856         cmdline_fixed_string_t port;
9857         portid_t port_id;
9858         cmdline_fixed_string_t cmd;
9859         cmdline_fixed_string_t user_priority;
9860         uint8_t  user_priority_id;
9861         cmdline_fixed_string_t region;
9862         uint8_t  region_id;
9863 };
9864
9865 static void
9866 cmd_user_priority_region_parsed(void *parsed_result,
9867                         __attribute__((unused)) struct cmdline *cl,
9868                         __attribute__((unused)) void *data)
9869 {
9870         struct cmd_user_priority_region_result *res = parsed_result;
9871         int ret = -ENOTSUP;
9872 #ifdef RTE_LIBRTE_I40E_PMD
9873         struct rte_pmd_i40e_queue_region_conf region_conf;
9874         enum rte_pmd_i40e_queue_region_op op_type;
9875 #endif
9876
9877         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9878                 return;
9879
9880 #ifdef RTE_LIBRTE_I40E_PMD
9881         memset(&region_conf, 0, sizeof(region_conf));
9882         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9883         region_conf.user_priority = res->user_priority_id;
9884         region_conf.region_id = res->region_id;
9885
9886         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9887                                 op_type, &region_conf);
9888 #endif
9889
9890         switch (ret) {
9891         case 0:
9892                 break;
9893         case -ENOTSUP:
9894                 printf("function not implemented or supported\n");
9895                 break;
9896         default:
9897                 printf("user_priority region config error: (%s)\n",
9898                                 strerror(-ret));
9899         }
9900 }
9901
9902 cmdline_parse_token_string_t cmd_user_priority_region_set =
9903         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9904                                 set, "set");
9905 cmdline_parse_token_string_t cmd_user_priority_region_port =
9906         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9907                                 port, "port");
9908 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9909         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9910                                 port_id, UINT16);
9911 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9912         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9913                                 cmd, "queue-region");
9914 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9915         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9916                                 user_priority, "UP");
9917 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9918         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9919                                 user_priority_id, UINT8);
9920 cmdline_parse_token_string_t cmd_user_priority_region_region =
9921         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9922                                 region, "region_id");
9923 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9924         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9925                                 region_id, UINT8);
9926
9927 cmdline_parse_inst_t cmd_user_priority_region = {
9928         .f = cmd_user_priority_region_parsed,
9929         .data = NULL,
9930         .help_str = "set port <port_id> queue-region UP <value> "
9931                 "region_id <value>: Set the mapping of User Priority (UP) "
9932                 "to queue region (region_id) ",
9933         .tokens = {
9934                 (void *)&cmd_user_priority_region_set,
9935                 (void *)&cmd_user_priority_region_port,
9936                 (void *)&cmd_user_priority_region_port_index,
9937                 (void *)&cmd_user_priority_region_cmd,
9938                 (void *)&cmd_user_priority_region_UP,
9939                 (void *)&cmd_user_priority_region_UP_id,
9940                 (void *)&cmd_user_priority_region_region,
9941                 (void *)&cmd_user_priority_region_region_id,
9942                 NULL,
9943         },
9944 };
9945
9946 /* *** flush all queue region related configuration *** */
9947 struct cmd_flush_queue_region_result {
9948         cmdline_fixed_string_t set;
9949         cmdline_fixed_string_t port;
9950         portid_t port_id;
9951         cmdline_fixed_string_t cmd;
9952         cmdline_fixed_string_t flush;
9953         cmdline_fixed_string_t what;
9954 };
9955
9956 static void
9957 cmd_flush_queue_region_parsed(void *parsed_result,
9958                         __attribute__((unused)) struct cmdline *cl,
9959                         __attribute__((unused)) void *data)
9960 {
9961         struct cmd_flush_queue_region_result *res = parsed_result;
9962         int ret = -ENOTSUP;
9963 #ifdef RTE_LIBRTE_I40E_PMD
9964         struct rte_pmd_i40e_queue_region_conf region_conf;
9965         enum rte_pmd_i40e_queue_region_op op_type;
9966 #endif
9967
9968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9969                 return;
9970
9971 #ifdef RTE_LIBRTE_I40E_PMD
9972         memset(&region_conf, 0, sizeof(region_conf));
9973
9974         if (strcmp(res->what, "on") == 0)
9975                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9976         else
9977                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9978
9979         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9980                                 op_type, &region_conf);
9981 #endif
9982
9983         switch (ret) {
9984         case 0:
9985                 break;
9986         case -ENOTSUP:
9987                 printf("function not implemented or supported\n");
9988                 break;
9989         default:
9990                 printf("queue region config flush error: (%s)\n",
9991                                 strerror(-ret));
9992         }
9993 }
9994
9995 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9996         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9997                                 set, "set");
9998 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9999         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10000                                 port, "port");
10001 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10002         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10003                                 port_id, UINT16);
10004 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10005         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10006                                 cmd, "queue-region");
10007 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10008         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10009                                 flush, "flush");
10010 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10011         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10012                                 what, "on#off");
10013
10014 cmdline_parse_inst_t cmd_flush_queue_region = {
10015         .f = cmd_flush_queue_region_parsed,
10016         .data = NULL,
10017         .help_str = "set port <port_id> queue-region flush on|off"
10018                 ": flush all queue region related configuration",
10019         .tokens = {
10020                 (void *)&cmd_flush_queue_region_set,
10021                 (void *)&cmd_flush_queue_region_port,
10022                 (void *)&cmd_flush_queue_region_port_index,
10023                 (void *)&cmd_flush_queue_region_cmd,
10024                 (void *)&cmd_flush_queue_region_flush,
10025                 (void *)&cmd_flush_queue_region_what,
10026                 NULL,
10027         },
10028 };
10029
10030 /* *** get all queue region related configuration info *** */
10031 struct cmd_show_queue_region_info {
10032         cmdline_fixed_string_t show;
10033         cmdline_fixed_string_t port;
10034         portid_t port_id;
10035         cmdline_fixed_string_t cmd;
10036 };
10037
10038 static void
10039 cmd_show_queue_region_info_parsed(void *parsed_result,
10040                         __attribute__((unused)) struct cmdline *cl,
10041                         __attribute__((unused)) void *data)
10042 {
10043         struct cmd_show_queue_region_info *res = parsed_result;
10044         int ret = -ENOTSUP;
10045 #ifdef RTE_LIBRTE_I40E_PMD
10046         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10047         enum rte_pmd_i40e_queue_region_op op_type;
10048 #endif
10049
10050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10051                 return;
10052
10053 #ifdef RTE_LIBRTE_I40E_PMD
10054         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10055
10056         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10057
10058         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10059                                         op_type, &rte_pmd_regions);
10060
10061         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10062 #endif
10063
10064         switch (ret) {
10065         case 0:
10066                 break;
10067         case -ENOTSUP:
10068                 printf("function not implemented or supported\n");
10069                 break;
10070         default:
10071                 printf("queue region config info show error: (%s)\n",
10072                                 strerror(-ret));
10073         }
10074 }
10075
10076 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10077 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10078                                 show, "show");
10079 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10080         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10081                                 port, "port");
10082 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10083         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10084                                 port_id, UINT16);
10085 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10086         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10087                                 cmd, "queue-region");
10088
10089 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10090         .f = cmd_show_queue_region_info_parsed,
10091         .data = NULL,
10092         .help_str = "show port <port_id> queue-region"
10093                 ": show all queue region related configuration info",
10094         .tokens = {
10095                 (void *)&cmd_show_queue_region_info_get,
10096                 (void *)&cmd_show_queue_region_info_port,
10097                 (void *)&cmd_show_queue_region_info_port_index,
10098                 (void *)&cmd_show_queue_region_info_cmd,
10099                 NULL,
10100         },
10101 };
10102
10103 /* *** ADD/REMOVE A 2tuple FILTER *** */
10104 struct cmd_2tuple_filter_result {
10105         cmdline_fixed_string_t filter;
10106         portid_t port_id;
10107         cmdline_fixed_string_t ops;
10108         cmdline_fixed_string_t dst_port;
10109         uint16_t dst_port_value;
10110         cmdline_fixed_string_t protocol;
10111         uint8_t protocol_value;
10112         cmdline_fixed_string_t mask;
10113         uint8_t  mask_value;
10114         cmdline_fixed_string_t tcp_flags;
10115         uint8_t tcp_flags_value;
10116         cmdline_fixed_string_t priority;
10117         uint8_t  priority_value;
10118         cmdline_fixed_string_t queue;
10119         uint16_t  queue_id;
10120 };
10121
10122 static void
10123 cmd_2tuple_filter_parsed(void *parsed_result,
10124                         __attribute__((unused)) struct cmdline *cl,
10125                         __attribute__((unused)) void *data)
10126 {
10127         struct rte_eth_ntuple_filter filter;
10128         struct cmd_2tuple_filter_result *res = parsed_result;
10129         int ret = 0;
10130
10131         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10132         if (ret < 0) {
10133                 printf("ntuple filter is not supported on port %u.\n",
10134                         res->port_id);
10135                 return;
10136         }
10137
10138         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10139
10140         filter.flags = RTE_2TUPLE_FLAGS;
10141         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10142         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10143         filter.proto = res->protocol_value;
10144         filter.priority = res->priority_value;
10145         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10146                 printf("nonzero tcp_flags is only meaningful"
10147                         " when protocol is TCP.\n");
10148                 return;
10149         }
10150         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10151                 printf("invalid TCP flags.\n");
10152                 return;
10153         }
10154
10155         if (res->tcp_flags_value != 0) {
10156                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10157                 filter.tcp_flags = res->tcp_flags_value;
10158         }
10159
10160         /* need convert to big endian. */
10161         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10162         filter.queue = res->queue_id;
10163
10164         if (!strcmp(res->ops, "add"))
10165                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10166                                 RTE_ETH_FILTER_NTUPLE,
10167                                 RTE_ETH_FILTER_ADD,
10168                                 &filter);
10169         else
10170                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10171                                 RTE_ETH_FILTER_NTUPLE,
10172                                 RTE_ETH_FILTER_DELETE,
10173                                 &filter);
10174         if (ret < 0)
10175                 printf("2tuple filter programming error: (%s)\n",
10176                         strerror(-ret));
10177
10178 }
10179
10180 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10181         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10182                                  filter, "2tuple_filter");
10183 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10184         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10185                                 port_id, UINT16);
10186 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10187         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10188                                  ops, "add#del");
10189 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10190         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10191                                 dst_port, "dst_port");
10192 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10193         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10194                                 dst_port_value, UINT16);
10195 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10196         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10197                                 protocol, "protocol");
10198 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10199         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10200                                 protocol_value, UINT8);
10201 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10202         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10203                                 mask, "mask");
10204 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10205         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10206                                 mask_value, INT8);
10207 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10208         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10209                                 tcp_flags, "tcp_flags");
10210 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10211         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10212                                 tcp_flags_value, UINT8);
10213 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10214         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10215                                 priority, "priority");
10216 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10217         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10218                                 priority_value, UINT8);
10219 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10220         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10221                                 queue, "queue");
10222 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10223         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10224                                 queue_id, UINT16);
10225
10226 cmdline_parse_inst_t cmd_2tuple_filter = {
10227         .f = cmd_2tuple_filter_parsed,
10228         .data = NULL,
10229         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10230                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10231                 "<queue_id>: Add a 2tuple filter",
10232         .tokens = {
10233                 (void *)&cmd_2tuple_filter_filter,
10234                 (void *)&cmd_2tuple_filter_port_id,
10235                 (void *)&cmd_2tuple_filter_ops,
10236                 (void *)&cmd_2tuple_filter_dst_port,
10237                 (void *)&cmd_2tuple_filter_dst_port_value,
10238                 (void *)&cmd_2tuple_filter_protocol,
10239                 (void *)&cmd_2tuple_filter_protocol_value,
10240                 (void *)&cmd_2tuple_filter_mask,
10241                 (void *)&cmd_2tuple_filter_mask_value,
10242                 (void *)&cmd_2tuple_filter_tcp_flags,
10243                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10244                 (void *)&cmd_2tuple_filter_priority,
10245                 (void *)&cmd_2tuple_filter_priority_value,
10246                 (void *)&cmd_2tuple_filter_queue,
10247                 (void *)&cmd_2tuple_filter_queue_id,
10248                 NULL,
10249         },
10250 };
10251
10252 /* *** ADD/REMOVE A 5tuple FILTER *** */
10253 struct cmd_5tuple_filter_result {
10254         cmdline_fixed_string_t filter;
10255         portid_t port_id;
10256         cmdline_fixed_string_t ops;
10257         cmdline_fixed_string_t dst_ip;
10258         cmdline_ipaddr_t dst_ip_value;
10259         cmdline_fixed_string_t src_ip;
10260         cmdline_ipaddr_t src_ip_value;
10261         cmdline_fixed_string_t dst_port;
10262         uint16_t dst_port_value;
10263         cmdline_fixed_string_t src_port;
10264         uint16_t src_port_value;
10265         cmdline_fixed_string_t protocol;
10266         uint8_t protocol_value;
10267         cmdline_fixed_string_t mask;
10268         uint8_t  mask_value;
10269         cmdline_fixed_string_t tcp_flags;
10270         uint8_t tcp_flags_value;
10271         cmdline_fixed_string_t priority;
10272         uint8_t  priority_value;
10273         cmdline_fixed_string_t queue;
10274         uint16_t  queue_id;
10275 };
10276
10277 static void
10278 cmd_5tuple_filter_parsed(void *parsed_result,
10279                         __attribute__((unused)) struct cmdline *cl,
10280                         __attribute__((unused)) void *data)
10281 {
10282         struct rte_eth_ntuple_filter filter;
10283         struct cmd_5tuple_filter_result *res = parsed_result;
10284         int ret = 0;
10285
10286         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10287         if (ret < 0) {
10288                 printf("ntuple filter is not supported on port %u.\n",
10289                         res->port_id);
10290                 return;
10291         }
10292
10293         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10294
10295         filter.flags = RTE_5TUPLE_FLAGS;
10296         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10297         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10298         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10299         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10300         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10301         filter.proto = res->protocol_value;
10302         filter.priority = res->priority_value;
10303         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10304                 printf("nonzero tcp_flags is only meaningful"
10305                         " when protocol is TCP.\n");
10306                 return;
10307         }
10308         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10309                 printf("invalid TCP flags.\n");
10310                 return;
10311         }
10312
10313         if (res->tcp_flags_value != 0) {
10314                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10315                 filter.tcp_flags = res->tcp_flags_value;
10316         }
10317
10318         if (res->dst_ip_value.family == AF_INET)
10319                 /* no need to convert, already big endian. */
10320                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10321         else {
10322                 if (filter.dst_ip_mask == 0) {
10323                         printf("can not support ipv6 involved compare.\n");
10324                         return;
10325                 }
10326                 filter.dst_ip = 0;
10327         }
10328
10329         if (res->src_ip_value.family == AF_INET)
10330                 /* no need to convert, already big endian. */
10331                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10332         else {
10333                 if (filter.src_ip_mask == 0) {
10334                         printf("can not support ipv6 involved compare.\n");
10335                         return;
10336                 }
10337                 filter.src_ip = 0;
10338         }
10339         /* need convert to big endian. */
10340         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10341         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10342         filter.queue = res->queue_id;
10343
10344         if (!strcmp(res->ops, "add"))
10345                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10346                                 RTE_ETH_FILTER_NTUPLE,
10347                                 RTE_ETH_FILTER_ADD,
10348                                 &filter);
10349         else
10350                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10351                                 RTE_ETH_FILTER_NTUPLE,
10352                                 RTE_ETH_FILTER_DELETE,
10353                                 &filter);
10354         if (ret < 0)
10355                 printf("5tuple filter programming error: (%s)\n",
10356                         strerror(-ret));
10357 }
10358
10359 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10360         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10361                                  filter, "5tuple_filter");
10362 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10363         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10364                                 port_id, UINT16);
10365 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10366         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10367                                  ops, "add#del");
10368 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10369         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10370                                 dst_ip, "dst_ip");
10371 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10372         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10373                                 dst_ip_value);
10374 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10375         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10376                                 src_ip, "src_ip");
10377 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10378         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10379                                 src_ip_value);
10380 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10381         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10382                                 dst_port, "dst_port");
10383 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10384         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10385                                 dst_port_value, UINT16);
10386 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10387         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10388                                 src_port, "src_port");
10389 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10390         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10391                                 src_port_value, UINT16);
10392 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10393         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10394                                 protocol, "protocol");
10395 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10396         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10397                                 protocol_value, UINT8);
10398 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10399         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10400                                 mask, "mask");
10401 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10402         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10403                                 mask_value, INT8);
10404 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10405         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10406                                 tcp_flags, "tcp_flags");
10407 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10408         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10409                                 tcp_flags_value, UINT8);
10410 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10411         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10412                                 priority, "priority");
10413 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10414         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10415                                 priority_value, UINT8);
10416 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10417         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10418                                 queue, "queue");
10419 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10420         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10421                                 queue_id, UINT16);
10422
10423 cmdline_parse_inst_t cmd_5tuple_filter = {
10424         .f = cmd_5tuple_filter_parsed,
10425         .data = NULL,
10426         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10427                 "src_ip <value> dst_port <value> src_port <value> "
10428                 "protocol <value>  mask <value> tcp_flags <value> "
10429                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10430         .tokens = {
10431                 (void *)&cmd_5tuple_filter_filter,
10432                 (void *)&cmd_5tuple_filter_port_id,
10433                 (void *)&cmd_5tuple_filter_ops,
10434                 (void *)&cmd_5tuple_filter_dst_ip,
10435                 (void *)&cmd_5tuple_filter_dst_ip_value,
10436                 (void *)&cmd_5tuple_filter_src_ip,
10437                 (void *)&cmd_5tuple_filter_src_ip_value,
10438                 (void *)&cmd_5tuple_filter_dst_port,
10439                 (void *)&cmd_5tuple_filter_dst_port_value,
10440                 (void *)&cmd_5tuple_filter_src_port,
10441                 (void *)&cmd_5tuple_filter_src_port_value,
10442                 (void *)&cmd_5tuple_filter_protocol,
10443                 (void *)&cmd_5tuple_filter_protocol_value,
10444                 (void *)&cmd_5tuple_filter_mask,
10445                 (void *)&cmd_5tuple_filter_mask_value,
10446                 (void *)&cmd_5tuple_filter_tcp_flags,
10447                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10448                 (void *)&cmd_5tuple_filter_priority,
10449                 (void *)&cmd_5tuple_filter_priority_value,
10450                 (void *)&cmd_5tuple_filter_queue,
10451                 (void *)&cmd_5tuple_filter_queue_id,
10452                 NULL,
10453         },
10454 };
10455
10456 /* *** ADD/REMOVE A flex FILTER *** */
10457 struct cmd_flex_filter_result {
10458         cmdline_fixed_string_t filter;
10459         cmdline_fixed_string_t ops;
10460         portid_t port_id;
10461         cmdline_fixed_string_t len;
10462         uint8_t len_value;
10463         cmdline_fixed_string_t bytes;
10464         cmdline_fixed_string_t bytes_value;
10465         cmdline_fixed_string_t mask;
10466         cmdline_fixed_string_t mask_value;
10467         cmdline_fixed_string_t priority;
10468         uint8_t priority_value;
10469         cmdline_fixed_string_t queue;
10470         uint16_t queue_id;
10471 };
10472
10473 static int xdigit2val(unsigned char c)
10474 {
10475         int val;
10476         if (isdigit(c))
10477                 val = c - '0';
10478         else if (isupper(c))
10479                 val = c - 'A' + 10;
10480         else
10481                 val = c - 'a' + 10;
10482         return val;
10483 }
10484
10485 static void
10486 cmd_flex_filter_parsed(void *parsed_result,
10487                           __attribute__((unused)) struct cmdline *cl,
10488                           __attribute__((unused)) void *data)
10489 {
10490         int ret = 0;
10491         struct rte_eth_flex_filter filter;
10492         struct cmd_flex_filter_result *res = parsed_result;
10493         char *bytes_ptr, *mask_ptr;
10494         uint16_t len, i, j = 0;
10495         char c;
10496         int val;
10497         uint8_t byte = 0;
10498
10499         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10500                 printf("the len exceed the max length 128\n");
10501                 return;
10502         }
10503         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10504         filter.len = res->len_value;
10505         filter.priority = res->priority_value;
10506         filter.queue = res->queue_id;
10507         bytes_ptr = res->bytes_value;
10508         mask_ptr = res->mask_value;
10509
10510          /* translate bytes string to array. */
10511         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10512                 (bytes_ptr[1] == 'X')))
10513                 bytes_ptr += 2;
10514         len = strnlen(bytes_ptr, res->len_value * 2);
10515         if (len == 0 || (len % 8 != 0)) {
10516                 printf("please check len and bytes input\n");
10517                 return;
10518         }
10519         for (i = 0; i < len; i++) {
10520                 c = bytes_ptr[i];
10521                 if (isxdigit(c) == 0) {
10522                         /* invalid characters. */
10523                         printf("invalid input\n");
10524                         return;
10525                 }
10526                 val = xdigit2val(c);
10527                 if (i % 2) {
10528                         byte |= val;
10529                         filter.bytes[j] = byte;
10530                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10531                         j++;
10532                         byte = 0;
10533                 } else
10534                         byte |= val << 4;
10535         }
10536         printf("\n");
10537          /* translate mask string to uint8_t array. */
10538         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10539                 (mask_ptr[1] == 'X')))
10540                 mask_ptr += 2;
10541         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10542         if (len == 0) {
10543                 printf("invalid input\n");
10544                 return;
10545         }
10546         j = 0;
10547         byte = 0;
10548         for (i = 0; i < len; i++) {
10549                 c = mask_ptr[i];
10550                 if (isxdigit(c) == 0) {
10551                         /* invalid characters. */
10552                         printf("invalid input\n");
10553                         return;
10554                 }
10555                 val = xdigit2val(c);
10556                 if (i % 2) {
10557                         byte |= val;
10558                         filter.mask[j] = byte;
10559                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10560                         j++;
10561                         byte = 0;
10562                 } else
10563                         byte |= val << 4;
10564         }
10565         printf("\n");
10566
10567         if (!strcmp(res->ops, "add"))
10568                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10569                                 RTE_ETH_FILTER_FLEXIBLE,
10570                                 RTE_ETH_FILTER_ADD,
10571                                 &filter);
10572         else
10573                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10574                                 RTE_ETH_FILTER_FLEXIBLE,
10575                                 RTE_ETH_FILTER_DELETE,
10576                                 &filter);
10577
10578         if (ret < 0)
10579                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10580 }
10581
10582 cmdline_parse_token_string_t cmd_flex_filter_filter =
10583         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10584                                 filter, "flex_filter");
10585 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10586         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10587                                 port_id, UINT16);
10588 cmdline_parse_token_string_t cmd_flex_filter_ops =
10589         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10590                                 ops, "add#del");
10591 cmdline_parse_token_string_t cmd_flex_filter_len =
10592         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10593                                 len, "len");
10594 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10595         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10596                                 len_value, UINT8);
10597 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10598         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10599                                 bytes, "bytes");
10600 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10601         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10602                                 bytes_value, NULL);
10603 cmdline_parse_token_string_t cmd_flex_filter_mask =
10604         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10605                                 mask, "mask");
10606 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10607         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10608                                 mask_value, NULL);
10609 cmdline_parse_token_string_t cmd_flex_filter_priority =
10610         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10611                                 priority, "priority");
10612 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10613         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10614                                 priority_value, UINT8);
10615 cmdline_parse_token_string_t cmd_flex_filter_queue =
10616         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10617                                 queue, "queue");
10618 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10619         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10620                                 queue_id, UINT16);
10621 cmdline_parse_inst_t cmd_flex_filter = {
10622         .f = cmd_flex_filter_parsed,
10623         .data = NULL,
10624         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10625                 "<value> mask <value> priority <value> queue <queue_id>: "
10626                 "Add/Del a flex filter",
10627         .tokens = {
10628                 (void *)&cmd_flex_filter_filter,
10629                 (void *)&cmd_flex_filter_port_id,
10630                 (void *)&cmd_flex_filter_ops,
10631                 (void *)&cmd_flex_filter_len,
10632                 (void *)&cmd_flex_filter_len_value,
10633                 (void *)&cmd_flex_filter_bytes,
10634                 (void *)&cmd_flex_filter_bytes_value,
10635                 (void *)&cmd_flex_filter_mask,
10636                 (void *)&cmd_flex_filter_mask_value,
10637                 (void *)&cmd_flex_filter_priority,
10638                 (void *)&cmd_flex_filter_priority_value,
10639                 (void *)&cmd_flex_filter_queue,
10640                 (void *)&cmd_flex_filter_queue_id,
10641                 NULL,
10642         },
10643 };
10644
10645 /* *** Filters Control *** */
10646
10647 /* *** deal with ethertype filter *** */
10648 struct cmd_ethertype_filter_result {
10649         cmdline_fixed_string_t filter;
10650         portid_t port_id;
10651         cmdline_fixed_string_t ops;
10652         cmdline_fixed_string_t mac;
10653         struct rte_ether_addr mac_addr;
10654         cmdline_fixed_string_t ethertype;
10655         uint16_t ethertype_value;
10656         cmdline_fixed_string_t drop;
10657         cmdline_fixed_string_t queue;
10658         uint16_t  queue_id;
10659 };
10660
10661 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10662         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10663                                  filter, "ethertype_filter");
10664 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10665         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10666                               port_id, UINT16);
10667 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10668         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10669                                  ops, "add#del");
10670 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10671         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10672                                  mac, "mac_addr#mac_ignr");
10673 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10674         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10675                                      mac_addr);
10676 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10677         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10678                                  ethertype, "ethertype");
10679 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10680         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10681                               ethertype_value, UINT16);
10682 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10683         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10684                                  drop, "drop#fwd");
10685 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10686         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10687                                  queue, "queue");
10688 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10689         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10690                               queue_id, UINT16);
10691
10692 static void
10693 cmd_ethertype_filter_parsed(void *parsed_result,
10694                           __attribute__((unused)) struct cmdline *cl,
10695                           __attribute__((unused)) void *data)
10696 {
10697         struct cmd_ethertype_filter_result *res = parsed_result;
10698         struct rte_eth_ethertype_filter filter;
10699         int ret = 0;
10700
10701         ret = rte_eth_dev_filter_supported(res->port_id,
10702                         RTE_ETH_FILTER_ETHERTYPE);
10703         if (ret < 0) {
10704                 printf("ethertype filter is not supported on port %u.\n",
10705                         res->port_id);
10706                 return;
10707         }
10708
10709         memset(&filter, 0, sizeof(filter));
10710         if (!strcmp(res->mac, "mac_addr")) {
10711                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10712                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10713                         sizeof(struct rte_ether_addr));
10714         }
10715         if (!strcmp(res->drop, "drop"))
10716                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10717         filter.ether_type = res->ethertype_value;
10718         filter.queue = res->queue_id;
10719
10720         if (!strcmp(res->ops, "add"))
10721                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10722                                 RTE_ETH_FILTER_ETHERTYPE,
10723                                 RTE_ETH_FILTER_ADD,
10724                                 &filter);
10725         else
10726                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10727                                 RTE_ETH_FILTER_ETHERTYPE,
10728                                 RTE_ETH_FILTER_DELETE,
10729                                 &filter);
10730         if (ret < 0)
10731                 printf("ethertype filter programming error: (%s)\n",
10732                         strerror(-ret));
10733 }
10734
10735 cmdline_parse_inst_t cmd_ethertype_filter = {
10736         .f = cmd_ethertype_filter_parsed,
10737         .data = NULL,
10738         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10739                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10740                 "Add or delete an ethertype filter entry",
10741         .tokens = {
10742                 (void *)&cmd_ethertype_filter_filter,
10743                 (void *)&cmd_ethertype_filter_port_id,
10744                 (void *)&cmd_ethertype_filter_ops,
10745                 (void *)&cmd_ethertype_filter_mac,
10746                 (void *)&cmd_ethertype_filter_mac_addr,
10747                 (void *)&cmd_ethertype_filter_ethertype,
10748                 (void *)&cmd_ethertype_filter_ethertype_value,
10749                 (void *)&cmd_ethertype_filter_drop,
10750                 (void *)&cmd_ethertype_filter_queue,
10751                 (void *)&cmd_ethertype_filter_queue_id,
10752                 NULL,
10753         },
10754 };
10755
10756 /* *** deal with flow director filter *** */
10757 struct cmd_flow_director_result {
10758         cmdline_fixed_string_t flow_director_filter;
10759         portid_t port_id;
10760         cmdline_fixed_string_t mode;
10761         cmdline_fixed_string_t mode_value;
10762         cmdline_fixed_string_t ops;
10763         cmdline_fixed_string_t flow;
10764         cmdline_fixed_string_t flow_type;
10765         cmdline_fixed_string_t ether;
10766         uint16_t ether_type;
10767         cmdline_fixed_string_t src;
10768         cmdline_ipaddr_t ip_src;
10769         uint16_t port_src;
10770         cmdline_fixed_string_t dst;
10771         cmdline_ipaddr_t ip_dst;
10772         uint16_t port_dst;
10773         cmdline_fixed_string_t verify_tag;
10774         uint32_t verify_tag_value;
10775         cmdline_fixed_string_t tos;
10776         uint8_t tos_value;
10777         cmdline_fixed_string_t proto;
10778         uint8_t proto_value;
10779         cmdline_fixed_string_t ttl;
10780         uint8_t ttl_value;
10781         cmdline_fixed_string_t vlan;
10782         uint16_t vlan_value;
10783         cmdline_fixed_string_t flexbytes;
10784         cmdline_fixed_string_t flexbytes_value;
10785         cmdline_fixed_string_t pf_vf;
10786         cmdline_fixed_string_t drop;
10787         cmdline_fixed_string_t queue;
10788         uint16_t  queue_id;
10789         cmdline_fixed_string_t fd_id;
10790         uint32_t  fd_id_value;
10791         cmdline_fixed_string_t mac;
10792         struct rte_ether_addr mac_addr;
10793         cmdline_fixed_string_t tunnel;
10794         cmdline_fixed_string_t tunnel_type;
10795         cmdline_fixed_string_t tunnel_id;
10796         uint32_t tunnel_id_value;
10797         cmdline_fixed_string_t packet;
10798         char filepath[];
10799 };
10800
10801 static inline int
10802 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10803 {
10804         char s[256];
10805         const char *p, *p0 = q_arg;
10806         char *end;
10807         unsigned long int_fld;
10808         char *str_fld[max_num];
10809         int i;
10810         unsigned size;
10811         int ret = -1;
10812
10813         p = strchr(p0, '(');
10814         if (p == NULL)
10815                 return -1;
10816         ++p;
10817         p0 = strchr(p, ')');
10818         if (p0 == NULL)
10819                 return -1;
10820
10821         size = p0 - p;
10822         if (size >= sizeof(s))
10823                 return -1;
10824
10825         snprintf(s, sizeof(s), "%.*s", size, p);
10826         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10827         if (ret < 0 || ret > max_num)
10828                 return -1;
10829         for (i = 0; i < ret; i++) {
10830                 errno = 0;
10831                 int_fld = strtoul(str_fld[i], &end, 0);
10832                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10833                         return -1;
10834                 flexbytes[i] = (uint8_t)int_fld;
10835         }
10836         return ret;
10837 }
10838
10839 static uint16_t
10840 str2flowtype(char *string)
10841 {
10842         uint8_t i = 0;
10843         static const struct {
10844                 char str[32];
10845                 uint16_t type;
10846         } flowtype_str[] = {
10847                 {"raw", RTE_ETH_FLOW_RAW},
10848                 {"ipv4", RTE_ETH_FLOW_IPV4},
10849                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10850                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10851                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10852                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10853                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10854                 {"ipv6", RTE_ETH_FLOW_IPV6},
10855                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10856                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10857                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10858                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10859                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10860                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10861         };
10862
10863         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10864                 if (!strcmp(flowtype_str[i].str, string))
10865                         return flowtype_str[i].type;
10866         }
10867
10868         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10869                 return (uint16_t)atoi(string);
10870
10871         return RTE_ETH_FLOW_UNKNOWN;
10872 }
10873
10874 static enum rte_eth_fdir_tunnel_type
10875 str2fdir_tunneltype(char *string)
10876 {
10877         uint8_t i = 0;
10878
10879         static const struct {
10880                 char str[32];
10881                 enum rte_eth_fdir_tunnel_type type;
10882         } tunneltype_str[] = {
10883                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10884                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10885         };
10886
10887         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10888                 if (!strcmp(tunneltype_str[i].str, string))
10889                         return tunneltype_str[i].type;
10890         }
10891         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10892 }
10893
10894 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10895 do { \
10896         if ((ip_addr).family == AF_INET) \
10897                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10898         else { \
10899                 printf("invalid parameter.\n"); \
10900                 return; \
10901         } \
10902 } while (0)
10903
10904 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10905 do { \
10906         if ((ip_addr).family == AF_INET6) \
10907                 rte_memcpy(&(ip), \
10908                                  &((ip_addr).addr.ipv6), \
10909                                  sizeof(struct in6_addr)); \
10910         else { \
10911                 printf("invalid parameter.\n"); \
10912                 return; \
10913         } \
10914 } while (0)
10915
10916 static void
10917 cmd_flow_director_filter_parsed(void *parsed_result,
10918                           __attribute__((unused)) struct cmdline *cl,
10919                           __attribute__((unused)) void *data)
10920 {
10921         struct cmd_flow_director_result *res = parsed_result;
10922         struct rte_eth_fdir_filter entry;
10923         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10924         char *end;
10925         unsigned long vf_id;
10926         int ret = 0;
10927
10928         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10929         if (ret < 0) {
10930                 printf("flow director is not supported on port %u.\n",
10931                         res->port_id);
10932                 return;
10933         }
10934         memset(flexbytes, 0, sizeof(flexbytes));
10935         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10936
10937         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10938                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10939                         printf("Please set mode to MAC-VLAN.\n");
10940                         return;
10941                 }
10942         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10943                 if (strcmp(res->mode_value, "Tunnel")) {
10944                         printf("Please set mode to Tunnel.\n");
10945                         return;
10946                 }
10947         } else {
10948                 if (!strcmp(res->mode_value, "raw")) {
10949 #ifdef RTE_LIBRTE_I40E_PMD
10950                         struct rte_pmd_i40e_flow_type_mapping
10951                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10952                         struct rte_pmd_i40e_pkt_template_conf conf;
10953                         uint16_t flow_type = str2flowtype(res->flow_type);
10954                         uint16_t i, port = res->port_id;
10955                         uint8_t add;
10956
10957                         memset(&conf, 0, sizeof(conf));
10958
10959                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10960                                 printf("Invalid flow type specified.\n");
10961                                 return;
10962                         }
10963                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10964                                                                  mapping);
10965                         if (ret)
10966                                 return;
10967                         if (mapping[flow_type].pctype == 0ULL) {
10968                                 printf("Invalid flow type specified.\n");
10969                                 return;
10970                         }
10971                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10972                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10973                                         conf.input.pctype = i;
10974                                         break;
10975                                 }
10976                         }
10977
10978                         conf.input.packet = open_file(res->filepath,
10979                                                 &conf.input.length);
10980                         if (!conf.input.packet)
10981                                 return;
10982                         if (!strcmp(res->drop, "drop"))
10983                                 conf.action.behavior =
10984                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10985                         else
10986                                 conf.action.behavior =
10987                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10988                         conf.action.report_status =
10989                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10990                         conf.action.rx_queue = res->queue_id;
10991                         conf.soft_id = res->fd_id_value;
10992                         add  = strcmp(res->ops, "del") ? 1 : 0;
10993                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10994                                                                         &conf,
10995                                                                         add);
10996                         if (ret < 0)
10997                                 printf("flow director config error: (%s)\n",
10998                                        strerror(-ret));
10999                         close_file(conf.input.packet);
11000 #endif
11001                         return;
11002                 } else if (strcmp(res->mode_value, "IP")) {
11003                         printf("Please set mode to IP or raw.\n");
11004                         return;
11005                 }
11006                 entry.input.flow_type = str2flowtype(res->flow_type);
11007         }
11008
11009         ret = parse_flexbytes(res->flexbytes_value,
11010                                         flexbytes,
11011                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11012         if (ret < 0) {
11013                 printf("error: Cannot parse flexbytes input.\n");
11014                 return;
11015         }
11016
11017         switch (entry.input.flow_type) {
11018         case RTE_ETH_FLOW_FRAG_IPV4:
11019         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11020                 entry.input.flow.ip4_flow.proto = res->proto_value;
11021                 /* fall-through */
11022         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11023         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11024                 IPV4_ADDR_TO_UINT(res->ip_dst,
11025                         entry.input.flow.ip4_flow.dst_ip);
11026                 IPV4_ADDR_TO_UINT(res->ip_src,
11027                         entry.input.flow.ip4_flow.src_ip);
11028                 entry.input.flow.ip4_flow.tos = res->tos_value;
11029                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11030                 /* need convert to big endian. */
11031                 entry.input.flow.udp4_flow.dst_port =
11032                                 rte_cpu_to_be_16(res->port_dst);
11033                 entry.input.flow.udp4_flow.src_port =
11034                                 rte_cpu_to_be_16(res->port_src);
11035                 break;
11036         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11037                 IPV4_ADDR_TO_UINT(res->ip_dst,
11038                         entry.input.flow.sctp4_flow.ip.dst_ip);
11039                 IPV4_ADDR_TO_UINT(res->ip_src,
11040                         entry.input.flow.sctp4_flow.ip.src_ip);
11041                 entry.input.flow.ip4_flow.tos = res->tos_value;
11042                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11043                 /* need convert to big endian. */
11044                 entry.input.flow.sctp4_flow.dst_port =
11045                                 rte_cpu_to_be_16(res->port_dst);
11046                 entry.input.flow.sctp4_flow.src_port =
11047                                 rte_cpu_to_be_16(res->port_src);
11048                 entry.input.flow.sctp4_flow.verify_tag =
11049                                 rte_cpu_to_be_32(res->verify_tag_value);
11050                 break;
11051         case RTE_ETH_FLOW_FRAG_IPV6:
11052         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11053                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11054                 /* fall-through */
11055         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11056         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11057                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11058                         entry.input.flow.ipv6_flow.dst_ip);
11059                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11060                         entry.input.flow.ipv6_flow.src_ip);
11061                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11062                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11063                 /* need convert to big endian. */
11064                 entry.input.flow.udp6_flow.dst_port =
11065                                 rte_cpu_to_be_16(res->port_dst);
11066                 entry.input.flow.udp6_flow.src_port =
11067                                 rte_cpu_to_be_16(res->port_src);
11068                 break;
11069         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11070                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11071                         entry.input.flow.sctp6_flow.ip.dst_ip);
11072                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11073                         entry.input.flow.sctp6_flow.ip.src_ip);
11074                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11075                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11076                 /* need convert to big endian. */
11077                 entry.input.flow.sctp6_flow.dst_port =
11078                                 rte_cpu_to_be_16(res->port_dst);
11079                 entry.input.flow.sctp6_flow.src_port =
11080                                 rte_cpu_to_be_16(res->port_src);
11081                 entry.input.flow.sctp6_flow.verify_tag =
11082                                 rte_cpu_to_be_32(res->verify_tag_value);
11083                 break;
11084         case RTE_ETH_FLOW_L2_PAYLOAD:
11085                 entry.input.flow.l2_flow.ether_type =
11086                         rte_cpu_to_be_16(res->ether_type);
11087                 break;
11088         default:
11089                 break;
11090         }
11091
11092         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11093                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11094                                  &res->mac_addr,
11095                                  sizeof(struct rte_ether_addr));
11096
11097         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11098                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11099                                  &res->mac_addr,
11100                                  sizeof(struct rte_ether_addr));
11101                 entry.input.flow.tunnel_flow.tunnel_type =
11102                         str2fdir_tunneltype(res->tunnel_type);
11103                 entry.input.flow.tunnel_flow.tunnel_id =
11104                         rte_cpu_to_be_32(res->tunnel_id_value);
11105         }
11106
11107         rte_memcpy(entry.input.flow_ext.flexbytes,
11108                    flexbytes,
11109                    RTE_ETH_FDIR_MAX_FLEXLEN);
11110
11111         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11112
11113         entry.action.flex_off = 0;  /*use 0 by default */
11114         if (!strcmp(res->drop, "drop"))
11115                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11116         else
11117                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11118
11119         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11120             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11121                 if (!strcmp(res->pf_vf, "pf"))
11122                         entry.input.flow_ext.is_vf = 0;
11123                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11124                         struct rte_eth_dev_info dev_info;
11125
11126                         ret = eth_dev_info_get_print_err(res->port_id,
11127                                                 &dev_info);
11128                         if (ret != 0)
11129                                 return;
11130
11131                         errno = 0;
11132                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11133                         if (errno != 0 || *end != '\0' ||
11134                             vf_id >= dev_info.max_vfs) {
11135                                 printf("invalid parameter %s.\n", res->pf_vf);
11136                                 return;
11137                         }
11138                         entry.input.flow_ext.is_vf = 1;
11139                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11140                 } else {
11141                         printf("invalid parameter %s.\n", res->pf_vf);
11142                         return;
11143                 }
11144         }
11145
11146         /* set to report FD ID by default */
11147         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11148         entry.action.rx_queue = res->queue_id;
11149         entry.soft_id = res->fd_id_value;
11150         if (!strcmp(res->ops, "add"))
11151                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11152                                              RTE_ETH_FILTER_ADD, &entry);
11153         else if (!strcmp(res->ops, "del"))
11154                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11155                                              RTE_ETH_FILTER_DELETE, &entry);
11156         else
11157                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11158                                              RTE_ETH_FILTER_UPDATE, &entry);
11159         if (ret < 0)
11160                 printf("flow director programming error: (%s)\n",
11161                         strerror(-ret));
11162 }
11163
11164 cmdline_parse_token_string_t cmd_flow_director_filter =
11165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11166                                  flow_director_filter, "flow_director_filter");
11167 cmdline_parse_token_num_t cmd_flow_director_port_id =
11168         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11169                               port_id, UINT16);
11170 cmdline_parse_token_string_t cmd_flow_director_ops =
11171         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11172                                  ops, "add#del#update");
11173 cmdline_parse_token_string_t cmd_flow_director_flow =
11174         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11175                                  flow, "flow");
11176 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11178                 flow_type, NULL);
11179 cmdline_parse_token_string_t cmd_flow_director_ether =
11180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11181                                  ether, "ether");
11182 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11183         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11184                               ether_type, UINT16);
11185 cmdline_parse_token_string_t cmd_flow_director_src =
11186         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11187                                  src, "src");
11188 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11189         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11190                                  ip_src);
11191 cmdline_parse_token_num_t cmd_flow_director_port_src =
11192         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11193                               port_src, UINT16);
11194 cmdline_parse_token_string_t cmd_flow_director_dst =
11195         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11196                                  dst, "dst");
11197 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11198         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11199                                  ip_dst);
11200 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11201         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11202                               port_dst, UINT16);
11203 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11204         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11205                                   verify_tag, "verify_tag");
11206 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11207         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11208                               verify_tag_value, UINT32);
11209 cmdline_parse_token_string_t cmd_flow_director_tos =
11210         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11211                                  tos, "tos");
11212 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11213         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11214                               tos_value, UINT8);
11215 cmdline_parse_token_string_t cmd_flow_director_proto =
11216         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11217                                  proto, "proto");
11218 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11219         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11220                               proto_value, UINT8);
11221 cmdline_parse_token_string_t cmd_flow_director_ttl =
11222         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11223                                  ttl, "ttl");
11224 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11225         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11226                               ttl_value, UINT8);
11227 cmdline_parse_token_string_t cmd_flow_director_vlan =
11228         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11229                                  vlan, "vlan");
11230 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11231         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11232                               vlan_value, UINT16);
11233 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11234         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11235                                  flexbytes, "flexbytes");
11236 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11237         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11238                               flexbytes_value, NULL);
11239 cmdline_parse_token_string_t cmd_flow_director_drop =
11240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11241                                  drop, "drop#fwd");
11242 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11244                               pf_vf, NULL);
11245 cmdline_parse_token_string_t cmd_flow_director_queue =
11246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11247                                  queue, "queue");
11248 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11249         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11250                               queue_id, UINT16);
11251 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11253                                  fd_id, "fd_id");
11254 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11256                               fd_id_value, UINT32);
11257
11258 cmdline_parse_token_string_t cmd_flow_director_mode =
11259         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11260                                  mode, "mode");
11261 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11263                                  mode_value, "IP");
11264 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11266                                  mode_value, "MAC-VLAN");
11267 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11269                                  mode_value, "Tunnel");
11270 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11272                                  mode_value, "raw");
11273 cmdline_parse_token_string_t cmd_flow_director_mac =
11274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11275                                  mac, "mac");
11276 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11277         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11278                                     mac_addr);
11279 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11280         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11281                                  tunnel, "tunnel");
11282 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11283         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11284                                  tunnel_type, "NVGRE#VxLAN");
11285 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11287                                  tunnel_id, "tunnel-id");
11288 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11289         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11290                               tunnel_id_value, UINT32);
11291 cmdline_parse_token_string_t cmd_flow_director_packet =
11292         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11293                                  packet, "packet");
11294 cmdline_parse_token_string_t cmd_flow_director_filepath =
11295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11296                                  filepath, NULL);
11297
11298 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11299         .f = cmd_flow_director_filter_parsed,
11300         .data = NULL,
11301         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11302                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11303                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11304                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11305                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11306                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11307                 "fd_id <fd_id_value>: "
11308                 "Add or delete an ip flow director entry on NIC",
11309         .tokens = {
11310                 (void *)&cmd_flow_director_filter,
11311                 (void *)&cmd_flow_director_port_id,
11312                 (void *)&cmd_flow_director_mode,
11313                 (void *)&cmd_flow_director_mode_ip,
11314                 (void *)&cmd_flow_director_ops,
11315                 (void *)&cmd_flow_director_flow,
11316                 (void *)&cmd_flow_director_flow_type,
11317                 (void *)&cmd_flow_director_src,
11318                 (void *)&cmd_flow_director_ip_src,
11319                 (void *)&cmd_flow_director_dst,
11320                 (void *)&cmd_flow_director_ip_dst,
11321                 (void *)&cmd_flow_director_tos,
11322                 (void *)&cmd_flow_director_tos_value,
11323                 (void *)&cmd_flow_director_proto,
11324                 (void *)&cmd_flow_director_proto_value,
11325                 (void *)&cmd_flow_director_ttl,
11326                 (void *)&cmd_flow_director_ttl_value,
11327                 (void *)&cmd_flow_director_vlan,
11328                 (void *)&cmd_flow_director_vlan_value,
11329                 (void *)&cmd_flow_director_flexbytes,
11330                 (void *)&cmd_flow_director_flexbytes_value,
11331                 (void *)&cmd_flow_director_drop,
11332                 (void *)&cmd_flow_director_pf_vf,
11333                 (void *)&cmd_flow_director_queue,
11334                 (void *)&cmd_flow_director_queue_id,
11335                 (void *)&cmd_flow_director_fd_id,
11336                 (void *)&cmd_flow_director_fd_id_value,
11337                 NULL,
11338         },
11339 };
11340
11341 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11342         .f = cmd_flow_director_filter_parsed,
11343         .data = NULL,
11344         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11345                 "director entry on NIC",
11346         .tokens = {
11347                 (void *)&cmd_flow_director_filter,
11348                 (void *)&cmd_flow_director_port_id,
11349                 (void *)&cmd_flow_director_mode,
11350                 (void *)&cmd_flow_director_mode_ip,
11351                 (void *)&cmd_flow_director_ops,
11352                 (void *)&cmd_flow_director_flow,
11353                 (void *)&cmd_flow_director_flow_type,
11354                 (void *)&cmd_flow_director_src,
11355                 (void *)&cmd_flow_director_ip_src,
11356                 (void *)&cmd_flow_director_port_src,
11357                 (void *)&cmd_flow_director_dst,
11358                 (void *)&cmd_flow_director_ip_dst,
11359                 (void *)&cmd_flow_director_port_dst,
11360                 (void *)&cmd_flow_director_tos,
11361                 (void *)&cmd_flow_director_tos_value,
11362                 (void *)&cmd_flow_director_ttl,
11363                 (void *)&cmd_flow_director_ttl_value,
11364                 (void *)&cmd_flow_director_vlan,
11365                 (void *)&cmd_flow_director_vlan_value,
11366                 (void *)&cmd_flow_director_flexbytes,
11367                 (void *)&cmd_flow_director_flexbytes_value,
11368                 (void *)&cmd_flow_director_drop,
11369                 (void *)&cmd_flow_director_pf_vf,
11370                 (void *)&cmd_flow_director_queue,
11371                 (void *)&cmd_flow_director_queue_id,
11372                 (void *)&cmd_flow_director_fd_id,
11373                 (void *)&cmd_flow_director_fd_id_value,
11374                 NULL,
11375         },
11376 };
11377
11378 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11379         .f = cmd_flow_director_filter_parsed,
11380         .data = NULL,
11381         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11382                 "director entry on NIC",
11383         .tokens = {
11384                 (void *)&cmd_flow_director_filter,
11385                 (void *)&cmd_flow_director_port_id,
11386                 (void *)&cmd_flow_director_mode,
11387                 (void *)&cmd_flow_director_mode_ip,
11388                 (void *)&cmd_flow_director_ops,
11389                 (void *)&cmd_flow_director_flow,
11390                 (void *)&cmd_flow_director_flow_type,
11391                 (void *)&cmd_flow_director_src,
11392                 (void *)&cmd_flow_director_ip_src,
11393                 (void *)&cmd_flow_director_port_src,
11394                 (void *)&cmd_flow_director_dst,
11395                 (void *)&cmd_flow_director_ip_dst,
11396                 (void *)&cmd_flow_director_port_dst,
11397                 (void *)&cmd_flow_director_verify_tag,
11398                 (void *)&cmd_flow_director_verify_tag_value,
11399                 (void *)&cmd_flow_director_tos,
11400                 (void *)&cmd_flow_director_tos_value,
11401                 (void *)&cmd_flow_director_ttl,
11402                 (void *)&cmd_flow_director_ttl_value,
11403                 (void *)&cmd_flow_director_vlan,
11404                 (void *)&cmd_flow_director_vlan_value,
11405                 (void *)&cmd_flow_director_flexbytes,
11406                 (void *)&cmd_flow_director_flexbytes_value,
11407                 (void *)&cmd_flow_director_drop,
11408                 (void *)&cmd_flow_director_pf_vf,
11409                 (void *)&cmd_flow_director_queue,
11410                 (void *)&cmd_flow_director_queue_id,
11411                 (void *)&cmd_flow_director_fd_id,
11412                 (void *)&cmd_flow_director_fd_id_value,
11413                 NULL,
11414         },
11415 };
11416
11417 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11418         .f = cmd_flow_director_filter_parsed,
11419         .data = NULL,
11420         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11421                 "director entry on NIC",
11422         .tokens = {
11423                 (void *)&cmd_flow_director_filter,
11424                 (void *)&cmd_flow_director_port_id,
11425                 (void *)&cmd_flow_director_mode,
11426                 (void *)&cmd_flow_director_mode_ip,
11427                 (void *)&cmd_flow_director_ops,
11428                 (void *)&cmd_flow_director_flow,
11429                 (void *)&cmd_flow_director_flow_type,
11430                 (void *)&cmd_flow_director_ether,
11431                 (void *)&cmd_flow_director_ether_type,
11432                 (void *)&cmd_flow_director_flexbytes,
11433                 (void *)&cmd_flow_director_flexbytes_value,
11434                 (void *)&cmd_flow_director_drop,
11435                 (void *)&cmd_flow_director_pf_vf,
11436                 (void *)&cmd_flow_director_queue,
11437                 (void *)&cmd_flow_director_queue_id,
11438                 (void *)&cmd_flow_director_fd_id,
11439                 (void *)&cmd_flow_director_fd_id_value,
11440                 NULL,
11441         },
11442 };
11443
11444 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11445         .f = cmd_flow_director_filter_parsed,
11446         .data = NULL,
11447         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11448                 "director entry on NIC",
11449         .tokens = {
11450                 (void *)&cmd_flow_director_filter,
11451                 (void *)&cmd_flow_director_port_id,
11452                 (void *)&cmd_flow_director_mode,
11453                 (void *)&cmd_flow_director_mode_mac_vlan,
11454                 (void *)&cmd_flow_director_ops,
11455                 (void *)&cmd_flow_director_mac,
11456                 (void *)&cmd_flow_director_mac_addr,
11457                 (void *)&cmd_flow_director_vlan,
11458                 (void *)&cmd_flow_director_vlan_value,
11459                 (void *)&cmd_flow_director_flexbytes,
11460                 (void *)&cmd_flow_director_flexbytes_value,
11461                 (void *)&cmd_flow_director_drop,
11462                 (void *)&cmd_flow_director_queue,
11463                 (void *)&cmd_flow_director_queue_id,
11464                 (void *)&cmd_flow_director_fd_id,
11465                 (void *)&cmd_flow_director_fd_id_value,
11466                 NULL,
11467         },
11468 };
11469
11470 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11471         .f = cmd_flow_director_filter_parsed,
11472         .data = NULL,
11473         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11474                 "director entry on NIC",
11475         .tokens = {
11476                 (void *)&cmd_flow_director_filter,
11477                 (void *)&cmd_flow_director_port_id,
11478                 (void *)&cmd_flow_director_mode,
11479                 (void *)&cmd_flow_director_mode_tunnel,
11480                 (void *)&cmd_flow_director_ops,
11481                 (void *)&cmd_flow_director_mac,
11482                 (void *)&cmd_flow_director_mac_addr,
11483                 (void *)&cmd_flow_director_vlan,
11484                 (void *)&cmd_flow_director_vlan_value,
11485                 (void *)&cmd_flow_director_tunnel,
11486                 (void *)&cmd_flow_director_tunnel_type,
11487                 (void *)&cmd_flow_director_tunnel_id,
11488                 (void *)&cmd_flow_director_tunnel_id_value,
11489                 (void *)&cmd_flow_director_flexbytes,
11490                 (void *)&cmd_flow_director_flexbytes_value,
11491                 (void *)&cmd_flow_director_drop,
11492                 (void *)&cmd_flow_director_queue,
11493                 (void *)&cmd_flow_director_queue_id,
11494                 (void *)&cmd_flow_director_fd_id,
11495                 (void *)&cmd_flow_director_fd_id_value,
11496                 NULL,
11497         },
11498 };
11499
11500 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11501         .f = cmd_flow_director_filter_parsed,
11502         .data = NULL,
11503         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11504                 "director entry on NIC",
11505         .tokens = {
11506                 (void *)&cmd_flow_director_filter,
11507                 (void *)&cmd_flow_director_port_id,
11508                 (void *)&cmd_flow_director_mode,
11509                 (void *)&cmd_flow_director_mode_raw,
11510                 (void *)&cmd_flow_director_ops,
11511                 (void *)&cmd_flow_director_flow,
11512                 (void *)&cmd_flow_director_flow_type,
11513                 (void *)&cmd_flow_director_drop,
11514                 (void *)&cmd_flow_director_queue,
11515                 (void *)&cmd_flow_director_queue_id,
11516                 (void *)&cmd_flow_director_fd_id,
11517                 (void *)&cmd_flow_director_fd_id_value,
11518                 (void *)&cmd_flow_director_packet,
11519                 (void *)&cmd_flow_director_filepath,
11520                 NULL,
11521         },
11522 };
11523
11524 struct cmd_flush_flow_director_result {
11525         cmdline_fixed_string_t flush_flow_director;
11526         portid_t port_id;
11527 };
11528
11529 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11530         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11531                                  flush_flow_director, "flush_flow_director");
11532 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11533         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11534                               port_id, UINT16);
11535
11536 static void
11537 cmd_flush_flow_director_parsed(void *parsed_result,
11538                           __attribute__((unused)) struct cmdline *cl,
11539                           __attribute__((unused)) void *data)
11540 {
11541         struct cmd_flow_director_result *res = parsed_result;
11542         int ret = 0;
11543
11544         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11545         if (ret < 0) {
11546                 printf("flow director is not supported on port %u.\n",
11547                         res->port_id);
11548                 return;
11549         }
11550
11551         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11552                         RTE_ETH_FILTER_FLUSH, NULL);
11553         if (ret < 0)
11554                 printf("flow director table flushing error: (%s)\n",
11555                         strerror(-ret));
11556 }
11557
11558 cmdline_parse_inst_t cmd_flush_flow_director = {
11559         .f = cmd_flush_flow_director_parsed,
11560         .data = NULL,
11561         .help_str = "flush_flow_director <port_id>: "
11562                 "Flush all flow director entries of a device on NIC",
11563         .tokens = {
11564                 (void *)&cmd_flush_flow_director_flush,
11565                 (void *)&cmd_flush_flow_director_port_id,
11566                 NULL,
11567         },
11568 };
11569
11570 /* *** deal with flow director mask *** */
11571 struct cmd_flow_director_mask_result {
11572         cmdline_fixed_string_t flow_director_mask;
11573         portid_t port_id;
11574         cmdline_fixed_string_t mode;
11575         cmdline_fixed_string_t mode_value;
11576         cmdline_fixed_string_t vlan;
11577         uint16_t vlan_mask;
11578         cmdline_fixed_string_t src_mask;
11579         cmdline_ipaddr_t ipv4_src;
11580         cmdline_ipaddr_t ipv6_src;
11581         uint16_t port_src;
11582         cmdline_fixed_string_t dst_mask;
11583         cmdline_ipaddr_t ipv4_dst;
11584         cmdline_ipaddr_t ipv6_dst;
11585         uint16_t port_dst;
11586         cmdline_fixed_string_t mac;
11587         uint8_t mac_addr_byte_mask;
11588         cmdline_fixed_string_t tunnel_id;
11589         uint32_t tunnel_id_mask;
11590         cmdline_fixed_string_t tunnel_type;
11591         uint8_t tunnel_type_mask;
11592 };
11593
11594 static void
11595 cmd_flow_director_mask_parsed(void *parsed_result,
11596                           __attribute__((unused)) struct cmdline *cl,
11597                           __attribute__((unused)) void *data)
11598 {
11599         struct cmd_flow_director_mask_result *res = parsed_result;
11600         struct rte_eth_fdir_masks *mask;
11601         struct rte_port *port;
11602
11603         port = &ports[res->port_id];
11604         /** Check if the port is not started **/
11605         if (port->port_status != RTE_PORT_STOPPED) {
11606                 printf("Please stop port %d first\n", res->port_id);
11607                 return;
11608         }
11609
11610         mask = &port->dev_conf.fdir_conf.mask;
11611
11612         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11613                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11614                         printf("Please set mode to MAC-VLAN.\n");
11615                         return;
11616                 }
11617
11618                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11619         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11620                 if (strcmp(res->mode_value, "Tunnel")) {
11621                         printf("Please set mode to Tunnel.\n");
11622                         return;
11623                 }
11624
11625                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11626                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11627                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11628                 mask->tunnel_type_mask = res->tunnel_type_mask;
11629         } else {
11630                 if (strcmp(res->mode_value, "IP")) {
11631                         printf("Please set mode to IP.\n");
11632                         return;
11633                 }
11634
11635                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11636                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11637                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11638                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11639                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11640                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11641                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11642         }
11643
11644         cmd_reconfig_device_queue(res->port_id, 1, 1);
11645 }
11646
11647 cmdline_parse_token_string_t cmd_flow_director_mask =
11648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11649                                  flow_director_mask, "flow_director_mask");
11650 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11651         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11652                               port_id, UINT16);
11653 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11654         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11655                                  vlan, "vlan");
11656 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11657         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11658                               vlan_mask, UINT16);
11659 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11660         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11661                                  src_mask, "src_mask");
11662 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11663         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11664                                  ipv4_src);
11665 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11666         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11667                                  ipv6_src);
11668 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11669         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11670                               port_src, UINT16);
11671 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11672         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11673                                  dst_mask, "dst_mask");
11674 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11675         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11676                                  ipv4_dst);
11677 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11678         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11679                                  ipv6_dst);
11680 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11681         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11682                               port_dst, UINT16);
11683
11684 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11685         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11686                                  mode, "mode");
11687 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11688         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11689                                  mode_value, "IP");
11690 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11691         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11692                                  mode_value, "MAC-VLAN");
11693 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11694         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11695                                  mode_value, "Tunnel");
11696 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11697         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11698                                  mac, "mac");
11699 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11700         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11701                               mac_addr_byte_mask, UINT8);
11702 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11703         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11704                                  tunnel_type, "tunnel-type");
11705 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11706         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11707                               tunnel_type_mask, UINT8);
11708 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11709         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11710                                  tunnel_id, "tunnel-id");
11711 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11712         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11713                               tunnel_id_mask, UINT32);
11714
11715 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11716         .f = cmd_flow_director_mask_parsed,
11717         .data = NULL,
11718         .help_str = "flow_director_mask ... : "
11719                 "Set IP mode flow director's mask on NIC",
11720         .tokens = {
11721                 (void *)&cmd_flow_director_mask,
11722                 (void *)&cmd_flow_director_mask_port_id,
11723                 (void *)&cmd_flow_director_mask_mode,
11724                 (void *)&cmd_flow_director_mask_mode_ip,
11725                 (void *)&cmd_flow_director_mask_vlan,
11726                 (void *)&cmd_flow_director_mask_vlan_value,
11727                 (void *)&cmd_flow_director_mask_src,
11728                 (void *)&cmd_flow_director_mask_ipv4_src,
11729                 (void *)&cmd_flow_director_mask_ipv6_src,
11730                 (void *)&cmd_flow_director_mask_port_src,
11731                 (void *)&cmd_flow_director_mask_dst,
11732                 (void *)&cmd_flow_director_mask_ipv4_dst,
11733                 (void *)&cmd_flow_director_mask_ipv6_dst,
11734                 (void *)&cmd_flow_director_mask_port_dst,
11735                 NULL,
11736         },
11737 };
11738
11739 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11740         .f = cmd_flow_director_mask_parsed,
11741         .data = NULL,
11742         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11743                 "flow director's mask on NIC",
11744         .tokens = {
11745                 (void *)&cmd_flow_director_mask,
11746                 (void *)&cmd_flow_director_mask_port_id,
11747                 (void *)&cmd_flow_director_mask_mode,
11748                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11749                 (void *)&cmd_flow_director_mask_vlan,
11750                 (void *)&cmd_flow_director_mask_vlan_value,
11751                 NULL,
11752         },
11753 };
11754
11755 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11756         .f = cmd_flow_director_mask_parsed,
11757         .data = NULL,
11758         .help_str = "flow_director_mask ... : Set tunnel mode "
11759                 "flow director's mask on NIC",
11760         .tokens = {
11761                 (void *)&cmd_flow_director_mask,
11762                 (void *)&cmd_flow_director_mask_port_id,
11763                 (void *)&cmd_flow_director_mask_mode,
11764                 (void *)&cmd_flow_director_mask_mode_tunnel,
11765                 (void *)&cmd_flow_director_mask_vlan,
11766                 (void *)&cmd_flow_director_mask_vlan_value,
11767                 (void *)&cmd_flow_director_mask_mac,
11768                 (void *)&cmd_flow_director_mask_mac_value,
11769                 (void *)&cmd_flow_director_mask_tunnel_type,
11770                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11771                 (void *)&cmd_flow_director_mask_tunnel_id,
11772                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11773                 NULL,
11774         },
11775 };
11776
11777 /* *** deal with flow director mask on flexible payload *** */
11778 struct cmd_flow_director_flex_mask_result {
11779         cmdline_fixed_string_t flow_director_flexmask;
11780         portid_t port_id;
11781         cmdline_fixed_string_t flow;
11782         cmdline_fixed_string_t flow_type;
11783         cmdline_fixed_string_t mask;
11784 };
11785
11786 static void
11787 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11788                           __attribute__((unused)) struct cmdline *cl,
11789                           __attribute__((unused)) void *data)
11790 {
11791         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11792         struct rte_eth_fdir_info fdir_info;
11793         struct rte_eth_fdir_flex_mask flex_mask;
11794         struct rte_port *port;
11795         uint64_t flow_type_mask;
11796         uint16_t i;
11797         int ret;
11798
11799         port = &ports[res->port_id];
11800         /** Check if the port is not started **/
11801         if (port->port_status != RTE_PORT_STOPPED) {
11802                 printf("Please stop port %d first\n", res->port_id);
11803                 return;
11804         }
11805
11806         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11807         ret = parse_flexbytes(res->mask,
11808                         flex_mask.mask,
11809                         RTE_ETH_FDIR_MAX_FLEXLEN);
11810         if (ret < 0) {
11811                 printf("error: Cannot parse mask input.\n");
11812                 return;
11813         }
11814
11815         memset(&fdir_info, 0, sizeof(fdir_info));
11816         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11817                                 RTE_ETH_FILTER_INFO, &fdir_info);
11818         if (ret < 0) {
11819                 printf("Cannot get FDir filter info\n");
11820                 return;
11821         }
11822
11823         if (!strcmp(res->flow_type, "none")) {
11824                 /* means don't specify the flow type */
11825                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11826                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11827                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11828                                0, sizeof(struct rte_eth_fdir_flex_mask));
11829                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11830                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11831                                  &flex_mask,
11832                                  sizeof(struct rte_eth_fdir_flex_mask));
11833                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11834                 return;
11835         }
11836         flow_type_mask = fdir_info.flow_types_mask[0];
11837         if (!strcmp(res->flow_type, "all")) {
11838                 if (!flow_type_mask) {
11839                         printf("No flow type supported\n");
11840                         return;
11841                 }
11842                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11843                         if (flow_type_mask & (1ULL << i)) {
11844                                 flex_mask.flow_type = i;
11845                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11846                         }
11847                 }
11848                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11849                 return;
11850         }
11851         flex_mask.flow_type = str2flowtype(res->flow_type);
11852         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11853                 printf("Flow type %s not supported on port %d\n",
11854                                 res->flow_type, res->port_id);
11855                 return;
11856         }
11857         fdir_set_flex_mask(res->port_id, &flex_mask);
11858         cmd_reconfig_device_queue(res->port_id, 1, 1);
11859 }
11860
11861 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11863                                  flow_director_flexmask,
11864                                  "flow_director_flex_mask");
11865 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11866         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11867                               port_id, UINT16);
11868 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11869         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11870                                  flow, "flow");
11871 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11872         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11873                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11874                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11875 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11876         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11877                                  mask, NULL);
11878
11879 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11880         .f = cmd_flow_director_flex_mask_parsed,
11881         .data = NULL,
11882         .help_str = "flow_director_flex_mask ... : "
11883                 "Set flow director's flex mask on NIC",
11884         .tokens = {
11885                 (void *)&cmd_flow_director_flexmask,
11886                 (void *)&cmd_flow_director_flexmask_port_id,
11887                 (void *)&cmd_flow_director_flexmask_flow,
11888                 (void *)&cmd_flow_director_flexmask_flow_type,
11889                 (void *)&cmd_flow_director_flexmask_mask,
11890                 NULL,
11891         },
11892 };
11893
11894 /* *** deal with flow director flexible payload configuration *** */
11895 struct cmd_flow_director_flexpayload_result {
11896         cmdline_fixed_string_t flow_director_flexpayload;
11897         portid_t port_id;
11898         cmdline_fixed_string_t payload_layer;
11899         cmdline_fixed_string_t payload_cfg;
11900 };
11901
11902 static inline int
11903 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11904 {
11905         char s[256];
11906         const char *p, *p0 = q_arg;
11907         char *end;
11908         unsigned long int_fld;
11909         char *str_fld[max_num];
11910         int i;
11911         unsigned size;
11912         int ret = -1;
11913
11914         p = strchr(p0, '(');
11915         if (p == NULL)
11916                 return -1;
11917         ++p;
11918         p0 = strchr(p, ')');
11919         if (p0 == NULL)
11920                 return -1;
11921
11922         size = p0 - p;
11923         if (size >= sizeof(s))
11924                 return -1;
11925
11926         snprintf(s, sizeof(s), "%.*s", size, p);
11927         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11928         if (ret < 0 || ret > max_num)
11929                 return -1;
11930         for (i = 0; i < ret; i++) {
11931                 errno = 0;
11932                 int_fld = strtoul(str_fld[i], &end, 0);
11933                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11934                         return -1;
11935                 offsets[i] = (uint16_t)int_fld;
11936         }
11937         return ret;
11938 }
11939
11940 static void
11941 cmd_flow_director_flxpld_parsed(void *parsed_result,
11942                           __attribute__((unused)) struct cmdline *cl,
11943                           __attribute__((unused)) void *data)
11944 {
11945         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11946         struct rte_eth_flex_payload_cfg flex_cfg;
11947         struct rte_port *port;
11948         int ret = 0;
11949
11950         port = &ports[res->port_id];
11951         /** Check if the port is not started **/
11952         if (port->port_status != RTE_PORT_STOPPED) {
11953                 printf("Please stop port %d first\n", res->port_id);
11954                 return;
11955         }
11956
11957         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11958
11959         if (!strcmp(res->payload_layer, "raw"))
11960                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11961         else if (!strcmp(res->payload_layer, "l2"))
11962                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11963         else if (!strcmp(res->payload_layer, "l3"))
11964                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11965         else if (!strcmp(res->payload_layer, "l4"))
11966                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11967
11968         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11969                             RTE_ETH_FDIR_MAX_FLEXLEN);
11970         if (ret < 0) {
11971                 printf("error: Cannot parse flex payload input.\n");
11972                 return;
11973         }
11974
11975         fdir_set_flex_payload(res->port_id, &flex_cfg);
11976         cmd_reconfig_device_queue(res->port_id, 1, 1);
11977 }
11978
11979 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11980         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11981                                  flow_director_flexpayload,
11982                                  "flow_director_flex_payload");
11983 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11984         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11985                               port_id, UINT16);
11986 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11987         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11988                                  payload_layer, "raw#l2#l3#l4");
11989 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11990         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11991                                  payload_cfg, NULL);
11992
11993 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11994         .f = cmd_flow_director_flxpld_parsed,
11995         .data = NULL,
11996         .help_str = "flow_director_flexpayload ... : "
11997                 "Set flow director's flex payload on NIC",
11998         .tokens = {
11999                 (void *)&cmd_flow_director_flexpayload,
12000                 (void *)&cmd_flow_director_flexpayload_port_id,
12001                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12002                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12003                 NULL,
12004         },
12005 };
12006
12007 /* Generic flow interface command. */
12008 extern cmdline_parse_inst_t cmd_flow;
12009
12010 /* *** Classification Filters Control *** */
12011 /* *** Get symmetric hash enable per port *** */
12012 struct cmd_get_sym_hash_ena_per_port_result {
12013         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12014         portid_t port_id;
12015 };
12016
12017 static void
12018 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12019                                  __rte_unused struct cmdline *cl,
12020                                  __rte_unused void *data)
12021 {
12022         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12023         struct rte_eth_hash_filter_info info;
12024         int ret;
12025
12026         if (rte_eth_dev_filter_supported(res->port_id,
12027                                 RTE_ETH_FILTER_HASH) < 0) {
12028                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12029                                                         res->port_id);
12030                 return;
12031         }
12032
12033         memset(&info, 0, sizeof(info));
12034         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12035         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12036                                                 RTE_ETH_FILTER_GET, &info);
12037
12038         if (ret < 0) {
12039                 printf("Cannot get symmetric hash enable per port "
12040                                         "on port %u\n", res->port_id);
12041                 return;
12042         }
12043
12044         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12045                                 "enabled" : "disabled", res->port_id);
12046 }
12047
12048 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12049         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12050                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12051 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12052         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12053                 port_id, UINT16);
12054
12055 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12056         .f = cmd_get_sym_hash_per_port_parsed,
12057         .data = NULL,
12058         .help_str = "get_sym_hash_ena_per_port <port_id>",
12059         .tokens = {
12060                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12061                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12062                 NULL,
12063         },
12064 };
12065
12066 /* *** Set symmetric hash enable per port *** */
12067 struct cmd_set_sym_hash_ena_per_port_result {
12068         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12069         cmdline_fixed_string_t enable;
12070         portid_t port_id;
12071 };
12072
12073 static void
12074 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12075                                  __rte_unused struct cmdline *cl,
12076                                  __rte_unused void *data)
12077 {
12078         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12079         struct rte_eth_hash_filter_info info;
12080         int ret;
12081
12082         if (rte_eth_dev_filter_supported(res->port_id,
12083                                 RTE_ETH_FILTER_HASH) < 0) {
12084                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12085                                                         res->port_id);
12086                 return;
12087         }
12088
12089         memset(&info, 0, sizeof(info));
12090         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12091         if (!strcmp(res->enable, "enable"))
12092                 info.info.enable = 1;
12093         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12094                                         RTE_ETH_FILTER_SET, &info);
12095         if (ret < 0) {
12096                 printf("Cannot set symmetric hash enable per port on "
12097                                         "port %u\n", res->port_id);
12098                 return;
12099         }
12100         printf("Symmetric hash has been set to %s on port %u\n",
12101                                         res->enable, res->port_id);
12102 }
12103
12104 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12105         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12106                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12107 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12108         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12109                 port_id, UINT16);
12110 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12111         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12112                 enable, "enable#disable");
12113
12114 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12115         .f = cmd_set_sym_hash_per_port_parsed,
12116         .data = NULL,
12117         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12118         .tokens = {
12119                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12120                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12121                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12122                 NULL,
12123         },
12124 };
12125
12126 /* Get global config of hash function */
12127 struct cmd_get_hash_global_config_result {
12128         cmdline_fixed_string_t get_hash_global_config;
12129         portid_t port_id;
12130 };
12131
12132 static char *
12133 flowtype_to_str(uint16_t ftype)
12134 {
12135         uint16_t i;
12136         static struct {
12137                 char str[16];
12138                 uint16_t ftype;
12139         } ftype_table[] = {
12140                 {"ipv4", RTE_ETH_FLOW_IPV4},
12141                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12142                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12143                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12144                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12145                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12146                 {"ipv6", RTE_ETH_FLOW_IPV6},
12147                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12148                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12149                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12150                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12151                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12152                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12153                 {"port", RTE_ETH_FLOW_PORT},
12154                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12155                 {"geneve", RTE_ETH_FLOW_GENEVE},
12156                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12157                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12158         };
12159
12160         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12161                 if (ftype_table[i].ftype == ftype)
12162                         return ftype_table[i].str;
12163         }
12164
12165         return NULL;
12166 }
12167
12168 static void
12169 cmd_get_hash_global_config_parsed(void *parsed_result,
12170                                   __rte_unused struct cmdline *cl,
12171                                   __rte_unused void *data)
12172 {
12173         struct cmd_get_hash_global_config_result *res = parsed_result;
12174         struct rte_eth_hash_filter_info info;
12175         uint32_t idx, offset;
12176         uint16_t i;
12177         char *str;
12178         int ret;
12179
12180         if (rte_eth_dev_filter_supported(res->port_id,
12181                         RTE_ETH_FILTER_HASH) < 0) {
12182                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12183                                                         res->port_id);
12184                 return;
12185         }
12186
12187         memset(&info, 0, sizeof(info));
12188         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12189         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12190                                         RTE_ETH_FILTER_GET, &info);
12191         if (ret < 0) {
12192                 printf("Cannot get hash global configurations by port %d\n",
12193                                                         res->port_id);
12194                 return;
12195         }
12196
12197         switch (info.info.global_conf.hash_func) {
12198         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12199                 printf("Hash function is Toeplitz\n");
12200                 break;
12201         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12202                 printf("Hash function is Simple XOR\n");
12203                 break;
12204         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12205                 printf("Hash function is Symmetric Toeplitz\n");
12206                 break;
12207         default:
12208                 printf("Unknown hash function\n");
12209                 break;
12210         }
12211
12212         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12213                 idx = i / UINT64_BIT;
12214                 offset = i % UINT64_BIT;
12215                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12216                                                 (1ULL << offset)))
12217                         continue;
12218                 str = flowtype_to_str(i);
12219                 if (!str)
12220                         continue;
12221                 printf("Symmetric hash is %s globally for flow type %s "
12222                                                         "by port %d\n",
12223                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12224                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12225                                                         res->port_id);
12226         }
12227 }
12228
12229 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12230         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12231                 get_hash_global_config, "get_hash_global_config");
12232 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12233         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12234                 port_id, UINT16);
12235
12236 cmdline_parse_inst_t cmd_get_hash_global_config = {
12237         .f = cmd_get_hash_global_config_parsed,
12238         .data = NULL,
12239         .help_str = "get_hash_global_config <port_id>",
12240         .tokens = {
12241                 (void *)&cmd_get_hash_global_config_all,
12242                 (void *)&cmd_get_hash_global_config_port_id,
12243                 NULL,
12244         },
12245 };
12246
12247 /* Set global config of hash function */
12248 struct cmd_set_hash_global_config_result {
12249         cmdline_fixed_string_t set_hash_global_config;
12250         portid_t port_id;
12251         cmdline_fixed_string_t hash_func;
12252         cmdline_fixed_string_t flow_type;
12253         cmdline_fixed_string_t enable;
12254 };
12255
12256 static void
12257 cmd_set_hash_global_config_parsed(void *parsed_result,
12258                                   __rte_unused struct cmdline *cl,
12259                                   __rte_unused void *data)
12260 {
12261         struct cmd_set_hash_global_config_result *res = parsed_result;
12262         struct rte_eth_hash_filter_info info;
12263         uint32_t ftype, idx, offset;
12264         int ret;
12265
12266         if (rte_eth_dev_filter_supported(res->port_id,
12267                                 RTE_ETH_FILTER_HASH) < 0) {
12268                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12269                                                         res->port_id);
12270                 return;
12271         }
12272         memset(&info, 0, sizeof(info));
12273         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12274         if (!strcmp(res->hash_func, "toeplitz"))
12275                 info.info.global_conf.hash_func =
12276                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12277         else if (!strcmp(res->hash_func, "simple_xor"))
12278                 info.info.global_conf.hash_func =
12279                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12280         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12281                 info.info.global_conf.hash_func =
12282                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12283         else if (!strcmp(res->hash_func, "default"))
12284                 info.info.global_conf.hash_func =
12285                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12286
12287         ftype = str2flowtype(res->flow_type);
12288         idx = ftype / UINT64_BIT;
12289         offset = ftype % UINT64_BIT;
12290         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12291         if (!strcmp(res->enable, "enable"))
12292                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12293                                                 (1ULL << offset);
12294         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12295                                         RTE_ETH_FILTER_SET, &info);
12296         if (ret < 0)
12297                 printf("Cannot set global hash configurations by port %d\n",
12298                                                         res->port_id);
12299         else
12300                 printf("Global hash configurations have been set "
12301                         "successfully by port %d\n", res->port_id);
12302 }
12303
12304 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12305         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12306                 set_hash_global_config, "set_hash_global_config");
12307 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12308         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12309                 port_id, UINT16);
12310 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12311         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12312                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12313 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12314         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12315                 flow_type,
12316                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12317                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12318 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12319         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12320                 enable, "enable#disable");
12321
12322 cmdline_parse_inst_t cmd_set_hash_global_config = {
12323         .f = cmd_set_hash_global_config_parsed,
12324         .data = NULL,
12325         .help_str = "set_hash_global_config <port_id> "
12326                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12327                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12328                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12329                 "l2_payload enable|disable",
12330         .tokens = {
12331                 (void *)&cmd_set_hash_global_config_all,
12332                 (void *)&cmd_set_hash_global_config_port_id,
12333                 (void *)&cmd_set_hash_global_config_hash_func,
12334                 (void *)&cmd_set_hash_global_config_flow_type,
12335                 (void *)&cmd_set_hash_global_config_enable,
12336                 NULL,
12337         },
12338 };
12339
12340 /* Set hash input set */
12341 struct cmd_set_hash_input_set_result {
12342         cmdline_fixed_string_t set_hash_input_set;
12343         portid_t port_id;
12344         cmdline_fixed_string_t flow_type;
12345         cmdline_fixed_string_t inset_field;
12346         cmdline_fixed_string_t select;
12347 };
12348
12349 static enum rte_eth_input_set_field
12350 str2inset(char *string)
12351 {
12352         uint16_t i;
12353
12354         static const struct {
12355                 char str[32];
12356                 enum rte_eth_input_set_field inset;
12357         } inset_table[] = {
12358                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12359                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12360                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12361                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12362                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12363                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12364                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12365                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12366                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12367                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12368                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12369                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12370                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12371                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12372                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12373                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12374                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12375                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12376                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12377                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12378                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12379                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12380                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12381                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12382                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12383                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12384                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12385                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12386                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12387                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12388                 {"none", RTE_ETH_INPUT_SET_NONE},
12389         };
12390
12391         for (i = 0; i < RTE_DIM(inset_table); i++) {
12392                 if (!strcmp(string, inset_table[i].str))
12393                         return inset_table[i].inset;
12394         }
12395
12396         return RTE_ETH_INPUT_SET_UNKNOWN;
12397 }
12398
12399 static void
12400 cmd_set_hash_input_set_parsed(void *parsed_result,
12401                               __rte_unused struct cmdline *cl,
12402                               __rte_unused void *data)
12403 {
12404         struct cmd_set_hash_input_set_result *res = parsed_result;
12405         struct rte_eth_hash_filter_info info;
12406
12407         memset(&info, 0, sizeof(info));
12408         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12409         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12410         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12411         info.info.input_set_conf.inset_size = 1;
12412         if (!strcmp(res->select, "select"))
12413                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12414         else if (!strcmp(res->select, "add"))
12415                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12416         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12417                                 RTE_ETH_FILTER_SET, &info);
12418 }
12419
12420 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12421         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12422                 set_hash_input_set, "set_hash_input_set");
12423 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12424         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12425                 port_id, UINT16);
12426 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12427         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12428                 flow_type, NULL);
12429 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12430         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12431                 inset_field,
12432                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12433                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12434                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12435                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12436                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12437                 "fld-8th#none");
12438 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12439         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12440                 select, "select#add");
12441
12442 cmdline_parse_inst_t cmd_set_hash_input_set = {
12443         .f = cmd_set_hash_input_set_parsed,
12444         .data = NULL,
12445         .help_str = "set_hash_input_set <port_id> "
12446         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12447         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12448         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12449         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12450         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12451         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12452         "fld-7th|fld-8th|none select|add",
12453         .tokens = {
12454                 (void *)&cmd_set_hash_input_set_cmd,
12455                 (void *)&cmd_set_hash_input_set_port_id,
12456                 (void *)&cmd_set_hash_input_set_flow_type,
12457                 (void *)&cmd_set_hash_input_set_field,
12458                 (void *)&cmd_set_hash_input_set_select,
12459                 NULL,
12460         },
12461 };
12462
12463 /* Set flow director input set */
12464 struct cmd_set_fdir_input_set_result {
12465         cmdline_fixed_string_t set_fdir_input_set;
12466         portid_t port_id;
12467         cmdline_fixed_string_t flow_type;
12468         cmdline_fixed_string_t inset_field;
12469         cmdline_fixed_string_t select;
12470 };
12471
12472 static void
12473 cmd_set_fdir_input_set_parsed(void *parsed_result,
12474         __rte_unused struct cmdline *cl,
12475         __rte_unused void *data)
12476 {
12477         struct cmd_set_fdir_input_set_result *res = parsed_result;
12478         struct rte_eth_fdir_filter_info info;
12479
12480         memset(&info, 0, sizeof(info));
12481         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12482         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12483         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12484         info.info.input_set_conf.inset_size = 1;
12485         if (!strcmp(res->select, "select"))
12486                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12487         else if (!strcmp(res->select, "add"))
12488                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12489         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12490                 RTE_ETH_FILTER_SET, &info);
12491 }
12492
12493 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12494         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12495         set_fdir_input_set, "set_fdir_input_set");
12496 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12497         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12498         port_id, UINT16);
12499 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12500         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12501         flow_type,
12502         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12503         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12504 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12505         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12506         inset_field,
12507         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12508         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12509         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12510         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12511         "sctp-veri-tag#none");
12512 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12513         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12514         select, "select#add");
12515
12516 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12517         .f = cmd_set_fdir_input_set_parsed,
12518         .data = NULL,
12519         .help_str = "set_fdir_input_set <port_id> "
12520         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12521         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12522         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12523         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12524         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12525         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12526         "sctp-veri-tag|none select|add",
12527         .tokens = {
12528                 (void *)&cmd_set_fdir_input_set_cmd,
12529                 (void *)&cmd_set_fdir_input_set_port_id,
12530                 (void *)&cmd_set_fdir_input_set_flow_type,
12531                 (void *)&cmd_set_fdir_input_set_field,
12532                 (void *)&cmd_set_fdir_input_set_select,
12533                 NULL,
12534         },
12535 };
12536
12537 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12538 struct cmd_mcast_addr_result {
12539         cmdline_fixed_string_t mcast_addr_cmd;
12540         cmdline_fixed_string_t what;
12541         uint16_t port_num;
12542         struct rte_ether_addr mc_addr;
12543 };
12544
12545 static void cmd_mcast_addr_parsed(void *parsed_result,
12546                 __attribute__((unused)) struct cmdline *cl,
12547                 __attribute__((unused)) void *data)
12548 {
12549         struct cmd_mcast_addr_result *res = parsed_result;
12550
12551         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12552                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12553                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12554                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12555                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12556                 return;
12557         }
12558         if (strcmp(res->what, "add") == 0)
12559                 mcast_addr_add(res->port_num, &res->mc_addr);
12560         else
12561                 mcast_addr_remove(res->port_num, &res->mc_addr);
12562 }
12563
12564 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12565         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12566                                  mcast_addr_cmd, "mcast_addr");
12567 cmdline_parse_token_string_t cmd_mcast_addr_what =
12568         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12569                                  "add#remove");
12570 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12571         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12572 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12573         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12574
12575 cmdline_parse_inst_t cmd_mcast_addr = {
12576         .f = cmd_mcast_addr_parsed,
12577         .data = (void *)0,
12578         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12579                 "Add/Remove multicast MAC address on port_id",
12580         .tokens = {
12581                 (void *)&cmd_mcast_addr_cmd,
12582                 (void *)&cmd_mcast_addr_what,
12583                 (void *)&cmd_mcast_addr_portnum,
12584                 (void *)&cmd_mcast_addr_addr,
12585                 NULL,
12586         },
12587 };
12588
12589 /* l2 tunnel config
12590  * only support E-tag now.
12591  */
12592
12593 /* Ether type config */
12594 struct cmd_config_l2_tunnel_eth_type_result {
12595         cmdline_fixed_string_t port;
12596         cmdline_fixed_string_t config;
12597         cmdline_fixed_string_t all;
12598         portid_t id;
12599         cmdline_fixed_string_t l2_tunnel;
12600         cmdline_fixed_string_t l2_tunnel_type;
12601         cmdline_fixed_string_t eth_type;
12602         uint16_t eth_type_val;
12603 };
12604
12605 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12606         TOKEN_STRING_INITIALIZER
12607                 (struct cmd_config_l2_tunnel_eth_type_result,
12608                  port, "port");
12609 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12610         TOKEN_STRING_INITIALIZER
12611                 (struct cmd_config_l2_tunnel_eth_type_result,
12612                  config, "config");
12613 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12614         TOKEN_STRING_INITIALIZER
12615                 (struct cmd_config_l2_tunnel_eth_type_result,
12616                  all, "all");
12617 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12618         TOKEN_NUM_INITIALIZER
12619                 (struct cmd_config_l2_tunnel_eth_type_result,
12620                  id, UINT16);
12621 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12622         TOKEN_STRING_INITIALIZER
12623                 (struct cmd_config_l2_tunnel_eth_type_result,
12624                  l2_tunnel, "l2-tunnel");
12625 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12626         TOKEN_STRING_INITIALIZER
12627                 (struct cmd_config_l2_tunnel_eth_type_result,
12628                  l2_tunnel_type, "E-tag");
12629 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12630         TOKEN_STRING_INITIALIZER
12631                 (struct cmd_config_l2_tunnel_eth_type_result,
12632                  eth_type, "ether-type");
12633 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12634         TOKEN_NUM_INITIALIZER
12635                 (struct cmd_config_l2_tunnel_eth_type_result,
12636                  eth_type_val, UINT16);
12637
12638 static enum rte_eth_tunnel_type
12639 str2fdir_l2_tunnel_type(char *string)
12640 {
12641         uint32_t i = 0;
12642
12643         static const struct {
12644                 char str[32];
12645                 enum rte_eth_tunnel_type type;
12646         } l2_tunnel_type_str[] = {
12647                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12648         };
12649
12650         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12651                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12652                         return l2_tunnel_type_str[i].type;
12653         }
12654         return RTE_TUNNEL_TYPE_NONE;
12655 }
12656
12657 /* ether type config for all ports */
12658 static void
12659 cmd_config_l2_tunnel_eth_type_all_parsed
12660         (void *parsed_result,
12661          __attribute__((unused)) struct cmdline *cl,
12662          __attribute__((unused)) void *data)
12663 {
12664         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12665         struct rte_eth_l2_tunnel_conf entry;
12666         portid_t pid;
12667
12668         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12669         entry.ether_type = res->eth_type_val;
12670
12671         RTE_ETH_FOREACH_DEV(pid) {
12672                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12673         }
12674 }
12675
12676 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12677         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12678         .data = NULL,
12679         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12680         .tokens = {
12681                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12682                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12683                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12684                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12685                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12686                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12687                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12688                 NULL,
12689         },
12690 };
12691
12692 /* ether type config for a specific port */
12693 static void
12694 cmd_config_l2_tunnel_eth_type_specific_parsed(
12695         void *parsed_result,
12696         __attribute__((unused)) struct cmdline *cl,
12697         __attribute__((unused)) void *data)
12698 {
12699         struct cmd_config_l2_tunnel_eth_type_result *res =
12700                  parsed_result;
12701         struct rte_eth_l2_tunnel_conf entry;
12702
12703         if (port_id_is_invalid(res->id, ENABLED_WARN))
12704                 return;
12705
12706         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12707         entry.ether_type = res->eth_type_val;
12708
12709         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12710 }
12711
12712 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12713         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12714         .data = NULL,
12715         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12716         .tokens = {
12717                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12718                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12719                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12720                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12721                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12722                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12723                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12724                 NULL,
12725         },
12726 };
12727
12728 /* Enable/disable l2 tunnel */
12729 struct cmd_config_l2_tunnel_en_dis_result {
12730         cmdline_fixed_string_t port;
12731         cmdline_fixed_string_t config;
12732         cmdline_fixed_string_t all;
12733         portid_t id;
12734         cmdline_fixed_string_t l2_tunnel;
12735         cmdline_fixed_string_t l2_tunnel_type;
12736         cmdline_fixed_string_t en_dis;
12737 };
12738
12739 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12740         TOKEN_STRING_INITIALIZER
12741                 (struct cmd_config_l2_tunnel_en_dis_result,
12742                  port, "port");
12743 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12744         TOKEN_STRING_INITIALIZER
12745                 (struct cmd_config_l2_tunnel_en_dis_result,
12746                  config, "config");
12747 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12748         TOKEN_STRING_INITIALIZER
12749                 (struct cmd_config_l2_tunnel_en_dis_result,
12750                  all, "all");
12751 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12752         TOKEN_NUM_INITIALIZER
12753                 (struct cmd_config_l2_tunnel_en_dis_result,
12754                  id, UINT16);
12755 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12756         TOKEN_STRING_INITIALIZER
12757                 (struct cmd_config_l2_tunnel_en_dis_result,
12758                  l2_tunnel, "l2-tunnel");
12759 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12760         TOKEN_STRING_INITIALIZER
12761                 (struct cmd_config_l2_tunnel_en_dis_result,
12762                  l2_tunnel_type, "E-tag");
12763 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12764         TOKEN_STRING_INITIALIZER
12765                 (struct cmd_config_l2_tunnel_en_dis_result,
12766                  en_dis, "enable#disable");
12767
12768 /* enable/disable l2 tunnel for all ports */
12769 static void
12770 cmd_config_l2_tunnel_en_dis_all_parsed(
12771         void *parsed_result,
12772         __attribute__((unused)) struct cmdline *cl,
12773         __attribute__((unused)) void *data)
12774 {
12775         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12776         struct rte_eth_l2_tunnel_conf entry;
12777         portid_t pid;
12778         uint8_t en;
12779
12780         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12781
12782         if (!strcmp("enable", res->en_dis))
12783                 en = 1;
12784         else
12785                 en = 0;
12786
12787         RTE_ETH_FOREACH_DEV(pid) {
12788                 rte_eth_dev_l2_tunnel_offload_set(pid,
12789                                                   &entry,
12790                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12791                                                   en);
12792         }
12793 }
12794
12795 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12796         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12797         .data = NULL,
12798         .help_str = "port config all l2-tunnel E-tag enable|disable",
12799         .tokens = {
12800                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12801                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12802                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12803                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12804                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12805                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12806                 NULL,
12807         },
12808 };
12809
12810 /* enable/disable l2 tunnel for a port */
12811 static void
12812 cmd_config_l2_tunnel_en_dis_specific_parsed(
12813         void *parsed_result,
12814         __attribute__((unused)) struct cmdline *cl,
12815         __attribute__((unused)) void *data)
12816 {
12817         struct cmd_config_l2_tunnel_en_dis_result *res =
12818                 parsed_result;
12819         struct rte_eth_l2_tunnel_conf entry;
12820
12821         if (port_id_is_invalid(res->id, ENABLED_WARN))
12822                 return;
12823
12824         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12825
12826         if (!strcmp("enable", res->en_dis))
12827                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12828                                                   &entry,
12829                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12830                                                   1);
12831         else
12832                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12833                                                   &entry,
12834                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12835                                                   0);
12836 }
12837
12838 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12839         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12840         .data = NULL,
12841         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12842         .tokens = {
12843                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12844                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12845                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12846                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12847                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12848                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12849                 NULL,
12850         },
12851 };
12852
12853 /* E-tag configuration */
12854
12855 /* Common result structure for all E-tag configuration */
12856 struct cmd_config_e_tag_result {
12857         cmdline_fixed_string_t e_tag;
12858         cmdline_fixed_string_t set;
12859         cmdline_fixed_string_t insertion;
12860         cmdline_fixed_string_t stripping;
12861         cmdline_fixed_string_t forwarding;
12862         cmdline_fixed_string_t filter;
12863         cmdline_fixed_string_t add;
12864         cmdline_fixed_string_t del;
12865         cmdline_fixed_string_t on;
12866         cmdline_fixed_string_t off;
12867         cmdline_fixed_string_t on_off;
12868         cmdline_fixed_string_t port_tag_id;
12869         uint32_t port_tag_id_val;
12870         cmdline_fixed_string_t e_tag_id;
12871         uint16_t e_tag_id_val;
12872         cmdline_fixed_string_t dst_pool;
12873         uint8_t dst_pool_val;
12874         cmdline_fixed_string_t port;
12875         portid_t port_id;
12876         cmdline_fixed_string_t vf;
12877         uint8_t vf_id;
12878 };
12879
12880 /* Common CLI fields for all E-tag configuration */
12881 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12882         TOKEN_STRING_INITIALIZER
12883                 (struct cmd_config_e_tag_result,
12884                  e_tag, "E-tag");
12885 cmdline_parse_token_string_t cmd_config_e_tag_set =
12886         TOKEN_STRING_INITIALIZER
12887                 (struct cmd_config_e_tag_result,
12888                  set, "set");
12889 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12890         TOKEN_STRING_INITIALIZER
12891                 (struct cmd_config_e_tag_result,
12892                  insertion, "insertion");
12893 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12894         TOKEN_STRING_INITIALIZER
12895                 (struct cmd_config_e_tag_result,
12896                  stripping, "stripping");
12897 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12898         TOKEN_STRING_INITIALIZER
12899                 (struct cmd_config_e_tag_result,
12900                  forwarding, "forwarding");
12901 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12902         TOKEN_STRING_INITIALIZER
12903                 (struct cmd_config_e_tag_result,
12904                  filter, "filter");
12905 cmdline_parse_token_string_t cmd_config_e_tag_add =
12906         TOKEN_STRING_INITIALIZER
12907                 (struct cmd_config_e_tag_result,
12908                  add, "add");
12909 cmdline_parse_token_string_t cmd_config_e_tag_del =
12910         TOKEN_STRING_INITIALIZER
12911                 (struct cmd_config_e_tag_result,
12912                  del, "del");
12913 cmdline_parse_token_string_t cmd_config_e_tag_on =
12914         TOKEN_STRING_INITIALIZER
12915                 (struct cmd_config_e_tag_result,
12916                  on, "on");
12917 cmdline_parse_token_string_t cmd_config_e_tag_off =
12918         TOKEN_STRING_INITIALIZER
12919                 (struct cmd_config_e_tag_result,
12920                  off, "off");
12921 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12922         TOKEN_STRING_INITIALIZER
12923                 (struct cmd_config_e_tag_result,
12924                  on_off, "on#off");
12925 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12926         TOKEN_STRING_INITIALIZER
12927                 (struct cmd_config_e_tag_result,
12928                  port_tag_id, "port-tag-id");
12929 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12930         TOKEN_NUM_INITIALIZER
12931                 (struct cmd_config_e_tag_result,
12932                  port_tag_id_val, UINT32);
12933 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12934         TOKEN_STRING_INITIALIZER
12935                 (struct cmd_config_e_tag_result,
12936                  e_tag_id, "e-tag-id");
12937 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12938         TOKEN_NUM_INITIALIZER
12939                 (struct cmd_config_e_tag_result,
12940                  e_tag_id_val, UINT16);
12941 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12942         TOKEN_STRING_INITIALIZER
12943                 (struct cmd_config_e_tag_result,
12944                  dst_pool, "dst-pool");
12945 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12946         TOKEN_NUM_INITIALIZER
12947                 (struct cmd_config_e_tag_result,
12948                  dst_pool_val, UINT8);
12949 cmdline_parse_token_string_t cmd_config_e_tag_port =
12950         TOKEN_STRING_INITIALIZER
12951                 (struct cmd_config_e_tag_result,
12952                  port, "port");
12953 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12954         TOKEN_NUM_INITIALIZER
12955                 (struct cmd_config_e_tag_result,
12956                  port_id, UINT16);
12957 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12958         TOKEN_STRING_INITIALIZER
12959                 (struct cmd_config_e_tag_result,
12960                  vf, "vf");
12961 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12962         TOKEN_NUM_INITIALIZER
12963                 (struct cmd_config_e_tag_result,
12964                  vf_id, UINT8);
12965
12966 /* E-tag insertion configuration */
12967 static void
12968 cmd_config_e_tag_insertion_en_parsed(
12969         void *parsed_result,
12970         __attribute__((unused)) struct cmdline *cl,
12971         __attribute__((unused)) void *data)
12972 {
12973         struct cmd_config_e_tag_result *res =
12974                 parsed_result;
12975         struct rte_eth_l2_tunnel_conf entry;
12976
12977         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12978                 return;
12979
12980         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12981         entry.tunnel_id = res->port_tag_id_val;
12982         entry.vf_id = res->vf_id;
12983         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12984                                           &entry,
12985                                           ETH_L2_TUNNEL_INSERTION_MASK,
12986                                           1);
12987 }
12988
12989 static void
12990 cmd_config_e_tag_insertion_dis_parsed(
12991         void *parsed_result,
12992         __attribute__((unused)) struct cmdline *cl,
12993         __attribute__((unused)) void *data)
12994 {
12995         struct cmd_config_e_tag_result *res =
12996                 parsed_result;
12997         struct rte_eth_l2_tunnel_conf entry;
12998
12999         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13000                 return;
13001
13002         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13003         entry.vf_id = res->vf_id;
13004
13005         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13006                                           &entry,
13007                                           ETH_L2_TUNNEL_INSERTION_MASK,
13008                                           0);
13009 }
13010
13011 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13012         .f = cmd_config_e_tag_insertion_en_parsed,
13013         .data = NULL,
13014         .help_str = "E-tag ... : E-tag insertion enable",
13015         .tokens = {
13016                 (void *)&cmd_config_e_tag_e_tag,
13017                 (void *)&cmd_config_e_tag_set,
13018                 (void *)&cmd_config_e_tag_insertion,
13019                 (void *)&cmd_config_e_tag_on,
13020                 (void *)&cmd_config_e_tag_port_tag_id,
13021                 (void *)&cmd_config_e_tag_port_tag_id_val,
13022                 (void *)&cmd_config_e_tag_port,
13023                 (void *)&cmd_config_e_tag_port_id,
13024                 (void *)&cmd_config_e_tag_vf,
13025                 (void *)&cmd_config_e_tag_vf_id,
13026                 NULL,
13027         },
13028 };
13029
13030 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13031         .f = cmd_config_e_tag_insertion_dis_parsed,
13032         .data = NULL,
13033         .help_str = "E-tag ... : E-tag insertion disable",
13034         .tokens = {
13035                 (void *)&cmd_config_e_tag_e_tag,
13036                 (void *)&cmd_config_e_tag_set,
13037                 (void *)&cmd_config_e_tag_insertion,
13038                 (void *)&cmd_config_e_tag_off,
13039                 (void *)&cmd_config_e_tag_port,
13040                 (void *)&cmd_config_e_tag_port_id,
13041                 (void *)&cmd_config_e_tag_vf,
13042                 (void *)&cmd_config_e_tag_vf_id,
13043                 NULL,
13044         },
13045 };
13046
13047 /* E-tag stripping configuration */
13048 static void
13049 cmd_config_e_tag_stripping_parsed(
13050         void *parsed_result,
13051         __attribute__((unused)) struct cmdline *cl,
13052         __attribute__((unused)) void *data)
13053 {
13054         struct cmd_config_e_tag_result *res =
13055                 parsed_result;
13056         struct rte_eth_l2_tunnel_conf entry;
13057
13058         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13059                 return;
13060
13061         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13062
13063         if (!strcmp(res->on_off, "on"))
13064                 rte_eth_dev_l2_tunnel_offload_set
13065                         (res->port_id,
13066                          &entry,
13067                          ETH_L2_TUNNEL_STRIPPING_MASK,
13068                          1);
13069         else
13070                 rte_eth_dev_l2_tunnel_offload_set
13071                         (res->port_id,
13072                          &entry,
13073                          ETH_L2_TUNNEL_STRIPPING_MASK,
13074                          0);
13075 }
13076
13077 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13078         .f = cmd_config_e_tag_stripping_parsed,
13079         .data = NULL,
13080         .help_str = "E-tag ... : E-tag stripping enable/disable",
13081         .tokens = {
13082                 (void *)&cmd_config_e_tag_e_tag,
13083                 (void *)&cmd_config_e_tag_set,
13084                 (void *)&cmd_config_e_tag_stripping,
13085                 (void *)&cmd_config_e_tag_on_off,
13086                 (void *)&cmd_config_e_tag_port,
13087                 (void *)&cmd_config_e_tag_port_id,
13088                 NULL,
13089         },
13090 };
13091
13092 /* E-tag forwarding configuration */
13093 static void
13094 cmd_config_e_tag_forwarding_parsed(
13095         void *parsed_result,
13096         __attribute__((unused)) struct cmdline *cl,
13097         __attribute__((unused)) void *data)
13098 {
13099         struct cmd_config_e_tag_result *res = parsed_result;
13100         struct rte_eth_l2_tunnel_conf entry;
13101
13102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13103                 return;
13104
13105         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13106
13107         if (!strcmp(res->on_off, "on"))
13108                 rte_eth_dev_l2_tunnel_offload_set
13109                         (res->port_id,
13110                          &entry,
13111                          ETH_L2_TUNNEL_FORWARDING_MASK,
13112                          1);
13113         else
13114                 rte_eth_dev_l2_tunnel_offload_set
13115                         (res->port_id,
13116                          &entry,
13117                          ETH_L2_TUNNEL_FORWARDING_MASK,
13118                          0);
13119 }
13120
13121 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13122         .f = cmd_config_e_tag_forwarding_parsed,
13123         .data = NULL,
13124         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13125         .tokens = {
13126                 (void *)&cmd_config_e_tag_e_tag,
13127                 (void *)&cmd_config_e_tag_set,
13128                 (void *)&cmd_config_e_tag_forwarding,
13129                 (void *)&cmd_config_e_tag_on_off,
13130                 (void *)&cmd_config_e_tag_port,
13131                 (void *)&cmd_config_e_tag_port_id,
13132                 NULL,
13133         },
13134 };
13135
13136 /* E-tag filter configuration */
13137 static void
13138 cmd_config_e_tag_filter_add_parsed(
13139         void *parsed_result,
13140         __attribute__((unused)) struct cmdline *cl,
13141         __attribute__((unused)) void *data)
13142 {
13143         struct cmd_config_e_tag_result *res = parsed_result;
13144         struct rte_eth_l2_tunnel_conf entry;
13145         int ret = 0;
13146
13147         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13148                 return;
13149
13150         if (res->e_tag_id_val > 0x3fff) {
13151                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13152                 return;
13153         }
13154
13155         ret = rte_eth_dev_filter_supported(res->port_id,
13156                                            RTE_ETH_FILTER_L2_TUNNEL);
13157         if (ret < 0) {
13158                 printf("E-tag filter is not supported on port %u.\n",
13159                        res->port_id);
13160                 return;
13161         }
13162
13163         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13164         entry.tunnel_id = res->e_tag_id_val;
13165         entry.pool = res->dst_pool_val;
13166
13167         ret = rte_eth_dev_filter_ctrl(res->port_id,
13168                                       RTE_ETH_FILTER_L2_TUNNEL,
13169                                       RTE_ETH_FILTER_ADD,
13170                                       &entry);
13171         if (ret < 0)
13172                 printf("E-tag filter programming error: (%s)\n",
13173                        strerror(-ret));
13174 }
13175
13176 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13177         .f = cmd_config_e_tag_filter_add_parsed,
13178         .data = NULL,
13179         .help_str = "E-tag ... : E-tag filter add",
13180         .tokens = {
13181                 (void *)&cmd_config_e_tag_e_tag,
13182                 (void *)&cmd_config_e_tag_set,
13183                 (void *)&cmd_config_e_tag_filter,
13184                 (void *)&cmd_config_e_tag_add,
13185                 (void *)&cmd_config_e_tag_e_tag_id,
13186                 (void *)&cmd_config_e_tag_e_tag_id_val,
13187                 (void *)&cmd_config_e_tag_dst_pool,
13188                 (void *)&cmd_config_e_tag_dst_pool_val,
13189                 (void *)&cmd_config_e_tag_port,
13190                 (void *)&cmd_config_e_tag_port_id,
13191                 NULL,
13192         },
13193 };
13194
13195 static void
13196 cmd_config_e_tag_filter_del_parsed(
13197         void *parsed_result,
13198         __attribute__((unused)) struct cmdline *cl,
13199         __attribute__((unused)) void *data)
13200 {
13201         struct cmd_config_e_tag_result *res = parsed_result;
13202         struct rte_eth_l2_tunnel_conf entry;
13203         int ret = 0;
13204
13205         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13206                 return;
13207
13208         if (res->e_tag_id_val > 0x3fff) {
13209                 printf("e-tag-id must be less than 0x3fff.\n");
13210                 return;
13211         }
13212
13213         ret = rte_eth_dev_filter_supported(res->port_id,
13214                                            RTE_ETH_FILTER_L2_TUNNEL);
13215         if (ret < 0) {
13216                 printf("E-tag filter is not supported on port %u.\n",
13217                        res->port_id);
13218                 return;
13219         }
13220
13221         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13222         entry.tunnel_id = res->e_tag_id_val;
13223
13224         ret = rte_eth_dev_filter_ctrl(res->port_id,
13225                                       RTE_ETH_FILTER_L2_TUNNEL,
13226                                       RTE_ETH_FILTER_DELETE,
13227                                       &entry);
13228         if (ret < 0)
13229                 printf("E-tag filter programming error: (%s)\n",
13230                        strerror(-ret));
13231 }
13232
13233 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13234         .f = cmd_config_e_tag_filter_del_parsed,
13235         .data = NULL,
13236         .help_str = "E-tag ... : E-tag filter delete",
13237         .tokens = {
13238                 (void *)&cmd_config_e_tag_e_tag,
13239                 (void *)&cmd_config_e_tag_set,
13240                 (void *)&cmd_config_e_tag_filter,
13241                 (void *)&cmd_config_e_tag_del,
13242                 (void *)&cmd_config_e_tag_e_tag_id,
13243                 (void *)&cmd_config_e_tag_e_tag_id_val,
13244                 (void *)&cmd_config_e_tag_port,
13245                 (void *)&cmd_config_e_tag_port_id,
13246                 NULL,
13247         },
13248 };
13249
13250 /* vf vlan anti spoof configuration */
13251
13252 /* Common result structure for vf vlan anti spoof */
13253 struct cmd_vf_vlan_anti_spoof_result {
13254         cmdline_fixed_string_t set;
13255         cmdline_fixed_string_t vf;
13256         cmdline_fixed_string_t vlan;
13257         cmdline_fixed_string_t antispoof;
13258         portid_t port_id;
13259         uint32_t vf_id;
13260         cmdline_fixed_string_t on_off;
13261 };
13262
13263 /* Common CLI fields for vf vlan anti spoof enable disable */
13264 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13265         TOKEN_STRING_INITIALIZER
13266                 (struct cmd_vf_vlan_anti_spoof_result,
13267                  set, "set");
13268 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13269         TOKEN_STRING_INITIALIZER
13270                 (struct cmd_vf_vlan_anti_spoof_result,
13271                  vf, "vf");
13272 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13273         TOKEN_STRING_INITIALIZER
13274                 (struct cmd_vf_vlan_anti_spoof_result,
13275                  vlan, "vlan");
13276 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13277         TOKEN_STRING_INITIALIZER
13278                 (struct cmd_vf_vlan_anti_spoof_result,
13279                  antispoof, "antispoof");
13280 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13281         TOKEN_NUM_INITIALIZER
13282                 (struct cmd_vf_vlan_anti_spoof_result,
13283                  port_id, UINT16);
13284 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13285         TOKEN_NUM_INITIALIZER
13286                 (struct cmd_vf_vlan_anti_spoof_result,
13287                  vf_id, UINT32);
13288 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13289         TOKEN_STRING_INITIALIZER
13290                 (struct cmd_vf_vlan_anti_spoof_result,
13291                  on_off, "on#off");
13292
13293 static void
13294 cmd_set_vf_vlan_anti_spoof_parsed(
13295         void *parsed_result,
13296         __attribute__((unused)) struct cmdline *cl,
13297         __attribute__((unused)) void *data)
13298 {
13299         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13300         int ret = -ENOTSUP;
13301
13302         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13303
13304         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13305                 return;
13306
13307 #ifdef RTE_LIBRTE_IXGBE_PMD
13308         if (ret == -ENOTSUP)
13309                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13310                                 res->vf_id, is_on);
13311 #endif
13312 #ifdef RTE_LIBRTE_I40E_PMD
13313         if (ret == -ENOTSUP)
13314                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13315                                 res->vf_id, is_on);
13316 #endif
13317 #ifdef RTE_LIBRTE_BNXT_PMD
13318         if (ret == -ENOTSUP)
13319                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13320                                 res->vf_id, is_on);
13321 #endif
13322
13323         switch (ret) {
13324         case 0:
13325                 break;
13326         case -EINVAL:
13327                 printf("invalid vf_id %d\n", res->vf_id);
13328                 break;
13329         case -ENODEV:
13330                 printf("invalid port_id %d\n", res->port_id);
13331                 break;
13332         case -ENOTSUP:
13333                 printf("function not implemented\n");
13334                 break;
13335         default:
13336                 printf("programming error: (%s)\n", strerror(-ret));
13337         }
13338 }
13339
13340 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13341         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13342         .data = NULL,
13343         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13344         .tokens = {
13345                 (void *)&cmd_vf_vlan_anti_spoof_set,
13346                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13347                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13348                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13349                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13350                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13351                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13352                 NULL,
13353         },
13354 };
13355
13356 /* vf mac anti spoof configuration */
13357
13358 /* Common result structure for vf mac anti spoof */
13359 struct cmd_vf_mac_anti_spoof_result {
13360         cmdline_fixed_string_t set;
13361         cmdline_fixed_string_t vf;
13362         cmdline_fixed_string_t mac;
13363         cmdline_fixed_string_t antispoof;
13364         portid_t port_id;
13365         uint32_t vf_id;
13366         cmdline_fixed_string_t on_off;
13367 };
13368
13369 /* Common CLI fields for vf mac anti spoof enable disable */
13370 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13371         TOKEN_STRING_INITIALIZER
13372                 (struct cmd_vf_mac_anti_spoof_result,
13373                  set, "set");
13374 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13375         TOKEN_STRING_INITIALIZER
13376                 (struct cmd_vf_mac_anti_spoof_result,
13377                  vf, "vf");
13378 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13379         TOKEN_STRING_INITIALIZER
13380                 (struct cmd_vf_mac_anti_spoof_result,
13381                  mac, "mac");
13382 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13383         TOKEN_STRING_INITIALIZER
13384                 (struct cmd_vf_mac_anti_spoof_result,
13385                  antispoof, "antispoof");
13386 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13387         TOKEN_NUM_INITIALIZER
13388                 (struct cmd_vf_mac_anti_spoof_result,
13389                  port_id, UINT16);
13390 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13391         TOKEN_NUM_INITIALIZER
13392                 (struct cmd_vf_mac_anti_spoof_result,
13393                  vf_id, UINT32);
13394 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13395         TOKEN_STRING_INITIALIZER
13396                 (struct cmd_vf_mac_anti_spoof_result,
13397                  on_off, "on#off");
13398
13399 static void
13400 cmd_set_vf_mac_anti_spoof_parsed(
13401         void *parsed_result,
13402         __attribute__((unused)) struct cmdline *cl,
13403         __attribute__((unused)) void *data)
13404 {
13405         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13406         int ret = -ENOTSUP;
13407
13408         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13409
13410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13411                 return;
13412
13413 #ifdef RTE_LIBRTE_IXGBE_PMD
13414         if (ret == -ENOTSUP)
13415                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13416                         res->vf_id, is_on);
13417 #endif
13418 #ifdef RTE_LIBRTE_I40E_PMD
13419         if (ret == -ENOTSUP)
13420                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13421                         res->vf_id, is_on);
13422 #endif
13423 #ifdef RTE_LIBRTE_BNXT_PMD
13424         if (ret == -ENOTSUP)
13425                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13426                         res->vf_id, is_on);
13427 #endif
13428
13429         switch (ret) {
13430         case 0:
13431                 break;
13432         case -EINVAL:
13433                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13434                 break;
13435         case -ENODEV:
13436                 printf("invalid port_id %d\n", res->port_id);
13437                 break;
13438         case -ENOTSUP:
13439                 printf("function not implemented\n");
13440                 break;
13441         default:
13442                 printf("programming error: (%s)\n", strerror(-ret));
13443         }
13444 }
13445
13446 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13447         .f = cmd_set_vf_mac_anti_spoof_parsed,
13448         .data = NULL,
13449         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13450         .tokens = {
13451                 (void *)&cmd_vf_mac_anti_spoof_set,
13452                 (void *)&cmd_vf_mac_anti_spoof_vf,
13453                 (void *)&cmd_vf_mac_anti_spoof_mac,
13454                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13455                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13456                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13457                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13458                 NULL,
13459         },
13460 };
13461
13462 /* vf vlan strip queue configuration */
13463
13464 /* Common result structure for vf mac anti spoof */
13465 struct cmd_vf_vlan_stripq_result {
13466         cmdline_fixed_string_t set;
13467         cmdline_fixed_string_t vf;
13468         cmdline_fixed_string_t vlan;
13469         cmdline_fixed_string_t stripq;
13470         portid_t port_id;
13471         uint16_t vf_id;
13472         cmdline_fixed_string_t on_off;
13473 };
13474
13475 /* Common CLI fields for vf vlan strip enable disable */
13476 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13477         TOKEN_STRING_INITIALIZER
13478                 (struct cmd_vf_vlan_stripq_result,
13479                  set, "set");
13480 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13481         TOKEN_STRING_INITIALIZER
13482                 (struct cmd_vf_vlan_stripq_result,
13483                  vf, "vf");
13484 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13485         TOKEN_STRING_INITIALIZER
13486                 (struct cmd_vf_vlan_stripq_result,
13487                  vlan, "vlan");
13488 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13489         TOKEN_STRING_INITIALIZER
13490                 (struct cmd_vf_vlan_stripq_result,
13491                  stripq, "stripq");
13492 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13493         TOKEN_NUM_INITIALIZER
13494                 (struct cmd_vf_vlan_stripq_result,
13495                  port_id, UINT16);
13496 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13497         TOKEN_NUM_INITIALIZER
13498                 (struct cmd_vf_vlan_stripq_result,
13499                  vf_id, UINT16);
13500 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13501         TOKEN_STRING_INITIALIZER
13502                 (struct cmd_vf_vlan_stripq_result,
13503                  on_off, "on#off");
13504
13505 static void
13506 cmd_set_vf_vlan_stripq_parsed(
13507         void *parsed_result,
13508         __attribute__((unused)) struct cmdline *cl,
13509         __attribute__((unused)) void *data)
13510 {
13511         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13512         int ret = -ENOTSUP;
13513
13514         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13515
13516         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13517                 return;
13518
13519 #ifdef RTE_LIBRTE_IXGBE_PMD
13520         if (ret == -ENOTSUP)
13521                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13522                         res->vf_id, is_on);
13523 #endif
13524 #ifdef RTE_LIBRTE_I40E_PMD
13525         if (ret == -ENOTSUP)
13526                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13527                         res->vf_id, is_on);
13528 #endif
13529 #ifdef RTE_LIBRTE_BNXT_PMD
13530         if (ret == -ENOTSUP)
13531                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13532                         res->vf_id, is_on);
13533 #endif
13534
13535         switch (ret) {
13536         case 0:
13537                 break;
13538         case -EINVAL:
13539                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13540                 break;
13541         case -ENODEV:
13542                 printf("invalid port_id %d\n", res->port_id);
13543                 break;
13544         case -ENOTSUP:
13545                 printf("function not implemented\n");
13546                 break;
13547         default:
13548                 printf("programming error: (%s)\n", strerror(-ret));
13549         }
13550 }
13551
13552 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13553         .f = cmd_set_vf_vlan_stripq_parsed,
13554         .data = NULL,
13555         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13556         .tokens = {
13557                 (void *)&cmd_vf_vlan_stripq_set,
13558                 (void *)&cmd_vf_vlan_stripq_vf,
13559                 (void *)&cmd_vf_vlan_stripq_vlan,
13560                 (void *)&cmd_vf_vlan_stripq_stripq,
13561                 (void *)&cmd_vf_vlan_stripq_port_id,
13562                 (void *)&cmd_vf_vlan_stripq_vf_id,
13563                 (void *)&cmd_vf_vlan_stripq_on_off,
13564                 NULL,
13565         },
13566 };
13567
13568 /* vf vlan insert configuration */
13569
13570 /* Common result structure for vf vlan insert */
13571 struct cmd_vf_vlan_insert_result {
13572         cmdline_fixed_string_t set;
13573         cmdline_fixed_string_t vf;
13574         cmdline_fixed_string_t vlan;
13575         cmdline_fixed_string_t insert;
13576         portid_t port_id;
13577         uint16_t vf_id;
13578         uint16_t vlan_id;
13579 };
13580
13581 /* Common CLI fields for vf vlan insert enable disable */
13582 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_vf_vlan_insert_result,
13585                  set, "set");
13586 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13587         TOKEN_STRING_INITIALIZER
13588                 (struct cmd_vf_vlan_insert_result,
13589                  vf, "vf");
13590 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13591         TOKEN_STRING_INITIALIZER
13592                 (struct cmd_vf_vlan_insert_result,
13593                  vlan, "vlan");
13594 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13595         TOKEN_STRING_INITIALIZER
13596                 (struct cmd_vf_vlan_insert_result,
13597                  insert, "insert");
13598 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13599         TOKEN_NUM_INITIALIZER
13600                 (struct cmd_vf_vlan_insert_result,
13601                  port_id, UINT16);
13602 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13603         TOKEN_NUM_INITIALIZER
13604                 (struct cmd_vf_vlan_insert_result,
13605                  vf_id, UINT16);
13606 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13607         TOKEN_NUM_INITIALIZER
13608                 (struct cmd_vf_vlan_insert_result,
13609                  vlan_id, UINT16);
13610
13611 static void
13612 cmd_set_vf_vlan_insert_parsed(
13613         void *parsed_result,
13614         __attribute__((unused)) struct cmdline *cl,
13615         __attribute__((unused)) void *data)
13616 {
13617         struct cmd_vf_vlan_insert_result *res = parsed_result;
13618         int ret = -ENOTSUP;
13619
13620         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13621                 return;
13622
13623 #ifdef RTE_LIBRTE_IXGBE_PMD
13624         if (ret == -ENOTSUP)
13625                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13626                         res->vlan_id);
13627 #endif
13628 #ifdef RTE_LIBRTE_I40E_PMD
13629         if (ret == -ENOTSUP)
13630                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13631                         res->vlan_id);
13632 #endif
13633 #ifdef RTE_LIBRTE_BNXT_PMD
13634         if (ret == -ENOTSUP)
13635                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13636                         res->vlan_id);
13637 #endif
13638
13639         switch (ret) {
13640         case 0:
13641                 break;
13642         case -EINVAL:
13643                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13644                 break;
13645         case -ENODEV:
13646                 printf("invalid port_id %d\n", res->port_id);
13647                 break;
13648         case -ENOTSUP:
13649                 printf("function not implemented\n");
13650                 break;
13651         default:
13652                 printf("programming error: (%s)\n", strerror(-ret));
13653         }
13654 }
13655
13656 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13657         .f = cmd_set_vf_vlan_insert_parsed,
13658         .data = NULL,
13659         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13660         .tokens = {
13661                 (void *)&cmd_vf_vlan_insert_set,
13662                 (void *)&cmd_vf_vlan_insert_vf,
13663                 (void *)&cmd_vf_vlan_insert_vlan,
13664                 (void *)&cmd_vf_vlan_insert_insert,
13665                 (void *)&cmd_vf_vlan_insert_port_id,
13666                 (void *)&cmd_vf_vlan_insert_vf_id,
13667                 (void *)&cmd_vf_vlan_insert_vlan_id,
13668                 NULL,
13669         },
13670 };
13671
13672 /* tx loopback configuration */
13673
13674 /* Common result structure for tx loopback */
13675 struct cmd_tx_loopback_result {
13676         cmdline_fixed_string_t set;
13677         cmdline_fixed_string_t tx;
13678         cmdline_fixed_string_t loopback;
13679         portid_t port_id;
13680         cmdline_fixed_string_t on_off;
13681 };
13682
13683 /* Common CLI fields for tx loopback enable disable */
13684 cmdline_parse_token_string_t cmd_tx_loopback_set =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_tx_loopback_result,
13687                  set, "set");
13688 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13689         TOKEN_STRING_INITIALIZER
13690                 (struct cmd_tx_loopback_result,
13691                  tx, "tx");
13692 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13693         TOKEN_STRING_INITIALIZER
13694                 (struct cmd_tx_loopback_result,
13695                  loopback, "loopback");
13696 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13697         TOKEN_NUM_INITIALIZER
13698                 (struct cmd_tx_loopback_result,
13699                  port_id, UINT16);
13700 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13701         TOKEN_STRING_INITIALIZER
13702                 (struct cmd_tx_loopback_result,
13703                  on_off, "on#off");
13704
13705 static void
13706 cmd_set_tx_loopback_parsed(
13707         void *parsed_result,
13708         __attribute__((unused)) struct cmdline *cl,
13709         __attribute__((unused)) void *data)
13710 {
13711         struct cmd_tx_loopback_result *res = parsed_result;
13712         int ret = -ENOTSUP;
13713
13714         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13715
13716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13717                 return;
13718
13719 #ifdef RTE_LIBRTE_IXGBE_PMD
13720         if (ret == -ENOTSUP)
13721                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13722 #endif
13723 #ifdef RTE_LIBRTE_I40E_PMD
13724         if (ret == -ENOTSUP)
13725                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13726 #endif
13727 #ifdef RTE_LIBRTE_BNXT_PMD
13728         if (ret == -ENOTSUP)
13729                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13730 #endif
13731 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13732         if (ret == -ENOTSUP)
13733                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13734 #endif
13735
13736         switch (ret) {
13737         case 0:
13738                 break;
13739         case -EINVAL:
13740                 printf("invalid is_on %d\n", is_on);
13741                 break;
13742         case -ENODEV:
13743                 printf("invalid port_id %d\n", res->port_id);
13744                 break;
13745         case -ENOTSUP:
13746                 printf("function not implemented\n");
13747                 break;
13748         default:
13749                 printf("programming error: (%s)\n", strerror(-ret));
13750         }
13751 }
13752
13753 cmdline_parse_inst_t cmd_set_tx_loopback = {
13754         .f = cmd_set_tx_loopback_parsed,
13755         .data = NULL,
13756         .help_str = "set tx loopback <port_id> on|off",
13757         .tokens = {
13758                 (void *)&cmd_tx_loopback_set,
13759                 (void *)&cmd_tx_loopback_tx,
13760                 (void *)&cmd_tx_loopback_loopback,
13761                 (void *)&cmd_tx_loopback_port_id,
13762                 (void *)&cmd_tx_loopback_on_off,
13763                 NULL,
13764         },
13765 };
13766
13767 /* all queues drop enable configuration */
13768
13769 /* Common result structure for all queues drop enable */
13770 struct cmd_all_queues_drop_en_result {
13771         cmdline_fixed_string_t set;
13772         cmdline_fixed_string_t all;
13773         cmdline_fixed_string_t queues;
13774         cmdline_fixed_string_t drop;
13775         portid_t port_id;
13776         cmdline_fixed_string_t on_off;
13777 };
13778
13779 /* Common CLI fields for tx loopback enable disable */
13780 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13781         TOKEN_STRING_INITIALIZER
13782                 (struct cmd_all_queues_drop_en_result,
13783                  set, "set");
13784 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13785         TOKEN_STRING_INITIALIZER
13786                 (struct cmd_all_queues_drop_en_result,
13787                  all, "all");
13788 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13789         TOKEN_STRING_INITIALIZER
13790                 (struct cmd_all_queues_drop_en_result,
13791                  queues, "queues");
13792 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13793         TOKEN_STRING_INITIALIZER
13794                 (struct cmd_all_queues_drop_en_result,
13795                  drop, "drop");
13796 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13797         TOKEN_NUM_INITIALIZER
13798                 (struct cmd_all_queues_drop_en_result,
13799                  port_id, UINT16);
13800 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13801         TOKEN_STRING_INITIALIZER
13802                 (struct cmd_all_queues_drop_en_result,
13803                  on_off, "on#off");
13804
13805 static void
13806 cmd_set_all_queues_drop_en_parsed(
13807         void *parsed_result,
13808         __attribute__((unused)) struct cmdline *cl,
13809         __attribute__((unused)) void *data)
13810 {
13811         struct cmd_all_queues_drop_en_result *res = parsed_result;
13812         int ret = -ENOTSUP;
13813         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13814
13815         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13816                 return;
13817
13818 #ifdef RTE_LIBRTE_IXGBE_PMD
13819         if (ret == -ENOTSUP)
13820                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13821 #endif
13822 #ifdef RTE_LIBRTE_BNXT_PMD
13823         if (ret == -ENOTSUP)
13824                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13825 #endif
13826         switch (ret) {
13827         case 0:
13828                 break;
13829         case -EINVAL:
13830                 printf("invalid is_on %d\n", is_on);
13831                 break;
13832         case -ENODEV:
13833                 printf("invalid port_id %d\n", res->port_id);
13834                 break;
13835         case -ENOTSUP:
13836                 printf("function not implemented\n");
13837                 break;
13838         default:
13839                 printf("programming error: (%s)\n", strerror(-ret));
13840         }
13841 }
13842
13843 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13844         .f = cmd_set_all_queues_drop_en_parsed,
13845         .data = NULL,
13846         .help_str = "set all queues drop <port_id> on|off",
13847         .tokens = {
13848                 (void *)&cmd_all_queues_drop_en_set,
13849                 (void *)&cmd_all_queues_drop_en_all,
13850                 (void *)&cmd_all_queues_drop_en_queues,
13851                 (void *)&cmd_all_queues_drop_en_drop,
13852                 (void *)&cmd_all_queues_drop_en_port_id,
13853                 (void *)&cmd_all_queues_drop_en_on_off,
13854                 NULL,
13855         },
13856 };
13857
13858 /* vf split drop enable configuration */
13859
13860 /* Common result structure for vf split drop enable */
13861 struct cmd_vf_split_drop_en_result {
13862         cmdline_fixed_string_t set;
13863         cmdline_fixed_string_t vf;
13864         cmdline_fixed_string_t split;
13865         cmdline_fixed_string_t drop;
13866         portid_t port_id;
13867         uint16_t vf_id;
13868         cmdline_fixed_string_t on_off;
13869 };
13870
13871 /* Common CLI fields for vf split drop enable disable */
13872 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13873         TOKEN_STRING_INITIALIZER
13874                 (struct cmd_vf_split_drop_en_result,
13875                  set, "set");
13876 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13877         TOKEN_STRING_INITIALIZER
13878                 (struct cmd_vf_split_drop_en_result,
13879                  vf, "vf");
13880 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13881         TOKEN_STRING_INITIALIZER
13882                 (struct cmd_vf_split_drop_en_result,
13883                  split, "split");
13884 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13885         TOKEN_STRING_INITIALIZER
13886                 (struct cmd_vf_split_drop_en_result,
13887                  drop, "drop");
13888 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13889         TOKEN_NUM_INITIALIZER
13890                 (struct cmd_vf_split_drop_en_result,
13891                  port_id, UINT16);
13892 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13893         TOKEN_NUM_INITIALIZER
13894                 (struct cmd_vf_split_drop_en_result,
13895                  vf_id, UINT16);
13896 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13897         TOKEN_STRING_INITIALIZER
13898                 (struct cmd_vf_split_drop_en_result,
13899                  on_off, "on#off");
13900
13901 static void
13902 cmd_set_vf_split_drop_en_parsed(
13903         void *parsed_result,
13904         __attribute__((unused)) struct cmdline *cl,
13905         __attribute__((unused)) void *data)
13906 {
13907         struct cmd_vf_split_drop_en_result *res = parsed_result;
13908         int ret = -ENOTSUP;
13909         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13910
13911         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13912                 return;
13913
13914 #ifdef RTE_LIBRTE_IXGBE_PMD
13915         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13916                         is_on);
13917 #endif
13918         switch (ret) {
13919         case 0:
13920                 break;
13921         case -EINVAL:
13922                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13923                 break;
13924         case -ENODEV:
13925                 printf("invalid port_id %d\n", res->port_id);
13926                 break;
13927         case -ENOTSUP:
13928                 printf("not supported on port %d\n", res->port_id);
13929                 break;
13930         default:
13931                 printf("programming error: (%s)\n", strerror(-ret));
13932         }
13933 }
13934
13935 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13936         .f = cmd_set_vf_split_drop_en_parsed,
13937         .data = NULL,
13938         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13939         .tokens = {
13940                 (void *)&cmd_vf_split_drop_en_set,
13941                 (void *)&cmd_vf_split_drop_en_vf,
13942                 (void *)&cmd_vf_split_drop_en_split,
13943                 (void *)&cmd_vf_split_drop_en_drop,
13944                 (void *)&cmd_vf_split_drop_en_port_id,
13945                 (void *)&cmd_vf_split_drop_en_vf_id,
13946                 (void *)&cmd_vf_split_drop_en_on_off,
13947                 NULL,
13948         },
13949 };
13950
13951 /* vf mac address configuration */
13952
13953 /* Common result structure for vf mac address */
13954 struct cmd_set_vf_mac_addr_result {
13955         cmdline_fixed_string_t set;
13956         cmdline_fixed_string_t vf;
13957         cmdline_fixed_string_t mac;
13958         cmdline_fixed_string_t addr;
13959         portid_t port_id;
13960         uint16_t vf_id;
13961         struct rte_ether_addr mac_addr;
13962
13963 };
13964
13965 /* Common CLI fields for vf split drop enable disable */
13966 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13967         TOKEN_STRING_INITIALIZER
13968                 (struct cmd_set_vf_mac_addr_result,
13969                  set, "set");
13970 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13971         TOKEN_STRING_INITIALIZER
13972                 (struct cmd_set_vf_mac_addr_result,
13973                  vf, "vf");
13974 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13975         TOKEN_STRING_INITIALIZER
13976                 (struct cmd_set_vf_mac_addr_result,
13977                  mac, "mac");
13978 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13979         TOKEN_STRING_INITIALIZER
13980                 (struct cmd_set_vf_mac_addr_result,
13981                  addr, "addr");
13982 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13983         TOKEN_NUM_INITIALIZER
13984                 (struct cmd_set_vf_mac_addr_result,
13985                  port_id, UINT16);
13986 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13987         TOKEN_NUM_INITIALIZER
13988                 (struct cmd_set_vf_mac_addr_result,
13989                  vf_id, UINT16);
13990 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13991         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13992                  mac_addr);
13993
13994 static void
13995 cmd_set_vf_mac_addr_parsed(
13996         void *parsed_result,
13997         __attribute__((unused)) struct cmdline *cl,
13998         __attribute__((unused)) void *data)
13999 {
14000         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14001         int ret = -ENOTSUP;
14002
14003         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14004                 return;
14005
14006 #ifdef RTE_LIBRTE_IXGBE_PMD
14007         if (ret == -ENOTSUP)
14008                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14009                                 &res->mac_addr);
14010 #endif
14011 #ifdef RTE_LIBRTE_I40E_PMD
14012         if (ret == -ENOTSUP)
14013                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14014                                 &res->mac_addr);
14015 #endif
14016 #ifdef RTE_LIBRTE_BNXT_PMD
14017         if (ret == -ENOTSUP)
14018                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14019                                 &res->mac_addr);
14020 #endif
14021
14022         switch (ret) {
14023         case 0:
14024                 break;
14025         case -EINVAL:
14026                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14027                 break;
14028         case -ENODEV:
14029                 printf("invalid port_id %d\n", res->port_id);
14030                 break;
14031         case -ENOTSUP:
14032                 printf("function not implemented\n");
14033                 break;
14034         default:
14035                 printf("programming error: (%s)\n", strerror(-ret));
14036         }
14037 }
14038
14039 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14040         .f = cmd_set_vf_mac_addr_parsed,
14041         .data = NULL,
14042         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14043         .tokens = {
14044                 (void *)&cmd_set_vf_mac_addr_set,
14045                 (void *)&cmd_set_vf_mac_addr_vf,
14046                 (void *)&cmd_set_vf_mac_addr_mac,
14047                 (void *)&cmd_set_vf_mac_addr_addr,
14048                 (void *)&cmd_set_vf_mac_addr_port_id,
14049                 (void *)&cmd_set_vf_mac_addr_vf_id,
14050                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14051                 NULL,
14052         },
14053 };
14054
14055 /* MACsec configuration */
14056
14057 /* Common result structure for MACsec offload enable */
14058 struct cmd_macsec_offload_on_result {
14059         cmdline_fixed_string_t set;
14060         cmdline_fixed_string_t macsec;
14061         cmdline_fixed_string_t offload;
14062         portid_t port_id;
14063         cmdline_fixed_string_t on;
14064         cmdline_fixed_string_t encrypt;
14065         cmdline_fixed_string_t en_on_off;
14066         cmdline_fixed_string_t replay_protect;
14067         cmdline_fixed_string_t rp_on_off;
14068 };
14069
14070 /* Common CLI fields for MACsec offload disable */
14071 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14072         TOKEN_STRING_INITIALIZER
14073                 (struct cmd_macsec_offload_on_result,
14074                  set, "set");
14075 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14076         TOKEN_STRING_INITIALIZER
14077                 (struct cmd_macsec_offload_on_result,
14078                  macsec, "macsec");
14079 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14080         TOKEN_STRING_INITIALIZER
14081                 (struct cmd_macsec_offload_on_result,
14082                  offload, "offload");
14083 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14084         TOKEN_NUM_INITIALIZER
14085                 (struct cmd_macsec_offload_on_result,
14086                  port_id, UINT16);
14087 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14088         TOKEN_STRING_INITIALIZER
14089                 (struct cmd_macsec_offload_on_result,
14090                  on, "on");
14091 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14092         TOKEN_STRING_INITIALIZER
14093                 (struct cmd_macsec_offload_on_result,
14094                  encrypt, "encrypt");
14095 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14096         TOKEN_STRING_INITIALIZER
14097                 (struct cmd_macsec_offload_on_result,
14098                  en_on_off, "on#off");
14099 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14100         TOKEN_STRING_INITIALIZER
14101                 (struct cmd_macsec_offload_on_result,
14102                  replay_protect, "replay-protect");
14103 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14104         TOKEN_STRING_INITIALIZER
14105                 (struct cmd_macsec_offload_on_result,
14106                  rp_on_off, "on#off");
14107
14108 static void
14109 cmd_set_macsec_offload_on_parsed(
14110         void *parsed_result,
14111         __attribute__((unused)) struct cmdline *cl,
14112         __attribute__((unused)) void *data)
14113 {
14114         struct cmd_macsec_offload_on_result *res = parsed_result;
14115         int ret = -ENOTSUP;
14116         portid_t port_id = res->port_id;
14117         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14118         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14119         struct rte_eth_dev_info dev_info;
14120
14121         if (port_id_is_invalid(port_id, ENABLED_WARN))
14122                 return;
14123         if (!port_is_stopped(port_id)) {
14124                 printf("Please stop port %d first\n", port_id);
14125                 return;
14126         }
14127
14128         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14129         if (ret != 0)
14130                 return;
14131
14132         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14133 #ifdef RTE_LIBRTE_IXGBE_PMD
14134                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14135 #endif
14136         }
14137         RTE_SET_USED(en);
14138         RTE_SET_USED(rp);
14139
14140         switch (ret) {
14141         case 0:
14142                 ports[port_id].dev_conf.txmode.offloads |=
14143                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14144                 cmd_reconfig_device_queue(port_id, 1, 1);
14145                 break;
14146         case -ENODEV:
14147                 printf("invalid port_id %d\n", port_id);
14148                 break;
14149         case -ENOTSUP:
14150                 printf("not supported on port %d\n", port_id);
14151                 break;
14152         default:
14153                 printf("programming error: (%s)\n", strerror(-ret));
14154         }
14155 }
14156
14157 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14158         .f = cmd_set_macsec_offload_on_parsed,
14159         .data = NULL,
14160         .help_str = "set macsec offload <port_id> on "
14161                 "encrypt on|off replay-protect on|off",
14162         .tokens = {
14163                 (void *)&cmd_macsec_offload_on_set,
14164                 (void *)&cmd_macsec_offload_on_macsec,
14165                 (void *)&cmd_macsec_offload_on_offload,
14166                 (void *)&cmd_macsec_offload_on_port_id,
14167                 (void *)&cmd_macsec_offload_on_on,
14168                 (void *)&cmd_macsec_offload_on_encrypt,
14169                 (void *)&cmd_macsec_offload_on_en_on_off,
14170                 (void *)&cmd_macsec_offload_on_replay_protect,
14171                 (void *)&cmd_macsec_offload_on_rp_on_off,
14172                 NULL,
14173         },
14174 };
14175
14176 /* Common result structure for MACsec offload disable */
14177 struct cmd_macsec_offload_off_result {
14178         cmdline_fixed_string_t set;
14179         cmdline_fixed_string_t macsec;
14180         cmdline_fixed_string_t offload;
14181         portid_t port_id;
14182         cmdline_fixed_string_t off;
14183 };
14184
14185 /* Common CLI fields for MACsec offload disable */
14186 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14187         TOKEN_STRING_INITIALIZER
14188                 (struct cmd_macsec_offload_off_result,
14189                  set, "set");
14190 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14191         TOKEN_STRING_INITIALIZER
14192                 (struct cmd_macsec_offload_off_result,
14193                  macsec, "macsec");
14194 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14195         TOKEN_STRING_INITIALIZER
14196                 (struct cmd_macsec_offload_off_result,
14197                  offload, "offload");
14198 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14199         TOKEN_NUM_INITIALIZER
14200                 (struct cmd_macsec_offload_off_result,
14201                  port_id, UINT16);
14202 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14203         TOKEN_STRING_INITIALIZER
14204                 (struct cmd_macsec_offload_off_result,
14205                  off, "off");
14206
14207 static void
14208 cmd_set_macsec_offload_off_parsed(
14209         void *parsed_result,
14210         __attribute__((unused)) struct cmdline *cl,
14211         __attribute__((unused)) void *data)
14212 {
14213         struct cmd_macsec_offload_off_result *res = parsed_result;
14214         int ret = -ENOTSUP;
14215         struct rte_eth_dev_info dev_info;
14216         portid_t port_id = res->port_id;
14217
14218         if (port_id_is_invalid(port_id, ENABLED_WARN))
14219                 return;
14220         if (!port_is_stopped(port_id)) {
14221                 printf("Please stop port %d first\n", port_id);
14222                 return;
14223         }
14224
14225         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14226         if (ret != 0)
14227                 return;
14228
14229         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14230 #ifdef RTE_LIBRTE_IXGBE_PMD
14231                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14232 #endif
14233         }
14234         switch (ret) {
14235         case 0:
14236                 ports[port_id].dev_conf.txmode.offloads &=
14237                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14238                 cmd_reconfig_device_queue(port_id, 1, 1);
14239                 break;
14240         case -ENODEV:
14241                 printf("invalid port_id %d\n", port_id);
14242                 break;
14243         case -ENOTSUP:
14244                 printf("not supported on port %d\n", port_id);
14245                 break;
14246         default:
14247                 printf("programming error: (%s)\n", strerror(-ret));
14248         }
14249 }
14250
14251 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14252         .f = cmd_set_macsec_offload_off_parsed,
14253         .data = NULL,
14254         .help_str = "set macsec offload <port_id> off",
14255         .tokens = {
14256                 (void *)&cmd_macsec_offload_off_set,
14257                 (void *)&cmd_macsec_offload_off_macsec,
14258                 (void *)&cmd_macsec_offload_off_offload,
14259                 (void *)&cmd_macsec_offload_off_port_id,
14260                 (void *)&cmd_macsec_offload_off_off,
14261                 NULL,
14262         },
14263 };
14264
14265 /* Common result structure for MACsec secure connection configure */
14266 struct cmd_macsec_sc_result {
14267         cmdline_fixed_string_t set;
14268         cmdline_fixed_string_t macsec;
14269         cmdline_fixed_string_t sc;
14270         cmdline_fixed_string_t tx_rx;
14271         portid_t port_id;
14272         struct rte_ether_addr mac;
14273         uint16_t pi;
14274 };
14275
14276 /* Common CLI fields for MACsec secure connection configure */
14277 cmdline_parse_token_string_t cmd_macsec_sc_set =
14278         TOKEN_STRING_INITIALIZER
14279                 (struct cmd_macsec_sc_result,
14280                  set, "set");
14281 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14282         TOKEN_STRING_INITIALIZER
14283                 (struct cmd_macsec_sc_result,
14284                  macsec, "macsec");
14285 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14286         TOKEN_STRING_INITIALIZER
14287                 (struct cmd_macsec_sc_result,
14288                  sc, "sc");
14289 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14290         TOKEN_STRING_INITIALIZER
14291                 (struct cmd_macsec_sc_result,
14292                  tx_rx, "tx#rx");
14293 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14294         TOKEN_NUM_INITIALIZER
14295                 (struct cmd_macsec_sc_result,
14296                  port_id, UINT16);
14297 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14298         TOKEN_ETHERADDR_INITIALIZER
14299                 (struct cmd_macsec_sc_result,
14300                  mac);
14301 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14302         TOKEN_NUM_INITIALIZER
14303                 (struct cmd_macsec_sc_result,
14304                  pi, UINT16);
14305
14306 static void
14307 cmd_set_macsec_sc_parsed(
14308         void *parsed_result,
14309         __attribute__((unused)) struct cmdline *cl,
14310         __attribute__((unused)) void *data)
14311 {
14312         struct cmd_macsec_sc_result *res = parsed_result;
14313         int ret = -ENOTSUP;
14314         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14315
14316 #ifdef RTE_LIBRTE_IXGBE_PMD
14317         ret = is_tx ?
14318                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14319                                 res->mac.addr_bytes) :
14320                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14321                                 res->mac.addr_bytes, res->pi);
14322 #endif
14323         RTE_SET_USED(is_tx);
14324
14325         switch (ret) {
14326         case 0:
14327                 break;
14328         case -ENODEV:
14329                 printf("invalid port_id %d\n", res->port_id);
14330                 break;
14331         case -ENOTSUP:
14332                 printf("not supported on port %d\n", res->port_id);
14333                 break;
14334         default:
14335                 printf("programming error: (%s)\n", strerror(-ret));
14336         }
14337 }
14338
14339 cmdline_parse_inst_t cmd_set_macsec_sc = {
14340         .f = cmd_set_macsec_sc_parsed,
14341         .data = NULL,
14342         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14343         .tokens = {
14344                 (void *)&cmd_macsec_sc_set,
14345                 (void *)&cmd_macsec_sc_macsec,
14346                 (void *)&cmd_macsec_sc_sc,
14347                 (void *)&cmd_macsec_sc_tx_rx,
14348                 (void *)&cmd_macsec_sc_port_id,
14349                 (void *)&cmd_macsec_sc_mac,
14350                 (void *)&cmd_macsec_sc_pi,
14351                 NULL,
14352         },
14353 };
14354
14355 /* Common result structure for MACsec secure connection configure */
14356 struct cmd_macsec_sa_result {
14357         cmdline_fixed_string_t set;
14358         cmdline_fixed_string_t macsec;
14359         cmdline_fixed_string_t sa;
14360         cmdline_fixed_string_t tx_rx;
14361         portid_t port_id;
14362         uint8_t idx;
14363         uint8_t an;
14364         uint32_t pn;
14365         cmdline_fixed_string_t key;
14366 };
14367
14368 /* Common CLI fields for MACsec secure connection configure */
14369 cmdline_parse_token_string_t cmd_macsec_sa_set =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_macsec_sa_result,
14372                  set, "set");
14373 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14374         TOKEN_STRING_INITIALIZER
14375                 (struct cmd_macsec_sa_result,
14376                  macsec, "macsec");
14377 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14378         TOKEN_STRING_INITIALIZER
14379                 (struct cmd_macsec_sa_result,
14380                  sa, "sa");
14381 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14382         TOKEN_STRING_INITIALIZER
14383                 (struct cmd_macsec_sa_result,
14384                  tx_rx, "tx#rx");
14385 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14386         TOKEN_NUM_INITIALIZER
14387                 (struct cmd_macsec_sa_result,
14388                  port_id, UINT16);
14389 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14390         TOKEN_NUM_INITIALIZER
14391                 (struct cmd_macsec_sa_result,
14392                  idx, UINT8);
14393 cmdline_parse_token_num_t cmd_macsec_sa_an =
14394         TOKEN_NUM_INITIALIZER
14395                 (struct cmd_macsec_sa_result,
14396                  an, UINT8);
14397 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14398         TOKEN_NUM_INITIALIZER
14399                 (struct cmd_macsec_sa_result,
14400                  pn, UINT32);
14401 cmdline_parse_token_string_t cmd_macsec_sa_key =
14402         TOKEN_STRING_INITIALIZER
14403                 (struct cmd_macsec_sa_result,
14404                  key, NULL);
14405
14406 static void
14407 cmd_set_macsec_sa_parsed(
14408         void *parsed_result,
14409         __attribute__((unused)) struct cmdline *cl,
14410         __attribute__((unused)) void *data)
14411 {
14412         struct cmd_macsec_sa_result *res = parsed_result;
14413         int ret = -ENOTSUP;
14414         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14415         uint8_t key[16] = { 0 };
14416         uint8_t xdgt0;
14417         uint8_t xdgt1;
14418         int key_len;
14419         int i;
14420
14421         key_len = strlen(res->key) / 2;
14422         if (key_len > 16)
14423                 key_len = 16;
14424
14425         for (i = 0; i < key_len; i++) {
14426                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14427                 if (xdgt0 == 0xFF)
14428                         return;
14429                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14430                 if (xdgt1 == 0xFF)
14431                         return;
14432                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14433         }
14434
14435 #ifdef RTE_LIBRTE_IXGBE_PMD
14436         ret = is_tx ?
14437                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14438                         res->idx, res->an, res->pn, key) :
14439                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14440                         res->idx, res->an, res->pn, key);
14441 #endif
14442         RTE_SET_USED(is_tx);
14443         RTE_SET_USED(key);
14444
14445         switch (ret) {
14446         case 0:
14447                 break;
14448         case -EINVAL:
14449                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14450                 break;
14451         case -ENODEV:
14452                 printf("invalid port_id %d\n", res->port_id);
14453                 break;
14454         case -ENOTSUP:
14455                 printf("not supported on port %d\n", res->port_id);
14456                 break;
14457         default:
14458                 printf("programming error: (%s)\n", strerror(-ret));
14459         }
14460 }
14461
14462 cmdline_parse_inst_t cmd_set_macsec_sa = {
14463         .f = cmd_set_macsec_sa_parsed,
14464         .data = NULL,
14465         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14466         .tokens = {
14467                 (void *)&cmd_macsec_sa_set,
14468                 (void *)&cmd_macsec_sa_macsec,
14469                 (void *)&cmd_macsec_sa_sa,
14470                 (void *)&cmd_macsec_sa_tx_rx,
14471                 (void *)&cmd_macsec_sa_port_id,
14472                 (void *)&cmd_macsec_sa_idx,
14473                 (void *)&cmd_macsec_sa_an,
14474                 (void *)&cmd_macsec_sa_pn,
14475                 (void *)&cmd_macsec_sa_key,
14476                 NULL,
14477         },
14478 };
14479
14480 /* VF unicast promiscuous mode configuration */
14481
14482 /* Common result structure for VF unicast promiscuous mode */
14483 struct cmd_vf_promisc_result {
14484         cmdline_fixed_string_t set;
14485         cmdline_fixed_string_t vf;
14486         cmdline_fixed_string_t promisc;
14487         portid_t port_id;
14488         uint32_t vf_id;
14489         cmdline_fixed_string_t on_off;
14490 };
14491
14492 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14493 cmdline_parse_token_string_t cmd_vf_promisc_set =
14494         TOKEN_STRING_INITIALIZER
14495                 (struct cmd_vf_promisc_result,
14496                  set, "set");
14497 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14498         TOKEN_STRING_INITIALIZER
14499                 (struct cmd_vf_promisc_result,
14500                  vf, "vf");
14501 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14502         TOKEN_STRING_INITIALIZER
14503                 (struct cmd_vf_promisc_result,
14504                  promisc, "promisc");
14505 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14506         TOKEN_NUM_INITIALIZER
14507                 (struct cmd_vf_promisc_result,
14508                  port_id, UINT16);
14509 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14510         TOKEN_NUM_INITIALIZER
14511                 (struct cmd_vf_promisc_result,
14512                  vf_id, UINT32);
14513 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14514         TOKEN_STRING_INITIALIZER
14515                 (struct cmd_vf_promisc_result,
14516                  on_off, "on#off");
14517
14518 static void
14519 cmd_set_vf_promisc_parsed(
14520         void *parsed_result,
14521         __attribute__((unused)) struct cmdline *cl,
14522         __attribute__((unused)) void *data)
14523 {
14524         struct cmd_vf_promisc_result *res = parsed_result;
14525         int ret = -ENOTSUP;
14526
14527         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14528
14529         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14530                 return;
14531
14532 #ifdef RTE_LIBRTE_I40E_PMD
14533         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14534                                                   res->vf_id, is_on);
14535 #endif
14536
14537         switch (ret) {
14538         case 0:
14539                 break;
14540         case -EINVAL:
14541                 printf("invalid vf_id %d\n", res->vf_id);
14542                 break;
14543         case -ENODEV:
14544                 printf("invalid port_id %d\n", res->port_id);
14545                 break;
14546         case -ENOTSUP:
14547                 printf("function not implemented\n");
14548                 break;
14549         default:
14550                 printf("programming error: (%s)\n", strerror(-ret));
14551         }
14552 }
14553
14554 cmdline_parse_inst_t cmd_set_vf_promisc = {
14555         .f = cmd_set_vf_promisc_parsed,
14556         .data = NULL,
14557         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14558                 "Set unicast promiscuous mode for a VF from the PF",
14559         .tokens = {
14560                 (void *)&cmd_vf_promisc_set,
14561                 (void *)&cmd_vf_promisc_vf,
14562                 (void *)&cmd_vf_promisc_promisc,
14563                 (void *)&cmd_vf_promisc_port_id,
14564                 (void *)&cmd_vf_promisc_vf_id,
14565                 (void *)&cmd_vf_promisc_on_off,
14566                 NULL,
14567         },
14568 };
14569
14570 /* VF multicast promiscuous mode configuration */
14571
14572 /* Common result structure for VF multicast promiscuous mode */
14573 struct cmd_vf_allmulti_result {
14574         cmdline_fixed_string_t set;
14575         cmdline_fixed_string_t vf;
14576         cmdline_fixed_string_t allmulti;
14577         portid_t port_id;
14578         uint32_t vf_id;
14579         cmdline_fixed_string_t on_off;
14580 };
14581
14582 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14583 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14584         TOKEN_STRING_INITIALIZER
14585                 (struct cmd_vf_allmulti_result,
14586                  set, "set");
14587 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14588         TOKEN_STRING_INITIALIZER
14589                 (struct cmd_vf_allmulti_result,
14590                  vf, "vf");
14591 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14592         TOKEN_STRING_INITIALIZER
14593                 (struct cmd_vf_allmulti_result,
14594                  allmulti, "allmulti");
14595 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14596         TOKEN_NUM_INITIALIZER
14597                 (struct cmd_vf_allmulti_result,
14598                  port_id, UINT16);
14599 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14600         TOKEN_NUM_INITIALIZER
14601                 (struct cmd_vf_allmulti_result,
14602                  vf_id, UINT32);
14603 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14604         TOKEN_STRING_INITIALIZER
14605                 (struct cmd_vf_allmulti_result,
14606                  on_off, "on#off");
14607
14608 static void
14609 cmd_set_vf_allmulti_parsed(
14610         void *parsed_result,
14611         __attribute__((unused)) struct cmdline *cl,
14612         __attribute__((unused)) void *data)
14613 {
14614         struct cmd_vf_allmulti_result *res = parsed_result;
14615         int ret = -ENOTSUP;
14616
14617         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14618
14619         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14620                 return;
14621
14622 #ifdef RTE_LIBRTE_I40E_PMD
14623         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14624                                                     res->vf_id, is_on);
14625 #endif
14626
14627         switch (ret) {
14628         case 0:
14629                 break;
14630         case -EINVAL:
14631                 printf("invalid vf_id %d\n", res->vf_id);
14632                 break;
14633         case -ENODEV:
14634                 printf("invalid port_id %d\n", res->port_id);
14635                 break;
14636         case -ENOTSUP:
14637                 printf("function not implemented\n");
14638                 break;
14639         default:
14640                 printf("programming error: (%s)\n", strerror(-ret));
14641         }
14642 }
14643
14644 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14645         .f = cmd_set_vf_allmulti_parsed,
14646         .data = NULL,
14647         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14648                 "Set multicast promiscuous mode for a VF from the PF",
14649         .tokens = {
14650                 (void *)&cmd_vf_allmulti_set,
14651                 (void *)&cmd_vf_allmulti_vf,
14652                 (void *)&cmd_vf_allmulti_allmulti,
14653                 (void *)&cmd_vf_allmulti_port_id,
14654                 (void *)&cmd_vf_allmulti_vf_id,
14655                 (void *)&cmd_vf_allmulti_on_off,
14656                 NULL,
14657         },
14658 };
14659
14660 /* vf broadcast mode configuration */
14661
14662 /* Common result structure for vf broadcast */
14663 struct cmd_set_vf_broadcast_result {
14664         cmdline_fixed_string_t set;
14665         cmdline_fixed_string_t vf;
14666         cmdline_fixed_string_t broadcast;
14667         portid_t port_id;
14668         uint16_t vf_id;
14669         cmdline_fixed_string_t on_off;
14670 };
14671
14672 /* Common CLI fields for vf broadcast enable disable */
14673 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14674         TOKEN_STRING_INITIALIZER
14675                 (struct cmd_set_vf_broadcast_result,
14676                  set, "set");
14677 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14678         TOKEN_STRING_INITIALIZER
14679                 (struct cmd_set_vf_broadcast_result,
14680                  vf, "vf");
14681 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14682         TOKEN_STRING_INITIALIZER
14683                 (struct cmd_set_vf_broadcast_result,
14684                  broadcast, "broadcast");
14685 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14686         TOKEN_NUM_INITIALIZER
14687                 (struct cmd_set_vf_broadcast_result,
14688                  port_id, UINT16);
14689 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14690         TOKEN_NUM_INITIALIZER
14691                 (struct cmd_set_vf_broadcast_result,
14692                  vf_id, UINT16);
14693 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14694         TOKEN_STRING_INITIALIZER
14695                 (struct cmd_set_vf_broadcast_result,
14696                  on_off, "on#off");
14697
14698 static void
14699 cmd_set_vf_broadcast_parsed(
14700         void *parsed_result,
14701         __attribute__((unused)) struct cmdline *cl,
14702         __attribute__((unused)) void *data)
14703 {
14704         struct cmd_set_vf_broadcast_result *res = parsed_result;
14705         int ret = -ENOTSUP;
14706
14707         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14708
14709         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14710                 return;
14711
14712 #ifdef RTE_LIBRTE_I40E_PMD
14713         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14714                                             res->vf_id, is_on);
14715 #endif
14716
14717         switch (ret) {
14718         case 0:
14719                 break;
14720         case -EINVAL:
14721                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14722                 break;
14723         case -ENODEV:
14724                 printf("invalid port_id %d\n", res->port_id);
14725                 break;
14726         case -ENOTSUP:
14727                 printf("function not implemented\n");
14728                 break;
14729         default:
14730                 printf("programming error: (%s)\n", strerror(-ret));
14731         }
14732 }
14733
14734 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14735         .f = cmd_set_vf_broadcast_parsed,
14736         .data = NULL,
14737         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14738         .tokens = {
14739                 (void *)&cmd_set_vf_broadcast_set,
14740                 (void *)&cmd_set_vf_broadcast_vf,
14741                 (void *)&cmd_set_vf_broadcast_broadcast,
14742                 (void *)&cmd_set_vf_broadcast_port_id,
14743                 (void *)&cmd_set_vf_broadcast_vf_id,
14744                 (void *)&cmd_set_vf_broadcast_on_off,
14745                 NULL,
14746         },
14747 };
14748
14749 /* vf vlan tag configuration */
14750
14751 /* Common result structure for vf vlan tag */
14752 struct cmd_set_vf_vlan_tag_result {
14753         cmdline_fixed_string_t set;
14754         cmdline_fixed_string_t vf;
14755         cmdline_fixed_string_t vlan;
14756         cmdline_fixed_string_t tag;
14757         portid_t port_id;
14758         uint16_t vf_id;
14759         cmdline_fixed_string_t on_off;
14760 };
14761
14762 /* Common CLI fields for vf vlan tag enable disable */
14763 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14764         TOKEN_STRING_INITIALIZER
14765                 (struct cmd_set_vf_vlan_tag_result,
14766                  set, "set");
14767 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14768         TOKEN_STRING_INITIALIZER
14769                 (struct cmd_set_vf_vlan_tag_result,
14770                  vf, "vf");
14771 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14772         TOKEN_STRING_INITIALIZER
14773                 (struct cmd_set_vf_vlan_tag_result,
14774                  vlan, "vlan");
14775 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14776         TOKEN_STRING_INITIALIZER
14777                 (struct cmd_set_vf_vlan_tag_result,
14778                  tag, "tag");
14779 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14780         TOKEN_NUM_INITIALIZER
14781                 (struct cmd_set_vf_vlan_tag_result,
14782                  port_id, UINT16);
14783 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14784         TOKEN_NUM_INITIALIZER
14785                 (struct cmd_set_vf_vlan_tag_result,
14786                  vf_id, UINT16);
14787 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14788         TOKEN_STRING_INITIALIZER
14789                 (struct cmd_set_vf_vlan_tag_result,
14790                  on_off, "on#off");
14791
14792 static void
14793 cmd_set_vf_vlan_tag_parsed(
14794         void *parsed_result,
14795         __attribute__((unused)) struct cmdline *cl,
14796         __attribute__((unused)) void *data)
14797 {
14798         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14799         int ret = -ENOTSUP;
14800
14801         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14802
14803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14804                 return;
14805
14806 #ifdef RTE_LIBRTE_I40E_PMD
14807         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14808                                            res->vf_id, is_on);
14809 #endif
14810
14811         switch (ret) {
14812         case 0:
14813                 break;
14814         case -EINVAL:
14815                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14816                 break;
14817         case -ENODEV:
14818                 printf("invalid port_id %d\n", res->port_id);
14819                 break;
14820         case -ENOTSUP:
14821                 printf("function not implemented\n");
14822                 break;
14823         default:
14824                 printf("programming error: (%s)\n", strerror(-ret));
14825         }
14826 }
14827
14828 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14829         .f = cmd_set_vf_vlan_tag_parsed,
14830         .data = NULL,
14831         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14832         .tokens = {
14833                 (void *)&cmd_set_vf_vlan_tag_set,
14834                 (void *)&cmd_set_vf_vlan_tag_vf,
14835                 (void *)&cmd_set_vf_vlan_tag_vlan,
14836                 (void *)&cmd_set_vf_vlan_tag_tag,
14837                 (void *)&cmd_set_vf_vlan_tag_port_id,
14838                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14839                 (void *)&cmd_set_vf_vlan_tag_on_off,
14840                 NULL,
14841         },
14842 };
14843
14844 /* Common definition of VF and TC TX bandwidth configuration */
14845 struct cmd_vf_tc_bw_result {
14846         cmdline_fixed_string_t set;
14847         cmdline_fixed_string_t vf;
14848         cmdline_fixed_string_t tc;
14849         cmdline_fixed_string_t tx;
14850         cmdline_fixed_string_t min_bw;
14851         cmdline_fixed_string_t max_bw;
14852         cmdline_fixed_string_t strict_link_prio;
14853         portid_t port_id;
14854         uint16_t vf_id;
14855         uint8_t tc_no;
14856         uint32_t bw;
14857         cmdline_fixed_string_t bw_list;
14858         uint8_t tc_map;
14859 };
14860
14861 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14862         TOKEN_STRING_INITIALIZER
14863                 (struct cmd_vf_tc_bw_result,
14864                  set, "set");
14865 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14866         TOKEN_STRING_INITIALIZER
14867                 (struct cmd_vf_tc_bw_result,
14868                  vf, "vf");
14869 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14870         TOKEN_STRING_INITIALIZER
14871                 (struct cmd_vf_tc_bw_result,
14872                  tc, "tc");
14873 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14874         TOKEN_STRING_INITIALIZER
14875                 (struct cmd_vf_tc_bw_result,
14876                  tx, "tx");
14877 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14878         TOKEN_STRING_INITIALIZER
14879                 (struct cmd_vf_tc_bw_result,
14880                  strict_link_prio, "strict-link-priority");
14881 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14882         TOKEN_STRING_INITIALIZER
14883                 (struct cmd_vf_tc_bw_result,
14884                  min_bw, "min-bandwidth");
14885 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14886         TOKEN_STRING_INITIALIZER
14887                 (struct cmd_vf_tc_bw_result,
14888                  max_bw, "max-bandwidth");
14889 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14890         TOKEN_NUM_INITIALIZER
14891                 (struct cmd_vf_tc_bw_result,
14892                  port_id, UINT16);
14893 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14894         TOKEN_NUM_INITIALIZER
14895                 (struct cmd_vf_tc_bw_result,
14896                  vf_id, UINT16);
14897 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14898         TOKEN_NUM_INITIALIZER
14899                 (struct cmd_vf_tc_bw_result,
14900                  tc_no, UINT8);
14901 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14902         TOKEN_NUM_INITIALIZER
14903                 (struct cmd_vf_tc_bw_result,
14904                  bw, UINT32);
14905 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14906         TOKEN_STRING_INITIALIZER
14907                 (struct cmd_vf_tc_bw_result,
14908                  bw_list, NULL);
14909 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14910         TOKEN_NUM_INITIALIZER
14911                 (struct cmd_vf_tc_bw_result,
14912                  tc_map, UINT8);
14913
14914 /* VF max bandwidth setting */
14915 static void
14916 cmd_vf_max_bw_parsed(
14917         void *parsed_result,
14918         __attribute__((unused)) struct cmdline *cl,
14919         __attribute__((unused)) void *data)
14920 {
14921         struct cmd_vf_tc_bw_result *res = parsed_result;
14922         int ret = -ENOTSUP;
14923
14924         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14925                 return;
14926
14927 #ifdef RTE_LIBRTE_I40E_PMD
14928         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14929                                          res->vf_id, res->bw);
14930 #endif
14931
14932         switch (ret) {
14933         case 0:
14934                 break;
14935         case -EINVAL:
14936                 printf("invalid vf_id %d or bandwidth %d\n",
14937                        res->vf_id, res->bw);
14938                 break;
14939         case -ENODEV:
14940                 printf("invalid port_id %d\n", res->port_id);
14941                 break;
14942         case -ENOTSUP:
14943                 printf("function not implemented\n");
14944                 break;
14945         default:
14946                 printf("programming error: (%s)\n", strerror(-ret));
14947         }
14948 }
14949
14950 cmdline_parse_inst_t cmd_vf_max_bw = {
14951         .f = cmd_vf_max_bw_parsed,
14952         .data = NULL,
14953         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14954         .tokens = {
14955                 (void *)&cmd_vf_tc_bw_set,
14956                 (void *)&cmd_vf_tc_bw_vf,
14957                 (void *)&cmd_vf_tc_bw_tx,
14958                 (void *)&cmd_vf_tc_bw_max_bw,
14959                 (void *)&cmd_vf_tc_bw_port_id,
14960                 (void *)&cmd_vf_tc_bw_vf_id,
14961                 (void *)&cmd_vf_tc_bw_bw,
14962                 NULL,
14963         },
14964 };
14965
14966 static int
14967 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14968                            uint8_t *tc_num,
14969                            char *str)
14970 {
14971         uint32_t size;
14972         const char *p, *p0 = str;
14973         char s[256];
14974         char *end;
14975         char *str_fld[16];
14976         uint16_t i;
14977         int ret;
14978
14979         p = strchr(p0, '(');
14980         if (p == NULL) {
14981                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14982                 return -1;
14983         }
14984         p++;
14985         p0 = strchr(p, ')');
14986         if (p0 == NULL) {
14987                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14988                 return -1;
14989         }
14990         size = p0 - p;
14991         if (size >= sizeof(s)) {
14992                 printf("The string size exceeds the internal buffer size\n");
14993                 return -1;
14994         }
14995         snprintf(s, sizeof(s), "%.*s", size, p);
14996         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14997         if (ret <= 0) {
14998                 printf("Failed to get the bandwidth list. ");
14999                 return -1;
15000         }
15001         *tc_num = ret;
15002         for (i = 0; i < ret; i++)
15003                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15004
15005         return 0;
15006 }
15007
15008 /* TC min bandwidth setting */
15009 static void
15010 cmd_vf_tc_min_bw_parsed(
15011         void *parsed_result,
15012         __attribute__((unused)) struct cmdline *cl,
15013         __attribute__((unused)) void *data)
15014 {
15015         struct cmd_vf_tc_bw_result *res = parsed_result;
15016         uint8_t tc_num;
15017         uint8_t bw[16];
15018         int ret = -ENOTSUP;
15019
15020         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15021                 return;
15022
15023         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15024         if (ret)
15025                 return;
15026
15027 #ifdef RTE_LIBRTE_I40E_PMD
15028         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15029                                               tc_num, bw);
15030 #endif
15031
15032         switch (ret) {
15033         case 0:
15034                 break;
15035         case -EINVAL:
15036                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15037                 break;
15038         case -ENODEV:
15039                 printf("invalid port_id %d\n", res->port_id);
15040                 break;
15041         case -ENOTSUP:
15042                 printf("function not implemented\n");
15043                 break;
15044         default:
15045                 printf("programming error: (%s)\n", strerror(-ret));
15046         }
15047 }
15048
15049 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15050         .f = cmd_vf_tc_min_bw_parsed,
15051         .data = NULL,
15052         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15053                     " <bw1, bw2, ...>",
15054         .tokens = {
15055                 (void *)&cmd_vf_tc_bw_set,
15056                 (void *)&cmd_vf_tc_bw_vf,
15057                 (void *)&cmd_vf_tc_bw_tc,
15058                 (void *)&cmd_vf_tc_bw_tx,
15059                 (void *)&cmd_vf_tc_bw_min_bw,
15060                 (void *)&cmd_vf_tc_bw_port_id,
15061                 (void *)&cmd_vf_tc_bw_vf_id,
15062                 (void *)&cmd_vf_tc_bw_bw_list,
15063                 NULL,
15064         },
15065 };
15066
15067 static void
15068 cmd_tc_min_bw_parsed(
15069         void *parsed_result,
15070         __attribute__((unused)) struct cmdline *cl,
15071         __attribute__((unused)) void *data)
15072 {
15073         struct cmd_vf_tc_bw_result *res = parsed_result;
15074         struct rte_port *port;
15075         uint8_t tc_num;
15076         uint8_t bw[16];
15077         int ret = -ENOTSUP;
15078
15079         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15080                 return;
15081
15082         port = &ports[res->port_id];
15083         /** Check if the port is not started **/
15084         if (port->port_status != RTE_PORT_STOPPED) {
15085                 printf("Please stop port %d first\n", res->port_id);
15086                 return;
15087         }
15088
15089         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15090         if (ret)
15091                 return;
15092
15093 #ifdef RTE_LIBRTE_IXGBE_PMD
15094         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15095 #endif
15096
15097         switch (ret) {
15098         case 0:
15099                 break;
15100         case -EINVAL:
15101                 printf("invalid bandwidth\n");
15102                 break;
15103         case -ENODEV:
15104                 printf("invalid port_id %d\n", res->port_id);
15105                 break;
15106         case -ENOTSUP:
15107                 printf("function not implemented\n");
15108                 break;
15109         default:
15110                 printf("programming error: (%s)\n", strerror(-ret));
15111         }
15112 }
15113
15114 cmdline_parse_inst_t cmd_tc_min_bw = {
15115         .f = cmd_tc_min_bw_parsed,
15116         .data = NULL,
15117         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15118         .tokens = {
15119                 (void *)&cmd_vf_tc_bw_set,
15120                 (void *)&cmd_vf_tc_bw_tc,
15121                 (void *)&cmd_vf_tc_bw_tx,
15122                 (void *)&cmd_vf_tc_bw_min_bw,
15123                 (void *)&cmd_vf_tc_bw_port_id,
15124                 (void *)&cmd_vf_tc_bw_bw_list,
15125                 NULL,
15126         },
15127 };
15128
15129 /* TC max bandwidth setting */
15130 static void
15131 cmd_vf_tc_max_bw_parsed(
15132         void *parsed_result,
15133         __attribute__((unused)) struct cmdline *cl,
15134         __attribute__((unused)) void *data)
15135 {
15136         struct cmd_vf_tc_bw_result *res = parsed_result;
15137         int ret = -ENOTSUP;
15138
15139         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15140                 return;
15141
15142 #ifdef RTE_LIBRTE_I40E_PMD
15143         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15144                                             res->tc_no, res->bw);
15145 #endif
15146
15147         switch (ret) {
15148         case 0:
15149                 break;
15150         case -EINVAL:
15151                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15152                        res->vf_id, res->tc_no, res->bw);
15153                 break;
15154         case -ENODEV:
15155                 printf("invalid port_id %d\n", res->port_id);
15156                 break;
15157         case -ENOTSUP:
15158                 printf("function not implemented\n");
15159                 break;
15160         default:
15161                 printf("programming error: (%s)\n", strerror(-ret));
15162         }
15163 }
15164
15165 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15166         .f = cmd_vf_tc_max_bw_parsed,
15167         .data = NULL,
15168         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15169                     " <bandwidth>",
15170         .tokens = {
15171                 (void *)&cmd_vf_tc_bw_set,
15172                 (void *)&cmd_vf_tc_bw_vf,
15173                 (void *)&cmd_vf_tc_bw_tc,
15174                 (void *)&cmd_vf_tc_bw_tx,
15175                 (void *)&cmd_vf_tc_bw_max_bw,
15176                 (void *)&cmd_vf_tc_bw_port_id,
15177                 (void *)&cmd_vf_tc_bw_vf_id,
15178                 (void *)&cmd_vf_tc_bw_tc_no,
15179                 (void *)&cmd_vf_tc_bw_bw,
15180                 NULL,
15181         },
15182 };
15183
15184
15185 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15186
15187 /* *** Set Port default Traffic Management Hierarchy *** */
15188 struct cmd_set_port_tm_hierarchy_default_result {
15189         cmdline_fixed_string_t set;
15190         cmdline_fixed_string_t port;
15191         cmdline_fixed_string_t tm;
15192         cmdline_fixed_string_t hierarchy;
15193         cmdline_fixed_string_t def;
15194         portid_t port_id;
15195 };
15196
15197 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15198         TOKEN_STRING_INITIALIZER(
15199                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15200 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15201         TOKEN_STRING_INITIALIZER(
15202                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15203 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15204         TOKEN_STRING_INITIALIZER(
15205                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15206 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15207         TOKEN_STRING_INITIALIZER(
15208                 struct cmd_set_port_tm_hierarchy_default_result,
15209                         hierarchy, "hierarchy");
15210 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15211         TOKEN_STRING_INITIALIZER(
15212                 struct cmd_set_port_tm_hierarchy_default_result,
15213                         def, "default");
15214 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15215         TOKEN_NUM_INITIALIZER(
15216                 struct cmd_set_port_tm_hierarchy_default_result,
15217                         port_id, UINT16);
15218
15219 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15220         __attribute__((unused)) struct cmdline *cl,
15221         __attribute__((unused)) void *data)
15222 {
15223         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15224         struct rte_port *p;
15225         portid_t port_id = res->port_id;
15226
15227         if (port_id_is_invalid(port_id, ENABLED_WARN))
15228                 return;
15229
15230         p = &ports[port_id];
15231
15232         /* Forward mode: tm */
15233         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15234                 printf("  softnicfwd mode not enabled(error)\n");
15235                 return;
15236         }
15237
15238         /* Set the default tm hierarchy */
15239         p->softport.default_tm_hierarchy_enable = 1;
15240 }
15241
15242 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15243         .f = cmd_set_port_tm_hierarchy_default_parsed,
15244         .data = NULL,
15245         .help_str = "set port tm hierarchy default <port_id>",
15246         .tokens = {
15247                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15248                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15249                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15250                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15251                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15252                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15253                 NULL,
15254         },
15255 };
15256 #endif
15257
15258 /** Set VXLAN encapsulation details */
15259 struct cmd_set_vxlan_result {
15260         cmdline_fixed_string_t set;
15261         cmdline_fixed_string_t vxlan;
15262         cmdline_fixed_string_t pos_token;
15263         cmdline_fixed_string_t ip_version;
15264         uint32_t vlan_present:1;
15265         uint32_t vni;
15266         uint16_t udp_src;
15267         uint16_t udp_dst;
15268         cmdline_ipaddr_t ip_src;
15269         cmdline_ipaddr_t ip_dst;
15270         uint16_t tci;
15271         uint8_t tos;
15272         uint8_t ttl;
15273         struct rte_ether_addr eth_src;
15274         struct rte_ether_addr eth_dst;
15275 };
15276
15277 cmdline_parse_token_string_t cmd_set_vxlan_set =
15278         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15279 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15280         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15281 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15282         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15283                                  "vxlan-tos-ttl");
15284 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15285         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15286                                  "vxlan-with-vlan");
15287 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15288         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15289                                  "ip-version");
15290 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15291         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15292                                  "ipv4#ipv6");
15293 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15294         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15295                                  "vni");
15296 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15297         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15298 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15299         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15300                                  "udp-src");
15301 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15302         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15303 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15304         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15305                                  "udp-dst");
15306 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15307         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15308 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15309         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15310                                  "ip-tos");
15311 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15312         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15313 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15314         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15315                                  "ip-ttl");
15316 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15317         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15318 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15319         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15320                                  "ip-src");
15321 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15322         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15323 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15324         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15325                                  "ip-dst");
15326 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15327         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15328 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15329         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15330                                  "vlan-tci");
15331 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15332         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15333 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15334         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15335                                  "eth-src");
15336 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15337         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15338 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15339         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15340                                  "eth-dst");
15341 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15342         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15343
15344 static void cmd_set_vxlan_parsed(void *parsed_result,
15345         __attribute__((unused)) struct cmdline *cl,
15346         __attribute__((unused)) void *data)
15347 {
15348         struct cmd_set_vxlan_result *res = parsed_result;
15349         union {
15350                 uint32_t vxlan_id;
15351                 uint8_t vni[4];
15352         } id = {
15353                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15354         };
15355
15356         vxlan_encap_conf.select_tos_ttl = 0;
15357         if (strcmp(res->vxlan, "vxlan") == 0)
15358                 vxlan_encap_conf.select_vlan = 0;
15359         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15360                 vxlan_encap_conf.select_vlan = 1;
15361         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15362                 vxlan_encap_conf.select_vlan = 0;
15363                 vxlan_encap_conf.select_tos_ttl = 1;
15364         }
15365         if (strcmp(res->ip_version, "ipv4") == 0)
15366                 vxlan_encap_conf.select_ipv4 = 1;
15367         else if (strcmp(res->ip_version, "ipv6") == 0)
15368                 vxlan_encap_conf.select_ipv4 = 0;
15369         else
15370                 return;
15371         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15372         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15373         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15374         vxlan_encap_conf.ip_tos = res->tos;
15375         vxlan_encap_conf.ip_ttl = res->ttl;
15376         if (vxlan_encap_conf.select_ipv4) {
15377                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15378                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15379         } else {
15380                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15381                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15382         }
15383         if (vxlan_encap_conf.select_vlan)
15384                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15385         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15386                    RTE_ETHER_ADDR_LEN);
15387         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15388                    RTE_ETHER_ADDR_LEN);
15389 }
15390
15391 cmdline_parse_inst_t cmd_set_vxlan = {
15392         .f = cmd_set_vxlan_parsed,
15393         .data = NULL,
15394         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15395                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15396                 " eth-src <eth-src> eth-dst <eth-dst>",
15397         .tokens = {
15398                 (void *)&cmd_set_vxlan_set,
15399                 (void *)&cmd_set_vxlan_vxlan,
15400                 (void *)&cmd_set_vxlan_ip_version,
15401                 (void *)&cmd_set_vxlan_ip_version_value,
15402                 (void *)&cmd_set_vxlan_vni,
15403                 (void *)&cmd_set_vxlan_vni_value,
15404                 (void *)&cmd_set_vxlan_udp_src,
15405                 (void *)&cmd_set_vxlan_udp_src_value,
15406                 (void *)&cmd_set_vxlan_udp_dst,
15407                 (void *)&cmd_set_vxlan_udp_dst_value,
15408                 (void *)&cmd_set_vxlan_ip_src,
15409                 (void *)&cmd_set_vxlan_ip_src_value,
15410                 (void *)&cmd_set_vxlan_ip_dst,
15411                 (void *)&cmd_set_vxlan_ip_dst_value,
15412                 (void *)&cmd_set_vxlan_eth_src,
15413                 (void *)&cmd_set_vxlan_eth_src_value,
15414                 (void *)&cmd_set_vxlan_eth_dst,
15415                 (void *)&cmd_set_vxlan_eth_dst_value,
15416                 NULL,
15417         },
15418 };
15419
15420 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15421         .f = cmd_set_vxlan_parsed,
15422         .data = NULL,
15423         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15424                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15425                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15426                 " eth-dst <eth-dst>",
15427         .tokens = {
15428                 (void *)&cmd_set_vxlan_set,
15429                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15430                 (void *)&cmd_set_vxlan_ip_version,
15431                 (void *)&cmd_set_vxlan_ip_version_value,
15432                 (void *)&cmd_set_vxlan_vni,
15433                 (void *)&cmd_set_vxlan_vni_value,
15434                 (void *)&cmd_set_vxlan_udp_src,
15435                 (void *)&cmd_set_vxlan_udp_src_value,
15436                 (void *)&cmd_set_vxlan_udp_dst,
15437                 (void *)&cmd_set_vxlan_udp_dst_value,
15438                 (void *)&cmd_set_vxlan_ip_tos,
15439                 (void *)&cmd_set_vxlan_ip_tos_value,
15440                 (void *)&cmd_set_vxlan_ip_ttl,
15441                 (void *)&cmd_set_vxlan_ip_ttl_value,
15442                 (void *)&cmd_set_vxlan_ip_src,
15443                 (void *)&cmd_set_vxlan_ip_src_value,
15444                 (void *)&cmd_set_vxlan_ip_dst,
15445                 (void *)&cmd_set_vxlan_ip_dst_value,
15446                 (void *)&cmd_set_vxlan_eth_src,
15447                 (void *)&cmd_set_vxlan_eth_src_value,
15448                 (void *)&cmd_set_vxlan_eth_dst,
15449                 (void *)&cmd_set_vxlan_eth_dst_value,
15450                 NULL,
15451         },
15452 };
15453
15454 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15455         .f = cmd_set_vxlan_parsed,
15456         .data = NULL,
15457         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15458                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15459                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15460                 " <eth-dst>",
15461         .tokens = {
15462                 (void *)&cmd_set_vxlan_set,
15463                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15464                 (void *)&cmd_set_vxlan_ip_version,
15465                 (void *)&cmd_set_vxlan_ip_version_value,
15466                 (void *)&cmd_set_vxlan_vni,
15467                 (void *)&cmd_set_vxlan_vni_value,
15468                 (void *)&cmd_set_vxlan_udp_src,
15469                 (void *)&cmd_set_vxlan_udp_src_value,
15470                 (void *)&cmd_set_vxlan_udp_dst,
15471                 (void *)&cmd_set_vxlan_udp_dst_value,
15472                 (void *)&cmd_set_vxlan_ip_src,
15473                 (void *)&cmd_set_vxlan_ip_src_value,
15474                 (void *)&cmd_set_vxlan_ip_dst,
15475                 (void *)&cmd_set_vxlan_ip_dst_value,
15476                 (void *)&cmd_set_vxlan_vlan,
15477                 (void *)&cmd_set_vxlan_vlan_value,
15478                 (void *)&cmd_set_vxlan_eth_src,
15479                 (void *)&cmd_set_vxlan_eth_src_value,
15480                 (void *)&cmd_set_vxlan_eth_dst,
15481                 (void *)&cmd_set_vxlan_eth_dst_value,
15482                 NULL,
15483         },
15484 };
15485
15486 /** Set NVGRE encapsulation details */
15487 struct cmd_set_nvgre_result {
15488         cmdline_fixed_string_t set;
15489         cmdline_fixed_string_t nvgre;
15490         cmdline_fixed_string_t pos_token;
15491         cmdline_fixed_string_t ip_version;
15492         uint32_t tni;
15493         cmdline_ipaddr_t ip_src;
15494         cmdline_ipaddr_t ip_dst;
15495         uint16_t tci;
15496         struct rte_ether_addr eth_src;
15497         struct rte_ether_addr eth_dst;
15498 };
15499
15500 cmdline_parse_token_string_t cmd_set_nvgre_set =
15501         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15502 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15503         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15504 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15505         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15506                                  "nvgre-with-vlan");
15507 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15508         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15509                                  "ip-version");
15510 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15511         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15512                                  "ipv4#ipv6");
15513 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15514         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15515                                  "tni");
15516 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15517         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15518 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15519         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15520                                  "ip-src");
15521 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15522         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15523 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15524         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15525                                  "ip-dst");
15526 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15527         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15528 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15529         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15530                                  "vlan-tci");
15531 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15532         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15533 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15534         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15535                                  "eth-src");
15536 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15537         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15538 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15539         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15540                                  "eth-dst");
15541 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15542         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15543
15544 static void cmd_set_nvgre_parsed(void *parsed_result,
15545         __attribute__((unused)) struct cmdline *cl,
15546         __attribute__((unused)) void *data)
15547 {
15548         struct cmd_set_nvgre_result *res = parsed_result;
15549         union {
15550                 uint32_t nvgre_tni;
15551                 uint8_t tni[4];
15552         } id = {
15553                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15554         };
15555
15556         if (strcmp(res->nvgre, "nvgre") == 0)
15557                 nvgre_encap_conf.select_vlan = 0;
15558         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15559                 nvgre_encap_conf.select_vlan = 1;
15560         if (strcmp(res->ip_version, "ipv4") == 0)
15561                 nvgre_encap_conf.select_ipv4 = 1;
15562         else if (strcmp(res->ip_version, "ipv6") == 0)
15563                 nvgre_encap_conf.select_ipv4 = 0;
15564         else
15565                 return;
15566         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15567         if (nvgre_encap_conf.select_ipv4) {
15568                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15569                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15570         } else {
15571                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15572                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15573         }
15574         if (nvgre_encap_conf.select_vlan)
15575                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15576         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15577                    RTE_ETHER_ADDR_LEN);
15578         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15579                    RTE_ETHER_ADDR_LEN);
15580 }
15581
15582 cmdline_parse_inst_t cmd_set_nvgre = {
15583         .f = cmd_set_nvgre_parsed,
15584         .data = NULL,
15585         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15586                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15587                 " eth-dst <eth-dst>",
15588         .tokens = {
15589                 (void *)&cmd_set_nvgre_set,
15590                 (void *)&cmd_set_nvgre_nvgre,
15591                 (void *)&cmd_set_nvgre_ip_version,
15592                 (void *)&cmd_set_nvgre_ip_version_value,
15593                 (void *)&cmd_set_nvgre_tni,
15594                 (void *)&cmd_set_nvgre_tni_value,
15595                 (void *)&cmd_set_nvgre_ip_src,
15596                 (void *)&cmd_set_nvgre_ip_src_value,
15597                 (void *)&cmd_set_nvgre_ip_dst,
15598                 (void *)&cmd_set_nvgre_ip_dst_value,
15599                 (void *)&cmd_set_nvgre_eth_src,
15600                 (void *)&cmd_set_nvgre_eth_src_value,
15601                 (void *)&cmd_set_nvgre_eth_dst,
15602                 (void *)&cmd_set_nvgre_eth_dst_value,
15603                 NULL,
15604         },
15605 };
15606
15607 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15608         .f = cmd_set_nvgre_parsed,
15609         .data = NULL,
15610         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15611                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15612                 " eth-src <eth-src> eth-dst <eth-dst>",
15613         .tokens = {
15614                 (void *)&cmd_set_nvgre_set,
15615                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15616                 (void *)&cmd_set_nvgre_ip_version,
15617                 (void *)&cmd_set_nvgre_ip_version_value,
15618                 (void *)&cmd_set_nvgre_tni,
15619                 (void *)&cmd_set_nvgre_tni_value,
15620                 (void *)&cmd_set_nvgre_ip_src,
15621                 (void *)&cmd_set_nvgre_ip_src_value,
15622                 (void *)&cmd_set_nvgre_ip_dst,
15623                 (void *)&cmd_set_nvgre_ip_dst_value,
15624                 (void *)&cmd_set_nvgre_vlan,
15625                 (void *)&cmd_set_nvgre_vlan_value,
15626                 (void *)&cmd_set_nvgre_eth_src,
15627                 (void *)&cmd_set_nvgre_eth_src_value,
15628                 (void *)&cmd_set_nvgre_eth_dst,
15629                 (void *)&cmd_set_nvgre_eth_dst_value,
15630                 NULL,
15631         },
15632 };
15633
15634 /** Set L2 encapsulation details */
15635 struct cmd_set_l2_encap_result {
15636         cmdline_fixed_string_t set;
15637         cmdline_fixed_string_t l2_encap;
15638         cmdline_fixed_string_t pos_token;
15639         cmdline_fixed_string_t ip_version;
15640         uint32_t vlan_present:1;
15641         uint16_t tci;
15642         struct rte_ether_addr eth_src;
15643         struct rte_ether_addr eth_dst;
15644 };
15645
15646 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15647         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15648 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15649         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15650 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15651         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15652                                  "l2_encap-with-vlan");
15653 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15654         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15655                                  "ip-version");
15656 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15657         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15658                                  "ipv4#ipv6");
15659 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15660         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15661                                  "vlan-tci");
15662 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15663         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15664 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15665         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15666                                  "eth-src");
15667 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15668         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15669 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15670         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15671                                  "eth-dst");
15672 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15673         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15674
15675 static void cmd_set_l2_encap_parsed(void *parsed_result,
15676         __attribute__((unused)) struct cmdline *cl,
15677         __attribute__((unused)) void *data)
15678 {
15679         struct cmd_set_l2_encap_result *res = parsed_result;
15680
15681         if (strcmp(res->l2_encap, "l2_encap") == 0)
15682                 l2_encap_conf.select_vlan = 0;
15683         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15684                 l2_encap_conf.select_vlan = 1;
15685         if (strcmp(res->ip_version, "ipv4") == 0)
15686                 l2_encap_conf.select_ipv4 = 1;
15687         else if (strcmp(res->ip_version, "ipv6") == 0)
15688                 l2_encap_conf.select_ipv4 = 0;
15689         else
15690                 return;
15691         if (l2_encap_conf.select_vlan)
15692                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15693         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15694                    RTE_ETHER_ADDR_LEN);
15695         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15696                    RTE_ETHER_ADDR_LEN);
15697 }
15698
15699 cmdline_parse_inst_t cmd_set_l2_encap = {
15700         .f = cmd_set_l2_encap_parsed,
15701         .data = NULL,
15702         .help_str = "set l2_encap ip-version ipv4|ipv6"
15703                 " eth-src <eth-src> eth-dst <eth-dst>",
15704         .tokens = {
15705                 (void *)&cmd_set_l2_encap_set,
15706                 (void *)&cmd_set_l2_encap_l2_encap,
15707                 (void *)&cmd_set_l2_encap_ip_version,
15708                 (void *)&cmd_set_l2_encap_ip_version_value,
15709                 (void *)&cmd_set_l2_encap_eth_src,
15710                 (void *)&cmd_set_l2_encap_eth_src_value,
15711                 (void *)&cmd_set_l2_encap_eth_dst,
15712                 (void *)&cmd_set_l2_encap_eth_dst_value,
15713                 NULL,
15714         },
15715 };
15716
15717 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15718         .f = cmd_set_l2_encap_parsed,
15719         .data = NULL,
15720         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15721                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15722         .tokens = {
15723                 (void *)&cmd_set_l2_encap_set,
15724                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15725                 (void *)&cmd_set_l2_encap_ip_version,
15726                 (void *)&cmd_set_l2_encap_ip_version_value,
15727                 (void *)&cmd_set_l2_encap_vlan,
15728                 (void *)&cmd_set_l2_encap_vlan_value,
15729                 (void *)&cmd_set_l2_encap_eth_src,
15730                 (void *)&cmd_set_l2_encap_eth_src_value,
15731                 (void *)&cmd_set_l2_encap_eth_dst,
15732                 (void *)&cmd_set_l2_encap_eth_dst_value,
15733                 NULL,
15734         },
15735 };
15736
15737 /** Set L2 decapsulation details */
15738 struct cmd_set_l2_decap_result {
15739         cmdline_fixed_string_t set;
15740         cmdline_fixed_string_t l2_decap;
15741         cmdline_fixed_string_t pos_token;
15742         uint32_t vlan_present:1;
15743 };
15744
15745 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15746         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15747 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15749                                  "l2_decap");
15750 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15752                                  "l2_decap-with-vlan");
15753
15754 static void cmd_set_l2_decap_parsed(void *parsed_result,
15755         __attribute__((unused)) struct cmdline *cl,
15756         __attribute__((unused)) void *data)
15757 {
15758         struct cmd_set_l2_decap_result *res = parsed_result;
15759
15760         if (strcmp(res->l2_decap, "l2_decap") == 0)
15761                 l2_decap_conf.select_vlan = 0;
15762         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15763                 l2_decap_conf.select_vlan = 1;
15764 }
15765
15766 cmdline_parse_inst_t cmd_set_l2_decap = {
15767         .f = cmd_set_l2_decap_parsed,
15768         .data = NULL,
15769         .help_str = "set l2_decap",
15770         .tokens = {
15771                 (void *)&cmd_set_l2_decap_set,
15772                 (void *)&cmd_set_l2_decap_l2_decap,
15773                 NULL,
15774         },
15775 };
15776
15777 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15778         .f = cmd_set_l2_decap_parsed,
15779         .data = NULL,
15780         .help_str = "set l2_decap-with-vlan",
15781         .tokens = {
15782                 (void *)&cmd_set_l2_decap_set,
15783                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15784                 NULL,
15785         },
15786 };
15787
15788 /** Set MPLSoGRE encapsulation details */
15789 struct cmd_set_mplsogre_encap_result {
15790         cmdline_fixed_string_t set;
15791         cmdline_fixed_string_t mplsogre;
15792         cmdline_fixed_string_t pos_token;
15793         cmdline_fixed_string_t ip_version;
15794         uint32_t vlan_present:1;
15795         uint32_t label;
15796         cmdline_ipaddr_t ip_src;
15797         cmdline_ipaddr_t ip_dst;
15798         uint16_t tci;
15799         struct rte_ether_addr eth_src;
15800         struct rte_ether_addr eth_dst;
15801 };
15802
15803 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15804         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15805                                  "set");
15806 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15807         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15808                                  "mplsogre_encap");
15809 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15810         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15811                                  mplsogre, "mplsogre_encap-with-vlan");
15812 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15813         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15814                                  pos_token, "ip-version");
15815 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15816         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15817                                  ip_version, "ipv4#ipv6");
15818 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15819         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15820                                  pos_token, "label");
15821 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15822         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15823                               UINT32);
15824 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15825         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15826                                  pos_token, "ip-src");
15827 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15828         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15829 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15830         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15831                                  pos_token, "ip-dst");
15832 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15833         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15834 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15835         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15836                                  pos_token, "vlan-tci");
15837 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15838         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15839                               UINT16);
15840 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15841         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15842                                  pos_token, "eth-src");
15843 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15844         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15845                                     eth_src);
15846 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15847         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15848                                  pos_token, "eth-dst");
15849 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15850         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15851                                     eth_dst);
15852
15853 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15854         __attribute__((unused)) struct cmdline *cl,
15855         __attribute__((unused)) void *data)
15856 {
15857         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15858         union {
15859                 uint32_t mplsogre_label;
15860                 uint8_t label[4];
15861         } id = {
15862                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15863         };
15864
15865         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15866                 mplsogre_encap_conf.select_vlan = 0;
15867         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15868                 mplsogre_encap_conf.select_vlan = 1;
15869         if (strcmp(res->ip_version, "ipv4") == 0)
15870                 mplsogre_encap_conf.select_ipv4 = 1;
15871         else if (strcmp(res->ip_version, "ipv6") == 0)
15872                 mplsogre_encap_conf.select_ipv4 = 0;
15873         else
15874                 return;
15875         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15876         if (mplsogre_encap_conf.select_ipv4) {
15877                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15878                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15879         } else {
15880                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15881                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15882         }
15883         if (mplsogre_encap_conf.select_vlan)
15884                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15885         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15886                    RTE_ETHER_ADDR_LEN);
15887         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15888                    RTE_ETHER_ADDR_LEN);
15889 }
15890
15891 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15892         .f = cmd_set_mplsogre_encap_parsed,
15893         .data = NULL,
15894         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15895                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15896                 " eth-dst <eth-dst>",
15897         .tokens = {
15898                 (void *)&cmd_set_mplsogre_encap_set,
15899                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15900                 (void *)&cmd_set_mplsogre_encap_ip_version,
15901                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15902                 (void *)&cmd_set_mplsogre_encap_label,
15903                 (void *)&cmd_set_mplsogre_encap_label_value,
15904                 (void *)&cmd_set_mplsogre_encap_ip_src,
15905                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15906                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15907                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15908                 (void *)&cmd_set_mplsogre_encap_eth_src,
15909                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15910                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15911                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15912                 NULL,
15913         },
15914 };
15915
15916 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15917         .f = cmd_set_mplsogre_encap_parsed,
15918         .data = NULL,
15919         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15920                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15921                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15922         .tokens = {
15923                 (void *)&cmd_set_mplsogre_encap_set,
15924                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15925                 (void *)&cmd_set_mplsogre_encap_ip_version,
15926                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15927                 (void *)&cmd_set_mplsogre_encap_label,
15928                 (void *)&cmd_set_mplsogre_encap_label_value,
15929                 (void *)&cmd_set_mplsogre_encap_ip_src,
15930                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15931                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15932                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15933                 (void *)&cmd_set_mplsogre_encap_vlan,
15934                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15935                 (void *)&cmd_set_mplsogre_encap_eth_src,
15936                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15937                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15938                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15939                 NULL,
15940         },
15941 };
15942
15943 /** Set MPLSoGRE decapsulation details */
15944 struct cmd_set_mplsogre_decap_result {
15945         cmdline_fixed_string_t set;
15946         cmdline_fixed_string_t mplsogre;
15947         cmdline_fixed_string_t pos_token;
15948         cmdline_fixed_string_t ip_version;
15949         uint32_t vlan_present:1;
15950 };
15951
15952 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15953         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15954                                  "set");
15955 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15956         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15957                                  "mplsogre_decap");
15958 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15959         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15960                                  mplsogre, "mplsogre_decap-with-vlan");
15961 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15962         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15963                                  pos_token, "ip-version");
15964 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15965         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15966                                  ip_version, "ipv4#ipv6");
15967
15968 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15969         __attribute__((unused)) struct cmdline *cl,
15970         __attribute__((unused)) void *data)
15971 {
15972         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15973
15974         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15975                 mplsogre_decap_conf.select_vlan = 0;
15976         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15977                 mplsogre_decap_conf.select_vlan = 1;
15978         if (strcmp(res->ip_version, "ipv4") == 0)
15979                 mplsogre_decap_conf.select_ipv4 = 1;
15980         else if (strcmp(res->ip_version, "ipv6") == 0)
15981                 mplsogre_decap_conf.select_ipv4 = 0;
15982 }
15983
15984 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15985         .f = cmd_set_mplsogre_decap_parsed,
15986         .data = NULL,
15987         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15988         .tokens = {
15989                 (void *)&cmd_set_mplsogre_decap_set,
15990                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15991                 (void *)&cmd_set_mplsogre_decap_ip_version,
15992                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15993                 NULL,
15994         },
15995 };
15996
15997 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15998         .f = cmd_set_mplsogre_decap_parsed,
15999         .data = NULL,
16000         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16001         .tokens = {
16002                 (void *)&cmd_set_mplsogre_decap_set,
16003                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16004                 (void *)&cmd_set_mplsogre_decap_ip_version,
16005                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16006                 NULL,
16007         },
16008 };
16009
16010 /** Set MPLSoUDP encapsulation details */
16011 struct cmd_set_mplsoudp_encap_result {
16012         cmdline_fixed_string_t set;
16013         cmdline_fixed_string_t mplsoudp;
16014         cmdline_fixed_string_t pos_token;
16015         cmdline_fixed_string_t ip_version;
16016         uint32_t vlan_present:1;
16017         uint32_t label;
16018         uint16_t udp_src;
16019         uint16_t udp_dst;
16020         cmdline_ipaddr_t ip_src;
16021         cmdline_ipaddr_t ip_dst;
16022         uint16_t tci;
16023         struct rte_ether_addr eth_src;
16024         struct rte_ether_addr eth_dst;
16025 };
16026
16027 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16028         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16029                                  "set");
16030 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16031         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16032                                  "mplsoudp_encap");
16033 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16034         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16035                                  mplsoudp, "mplsoudp_encap-with-vlan");
16036 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16037         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16038                                  pos_token, "ip-version");
16039 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16040         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16041                                  ip_version, "ipv4#ipv6");
16042 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16043         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16044                                  pos_token, "label");
16045 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16046         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16047                               UINT32);
16048 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16049         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16050                                  pos_token, "udp-src");
16051 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16052         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16053                               UINT16);
16054 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16055         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16056                                  pos_token, "udp-dst");
16057 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16058         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16059                               UINT16);
16060 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16061         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16062                                  pos_token, "ip-src");
16063 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16064         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16065 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16066         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16067                                  pos_token, "ip-dst");
16068 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16069         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16070 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16071         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16072                                  pos_token, "vlan-tci");
16073 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16074         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16075                               UINT16);
16076 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16077         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16078                                  pos_token, "eth-src");
16079 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16080         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16081                                     eth_src);
16082 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16083         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16084                                  pos_token, "eth-dst");
16085 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16086         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16087                                     eth_dst);
16088
16089 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16090         __attribute__((unused)) struct cmdline *cl,
16091         __attribute__((unused)) void *data)
16092 {
16093         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16094         union {
16095                 uint32_t mplsoudp_label;
16096                 uint8_t label[4];
16097         } id = {
16098                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16099         };
16100
16101         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16102                 mplsoudp_encap_conf.select_vlan = 0;
16103         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16104                 mplsoudp_encap_conf.select_vlan = 1;
16105         if (strcmp(res->ip_version, "ipv4") == 0)
16106                 mplsoudp_encap_conf.select_ipv4 = 1;
16107         else if (strcmp(res->ip_version, "ipv6") == 0)
16108                 mplsoudp_encap_conf.select_ipv4 = 0;
16109         else
16110                 return;
16111         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16112         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16113         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16114         if (mplsoudp_encap_conf.select_ipv4) {
16115                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16116                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16117         } else {
16118                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16119                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16120         }
16121         if (mplsoudp_encap_conf.select_vlan)
16122                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16123         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16124                    RTE_ETHER_ADDR_LEN);
16125         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16126                    RTE_ETHER_ADDR_LEN);
16127 }
16128
16129 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16130         .f = cmd_set_mplsoudp_encap_parsed,
16131         .data = NULL,
16132         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16133                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16134                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16135         .tokens = {
16136                 (void *)&cmd_set_mplsoudp_encap_set,
16137                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16138                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16139                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16140                 (void *)&cmd_set_mplsoudp_encap_label,
16141                 (void *)&cmd_set_mplsoudp_encap_label_value,
16142                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16143                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16144                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16145                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16146                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16147                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16148                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16149                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16150                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16151                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16152                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16153                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16154                 NULL,
16155         },
16156 };
16157
16158 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16159         .f = cmd_set_mplsoudp_encap_parsed,
16160         .data = NULL,
16161         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16162                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16163                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16164                 " eth-src <eth-src> eth-dst <eth-dst>",
16165         .tokens = {
16166                 (void *)&cmd_set_mplsoudp_encap_set,
16167                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16168                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16169                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16170                 (void *)&cmd_set_mplsoudp_encap_label,
16171                 (void *)&cmd_set_mplsoudp_encap_label_value,
16172                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16173                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16174                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16175                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16176                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16177                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16178                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16179                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16180                 (void *)&cmd_set_mplsoudp_encap_vlan,
16181                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16182                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16183                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16184                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16185                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16186                 NULL,
16187         },
16188 };
16189
16190 /** Set MPLSoUDP decapsulation details */
16191 struct cmd_set_mplsoudp_decap_result {
16192         cmdline_fixed_string_t set;
16193         cmdline_fixed_string_t mplsoudp;
16194         cmdline_fixed_string_t pos_token;
16195         cmdline_fixed_string_t ip_version;
16196         uint32_t vlan_present:1;
16197 };
16198
16199 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16200         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16201                                  "set");
16202 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16203         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16204                                  "mplsoudp_decap");
16205 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16206         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16207                                  mplsoudp, "mplsoudp_decap-with-vlan");
16208 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16209         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16210                                  pos_token, "ip-version");
16211 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16212         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16213                                  ip_version, "ipv4#ipv6");
16214
16215 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16216         __attribute__((unused)) struct cmdline *cl,
16217         __attribute__((unused)) void *data)
16218 {
16219         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16220
16221         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16222                 mplsoudp_decap_conf.select_vlan = 0;
16223         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16224                 mplsoudp_decap_conf.select_vlan = 1;
16225         if (strcmp(res->ip_version, "ipv4") == 0)
16226                 mplsoudp_decap_conf.select_ipv4 = 1;
16227         else if (strcmp(res->ip_version, "ipv6") == 0)
16228                 mplsoudp_decap_conf.select_ipv4 = 0;
16229 }
16230
16231 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16232         .f = cmd_set_mplsoudp_decap_parsed,
16233         .data = NULL,
16234         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16235         .tokens = {
16236                 (void *)&cmd_set_mplsoudp_decap_set,
16237                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16238                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16239                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16240                 NULL,
16241         },
16242 };
16243
16244 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16245         .f = cmd_set_mplsoudp_decap_parsed,
16246         .data = NULL,
16247         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16248         .tokens = {
16249                 (void *)&cmd_set_mplsoudp_decap_set,
16250                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16251                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16252                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16253                 NULL,
16254         },
16255 };
16256
16257 /* Strict link priority scheduling mode setting */
16258 static void
16259 cmd_strict_link_prio_parsed(
16260         void *parsed_result,
16261         __attribute__((unused)) struct cmdline *cl,
16262         __attribute__((unused)) void *data)
16263 {
16264         struct cmd_vf_tc_bw_result *res = parsed_result;
16265         int ret = -ENOTSUP;
16266
16267         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16268                 return;
16269
16270 #ifdef RTE_LIBRTE_I40E_PMD
16271         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16272 #endif
16273
16274         switch (ret) {
16275         case 0:
16276                 break;
16277         case -EINVAL:
16278                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16279                 break;
16280         case -ENODEV:
16281                 printf("invalid port_id %d\n", res->port_id);
16282                 break;
16283         case -ENOTSUP:
16284                 printf("function not implemented\n");
16285                 break;
16286         default:
16287                 printf("programming error: (%s)\n", strerror(-ret));
16288         }
16289 }
16290
16291 cmdline_parse_inst_t cmd_strict_link_prio = {
16292         .f = cmd_strict_link_prio_parsed,
16293         .data = NULL,
16294         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16295         .tokens = {
16296                 (void *)&cmd_vf_tc_bw_set,
16297                 (void *)&cmd_vf_tc_bw_tx,
16298                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16299                 (void *)&cmd_vf_tc_bw_port_id,
16300                 (void *)&cmd_vf_tc_bw_tc_map,
16301                 NULL,
16302         },
16303 };
16304
16305 /* Load dynamic device personalization*/
16306 struct cmd_ddp_add_result {
16307         cmdline_fixed_string_t ddp;
16308         cmdline_fixed_string_t add;
16309         portid_t port_id;
16310         char filepath[];
16311 };
16312
16313 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16314         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16315 cmdline_parse_token_string_t cmd_ddp_add_add =
16316         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16317 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16318         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16319 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16320         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16321
16322 static void
16323 cmd_ddp_add_parsed(
16324         void *parsed_result,
16325         __attribute__((unused)) struct cmdline *cl,
16326         __attribute__((unused)) void *data)
16327 {
16328         struct cmd_ddp_add_result *res = parsed_result;
16329         uint8_t *buff;
16330         uint32_t size;
16331         char *filepath;
16332         char *file_fld[2];
16333         int file_num;
16334         int ret = -ENOTSUP;
16335
16336         if (!all_ports_stopped()) {
16337                 printf("Please stop all ports first\n");
16338                 return;
16339         }
16340
16341         filepath = strdup(res->filepath);
16342         if (filepath == NULL) {
16343                 printf("Failed to allocate memory\n");
16344                 return;
16345         }
16346         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16347
16348         buff = open_file(file_fld[0], &size);
16349         if (!buff) {
16350                 free((void *)filepath);
16351                 return;
16352         }
16353
16354 #ifdef RTE_LIBRTE_I40E_PMD
16355         if (ret == -ENOTSUP)
16356                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16357                                                buff, size,
16358                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16359 #endif
16360
16361         if (ret == -EEXIST)
16362                 printf("Profile has already existed.\n");
16363         else if (ret < 0)
16364                 printf("Failed to load profile.\n");
16365         else if (file_num == 2)
16366                 save_file(file_fld[1], buff, size);
16367
16368         close_file(buff);
16369         free((void *)filepath);
16370 }
16371
16372 cmdline_parse_inst_t cmd_ddp_add = {
16373         .f = cmd_ddp_add_parsed,
16374         .data = NULL,
16375         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16376         .tokens = {
16377                 (void *)&cmd_ddp_add_ddp,
16378                 (void *)&cmd_ddp_add_add,
16379                 (void *)&cmd_ddp_add_port_id,
16380                 (void *)&cmd_ddp_add_filepath,
16381                 NULL,
16382         },
16383 };
16384
16385 /* Delete dynamic device personalization*/
16386 struct cmd_ddp_del_result {
16387         cmdline_fixed_string_t ddp;
16388         cmdline_fixed_string_t del;
16389         portid_t port_id;
16390         char filepath[];
16391 };
16392
16393 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16394         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16395 cmdline_parse_token_string_t cmd_ddp_del_del =
16396         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16397 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16398         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16399 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16400         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16401
16402 static void
16403 cmd_ddp_del_parsed(
16404         void *parsed_result,
16405         __attribute__((unused)) struct cmdline *cl,
16406         __attribute__((unused)) void *data)
16407 {
16408         struct cmd_ddp_del_result *res = parsed_result;
16409         uint8_t *buff;
16410         uint32_t size;
16411         int ret = -ENOTSUP;
16412
16413         if (!all_ports_stopped()) {
16414                 printf("Please stop all ports first\n");
16415                 return;
16416         }
16417
16418         buff = open_file(res->filepath, &size);
16419         if (!buff)
16420                 return;
16421
16422 #ifdef RTE_LIBRTE_I40E_PMD
16423         if (ret == -ENOTSUP)
16424                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16425                                                buff, size,
16426                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16427 #endif
16428
16429         if (ret == -EACCES)
16430                 printf("Profile does not exist.\n");
16431         else if (ret < 0)
16432                 printf("Failed to delete profile.\n");
16433
16434         close_file(buff);
16435 }
16436
16437 cmdline_parse_inst_t cmd_ddp_del = {
16438         .f = cmd_ddp_del_parsed,
16439         .data = NULL,
16440         .help_str = "ddp del <port_id> <backup_profile_path>",
16441         .tokens = {
16442                 (void *)&cmd_ddp_del_ddp,
16443                 (void *)&cmd_ddp_del_del,
16444                 (void *)&cmd_ddp_del_port_id,
16445                 (void *)&cmd_ddp_del_filepath,
16446                 NULL,
16447         },
16448 };
16449
16450 /* Get dynamic device personalization profile info */
16451 struct cmd_ddp_info_result {
16452         cmdline_fixed_string_t ddp;
16453         cmdline_fixed_string_t get;
16454         cmdline_fixed_string_t info;
16455         char filepath[];
16456 };
16457
16458 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16459         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16460 cmdline_parse_token_string_t cmd_ddp_info_get =
16461         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16462 cmdline_parse_token_string_t cmd_ddp_info_info =
16463         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16464 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16465         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16466
16467 static void
16468 cmd_ddp_info_parsed(
16469         void *parsed_result,
16470         __attribute__((unused)) struct cmdline *cl,
16471         __attribute__((unused)) void *data)
16472 {
16473         struct cmd_ddp_info_result *res = parsed_result;
16474         uint8_t *pkg;
16475         uint32_t pkg_size;
16476         int ret = -ENOTSUP;
16477 #ifdef RTE_LIBRTE_I40E_PMD
16478         uint32_t i, j, n;
16479         uint8_t *buff;
16480         uint32_t buff_size = 0;
16481         struct rte_pmd_i40e_profile_info info;
16482         uint32_t dev_num = 0;
16483         struct rte_pmd_i40e_ddp_device_id *devs;
16484         uint32_t proto_num = 0;
16485         struct rte_pmd_i40e_proto_info *proto = NULL;
16486         uint32_t pctype_num = 0;
16487         struct rte_pmd_i40e_ptype_info *pctype;
16488         uint32_t ptype_num = 0;
16489         struct rte_pmd_i40e_ptype_info *ptype;
16490         uint8_t proto_id;
16491
16492 #endif
16493
16494         pkg = open_file(res->filepath, &pkg_size);
16495         if (!pkg)
16496                 return;
16497
16498 #ifdef RTE_LIBRTE_I40E_PMD
16499         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16500                                 (uint8_t *)&info, sizeof(info),
16501                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16502         if (!ret) {
16503                 printf("Global Track id:       0x%x\n", info.track_id);
16504                 printf("Global Version:        %d.%d.%d.%d\n",
16505                         info.version.major,
16506                         info.version.minor,
16507                         info.version.update,
16508                         info.version.draft);
16509                 printf("Global Package name:   %s\n\n", info.name);
16510         }
16511
16512         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16513                                 (uint8_t *)&info, sizeof(info),
16514                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16515         if (!ret) {
16516                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16517                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16518                         info.version.major,
16519                         info.version.minor,
16520                         info.version.update,
16521                         info.version.draft);
16522                 printf("i40e Profile name:     %s\n\n", info.name);
16523         }
16524
16525         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16526                                 (uint8_t *)&buff_size, sizeof(buff_size),
16527                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16528         if (!ret && buff_size) {
16529                 buff = (uint8_t *)malloc(buff_size);
16530                 if (buff) {
16531                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16532                                                 buff, buff_size,
16533                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16534                         if (!ret)
16535                                 printf("Package Notes:\n%s\n\n", buff);
16536                         free(buff);
16537                 }
16538         }
16539
16540         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16541                                 (uint8_t *)&dev_num, sizeof(dev_num),
16542                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16543         if (!ret && dev_num) {
16544                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16545                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16546                 if (devs) {
16547                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16548                                                 (uint8_t *)devs, buff_size,
16549                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16550                         if (!ret) {
16551                                 printf("List of supported devices:\n");
16552                                 for (i = 0; i < dev_num; i++) {
16553                                         printf("  %04X:%04X %04X:%04X\n",
16554                                                 devs[i].vendor_dev_id >> 16,
16555                                                 devs[i].vendor_dev_id & 0xFFFF,
16556                                                 devs[i].sub_vendor_dev_id >> 16,
16557                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16558                                 }
16559                                 printf("\n");
16560                         }
16561                         free(devs);
16562                 }
16563         }
16564
16565         /* get information about protocols and packet types */
16566         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16567                 (uint8_t *)&proto_num, sizeof(proto_num),
16568                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16569         if (ret || !proto_num)
16570                 goto no_print_return;
16571
16572         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16573         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16574         if (!proto)
16575                 goto no_print_return;
16576
16577         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16578                                         buff_size,
16579                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16580         if (!ret) {
16581                 printf("List of used protocols:\n");
16582                 for (i = 0; i < proto_num; i++)
16583                         printf("  %2u: %s\n", proto[i].proto_id,
16584                                proto[i].name);
16585                 printf("\n");
16586         }
16587         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16588                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16589                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16590         if (ret || !pctype_num)
16591                 goto no_print_pctypes;
16592
16593         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16594         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16595         if (!pctype)
16596                 goto no_print_pctypes;
16597
16598         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16599                                         buff_size,
16600                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16601         if (ret) {
16602                 free(pctype);
16603                 goto no_print_pctypes;
16604         }
16605
16606         printf("List of defined packet classification types:\n");
16607         for (i = 0; i < pctype_num; i++) {
16608                 printf("  %2u:", pctype[i].ptype_id);
16609                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16610                         proto_id = pctype[i].protocols[j];
16611                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16612                                 for (n = 0; n < proto_num; n++) {
16613                                         if (proto[n].proto_id == proto_id) {
16614                                                 printf(" %s", proto[n].name);
16615                                                 break;
16616                                         }
16617                                 }
16618                         }
16619                 }
16620                 printf("\n");
16621         }
16622         printf("\n");
16623         free(pctype);
16624
16625 no_print_pctypes:
16626
16627         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16628                                         sizeof(ptype_num),
16629                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16630         if (ret || !ptype_num)
16631                 goto no_print_return;
16632
16633         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16634         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16635         if (!ptype)
16636                 goto no_print_return;
16637
16638         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16639                                         buff_size,
16640                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16641         if (ret) {
16642                 free(ptype);
16643                 goto no_print_return;
16644         }
16645         printf("List of defined packet types:\n");
16646         for (i = 0; i < ptype_num; i++) {
16647                 printf("  %2u:", ptype[i].ptype_id);
16648                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16649                         proto_id = ptype[i].protocols[j];
16650                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16651                                 for (n = 0; n < proto_num; n++) {
16652                                         if (proto[n].proto_id == proto_id) {
16653                                                 printf(" %s", proto[n].name);
16654                                                 break;
16655                                         }
16656                                 }
16657                         }
16658                 }
16659                 printf("\n");
16660         }
16661         free(ptype);
16662         printf("\n");
16663
16664         ret = 0;
16665 no_print_return:
16666         if (proto)
16667                 free(proto);
16668 #endif
16669         if (ret == -ENOTSUP)
16670                 printf("Function not supported in PMD driver\n");
16671         close_file(pkg);
16672 }
16673
16674 cmdline_parse_inst_t cmd_ddp_get_info = {
16675         .f = cmd_ddp_info_parsed,
16676         .data = NULL,
16677         .help_str = "ddp get info <profile_path>",
16678         .tokens = {
16679                 (void *)&cmd_ddp_info_ddp,
16680                 (void *)&cmd_ddp_info_get,
16681                 (void *)&cmd_ddp_info_info,
16682                 (void *)&cmd_ddp_info_filepath,
16683                 NULL,
16684         },
16685 };
16686
16687 /* Get dynamic device personalization profile info list*/
16688 #define PROFILE_INFO_SIZE 48
16689 #define MAX_PROFILE_NUM 16
16690
16691 struct cmd_ddp_get_list_result {
16692         cmdline_fixed_string_t ddp;
16693         cmdline_fixed_string_t get;
16694         cmdline_fixed_string_t list;
16695         portid_t port_id;
16696 };
16697
16698 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16699         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16700 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16701         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16702 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16703         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16704 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16705         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16706
16707 static void
16708 cmd_ddp_get_list_parsed(
16709         __attribute__((unused)) void *parsed_result,
16710         __attribute__((unused)) struct cmdline *cl,
16711         __attribute__((unused)) void *data)
16712 {
16713 #ifdef RTE_LIBRTE_I40E_PMD
16714         struct cmd_ddp_get_list_result *res = parsed_result;
16715         struct rte_pmd_i40e_profile_list *p_list;
16716         struct rte_pmd_i40e_profile_info *p_info;
16717         uint32_t p_num;
16718         uint32_t size;
16719         uint32_t i;
16720 #endif
16721         int ret = -ENOTSUP;
16722
16723 #ifdef RTE_LIBRTE_I40E_PMD
16724         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16725         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16726         if (!p_list)
16727                 printf("%s: Failed to malloc buffer\n", __func__);
16728
16729         if (ret == -ENOTSUP)
16730                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16731                                                 (uint8_t *)p_list, size);
16732
16733         if (!ret) {
16734                 p_num = p_list->p_count;
16735                 printf("Profile number is: %d\n\n", p_num);
16736
16737                 for (i = 0; i < p_num; i++) {
16738                         p_info = &p_list->p_info[i];
16739                         printf("Profile %d:\n", i);
16740                         printf("Track id:     0x%x\n", p_info->track_id);
16741                         printf("Version:      %d.%d.%d.%d\n",
16742                                p_info->version.major,
16743                                p_info->version.minor,
16744                                p_info->version.update,
16745                                p_info->version.draft);
16746                         printf("Profile name: %s\n\n", p_info->name);
16747                 }
16748         }
16749
16750         free(p_list);
16751 #endif
16752
16753         if (ret < 0)
16754                 printf("Failed to get ddp list\n");
16755 }
16756
16757 cmdline_parse_inst_t cmd_ddp_get_list = {
16758         .f = cmd_ddp_get_list_parsed,
16759         .data = NULL,
16760         .help_str = "ddp get list <port_id>",
16761         .tokens = {
16762                 (void *)&cmd_ddp_get_list_ddp,
16763                 (void *)&cmd_ddp_get_list_get,
16764                 (void *)&cmd_ddp_get_list_list,
16765                 (void *)&cmd_ddp_get_list_port_id,
16766                 NULL,
16767         },
16768 };
16769
16770 /* Configure input set */
16771 struct cmd_cfg_input_set_result {
16772         cmdline_fixed_string_t port;
16773         cmdline_fixed_string_t cfg;
16774         portid_t port_id;
16775         cmdline_fixed_string_t pctype;
16776         uint8_t pctype_id;
16777         cmdline_fixed_string_t inset_type;
16778         cmdline_fixed_string_t opt;
16779         cmdline_fixed_string_t field;
16780         uint8_t field_idx;
16781 };
16782
16783 static void
16784 cmd_cfg_input_set_parsed(
16785         __attribute__((unused)) void *parsed_result,
16786         __attribute__((unused)) struct cmdline *cl,
16787         __attribute__((unused)) void *data)
16788 {
16789 #ifdef RTE_LIBRTE_I40E_PMD
16790         struct cmd_cfg_input_set_result *res = parsed_result;
16791         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16792         struct rte_pmd_i40e_inset inset;
16793 #endif
16794         int ret = -ENOTSUP;
16795
16796         if (!all_ports_stopped()) {
16797                 printf("Please stop all ports first\n");
16798                 return;
16799         }
16800
16801 #ifdef RTE_LIBRTE_I40E_PMD
16802         if (!strcmp(res->inset_type, "hash_inset"))
16803                 inset_type = INSET_HASH;
16804         else if (!strcmp(res->inset_type, "fdir_inset"))
16805                 inset_type = INSET_FDIR;
16806         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16807                 inset_type = INSET_FDIR_FLX;
16808         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16809                                      &inset, inset_type);
16810         if (ret) {
16811                 printf("Failed to get input set.\n");
16812                 return;
16813         }
16814
16815         if (!strcmp(res->opt, "get")) {
16816                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16817                                                    res->field_idx);
16818                 if (ret)
16819                         printf("Field index %d is enabled.\n", res->field_idx);
16820                 else
16821                         printf("Field index %d is disabled.\n", res->field_idx);
16822                 return;
16823         } else if (!strcmp(res->opt, "set"))
16824                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16825                                                    res->field_idx);
16826         else if (!strcmp(res->opt, "clear"))
16827                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16828                                                      res->field_idx);
16829         if (ret) {
16830                 printf("Failed to configure input set field.\n");
16831                 return;
16832         }
16833
16834         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16835                                      &inset, inset_type);
16836         if (ret) {
16837                 printf("Failed to set input set.\n");
16838                 return;
16839         }
16840 #endif
16841
16842         if (ret == -ENOTSUP)
16843                 printf("Function not supported\n");
16844 }
16845
16846 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16847         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16848                                  port, "port");
16849 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16850         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16851                                  cfg, "config");
16852 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16853         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16854                               port_id, UINT16);
16855 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16856         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16857                                  pctype, "pctype");
16858 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16859         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16860                               pctype_id, UINT8);
16861 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16862         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16863                                  inset_type,
16864                                  "hash_inset#fdir_inset#fdir_flx_inset");
16865 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16866         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16867                                  opt, "get#set#clear");
16868 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16869         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16870                                  field, "field");
16871 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16872         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16873                               field_idx, UINT8);
16874
16875 cmdline_parse_inst_t cmd_cfg_input_set = {
16876         .f = cmd_cfg_input_set_parsed,
16877         .data = NULL,
16878         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16879                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16880         .tokens = {
16881                 (void *)&cmd_cfg_input_set_port,
16882                 (void *)&cmd_cfg_input_set_cfg,
16883                 (void *)&cmd_cfg_input_set_port_id,
16884                 (void *)&cmd_cfg_input_set_pctype,
16885                 (void *)&cmd_cfg_input_set_pctype_id,
16886                 (void *)&cmd_cfg_input_set_inset_type,
16887                 (void *)&cmd_cfg_input_set_opt,
16888                 (void *)&cmd_cfg_input_set_field,
16889                 (void *)&cmd_cfg_input_set_field_idx,
16890                 NULL,
16891         },
16892 };
16893
16894 /* Clear input set */
16895 struct cmd_clear_input_set_result {
16896         cmdline_fixed_string_t port;
16897         cmdline_fixed_string_t cfg;
16898         portid_t port_id;
16899         cmdline_fixed_string_t pctype;
16900         uint8_t pctype_id;
16901         cmdline_fixed_string_t inset_type;
16902         cmdline_fixed_string_t clear;
16903         cmdline_fixed_string_t all;
16904 };
16905
16906 static void
16907 cmd_clear_input_set_parsed(
16908         __attribute__((unused)) void *parsed_result,
16909         __attribute__((unused)) struct cmdline *cl,
16910         __attribute__((unused)) void *data)
16911 {
16912 #ifdef RTE_LIBRTE_I40E_PMD
16913         struct cmd_clear_input_set_result *res = parsed_result;
16914         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16915         struct rte_pmd_i40e_inset inset;
16916 #endif
16917         int ret = -ENOTSUP;
16918
16919         if (!all_ports_stopped()) {
16920                 printf("Please stop all ports first\n");
16921                 return;
16922         }
16923
16924 #ifdef RTE_LIBRTE_I40E_PMD
16925         if (!strcmp(res->inset_type, "hash_inset"))
16926                 inset_type = INSET_HASH;
16927         else if (!strcmp(res->inset_type, "fdir_inset"))
16928                 inset_type = INSET_FDIR;
16929         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16930                 inset_type = INSET_FDIR_FLX;
16931
16932         memset(&inset, 0, sizeof(inset));
16933
16934         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16935                                      &inset, inset_type);
16936         if (ret) {
16937                 printf("Failed to clear input set.\n");
16938                 return;
16939         }
16940
16941 #endif
16942
16943         if (ret == -ENOTSUP)
16944                 printf("Function not supported\n");
16945 }
16946
16947 cmdline_parse_token_string_t cmd_clear_input_set_port =
16948         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16949                                  port, "port");
16950 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16951         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16952                                  cfg, "config");
16953 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16954         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16955                               port_id, UINT16);
16956 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16957         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16958                                  pctype, "pctype");
16959 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16960         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16961                               pctype_id, UINT8);
16962 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16963         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16964                                  inset_type,
16965                                  "hash_inset#fdir_inset#fdir_flx_inset");
16966 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16967         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16968                                  clear, "clear");
16969 cmdline_parse_token_string_t cmd_clear_input_set_all =
16970         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16971                                  all, "all");
16972
16973 cmdline_parse_inst_t cmd_clear_input_set = {
16974         .f = cmd_clear_input_set_parsed,
16975         .data = NULL,
16976         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16977                     "fdir_inset|fdir_flx_inset clear all",
16978         .tokens = {
16979                 (void *)&cmd_clear_input_set_port,
16980                 (void *)&cmd_clear_input_set_cfg,
16981                 (void *)&cmd_clear_input_set_port_id,
16982                 (void *)&cmd_clear_input_set_pctype,
16983                 (void *)&cmd_clear_input_set_pctype_id,
16984                 (void *)&cmd_clear_input_set_inset_type,
16985                 (void *)&cmd_clear_input_set_clear,
16986                 (void *)&cmd_clear_input_set_all,
16987                 NULL,
16988         },
16989 };
16990
16991 /* show vf stats */
16992
16993 /* Common result structure for show vf stats */
16994 struct cmd_show_vf_stats_result {
16995         cmdline_fixed_string_t show;
16996         cmdline_fixed_string_t vf;
16997         cmdline_fixed_string_t stats;
16998         portid_t port_id;
16999         uint16_t vf_id;
17000 };
17001
17002 /* Common CLI fields show vf stats*/
17003 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17004         TOKEN_STRING_INITIALIZER
17005                 (struct cmd_show_vf_stats_result,
17006                  show, "show");
17007 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17008         TOKEN_STRING_INITIALIZER
17009                 (struct cmd_show_vf_stats_result,
17010                  vf, "vf");
17011 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17012         TOKEN_STRING_INITIALIZER
17013                 (struct cmd_show_vf_stats_result,
17014                  stats, "stats");
17015 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17016         TOKEN_NUM_INITIALIZER
17017                 (struct cmd_show_vf_stats_result,
17018                  port_id, UINT16);
17019 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17020         TOKEN_NUM_INITIALIZER
17021                 (struct cmd_show_vf_stats_result,
17022                  vf_id, UINT16);
17023
17024 static void
17025 cmd_show_vf_stats_parsed(
17026         void *parsed_result,
17027         __attribute__((unused)) struct cmdline *cl,
17028         __attribute__((unused)) void *data)
17029 {
17030         struct cmd_show_vf_stats_result *res = parsed_result;
17031         struct rte_eth_stats stats;
17032         int ret = -ENOTSUP;
17033         static const char *nic_stats_border = "########################";
17034
17035         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17036                 return;
17037
17038         memset(&stats, 0, sizeof(stats));
17039
17040 #ifdef RTE_LIBRTE_I40E_PMD
17041         if (ret == -ENOTSUP)
17042                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17043                                                 res->vf_id,
17044                                                 &stats);
17045 #endif
17046 #ifdef RTE_LIBRTE_BNXT_PMD
17047         if (ret == -ENOTSUP)
17048                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17049                                                 res->vf_id,
17050                                                 &stats);
17051 #endif
17052
17053         switch (ret) {
17054         case 0:
17055                 break;
17056         case -EINVAL:
17057                 printf("invalid vf_id %d\n", res->vf_id);
17058                 break;
17059         case -ENODEV:
17060                 printf("invalid port_id %d\n", res->port_id);
17061                 break;
17062         case -ENOTSUP:
17063                 printf("function not implemented\n");
17064                 break;
17065         default:
17066                 printf("programming error: (%s)\n", strerror(-ret));
17067         }
17068
17069         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17070                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17071
17072         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17073                "%-"PRIu64"\n",
17074                stats.ipackets, stats.imissed, stats.ibytes);
17075         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17076         printf("  RX-nombuf:  %-10"PRIu64"\n",
17077                stats.rx_nombuf);
17078         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17079                "%-"PRIu64"\n",
17080                stats.opackets, stats.oerrors, stats.obytes);
17081
17082         printf("  %s############################%s\n",
17083                                nic_stats_border, nic_stats_border);
17084 }
17085
17086 cmdline_parse_inst_t cmd_show_vf_stats = {
17087         .f = cmd_show_vf_stats_parsed,
17088         .data = NULL,
17089         .help_str = "show vf stats <port_id> <vf_id>",
17090         .tokens = {
17091                 (void *)&cmd_show_vf_stats_show,
17092                 (void *)&cmd_show_vf_stats_vf,
17093                 (void *)&cmd_show_vf_stats_stats,
17094                 (void *)&cmd_show_vf_stats_port_id,
17095                 (void *)&cmd_show_vf_stats_vf_id,
17096                 NULL,
17097         },
17098 };
17099
17100 /* clear vf stats */
17101
17102 /* Common result structure for clear vf stats */
17103 struct cmd_clear_vf_stats_result {
17104         cmdline_fixed_string_t clear;
17105         cmdline_fixed_string_t vf;
17106         cmdline_fixed_string_t stats;
17107         portid_t port_id;
17108         uint16_t vf_id;
17109 };
17110
17111 /* Common CLI fields clear vf stats*/
17112 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17113         TOKEN_STRING_INITIALIZER
17114                 (struct cmd_clear_vf_stats_result,
17115                  clear, "clear");
17116 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17117         TOKEN_STRING_INITIALIZER
17118                 (struct cmd_clear_vf_stats_result,
17119                  vf, "vf");
17120 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17121         TOKEN_STRING_INITIALIZER
17122                 (struct cmd_clear_vf_stats_result,
17123                  stats, "stats");
17124 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17125         TOKEN_NUM_INITIALIZER
17126                 (struct cmd_clear_vf_stats_result,
17127                  port_id, UINT16);
17128 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17129         TOKEN_NUM_INITIALIZER
17130                 (struct cmd_clear_vf_stats_result,
17131                  vf_id, UINT16);
17132
17133 static void
17134 cmd_clear_vf_stats_parsed(
17135         void *parsed_result,
17136         __attribute__((unused)) struct cmdline *cl,
17137         __attribute__((unused)) void *data)
17138 {
17139         struct cmd_clear_vf_stats_result *res = parsed_result;
17140         int ret = -ENOTSUP;
17141
17142         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17143                 return;
17144
17145 #ifdef RTE_LIBRTE_I40E_PMD
17146         if (ret == -ENOTSUP)
17147                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17148                                                   res->vf_id);
17149 #endif
17150 #ifdef RTE_LIBRTE_BNXT_PMD
17151         if (ret == -ENOTSUP)
17152                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17153                                                   res->vf_id);
17154 #endif
17155
17156         switch (ret) {
17157         case 0:
17158                 break;
17159         case -EINVAL:
17160                 printf("invalid vf_id %d\n", res->vf_id);
17161                 break;
17162         case -ENODEV:
17163                 printf("invalid port_id %d\n", res->port_id);
17164                 break;
17165         case -ENOTSUP:
17166                 printf("function not implemented\n");
17167                 break;
17168         default:
17169                 printf("programming error: (%s)\n", strerror(-ret));
17170         }
17171 }
17172
17173 cmdline_parse_inst_t cmd_clear_vf_stats = {
17174         .f = cmd_clear_vf_stats_parsed,
17175         .data = NULL,
17176         .help_str = "clear vf stats <port_id> <vf_id>",
17177         .tokens = {
17178                 (void *)&cmd_clear_vf_stats_clear,
17179                 (void *)&cmd_clear_vf_stats_vf,
17180                 (void *)&cmd_clear_vf_stats_stats,
17181                 (void *)&cmd_clear_vf_stats_port_id,
17182                 (void *)&cmd_clear_vf_stats_vf_id,
17183                 NULL,
17184         },
17185 };
17186
17187 /* port config pctype mapping reset */
17188
17189 /* Common result structure for port config pctype mapping reset */
17190 struct cmd_pctype_mapping_reset_result {
17191         cmdline_fixed_string_t port;
17192         cmdline_fixed_string_t config;
17193         portid_t port_id;
17194         cmdline_fixed_string_t pctype;
17195         cmdline_fixed_string_t mapping;
17196         cmdline_fixed_string_t reset;
17197 };
17198
17199 /* Common CLI fields for port config pctype mapping reset*/
17200 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17201         TOKEN_STRING_INITIALIZER
17202                 (struct cmd_pctype_mapping_reset_result,
17203                  port, "port");
17204 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17205         TOKEN_STRING_INITIALIZER
17206                 (struct cmd_pctype_mapping_reset_result,
17207                  config, "config");
17208 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17209         TOKEN_NUM_INITIALIZER
17210                 (struct cmd_pctype_mapping_reset_result,
17211                  port_id, UINT16);
17212 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17213         TOKEN_STRING_INITIALIZER
17214                 (struct cmd_pctype_mapping_reset_result,
17215                  pctype, "pctype");
17216 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17217         TOKEN_STRING_INITIALIZER
17218                 (struct cmd_pctype_mapping_reset_result,
17219                  mapping, "mapping");
17220 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17221         TOKEN_STRING_INITIALIZER
17222                 (struct cmd_pctype_mapping_reset_result,
17223                  reset, "reset");
17224
17225 static void
17226 cmd_pctype_mapping_reset_parsed(
17227         void *parsed_result,
17228         __attribute__((unused)) struct cmdline *cl,
17229         __attribute__((unused)) void *data)
17230 {
17231         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17232         int ret = -ENOTSUP;
17233
17234         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17235                 return;
17236
17237 #ifdef RTE_LIBRTE_I40E_PMD
17238         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17239 #endif
17240
17241         switch (ret) {
17242         case 0:
17243                 break;
17244         case -ENODEV:
17245                 printf("invalid port_id %d\n", res->port_id);
17246                 break;
17247         case -ENOTSUP:
17248                 printf("function not implemented\n");
17249                 break;
17250         default:
17251                 printf("programming error: (%s)\n", strerror(-ret));
17252         }
17253 }
17254
17255 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17256         .f = cmd_pctype_mapping_reset_parsed,
17257         .data = NULL,
17258         .help_str = "port config <port_id> pctype mapping reset",
17259         .tokens = {
17260                 (void *)&cmd_pctype_mapping_reset_port,
17261                 (void *)&cmd_pctype_mapping_reset_config,
17262                 (void *)&cmd_pctype_mapping_reset_port_id,
17263                 (void *)&cmd_pctype_mapping_reset_pctype,
17264                 (void *)&cmd_pctype_mapping_reset_mapping,
17265                 (void *)&cmd_pctype_mapping_reset_reset,
17266                 NULL,
17267         },
17268 };
17269
17270 /* show port pctype mapping */
17271
17272 /* Common result structure for show port pctype mapping */
17273 struct cmd_pctype_mapping_get_result {
17274         cmdline_fixed_string_t show;
17275         cmdline_fixed_string_t port;
17276         portid_t port_id;
17277         cmdline_fixed_string_t pctype;
17278         cmdline_fixed_string_t mapping;
17279 };
17280
17281 /* Common CLI fields for pctype mapping get */
17282 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17283         TOKEN_STRING_INITIALIZER
17284                 (struct cmd_pctype_mapping_get_result,
17285                  show, "show");
17286 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17287         TOKEN_STRING_INITIALIZER
17288                 (struct cmd_pctype_mapping_get_result,
17289                  port, "port");
17290 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17291         TOKEN_NUM_INITIALIZER
17292                 (struct cmd_pctype_mapping_get_result,
17293                  port_id, UINT16);
17294 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17295         TOKEN_STRING_INITIALIZER
17296                 (struct cmd_pctype_mapping_get_result,
17297                  pctype, "pctype");
17298 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17299         TOKEN_STRING_INITIALIZER
17300                 (struct cmd_pctype_mapping_get_result,
17301                  mapping, "mapping");
17302
17303 static void
17304 cmd_pctype_mapping_get_parsed(
17305         void *parsed_result,
17306         __attribute__((unused)) struct cmdline *cl,
17307         __attribute__((unused)) void *data)
17308 {
17309         struct cmd_pctype_mapping_get_result *res = parsed_result;
17310         int ret = -ENOTSUP;
17311 #ifdef RTE_LIBRTE_I40E_PMD
17312         struct rte_pmd_i40e_flow_type_mapping
17313                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17314         int i, j, first_pctype;
17315 #endif
17316
17317         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17318                 return;
17319
17320 #ifdef RTE_LIBRTE_I40E_PMD
17321         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17322 #endif
17323
17324         switch (ret) {
17325         case 0:
17326                 break;
17327         case -ENODEV:
17328                 printf("invalid port_id %d\n", res->port_id);
17329                 return;
17330         case -ENOTSUP:
17331                 printf("function not implemented\n");
17332                 return;
17333         default:
17334                 printf("programming error: (%s)\n", strerror(-ret));
17335                 return;
17336         }
17337
17338 #ifdef RTE_LIBRTE_I40E_PMD
17339         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17340                 if (mapping[i].pctype != 0ULL) {
17341                         first_pctype = 1;
17342
17343                         printf("pctype: ");
17344                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17345                                 if (mapping[i].pctype & (1ULL << j)) {
17346                                         printf(first_pctype ?
17347                                                "%02d" : ",%02d", j);
17348                                         first_pctype = 0;
17349                                 }
17350                         }
17351                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17352                 }
17353         }
17354 #endif
17355 }
17356
17357 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17358         .f = cmd_pctype_mapping_get_parsed,
17359         .data = NULL,
17360         .help_str = "show port <port_id> pctype mapping",
17361         .tokens = {
17362                 (void *)&cmd_pctype_mapping_get_show,
17363                 (void *)&cmd_pctype_mapping_get_port,
17364                 (void *)&cmd_pctype_mapping_get_port_id,
17365                 (void *)&cmd_pctype_mapping_get_pctype,
17366                 (void *)&cmd_pctype_mapping_get_mapping,
17367                 NULL,
17368         },
17369 };
17370
17371 /* port config pctype mapping update */
17372
17373 /* Common result structure for port config pctype mapping update */
17374 struct cmd_pctype_mapping_update_result {
17375         cmdline_fixed_string_t port;
17376         cmdline_fixed_string_t config;
17377         portid_t port_id;
17378         cmdline_fixed_string_t pctype;
17379         cmdline_fixed_string_t mapping;
17380         cmdline_fixed_string_t update;
17381         cmdline_fixed_string_t pctype_list;
17382         uint16_t flow_type;
17383 };
17384
17385 /* Common CLI fields for pctype mapping update*/
17386 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17387         TOKEN_STRING_INITIALIZER
17388                 (struct cmd_pctype_mapping_update_result,
17389                  port, "port");
17390 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17391         TOKEN_STRING_INITIALIZER
17392                 (struct cmd_pctype_mapping_update_result,
17393                  config, "config");
17394 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17395         TOKEN_NUM_INITIALIZER
17396                 (struct cmd_pctype_mapping_update_result,
17397                  port_id, UINT16);
17398 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17399         TOKEN_STRING_INITIALIZER
17400                 (struct cmd_pctype_mapping_update_result,
17401                  pctype, "pctype");
17402 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17403         TOKEN_STRING_INITIALIZER
17404                 (struct cmd_pctype_mapping_update_result,
17405                  mapping, "mapping");
17406 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17407         TOKEN_STRING_INITIALIZER
17408                 (struct cmd_pctype_mapping_update_result,
17409                  update, "update");
17410 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17411         TOKEN_STRING_INITIALIZER
17412                 (struct cmd_pctype_mapping_update_result,
17413                  pctype_list, NULL);
17414 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17415         TOKEN_NUM_INITIALIZER
17416                 (struct cmd_pctype_mapping_update_result,
17417                  flow_type, UINT16);
17418
17419 static void
17420 cmd_pctype_mapping_update_parsed(
17421         void *parsed_result,
17422         __attribute__((unused)) struct cmdline *cl,
17423         __attribute__((unused)) void *data)
17424 {
17425         struct cmd_pctype_mapping_update_result *res = parsed_result;
17426         int ret = -ENOTSUP;
17427 #ifdef RTE_LIBRTE_I40E_PMD
17428         struct rte_pmd_i40e_flow_type_mapping mapping;
17429         unsigned int i;
17430         unsigned int nb_item;
17431         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17432 #endif
17433
17434         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17435                 return;
17436
17437 #ifdef RTE_LIBRTE_I40E_PMD
17438         nb_item = parse_item_list(res->pctype_list, "pctypes",
17439                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17440         mapping.flow_type = res->flow_type;
17441         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17442                 mapping.pctype |= (1ULL << pctype_list[i]);
17443         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17444                                                 &mapping,
17445                                                 1,
17446                                                 0);
17447 #endif
17448
17449         switch (ret) {
17450         case 0:
17451                 break;
17452         case -EINVAL:
17453                 printf("invalid pctype or flow type\n");
17454                 break;
17455         case -ENODEV:
17456                 printf("invalid port_id %d\n", res->port_id);
17457                 break;
17458         case -ENOTSUP:
17459                 printf("function not implemented\n");
17460                 break;
17461         default:
17462                 printf("programming error: (%s)\n", strerror(-ret));
17463         }
17464 }
17465
17466 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17467         .f = cmd_pctype_mapping_update_parsed,
17468         .data = NULL,
17469         .help_str = "port config <port_id> pctype mapping update"
17470         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17471         .tokens = {
17472                 (void *)&cmd_pctype_mapping_update_port,
17473                 (void *)&cmd_pctype_mapping_update_config,
17474                 (void *)&cmd_pctype_mapping_update_port_id,
17475                 (void *)&cmd_pctype_mapping_update_pctype,
17476                 (void *)&cmd_pctype_mapping_update_mapping,
17477                 (void *)&cmd_pctype_mapping_update_update,
17478                 (void *)&cmd_pctype_mapping_update_pc_type,
17479                 (void *)&cmd_pctype_mapping_update_flow_type,
17480                 NULL,
17481         },
17482 };
17483
17484 /* ptype mapping get */
17485
17486 /* Common result structure for ptype mapping get */
17487 struct cmd_ptype_mapping_get_result {
17488         cmdline_fixed_string_t ptype;
17489         cmdline_fixed_string_t mapping;
17490         cmdline_fixed_string_t get;
17491         portid_t port_id;
17492         uint8_t valid_only;
17493 };
17494
17495 /* Common CLI fields for ptype mapping get */
17496 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17497         TOKEN_STRING_INITIALIZER
17498                 (struct cmd_ptype_mapping_get_result,
17499                  ptype, "ptype");
17500 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17501         TOKEN_STRING_INITIALIZER
17502                 (struct cmd_ptype_mapping_get_result,
17503                  mapping, "mapping");
17504 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17505         TOKEN_STRING_INITIALIZER
17506                 (struct cmd_ptype_mapping_get_result,
17507                  get, "get");
17508 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17509         TOKEN_NUM_INITIALIZER
17510                 (struct cmd_ptype_mapping_get_result,
17511                  port_id, UINT16);
17512 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17513         TOKEN_NUM_INITIALIZER
17514                 (struct cmd_ptype_mapping_get_result,
17515                  valid_only, UINT8);
17516
17517 static void
17518 cmd_ptype_mapping_get_parsed(
17519         void *parsed_result,
17520         __attribute__((unused)) struct cmdline *cl,
17521         __attribute__((unused)) void *data)
17522 {
17523         struct cmd_ptype_mapping_get_result *res = parsed_result;
17524         int ret = -ENOTSUP;
17525 #ifdef RTE_LIBRTE_I40E_PMD
17526         int max_ptype_num = 256;
17527         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17528         uint16_t count;
17529         int i;
17530 #endif
17531
17532         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17533                 return;
17534
17535 #ifdef RTE_LIBRTE_I40E_PMD
17536         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17537                                         mapping,
17538                                         max_ptype_num,
17539                                         &count,
17540                                         res->valid_only);
17541 #endif
17542
17543         switch (ret) {
17544         case 0:
17545                 break;
17546         case -ENODEV:
17547                 printf("invalid port_id %d\n", res->port_id);
17548                 break;
17549         case -ENOTSUP:
17550                 printf("function not implemented\n");
17551                 break;
17552         default:
17553                 printf("programming error: (%s)\n", strerror(-ret));
17554         }
17555
17556 #ifdef RTE_LIBRTE_I40E_PMD
17557         if (!ret) {
17558                 for (i = 0; i < count; i++)
17559                         printf("%3d\t0x%08x\n",
17560                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17561         }
17562 #endif
17563 }
17564
17565 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17566         .f = cmd_ptype_mapping_get_parsed,
17567         .data = NULL,
17568         .help_str = "ptype mapping get <port_id> <valid_only>",
17569         .tokens = {
17570                 (void *)&cmd_ptype_mapping_get_ptype,
17571                 (void *)&cmd_ptype_mapping_get_mapping,
17572                 (void *)&cmd_ptype_mapping_get_get,
17573                 (void *)&cmd_ptype_mapping_get_port_id,
17574                 (void *)&cmd_ptype_mapping_get_valid_only,
17575                 NULL,
17576         },
17577 };
17578
17579 /* ptype mapping replace */
17580
17581 /* Common result structure for ptype mapping replace */
17582 struct cmd_ptype_mapping_replace_result {
17583         cmdline_fixed_string_t ptype;
17584         cmdline_fixed_string_t mapping;
17585         cmdline_fixed_string_t replace;
17586         portid_t port_id;
17587         uint32_t target;
17588         uint8_t mask;
17589         uint32_t pkt_type;
17590 };
17591
17592 /* Common CLI fields for ptype mapping replace */
17593 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17594         TOKEN_STRING_INITIALIZER
17595                 (struct cmd_ptype_mapping_replace_result,
17596                  ptype, "ptype");
17597 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17598         TOKEN_STRING_INITIALIZER
17599                 (struct cmd_ptype_mapping_replace_result,
17600                  mapping, "mapping");
17601 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17602         TOKEN_STRING_INITIALIZER
17603                 (struct cmd_ptype_mapping_replace_result,
17604                  replace, "replace");
17605 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17606         TOKEN_NUM_INITIALIZER
17607                 (struct cmd_ptype_mapping_replace_result,
17608                  port_id, UINT16);
17609 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17610         TOKEN_NUM_INITIALIZER
17611                 (struct cmd_ptype_mapping_replace_result,
17612                  target, UINT32);
17613 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17614         TOKEN_NUM_INITIALIZER
17615                 (struct cmd_ptype_mapping_replace_result,
17616                  mask, UINT8);
17617 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17618         TOKEN_NUM_INITIALIZER
17619                 (struct cmd_ptype_mapping_replace_result,
17620                  pkt_type, UINT32);
17621
17622 static void
17623 cmd_ptype_mapping_replace_parsed(
17624         void *parsed_result,
17625         __attribute__((unused)) struct cmdline *cl,
17626         __attribute__((unused)) void *data)
17627 {
17628         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17629         int ret = -ENOTSUP;
17630
17631         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17632                 return;
17633
17634 #ifdef RTE_LIBRTE_I40E_PMD
17635         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17636                                         res->target,
17637                                         res->mask,
17638                                         res->pkt_type);
17639 #endif
17640
17641         switch (ret) {
17642         case 0:
17643                 break;
17644         case -EINVAL:
17645                 printf("invalid ptype 0x%8x or 0x%8x\n",
17646                                 res->target, res->pkt_type);
17647                 break;
17648         case -ENODEV:
17649                 printf("invalid port_id %d\n", res->port_id);
17650                 break;
17651         case -ENOTSUP:
17652                 printf("function not implemented\n");
17653                 break;
17654         default:
17655                 printf("programming error: (%s)\n", strerror(-ret));
17656         }
17657 }
17658
17659 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17660         .f = cmd_ptype_mapping_replace_parsed,
17661         .data = NULL,
17662         .help_str =
17663                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17664         .tokens = {
17665                 (void *)&cmd_ptype_mapping_replace_ptype,
17666                 (void *)&cmd_ptype_mapping_replace_mapping,
17667                 (void *)&cmd_ptype_mapping_replace_replace,
17668                 (void *)&cmd_ptype_mapping_replace_port_id,
17669                 (void *)&cmd_ptype_mapping_replace_target,
17670                 (void *)&cmd_ptype_mapping_replace_mask,
17671                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17672                 NULL,
17673         },
17674 };
17675
17676 /* ptype mapping reset */
17677
17678 /* Common result structure for ptype mapping reset */
17679 struct cmd_ptype_mapping_reset_result {
17680         cmdline_fixed_string_t ptype;
17681         cmdline_fixed_string_t mapping;
17682         cmdline_fixed_string_t reset;
17683         portid_t port_id;
17684 };
17685
17686 /* Common CLI fields for ptype mapping reset*/
17687 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17688         TOKEN_STRING_INITIALIZER
17689                 (struct cmd_ptype_mapping_reset_result,
17690                  ptype, "ptype");
17691 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17692         TOKEN_STRING_INITIALIZER
17693                 (struct cmd_ptype_mapping_reset_result,
17694                  mapping, "mapping");
17695 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17696         TOKEN_STRING_INITIALIZER
17697                 (struct cmd_ptype_mapping_reset_result,
17698                  reset, "reset");
17699 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17700         TOKEN_NUM_INITIALIZER
17701                 (struct cmd_ptype_mapping_reset_result,
17702                  port_id, UINT16);
17703
17704 static void
17705 cmd_ptype_mapping_reset_parsed(
17706         void *parsed_result,
17707         __attribute__((unused)) struct cmdline *cl,
17708         __attribute__((unused)) void *data)
17709 {
17710         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17711         int ret = -ENOTSUP;
17712
17713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17714                 return;
17715
17716 #ifdef RTE_LIBRTE_I40E_PMD
17717         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17718 #endif
17719
17720         switch (ret) {
17721         case 0:
17722                 break;
17723         case -ENODEV:
17724                 printf("invalid port_id %d\n", res->port_id);
17725                 break;
17726         case -ENOTSUP:
17727                 printf("function not implemented\n");
17728                 break;
17729         default:
17730                 printf("programming error: (%s)\n", strerror(-ret));
17731         }
17732 }
17733
17734 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17735         .f = cmd_ptype_mapping_reset_parsed,
17736         .data = NULL,
17737         .help_str = "ptype mapping reset <port_id>",
17738         .tokens = {
17739                 (void *)&cmd_ptype_mapping_reset_ptype,
17740                 (void *)&cmd_ptype_mapping_reset_mapping,
17741                 (void *)&cmd_ptype_mapping_reset_reset,
17742                 (void *)&cmd_ptype_mapping_reset_port_id,
17743                 NULL,
17744         },
17745 };
17746
17747 /* ptype mapping update */
17748
17749 /* Common result structure for ptype mapping update */
17750 struct cmd_ptype_mapping_update_result {
17751         cmdline_fixed_string_t ptype;
17752         cmdline_fixed_string_t mapping;
17753         cmdline_fixed_string_t reset;
17754         portid_t port_id;
17755         uint8_t hw_ptype;
17756         uint32_t sw_ptype;
17757 };
17758
17759 /* Common CLI fields for ptype mapping update*/
17760 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17761         TOKEN_STRING_INITIALIZER
17762                 (struct cmd_ptype_mapping_update_result,
17763                  ptype, "ptype");
17764 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17765         TOKEN_STRING_INITIALIZER
17766                 (struct cmd_ptype_mapping_update_result,
17767                  mapping, "mapping");
17768 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17769         TOKEN_STRING_INITIALIZER
17770                 (struct cmd_ptype_mapping_update_result,
17771                  reset, "update");
17772 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17773         TOKEN_NUM_INITIALIZER
17774                 (struct cmd_ptype_mapping_update_result,
17775                  port_id, UINT16);
17776 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17777         TOKEN_NUM_INITIALIZER
17778                 (struct cmd_ptype_mapping_update_result,
17779                  hw_ptype, UINT8);
17780 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17781         TOKEN_NUM_INITIALIZER
17782                 (struct cmd_ptype_mapping_update_result,
17783                  sw_ptype, UINT32);
17784
17785 static void
17786 cmd_ptype_mapping_update_parsed(
17787         void *parsed_result,
17788         __attribute__((unused)) struct cmdline *cl,
17789         __attribute__((unused)) void *data)
17790 {
17791         struct cmd_ptype_mapping_update_result *res = parsed_result;
17792         int ret = -ENOTSUP;
17793 #ifdef RTE_LIBRTE_I40E_PMD
17794         struct rte_pmd_i40e_ptype_mapping mapping;
17795 #endif
17796         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17797                 return;
17798
17799 #ifdef RTE_LIBRTE_I40E_PMD
17800         mapping.hw_ptype = res->hw_ptype;
17801         mapping.sw_ptype = res->sw_ptype;
17802         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17803                                                 &mapping,
17804                                                 1,
17805                                                 0);
17806 #endif
17807
17808         switch (ret) {
17809         case 0:
17810                 break;
17811         case -EINVAL:
17812                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17813                 break;
17814         case -ENODEV:
17815                 printf("invalid port_id %d\n", res->port_id);
17816                 break;
17817         case -ENOTSUP:
17818                 printf("function not implemented\n");
17819                 break;
17820         default:
17821                 printf("programming error: (%s)\n", strerror(-ret));
17822         }
17823 }
17824
17825 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17826         .f = cmd_ptype_mapping_update_parsed,
17827         .data = NULL,
17828         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17829         .tokens = {
17830                 (void *)&cmd_ptype_mapping_update_ptype,
17831                 (void *)&cmd_ptype_mapping_update_mapping,
17832                 (void *)&cmd_ptype_mapping_update_update,
17833                 (void *)&cmd_ptype_mapping_update_port_id,
17834                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17835                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17836                 NULL,
17837         },
17838 };
17839
17840 /* Common result structure for file commands */
17841 struct cmd_cmdfile_result {
17842         cmdline_fixed_string_t load;
17843         cmdline_fixed_string_t filename;
17844 };
17845
17846 /* Common CLI fields for file commands */
17847 cmdline_parse_token_string_t cmd_load_cmdfile =
17848         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17849 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17850         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17851
17852 static void
17853 cmd_load_from_file_parsed(
17854         void *parsed_result,
17855         __attribute__((unused)) struct cmdline *cl,
17856         __attribute__((unused)) void *data)
17857 {
17858         struct cmd_cmdfile_result *res = parsed_result;
17859
17860         cmdline_read_from_file(res->filename);
17861 }
17862
17863 cmdline_parse_inst_t cmd_load_from_file = {
17864         .f = cmd_load_from_file_parsed,
17865         .data = NULL,
17866         .help_str = "load <filename>",
17867         .tokens = {
17868                 (void *)&cmd_load_cmdfile,
17869                 (void *)&cmd_load_cmdfile_filename,
17870                 NULL,
17871         },
17872 };
17873
17874 /* Get Rx offloads capabilities */
17875 struct cmd_rx_offload_get_capa_result {
17876         cmdline_fixed_string_t show;
17877         cmdline_fixed_string_t port;
17878         portid_t port_id;
17879         cmdline_fixed_string_t rx_offload;
17880         cmdline_fixed_string_t capabilities;
17881 };
17882
17883 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17884         TOKEN_STRING_INITIALIZER
17885                 (struct cmd_rx_offload_get_capa_result,
17886                  show, "show");
17887 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17888         TOKEN_STRING_INITIALIZER
17889                 (struct cmd_rx_offload_get_capa_result,
17890                  port, "port");
17891 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17892         TOKEN_NUM_INITIALIZER
17893                 (struct cmd_rx_offload_get_capa_result,
17894                  port_id, UINT16);
17895 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17896         TOKEN_STRING_INITIALIZER
17897                 (struct cmd_rx_offload_get_capa_result,
17898                  rx_offload, "rx_offload");
17899 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17900         TOKEN_STRING_INITIALIZER
17901                 (struct cmd_rx_offload_get_capa_result,
17902                  capabilities, "capabilities");
17903
17904 static void
17905 print_rx_offloads(uint64_t offloads)
17906 {
17907         uint64_t single_offload;
17908         int begin;
17909         int end;
17910         int bit;
17911
17912         if (offloads == 0)
17913                 return;
17914
17915         begin = __builtin_ctzll(offloads);
17916         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17917
17918         single_offload = 1ULL << begin;
17919         for (bit = begin; bit < end; bit++) {
17920                 if (offloads & single_offload)
17921                         printf(" %s",
17922                                rte_eth_dev_rx_offload_name(single_offload));
17923                 single_offload <<= 1;
17924         }
17925 }
17926
17927 static void
17928 cmd_rx_offload_get_capa_parsed(
17929         void *parsed_result,
17930         __attribute__((unused)) struct cmdline *cl,
17931         __attribute__((unused)) void *data)
17932 {
17933         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17934         struct rte_eth_dev_info dev_info;
17935         portid_t port_id = res->port_id;
17936         uint64_t queue_offloads;
17937         uint64_t port_offloads;
17938         int ret;
17939
17940         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17941         if (ret != 0)
17942                 return;
17943
17944         queue_offloads = dev_info.rx_queue_offload_capa;
17945         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17946
17947         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17948         printf("  Per Queue :");
17949         print_rx_offloads(queue_offloads);
17950
17951         printf("\n");
17952         printf("  Per Port  :");
17953         print_rx_offloads(port_offloads);
17954         printf("\n\n");
17955 }
17956
17957 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17958         .f = cmd_rx_offload_get_capa_parsed,
17959         .data = NULL,
17960         .help_str = "show port <port_id> rx_offload capabilities",
17961         .tokens = {
17962                 (void *)&cmd_rx_offload_get_capa_show,
17963                 (void *)&cmd_rx_offload_get_capa_port,
17964                 (void *)&cmd_rx_offload_get_capa_port_id,
17965                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17966                 (void *)&cmd_rx_offload_get_capa_capabilities,
17967                 NULL,
17968         }
17969 };
17970
17971 /* Get Rx offloads configuration */
17972 struct cmd_rx_offload_get_configuration_result {
17973         cmdline_fixed_string_t show;
17974         cmdline_fixed_string_t port;
17975         portid_t port_id;
17976         cmdline_fixed_string_t rx_offload;
17977         cmdline_fixed_string_t configuration;
17978 };
17979
17980 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17981         TOKEN_STRING_INITIALIZER
17982                 (struct cmd_rx_offload_get_configuration_result,
17983                  show, "show");
17984 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17985         TOKEN_STRING_INITIALIZER
17986                 (struct cmd_rx_offload_get_configuration_result,
17987                  port, "port");
17988 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17989         TOKEN_NUM_INITIALIZER
17990                 (struct cmd_rx_offload_get_configuration_result,
17991                  port_id, UINT16);
17992 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17993         TOKEN_STRING_INITIALIZER
17994                 (struct cmd_rx_offload_get_configuration_result,
17995                  rx_offload, "rx_offload");
17996 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17997         TOKEN_STRING_INITIALIZER
17998                 (struct cmd_rx_offload_get_configuration_result,
17999                  configuration, "configuration");
18000
18001 static void
18002 cmd_rx_offload_get_configuration_parsed(
18003         void *parsed_result,
18004         __attribute__((unused)) struct cmdline *cl,
18005         __attribute__((unused)) void *data)
18006 {
18007         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18008         struct rte_eth_dev_info dev_info;
18009         portid_t port_id = res->port_id;
18010         struct rte_port *port = &ports[port_id];
18011         uint64_t port_offloads;
18012         uint64_t queue_offloads;
18013         uint16_t nb_rx_queues;
18014         int q;
18015         int ret;
18016
18017         printf("Rx Offloading Configuration of port %d :\n", port_id);
18018
18019         port_offloads = port->dev_conf.rxmode.offloads;
18020         printf("  Port :");
18021         print_rx_offloads(port_offloads);
18022         printf("\n");
18023
18024         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18025         if (ret != 0)
18026                 return;
18027
18028         nb_rx_queues = dev_info.nb_rx_queues;
18029         for (q = 0; q < nb_rx_queues; q++) {
18030                 queue_offloads = port->rx_conf[q].offloads;
18031                 printf("  Queue[%2d] :", q);
18032                 print_rx_offloads(queue_offloads);
18033                 printf("\n");
18034         }
18035         printf("\n");
18036 }
18037
18038 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18039         .f = cmd_rx_offload_get_configuration_parsed,
18040         .data = NULL,
18041         .help_str = "show port <port_id> rx_offload configuration",
18042         .tokens = {
18043                 (void *)&cmd_rx_offload_get_configuration_show,
18044                 (void *)&cmd_rx_offload_get_configuration_port,
18045                 (void *)&cmd_rx_offload_get_configuration_port_id,
18046                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18047                 (void *)&cmd_rx_offload_get_configuration_configuration,
18048                 NULL,
18049         }
18050 };
18051
18052 /* Enable/Disable a per port offloading */
18053 struct cmd_config_per_port_rx_offload_result {
18054         cmdline_fixed_string_t port;
18055         cmdline_fixed_string_t config;
18056         portid_t port_id;
18057         cmdline_fixed_string_t rx_offload;
18058         cmdline_fixed_string_t offload;
18059         cmdline_fixed_string_t on_off;
18060 };
18061
18062 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18063         TOKEN_STRING_INITIALIZER
18064                 (struct cmd_config_per_port_rx_offload_result,
18065                  port, "port");
18066 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18067         TOKEN_STRING_INITIALIZER
18068                 (struct cmd_config_per_port_rx_offload_result,
18069                  config, "config");
18070 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18071         TOKEN_NUM_INITIALIZER
18072                 (struct cmd_config_per_port_rx_offload_result,
18073                  port_id, UINT16);
18074 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18075         TOKEN_STRING_INITIALIZER
18076                 (struct cmd_config_per_port_rx_offload_result,
18077                  rx_offload, "rx_offload");
18078 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18079         TOKEN_STRING_INITIALIZER
18080                 (struct cmd_config_per_port_rx_offload_result,
18081                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18082                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18083                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18084                            "scatter#timestamp#security#keep_crc");
18085 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18086         TOKEN_STRING_INITIALIZER
18087                 (struct cmd_config_per_port_rx_offload_result,
18088                  on_off, "on#off");
18089
18090 static uint64_t
18091 search_rx_offload(const char *name)
18092 {
18093         uint64_t single_offload;
18094         const char *single_name;
18095         int found = 0;
18096         unsigned int bit;
18097
18098         single_offload = 1;
18099         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18100                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18101                 if (!strcasecmp(single_name, name)) {
18102                         found = 1;
18103                         break;
18104                 }
18105                 single_offload <<= 1;
18106         }
18107
18108         if (found)
18109                 return single_offload;
18110
18111         return 0;
18112 }
18113
18114 static void
18115 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18116                                 __attribute__((unused)) struct cmdline *cl,
18117                                 __attribute__((unused)) void *data)
18118 {
18119         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18120         portid_t port_id = res->port_id;
18121         struct rte_eth_dev_info dev_info;
18122         struct rte_port *port = &ports[port_id];
18123         uint64_t single_offload;
18124         uint16_t nb_rx_queues;
18125         int q;
18126         int ret;
18127
18128         if (port->port_status != RTE_PORT_STOPPED) {
18129                 printf("Error: Can't config offload when Port %d "
18130                        "is not stopped\n", port_id);
18131                 return;
18132         }
18133
18134         single_offload = search_rx_offload(res->offload);
18135         if (single_offload == 0) {
18136                 printf("Unknown offload name: %s\n", res->offload);
18137                 return;
18138         }
18139
18140         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18141         if (ret != 0)
18142                 return;
18143
18144         nb_rx_queues = dev_info.nb_rx_queues;
18145         if (!strcmp(res->on_off, "on")) {
18146                 port->dev_conf.rxmode.offloads |= single_offload;
18147                 for (q = 0; q < nb_rx_queues; q++)
18148                         port->rx_conf[q].offloads |= single_offload;
18149         } else {
18150                 port->dev_conf.rxmode.offloads &= ~single_offload;
18151                 for (q = 0; q < nb_rx_queues; q++)
18152                         port->rx_conf[q].offloads &= ~single_offload;
18153         }
18154
18155         cmd_reconfig_device_queue(port_id, 1, 1);
18156 }
18157
18158 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18159         .f = cmd_config_per_port_rx_offload_parsed,
18160         .data = NULL,
18161         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18162                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18163                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18164                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18165                     "on|off",
18166         .tokens = {
18167                 (void *)&cmd_config_per_port_rx_offload_result_port,
18168                 (void *)&cmd_config_per_port_rx_offload_result_config,
18169                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18170                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18171                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18172                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18173                 NULL,
18174         }
18175 };
18176
18177 /* Enable/Disable a per queue offloading */
18178 struct cmd_config_per_queue_rx_offload_result {
18179         cmdline_fixed_string_t port;
18180         portid_t port_id;
18181         cmdline_fixed_string_t rxq;
18182         uint16_t queue_id;
18183         cmdline_fixed_string_t rx_offload;
18184         cmdline_fixed_string_t offload;
18185         cmdline_fixed_string_t on_off;
18186 };
18187
18188 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18189         TOKEN_STRING_INITIALIZER
18190                 (struct cmd_config_per_queue_rx_offload_result,
18191                  port, "port");
18192 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18193         TOKEN_NUM_INITIALIZER
18194                 (struct cmd_config_per_queue_rx_offload_result,
18195                  port_id, UINT16);
18196 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18197         TOKEN_STRING_INITIALIZER
18198                 (struct cmd_config_per_queue_rx_offload_result,
18199                  rxq, "rxq");
18200 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18201         TOKEN_NUM_INITIALIZER
18202                 (struct cmd_config_per_queue_rx_offload_result,
18203                  queue_id, UINT16);
18204 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18205         TOKEN_STRING_INITIALIZER
18206                 (struct cmd_config_per_queue_rx_offload_result,
18207                  rx_offload, "rx_offload");
18208 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18209         TOKEN_STRING_INITIALIZER
18210                 (struct cmd_config_per_queue_rx_offload_result,
18211                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18212                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18213                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18214                            "scatter#timestamp#security#keep_crc");
18215 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18216         TOKEN_STRING_INITIALIZER
18217                 (struct cmd_config_per_queue_rx_offload_result,
18218                  on_off, "on#off");
18219
18220 static void
18221 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18222                                 __attribute__((unused)) struct cmdline *cl,
18223                                 __attribute__((unused)) void *data)
18224 {
18225         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18226         struct rte_eth_dev_info dev_info;
18227         portid_t port_id = res->port_id;
18228         uint16_t queue_id = res->queue_id;
18229         struct rte_port *port = &ports[port_id];
18230         uint64_t single_offload;
18231         int ret;
18232
18233         if (port->port_status != RTE_PORT_STOPPED) {
18234                 printf("Error: Can't config offload when Port %d "
18235                        "is not stopped\n", port_id);
18236                 return;
18237         }
18238
18239         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18240         if (ret != 0)
18241                 return;
18242
18243         if (queue_id >= dev_info.nb_rx_queues) {
18244                 printf("Error: input queue_id should be 0 ... "
18245                        "%d\n", dev_info.nb_rx_queues - 1);
18246                 return;
18247         }
18248
18249         single_offload = search_rx_offload(res->offload);
18250         if (single_offload == 0) {
18251                 printf("Unknown offload name: %s\n", res->offload);
18252                 return;
18253         }
18254
18255         if (!strcmp(res->on_off, "on"))
18256                 port->rx_conf[queue_id].offloads |= single_offload;
18257         else
18258                 port->rx_conf[queue_id].offloads &= ~single_offload;
18259
18260         cmd_reconfig_device_queue(port_id, 1, 1);
18261 }
18262
18263 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18264         .f = cmd_config_per_queue_rx_offload_parsed,
18265         .data = NULL,
18266         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18267                     "vlan_strip|ipv4_cksum|"
18268                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18269                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18270                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18271                     "on|off",
18272         .tokens = {
18273                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18274                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18275                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18276                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18277                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18278                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18279                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18280                 NULL,
18281         }
18282 };
18283
18284 /* Get Tx offloads capabilities */
18285 struct cmd_tx_offload_get_capa_result {
18286         cmdline_fixed_string_t show;
18287         cmdline_fixed_string_t port;
18288         portid_t port_id;
18289         cmdline_fixed_string_t tx_offload;
18290         cmdline_fixed_string_t capabilities;
18291 };
18292
18293 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18294         TOKEN_STRING_INITIALIZER
18295                 (struct cmd_tx_offload_get_capa_result,
18296                  show, "show");
18297 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18298         TOKEN_STRING_INITIALIZER
18299                 (struct cmd_tx_offload_get_capa_result,
18300                  port, "port");
18301 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18302         TOKEN_NUM_INITIALIZER
18303                 (struct cmd_tx_offload_get_capa_result,
18304                  port_id, UINT16);
18305 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18306         TOKEN_STRING_INITIALIZER
18307                 (struct cmd_tx_offload_get_capa_result,
18308                  tx_offload, "tx_offload");
18309 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18310         TOKEN_STRING_INITIALIZER
18311                 (struct cmd_tx_offload_get_capa_result,
18312                  capabilities, "capabilities");
18313
18314 static void
18315 print_tx_offloads(uint64_t offloads)
18316 {
18317         uint64_t single_offload;
18318         int begin;
18319         int end;
18320         int bit;
18321
18322         if (offloads == 0)
18323                 return;
18324
18325         begin = __builtin_ctzll(offloads);
18326         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18327
18328         single_offload = 1ULL << begin;
18329         for (bit = begin; bit < end; bit++) {
18330                 if (offloads & single_offload)
18331                         printf(" %s",
18332                                rte_eth_dev_tx_offload_name(single_offload));
18333                 single_offload <<= 1;
18334         }
18335 }
18336
18337 static void
18338 cmd_tx_offload_get_capa_parsed(
18339         void *parsed_result,
18340         __attribute__((unused)) struct cmdline *cl,
18341         __attribute__((unused)) void *data)
18342 {
18343         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18344         struct rte_eth_dev_info dev_info;
18345         portid_t port_id = res->port_id;
18346         uint64_t queue_offloads;
18347         uint64_t port_offloads;
18348         int ret;
18349
18350         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18351         if (ret != 0)
18352                 return;
18353
18354         queue_offloads = dev_info.tx_queue_offload_capa;
18355         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18356
18357         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18358         printf("  Per Queue :");
18359         print_tx_offloads(queue_offloads);
18360
18361         printf("\n");
18362         printf("  Per Port  :");
18363         print_tx_offloads(port_offloads);
18364         printf("\n\n");
18365 }
18366
18367 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18368         .f = cmd_tx_offload_get_capa_parsed,
18369         .data = NULL,
18370         .help_str = "show port <port_id> tx_offload capabilities",
18371         .tokens = {
18372                 (void *)&cmd_tx_offload_get_capa_show,
18373                 (void *)&cmd_tx_offload_get_capa_port,
18374                 (void *)&cmd_tx_offload_get_capa_port_id,
18375                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18376                 (void *)&cmd_tx_offload_get_capa_capabilities,
18377                 NULL,
18378         }
18379 };
18380
18381 /* Get Tx offloads configuration */
18382 struct cmd_tx_offload_get_configuration_result {
18383         cmdline_fixed_string_t show;
18384         cmdline_fixed_string_t port;
18385         portid_t port_id;
18386         cmdline_fixed_string_t tx_offload;
18387         cmdline_fixed_string_t configuration;
18388 };
18389
18390 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18391         TOKEN_STRING_INITIALIZER
18392                 (struct cmd_tx_offload_get_configuration_result,
18393                  show, "show");
18394 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18395         TOKEN_STRING_INITIALIZER
18396                 (struct cmd_tx_offload_get_configuration_result,
18397                  port, "port");
18398 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18399         TOKEN_NUM_INITIALIZER
18400                 (struct cmd_tx_offload_get_configuration_result,
18401                  port_id, UINT16);
18402 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18403         TOKEN_STRING_INITIALIZER
18404                 (struct cmd_tx_offload_get_configuration_result,
18405                  tx_offload, "tx_offload");
18406 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18407         TOKEN_STRING_INITIALIZER
18408                 (struct cmd_tx_offload_get_configuration_result,
18409                  configuration, "configuration");
18410
18411 static void
18412 cmd_tx_offload_get_configuration_parsed(
18413         void *parsed_result,
18414         __attribute__((unused)) struct cmdline *cl,
18415         __attribute__((unused)) void *data)
18416 {
18417         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18418         struct rte_eth_dev_info dev_info;
18419         portid_t port_id = res->port_id;
18420         struct rte_port *port = &ports[port_id];
18421         uint64_t port_offloads;
18422         uint64_t queue_offloads;
18423         uint16_t nb_tx_queues;
18424         int q;
18425         int ret;
18426
18427         printf("Tx Offloading Configuration of port %d :\n", port_id);
18428
18429         port_offloads = port->dev_conf.txmode.offloads;
18430         printf("  Port :");
18431         print_tx_offloads(port_offloads);
18432         printf("\n");
18433
18434         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18435         if (ret != 0)
18436                 return;
18437
18438         nb_tx_queues = dev_info.nb_tx_queues;
18439         for (q = 0; q < nb_tx_queues; q++) {
18440                 queue_offloads = port->tx_conf[q].offloads;
18441                 printf("  Queue[%2d] :", q);
18442                 print_tx_offloads(queue_offloads);
18443                 printf("\n");
18444         }
18445         printf("\n");
18446 }
18447
18448 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18449         .f = cmd_tx_offload_get_configuration_parsed,
18450         .data = NULL,
18451         .help_str = "show port <port_id> tx_offload configuration",
18452         .tokens = {
18453                 (void *)&cmd_tx_offload_get_configuration_show,
18454                 (void *)&cmd_tx_offload_get_configuration_port,
18455                 (void *)&cmd_tx_offload_get_configuration_port_id,
18456                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18457                 (void *)&cmd_tx_offload_get_configuration_configuration,
18458                 NULL,
18459         }
18460 };
18461
18462 /* Enable/Disable a per port offloading */
18463 struct cmd_config_per_port_tx_offload_result {
18464         cmdline_fixed_string_t port;
18465         cmdline_fixed_string_t config;
18466         portid_t port_id;
18467         cmdline_fixed_string_t tx_offload;
18468         cmdline_fixed_string_t offload;
18469         cmdline_fixed_string_t on_off;
18470 };
18471
18472 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18473         TOKEN_STRING_INITIALIZER
18474                 (struct cmd_config_per_port_tx_offload_result,
18475                  port, "port");
18476 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18477         TOKEN_STRING_INITIALIZER
18478                 (struct cmd_config_per_port_tx_offload_result,
18479                  config, "config");
18480 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18481         TOKEN_NUM_INITIALIZER
18482                 (struct cmd_config_per_port_tx_offload_result,
18483                  port_id, UINT16);
18484 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18485         TOKEN_STRING_INITIALIZER
18486                 (struct cmd_config_per_port_tx_offload_result,
18487                  tx_offload, "tx_offload");
18488 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18489         TOKEN_STRING_INITIALIZER
18490                 (struct cmd_config_per_port_tx_offload_result,
18491                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18492                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18493                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18494                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18495                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18496                           "match_metadata");
18497 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18498         TOKEN_STRING_INITIALIZER
18499                 (struct cmd_config_per_port_tx_offload_result,
18500                  on_off, "on#off");
18501
18502 static uint64_t
18503 search_tx_offload(const char *name)
18504 {
18505         uint64_t single_offload;
18506         const char *single_name;
18507         int found = 0;
18508         unsigned int bit;
18509
18510         single_offload = 1;
18511         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18512                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18513                 if (single_name == NULL)
18514                         break;
18515                 if (!strcasecmp(single_name, name)) {
18516                         found = 1;
18517                         break;
18518                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18519                         break;
18520                 single_offload <<= 1;
18521         }
18522
18523         if (found)
18524                 return single_offload;
18525
18526         return 0;
18527 }
18528
18529 static void
18530 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18531                                 __attribute__((unused)) struct cmdline *cl,
18532                                 __attribute__((unused)) void *data)
18533 {
18534         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18535         portid_t port_id = res->port_id;
18536         struct rte_eth_dev_info dev_info;
18537         struct rte_port *port = &ports[port_id];
18538         uint64_t single_offload;
18539         uint16_t nb_tx_queues;
18540         int q;
18541         int ret;
18542
18543         if (port->port_status != RTE_PORT_STOPPED) {
18544                 printf("Error: Can't config offload when Port %d "
18545                        "is not stopped\n", port_id);
18546                 return;
18547         }
18548
18549         single_offload = search_tx_offload(res->offload);
18550         if (single_offload == 0) {
18551                 printf("Unknown offload name: %s\n", res->offload);
18552                 return;
18553         }
18554
18555         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18556         if (ret != 0)
18557                 return;
18558
18559         nb_tx_queues = dev_info.nb_tx_queues;
18560         if (!strcmp(res->on_off, "on")) {
18561                 port->dev_conf.txmode.offloads |= single_offload;
18562                 for (q = 0; q < nb_tx_queues; q++)
18563                         port->tx_conf[q].offloads |= single_offload;
18564         } else {
18565                 port->dev_conf.txmode.offloads &= ~single_offload;
18566                 for (q = 0; q < nb_tx_queues; q++)
18567                         port->tx_conf[q].offloads &= ~single_offload;
18568         }
18569
18570         cmd_reconfig_device_queue(port_id, 1, 1);
18571 }
18572
18573 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18574         .f = cmd_config_per_port_tx_offload_parsed,
18575         .data = NULL,
18576         .help_str = "port config <port_id> tx_offload "
18577                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18578                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18579                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18580                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18581                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18582                     "match_metadata on|off",
18583         .tokens = {
18584                 (void *)&cmd_config_per_port_tx_offload_result_port,
18585                 (void *)&cmd_config_per_port_tx_offload_result_config,
18586                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18587                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18588                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18589                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18590                 NULL,
18591         }
18592 };
18593
18594 /* Enable/Disable a per queue offloading */
18595 struct cmd_config_per_queue_tx_offload_result {
18596         cmdline_fixed_string_t port;
18597         portid_t port_id;
18598         cmdline_fixed_string_t txq;
18599         uint16_t queue_id;
18600         cmdline_fixed_string_t tx_offload;
18601         cmdline_fixed_string_t offload;
18602         cmdline_fixed_string_t on_off;
18603 };
18604
18605 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18606         TOKEN_STRING_INITIALIZER
18607                 (struct cmd_config_per_queue_tx_offload_result,
18608                  port, "port");
18609 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18610         TOKEN_NUM_INITIALIZER
18611                 (struct cmd_config_per_queue_tx_offload_result,
18612                  port_id, UINT16);
18613 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18614         TOKEN_STRING_INITIALIZER
18615                 (struct cmd_config_per_queue_tx_offload_result,
18616                  txq, "txq");
18617 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18618         TOKEN_NUM_INITIALIZER
18619                 (struct cmd_config_per_queue_tx_offload_result,
18620                  queue_id, UINT16);
18621 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18622         TOKEN_STRING_INITIALIZER
18623                 (struct cmd_config_per_queue_tx_offload_result,
18624                  tx_offload, "tx_offload");
18625 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18626         TOKEN_STRING_INITIALIZER
18627                 (struct cmd_config_per_queue_tx_offload_result,
18628                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18629                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18630                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18631                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18632                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18633 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18634         TOKEN_STRING_INITIALIZER
18635                 (struct cmd_config_per_queue_tx_offload_result,
18636                  on_off, "on#off");
18637
18638 static void
18639 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18640                                 __attribute__((unused)) struct cmdline *cl,
18641                                 __attribute__((unused)) void *data)
18642 {
18643         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18644         struct rte_eth_dev_info dev_info;
18645         portid_t port_id = res->port_id;
18646         uint16_t queue_id = res->queue_id;
18647         struct rte_port *port = &ports[port_id];
18648         uint64_t single_offload;
18649         int ret;
18650
18651         if (port->port_status != RTE_PORT_STOPPED) {
18652                 printf("Error: Can't config offload when Port %d "
18653                        "is not stopped\n", port_id);
18654                 return;
18655         }
18656
18657         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18658         if (ret != 0)
18659                 return;
18660
18661         if (queue_id >= dev_info.nb_tx_queues) {
18662                 printf("Error: input queue_id should be 0 ... "
18663                        "%d\n", dev_info.nb_tx_queues - 1);
18664                 return;
18665         }
18666
18667         single_offload = search_tx_offload(res->offload);
18668         if (single_offload == 0) {
18669                 printf("Unknown offload name: %s\n", res->offload);
18670                 return;
18671         }
18672
18673         if (!strcmp(res->on_off, "on"))
18674                 port->tx_conf[queue_id].offloads |= single_offload;
18675         else
18676                 port->tx_conf[queue_id].offloads &= ~single_offload;
18677
18678         cmd_reconfig_device_queue(port_id, 1, 1);
18679 }
18680
18681 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18682         .f = cmd_config_per_queue_tx_offload_parsed,
18683         .data = NULL,
18684         .help_str = "port <port_id> txq <queue_id> tx_offload "
18685                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18686                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18687                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18688                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18689                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18690                     "on|off",
18691         .tokens = {
18692                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18693                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18694                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18695                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18696                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18697                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18698                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18699                 NULL,
18700         }
18701 };
18702
18703 /* *** configure tx_metadata for specific port *** */
18704 struct cmd_config_tx_metadata_specific_result {
18705         cmdline_fixed_string_t port;
18706         cmdline_fixed_string_t keyword;
18707         uint16_t port_id;
18708         cmdline_fixed_string_t item;
18709         uint32_t value;
18710 };
18711
18712 static void
18713 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18714                                 __attribute__((unused)) struct cmdline *cl,
18715                                 __attribute__((unused)) void *data)
18716 {
18717         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18718
18719         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18720                 return;
18721         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18722         /* Add/remove callback to insert valid metadata in every Tx packet. */
18723         if (ports[res->port_id].tx_metadata)
18724                 add_tx_md_callback(res->port_id);
18725         else
18726                 remove_tx_md_callback(res->port_id);
18727 }
18728
18729 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18730         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18731                         port, "port");
18732 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18733         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18734                         keyword, "config");
18735 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18736         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18737                         port_id, UINT16);
18738 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18739         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18740                         item, "tx_metadata");
18741 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18742         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18743                         value, UINT32);
18744
18745 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18746         .f = cmd_config_tx_metadata_specific_parsed,
18747         .data = NULL,
18748         .help_str = "port config <port_id> tx_metadata <value>",
18749         .tokens = {
18750                 (void *)&cmd_config_tx_metadata_specific_port,
18751                 (void *)&cmd_config_tx_metadata_specific_keyword,
18752                 (void *)&cmd_config_tx_metadata_specific_id,
18753                 (void *)&cmd_config_tx_metadata_specific_item,
18754                 (void *)&cmd_config_tx_metadata_specific_value,
18755                 NULL,
18756         },
18757 };
18758
18759 /* *** display tx_metadata per port configuration *** */
18760 struct cmd_show_tx_metadata_result {
18761         cmdline_fixed_string_t cmd_show;
18762         cmdline_fixed_string_t cmd_port;
18763         cmdline_fixed_string_t cmd_keyword;
18764         portid_t cmd_pid;
18765 };
18766
18767 static void
18768 cmd_show_tx_metadata_parsed(void *parsed_result,
18769                 __attribute__((unused)) struct cmdline *cl,
18770                 __attribute__((unused)) void *data)
18771 {
18772         struct cmd_show_tx_metadata_result *res = parsed_result;
18773
18774         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18775                 printf("invalid port id %u\n", res->cmd_pid);
18776                 return;
18777         }
18778         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18779                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18780                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18781         }
18782 }
18783
18784 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18785         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18786                         cmd_show, "show");
18787 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18788         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18789                         cmd_port, "port");
18790 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18791         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18792                         cmd_pid, UINT16);
18793 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18794         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18795                         cmd_keyword, "tx_metadata");
18796
18797 cmdline_parse_inst_t cmd_show_tx_metadata = {
18798         .f = cmd_show_tx_metadata_parsed,
18799         .data = NULL,
18800         .help_str = "show port <port_id> tx_metadata",
18801         .tokens = {
18802                 (void *)&cmd_show_tx_metadata_show,
18803                 (void *)&cmd_show_tx_metadata_port,
18804                 (void *)&cmd_show_tx_metadata_pid,
18805                 (void *)&cmd_show_tx_metadata_keyword,
18806                 NULL,
18807         },
18808 };
18809
18810 /* show port supported ptypes */
18811
18812 /* Common result structure for show port ptypes */
18813 struct cmd_show_port_supported_ptypes_result {
18814         cmdline_fixed_string_t show;
18815         cmdline_fixed_string_t port;
18816         portid_t port_id;
18817         cmdline_fixed_string_t ptypes;
18818 };
18819
18820 /* Common CLI fields for show port ptypes */
18821 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18822         TOKEN_STRING_INITIALIZER
18823                 (struct cmd_show_port_supported_ptypes_result,
18824                  show, "show");
18825 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18826         TOKEN_STRING_INITIALIZER
18827                 (struct cmd_show_port_supported_ptypes_result,
18828                  port, "port");
18829 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
18830         TOKEN_NUM_INITIALIZER
18831                 (struct cmd_show_port_supported_ptypes_result,
18832                  port_id, UINT16);
18833 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
18834         TOKEN_STRING_INITIALIZER
18835                 (struct cmd_show_port_supported_ptypes_result,
18836                  ptypes, "ptypes");
18837
18838 static void
18839 cmd_show_port_supported_ptypes_parsed(
18840         void *parsed_result,
18841         __attribute__((unused)) struct cmdline *cl,
18842         __attribute__((unused)) void *data)
18843 {
18844 #define RSVD_PTYPE_MASK       0xf0000000
18845 #define MAX_PTYPES_PER_LAYER  16
18846 #define LTYPE_NAMESIZE        32
18847 #define PTYPE_NAMESIZE        256
18848         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
18849         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
18850         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
18851         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
18852         uint16_t port_id = res->port_id;
18853         int ret, i;
18854
18855         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
18856         if (ret < 0)
18857                 return;
18858
18859         while (ptype_mask != RSVD_PTYPE_MASK) {
18860
18861                 switch (ptype_mask) {
18862                 case RTE_PTYPE_L2_MASK:
18863                         strlcpy(ltype, "L2", sizeof(ltype));
18864                         break;
18865                 case RTE_PTYPE_L3_MASK:
18866                         strlcpy(ltype, "L3", sizeof(ltype));
18867                         break;
18868                 case RTE_PTYPE_L4_MASK:
18869                         strlcpy(ltype, "L4", sizeof(ltype));
18870                         break;
18871                 case RTE_PTYPE_TUNNEL_MASK:
18872                         strlcpy(ltype, "Tunnel", sizeof(ltype));
18873                         break;
18874                 case RTE_PTYPE_INNER_L2_MASK:
18875                         strlcpy(ltype, "Inner L2", sizeof(ltype));
18876                         break;
18877                 case RTE_PTYPE_INNER_L3_MASK:
18878                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18879                         break;
18880                 case RTE_PTYPE_INNER_L4_MASK:
18881                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18882                         break;
18883                 default:
18884                         return;
18885                 }
18886
18887                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18888                                                        ptype_mask, ptypes,
18889                                                        MAX_PTYPES_PER_LAYER);
18890
18891                 if (ret > 0)
18892                         printf("Supported %s ptypes:\n", ltype);
18893                 else
18894                         printf("%s ptypes unsupported\n", ltype);
18895
18896                 for (i = 0; i < ret; ++i) {
18897                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18898                         printf("%s\n", buf);
18899                 }
18900
18901                 ptype_mask <<= 4;
18902         }
18903 }
18904
18905 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18906         .f = cmd_show_port_supported_ptypes_parsed,
18907         .data = NULL,
18908         .help_str = "show port <port_id> ptypes",
18909         .tokens = {
18910                 (void *)&cmd_show_port_supported_ptypes_show,
18911                 (void *)&cmd_show_port_supported_ptypes_port,
18912                 (void *)&cmd_show_port_supported_ptypes_port_id,
18913                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18914                 NULL,
18915         },
18916 };
18917
18918 /* ******************************************************************************** */
18919
18920 /* list of instructions */
18921 cmdline_parse_ctx_t main_ctx[] = {
18922         (cmdline_parse_inst_t *)&cmd_help_brief,
18923         (cmdline_parse_inst_t *)&cmd_help_long,
18924         (cmdline_parse_inst_t *)&cmd_quit,
18925         (cmdline_parse_inst_t *)&cmd_load_from_file,
18926         (cmdline_parse_inst_t *)&cmd_showport,
18927         (cmdline_parse_inst_t *)&cmd_showqueue,
18928         (cmdline_parse_inst_t *)&cmd_showportall,
18929         (cmdline_parse_inst_t *)&cmd_showdevice,
18930         (cmdline_parse_inst_t *)&cmd_showcfg,
18931         (cmdline_parse_inst_t *)&cmd_showfwdall,
18932         (cmdline_parse_inst_t *)&cmd_start,
18933         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18934         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18935         (cmdline_parse_inst_t *)&cmd_set_link_up,
18936         (cmdline_parse_inst_t *)&cmd_set_link_down,
18937         (cmdline_parse_inst_t *)&cmd_reset,
18938         (cmdline_parse_inst_t *)&cmd_set_numbers,
18939         (cmdline_parse_inst_t *)&cmd_set_log,
18940         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18941         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18942         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18943         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18944         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18945         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18946         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18947         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18948         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18949         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18950         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18951         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18952         (cmdline_parse_inst_t *)&cmd_set_link_check,
18953         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18954         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18955         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18956         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18957 #ifdef RTE_LIBRTE_PMD_BOND
18958         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18959         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18960         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18961         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18962         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18963         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18964         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18965         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18966         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18967         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18968         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18969 #endif
18970         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18971         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18972         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18973         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18974         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18975         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18976         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18977         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18978         (cmdline_parse_inst_t *)&cmd_csum_set,
18979         (cmdline_parse_inst_t *)&cmd_csum_show,
18980         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18981         (cmdline_parse_inst_t *)&cmd_tso_set,
18982         (cmdline_parse_inst_t *)&cmd_tso_show,
18983         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18984         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18985         (cmdline_parse_inst_t *)&cmd_gro_enable,
18986         (cmdline_parse_inst_t *)&cmd_gro_flush,
18987         (cmdline_parse_inst_t *)&cmd_gro_show,
18988         (cmdline_parse_inst_t *)&cmd_gso_enable,
18989         (cmdline_parse_inst_t *)&cmd_gso_size,
18990         (cmdline_parse_inst_t *)&cmd_gso_show,
18991         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18992         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18993         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18994         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18995         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18996         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18997         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18998         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18999         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19000         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19001         (cmdline_parse_inst_t *)&cmd_config_dcb,
19002         (cmdline_parse_inst_t *)&cmd_read_reg,
19003         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19004         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19005         (cmdline_parse_inst_t *)&cmd_write_reg,
19006         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19007         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19008         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19009         (cmdline_parse_inst_t *)&cmd_stop,
19010         (cmdline_parse_inst_t *)&cmd_mac_addr,
19011         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19012         (cmdline_parse_inst_t *)&cmd_set_qmap,
19013         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19014         (cmdline_parse_inst_t *)&cmd_operate_port,
19015         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19016         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19017         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19018         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19019         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19020         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19021         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19022         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19023         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19024         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19025         (cmdline_parse_inst_t *)&cmd_config_mtu,
19026         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19027         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19028         (cmdline_parse_inst_t *)&cmd_config_rss,
19029         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19030         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19031         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19032         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19033         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19034         (cmdline_parse_inst_t *)&cmd_showport_reta,
19035         (cmdline_parse_inst_t *)&cmd_config_burst,
19036         (cmdline_parse_inst_t *)&cmd_config_thresh,
19037         (cmdline_parse_inst_t *)&cmd_config_threshold,
19038         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19039         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19040         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19041         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19042         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19043         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19044         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19045         (cmdline_parse_inst_t *)&cmd_global_config,
19046         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19047         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19048         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19049         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19050         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19051         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19052         (cmdline_parse_inst_t *)&cmd_dump,
19053         (cmdline_parse_inst_t *)&cmd_dump_one,
19054         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19055         (cmdline_parse_inst_t *)&cmd_syn_filter,
19056         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19057         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19058         (cmdline_parse_inst_t *)&cmd_flex_filter,
19059         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19060         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19061         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19062         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19063         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19064         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19065         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19066         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19067         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19068         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19069         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19070         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19071         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19072         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19073         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19074         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19075         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19076         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19077         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19078         (cmdline_parse_inst_t *)&cmd_flow,
19079         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19080         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19081         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19082         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19083         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19084         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19085         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19086         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19087         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19088         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19089         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19090         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19091         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19092         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19093         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19094         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19095         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19096         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19097         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19098         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19099         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19100         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19101         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19102         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19103         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19104         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19105         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19106         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19107         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19108         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19109         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19110         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19111         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19112         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19113         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19114         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19115         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19116         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19117         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19118         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19119         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19120         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19121         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19122         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19123         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19124         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19125         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19126         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19127         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19128 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19129         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19130 #endif
19131         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19132         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19133         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19134         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19135         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19136         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19137         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19138         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19139         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19140         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19141         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19142         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19143         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19144         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19145         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19146         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19147         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19148         (cmdline_parse_inst_t *)&cmd_ddp_add,
19149         (cmdline_parse_inst_t *)&cmd_ddp_del,
19150         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19151         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19152         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19153         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19154         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19155         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19156         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19157         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19158         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19159         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19160         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19161
19162         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19163         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19164         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19165         (cmdline_parse_inst_t *)&cmd_queue_region,
19166         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19167         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19168         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19169         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19170         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19171         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19172         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19173         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19174         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19175         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19176         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19177         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19178         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19179         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19180         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19181         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19182         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19183         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19184         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19185         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19186         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19187         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19188         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19189         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19190         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19191         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19192         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19193         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19194         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19195         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19196         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19197         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19198         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19199         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19200         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19201 #ifdef RTE_LIBRTE_BPF
19202         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19203         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19204 #endif
19205         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19206         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19207         (cmdline_parse_inst_t *)&cmd_set_raw,
19208         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19209         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19210         NULL,
19211 };
19212
19213 /* read cmdline commands from file */
19214 void
19215 cmdline_read_from_file(const char *filename)
19216 {
19217         struct cmdline *cl;
19218
19219         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19220         if (cl == NULL) {
19221                 printf("Failed to create file based cmdline context: %s\n",
19222                        filename);
19223                 return;
19224         }
19225
19226         cmdline_interact(cl);
19227         cmdline_quit(cl);
19228
19229         cmdline_free(cl);
19230
19231         printf("Read CLI commands from %s\n", filename);
19232 }
19233
19234 /* prompt function, called from main on MASTER lcore */
19235 void
19236 prompt(void)
19237 {
19238         /* initialize non-constant commands */
19239         cmd_set_fwd_mode_init();
19240         cmd_set_fwd_retry_mode_init();
19241
19242         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19243         if (testpmd_cl == NULL)
19244                 return;
19245         cmdline_interact(testpmd_cl);
19246         cmdline_stdin_exit(testpmd_cl);
19247 }
19248
19249 void
19250 prompt_exit(void)
19251 {
19252         if (testpmd_cl != NULL)
19253                 cmdline_quit(testpmd_cl);
19254 }
19255
19256 static void
19257 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19258 {
19259         if (id == (portid_t)RTE_PORT_ALL) {
19260                 portid_t pid;
19261
19262                 RTE_ETH_FOREACH_DEV(pid) {
19263                         /* check if need_reconfig has been set to 1 */
19264                         if (ports[pid].need_reconfig == 0)
19265                                 ports[pid].need_reconfig = dev;
19266                         /* check if need_reconfig_queues has been set to 1 */
19267                         if (ports[pid].need_reconfig_queues == 0)
19268                                 ports[pid].need_reconfig_queues = queue;
19269                 }
19270         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19271                 /* check if need_reconfig has been set to 1 */
19272                 if (ports[id].need_reconfig == 0)
19273                         ports[id].need_reconfig = dev;
19274                 /* check if need_reconfig_queues has been set to 1 */
19275                 if (ports[id].need_reconfig_queues == 0)
19276                         ports[id].need_reconfig_queues = queue;
19277         }
19278 }