app/testpmd: disable packet type parsing by default
[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                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
245                         "       Show status of rx|tx descriptor.\n\n"
246                 );
247         }
248
249         if (show_all || !strcmp(res->section, "config")) {
250                 cmdline_printf(
251                         cl,
252                         "\n"
253                         "Configuration:\n"
254                         "--------------\n"
255                         "Configuration changes only become active when"
256                         " forwarding is started/restarted.\n\n"
257
258                         "set default\n"
259                         "    Reset forwarding to the default configuration.\n\n"
260
261                         "set verbose (level)\n"
262                         "    Set the debug verbosity level X.\n\n"
263
264                         "set log global|(type) (level)\n"
265                         "    Set the log level.\n\n"
266
267                         "set nbport (num)\n"
268                         "    Set number of ports.\n\n"
269
270                         "set nbcore (num)\n"
271                         "    Set number of cores.\n\n"
272
273                         "set coremask (mask)\n"
274                         "    Set the forwarding cores hexadecimal mask.\n\n"
275
276                         "set portmask (mask)\n"
277                         "    Set the forwarding ports hexadecimal mask.\n\n"
278
279                         "set burst (num)\n"
280                         "    Set number of packets per burst.\n\n"
281
282                         "set burst tx delay (microseconds) retry (num)\n"
283                         "    Set the transmit delay time and number of retries,"
284                         " effective when retry is enabled.\n\n"
285
286                         "set txpkts (x[,y]*)\n"
287                         "    Set the length of each segment of TXONLY"
288                         " and optionally CSUM packets.\n\n"
289
290                         "set txsplit (off|on|rand)\n"
291                         "    Set the split policy for the TX packets."
292                         " Right now only applicable for CSUM and TXONLY"
293                         " modes\n\n"
294
295                         "set corelist (x[,y]*)\n"
296                         "    Set the list of forwarding cores.\n\n"
297
298                         "set portlist (x[,y]*)\n"
299                         "    Set the list of forwarding ports.\n\n"
300
301                         "set port setup on (iterator|event)\n"
302                         "    Select how attached port is retrieved for setup.\n\n"
303
304                         "set tx loopback (port_id) (on|off)\n"
305                         "    Enable or disable tx loopback.\n\n"
306
307                         "set all queues drop (port_id) (on|off)\n"
308                         "    Set drop enable bit for all queues.\n\n"
309
310                         "set vf split drop (port_id) (vf_id) (on|off)\n"
311                         "    Set split drop enable bit for a VF from the PF.\n\n"
312
313                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
314                         "    Set MAC antispoof for a VF from the PF.\n\n"
315
316                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
317                         "    Enable MACsec offload.\n\n"
318
319                         "set macsec offload (port_id) off\n"
320                         "    Disable MACsec offload.\n\n"
321
322                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
323                         "    Configure MACsec secure connection (SC).\n\n"
324
325                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
326                         "    Configure MACsec secure association (SA).\n\n"
327
328                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
329                         "    Set VF broadcast for a VF from the PF.\n\n"
330
331                         "vlan set stripq (on|off) (port_id,queue_id)\n"
332                         "    Set the VLAN strip for a queue on a port.\n\n"
333
334                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
335                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
336
337                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
338                         "    Set VLAN insert for a VF from the PF.\n\n"
339
340                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
341                         "    Set VLAN antispoof for a VF from the PF.\n\n"
342
343                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
344                         "    Set VLAN tag for a VF from the PF.\n\n"
345
346                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
347                         "    Set a VF's max bandwidth(Mbps).\n\n"
348
349                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
350                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
351
352                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
353                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
354
355                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
356                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
357
358                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
359                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
360
361                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
362                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
363
364                         "vlan set (inner|outer) tpid (value) (port_id)\n"
365                         "    Set the VLAN TPID for Packet Filtering on"
366                         " a port\n\n"
367
368                         "rx_vlan add (vlan_id|all) (port_id)\n"
369                         "    Add a vlan_id, or all identifiers, to the set"
370                         " of VLAN identifiers filtered by port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id|all) (port_id)\n"
373                         "    Remove a vlan_id, or all identifiers, from the set"
374                         " of VLAN identifiers filtered by port_id.\n\n"
375
376                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
377                         "    Add a vlan_id, to the set of VLAN identifiers"
378                         "filtered for VF(s) from port_id.\n\n"
379
380                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
381                         "    Remove a vlan_id, to the set of VLAN identifiers"
382                         "filtered for VF(s) from port_id.\n\n"
383
384                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
385                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
386                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
387                         "   add a tunnel filter of a port.\n\n"
388
389                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
390                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
391                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
392                         "   remove a tunnel filter of a port.\n\n"
393
394                         "rx_vxlan_port add (udp_port) (port_id)\n"
395                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
396
397                         "rx_vxlan_port rm (udp_port) (port_id)\n"
398                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
399
400                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
401                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
402                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
403
404                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
405                         "    Set port based TX VLAN insertion.\n\n"
406
407                         "tx_vlan reset (port_id)\n"
408                         "    Disable hardware insertion of a VLAN header in"
409                         " packets sent on a port.\n\n"
410
411                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
412                         "    Select hardware or software calculation of the"
413                         " checksum when transmitting a packet using the"
414                         " csum forward engine.\n"
415                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
416                         "    outer-ip concerns the outer IP layer in"
417                         "    outer-udp concerns the outer UDP layer in"
418                         " case the packet is recognized as a tunnel packet by"
419                         " the forward engine (vxlan, gre and ipip are supported)\n"
420                         "    Please check the NIC datasheet for HW limits.\n\n"
421
422                         "csum parse-tunnel (on|off) (tx_port_id)\n"
423                         "    If disabled, treat tunnel packets as non-tunneled"
424                         " packets (treat inner headers as payload). The port\n"
425                         "    argument is the port used for TX in csum forward"
426                         " engine.\n\n"
427
428                         "csum show (port_id)\n"
429                         "    Display tx checksum offload configuration\n\n"
430
431                         "tso set (segsize) (portid)\n"
432                         "    Enable TCP Segmentation Offload in csum forward"
433                         " engine.\n"
434                         "    Please check the NIC datasheet for HW limits.\n\n"
435
436                         "tso show (portid)"
437                         "    Display the status of TCP Segmentation Offload.\n\n"
438
439                         "set port (port_id) gro on|off\n"
440                         "    Enable or disable Generic Receive Offload in"
441                         " csum forwarding engine.\n\n"
442
443                         "show port (port_id) gro\n"
444                         "    Display GRO configuration.\n\n"
445
446                         "set gro flush (cycles)\n"
447                         "    Set the cycle to flush GROed packets from"
448                         " reassembly tables.\n\n"
449
450                         "set port (port_id) gso (on|off)"
451                         "    Enable or disable Generic Segmentation Offload in"
452                         " csum forwarding engine.\n\n"
453
454                         "set gso segsz (length)\n"
455                         "    Set max packet length for output GSO segments,"
456                         " including packet header and payload.\n\n"
457
458                         "show port (port_id) gso\n"
459                         "    Show GSO configuration.\n\n"
460
461                         "set fwd (%s)\n"
462                         "    Set packet forwarding mode.\n\n"
463
464                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Add a MAC address on port_id.\n\n"
466
467                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Remove a MAC address from port_id.\n\n"
469
470                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
471                         "    Set the default MAC address for port_id.\n\n"
472
473                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
474                         "    Add a MAC address for a VF on the port.\n\n"
475
476                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
477                         "    Set the MAC address for a VF from the PF.\n\n"
478
479                         "set eth-peer (port_id) (peer_addr)\n"
480                         "    set the peer address for certain port.\n\n"
481
482                         "set port (port_id) uta (mac_address|all) (on|off)\n"
483                         "    Add/Remove a or all unicast hash filter(s)"
484                         "from port X.\n\n"
485
486                         "set promisc (port_id|all) (on|off)\n"
487                         "    Set the promiscuous mode on port_id, or all.\n\n"
488
489                         "set allmulti (port_id|all) (on|off)\n"
490                         "    Set the allmulti mode on port_id, or all.\n\n"
491
492                         "set vf promisc (port_id) (vf_id) (on|off)\n"
493                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
494
495                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
496                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
497
498                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
499                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
500                         " (on|off) autoneg (on|off) (port_id)\n"
501                         "set flow_ctrl rx (on|off) (portid)\n"
502                         "set flow_ctrl tx (on|off) (portid)\n"
503                         "set flow_ctrl high_water (high_water) (portid)\n"
504                         "set flow_ctrl low_water (low_water) (portid)\n"
505                         "set flow_ctrl pause_time (pause_time) (portid)\n"
506                         "set flow_ctrl send_xon (send_xon) (portid)\n"
507                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
508                         "set flow_ctrl autoneg (on|off) (port_id)\n"
509                         "    Set the link flow control parameter on a port.\n\n"
510
511                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
512                         " (low_water) (pause_time) (priority) (port_id)\n"
513                         "    Set the priority flow control parameter on a"
514                         " port.\n\n"
515
516                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
517                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
518                         " queue on port.\n"
519                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
520                         " on port 0 to mapping 5.\n\n"
521
522                         "set xstats-hide-zero on|off\n"
523                         "    Set the option to hide the zero values"
524                         " for xstats display.\n"
525
526                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
527                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
528
529                         "set port (port_id) vf (vf_id) (mac_addr)"
530                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
531                         "   Add/Remove unicast or multicast MAC addr filter"
532                         " for a VF.\n\n"
533
534                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
535                         "|MPE) (on|off)\n"
536                         "    AUPE:accepts untagged VLAN;"
537                         "ROPE:accept unicast hash\n\n"
538                         "    BAM:accepts broadcast packets;"
539                         "MPE:accepts all multicast packets\n\n"
540                         "    Enable/Disable a VF receive mode of a port\n\n"
541
542                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
543                         "    Set rate limit for a queue of a port\n\n"
544
545                         "set port (port_id) vf (vf_id) rate (rate_num) "
546                         "queue_mask (queue_mask_value)\n"
547                         "    Set rate limit for queues in VF of a port\n\n"
548
549                         "set port (port_id) mirror-rule (rule_id)"
550                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
551                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
552                         "   Set pool or vlan type mirror rule on a port.\n"
553                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
554                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
555                         " to pool 0.\n\n"
556
557                         "set port (port_id) mirror-rule (rule_id)"
558                         " (uplink-mirror|downlink-mirror) dst-pool"
559                         " (pool_id) (on|off)\n"
560                         "   Set uplink or downlink type mirror rule on a port.\n"
561                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
562                         " 0 on' enable mirror income traffic to pool 0.\n\n"
563
564                         "reset port (port_id) mirror-rule (rule_id)\n"
565                         "   Reset a mirror rule.\n\n"
566
567                         "set flush_rx (on|off)\n"
568                         "   Flush (default) or don't flush RX streams before"
569                         " forwarding. Mainly used with PCAP drivers.\n\n"
570
571                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
572                         "   Set the bypass mode for the lowest port on bypass enabled"
573                         " NIC.\n\n"
574
575                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
576                         "mode (normal|bypass|isolate) (port_id)\n"
577                         "   Set the event required to initiate specified bypass mode for"
578                         " the lowest port on a bypass enabled NIC where:\n"
579                         "       timeout   = enable bypass after watchdog timeout.\n"
580                         "       os_on     = enable bypass when OS/board is powered on.\n"
581                         "       os_off    = enable bypass when OS/board is powered off.\n"
582                         "       power_on  = enable bypass when power supply is turned on.\n"
583                         "       power_off = enable bypass when power supply is turned off."
584                         "\n\n"
585
586                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
587                         "   Set the bypass watchdog timeout to 'n' seconds"
588                         " where 0 = instant.\n\n"
589
590                         "show bypass config (port_id)\n"
591                         "   Show the bypass configuration for a bypass enabled NIC"
592                         " using the lowest port on the NIC.\n\n"
593
594 #ifdef RTE_LIBRTE_PMD_BOND
595                         "create bonded device (mode) (socket)\n"
596                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
597
598                         "add bonding slave (slave_id) (port_id)\n"
599                         "       Add a slave device to a bonded device.\n\n"
600
601                         "remove bonding slave (slave_id) (port_id)\n"
602                         "       Remove a slave device from a bonded device.\n\n"
603
604                         "set bonding mode (value) (port_id)\n"
605                         "       Set the bonding mode on a bonded device.\n\n"
606
607                         "set bonding primary (slave_id) (port_id)\n"
608                         "       Set the primary slave for a bonded device.\n\n"
609
610                         "show bonding config (port_id)\n"
611                         "       Show the bonding config for port_id.\n\n"
612
613                         "set bonding mac_addr (port_id) (address)\n"
614                         "       Set the MAC address of a bonded device.\n\n"
615
616                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
617                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
618
619                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
620                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
621
622                         "set bonding mon_period (port_id) (value)\n"
623                         "       Set the bonding link status monitoring polling period in ms.\n\n"
624
625                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
626                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
627
628 #endif
629                         "set link-up port (port_id)\n"
630                         "       Set link up for a port.\n\n"
631
632                         "set link-down port (port_id)\n"
633                         "       Set link down for a port.\n\n"
634
635                         "E-tag set insertion on port-tag-id (value)"
636                         " port (port_id) vf (vf_id)\n"
637                         "    Enable E-tag insertion for a VF on a port\n\n"
638
639                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
640                         "    Disable E-tag insertion for a VF on a port\n\n"
641
642                         "E-tag set stripping (on|off) port (port_id)\n"
643                         "    Enable/disable E-tag stripping on a port\n\n"
644
645                         "E-tag set forwarding (on|off) port (port_id)\n"
646                         "    Enable/disable E-tag based forwarding"
647                         " on a port\n\n"
648
649                         "E-tag set filter add e-tag-id (value) dst-pool"
650                         " (pool_id) port (port_id)\n"
651                         "    Add an E-tag forwarding filter on a port\n\n"
652
653                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
654                         "    Delete an E-tag forwarding filter on a port\n\n"
655
656                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
657                         "    Load a profile package on a port\n\n"
658
659                         "ddp del (port_id) (backup_profile_path)\n"
660                         "    Delete a profile package from a port\n\n"
661
662                         "ptype mapping get (port_id) (valid_only)\n"
663                         "    Get ptype mapping on a port\n\n"
664
665                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
666                         "    Replace target with the pkt_type in ptype mapping\n\n"
667
668                         "ptype mapping reset (port_id)\n"
669                         "    Reset ptype mapping on a port\n\n"
670
671                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
672                         "    Update a ptype mapping item on a port\n\n"
673
674                         "set port (port_id) ptype_mask (ptype_mask)\n"
675                         "    set packet types classification for a specific port\n\n"
676
677                         "set port (port_id) queue-region region_id (value) "
678                         "queue_start_index (value) queue_num (value)\n"
679                         "    Set a queue region on a port\n\n"
680
681                         "set port (port_id) queue-region region_id (value) "
682                         "flowtype (value)\n"
683                         "    Set a flowtype region index on a port\n\n"
684
685                         "set port (port_id) queue-region UP (value) region_id (value)\n"
686                         "    Set the mapping of User Priority to "
687                         "queue region on a port\n\n"
688
689                         "set port (port_id) queue-region flush (on|off)\n"
690                         "    flush all queue region related configuration\n\n"
691
692                         "show port meter cap (port_id)\n"
693                         "    Show port meter capability information\n\n"
694
695                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
696                         "    meter profile add - srtcm rfc 2697\n\n"
697
698                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
699                         "    meter profile add - trtcm rfc 2698\n\n"
700
701                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
702                         "    meter profile add - trtcm rfc 4115\n\n"
703
704                         "del port meter profile (port_id) (profile_id)\n"
705                         "    meter profile delete\n\n"
706
707                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
708                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
709                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
710                         "(dscp_tbl_entry63)]\n"
711                         "    meter create\n\n"
712
713                         "enable port meter (port_id) (mtr_id)\n"
714                         "    meter enable\n\n"
715
716                         "disable port meter (port_id) (mtr_id)\n"
717                         "    meter disable\n\n"
718
719                         "del port meter (port_id) (mtr_id)\n"
720                         "    meter delete\n\n"
721
722                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
723                         "    meter update meter profile\n\n"
724
725                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
726                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
727                         "    update meter dscp table entries\n\n"
728
729                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
730                         "(action0) [(action1) (action2)]\n"
731                         "    meter update policer action\n\n"
732
733                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
734                         "    meter update stats\n\n"
735
736                         "show port (port_id) queue-region\n"
737                         "    show all queue region related configuration info\n\n"
738
739                         , list_pkt_forwarding_modes()
740                 );
741         }
742
743         if (show_all || !strcmp(res->section, "ports")) {
744
745                 cmdline_printf(
746                         cl,
747                         "\n"
748                         "Port Operations:\n"
749                         "----------------\n\n"
750
751                         "port start (port_id|all)\n"
752                         "    Start all ports or port_id.\n\n"
753
754                         "port stop (port_id|all)\n"
755                         "    Stop all ports or port_id.\n\n"
756
757                         "port close (port_id|all)\n"
758                         "    Close all ports or port_id.\n\n"
759
760                         "port reset (port_id|all)\n"
761                         "    Reset all ports or port_id.\n\n"
762
763                         "port attach (ident)\n"
764                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
765
766                         "port detach (port_id)\n"
767                         "    Detach physical or virtual dev by port_id\n\n"
768
769                         "port config (port_id|all)"
770                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
771                         " duplex (half|full|auto)\n"
772                         "    Set speed and duplex for all ports or port_id\n\n"
773
774                         "port config (port_id|all) loopback (mode)\n"
775                         "    Set loopback mode for all ports or port_id\n\n"
776
777                         "port config all (rxq|txq|rxd|txd) (value)\n"
778                         "    Set number for rxq/txq/rxd/txd.\n\n"
779
780                         "port config all max-pkt-len (value)\n"
781                         "    Set the max packet length.\n\n"
782
783                         "port config all drop-en (on|off)\n"
784                         "    Enable or disable packet drop on all RX queues of all ports when no "
785                         "receive buffers available.\n\n"
786
787                         "port config all rss (all|default|ip|tcp|udp|sctp|"
788                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
789                         "    Set the RSS mode.\n\n"
790
791                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
792                         "    Set the RSS redirection table.\n\n"
793
794                         "port config (port_id) dcb vt (on|off) (traffic_class)"
795                         " pfc (on|off)\n"
796                         "    Set the DCB mode.\n\n"
797
798                         "port config all burst (value)\n"
799                         "    Set the number of packets per burst.\n\n"
800
801                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
802                         " (value)\n"
803                         "    Set the ring prefetch/host/writeback threshold"
804                         " for tx/rx queue.\n\n"
805
806                         "port config all (txfreet|txrst|rxfreet) (value)\n"
807                         "    Set free threshold for rx/tx, or set"
808                         " tx rs bit threshold.\n\n"
809                         "port config mtu X value\n"
810                         "    Set the MTU of port X to a given value\n\n"
811
812                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
813                         "    Set a rx/tx queue's ring size configuration, the new"
814                         " value will take effect after command that (re-)start the port"
815                         " or command that setup the specific queue\n\n"
816
817                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
818                         "    Start/stop a rx/tx queue of port X. Only take effect"
819                         " when port X is started\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
822                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
823                         " take effect when port X is stopped.\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) setup\n"
826                         "    Setup a rx/tx queue of port X.\n\n"
827
828                         "port config (port_id|all) l2-tunnel E-tag ether-type"
829                         " (value)\n"
830                         "    Set the value of E-tag ether-type.\n\n"
831
832                         "port config (port_id|all) l2-tunnel E-tag"
833                         " (enable|disable)\n"
834                         "    Enable/disable the E-tag support.\n\n"
835
836                         "port config (port_id) pctype mapping reset\n"
837                         "    Reset flow type to pctype mapping on a port\n\n"
838
839                         "port config (port_id) pctype mapping update"
840                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
841                         "    Update a flow type to pctype mapping item on a port\n\n"
842
843                         "port config (port_id) pctype (pctype_id) hash_inset|"
844                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
845                         " (field_idx)\n"
846                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
847
848                         "port config (port_id) pctype (pctype_id) hash_inset|"
849                         "fdir_inset|fdir_flx_inset clear all"
850                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
851
852                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
853                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
854
855                         "port config <port_id> rx_offload vlan_strip|"
856                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
857                         "outer_ipv4_cksum|macsec_strip|header_split|"
858                         "vlan_filter|vlan_extend|jumbo_frame|"
859                         "scatter|timestamp|security|keep_crc on|off\n"
860                         "     Enable or disable a per port Rx offloading"
861                         " on all Rx queues of a port\n\n"
862
863                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
864                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
865                         "outer_ipv4_cksum|macsec_strip|header_split|"
866                         "vlan_filter|vlan_extend|jumbo_frame|"
867                         "scatter|timestamp|security|keep_crc on|off\n"
868                         "    Enable or disable a per queue Rx offloading"
869                         " only on a specific Rx queue\n\n"
870
871                         "port config (port_id) tx_offload vlan_insert|"
872                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
873                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
874                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
875                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
876                         "security|match_metadata on|off\n"
877                         "    Enable or disable a per port Tx offloading"
878                         " on all Tx queues of a port\n\n"
879
880                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
881                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
882                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
883                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
884                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
885                         " on|off\n"
886                         "    Enable or disable a per queue Tx offloading"
887                         " only on a specific Tx queue\n\n"
888
889                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
890                         "    Load an eBPF program as a callback"
891                         " for particular RX/TX queue\n\n"
892
893                         "bpf-unload rx|tx (port) (queue)\n"
894                         "    Unload previously loaded eBPF program"
895                         " for particular RX/TX queue\n\n"
896
897                         "port config (port_id) tx_metadata (value)\n"
898                         "    Set Tx metadata value per port. Testpmd will add this value"
899                         " to any Tx packet sent from this port\n\n"
900                 );
901         }
902
903         if (show_all || !strcmp(res->section, "registers")) {
904
905                 cmdline_printf(
906                         cl,
907                         "\n"
908                         "Registers:\n"
909                         "----------\n\n"
910
911                         "read reg (port_id) (address)\n"
912                         "    Display value of a port register.\n\n"
913
914                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
915                         "    Display a port register bit field.\n\n"
916
917                         "read regbit (port_id) (address) (bit_x)\n"
918                         "    Display a single port register bit.\n\n"
919
920                         "write reg (port_id) (address) (value)\n"
921                         "    Set value of a port register.\n\n"
922
923                         "write regfield (port_id) (address) (bit_x) (bit_y)"
924                         " (value)\n"
925                         "    Set bit field of a port register.\n\n"
926
927                         "write regbit (port_id) (address) (bit_x) (value)\n"
928                         "    Set single bit value of a port register.\n\n"
929                 );
930         }
931         if (show_all || !strcmp(res->section, "filters")) {
932
933                 cmdline_printf(
934                         cl,
935                         "\n"
936                         "filters:\n"
937                         "--------\n\n"
938
939                         "ethertype_filter (port_id) (add|del)"
940                         " (mac_addr|mac_ignr) (mac_address) ethertype"
941                         " (ether_type) (drop|fwd) queue (queue_id)\n"
942                         "    Add/Del an ethertype filter.\n\n"
943
944                         "2tuple_filter (port_id) (add|del)"
945                         " dst_port (dst_port_value) protocol (protocol_value)"
946                         " mask (mask_value) tcp_flags (tcp_flags_value)"
947                         " priority (prio_value) queue (queue_id)\n"
948                         "    Add/Del a 2tuple filter.\n\n"
949
950                         "5tuple_filter (port_id) (add|del)"
951                         " dst_ip (dst_address) src_ip (src_address)"
952                         " dst_port (dst_port_value) src_port (src_port_value)"
953                         " protocol (protocol_value)"
954                         " mask (mask_value) tcp_flags (tcp_flags_value)"
955                         " priority (prio_value) queue (queue_id)\n"
956                         "    Add/Del a 5tuple filter.\n\n"
957
958                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
959                         "    Add/Del syn filter.\n\n"
960
961                         "flex_filter (port_id) (add|del) len (len_value)"
962                         " bytes (bytes_value) mask (mask_value)"
963                         " priority (prio_value) queue (queue_id)\n"
964                         "    Add/Del a flex filter.\n\n"
965
966                         "flow_director_filter (port_id) mode IP (add|del|update)"
967                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
968                         " src (src_ip_address) dst (dst_ip_address)"
969                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
970                         " vlan (vlan_value) flexbytes (flexbytes_value)"
971                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
972                         " fd_id (fd_id_value)\n"
973                         "    Add/Del an IP type flow director filter.\n\n"
974
975                         "flow_director_filter (port_id) mode IP (add|del|update)"
976                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
977                         " src (src_ip_address) (src_port)"
978                         " dst (dst_ip_address) (dst_port)"
979                         " tos (tos_value) ttl (ttl_value)"
980                         " vlan (vlan_value) flexbytes (flexbytes_value)"
981                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982                         " fd_id (fd_id_value)\n"
983                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
984
985                         "flow_director_filter (port_id) mode IP (add|del|update)"
986                         " flow (ipv4-sctp|ipv6-sctp)"
987                         " src (src_ip_address) (src_port)"
988                         " dst (dst_ip_address) (dst_port)"
989                         " tag (verification_tag) "
990                         " tos (tos_value) ttl (ttl_value)"
991                         " vlan (vlan_value)"
992                         " flexbytes (flexbytes_value) (drop|fwd)"
993                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
994                         "    Add/Del a SCTP type flow director filter.\n\n"
995
996                         "flow_director_filter (port_id) mode IP (add|del|update)"
997                         " flow l2_payload ether (ethertype)"
998                         " flexbytes (flexbytes_value) (drop|fwd)"
999                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1000                         "    Add/Del a l2 payload type flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1003                         " mac (mac_address) vlan (vlan_value)"
1004                         " flexbytes (flexbytes_value) (drop|fwd)"
1005                         " queue (queue_id) fd_id (fd_id_value)\n"
1006                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1007
1008                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1009                         " mac (mac_address) vlan (vlan_value)"
1010                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1011                         " flexbytes (flexbytes_value) (drop|fwd)"
1012                         " queue (queue_id) fd_id (fd_id_value)\n"
1013                         "    Add/Del a Tunnel flow director filter.\n\n"
1014
1015                         "flow_director_filter (port_id) mode raw (add|del|update)"
1016                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1017                         " fd_id (fd_id_value) packet (packet file name)\n"
1018                         "    Add/Del a raw type flow director filter.\n\n"
1019
1020                         "flush_flow_director (port_id)\n"
1021                         "    Flush all flow director entries of a device.\n\n"
1022
1023                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1024                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1025                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1026                         "    Set flow director IP mask.\n\n"
1027
1028                         "flow_director_mask (port_id) mode MAC-VLAN"
1029                         " vlan (vlan_value)\n"
1030                         "    Set flow director MAC-VLAN mask.\n\n"
1031
1032                         "flow_director_mask (port_id) mode Tunnel"
1033                         " vlan (vlan_value) mac (mac_value)"
1034                         " tunnel-type (tunnel_type_value)"
1035                         " tunnel-id (tunnel_id_value)\n"
1036                         "    Set flow director Tunnel mask.\n\n"
1037
1038                         "flow_director_flex_mask (port_id)"
1039                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1040                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1041                         " (mask)\n"
1042                         "    Configure mask of flex payload.\n\n"
1043
1044                         "flow_director_flex_payload (port_id)"
1045                         " (raw|l2|l3|l4) (config)\n"
1046                         "    Configure flex payload selection.\n\n"
1047
1048                         "get_sym_hash_ena_per_port (port_id)\n"
1049                         "    get symmetric hash enable configuration per port.\n\n"
1050
1051                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1052                         "    set symmetric hash enable configuration per port"
1053                         " to enable or disable.\n\n"
1054
1055                         "get_hash_global_config (port_id)\n"
1056                         "    Get the global configurations of hash filters.\n\n"
1057
1058                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1059                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1060                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1061                         " (enable|disable)\n"
1062                         "    Set the global configurations of hash filters.\n\n"
1063
1064                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1065                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1066                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1067                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1068                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1069                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1070                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1071                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1072                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1073                         "fld-8th|none) (select|add)\n"
1074                         "    Set the input set for hash.\n\n"
1075
1076                         "set_fdir_input_set (port_id) "
1077                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1078                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1079                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1080                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1081                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1082                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1083                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1084                         " (select|add)\n"
1085                         "    Set the input set for FDir.\n\n"
1086
1087                         "flow validate {port_id}"
1088                         " [group {group_id}] [priority {level}]"
1089                         " [ingress] [egress]"
1090                         " pattern {item} [/ {item} [...]] / end"
1091                         " actions {action} [/ {action} [...]] / end\n"
1092                         "    Check whether a flow rule can be created.\n\n"
1093
1094                         "flow create {port_id}"
1095                         " [group {group_id}] [priority {level}]"
1096                         " [ingress] [egress]"
1097                         " pattern {item} [/ {item} [...]] / end"
1098                         " actions {action} [/ {action} [...]] / end\n"
1099                         "    Create a flow rule.\n\n"
1100
1101                         "flow destroy {port_id} rule {rule_id} [...]\n"
1102                         "    Destroy specific flow rules.\n\n"
1103
1104                         "flow flush {port_id}\n"
1105                         "    Destroy all flow rules.\n\n"
1106
1107                         "flow query {port_id} {rule_id} {action}\n"
1108                         "    Query an existing flow rule.\n\n"
1109
1110                         "flow list {port_id} [group {group_id}] [...]\n"
1111                         "    List existing flow rules sorted by priority,"
1112                         " filtered by group identifiers.\n\n"
1113
1114                         "flow isolate {port_id} {boolean}\n"
1115                         "    Restrict ingress traffic to the defined"
1116                         " flow rules\n\n"
1117
1118                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1119                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1120                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1121                         "       Configure the VXLAN encapsulation for flows.\n\n"
1122
1123                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1124                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1125                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1126                         " eth-dst (eth-dst)\n"
1127                         "       Configure the VXLAN encapsulation for flows.\n\n"
1128
1129                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1130                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1131                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1132                         " eth-dst (eth-dst)\n"
1133                         "       Configure the VXLAN encapsulation for flows.\n\n"
1134
1135                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1136                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1137                         " (eth-dst)\n"
1138                         "       Configure the NVGRE encapsulation for flows.\n\n"
1139
1140                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1141                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1142                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1143                         "       Configure the NVGRE encapsulation for flows.\n\n"
1144
1145                         "set raw_encap {flow items}\n"
1146                         "       Configure the encapsulation with raw data.\n\n"
1147
1148                         "set raw_decap {flow items}\n"
1149                         "       Configure the decapsulation with raw data.\n\n"
1150
1151                 );
1152         }
1153
1154         if (show_all || !strcmp(res->section, "traffic_management")) {
1155                 cmdline_printf(
1156                         cl,
1157                         "\n"
1158                         "Traffic Management:\n"
1159                         "--------------\n"
1160                         "show port tm cap (port_id)\n"
1161                         "       Display the port TM capability.\n\n"
1162
1163                         "show port tm level cap (port_id) (level_id)\n"
1164                         "       Display the port TM hierarchical level capability.\n\n"
1165
1166                         "show port tm node cap (port_id) (node_id)\n"
1167                         "       Display the port TM node capability.\n\n"
1168
1169                         "show port tm node type (port_id) (node_id)\n"
1170                         "       Display the port TM node type.\n\n"
1171
1172                         "show port tm node stats (port_id) (node_id) (clear)\n"
1173                         "       Display the port TM node stats.\n\n"
1174
1175 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1176                         "set port tm hierarchy default (port_id)\n"
1177                         "       Set default traffic Management hierarchy on a port\n\n"
1178 #endif
1179
1180                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1181                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1182                         " (packet_length_adjust)\n"
1183                         "       Add port tm node private shaper profile.\n\n"
1184
1185                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1186                         "       Delete port tm node private shaper profile.\n\n"
1187
1188                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1189                         " (shaper_profile_id)\n"
1190                         "       Add/update port tm node shared shaper.\n\n"
1191
1192                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1193                         "       Delete port tm node shared shaper.\n\n"
1194
1195                         "set port tm node shaper profile (port_id) (node_id)"
1196                         " (shaper_profile_id)\n"
1197                         "       Set port tm node shaper profile.\n\n"
1198
1199                         "add port tm node wred profile (port_id) (wred_profile_id)"
1200                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1201                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1202                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1203                         "       Add port tm node wred profile.\n\n"
1204
1205                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1206                         "       Delete port tm node wred profile.\n\n"
1207
1208                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1209                         " (priority) (weight) (level_id) (shaper_profile_id)"
1210                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1211                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1212                         "       Add port tm nonleaf node.\n\n"
1213
1214                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1215                         " (priority) (weight) (level_id) (shaper_profile_id)"
1216                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1217                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1218                         "       Add port tm leaf node.\n\n"
1219
1220                         "del port tm node (port_id) (node_id)\n"
1221                         "       Delete port tm node.\n\n"
1222
1223                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1224                         " (priority) (weight)\n"
1225                         "       Set port tm node parent.\n\n"
1226
1227                         "suspend port tm node (port_id) (node_id)"
1228                         "       Suspend tm node.\n\n"
1229
1230                         "resume port tm node (port_id) (node_id)"
1231                         "       Resume tm node.\n\n"
1232
1233                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1234                         "       Commit tm hierarchy.\n\n"
1235
1236                         "set port tm mark ip_ecn (port) (green) (yellow)"
1237                         " (red)\n"
1238                         "    Enables/Disables the traffic management marking"
1239                         " for IP ECN (Explicit Congestion Notification)"
1240                         " packets on a given port\n\n"
1241
1242                         "set port tm mark ip_dscp (port) (green) (yellow)"
1243                         " (red)\n"
1244                         "    Enables/Disables the traffic management marking"
1245                         " on the port for IP dscp packets\n\n"
1246
1247                         "set port tm mark vlan_dei (port) (green) (yellow)"
1248                         " (red)\n"
1249                         "    Enables/Disables the traffic management marking"
1250                         " on the port for VLAN packets with DEI enabled\n\n"
1251                 );
1252         }
1253
1254         if (show_all || !strcmp(res->section, "devices")) {
1255                 cmdline_printf(
1256                         cl,
1257                         "\n"
1258                         "Device Operations:\n"
1259                         "--------------\n"
1260                         "device detach (identifier)\n"
1261                         "       Detach device by identifier.\n\n"
1262                 );
1263         }
1264
1265 }
1266
1267 cmdline_parse_token_string_t cmd_help_long_help =
1268         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1269
1270 cmdline_parse_token_string_t cmd_help_long_section =
1271         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1272                         "all#control#display#config#"
1273                         "ports#registers#filters#traffic_management#devices");
1274
1275 cmdline_parse_inst_t cmd_help_long = {
1276         .f = cmd_help_long_parsed,
1277         .data = NULL,
1278         .help_str = "help all|control|display|config|ports|register|"
1279                 "filters|traffic_management|devices: "
1280                 "Show help",
1281         .tokens = {
1282                 (void *)&cmd_help_long_help,
1283                 (void *)&cmd_help_long_section,
1284                 NULL,
1285         },
1286 };
1287
1288
1289 /* *** start/stop/close all ports *** */
1290 struct cmd_operate_port_result {
1291         cmdline_fixed_string_t keyword;
1292         cmdline_fixed_string_t name;
1293         cmdline_fixed_string_t value;
1294 };
1295
1296 static void cmd_operate_port_parsed(void *parsed_result,
1297                                 __attribute__((unused)) struct cmdline *cl,
1298                                 __attribute__((unused)) void *data)
1299 {
1300         struct cmd_operate_port_result *res = parsed_result;
1301
1302         if (!strcmp(res->name, "start"))
1303                 start_port(RTE_PORT_ALL);
1304         else if (!strcmp(res->name, "stop"))
1305                 stop_port(RTE_PORT_ALL);
1306         else if (!strcmp(res->name, "close"))
1307                 close_port(RTE_PORT_ALL);
1308         else if (!strcmp(res->name, "reset"))
1309                 reset_port(RTE_PORT_ALL);
1310         else
1311                 printf("Unknown parameter\n");
1312 }
1313
1314 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1315         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1316                                                                 "port");
1317 cmdline_parse_token_string_t cmd_operate_port_all_port =
1318         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1319                                                 "start#stop#close#reset");
1320 cmdline_parse_token_string_t cmd_operate_port_all_all =
1321         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1322
1323 cmdline_parse_inst_t cmd_operate_port = {
1324         .f = cmd_operate_port_parsed,
1325         .data = NULL,
1326         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1327         .tokens = {
1328                 (void *)&cmd_operate_port_all_cmd,
1329                 (void *)&cmd_operate_port_all_port,
1330                 (void *)&cmd_operate_port_all_all,
1331                 NULL,
1332         },
1333 };
1334
1335 /* *** start/stop/close specific port *** */
1336 struct cmd_operate_specific_port_result {
1337         cmdline_fixed_string_t keyword;
1338         cmdline_fixed_string_t name;
1339         uint8_t value;
1340 };
1341
1342 static void cmd_operate_specific_port_parsed(void *parsed_result,
1343                         __attribute__((unused)) struct cmdline *cl,
1344                                 __attribute__((unused)) void *data)
1345 {
1346         struct cmd_operate_specific_port_result *res = parsed_result;
1347
1348         if (!strcmp(res->name, "start"))
1349                 start_port(res->value);
1350         else if (!strcmp(res->name, "stop"))
1351                 stop_port(res->value);
1352         else if (!strcmp(res->name, "close"))
1353                 close_port(res->value);
1354         else if (!strcmp(res->name, "reset"))
1355                 reset_port(res->value);
1356         else
1357                 printf("Unknown parameter\n");
1358 }
1359
1360 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1361         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1362                                                         keyword, "port");
1363 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1364         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1365                                                 name, "start#stop#close#reset");
1366 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1367         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1368                                                         value, UINT8);
1369
1370 cmdline_parse_inst_t cmd_operate_specific_port = {
1371         .f = cmd_operate_specific_port_parsed,
1372         .data = NULL,
1373         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1374         .tokens = {
1375                 (void *)&cmd_operate_specific_port_cmd,
1376                 (void *)&cmd_operate_specific_port_port,
1377                 (void *)&cmd_operate_specific_port_id,
1378                 NULL,
1379         },
1380 };
1381
1382 /* *** enable port setup (after attach) via iterator or event *** */
1383 struct cmd_set_port_setup_on_result {
1384         cmdline_fixed_string_t set;
1385         cmdline_fixed_string_t port;
1386         cmdline_fixed_string_t setup;
1387         cmdline_fixed_string_t on;
1388         cmdline_fixed_string_t mode;
1389 };
1390
1391 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1392                                 __attribute__((unused)) struct cmdline *cl,
1393                                 __attribute__((unused)) void *data)
1394 {
1395         struct cmd_set_port_setup_on_result *res = parsed_result;
1396
1397         if (strcmp(res->mode, "event") == 0)
1398                 setup_on_probe_event = true;
1399         else if (strcmp(res->mode, "iterator") == 0)
1400                 setup_on_probe_event = false;
1401         else
1402                 printf("Unknown mode\n");
1403 }
1404
1405 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1406         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1407                         set, "set");
1408 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1409         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1410                         port, "port");
1411 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1412         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1413                         setup, "setup");
1414 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1415         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1416                         on, "on");
1417 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1418         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1419                         mode, "iterator#event");
1420
1421 cmdline_parse_inst_t cmd_set_port_setup_on = {
1422         .f = cmd_set_port_setup_on_parsed,
1423         .data = NULL,
1424         .help_str = "set port setup on iterator|event",
1425         .tokens = {
1426                 (void *)&cmd_set_port_setup_on_set,
1427                 (void *)&cmd_set_port_setup_on_port,
1428                 (void *)&cmd_set_port_setup_on_setup,
1429                 (void *)&cmd_set_port_setup_on_on,
1430                 (void *)&cmd_set_port_setup_on_mode,
1431                 NULL,
1432         },
1433 };
1434
1435 /* *** attach a specified port *** */
1436 struct cmd_operate_attach_port_result {
1437         cmdline_fixed_string_t port;
1438         cmdline_fixed_string_t keyword;
1439         cmdline_fixed_string_t identifier;
1440 };
1441
1442 static void cmd_operate_attach_port_parsed(void *parsed_result,
1443                                 __attribute__((unused)) struct cmdline *cl,
1444                                 __attribute__((unused)) void *data)
1445 {
1446         struct cmd_operate_attach_port_result *res = parsed_result;
1447
1448         if (!strcmp(res->keyword, "attach"))
1449                 attach_port(res->identifier);
1450         else
1451                 printf("Unknown parameter\n");
1452 }
1453
1454 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1455         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1456                         port, "port");
1457 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1458         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1459                         keyword, "attach");
1460 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1461         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1462                         identifier, NULL);
1463
1464 cmdline_parse_inst_t cmd_operate_attach_port = {
1465         .f = cmd_operate_attach_port_parsed,
1466         .data = NULL,
1467         .help_str = "port attach <identifier>: "
1468                 "(identifier: pci address or virtual dev name)",
1469         .tokens = {
1470                 (void *)&cmd_operate_attach_port_port,
1471                 (void *)&cmd_operate_attach_port_keyword,
1472                 (void *)&cmd_operate_attach_port_identifier,
1473                 NULL,
1474         },
1475 };
1476
1477 /* *** detach a specified port *** */
1478 struct cmd_operate_detach_port_result {
1479         cmdline_fixed_string_t port;
1480         cmdline_fixed_string_t keyword;
1481         portid_t port_id;
1482 };
1483
1484 static void cmd_operate_detach_port_parsed(void *parsed_result,
1485                                 __attribute__((unused)) struct cmdline *cl,
1486                                 __attribute__((unused)) void *data)
1487 {
1488         struct cmd_operate_detach_port_result *res = parsed_result;
1489
1490         if (!strcmp(res->keyword, "detach"))
1491                 detach_port_device(res->port_id);
1492         else
1493                 printf("Unknown parameter\n");
1494 }
1495
1496 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1497         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1498                         port, "port");
1499 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1500         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1501                         keyword, "detach");
1502 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1503         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1504                         port_id, UINT16);
1505
1506 cmdline_parse_inst_t cmd_operate_detach_port = {
1507         .f = cmd_operate_detach_port_parsed,
1508         .data = NULL,
1509         .help_str = "port detach <port_id>",
1510         .tokens = {
1511                 (void *)&cmd_operate_detach_port_port,
1512                 (void *)&cmd_operate_detach_port_keyword,
1513                 (void *)&cmd_operate_detach_port_port_id,
1514                 NULL,
1515         },
1516 };
1517
1518 /* *** detach device by identifier *** */
1519 struct cmd_operate_detach_device_result {
1520         cmdline_fixed_string_t device;
1521         cmdline_fixed_string_t keyword;
1522         cmdline_fixed_string_t identifier;
1523 };
1524
1525 static void cmd_operate_detach_device_parsed(void *parsed_result,
1526                                 __attribute__((unused)) struct cmdline *cl,
1527                                 __attribute__((unused)) void *data)
1528 {
1529         struct cmd_operate_detach_device_result *res = parsed_result;
1530
1531         if (!strcmp(res->keyword, "detach"))
1532                 detach_device(res->identifier);
1533         else
1534                 printf("Unknown parameter\n");
1535 }
1536
1537 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1538         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1539                         device, "device");
1540 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1541         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1542                         keyword, "detach");
1543 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1544         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1545                         identifier, NULL);
1546
1547 cmdline_parse_inst_t cmd_operate_detach_device = {
1548         .f = cmd_operate_detach_device_parsed,
1549         .data = NULL,
1550         .help_str = "device detach <identifier>:"
1551                 "(identifier: pci address or virtual dev name)",
1552         .tokens = {
1553                 (void *)&cmd_operate_detach_device_device,
1554                 (void *)&cmd_operate_detach_device_keyword,
1555                 (void *)&cmd_operate_detach_device_identifier,
1556                 NULL,
1557         },
1558 };
1559 /* *** configure speed for all ports *** */
1560 struct cmd_config_speed_all {
1561         cmdline_fixed_string_t port;
1562         cmdline_fixed_string_t keyword;
1563         cmdline_fixed_string_t all;
1564         cmdline_fixed_string_t item1;
1565         cmdline_fixed_string_t item2;
1566         cmdline_fixed_string_t value1;
1567         cmdline_fixed_string_t value2;
1568 };
1569
1570 static int
1571 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1572 {
1573
1574         int duplex;
1575
1576         if (!strcmp(duplexstr, "half")) {
1577                 duplex = ETH_LINK_HALF_DUPLEX;
1578         } else if (!strcmp(duplexstr, "full")) {
1579                 duplex = ETH_LINK_FULL_DUPLEX;
1580         } else if (!strcmp(duplexstr, "auto")) {
1581                 duplex = ETH_LINK_FULL_DUPLEX;
1582         } else {
1583                 printf("Unknown duplex parameter\n");
1584                 return -1;
1585         }
1586
1587         if (!strcmp(speedstr, "10")) {
1588                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1589                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1590         } else if (!strcmp(speedstr, "100")) {
1591                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1592                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1593         } else {
1594                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1595                         printf("Invalid speed/duplex parameters\n");
1596                         return -1;
1597                 }
1598                 if (!strcmp(speedstr, "1000")) {
1599                         *speed = ETH_LINK_SPEED_1G;
1600                 } else if (!strcmp(speedstr, "10000")) {
1601                         *speed = ETH_LINK_SPEED_10G;
1602                 } else if (!strcmp(speedstr, "25000")) {
1603                         *speed = ETH_LINK_SPEED_25G;
1604                 } else if (!strcmp(speedstr, "40000")) {
1605                         *speed = ETH_LINK_SPEED_40G;
1606                 } else if (!strcmp(speedstr, "50000")) {
1607                         *speed = ETH_LINK_SPEED_50G;
1608                 } else if (!strcmp(speedstr, "100000")) {
1609                         *speed = ETH_LINK_SPEED_100G;
1610                 } else if (!strcmp(speedstr, "auto")) {
1611                         *speed = ETH_LINK_SPEED_AUTONEG;
1612                 } else {
1613                         printf("Unknown speed parameter\n");
1614                         return -1;
1615                 }
1616         }
1617
1618         return 0;
1619 }
1620
1621 static void
1622 cmd_config_speed_all_parsed(void *parsed_result,
1623                         __attribute__((unused)) struct cmdline *cl,
1624                         __attribute__((unused)) void *data)
1625 {
1626         struct cmd_config_speed_all *res = parsed_result;
1627         uint32_t link_speed;
1628         portid_t pid;
1629
1630         if (!all_ports_stopped()) {
1631                 printf("Please stop all ports first\n");
1632                 return;
1633         }
1634
1635         if (parse_and_check_speed_duplex(res->value1, res->value2,
1636                         &link_speed) < 0)
1637                 return;
1638
1639         RTE_ETH_FOREACH_DEV(pid) {
1640                 ports[pid].dev_conf.link_speeds = link_speed;
1641         }
1642
1643         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1644 }
1645
1646 cmdline_parse_token_string_t cmd_config_speed_all_port =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1648 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1649         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1650                                                         "config");
1651 cmdline_parse_token_string_t cmd_config_speed_all_all =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1653 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1654         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1655 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1657                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1658 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1660 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1662                                                 "half#full#auto");
1663
1664 cmdline_parse_inst_t cmd_config_speed_all = {
1665         .f = cmd_config_speed_all_parsed,
1666         .data = NULL,
1667         .help_str = "port config all speed "
1668                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1669                                                         "half|full|auto",
1670         .tokens = {
1671                 (void *)&cmd_config_speed_all_port,
1672                 (void *)&cmd_config_speed_all_keyword,
1673                 (void *)&cmd_config_speed_all_all,
1674                 (void *)&cmd_config_speed_all_item1,
1675                 (void *)&cmd_config_speed_all_value1,
1676                 (void *)&cmd_config_speed_all_item2,
1677                 (void *)&cmd_config_speed_all_value2,
1678                 NULL,
1679         },
1680 };
1681
1682 /* *** configure speed for specific port *** */
1683 struct cmd_config_speed_specific {
1684         cmdline_fixed_string_t port;
1685         cmdline_fixed_string_t keyword;
1686         portid_t id;
1687         cmdline_fixed_string_t item1;
1688         cmdline_fixed_string_t item2;
1689         cmdline_fixed_string_t value1;
1690         cmdline_fixed_string_t value2;
1691 };
1692
1693 static void
1694 cmd_config_speed_specific_parsed(void *parsed_result,
1695                                 __attribute__((unused)) struct cmdline *cl,
1696                                 __attribute__((unused)) void *data)
1697 {
1698         struct cmd_config_speed_specific *res = parsed_result;
1699         uint32_t link_speed;
1700
1701         if (!all_ports_stopped()) {
1702                 printf("Please stop all ports first\n");
1703                 return;
1704         }
1705
1706         if (port_id_is_invalid(res->id, ENABLED_WARN))
1707                 return;
1708
1709         if (parse_and_check_speed_duplex(res->value1, res->value2,
1710                         &link_speed) < 0)
1711                 return;
1712
1713         ports[res->id].dev_conf.link_speeds = link_speed;
1714
1715         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1716 }
1717
1718
1719 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1720         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1721                                                                 "port");
1722 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1723         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1724                                                                 "config");
1725 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1726         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1727 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1728         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1729                                                                 "speed");
1730 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1732                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1733 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1734         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1735                                                                 "duplex");
1736 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1737         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1738                                                         "half#full#auto");
1739
1740 cmdline_parse_inst_t cmd_config_speed_specific = {
1741         .f = cmd_config_speed_specific_parsed,
1742         .data = NULL,
1743         .help_str = "port config <port_id> speed "
1744                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1745                                                         "half|full|auto",
1746         .tokens = {
1747                 (void *)&cmd_config_speed_specific_port,
1748                 (void *)&cmd_config_speed_specific_keyword,
1749                 (void *)&cmd_config_speed_specific_id,
1750                 (void *)&cmd_config_speed_specific_item1,
1751                 (void *)&cmd_config_speed_specific_value1,
1752                 (void *)&cmd_config_speed_specific_item2,
1753                 (void *)&cmd_config_speed_specific_value2,
1754                 NULL,
1755         },
1756 };
1757
1758 /* *** configure loopback for all ports *** */
1759 struct cmd_config_loopback_all {
1760         cmdline_fixed_string_t port;
1761         cmdline_fixed_string_t keyword;
1762         cmdline_fixed_string_t all;
1763         cmdline_fixed_string_t item;
1764         uint32_t mode;
1765 };
1766
1767 static void
1768 cmd_config_loopback_all_parsed(void *parsed_result,
1769                         __attribute__((unused)) struct cmdline *cl,
1770                         __attribute__((unused)) void *data)
1771 {
1772         struct cmd_config_loopback_all *res = parsed_result;
1773         portid_t pid;
1774
1775         if (!all_ports_stopped()) {
1776                 printf("Please stop all ports first\n");
1777                 return;
1778         }
1779
1780         RTE_ETH_FOREACH_DEV(pid) {
1781                 ports[pid].dev_conf.lpbk_mode = res->mode;
1782         }
1783
1784         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1785 }
1786
1787 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1789 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1790         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1791                                                         "config");
1792 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1794 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1795         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1796                                                         "loopback");
1797 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1798         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1799
1800 cmdline_parse_inst_t cmd_config_loopback_all = {
1801         .f = cmd_config_loopback_all_parsed,
1802         .data = NULL,
1803         .help_str = "port config all loopback <mode>",
1804         .tokens = {
1805                 (void *)&cmd_config_loopback_all_port,
1806                 (void *)&cmd_config_loopback_all_keyword,
1807                 (void *)&cmd_config_loopback_all_all,
1808                 (void *)&cmd_config_loopback_all_item,
1809                 (void *)&cmd_config_loopback_all_mode,
1810                 NULL,
1811         },
1812 };
1813
1814 /* *** configure loopback for specific port *** */
1815 struct cmd_config_loopback_specific {
1816         cmdline_fixed_string_t port;
1817         cmdline_fixed_string_t keyword;
1818         uint16_t port_id;
1819         cmdline_fixed_string_t item;
1820         uint32_t mode;
1821 };
1822
1823 static void
1824 cmd_config_loopback_specific_parsed(void *parsed_result,
1825                                 __attribute__((unused)) struct cmdline *cl,
1826                                 __attribute__((unused)) void *data)
1827 {
1828         struct cmd_config_loopback_specific *res = parsed_result;
1829
1830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1831                 return;
1832
1833         if (!port_is_stopped(res->port_id)) {
1834                 printf("Please stop port %u first\n", res->port_id);
1835                 return;
1836         }
1837
1838         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1839
1840         cmd_reconfig_device_queue(res->port_id, 1, 1);
1841 }
1842
1843
1844 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1845         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1846                                                                 "port");
1847 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1848         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1849                                                                 "config");
1850 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1851         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1852                                                                 UINT16);
1853 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1854         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1855                                                                 "loopback");
1856 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1857         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1858                               UINT32);
1859
1860 cmdline_parse_inst_t cmd_config_loopback_specific = {
1861         .f = cmd_config_loopback_specific_parsed,
1862         .data = NULL,
1863         .help_str = "port config <port_id> loopback <mode>",
1864         .tokens = {
1865                 (void *)&cmd_config_loopback_specific_port,
1866                 (void *)&cmd_config_loopback_specific_keyword,
1867                 (void *)&cmd_config_loopback_specific_id,
1868                 (void *)&cmd_config_loopback_specific_item,
1869                 (void *)&cmd_config_loopback_specific_mode,
1870                 NULL,
1871         },
1872 };
1873
1874 /* *** configure txq/rxq, txd/rxd *** */
1875 struct cmd_config_rx_tx {
1876         cmdline_fixed_string_t port;
1877         cmdline_fixed_string_t keyword;
1878         cmdline_fixed_string_t all;
1879         cmdline_fixed_string_t name;
1880         uint16_t value;
1881 };
1882
1883 static void
1884 cmd_config_rx_tx_parsed(void *parsed_result,
1885                         __attribute__((unused)) struct cmdline *cl,
1886                         __attribute__((unused)) void *data)
1887 {
1888         struct cmd_config_rx_tx *res = parsed_result;
1889
1890         if (!all_ports_stopped()) {
1891                 printf("Please stop all ports first\n");
1892                 return;
1893         }
1894         if (!strcmp(res->name, "rxq")) {
1895                 if (!res->value && !nb_txq) {
1896                         printf("Warning: Either rx or tx queues should be non zero\n");
1897                         return;
1898                 }
1899                 if (check_nb_rxq(res->value) != 0)
1900                         return;
1901                 nb_rxq = res->value;
1902         }
1903         else if (!strcmp(res->name, "txq")) {
1904                 if (!res->value && !nb_rxq) {
1905                         printf("Warning: Either rx or tx queues should be non zero\n");
1906                         return;
1907                 }
1908                 if (check_nb_txq(res->value) != 0)
1909                         return;
1910                 nb_txq = res->value;
1911         }
1912         else if (!strcmp(res->name, "rxd")) {
1913                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1914                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1915                                         res->value, RTE_TEST_RX_DESC_MAX);
1916                         return;
1917                 }
1918                 nb_rxd = res->value;
1919         } else if (!strcmp(res->name, "txd")) {
1920                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1921                         printf("txd %d invalid - must be > 0 && <= %d\n",
1922                                         res->value, RTE_TEST_TX_DESC_MAX);
1923                         return;
1924                 }
1925                 nb_txd = res->value;
1926         } else {
1927                 printf("Unknown parameter\n");
1928                 return;
1929         }
1930
1931         fwd_config_setup();
1932
1933         init_port_config();
1934
1935         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1936 }
1937
1938 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1940 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1941         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1942 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1943         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1944 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1945         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1946                                                 "rxq#txq#rxd#txd");
1947 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1948         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1949
1950 cmdline_parse_inst_t cmd_config_rx_tx = {
1951         .f = cmd_config_rx_tx_parsed,
1952         .data = NULL,
1953         .help_str = "port config all rxq|txq|rxd|txd <value>",
1954         .tokens = {
1955                 (void *)&cmd_config_rx_tx_port,
1956                 (void *)&cmd_config_rx_tx_keyword,
1957                 (void *)&cmd_config_rx_tx_all,
1958                 (void *)&cmd_config_rx_tx_name,
1959                 (void *)&cmd_config_rx_tx_value,
1960                 NULL,
1961         },
1962 };
1963
1964 /* *** config max packet length *** */
1965 struct cmd_config_max_pkt_len_result {
1966         cmdline_fixed_string_t port;
1967         cmdline_fixed_string_t keyword;
1968         cmdline_fixed_string_t all;
1969         cmdline_fixed_string_t name;
1970         uint32_t value;
1971 };
1972
1973 static void
1974 cmd_config_max_pkt_len_parsed(void *parsed_result,
1975                                 __attribute__((unused)) struct cmdline *cl,
1976                                 __attribute__((unused)) void *data)
1977 {
1978         struct cmd_config_max_pkt_len_result *res = parsed_result;
1979         portid_t pid;
1980
1981         if (!all_ports_stopped()) {
1982                 printf("Please stop all ports first\n");
1983                 return;
1984         }
1985
1986         RTE_ETH_FOREACH_DEV(pid) {
1987                 struct rte_port *port = &ports[pid];
1988                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1989
1990                 if (!strcmp(res->name, "max-pkt-len")) {
1991                         if (res->value < RTE_ETHER_MIN_LEN) {
1992                                 printf("max-pkt-len can not be less than %d\n",
1993                                                 RTE_ETHER_MIN_LEN);
1994                                 return;
1995                         }
1996                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1997                                 return;
1998
1999                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2000                         if (res->value > RTE_ETHER_MAX_LEN)
2001                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2002                         else
2003                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2004                         port->dev_conf.rxmode.offloads = rx_offloads;
2005                 } else {
2006                         printf("Unknown parameter\n");
2007                         return;
2008                 }
2009         }
2010
2011         init_port_config();
2012
2013         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2014 }
2015
2016 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2018                                                                 "port");
2019 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2020         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2021                                                                 "config");
2022 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2023         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2024                                                                 "all");
2025 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2026         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2027                                                                 "max-pkt-len");
2028 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2029         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2030                                                                 UINT32);
2031
2032 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2033         .f = cmd_config_max_pkt_len_parsed,
2034         .data = NULL,
2035         .help_str = "port config all max-pkt-len <value>",
2036         .tokens = {
2037                 (void *)&cmd_config_max_pkt_len_port,
2038                 (void *)&cmd_config_max_pkt_len_keyword,
2039                 (void *)&cmd_config_max_pkt_len_all,
2040                 (void *)&cmd_config_max_pkt_len_name,
2041                 (void *)&cmd_config_max_pkt_len_value,
2042                 NULL,
2043         },
2044 };
2045
2046 /* *** configure port MTU *** */
2047 struct cmd_config_mtu_result {
2048         cmdline_fixed_string_t port;
2049         cmdline_fixed_string_t keyword;
2050         cmdline_fixed_string_t mtu;
2051         portid_t port_id;
2052         uint16_t value;
2053 };
2054
2055 static void
2056 cmd_config_mtu_parsed(void *parsed_result,
2057                       __attribute__((unused)) struct cmdline *cl,
2058                       __attribute__((unused)) void *data)
2059 {
2060         struct cmd_config_mtu_result *res = parsed_result;
2061
2062         if (res->value < RTE_ETHER_MIN_LEN) {
2063                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2064                 return;
2065         }
2066         port_mtu_set(res->port_id, res->value);
2067 }
2068
2069 cmdline_parse_token_string_t cmd_config_mtu_port =
2070         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2071                                  "port");
2072 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2073         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2074                                  "config");
2075 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2076         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2077                                  "mtu");
2078 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2079         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2080 cmdline_parse_token_num_t cmd_config_mtu_value =
2081         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2082
2083 cmdline_parse_inst_t cmd_config_mtu = {
2084         .f = cmd_config_mtu_parsed,
2085         .data = NULL,
2086         .help_str = "port config mtu <port_id> <value>",
2087         .tokens = {
2088                 (void *)&cmd_config_mtu_port,
2089                 (void *)&cmd_config_mtu_keyword,
2090                 (void *)&cmd_config_mtu_mtu,
2091                 (void *)&cmd_config_mtu_port_id,
2092                 (void *)&cmd_config_mtu_value,
2093                 NULL,
2094         },
2095 };
2096
2097 /* *** configure rx mode *** */
2098 struct cmd_config_rx_mode_flag {
2099         cmdline_fixed_string_t port;
2100         cmdline_fixed_string_t keyword;
2101         cmdline_fixed_string_t all;
2102         cmdline_fixed_string_t name;
2103         cmdline_fixed_string_t value;
2104 };
2105
2106 static void
2107 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2108                                 __attribute__((unused)) struct cmdline *cl,
2109                                 __attribute__((unused)) void *data)
2110 {
2111         struct cmd_config_rx_mode_flag *res = parsed_result;
2112
2113         if (!all_ports_stopped()) {
2114                 printf("Please stop all ports first\n");
2115                 return;
2116         }
2117
2118         if (!strcmp(res->name, "drop-en")) {
2119                 if (!strcmp(res->value, "on"))
2120                         rx_drop_en = 1;
2121                 else if (!strcmp(res->value, "off"))
2122                         rx_drop_en = 0;
2123                 else {
2124                         printf("Unknown parameter\n");
2125                         return;
2126                 }
2127         } else {
2128                 printf("Unknown parameter\n");
2129                 return;
2130         }
2131
2132         init_port_config();
2133
2134         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2135 }
2136
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2139 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2140         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2141                                                                 "config");
2142 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2143         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2144 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2145         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2146                                         "drop-en");
2147 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2148         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2149                                                         "on#off");
2150
2151 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2152         .f = cmd_config_rx_mode_flag_parsed,
2153         .data = NULL,
2154         .help_str = "port config all drop-en on|off",
2155         .tokens = {
2156                 (void *)&cmd_config_rx_mode_flag_port,
2157                 (void *)&cmd_config_rx_mode_flag_keyword,
2158                 (void *)&cmd_config_rx_mode_flag_all,
2159                 (void *)&cmd_config_rx_mode_flag_name,
2160                 (void *)&cmd_config_rx_mode_flag_value,
2161                 NULL,
2162         },
2163 };
2164
2165 /* *** configure rss *** */
2166 struct cmd_config_rss {
2167         cmdline_fixed_string_t port;
2168         cmdline_fixed_string_t keyword;
2169         cmdline_fixed_string_t all;
2170         cmdline_fixed_string_t name;
2171         cmdline_fixed_string_t value;
2172 };
2173
2174 static void
2175 cmd_config_rss_parsed(void *parsed_result,
2176                         __attribute__((unused)) struct cmdline *cl,
2177                         __attribute__((unused)) void *data)
2178 {
2179         struct cmd_config_rss *res = parsed_result;
2180         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2181         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2182         int use_default = 0;
2183         int all_updated = 1;
2184         int diag;
2185         uint16_t i;
2186         int ret;
2187
2188         if (!strcmp(res->value, "all"))
2189                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2190                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2191                                         ETH_RSS_L2_PAYLOAD;
2192         else if (!strcmp(res->value, "ip"))
2193                 rss_conf.rss_hf = ETH_RSS_IP;
2194         else if (!strcmp(res->value, "udp"))
2195                 rss_conf.rss_hf = ETH_RSS_UDP;
2196         else if (!strcmp(res->value, "tcp"))
2197                 rss_conf.rss_hf = ETH_RSS_TCP;
2198         else if (!strcmp(res->value, "sctp"))
2199                 rss_conf.rss_hf = ETH_RSS_SCTP;
2200         else if (!strcmp(res->value, "ether"))
2201                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2202         else if (!strcmp(res->value, "port"))
2203                 rss_conf.rss_hf = ETH_RSS_PORT;
2204         else if (!strcmp(res->value, "vxlan"))
2205                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2206         else if (!strcmp(res->value, "geneve"))
2207                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2208         else if (!strcmp(res->value, "nvgre"))
2209                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2210         else if (!strcmp(res->value, "l3-src-only"))
2211                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2212         else if (!strcmp(res->value, "l3-dst-only"))
2213                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2214         else if (!strcmp(res->value, "l4-src-only"))
2215                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2216         else if (!strcmp(res->value, "l4-dst-only"))
2217                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2218         else if (!strcmp(res->value, "none"))
2219                 rss_conf.rss_hf = 0;
2220         else if (!strcmp(res->value, "default"))
2221                 use_default = 1;
2222         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2223                                                 atoi(res->value) < 64)
2224                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2225         else {
2226                 printf("Unknown parameter\n");
2227                 return;
2228         }
2229         rss_conf.rss_key = NULL;
2230         /* Update global configuration for RSS types. */
2231         RTE_ETH_FOREACH_DEV(i) {
2232                 struct rte_eth_rss_conf local_rss_conf;
2233
2234                 ret = eth_dev_info_get_print_err(i, &dev_info);
2235                 if (ret != 0)
2236                         return;
2237
2238                 if (use_default)
2239                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2240
2241                 local_rss_conf = rss_conf;
2242                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2243                         dev_info.flow_type_rss_offloads;
2244                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2245                         printf("Port %u modified RSS hash function based on hardware support,"
2246                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2247                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2248                 }
2249                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2250                 if (diag < 0) {
2251                         all_updated = 0;
2252                         printf("Configuration of RSS hash at ethernet port %d "
2253                                 "failed with error (%d): %s.\n",
2254                                 i, -diag, strerror(-diag));
2255                 }
2256         }
2257         if (all_updated && !use_default)
2258                 rss_hf = rss_conf.rss_hf;
2259 }
2260
2261 cmdline_parse_token_string_t cmd_config_rss_port =
2262         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2263 cmdline_parse_token_string_t cmd_config_rss_keyword =
2264         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2265 cmdline_parse_token_string_t cmd_config_rss_all =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2267 cmdline_parse_token_string_t cmd_config_rss_name =
2268         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2269 cmdline_parse_token_string_t cmd_config_rss_value =
2270         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2271
2272 cmdline_parse_inst_t cmd_config_rss = {
2273         .f = cmd_config_rss_parsed,
2274         .data = NULL,
2275         .help_str = "port config all rss "
2276                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2277         .tokens = {
2278                 (void *)&cmd_config_rss_port,
2279                 (void *)&cmd_config_rss_keyword,
2280                 (void *)&cmd_config_rss_all,
2281                 (void *)&cmd_config_rss_name,
2282                 (void *)&cmd_config_rss_value,
2283                 NULL,
2284         },
2285 };
2286
2287 /* *** configure rss hash key *** */
2288 struct cmd_config_rss_hash_key {
2289         cmdline_fixed_string_t port;
2290         cmdline_fixed_string_t config;
2291         portid_t port_id;
2292         cmdline_fixed_string_t rss_hash_key;
2293         cmdline_fixed_string_t rss_type;
2294         cmdline_fixed_string_t key;
2295 };
2296
2297 static uint8_t
2298 hexa_digit_to_value(char hexa_digit)
2299 {
2300         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2301                 return (uint8_t) (hexa_digit - '0');
2302         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2303                 return (uint8_t) ((hexa_digit - 'a') + 10);
2304         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2305                 return (uint8_t) ((hexa_digit - 'A') + 10);
2306         /* Invalid hexa digit */
2307         return 0xFF;
2308 }
2309
2310 static uint8_t
2311 parse_and_check_key_hexa_digit(char *key, int idx)
2312 {
2313         uint8_t hexa_v;
2314
2315         hexa_v = hexa_digit_to_value(key[idx]);
2316         if (hexa_v == 0xFF)
2317                 printf("invalid key: character %c at position %d is not a "
2318                        "valid hexa digit\n", key[idx], idx);
2319         return hexa_v;
2320 }
2321
2322 static void
2323 cmd_config_rss_hash_key_parsed(void *parsed_result,
2324                                __attribute__((unused)) struct cmdline *cl,
2325                                __attribute__((unused)) void *data)
2326 {
2327         struct cmd_config_rss_hash_key *res = parsed_result;
2328         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2329         uint8_t xdgt0;
2330         uint8_t xdgt1;
2331         int i;
2332         struct rte_eth_dev_info dev_info;
2333         uint8_t hash_key_size;
2334         uint32_t key_len;
2335         int ret;
2336
2337         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2338         if (ret != 0)
2339                 return;
2340
2341         if (dev_info.hash_key_size > 0 &&
2342                         dev_info.hash_key_size <= sizeof(hash_key))
2343                 hash_key_size = dev_info.hash_key_size;
2344         else {
2345                 printf("dev_info did not provide a valid hash key size\n");
2346                 return;
2347         }
2348         /* Check the length of the RSS hash key */
2349         key_len = strlen(res->key);
2350         if (key_len != (hash_key_size * 2)) {
2351                 printf("key length: %d invalid - key must be a string of %d"
2352                            " hexa-decimal numbers\n",
2353                            (int) key_len, hash_key_size * 2);
2354                 return;
2355         }
2356         /* Translate RSS hash key into binary representation */
2357         for (i = 0; i < hash_key_size; i++) {
2358                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2359                 if (xdgt0 == 0xFF)
2360                         return;
2361                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2362                 if (xdgt1 == 0xFF)
2363                         return;
2364                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2365         }
2366         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2367                         hash_key_size);
2368 }
2369
2370 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2372 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2373         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2374                                  "config");
2375 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2376         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2377 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2378         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2379                                  rss_hash_key, "rss-hash-key");
2380 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2381         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2382                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2383                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2384                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2385                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2386                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only");
2387 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2388         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2389
2390 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2391         .f = cmd_config_rss_hash_key_parsed,
2392         .data = NULL,
2393         .help_str = "port config <port_id> rss-hash-key "
2394                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2395                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2396                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2397                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only "
2398                 "<string of hex digits (variable length, NIC dependent)>",
2399         .tokens = {
2400                 (void *)&cmd_config_rss_hash_key_port,
2401                 (void *)&cmd_config_rss_hash_key_config,
2402                 (void *)&cmd_config_rss_hash_key_port_id,
2403                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2404                 (void *)&cmd_config_rss_hash_key_rss_type,
2405                 (void *)&cmd_config_rss_hash_key_value,
2406                 NULL,
2407         },
2408 };
2409
2410 /* *** configure port rxq/txq ring size *** */
2411 struct cmd_config_rxtx_ring_size {
2412         cmdline_fixed_string_t port;
2413         cmdline_fixed_string_t config;
2414         portid_t portid;
2415         cmdline_fixed_string_t rxtxq;
2416         uint16_t qid;
2417         cmdline_fixed_string_t rsize;
2418         uint16_t size;
2419 };
2420
2421 static void
2422 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2423                                  __attribute__((unused)) struct cmdline *cl,
2424                                  __attribute__((unused)) void *data)
2425 {
2426         struct cmd_config_rxtx_ring_size *res = parsed_result;
2427         struct rte_port *port;
2428         uint8_t isrx;
2429
2430         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2431                 return;
2432
2433         if (res->portid == (portid_t)RTE_PORT_ALL) {
2434                 printf("Invalid port id\n");
2435                 return;
2436         }
2437
2438         port = &ports[res->portid];
2439
2440         if (!strcmp(res->rxtxq, "rxq"))
2441                 isrx = 1;
2442         else if (!strcmp(res->rxtxq, "txq"))
2443                 isrx = 0;
2444         else {
2445                 printf("Unknown parameter\n");
2446                 return;
2447         }
2448
2449         if (isrx && rx_queue_id_is_invalid(res->qid))
2450                 return;
2451         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2452                 return;
2453
2454         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2455                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2456                        rx_free_thresh);
2457                 return;
2458         }
2459
2460         if (isrx)
2461                 port->nb_rx_desc[res->qid] = res->size;
2462         else
2463                 port->nb_tx_desc[res->qid] = res->size;
2464
2465         cmd_reconfig_device_queue(res->portid, 0, 1);
2466 }
2467
2468 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2469         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2470                                  port, "port");
2471 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2472         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2473                                  config, "config");
2474 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2475         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2476                                  portid, UINT16);
2477 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2478         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2479                                  rxtxq, "rxq#txq");
2480 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2481         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2482                               qid, UINT16);
2483 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2484         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2485                                  rsize, "ring_size");
2486 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2487         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2488                               size, UINT16);
2489
2490 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2491         .f = cmd_config_rxtx_ring_size_parsed,
2492         .data = NULL,
2493         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2494         .tokens = {
2495                 (void *)&cmd_config_rxtx_ring_size_port,
2496                 (void *)&cmd_config_rxtx_ring_size_config,
2497                 (void *)&cmd_config_rxtx_ring_size_portid,
2498                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2499                 (void *)&cmd_config_rxtx_ring_size_qid,
2500                 (void *)&cmd_config_rxtx_ring_size_rsize,
2501                 (void *)&cmd_config_rxtx_ring_size_size,
2502                 NULL,
2503         },
2504 };
2505
2506 /* *** configure port rxq/txq start/stop *** */
2507 struct cmd_config_rxtx_queue {
2508         cmdline_fixed_string_t port;
2509         portid_t portid;
2510         cmdline_fixed_string_t rxtxq;
2511         uint16_t qid;
2512         cmdline_fixed_string_t opname;
2513 };
2514
2515 static void
2516 cmd_config_rxtx_queue_parsed(void *parsed_result,
2517                         __attribute__((unused)) struct cmdline *cl,
2518                         __attribute__((unused)) void *data)
2519 {
2520         struct cmd_config_rxtx_queue *res = parsed_result;
2521         uint8_t isrx;
2522         uint8_t isstart;
2523         int ret = 0;
2524
2525         if (test_done == 0) {
2526                 printf("Please stop forwarding first\n");
2527                 return;
2528         }
2529
2530         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2531                 return;
2532
2533         if (port_is_started(res->portid) != 1) {
2534                 printf("Please start port %u first\n", res->portid);
2535                 return;
2536         }
2537
2538         if (!strcmp(res->rxtxq, "rxq"))
2539                 isrx = 1;
2540         else if (!strcmp(res->rxtxq, "txq"))
2541                 isrx = 0;
2542         else {
2543                 printf("Unknown parameter\n");
2544                 return;
2545         }
2546
2547         if (isrx && rx_queue_id_is_invalid(res->qid))
2548                 return;
2549         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2550                 return;
2551
2552         if (!strcmp(res->opname, "start"))
2553                 isstart = 1;
2554         else if (!strcmp(res->opname, "stop"))
2555                 isstart = 0;
2556         else {
2557                 printf("Unknown parameter\n");
2558                 return;
2559         }
2560
2561         if (isstart && isrx)
2562                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2563         else if (!isstart && isrx)
2564                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2565         else if (isstart && !isrx)
2566                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2567         else
2568                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2569
2570         if (ret == -ENOTSUP)
2571                 printf("Function not supported in PMD driver\n");
2572 }
2573
2574 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2575         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2576 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2577         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2578 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2579         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2580 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2581         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2582 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2583         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2584                                                 "start#stop");
2585
2586 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2587         .f = cmd_config_rxtx_queue_parsed,
2588         .data = NULL,
2589         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2590         .tokens = {
2591                 (void *)&cmd_config_rxtx_queue_port,
2592                 (void *)&cmd_config_rxtx_queue_portid,
2593                 (void *)&cmd_config_rxtx_queue_rxtxq,
2594                 (void *)&cmd_config_rxtx_queue_qid,
2595                 (void *)&cmd_config_rxtx_queue_opname,
2596                 NULL,
2597         },
2598 };
2599
2600 /* *** configure port rxq/txq deferred start on/off *** */
2601 struct cmd_config_deferred_start_rxtx_queue {
2602         cmdline_fixed_string_t port;
2603         portid_t port_id;
2604         cmdline_fixed_string_t rxtxq;
2605         uint16_t qid;
2606         cmdline_fixed_string_t opname;
2607         cmdline_fixed_string_t state;
2608 };
2609
2610 static void
2611 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2612                         __attribute__((unused)) struct cmdline *cl,
2613                         __attribute__((unused)) void *data)
2614 {
2615         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2616         struct rte_port *port;
2617         uint8_t isrx;
2618         uint8_t ison;
2619         uint8_t needreconfig = 0;
2620
2621         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2622                 return;
2623
2624         if (port_is_started(res->port_id) != 0) {
2625                 printf("Please stop port %u first\n", res->port_id);
2626                 return;
2627         }
2628
2629         port = &ports[res->port_id];
2630
2631         isrx = !strcmp(res->rxtxq, "rxq");
2632
2633         if (isrx && rx_queue_id_is_invalid(res->qid))
2634                 return;
2635         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2636                 return;
2637
2638         ison = !strcmp(res->state, "on");
2639
2640         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2641                 port->rx_conf[res->qid].rx_deferred_start = ison;
2642                 needreconfig = 1;
2643         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2644                 port->tx_conf[res->qid].tx_deferred_start = ison;
2645                 needreconfig = 1;
2646         }
2647
2648         if (needreconfig)
2649                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2650 }
2651
2652 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2654                                                 port, "port");
2655 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2656         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2657                                                 port_id, UINT16);
2658 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2659         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2660                                                 rxtxq, "rxq#txq");
2661 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2662         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2663                                                 qid, UINT16);
2664 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2665         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2666                                                 opname, "deferred_start");
2667 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2668         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2669                                                 state, "on#off");
2670
2671 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2672         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2673         .data = NULL,
2674         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2675         .tokens = {
2676                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2677                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2678                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2679                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2680                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2681                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2682                 NULL,
2683         },
2684 };
2685
2686 /* *** configure port rxq/txq setup *** */
2687 struct cmd_setup_rxtx_queue {
2688         cmdline_fixed_string_t port;
2689         portid_t portid;
2690         cmdline_fixed_string_t rxtxq;
2691         uint16_t qid;
2692         cmdline_fixed_string_t setup;
2693 };
2694
2695 /* Common CLI fields for queue setup */
2696 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2697         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2698 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2699         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2700 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2701         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2702 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2703         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2704 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2705         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2706
2707 static void
2708 cmd_setup_rxtx_queue_parsed(
2709         void *parsed_result,
2710         __attribute__((unused)) struct cmdline *cl,
2711         __attribute__((unused)) void *data)
2712 {
2713         struct cmd_setup_rxtx_queue *res = parsed_result;
2714         struct rte_port *port;
2715         struct rte_mempool *mp;
2716         unsigned int socket_id;
2717         uint8_t isrx = 0;
2718         int ret;
2719
2720         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2721                 return;
2722
2723         if (res->portid == (portid_t)RTE_PORT_ALL) {
2724                 printf("Invalid port id\n");
2725                 return;
2726         }
2727
2728         if (!strcmp(res->rxtxq, "rxq"))
2729                 isrx = 1;
2730         else if (!strcmp(res->rxtxq, "txq"))
2731                 isrx = 0;
2732         else {
2733                 printf("Unknown parameter\n");
2734                 return;
2735         }
2736
2737         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2738                 printf("Invalid rx queue\n");
2739                 return;
2740         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2741                 printf("Invalid tx queue\n");
2742                 return;
2743         }
2744
2745         port = &ports[res->portid];
2746         if (isrx) {
2747                 socket_id = rxring_numa[res->portid];
2748                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2749                         socket_id = port->socket_id;
2750
2751                 mp = mbuf_pool_find(socket_id);
2752                 if (mp == NULL) {
2753                         printf("Failed to setup RX queue: "
2754                                 "No mempool allocation"
2755                                 " on the socket %d\n",
2756                                 rxring_numa[res->portid]);
2757                         return;
2758                 }
2759                 ret = rte_eth_rx_queue_setup(res->portid,
2760                                              res->qid,
2761                                              port->nb_rx_desc[res->qid],
2762                                              socket_id,
2763                                              &port->rx_conf[res->qid],
2764                                              mp);
2765                 if (ret)
2766                         printf("Failed to setup RX queue\n");
2767         } else {
2768                 socket_id = txring_numa[res->portid];
2769                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2770                         socket_id = port->socket_id;
2771
2772                 ret = rte_eth_tx_queue_setup(res->portid,
2773                                              res->qid,
2774                                              port->nb_tx_desc[res->qid],
2775                                              socket_id,
2776                                              &port->tx_conf[res->qid]);
2777                 if (ret)
2778                         printf("Failed to setup TX queue\n");
2779         }
2780 }
2781
2782 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2783         .f = cmd_setup_rxtx_queue_parsed,
2784         .data = NULL,
2785         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2786         .tokens = {
2787                 (void *)&cmd_setup_rxtx_queue_port,
2788                 (void *)&cmd_setup_rxtx_queue_portid,
2789                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2790                 (void *)&cmd_setup_rxtx_queue_qid,
2791                 (void *)&cmd_setup_rxtx_queue_setup,
2792                 NULL,
2793         },
2794 };
2795
2796
2797 /* *** Configure RSS RETA *** */
2798 struct cmd_config_rss_reta {
2799         cmdline_fixed_string_t port;
2800         cmdline_fixed_string_t keyword;
2801         portid_t port_id;
2802         cmdline_fixed_string_t name;
2803         cmdline_fixed_string_t list_name;
2804         cmdline_fixed_string_t list_of_items;
2805 };
2806
2807 static int
2808 parse_reta_config(const char *str,
2809                   struct rte_eth_rss_reta_entry64 *reta_conf,
2810                   uint16_t nb_entries)
2811 {
2812         int i;
2813         unsigned size;
2814         uint16_t hash_index, idx, shift;
2815         uint16_t nb_queue;
2816         char s[256];
2817         const char *p, *p0 = str;
2818         char *end;
2819         enum fieldnames {
2820                 FLD_HASH_INDEX = 0,
2821                 FLD_QUEUE,
2822                 _NUM_FLD
2823         };
2824         unsigned long int_fld[_NUM_FLD];
2825         char *str_fld[_NUM_FLD];
2826
2827         while ((p = strchr(p0,'(')) != NULL) {
2828                 ++p;
2829                 if((p0 = strchr(p,')')) == NULL)
2830                         return -1;
2831
2832                 size = p0 - p;
2833                 if(size >= sizeof(s))
2834                         return -1;
2835
2836                 snprintf(s, sizeof(s), "%.*s", size, p);
2837                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2838                         return -1;
2839                 for (i = 0; i < _NUM_FLD; i++) {
2840                         errno = 0;
2841                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2842                         if (errno != 0 || end == str_fld[i] ||
2843                                         int_fld[i] > 65535)
2844                                 return -1;
2845                 }
2846
2847                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2848                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2849
2850                 if (hash_index >= nb_entries) {
2851                         printf("Invalid RETA hash index=%d\n", hash_index);
2852                         return -1;
2853                 }
2854
2855                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2856                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2857                 reta_conf[idx].mask |= (1ULL << shift);
2858                 reta_conf[idx].reta[shift] = nb_queue;
2859         }
2860
2861         return 0;
2862 }
2863
2864 static void
2865 cmd_set_rss_reta_parsed(void *parsed_result,
2866                         __attribute__((unused)) struct cmdline *cl,
2867                         __attribute__((unused)) void *data)
2868 {
2869         int ret;
2870         struct rte_eth_dev_info dev_info;
2871         struct rte_eth_rss_reta_entry64 reta_conf[8];
2872         struct cmd_config_rss_reta *res = parsed_result;
2873
2874         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2875         if (ret != 0)
2876                 return;
2877
2878         if (dev_info.reta_size == 0) {
2879                 printf("Redirection table size is 0 which is "
2880                                         "invalid for RSS\n");
2881                 return;
2882         } else
2883                 printf("The reta size of port %d is %u\n",
2884                         res->port_id, dev_info.reta_size);
2885         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2886                 printf("Currently do not support more than %u entries of "
2887                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2888                 return;
2889         }
2890
2891         memset(reta_conf, 0, sizeof(reta_conf));
2892         if (!strcmp(res->list_name, "reta")) {
2893                 if (parse_reta_config(res->list_of_items, reta_conf,
2894                                                 dev_info.reta_size)) {
2895                         printf("Invalid RSS Redirection Table "
2896                                         "config entered\n");
2897                         return;
2898                 }
2899                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2900                                 reta_conf, dev_info.reta_size);
2901                 if (ret != 0)
2902                         printf("Bad redirection table parameter, "
2903                                         "return code = %d \n", ret);
2904         }
2905 }
2906
2907 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2908         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2909 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2910         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2911 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2912         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2913 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2914         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2915 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2916         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2917 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2918         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2919                                  NULL);
2920 cmdline_parse_inst_t cmd_config_rss_reta = {
2921         .f = cmd_set_rss_reta_parsed,
2922         .data = NULL,
2923         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2924         .tokens = {
2925                 (void *)&cmd_config_rss_reta_port,
2926                 (void *)&cmd_config_rss_reta_keyword,
2927                 (void *)&cmd_config_rss_reta_port_id,
2928                 (void *)&cmd_config_rss_reta_name,
2929                 (void *)&cmd_config_rss_reta_list_name,
2930                 (void *)&cmd_config_rss_reta_list_of_items,
2931                 NULL,
2932         },
2933 };
2934
2935 /* *** SHOW PORT RETA INFO *** */
2936 struct cmd_showport_reta {
2937         cmdline_fixed_string_t show;
2938         cmdline_fixed_string_t port;
2939         portid_t port_id;
2940         cmdline_fixed_string_t rss;
2941         cmdline_fixed_string_t reta;
2942         uint16_t size;
2943         cmdline_fixed_string_t list_of_items;
2944 };
2945
2946 static int
2947 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2948                            uint16_t nb_entries,
2949                            char *str)
2950 {
2951         uint32_t size;
2952         const char *p, *p0 = str;
2953         char s[256];
2954         char *end;
2955         char *str_fld[8];
2956         uint16_t i;
2957         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2958                         RTE_RETA_GROUP_SIZE;
2959         int ret;
2960
2961         p = strchr(p0, '(');
2962         if (p == NULL)
2963                 return -1;
2964         p++;
2965         p0 = strchr(p, ')');
2966         if (p0 == NULL)
2967                 return -1;
2968         size = p0 - p;
2969         if (size >= sizeof(s)) {
2970                 printf("The string size exceeds the internal buffer size\n");
2971                 return -1;
2972         }
2973         snprintf(s, sizeof(s), "%.*s", size, p);
2974         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2975         if (ret <= 0 || ret != num) {
2976                 printf("The bits of masks do not match the number of "
2977                                         "reta entries: %u\n", num);
2978                 return -1;
2979         }
2980         for (i = 0; i < ret; i++)
2981                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2982
2983         return 0;
2984 }
2985
2986 static void
2987 cmd_showport_reta_parsed(void *parsed_result,
2988                          __attribute__((unused)) struct cmdline *cl,
2989                          __attribute__((unused)) void *data)
2990 {
2991         struct cmd_showport_reta *res = parsed_result;
2992         struct rte_eth_rss_reta_entry64 reta_conf[8];
2993         struct rte_eth_dev_info dev_info;
2994         uint16_t max_reta_size;
2995         int ret;
2996
2997         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2998         if (ret != 0)
2999                 return;
3000
3001         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3002         if (res->size == 0 || res->size > max_reta_size) {
3003                 printf("Invalid redirection table size: %u (1-%u)\n",
3004                         res->size, max_reta_size);
3005                 return;
3006         }
3007
3008         memset(reta_conf, 0, sizeof(reta_conf));
3009         if (showport_parse_reta_config(reta_conf, res->size,
3010                                 res->list_of_items) < 0) {
3011                 printf("Invalid string: %s for reta masks\n",
3012                                         res->list_of_items);
3013                 return;
3014         }
3015         port_rss_reta_info(res->port_id, reta_conf, res->size);
3016 }
3017
3018 cmdline_parse_token_string_t cmd_showport_reta_show =
3019         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3020 cmdline_parse_token_string_t cmd_showport_reta_port =
3021         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3022 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3023         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3024 cmdline_parse_token_string_t cmd_showport_reta_rss =
3025         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3026 cmdline_parse_token_string_t cmd_showport_reta_reta =
3027         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3028 cmdline_parse_token_num_t cmd_showport_reta_size =
3029         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3030 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3031         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3032                                         list_of_items, NULL);
3033
3034 cmdline_parse_inst_t cmd_showport_reta = {
3035         .f = cmd_showport_reta_parsed,
3036         .data = NULL,
3037         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3038         .tokens = {
3039                 (void *)&cmd_showport_reta_show,
3040                 (void *)&cmd_showport_reta_port,
3041                 (void *)&cmd_showport_reta_port_id,
3042                 (void *)&cmd_showport_reta_rss,
3043                 (void *)&cmd_showport_reta_reta,
3044                 (void *)&cmd_showport_reta_size,
3045                 (void *)&cmd_showport_reta_list_of_items,
3046                 NULL,
3047         },
3048 };
3049
3050 /* *** Show RSS hash configuration *** */
3051 struct cmd_showport_rss_hash {
3052         cmdline_fixed_string_t show;
3053         cmdline_fixed_string_t port;
3054         portid_t port_id;
3055         cmdline_fixed_string_t rss_hash;
3056         cmdline_fixed_string_t rss_type;
3057         cmdline_fixed_string_t key; /* optional argument */
3058 };
3059
3060 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3061                                 __attribute__((unused)) struct cmdline *cl,
3062                                 void *show_rss_key)
3063 {
3064         struct cmd_showport_rss_hash *res = parsed_result;
3065
3066         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3067 }
3068
3069 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3070         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3071 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3072         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3073 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3074         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3075 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3076         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3077                                  "rss-hash");
3078 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3079         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3080
3081 cmdline_parse_inst_t cmd_showport_rss_hash = {
3082         .f = cmd_showport_rss_hash_parsed,
3083         .data = NULL,
3084         .help_str = "show port <port_id> rss-hash",
3085         .tokens = {
3086                 (void *)&cmd_showport_rss_hash_show,
3087                 (void *)&cmd_showport_rss_hash_port,
3088                 (void *)&cmd_showport_rss_hash_port_id,
3089                 (void *)&cmd_showport_rss_hash_rss_hash,
3090                 NULL,
3091         },
3092 };
3093
3094 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3095         .f = cmd_showport_rss_hash_parsed,
3096         .data = (void *)1,
3097         .help_str = "show port <port_id> rss-hash key",
3098         .tokens = {
3099                 (void *)&cmd_showport_rss_hash_show,
3100                 (void *)&cmd_showport_rss_hash_port,
3101                 (void *)&cmd_showport_rss_hash_port_id,
3102                 (void *)&cmd_showport_rss_hash_rss_hash,
3103                 (void *)&cmd_showport_rss_hash_rss_key,
3104                 NULL,
3105         },
3106 };
3107
3108 /* *** Configure DCB *** */
3109 struct cmd_config_dcb {
3110         cmdline_fixed_string_t port;
3111         cmdline_fixed_string_t config;
3112         portid_t port_id;
3113         cmdline_fixed_string_t dcb;
3114         cmdline_fixed_string_t vt;
3115         cmdline_fixed_string_t vt_en;
3116         uint8_t num_tcs;
3117         cmdline_fixed_string_t pfc;
3118         cmdline_fixed_string_t pfc_en;
3119 };
3120
3121 static void
3122 cmd_config_dcb_parsed(void *parsed_result,
3123                         __attribute__((unused)) struct cmdline *cl,
3124                         __attribute__((unused)) void *data)
3125 {
3126         struct cmd_config_dcb *res = parsed_result;
3127         portid_t port_id = res->port_id;
3128         struct rte_port *port;
3129         uint8_t pfc_en;
3130         int ret;
3131
3132         port = &ports[port_id];
3133         /** Check if the port is not started **/
3134         if (port->port_status != RTE_PORT_STOPPED) {
3135                 printf("Please stop port %d first\n", port_id);
3136                 return;
3137         }
3138
3139         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3140                 printf("The invalid number of traffic class,"
3141                         " only 4 or 8 allowed.\n");
3142                 return;
3143         }
3144
3145         if (nb_fwd_lcores < res->num_tcs) {
3146                 printf("nb_cores shouldn't be less than number of TCs.\n");
3147                 return;
3148         }
3149         if (!strncmp(res->pfc_en, "on", 2))
3150                 pfc_en = 1;
3151         else
3152                 pfc_en = 0;
3153
3154         /* DCB in VT mode */
3155         if (!strncmp(res->vt_en, "on", 2))
3156                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3157                                 (enum rte_eth_nb_tcs)res->num_tcs,
3158                                 pfc_en);
3159         else
3160                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3161                                 (enum rte_eth_nb_tcs)res->num_tcs,
3162                                 pfc_en);
3163
3164
3165         if (ret != 0) {
3166                 printf("Cannot initialize network ports.\n");
3167                 return;
3168         }
3169
3170         cmd_reconfig_device_queue(port_id, 1, 1);
3171 }
3172
3173 cmdline_parse_token_string_t cmd_config_dcb_port =
3174         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3175 cmdline_parse_token_string_t cmd_config_dcb_config =
3176         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3177 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3178         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3179 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3180         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3181 cmdline_parse_token_string_t cmd_config_dcb_vt =
3182         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3183 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3184         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3185 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3186         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3187 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3188         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3189 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3190         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3191
3192 cmdline_parse_inst_t cmd_config_dcb = {
3193         .f = cmd_config_dcb_parsed,
3194         .data = NULL,
3195         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3196         .tokens = {
3197                 (void *)&cmd_config_dcb_port,
3198                 (void *)&cmd_config_dcb_config,
3199                 (void *)&cmd_config_dcb_port_id,
3200                 (void *)&cmd_config_dcb_dcb,
3201                 (void *)&cmd_config_dcb_vt,
3202                 (void *)&cmd_config_dcb_vt_en,
3203                 (void *)&cmd_config_dcb_num_tcs,
3204                 (void *)&cmd_config_dcb_pfc,
3205                 (void *)&cmd_config_dcb_pfc_en,
3206                 NULL,
3207         },
3208 };
3209
3210 /* *** configure number of packets per burst *** */
3211 struct cmd_config_burst {
3212         cmdline_fixed_string_t port;
3213         cmdline_fixed_string_t keyword;
3214         cmdline_fixed_string_t all;
3215         cmdline_fixed_string_t name;
3216         uint16_t value;
3217 };
3218
3219 static void
3220 cmd_config_burst_parsed(void *parsed_result,
3221                         __attribute__((unused)) struct cmdline *cl,
3222                         __attribute__((unused)) void *data)
3223 {
3224         struct cmd_config_burst *res = parsed_result;
3225         struct rte_eth_dev_info dev_info;
3226         uint16_t rec_nb_pkts;
3227         int ret;
3228
3229         if (!all_ports_stopped()) {
3230                 printf("Please stop all ports first\n");
3231                 return;
3232         }
3233
3234         if (!strcmp(res->name, "burst")) {
3235                 if (res->value == 0) {
3236                         /* If user gives a value of zero, query the PMD for
3237                          * its recommended Rx burst size. Testpmd uses a single
3238                          * size for all ports, so assume all ports are the same
3239                          * NIC model and use the values from Port 0.
3240                          */
3241                         ret = eth_dev_info_get_print_err(0, &dev_info);
3242                         if (ret != 0)
3243                                 return;
3244
3245                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3246
3247                         if (rec_nb_pkts == 0) {
3248                                 printf("PMD does not recommend a burst size.\n"
3249                                         "User provided value must be between"
3250                                         " 1 and %d\n", MAX_PKT_BURST);
3251                                 return;
3252                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3253                                 printf("PMD recommended burst size of %d"
3254                                         " exceeds maximum value of %d\n",
3255                                         rec_nb_pkts, MAX_PKT_BURST);
3256                                 return;
3257                         }
3258                         printf("Using PMD-provided burst value of %d\n",
3259                                 rec_nb_pkts);
3260                         nb_pkt_per_burst = rec_nb_pkts;
3261                 } else if (res->value > MAX_PKT_BURST) {
3262                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3263                         return;
3264                 } else
3265                         nb_pkt_per_burst = res->value;
3266         } else {
3267                 printf("Unknown parameter\n");
3268                 return;
3269         }
3270
3271         init_port_config();
3272
3273         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3274 }
3275
3276 cmdline_parse_token_string_t cmd_config_burst_port =
3277         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3278 cmdline_parse_token_string_t cmd_config_burst_keyword =
3279         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3280 cmdline_parse_token_string_t cmd_config_burst_all =
3281         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3282 cmdline_parse_token_string_t cmd_config_burst_name =
3283         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3284 cmdline_parse_token_num_t cmd_config_burst_value =
3285         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3286
3287 cmdline_parse_inst_t cmd_config_burst = {
3288         .f = cmd_config_burst_parsed,
3289         .data = NULL,
3290         .help_str = "port config all burst <value>",
3291         .tokens = {
3292                 (void *)&cmd_config_burst_port,
3293                 (void *)&cmd_config_burst_keyword,
3294                 (void *)&cmd_config_burst_all,
3295                 (void *)&cmd_config_burst_name,
3296                 (void *)&cmd_config_burst_value,
3297                 NULL,
3298         },
3299 };
3300
3301 /* *** configure rx/tx queues *** */
3302 struct cmd_config_thresh {
3303         cmdline_fixed_string_t port;
3304         cmdline_fixed_string_t keyword;
3305         cmdline_fixed_string_t all;
3306         cmdline_fixed_string_t name;
3307         uint8_t value;
3308 };
3309
3310 static void
3311 cmd_config_thresh_parsed(void *parsed_result,
3312                         __attribute__((unused)) struct cmdline *cl,
3313                         __attribute__((unused)) void *data)
3314 {
3315         struct cmd_config_thresh *res = parsed_result;
3316
3317         if (!all_ports_stopped()) {
3318                 printf("Please stop all ports first\n");
3319                 return;
3320         }
3321
3322         if (!strcmp(res->name, "txpt"))
3323                 tx_pthresh = res->value;
3324         else if(!strcmp(res->name, "txht"))
3325                 tx_hthresh = res->value;
3326         else if(!strcmp(res->name, "txwt"))
3327                 tx_wthresh = res->value;
3328         else if(!strcmp(res->name, "rxpt"))
3329                 rx_pthresh = res->value;
3330         else if(!strcmp(res->name, "rxht"))
3331                 rx_hthresh = res->value;
3332         else if(!strcmp(res->name, "rxwt"))
3333                 rx_wthresh = res->value;
3334         else {
3335                 printf("Unknown parameter\n");
3336                 return;
3337         }
3338
3339         init_port_config();
3340
3341         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3342 }
3343
3344 cmdline_parse_token_string_t cmd_config_thresh_port =
3345         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3346 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3347         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3348 cmdline_parse_token_string_t cmd_config_thresh_all =
3349         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3350 cmdline_parse_token_string_t cmd_config_thresh_name =
3351         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3352                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3353 cmdline_parse_token_num_t cmd_config_thresh_value =
3354         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3355
3356 cmdline_parse_inst_t cmd_config_thresh = {
3357         .f = cmd_config_thresh_parsed,
3358         .data = NULL,
3359         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3360         .tokens = {
3361                 (void *)&cmd_config_thresh_port,
3362                 (void *)&cmd_config_thresh_keyword,
3363                 (void *)&cmd_config_thresh_all,
3364                 (void *)&cmd_config_thresh_name,
3365                 (void *)&cmd_config_thresh_value,
3366                 NULL,
3367         },
3368 };
3369
3370 /* *** configure free/rs threshold *** */
3371 struct cmd_config_threshold {
3372         cmdline_fixed_string_t port;
3373         cmdline_fixed_string_t keyword;
3374         cmdline_fixed_string_t all;
3375         cmdline_fixed_string_t name;
3376         uint16_t value;
3377 };
3378
3379 static void
3380 cmd_config_threshold_parsed(void *parsed_result,
3381                         __attribute__((unused)) struct cmdline *cl,
3382                         __attribute__((unused)) void *data)
3383 {
3384         struct cmd_config_threshold *res = parsed_result;
3385
3386         if (!all_ports_stopped()) {
3387                 printf("Please stop all ports first\n");
3388                 return;
3389         }
3390
3391         if (!strcmp(res->name, "txfreet"))
3392                 tx_free_thresh = res->value;
3393         else if (!strcmp(res->name, "txrst"))
3394                 tx_rs_thresh = res->value;
3395         else if (!strcmp(res->name, "rxfreet"))
3396                 rx_free_thresh = res->value;
3397         else {
3398                 printf("Unknown parameter\n");
3399                 return;
3400         }
3401
3402         init_port_config();
3403
3404         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3405 }
3406
3407 cmdline_parse_token_string_t cmd_config_threshold_port =
3408         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3409 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3410         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3411                                                                 "config");
3412 cmdline_parse_token_string_t cmd_config_threshold_all =
3413         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3414 cmdline_parse_token_string_t cmd_config_threshold_name =
3415         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3416                                                 "txfreet#txrst#rxfreet");
3417 cmdline_parse_token_num_t cmd_config_threshold_value =
3418         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3419
3420 cmdline_parse_inst_t cmd_config_threshold = {
3421         .f = cmd_config_threshold_parsed,
3422         .data = NULL,
3423         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3424         .tokens = {
3425                 (void *)&cmd_config_threshold_port,
3426                 (void *)&cmd_config_threshold_keyword,
3427                 (void *)&cmd_config_threshold_all,
3428                 (void *)&cmd_config_threshold_name,
3429                 (void *)&cmd_config_threshold_value,
3430                 NULL,
3431         },
3432 };
3433
3434 /* *** stop *** */
3435 struct cmd_stop_result {
3436         cmdline_fixed_string_t stop;
3437 };
3438
3439 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3440                             __attribute__((unused)) struct cmdline *cl,
3441                             __attribute__((unused)) void *data)
3442 {
3443         stop_packet_forwarding();
3444 }
3445
3446 cmdline_parse_token_string_t cmd_stop_stop =
3447         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3448
3449 cmdline_parse_inst_t cmd_stop = {
3450         .f = cmd_stop_parsed,
3451         .data = NULL,
3452         .help_str = "stop: Stop packet forwarding",
3453         .tokens = {
3454                 (void *)&cmd_stop_stop,
3455                 NULL,
3456         },
3457 };
3458
3459 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3460
3461 unsigned int
3462 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3463                 unsigned int *parsed_items, int check_unique_values)
3464 {
3465         unsigned int nb_item;
3466         unsigned int value;
3467         unsigned int i;
3468         unsigned int j;
3469         int value_ok;
3470         char c;
3471
3472         /*
3473          * First parse all items in the list and store their value.
3474          */
3475         value = 0;
3476         nb_item = 0;
3477         value_ok = 0;
3478         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3479                 c = str[i];
3480                 if ((c >= '0') && (c <= '9')) {
3481                         value = (unsigned int) (value * 10 + (c - '0'));
3482                         value_ok = 1;
3483                         continue;
3484                 }
3485                 if (c != ',') {
3486                         printf("character %c is not a decimal digit\n", c);
3487                         return 0;
3488                 }
3489                 if (! value_ok) {
3490                         printf("No valid value before comma\n");
3491                         return 0;
3492                 }
3493                 if (nb_item < max_items) {
3494                         parsed_items[nb_item] = value;
3495                         value_ok = 0;
3496                         value = 0;
3497                 }
3498                 nb_item++;
3499         }
3500         if (nb_item >= max_items) {
3501                 printf("Number of %s = %u > %u (maximum items)\n",
3502                        item_name, nb_item + 1, max_items);
3503                 return 0;
3504         }
3505         parsed_items[nb_item++] = value;
3506         if (! check_unique_values)
3507                 return nb_item;
3508
3509         /*
3510          * Then, check that all values in the list are differents.
3511          * No optimization here...
3512          */
3513         for (i = 0; i < nb_item; i++) {
3514                 for (j = i + 1; j < nb_item; j++) {
3515                         if (parsed_items[j] == parsed_items[i]) {
3516                                 printf("duplicated %s %u at index %u and %u\n",
3517                                        item_name, parsed_items[i], i, j);
3518                                 return 0;
3519                         }
3520                 }
3521         }
3522         return nb_item;
3523 }
3524
3525 struct cmd_set_list_result {
3526         cmdline_fixed_string_t cmd_keyword;
3527         cmdline_fixed_string_t list_name;
3528         cmdline_fixed_string_t list_of_items;
3529 };
3530
3531 static void cmd_set_list_parsed(void *parsed_result,
3532                                 __attribute__((unused)) struct cmdline *cl,
3533                                 __attribute__((unused)) void *data)
3534 {
3535         struct cmd_set_list_result *res;
3536         union {
3537                 unsigned int lcorelist[RTE_MAX_LCORE];
3538                 unsigned int portlist[RTE_MAX_ETHPORTS];
3539         } parsed_items;
3540         unsigned int nb_item;
3541
3542         if (test_done == 0) {
3543                 printf("Please stop forwarding first\n");
3544                 return;
3545         }
3546
3547         res = parsed_result;
3548         if (!strcmp(res->list_name, "corelist")) {
3549                 nb_item = parse_item_list(res->list_of_items, "core",
3550                                           RTE_MAX_LCORE,
3551                                           parsed_items.lcorelist, 1);
3552                 if (nb_item > 0) {
3553                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3554                         fwd_config_setup();
3555                 }
3556                 return;
3557         }
3558         if (!strcmp(res->list_name, "portlist")) {
3559                 nb_item = parse_item_list(res->list_of_items, "port",
3560                                           RTE_MAX_ETHPORTS,
3561                                           parsed_items.portlist, 1);
3562                 if (nb_item > 0) {
3563                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3564                         fwd_config_setup();
3565                 }
3566         }
3567 }
3568
3569 cmdline_parse_token_string_t cmd_set_list_keyword =
3570         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3571                                  "set");
3572 cmdline_parse_token_string_t cmd_set_list_name =
3573         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3574                                  "corelist#portlist");
3575 cmdline_parse_token_string_t cmd_set_list_of_items =
3576         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3577                                  NULL);
3578
3579 cmdline_parse_inst_t cmd_set_fwd_list = {
3580         .f = cmd_set_list_parsed,
3581         .data = NULL,
3582         .help_str = "set corelist|portlist <list0[,list1]*>",
3583         .tokens = {
3584                 (void *)&cmd_set_list_keyword,
3585                 (void *)&cmd_set_list_name,
3586                 (void *)&cmd_set_list_of_items,
3587                 NULL,
3588         },
3589 };
3590
3591 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3592
3593 struct cmd_setmask_result {
3594         cmdline_fixed_string_t set;
3595         cmdline_fixed_string_t mask;
3596         uint64_t hexavalue;
3597 };
3598
3599 static void cmd_set_mask_parsed(void *parsed_result,
3600                                 __attribute__((unused)) struct cmdline *cl,
3601                                 __attribute__((unused)) void *data)
3602 {
3603         struct cmd_setmask_result *res = parsed_result;
3604
3605         if (test_done == 0) {
3606                 printf("Please stop forwarding first\n");
3607                 return;
3608         }
3609         if (!strcmp(res->mask, "coremask")) {
3610                 set_fwd_lcores_mask(res->hexavalue);
3611                 fwd_config_setup();
3612         } else if (!strcmp(res->mask, "portmask")) {
3613                 set_fwd_ports_mask(res->hexavalue);
3614                 fwd_config_setup();
3615         }
3616 }
3617
3618 cmdline_parse_token_string_t cmd_setmask_set =
3619         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3620 cmdline_parse_token_string_t cmd_setmask_mask =
3621         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3622                                  "coremask#portmask");
3623 cmdline_parse_token_num_t cmd_setmask_value =
3624         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3625
3626 cmdline_parse_inst_t cmd_set_fwd_mask = {
3627         .f = cmd_set_mask_parsed,
3628         .data = NULL,
3629         .help_str = "set coremask|portmask <hexadecimal value>",
3630         .tokens = {
3631                 (void *)&cmd_setmask_set,
3632                 (void *)&cmd_setmask_mask,
3633                 (void *)&cmd_setmask_value,
3634                 NULL,
3635         },
3636 };
3637
3638 /*
3639  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3640  */
3641 struct cmd_set_result {
3642         cmdline_fixed_string_t set;
3643         cmdline_fixed_string_t what;
3644         uint16_t value;
3645 };
3646
3647 static void cmd_set_parsed(void *parsed_result,
3648                            __attribute__((unused)) struct cmdline *cl,
3649                            __attribute__((unused)) void *data)
3650 {
3651         struct cmd_set_result *res = parsed_result;
3652         if (!strcmp(res->what, "nbport")) {
3653                 set_fwd_ports_number(res->value);
3654                 fwd_config_setup();
3655         } else if (!strcmp(res->what, "nbcore")) {
3656                 set_fwd_lcores_number(res->value);
3657                 fwd_config_setup();
3658         } else if (!strcmp(res->what, "burst"))
3659                 set_nb_pkt_per_burst(res->value);
3660         else if (!strcmp(res->what, "verbose"))
3661                 set_verbose_level(res->value);
3662 }
3663
3664 cmdline_parse_token_string_t cmd_set_set =
3665         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3666 cmdline_parse_token_string_t cmd_set_what =
3667         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3668                                  "nbport#nbcore#burst#verbose");
3669 cmdline_parse_token_num_t cmd_set_value =
3670         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3671
3672 cmdline_parse_inst_t cmd_set_numbers = {
3673         .f = cmd_set_parsed,
3674         .data = NULL,
3675         .help_str = "set nbport|nbcore|burst|verbose <value>",
3676         .tokens = {
3677                 (void *)&cmd_set_set,
3678                 (void *)&cmd_set_what,
3679                 (void *)&cmd_set_value,
3680                 NULL,
3681         },
3682 };
3683
3684 /* *** SET LOG LEVEL CONFIGURATION *** */
3685
3686 struct cmd_set_log_result {
3687         cmdline_fixed_string_t set;
3688         cmdline_fixed_string_t log;
3689         cmdline_fixed_string_t type;
3690         uint32_t level;
3691 };
3692
3693 static void
3694 cmd_set_log_parsed(void *parsed_result,
3695                    __attribute__((unused)) struct cmdline *cl,
3696                    __attribute__((unused)) void *data)
3697 {
3698         struct cmd_set_log_result *res;
3699         int ret;
3700
3701         res = parsed_result;
3702         if (!strcmp(res->type, "global"))
3703                 rte_log_set_global_level(res->level);
3704         else {
3705                 ret = rte_log_set_level_regexp(res->type, res->level);
3706                 if (ret < 0)
3707                         printf("Unable to set log level\n");
3708         }
3709 }
3710
3711 cmdline_parse_token_string_t cmd_set_log_set =
3712         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3713 cmdline_parse_token_string_t cmd_set_log_log =
3714         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3715 cmdline_parse_token_string_t cmd_set_log_type =
3716         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3717 cmdline_parse_token_num_t cmd_set_log_level =
3718         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3719
3720 cmdline_parse_inst_t cmd_set_log = {
3721         .f = cmd_set_log_parsed,
3722         .data = NULL,
3723         .help_str = "set log global|<type> <level>",
3724         .tokens = {
3725                 (void *)&cmd_set_log_set,
3726                 (void *)&cmd_set_log_log,
3727                 (void *)&cmd_set_log_type,
3728                 (void *)&cmd_set_log_level,
3729                 NULL,
3730         },
3731 };
3732
3733 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3734
3735 struct cmd_set_txpkts_result {
3736         cmdline_fixed_string_t cmd_keyword;
3737         cmdline_fixed_string_t txpkts;
3738         cmdline_fixed_string_t seg_lengths;
3739 };
3740
3741 static void
3742 cmd_set_txpkts_parsed(void *parsed_result,
3743                       __attribute__((unused)) struct cmdline *cl,
3744                       __attribute__((unused)) void *data)
3745 {
3746         struct cmd_set_txpkts_result *res;
3747         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3748         unsigned int nb_segs;
3749
3750         res = parsed_result;
3751         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3752                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3753         if (nb_segs > 0)
3754                 set_tx_pkt_segments(seg_lengths, nb_segs);
3755 }
3756
3757 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3758         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3759                                  cmd_keyword, "set");
3760 cmdline_parse_token_string_t cmd_set_txpkts_name =
3761         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3762                                  txpkts, "txpkts");
3763 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3764         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3765                                  seg_lengths, NULL);
3766
3767 cmdline_parse_inst_t cmd_set_txpkts = {
3768         .f = cmd_set_txpkts_parsed,
3769         .data = NULL,
3770         .help_str = "set txpkts <len0[,len1]*>",
3771         .tokens = {
3772                 (void *)&cmd_set_txpkts_keyword,
3773                 (void *)&cmd_set_txpkts_name,
3774                 (void *)&cmd_set_txpkts_lengths,
3775                 NULL,
3776         },
3777 };
3778
3779 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3780
3781 struct cmd_set_txsplit_result {
3782         cmdline_fixed_string_t cmd_keyword;
3783         cmdline_fixed_string_t txsplit;
3784         cmdline_fixed_string_t mode;
3785 };
3786
3787 static void
3788 cmd_set_txsplit_parsed(void *parsed_result,
3789                       __attribute__((unused)) struct cmdline *cl,
3790                       __attribute__((unused)) void *data)
3791 {
3792         struct cmd_set_txsplit_result *res;
3793
3794         res = parsed_result;
3795         set_tx_pkt_split(res->mode);
3796 }
3797
3798 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3799         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3800                                  cmd_keyword, "set");
3801 cmdline_parse_token_string_t cmd_set_txsplit_name =
3802         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3803                                  txsplit, "txsplit");
3804 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3805         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3806                                  mode, NULL);
3807
3808 cmdline_parse_inst_t cmd_set_txsplit = {
3809         .f = cmd_set_txsplit_parsed,
3810         .data = NULL,
3811         .help_str = "set txsplit on|off|rand",
3812         .tokens = {
3813                 (void *)&cmd_set_txsplit_keyword,
3814                 (void *)&cmd_set_txsplit_name,
3815                 (void *)&cmd_set_txsplit_mode,
3816                 NULL,
3817         },
3818 };
3819
3820 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3821 struct cmd_rx_vlan_filter_all_result {
3822         cmdline_fixed_string_t rx_vlan;
3823         cmdline_fixed_string_t what;
3824         cmdline_fixed_string_t all;
3825         portid_t port_id;
3826 };
3827
3828 static void
3829 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3830                               __attribute__((unused)) struct cmdline *cl,
3831                               __attribute__((unused)) void *data)
3832 {
3833         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3834
3835         if (!strcmp(res->what, "add"))
3836                 rx_vlan_all_filter_set(res->port_id, 1);
3837         else
3838                 rx_vlan_all_filter_set(res->port_id, 0);
3839 }
3840
3841 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3842         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3843                                  rx_vlan, "rx_vlan");
3844 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3845         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3846                                  what, "add#rm");
3847 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3848         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3849                                  all, "all");
3850 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3851         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3852                               port_id, UINT16);
3853
3854 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3855         .f = cmd_rx_vlan_filter_all_parsed,
3856         .data = NULL,
3857         .help_str = "rx_vlan add|rm all <port_id>: "
3858                 "Add/Remove all identifiers to/from the set of VLAN "
3859                 "identifiers filtered by a port",
3860         .tokens = {
3861                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3862                 (void *)&cmd_rx_vlan_filter_all_what,
3863                 (void *)&cmd_rx_vlan_filter_all_all,
3864                 (void *)&cmd_rx_vlan_filter_all_portid,
3865                 NULL,
3866         },
3867 };
3868
3869 /* *** VLAN OFFLOAD SET ON A PORT *** */
3870 struct cmd_vlan_offload_result {
3871         cmdline_fixed_string_t vlan;
3872         cmdline_fixed_string_t set;
3873         cmdline_fixed_string_t vlan_type;
3874         cmdline_fixed_string_t what;
3875         cmdline_fixed_string_t on;
3876         cmdline_fixed_string_t port_id;
3877 };
3878
3879 static void
3880 cmd_vlan_offload_parsed(void *parsed_result,
3881                           __attribute__((unused)) struct cmdline *cl,
3882                           __attribute__((unused)) void *data)
3883 {
3884         int on;
3885         struct cmd_vlan_offload_result *res = parsed_result;
3886         char *str;
3887         int i, len = 0;
3888         portid_t port_id = 0;
3889         unsigned int tmp;
3890
3891         str = res->port_id;
3892         len = strnlen(str, STR_TOKEN_SIZE);
3893         i = 0;
3894         /* Get port_id first */
3895         while(i < len){
3896                 if(str[i] == ',')
3897                         break;
3898
3899                 i++;
3900         }
3901         str[i]='\0';
3902         tmp = strtoul(str, NULL, 0);
3903         /* If port_id greater that what portid_t can represent, return */
3904         if(tmp >= RTE_MAX_ETHPORTS)
3905                 return;
3906         port_id = (portid_t)tmp;
3907
3908         if (!strcmp(res->on, "on"))
3909                 on = 1;
3910         else
3911                 on = 0;
3912
3913         if (!strcmp(res->what, "strip"))
3914                 rx_vlan_strip_set(port_id,  on);
3915         else if(!strcmp(res->what, "stripq")){
3916                 uint16_t queue_id = 0;
3917
3918                 /* No queue_id, return */
3919                 if(i + 1 >= len) {
3920                         printf("must specify (port,queue_id)\n");
3921                         return;
3922                 }
3923                 tmp = strtoul(str + i + 1, NULL, 0);
3924                 /* If queue_id greater that what 16-bits can represent, return */
3925                 if(tmp > 0xffff)
3926                         return;
3927
3928                 queue_id = (uint16_t)tmp;
3929                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3930         }
3931         else if (!strcmp(res->what, "filter"))
3932                 rx_vlan_filter_set(port_id, on);
3933         else if (!strcmp(res->what, "qinq_strip"))
3934                 rx_vlan_qinq_strip_set(port_id, on);
3935         else
3936                 vlan_extend_set(port_id, on);
3937
3938         return;
3939 }
3940
3941 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3942         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3943                                  vlan, "vlan");
3944 cmdline_parse_token_string_t cmd_vlan_offload_set =
3945         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3946                                  set, "set");
3947 cmdline_parse_token_string_t cmd_vlan_offload_what =
3948         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3949                                 what, "strip#filter#qinq_strip#extend#stripq");
3950 cmdline_parse_token_string_t cmd_vlan_offload_on =
3951         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3952                               on, "on#off");
3953 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3954         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3955                               port_id, NULL);
3956
3957 cmdline_parse_inst_t cmd_vlan_offload = {
3958         .f = cmd_vlan_offload_parsed,
3959         .data = NULL,
3960         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
3961                 "<port_id[,queue_id]>: "
3962                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
3963         .tokens = {
3964                 (void *)&cmd_vlan_offload_vlan,
3965                 (void *)&cmd_vlan_offload_set,
3966                 (void *)&cmd_vlan_offload_what,
3967                 (void *)&cmd_vlan_offload_on,
3968                 (void *)&cmd_vlan_offload_portid,
3969                 NULL,
3970         },
3971 };
3972
3973 /* *** VLAN TPID SET ON A PORT *** */
3974 struct cmd_vlan_tpid_result {
3975         cmdline_fixed_string_t vlan;
3976         cmdline_fixed_string_t set;
3977         cmdline_fixed_string_t vlan_type;
3978         cmdline_fixed_string_t what;
3979         uint16_t tp_id;
3980         portid_t port_id;
3981 };
3982
3983 static void
3984 cmd_vlan_tpid_parsed(void *parsed_result,
3985                           __attribute__((unused)) struct cmdline *cl,
3986                           __attribute__((unused)) void *data)
3987 {
3988         struct cmd_vlan_tpid_result *res = parsed_result;
3989         enum rte_vlan_type vlan_type;
3990
3991         if (!strcmp(res->vlan_type, "inner"))
3992                 vlan_type = ETH_VLAN_TYPE_INNER;
3993         else if (!strcmp(res->vlan_type, "outer"))
3994                 vlan_type = ETH_VLAN_TYPE_OUTER;
3995         else {
3996                 printf("Unknown vlan type\n");
3997                 return;
3998         }
3999         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4000 }
4001
4002 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4003         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4004                                  vlan, "vlan");
4005 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4006         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4007                                  set, "set");
4008 cmdline_parse_token_string_t cmd_vlan_type =
4009         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4010                                  vlan_type, "inner#outer");
4011 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4012         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4013                                  what, "tpid");
4014 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4015         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4016                               tp_id, UINT16);
4017 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4018         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4019                               port_id, UINT16);
4020
4021 cmdline_parse_inst_t cmd_vlan_tpid = {
4022         .f = cmd_vlan_tpid_parsed,
4023         .data = NULL,
4024         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4025                 "Set the VLAN Ether type",
4026         .tokens = {
4027                 (void *)&cmd_vlan_tpid_vlan,
4028                 (void *)&cmd_vlan_tpid_set,
4029                 (void *)&cmd_vlan_type,
4030                 (void *)&cmd_vlan_tpid_what,
4031                 (void *)&cmd_vlan_tpid_tpid,
4032                 (void *)&cmd_vlan_tpid_portid,
4033                 NULL,
4034         },
4035 };
4036
4037 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4038 struct cmd_rx_vlan_filter_result {
4039         cmdline_fixed_string_t rx_vlan;
4040         cmdline_fixed_string_t what;
4041         uint16_t vlan_id;
4042         portid_t port_id;
4043 };
4044
4045 static void
4046 cmd_rx_vlan_filter_parsed(void *parsed_result,
4047                           __attribute__((unused)) struct cmdline *cl,
4048                           __attribute__((unused)) void *data)
4049 {
4050         struct cmd_rx_vlan_filter_result *res = parsed_result;
4051
4052         if (!strcmp(res->what, "add"))
4053                 rx_vft_set(res->port_id, res->vlan_id, 1);
4054         else
4055                 rx_vft_set(res->port_id, res->vlan_id, 0);
4056 }
4057
4058 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4059         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4060                                  rx_vlan, "rx_vlan");
4061 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4062         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4063                                  what, "add#rm");
4064 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4065         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4066                               vlan_id, UINT16);
4067 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4068         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4069                               port_id, UINT16);
4070
4071 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4072         .f = cmd_rx_vlan_filter_parsed,
4073         .data = NULL,
4074         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4075                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4076                 "identifiers filtered by a port",
4077         .tokens = {
4078                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4079                 (void *)&cmd_rx_vlan_filter_what,
4080                 (void *)&cmd_rx_vlan_filter_vlanid,
4081                 (void *)&cmd_rx_vlan_filter_portid,
4082                 NULL,
4083         },
4084 };
4085
4086 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4087 struct cmd_tx_vlan_set_result {
4088         cmdline_fixed_string_t tx_vlan;
4089         cmdline_fixed_string_t set;
4090         portid_t port_id;
4091         uint16_t vlan_id;
4092 };
4093
4094 static void
4095 cmd_tx_vlan_set_parsed(void *parsed_result,
4096                        __attribute__((unused)) struct cmdline *cl,
4097                        __attribute__((unused)) void *data)
4098 {
4099         struct cmd_tx_vlan_set_result *res = parsed_result;
4100
4101         if (!port_is_stopped(res->port_id)) {
4102                 printf("Please stop port %d first\n", res->port_id);
4103                 return;
4104         }
4105
4106         tx_vlan_set(res->port_id, res->vlan_id);
4107
4108         cmd_reconfig_device_queue(res->port_id, 1, 1);
4109 }
4110
4111 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4112         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4113                                  tx_vlan, "tx_vlan");
4114 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4115         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4116                                  set, "set");
4117 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4118         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4119                               port_id, UINT16);
4120 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4121         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4122                               vlan_id, UINT16);
4123
4124 cmdline_parse_inst_t cmd_tx_vlan_set = {
4125         .f = cmd_tx_vlan_set_parsed,
4126         .data = NULL,
4127         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4128                 "Enable hardware insertion of a single VLAN header "
4129                 "with a given TAG Identifier in packets sent on a port",
4130         .tokens = {
4131                 (void *)&cmd_tx_vlan_set_tx_vlan,
4132                 (void *)&cmd_tx_vlan_set_set,
4133                 (void *)&cmd_tx_vlan_set_portid,
4134                 (void *)&cmd_tx_vlan_set_vlanid,
4135                 NULL,
4136         },
4137 };
4138
4139 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4140 struct cmd_tx_vlan_set_qinq_result {
4141         cmdline_fixed_string_t tx_vlan;
4142         cmdline_fixed_string_t set;
4143         portid_t port_id;
4144         uint16_t vlan_id;
4145         uint16_t vlan_id_outer;
4146 };
4147
4148 static void
4149 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4150                             __attribute__((unused)) struct cmdline *cl,
4151                             __attribute__((unused)) void *data)
4152 {
4153         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4154
4155         if (!port_is_stopped(res->port_id)) {
4156                 printf("Please stop port %d first\n", res->port_id);
4157                 return;
4158         }
4159
4160         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4161
4162         cmd_reconfig_device_queue(res->port_id, 1, 1);
4163 }
4164
4165 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4166         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4167                 tx_vlan, "tx_vlan");
4168 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4169         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4170                 set, "set");
4171 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4172         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4173                 port_id, UINT16);
4174 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4175         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4176                 vlan_id, UINT16);
4177 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4178         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4179                 vlan_id_outer, UINT16);
4180
4181 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4182         .f = cmd_tx_vlan_set_qinq_parsed,
4183         .data = NULL,
4184         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4185                 "Enable hardware insertion of double VLAN header "
4186                 "with given TAG Identifiers in packets sent on a port",
4187         .tokens = {
4188                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4189                 (void *)&cmd_tx_vlan_set_qinq_set,
4190                 (void *)&cmd_tx_vlan_set_qinq_portid,
4191                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4192                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4193                 NULL,
4194         },
4195 };
4196
4197 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4198 struct cmd_tx_vlan_set_pvid_result {
4199         cmdline_fixed_string_t tx_vlan;
4200         cmdline_fixed_string_t set;
4201         cmdline_fixed_string_t pvid;
4202         portid_t port_id;
4203         uint16_t vlan_id;
4204         cmdline_fixed_string_t mode;
4205 };
4206
4207 static void
4208 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4209                             __attribute__((unused)) struct cmdline *cl,
4210                             __attribute__((unused)) void *data)
4211 {
4212         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4213
4214         if (strcmp(res->mode, "on") == 0)
4215                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4216         else
4217                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4218 }
4219
4220 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4221         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4222                                  tx_vlan, "tx_vlan");
4223 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4224         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4225                                  set, "set");
4226 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4227         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4228                                  pvid, "pvid");
4229 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4230         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4231                              port_id, UINT16);
4232 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4233         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4234                               vlan_id, UINT16);
4235 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4236         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4237                                  mode, "on#off");
4238
4239 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4240         .f = cmd_tx_vlan_set_pvid_parsed,
4241         .data = NULL,
4242         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4243         .tokens = {
4244                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4245                 (void *)&cmd_tx_vlan_set_pvid_set,
4246                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4247                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4248                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4249                 (void *)&cmd_tx_vlan_set_pvid_mode,
4250                 NULL,
4251         },
4252 };
4253
4254 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4255 struct cmd_tx_vlan_reset_result {
4256         cmdline_fixed_string_t tx_vlan;
4257         cmdline_fixed_string_t reset;
4258         portid_t port_id;
4259 };
4260
4261 static void
4262 cmd_tx_vlan_reset_parsed(void *parsed_result,
4263                          __attribute__((unused)) struct cmdline *cl,
4264                          __attribute__((unused)) void *data)
4265 {
4266         struct cmd_tx_vlan_reset_result *res = parsed_result;
4267
4268         if (!port_is_stopped(res->port_id)) {
4269                 printf("Please stop port %d first\n", res->port_id);
4270                 return;
4271         }
4272
4273         tx_vlan_reset(res->port_id);
4274
4275         cmd_reconfig_device_queue(res->port_id, 1, 1);
4276 }
4277
4278 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4279         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4280                                  tx_vlan, "tx_vlan");
4281 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4282         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4283                                  reset, "reset");
4284 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4285         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4286                               port_id, UINT16);
4287
4288 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4289         .f = cmd_tx_vlan_reset_parsed,
4290         .data = NULL,
4291         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4292                 "VLAN header in packets sent on a port",
4293         .tokens = {
4294                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4295                 (void *)&cmd_tx_vlan_reset_reset,
4296                 (void *)&cmd_tx_vlan_reset_portid,
4297                 NULL,
4298         },
4299 };
4300
4301
4302 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4303 struct cmd_csum_result {
4304         cmdline_fixed_string_t csum;
4305         cmdline_fixed_string_t mode;
4306         cmdline_fixed_string_t proto;
4307         cmdline_fixed_string_t hwsw;
4308         portid_t port_id;
4309 };
4310
4311 static void
4312 csum_show(int port_id)
4313 {
4314         struct rte_eth_dev_info dev_info;
4315         uint64_t tx_offloads;
4316         int ret;
4317
4318         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4319         printf("Parse tunnel is %s\n",
4320                 (ports[port_id].parse_tunnel) ? "on" : "off");
4321         printf("IP checksum offload is %s\n",
4322                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4323         printf("UDP checksum offload is %s\n",
4324                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4325         printf("TCP checksum offload is %s\n",
4326                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4327         printf("SCTP checksum offload is %s\n",
4328                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4329         printf("Outer-Ip checksum offload is %s\n",
4330                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4331         printf("Outer-Udp checksum offload is %s\n",
4332                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4333
4334         /* display warnings if configuration is not supported by the NIC */
4335         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4336         if (ret != 0)
4337                 return;
4338
4339         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4340                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4341                 printf("Warning: hardware IP checksum enabled but not "
4342                         "supported by port %d\n", port_id);
4343         }
4344         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4345                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4346                 printf("Warning: hardware UDP checksum enabled but not "
4347                         "supported by port %d\n", port_id);
4348         }
4349         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4350                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4351                 printf("Warning: hardware TCP checksum enabled but not "
4352                         "supported by port %d\n", port_id);
4353         }
4354         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4355                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4356                 printf("Warning: hardware SCTP checksum enabled but not "
4357                         "supported by port %d\n", port_id);
4358         }
4359         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4360                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4361                 printf("Warning: hardware outer IP checksum enabled but not "
4362                         "supported by port %d\n", port_id);
4363         }
4364         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4365                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4366                         == 0) {
4367                 printf("Warning: hardware outer UDP checksum enabled but not "
4368                         "supported by port %d\n", port_id);
4369         }
4370 }
4371
4372 static void
4373 cmd_config_queue_tx_offloads(struct rte_port *port)
4374 {
4375         int k;
4376
4377         /* Apply queue tx offloads configuration */
4378         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4379                 port->tx_conf[k].offloads =
4380                         port->dev_conf.txmode.offloads;
4381 }
4382
4383 static void
4384 cmd_csum_parsed(void *parsed_result,
4385                        __attribute__((unused)) struct cmdline *cl,
4386                        __attribute__((unused)) void *data)
4387 {
4388         struct cmd_csum_result *res = parsed_result;
4389         int hw = 0;
4390         uint64_t csum_offloads = 0;
4391         struct rte_eth_dev_info dev_info;
4392         int ret;
4393
4394         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4395                 printf("invalid port %d\n", res->port_id);
4396                 return;
4397         }
4398         if (!port_is_stopped(res->port_id)) {
4399                 printf("Please stop port %d first\n", res->port_id);
4400                 return;
4401         }
4402
4403         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4404         if (ret != 0)
4405                 return;
4406
4407         if (!strcmp(res->mode, "set")) {
4408
4409                 if (!strcmp(res->hwsw, "hw"))
4410                         hw = 1;
4411
4412                 if (!strcmp(res->proto, "ip")) {
4413                         if (hw == 0 || (dev_info.tx_offload_capa &
4414                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4415                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4416                         } else {
4417                                 printf("IP checksum offload is not supported "
4418                                        "by port %u\n", res->port_id);
4419                         }
4420                 } else if (!strcmp(res->proto, "udp")) {
4421                         if (hw == 0 || (dev_info.tx_offload_capa &
4422                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4423                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4424                         } else {
4425                                 printf("UDP checksum offload is not supported "
4426                                        "by port %u\n", res->port_id);
4427                         }
4428                 } else if (!strcmp(res->proto, "tcp")) {
4429                         if (hw == 0 || (dev_info.tx_offload_capa &
4430                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4431                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4432                         } else {
4433                                 printf("TCP checksum offload is not supported "
4434                                        "by port %u\n", res->port_id);
4435                         }
4436                 } else if (!strcmp(res->proto, "sctp")) {
4437                         if (hw == 0 || (dev_info.tx_offload_capa &
4438                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4439                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4440                         } else {
4441                                 printf("SCTP checksum offload is not supported "
4442                                        "by port %u\n", res->port_id);
4443                         }
4444                 } else if (!strcmp(res->proto, "outer-ip")) {
4445                         if (hw == 0 || (dev_info.tx_offload_capa &
4446                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4447                                 csum_offloads |=
4448                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4449                         } else {
4450                                 printf("Outer IP checksum offload is not "
4451                                        "supported by port %u\n", res->port_id);
4452                         }
4453                 } else if (!strcmp(res->proto, "outer-udp")) {
4454                         if (hw == 0 || (dev_info.tx_offload_capa &
4455                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4456                                 csum_offloads |=
4457                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4458                         } else {
4459                                 printf("Outer UDP checksum offload is not "
4460                                        "supported by port %u\n", res->port_id);
4461                         }
4462                 }
4463
4464                 if (hw) {
4465                         ports[res->port_id].dev_conf.txmode.offloads |=
4466                                                         csum_offloads;
4467                 } else {
4468                         ports[res->port_id].dev_conf.txmode.offloads &=
4469                                                         (~csum_offloads);
4470                 }
4471                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4472         }
4473         csum_show(res->port_id);
4474
4475         cmd_reconfig_device_queue(res->port_id, 1, 1);
4476 }
4477
4478 cmdline_parse_token_string_t cmd_csum_csum =
4479         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4480                                 csum, "csum");
4481 cmdline_parse_token_string_t cmd_csum_mode =
4482         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4483                                 mode, "set");
4484 cmdline_parse_token_string_t cmd_csum_proto =
4485         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4486                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4487 cmdline_parse_token_string_t cmd_csum_hwsw =
4488         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4489                                 hwsw, "hw#sw");
4490 cmdline_parse_token_num_t cmd_csum_portid =
4491         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4492                                 port_id, UINT16);
4493
4494 cmdline_parse_inst_t cmd_csum_set = {
4495         .f = cmd_csum_parsed,
4496         .data = NULL,
4497         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4498                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4499                 "using csum forward engine",
4500         .tokens = {
4501                 (void *)&cmd_csum_csum,
4502                 (void *)&cmd_csum_mode,
4503                 (void *)&cmd_csum_proto,
4504                 (void *)&cmd_csum_hwsw,
4505                 (void *)&cmd_csum_portid,
4506                 NULL,
4507         },
4508 };
4509
4510 cmdline_parse_token_string_t cmd_csum_mode_show =
4511         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4512                                 mode, "show");
4513
4514 cmdline_parse_inst_t cmd_csum_show = {
4515         .f = cmd_csum_parsed,
4516         .data = NULL,
4517         .help_str = "csum show <port_id>: Show checksum offload configuration",
4518         .tokens = {
4519                 (void *)&cmd_csum_csum,
4520                 (void *)&cmd_csum_mode_show,
4521                 (void *)&cmd_csum_portid,
4522                 NULL,
4523         },
4524 };
4525
4526 /* Enable/disable tunnel parsing */
4527 struct cmd_csum_tunnel_result {
4528         cmdline_fixed_string_t csum;
4529         cmdline_fixed_string_t parse;
4530         cmdline_fixed_string_t onoff;
4531         portid_t port_id;
4532 };
4533
4534 static void
4535 cmd_csum_tunnel_parsed(void *parsed_result,
4536                        __attribute__((unused)) struct cmdline *cl,
4537                        __attribute__((unused)) void *data)
4538 {
4539         struct cmd_csum_tunnel_result *res = parsed_result;
4540
4541         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4542                 return;
4543
4544         if (!strcmp(res->onoff, "on"))
4545                 ports[res->port_id].parse_tunnel = 1;
4546         else
4547                 ports[res->port_id].parse_tunnel = 0;
4548
4549         csum_show(res->port_id);
4550 }
4551
4552 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4553         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4554                                 csum, "csum");
4555 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4556         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4557                                 parse, "parse-tunnel");
4558 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4559         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4560                                 onoff, "on#off");
4561 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4562         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4563                                 port_id, UINT16);
4564
4565 cmdline_parse_inst_t cmd_csum_tunnel = {
4566         .f = cmd_csum_tunnel_parsed,
4567         .data = NULL,
4568         .help_str = "csum parse-tunnel on|off <port_id>: "
4569                 "Enable/Disable parsing of tunnels for csum engine",
4570         .tokens = {
4571                 (void *)&cmd_csum_tunnel_csum,
4572                 (void *)&cmd_csum_tunnel_parse,
4573                 (void *)&cmd_csum_tunnel_onoff,
4574                 (void *)&cmd_csum_tunnel_portid,
4575                 NULL,
4576         },
4577 };
4578
4579 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4580 struct cmd_tso_set_result {
4581         cmdline_fixed_string_t tso;
4582         cmdline_fixed_string_t mode;
4583         uint16_t tso_segsz;
4584         portid_t port_id;
4585 };
4586
4587 static void
4588 cmd_tso_set_parsed(void *parsed_result,
4589                        __attribute__((unused)) struct cmdline *cl,
4590                        __attribute__((unused)) void *data)
4591 {
4592         struct cmd_tso_set_result *res = parsed_result;
4593         struct rte_eth_dev_info dev_info;
4594         int ret;
4595
4596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4597                 return;
4598         if (!port_is_stopped(res->port_id)) {
4599                 printf("Please stop port %d first\n", res->port_id);
4600                 return;
4601         }
4602
4603         if (!strcmp(res->mode, "set"))
4604                 ports[res->port_id].tso_segsz = res->tso_segsz;
4605
4606         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4607         if (ret != 0)
4608                 return;
4609
4610         if ((ports[res->port_id].tso_segsz != 0) &&
4611                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4612                 printf("Error: TSO is not supported by port %d\n",
4613                        res->port_id);
4614                 return;
4615         }
4616
4617         if (ports[res->port_id].tso_segsz == 0) {
4618                 ports[res->port_id].dev_conf.txmode.offloads &=
4619                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4620                 printf("TSO for non-tunneled packets is disabled\n");
4621         } else {
4622                 ports[res->port_id].dev_conf.txmode.offloads |=
4623                                                 DEV_TX_OFFLOAD_TCP_TSO;
4624                 printf("TSO segment size for non-tunneled packets is %d\n",
4625                         ports[res->port_id].tso_segsz);
4626         }
4627         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4628
4629         /* display warnings if configuration is not supported by the NIC */
4630         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4631         if (ret != 0)
4632                 return;
4633
4634         if ((ports[res->port_id].tso_segsz != 0) &&
4635                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4636                 printf("Warning: TSO enabled but not "
4637                         "supported by port %d\n", res->port_id);
4638         }
4639
4640         cmd_reconfig_device_queue(res->port_id, 1, 1);
4641 }
4642
4643 cmdline_parse_token_string_t cmd_tso_set_tso =
4644         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4645                                 tso, "tso");
4646 cmdline_parse_token_string_t cmd_tso_set_mode =
4647         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4648                                 mode, "set");
4649 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4650         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4651                                 tso_segsz, UINT16);
4652 cmdline_parse_token_num_t cmd_tso_set_portid =
4653         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4654                                 port_id, UINT16);
4655
4656 cmdline_parse_inst_t cmd_tso_set = {
4657         .f = cmd_tso_set_parsed,
4658         .data = NULL,
4659         .help_str = "tso set <tso_segsz> <port_id>: "
4660                 "Set TSO segment size of non-tunneled packets for csum engine "
4661                 "(0 to disable)",
4662         .tokens = {
4663                 (void *)&cmd_tso_set_tso,
4664                 (void *)&cmd_tso_set_mode,
4665                 (void *)&cmd_tso_set_tso_segsz,
4666                 (void *)&cmd_tso_set_portid,
4667                 NULL,
4668         },
4669 };
4670
4671 cmdline_parse_token_string_t cmd_tso_show_mode =
4672         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4673                                 mode, "show");
4674
4675
4676 cmdline_parse_inst_t cmd_tso_show = {
4677         .f = cmd_tso_set_parsed,
4678         .data = NULL,
4679         .help_str = "tso show <port_id>: "
4680                 "Show TSO segment size of non-tunneled packets for csum engine",
4681         .tokens = {
4682                 (void *)&cmd_tso_set_tso,
4683                 (void *)&cmd_tso_show_mode,
4684                 (void *)&cmd_tso_set_portid,
4685                 NULL,
4686         },
4687 };
4688
4689 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4690 struct cmd_tunnel_tso_set_result {
4691         cmdline_fixed_string_t tso;
4692         cmdline_fixed_string_t mode;
4693         uint16_t tso_segsz;
4694         portid_t port_id;
4695 };
4696
4697 static struct rte_eth_dev_info
4698 check_tunnel_tso_nic_support(portid_t port_id)
4699 {
4700         struct rte_eth_dev_info dev_info;
4701
4702         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4703                 return dev_info;
4704
4705         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4706                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4707                        "not enabled for port %d\n", port_id);
4708         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4709                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4710                        "not enabled for port %d\n", port_id);
4711         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4712                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4713                        "not enabled for port %d\n", port_id);
4714         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4715                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4716                        "not enabled for port %d\n", port_id);
4717         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4718                 printf("Warning: IP TUNNEL TSO not supported therefore "
4719                        "not enabled for port %d\n", port_id);
4720         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4721                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4722                        "not enabled for port %d\n", port_id);
4723         return dev_info;
4724 }
4725
4726 static void
4727 cmd_tunnel_tso_set_parsed(void *parsed_result,
4728                           __attribute__((unused)) struct cmdline *cl,
4729                           __attribute__((unused)) void *data)
4730 {
4731         struct cmd_tunnel_tso_set_result *res = parsed_result;
4732         struct rte_eth_dev_info dev_info;
4733
4734         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4735                 return;
4736         if (!port_is_stopped(res->port_id)) {
4737                 printf("Please stop port %d first\n", res->port_id);
4738                 return;
4739         }
4740
4741         if (!strcmp(res->mode, "set"))
4742                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4743
4744         dev_info = check_tunnel_tso_nic_support(res->port_id);
4745         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4746                 ports[res->port_id].dev_conf.txmode.offloads &=
4747                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4748                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4749                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4750                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4751                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4752                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4753                 printf("TSO for tunneled packets is disabled\n");
4754         } else {
4755                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4756                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4757                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4758                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4759                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4760                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4761
4762                 ports[res->port_id].dev_conf.txmode.offloads |=
4763                         (tso_offloads & dev_info.tx_offload_capa);
4764                 printf("TSO segment size for tunneled packets is %d\n",
4765                         ports[res->port_id].tunnel_tso_segsz);
4766
4767                 /* Below conditions are needed to make it work:
4768                  * (1) tunnel TSO is supported by the NIC;
4769                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4770                  * are recognized;
4771                  * (3) for tunneled pkts with outer L3 of IPv4,
4772                  * "csum set outer-ip" must be set to hw, because after tso,
4773                  * total_len of outer IP header is changed, and the checksum
4774                  * of outer IP header calculated by sw should be wrong; that
4775                  * is not necessary for IPv6 tunneled pkts because there's no
4776                  * checksum in IP header anymore.
4777                  */
4778
4779                 if (!ports[res->port_id].parse_tunnel)
4780                         printf("Warning: csum parse_tunnel must be set "
4781                                 "so that tunneled packets are recognized\n");
4782                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4783                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4784                         printf("Warning: csum set outer-ip must be set to hw "
4785                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4786         }
4787
4788         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4789         cmd_reconfig_device_queue(res->port_id, 1, 1);
4790 }
4791
4792 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4793         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4794                                 tso, "tunnel_tso");
4795 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4796         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4797                                 mode, "set");
4798 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4799         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4800                                 tso_segsz, UINT16);
4801 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4802         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4803                                 port_id, UINT16);
4804
4805 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4806         .f = cmd_tunnel_tso_set_parsed,
4807         .data = NULL,
4808         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4809                 "Set TSO segment size of tunneled packets for csum engine "
4810                 "(0 to disable)",
4811         .tokens = {
4812                 (void *)&cmd_tunnel_tso_set_tso,
4813                 (void *)&cmd_tunnel_tso_set_mode,
4814                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4815                 (void *)&cmd_tunnel_tso_set_portid,
4816                 NULL,
4817         },
4818 };
4819
4820 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4821         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4822                                 mode, "show");
4823
4824
4825 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4826         .f = cmd_tunnel_tso_set_parsed,
4827         .data = NULL,
4828         .help_str = "tunnel_tso show <port_id> "
4829                 "Show TSO segment size of tunneled packets for csum engine",
4830         .tokens = {
4831                 (void *)&cmd_tunnel_tso_set_tso,
4832                 (void *)&cmd_tunnel_tso_show_mode,
4833                 (void *)&cmd_tunnel_tso_set_portid,
4834                 NULL,
4835         },
4836 };
4837
4838 /* *** SET GRO FOR A PORT *** */
4839 struct cmd_gro_enable_result {
4840         cmdline_fixed_string_t cmd_set;
4841         cmdline_fixed_string_t cmd_port;
4842         cmdline_fixed_string_t cmd_keyword;
4843         cmdline_fixed_string_t cmd_onoff;
4844         portid_t cmd_pid;
4845 };
4846
4847 static void
4848 cmd_gro_enable_parsed(void *parsed_result,
4849                 __attribute__((unused)) struct cmdline *cl,
4850                 __attribute__((unused)) void *data)
4851 {
4852         struct cmd_gro_enable_result *res;
4853
4854         res = parsed_result;
4855         if (!strcmp(res->cmd_keyword, "gro"))
4856                 setup_gro(res->cmd_onoff, res->cmd_pid);
4857 }
4858
4859 cmdline_parse_token_string_t cmd_gro_enable_set =
4860         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4861                         cmd_set, "set");
4862 cmdline_parse_token_string_t cmd_gro_enable_port =
4863         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4864                         cmd_keyword, "port");
4865 cmdline_parse_token_num_t cmd_gro_enable_pid =
4866         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4867                         cmd_pid, UINT16);
4868 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4869         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4870                         cmd_keyword, "gro");
4871 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4872         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4873                         cmd_onoff, "on#off");
4874
4875 cmdline_parse_inst_t cmd_gro_enable = {
4876         .f = cmd_gro_enable_parsed,
4877         .data = NULL,
4878         .help_str = "set port <port_id> gro on|off",
4879         .tokens = {
4880                 (void *)&cmd_gro_enable_set,
4881                 (void *)&cmd_gro_enable_port,
4882                 (void *)&cmd_gro_enable_pid,
4883                 (void *)&cmd_gro_enable_keyword,
4884                 (void *)&cmd_gro_enable_onoff,
4885                 NULL,
4886         },
4887 };
4888
4889 /* *** DISPLAY GRO CONFIGURATION *** */
4890 struct cmd_gro_show_result {
4891         cmdline_fixed_string_t cmd_show;
4892         cmdline_fixed_string_t cmd_port;
4893         cmdline_fixed_string_t cmd_keyword;
4894         portid_t cmd_pid;
4895 };
4896
4897 static void
4898 cmd_gro_show_parsed(void *parsed_result,
4899                 __attribute__((unused)) struct cmdline *cl,
4900                 __attribute__((unused)) void *data)
4901 {
4902         struct cmd_gro_show_result *res;
4903
4904         res = parsed_result;
4905         if (!strcmp(res->cmd_keyword, "gro"))
4906                 show_gro(res->cmd_pid);
4907 }
4908
4909 cmdline_parse_token_string_t cmd_gro_show_show =
4910         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4911                         cmd_show, "show");
4912 cmdline_parse_token_string_t cmd_gro_show_port =
4913         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4914                         cmd_port, "port");
4915 cmdline_parse_token_num_t cmd_gro_show_pid =
4916         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4917                         cmd_pid, UINT16);
4918 cmdline_parse_token_string_t cmd_gro_show_keyword =
4919         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4920                         cmd_keyword, "gro");
4921
4922 cmdline_parse_inst_t cmd_gro_show = {
4923         .f = cmd_gro_show_parsed,
4924         .data = NULL,
4925         .help_str = "show port <port_id> gro",
4926         .tokens = {
4927                 (void *)&cmd_gro_show_show,
4928                 (void *)&cmd_gro_show_port,
4929                 (void *)&cmd_gro_show_pid,
4930                 (void *)&cmd_gro_show_keyword,
4931                 NULL,
4932         },
4933 };
4934
4935 /* *** SET FLUSH CYCLES FOR GRO *** */
4936 struct cmd_gro_flush_result {
4937         cmdline_fixed_string_t cmd_set;
4938         cmdline_fixed_string_t cmd_keyword;
4939         cmdline_fixed_string_t cmd_flush;
4940         uint8_t cmd_cycles;
4941 };
4942
4943 static void
4944 cmd_gro_flush_parsed(void *parsed_result,
4945                 __attribute__((unused)) struct cmdline *cl,
4946                 __attribute__((unused)) void *data)
4947 {
4948         struct cmd_gro_flush_result *res;
4949
4950         res = parsed_result;
4951         if ((!strcmp(res->cmd_keyword, "gro")) &&
4952                         (!strcmp(res->cmd_flush, "flush")))
4953                 setup_gro_flush_cycles(res->cmd_cycles);
4954 }
4955
4956 cmdline_parse_token_string_t cmd_gro_flush_set =
4957         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4958                         cmd_set, "set");
4959 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4960         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4961                         cmd_keyword, "gro");
4962 cmdline_parse_token_string_t cmd_gro_flush_flush =
4963         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4964                         cmd_flush, "flush");
4965 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4966         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4967                         cmd_cycles, UINT8);
4968
4969 cmdline_parse_inst_t cmd_gro_flush = {
4970         .f = cmd_gro_flush_parsed,
4971         .data = NULL,
4972         .help_str = "set gro flush <cycles>",
4973         .tokens = {
4974                 (void *)&cmd_gro_flush_set,
4975                 (void *)&cmd_gro_flush_keyword,
4976                 (void *)&cmd_gro_flush_flush,
4977                 (void *)&cmd_gro_flush_cycles,
4978                 NULL,
4979         },
4980 };
4981
4982 /* *** ENABLE/DISABLE GSO *** */
4983 struct cmd_gso_enable_result {
4984         cmdline_fixed_string_t cmd_set;
4985         cmdline_fixed_string_t cmd_port;
4986         cmdline_fixed_string_t cmd_keyword;
4987         cmdline_fixed_string_t cmd_mode;
4988         portid_t cmd_pid;
4989 };
4990
4991 static void
4992 cmd_gso_enable_parsed(void *parsed_result,
4993                 __attribute__((unused)) struct cmdline *cl,
4994                 __attribute__((unused)) void *data)
4995 {
4996         struct cmd_gso_enable_result *res;
4997
4998         res = parsed_result;
4999         if (!strcmp(res->cmd_keyword, "gso"))
5000                 setup_gso(res->cmd_mode, res->cmd_pid);
5001 }
5002
5003 cmdline_parse_token_string_t cmd_gso_enable_set =
5004         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5005                         cmd_set, "set");
5006 cmdline_parse_token_string_t cmd_gso_enable_port =
5007         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5008                         cmd_port, "port");
5009 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5010         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5011                         cmd_keyword, "gso");
5012 cmdline_parse_token_string_t cmd_gso_enable_mode =
5013         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5014                         cmd_mode, "on#off");
5015 cmdline_parse_token_num_t cmd_gso_enable_pid =
5016         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5017                         cmd_pid, UINT16);
5018
5019 cmdline_parse_inst_t cmd_gso_enable = {
5020         .f = cmd_gso_enable_parsed,
5021         .data = NULL,
5022         .help_str = "set port <port_id> gso on|off",
5023         .tokens = {
5024                 (void *)&cmd_gso_enable_set,
5025                 (void *)&cmd_gso_enable_port,
5026                 (void *)&cmd_gso_enable_pid,
5027                 (void *)&cmd_gso_enable_keyword,
5028                 (void *)&cmd_gso_enable_mode,
5029                 NULL,
5030         },
5031 };
5032
5033 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5034 struct cmd_gso_size_result {
5035         cmdline_fixed_string_t cmd_set;
5036         cmdline_fixed_string_t cmd_keyword;
5037         cmdline_fixed_string_t cmd_segsz;
5038         uint16_t cmd_size;
5039 };
5040
5041 static void
5042 cmd_gso_size_parsed(void *parsed_result,
5043                        __attribute__((unused)) struct cmdline *cl,
5044                        __attribute__((unused)) void *data)
5045 {
5046         struct cmd_gso_size_result *res = parsed_result;
5047
5048         if (test_done == 0) {
5049                 printf("Before setting GSO segsz, please first"
5050                                 " stop fowarding\n");
5051                 return;
5052         }
5053
5054         if (!strcmp(res->cmd_keyword, "gso") &&
5055                         !strcmp(res->cmd_segsz, "segsz")) {
5056                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5057                         printf("gso_size should be larger than %zu."
5058                                         " Please input a legal value\n",
5059                                         RTE_GSO_SEG_SIZE_MIN);
5060                 else
5061                         gso_max_segment_size = res->cmd_size;
5062         }
5063 }
5064
5065 cmdline_parse_token_string_t cmd_gso_size_set =
5066         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5067                                 cmd_set, "set");
5068 cmdline_parse_token_string_t cmd_gso_size_keyword =
5069         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5070                                 cmd_keyword, "gso");
5071 cmdline_parse_token_string_t cmd_gso_size_segsz =
5072         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5073                                 cmd_segsz, "segsz");
5074 cmdline_parse_token_num_t cmd_gso_size_size =
5075         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5076                                 cmd_size, UINT16);
5077
5078 cmdline_parse_inst_t cmd_gso_size = {
5079         .f = cmd_gso_size_parsed,
5080         .data = NULL,
5081         .help_str = "set gso segsz <length>",
5082         .tokens = {
5083                 (void *)&cmd_gso_size_set,
5084                 (void *)&cmd_gso_size_keyword,
5085                 (void *)&cmd_gso_size_segsz,
5086                 (void *)&cmd_gso_size_size,
5087                 NULL,
5088         },
5089 };
5090
5091 /* *** SHOW GSO CONFIGURATION *** */
5092 struct cmd_gso_show_result {
5093         cmdline_fixed_string_t cmd_show;
5094         cmdline_fixed_string_t cmd_port;
5095         cmdline_fixed_string_t cmd_keyword;
5096         portid_t cmd_pid;
5097 };
5098
5099 static void
5100 cmd_gso_show_parsed(void *parsed_result,
5101                        __attribute__((unused)) struct cmdline *cl,
5102                        __attribute__((unused)) void *data)
5103 {
5104         struct cmd_gso_show_result *res = parsed_result;
5105
5106         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5107                 printf("invalid port id %u\n", res->cmd_pid);
5108                 return;
5109         }
5110         if (!strcmp(res->cmd_keyword, "gso")) {
5111                 if (gso_ports[res->cmd_pid].enable) {
5112                         printf("Max GSO'd packet size: %uB\n"
5113                                         "Supported GSO types: TCP/IPv4, "
5114                                         "UDP/IPv4, VxLAN with inner "
5115                                         "TCP/IPv4 packet, GRE with inner "
5116                                         "TCP/IPv4 packet\n",
5117                                         gso_max_segment_size);
5118                 } else
5119                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5120         }
5121 }
5122
5123 cmdline_parse_token_string_t cmd_gso_show_show =
5124 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5125                 cmd_show, "show");
5126 cmdline_parse_token_string_t cmd_gso_show_port =
5127 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5128                 cmd_port, "port");
5129 cmdline_parse_token_string_t cmd_gso_show_keyword =
5130         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5131                                 cmd_keyword, "gso");
5132 cmdline_parse_token_num_t cmd_gso_show_pid =
5133         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5134                                 cmd_pid, UINT16);
5135
5136 cmdline_parse_inst_t cmd_gso_show = {
5137         .f = cmd_gso_show_parsed,
5138         .data = NULL,
5139         .help_str = "show port <port_id> gso",
5140         .tokens = {
5141                 (void *)&cmd_gso_show_show,
5142                 (void *)&cmd_gso_show_port,
5143                 (void *)&cmd_gso_show_pid,
5144                 (void *)&cmd_gso_show_keyword,
5145                 NULL,
5146         },
5147 };
5148
5149 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5150 struct cmd_set_flush_rx {
5151         cmdline_fixed_string_t set;
5152         cmdline_fixed_string_t flush_rx;
5153         cmdline_fixed_string_t mode;
5154 };
5155
5156 static void
5157 cmd_set_flush_rx_parsed(void *parsed_result,
5158                 __attribute__((unused)) struct cmdline *cl,
5159                 __attribute__((unused)) void *data)
5160 {
5161         struct cmd_set_flush_rx *res = parsed_result;
5162         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5163 }
5164
5165 cmdline_parse_token_string_t cmd_setflushrx_set =
5166         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5167                         set, "set");
5168 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5169         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5170                         flush_rx, "flush_rx");
5171 cmdline_parse_token_string_t cmd_setflushrx_mode =
5172         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5173                         mode, "on#off");
5174
5175
5176 cmdline_parse_inst_t cmd_set_flush_rx = {
5177         .f = cmd_set_flush_rx_parsed,
5178         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5179         .data = NULL,
5180         .tokens = {
5181                 (void *)&cmd_setflushrx_set,
5182                 (void *)&cmd_setflushrx_flush_rx,
5183                 (void *)&cmd_setflushrx_mode,
5184                 NULL,
5185         },
5186 };
5187
5188 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5189 struct cmd_set_link_check {
5190         cmdline_fixed_string_t set;
5191         cmdline_fixed_string_t link_check;
5192         cmdline_fixed_string_t mode;
5193 };
5194
5195 static void
5196 cmd_set_link_check_parsed(void *parsed_result,
5197                 __attribute__((unused)) struct cmdline *cl,
5198                 __attribute__((unused)) void *data)
5199 {
5200         struct cmd_set_link_check *res = parsed_result;
5201         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5202 }
5203
5204 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5205         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5206                         set, "set");
5207 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5208         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5209                         link_check, "link_check");
5210 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5211         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5212                         mode, "on#off");
5213
5214
5215 cmdline_parse_inst_t cmd_set_link_check = {
5216         .f = cmd_set_link_check_parsed,
5217         .help_str = "set link_check on|off: Enable/Disable link status check "
5218                     "when starting/stopping a port",
5219         .data = NULL,
5220         .tokens = {
5221                 (void *)&cmd_setlinkcheck_set,
5222                 (void *)&cmd_setlinkcheck_link_check,
5223                 (void *)&cmd_setlinkcheck_mode,
5224                 NULL,
5225         },
5226 };
5227
5228 /* *** SET NIC BYPASS MODE *** */
5229 struct cmd_set_bypass_mode_result {
5230         cmdline_fixed_string_t set;
5231         cmdline_fixed_string_t bypass;
5232         cmdline_fixed_string_t mode;
5233         cmdline_fixed_string_t value;
5234         portid_t port_id;
5235 };
5236
5237 static void
5238 cmd_set_bypass_mode_parsed(void *parsed_result,
5239                 __attribute__((unused)) struct cmdline *cl,
5240                 __attribute__((unused)) void *data)
5241 {
5242         struct cmd_set_bypass_mode_result *res = parsed_result;
5243         portid_t port_id = res->port_id;
5244         int32_t rc = -EINVAL;
5245
5246 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5247         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5248
5249         if (!strcmp(res->value, "bypass"))
5250                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5251         else if (!strcmp(res->value, "isolate"))
5252                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5253         else
5254                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5255
5256         /* Set the bypass mode for the relevant port. */
5257         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5258 #endif
5259         if (rc != 0)
5260                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5261 }
5262
5263 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5264         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5265                         set, "set");
5266 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5267         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5268                         bypass, "bypass");
5269 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5270         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5271                         mode, "mode");
5272 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5273         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5274                         value, "normal#bypass#isolate");
5275 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5276         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5277                                 port_id, UINT16);
5278
5279 cmdline_parse_inst_t cmd_set_bypass_mode = {
5280         .f = cmd_set_bypass_mode_parsed,
5281         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5282                     "Set the NIC bypass mode for port_id",
5283         .data = NULL,
5284         .tokens = {
5285                 (void *)&cmd_setbypass_mode_set,
5286                 (void *)&cmd_setbypass_mode_bypass,
5287                 (void *)&cmd_setbypass_mode_mode,
5288                 (void *)&cmd_setbypass_mode_value,
5289                 (void *)&cmd_setbypass_mode_port,
5290                 NULL,
5291         },
5292 };
5293
5294 /* *** SET NIC BYPASS EVENT *** */
5295 struct cmd_set_bypass_event_result {
5296         cmdline_fixed_string_t set;
5297         cmdline_fixed_string_t bypass;
5298         cmdline_fixed_string_t event;
5299         cmdline_fixed_string_t event_value;
5300         cmdline_fixed_string_t mode;
5301         cmdline_fixed_string_t mode_value;
5302         portid_t port_id;
5303 };
5304
5305 static void
5306 cmd_set_bypass_event_parsed(void *parsed_result,
5307                 __attribute__((unused)) struct cmdline *cl,
5308                 __attribute__((unused)) void *data)
5309 {
5310         int32_t rc = -EINVAL;
5311         struct cmd_set_bypass_event_result *res = parsed_result;
5312         portid_t port_id = res->port_id;
5313
5314 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5315         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5316         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5317
5318         if (!strcmp(res->event_value, "timeout"))
5319                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5320         else if (!strcmp(res->event_value, "os_on"))
5321                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5322         else if (!strcmp(res->event_value, "os_off"))
5323                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5324         else if (!strcmp(res->event_value, "power_on"))
5325                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5326         else if (!strcmp(res->event_value, "power_off"))
5327                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5328         else
5329                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5330
5331         if (!strcmp(res->mode_value, "bypass"))
5332                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5333         else if (!strcmp(res->mode_value, "isolate"))
5334                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5335         else
5336                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5337
5338         /* Set the watchdog timeout. */
5339         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5340
5341                 rc = -EINVAL;
5342                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5343                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5344                                                            bypass_timeout);
5345                 }
5346                 if (rc != 0) {
5347                         printf("Failed to set timeout value %u "
5348                         "for port %d, errto code: %d.\n",
5349                         bypass_timeout, port_id, rc);
5350                 }
5351         }
5352
5353         /* Set the bypass event to transition to bypass mode. */
5354         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5355                                               bypass_mode);
5356 #endif
5357
5358         if (rc != 0)
5359                 printf("\t Failed to set bypass event for port = %d.\n",
5360                        port_id);
5361 }
5362
5363 cmdline_parse_token_string_t cmd_setbypass_event_set =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5365                         set, "set");
5366 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5367         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5368                         bypass, "bypass");
5369 cmdline_parse_token_string_t cmd_setbypass_event_event =
5370         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5371                         event, "event");
5372 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5373         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5374                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5375 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5376         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5377                         mode, "mode");
5378 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5379         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5380                         mode_value, "normal#bypass#isolate");
5381 cmdline_parse_token_num_t cmd_setbypass_event_port =
5382         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5383                                 port_id, UINT16);
5384
5385 cmdline_parse_inst_t cmd_set_bypass_event = {
5386         .f = cmd_set_bypass_event_parsed,
5387         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5388                 "power_off mode normal|bypass|isolate <port_id>: "
5389                 "Set the NIC bypass event mode for port_id",
5390         .data = NULL,
5391         .tokens = {
5392                 (void *)&cmd_setbypass_event_set,
5393                 (void *)&cmd_setbypass_event_bypass,
5394                 (void *)&cmd_setbypass_event_event,
5395                 (void *)&cmd_setbypass_event_event_value,
5396                 (void *)&cmd_setbypass_event_mode,
5397                 (void *)&cmd_setbypass_event_mode_value,
5398                 (void *)&cmd_setbypass_event_port,
5399                 NULL,
5400         },
5401 };
5402
5403
5404 /* *** SET NIC BYPASS TIMEOUT *** */
5405 struct cmd_set_bypass_timeout_result {
5406         cmdline_fixed_string_t set;
5407         cmdline_fixed_string_t bypass;
5408         cmdline_fixed_string_t timeout;
5409         cmdline_fixed_string_t value;
5410 };
5411
5412 static void
5413 cmd_set_bypass_timeout_parsed(void *parsed_result,
5414                 __attribute__((unused)) struct cmdline *cl,
5415                 __attribute__((unused)) void *data)
5416 {
5417         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5418
5419 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5420         if (!strcmp(res->value, "1.5"))
5421                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5422         else if (!strcmp(res->value, "2"))
5423                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5424         else if (!strcmp(res->value, "3"))
5425                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5426         else if (!strcmp(res->value, "4"))
5427                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5428         else if (!strcmp(res->value, "8"))
5429                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5430         else if (!strcmp(res->value, "16"))
5431                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5432         else if (!strcmp(res->value, "32"))
5433                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5434         else
5435                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5436 #endif
5437 }
5438
5439 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5440         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5441                         set, "set");
5442 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5444                         bypass, "bypass");
5445 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5446         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5447                         timeout, "timeout");
5448 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5449         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5450                         value, "0#1.5#2#3#4#8#16#32");
5451
5452 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5453         .f = cmd_set_bypass_timeout_parsed,
5454         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5455                 "Set the NIC bypass watchdog timeout in seconds",
5456         .data = NULL,
5457         .tokens = {
5458                 (void *)&cmd_setbypass_timeout_set,
5459                 (void *)&cmd_setbypass_timeout_bypass,
5460                 (void *)&cmd_setbypass_timeout_timeout,
5461                 (void *)&cmd_setbypass_timeout_value,
5462                 NULL,
5463         },
5464 };
5465
5466 /* *** SHOW NIC BYPASS MODE *** */
5467 struct cmd_show_bypass_config_result {
5468         cmdline_fixed_string_t show;
5469         cmdline_fixed_string_t bypass;
5470         cmdline_fixed_string_t config;
5471         portid_t port_id;
5472 };
5473
5474 static void
5475 cmd_show_bypass_config_parsed(void *parsed_result,
5476                 __attribute__((unused)) struct cmdline *cl,
5477                 __attribute__((unused)) void *data)
5478 {
5479         struct cmd_show_bypass_config_result *res = parsed_result;
5480         portid_t port_id = res->port_id;
5481         int rc = -EINVAL;
5482 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5483         uint32_t event_mode;
5484         uint32_t bypass_mode;
5485         uint32_t timeout = bypass_timeout;
5486         int i;
5487
5488         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5489                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5490         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5491                 {"UNKNOWN", "normal", "bypass", "isolate"};
5492         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5493                 "NONE",
5494                 "OS/board on",
5495                 "power supply on",
5496                 "OS/board off",
5497                 "power supply off",
5498                 "timeout"};
5499         int num_events = (sizeof events) / (sizeof events[0]);
5500
5501         /* Display the bypass mode.*/
5502         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5503                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5504                 return;
5505         }
5506         else {
5507                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5508                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5509
5510                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5511         }
5512
5513         /* Display the bypass timeout.*/
5514         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5515                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5516
5517         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5518
5519         /* Display the bypass events and associated modes. */
5520         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5521
5522                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5523                         printf("\tFailed to get bypass mode for event = %s\n",
5524                                 events[i]);
5525                 } else {
5526                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5527                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5528
5529                         printf("\tbypass event: %-16s = %s\n", events[i],
5530                                 modes[event_mode]);
5531                 }
5532         }
5533 #endif
5534         if (rc != 0)
5535                 printf("\tFailed to get bypass configuration for port = %d\n",
5536                        port_id);
5537 }
5538
5539 cmdline_parse_token_string_t cmd_showbypass_config_show =
5540         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5541                         show, "show");
5542 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5543         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5544                         bypass, "bypass");
5545 cmdline_parse_token_string_t cmd_showbypass_config_config =
5546         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5547                         config, "config");
5548 cmdline_parse_token_num_t cmd_showbypass_config_port =
5549         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5550                                 port_id, UINT16);
5551
5552 cmdline_parse_inst_t cmd_show_bypass_config = {
5553         .f = cmd_show_bypass_config_parsed,
5554         .help_str = "show bypass config <port_id>: "
5555                     "Show the NIC bypass config for port_id",
5556         .data = NULL,
5557         .tokens = {
5558                 (void *)&cmd_showbypass_config_show,
5559                 (void *)&cmd_showbypass_config_bypass,
5560                 (void *)&cmd_showbypass_config_config,
5561                 (void *)&cmd_showbypass_config_port,
5562                 NULL,
5563         },
5564 };
5565
5566 #ifdef RTE_LIBRTE_PMD_BOND
5567 /* *** SET BONDING MODE *** */
5568 struct cmd_set_bonding_mode_result {
5569         cmdline_fixed_string_t set;
5570         cmdline_fixed_string_t bonding;
5571         cmdline_fixed_string_t mode;
5572         uint8_t value;
5573         portid_t port_id;
5574 };
5575
5576 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5577                 __attribute__((unused))  struct cmdline *cl,
5578                 __attribute__((unused)) void *data)
5579 {
5580         struct cmd_set_bonding_mode_result *res = parsed_result;
5581         portid_t port_id = res->port_id;
5582
5583         /* Set the bonding mode for the relevant port. */
5584         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5585                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5586 }
5587
5588 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5589 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5590                 set, "set");
5591 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5592 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5593                 bonding, "bonding");
5594 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5595 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5596                 mode, "mode");
5597 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5598 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5599                 value, UINT8);
5600 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5601 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5602                 port_id, UINT16);
5603
5604 cmdline_parse_inst_t cmd_set_bonding_mode = {
5605                 .f = cmd_set_bonding_mode_parsed,
5606                 .help_str = "set bonding mode <mode_value> <port_id>: "
5607                         "Set the bonding mode for port_id",
5608                 .data = NULL,
5609                 .tokens = {
5610                                 (void *) &cmd_setbonding_mode_set,
5611                                 (void *) &cmd_setbonding_mode_bonding,
5612                                 (void *) &cmd_setbonding_mode_mode,
5613                                 (void *) &cmd_setbonding_mode_value,
5614                                 (void *) &cmd_setbonding_mode_port,
5615                                 NULL
5616                 }
5617 };
5618
5619 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5620 struct cmd_set_bonding_lacp_dedicated_queues_result {
5621         cmdline_fixed_string_t set;
5622         cmdline_fixed_string_t bonding;
5623         cmdline_fixed_string_t lacp;
5624         cmdline_fixed_string_t dedicated_queues;
5625         portid_t port_id;
5626         cmdline_fixed_string_t mode;
5627 };
5628
5629 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5630                 __attribute__((unused))  struct cmdline *cl,
5631                 __attribute__((unused)) void *data)
5632 {
5633         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5634         portid_t port_id = res->port_id;
5635         struct rte_port *port;
5636
5637         port = &ports[port_id];
5638
5639         /** Check if the port is not started **/
5640         if (port->port_status != RTE_PORT_STOPPED) {
5641                 printf("Please stop port %d first\n", port_id);
5642                 return;
5643         }
5644
5645         if (!strcmp(res->mode, "enable")) {
5646                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5647                         printf("Dedicate queues for LACP control packets"
5648                                         " enabled\n");
5649                 else
5650                         printf("Enabling dedicate queues for LACP control "
5651                                         "packets on port %d failed\n", port_id);
5652         } else if (!strcmp(res->mode, "disable")) {
5653                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5654                         printf("Dedicated queues for LACP control packets "
5655                                         "disabled\n");
5656                 else
5657                         printf("Disabling dedicated queues for LACP control "
5658                                         "traffic on port %d failed\n", port_id);
5659         }
5660 }
5661
5662 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5663 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5664                 set, "set");
5665 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5666 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5667                 bonding, "bonding");
5668 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5669 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5670                 lacp, "lacp");
5671 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5672 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5673                 dedicated_queues, "dedicated_queues");
5674 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5675 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5676                 port_id, UINT16);
5677 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5678 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5679                 mode, "enable#disable");
5680
5681 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5682                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5683                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5684                         "enable|disable: "
5685                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5686                 .data = NULL,
5687                 .tokens = {
5688                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5689                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5690                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5691                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5692                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5693                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5694                         NULL
5695                 }
5696 };
5697
5698 /* *** SET BALANCE XMIT POLICY *** */
5699 struct cmd_set_bonding_balance_xmit_policy_result {
5700         cmdline_fixed_string_t set;
5701         cmdline_fixed_string_t bonding;
5702         cmdline_fixed_string_t balance_xmit_policy;
5703         portid_t port_id;
5704         cmdline_fixed_string_t policy;
5705 };
5706
5707 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5708                 __attribute__((unused))  struct cmdline *cl,
5709                 __attribute__((unused)) void *data)
5710 {
5711         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5712         portid_t port_id = res->port_id;
5713         uint8_t policy;
5714
5715         if (!strcmp(res->policy, "l2")) {
5716                 policy = BALANCE_XMIT_POLICY_LAYER2;
5717         } else if (!strcmp(res->policy, "l23")) {
5718                 policy = BALANCE_XMIT_POLICY_LAYER23;
5719         } else if (!strcmp(res->policy, "l34")) {
5720                 policy = BALANCE_XMIT_POLICY_LAYER34;
5721         } else {
5722                 printf("\t Invalid xmit policy selection");
5723                 return;
5724         }
5725
5726         /* Set the bonding mode for the relevant port. */
5727         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5728                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5729                                 port_id);
5730         }
5731 }
5732
5733 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5734 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5735                 set, "set");
5736 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5737 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5738                 bonding, "bonding");
5739 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5740 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5741                 balance_xmit_policy, "balance_xmit_policy");
5742 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5743 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5744                 port_id, UINT16);
5745 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5746 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5747                 policy, "l2#l23#l34");
5748
5749 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5750                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5751                 .help_str = "set bonding balance_xmit_policy <port_id> "
5752                         "l2|l23|l34: "
5753                         "Set the bonding balance_xmit_policy for port_id",
5754                 .data = NULL,
5755                 .tokens = {
5756                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5757                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5758                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5759                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5760                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5761                                 NULL
5762                 }
5763 };
5764
5765 /* *** SHOW NIC BONDING CONFIGURATION *** */
5766 struct cmd_show_bonding_config_result {
5767         cmdline_fixed_string_t show;
5768         cmdline_fixed_string_t bonding;
5769         cmdline_fixed_string_t config;
5770         portid_t port_id;
5771 };
5772
5773 static void cmd_show_bonding_config_parsed(void *parsed_result,
5774                 __attribute__((unused))  struct cmdline *cl,
5775                 __attribute__((unused)) void *data)
5776 {
5777         struct cmd_show_bonding_config_result *res = parsed_result;
5778         int bonding_mode, agg_mode;
5779         portid_t slaves[RTE_MAX_ETHPORTS];
5780         int num_slaves, num_active_slaves;
5781         int primary_id;
5782         int i;
5783         portid_t port_id = res->port_id;
5784
5785         /* Display the bonding mode.*/
5786         bonding_mode = rte_eth_bond_mode_get(port_id);
5787         if (bonding_mode < 0) {
5788                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5789                 return;
5790         } else
5791                 printf("\tBonding mode: %d\n", bonding_mode);
5792
5793         if (bonding_mode == BONDING_MODE_BALANCE) {
5794                 int balance_xmit_policy;
5795
5796                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5797                 if (balance_xmit_policy < 0) {
5798                         printf("\tFailed to get balance xmit policy for port = %d\n",
5799                                         port_id);
5800                         return;
5801                 } else {
5802                         printf("\tBalance Xmit Policy: ");
5803
5804                         switch (balance_xmit_policy) {
5805                         case BALANCE_XMIT_POLICY_LAYER2:
5806                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5807                                 break;
5808                         case BALANCE_XMIT_POLICY_LAYER23:
5809                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5810                                 break;
5811                         case BALANCE_XMIT_POLICY_LAYER34:
5812                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5813                                 break;
5814                         }
5815                         printf("\n");
5816                 }
5817         }
5818
5819         if (bonding_mode == BONDING_MODE_8023AD) {
5820                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5821                 printf("\tIEEE802.3AD Aggregator Mode: ");
5822                 switch (agg_mode) {
5823                 case AGG_BANDWIDTH:
5824                         printf("bandwidth");
5825                         break;
5826                 case AGG_STABLE:
5827                         printf("stable");
5828                         break;
5829                 case AGG_COUNT:
5830                         printf("count");
5831                         break;
5832                 }
5833                 printf("\n");
5834         }
5835
5836         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5837
5838         if (num_slaves < 0) {
5839                 printf("\tFailed to get slave list for port = %d\n", port_id);
5840                 return;
5841         }
5842         if (num_slaves > 0) {
5843                 printf("\tSlaves (%d): [", num_slaves);
5844                 for (i = 0; i < num_slaves - 1; i++)
5845                         printf("%d ", slaves[i]);
5846
5847                 printf("%d]\n", slaves[num_slaves - 1]);
5848         } else {
5849                 printf("\tSlaves: []\n");
5850
5851         }
5852
5853         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5854                         RTE_MAX_ETHPORTS);
5855
5856         if (num_active_slaves < 0) {
5857                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5858                 return;
5859         }
5860         if (num_active_slaves > 0) {
5861                 printf("\tActive Slaves (%d): [", num_active_slaves);
5862                 for (i = 0; i < num_active_slaves - 1; i++)
5863                         printf("%d ", slaves[i]);
5864
5865                 printf("%d]\n", slaves[num_active_slaves - 1]);
5866
5867         } else {
5868                 printf("\tActive Slaves: []\n");
5869
5870         }
5871
5872         primary_id = rte_eth_bond_primary_get(port_id);
5873         if (primary_id < 0) {
5874                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5875                 return;
5876         } else
5877                 printf("\tPrimary: [%d]\n", primary_id);
5878
5879 }
5880
5881 cmdline_parse_token_string_t cmd_showbonding_config_show =
5882 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5883                 show, "show");
5884 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5885 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5886                 bonding, "bonding");
5887 cmdline_parse_token_string_t cmd_showbonding_config_config =
5888 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5889                 config, "config");
5890 cmdline_parse_token_num_t cmd_showbonding_config_port =
5891 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5892                 port_id, UINT16);
5893
5894 cmdline_parse_inst_t cmd_show_bonding_config = {
5895                 .f = cmd_show_bonding_config_parsed,
5896                 .help_str = "show bonding config <port_id>: "
5897                         "Show the bonding config for port_id",
5898                 .data = NULL,
5899                 .tokens = {
5900                                 (void *)&cmd_showbonding_config_show,
5901                                 (void *)&cmd_showbonding_config_bonding,
5902                                 (void *)&cmd_showbonding_config_config,
5903                                 (void *)&cmd_showbonding_config_port,
5904                                 NULL
5905                 }
5906 };
5907
5908 /* *** SET BONDING PRIMARY *** */
5909 struct cmd_set_bonding_primary_result {
5910         cmdline_fixed_string_t set;
5911         cmdline_fixed_string_t bonding;
5912         cmdline_fixed_string_t primary;
5913         portid_t slave_id;
5914         portid_t port_id;
5915 };
5916
5917 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5918                 __attribute__((unused))  struct cmdline *cl,
5919                 __attribute__((unused)) void *data)
5920 {
5921         struct cmd_set_bonding_primary_result *res = parsed_result;
5922         portid_t master_port_id = res->port_id;
5923         portid_t slave_port_id = res->slave_id;
5924
5925         /* Set the primary slave for a bonded device. */
5926         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5927                 printf("\t Failed to set primary slave for port = %d.\n",
5928                                 master_port_id);
5929                 return;
5930         }
5931         init_port_config();
5932 }
5933
5934 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5935 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5936                 set, "set");
5937 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5938 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5939                 bonding, "bonding");
5940 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5941 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5942                 primary, "primary");
5943 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5944 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5945                 slave_id, UINT16);
5946 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5947 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5948                 port_id, UINT16);
5949
5950 cmdline_parse_inst_t cmd_set_bonding_primary = {
5951                 .f = cmd_set_bonding_primary_parsed,
5952                 .help_str = "set bonding primary <slave_id> <port_id>: "
5953                         "Set the primary slave for port_id",
5954                 .data = NULL,
5955                 .tokens = {
5956                                 (void *)&cmd_setbonding_primary_set,
5957                                 (void *)&cmd_setbonding_primary_bonding,
5958                                 (void *)&cmd_setbonding_primary_primary,
5959                                 (void *)&cmd_setbonding_primary_slave,
5960                                 (void *)&cmd_setbonding_primary_port,
5961                                 NULL
5962                 }
5963 };
5964
5965 /* *** ADD SLAVE *** */
5966 struct cmd_add_bonding_slave_result {
5967         cmdline_fixed_string_t add;
5968         cmdline_fixed_string_t bonding;
5969         cmdline_fixed_string_t slave;
5970         portid_t slave_id;
5971         portid_t port_id;
5972 };
5973
5974 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5975                 __attribute__((unused))  struct cmdline *cl,
5976                 __attribute__((unused)) void *data)
5977 {
5978         struct cmd_add_bonding_slave_result *res = parsed_result;
5979         portid_t master_port_id = res->port_id;
5980         portid_t slave_port_id = res->slave_id;
5981
5982         /* add the slave for a bonded device. */
5983         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5984                 printf("\t Failed to add slave %d to master port = %d.\n",
5985                                 slave_port_id, master_port_id);
5986                 return;
5987         }
5988         init_port_config();
5989         set_port_slave_flag(slave_port_id);
5990 }
5991
5992 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5993 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5994                 add, "add");
5995 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5996 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5997                 bonding, "bonding");
5998 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5999 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6000                 slave, "slave");
6001 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6002 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6003                 slave_id, UINT16);
6004 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6005 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6006                 port_id, UINT16);
6007
6008 cmdline_parse_inst_t cmd_add_bonding_slave = {
6009                 .f = cmd_add_bonding_slave_parsed,
6010                 .help_str = "add bonding slave <slave_id> <port_id>: "
6011                         "Add a slave device to a bonded device",
6012                 .data = NULL,
6013                 .tokens = {
6014                                 (void *)&cmd_addbonding_slave_add,
6015                                 (void *)&cmd_addbonding_slave_bonding,
6016                                 (void *)&cmd_addbonding_slave_slave,
6017                                 (void *)&cmd_addbonding_slave_slaveid,
6018                                 (void *)&cmd_addbonding_slave_port,
6019                                 NULL
6020                 }
6021 };
6022
6023 /* *** REMOVE SLAVE *** */
6024 struct cmd_remove_bonding_slave_result {
6025         cmdline_fixed_string_t remove;
6026         cmdline_fixed_string_t bonding;
6027         cmdline_fixed_string_t slave;
6028         portid_t slave_id;
6029         portid_t port_id;
6030 };
6031
6032 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6033                 __attribute__((unused))  struct cmdline *cl,
6034                 __attribute__((unused)) void *data)
6035 {
6036         struct cmd_remove_bonding_slave_result *res = parsed_result;
6037         portid_t master_port_id = res->port_id;
6038         portid_t slave_port_id = res->slave_id;
6039
6040         /* remove the slave from a bonded device. */
6041         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6042                 printf("\t Failed to remove slave %d from master port = %d.\n",
6043                                 slave_port_id, master_port_id);
6044                 return;
6045         }
6046         init_port_config();
6047         clear_port_slave_flag(slave_port_id);
6048 }
6049
6050 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6051                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6052                                 remove, "remove");
6053 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6054                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6055                                 bonding, "bonding");
6056 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6057                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6058                                 slave, "slave");
6059 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6060                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6061                                 slave_id, UINT16);
6062 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6063                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6064                                 port_id, UINT16);
6065
6066 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6067                 .f = cmd_remove_bonding_slave_parsed,
6068                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6069                         "Remove a slave device from a bonded device",
6070                 .data = NULL,
6071                 .tokens = {
6072                                 (void *)&cmd_removebonding_slave_remove,
6073                                 (void *)&cmd_removebonding_slave_bonding,
6074                                 (void *)&cmd_removebonding_slave_slave,
6075                                 (void *)&cmd_removebonding_slave_slaveid,
6076                                 (void *)&cmd_removebonding_slave_port,
6077                                 NULL
6078                 }
6079 };
6080
6081 /* *** CREATE BONDED DEVICE *** */
6082 struct cmd_create_bonded_device_result {
6083         cmdline_fixed_string_t create;
6084         cmdline_fixed_string_t bonded;
6085         cmdline_fixed_string_t device;
6086         uint8_t mode;
6087         uint8_t socket;
6088 };
6089
6090 static int bond_dev_num = 0;
6091
6092 static void cmd_create_bonded_device_parsed(void *parsed_result,
6093                 __attribute__((unused))  struct cmdline *cl,
6094                 __attribute__((unused)) void *data)
6095 {
6096         struct cmd_create_bonded_device_result *res = parsed_result;
6097         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6098         int port_id;
6099         int ret;
6100
6101         if (test_done == 0) {
6102                 printf("Please stop forwarding first\n");
6103                 return;
6104         }
6105
6106         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6107                         bond_dev_num++);
6108
6109         /* Create a new bonded device. */
6110         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6111         if (port_id < 0) {
6112                 printf("\t Failed to create bonded device.\n");
6113                 return;
6114         } else {
6115                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6116                                 port_id);
6117
6118                 /* Update number of ports */
6119                 nb_ports = rte_eth_dev_count_avail();
6120                 reconfig(port_id, res->socket);
6121                 ret = rte_eth_promiscuous_enable(port_id);
6122                 if (ret != 0)
6123                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6124                                 port_id, rte_strerror(-ret));
6125
6126                 ports[port_id].need_setup = 0;
6127                 ports[port_id].port_status = RTE_PORT_STOPPED;
6128         }
6129
6130 }
6131
6132 cmdline_parse_token_string_t cmd_createbonded_device_create =
6133                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6134                                 create, "create");
6135 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6136                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6137                                 bonded, "bonded");
6138 cmdline_parse_token_string_t cmd_createbonded_device_device =
6139                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6140                                 device, "device");
6141 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6142                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6143                                 mode, UINT8);
6144 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6145                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6146                                 socket, UINT8);
6147
6148 cmdline_parse_inst_t cmd_create_bonded_device = {
6149                 .f = cmd_create_bonded_device_parsed,
6150                 .help_str = "create bonded device <mode> <socket>: "
6151                         "Create a new bonded device with specific bonding mode and socket",
6152                 .data = NULL,
6153                 .tokens = {
6154                                 (void *)&cmd_createbonded_device_create,
6155                                 (void *)&cmd_createbonded_device_bonded,
6156                                 (void *)&cmd_createbonded_device_device,
6157                                 (void *)&cmd_createbonded_device_mode,
6158                                 (void *)&cmd_createbonded_device_socket,
6159                                 NULL
6160                 }
6161 };
6162
6163 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6164 struct cmd_set_bond_mac_addr_result {
6165         cmdline_fixed_string_t set;
6166         cmdline_fixed_string_t bonding;
6167         cmdline_fixed_string_t mac_addr;
6168         uint16_t port_num;
6169         struct rte_ether_addr address;
6170 };
6171
6172 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6173                 __attribute__((unused))  struct cmdline *cl,
6174                 __attribute__((unused)) void *data)
6175 {
6176         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6177         int ret;
6178
6179         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6180                 return;
6181
6182         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6183
6184         /* check the return value and print it if is < 0 */
6185         if (ret < 0)
6186                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6187 }
6188
6189 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6190                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6191 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6192                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6193                                 "bonding");
6194 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6195                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6196                                 "mac_addr");
6197 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6198                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6199                                 port_num, UINT16);
6200 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6201                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6202
6203 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6204                 .f = cmd_set_bond_mac_addr_parsed,
6205                 .data = (void *) 0,
6206                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6207                 .tokens = {
6208                                 (void *)&cmd_set_bond_mac_addr_set,
6209                                 (void *)&cmd_set_bond_mac_addr_bonding,
6210                                 (void *)&cmd_set_bond_mac_addr_mac,
6211                                 (void *)&cmd_set_bond_mac_addr_portnum,
6212                                 (void *)&cmd_set_bond_mac_addr_addr,
6213                                 NULL
6214                 }
6215 };
6216
6217
6218 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6219 struct cmd_set_bond_mon_period_result {
6220         cmdline_fixed_string_t set;
6221         cmdline_fixed_string_t bonding;
6222         cmdline_fixed_string_t mon_period;
6223         uint16_t port_num;
6224         uint32_t period_ms;
6225 };
6226
6227 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6228                 __attribute__((unused))  struct cmdline *cl,
6229                 __attribute__((unused)) void *data)
6230 {
6231         struct cmd_set_bond_mon_period_result *res = parsed_result;
6232         int ret;
6233
6234         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6235
6236         /* check the return value and print it if is < 0 */
6237         if (ret < 0)
6238                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6239 }
6240
6241 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6242                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6243                                 set, "set");
6244 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6245                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6246                                 bonding, "bonding");
6247 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6248                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6249                                 mon_period,     "mon_period");
6250 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6251                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6252                                 port_num, UINT16);
6253 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6254                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6255                                 period_ms, UINT32);
6256
6257 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6258                 .f = cmd_set_bond_mon_period_parsed,
6259                 .data = (void *) 0,
6260                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6261                 .tokens = {
6262                                 (void *)&cmd_set_bond_mon_period_set,
6263                                 (void *)&cmd_set_bond_mon_period_bonding,
6264                                 (void *)&cmd_set_bond_mon_period_mon_period,
6265                                 (void *)&cmd_set_bond_mon_period_portnum,
6266                                 (void *)&cmd_set_bond_mon_period_period_ms,
6267                                 NULL
6268                 }
6269 };
6270
6271
6272
6273 struct cmd_set_bonding_agg_mode_policy_result {
6274         cmdline_fixed_string_t set;
6275         cmdline_fixed_string_t bonding;
6276         cmdline_fixed_string_t agg_mode;
6277         uint16_t port_num;
6278         cmdline_fixed_string_t policy;
6279 };
6280
6281
6282 static void
6283 cmd_set_bonding_agg_mode(void *parsed_result,
6284                 __attribute__((unused)) struct cmdline *cl,
6285                 __attribute__((unused)) void *data)
6286 {
6287         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6288         uint8_t policy = AGG_BANDWIDTH;
6289
6290         if (!strcmp(res->policy, "bandwidth"))
6291                 policy = AGG_BANDWIDTH;
6292         else if (!strcmp(res->policy, "stable"))
6293                 policy = AGG_STABLE;
6294         else if (!strcmp(res->policy, "count"))
6295                 policy = AGG_COUNT;
6296
6297         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6298 }
6299
6300
6301 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6302         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6303                                 set, "set");
6304 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6305         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6306                                 bonding, "bonding");
6307
6308 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6309         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6310                                 agg_mode, "agg_mode");
6311
6312 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6313         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6314                                 port_num, UINT16);
6315
6316 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6317         TOKEN_STRING_INITIALIZER(
6318                         struct cmd_set_bonding_balance_xmit_policy_result,
6319                 policy, "stable#bandwidth#count");
6320
6321 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6322         .f = cmd_set_bonding_agg_mode,
6323         .data = (void *) 0,
6324         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6325         .tokens = {
6326                         (void *)&cmd_set_bonding_agg_mode_set,
6327                         (void *)&cmd_set_bonding_agg_mode_bonding,
6328                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6329                         (void *)&cmd_set_bonding_agg_mode_portnum,
6330                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6331                         NULL
6332                 }
6333 };
6334
6335
6336 #endif /* RTE_LIBRTE_PMD_BOND */
6337
6338 /* *** SET FORWARDING MODE *** */
6339 struct cmd_set_fwd_mode_result {
6340         cmdline_fixed_string_t set;
6341         cmdline_fixed_string_t fwd;
6342         cmdline_fixed_string_t mode;
6343 };
6344
6345 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6346                                     __attribute__((unused)) struct cmdline *cl,
6347                                     __attribute__((unused)) void *data)
6348 {
6349         struct cmd_set_fwd_mode_result *res = parsed_result;
6350
6351         retry_enabled = 0;
6352         set_pkt_forwarding_mode(res->mode);
6353 }
6354
6355 cmdline_parse_token_string_t cmd_setfwd_set =
6356         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6357 cmdline_parse_token_string_t cmd_setfwd_fwd =
6358         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6359 cmdline_parse_token_string_t cmd_setfwd_mode =
6360         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6361                 "" /* defined at init */);
6362
6363 cmdline_parse_inst_t cmd_set_fwd_mode = {
6364         .f = cmd_set_fwd_mode_parsed,
6365         .data = NULL,
6366         .help_str = NULL, /* defined at init */
6367         .tokens = {
6368                 (void *)&cmd_setfwd_set,
6369                 (void *)&cmd_setfwd_fwd,
6370                 (void *)&cmd_setfwd_mode,
6371                 NULL,
6372         },
6373 };
6374
6375 static void cmd_set_fwd_mode_init(void)
6376 {
6377         char *modes, *c;
6378         static char token[128];
6379         static char help[256];
6380         cmdline_parse_token_string_t *token_struct;
6381
6382         modes = list_pkt_forwarding_modes();
6383         snprintf(help, sizeof(help), "set fwd %s: "
6384                 "Set packet forwarding mode", modes);
6385         cmd_set_fwd_mode.help_str = help;
6386
6387         /* string token separator is # */
6388         for (c = token; *modes != '\0'; modes++)
6389                 if (*modes == '|')
6390                         *c++ = '#';
6391                 else
6392                         *c++ = *modes;
6393         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6394         token_struct->string_data.str = token;
6395 }
6396
6397 /* *** SET RETRY FORWARDING MODE *** */
6398 struct cmd_set_fwd_retry_mode_result {
6399         cmdline_fixed_string_t set;
6400         cmdline_fixed_string_t fwd;
6401         cmdline_fixed_string_t mode;
6402         cmdline_fixed_string_t retry;
6403 };
6404
6405 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6406                             __attribute__((unused)) struct cmdline *cl,
6407                             __attribute__((unused)) void *data)
6408 {
6409         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6410
6411         retry_enabled = 1;
6412         set_pkt_forwarding_mode(res->mode);
6413 }
6414
6415 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6416         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6417                         set, "set");
6418 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6420                         fwd, "fwd");
6421 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6422         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6423                         mode,
6424                 "" /* defined at init */);
6425 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6426         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6427                         retry, "retry");
6428
6429 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6430         .f = cmd_set_fwd_retry_mode_parsed,
6431         .data = NULL,
6432         .help_str = NULL, /* defined at init */
6433         .tokens = {
6434                 (void *)&cmd_setfwd_retry_set,
6435                 (void *)&cmd_setfwd_retry_fwd,
6436                 (void *)&cmd_setfwd_retry_mode,
6437                 (void *)&cmd_setfwd_retry_retry,
6438                 NULL,
6439         },
6440 };
6441
6442 static void cmd_set_fwd_retry_mode_init(void)
6443 {
6444         char *modes, *c;
6445         static char token[128];
6446         static char help[256];
6447         cmdline_parse_token_string_t *token_struct;
6448
6449         modes = list_pkt_forwarding_retry_modes();
6450         snprintf(help, sizeof(help), "set fwd %s retry: "
6451                 "Set packet forwarding mode with retry", modes);
6452         cmd_set_fwd_retry_mode.help_str = help;
6453
6454         /* string token separator is # */
6455         for (c = token; *modes != '\0'; modes++)
6456                 if (*modes == '|')
6457                         *c++ = '#';
6458                 else
6459                         *c++ = *modes;
6460         token_struct = (cmdline_parse_token_string_t *)
6461                 cmd_set_fwd_retry_mode.tokens[2];
6462         token_struct->string_data.str = token;
6463 }
6464
6465 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6466 struct cmd_set_burst_tx_retry_result {
6467         cmdline_fixed_string_t set;
6468         cmdline_fixed_string_t burst;
6469         cmdline_fixed_string_t tx;
6470         cmdline_fixed_string_t delay;
6471         uint32_t time;
6472         cmdline_fixed_string_t retry;
6473         uint32_t retry_num;
6474 };
6475
6476 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6477                                         __attribute__((unused)) struct cmdline *cl,
6478                                         __attribute__((unused)) void *data)
6479 {
6480         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6481
6482         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6483                 && !strcmp(res->tx, "tx")) {
6484                 if (!strcmp(res->delay, "delay"))
6485                         burst_tx_delay_time = res->time;
6486                 if (!strcmp(res->retry, "retry"))
6487                         burst_tx_retry_num = res->retry_num;
6488         }
6489
6490 }
6491
6492 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6493         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6494 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6495         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6496                                  "burst");
6497 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6498         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6499 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6500         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6501 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6502         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6503 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6504         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6505 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6506         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6507
6508 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6509         .f = cmd_set_burst_tx_retry_parsed,
6510         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6511         .tokens = {
6512                 (void *)&cmd_set_burst_tx_retry_set,
6513                 (void *)&cmd_set_burst_tx_retry_burst,
6514                 (void *)&cmd_set_burst_tx_retry_tx,
6515                 (void *)&cmd_set_burst_tx_retry_delay,
6516                 (void *)&cmd_set_burst_tx_retry_time,
6517                 (void *)&cmd_set_burst_tx_retry_retry,
6518                 (void *)&cmd_set_burst_tx_retry_retry_num,
6519                 NULL,
6520         },
6521 };
6522
6523 /* *** SET PROMISC MODE *** */
6524 struct cmd_set_promisc_mode_result {
6525         cmdline_fixed_string_t set;
6526         cmdline_fixed_string_t promisc;
6527         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6528         uint16_t port_num;               /* valid if "allports" argument == 0 */
6529         cmdline_fixed_string_t mode;
6530 };
6531
6532 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6533                                         __attribute__((unused)) struct cmdline *cl,
6534                                         void *allports)
6535 {
6536         struct cmd_set_promisc_mode_result *res = parsed_result;
6537         int enable;
6538         portid_t i;
6539
6540         if (!strcmp(res->mode, "on"))
6541                 enable = 1;
6542         else
6543                 enable = 0;
6544
6545         /* all ports */
6546         if (allports) {
6547                 RTE_ETH_FOREACH_DEV(i)
6548                         eth_set_promisc_mode(i, enable);
6549         } else {
6550                 eth_set_promisc_mode(res->port_num, enable);
6551         }
6552 }
6553
6554 cmdline_parse_token_string_t cmd_setpromisc_set =
6555         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6556 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6557         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6558                                  "promisc");
6559 cmdline_parse_token_string_t cmd_setpromisc_portall =
6560         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6561                                  "all");
6562 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6563         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6564                               UINT16);
6565 cmdline_parse_token_string_t cmd_setpromisc_mode =
6566         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6567                                  "on#off");
6568
6569 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6570         .f = cmd_set_promisc_mode_parsed,
6571         .data = (void *)1,
6572         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6573         .tokens = {
6574                 (void *)&cmd_setpromisc_set,
6575                 (void *)&cmd_setpromisc_promisc,
6576                 (void *)&cmd_setpromisc_portall,
6577                 (void *)&cmd_setpromisc_mode,
6578                 NULL,
6579         },
6580 };
6581
6582 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6583         .f = cmd_set_promisc_mode_parsed,
6584         .data = (void *)0,
6585         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6586         .tokens = {
6587                 (void *)&cmd_setpromisc_set,
6588                 (void *)&cmd_setpromisc_promisc,
6589                 (void *)&cmd_setpromisc_portnum,
6590                 (void *)&cmd_setpromisc_mode,
6591                 NULL,
6592         },
6593 };
6594
6595 /* *** SET ALLMULTI MODE *** */
6596 struct cmd_set_allmulti_mode_result {
6597         cmdline_fixed_string_t set;
6598         cmdline_fixed_string_t allmulti;
6599         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6600         uint16_t port_num;               /* valid if "allports" argument == 0 */
6601         cmdline_fixed_string_t mode;
6602 };
6603
6604 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6605                                         __attribute__((unused)) struct cmdline *cl,
6606                                         void *allports)
6607 {
6608         struct cmd_set_allmulti_mode_result *res = parsed_result;
6609         int enable;
6610         portid_t i;
6611
6612         if (!strcmp(res->mode, "on"))
6613                 enable = 1;
6614         else
6615                 enable = 0;
6616
6617         /* all ports */
6618         if (allports) {
6619                 RTE_ETH_FOREACH_DEV(i) {
6620                         eth_set_allmulticast_mode(i, enable);
6621                 }
6622         }
6623         else {
6624                 eth_set_allmulticast_mode(res->port_num, enable);
6625         }
6626 }
6627
6628 cmdline_parse_token_string_t cmd_setallmulti_set =
6629         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6630 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6631         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6632                                  "allmulti");
6633 cmdline_parse_token_string_t cmd_setallmulti_portall =
6634         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6635                                  "all");
6636 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6637         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6638                               UINT16);
6639 cmdline_parse_token_string_t cmd_setallmulti_mode =
6640         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6641                                  "on#off");
6642
6643 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6644         .f = cmd_set_allmulti_mode_parsed,
6645         .data = (void *)1,
6646         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6647         .tokens = {
6648                 (void *)&cmd_setallmulti_set,
6649                 (void *)&cmd_setallmulti_allmulti,
6650                 (void *)&cmd_setallmulti_portall,
6651                 (void *)&cmd_setallmulti_mode,
6652                 NULL,
6653         },
6654 };
6655
6656 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6657         .f = cmd_set_allmulti_mode_parsed,
6658         .data = (void *)0,
6659         .help_str = "set allmulti <port_id> on|off: "
6660                 "Set allmulti mode on port_id",
6661         .tokens = {
6662                 (void *)&cmd_setallmulti_set,
6663                 (void *)&cmd_setallmulti_allmulti,
6664                 (void *)&cmd_setallmulti_portnum,
6665                 (void *)&cmd_setallmulti_mode,
6666                 NULL,
6667         },
6668 };
6669
6670 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6671 struct cmd_link_flow_ctrl_set_result {
6672         cmdline_fixed_string_t set;
6673         cmdline_fixed_string_t flow_ctrl;
6674         cmdline_fixed_string_t rx;
6675         cmdline_fixed_string_t rx_lfc_mode;
6676         cmdline_fixed_string_t tx;
6677         cmdline_fixed_string_t tx_lfc_mode;
6678         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6679         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6680         cmdline_fixed_string_t autoneg_str;
6681         cmdline_fixed_string_t autoneg;
6682         cmdline_fixed_string_t hw_str;
6683         uint32_t high_water;
6684         cmdline_fixed_string_t lw_str;
6685         uint32_t low_water;
6686         cmdline_fixed_string_t pt_str;
6687         uint16_t pause_time;
6688         cmdline_fixed_string_t xon_str;
6689         uint16_t send_xon;
6690         portid_t port_id;
6691 };
6692
6693 cmdline_parse_token_string_t cmd_lfc_set_set =
6694         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6695                                 set, "set");
6696 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6697         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6698                                 flow_ctrl, "flow_ctrl");
6699 cmdline_parse_token_string_t cmd_lfc_set_rx =
6700         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6701                                 rx, "rx");
6702 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6703         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6704                                 rx_lfc_mode, "on#off");
6705 cmdline_parse_token_string_t cmd_lfc_set_tx =
6706         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6707                                 tx, "tx");
6708 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6709         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6710                                 tx_lfc_mode, "on#off");
6711 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6712         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6713                                 hw_str, "high_water");
6714 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6715         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6716                                 high_water, UINT32);
6717 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6718         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6719                                 lw_str, "low_water");
6720 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6721         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6722                                 low_water, UINT32);
6723 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6724         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6725                                 pt_str, "pause_time");
6726 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6727         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6728                                 pause_time, UINT16);
6729 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6730         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6731                                 xon_str, "send_xon");
6732 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6733         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6734                                 send_xon, UINT16);
6735 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6736         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6737                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6738 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6739         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6740                                 mac_ctrl_frame_fwd_mode, "on#off");
6741 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6742         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6743                                 autoneg_str, "autoneg");
6744 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6745         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6746                                 autoneg, "on#off");
6747 cmdline_parse_token_num_t cmd_lfc_set_portid =
6748         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6749                                 port_id, UINT16);
6750
6751 /* forward declaration */
6752 static void
6753 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6754                               void *data);
6755
6756 cmdline_parse_inst_t cmd_link_flow_control_set = {
6757         .f = cmd_link_flow_ctrl_set_parsed,
6758         .data = NULL,
6759         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6760                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6761                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6762         .tokens = {
6763                 (void *)&cmd_lfc_set_set,
6764                 (void *)&cmd_lfc_set_flow_ctrl,
6765                 (void *)&cmd_lfc_set_rx,
6766                 (void *)&cmd_lfc_set_rx_mode,
6767                 (void *)&cmd_lfc_set_tx,
6768                 (void *)&cmd_lfc_set_tx_mode,
6769                 (void *)&cmd_lfc_set_high_water,
6770                 (void *)&cmd_lfc_set_low_water,
6771                 (void *)&cmd_lfc_set_pause_time,
6772                 (void *)&cmd_lfc_set_send_xon,
6773                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6774                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6775                 (void *)&cmd_lfc_set_autoneg_str,
6776                 (void *)&cmd_lfc_set_autoneg,
6777                 (void *)&cmd_lfc_set_portid,
6778                 NULL,
6779         },
6780 };
6781
6782 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6783         .f = cmd_link_flow_ctrl_set_parsed,
6784         .data = (void *)&cmd_link_flow_control_set_rx,
6785         .help_str = "set flow_ctrl rx on|off <port_id>: "
6786                 "Change rx flow control parameter",
6787         .tokens = {
6788                 (void *)&cmd_lfc_set_set,
6789                 (void *)&cmd_lfc_set_flow_ctrl,
6790                 (void *)&cmd_lfc_set_rx,
6791                 (void *)&cmd_lfc_set_rx_mode,
6792                 (void *)&cmd_lfc_set_portid,
6793                 NULL,
6794         },
6795 };
6796
6797 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6798         .f = cmd_link_flow_ctrl_set_parsed,
6799         .data = (void *)&cmd_link_flow_control_set_tx,
6800         .help_str = "set flow_ctrl tx on|off <port_id>: "
6801                 "Change tx flow control parameter",
6802         .tokens = {
6803                 (void *)&cmd_lfc_set_set,
6804                 (void *)&cmd_lfc_set_flow_ctrl,
6805                 (void *)&cmd_lfc_set_tx,
6806                 (void *)&cmd_lfc_set_tx_mode,
6807                 (void *)&cmd_lfc_set_portid,
6808                 NULL,
6809         },
6810 };
6811
6812 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6813         .f = cmd_link_flow_ctrl_set_parsed,
6814         .data = (void *)&cmd_link_flow_control_set_hw,
6815         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6816                 "Change high water flow control parameter",
6817         .tokens = {
6818                 (void *)&cmd_lfc_set_set,
6819                 (void *)&cmd_lfc_set_flow_ctrl,
6820                 (void *)&cmd_lfc_set_high_water_str,
6821                 (void *)&cmd_lfc_set_high_water,
6822                 (void *)&cmd_lfc_set_portid,
6823                 NULL,
6824         },
6825 };
6826
6827 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6828         .f = cmd_link_flow_ctrl_set_parsed,
6829         .data = (void *)&cmd_link_flow_control_set_lw,
6830         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6831                 "Change low water flow control parameter",
6832         .tokens = {
6833                 (void *)&cmd_lfc_set_set,
6834                 (void *)&cmd_lfc_set_flow_ctrl,
6835                 (void *)&cmd_lfc_set_low_water_str,
6836                 (void *)&cmd_lfc_set_low_water,
6837                 (void *)&cmd_lfc_set_portid,
6838                 NULL,
6839         },
6840 };
6841
6842 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6843         .f = cmd_link_flow_ctrl_set_parsed,
6844         .data = (void *)&cmd_link_flow_control_set_pt,
6845         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6846                 "Change pause time flow control parameter",
6847         .tokens = {
6848                 (void *)&cmd_lfc_set_set,
6849                 (void *)&cmd_lfc_set_flow_ctrl,
6850                 (void *)&cmd_lfc_set_pause_time_str,
6851                 (void *)&cmd_lfc_set_pause_time,
6852                 (void *)&cmd_lfc_set_portid,
6853                 NULL,
6854         },
6855 };
6856
6857 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6858         .f = cmd_link_flow_ctrl_set_parsed,
6859         .data = (void *)&cmd_link_flow_control_set_xon,
6860         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6861                 "Change send_xon flow control parameter",
6862         .tokens = {
6863                 (void *)&cmd_lfc_set_set,
6864                 (void *)&cmd_lfc_set_flow_ctrl,
6865                 (void *)&cmd_lfc_set_send_xon_str,
6866                 (void *)&cmd_lfc_set_send_xon,
6867                 (void *)&cmd_lfc_set_portid,
6868                 NULL,
6869         },
6870 };
6871
6872 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6873         .f = cmd_link_flow_ctrl_set_parsed,
6874         .data = (void *)&cmd_link_flow_control_set_macfwd,
6875         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6876                 "Change mac ctrl fwd flow control parameter",
6877         .tokens = {
6878                 (void *)&cmd_lfc_set_set,
6879                 (void *)&cmd_lfc_set_flow_ctrl,
6880                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6881                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6882                 (void *)&cmd_lfc_set_portid,
6883                 NULL,
6884         },
6885 };
6886
6887 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6888         .f = cmd_link_flow_ctrl_set_parsed,
6889         .data = (void *)&cmd_link_flow_control_set_autoneg,
6890         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6891                 "Change autoneg flow control parameter",
6892         .tokens = {
6893                 (void *)&cmd_lfc_set_set,
6894                 (void *)&cmd_lfc_set_flow_ctrl,
6895                 (void *)&cmd_lfc_set_autoneg_str,
6896                 (void *)&cmd_lfc_set_autoneg,
6897                 (void *)&cmd_lfc_set_portid,
6898                 NULL,
6899         },
6900 };
6901
6902 static void
6903 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6904                               __attribute__((unused)) struct cmdline *cl,
6905                               void *data)
6906 {
6907         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6908         cmdline_parse_inst_t *cmd = data;
6909         struct rte_eth_fc_conf fc_conf;
6910         int rx_fc_en = 0;
6911         int tx_fc_en = 0;
6912         int ret;
6913
6914         /*
6915          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6916          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6917          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6918          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6919          */
6920         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6921                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6922         };
6923
6924         /* Partial command line, retrieve current configuration */
6925         if (cmd) {
6926                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6927                 if (ret != 0) {
6928                         printf("cannot get current flow ctrl parameters, return"
6929                                "code = %d\n", ret);
6930                         return;
6931                 }
6932
6933                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6934                     (fc_conf.mode == RTE_FC_FULL))
6935                         rx_fc_en = 1;
6936                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6937                     (fc_conf.mode == RTE_FC_FULL))
6938                         tx_fc_en = 1;
6939         }
6940
6941         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6942                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6943
6944         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6945                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6946
6947         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6948
6949         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6950                 fc_conf.high_water = res->high_water;
6951
6952         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6953                 fc_conf.low_water = res->low_water;
6954
6955         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6956                 fc_conf.pause_time = res->pause_time;
6957
6958         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6959                 fc_conf.send_xon = res->send_xon;
6960
6961         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6962                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6963                         fc_conf.mac_ctrl_frame_fwd = 1;
6964                 else
6965                         fc_conf.mac_ctrl_frame_fwd = 0;
6966         }
6967
6968         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6969                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6970
6971         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6972         if (ret != 0)
6973                 printf("bad flow contrl parameter, return code = %d \n", ret);
6974 }
6975
6976 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6977 struct cmd_priority_flow_ctrl_set_result {
6978         cmdline_fixed_string_t set;
6979         cmdline_fixed_string_t pfc_ctrl;
6980         cmdline_fixed_string_t rx;
6981         cmdline_fixed_string_t rx_pfc_mode;
6982         cmdline_fixed_string_t tx;
6983         cmdline_fixed_string_t tx_pfc_mode;
6984         uint32_t high_water;
6985         uint32_t low_water;
6986         uint16_t pause_time;
6987         uint8_t  priority;
6988         portid_t port_id;
6989 };
6990
6991 static void
6992 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6993                        __attribute__((unused)) struct cmdline *cl,
6994                        __attribute__((unused)) void *data)
6995 {
6996         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6997         struct rte_eth_pfc_conf pfc_conf;
6998         int rx_fc_enable, tx_fc_enable;
6999         int ret;
7000
7001         /*
7002          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7003          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7004          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7005          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7006          */
7007         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7008                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7009         };
7010
7011         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7012         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7013         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7014         pfc_conf.fc.high_water = res->high_water;
7015         pfc_conf.fc.low_water  = res->low_water;
7016         pfc_conf.fc.pause_time = res->pause_time;
7017         pfc_conf.priority      = res->priority;
7018
7019         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7020         if (ret != 0)
7021                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7022 }
7023
7024 cmdline_parse_token_string_t cmd_pfc_set_set =
7025         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7026                                 set, "set");
7027 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7028         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7029                                 pfc_ctrl, "pfc_ctrl");
7030 cmdline_parse_token_string_t cmd_pfc_set_rx =
7031         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7032                                 rx, "rx");
7033 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7034         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7035                                 rx_pfc_mode, "on#off");
7036 cmdline_parse_token_string_t cmd_pfc_set_tx =
7037         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7038                                 tx, "tx");
7039 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7040         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7041                                 tx_pfc_mode, "on#off");
7042 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7043         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7044                                 high_water, UINT32);
7045 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7046         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7047                                 low_water, UINT32);
7048 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7049         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7050                                 pause_time, UINT16);
7051 cmdline_parse_token_num_t cmd_pfc_set_priority =
7052         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7053                                 priority, UINT8);
7054 cmdline_parse_token_num_t cmd_pfc_set_portid =
7055         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7056                                 port_id, UINT16);
7057
7058 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7059         .f = cmd_priority_flow_ctrl_set_parsed,
7060         .data = NULL,
7061         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7062                 "<pause_time> <priority> <port_id>: "
7063                 "Configure the Ethernet priority flow control",
7064         .tokens = {
7065                 (void *)&cmd_pfc_set_set,
7066                 (void *)&cmd_pfc_set_flow_ctrl,
7067                 (void *)&cmd_pfc_set_rx,
7068                 (void *)&cmd_pfc_set_rx_mode,
7069                 (void *)&cmd_pfc_set_tx,
7070                 (void *)&cmd_pfc_set_tx_mode,
7071                 (void *)&cmd_pfc_set_high_water,
7072                 (void *)&cmd_pfc_set_low_water,
7073                 (void *)&cmd_pfc_set_pause_time,
7074                 (void *)&cmd_pfc_set_priority,
7075                 (void *)&cmd_pfc_set_portid,
7076                 NULL,
7077         },
7078 };
7079
7080 /* *** RESET CONFIGURATION *** */
7081 struct cmd_reset_result {
7082         cmdline_fixed_string_t reset;
7083         cmdline_fixed_string_t def;
7084 };
7085
7086 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7087                              struct cmdline *cl,
7088                              __attribute__((unused)) void *data)
7089 {
7090         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7091         set_def_fwd_config();
7092 }
7093
7094 cmdline_parse_token_string_t cmd_reset_set =
7095         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7096 cmdline_parse_token_string_t cmd_reset_def =
7097         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7098                                  "default");
7099
7100 cmdline_parse_inst_t cmd_reset = {
7101         .f = cmd_reset_parsed,
7102         .data = NULL,
7103         .help_str = "set default: Reset default forwarding configuration",
7104         .tokens = {
7105                 (void *)&cmd_reset_set,
7106                 (void *)&cmd_reset_def,
7107                 NULL,
7108         },
7109 };
7110
7111 /* *** START FORWARDING *** */
7112 struct cmd_start_result {
7113         cmdline_fixed_string_t start;
7114 };
7115
7116 cmdline_parse_token_string_t cmd_start_start =
7117         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7118
7119 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7120                              __attribute__((unused)) struct cmdline *cl,
7121                              __attribute__((unused)) void *data)
7122 {
7123         start_packet_forwarding(0);
7124 }
7125
7126 cmdline_parse_inst_t cmd_start = {
7127         .f = cmd_start_parsed,
7128         .data = NULL,
7129         .help_str = "start: Start packet forwarding",
7130         .tokens = {
7131                 (void *)&cmd_start_start,
7132                 NULL,
7133         },
7134 };
7135
7136 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7137 struct cmd_start_tx_first_result {
7138         cmdline_fixed_string_t start;
7139         cmdline_fixed_string_t tx_first;
7140 };
7141
7142 static void
7143 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7144                           __attribute__((unused)) struct cmdline *cl,
7145                           __attribute__((unused)) void *data)
7146 {
7147         start_packet_forwarding(1);
7148 }
7149
7150 cmdline_parse_token_string_t cmd_start_tx_first_start =
7151         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7152                                  "start");
7153 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7154         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7155                                  tx_first, "tx_first");
7156
7157 cmdline_parse_inst_t cmd_start_tx_first = {
7158         .f = cmd_start_tx_first_parsed,
7159         .data = NULL,
7160         .help_str = "start tx_first: Start packet forwarding, "
7161                 "after sending 1 burst of packets",
7162         .tokens = {
7163                 (void *)&cmd_start_tx_first_start,
7164                 (void *)&cmd_start_tx_first_tx_first,
7165                 NULL,
7166         },
7167 };
7168
7169 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7170 struct cmd_start_tx_first_n_result {
7171         cmdline_fixed_string_t start;
7172         cmdline_fixed_string_t tx_first;
7173         uint32_t tx_num;
7174 };
7175
7176 static void
7177 cmd_start_tx_first_n_parsed(void *parsed_result,
7178                           __attribute__((unused)) struct cmdline *cl,
7179                           __attribute__((unused)) void *data)
7180 {
7181         struct cmd_start_tx_first_n_result *res = parsed_result;
7182
7183         start_packet_forwarding(res->tx_num);
7184 }
7185
7186 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7187         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7188                         start, "start");
7189 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7190         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7191                         tx_first, "tx_first");
7192 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7193         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7194                         tx_num, UINT32);
7195
7196 cmdline_parse_inst_t cmd_start_tx_first_n = {
7197         .f = cmd_start_tx_first_n_parsed,
7198         .data = NULL,
7199         .help_str = "start tx_first <num>: "
7200                 "packet forwarding, after sending <num> bursts of packets",
7201         .tokens = {
7202                 (void *)&cmd_start_tx_first_n_start,
7203                 (void *)&cmd_start_tx_first_n_tx_first,
7204                 (void *)&cmd_start_tx_first_n_tx_num,
7205                 NULL,
7206         },
7207 };
7208
7209 /* *** SET LINK UP *** */
7210 struct cmd_set_link_up_result {
7211         cmdline_fixed_string_t set;
7212         cmdline_fixed_string_t link_up;
7213         cmdline_fixed_string_t port;
7214         portid_t port_id;
7215 };
7216
7217 cmdline_parse_token_string_t cmd_set_link_up_set =
7218         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7219 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7221                                 "link-up");
7222 cmdline_parse_token_string_t cmd_set_link_up_port =
7223         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7224 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7225         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7226
7227 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7228                              __attribute__((unused)) struct cmdline *cl,
7229                              __attribute__((unused)) void *data)
7230 {
7231         struct cmd_set_link_up_result *res = parsed_result;
7232         dev_set_link_up(res->port_id);
7233 }
7234
7235 cmdline_parse_inst_t cmd_set_link_up = {
7236         .f = cmd_set_link_up_parsed,
7237         .data = NULL,
7238         .help_str = "set link-up port <port id>",
7239         .tokens = {
7240                 (void *)&cmd_set_link_up_set,
7241                 (void *)&cmd_set_link_up_link_up,
7242                 (void *)&cmd_set_link_up_port,
7243                 (void *)&cmd_set_link_up_port_id,
7244                 NULL,
7245         },
7246 };
7247
7248 /* *** SET LINK DOWN *** */
7249 struct cmd_set_link_down_result {
7250         cmdline_fixed_string_t set;
7251         cmdline_fixed_string_t link_down;
7252         cmdline_fixed_string_t port;
7253         portid_t port_id;
7254 };
7255
7256 cmdline_parse_token_string_t cmd_set_link_down_set =
7257         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7258 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7259         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7260                                 "link-down");
7261 cmdline_parse_token_string_t cmd_set_link_down_port =
7262         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7263 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7264         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7265
7266 static void cmd_set_link_down_parsed(
7267                                 __attribute__((unused)) void *parsed_result,
7268                                 __attribute__((unused)) struct cmdline *cl,
7269                                 __attribute__((unused)) void *data)
7270 {
7271         struct cmd_set_link_down_result *res = parsed_result;
7272         dev_set_link_down(res->port_id);
7273 }
7274
7275 cmdline_parse_inst_t cmd_set_link_down = {
7276         .f = cmd_set_link_down_parsed,
7277         .data = NULL,
7278         .help_str = "set link-down port <port id>",
7279         .tokens = {
7280                 (void *)&cmd_set_link_down_set,
7281                 (void *)&cmd_set_link_down_link_down,
7282                 (void *)&cmd_set_link_down_port,
7283                 (void *)&cmd_set_link_down_port_id,
7284                 NULL,
7285         },
7286 };
7287
7288 /* *** SHOW CFG *** */
7289 struct cmd_showcfg_result {
7290         cmdline_fixed_string_t show;
7291         cmdline_fixed_string_t cfg;
7292         cmdline_fixed_string_t what;
7293 };
7294
7295 static void cmd_showcfg_parsed(void *parsed_result,
7296                                __attribute__((unused)) struct cmdline *cl,
7297                                __attribute__((unused)) void *data)
7298 {
7299         struct cmd_showcfg_result *res = parsed_result;
7300         if (!strcmp(res->what, "rxtx"))
7301                 rxtx_config_display();
7302         else if (!strcmp(res->what, "cores"))
7303                 fwd_lcores_config_display();
7304         else if (!strcmp(res->what, "fwd"))
7305                 pkt_fwd_config_display(&cur_fwd_config);
7306         else if (!strcmp(res->what, "txpkts"))
7307                 show_tx_pkt_segments();
7308 }
7309
7310 cmdline_parse_token_string_t cmd_showcfg_show =
7311         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7312 cmdline_parse_token_string_t cmd_showcfg_port =
7313         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7314 cmdline_parse_token_string_t cmd_showcfg_what =
7315         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7316                                  "rxtx#cores#fwd#txpkts");
7317
7318 cmdline_parse_inst_t cmd_showcfg = {
7319         .f = cmd_showcfg_parsed,
7320         .data = NULL,
7321         .help_str = "show config rxtx|cores|fwd|txpkts",
7322         .tokens = {
7323                 (void *)&cmd_showcfg_show,
7324                 (void *)&cmd_showcfg_port,
7325                 (void *)&cmd_showcfg_what,
7326                 NULL,
7327         },
7328 };
7329
7330 /* *** SHOW ALL PORT INFO *** */
7331 struct cmd_showportall_result {
7332         cmdline_fixed_string_t show;
7333         cmdline_fixed_string_t port;
7334         cmdline_fixed_string_t what;
7335         cmdline_fixed_string_t all;
7336 };
7337
7338 static void cmd_showportall_parsed(void *parsed_result,
7339                                 __attribute__((unused)) struct cmdline *cl,
7340                                 __attribute__((unused)) void *data)
7341 {
7342         portid_t i;
7343
7344         struct cmd_showportall_result *res = parsed_result;
7345         if (!strcmp(res->show, "clear")) {
7346                 if (!strcmp(res->what, "stats"))
7347                         RTE_ETH_FOREACH_DEV(i)
7348                                 nic_stats_clear(i);
7349                 else if (!strcmp(res->what, "xstats"))
7350                         RTE_ETH_FOREACH_DEV(i)
7351                                 nic_xstats_clear(i);
7352         } else if (!strcmp(res->what, "info"))
7353                 RTE_ETH_FOREACH_DEV(i)
7354                         port_infos_display(i);
7355         else if (!strcmp(res->what, "summary")) {
7356                 port_summary_header_display();
7357                 RTE_ETH_FOREACH_DEV(i)
7358                         port_summary_display(i);
7359         }
7360         else if (!strcmp(res->what, "stats"))
7361                 RTE_ETH_FOREACH_DEV(i)
7362                         nic_stats_display(i);
7363         else if (!strcmp(res->what, "xstats"))
7364                 RTE_ETH_FOREACH_DEV(i)
7365                         nic_xstats_display(i);
7366         else if (!strcmp(res->what, "fdir"))
7367                 RTE_ETH_FOREACH_DEV(i)
7368                         fdir_get_infos(i);
7369         else if (!strcmp(res->what, "stat_qmap"))
7370                 RTE_ETH_FOREACH_DEV(i)
7371                         nic_stats_mapping_display(i);
7372         else if (!strcmp(res->what, "dcb_tc"))
7373                 RTE_ETH_FOREACH_DEV(i)
7374                         port_dcb_info_display(i);
7375         else if (!strcmp(res->what, "cap"))
7376                 RTE_ETH_FOREACH_DEV(i)
7377                         port_offload_cap_display(i);
7378 }
7379
7380 cmdline_parse_token_string_t cmd_showportall_show =
7381         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7382                                  "show#clear");
7383 cmdline_parse_token_string_t cmd_showportall_port =
7384         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7385 cmdline_parse_token_string_t cmd_showportall_what =
7386         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7387                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7388 cmdline_parse_token_string_t cmd_showportall_all =
7389         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7390 cmdline_parse_inst_t cmd_showportall = {
7391         .f = cmd_showportall_parsed,
7392         .data = NULL,
7393         .help_str = "show|clear port "
7394                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7395         .tokens = {
7396                 (void *)&cmd_showportall_show,
7397                 (void *)&cmd_showportall_port,
7398                 (void *)&cmd_showportall_what,
7399                 (void *)&cmd_showportall_all,
7400                 NULL,
7401         },
7402 };
7403
7404 /* *** SHOW PORT INFO *** */
7405 struct cmd_showport_result {
7406         cmdline_fixed_string_t show;
7407         cmdline_fixed_string_t port;
7408         cmdline_fixed_string_t what;
7409         uint16_t portnum;
7410 };
7411
7412 static void cmd_showport_parsed(void *parsed_result,
7413                                 __attribute__((unused)) struct cmdline *cl,
7414                                 __attribute__((unused)) void *data)
7415 {
7416         struct cmd_showport_result *res = parsed_result;
7417         if (!strcmp(res->show, "clear")) {
7418                 if (!strcmp(res->what, "stats"))
7419                         nic_stats_clear(res->portnum);
7420                 else if (!strcmp(res->what, "xstats"))
7421                         nic_xstats_clear(res->portnum);
7422         } else if (!strcmp(res->what, "info"))
7423                 port_infos_display(res->portnum);
7424         else if (!strcmp(res->what, "summary")) {
7425                 port_summary_header_display();
7426                 port_summary_display(res->portnum);
7427         }
7428         else if (!strcmp(res->what, "stats"))
7429                 nic_stats_display(res->portnum);
7430         else if (!strcmp(res->what, "xstats"))
7431                 nic_xstats_display(res->portnum);
7432         else if (!strcmp(res->what, "fdir"))
7433                  fdir_get_infos(res->portnum);
7434         else if (!strcmp(res->what, "stat_qmap"))
7435                 nic_stats_mapping_display(res->portnum);
7436         else if (!strcmp(res->what, "dcb_tc"))
7437                 port_dcb_info_display(res->portnum);
7438         else if (!strcmp(res->what, "cap"))
7439                 port_offload_cap_display(res->portnum);
7440 }
7441
7442 cmdline_parse_token_string_t cmd_showport_show =
7443         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7444                                  "show#clear");
7445 cmdline_parse_token_string_t cmd_showport_port =
7446         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7447 cmdline_parse_token_string_t cmd_showport_what =
7448         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7449                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7450 cmdline_parse_token_num_t cmd_showport_portnum =
7451         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7452
7453 cmdline_parse_inst_t cmd_showport = {
7454         .f = cmd_showport_parsed,
7455         .data = NULL,
7456         .help_str = "show|clear port "
7457                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7458                 "<port_id>",
7459         .tokens = {
7460                 (void *)&cmd_showport_show,
7461                 (void *)&cmd_showport_port,
7462                 (void *)&cmd_showport_what,
7463                 (void *)&cmd_showport_portnum,
7464                 NULL,
7465         },
7466 };
7467
7468 /* *** SHOW DEVICE INFO *** */
7469 struct cmd_showdevice_result {
7470         cmdline_fixed_string_t show;
7471         cmdline_fixed_string_t device;
7472         cmdline_fixed_string_t what;
7473         cmdline_fixed_string_t identifier;
7474 };
7475
7476 static void cmd_showdevice_parsed(void *parsed_result,
7477                                 __attribute__((unused)) struct cmdline *cl,
7478                                 __attribute__((unused)) void *data)
7479 {
7480         struct cmd_showdevice_result *res = parsed_result;
7481         if (!strcmp(res->what, "info")) {
7482                 if (!strcmp(res->identifier, "all"))
7483                         device_infos_display(NULL);
7484                 else
7485                         device_infos_display(res->identifier);
7486         }
7487 }
7488
7489 cmdline_parse_token_string_t cmd_showdevice_show =
7490         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7491                                  "show");
7492 cmdline_parse_token_string_t cmd_showdevice_device =
7493         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7494 cmdline_parse_token_string_t cmd_showdevice_what =
7495         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7496                                  "info");
7497 cmdline_parse_token_string_t cmd_showdevice_identifier =
7498         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7499                         identifier, NULL);
7500
7501 cmdline_parse_inst_t cmd_showdevice = {
7502         .f = cmd_showdevice_parsed,
7503         .data = NULL,
7504         .help_str = "show device info <identifier>|all",
7505         .tokens = {
7506                 (void *)&cmd_showdevice_show,
7507                 (void *)&cmd_showdevice_device,
7508                 (void *)&cmd_showdevice_what,
7509                 (void *)&cmd_showdevice_identifier,
7510                 NULL,
7511         },
7512 };
7513 /* *** SHOW QUEUE INFO *** */
7514 struct cmd_showqueue_result {
7515         cmdline_fixed_string_t show;
7516         cmdline_fixed_string_t type;
7517         cmdline_fixed_string_t what;
7518         uint16_t portnum;
7519         uint16_t queuenum;
7520 };
7521
7522 static void
7523 cmd_showqueue_parsed(void *parsed_result,
7524         __attribute__((unused)) struct cmdline *cl,
7525         __attribute__((unused)) void *data)
7526 {
7527         struct cmd_showqueue_result *res = parsed_result;
7528
7529         if (!strcmp(res->type, "rxq"))
7530                 rx_queue_infos_display(res->portnum, res->queuenum);
7531         else if (!strcmp(res->type, "txq"))
7532                 tx_queue_infos_display(res->portnum, res->queuenum);
7533 }
7534
7535 cmdline_parse_token_string_t cmd_showqueue_show =
7536         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7537 cmdline_parse_token_string_t cmd_showqueue_type =
7538         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7539 cmdline_parse_token_string_t cmd_showqueue_what =
7540         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7541 cmdline_parse_token_num_t cmd_showqueue_portnum =
7542         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7543 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7544         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7545
7546 cmdline_parse_inst_t cmd_showqueue = {
7547         .f = cmd_showqueue_parsed,
7548         .data = NULL,
7549         .help_str = "show rxq|txq info <port_id> <queue_id>",
7550         .tokens = {
7551                 (void *)&cmd_showqueue_show,
7552                 (void *)&cmd_showqueue_type,
7553                 (void *)&cmd_showqueue_what,
7554                 (void *)&cmd_showqueue_portnum,
7555                 (void *)&cmd_showqueue_queuenum,
7556                 NULL,
7557         },
7558 };
7559
7560 /* show/clear fwd engine statistics */
7561 struct fwd_result {
7562         cmdline_fixed_string_t action;
7563         cmdline_fixed_string_t fwd;
7564         cmdline_fixed_string_t stats;
7565         cmdline_fixed_string_t all;
7566 };
7567
7568 cmdline_parse_token_string_t cmd_fwd_action =
7569         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7570 cmdline_parse_token_string_t cmd_fwd_fwd =
7571         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7572 cmdline_parse_token_string_t cmd_fwd_stats =
7573         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7574 cmdline_parse_token_string_t cmd_fwd_all =
7575         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7576
7577 static void
7578 cmd_showfwdall_parsed(void *parsed_result,
7579                       __rte_unused struct cmdline *cl,
7580                       __rte_unused void *data)
7581 {
7582         struct fwd_result *res = parsed_result;
7583
7584         if (!strcmp(res->action, "show"))
7585                 fwd_stats_display();
7586         else
7587                 fwd_stats_reset();
7588 }
7589
7590 static cmdline_parse_inst_t cmd_showfwdall = {
7591         .f = cmd_showfwdall_parsed,
7592         .data = NULL,
7593         .help_str = "show|clear fwd stats all",
7594         .tokens = {
7595                 (void *)&cmd_fwd_action,
7596                 (void *)&cmd_fwd_fwd,
7597                 (void *)&cmd_fwd_stats,
7598                 (void *)&cmd_fwd_all,
7599                 NULL,
7600         },
7601 };
7602
7603 /* *** READ PORT REGISTER *** */
7604 struct cmd_read_reg_result {
7605         cmdline_fixed_string_t read;
7606         cmdline_fixed_string_t reg;
7607         portid_t port_id;
7608         uint32_t reg_off;
7609 };
7610
7611 static void
7612 cmd_read_reg_parsed(void *parsed_result,
7613                     __attribute__((unused)) struct cmdline *cl,
7614                     __attribute__((unused)) void *data)
7615 {
7616         struct cmd_read_reg_result *res = parsed_result;
7617         port_reg_display(res->port_id, res->reg_off);
7618 }
7619
7620 cmdline_parse_token_string_t cmd_read_reg_read =
7621         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7622 cmdline_parse_token_string_t cmd_read_reg_reg =
7623         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7624 cmdline_parse_token_num_t cmd_read_reg_port_id =
7625         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7626 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7627         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7628
7629 cmdline_parse_inst_t cmd_read_reg = {
7630         .f = cmd_read_reg_parsed,
7631         .data = NULL,
7632         .help_str = "read reg <port_id> <reg_off>",
7633         .tokens = {
7634                 (void *)&cmd_read_reg_read,
7635                 (void *)&cmd_read_reg_reg,
7636                 (void *)&cmd_read_reg_port_id,
7637                 (void *)&cmd_read_reg_reg_off,
7638                 NULL,
7639         },
7640 };
7641
7642 /* *** READ PORT REGISTER BIT FIELD *** */
7643 struct cmd_read_reg_bit_field_result {
7644         cmdline_fixed_string_t read;
7645         cmdline_fixed_string_t regfield;
7646         portid_t port_id;
7647         uint32_t reg_off;
7648         uint8_t bit1_pos;
7649         uint8_t bit2_pos;
7650 };
7651
7652 static void
7653 cmd_read_reg_bit_field_parsed(void *parsed_result,
7654                               __attribute__((unused)) struct cmdline *cl,
7655                               __attribute__((unused)) void *data)
7656 {
7657         struct cmd_read_reg_bit_field_result *res = parsed_result;
7658         port_reg_bit_field_display(res->port_id, res->reg_off,
7659                                    res->bit1_pos, res->bit2_pos);
7660 }
7661
7662 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7663         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7664                                  "read");
7665 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7666         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7667                                  regfield, "regfield");
7668 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7669         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7670                               UINT16);
7671 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7672         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7673                               UINT32);
7674 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7675         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7676                               UINT8);
7677 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7678         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7679                               UINT8);
7680
7681 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7682         .f = cmd_read_reg_bit_field_parsed,
7683         .data = NULL,
7684         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7685         "Read register bit field between bit_x and bit_y included",
7686         .tokens = {
7687                 (void *)&cmd_read_reg_bit_field_read,
7688                 (void *)&cmd_read_reg_bit_field_regfield,
7689                 (void *)&cmd_read_reg_bit_field_port_id,
7690                 (void *)&cmd_read_reg_bit_field_reg_off,
7691                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7692                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7693                 NULL,
7694         },
7695 };
7696
7697 /* *** READ PORT REGISTER BIT *** */
7698 struct cmd_read_reg_bit_result {
7699         cmdline_fixed_string_t read;
7700         cmdline_fixed_string_t regbit;
7701         portid_t port_id;
7702         uint32_t reg_off;
7703         uint8_t bit_pos;
7704 };
7705
7706 static void
7707 cmd_read_reg_bit_parsed(void *parsed_result,
7708                         __attribute__((unused)) struct cmdline *cl,
7709                         __attribute__((unused)) void *data)
7710 {
7711         struct cmd_read_reg_bit_result *res = parsed_result;
7712         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7713 }
7714
7715 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7716         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7717 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7718         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7719                                  regbit, "regbit");
7720 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7721         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7722 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7723         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7724 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7725         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7726
7727 cmdline_parse_inst_t cmd_read_reg_bit = {
7728         .f = cmd_read_reg_bit_parsed,
7729         .data = NULL,
7730         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7731         .tokens = {
7732                 (void *)&cmd_read_reg_bit_read,
7733                 (void *)&cmd_read_reg_bit_regbit,
7734                 (void *)&cmd_read_reg_bit_port_id,
7735                 (void *)&cmd_read_reg_bit_reg_off,
7736                 (void *)&cmd_read_reg_bit_bit_pos,
7737                 NULL,
7738         },
7739 };
7740
7741 /* *** WRITE PORT REGISTER *** */
7742 struct cmd_write_reg_result {
7743         cmdline_fixed_string_t write;
7744         cmdline_fixed_string_t reg;
7745         portid_t port_id;
7746         uint32_t reg_off;
7747         uint32_t value;
7748 };
7749
7750 static void
7751 cmd_write_reg_parsed(void *parsed_result,
7752                      __attribute__((unused)) struct cmdline *cl,
7753                      __attribute__((unused)) void *data)
7754 {
7755         struct cmd_write_reg_result *res = parsed_result;
7756         port_reg_set(res->port_id, res->reg_off, res->value);
7757 }
7758
7759 cmdline_parse_token_string_t cmd_write_reg_write =
7760         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7761 cmdline_parse_token_string_t cmd_write_reg_reg =
7762         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7763 cmdline_parse_token_num_t cmd_write_reg_port_id =
7764         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7765 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7766         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7767 cmdline_parse_token_num_t cmd_write_reg_value =
7768         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7769
7770 cmdline_parse_inst_t cmd_write_reg = {
7771         .f = cmd_write_reg_parsed,
7772         .data = NULL,
7773         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7774         .tokens = {
7775                 (void *)&cmd_write_reg_write,
7776                 (void *)&cmd_write_reg_reg,
7777                 (void *)&cmd_write_reg_port_id,
7778                 (void *)&cmd_write_reg_reg_off,
7779                 (void *)&cmd_write_reg_value,
7780                 NULL,
7781         },
7782 };
7783
7784 /* *** WRITE PORT REGISTER BIT FIELD *** */
7785 struct cmd_write_reg_bit_field_result {
7786         cmdline_fixed_string_t write;
7787         cmdline_fixed_string_t regfield;
7788         portid_t port_id;
7789         uint32_t reg_off;
7790         uint8_t bit1_pos;
7791         uint8_t bit2_pos;
7792         uint32_t value;
7793 };
7794
7795 static void
7796 cmd_write_reg_bit_field_parsed(void *parsed_result,
7797                                __attribute__((unused)) struct cmdline *cl,
7798                                __attribute__((unused)) void *data)
7799 {
7800         struct cmd_write_reg_bit_field_result *res = parsed_result;
7801         port_reg_bit_field_set(res->port_id, res->reg_off,
7802                           res->bit1_pos, res->bit2_pos, res->value);
7803 }
7804
7805 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7806         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7807                                  "write");
7808 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7809         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7810                                  regfield, "regfield");
7811 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7812         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7813                               UINT16);
7814 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7815         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7816                               UINT32);
7817 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7818         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7819                               UINT8);
7820 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7821         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7822                               UINT8);
7823 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7824         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7825                               UINT32);
7826
7827 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7828         .f = cmd_write_reg_bit_field_parsed,
7829         .data = NULL,
7830         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7831                 "<reg_value>: "
7832                 "Set register bit field between bit_x and bit_y included",
7833         .tokens = {
7834                 (void *)&cmd_write_reg_bit_field_write,
7835                 (void *)&cmd_write_reg_bit_field_regfield,
7836                 (void *)&cmd_write_reg_bit_field_port_id,
7837                 (void *)&cmd_write_reg_bit_field_reg_off,
7838                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7839                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7840                 (void *)&cmd_write_reg_bit_field_value,
7841                 NULL,
7842         },
7843 };
7844
7845 /* *** WRITE PORT REGISTER BIT *** */
7846 struct cmd_write_reg_bit_result {
7847         cmdline_fixed_string_t write;
7848         cmdline_fixed_string_t regbit;
7849         portid_t port_id;
7850         uint32_t reg_off;
7851         uint8_t bit_pos;
7852         uint8_t value;
7853 };
7854
7855 static void
7856 cmd_write_reg_bit_parsed(void *parsed_result,
7857                          __attribute__((unused)) struct cmdline *cl,
7858                          __attribute__((unused)) void *data)
7859 {
7860         struct cmd_write_reg_bit_result *res = parsed_result;
7861         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7862 }
7863
7864 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7865         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7866                                  "write");
7867 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7868         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7869                                  regbit, "regbit");
7870 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7871         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7872 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7873         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7874 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7875         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7876 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7877         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7878
7879 cmdline_parse_inst_t cmd_write_reg_bit = {
7880         .f = cmd_write_reg_bit_parsed,
7881         .data = NULL,
7882         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7883                 "0 <= bit_x <= 31",
7884         .tokens = {
7885                 (void *)&cmd_write_reg_bit_write,
7886                 (void *)&cmd_write_reg_bit_regbit,
7887                 (void *)&cmd_write_reg_bit_port_id,
7888                 (void *)&cmd_write_reg_bit_reg_off,
7889                 (void *)&cmd_write_reg_bit_bit_pos,
7890                 (void *)&cmd_write_reg_bit_value,
7891                 NULL,
7892         },
7893 };
7894
7895 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7896 struct cmd_read_rxd_txd_result {
7897         cmdline_fixed_string_t read;
7898         cmdline_fixed_string_t rxd_txd;
7899         portid_t port_id;
7900         uint16_t queue_id;
7901         uint16_t desc_id;
7902 };
7903
7904 static void
7905 cmd_read_rxd_txd_parsed(void *parsed_result,
7906                         __attribute__((unused)) struct cmdline *cl,
7907                         __attribute__((unused)) void *data)
7908 {
7909         struct cmd_read_rxd_txd_result *res = parsed_result;
7910
7911         if (!strcmp(res->rxd_txd, "rxd"))
7912                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7913         else if (!strcmp(res->rxd_txd, "txd"))
7914                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7915 }
7916
7917 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7918         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7919 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7920         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7921                                  "rxd#txd");
7922 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7923         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7924 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7925         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7926 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7927         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7928
7929 cmdline_parse_inst_t cmd_read_rxd_txd = {
7930         .f = cmd_read_rxd_txd_parsed,
7931         .data = NULL,
7932         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7933         .tokens = {
7934                 (void *)&cmd_read_rxd_txd_read,
7935                 (void *)&cmd_read_rxd_txd_rxd_txd,
7936                 (void *)&cmd_read_rxd_txd_port_id,
7937                 (void *)&cmd_read_rxd_txd_queue_id,
7938                 (void *)&cmd_read_rxd_txd_desc_id,
7939                 NULL,
7940         },
7941 };
7942
7943 /* *** QUIT *** */
7944 struct cmd_quit_result {
7945         cmdline_fixed_string_t quit;
7946 };
7947
7948 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7949                             struct cmdline *cl,
7950                             __attribute__((unused)) void *data)
7951 {
7952         cmdline_quit(cl);
7953 }
7954
7955 cmdline_parse_token_string_t cmd_quit_quit =
7956         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7957
7958 cmdline_parse_inst_t cmd_quit = {
7959         .f = cmd_quit_parsed,
7960         .data = NULL,
7961         .help_str = "quit: Exit application",
7962         .tokens = {
7963                 (void *)&cmd_quit_quit,
7964                 NULL,
7965         },
7966 };
7967
7968 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7969 struct cmd_mac_addr_result {
7970         cmdline_fixed_string_t mac_addr_cmd;
7971         cmdline_fixed_string_t what;
7972         uint16_t port_num;
7973         struct rte_ether_addr address;
7974 };
7975
7976 static void cmd_mac_addr_parsed(void *parsed_result,
7977                 __attribute__((unused)) struct cmdline *cl,
7978                 __attribute__((unused)) void *data)
7979 {
7980         struct cmd_mac_addr_result *res = parsed_result;
7981         int ret;
7982
7983         if (strcmp(res->what, "add") == 0)
7984                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7985         else if (strcmp(res->what, "set") == 0)
7986                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7987                                                        &res->address);
7988         else
7989                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7990
7991         /* check the return value and print it if is < 0 */
7992         if(ret < 0)
7993                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7994
7995 }
7996
7997 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7998         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7999                                 "mac_addr");
8000 cmdline_parse_token_string_t cmd_mac_addr_what =
8001         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8002                                 "add#remove#set");
8003 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8004                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8005                                         UINT16);
8006 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8007                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8008
8009 cmdline_parse_inst_t cmd_mac_addr = {
8010         .f = cmd_mac_addr_parsed,
8011         .data = (void *)0,
8012         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8013                         "Add/Remove/Set MAC address on port_id",
8014         .tokens = {
8015                 (void *)&cmd_mac_addr_cmd,
8016                 (void *)&cmd_mac_addr_what,
8017                 (void *)&cmd_mac_addr_portnum,
8018                 (void *)&cmd_mac_addr_addr,
8019                 NULL,
8020         },
8021 };
8022
8023 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8024 struct cmd_eth_peer_result {
8025         cmdline_fixed_string_t set;
8026         cmdline_fixed_string_t eth_peer;
8027         portid_t port_id;
8028         cmdline_fixed_string_t peer_addr;
8029 };
8030
8031 static void cmd_set_eth_peer_parsed(void *parsed_result,
8032                         __attribute__((unused)) struct cmdline *cl,
8033                         __attribute__((unused)) void *data)
8034 {
8035                 struct cmd_eth_peer_result *res = parsed_result;
8036
8037                 if (test_done == 0) {
8038                         printf("Please stop forwarding first\n");
8039                         return;
8040                 }
8041                 if (!strcmp(res->eth_peer, "eth-peer")) {
8042                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8043                         fwd_config_setup();
8044                 }
8045 }
8046 cmdline_parse_token_string_t cmd_eth_peer_set =
8047         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8048 cmdline_parse_token_string_t cmd_eth_peer =
8049         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8050 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8051         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8052 cmdline_parse_token_string_t cmd_eth_peer_addr =
8053         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8054
8055 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8056         .f = cmd_set_eth_peer_parsed,
8057         .data = NULL,
8058         .help_str = "set eth-peer <port_id> <peer_mac>",
8059         .tokens = {
8060                 (void *)&cmd_eth_peer_set,
8061                 (void *)&cmd_eth_peer,
8062                 (void *)&cmd_eth_peer_port_id,
8063                 (void *)&cmd_eth_peer_addr,
8064                 NULL,
8065         },
8066 };
8067
8068 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8069 struct cmd_set_qmap_result {
8070         cmdline_fixed_string_t set;
8071         cmdline_fixed_string_t qmap;
8072         cmdline_fixed_string_t what;
8073         portid_t port_id;
8074         uint16_t queue_id;
8075         uint8_t map_value;
8076 };
8077
8078 static void
8079 cmd_set_qmap_parsed(void *parsed_result,
8080                        __attribute__((unused)) struct cmdline *cl,
8081                        __attribute__((unused)) void *data)
8082 {
8083         struct cmd_set_qmap_result *res = parsed_result;
8084         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8085
8086         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8087 }
8088
8089 cmdline_parse_token_string_t cmd_setqmap_set =
8090         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8091                                  set, "set");
8092 cmdline_parse_token_string_t cmd_setqmap_qmap =
8093         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8094                                  qmap, "stat_qmap");
8095 cmdline_parse_token_string_t cmd_setqmap_what =
8096         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8097                                  what, "tx#rx");
8098 cmdline_parse_token_num_t cmd_setqmap_portid =
8099         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8100                               port_id, UINT16);
8101 cmdline_parse_token_num_t cmd_setqmap_queueid =
8102         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8103                               queue_id, UINT16);
8104 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8105         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8106                               map_value, UINT8);
8107
8108 cmdline_parse_inst_t cmd_set_qmap = {
8109         .f = cmd_set_qmap_parsed,
8110         .data = NULL,
8111         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8112                 "Set statistics mapping value on tx|rx queue_id of port_id",
8113         .tokens = {
8114                 (void *)&cmd_setqmap_set,
8115                 (void *)&cmd_setqmap_qmap,
8116                 (void *)&cmd_setqmap_what,
8117                 (void *)&cmd_setqmap_portid,
8118                 (void *)&cmd_setqmap_queueid,
8119                 (void *)&cmd_setqmap_mapvalue,
8120                 NULL,
8121         },
8122 };
8123
8124 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8125 struct cmd_set_xstats_hide_zero_result {
8126         cmdline_fixed_string_t keyword;
8127         cmdline_fixed_string_t name;
8128         cmdline_fixed_string_t on_off;
8129 };
8130
8131 static void
8132 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8133                         __attribute__((unused)) struct cmdline *cl,
8134                         __attribute__((unused)) void *data)
8135 {
8136         struct cmd_set_xstats_hide_zero_result *res;
8137         uint16_t on_off = 0;
8138
8139         res = parsed_result;
8140         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8141         set_xstats_hide_zero(on_off);
8142 }
8143
8144 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8145         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8146                                  keyword, "set");
8147 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8148         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8149                                  name, "xstats-hide-zero");
8150 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8151         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8152                                  on_off, "on#off");
8153
8154 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8155         .f = cmd_set_xstats_hide_zero_parsed,
8156         .data = NULL,
8157         .help_str = "set xstats-hide-zero on|off",
8158         .tokens = {
8159                 (void *)&cmd_set_xstats_hide_zero_keyword,
8160                 (void *)&cmd_set_xstats_hide_zero_name,
8161                 (void *)&cmd_set_xstats_hide_zero_on_off,
8162                 NULL,
8163         },
8164 };
8165
8166 /* *** CONFIGURE UNICAST HASH TABLE *** */
8167 struct cmd_set_uc_hash_table {
8168         cmdline_fixed_string_t set;
8169         cmdline_fixed_string_t port;
8170         portid_t port_id;
8171         cmdline_fixed_string_t what;
8172         struct rte_ether_addr address;
8173         cmdline_fixed_string_t mode;
8174 };
8175
8176 static void
8177 cmd_set_uc_hash_parsed(void *parsed_result,
8178                        __attribute__((unused)) struct cmdline *cl,
8179                        __attribute__((unused)) void *data)
8180 {
8181         int ret=0;
8182         struct cmd_set_uc_hash_table *res = parsed_result;
8183
8184         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8185
8186         if (strcmp(res->what, "uta") == 0)
8187                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8188                                                 &res->address,(uint8_t)is_on);
8189         if (ret < 0)
8190                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8191
8192 }
8193
8194 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8195         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8196                                  set, "set");
8197 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8198         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8199                                  port, "port");
8200 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8201         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8202                               port_id, UINT16);
8203 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8204         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8205                                  what, "uta");
8206 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8207         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8208                                 address);
8209 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8210         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8211                                  mode, "on#off");
8212
8213 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8214         .f = cmd_set_uc_hash_parsed,
8215         .data = NULL,
8216         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8217         .tokens = {
8218                 (void *)&cmd_set_uc_hash_set,
8219                 (void *)&cmd_set_uc_hash_port,
8220                 (void *)&cmd_set_uc_hash_portid,
8221                 (void *)&cmd_set_uc_hash_what,
8222                 (void *)&cmd_set_uc_hash_mac,
8223                 (void *)&cmd_set_uc_hash_mode,
8224                 NULL,
8225         },
8226 };
8227
8228 struct cmd_set_uc_all_hash_table {
8229         cmdline_fixed_string_t set;
8230         cmdline_fixed_string_t port;
8231         portid_t port_id;
8232         cmdline_fixed_string_t what;
8233         cmdline_fixed_string_t value;
8234         cmdline_fixed_string_t mode;
8235 };
8236
8237 static void
8238 cmd_set_uc_all_hash_parsed(void *parsed_result,
8239                        __attribute__((unused)) struct cmdline *cl,
8240                        __attribute__((unused)) void *data)
8241 {
8242         int ret=0;
8243         struct cmd_set_uc_all_hash_table *res = parsed_result;
8244
8245         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8246
8247         if ((strcmp(res->what, "uta") == 0) &&
8248                 (strcmp(res->value, "all") == 0))
8249                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8250         if (ret < 0)
8251                 printf("bad unicast hash table parameter,"
8252                         "return code = %d \n", ret);
8253 }
8254
8255 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8256         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8257                                  set, "set");
8258 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8259         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8260                                  port, "port");
8261 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8262         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8263                               port_id, UINT16);
8264 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8265         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8266                                  what, "uta");
8267 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8268         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8269                                 value,"all");
8270 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8271         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8272                                  mode, "on#off");
8273
8274 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8275         .f = cmd_set_uc_all_hash_parsed,
8276         .data = NULL,
8277         .help_str = "set port <port_id> uta all on|off",
8278         .tokens = {
8279                 (void *)&cmd_set_uc_all_hash_set,
8280                 (void *)&cmd_set_uc_all_hash_port,
8281                 (void *)&cmd_set_uc_all_hash_portid,
8282                 (void *)&cmd_set_uc_all_hash_what,
8283                 (void *)&cmd_set_uc_all_hash_value,
8284                 (void *)&cmd_set_uc_all_hash_mode,
8285                 NULL,
8286         },
8287 };
8288
8289 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8290 struct cmd_set_vf_macvlan_filter {
8291         cmdline_fixed_string_t set;
8292         cmdline_fixed_string_t port;
8293         portid_t port_id;
8294         cmdline_fixed_string_t vf;
8295         uint8_t vf_id;
8296         struct rte_ether_addr address;
8297         cmdline_fixed_string_t filter_type;
8298         cmdline_fixed_string_t mode;
8299 };
8300
8301 static void
8302 cmd_set_vf_macvlan_parsed(void *parsed_result,
8303                        __attribute__((unused)) struct cmdline *cl,
8304                        __attribute__((unused)) void *data)
8305 {
8306         int is_on, ret = 0;
8307         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8308         struct rte_eth_mac_filter filter;
8309
8310         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8311
8312         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8313
8314         /* set VF MAC filter */
8315         filter.is_vf = 1;
8316
8317         /* set VF ID */
8318         filter.dst_id = res->vf_id;
8319
8320         if (!strcmp(res->filter_type, "exact-mac"))
8321                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8322         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8323                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8324         else if (!strcmp(res->filter_type, "hashmac"))
8325                 filter.filter_type = RTE_MAC_HASH_MATCH;
8326         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8327                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8328
8329         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8330
8331         if (is_on)
8332                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8333                                         RTE_ETH_FILTER_MACVLAN,
8334                                         RTE_ETH_FILTER_ADD,
8335                                          &filter);
8336         else
8337                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8338                                         RTE_ETH_FILTER_MACVLAN,
8339                                         RTE_ETH_FILTER_DELETE,
8340                                         &filter);
8341
8342         if (ret < 0)
8343                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8344
8345 }
8346
8347 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8348         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8349                                  set, "set");
8350 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8351         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8352                                  port, "port");
8353 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8354         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8355                               port_id, UINT16);
8356 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8357         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8358                                  vf, "vf");
8359 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8360         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8361                                 vf_id, UINT8);
8362 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8363         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8364                                 address);
8365 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8366         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8367                                 filter_type, "exact-mac#exact-mac-vlan"
8368                                 "#hashmac#hashmac-vlan");
8369 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8370         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8371                                  mode, "on#off");
8372
8373 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8374         .f = cmd_set_vf_macvlan_parsed,
8375         .data = NULL,
8376         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8377                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8378                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8379                 "hash match rule: hash match of MAC and exact match of VLAN",
8380         .tokens = {
8381                 (void *)&cmd_set_vf_macvlan_set,
8382                 (void *)&cmd_set_vf_macvlan_port,
8383                 (void *)&cmd_set_vf_macvlan_portid,
8384                 (void *)&cmd_set_vf_macvlan_vf,
8385                 (void *)&cmd_set_vf_macvlan_vf_id,
8386                 (void *)&cmd_set_vf_macvlan_mac,
8387                 (void *)&cmd_set_vf_macvlan_filter_type,
8388                 (void *)&cmd_set_vf_macvlan_mode,
8389                 NULL,
8390         },
8391 };
8392
8393 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8394 struct cmd_set_vf_traffic {
8395         cmdline_fixed_string_t set;
8396         cmdline_fixed_string_t port;
8397         portid_t port_id;
8398         cmdline_fixed_string_t vf;
8399         uint8_t vf_id;
8400         cmdline_fixed_string_t what;
8401         cmdline_fixed_string_t mode;
8402 };
8403
8404 static void
8405 cmd_set_vf_traffic_parsed(void *parsed_result,
8406                        __attribute__((unused)) struct cmdline *cl,
8407                        __attribute__((unused)) void *data)
8408 {
8409         struct cmd_set_vf_traffic *res = parsed_result;
8410         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8411         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8412
8413         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8414 }
8415
8416 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8417         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8418                                  set, "set");
8419 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8420         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8421                                  port, "port");
8422 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8423         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8424                               port_id, UINT16);
8425 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8426         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8427                                  vf, "vf");
8428 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8429         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8430                               vf_id, UINT8);
8431 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8432         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8433                                  what, "tx#rx");
8434 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8435         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8436                                  mode, "on#off");
8437
8438 cmdline_parse_inst_t cmd_set_vf_traffic = {
8439         .f = cmd_set_vf_traffic_parsed,
8440         .data = NULL,
8441         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8442         .tokens = {
8443                 (void *)&cmd_setvf_traffic_set,
8444                 (void *)&cmd_setvf_traffic_port,
8445                 (void *)&cmd_setvf_traffic_portid,
8446                 (void *)&cmd_setvf_traffic_vf,
8447                 (void *)&cmd_setvf_traffic_vfid,
8448                 (void *)&cmd_setvf_traffic_what,
8449                 (void *)&cmd_setvf_traffic_mode,
8450                 NULL,
8451         },
8452 };
8453
8454 /* *** CONFIGURE VF RECEIVE MODE *** */
8455 struct cmd_set_vf_rxmode {
8456         cmdline_fixed_string_t set;
8457         cmdline_fixed_string_t port;
8458         portid_t port_id;
8459         cmdline_fixed_string_t vf;
8460         uint8_t vf_id;
8461         cmdline_fixed_string_t what;
8462         cmdline_fixed_string_t mode;
8463         cmdline_fixed_string_t on;
8464 };
8465
8466 static void
8467 cmd_set_vf_rxmode_parsed(void *parsed_result,
8468                        __attribute__((unused)) struct cmdline *cl,
8469                        __attribute__((unused)) void *data)
8470 {
8471         int ret = -ENOTSUP;
8472         uint16_t vf_rxmode = 0;
8473         struct cmd_set_vf_rxmode *res = parsed_result;
8474
8475         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8476         if (!strcmp(res->what,"rxmode")) {
8477                 if (!strcmp(res->mode, "AUPE"))
8478                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8479                 else if (!strcmp(res->mode, "ROPE"))
8480                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8481                 else if (!strcmp(res->mode, "BAM"))
8482                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8483                 else if (!strncmp(res->mode, "MPE",3))
8484                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8485         }
8486
8487         RTE_SET_USED(is_on);
8488
8489 #ifdef RTE_LIBRTE_IXGBE_PMD
8490         if (ret == -ENOTSUP)
8491                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8492                                                   vf_rxmode, (uint8_t)is_on);
8493 #endif
8494 #ifdef RTE_LIBRTE_BNXT_PMD
8495         if (ret == -ENOTSUP)
8496                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8497                                                  vf_rxmode, (uint8_t)is_on);
8498 #endif
8499         if (ret < 0)
8500                 printf("bad VF receive mode parameter, return code = %d \n",
8501                 ret);
8502 }
8503
8504 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8505         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8506                                  set, "set");
8507 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8508         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8509                                  port, "port");
8510 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8511         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8512                               port_id, UINT16);
8513 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8514         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8515                                  vf, "vf");
8516 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8517         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8518                               vf_id, UINT8);
8519 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8521                                  what, "rxmode");
8522 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8523         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8524                                  mode, "AUPE#ROPE#BAM#MPE");
8525 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8526         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8527                                  on, "on#off");
8528
8529 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8530         .f = cmd_set_vf_rxmode_parsed,
8531         .data = NULL,
8532         .help_str = "set port <port_id> vf <vf_id> rxmode "
8533                 "AUPE|ROPE|BAM|MPE on|off",
8534         .tokens = {
8535                 (void *)&cmd_set_vf_rxmode_set,
8536                 (void *)&cmd_set_vf_rxmode_port,
8537                 (void *)&cmd_set_vf_rxmode_portid,
8538                 (void *)&cmd_set_vf_rxmode_vf,
8539                 (void *)&cmd_set_vf_rxmode_vfid,
8540                 (void *)&cmd_set_vf_rxmode_what,
8541                 (void *)&cmd_set_vf_rxmode_mode,
8542                 (void *)&cmd_set_vf_rxmode_on,
8543                 NULL,
8544         },
8545 };
8546
8547 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8548 struct cmd_vf_mac_addr_result {
8549         cmdline_fixed_string_t mac_addr_cmd;
8550         cmdline_fixed_string_t what;
8551         cmdline_fixed_string_t port;
8552         uint16_t port_num;
8553         cmdline_fixed_string_t vf;
8554         uint8_t vf_num;
8555         struct rte_ether_addr address;
8556 };
8557
8558 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8559                 __attribute__((unused)) struct cmdline *cl,
8560                 __attribute__((unused)) void *data)
8561 {
8562         struct cmd_vf_mac_addr_result *res = parsed_result;
8563         int ret = -ENOTSUP;
8564
8565         if (strcmp(res->what, "add") != 0)
8566                 return;
8567
8568 #ifdef RTE_LIBRTE_I40E_PMD
8569         if (ret == -ENOTSUP)
8570                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8571                                                    &res->address);
8572 #endif
8573 #ifdef RTE_LIBRTE_BNXT_PMD
8574         if (ret == -ENOTSUP)
8575                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8576                                                 res->vf_num);
8577 #endif
8578
8579         if(ret < 0)
8580                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8581
8582 }
8583
8584 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8585         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8586                                 mac_addr_cmd,"mac_addr");
8587 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8588         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8589                                 what,"add");
8590 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8591         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8592                                 port,"port");
8593 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8594         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8595                                 port_num, UINT16);
8596 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8597         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8598                                 vf,"vf");
8599 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8600         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8601                                 vf_num, UINT8);
8602 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8603         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8604                                 address);
8605
8606 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8607         .f = cmd_vf_mac_addr_parsed,
8608         .data = (void *)0,
8609         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8610                 "Add MAC address filtering for a VF on port_id",
8611         .tokens = {
8612                 (void *)&cmd_vf_mac_addr_cmd,
8613                 (void *)&cmd_vf_mac_addr_what,
8614                 (void *)&cmd_vf_mac_addr_port,
8615                 (void *)&cmd_vf_mac_addr_portnum,
8616                 (void *)&cmd_vf_mac_addr_vf,
8617                 (void *)&cmd_vf_mac_addr_vfnum,
8618                 (void *)&cmd_vf_mac_addr_addr,
8619                 NULL,
8620         },
8621 };
8622
8623 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8624 struct cmd_vf_rx_vlan_filter {
8625         cmdline_fixed_string_t rx_vlan;
8626         cmdline_fixed_string_t what;
8627         uint16_t vlan_id;
8628         cmdline_fixed_string_t port;
8629         portid_t port_id;
8630         cmdline_fixed_string_t vf;
8631         uint64_t vf_mask;
8632 };
8633
8634 static void
8635 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8636                           __attribute__((unused)) struct cmdline *cl,
8637                           __attribute__((unused)) void *data)
8638 {
8639         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8640         int ret = -ENOTSUP;
8641
8642         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8643
8644 #ifdef RTE_LIBRTE_IXGBE_PMD
8645         if (ret == -ENOTSUP)
8646                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8647                                 res->vlan_id, res->vf_mask, is_add);
8648 #endif
8649 #ifdef RTE_LIBRTE_I40E_PMD
8650         if (ret == -ENOTSUP)
8651                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8652                                 res->vlan_id, res->vf_mask, is_add);
8653 #endif
8654 #ifdef RTE_LIBRTE_BNXT_PMD
8655         if (ret == -ENOTSUP)
8656                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8657                                 res->vlan_id, res->vf_mask, is_add);
8658 #endif
8659
8660         switch (ret) {
8661         case 0:
8662                 break;
8663         case -EINVAL:
8664                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8665                                 res->vlan_id, res->vf_mask);
8666                 break;
8667         case -ENODEV:
8668                 printf("invalid port_id %d\n", res->port_id);
8669                 break;
8670         case -ENOTSUP:
8671                 printf("function not implemented or supported\n");
8672                 break;
8673         default:
8674                 printf("programming error: (%s)\n", strerror(-ret));
8675         }
8676 }
8677
8678 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8679         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8680                                  rx_vlan, "rx_vlan");
8681 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8682         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8683                                  what, "add#rm");
8684 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8685         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8686                               vlan_id, UINT16);
8687 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8688         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8689                                  port, "port");
8690 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8691         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8692                               port_id, UINT16);
8693 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8694         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8695                                  vf, "vf");
8696 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8697         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8698                               vf_mask, UINT64);
8699
8700 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8701         .f = cmd_vf_rx_vlan_filter_parsed,
8702         .data = NULL,
8703         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8704                 "(vf_mask = hexadecimal VF mask)",
8705         .tokens = {
8706                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8707                 (void *)&cmd_vf_rx_vlan_filter_what,
8708                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8709                 (void *)&cmd_vf_rx_vlan_filter_port,
8710                 (void *)&cmd_vf_rx_vlan_filter_portid,
8711                 (void *)&cmd_vf_rx_vlan_filter_vf,
8712                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8713                 NULL,
8714         },
8715 };
8716
8717 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8718 struct cmd_queue_rate_limit_result {
8719         cmdline_fixed_string_t set;
8720         cmdline_fixed_string_t port;
8721         uint16_t port_num;
8722         cmdline_fixed_string_t queue;
8723         uint8_t queue_num;
8724         cmdline_fixed_string_t rate;
8725         uint16_t rate_num;
8726 };
8727
8728 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8729                 __attribute__((unused)) struct cmdline *cl,
8730                 __attribute__((unused)) void *data)
8731 {
8732         struct cmd_queue_rate_limit_result *res = parsed_result;
8733         int ret = 0;
8734
8735         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8736                 && (strcmp(res->queue, "queue") == 0)
8737                 && (strcmp(res->rate, "rate") == 0))
8738                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8739                                         res->rate_num);
8740         if (ret < 0)
8741                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8742
8743 }
8744
8745 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8746         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8747                                 set, "set");
8748 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8749         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8750                                 port, "port");
8751 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8752         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8753                                 port_num, UINT16);
8754 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8755         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8756                                 queue, "queue");
8757 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8758         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8759                                 queue_num, UINT8);
8760 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8761         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8762                                 rate, "rate");
8763 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8764         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8765                                 rate_num, UINT16);
8766
8767 cmdline_parse_inst_t cmd_queue_rate_limit = {
8768         .f = cmd_queue_rate_limit_parsed,
8769         .data = (void *)0,
8770         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8771                 "Set rate limit for a queue on port_id",
8772         .tokens = {
8773                 (void *)&cmd_queue_rate_limit_set,
8774                 (void *)&cmd_queue_rate_limit_port,
8775                 (void *)&cmd_queue_rate_limit_portnum,
8776                 (void *)&cmd_queue_rate_limit_queue,
8777                 (void *)&cmd_queue_rate_limit_queuenum,
8778                 (void *)&cmd_queue_rate_limit_rate,
8779                 (void *)&cmd_queue_rate_limit_ratenum,
8780                 NULL,
8781         },
8782 };
8783
8784 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8785 struct cmd_vf_rate_limit_result {
8786         cmdline_fixed_string_t set;
8787         cmdline_fixed_string_t port;
8788         uint16_t port_num;
8789         cmdline_fixed_string_t vf;
8790         uint8_t vf_num;
8791         cmdline_fixed_string_t rate;
8792         uint16_t rate_num;
8793         cmdline_fixed_string_t q_msk;
8794         uint64_t q_msk_val;
8795 };
8796
8797 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8798                 __attribute__((unused)) struct cmdline *cl,
8799                 __attribute__((unused)) void *data)
8800 {
8801         struct cmd_vf_rate_limit_result *res = parsed_result;
8802         int ret = 0;
8803
8804         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8805                 && (strcmp(res->vf, "vf") == 0)
8806                 && (strcmp(res->rate, "rate") == 0)
8807                 && (strcmp(res->q_msk, "queue_mask") == 0))
8808                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8809                                         res->rate_num, res->q_msk_val);
8810         if (ret < 0)
8811                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8812
8813 }
8814
8815 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8816         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8817                                 set, "set");
8818 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8819         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8820                                 port, "port");
8821 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8822         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8823                                 port_num, UINT16);
8824 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8825         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8826                                 vf, "vf");
8827 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8828         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8829                                 vf_num, UINT8);
8830 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8831         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8832                                 rate, "rate");
8833 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8834         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8835                                 rate_num, UINT16);
8836 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8837         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8838                                 q_msk, "queue_mask");
8839 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8840         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8841                                 q_msk_val, UINT64);
8842
8843 cmdline_parse_inst_t cmd_vf_rate_limit = {
8844         .f = cmd_vf_rate_limit_parsed,
8845         .data = (void *)0,
8846         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8847                 "queue_mask <queue_mask_value>: "
8848                 "Set rate limit for queues of VF on port_id",
8849         .tokens = {
8850                 (void *)&cmd_vf_rate_limit_set,
8851                 (void *)&cmd_vf_rate_limit_port,
8852                 (void *)&cmd_vf_rate_limit_portnum,
8853                 (void *)&cmd_vf_rate_limit_vf,
8854                 (void *)&cmd_vf_rate_limit_vfnum,
8855                 (void *)&cmd_vf_rate_limit_rate,
8856                 (void *)&cmd_vf_rate_limit_ratenum,
8857                 (void *)&cmd_vf_rate_limit_q_msk,
8858                 (void *)&cmd_vf_rate_limit_q_msk_val,
8859                 NULL,
8860         },
8861 };
8862
8863 /* *** ADD TUNNEL FILTER OF A PORT *** */
8864 struct cmd_tunnel_filter_result {
8865         cmdline_fixed_string_t cmd;
8866         cmdline_fixed_string_t what;
8867         portid_t port_id;
8868         struct rte_ether_addr outer_mac;
8869         struct rte_ether_addr inner_mac;
8870         cmdline_ipaddr_t ip_value;
8871         uint16_t inner_vlan;
8872         cmdline_fixed_string_t tunnel_type;
8873         cmdline_fixed_string_t filter_type;
8874         uint32_t tenant_id;
8875         uint16_t queue_num;
8876 };
8877
8878 static void
8879 cmd_tunnel_filter_parsed(void *parsed_result,
8880                           __attribute__((unused)) struct cmdline *cl,
8881                           __attribute__((unused)) void *data)
8882 {
8883         struct cmd_tunnel_filter_result *res = parsed_result;
8884         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8885         int ret = 0;
8886
8887         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8888
8889         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8890         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8891         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8892
8893         if (res->ip_value.family == AF_INET) {
8894                 tunnel_filter_conf.ip_addr.ipv4_addr =
8895                         res->ip_value.addr.ipv4.s_addr;
8896                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8897         } else {
8898                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8899                         &(res->ip_value.addr.ipv6),
8900                         sizeof(struct in6_addr));
8901                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8902         }
8903
8904         if (!strcmp(res->filter_type, "imac-ivlan"))
8905                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8906         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8907                 tunnel_filter_conf.filter_type =
8908                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8909         else if (!strcmp(res->filter_type, "imac-tenid"))
8910                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8911         else if (!strcmp(res->filter_type, "imac"))
8912                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8913         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8914                 tunnel_filter_conf.filter_type =
8915                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8916         else if (!strcmp(res->filter_type, "oip"))
8917                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8918         else if (!strcmp(res->filter_type, "iip"))
8919                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8920         else {
8921                 printf("The filter type is not supported");
8922                 return;
8923         }
8924
8925         if (!strcmp(res->tunnel_type, "vxlan"))
8926                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8927         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8928                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8929         else if (!strcmp(res->tunnel_type, "nvgre"))
8930                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8931         else if (!strcmp(res->tunnel_type, "ipingre"))
8932                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8933         else {
8934                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8935                 return;
8936         }
8937
8938         tunnel_filter_conf.tenant_id = res->tenant_id;
8939         tunnel_filter_conf.queue_id = res->queue_num;
8940         if (!strcmp(res->what, "add"))
8941                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8942                                         RTE_ETH_FILTER_TUNNEL,
8943                                         RTE_ETH_FILTER_ADD,
8944                                         &tunnel_filter_conf);
8945         else
8946                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8947                                         RTE_ETH_FILTER_TUNNEL,
8948                                         RTE_ETH_FILTER_DELETE,
8949                                         &tunnel_filter_conf);
8950         if (ret < 0)
8951                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8952                                 strerror(-ret));
8953
8954 }
8955 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8956         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8957         cmd, "tunnel_filter");
8958 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8959         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8960         what, "add#rm");
8961 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8962         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8963         port_id, UINT16);
8964 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8965         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8966         outer_mac);
8967 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8968         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8969         inner_mac);
8970 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8971         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8972         inner_vlan, UINT16);
8973 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8974         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8975         ip_value);
8976 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8977         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8978         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8979
8980 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8981         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8982         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8983                 "imac#omac-imac-tenid");
8984 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8985         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8986         tenant_id, UINT32);
8987 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8988         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8989         queue_num, UINT16);
8990
8991 cmdline_parse_inst_t cmd_tunnel_filter = {
8992         .f = cmd_tunnel_filter_parsed,
8993         .data = (void *)0,
8994         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8995                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8996                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8997                 "<queue_id>: Add/Rm tunnel filter of a port",
8998         .tokens = {
8999                 (void *)&cmd_tunnel_filter_cmd,
9000                 (void *)&cmd_tunnel_filter_what,
9001                 (void *)&cmd_tunnel_filter_port_id,
9002                 (void *)&cmd_tunnel_filter_outer_mac,
9003                 (void *)&cmd_tunnel_filter_inner_mac,
9004                 (void *)&cmd_tunnel_filter_ip_value,
9005                 (void *)&cmd_tunnel_filter_innner_vlan,
9006                 (void *)&cmd_tunnel_filter_tunnel_type,
9007                 (void *)&cmd_tunnel_filter_filter_type,
9008                 (void *)&cmd_tunnel_filter_tenant_id,
9009                 (void *)&cmd_tunnel_filter_queue_num,
9010                 NULL,
9011         },
9012 };
9013
9014 /* *** CONFIGURE TUNNEL UDP PORT *** */
9015 struct cmd_tunnel_udp_config {
9016         cmdline_fixed_string_t cmd;
9017         cmdline_fixed_string_t what;
9018         uint16_t udp_port;
9019         portid_t port_id;
9020 };
9021
9022 static void
9023 cmd_tunnel_udp_config_parsed(void *parsed_result,
9024                           __attribute__((unused)) struct cmdline *cl,
9025                           __attribute__((unused)) void *data)
9026 {
9027         struct cmd_tunnel_udp_config *res = parsed_result;
9028         struct rte_eth_udp_tunnel tunnel_udp;
9029         int ret;
9030
9031         tunnel_udp.udp_port = res->udp_port;
9032
9033         if (!strcmp(res->cmd, "rx_vxlan_port"))
9034                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9035
9036         if (!strcmp(res->what, "add"))
9037                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9038                                                       &tunnel_udp);
9039         else
9040                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9041                                                          &tunnel_udp);
9042
9043         if (ret < 0)
9044                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9045 }
9046
9047 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9048         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9049                                 cmd, "rx_vxlan_port");
9050 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9051         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9052                                 what, "add#rm");
9053 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9054         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9055                                 udp_port, UINT16);
9056 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9057         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9058                                 port_id, UINT16);
9059
9060 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9061         .f = cmd_tunnel_udp_config_parsed,
9062         .data = (void *)0,
9063         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9064                 "Add/Remove a tunneling UDP port filter",
9065         .tokens = {
9066                 (void *)&cmd_tunnel_udp_config_cmd,
9067                 (void *)&cmd_tunnel_udp_config_what,
9068                 (void *)&cmd_tunnel_udp_config_udp_port,
9069                 (void *)&cmd_tunnel_udp_config_port_id,
9070                 NULL,
9071         },
9072 };
9073
9074 struct cmd_config_tunnel_udp_port {
9075         cmdline_fixed_string_t port;
9076         cmdline_fixed_string_t config;
9077         portid_t port_id;
9078         cmdline_fixed_string_t udp_tunnel_port;
9079         cmdline_fixed_string_t action;
9080         cmdline_fixed_string_t tunnel_type;
9081         uint16_t udp_port;
9082 };
9083
9084 static void
9085 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9086                                __attribute__((unused)) struct cmdline *cl,
9087                                __attribute__((unused)) void *data)
9088 {
9089         struct cmd_config_tunnel_udp_port *res = parsed_result;
9090         struct rte_eth_udp_tunnel tunnel_udp;
9091         int ret = 0;
9092
9093         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9094                 return;
9095
9096         tunnel_udp.udp_port = res->udp_port;
9097
9098         if (!strcmp(res->tunnel_type, "vxlan")) {
9099                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9100         } else if (!strcmp(res->tunnel_type, "geneve")) {
9101                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9102         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9103                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9104         } else {
9105                 printf("Invalid tunnel type\n");
9106                 return;
9107         }
9108
9109         if (!strcmp(res->action, "add"))
9110                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9111                                                       &tunnel_udp);
9112         else
9113                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9114                                                          &tunnel_udp);
9115
9116         if (ret < 0)
9117                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9118 }
9119
9120 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9121         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9122                                  "port");
9123 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9124         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9125                                  "config");
9126 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9127         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9128                               UINT16);
9129 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9130         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9131                                  udp_tunnel_port,
9132                                  "udp_tunnel_port");
9133 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9134         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9135                                  "add#rm");
9136 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9137         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9138                                  "vxlan#geneve#vxlan-gpe");
9139 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9140         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9141                               UINT16);
9142
9143 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9144         .f = cmd_cfg_tunnel_udp_port_parsed,
9145         .data = NULL,
9146         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9147         .tokens = {
9148                 (void *)&cmd_config_tunnel_udp_port_port,
9149                 (void *)&cmd_config_tunnel_udp_port_config,
9150                 (void *)&cmd_config_tunnel_udp_port_port_id,
9151                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9152                 (void *)&cmd_config_tunnel_udp_port_action,
9153                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9154                 (void *)&cmd_config_tunnel_udp_port_value,
9155                 NULL,
9156         },
9157 };
9158
9159 /* *** GLOBAL CONFIG *** */
9160 struct cmd_global_config_result {
9161         cmdline_fixed_string_t cmd;
9162         portid_t port_id;
9163         cmdline_fixed_string_t cfg_type;
9164         uint8_t len;
9165 };
9166
9167 static void
9168 cmd_global_config_parsed(void *parsed_result,
9169                          __attribute__((unused)) struct cmdline *cl,
9170                          __attribute__((unused)) void *data)
9171 {
9172         struct cmd_global_config_result *res = parsed_result;
9173         struct rte_eth_global_cfg conf;
9174         int ret;
9175
9176         memset(&conf, 0, sizeof(conf));
9177         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9178         conf.cfg.gre_key_len = res->len;
9179         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9180                                       RTE_ETH_FILTER_SET, &conf);
9181         if (ret != 0)
9182                 printf("Global config error\n");
9183 }
9184
9185 cmdline_parse_token_string_t cmd_global_config_cmd =
9186         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9187                 "global_config");
9188 cmdline_parse_token_num_t cmd_global_config_port_id =
9189         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9190                                UINT16);
9191 cmdline_parse_token_string_t cmd_global_config_type =
9192         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9193                 cfg_type, "gre-key-len");
9194 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9195         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9196                 len, UINT8);
9197
9198 cmdline_parse_inst_t cmd_global_config = {
9199         .f = cmd_global_config_parsed,
9200         .data = (void *)NULL,
9201         .help_str = "global_config <port_id> gre-key-len <key_len>",
9202         .tokens = {
9203                 (void *)&cmd_global_config_cmd,
9204                 (void *)&cmd_global_config_port_id,
9205                 (void *)&cmd_global_config_type,
9206                 (void *)&cmd_global_config_gre_key_len,
9207                 NULL,
9208         },
9209 };
9210
9211 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9212 struct cmd_set_mirror_mask_result {
9213         cmdline_fixed_string_t set;
9214         cmdline_fixed_string_t port;
9215         portid_t port_id;
9216         cmdline_fixed_string_t mirror;
9217         uint8_t rule_id;
9218         cmdline_fixed_string_t what;
9219         cmdline_fixed_string_t value;
9220         cmdline_fixed_string_t dstpool;
9221         uint8_t dstpool_id;
9222         cmdline_fixed_string_t on;
9223 };
9224
9225 cmdline_parse_token_string_t cmd_mirror_mask_set =
9226         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9227                                 set, "set");
9228 cmdline_parse_token_string_t cmd_mirror_mask_port =
9229         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9230                                 port, "port");
9231 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9232         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9233                                 port_id, UINT16);
9234 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9235         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9236                                 mirror, "mirror-rule");
9237 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9238         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9239                                 rule_id, UINT8);
9240 cmdline_parse_token_string_t cmd_mirror_mask_what =
9241         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9242                                 what, "pool-mirror-up#pool-mirror-down"
9243                                       "#vlan-mirror");
9244 cmdline_parse_token_string_t cmd_mirror_mask_value =
9245         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9246                                 value, NULL);
9247 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9248         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9249                                 dstpool, "dst-pool");
9250 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9251         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9252                                 dstpool_id, UINT8);
9253 cmdline_parse_token_string_t cmd_mirror_mask_on =
9254         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9255                                 on, "on#off");
9256
9257 static void
9258 cmd_set_mirror_mask_parsed(void *parsed_result,
9259                        __attribute__((unused)) struct cmdline *cl,
9260                        __attribute__((unused)) void *data)
9261 {
9262         int ret,nb_item,i;
9263         struct cmd_set_mirror_mask_result *res = parsed_result;
9264         struct rte_eth_mirror_conf mr_conf;
9265
9266         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9267
9268         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9269
9270         mr_conf.dst_pool = res->dstpool_id;
9271
9272         if (!strcmp(res->what, "pool-mirror-up")) {
9273                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9274                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9275         } else if (!strcmp(res->what, "pool-mirror-down")) {
9276                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9277                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9278         } else if (!strcmp(res->what, "vlan-mirror")) {
9279                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9280                 nb_item = parse_item_list(res->value, "vlan",
9281                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9282                 if (nb_item <= 0)
9283                         return;
9284
9285                 for (i = 0; i < nb_item; i++) {
9286                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9287                                 printf("Invalid vlan_id: must be < 4096\n");
9288                                 return;
9289                         }
9290
9291                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9292                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9293                 }
9294         }
9295
9296         if (!strcmp(res->on, "on"))
9297                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9298                                                 res->rule_id, 1);
9299         else
9300                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9301                                                 res->rule_id, 0);
9302         if (ret < 0)
9303                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9304 }
9305
9306 cmdline_parse_inst_t cmd_set_mirror_mask = {
9307                 .f = cmd_set_mirror_mask_parsed,
9308                 .data = NULL,
9309                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9310                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9311                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9312                 .tokens = {
9313                         (void *)&cmd_mirror_mask_set,
9314                         (void *)&cmd_mirror_mask_port,
9315                         (void *)&cmd_mirror_mask_portid,
9316                         (void *)&cmd_mirror_mask_mirror,
9317                         (void *)&cmd_mirror_mask_ruleid,
9318                         (void *)&cmd_mirror_mask_what,
9319                         (void *)&cmd_mirror_mask_value,
9320                         (void *)&cmd_mirror_mask_dstpool,
9321                         (void *)&cmd_mirror_mask_poolid,
9322                         (void *)&cmd_mirror_mask_on,
9323                         NULL,
9324                 },
9325 };
9326
9327 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9328 struct cmd_set_mirror_link_result {
9329         cmdline_fixed_string_t set;
9330         cmdline_fixed_string_t port;
9331         portid_t port_id;
9332         cmdline_fixed_string_t mirror;
9333         uint8_t rule_id;
9334         cmdline_fixed_string_t what;
9335         cmdline_fixed_string_t dstpool;
9336         uint8_t dstpool_id;
9337         cmdline_fixed_string_t on;
9338 };
9339
9340 cmdline_parse_token_string_t cmd_mirror_link_set =
9341         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9342                                  set, "set");
9343 cmdline_parse_token_string_t cmd_mirror_link_port =
9344         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9345                                 port, "port");
9346 cmdline_parse_token_num_t cmd_mirror_link_portid =
9347         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9348                                 port_id, UINT16);
9349 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9350         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9351                                 mirror, "mirror-rule");
9352 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9353         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9354                             rule_id, UINT8);
9355 cmdline_parse_token_string_t cmd_mirror_link_what =
9356         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9357                                 what, "uplink-mirror#downlink-mirror");
9358 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9359         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9360                                 dstpool, "dst-pool");
9361 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9362         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9363                                 dstpool_id, UINT8);
9364 cmdline_parse_token_string_t cmd_mirror_link_on =
9365         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9366                                 on, "on#off");
9367
9368 static void
9369 cmd_set_mirror_link_parsed(void *parsed_result,
9370                        __attribute__((unused)) struct cmdline *cl,
9371                        __attribute__((unused)) void *data)
9372 {
9373         int ret;
9374         struct cmd_set_mirror_link_result *res = parsed_result;
9375         struct rte_eth_mirror_conf mr_conf;
9376
9377         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9378         if (!strcmp(res->what, "uplink-mirror"))
9379                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9380         else
9381                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9382
9383         mr_conf.dst_pool = res->dstpool_id;
9384
9385         if (!strcmp(res->on, "on"))
9386                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9387                                                 res->rule_id, 1);
9388         else
9389                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9390                                                 res->rule_id, 0);
9391
9392         /* check the return value and print it if is < 0 */
9393         if (ret < 0)
9394                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9395
9396 }
9397
9398 cmdline_parse_inst_t cmd_set_mirror_link = {
9399                 .f = cmd_set_mirror_link_parsed,
9400                 .data = NULL,
9401                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9402                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9403                 .tokens = {
9404                         (void *)&cmd_mirror_link_set,
9405                         (void *)&cmd_mirror_link_port,
9406                         (void *)&cmd_mirror_link_portid,
9407                         (void *)&cmd_mirror_link_mirror,
9408                         (void *)&cmd_mirror_link_ruleid,
9409                         (void *)&cmd_mirror_link_what,
9410                         (void *)&cmd_mirror_link_dstpool,
9411                         (void *)&cmd_mirror_link_poolid,
9412                         (void *)&cmd_mirror_link_on,
9413                         NULL,
9414                 },
9415 };
9416
9417 /* *** RESET VM MIRROR RULE *** */
9418 struct cmd_rm_mirror_rule_result {
9419         cmdline_fixed_string_t reset;
9420         cmdline_fixed_string_t port;
9421         portid_t port_id;
9422         cmdline_fixed_string_t mirror;
9423         uint8_t rule_id;
9424 };
9425
9426 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9427         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9428                                  reset, "reset");
9429 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9430         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9431                                 port, "port");
9432 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9433         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9434                                 port_id, UINT16);
9435 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9436         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9437                                 mirror, "mirror-rule");
9438 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9439         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9440                                 rule_id, UINT8);
9441
9442 static void
9443 cmd_reset_mirror_rule_parsed(void *parsed_result,
9444                        __attribute__((unused)) struct cmdline *cl,
9445                        __attribute__((unused)) void *data)
9446 {
9447         int ret;
9448         struct cmd_set_mirror_link_result *res = parsed_result;
9449         /* check rule_id */
9450         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9451         if(ret < 0)
9452                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9453 }
9454
9455 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9456                 .f = cmd_reset_mirror_rule_parsed,
9457                 .data = NULL,
9458                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9459                 .tokens = {
9460                         (void *)&cmd_rm_mirror_rule_reset,
9461                         (void *)&cmd_rm_mirror_rule_port,
9462                         (void *)&cmd_rm_mirror_rule_portid,
9463                         (void *)&cmd_rm_mirror_rule_mirror,
9464                         (void *)&cmd_rm_mirror_rule_ruleid,
9465                         NULL,
9466                 },
9467 };
9468
9469 /* ******************************************************************************** */
9470
9471 struct cmd_dump_result {
9472         cmdline_fixed_string_t dump;
9473 };
9474
9475 static void
9476 dump_struct_sizes(void)
9477 {
9478 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9479         DUMP_SIZE(struct rte_mbuf);
9480         DUMP_SIZE(struct rte_mempool);
9481         DUMP_SIZE(struct rte_ring);
9482 #undef DUMP_SIZE
9483 }
9484
9485 static void cmd_dump_parsed(void *parsed_result,
9486                             __attribute__((unused)) struct cmdline *cl,
9487                             __attribute__((unused)) void *data)
9488 {
9489         struct cmd_dump_result *res = parsed_result;
9490
9491         if (!strcmp(res->dump, "dump_physmem"))
9492                 rte_dump_physmem_layout(stdout);
9493         else if (!strcmp(res->dump, "dump_memzone"))
9494                 rte_memzone_dump(stdout);
9495         else if (!strcmp(res->dump, "dump_struct_sizes"))
9496                 dump_struct_sizes();
9497         else if (!strcmp(res->dump, "dump_ring"))
9498                 rte_ring_list_dump(stdout);
9499         else if (!strcmp(res->dump, "dump_mempool"))
9500                 rte_mempool_list_dump(stdout);
9501         else if (!strcmp(res->dump, "dump_devargs"))
9502                 rte_devargs_dump(stdout);
9503         else if (!strcmp(res->dump, "dump_log_types"))
9504                 rte_log_dump(stdout);
9505 }
9506
9507 cmdline_parse_token_string_t cmd_dump_dump =
9508         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9509                 "dump_physmem#"
9510                 "dump_memzone#"
9511                 "dump_struct_sizes#"
9512                 "dump_ring#"
9513                 "dump_mempool#"
9514                 "dump_devargs#"
9515                 "dump_log_types");
9516
9517 cmdline_parse_inst_t cmd_dump = {
9518         .f = cmd_dump_parsed,  /* function to call */
9519         .data = NULL,      /* 2nd arg of func */
9520         .help_str = "Dump status",
9521         .tokens = {        /* token list, NULL terminated */
9522                 (void *)&cmd_dump_dump,
9523                 NULL,
9524         },
9525 };
9526
9527 /* ******************************************************************************** */
9528
9529 struct cmd_dump_one_result {
9530         cmdline_fixed_string_t dump;
9531         cmdline_fixed_string_t name;
9532 };
9533
9534 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9535                                 __attribute__((unused)) void *data)
9536 {
9537         struct cmd_dump_one_result *res = parsed_result;
9538
9539         if (!strcmp(res->dump, "dump_ring")) {
9540                 struct rte_ring *r;
9541                 r = rte_ring_lookup(res->name);
9542                 if (r == NULL) {
9543                         cmdline_printf(cl, "Cannot find ring\n");
9544                         return;
9545                 }
9546                 rte_ring_dump(stdout, r);
9547         } else if (!strcmp(res->dump, "dump_mempool")) {
9548                 struct rte_mempool *mp;
9549                 mp = rte_mempool_lookup(res->name);
9550                 if (mp == NULL) {
9551                         cmdline_printf(cl, "Cannot find mempool\n");
9552                         return;
9553                 }
9554                 rte_mempool_dump(stdout, mp);
9555         }
9556 }
9557
9558 cmdline_parse_token_string_t cmd_dump_one_dump =
9559         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9560                                  "dump_ring#dump_mempool");
9561
9562 cmdline_parse_token_string_t cmd_dump_one_name =
9563         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9564
9565 cmdline_parse_inst_t cmd_dump_one = {
9566         .f = cmd_dump_one_parsed,  /* function to call */
9567         .data = NULL,      /* 2nd arg of func */
9568         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9569         .tokens = {        /* token list, NULL terminated */
9570                 (void *)&cmd_dump_one_dump,
9571                 (void *)&cmd_dump_one_name,
9572                 NULL,
9573         },
9574 };
9575
9576 /* *** Add/Del syn filter *** */
9577 struct cmd_syn_filter_result {
9578         cmdline_fixed_string_t filter;
9579         portid_t port_id;
9580         cmdline_fixed_string_t ops;
9581         cmdline_fixed_string_t priority;
9582         cmdline_fixed_string_t high;
9583         cmdline_fixed_string_t queue;
9584         uint16_t queue_id;
9585 };
9586
9587 static void
9588 cmd_syn_filter_parsed(void *parsed_result,
9589                         __attribute__((unused)) struct cmdline *cl,
9590                         __attribute__((unused)) void *data)
9591 {
9592         struct cmd_syn_filter_result *res = parsed_result;
9593         struct rte_eth_syn_filter syn_filter;
9594         int ret = 0;
9595
9596         ret = rte_eth_dev_filter_supported(res->port_id,
9597                                         RTE_ETH_FILTER_SYN);
9598         if (ret < 0) {
9599                 printf("syn filter is not supported on port %u.\n",
9600                                 res->port_id);
9601                 return;
9602         }
9603
9604         memset(&syn_filter, 0, sizeof(syn_filter));
9605
9606         if (!strcmp(res->ops, "add")) {
9607                 if (!strcmp(res->high, "high"))
9608                         syn_filter.hig_pri = 1;
9609                 else
9610                         syn_filter.hig_pri = 0;
9611
9612                 syn_filter.queue = res->queue_id;
9613                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9614                                                 RTE_ETH_FILTER_SYN,
9615                                                 RTE_ETH_FILTER_ADD,
9616                                                 &syn_filter);
9617         } else
9618                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9619                                                 RTE_ETH_FILTER_SYN,
9620                                                 RTE_ETH_FILTER_DELETE,
9621                                                 &syn_filter);
9622
9623         if (ret < 0)
9624                 printf("syn filter programming error: (%s)\n",
9625                                 strerror(-ret));
9626 }
9627
9628 cmdline_parse_token_string_t cmd_syn_filter_filter =
9629         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9630         filter, "syn_filter");
9631 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9632         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9633         port_id, UINT16);
9634 cmdline_parse_token_string_t cmd_syn_filter_ops =
9635         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9636         ops, "add#del");
9637 cmdline_parse_token_string_t cmd_syn_filter_priority =
9638         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9639                                 priority, "priority");
9640 cmdline_parse_token_string_t cmd_syn_filter_high =
9641         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9642                                 high, "high#low");
9643 cmdline_parse_token_string_t cmd_syn_filter_queue =
9644         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9645                                 queue, "queue");
9646 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9647         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9648                                 queue_id, UINT16);
9649
9650 cmdline_parse_inst_t cmd_syn_filter = {
9651         .f = cmd_syn_filter_parsed,
9652         .data = NULL,
9653         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9654                 "<queue_id>: Add/Delete syn filter",
9655         .tokens = {
9656                 (void *)&cmd_syn_filter_filter,
9657                 (void *)&cmd_syn_filter_port_id,
9658                 (void *)&cmd_syn_filter_ops,
9659                 (void *)&cmd_syn_filter_priority,
9660                 (void *)&cmd_syn_filter_high,
9661                 (void *)&cmd_syn_filter_queue,
9662                 (void *)&cmd_syn_filter_queue_id,
9663                 NULL,
9664         },
9665 };
9666
9667 /* *** queue region set *** */
9668 struct cmd_queue_region_result {
9669         cmdline_fixed_string_t set;
9670         cmdline_fixed_string_t port;
9671         portid_t port_id;
9672         cmdline_fixed_string_t cmd;
9673         cmdline_fixed_string_t region;
9674         uint8_t  region_id;
9675         cmdline_fixed_string_t queue_start_index;
9676         uint8_t  queue_id;
9677         cmdline_fixed_string_t queue_num;
9678         uint8_t  queue_num_value;
9679 };
9680
9681 static void
9682 cmd_queue_region_parsed(void *parsed_result,
9683                         __attribute__((unused)) struct cmdline *cl,
9684                         __attribute__((unused)) void *data)
9685 {
9686         struct cmd_queue_region_result *res = parsed_result;
9687         int ret = -ENOTSUP;
9688 #ifdef RTE_LIBRTE_I40E_PMD
9689         struct rte_pmd_i40e_queue_region_conf region_conf;
9690         enum rte_pmd_i40e_queue_region_op op_type;
9691 #endif
9692
9693         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9694                 return;
9695
9696 #ifdef RTE_LIBRTE_I40E_PMD
9697         memset(&region_conf, 0, sizeof(region_conf));
9698         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9699         region_conf.region_id = res->region_id;
9700         region_conf.queue_num = res->queue_num_value;
9701         region_conf.queue_start_index = res->queue_id;
9702
9703         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9704                                 op_type, &region_conf);
9705 #endif
9706
9707         switch (ret) {
9708         case 0:
9709                 break;
9710         case -ENOTSUP:
9711                 printf("function not implemented or supported\n");
9712                 break;
9713         default:
9714                 printf("queue region config error: (%s)\n", strerror(-ret));
9715         }
9716 }
9717
9718 cmdline_parse_token_string_t cmd_queue_region_set =
9719 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9720                 set, "set");
9721 cmdline_parse_token_string_t cmd_queue_region_port =
9722         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9723 cmdline_parse_token_num_t cmd_queue_region_port_id =
9724         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9725                                 port_id, UINT16);
9726 cmdline_parse_token_string_t cmd_queue_region_cmd =
9727         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9728                                  cmd, "queue-region");
9729 cmdline_parse_token_string_t cmd_queue_region_id =
9730         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9731                                 region, "region_id");
9732 cmdline_parse_token_num_t cmd_queue_region_index =
9733         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9734                                 region_id, UINT8);
9735 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9736         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9737                                 queue_start_index, "queue_start_index");
9738 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9739         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9740                                 queue_id, UINT8);
9741 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9742         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9743                                 queue_num, "queue_num");
9744 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9745         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9746                                 queue_num_value, UINT8);
9747
9748 cmdline_parse_inst_t cmd_queue_region = {
9749         .f = cmd_queue_region_parsed,
9750         .data = NULL,
9751         .help_str = "set port <port_id> queue-region region_id <value> "
9752                 "queue_start_index <value> queue_num <value>: Set a queue region",
9753         .tokens = {
9754                 (void *)&cmd_queue_region_set,
9755                 (void *)&cmd_queue_region_port,
9756                 (void *)&cmd_queue_region_port_id,
9757                 (void *)&cmd_queue_region_cmd,
9758                 (void *)&cmd_queue_region_id,
9759                 (void *)&cmd_queue_region_index,
9760                 (void *)&cmd_queue_region_queue_start_index,
9761                 (void *)&cmd_queue_region_queue_id,
9762                 (void *)&cmd_queue_region_queue_num,
9763                 (void *)&cmd_queue_region_queue_num_value,
9764                 NULL,
9765         },
9766 };
9767
9768 /* *** queue region and flowtype set *** */
9769 struct cmd_region_flowtype_result {
9770         cmdline_fixed_string_t set;
9771         cmdline_fixed_string_t port;
9772         portid_t port_id;
9773         cmdline_fixed_string_t cmd;
9774         cmdline_fixed_string_t region;
9775         uint8_t  region_id;
9776         cmdline_fixed_string_t flowtype;
9777         uint8_t  flowtype_id;
9778 };
9779
9780 static void
9781 cmd_region_flowtype_parsed(void *parsed_result,
9782                         __attribute__((unused)) struct cmdline *cl,
9783                         __attribute__((unused)) void *data)
9784 {
9785         struct cmd_region_flowtype_result *res = parsed_result;
9786         int ret = -ENOTSUP;
9787 #ifdef RTE_LIBRTE_I40E_PMD
9788         struct rte_pmd_i40e_queue_region_conf region_conf;
9789         enum rte_pmd_i40e_queue_region_op op_type;
9790 #endif
9791
9792         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9793                 return;
9794
9795 #ifdef RTE_LIBRTE_I40E_PMD
9796         memset(&region_conf, 0, sizeof(region_conf));
9797
9798         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9799         region_conf.region_id = res->region_id;
9800         region_conf.hw_flowtype = res->flowtype_id;
9801
9802         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9803                         op_type, &region_conf);
9804 #endif
9805
9806         switch (ret) {
9807         case 0:
9808                 break;
9809         case -ENOTSUP:
9810                 printf("function not implemented or supported\n");
9811                 break;
9812         default:
9813                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9814         }
9815 }
9816
9817 cmdline_parse_token_string_t cmd_region_flowtype_set =
9818 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9819                                 set, "set");
9820 cmdline_parse_token_string_t cmd_region_flowtype_port =
9821         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9822                                 port, "port");
9823 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9824         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9825                                 port_id, UINT16);
9826 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9827         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9828                                 cmd, "queue-region");
9829 cmdline_parse_token_string_t cmd_region_flowtype_index =
9830         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9831                                 region, "region_id");
9832 cmdline_parse_token_num_t cmd_region_flowtype_id =
9833         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9834                                 region_id, UINT8);
9835 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9836         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9837                                 flowtype, "flowtype");
9838 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9839         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9840                                 flowtype_id, UINT8);
9841 cmdline_parse_inst_t cmd_region_flowtype = {
9842         .f = cmd_region_flowtype_parsed,
9843         .data = NULL,
9844         .help_str = "set port <port_id> queue-region region_id <value> "
9845                 "flowtype <value>: Set a flowtype region index",
9846         .tokens = {
9847                 (void *)&cmd_region_flowtype_set,
9848                 (void *)&cmd_region_flowtype_port,
9849                 (void *)&cmd_region_flowtype_port_index,
9850                 (void *)&cmd_region_flowtype_cmd,
9851                 (void *)&cmd_region_flowtype_index,
9852                 (void *)&cmd_region_flowtype_id,
9853                 (void *)&cmd_region_flowtype_flow_index,
9854                 (void *)&cmd_region_flowtype_flow_id,
9855                 NULL,
9856         },
9857 };
9858
9859 /* *** User Priority (UP) to queue region (region_id) set *** */
9860 struct cmd_user_priority_region_result {
9861         cmdline_fixed_string_t set;
9862         cmdline_fixed_string_t port;
9863         portid_t port_id;
9864         cmdline_fixed_string_t cmd;
9865         cmdline_fixed_string_t user_priority;
9866         uint8_t  user_priority_id;
9867         cmdline_fixed_string_t region;
9868         uint8_t  region_id;
9869 };
9870
9871 static void
9872 cmd_user_priority_region_parsed(void *parsed_result,
9873                         __attribute__((unused)) struct cmdline *cl,
9874                         __attribute__((unused)) void *data)
9875 {
9876         struct cmd_user_priority_region_result *res = parsed_result;
9877         int ret = -ENOTSUP;
9878 #ifdef RTE_LIBRTE_I40E_PMD
9879         struct rte_pmd_i40e_queue_region_conf region_conf;
9880         enum rte_pmd_i40e_queue_region_op op_type;
9881 #endif
9882
9883         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9884                 return;
9885
9886 #ifdef RTE_LIBRTE_I40E_PMD
9887         memset(&region_conf, 0, sizeof(region_conf));
9888         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9889         region_conf.user_priority = res->user_priority_id;
9890         region_conf.region_id = res->region_id;
9891
9892         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9893                                 op_type, &region_conf);
9894 #endif
9895
9896         switch (ret) {
9897         case 0:
9898                 break;
9899         case -ENOTSUP:
9900                 printf("function not implemented or supported\n");
9901                 break;
9902         default:
9903                 printf("user_priority region config error: (%s)\n",
9904                                 strerror(-ret));
9905         }
9906 }
9907
9908 cmdline_parse_token_string_t cmd_user_priority_region_set =
9909         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9910                                 set, "set");
9911 cmdline_parse_token_string_t cmd_user_priority_region_port =
9912         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9913                                 port, "port");
9914 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9915         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9916                                 port_id, UINT16);
9917 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9918         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9919                                 cmd, "queue-region");
9920 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9921         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9922                                 user_priority, "UP");
9923 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9924         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9925                                 user_priority_id, UINT8);
9926 cmdline_parse_token_string_t cmd_user_priority_region_region =
9927         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9928                                 region, "region_id");
9929 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9930         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9931                                 region_id, UINT8);
9932
9933 cmdline_parse_inst_t cmd_user_priority_region = {
9934         .f = cmd_user_priority_region_parsed,
9935         .data = NULL,
9936         .help_str = "set port <port_id> queue-region UP <value> "
9937                 "region_id <value>: Set the mapping of User Priority (UP) "
9938                 "to queue region (region_id) ",
9939         .tokens = {
9940                 (void *)&cmd_user_priority_region_set,
9941                 (void *)&cmd_user_priority_region_port,
9942                 (void *)&cmd_user_priority_region_port_index,
9943                 (void *)&cmd_user_priority_region_cmd,
9944                 (void *)&cmd_user_priority_region_UP,
9945                 (void *)&cmd_user_priority_region_UP_id,
9946                 (void *)&cmd_user_priority_region_region,
9947                 (void *)&cmd_user_priority_region_region_id,
9948                 NULL,
9949         },
9950 };
9951
9952 /* *** flush all queue region related configuration *** */
9953 struct cmd_flush_queue_region_result {
9954         cmdline_fixed_string_t set;
9955         cmdline_fixed_string_t port;
9956         portid_t port_id;
9957         cmdline_fixed_string_t cmd;
9958         cmdline_fixed_string_t flush;
9959         cmdline_fixed_string_t what;
9960 };
9961
9962 static void
9963 cmd_flush_queue_region_parsed(void *parsed_result,
9964                         __attribute__((unused)) struct cmdline *cl,
9965                         __attribute__((unused)) void *data)
9966 {
9967         struct cmd_flush_queue_region_result *res = parsed_result;
9968         int ret = -ENOTSUP;
9969 #ifdef RTE_LIBRTE_I40E_PMD
9970         struct rte_pmd_i40e_queue_region_conf region_conf;
9971         enum rte_pmd_i40e_queue_region_op op_type;
9972 #endif
9973
9974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9975                 return;
9976
9977 #ifdef RTE_LIBRTE_I40E_PMD
9978         memset(&region_conf, 0, sizeof(region_conf));
9979
9980         if (strcmp(res->what, "on") == 0)
9981                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9982         else
9983                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9984
9985         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9986                                 op_type, &region_conf);
9987 #endif
9988
9989         switch (ret) {
9990         case 0:
9991                 break;
9992         case -ENOTSUP:
9993                 printf("function not implemented or supported\n");
9994                 break;
9995         default:
9996                 printf("queue region config flush error: (%s)\n",
9997                                 strerror(-ret));
9998         }
9999 }
10000
10001 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10002         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10003                                 set, "set");
10004 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10005         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10006                                 port, "port");
10007 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10008         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10009                                 port_id, UINT16);
10010 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10011         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10012                                 cmd, "queue-region");
10013 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10014         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10015                                 flush, "flush");
10016 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10017         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10018                                 what, "on#off");
10019
10020 cmdline_parse_inst_t cmd_flush_queue_region = {
10021         .f = cmd_flush_queue_region_parsed,
10022         .data = NULL,
10023         .help_str = "set port <port_id> queue-region flush on|off"
10024                 ": flush all queue region related configuration",
10025         .tokens = {
10026                 (void *)&cmd_flush_queue_region_set,
10027                 (void *)&cmd_flush_queue_region_port,
10028                 (void *)&cmd_flush_queue_region_port_index,
10029                 (void *)&cmd_flush_queue_region_cmd,
10030                 (void *)&cmd_flush_queue_region_flush,
10031                 (void *)&cmd_flush_queue_region_what,
10032                 NULL,
10033         },
10034 };
10035
10036 /* *** get all queue region related configuration info *** */
10037 struct cmd_show_queue_region_info {
10038         cmdline_fixed_string_t show;
10039         cmdline_fixed_string_t port;
10040         portid_t port_id;
10041         cmdline_fixed_string_t cmd;
10042 };
10043
10044 static void
10045 cmd_show_queue_region_info_parsed(void *parsed_result,
10046                         __attribute__((unused)) struct cmdline *cl,
10047                         __attribute__((unused)) void *data)
10048 {
10049         struct cmd_show_queue_region_info *res = parsed_result;
10050         int ret = -ENOTSUP;
10051 #ifdef RTE_LIBRTE_I40E_PMD
10052         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10053         enum rte_pmd_i40e_queue_region_op op_type;
10054 #endif
10055
10056         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10057                 return;
10058
10059 #ifdef RTE_LIBRTE_I40E_PMD
10060         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10061
10062         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10063
10064         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10065                                         op_type, &rte_pmd_regions);
10066
10067         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10068 #endif
10069
10070         switch (ret) {
10071         case 0:
10072                 break;
10073         case -ENOTSUP:
10074                 printf("function not implemented or supported\n");
10075                 break;
10076         default:
10077                 printf("queue region config info show error: (%s)\n",
10078                                 strerror(-ret));
10079         }
10080 }
10081
10082 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10083 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10084                                 show, "show");
10085 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10086         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10087                                 port, "port");
10088 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10089         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10090                                 port_id, UINT16);
10091 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10092         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10093                                 cmd, "queue-region");
10094
10095 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10096         .f = cmd_show_queue_region_info_parsed,
10097         .data = NULL,
10098         .help_str = "show port <port_id> queue-region"
10099                 ": show all queue region related configuration info",
10100         .tokens = {
10101                 (void *)&cmd_show_queue_region_info_get,
10102                 (void *)&cmd_show_queue_region_info_port,
10103                 (void *)&cmd_show_queue_region_info_port_index,
10104                 (void *)&cmd_show_queue_region_info_cmd,
10105                 NULL,
10106         },
10107 };
10108
10109 /* *** ADD/REMOVE A 2tuple FILTER *** */
10110 struct cmd_2tuple_filter_result {
10111         cmdline_fixed_string_t filter;
10112         portid_t port_id;
10113         cmdline_fixed_string_t ops;
10114         cmdline_fixed_string_t dst_port;
10115         uint16_t dst_port_value;
10116         cmdline_fixed_string_t protocol;
10117         uint8_t protocol_value;
10118         cmdline_fixed_string_t mask;
10119         uint8_t  mask_value;
10120         cmdline_fixed_string_t tcp_flags;
10121         uint8_t tcp_flags_value;
10122         cmdline_fixed_string_t priority;
10123         uint8_t  priority_value;
10124         cmdline_fixed_string_t queue;
10125         uint16_t  queue_id;
10126 };
10127
10128 static void
10129 cmd_2tuple_filter_parsed(void *parsed_result,
10130                         __attribute__((unused)) struct cmdline *cl,
10131                         __attribute__((unused)) void *data)
10132 {
10133         struct rte_eth_ntuple_filter filter;
10134         struct cmd_2tuple_filter_result *res = parsed_result;
10135         int ret = 0;
10136
10137         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10138         if (ret < 0) {
10139                 printf("ntuple filter is not supported on port %u.\n",
10140                         res->port_id);
10141                 return;
10142         }
10143
10144         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10145
10146         filter.flags = RTE_2TUPLE_FLAGS;
10147         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10148         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10149         filter.proto = res->protocol_value;
10150         filter.priority = res->priority_value;
10151         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10152                 printf("nonzero tcp_flags is only meaningful"
10153                         " when protocol is TCP.\n");
10154                 return;
10155         }
10156         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10157                 printf("invalid TCP flags.\n");
10158                 return;
10159         }
10160
10161         if (res->tcp_flags_value != 0) {
10162                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10163                 filter.tcp_flags = res->tcp_flags_value;
10164         }
10165
10166         /* need convert to big endian. */
10167         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10168         filter.queue = res->queue_id;
10169
10170         if (!strcmp(res->ops, "add"))
10171                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10172                                 RTE_ETH_FILTER_NTUPLE,
10173                                 RTE_ETH_FILTER_ADD,
10174                                 &filter);
10175         else
10176                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10177                                 RTE_ETH_FILTER_NTUPLE,
10178                                 RTE_ETH_FILTER_DELETE,
10179                                 &filter);
10180         if (ret < 0)
10181                 printf("2tuple filter programming error: (%s)\n",
10182                         strerror(-ret));
10183
10184 }
10185
10186 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10187         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10188                                  filter, "2tuple_filter");
10189 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10190         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10191                                 port_id, UINT16);
10192 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10193         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10194                                  ops, "add#del");
10195 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10196         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10197                                 dst_port, "dst_port");
10198 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10199         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10200                                 dst_port_value, UINT16);
10201 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10202         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10203                                 protocol, "protocol");
10204 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10205         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10206                                 protocol_value, UINT8);
10207 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10208         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10209                                 mask, "mask");
10210 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10211         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10212                                 mask_value, INT8);
10213 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10214         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10215                                 tcp_flags, "tcp_flags");
10216 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10217         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10218                                 tcp_flags_value, UINT8);
10219 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10220         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10221                                 priority, "priority");
10222 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10223         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10224                                 priority_value, UINT8);
10225 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10226         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10227                                 queue, "queue");
10228 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10229         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10230                                 queue_id, UINT16);
10231
10232 cmdline_parse_inst_t cmd_2tuple_filter = {
10233         .f = cmd_2tuple_filter_parsed,
10234         .data = NULL,
10235         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10236                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10237                 "<queue_id>: Add a 2tuple filter",
10238         .tokens = {
10239                 (void *)&cmd_2tuple_filter_filter,
10240                 (void *)&cmd_2tuple_filter_port_id,
10241                 (void *)&cmd_2tuple_filter_ops,
10242                 (void *)&cmd_2tuple_filter_dst_port,
10243                 (void *)&cmd_2tuple_filter_dst_port_value,
10244                 (void *)&cmd_2tuple_filter_protocol,
10245                 (void *)&cmd_2tuple_filter_protocol_value,
10246                 (void *)&cmd_2tuple_filter_mask,
10247                 (void *)&cmd_2tuple_filter_mask_value,
10248                 (void *)&cmd_2tuple_filter_tcp_flags,
10249                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10250                 (void *)&cmd_2tuple_filter_priority,
10251                 (void *)&cmd_2tuple_filter_priority_value,
10252                 (void *)&cmd_2tuple_filter_queue,
10253                 (void *)&cmd_2tuple_filter_queue_id,
10254                 NULL,
10255         },
10256 };
10257
10258 /* *** ADD/REMOVE A 5tuple FILTER *** */
10259 struct cmd_5tuple_filter_result {
10260         cmdline_fixed_string_t filter;
10261         portid_t port_id;
10262         cmdline_fixed_string_t ops;
10263         cmdline_fixed_string_t dst_ip;
10264         cmdline_ipaddr_t dst_ip_value;
10265         cmdline_fixed_string_t src_ip;
10266         cmdline_ipaddr_t src_ip_value;
10267         cmdline_fixed_string_t dst_port;
10268         uint16_t dst_port_value;
10269         cmdline_fixed_string_t src_port;
10270         uint16_t src_port_value;
10271         cmdline_fixed_string_t protocol;
10272         uint8_t protocol_value;
10273         cmdline_fixed_string_t mask;
10274         uint8_t  mask_value;
10275         cmdline_fixed_string_t tcp_flags;
10276         uint8_t tcp_flags_value;
10277         cmdline_fixed_string_t priority;
10278         uint8_t  priority_value;
10279         cmdline_fixed_string_t queue;
10280         uint16_t  queue_id;
10281 };
10282
10283 static void
10284 cmd_5tuple_filter_parsed(void *parsed_result,
10285                         __attribute__((unused)) struct cmdline *cl,
10286                         __attribute__((unused)) void *data)
10287 {
10288         struct rte_eth_ntuple_filter filter;
10289         struct cmd_5tuple_filter_result *res = parsed_result;
10290         int ret = 0;
10291
10292         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10293         if (ret < 0) {
10294                 printf("ntuple filter is not supported on port %u.\n",
10295                         res->port_id);
10296                 return;
10297         }
10298
10299         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10300
10301         filter.flags = RTE_5TUPLE_FLAGS;
10302         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10303         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10304         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10305         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10306         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10307         filter.proto = res->protocol_value;
10308         filter.priority = res->priority_value;
10309         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10310                 printf("nonzero tcp_flags is only meaningful"
10311                         " when protocol is TCP.\n");
10312                 return;
10313         }
10314         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10315                 printf("invalid TCP flags.\n");
10316                 return;
10317         }
10318
10319         if (res->tcp_flags_value != 0) {
10320                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10321                 filter.tcp_flags = res->tcp_flags_value;
10322         }
10323
10324         if (res->dst_ip_value.family == AF_INET)
10325                 /* no need to convert, already big endian. */
10326                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10327         else {
10328                 if (filter.dst_ip_mask == 0) {
10329                         printf("can not support ipv6 involved compare.\n");
10330                         return;
10331                 }
10332                 filter.dst_ip = 0;
10333         }
10334
10335         if (res->src_ip_value.family == AF_INET)
10336                 /* no need to convert, already big endian. */
10337                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10338         else {
10339                 if (filter.src_ip_mask == 0) {
10340                         printf("can not support ipv6 involved compare.\n");
10341                         return;
10342                 }
10343                 filter.src_ip = 0;
10344         }
10345         /* need convert to big endian. */
10346         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10347         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10348         filter.queue = res->queue_id;
10349
10350         if (!strcmp(res->ops, "add"))
10351                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10352                                 RTE_ETH_FILTER_NTUPLE,
10353                                 RTE_ETH_FILTER_ADD,
10354                                 &filter);
10355         else
10356                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10357                                 RTE_ETH_FILTER_NTUPLE,
10358                                 RTE_ETH_FILTER_DELETE,
10359                                 &filter);
10360         if (ret < 0)
10361                 printf("5tuple filter programming error: (%s)\n",
10362                         strerror(-ret));
10363 }
10364
10365 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10366         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10367                                  filter, "5tuple_filter");
10368 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10369         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10370                                 port_id, UINT16);
10371 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10372         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10373                                  ops, "add#del");
10374 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10375         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10376                                 dst_ip, "dst_ip");
10377 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10378         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10379                                 dst_ip_value);
10380 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10381         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10382                                 src_ip, "src_ip");
10383 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10384         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10385                                 src_ip_value);
10386 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10387         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10388                                 dst_port, "dst_port");
10389 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10390         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10391                                 dst_port_value, UINT16);
10392 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10393         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10394                                 src_port, "src_port");
10395 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10396         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10397                                 src_port_value, UINT16);
10398 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10399         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10400                                 protocol, "protocol");
10401 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10402         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10403                                 protocol_value, UINT8);
10404 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10405         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10406                                 mask, "mask");
10407 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10408         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10409                                 mask_value, INT8);
10410 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10411         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10412                                 tcp_flags, "tcp_flags");
10413 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10414         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10415                                 tcp_flags_value, UINT8);
10416 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10417         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10418                                 priority, "priority");
10419 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10420         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10421                                 priority_value, UINT8);
10422 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10423         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10424                                 queue, "queue");
10425 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10426         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10427                                 queue_id, UINT16);
10428
10429 cmdline_parse_inst_t cmd_5tuple_filter = {
10430         .f = cmd_5tuple_filter_parsed,
10431         .data = NULL,
10432         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10433                 "src_ip <value> dst_port <value> src_port <value> "
10434                 "protocol <value>  mask <value> tcp_flags <value> "
10435                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10436         .tokens = {
10437                 (void *)&cmd_5tuple_filter_filter,
10438                 (void *)&cmd_5tuple_filter_port_id,
10439                 (void *)&cmd_5tuple_filter_ops,
10440                 (void *)&cmd_5tuple_filter_dst_ip,
10441                 (void *)&cmd_5tuple_filter_dst_ip_value,
10442                 (void *)&cmd_5tuple_filter_src_ip,
10443                 (void *)&cmd_5tuple_filter_src_ip_value,
10444                 (void *)&cmd_5tuple_filter_dst_port,
10445                 (void *)&cmd_5tuple_filter_dst_port_value,
10446                 (void *)&cmd_5tuple_filter_src_port,
10447                 (void *)&cmd_5tuple_filter_src_port_value,
10448                 (void *)&cmd_5tuple_filter_protocol,
10449                 (void *)&cmd_5tuple_filter_protocol_value,
10450                 (void *)&cmd_5tuple_filter_mask,
10451                 (void *)&cmd_5tuple_filter_mask_value,
10452                 (void *)&cmd_5tuple_filter_tcp_flags,
10453                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10454                 (void *)&cmd_5tuple_filter_priority,
10455                 (void *)&cmd_5tuple_filter_priority_value,
10456                 (void *)&cmd_5tuple_filter_queue,
10457                 (void *)&cmd_5tuple_filter_queue_id,
10458                 NULL,
10459         },
10460 };
10461
10462 /* *** ADD/REMOVE A flex FILTER *** */
10463 struct cmd_flex_filter_result {
10464         cmdline_fixed_string_t filter;
10465         cmdline_fixed_string_t ops;
10466         portid_t port_id;
10467         cmdline_fixed_string_t len;
10468         uint8_t len_value;
10469         cmdline_fixed_string_t bytes;
10470         cmdline_fixed_string_t bytes_value;
10471         cmdline_fixed_string_t mask;
10472         cmdline_fixed_string_t mask_value;
10473         cmdline_fixed_string_t priority;
10474         uint8_t priority_value;
10475         cmdline_fixed_string_t queue;
10476         uint16_t queue_id;
10477 };
10478
10479 static int xdigit2val(unsigned char c)
10480 {
10481         int val;
10482         if (isdigit(c))
10483                 val = c - '0';
10484         else if (isupper(c))
10485                 val = c - 'A' + 10;
10486         else
10487                 val = c - 'a' + 10;
10488         return val;
10489 }
10490
10491 static void
10492 cmd_flex_filter_parsed(void *parsed_result,
10493                           __attribute__((unused)) struct cmdline *cl,
10494                           __attribute__((unused)) void *data)
10495 {
10496         int ret = 0;
10497         struct rte_eth_flex_filter filter;
10498         struct cmd_flex_filter_result *res = parsed_result;
10499         char *bytes_ptr, *mask_ptr;
10500         uint16_t len, i, j = 0;
10501         char c;
10502         int val;
10503         uint8_t byte = 0;
10504
10505         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10506                 printf("the len exceed the max length 128\n");
10507                 return;
10508         }
10509         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10510         filter.len = res->len_value;
10511         filter.priority = res->priority_value;
10512         filter.queue = res->queue_id;
10513         bytes_ptr = res->bytes_value;
10514         mask_ptr = res->mask_value;
10515
10516          /* translate bytes string to array. */
10517         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10518                 (bytes_ptr[1] == 'X')))
10519                 bytes_ptr += 2;
10520         len = strnlen(bytes_ptr, res->len_value * 2);
10521         if (len == 0 || (len % 8 != 0)) {
10522                 printf("please check len and bytes input\n");
10523                 return;
10524         }
10525         for (i = 0; i < len; i++) {
10526                 c = bytes_ptr[i];
10527                 if (isxdigit(c) == 0) {
10528                         /* invalid characters. */
10529                         printf("invalid input\n");
10530                         return;
10531                 }
10532                 val = xdigit2val(c);
10533                 if (i % 2) {
10534                         byte |= val;
10535                         filter.bytes[j] = byte;
10536                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10537                         j++;
10538                         byte = 0;
10539                 } else
10540                         byte |= val << 4;
10541         }
10542         printf("\n");
10543          /* translate mask string to uint8_t array. */
10544         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10545                 (mask_ptr[1] == 'X')))
10546                 mask_ptr += 2;
10547         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10548         if (len == 0) {
10549                 printf("invalid input\n");
10550                 return;
10551         }
10552         j = 0;
10553         byte = 0;
10554         for (i = 0; i < len; i++) {
10555                 c = mask_ptr[i];
10556                 if (isxdigit(c) == 0) {
10557                         /* invalid characters. */
10558                         printf("invalid input\n");
10559                         return;
10560                 }
10561                 val = xdigit2val(c);
10562                 if (i % 2) {
10563                         byte |= val;
10564                         filter.mask[j] = byte;
10565                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10566                         j++;
10567                         byte = 0;
10568                 } else
10569                         byte |= val << 4;
10570         }
10571         printf("\n");
10572
10573         if (!strcmp(res->ops, "add"))
10574                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10575                                 RTE_ETH_FILTER_FLEXIBLE,
10576                                 RTE_ETH_FILTER_ADD,
10577                                 &filter);
10578         else
10579                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10580                                 RTE_ETH_FILTER_FLEXIBLE,
10581                                 RTE_ETH_FILTER_DELETE,
10582                                 &filter);
10583
10584         if (ret < 0)
10585                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10586 }
10587
10588 cmdline_parse_token_string_t cmd_flex_filter_filter =
10589         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10590                                 filter, "flex_filter");
10591 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10592         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10593                                 port_id, UINT16);
10594 cmdline_parse_token_string_t cmd_flex_filter_ops =
10595         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10596                                 ops, "add#del");
10597 cmdline_parse_token_string_t cmd_flex_filter_len =
10598         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10599                                 len, "len");
10600 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10601         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10602                                 len_value, UINT8);
10603 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10604         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10605                                 bytes, "bytes");
10606 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10607         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10608                                 bytes_value, NULL);
10609 cmdline_parse_token_string_t cmd_flex_filter_mask =
10610         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10611                                 mask, "mask");
10612 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10613         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10614                                 mask_value, NULL);
10615 cmdline_parse_token_string_t cmd_flex_filter_priority =
10616         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10617                                 priority, "priority");
10618 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10619         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10620                                 priority_value, UINT8);
10621 cmdline_parse_token_string_t cmd_flex_filter_queue =
10622         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10623                                 queue, "queue");
10624 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10625         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10626                                 queue_id, UINT16);
10627 cmdline_parse_inst_t cmd_flex_filter = {
10628         .f = cmd_flex_filter_parsed,
10629         .data = NULL,
10630         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10631                 "<value> mask <value> priority <value> queue <queue_id>: "
10632                 "Add/Del a flex filter",
10633         .tokens = {
10634                 (void *)&cmd_flex_filter_filter,
10635                 (void *)&cmd_flex_filter_port_id,
10636                 (void *)&cmd_flex_filter_ops,
10637                 (void *)&cmd_flex_filter_len,
10638                 (void *)&cmd_flex_filter_len_value,
10639                 (void *)&cmd_flex_filter_bytes,
10640                 (void *)&cmd_flex_filter_bytes_value,
10641                 (void *)&cmd_flex_filter_mask,
10642                 (void *)&cmd_flex_filter_mask_value,
10643                 (void *)&cmd_flex_filter_priority,
10644                 (void *)&cmd_flex_filter_priority_value,
10645                 (void *)&cmd_flex_filter_queue,
10646                 (void *)&cmd_flex_filter_queue_id,
10647                 NULL,
10648         },
10649 };
10650
10651 /* *** Filters Control *** */
10652
10653 /* *** deal with ethertype filter *** */
10654 struct cmd_ethertype_filter_result {
10655         cmdline_fixed_string_t filter;
10656         portid_t port_id;
10657         cmdline_fixed_string_t ops;
10658         cmdline_fixed_string_t mac;
10659         struct rte_ether_addr mac_addr;
10660         cmdline_fixed_string_t ethertype;
10661         uint16_t ethertype_value;
10662         cmdline_fixed_string_t drop;
10663         cmdline_fixed_string_t queue;
10664         uint16_t  queue_id;
10665 };
10666
10667 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10668         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10669                                  filter, "ethertype_filter");
10670 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10671         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10672                               port_id, UINT16);
10673 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10674         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10675                                  ops, "add#del");
10676 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10677         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10678                                  mac, "mac_addr#mac_ignr");
10679 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10680         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10681                                      mac_addr);
10682 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10683         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10684                                  ethertype, "ethertype");
10685 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10686         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10687                               ethertype_value, UINT16);
10688 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10689         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10690                                  drop, "drop#fwd");
10691 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10692         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10693                                  queue, "queue");
10694 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10695         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10696                               queue_id, UINT16);
10697
10698 static void
10699 cmd_ethertype_filter_parsed(void *parsed_result,
10700                           __attribute__((unused)) struct cmdline *cl,
10701                           __attribute__((unused)) void *data)
10702 {
10703         struct cmd_ethertype_filter_result *res = parsed_result;
10704         struct rte_eth_ethertype_filter filter;
10705         int ret = 0;
10706
10707         ret = rte_eth_dev_filter_supported(res->port_id,
10708                         RTE_ETH_FILTER_ETHERTYPE);
10709         if (ret < 0) {
10710                 printf("ethertype filter is not supported on port %u.\n",
10711                         res->port_id);
10712                 return;
10713         }
10714
10715         memset(&filter, 0, sizeof(filter));
10716         if (!strcmp(res->mac, "mac_addr")) {
10717                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10718                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10719                         sizeof(struct rte_ether_addr));
10720         }
10721         if (!strcmp(res->drop, "drop"))
10722                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10723         filter.ether_type = res->ethertype_value;
10724         filter.queue = res->queue_id;
10725
10726         if (!strcmp(res->ops, "add"))
10727                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10728                                 RTE_ETH_FILTER_ETHERTYPE,
10729                                 RTE_ETH_FILTER_ADD,
10730                                 &filter);
10731         else
10732                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10733                                 RTE_ETH_FILTER_ETHERTYPE,
10734                                 RTE_ETH_FILTER_DELETE,
10735                                 &filter);
10736         if (ret < 0)
10737                 printf("ethertype filter programming error: (%s)\n",
10738                         strerror(-ret));
10739 }
10740
10741 cmdline_parse_inst_t cmd_ethertype_filter = {
10742         .f = cmd_ethertype_filter_parsed,
10743         .data = NULL,
10744         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10745                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10746                 "Add or delete an ethertype filter entry",
10747         .tokens = {
10748                 (void *)&cmd_ethertype_filter_filter,
10749                 (void *)&cmd_ethertype_filter_port_id,
10750                 (void *)&cmd_ethertype_filter_ops,
10751                 (void *)&cmd_ethertype_filter_mac,
10752                 (void *)&cmd_ethertype_filter_mac_addr,
10753                 (void *)&cmd_ethertype_filter_ethertype,
10754                 (void *)&cmd_ethertype_filter_ethertype_value,
10755                 (void *)&cmd_ethertype_filter_drop,
10756                 (void *)&cmd_ethertype_filter_queue,
10757                 (void *)&cmd_ethertype_filter_queue_id,
10758                 NULL,
10759         },
10760 };
10761
10762 /* *** deal with flow director filter *** */
10763 struct cmd_flow_director_result {
10764         cmdline_fixed_string_t flow_director_filter;
10765         portid_t port_id;
10766         cmdline_fixed_string_t mode;
10767         cmdline_fixed_string_t mode_value;
10768         cmdline_fixed_string_t ops;
10769         cmdline_fixed_string_t flow;
10770         cmdline_fixed_string_t flow_type;
10771         cmdline_fixed_string_t ether;
10772         uint16_t ether_type;
10773         cmdline_fixed_string_t src;
10774         cmdline_ipaddr_t ip_src;
10775         uint16_t port_src;
10776         cmdline_fixed_string_t dst;
10777         cmdline_ipaddr_t ip_dst;
10778         uint16_t port_dst;
10779         cmdline_fixed_string_t verify_tag;
10780         uint32_t verify_tag_value;
10781         cmdline_fixed_string_t tos;
10782         uint8_t tos_value;
10783         cmdline_fixed_string_t proto;
10784         uint8_t proto_value;
10785         cmdline_fixed_string_t ttl;
10786         uint8_t ttl_value;
10787         cmdline_fixed_string_t vlan;
10788         uint16_t vlan_value;
10789         cmdline_fixed_string_t flexbytes;
10790         cmdline_fixed_string_t flexbytes_value;
10791         cmdline_fixed_string_t pf_vf;
10792         cmdline_fixed_string_t drop;
10793         cmdline_fixed_string_t queue;
10794         uint16_t  queue_id;
10795         cmdline_fixed_string_t fd_id;
10796         uint32_t  fd_id_value;
10797         cmdline_fixed_string_t mac;
10798         struct rte_ether_addr mac_addr;
10799         cmdline_fixed_string_t tunnel;
10800         cmdline_fixed_string_t tunnel_type;
10801         cmdline_fixed_string_t tunnel_id;
10802         uint32_t tunnel_id_value;
10803         cmdline_fixed_string_t packet;
10804         char filepath[];
10805 };
10806
10807 static inline int
10808 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10809 {
10810         char s[256];
10811         const char *p, *p0 = q_arg;
10812         char *end;
10813         unsigned long int_fld;
10814         char *str_fld[max_num];
10815         int i;
10816         unsigned size;
10817         int ret = -1;
10818
10819         p = strchr(p0, '(');
10820         if (p == NULL)
10821                 return -1;
10822         ++p;
10823         p0 = strchr(p, ')');
10824         if (p0 == NULL)
10825                 return -1;
10826
10827         size = p0 - p;
10828         if (size >= sizeof(s))
10829                 return -1;
10830
10831         snprintf(s, sizeof(s), "%.*s", size, p);
10832         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10833         if (ret < 0 || ret > max_num)
10834                 return -1;
10835         for (i = 0; i < ret; i++) {
10836                 errno = 0;
10837                 int_fld = strtoul(str_fld[i], &end, 0);
10838                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10839                         return -1;
10840                 flexbytes[i] = (uint8_t)int_fld;
10841         }
10842         return ret;
10843 }
10844
10845 static uint16_t
10846 str2flowtype(char *string)
10847 {
10848         uint8_t i = 0;
10849         static const struct {
10850                 char str[32];
10851                 uint16_t type;
10852         } flowtype_str[] = {
10853                 {"raw", RTE_ETH_FLOW_RAW},
10854                 {"ipv4", RTE_ETH_FLOW_IPV4},
10855                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10856                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10857                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10858                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10859                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10860                 {"ipv6", RTE_ETH_FLOW_IPV6},
10861                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10862                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10863                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10864                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10865                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10866                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10867         };
10868
10869         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10870                 if (!strcmp(flowtype_str[i].str, string))
10871                         return flowtype_str[i].type;
10872         }
10873
10874         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10875                 return (uint16_t)atoi(string);
10876
10877         return RTE_ETH_FLOW_UNKNOWN;
10878 }
10879
10880 static enum rte_eth_fdir_tunnel_type
10881 str2fdir_tunneltype(char *string)
10882 {
10883         uint8_t i = 0;
10884
10885         static const struct {
10886                 char str[32];
10887                 enum rte_eth_fdir_tunnel_type type;
10888         } tunneltype_str[] = {
10889                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10890                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10891         };
10892
10893         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10894                 if (!strcmp(tunneltype_str[i].str, string))
10895                         return tunneltype_str[i].type;
10896         }
10897         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10898 }
10899
10900 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10901 do { \
10902         if ((ip_addr).family == AF_INET) \
10903                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10904         else { \
10905                 printf("invalid parameter.\n"); \
10906                 return; \
10907         } \
10908 } while (0)
10909
10910 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10911 do { \
10912         if ((ip_addr).family == AF_INET6) \
10913                 rte_memcpy(&(ip), \
10914                                  &((ip_addr).addr.ipv6), \
10915                                  sizeof(struct in6_addr)); \
10916         else { \
10917                 printf("invalid parameter.\n"); \
10918                 return; \
10919         } \
10920 } while (0)
10921
10922 static void
10923 cmd_flow_director_filter_parsed(void *parsed_result,
10924                           __attribute__((unused)) struct cmdline *cl,
10925                           __attribute__((unused)) void *data)
10926 {
10927         struct cmd_flow_director_result *res = parsed_result;
10928         struct rte_eth_fdir_filter entry;
10929         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10930         char *end;
10931         unsigned long vf_id;
10932         int ret = 0;
10933
10934         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10935         if (ret < 0) {
10936                 printf("flow director is not supported on port %u.\n",
10937                         res->port_id);
10938                 return;
10939         }
10940         memset(flexbytes, 0, sizeof(flexbytes));
10941         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10942
10943         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10944                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10945                         printf("Please set mode to MAC-VLAN.\n");
10946                         return;
10947                 }
10948         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10949                 if (strcmp(res->mode_value, "Tunnel")) {
10950                         printf("Please set mode to Tunnel.\n");
10951                         return;
10952                 }
10953         } else {
10954                 if (!strcmp(res->mode_value, "raw")) {
10955 #ifdef RTE_LIBRTE_I40E_PMD
10956                         struct rte_pmd_i40e_flow_type_mapping
10957                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10958                         struct rte_pmd_i40e_pkt_template_conf conf;
10959                         uint16_t flow_type = str2flowtype(res->flow_type);
10960                         uint16_t i, port = res->port_id;
10961                         uint8_t add;
10962
10963                         memset(&conf, 0, sizeof(conf));
10964
10965                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10966                                 printf("Invalid flow type specified.\n");
10967                                 return;
10968                         }
10969                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10970                                                                  mapping);
10971                         if (ret)
10972                                 return;
10973                         if (mapping[flow_type].pctype == 0ULL) {
10974                                 printf("Invalid flow type specified.\n");
10975                                 return;
10976                         }
10977                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10978                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10979                                         conf.input.pctype = i;
10980                                         break;
10981                                 }
10982                         }
10983
10984                         conf.input.packet = open_file(res->filepath,
10985                                                 &conf.input.length);
10986                         if (!conf.input.packet)
10987                                 return;
10988                         if (!strcmp(res->drop, "drop"))
10989                                 conf.action.behavior =
10990                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10991                         else
10992                                 conf.action.behavior =
10993                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10994                         conf.action.report_status =
10995                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10996                         conf.action.rx_queue = res->queue_id;
10997                         conf.soft_id = res->fd_id_value;
10998                         add  = strcmp(res->ops, "del") ? 1 : 0;
10999                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11000                                                                         &conf,
11001                                                                         add);
11002                         if (ret < 0)
11003                                 printf("flow director config error: (%s)\n",
11004                                        strerror(-ret));
11005                         close_file(conf.input.packet);
11006 #endif
11007                         return;
11008                 } else if (strcmp(res->mode_value, "IP")) {
11009                         printf("Please set mode to IP or raw.\n");
11010                         return;
11011                 }
11012                 entry.input.flow_type = str2flowtype(res->flow_type);
11013         }
11014
11015         ret = parse_flexbytes(res->flexbytes_value,
11016                                         flexbytes,
11017                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11018         if (ret < 0) {
11019                 printf("error: Cannot parse flexbytes input.\n");
11020                 return;
11021         }
11022
11023         switch (entry.input.flow_type) {
11024         case RTE_ETH_FLOW_FRAG_IPV4:
11025         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11026                 entry.input.flow.ip4_flow.proto = res->proto_value;
11027                 /* fall-through */
11028         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11029         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11030                 IPV4_ADDR_TO_UINT(res->ip_dst,
11031                         entry.input.flow.ip4_flow.dst_ip);
11032                 IPV4_ADDR_TO_UINT(res->ip_src,
11033                         entry.input.flow.ip4_flow.src_ip);
11034                 entry.input.flow.ip4_flow.tos = res->tos_value;
11035                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11036                 /* need convert to big endian. */
11037                 entry.input.flow.udp4_flow.dst_port =
11038                                 rte_cpu_to_be_16(res->port_dst);
11039                 entry.input.flow.udp4_flow.src_port =
11040                                 rte_cpu_to_be_16(res->port_src);
11041                 break;
11042         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11043                 IPV4_ADDR_TO_UINT(res->ip_dst,
11044                         entry.input.flow.sctp4_flow.ip.dst_ip);
11045                 IPV4_ADDR_TO_UINT(res->ip_src,
11046                         entry.input.flow.sctp4_flow.ip.src_ip);
11047                 entry.input.flow.ip4_flow.tos = res->tos_value;
11048                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11049                 /* need convert to big endian. */
11050                 entry.input.flow.sctp4_flow.dst_port =
11051                                 rte_cpu_to_be_16(res->port_dst);
11052                 entry.input.flow.sctp4_flow.src_port =
11053                                 rte_cpu_to_be_16(res->port_src);
11054                 entry.input.flow.sctp4_flow.verify_tag =
11055                                 rte_cpu_to_be_32(res->verify_tag_value);
11056                 break;
11057         case RTE_ETH_FLOW_FRAG_IPV6:
11058         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11059                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11060                 /* fall-through */
11061         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11062         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11063                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11064                         entry.input.flow.ipv6_flow.dst_ip);
11065                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11066                         entry.input.flow.ipv6_flow.src_ip);
11067                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11068                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11069                 /* need convert to big endian. */
11070                 entry.input.flow.udp6_flow.dst_port =
11071                                 rte_cpu_to_be_16(res->port_dst);
11072                 entry.input.flow.udp6_flow.src_port =
11073                                 rte_cpu_to_be_16(res->port_src);
11074                 break;
11075         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11076                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11077                         entry.input.flow.sctp6_flow.ip.dst_ip);
11078                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11079                         entry.input.flow.sctp6_flow.ip.src_ip);
11080                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11081                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11082                 /* need convert to big endian. */
11083                 entry.input.flow.sctp6_flow.dst_port =
11084                                 rte_cpu_to_be_16(res->port_dst);
11085                 entry.input.flow.sctp6_flow.src_port =
11086                                 rte_cpu_to_be_16(res->port_src);
11087                 entry.input.flow.sctp6_flow.verify_tag =
11088                                 rte_cpu_to_be_32(res->verify_tag_value);
11089                 break;
11090         case RTE_ETH_FLOW_L2_PAYLOAD:
11091                 entry.input.flow.l2_flow.ether_type =
11092                         rte_cpu_to_be_16(res->ether_type);
11093                 break;
11094         default:
11095                 break;
11096         }
11097
11098         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11099                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11100                                  &res->mac_addr,
11101                                  sizeof(struct rte_ether_addr));
11102
11103         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11104                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11105                                  &res->mac_addr,
11106                                  sizeof(struct rte_ether_addr));
11107                 entry.input.flow.tunnel_flow.tunnel_type =
11108                         str2fdir_tunneltype(res->tunnel_type);
11109                 entry.input.flow.tunnel_flow.tunnel_id =
11110                         rte_cpu_to_be_32(res->tunnel_id_value);
11111         }
11112
11113         rte_memcpy(entry.input.flow_ext.flexbytes,
11114                    flexbytes,
11115                    RTE_ETH_FDIR_MAX_FLEXLEN);
11116
11117         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11118
11119         entry.action.flex_off = 0;  /*use 0 by default */
11120         if (!strcmp(res->drop, "drop"))
11121                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11122         else
11123                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11124
11125         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11126             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11127                 if (!strcmp(res->pf_vf, "pf"))
11128                         entry.input.flow_ext.is_vf = 0;
11129                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11130                         struct rte_eth_dev_info dev_info;
11131
11132                         ret = eth_dev_info_get_print_err(res->port_id,
11133                                                 &dev_info);
11134                         if (ret != 0)
11135                                 return;
11136
11137                         errno = 0;
11138                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11139                         if (errno != 0 || *end != '\0' ||
11140                             vf_id >= dev_info.max_vfs) {
11141                                 printf("invalid parameter %s.\n", res->pf_vf);
11142                                 return;
11143                         }
11144                         entry.input.flow_ext.is_vf = 1;
11145                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11146                 } else {
11147                         printf("invalid parameter %s.\n", res->pf_vf);
11148                         return;
11149                 }
11150         }
11151
11152         /* set to report FD ID by default */
11153         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11154         entry.action.rx_queue = res->queue_id;
11155         entry.soft_id = res->fd_id_value;
11156         if (!strcmp(res->ops, "add"))
11157                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11158                                              RTE_ETH_FILTER_ADD, &entry);
11159         else if (!strcmp(res->ops, "del"))
11160                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11161                                              RTE_ETH_FILTER_DELETE, &entry);
11162         else
11163                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11164                                              RTE_ETH_FILTER_UPDATE, &entry);
11165         if (ret < 0)
11166                 printf("flow director programming error: (%s)\n",
11167                         strerror(-ret));
11168 }
11169
11170 cmdline_parse_token_string_t cmd_flow_director_filter =
11171         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11172                                  flow_director_filter, "flow_director_filter");
11173 cmdline_parse_token_num_t cmd_flow_director_port_id =
11174         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11175                               port_id, UINT16);
11176 cmdline_parse_token_string_t cmd_flow_director_ops =
11177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11178                                  ops, "add#del#update");
11179 cmdline_parse_token_string_t cmd_flow_director_flow =
11180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11181                                  flow, "flow");
11182 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11184                 flow_type, NULL);
11185 cmdline_parse_token_string_t cmd_flow_director_ether =
11186         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11187                                  ether, "ether");
11188 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11189         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11190                               ether_type, UINT16);
11191 cmdline_parse_token_string_t cmd_flow_director_src =
11192         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11193                                  src, "src");
11194 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11195         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11196                                  ip_src);
11197 cmdline_parse_token_num_t cmd_flow_director_port_src =
11198         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11199                               port_src, UINT16);
11200 cmdline_parse_token_string_t cmd_flow_director_dst =
11201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11202                                  dst, "dst");
11203 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11204         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11205                                  ip_dst);
11206 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11207         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11208                               port_dst, UINT16);
11209 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11210         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11211                                   verify_tag, "verify_tag");
11212 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11213         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11214                               verify_tag_value, UINT32);
11215 cmdline_parse_token_string_t cmd_flow_director_tos =
11216         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11217                                  tos, "tos");
11218 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11219         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11220                               tos_value, UINT8);
11221 cmdline_parse_token_string_t cmd_flow_director_proto =
11222         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11223                                  proto, "proto");
11224 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11225         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11226                               proto_value, UINT8);
11227 cmdline_parse_token_string_t cmd_flow_director_ttl =
11228         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11229                                  ttl, "ttl");
11230 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11231         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11232                               ttl_value, UINT8);
11233 cmdline_parse_token_string_t cmd_flow_director_vlan =
11234         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11235                                  vlan, "vlan");
11236 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11237         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11238                               vlan_value, UINT16);
11239 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11241                                  flexbytes, "flexbytes");
11242 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11244                               flexbytes_value, NULL);
11245 cmdline_parse_token_string_t cmd_flow_director_drop =
11246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11247                                  drop, "drop#fwd");
11248 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11250                               pf_vf, NULL);
11251 cmdline_parse_token_string_t cmd_flow_director_queue =
11252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11253                                  queue, "queue");
11254 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11256                               queue_id, UINT16);
11257 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11259                                  fd_id, "fd_id");
11260 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11261         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11262                               fd_id_value, UINT32);
11263
11264 cmdline_parse_token_string_t cmd_flow_director_mode =
11265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11266                                  mode, "mode");
11267 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11269                                  mode_value, "IP");
11270 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11272                                  mode_value, "MAC-VLAN");
11273 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11275                                  mode_value, "Tunnel");
11276 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11278                                  mode_value, "raw");
11279 cmdline_parse_token_string_t cmd_flow_director_mac =
11280         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11281                                  mac, "mac");
11282 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11283         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11284                                     mac_addr);
11285 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11287                                  tunnel, "tunnel");
11288 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11289         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11290                                  tunnel_type, "NVGRE#VxLAN");
11291 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11292         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11293                                  tunnel_id, "tunnel-id");
11294 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11295         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11296                               tunnel_id_value, UINT32);
11297 cmdline_parse_token_string_t cmd_flow_director_packet =
11298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11299                                  packet, "packet");
11300 cmdline_parse_token_string_t cmd_flow_director_filepath =
11301         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11302                                  filepath, NULL);
11303
11304 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11305         .f = cmd_flow_director_filter_parsed,
11306         .data = NULL,
11307         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11308                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11309                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11310                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11311                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11312                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11313                 "fd_id <fd_id_value>: "
11314                 "Add or delete an ip flow director entry on NIC",
11315         .tokens = {
11316                 (void *)&cmd_flow_director_filter,
11317                 (void *)&cmd_flow_director_port_id,
11318                 (void *)&cmd_flow_director_mode,
11319                 (void *)&cmd_flow_director_mode_ip,
11320                 (void *)&cmd_flow_director_ops,
11321                 (void *)&cmd_flow_director_flow,
11322                 (void *)&cmd_flow_director_flow_type,
11323                 (void *)&cmd_flow_director_src,
11324                 (void *)&cmd_flow_director_ip_src,
11325                 (void *)&cmd_flow_director_dst,
11326                 (void *)&cmd_flow_director_ip_dst,
11327                 (void *)&cmd_flow_director_tos,
11328                 (void *)&cmd_flow_director_tos_value,
11329                 (void *)&cmd_flow_director_proto,
11330                 (void *)&cmd_flow_director_proto_value,
11331                 (void *)&cmd_flow_director_ttl,
11332                 (void *)&cmd_flow_director_ttl_value,
11333                 (void *)&cmd_flow_director_vlan,
11334                 (void *)&cmd_flow_director_vlan_value,
11335                 (void *)&cmd_flow_director_flexbytes,
11336                 (void *)&cmd_flow_director_flexbytes_value,
11337                 (void *)&cmd_flow_director_drop,
11338                 (void *)&cmd_flow_director_pf_vf,
11339                 (void *)&cmd_flow_director_queue,
11340                 (void *)&cmd_flow_director_queue_id,
11341                 (void *)&cmd_flow_director_fd_id,
11342                 (void *)&cmd_flow_director_fd_id_value,
11343                 NULL,
11344         },
11345 };
11346
11347 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11348         .f = cmd_flow_director_filter_parsed,
11349         .data = NULL,
11350         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11351                 "director entry on NIC",
11352         .tokens = {
11353                 (void *)&cmd_flow_director_filter,
11354                 (void *)&cmd_flow_director_port_id,
11355                 (void *)&cmd_flow_director_mode,
11356                 (void *)&cmd_flow_director_mode_ip,
11357                 (void *)&cmd_flow_director_ops,
11358                 (void *)&cmd_flow_director_flow,
11359                 (void *)&cmd_flow_director_flow_type,
11360                 (void *)&cmd_flow_director_src,
11361                 (void *)&cmd_flow_director_ip_src,
11362                 (void *)&cmd_flow_director_port_src,
11363                 (void *)&cmd_flow_director_dst,
11364                 (void *)&cmd_flow_director_ip_dst,
11365                 (void *)&cmd_flow_director_port_dst,
11366                 (void *)&cmd_flow_director_tos,
11367                 (void *)&cmd_flow_director_tos_value,
11368                 (void *)&cmd_flow_director_ttl,
11369                 (void *)&cmd_flow_director_ttl_value,
11370                 (void *)&cmd_flow_director_vlan,
11371                 (void *)&cmd_flow_director_vlan_value,
11372                 (void *)&cmd_flow_director_flexbytes,
11373                 (void *)&cmd_flow_director_flexbytes_value,
11374                 (void *)&cmd_flow_director_drop,
11375                 (void *)&cmd_flow_director_pf_vf,
11376                 (void *)&cmd_flow_director_queue,
11377                 (void *)&cmd_flow_director_queue_id,
11378                 (void *)&cmd_flow_director_fd_id,
11379                 (void *)&cmd_flow_director_fd_id_value,
11380                 NULL,
11381         },
11382 };
11383
11384 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11385         .f = cmd_flow_director_filter_parsed,
11386         .data = NULL,
11387         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11388                 "director entry on NIC",
11389         .tokens = {
11390                 (void *)&cmd_flow_director_filter,
11391                 (void *)&cmd_flow_director_port_id,
11392                 (void *)&cmd_flow_director_mode,
11393                 (void *)&cmd_flow_director_mode_ip,
11394                 (void *)&cmd_flow_director_ops,
11395                 (void *)&cmd_flow_director_flow,
11396                 (void *)&cmd_flow_director_flow_type,
11397                 (void *)&cmd_flow_director_src,
11398                 (void *)&cmd_flow_director_ip_src,
11399                 (void *)&cmd_flow_director_port_src,
11400                 (void *)&cmd_flow_director_dst,
11401                 (void *)&cmd_flow_director_ip_dst,
11402                 (void *)&cmd_flow_director_port_dst,
11403                 (void *)&cmd_flow_director_verify_tag,
11404                 (void *)&cmd_flow_director_verify_tag_value,
11405                 (void *)&cmd_flow_director_tos,
11406                 (void *)&cmd_flow_director_tos_value,
11407                 (void *)&cmd_flow_director_ttl,
11408                 (void *)&cmd_flow_director_ttl_value,
11409                 (void *)&cmd_flow_director_vlan,
11410                 (void *)&cmd_flow_director_vlan_value,
11411                 (void *)&cmd_flow_director_flexbytes,
11412                 (void *)&cmd_flow_director_flexbytes_value,
11413                 (void *)&cmd_flow_director_drop,
11414                 (void *)&cmd_flow_director_pf_vf,
11415                 (void *)&cmd_flow_director_queue,
11416                 (void *)&cmd_flow_director_queue_id,
11417                 (void *)&cmd_flow_director_fd_id,
11418                 (void *)&cmd_flow_director_fd_id_value,
11419                 NULL,
11420         },
11421 };
11422
11423 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11424         .f = cmd_flow_director_filter_parsed,
11425         .data = NULL,
11426         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11427                 "director entry on NIC",
11428         .tokens = {
11429                 (void *)&cmd_flow_director_filter,
11430                 (void *)&cmd_flow_director_port_id,
11431                 (void *)&cmd_flow_director_mode,
11432                 (void *)&cmd_flow_director_mode_ip,
11433                 (void *)&cmd_flow_director_ops,
11434                 (void *)&cmd_flow_director_flow,
11435                 (void *)&cmd_flow_director_flow_type,
11436                 (void *)&cmd_flow_director_ether,
11437                 (void *)&cmd_flow_director_ether_type,
11438                 (void *)&cmd_flow_director_flexbytes,
11439                 (void *)&cmd_flow_director_flexbytes_value,
11440                 (void *)&cmd_flow_director_drop,
11441                 (void *)&cmd_flow_director_pf_vf,
11442                 (void *)&cmd_flow_director_queue,
11443                 (void *)&cmd_flow_director_queue_id,
11444                 (void *)&cmd_flow_director_fd_id,
11445                 (void *)&cmd_flow_director_fd_id_value,
11446                 NULL,
11447         },
11448 };
11449
11450 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11451         .f = cmd_flow_director_filter_parsed,
11452         .data = NULL,
11453         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11454                 "director entry on NIC",
11455         .tokens = {
11456                 (void *)&cmd_flow_director_filter,
11457                 (void *)&cmd_flow_director_port_id,
11458                 (void *)&cmd_flow_director_mode,
11459                 (void *)&cmd_flow_director_mode_mac_vlan,
11460                 (void *)&cmd_flow_director_ops,
11461                 (void *)&cmd_flow_director_mac,
11462                 (void *)&cmd_flow_director_mac_addr,
11463                 (void *)&cmd_flow_director_vlan,
11464                 (void *)&cmd_flow_director_vlan_value,
11465                 (void *)&cmd_flow_director_flexbytes,
11466                 (void *)&cmd_flow_director_flexbytes_value,
11467                 (void *)&cmd_flow_director_drop,
11468                 (void *)&cmd_flow_director_queue,
11469                 (void *)&cmd_flow_director_queue_id,
11470                 (void *)&cmd_flow_director_fd_id,
11471                 (void *)&cmd_flow_director_fd_id_value,
11472                 NULL,
11473         },
11474 };
11475
11476 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11477         .f = cmd_flow_director_filter_parsed,
11478         .data = NULL,
11479         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11480                 "director entry on NIC",
11481         .tokens = {
11482                 (void *)&cmd_flow_director_filter,
11483                 (void *)&cmd_flow_director_port_id,
11484                 (void *)&cmd_flow_director_mode,
11485                 (void *)&cmd_flow_director_mode_tunnel,
11486                 (void *)&cmd_flow_director_ops,
11487                 (void *)&cmd_flow_director_mac,
11488                 (void *)&cmd_flow_director_mac_addr,
11489                 (void *)&cmd_flow_director_vlan,
11490                 (void *)&cmd_flow_director_vlan_value,
11491                 (void *)&cmd_flow_director_tunnel,
11492                 (void *)&cmd_flow_director_tunnel_type,
11493                 (void *)&cmd_flow_director_tunnel_id,
11494                 (void *)&cmd_flow_director_tunnel_id_value,
11495                 (void *)&cmd_flow_director_flexbytes,
11496                 (void *)&cmd_flow_director_flexbytes_value,
11497                 (void *)&cmd_flow_director_drop,
11498                 (void *)&cmd_flow_director_queue,
11499                 (void *)&cmd_flow_director_queue_id,
11500                 (void *)&cmd_flow_director_fd_id,
11501                 (void *)&cmd_flow_director_fd_id_value,
11502                 NULL,
11503         },
11504 };
11505
11506 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11507         .f = cmd_flow_director_filter_parsed,
11508         .data = NULL,
11509         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11510                 "director entry on NIC",
11511         .tokens = {
11512                 (void *)&cmd_flow_director_filter,
11513                 (void *)&cmd_flow_director_port_id,
11514                 (void *)&cmd_flow_director_mode,
11515                 (void *)&cmd_flow_director_mode_raw,
11516                 (void *)&cmd_flow_director_ops,
11517                 (void *)&cmd_flow_director_flow,
11518                 (void *)&cmd_flow_director_flow_type,
11519                 (void *)&cmd_flow_director_drop,
11520                 (void *)&cmd_flow_director_queue,
11521                 (void *)&cmd_flow_director_queue_id,
11522                 (void *)&cmd_flow_director_fd_id,
11523                 (void *)&cmd_flow_director_fd_id_value,
11524                 (void *)&cmd_flow_director_packet,
11525                 (void *)&cmd_flow_director_filepath,
11526                 NULL,
11527         },
11528 };
11529
11530 struct cmd_flush_flow_director_result {
11531         cmdline_fixed_string_t flush_flow_director;
11532         portid_t port_id;
11533 };
11534
11535 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11536         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11537                                  flush_flow_director, "flush_flow_director");
11538 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11539         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11540                               port_id, UINT16);
11541
11542 static void
11543 cmd_flush_flow_director_parsed(void *parsed_result,
11544                           __attribute__((unused)) struct cmdline *cl,
11545                           __attribute__((unused)) void *data)
11546 {
11547         struct cmd_flow_director_result *res = parsed_result;
11548         int ret = 0;
11549
11550         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11551         if (ret < 0) {
11552                 printf("flow director is not supported on port %u.\n",
11553                         res->port_id);
11554                 return;
11555         }
11556
11557         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11558                         RTE_ETH_FILTER_FLUSH, NULL);
11559         if (ret < 0)
11560                 printf("flow director table flushing error: (%s)\n",
11561                         strerror(-ret));
11562 }
11563
11564 cmdline_parse_inst_t cmd_flush_flow_director = {
11565         .f = cmd_flush_flow_director_parsed,
11566         .data = NULL,
11567         .help_str = "flush_flow_director <port_id>: "
11568                 "Flush all flow director entries of a device on NIC",
11569         .tokens = {
11570                 (void *)&cmd_flush_flow_director_flush,
11571                 (void *)&cmd_flush_flow_director_port_id,
11572                 NULL,
11573         },
11574 };
11575
11576 /* *** deal with flow director mask *** */
11577 struct cmd_flow_director_mask_result {
11578         cmdline_fixed_string_t flow_director_mask;
11579         portid_t port_id;
11580         cmdline_fixed_string_t mode;
11581         cmdline_fixed_string_t mode_value;
11582         cmdline_fixed_string_t vlan;
11583         uint16_t vlan_mask;
11584         cmdline_fixed_string_t src_mask;
11585         cmdline_ipaddr_t ipv4_src;
11586         cmdline_ipaddr_t ipv6_src;
11587         uint16_t port_src;
11588         cmdline_fixed_string_t dst_mask;
11589         cmdline_ipaddr_t ipv4_dst;
11590         cmdline_ipaddr_t ipv6_dst;
11591         uint16_t port_dst;
11592         cmdline_fixed_string_t mac;
11593         uint8_t mac_addr_byte_mask;
11594         cmdline_fixed_string_t tunnel_id;
11595         uint32_t tunnel_id_mask;
11596         cmdline_fixed_string_t tunnel_type;
11597         uint8_t tunnel_type_mask;
11598 };
11599
11600 static void
11601 cmd_flow_director_mask_parsed(void *parsed_result,
11602                           __attribute__((unused)) struct cmdline *cl,
11603                           __attribute__((unused)) void *data)
11604 {
11605         struct cmd_flow_director_mask_result *res = parsed_result;
11606         struct rte_eth_fdir_masks *mask;
11607         struct rte_port *port;
11608
11609         port = &ports[res->port_id];
11610         /** Check if the port is not started **/
11611         if (port->port_status != RTE_PORT_STOPPED) {
11612                 printf("Please stop port %d first\n", res->port_id);
11613                 return;
11614         }
11615
11616         mask = &port->dev_conf.fdir_conf.mask;
11617
11618         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11619                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11620                         printf("Please set mode to MAC-VLAN.\n");
11621                         return;
11622                 }
11623
11624                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11625         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11626                 if (strcmp(res->mode_value, "Tunnel")) {
11627                         printf("Please set mode to Tunnel.\n");
11628                         return;
11629                 }
11630
11631                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11632                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11633                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11634                 mask->tunnel_type_mask = res->tunnel_type_mask;
11635         } else {
11636                 if (strcmp(res->mode_value, "IP")) {
11637                         printf("Please set mode to IP.\n");
11638                         return;
11639                 }
11640
11641                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11642                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11643                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11644                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11645                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11646                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11647                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11648         }
11649
11650         cmd_reconfig_device_queue(res->port_id, 1, 1);
11651 }
11652
11653 cmdline_parse_token_string_t cmd_flow_director_mask =
11654         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11655                                  flow_director_mask, "flow_director_mask");
11656 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11657         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11658                               port_id, UINT16);
11659 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11660         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11661                                  vlan, "vlan");
11662 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11663         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11664                               vlan_mask, UINT16);
11665 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11666         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11667                                  src_mask, "src_mask");
11668 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11669         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11670                                  ipv4_src);
11671 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11672         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11673                                  ipv6_src);
11674 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11675         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11676                               port_src, UINT16);
11677 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11678         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11679                                  dst_mask, "dst_mask");
11680 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11681         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11682                                  ipv4_dst);
11683 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11684         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11685                                  ipv6_dst);
11686 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11687         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11688                               port_dst, UINT16);
11689
11690 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11691         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11692                                  mode, "mode");
11693 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11694         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11695                                  mode_value, "IP");
11696 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11697         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11698                                  mode_value, "MAC-VLAN");
11699 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11701                                  mode_value, "Tunnel");
11702 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11703         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11704                                  mac, "mac");
11705 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11706         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11707                               mac_addr_byte_mask, UINT8);
11708 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11709         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11710                                  tunnel_type, "tunnel-type");
11711 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11712         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11713                               tunnel_type_mask, UINT8);
11714 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11715         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11716                                  tunnel_id, "tunnel-id");
11717 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11718         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11719                               tunnel_id_mask, UINT32);
11720
11721 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11722         .f = cmd_flow_director_mask_parsed,
11723         .data = NULL,
11724         .help_str = "flow_director_mask ... : "
11725                 "Set IP mode flow director's mask on NIC",
11726         .tokens = {
11727                 (void *)&cmd_flow_director_mask,
11728                 (void *)&cmd_flow_director_mask_port_id,
11729                 (void *)&cmd_flow_director_mask_mode,
11730                 (void *)&cmd_flow_director_mask_mode_ip,
11731                 (void *)&cmd_flow_director_mask_vlan,
11732                 (void *)&cmd_flow_director_mask_vlan_value,
11733                 (void *)&cmd_flow_director_mask_src,
11734                 (void *)&cmd_flow_director_mask_ipv4_src,
11735                 (void *)&cmd_flow_director_mask_ipv6_src,
11736                 (void *)&cmd_flow_director_mask_port_src,
11737                 (void *)&cmd_flow_director_mask_dst,
11738                 (void *)&cmd_flow_director_mask_ipv4_dst,
11739                 (void *)&cmd_flow_director_mask_ipv6_dst,
11740                 (void *)&cmd_flow_director_mask_port_dst,
11741                 NULL,
11742         },
11743 };
11744
11745 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11746         .f = cmd_flow_director_mask_parsed,
11747         .data = NULL,
11748         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11749                 "flow director's mask on NIC",
11750         .tokens = {
11751                 (void *)&cmd_flow_director_mask,
11752                 (void *)&cmd_flow_director_mask_port_id,
11753                 (void *)&cmd_flow_director_mask_mode,
11754                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11755                 (void *)&cmd_flow_director_mask_vlan,
11756                 (void *)&cmd_flow_director_mask_vlan_value,
11757                 NULL,
11758         },
11759 };
11760
11761 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11762         .f = cmd_flow_director_mask_parsed,
11763         .data = NULL,
11764         .help_str = "flow_director_mask ... : Set tunnel mode "
11765                 "flow director's mask on NIC",
11766         .tokens = {
11767                 (void *)&cmd_flow_director_mask,
11768                 (void *)&cmd_flow_director_mask_port_id,
11769                 (void *)&cmd_flow_director_mask_mode,
11770                 (void *)&cmd_flow_director_mask_mode_tunnel,
11771                 (void *)&cmd_flow_director_mask_vlan,
11772                 (void *)&cmd_flow_director_mask_vlan_value,
11773                 (void *)&cmd_flow_director_mask_mac,
11774                 (void *)&cmd_flow_director_mask_mac_value,
11775                 (void *)&cmd_flow_director_mask_tunnel_type,
11776                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11777                 (void *)&cmd_flow_director_mask_tunnel_id,
11778                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11779                 NULL,
11780         },
11781 };
11782
11783 /* *** deal with flow director mask on flexible payload *** */
11784 struct cmd_flow_director_flex_mask_result {
11785         cmdline_fixed_string_t flow_director_flexmask;
11786         portid_t port_id;
11787         cmdline_fixed_string_t flow;
11788         cmdline_fixed_string_t flow_type;
11789         cmdline_fixed_string_t mask;
11790 };
11791
11792 static void
11793 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11794                           __attribute__((unused)) struct cmdline *cl,
11795                           __attribute__((unused)) void *data)
11796 {
11797         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11798         struct rte_eth_fdir_info fdir_info;
11799         struct rte_eth_fdir_flex_mask flex_mask;
11800         struct rte_port *port;
11801         uint64_t flow_type_mask;
11802         uint16_t i;
11803         int ret;
11804
11805         port = &ports[res->port_id];
11806         /** Check if the port is not started **/
11807         if (port->port_status != RTE_PORT_STOPPED) {
11808                 printf("Please stop port %d first\n", res->port_id);
11809                 return;
11810         }
11811
11812         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11813         ret = parse_flexbytes(res->mask,
11814                         flex_mask.mask,
11815                         RTE_ETH_FDIR_MAX_FLEXLEN);
11816         if (ret < 0) {
11817                 printf("error: Cannot parse mask input.\n");
11818                 return;
11819         }
11820
11821         memset(&fdir_info, 0, sizeof(fdir_info));
11822         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11823                                 RTE_ETH_FILTER_INFO, &fdir_info);
11824         if (ret < 0) {
11825                 printf("Cannot get FDir filter info\n");
11826                 return;
11827         }
11828
11829         if (!strcmp(res->flow_type, "none")) {
11830                 /* means don't specify the flow type */
11831                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11832                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11833                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11834                                0, sizeof(struct rte_eth_fdir_flex_mask));
11835                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11836                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11837                                  &flex_mask,
11838                                  sizeof(struct rte_eth_fdir_flex_mask));
11839                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11840                 return;
11841         }
11842         flow_type_mask = fdir_info.flow_types_mask[0];
11843         if (!strcmp(res->flow_type, "all")) {
11844                 if (!flow_type_mask) {
11845                         printf("No flow type supported\n");
11846                         return;
11847                 }
11848                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11849                         if (flow_type_mask & (1ULL << i)) {
11850                                 flex_mask.flow_type = i;
11851                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11852                         }
11853                 }
11854                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11855                 return;
11856         }
11857         flex_mask.flow_type = str2flowtype(res->flow_type);
11858         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11859                 printf("Flow type %s not supported on port %d\n",
11860                                 res->flow_type, res->port_id);
11861                 return;
11862         }
11863         fdir_set_flex_mask(res->port_id, &flex_mask);
11864         cmd_reconfig_device_queue(res->port_id, 1, 1);
11865 }
11866
11867 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11869                                  flow_director_flexmask,
11870                                  "flow_director_flex_mask");
11871 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11872         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11873                               port_id, UINT16);
11874 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11875         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11876                                  flow, "flow");
11877 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11878         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11879                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11880                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11881 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11882         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11883                                  mask, NULL);
11884
11885 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11886         .f = cmd_flow_director_flex_mask_parsed,
11887         .data = NULL,
11888         .help_str = "flow_director_flex_mask ... : "
11889                 "Set flow director's flex mask on NIC",
11890         .tokens = {
11891                 (void *)&cmd_flow_director_flexmask,
11892                 (void *)&cmd_flow_director_flexmask_port_id,
11893                 (void *)&cmd_flow_director_flexmask_flow,
11894                 (void *)&cmd_flow_director_flexmask_flow_type,
11895                 (void *)&cmd_flow_director_flexmask_mask,
11896                 NULL,
11897         },
11898 };
11899
11900 /* *** deal with flow director flexible payload configuration *** */
11901 struct cmd_flow_director_flexpayload_result {
11902         cmdline_fixed_string_t flow_director_flexpayload;
11903         portid_t port_id;
11904         cmdline_fixed_string_t payload_layer;
11905         cmdline_fixed_string_t payload_cfg;
11906 };
11907
11908 static inline int
11909 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11910 {
11911         char s[256];
11912         const char *p, *p0 = q_arg;
11913         char *end;
11914         unsigned long int_fld;
11915         char *str_fld[max_num];
11916         int i;
11917         unsigned size;
11918         int ret = -1;
11919
11920         p = strchr(p0, '(');
11921         if (p == NULL)
11922                 return -1;
11923         ++p;
11924         p0 = strchr(p, ')');
11925         if (p0 == NULL)
11926                 return -1;
11927
11928         size = p0 - p;
11929         if (size >= sizeof(s))
11930                 return -1;
11931
11932         snprintf(s, sizeof(s), "%.*s", size, p);
11933         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11934         if (ret < 0 || ret > max_num)
11935                 return -1;
11936         for (i = 0; i < ret; i++) {
11937                 errno = 0;
11938                 int_fld = strtoul(str_fld[i], &end, 0);
11939                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11940                         return -1;
11941                 offsets[i] = (uint16_t)int_fld;
11942         }
11943         return ret;
11944 }
11945
11946 static void
11947 cmd_flow_director_flxpld_parsed(void *parsed_result,
11948                           __attribute__((unused)) struct cmdline *cl,
11949                           __attribute__((unused)) void *data)
11950 {
11951         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11952         struct rte_eth_flex_payload_cfg flex_cfg;
11953         struct rte_port *port;
11954         int ret = 0;
11955
11956         port = &ports[res->port_id];
11957         /** Check if the port is not started **/
11958         if (port->port_status != RTE_PORT_STOPPED) {
11959                 printf("Please stop port %d first\n", res->port_id);
11960                 return;
11961         }
11962
11963         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11964
11965         if (!strcmp(res->payload_layer, "raw"))
11966                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11967         else if (!strcmp(res->payload_layer, "l2"))
11968                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11969         else if (!strcmp(res->payload_layer, "l3"))
11970                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11971         else if (!strcmp(res->payload_layer, "l4"))
11972                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11973
11974         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11975                             RTE_ETH_FDIR_MAX_FLEXLEN);
11976         if (ret < 0) {
11977                 printf("error: Cannot parse flex payload input.\n");
11978                 return;
11979         }
11980
11981         fdir_set_flex_payload(res->port_id, &flex_cfg);
11982         cmd_reconfig_device_queue(res->port_id, 1, 1);
11983 }
11984
11985 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11986         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11987                                  flow_director_flexpayload,
11988                                  "flow_director_flex_payload");
11989 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11990         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11991                               port_id, UINT16);
11992 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11993         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11994                                  payload_layer, "raw#l2#l3#l4");
11995 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11996         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11997                                  payload_cfg, NULL);
11998
11999 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12000         .f = cmd_flow_director_flxpld_parsed,
12001         .data = NULL,
12002         .help_str = "flow_director_flexpayload ... : "
12003                 "Set flow director's flex payload on NIC",
12004         .tokens = {
12005                 (void *)&cmd_flow_director_flexpayload,
12006                 (void *)&cmd_flow_director_flexpayload_port_id,
12007                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12008                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12009                 NULL,
12010         },
12011 };
12012
12013 /* Generic flow interface command. */
12014 extern cmdline_parse_inst_t cmd_flow;
12015
12016 /* *** Classification Filters Control *** */
12017 /* *** Get symmetric hash enable per port *** */
12018 struct cmd_get_sym_hash_ena_per_port_result {
12019         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12020         portid_t port_id;
12021 };
12022
12023 static void
12024 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12025                                  __rte_unused struct cmdline *cl,
12026                                  __rte_unused void *data)
12027 {
12028         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12029         struct rte_eth_hash_filter_info info;
12030         int ret;
12031
12032         if (rte_eth_dev_filter_supported(res->port_id,
12033                                 RTE_ETH_FILTER_HASH) < 0) {
12034                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12035                                                         res->port_id);
12036                 return;
12037         }
12038
12039         memset(&info, 0, sizeof(info));
12040         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12041         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12042                                                 RTE_ETH_FILTER_GET, &info);
12043
12044         if (ret < 0) {
12045                 printf("Cannot get symmetric hash enable per port "
12046                                         "on port %u\n", res->port_id);
12047                 return;
12048         }
12049
12050         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12051                                 "enabled" : "disabled", res->port_id);
12052 }
12053
12054 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12055         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12056                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12057 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12058         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12059                 port_id, UINT16);
12060
12061 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12062         .f = cmd_get_sym_hash_per_port_parsed,
12063         .data = NULL,
12064         .help_str = "get_sym_hash_ena_per_port <port_id>",
12065         .tokens = {
12066                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12067                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12068                 NULL,
12069         },
12070 };
12071
12072 /* *** Set symmetric hash enable per port *** */
12073 struct cmd_set_sym_hash_ena_per_port_result {
12074         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12075         cmdline_fixed_string_t enable;
12076         portid_t port_id;
12077 };
12078
12079 static void
12080 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12081                                  __rte_unused struct cmdline *cl,
12082                                  __rte_unused void *data)
12083 {
12084         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12085         struct rte_eth_hash_filter_info info;
12086         int ret;
12087
12088         if (rte_eth_dev_filter_supported(res->port_id,
12089                                 RTE_ETH_FILTER_HASH) < 0) {
12090                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12091                                                         res->port_id);
12092                 return;
12093         }
12094
12095         memset(&info, 0, sizeof(info));
12096         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12097         if (!strcmp(res->enable, "enable"))
12098                 info.info.enable = 1;
12099         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12100                                         RTE_ETH_FILTER_SET, &info);
12101         if (ret < 0) {
12102                 printf("Cannot set symmetric hash enable per port on "
12103                                         "port %u\n", res->port_id);
12104                 return;
12105         }
12106         printf("Symmetric hash has been set to %s on port %u\n",
12107                                         res->enable, res->port_id);
12108 }
12109
12110 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12111         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12112                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12113 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12114         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12115                 port_id, UINT16);
12116 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12117         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12118                 enable, "enable#disable");
12119
12120 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12121         .f = cmd_set_sym_hash_per_port_parsed,
12122         .data = NULL,
12123         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12124         .tokens = {
12125                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12126                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12127                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12128                 NULL,
12129         },
12130 };
12131
12132 /* Get global config of hash function */
12133 struct cmd_get_hash_global_config_result {
12134         cmdline_fixed_string_t get_hash_global_config;
12135         portid_t port_id;
12136 };
12137
12138 static char *
12139 flowtype_to_str(uint16_t ftype)
12140 {
12141         uint16_t i;
12142         static struct {
12143                 char str[16];
12144                 uint16_t ftype;
12145         } ftype_table[] = {
12146                 {"ipv4", RTE_ETH_FLOW_IPV4},
12147                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12148                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12149                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12150                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12151                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12152                 {"ipv6", RTE_ETH_FLOW_IPV6},
12153                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12154                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12155                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12156                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12157                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12158                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12159                 {"port", RTE_ETH_FLOW_PORT},
12160                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12161                 {"geneve", RTE_ETH_FLOW_GENEVE},
12162                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12163                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12164         };
12165
12166         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12167                 if (ftype_table[i].ftype == ftype)
12168                         return ftype_table[i].str;
12169         }
12170
12171         return NULL;
12172 }
12173
12174 static void
12175 cmd_get_hash_global_config_parsed(void *parsed_result,
12176                                   __rte_unused struct cmdline *cl,
12177                                   __rte_unused void *data)
12178 {
12179         struct cmd_get_hash_global_config_result *res = parsed_result;
12180         struct rte_eth_hash_filter_info info;
12181         uint32_t idx, offset;
12182         uint16_t i;
12183         char *str;
12184         int ret;
12185
12186         if (rte_eth_dev_filter_supported(res->port_id,
12187                         RTE_ETH_FILTER_HASH) < 0) {
12188                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12189                                                         res->port_id);
12190                 return;
12191         }
12192
12193         memset(&info, 0, sizeof(info));
12194         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12195         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12196                                         RTE_ETH_FILTER_GET, &info);
12197         if (ret < 0) {
12198                 printf("Cannot get hash global configurations by port %d\n",
12199                                                         res->port_id);
12200                 return;
12201         }
12202
12203         switch (info.info.global_conf.hash_func) {
12204         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12205                 printf("Hash function is Toeplitz\n");
12206                 break;
12207         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12208                 printf("Hash function is Simple XOR\n");
12209                 break;
12210         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12211                 printf("Hash function is Symmetric Toeplitz\n");
12212                 break;
12213         default:
12214                 printf("Unknown hash function\n");
12215                 break;
12216         }
12217
12218         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12219                 idx = i / UINT64_BIT;
12220                 offset = i % UINT64_BIT;
12221                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12222                                                 (1ULL << offset)))
12223                         continue;
12224                 str = flowtype_to_str(i);
12225                 if (!str)
12226                         continue;
12227                 printf("Symmetric hash is %s globally for flow type %s "
12228                                                         "by port %d\n",
12229                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12230                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12231                                                         res->port_id);
12232         }
12233 }
12234
12235 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12236         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12237                 get_hash_global_config, "get_hash_global_config");
12238 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12239         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12240                 port_id, UINT16);
12241
12242 cmdline_parse_inst_t cmd_get_hash_global_config = {
12243         .f = cmd_get_hash_global_config_parsed,
12244         .data = NULL,
12245         .help_str = "get_hash_global_config <port_id>",
12246         .tokens = {
12247                 (void *)&cmd_get_hash_global_config_all,
12248                 (void *)&cmd_get_hash_global_config_port_id,
12249                 NULL,
12250         },
12251 };
12252
12253 /* Set global config of hash function */
12254 struct cmd_set_hash_global_config_result {
12255         cmdline_fixed_string_t set_hash_global_config;
12256         portid_t port_id;
12257         cmdline_fixed_string_t hash_func;
12258         cmdline_fixed_string_t flow_type;
12259         cmdline_fixed_string_t enable;
12260 };
12261
12262 static void
12263 cmd_set_hash_global_config_parsed(void *parsed_result,
12264                                   __rte_unused struct cmdline *cl,
12265                                   __rte_unused void *data)
12266 {
12267         struct cmd_set_hash_global_config_result *res = parsed_result;
12268         struct rte_eth_hash_filter_info info;
12269         uint32_t ftype, idx, offset;
12270         int ret;
12271
12272         if (rte_eth_dev_filter_supported(res->port_id,
12273                                 RTE_ETH_FILTER_HASH) < 0) {
12274                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12275                                                         res->port_id);
12276                 return;
12277         }
12278         memset(&info, 0, sizeof(info));
12279         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12280         if (!strcmp(res->hash_func, "toeplitz"))
12281                 info.info.global_conf.hash_func =
12282                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12283         else if (!strcmp(res->hash_func, "simple_xor"))
12284                 info.info.global_conf.hash_func =
12285                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12286         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12287                 info.info.global_conf.hash_func =
12288                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12289         else if (!strcmp(res->hash_func, "default"))
12290                 info.info.global_conf.hash_func =
12291                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12292
12293         ftype = str2flowtype(res->flow_type);
12294         idx = ftype / UINT64_BIT;
12295         offset = ftype % UINT64_BIT;
12296         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12297         if (!strcmp(res->enable, "enable"))
12298                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12299                                                 (1ULL << offset);
12300         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12301                                         RTE_ETH_FILTER_SET, &info);
12302         if (ret < 0)
12303                 printf("Cannot set global hash configurations by port %d\n",
12304                                                         res->port_id);
12305         else
12306                 printf("Global hash configurations have been set "
12307                         "successfully by port %d\n", res->port_id);
12308 }
12309
12310 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12311         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12312                 set_hash_global_config, "set_hash_global_config");
12313 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12314         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12315                 port_id, UINT16);
12316 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12317         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12318                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12319 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12320         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12321                 flow_type,
12322                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12323                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12324 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12325         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12326                 enable, "enable#disable");
12327
12328 cmdline_parse_inst_t cmd_set_hash_global_config = {
12329         .f = cmd_set_hash_global_config_parsed,
12330         .data = NULL,
12331         .help_str = "set_hash_global_config <port_id> "
12332                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12333                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12334                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12335                 "l2_payload enable|disable",
12336         .tokens = {
12337                 (void *)&cmd_set_hash_global_config_all,
12338                 (void *)&cmd_set_hash_global_config_port_id,
12339                 (void *)&cmd_set_hash_global_config_hash_func,
12340                 (void *)&cmd_set_hash_global_config_flow_type,
12341                 (void *)&cmd_set_hash_global_config_enable,
12342                 NULL,
12343         },
12344 };
12345
12346 /* Set hash input set */
12347 struct cmd_set_hash_input_set_result {
12348         cmdline_fixed_string_t set_hash_input_set;
12349         portid_t port_id;
12350         cmdline_fixed_string_t flow_type;
12351         cmdline_fixed_string_t inset_field;
12352         cmdline_fixed_string_t select;
12353 };
12354
12355 static enum rte_eth_input_set_field
12356 str2inset(char *string)
12357 {
12358         uint16_t i;
12359
12360         static const struct {
12361                 char str[32];
12362                 enum rte_eth_input_set_field inset;
12363         } inset_table[] = {
12364                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12365                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12366                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12367                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12368                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12369                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12370                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12371                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12372                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12373                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12374                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12375                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12376                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12377                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12378                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12379                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12380                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12381                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12382                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12383                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12384                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12385                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12386                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12387                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12388                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12389                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12390                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12391                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12392                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12393                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12394                 {"none", RTE_ETH_INPUT_SET_NONE},
12395         };
12396
12397         for (i = 0; i < RTE_DIM(inset_table); i++) {
12398                 if (!strcmp(string, inset_table[i].str))
12399                         return inset_table[i].inset;
12400         }
12401
12402         return RTE_ETH_INPUT_SET_UNKNOWN;
12403 }
12404
12405 static void
12406 cmd_set_hash_input_set_parsed(void *parsed_result,
12407                               __rte_unused struct cmdline *cl,
12408                               __rte_unused void *data)
12409 {
12410         struct cmd_set_hash_input_set_result *res = parsed_result;
12411         struct rte_eth_hash_filter_info info;
12412
12413         memset(&info, 0, sizeof(info));
12414         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12415         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12416         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12417         info.info.input_set_conf.inset_size = 1;
12418         if (!strcmp(res->select, "select"))
12419                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12420         else if (!strcmp(res->select, "add"))
12421                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12422         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12423                                 RTE_ETH_FILTER_SET, &info);
12424 }
12425
12426 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12427         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12428                 set_hash_input_set, "set_hash_input_set");
12429 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12430         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12431                 port_id, UINT16);
12432 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12433         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12434                 flow_type, NULL);
12435 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12436         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12437                 inset_field,
12438                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12439                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12440                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12441                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12442                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12443                 "fld-8th#none");
12444 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12445         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12446                 select, "select#add");
12447
12448 cmdline_parse_inst_t cmd_set_hash_input_set = {
12449         .f = cmd_set_hash_input_set_parsed,
12450         .data = NULL,
12451         .help_str = "set_hash_input_set <port_id> "
12452         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12453         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12454         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12455         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12456         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12457         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12458         "fld-7th|fld-8th|none select|add",
12459         .tokens = {
12460                 (void *)&cmd_set_hash_input_set_cmd,
12461                 (void *)&cmd_set_hash_input_set_port_id,
12462                 (void *)&cmd_set_hash_input_set_flow_type,
12463                 (void *)&cmd_set_hash_input_set_field,
12464                 (void *)&cmd_set_hash_input_set_select,
12465                 NULL,
12466         },
12467 };
12468
12469 /* Set flow director input set */
12470 struct cmd_set_fdir_input_set_result {
12471         cmdline_fixed_string_t set_fdir_input_set;
12472         portid_t port_id;
12473         cmdline_fixed_string_t flow_type;
12474         cmdline_fixed_string_t inset_field;
12475         cmdline_fixed_string_t select;
12476 };
12477
12478 static void
12479 cmd_set_fdir_input_set_parsed(void *parsed_result,
12480         __rte_unused struct cmdline *cl,
12481         __rte_unused void *data)
12482 {
12483         struct cmd_set_fdir_input_set_result *res = parsed_result;
12484         struct rte_eth_fdir_filter_info info;
12485
12486         memset(&info, 0, sizeof(info));
12487         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12488         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12489         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12490         info.info.input_set_conf.inset_size = 1;
12491         if (!strcmp(res->select, "select"))
12492                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12493         else if (!strcmp(res->select, "add"))
12494                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12495         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12496                 RTE_ETH_FILTER_SET, &info);
12497 }
12498
12499 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12500         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12501         set_fdir_input_set, "set_fdir_input_set");
12502 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12503         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12504         port_id, UINT16);
12505 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12506         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12507         flow_type,
12508         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12509         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12510 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12511         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12512         inset_field,
12513         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12514         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12515         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12516         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12517         "sctp-veri-tag#none");
12518 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12519         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12520         select, "select#add");
12521
12522 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12523         .f = cmd_set_fdir_input_set_parsed,
12524         .data = NULL,
12525         .help_str = "set_fdir_input_set <port_id> "
12526         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12527         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12528         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12529         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12530         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12531         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12532         "sctp-veri-tag|none select|add",
12533         .tokens = {
12534                 (void *)&cmd_set_fdir_input_set_cmd,
12535                 (void *)&cmd_set_fdir_input_set_port_id,
12536                 (void *)&cmd_set_fdir_input_set_flow_type,
12537                 (void *)&cmd_set_fdir_input_set_field,
12538                 (void *)&cmd_set_fdir_input_set_select,
12539                 NULL,
12540         },
12541 };
12542
12543 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12544 struct cmd_mcast_addr_result {
12545         cmdline_fixed_string_t mcast_addr_cmd;
12546         cmdline_fixed_string_t what;
12547         uint16_t port_num;
12548         struct rte_ether_addr mc_addr;
12549 };
12550
12551 static void cmd_mcast_addr_parsed(void *parsed_result,
12552                 __attribute__((unused)) struct cmdline *cl,
12553                 __attribute__((unused)) void *data)
12554 {
12555         struct cmd_mcast_addr_result *res = parsed_result;
12556
12557         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12558                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12559                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12560                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12561                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12562                 return;
12563         }
12564         if (strcmp(res->what, "add") == 0)
12565                 mcast_addr_add(res->port_num, &res->mc_addr);
12566         else
12567                 mcast_addr_remove(res->port_num, &res->mc_addr);
12568 }
12569
12570 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12571         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12572                                  mcast_addr_cmd, "mcast_addr");
12573 cmdline_parse_token_string_t cmd_mcast_addr_what =
12574         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12575                                  "add#remove");
12576 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12577         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12578 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12579         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12580
12581 cmdline_parse_inst_t cmd_mcast_addr = {
12582         .f = cmd_mcast_addr_parsed,
12583         .data = (void *)0,
12584         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12585                 "Add/Remove multicast MAC address on port_id",
12586         .tokens = {
12587                 (void *)&cmd_mcast_addr_cmd,
12588                 (void *)&cmd_mcast_addr_what,
12589                 (void *)&cmd_mcast_addr_portnum,
12590                 (void *)&cmd_mcast_addr_addr,
12591                 NULL,
12592         },
12593 };
12594
12595 /* l2 tunnel config
12596  * only support E-tag now.
12597  */
12598
12599 /* Ether type config */
12600 struct cmd_config_l2_tunnel_eth_type_result {
12601         cmdline_fixed_string_t port;
12602         cmdline_fixed_string_t config;
12603         cmdline_fixed_string_t all;
12604         portid_t id;
12605         cmdline_fixed_string_t l2_tunnel;
12606         cmdline_fixed_string_t l2_tunnel_type;
12607         cmdline_fixed_string_t eth_type;
12608         uint16_t eth_type_val;
12609 };
12610
12611 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12612         TOKEN_STRING_INITIALIZER
12613                 (struct cmd_config_l2_tunnel_eth_type_result,
12614                  port, "port");
12615 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12616         TOKEN_STRING_INITIALIZER
12617                 (struct cmd_config_l2_tunnel_eth_type_result,
12618                  config, "config");
12619 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12620         TOKEN_STRING_INITIALIZER
12621                 (struct cmd_config_l2_tunnel_eth_type_result,
12622                  all, "all");
12623 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12624         TOKEN_NUM_INITIALIZER
12625                 (struct cmd_config_l2_tunnel_eth_type_result,
12626                  id, UINT16);
12627 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12628         TOKEN_STRING_INITIALIZER
12629                 (struct cmd_config_l2_tunnel_eth_type_result,
12630                  l2_tunnel, "l2-tunnel");
12631 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12632         TOKEN_STRING_INITIALIZER
12633                 (struct cmd_config_l2_tunnel_eth_type_result,
12634                  l2_tunnel_type, "E-tag");
12635 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12636         TOKEN_STRING_INITIALIZER
12637                 (struct cmd_config_l2_tunnel_eth_type_result,
12638                  eth_type, "ether-type");
12639 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12640         TOKEN_NUM_INITIALIZER
12641                 (struct cmd_config_l2_tunnel_eth_type_result,
12642                  eth_type_val, UINT16);
12643
12644 static enum rte_eth_tunnel_type
12645 str2fdir_l2_tunnel_type(char *string)
12646 {
12647         uint32_t i = 0;
12648
12649         static const struct {
12650                 char str[32];
12651                 enum rte_eth_tunnel_type type;
12652         } l2_tunnel_type_str[] = {
12653                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12654         };
12655
12656         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12657                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12658                         return l2_tunnel_type_str[i].type;
12659         }
12660         return RTE_TUNNEL_TYPE_NONE;
12661 }
12662
12663 /* ether type config for all ports */
12664 static void
12665 cmd_config_l2_tunnel_eth_type_all_parsed
12666         (void *parsed_result,
12667          __attribute__((unused)) struct cmdline *cl,
12668          __attribute__((unused)) void *data)
12669 {
12670         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12671         struct rte_eth_l2_tunnel_conf entry;
12672         portid_t pid;
12673
12674         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12675         entry.ether_type = res->eth_type_val;
12676
12677         RTE_ETH_FOREACH_DEV(pid) {
12678                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12679         }
12680 }
12681
12682 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12683         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12684         .data = NULL,
12685         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12686         .tokens = {
12687                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12688                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12689                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12690                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12691                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12692                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12693                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12694                 NULL,
12695         },
12696 };
12697
12698 /* ether type config for a specific port */
12699 static void
12700 cmd_config_l2_tunnel_eth_type_specific_parsed(
12701         void *parsed_result,
12702         __attribute__((unused)) struct cmdline *cl,
12703         __attribute__((unused)) void *data)
12704 {
12705         struct cmd_config_l2_tunnel_eth_type_result *res =
12706                  parsed_result;
12707         struct rte_eth_l2_tunnel_conf entry;
12708
12709         if (port_id_is_invalid(res->id, ENABLED_WARN))
12710                 return;
12711
12712         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12713         entry.ether_type = res->eth_type_val;
12714
12715         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12716 }
12717
12718 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12719         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12720         .data = NULL,
12721         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12722         .tokens = {
12723                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12724                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12725                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12726                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12727                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12728                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12729                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12730                 NULL,
12731         },
12732 };
12733
12734 /* Enable/disable l2 tunnel */
12735 struct cmd_config_l2_tunnel_en_dis_result {
12736         cmdline_fixed_string_t port;
12737         cmdline_fixed_string_t config;
12738         cmdline_fixed_string_t all;
12739         portid_t id;
12740         cmdline_fixed_string_t l2_tunnel;
12741         cmdline_fixed_string_t l2_tunnel_type;
12742         cmdline_fixed_string_t en_dis;
12743 };
12744
12745 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12746         TOKEN_STRING_INITIALIZER
12747                 (struct cmd_config_l2_tunnel_en_dis_result,
12748                  port, "port");
12749 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12750         TOKEN_STRING_INITIALIZER
12751                 (struct cmd_config_l2_tunnel_en_dis_result,
12752                  config, "config");
12753 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12754         TOKEN_STRING_INITIALIZER
12755                 (struct cmd_config_l2_tunnel_en_dis_result,
12756                  all, "all");
12757 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12758         TOKEN_NUM_INITIALIZER
12759                 (struct cmd_config_l2_tunnel_en_dis_result,
12760                  id, UINT16);
12761 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12762         TOKEN_STRING_INITIALIZER
12763                 (struct cmd_config_l2_tunnel_en_dis_result,
12764                  l2_tunnel, "l2-tunnel");
12765 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12766         TOKEN_STRING_INITIALIZER
12767                 (struct cmd_config_l2_tunnel_en_dis_result,
12768                  l2_tunnel_type, "E-tag");
12769 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12770         TOKEN_STRING_INITIALIZER
12771                 (struct cmd_config_l2_tunnel_en_dis_result,
12772                  en_dis, "enable#disable");
12773
12774 /* enable/disable l2 tunnel for all ports */
12775 static void
12776 cmd_config_l2_tunnel_en_dis_all_parsed(
12777         void *parsed_result,
12778         __attribute__((unused)) struct cmdline *cl,
12779         __attribute__((unused)) void *data)
12780 {
12781         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12782         struct rte_eth_l2_tunnel_conf entry;
12783         portid_t pid;
12784         uint8_t en;
12785
12786         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12787
12788         if (!strcmp("enable", res->en_dis))
12789                 en = 1;
12790         else
12791                 en = 0;
12792
12793         RTE_ETH_FOREACH_DEV(pid) {
12794                 rte_eth_dev_l2_tunnel_offload_set(pid,
12795                                                   &entry,
12796                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12797                                                   en);
12798         }
12799 }
12800
12801 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12802         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12803         .data = NULL,
12804         .help_str = "port config all l2-tunnel E-tag enable|disable",
12805         .tokens = {
12806                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12807                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12808                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12809                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12810                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12811                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12812                 NULL,
12813         },
12814 };
12815
12816 /* enable/disable l2 tunnel for a port */
12817 static void
12818 cmd_config_l2_tunnel_en_dis_specific_parsed(
12819         void *parsed_result,
12820         __attribute__((unused)) struct cmdline *cl,
12821         __attribute__((unused)) void *data)
12822 {
12823         struct cmd_config_l2_tunnel_en_dis_result *res =
12824                 parsed_result;
12825         struct rte_eth_l2_tunnel_conf entry;
12826
12827         if (port_id_is_invalid(res->id, ENABLED_WARN))
12828                 return;
12829
12830         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12831
12832         if (!strcmp("enable", res->en_dis))
12833                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12834                                                   &entry,
12835                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12836                                                   1);
12837         else
12838                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12839                                                   &entry,
12840                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12841                                                   0);
12842 }
12843
12844 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12845         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12846         .data = NULL,
12847         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12848         .tokens = {
12849                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12850                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12851                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12852                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12853                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12854                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12855                 NULL,
12856         },
12857 };
12858
12859 /* E-tag configuration */
12860
12861 /* Common result structure for all E-tag configuration */
12862 struct cmd_config_e_tag_result {
12863         cmdline_fixed_string_t e_tag;
12864         cmdline_fixed_string_t set;
12865         cmdline_fixed_string_t insertion;
12866         cmdline_fixed_string_t stripping;
12867         cmdline_fixed_string_t forwarding;
12868         cmdline_fixed_string_t filter;
12869         cmdline_fixed_string_t add;
12870         cmdline_fixed_string_t del;
12871         cmdline_fixed_string_t on;
12872         cmdline_fixed_string_t off;
12873         cmdline_fixed_string_t on_off;
12874         cmdline_fixed_string_t port_tag_id;
12875         uint32_t port_tag_id_val;
12876         cmdline_fixed_string_t e_tag_id;
12877         uint16_t e_tag_id_val;
12878         cmdline_fixed_string_t dst_pool;
12879         uint8_t dst_pool_val;
12880         cmdline_fixed_string_t port;
12881         portid_t port_id;
12882         cmdline_fixed_string_t vf;
12883         uint8_t vf_id;
12884 };
12885
12886 /* Common CLI fields for all E-tag configuration */
12887 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12888         TOKEN_STRING_INITIALIZER
12889                 (struct cmd_config_e_tag_result,
12890                  e_tag, "E-tag");
12891 cmdline_parse_token_string_t cmd_config_e_tag_set =
12892         TOKEN_STRING_INITIALIZER
12893                 (struct cmd_config_e_tag_result,
12894                  set, "set");
12895 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12896         TOKEN_STRING_INITIALIZER
12897                 (struct cmd_config_e_tag_result,
12898                  insertion, "insertion");
12899 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12900         TOKEN_STRING_INITIALIZER
12901                 (struct cmd_config_e_tag_result,
12902                  stripping, "stripping");
12903 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12904         TOKEN_STRING_INITIALIZER
12905                 (struct cmd_config_e_tag_result,
12906                  forwarding, "forwarding");
12907 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12908         TOKEN_STRING_INITIALIZER
12909                 (struct cmd_config_e_tag_result,
12910                  filter, "filter");
12911 cmdline_parse_token_string_t cmd_config_e_tag_add =
12912         TOKEN_STRING_INITIALIZER
12913                 (struct cmd_config_e_tag_result,
12914                  add, "add");
12915 cmdline_parse_token_string_t cmd_config_e_tag_del =
12916         TOKEN_STRING_INITIALIZER
12917                 (struct cmd_config_e_tag_result,
12918                  del, "del");
12919 cmdline_parse_token_string_t cmd_config_e_tag_on =
12920         TOKEN_STRING_INITIALIZER
12921                 (struct cmd_config_e_tag_result,
12922                  on, "on");
12923 cmdline_parse_token_string_t cmd_config_e_tag_off =
12924         TOKEN_STRING_INITIALIZER
12925                 (struct cmd_config_e_tag_result,
12926                  off, "off");
12927 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12928         TOKEN_STRING_INITIALIZER
12929                 (struct cmd_config_e_tag_result,
12930                  on_off, "on#off");
12931 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12932         TOKEN_STRING_INITIALIZER
12933                 (struct cmd_config_e_tag_result,
12934                  port_tag_id, "port-tag-id");
12935 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12936         TOKEN_NUM_INITIALIZER
12937                 (struct cmd_config_e_tag_result,
12938                  port_tag_id_val, UINT32);
12939 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12940         TOKEN_STRING_INITIALIZER
12941                 (struct cmd_config_e_tag_result,
12942                  e_tag_id, "e-tag-id");
12943 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12944         TOKEN_NUM_INITIALIZER
12945                 (struct cmd_config_e_tag_result,
12946                  e_tag_id_val, UINT16);
12947 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12948         TOKEN_STRING_INITIALIZER
12949                 (struct cmd_config_e_tag_result,
12950                  dst_pool, "dst-pool");
12951 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12952         TOKEN_NUM_INITIALIZER
12953                 (struct cmd_config_e_tag_result,
12954                  dst_pool_val, UINT8);
12955 cmdline_parse_token_string_t cmd_config_e_tag_port =
12956         TOKEN_STRING_INITIALIZER
12957                 (struct cmd_config_e_tag_result,
12958                  port, "port");
12959 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12960         TOKEN_NUM_INITIALIZER
12961                 (struct cmd_config_e_tag_result,
12962                  port_id, UINT16);
12963 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_config_e_tag_result,
12966                  vf, "vf");
12967 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12968         TOKEN_NUM_INITIALIZER
12969                 (struct cmd_config_e_tag_result,
12970                  vf_id, UINT8);
12971
12972 /* E-tag insertion configuration */
12973 static void
12974 cmd_config_e_tag_insertion_en_parsed(
12975         void *parsed_result,
12976         __attribute__((unused)) struct cmdline *cl,
12977         __attribute__((unused)) void *data)
12978 {
12979         struct cmd_config_e_tag_result *res =
12980                 parsed_result;
12981         struct rte_eth_l2_tunnel_conf entry;
12982
12983         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12984                 return;
12985
12986         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12987         entry.tunnel_id = res->port_tag_id_val;
12988         entry.vf_id = res->vf_id;
12989         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12990                                           &entry,
12991                                           ETH_L2_TUNNEL_INSERTION_MASK,
12992                                           1);
12993 }
12994
12995 static void
12996 cmd_config_e_tag_insertion_dis_parsed(
12997         void *parsed_result,
12998         __attribute__((unused)) struct cmdline *cl,
12999         __attribute__((unused)) void *data)
13000 {
13001         struct cmd_config_e_tag_result *res =
13002                 parsed_result;
13003         struct rte_eth_l2_tunnel_conf entry;
13004
13005         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13006                 return;
13007
13008         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13009         entry.vf_id = res->vf_id;
13010
13011         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13012                                           &entry,
13013                                           ETH_L2_TUNNEL_INSERTION_MASK,
13014                                           0);
13015 }
13016
13017 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13018         .f = cmd_config_e_tag_insertion_en_parsed,
13019         .data = NULL,
13020         .help_str = "E-tag ... : E-tag insertion enable",
13021         .tokens = {
13022                 (void *)&cmd_config_e_tag_e_tag,
13023                 (void *)&cmd_config_e_tag_set,
13024                 (void *)&cmd_config_e_tag_insertion,
13025                 (void *)&cmd_config_e_tag_on,
13026                 (void *)&cmd_config_e_tag_port_tag_id,
13027                 (void *)&cmd_config_e_tag_port_tag_id_val,
13028                 (void *)&cmd_config_e_tag_port,
13029                 (void *)&cmd_config_e_tag_port_id,
13030                 (void *)&cmd_config_e_tag_vf,
13031                 (void *)&cmd_config_e_tag_vf_id,
13032                 NULL,
13033         },
13034 };
13035
13036 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13037         .f = cmd_config_e_tag_insertion_dis_parsed,
13038         .data = NULL,
13039         .help_str = "E-tag ... : E-tag insertion disable",
13040         .tokens = {
13041                 (void *)&cmd_config_e_tag_e_tag,
13042                 (void *)&cmd_config_e_tag_set,
13043                 (void *)&cmd_config_e_tag_insertion,
13044                 (void *)&cmd_config_e_tag_off,
13045                 (void *)&cmd_config_e_tag_port,
13046                 (void *)&cmd_config_e_tag_port_id,
13047                 (void *)&cmd_config_e_tag_vf,
13048                 (void *)&cmd_config_e_tag_vf_id,
13049                 NULL,
13050         },
13051 };
13052
13053 /* E-tag stripping configuration */
13054 static void
13055 cmd_config_e_tag_stripping_parsed(
13056         void *parsed_result,
13057         __attribute__((unused)) struct cmdline *cl,
13058         __attribute__((unused)) void *data)
13059 {
13060         struct cmd_config_e_tag_result *res =
13061                 parsed_result;
13062         struct rte_eth_l2_tunnel_conf entry;
13063
13064         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13065                 return;
13066
13067         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13068
13069         if (!strcmp(res->on_off, "on"))
13070                 rte_eth_dev_l2_tunnel_offload_set
13071                         (res->port_id,
13072                          &entry,
13073                          ETH_L2_TUNNEL_STRIPPING_MASK,
13074                          1);
13075         else
13076                 rte_eth_dev_l2_tunnel_offload_set
13077                         (res->port_id,
13078                          &entry,
13079                          ETH_L2_TUNNEL_STRIPPING_MASK,
13080                          0);
13081 }
13082
13083 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13084         .f = cmd_config_e_tag_stripping_parsed,
13085         .data = NULL,
13086         .help_str = "E-tag ... : E-tag stripping enable/disable",
13087         .tokens = {
13088                 (void *)&cmd_config_e_tag_e_tag,
13089                 (void *)&cmd_config_e_tag_set,
13090                 (void *)&cmd_config_e_tag_stripping,
13091                 (void *)&cmd_config_e_tag_on_off,
13092                 (void *)&cmd_config_e_tag_port,
13093                 (void *)&cmd_config_e_tag_port_id,
13094                 NULL,
13095         },
13096 };
13097
13098 /* E-tag forwarding configuration */
13099 static void
13100 cmd_config_e_tag_forwarding_parsed(
13101         void *parsed_result,
13102         __attribute__((unused)) struct cmdline *cl,
13103         __attribute__((unused)) void *data)
13104 {
13105         struct cmd_config_e_tag_result *res = parsed_result;
13106         struct rte_eth_l2_tunnel_conf entry;
13107
13108         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13109                 return;
13110
13111         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13112
13113         if (!strcmp(res->on_off, "on"))
13114                 rte_eth_dev_l2_tunnel_offload_set
13115                         (res->port_id,
13116                          &entry,
13117                          ETH_L2_TUNNEL_FORWARDING_MASK,
13118                          1);
13119         else
13120                 rte_eth_dev_l2_tunnel_offload_set
13121                         (res->port_id,
13122                          &entry,
13123                          ETH_L2_TUNNEL_FORWARDING_MASK,
13124                          0);
13125 }
13126
13127 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13128         .f = cmd_config_e_tag_forwarding_parsed,
13129         .data = NULL,
13130         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13131         .tokens = {
13132                 (void *)&cmd_config_e_tag_e_tag,
13133                 (void *)&cmd_config_e_tag_set,
13134                 (void *)&cmd_config_e_tag_forwarding,
13135                 (void *)&cmd_config_e_tag_on_off,
13136                 (void *)&cmd_config_e_tag_port,
13137                 (void *)&cmd_config_e_tag_port_id,
13138                 NULL,
13139         },
13140 };
13141
13142 /* E-tag filter configuration */
13143 static void
13144 cmd_config_e_tag_filter_add_parsed(
13145         void *parsed_result,
13146         __attribute__((unused)) struct cmdline *cl,
13147         __attribute__((unused)) void *data)
13148 {
13149         struct cmd_config_e_tag_result *res = parsed_result;
13150         struct rte_eth_l2_tunnel_conf entry;
13151         int ret = 0;
13152
13153         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13154                 return;
13155
13156         if (res->e_tag_id_val > 0x3fff) {
13157                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13158                 return;
13159         }
13160
13161         ret = rte_eth_dev_filter_supported(res->port_id,
13162                                            RTE_ETH_FILTER_L2_TUNNEL);
13163         if (ret < 0) {
13164                 printf("E-tag filter is not supported on port %u.\n",
13165                        res->port_id);
13166                 return;
13167         }
13168
13169         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13170         entry.tunnel_id = res->e_tag_id_val;
13171         entry.pool = res->dst_pool_val;
13172
13173         ret = rte_eth_dev_filter_ctrl(res->port_id,
13174                                       RTE_ETH_FILTER_L2_TUNNEL,
13175                                       RTE_ETH_FILTER_ADD,
13176                                       &entry);
13177         if (ret < 0)
13178                 printf("E-tag filter programming error: (%s)\n",
13179                        strerror(-ret));
13180 }
13181
13182 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13183         .f = cmd_config_e_tag_filter_add_parsed,
13184         .data = NULL,
13185         .help_str = "E-tag ... : E-tag filter add",
13186         .tokens = {
13187                 (void *)&cmd_config_e_tag_e_tag,
13188                 (void *)&cmd_config_e_tag_set,
13189                 (void *)&cmd_config_e_tag_filter,
13190                 (void *)&cmd_config_e_tag_add,
13191                 (void *)&cmd_config_e_tag_e_tag_id,
13192                 (void *)&cmd_config_e_tag_e_tag_id_val,
13193                 (void *)&cmd_config_e_tag_dst_pool,
13194                 (void *)&cmd_config_e_tag_dst_pool_val,
13195                 (void *)&cmd_config_e_tag_port,
13196                 (void *)&cmd_config_e_tag_port_id,
13197                 NULL,
13198         },
13199 };
13200
13201 static void
13202 cmd_config_e_tag_filter_del_parsed(
13203         void *parsed_result,
13204         __attribute__((unused)) struct cmdline *cl,
13205         __attribute__((unused)) void *data)
13206 {
13207         struct cmd_config_e_tag_result *res = parsed_result;
13208         struct rte_eth_l2_tunnel_conf entry;
13209         int ret = 0;
13210
13211         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13212                 return;
13213
13214         if (res->e_tag_id_val > 0x3fff) {
13215                 printf("e-tag-id must be less than 0x3fff.\n");
13216                 return;
13217         }
13218
13219         ret = rte_eth_dev_filter_supported(res->port_id,
13220                                            RTE_ETH_FILTER_L2_TUNNEL);
13221         if (ret < 0) {
13222                 printf("E-tag filter is not supported on port %u.\n",
13223                        res->port_id);
13224                 return;
13225         }
13226
13227         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13228         entry.tunnel_id = res->e_tag_id_val;
13229
13230         ret = rte_eth_dev_filter_ctrl(res->port_id,
13231                                       RTE_ETH_FILTER_L2_TUNNEL,
13232                                       RTE_ETH_FILTER_DELETE,
13233                                       &entry);
13234         if (ret < 0)
13235                 printf("E-tag filter programming error: (%s)\n",
13236                        strerror(-ret));
13237 }
13238
13239 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13240         .f = cmd_config_e_tag_filter_del_parsed,
13241         .data = NULL,
13242         .help_str = "E-tag ... : E-tag filter delete",
13243         .tokens = {
13244                 (void *)&cmd_config_e_tag_e_tag,
13245                 (void *)&cmd_config_e_tag_set,
13246                 (void *)&cmd_config_e_tag_filter,
13247                 (void *)&cmd_config_e_tag_del,
13248                 (void *)&cmd_config_e_tag_e_tag_id,
13249                 (void *)&cmd_config_e_tag_e_tag_id_val,
13250                 (void *)&cmd_config_e_tag_port,
13251                 (void *)&cmd_config_e_tag_port_id,
13252                 NULL,
13253         },
13254 };
13255
13256 /* vf vlan anti spoof configuration */
13257
13258 /* Common result structure for vf vlan anti spoof */
13259 struct cmd_vf_vlan_anti_spoof_result {
13260         cmdline_fixed_string_t set;
13261         cmdline_fixed_string_t vf;
13262         cmdline_fixed_string_t vlan;
13263         cmdline_fixed_string_t antispoof;
13264         portid_t port_id;
13265         uint32_t vf_id;
13266         cmdline_fixed_string_t on_off;
13267 };
13268
13269 /* Common CLI fields for vf vlan anti spoof enable disable */
13270 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13271         TOKEN_STRING_INITIALIZER
13272                 (struct cmd_vf_vlan_anti_spoof_result,
13273                  set, "set");
13274 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13275         TOKEN_STRING_INITIALIZER
13276                 (struct cmd_vf_vlan_anti_spoof_result,
13277                  vf, "vf");
13278 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13279         TOKEN_STRING_INITIALIZER
13280                 (struct cmd_vf_vlan_anti_spoof_result,
13281                  vlan, "vlan");
13282 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13283         TOKEN_STRING_INITIALIZER
13284                 (struct cmd_vf_vlan_anti_spoof_result,
13285                  antispoof, "antispoof");
13286 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13287         TOKEN_NUM_INITIALIZER
13288                 (struct cmd_vf_vlan_anti_spoof_result,
13289                  port_id, UINT16);
13290 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13291         TOKEN_NUM_INITIALIZER
13292                 (struct cmd_vf_vlan_anti_spoof_result,
13293                  vf_id, UINT32);
13294 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13295         TOKEN_STRING_INITIALIZER
13296                 (struct cmd_vf_vlan_anti_spoof_result,
13297                  on_off, "on#off");
13298
13299 static void
13300 cmd_set_vf_vlan_anti_spoof_parsed(
13301         void *parsed_result,
13302         __attribute__((unused)) struct cmdline *cl,
13303         __attribute__((unused)) void *data)
13304 {
13305         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13306         int ret = -ENOTSUP;
13307
13308         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13309
13310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13311                 return;
13312
13313 #ifdef RTE_LIBRTE_IXGBE_PMD
13314         if (ret == -ENOTSUP)
13315                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13316                                 res->vf_id, is_on);
13317 #endif
13318 #ifdef RTE_LIBRTE_I40E_PMD
13319         if (ret == -ENOTSUP)
13320                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13321                                 res->vf_id, is_on);
13322 #endif
13323 #ifdef RTE_LIBRTE_BNXT_PMD
13324         if (ret == -ENOTSUP)
13325                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13326                                 res->vf_id, is_on);
13327 #endif
13328
13329         switch (ret) {
13330         case 0:
13331                 break;
13332         case -EINVAL:
13333                 printf("invalid vf_id %d\n", res->vf_id);
13334                 break;
13335         case -ENODEV:
13336                 printf("invalid port_id %d\n", res->port_id);
13337                 break;
13338         case -ENOTSUP:
13339                 printf("function not implemented\n");
13340                 break;
13341         default:
13342                 printf("programming error: (%s)\n", strerror(-ret));
13343         }
13344 }
13345
13346 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13347         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13348         .data = NULL,
13349         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13350         .tokens = {
13351                 (void *)&cmd_vf_vlan_anti_spoof_set,
13352                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13353                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13354                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13355                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13356                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13357                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13358                 NULL,
13359         },
13360 };
13361
13362 /* vf mac anti spoof configuration */
13363
13364 /* Common result structure for vf mac anti spoof */
13365 struct cmd_vf_mac_anti_spoof_result {
13366         cmdline_fixed_string_t set;
13367         cmdline_fixed_string_t vf;
13368         cmdline_fixed_string_t mac;
13369         cmdline_fixed_string_t antispoof;
13370         portid_t port_id;
13371         uint32_t vf_id;
13372         cmdline_fixed_string_t on_off;
13373 };
13374
13375 /* Common CLI fields for vf mac anti spoof enable disable */
13376 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13377         TOKEN_STRING_INITIALIZER
13378                 (struct cmd_vf_mac_anti_spoof_result,
13379                  set, "set");
13380 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13381         TOKEN_STRING_INITIALIZER
13382                 (struct cmd_vf_mac_anti_spoof_result,
13383                  vf, "vf");
13384 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13385         TOKEN_STRING_INITIALIZER
13386                 (struct cmd_vf_mac_anti_spoof_result,
13387                  mac, "mac");
13388 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13389         TOKEN_STRING_INITIALIZER
13390                 (struct cmd_vf_mac_anti_spoof_result,
13391                  antispoof, "antispoof");
13392 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13393         TOKEN_NUM_INITIALIZER
13394                 (struct cmd_vf_mac_anti_spoof_result,
13395                  port_id, UINT16);
13396 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13397         TOKEN_NUM_INITIALIZER
13398                 (struct cmd_vf_mac_anti_spoof_result,
13399                  vf_id, UINT32);
13400 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13401         TOKEN_STRING_INITIALIZER
13402                 (struct cmd_vf_mac_anti_spoof_result,
13403                  on_off, "on#off");
13404
13405 static void
13406 cmd_set_vf_mac_anti_spoof_parsed(
13407         void *parsed_result,
13408         __attribute__((unused)) struct cmdline *cl,
13409         __attribute__((unused)) void *data)
13410 {
13411         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13412         int ret = -ENOTSUP;
13413
13414         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13415
13416         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13417                 return;
13418
13419 #ifdef RTE_LIBRTE_IXGBE_PMD
13420         if (ret == -ENOTSUP)
13421                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13422                         res->vf_id, is_on);
13423 #endif
13424 #ifdef RTE_LIBRTE_I40E_PMD
13425         if (ret == -ENOTSUP)
13426                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13427                         res->vf_id, is_on);
13428 #endif
13429 #ifdef RTE_LIBRTE_BNXT_PMD
13430         if (ret == -ENOTSUP)
13431                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13432                         res->vf_id, is_on);
13433 #endif
13434
13435         switch (ret) {
13436         case 0:
13437                 break;
13438         case -EINVAL:
13439                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13440                 break;
13441         case -ENODEV:
13442                 printf("invalid port_id %d\n", res->port_id);
13443                 break;
13444         case -ENOTSUP:
13445                 printf("function not implemented\n");
13446                 break;
13447         default:
13448                 printf("programming error: (%s)\n", strerror(-ret));
13449         }
13450 }
13451
13452 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13453         .f = cmd_set_vf_mac_anti_spoof_parsed,
13454         .data = NULL,
13455         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13456         .tokens = {
13457                 (void *)&cmd_vf_mac_anti_spoof_set,
13458                 (void *)&cmd_vf_mac_anti_spoof_vf,
13459                 (void *)&cmd_vf_mac_anti_spoof_mac,
13460                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13461                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13462                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13463                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13464                 NULL,
13465         },
13466 };
13467
13468 /* vf vlan strip queue configuration */
13469
13470 /* Common result structure for vf mac anti spoof */
13471 struct cmd_vf_vlan_stripq_result {
13472         cmdline_fixed_string_t set;
13473         cmdline_fixed_string_t vf;
13474         cmdline_fixed_string_t vlan;
13475         cmdline_fixed_string_t stripq;
13476         portid_t port_id;
13477         uint16_t vf_id;
13478         cmdline_fixed_string_t on_off;
13479 };
13480
13481 /* Common CLI fields for vf vlan strip enable disable */
13482 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13483         TOKEN_STRING_INITIALIZER
13484                 (struct cmd_vf_vlan_stripq_result,
13485                  set, "set");
13486 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13487         TOKEN_STRING_INITIALIZER
13488                 (struct cmd_vf_vlan_stripq_result,
13489                  vf, "vf");
13490 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13491         TOKEN_STRING_INITIALIZER
13492                 (struct cmd_vf_vlan_stripq_result,
13493                  vlan, "vlan");
13494 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13495         TOKEN_STRING_INITIALIZER
13496                 (struct cmd_vf_vlan_stripq_result,
13497                  stripq, "stripq");
13498 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13499         TOKEN_NUM_INITIALIZER
13500                 (struct cmd_vf_vlan_stripq_result,
13501                  port_id, UINT16);
13502 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13503         TOKEN_NUM_INITIALIZER
13504                 (struct cmd_vf_vlan_stripq_result,
13505                  vf_id, UINT16);
13506 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13507         TOKEN_STRING_INITIALIZER
13508                 (struct cmd_vf_vlan_stripq_result,
13509                  on_off, "on#off");
13510
13511 static void
13512 cmd_set_vf_vlan_stripq_parsed(
13513         void *parsed_result,
13514         __attribute__((unused)) struct cmdline *cl,
13515         __attribute__((unused)) void *data)
13516 {
13517         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13518         int ret = -ENOTSUP;
13519
13520         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13521
13522         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13523                 return;
13524
13525 #ifdef RTE_LIBRTE_IXGBE_PMD
13526         if (ret == -ENOTSUP)
13527                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13528                         res->vf_id, is_on);
13529 #endif
13530 #ifdef RTE_LIBRTE_I40E_PMD
13531         if (ret == -ENOTSUP)
13532                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13533                         res->vf_id, is_on);
13534 #endif
13535 #ifdef RTE_LIBRTE_BNXT_PMD
13536         if (ret == -ENOTSUP)
13537                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13538                         res->vf_id, is_on);
13539 #endif
13540
13541         switch (ret) {
13542         case 0:
13543                 break;
13544         case -EINVAL:
13545                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13546                 break;
13547         case -ENODEV:
13548                 printf("invalid port_id %d\n", res->port_id);
13549                 break;
13550         case -ENOTSUP:
13551                 printf("function not implemented\n");
13552                 break;
13553         default:
13554                 printf("programming error: (%s)\n", strerror(-ret));
13555         }
13556 }
13557
13558 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13559         .f = cmd_set_vf_vlan_stripq_parsed,
13560         .data = NULL,
13561         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13562         .tokens = {
13563                 (void *)&cmd_vf_vlan_stripq_set,
13564                 (void *)&cmd_vf_vlan_stripq_vf,
13565                 (void *)&cmd_vf_vlan_stripq_vlan,
13566                 (void *)&cmd_vf_vlan_stripq_stripq,
13567                 (void *)&cmd_vf_vlan_stripq_port_id,
13568                 (void *)&cmd_vf_vlan_stripq_vf_id,
13569                 (void *)&cmd_vf_vlan_stripq_on_off,
13570                 NULL,
13571         },
13572 };
13573
13574 /* vf vlan insert configuration */
13575
13576 /* Common result structure for vf vlan insert */
13577 struct cmd_vf_vlan_insert_result {
13578         cmdline_fixed_string_t set;
13579         cmdline_fixed_string_t vf;
13580         cmdline_fixed_string_t vlan;
13581         cmdline_fixed_string_t insert;
13582         portid_t port_id;
13583         uint16_t vf_id;
13584         uint16_t vlan_id;
13585 };
13586
13587 /* Common CLI fields for vf vlan insert enable disable */
13588 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13589         TOKEN_STRING_INITIALIZER
13590                 (struct cmd_vf_vlan_insert_result,
13591                  set, "set");
13592 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13593         TOKEN_STRING_INITIALIZER
13594                 (struct cmd_vf_vlan_insert_result,
13595                  vf, "vf");
13596 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13597         TOKEN_STRING_INITIALIZER
13598                 (struct cmd_vf_vlan_insert_result,
13599                  vlan, "vlan");
13600 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13601         TOKEN_STRING_INITIALIZER
13602                 (struct cmd_vf_vlan_insert_result,
13603                  insert, "insert");
13604 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13605         TOKEN_NUM_INITIALIZER
13606                 (struct cmd_vf_vlan_insert_result,
13607                  port_id, UINT16);
13608 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13609         TOKEN_NUM_INITIALIZER
13610                 (struct cmd_vf_vlan_insert_result,
13611                  vf_id, UINT16);
13612 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13613         TOKEN_NUM_INITIALIZER
13614                 (struct cmd_vf_vlan_insert_result,
13615                  vlan_id, UINT16);
13616
13617 static void
13618 cmd_set_vf_vlan_insert_parsed(
13619         void *parsed_result,
13620         __attribute__((unused)) struct cmdline *cl,
13621         __attribute__((unused)) void *data)
13622 {
13623         struct cmd_vf_vlan_insert_result *res = parsed_result;
13624         int ret = -ENOTSUP;
13625
13626         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13627                 return;
13628
13629 #ifdef RTE_LIBRTE_IXGBE_PMD
13630         if (ret == -ENOTSUP)
13631                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13632                         res->vlan_id);
13633 #endif
13634 #ifdef RTE_LIBRTE_I40E_PMD
13635         if (ret == -ENOTSUP)
13636                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13637                         res->vlan_id);
13638 #endif
13639 #ifdef RTE_LIBRTE_BNXT_PMD
13640         if (ret == -ENOTSUP)
13641                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13642                         res->vlan_id);
13643 #endif
13644
13645         switch (ret) {
13646         case 0:
13647                 break;
13648         case -EINVAL:
13649                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13650                 break;
13651         case -ENODEV:
13652                 printf("invalid port_id %d\n", res->port_id);
13653                 break;
13654         case -ENOTSUP:
13655                 printf("function not implemented\n");
13656                 break;
13657         default:
13658                 printf("programming error: (%s)\n", strerror(-ret));
13659         }
13660 }
13661
13662 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13663         .f = cmd_set_vf_vlan_insert_parsed,
13664         .data = NULL,
13665         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13666         .tokens = {
13667                 (void *)&cmd_vf_vlan_insert_set,
13668                 (void *)&cmd_vf_vlan_insert_vf,
13669                 (void *)&cmd_vf_vlan_insert_vlan,
13670                 (void *)&cmd_vf_vlan_insert_insert,
13671                 (void *)&cmd_vf_vlan_insert_port_id,
13672                 (void *)&cmd_vf_vlan_insert_vf_id,
13673                 (void *)&cmd_vf_vlan_insert_vlan_id,
13674                 NULL,
13675         },
13676 };
13677
13678 /* tx loopback configuration */
13679
13680 /* Common result structure for tx loopback */
13681 struct cmd_tx_loopback_result {
13682         cmdline_fixed_string_t set;
13683         cmdline_fixed_string_t tx;
13684         cmdline_fixed_string_t loopback;
13685         portid_t port_id;
13686         cmdline_fixed_string_t on_off;
13687 };
13688
13689 /* Common CLI fields for tx loopback enable disable */
13690 cmdline_parse_token_string_t cmd_tx_loopback_set =
13691         TOKEN_STRING_INITIALIZER
13692                 (struct cmd_tx_loopback_result,
13693                  set, "set");
13694 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13695         TOKEN_STRING_INITIALIZER
13696                 (struct cmd_tx_loopback_result,
13697                  tx, "tx");
13698 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13699         TOKEN_STRING_INITIALIZER
13700                 (struct cmd_tx_loopback_result,
13701                  loopback, "loopback");
13702 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13703         TOKEN_NUM_INITIALIZER
13704                 (struct cmd_tx_loopback_result,
13705                  port_id, UINT16);
13706 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13707         TOKEN_STRING_INITIALIZER
13708                 (struct cmd_tx_loopback_result,
13709                  on_off, "on#off");
13710
13711 static void
13712 cmd_set_tx_loopback_parsed(
13713         void *parsed_result,
13714         __attribute__((unused)) struct cmdline *cl,
13715         __attribute__((unused)) void *data)
13716 {
13717         struct cmd_tx_loopback_result *res = parsed_result;
13718         int ret = -ENOTSUP;
13719
13720         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13721
13722         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13723                 return;
13724
13725 #ifdef RTE_LIBRTE_IXGBE_PMD
13726         if (ret == -ENOTSUP)
13727                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13728 #endif
13729 #ifdef RTE_LIBRTE_I40E_PMD
13730         if (ret == -ENOTSUP)
13731                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13732 #endif
13733 #ifdef RTE_LIBRTE_BNXT_PMD
13734         if (ret == -ENOTSUP)
13735                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13736 #endif
13737 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13738         if (ret == -ENOTSUP)
13739                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13740 #endif
13741
13742         switch (ret) {
13743         case 0:
13744                 break;
13745         case -EINVAL:
13746                 printf("invalid is_on %d\n", is_on);
13747                 break;
13748         case -ENODEV:
13749                 printf("invalid port_id %d\n", res->port_id);
13750                 break;
13751         case -ENOTSUP:
13752                 printf("function not implemented\n");
13753                 break;
13754         default:
13755                 printf("programming error: (%s)\n", strerror(-ret));
13756         }
13757 }
13758
13759 cmdline_parse_inst_t cmd_set_tx_loopback = {
13760         .f = cmd_set_tx_loopback_parsed,
13761         .data = NULL,
13762         .help_str = "set tx loopback <port_id> on|off",
13763         .tokens = {
13764                 (void *)&cmd_tx_loopback_set,
13765                 (void *)&cmd_tx_loopback_tx,
13766                 (void *)&cmd_tx_loopback_loopback,
13767                 (void *)&cmd_tx_loopback_port_id,
13768                 (void *)&cmd_tx_loopback_on_off,
13769                 NULL,
13770         },
13771 };
13772
13773 /* all queues drop enable configuration */
13774
13775 /* Common result structure for all queues drop enable */
13776 struct cmd_all_queues_drop_en_result {
13777         cmdline_fixed_string_t set;
13778         cmdline_fixed_string_t all;
13779         cmdline_fixed_string_t queues;
13780         cmdline_fixed_string_t drop;
13781         portid_t port_id;
13782         cmdline_fixed_string_t on_off;
13783 };
13784
13785 /* Common CLI fields for tx loopback enable disable */
13786 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13787         TOKEN_STRING_INITIALIZER
13788                 (struct cmd_all_queues_drop_en_result,
13789                  set, "set");
13790 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13791         TOKEN_STRING_INITIALIZER
13792                 (struct cmd_all_queues_drop_en_result,
13793                  all, "all");
13794 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13795         TOKEN_STRING_INITIALIZER
13796                 (struct cmd_all_queues_drop_en_result,
13797                  queues, "queues");
13798 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13799         TOKEN_STRING_INITIALIZER
13800                 (struct cmd_all_queues_drop_en_result,
13801                  drop, "drop");
13802 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13803         TOKEN_NUM_INITIALIZER
13804                 (struct cmd_all_queues_drop_en_result,
13805                  port_id, UINT16);
13806 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13807         TOKEN_STRING_INITIALIZER
13808                 (struct cmd_all_queues_drop_en_result,
13809                  on_off, "on#off");
13810
13811 static void
13812 cmd_set_all_queues_drop_en_parsed(
13813         void *parsed_result,
13814         __attribute__((unused)) struct cmdline *cl,
13815         __attribute__((unused)) void *data)
13816 {
13817         struct cmd_all_queues_drop_en_result *res = parsed_result;
13818         int ret = -ENOTSUP;
13819         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13820
13821         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13822                 return;
13823
13824 #ifdef RTE_LIBRTE_IXGBE_PMD
13825         if (ret == -ENOTSUP)
13826                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13827 #endif
13828 #ifdef RTE_LIBRTE_BNXT_PMD
13829         if (ret == -ENOTSUP)
13830                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13831 #endif
13832         switch (ret) {
13833         case 0:
13834                 break;
13835         case -EINVAL:
13836                 printf("invalid is_on %d\n", is_on);
13837                 break;
13838         case -ENODEV:
13839                 printf("invalid port_id %d\n", res->port_id);
13840                 break;
13841         case -ENOTSUP:
13842                 printf("function not implemented\n");
13843                 break;
13844         default:
13845                 printf("programming error: (%s)\n", strerror(-ret));
13846         }
13847 }
13848
13849 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13850         .f = cmd_set_all_queues_drop_en_parsed,
13851         .data = NULL,
13852         .help_str = "set all queues drop <port_id> on|off",
13853         .tokens = {
13854                 (void *)&cmd_all_queues_drop_en_set,
13855                 (void *)&cmd_all_queues_drop_en_all,
13856                 (void *)&cmd_all_queues_drop_en_queues,
13857                 (void *)&cmd_all_queues_drop_en_drop,
13858                 (void *)&cmd_all_queues_drop_en_port_id,
13859                 (void *)&cmd_all_queues_drop_en_on_off,
13860                 NULL,
13861         },
13862 };
13863
13864 /* vf split drop enable configuration */
13865
13866 /* Common result structure for vf split drop enable */
13867 struct cmd_vf_split_drop_en_result {
13868         cmdline_fixed_string_t set;
13869         cmdline_fixed_string_t vf;
13870         cmdline_fixed_string_t split;
13871         cmdline_fixed_string_t drop;
13872         portid_t port_id;
13873         uint16_t vf_id;
13874         cmdline_fixed_string_t on_off;
13875 };
13876
13877 /* Common CLI fields for vf split drop enable disable */
13878 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13879         TOKEN_STRING_INITIALIZER
13880                 (struct cmd_vf_split_drop_en_result,
13881                  set, "set");
13882 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13883         TOKEN_STRING_INITIALIZER
13884                 (struct cmd_vf_split_drop_en_result,
13885                  vf, "vf");
13886 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13887         TOKEN_STRING_INITIALIZER
13888                 (struct cmd_vf_split_drop_en_result,
13889                  split, "split");
13890 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13891         TOKEN_STRING_INITIALIZER
13892                 (struct cmd_vf_split_drop_en_result,
13893                  drop, "drop");
13894 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13895         TOKEN_NUM_INITIALIZER
13896                 (struct cmd_vf_split_drop_en_result,
13897                  port_id, UINT16);
13898 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13899         TOKEN_NUM_INITIALIZER
13900                 (struct cmd_vf_split_drop_en_result,
13901                  vf_id, UINT16);
13902 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13903         TOKEN_STRING_INITIALIZER
13904                 (struct cmd_vf_split_drop_en_result,
13905                  on_off, "on#off");
13906
13907 static void
13908 cmd_set_vf_split_drop_en_parsed(
13909         void *parsed_result,
13910         __attribute__((unused)) struct cmdline *cl,
13911         __attribute__((unused)) void *data)
13912 {
13913         struct cmd_vf_split_drop_en_result *res = parsed_result;
13914         int ret = -ENOTSUP;
13915         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13916
13917         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13918                 return;
13919
13920 #ifdef RTE_LIBRTE_IXGBE_PMD
13921         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13922                         is_on);
13923 #endif
13924         switch (ret) {
13925         case 0:
13926                 break;
13927         case -EINVAL:
13928                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13929                 break;
13930         case -ENODEV:
13931                 printf("invalid port_id %d\n", res->port_id);
13932                 break;
13933         case -ENOTSUP:
13934                 printf("not supported on port %d\n", res->port_id);
13935                 break;
13936         default:
13937                 printf("programming error: (%s)\n", strerror(-ret));
13938         }
13939 }
13940
13941 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13942         .f = cmd_set_vf_split_drop_en_parsed,
13943         .data = NULL,
13944         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13945         .tokens = {
13946                 (void *)&cmd_vf_split_drop_en_set,
13947                 (void *)&cmd_vf_split_drop_en_vf,
13948                 (void *)&cmd_vf_split_drop_en_split,
13949                 (void *)&cmd_vf_split_drop_en_drop,
13950                 (void *)&cmd_vf_split_drop_en_port_id,
13951                 (void *)&cmd_vf_split_drop_en_vf_id,
13952                 (void *)&cmd_vf_split_drop_en_on_off,
13953                 NULL,
13954         },
13955 };
13956
13957 /* vf mac address configuration */
13958
13959 /* Common result structure for vf mac address */
13960 struct cmd_set_vf_mac_addr_result {
13961         cmdline_fixed_string_t set;
13962         cmdline_fixed_string_t vf;
13963         cmdline_fixed_string_t mac;
13964         cmdline_fixed_string_t addr;
13965         portid_t port_id;
13966         uint16_t vf_id;
13967         struct rte_ether_addr mac_addr;
13968
13969 };
13970
13971 /* Common CLI fields for vf split drop enable disable */
13972 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13973         TOKEN_STRING_INITIALIZER
13974                 (struct cmd_set_vf_mac_addr_result,
13975                  set, "set");
13976 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13977         TOKEN_STRING_INITIALIZER
13978                 (struct cmd_set_vf_mac_addr_result,
13979                  vf, "vf");
13980 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13981         TOKEN_STRING_INITIALIZER
13982                 (struct cmd_set_vf_mac_addr_result,
13983                  mac, "mac");
13984 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13985         TOKEN_STRING_INITIALIZER
13986                 (struct cmd_set_vf_mac_addr_result,
13987                  addr, "addr");
13988 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13989         TOKEN_NUM_INITIALIZER
13990                 (struct cmd_set_vf_mac_addr_result,
13991                  port_id, UINT16);
13992 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13993         TOKEN_NUM_INITIALIZER
13994                 (struct cmd_set_vf_mac_addr_result,
13995                  vf_id, UINT16);
13996 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13997         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13998                  mac_addr);
13999
14000 static void
14001 cmd_set_vf_mac_addr_parsed(
14002         void *parsed_result,
14003         __attribute__((unused)) struct cmdline *cl,
14004         __attribute__((unused)) void *data)
14005 {
14006         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14007         int ret = -ENOTSUP;
14008
14009         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14010                 return;
14011
14012 #ifdef RTE_LIBRTE_IXGBE_PMD
14013         if (ret == -ENOTSUP)
14014                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14015                                 &res->mac_addr);
14016 #endif
14017 #ifdef RTE_LIBRTE_I40E_PMD
14018         if (ret == -ENOTSUP)
14019                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14020                                 &res->mac_addr);
14021 #endif
14022 #ifdef RTE_LIBRTE_BNXT_PMD
14023         if (ret == -ENOTSUP)
14024                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14025                                 &res->mac_addr);
14026 #endif
14027
14028         switch (ret) {
14029         case 0:
14030                 break;
14031         case -EINVAL:
14032                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14033                 break;
14034         case -ENODEV:
14035                 printf("invalid port_id %d\n", res->port_id);
14036                 break;
14037         case -ENOTSUP:
14038                 printf("function not implemented\n");
14039                 break;
14040         default:
14041                 printf("programming error: (%s)\n", strerror(-ret));
14042         }
14043 }
14044
14045 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14046         .f = cmd_set_vf_mac_addr_parsed,
14047         .data = NULL,
14048         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14049         .tokens = {
14050                 (void *)&cmd_set_vf_mac_addr_set,
14051                 (void *)&cmd_set_vf_mac_addr_vf,
14052                 (void *)&cmd_set_vf_mac_addr_mac,
14053                 (void *)&cmd_set_vf_mac_addr_addr,
14054                 (void *)&cmd_set_vf_mac_addr_port_id,
14055                 (void *)&cmd_set_vf_mac_addr_vf_id,
14056                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14057                 NULL,
14058         },
14059 };
14060
14061 /* MACsec configuration */
14062
14063 /* Common result structure for MACsec offload enable */
14064 struct cmd_macsec_offload_on_result {
14065         cmdline_fixed_string_t set;
14066         cmdline_fixed_string_t macsec;
14067         cmdline_fixed_string_t offload;
14068         portid_t port_id;
14069         cmdline_fixed_string_t on;
14070         cmdline_fixed_string_t encrypt;
14071         cmdline_fixed_string_t en_on_off;
14072         cmdline_fixed_string_t replay_protect;
14073         cmdline_fixed_string_t rp_on_off;
14074 };
14075
14076 /* Common CLI fields for MACsec offload disable */
14077 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14078         TOKEN_STRING_INITIALIZER
14079                 (struct cmd_macsec_offload_on_result,
14080                  set, "set");
14081 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14082         TOKEN_STRING_INITIALIZER
14083                 (struct cmd_macsec_offload_on_result,
14084                  macsec, "macsec");
14085 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14086         TOKEN_STRING_INITIALIZER
14087                 (struct cmd_macsec_offload_on_result,
14088                  offload, "offload");
14089 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14090         TOKEN_NUM_INITIALIZER
14091                 (struct cmd_macsec_offload_on_result,
14092                  port_id, UINT16);
14093 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14094         TOKEN_STRING_INITIALIZER
14095                 (struct cmd_macsec_offload_on_result,
14096                  on, "on");
14097 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14098         TOKEN_STRING_INITIALIZER
14099                 (struct cmd_macsec_offload_on_result,
14100                  encrypt, "encrypt");
14101 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14102         TOKEN_STRING_INITIALIZER
14103                 (struct cmd_macsec_offload_on_result,
14104                  en_on_off, "on#off");
14105 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14106         TOKEN_STRING_INITIALIZER
14107                 (struct cmd_macsec_offload_on_result,
14108                  replay_protect, "replay-protect");
14109 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14110         TOKEN_STRING_INITIALIZER
14111                 (struct cmd_macsec_offload_on_result,
14112                  rp_on_off, "on#off");
14113
14114 static void
14115 cmd_set_macsec_offload_on_parsed(
14116         void *parsed_result,
14117         __attribute__((unused)) struct cmdline *cl,
14118         __attribute__((unused)) void *data)
14119 {
14120         struct cmd_macsec_offload_on_result *res = parsed_result;
14121         int ret = -ENOTSUP;
14122         portid_t port_id = res->port_id;
14123         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14124         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14125         struct rte_eth_dev_info dev_info;
14126
14127         if (port_id_is_invalid(port_id, ENABLED_WARN))
14128                 return;
14129         if (!port_is_stopped(port_id)) {
14130                 printf("Please stop port %d first\n", port_id);
14131                 return;
14132         }
14133
14134         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14135         if (ret != 0)
14136                 return;
14137
14138         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14139 #ifdef RTE_LIBRTE_IXGBE_PMD
14140                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14141 #endif
14142         }
14143         RTE_SET_USED(en);
14144         RTE_SET_USED(rp);
14145
14146         switch (ret) {
14147         case 0:
14148                 ports[port_id].dev_conf.txmode.offloads |=
14149                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14150                 cmd_reconfig_device_queue(port_id, 1, 1);
14151                 break;
14152         case -ENODEV:
14153                 printf("invalid port_id %d\n", port_id);
14154                 break;
14155         case -ENOTSUP:
14156                 printf("not supported on port %d\n", port_id);
14157                 break;
14158         default:
14159                 printf("programming error: (%s)\n", strerror(-ret));
14160         }
14161 }
14162
14163 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14164         .f = cmd_set_macsec_offload_on_parsed,
14165         .data = NULL,
14166         .help_str = "set macsec offload <port_id> on "
14167                 "encrypt on|off replay-protect on|off",
14168         .tokens = {
14169                 (void *)&cmd_macsec_offload_on_set,
14170                 (void *)&cmd_macsec_offload_on_macsec,
14171                 (void *)&cmd_macsec_offload_on_offload,
14172                 (void *)&cmd_macsec_offload_on_port_id,
14173                 (void *)&cmd_macsec_offload_on_on,
14174                 (void *)&cmd_macsec_offload_on_encrypt,
14175                 (void *)&cmd_macsec_offload_on_en_on_off,
14176                 (void *)&cmd_macsec_offload_on_replay_protect,
14177                 (void *)&cmd_macsec_offload_on_rp_on_off,
14178                 NULL,
14179         },
14180 };
14181
14182 /* Common result structure for MACsec offload disable */
14183 struct cmd_macsec_offload_off_result {
14184         cmdline_fixed_string_t set;
14185         cmdline_fixed_string_t macsec;
14186         cmdline_fixed_string_t offload;
14187         portid_t port_id;
14188         cmdline_fixed_string_t off;
14189 };
14190
14191 /* Common CLI fields for MACsec offload disable */
14192 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14193         TOKEN_STRING_INITIALIZER
14194                 (struct cmd_macsec_offload_off_result,
14195                  set, "set");
14196 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14197         TOKEN_STRING_INITIALIZER
14198                 (struct cmd_macsec_offload_off_result,
14199                  macsec, "macsec");
14200 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14201         TOKEN_STRING_INITIALIZER
14202                 (struct cmd_macsec_offload_off_result,
14203                  offload, "offload");
14204 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14205         TOKEN_NUM_INITIALIZER
14206                 (struct cmd_macsec_offload_off_result,
14207                  port_id, UINT16);
14208 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14209         TOKEN_STRING_INITIALIZER
14210                 (struct cmd_macsec_offload_off_result,
14211                  off, "off");
14212
14213 static void
14214 cmd_set_macsec_offload_off_parsed(
14215         void *parsed_result,
14216         __attribute__((unused)) struct cmdline *cl,
14217         __attribute__((unused)) void *data)
14218 {
14219         struct cmd_macsec_offload_off_result *res = parsed_result;
14220         int ret = -ENOTSUP;
14221         struct rte_eth_dev_info dev_info;
14222         portid_t port_id = res->port_id;
14223
14224         if (port_id_is_invalid(port_id, ENABLED_WARN))
14225                 return;
14226         if (!port_is_stopped(port_id)) {
14227                 printf("Please stop port %d first\n", port_id);
14228                 return;
14229         }
14230
14231         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14232         if (ret != 0)
14233                 return;
14234
14235         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14236 #ifdef RTE_LIBRTE_IXGBE_PMD
14237                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14238 #endif
14239         }
14240         switch (ret) {
14241         case 0:
14242                 ports[port_id].dev_conf.txmode.offloads &=
14243                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14244                 cmd_reconfig_device_queue(port_id, 1, 1);
14245                 break;
14246         case -ENODEV:
14247                 printf("invalid port_id %d\n", port_id);
14248                 break;
14249         case -ENOTSUP:
14250                 printf("not supported on port %d\n", port_id);
14251                 break;
14252         default:
14253                 printf("programming error: (%s)\n", strerror(-ret));
14254         }
14255 }
14256
14257 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14258         .f = cmd_set_macsec_offload_off_parsed,
14259         .data = NULL,
14260         .help_str = "set macsec offload <port_id> off",
14261         .tokens = {
14262                 (void *)&cmd_macsec_offload_off_set,
14263                 (void *)&cmd_macsec_offload_off_macsec,
14264                 (void *)&cmd_macsec_offload_off_offload,
14265                 (void *)&cmd_macsec_offload_off_port_id,
14266                 (void *)&cmd_macsec_offload_off_off,
14267                 NULL,
14268         },
14269 };
14270
14271 /* Common result structure for MACsec secure connection configure */
14272 struct cmd_macsec_sc_result {
14273         cmdline_fixed_string_t set;
14274         cmdline_fixed_string_t macsec;
14275         cmdline_fixed_string_t sc;
14276         cmdline_fixed_string_t tx_rx;
14277         portid_t port_id;
14278         struct rte_ether_addr mac;
14279         uint16_t pi;
14280 };
14281
14282 /* Common CLI fields for MACsec secure connection configure */
14283 cmdline_parse_token_string_t cmd_macsec_sc_set =
14284         TOKEN_STRING_INITIALIZER
14285                 (struct cmd_macsec_sc_result,
14286                  set, "set");
14287 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14288         TOKEN_STRING_INITIALIZER
14289                 (struct cmd_macsec_sc_result,
14290                  macsec, "macsec");
14291 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14292         TOKEN_STRING_INITIALIZER
14293                 (struct cmd_macsec_sc_result,
14294                  sc, "sc");
14295 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14296         TOKEN_STRING_INITIALIZER
14297                 (struct cmd_macsec_sc_result,
14298                  tx_rx, "tx#rx");
14299 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14300         TOKEN_NUM_INITIALIZER
14301                 (struct cmd_macsec_sc_result,
14302                  port_id, UINT16);
14303 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14304         TOKEN_ETHERADDR_INITIALIZER
14305                 (struct cmd_macsec_sc_result,
14306                  mac);
14307 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14308         TOKEN_NUM_INITIALIZER
14309                 (struct cmd_macsec_sc_result,
14310                  pi, UINT16);
14311
14312 static void
14313 cmd_set_macsec_sc_parsed(
14314         void *parsed_result,
14315         __attribute__((unused)) struct cmdline *cl,
14316         __attribute__((unused)) void *data)
14317 {
14318         struct cmd_macsec_sc_result *res = parsed_result;
14319         int ret = -ENOTSUP;
14320         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14321
14322 #ifdef RTE_LIBRTE_IXGBE_PMD
14323         ret = is_tx ?
14324                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14325                                 res->mac.addr_bytes) :
14326                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14327                                 res->mac.addr_bytes, res->pi);
14328 #endif
14329         RTE_SET_USED(is_tx);
14330
14331         switch (ret) {
14332         case 0:
14333                 break;
14334         case -ENODEV:
14335                 printf("invalid port_id %d\n", res->port_id);
14336                 break;
14337         case -ENOTSUP:
14338                 printf("not supported on port %d\n", res->port_id);
14339                 break;
14340         default:
14341                 printf("programming error: (%s)\n", strerror(-ret));
14342         }
14343 }
14344
14345 cmdline_parse_inst_t cmd_set_macsec_sc = {
14346         .f = cmd_set_macsec_sc_parsed,
14347         .data = NULL,
14348         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14349         .tokens = {
14350                 (void *)&cmd_macsec_sc_set,
14351                 (void *)&cmd_macsec_sc_macsec,
14352                 (void *)&cmd_macsec_sc_sc,
14353                 (void *)&cmd_macsec_sc_tx_rx,
14354                 (void *)&cmd_macsec_sc_port_id,
14355                 (void *)&cmd_macsec_sc_mac,
14356                 (void *)&cmd_macsec_sc_pi,
14357                 NULL,
14358         },
14359 };
14360
14361 /* Common result structure for MACsec secure connection configure */
14362 struct cmd_macsec_sa_result {
14363         cmdline_fixed_string_t set;
14364         cmdline_fixed_string_t macsec;
14365         cmdline_fixed_string_t sa;
14366         cmdline_fixed_string_t tx_rx;
14367         portid_t port_id;
14368         uint8_t idx;
14369         uint8_t an;
14370         uint32_t pn;
14371         cmdline_fixed_string_t key;
14372 };
14373
14374 /* Common CLI fields for MACsec secure connection configure */
14375 cmdline_parse_token_string_t cmd_macsec_sa_set =
14376         TOKEN_STRING_INITIALIZER
14377                 (struct cmd_macsec_sa_result,
14378                  set, "set");
14379 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14380         TOKEN_STRING_INITIALIZER
14381                 (struct cmd_macsec_sa_result,
14382                  macsec, "macsec");
14383 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14384         TOKEN_STRING_INITIALIZER
14385                 (struct cmd_macsec_sa_result,
14386                  sa, "sa");
14387 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14388         TOKEN_STRING_INITIALIZER
14389                 (struct cmd_macsec_sa_result,
14390                  tx_rx, "tx#rx");
14391 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14392         TOKEN_NUM_INITIALIZER
14393                 (struct cmd_macsec_sa_result,
14394                  port_id, UINT16);
14395 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14396         TOKEN_NUM_INITIALIZER
14397                 (struct cmd_macsec_sa_result,
14398                  idx, UINT8);
14399 cmdline_parse_token_num_t cmd_macsec_sa_an =
14400         TOKEN_NUM_INITIALIZER
14401                 (struct cmd_macsec_sa_result,
14402                  an, UINT8);
14403 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14404         TOKEN_NUM_INITIALIZER
14405                 (struct cmd_macsec_sa_result,
14406                  pn, UINT32);
14407 cmdline_parse_token_string_t cmd_macsec_sa_key =
14408         TOKEN_STRING_INITIALIZER
14409                 (struct cmd_macsec_sa_result,
14410                  key, NULL);
14411
14412 static void
14413 cmd_set_macsec_sa_parsed(
14414         void *parsed_result,
14415         __attribute__((unused)) struct cmdline *cl,
14416         __attribute__((unused)) void *data)
14417 {
14418         struct cmd_macsec_sa_result *res = parsed_result;
14419         int ret = -ENOTSUP;
14420         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14421         uint8_t key[16] = { 0 };
14422         uint8_t xdgt0;
14423         uint8_t xdgt1;
14424         int key_len;
14425         int i;
14426
14427         key_len = strlen(res->key) / 2;
14428         if (key_len > 16)
14429                 key_len = 16;
14430
14431         for (i = 0; i < key_len; i++) {
14432                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14433                 if (xdgt0 == 0xFF)
14434                         return;
14435                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14436                 if (xdgt1 == 0xFF)
14437                         return;
14438                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14439         }
14440
14441 #ifdef RTE_LIBRTE_IXGBE_PMD
14442         ret = is_tx ?
14443                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14444                         res->idx, res->an, res->pn, key) :
14445                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14446                         res->idx, res->an, res->pn, key);
14447 #endif
14448         RTE_SET_USED(is_tx);
14449         RTE_SET_USED(key);
14450
14451         switch (ret) {
14452         case 0:
14453                 break;
14454         case -EINVAL:
14455                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14456                 break;
14457         case -ENODEV:
14458                 printf("invalid port_id %d\n", res->port_id);
14459                 break;
14460         case -ENOTSUP:
14461                 printf("not supported on port %d\n", res->port_id);
14462                 break;
14463         default:
14464                 printf("programming error: (%s)\n", strerror(-ret));
14465         }
14466 }
14467
14468 cmdline_parse_inst_t cmd_set_macsec_sa = {
14469         .f = cmd_set_macsec_sa_parsed,
14470         .data = NULL,
14471         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14472         .tokens = {
14473                 (void *)&cmd_macsec_sa_set,
14474                 (void *)&cmd_macsec_sa_macsec,
14475                 (void *)&cmd_macsec_sa_sa,
14476                 (void *)&cmd_macsec_sa_tx_rx,
14477                 (void *)&cmd_macsec_sa_port_id,
14478                 (void *)&cmd_macsec_sa_idx,
14479                 (void *)&cmd_macsec_sa_an,
14480                 (void *)&cmd_macsec_sa_pn,
14481                 (void *)&cmd_macsec_sa_key,
14482                 NULL,
14483         },
14484 };
14485
14486 /* VF unicast promiscuous mode configuration */
14487
14488 /* Common result structure for VF unicast promiscuous mode */
14489 struct cmd_vf_promisc_result {
14490         cmdline_fixed_string_t set;
14491         cmdline_fixed_string_t vf;
14492         cmdline_fixed_string_t promisc;
14493         portid_t port_id;
14494         uint32_t vf_id;
14495         cmdline_fixed_string_t on_off;
14496 };
14497
14498 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14499 cmdline_parse_token_string_t cmd_vf_promisc_set =
14500         TOKEN_STRING_INITIALIZER
14501                 (struct cmd_vf_promisc_result,
14502                  set, "set");
14503 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14504         TOKEN_STRING_INITIALIZER
14505                 (struct cmd_vf_promisc_result,
14506                  vf, "vf");
14507 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14508         TOKEN_STRING_INITIALIZER
14509                 (struct cmd_vf_promisc_result,
14510                  promisc, "promisc");
14511 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14512         TOKEN_NUM_INITIALIZER
14513                 (struct cmd_vf_promisc_result,
14514                  port_id, UINT16);
14515 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14516         TOKEN_NUM_INITIALIZER
14517                 (struct cmd_vf_promisc_result,
14518                  vf_id, UINT32);
14519 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14520         TOKEN_STRING_INITIALIZER
14521                 (struct cmd_vf_promisc_result,
14522                  on_off, "on#off");
14523
14524 static void
14525 cmd_set_vf_promisc_parsed(
14526         void *parsed_result,
14527         __attribute__((unused)) struct cmdline *cl,
14528         __attribute__((unused)) void *data)
14529 {
14530         struct cmd_vf_promisc_result *res = parsed_result;
14531         int ret = -ENOTSUP;
14532
14533         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14534
14535         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14536                 return;
14537
14538 #ifdef RTE_LIBRTE_I40E_PMD
14539         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14540                                                   res->vf_id, is_on);
14541 #endif
14542
14543         switch (ret) {
14544         case 0:
14545                 break;
14546         case -EINVAL:
14547                 printf("invalid vf_id %d\n", res->vf_id);
14548                 break;
14549         case -ENODEV:
14550                 printf("invalid port_id %d\n", res->port_id);
14551                 break;
14552         case -ENOTSUP:
14553                 printf("function not implemented\n");
14554                 break;
14555         default:
14556                 printf("programming error: (%s)\n", strerror(-ret));
14557         }
14558 }
14559
14560 cmdline_parse_inst_t cmd_set_vf_promisc = {
14561         .f = cmd_set_vf_promisc_parsed,
14562         .data = NULL,
14563         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14564                 "Set unicast promiscuous mode for a VF from the PF",
14565         .tokens = {
14566                 (void *)&cmd_vf_promisc_set,
14567                 (void *)&cmd_vf_promisc_vf,
14568                 (void *)&cmd_vf_promisc_promisc,
14569                 (void *)&cmd_vf_promisc_port_id,
14570                 (void *)&cmd_vf_promisc_vf_id,
14571                 (void *)&cmd_vf_promisc_on_off,
14572                 NULL,
14573         },
14574 };
14575
14576 /* VF multicast promiscuous mode configuration */
14577
14578 /* Common result structure for VF multicast promiscuous mode */
14579 struct cmd_vf_allmulti_result {
14580         cmdline_fixed_string_t set;
14581         cmdline_fixed_string_t vf;
14582         cmdline_fixed_string_t allmulti;
14583         portid_t port_id;
14584         uint32_t vf_id;
14585         cmdline_fixed_string_t on_off;
14586 };
14587
14588 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14589 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14590         TOKEN_STRING_INITIALIZER
14591                 (struct cmd_vf_allmulti_result,
14592                  set, "set");
14593 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14594         TOKEN_STRING_INITIALIZER
14595                 (struct cmd_vf_allmulti_result,
14596                  vf, "vf");
14597 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14598         TOKEN_STRING_INITIALIZER
14599                 (struct cmd_vf_allmulti_result,
14600                  allmulti, "allmulti");
14601 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14602         TOKEN_NUM_INITIALIZER
14603                 (struct cmd_vf_allmulti_result,
14604                  port_id, UINT16);
14605 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14606         TOKEN_NUM_INITIALIZER
14607                 (struct cmd_vf_allmulti_result,
14608                  vf_id, UINT32);
14609 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14610         TOKEN_STRING_INITIALIZER
14611                 (struct cmd_vf_allmulti_result,
14612                  on_off, "on#off");
14613
14614 static void
14615 cmd_set_vf_allmulti_parsed(
14616         void *parsed_result,
14617         __attribute__((unused)) struct cmdline *cl,
14618         __attribute__((unused)) void *data)
14619 {
14620         struct cmd_vf_allmulti_result *res = parsed_result;
14621         int ret = -ENOTSUP;
14622
14623         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14624
14625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14626                 return;
14627
14628 #ifdef RTE_LIBRTE_I40E_PMD
14629         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14630                                                     res->vf_id, is_on);
14631 #endif
14632
14633         switch (ret) {
14634         case 0:
14635                 break;
14636         case -EINVAL:
14637                 printf("invalid vf_id %d\n", res->vf_id);
14638                 break;
14639         case -ENODEV:
14640                 printf("invalid port_id %d\n", res->port_id);
14641                 break;
14642         case -ENOTSUP:
14643                 printf("function not implemented\n");
14644                 break;
14645         default:
14646                 printf("programming error: (%s)\n", strerror(-ret));
14647         }
14648 }
14649
14650 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14651         .f = cmd_set_vf_allmulti_parsed,
14652         .data = NULL,
14653         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14654                 "Set multicast promiscuous mode for a VF from the PF",
14655         .tokens = {
14656                 (void *)&cmd_vf_allmulti_set,
14657                 (void *)&cmd_vf_allmulti_vf,
14658                 (void *)&cmd_vf_allmulti_allmulti,
14659                 (void *)&cmd_vf_allmulti_port_id,
14660                 (void *)&cmd_vf_allmulti_vf_id,
14661                 (void *)&cmd_vf_allmulti_on_off,
14662                 NULL,
14663         },
14664 };
14665
14666 /* vf broadcast mode configuration */
14667
14668 /* Common result structure for vf broadcast */
14669 struct cmd_set_vf_broadcast_result {
14670         cmdline_fixed_string_t set;
14671         cmdline_fixed_string_t vf;
14672         cmdline_fixed_string_t broadcast;
14673         portid_t port_id;
14674         uint16_t vf_id;
14675         cmdline_fixed_string_t on_off;
14676 };
14677
14678 /* Common CLI fields for vf broadcast enable disable */
14679 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14680         TOKEN_STRING_INITIALIZER
14681                 (struct cmd_set_vf_broadcast_result,
14682                  set, "set");
14683 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14684         TOKEN_STRING_INITIALIZER
14685                 (struct cmd_set_vf_broadcast_result,
14686                  vf, "vf");
14687 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14688         TOKEN_STRING_INITIALIZER
14689                 (struct cmd_set_vf_broadcast_result,
14690                  broadcast, "broadcast");
14691 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14692         TOKEN_NUM_INITIALIZER
14693                 (struct cmd_set_vf_broadcast_result,
14694                  port_id, UINT16);
14695 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14696         TOKEN_NUM_INITIALIZER
14697                 (struct cmd_set_vf_broadcast_result,
14698                  vf_id, UINT16);
14699 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14700         TOKEN_STRING_INITIALIZER
14701                 (struct cmd_set_vf_broadcast_result,
14702                  on_off, "on#off");
14703
14704 static void
14705 cmd_set_vf_broadcast_parsed(
14706         void *parsed_result,
14707         __attribute__((unused)) struct cmdline *cl,
14708         __attribute__((unused)) void *data)
14709 {
14710         struct cmd_set_vf_broadcast_result *res = parsed_result;
14711         int ret = -ENOTSUP;
14712
14713         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14714
14715         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14716                 return;
14717
14718 #ifdef RTE_LIBRTE_I40E_PMD
14719         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14720                                             res->vf_id, is_on);
14721 #endif
14722
14723         switch (ret) {
14724         case 0:
14725                 break;
14726         case -EINVAL:
14727                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14728                 break;
14729         case -ENODEV:
14730                 printf("invalid port_id %d\n", res->port_id);
14731                 break;
14732         case -ENOTSUP:
14733                 printf("function not implemented\n");
14734                 break;
14735         default:
14736                 printf("programming error: (%s)\n", strerror(-ret));
14737         }
14738 }
14739
14740 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14741         .f = cmd_set_vf_broadcast_parsed,
14742         .data = NULL,
14743         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14744         .tokens = {
14745                 (void *)&cmd_set_vf_broadcast_set,
14746                 (void *)&cmd_set_vf_broadcast_vf,
14747                 (void *)&cmd_set_vf_broadcast_broadcast,
14748                 (void *)&cmd_set_vf_broadcast_port_id,
14749                 (void *)&cmd_set_vf_broadcast_vf_id,
14750                 (void *)&cmd_set_vf_broadcast_on_off,
14751                 NULL,
14752         },
14753 };
14754
14755 /* vf vlan tag configuration */
14756
14757 /* Common result structure for vf vlan tag */
14758 struct cmd_set_vf_vlan_tag_result {
14759         cmdline_fixed_string_t set;
14760         cmdline_fixed_string_t vf;
14761         cmdline_fixed_string_t vlan;
14762         cmdline_fixed_string_t tag;
14763         portid_t port_id;
14764         uint16_t vf_id;
14765         cmdline_fixed_string_t on_off;
14766 };
14767
14768 /* Common CLI fields for vf vlan tag enable disable */
14769 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14770         TOKEN_STRING_INITIALIZER
14771                 (struct cmd_set_vf_vlan_tag_result,
14772                  set, "set");
14773 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14774         TOKEN_STRING_INITIALIZER
14775                 (struct cmd_set_vf_vlan_tag_result,
14776                  vf, "vf");
14777 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14778         TOKEN_STRING_INITIALIZER
14779                 (struct cmd_set_vf_vlan_tag_result,
14780                  vlan, "vlan");
14781 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14782         TOKEN_STRING_INITIALIZER
14783                 (struct cmd_set_vf_vlan_tag_result,
14784                  tag, "tag");
14785 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14786         TOKEN_NUM_INITIALIZER
14787                 (struct cmd_set_vf_vlan_tag_result,
14788                  port_id, UINT16);
14789 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14790         TOKEN_NUM_INITIALIZER
14791                 (struct cmd_set_vf_vlan_tag_result,
14792                  vf_id, UINT16);
14793 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14794         TOKEN_STRING_INITIALIZER
14795                 (struct cmd_set_vf_vlan_tag_result,
14796                  on_off, "on#off");
14797
14798 static void
14799 cmd_set_vf_vlan_tag_parsed(
14800         void *parsed_result,
14801         __attribute__((unused)) struct cmdline *cl,
14802         __attribute__((unused)) void *data)
14803 {
14804         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14805         int ret = -ENOTSUP;
14806
14807         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14808
14809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14810                 return;
14811
14812 #ifdef RTE_LIBRTE_I40E_PMD
14813         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14814                                            res->vf_id, is_on);
14815 #endif
14816
14817         switch (ret) {
14818         case 0:
14819                 break;
14820         case -EINVAL:
14821                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14822                 break;
14823         case -ENODEV:
14824                 printf("invalid port_id %d\n", res->port_id);
14825                 break;
14826         case -ENOTSUP:
14827                 printf("function not implemented\n");
14828                 break;
14829         default:
14830                 printf("programming error: (%s)\n", strerror(-ret));
14831         }
14832 }
14833
14834 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14835         .f = cmd_set_vf_vlan_tag_parsed,
14836         .data = NULL,
14837         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14838         .tokens = {
14839                 (void *)&cmd_set_vf_vlan_tag_set,
14840                 (void *)&cmd_set_vf_vlan_tag_vf,
14841                 (void *)&cmd_set_vf_vlan_tag_vlan,
14842                 (void *)&cmd_set_vf_vlan_tag_tag,
14843                 (void *)&cmd_set_vf_vlan_tag_port_id,
14844                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14845                 (void *)&cmd_set_vf_vlan_tag_on_off,
14846                 NULL,
14847         },
14848 };
14849
14850 /* Common definition of VF and TC TX bandwidth configuration */
14851 struct cmd_vf_tc_bw_result {
14852         cmdline_fixed_string_t set;
14853         cmdline_fixed_string_t vf;
14854         cmdline_fixed_string_t tc;
14855         cmdline_fixed_string_t tx;
14856         cmdline_fixed_string_t min_bw;
14857         cmdline_fixed_string_t max_bw;
14858         cmdline_fixed_string_t strict_link_prio;
14859         portid_t port_id;
14860         uint16_t vf_id;
14861         uint8_t tc_no;
14862         uint32_t bw;
14863         cmdline_fixed_string_t bw_list;
14864         uint8_t tc_map;
14865 };
14866
14867 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14868         TOKEN_STRING_INITIALIZER
14869                 (struct cmd_vf_tc_bw_result,
14870                  set, "set");
14871 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14872         TOKEN_STRING_INITIALIZER
14873                 (struct cmd_vf_tc_bw_result,
14874                  vf, "vf");
14875 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14876         TOKEN_STRING_INITIALIZER
14877                 (struct cmd_vf_tc_bw_result,
14878                  tc, "tc");
14879 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14880         TOKEN_STRING_INITIALIZER
14881                 (struct cmd_vf_tc_bw_result,
14882                  tx, "tx");
14883 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14884         TOKEN_STRING_INITIALIZER
14885                 (struct cmd_vf_tc_bw_result,
14886                  strict_link_prio, "strict-link-priority");
14887 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14888         TOKEN_STRING_INITIALIZER
14889                 (struct cmd_vf_tc_bw_result,
14890                  min_bw, "min-bandwidth");
14891 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14892         TOKEN_STRING_INITIALIZER
14893                 (struct cmd_vf_tc_bw_result,
14894                  max_bw, "max-bandwidth");
14895 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14896         TOKEN_NUM_INITIALIZER
14897                 (struct cmd_vf_tc_bw_result,
14898                  port_id, UINT16);
14899 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14900         TOKEN_NUM_INITIALIZER
14901                 (struct cmd_vf_tc_bw_result,
14902                  vf_id, UINT16);
14903 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14904         TOKEN_NUM_INITIALIZER
14905                 (struct cmd_vf_tc_bw_result,
14906                  tc_no, UINT8);
14907 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14908         TOKEN_NUM_INITIALIZER
14909                 (struct cmd_vf_tc_bw_result,
14910                  bw, UINT32);
14911 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14912         TOKEN_STRING_INITIALIZER
14913                 (struct cmd_vf_tc_bw_result,
14914                  bw_list, NULL);
14915 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14916         TOKEN_NUM_INITIALIZER
14917                 (struct cmd_vf_tc_bw_result,
14918                  tc_map, UINT8);
14919
14920 /* VF max bandwidth setting */
14921 static void
14922 cmd_vf_max_bw_parsed(
14923         void *parsed_result,
14924         __attribute__((unused)) struct cmdline *cl,
14925         __attribute__((unused)) void *data)
14926 {
14927         struct cmd_vf_tc_bw_result *res = parsed_result;
14928         int ret = -ENOTSUP;
14929
14930         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14931                 return;
14932
14933 #ifdef RTE_LIBRTE_I40E_PMD
14934         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14935                                          res->vf_id, res->bw);
14936 #endif
14937
14938         switch (ret) {
14939         case 0:
14940                 break;
14941         case -EINVAL:
14942                 printf("invalid vf_id %d or bandwidth %d\n",
14943                        res->vf_id, res->bw);
14944                 break;
14945         case -ENODEV:
14946                 printf("invalid port_id %d\n", res->port_id);
14947                 break;
14948         case -ENOTSUP:
14949                 printf("function not implemented\n");
14950                 break;
14951         default:
14952                 printf("programming error: (%s)\n", strerror(-ret));
14953         }
14954 }
14955
14956 cmdline_parse_inst_t cmd_vf_max_bw = {
14957         .f = cmd_vf_max_bw_parsed,
14958         .data = NULL,
14959         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14960         .tokens = {
14961                 (void *)&cmd_vf_tc_bw_set,
14962                 (void *)&cmd_vf_tc_bw_vf,
14963                 (void *)&cmd_vf_tc_bw_tx,
14964                 (void *)&cmd_vf_tc_bw_max_bw,
14965                 (void *)&cmd_vf_tc_bw_port_id,
14966                 (void *)&cmd_vf_tc_bw_vf_id,
14967                 (void *)&cmd_vf_tc_bw_bw,
14968                 NULL,
14969         },
14970 };
14971
14972 static int
14973 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14974                            uint8_t *tc_num,
14975                            char *str)
14976 {
14977         uint32_t size;
14978         const char *p, *p0 = str;
14979         char s[256];
14980         char *end;
14981         char *str_fld[16];
14982         uint16_t i;
14983         int ret;
14984
14985         p = strchr(p0, '(');
14986         if (p == NULL) {
14987                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14988                 return -1;
14989         }
14990         p++;
14991         p0 = strchr(p, ')');
14992         if (p0 == NULL) {
14993                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14994                 return -1;
14995         }
14996         size = p0 - p;
14997         if (size >= sizeof(s)) {
14998                 printf("The string size exceeds the internal buffer size\n");
14999                 return -1;
15000         }
15001         snprintf(s, sizeof(s), "%.*s", size, p);
15002         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15003         if (ret <= 0) {
15004                 printf("Failed to get the bandwidth list. ");
15005                 return -1;
15006         }
15007         *tc_num = ret;
15008         for (i = 0; i < ret; i++)
15009                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15010
15011         return 0;
15012 }
15013
15014 /* TC min bandwidth setting */
15015 static void
15016 cmd_vf_tc_min_bw_parsed(
15017         void *parsed_result,
15018         __attribute__((unused)) struct cmdline *cl,
15019         __attribute__((unused)) void *data)
15020 {
15021         struct cmd_vf_tc_bw_result *res = parsed_result;
15022         uint8_t tc_num;
15023         uint8_t bw[16];
15024         int ret = -ENOTSUP;
15025
15026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15027                 return;
15028
15029         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15030         if (ret)
15031                 return;
15032
15033 #ifdef RTE_LIBRTE_I40E_PMD
15034         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15035                                               tc_num, bw);
15036 #endif
15037
15038         switch (ret) {
15039         case 0:
15040                 break;
15041         case -EINVAL:
15042                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15043                 break;
15044         case -ENODEV:
15045                 printf("invalid port_id %d\n", res->port_id);
15046                 break;
15047         case -ENOTSUP:
15048                 printf("function not implemented\n");
15049                 break;
15050         default:
15051                 printf("programming error: (%s)\n", strerror(-ret));
15052         }
15053 }
15054
15055 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15056         .f = cmd_vf_tc_min_bw_parsed,
15057         .data = NULL,
15058         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15059                     " <bw1, bw2, ...>",
15060         .tokens = {
15061                 (void *)&cmd_vf_tc_bw_set,
15062                 (void *)&cmd_vf_tc_bw_vf,
15063                 (void *)&cmd_vf_tc_bw_tc,
15064                 (void *)&cmd_vf_tc_bw_tx,
15065                 (void *)&cmd_vf_tc_bw_min_bw,
15066                 (void *)&cmd_vf_tc_bw_port_id,
15067                 (void *)&cmd_vf_tc_bw_vf_id,
15068                 (void *)&cmd_vf_tc_bw_bw_list,
15069                 NULL,
15070         },
15071 };
15072
15073 static void
15074 cmd_tc_min_bw_parsed(
15075         void *parsed_result,
15076         __attribute__((unused)) struct cmdline *cl,
15077         __attribute__((unused)) void *data)
15078 {
15079         struct cmd_vf_tc_bw_result *res = parsed_result;
15080         struct rte_port *port;
15081         uint8_t tc_num;
15082         uint8_t bw[16];
15083         int ret = -ENOTSUP;
15084
15085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15086                 return;
15087
15088         port = &ports[res->port_id];
15089         /** Check if the port is not started **/
15090         if (port->port_status != RTE_PORT_STOPPED) {
15091                 printf("Please stop port %d first\n", res->port_id);
15092                 return;
15093         }
15094
15095         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15096         if (ret)
15097                 return;
15098
15099 #ifdef RTE_LIBRTE_IXGBE_PMD
15100         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15101 #endif
15102
15103         switch (ret) {
15104         case 0:
15105                 break;
15106         case -EINVAL:
15107                 printf("invalid bandwidth\n");
15108                 break;
15109         case -ENODEV:
15110                 printf("invalid port_id %d\n", res->port_id);
15111                 break;
15112         case -ENOTSUP:
15113                 printf("function not implemented\n");
15114                 break;
15115         default:
15116                 printf("programming error: (%s)\n", strerror(-ret));
15117         }
15118 }
15119
15120 cmdline_parse_inst_t cmd_tc_min_bw = {
15121         .f = cmd_tc_min_bw_parsed,
15122         .data = NULL,
15123         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15124         .tokens = {
15125                 (void *)&cmd_vf_tc_bw_set,
15126                 (void *)&cmd_vf_tc_bw_tc,
15127                 (void *)&cmd_vf_tc_bw_tx,
15128                 (void *)&cmd_vf_tc_bw_min_bw,
15129                 (void *)&cmd_vf_tc_bw_port_id,
15130                 (void *)&cmd_vf_tc_bw_bw_list,
15131                 NULL,
15132         },
15133 };
15134
15135 /* TC max bandwidth setting */
15136 static void
15137 cmd_vf_tc_max_bw_parsed(
15138         void *parsed_result,
15139         __attribute__((unused)) struct cmdline *cl,
15140         __attribute__((unused)) void *data)
15141 {
15142         struct cmd_vf_tc_bw_result *res = parsed_result;
15143         int ret = -ENOTSUP;
15144
15145         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15146                 return;
15147
15148 #ifdef RTE_LIBRTE_I40E_PMD
15149         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15150                                             res->tc_no, res->bw);
15151 #endif
15152
15153         switch (ret) {
15154         case 0:
15155                 break;
15156         case -EINVAL:
15157                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15158                        res->vf_id, res->tc_no, res->bw);
15159                 break;
15160         case -ENODEV:
15161                 printf("invalid port_id %d\n", res->port_id);
15162                 break;
15163         case -ENOTSUP:
15164                 printf("function not implemented\n");
15165                 break;
15166         default:
15167                 printf("programming error: (%s)\n", strerror(-ret));
15168         }
15169 }
15170
15171 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15172         .f = cmd_vf_tc_max_bw_parsed,
15173         .data = NULL,
15174         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15175                     " <bandwidth>",
15176         .tokens = {
15177                 (void *)&cmd_vf_tc_bw_set,
15178                 (void *)&cmd_vf_tc_bw_vf,
15179                 (void *)&cmd_vf_tc_bw_tc,
15180                 (void *)&cmd_vf_tc_bw_tx,
15181                 (void *)&cmd_vf_tc_bw_max_bw,
15182                 (void *)&cmd_vf_tc_bw_port_id,
15183                 (void *)&cmd_vf_tc_bw_vf_id,
15184                 (void *)&cmd_vf_tc_bw_tc_no,
15185                 (void *)&cmd_vf_tc_bw_bw,
15186                 NULL,
15187         },
15188 };
15189
15190
15191 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15192
15193 /* *** Set Port default Traffic Management Hierarchy *** */
15194 struct cmd_set_port_tm_hierarchy_default_result {
15195         cmdline_fixed_string_t set;
15196         cmdline_fixed_string_t port;
15197         cmdline_fixed_string_t tm;
15198         cmdline_fixed_string_t hierarchy;
15199         cmdline_fixed_string_t def;
15200         portid_t port_id;
15201 };
15202
15203 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15204         TOKEN_STRING_INITIALIZER(
15205                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15206 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15207         TOKEN_STRING_INITIALIZER(
15208                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15209 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15210         TOKEN_STRING_INITIALIZER(
15211                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15212 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15213         TOKEN_STRING_INITIALIZER(
15214                 struct cmd_set_port_tm_hierarchy_default_result,
15215                         hierarchy, "hierarchy");
15216 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15217         TOKEN_STRING_INITIALIZER(
15218                 struct cmd_set_port_tm_hierarchy_default_result,
15219                         def, "default");
15220 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15221         TOKEN_NUM_INITIALIZER(
15222                 struct cmd_set_port_tm_hierarchy_default_result,
15223                         port_id, UINT16);
15224
15225 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15226         __attribute__((unused)) struct cmdline *cl,
15227         __attribute__((unused)) void *data)
15228 {
15229         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15230         struct rte_port *p;
15231         portid_t port_id = res->port_id;
15232
15233         if (port_id_is_invalid(port_id, ENABLED_WARN))
15234                 return;
15235
15236         p = &ports[port_id];
15237
15238         /* Forward mode: tm */
15239         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15240                 printf("  softnicfwd mode not enabled(error)\n");
15241                 return;
15242         }
15243
15244         /* Set the default tm hierarchy */
15245         p->softport.default_tm_hierarchy_enable = 1;
15246 }
15247
15248 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15249         .f = cmd_set_port_tm_hierarchy_default_parsed,
15250         .data = NULL,
15251         .help_str = "set port tm hierarchy default <port_id>",
15252         .tokens = {
15253                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15254                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15255                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15256                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15257                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15258                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15259                 NULL,
15260         },
15261 };
15262 #endif
15263
15264 /** Set VXLAN encapsulation details */
15265 struct cmd_set_vxlan_result {
15266         cmdline_fixed_string_t set;
15267         cmdline_fixed_string_t vxlan;
15268         cmdline_fixed_string_t pos_token;
15269         cmdline_fixed_string_t ip_version;
15270         uint32_t vlan_present:1;
15271         uint32_t vni;
15272         uint16_t udp_src;
15273         uint16_t udp_dst;
15274         cmdline_ipaddr_t ip_src;
15275         cmdline_ipaddr_t ip_dst;
15276         uint16_t tci;
15277         uint8_t tos;
15278         uint8_t ttl;
15279         struct rte_ether_addr eth_src;
15280         struct rte_ether_addr eth_dst;
15281 };
15282
15283 cmdline_parse_token_string_t cmd_set_vxlan_set =
15284         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15285 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15286         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15287 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15288         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15289                                  "vxlan-tos-ttl");
15290 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15291         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15292                                  "vxlan-with-vlan");
15293 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15294         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15295                                  "ip-version");
15296 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15297         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15298                                  "ipv4#ipv6");
15299 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15300         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15301                                  "vni");
15302 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15303         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15304 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15305         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15306                                  "udp-src");
15307 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15308         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15309 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15310         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15311                                  "udp-dst");
15312 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15313         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15314 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15315         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15316                                  "ip-tos");
15317 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15318         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15319 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15320         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15321                                  "ip-ttl");
15322 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15323         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15324 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15325         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15326                                  "ip-src");
15327 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15328         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15329 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15330         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15331                                  "ip-dst");
15332 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15333         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15334 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15335         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15336                                  "vlan-tci");
15337 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15338         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15339 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15340         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15341                                  "eth-src");
15342 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15343         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15344 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15345         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15346                                  "eth-dst");
15347 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15348         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15349
15350 static void cmd_set_vxlan_parsed(void *parsed_result,
15351         __attribute__((unused)) struct cmdline *cl,
15352         __attribute__((unused)) void *data)
15353 {
15354         struct cmd_set_vxlan_result *res = parsed_result;
15355         union {
15356                 uint32_t vxlan_id;
15357                 uint8_t vni[4];
15358         } id = {
15359                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15360         };
15361
15362         vxlan_encap_conf.select_tos_ttl = 0;
15363         if (strcmp(res->vxlan, "vxlan") == 0)
15364                 vxlan_encap_conf.select_vlan = 0;
15365         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15366                 vxlan_encap_conf.select_vlan = 1;
15367         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15368                 vxlan_encap_conf.select_vlan = 0;
15369                 vxlan_encap_conf.select_tos_ttl = 1;
15370         }
15371         if (strcmp(res->ip_version, "ipv4") == 0)
15372                 vxlan_encap_conf.select_ipv4 = 1;
15373         else if (strcmp(res->ip_version, "ipv6") == 0)
15374                 vxlan_encap_conf.select_ipv4 = 0;
15375         else
15376                 return;
15377         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15378         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15379         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15380         vxlan_encap_conf.ip_tos = res->tos;
15381         vxlan_encap_conf.ip_ttl = res->ttl;
15382         if (vxlan_encap_conf.select_ipv4) {
15383                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15384                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15385         } else {
15386                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15387                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15388         }
15389         if (vxlan_encap_conf.select_vlan)
15390                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15391         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15392                    RTE_ETHER_ADDR_LEN);
15393         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15394                    RTE_ETHER_ADDR_LEN);
15395 }
15396
15397 cmdline_parse_inst_t cmd_set_vxlan = {
15398         .f = cmd_set_vxlan_parsed,
15399         .data = NULL,
15400         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15401                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15402                 " eth-src <eth-src> eth-dst <eth-dst>",
15403         .tokens = {
15404                 (void *)&cmd_set_vxlan_set,
15405                 (void *)&cmd_set_vxlan_vxlan,
15406                 (void *)&cmd_set_vxlan_ip_version,
15407                 (void *)&cmd_set_vxlan_ip_version_value,
15408                 (void *)&cmd_set_vxlan_vni,
15409                 (void *)&cmd_set_vxlan_vni_value,
15410                 (void *)&cmd_set_vxlan_udp_src,
15411                 (void *)&cmd_set_vxlan_udp_src_value,
15412                 (void *)&cmd_set_vxlan_udp_dst,
15413                 (void *)&cmd_set_vxlan_udp_dst_value,
15414                 (void *)&cmd_set_vxlan_ip_src,
15415                 (void *)&cmd_set_vxlan_ip_src_value,
15416                 (void *)&cmd_set_vxlan_ip_dst,
15417                 (void *)&cmd_set_vxlan_ip_dst_value,
15418                 (void *)&cmd_set_vxlan_eth_src,
15419                 (void *)&cmd_set_vxlan_eth_src_value,
15420                 (void *)&cmd_set_vxlan_eth_dst,
15421                 (void *)&cmd_set_vxlan_eth_dst_value,
15422                 NULL,
15423         },
15424 };
15425
15426 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15427         .f = cmd_set_vxlan_parsed,
15428         .data = NULL,
15429         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15430                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15431                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15432                 " eth-dst <eth-dst>",
15433         .tokens = {
15434                 (void *)&cmd_set_vxlan_set,
15435                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15436                 (void *)&cmd_set_vxlan_ip_version,
15437                 (void *)&cmd_set_vxlan_ip_version_value,
15438                 (void *)&cmd_set_vxlan_vni,
15439                 (void *)&cmd_set_vxlan_vni_value,
15440                 (void *)&cmd_set_vxlan_udp_src,
15441                 (void *)&cmd_set_vxlan_udp_src_value,
15442                 (void *)&cmd_set_vxlan_udp_dst,
15443                 (void *)&cmd_set_vxlan_udp_dst_value,
15444                 (void *)&cmd_set_vxlan_ip_tos,
15445                 (void *)&cmd_set_vxlan_ip_tos_value,
15446                 (void *)&cmd_set_vxlan_ip_ttl,
15447                 (void *)&cmd_set_vxlan_ip_ttl_value,
15448                 (void *)&cmd_set_vxlan_ip_src,
15449                 (void *)&cmd_set_vxlan_ip_src_value,
15450                 (void *)&cmd_set_vxlan_ip_dst,
15451                 (void *)&cmd_set_vxlan_ip_dst_value,
15452                 (void *)&cmd_set_vxlan_eth_src,
15453                 (void *)&cmd_set_vxlan_eth_src_value,
15454                 (void *)&cmd_set_vxlan_eth_dst,
15455                 (void *)&cmd_set_vxlan_eth_dst_value,
15456                 NULL,
15457         },
15458 };
15459
15460 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15461         .f = cmd_set_vxlan_parsed,
15462         .data = NULL,
15463         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15464                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15465                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15466                 " <eth-dst>",
15467         .tokens = {
15468                 (void *)&cmd_set_vxlan_set,
15469                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15470                 (void *)&cmd_set_vxlan_ip_version,
15471                 (void *)&cmd_set_vxlan_ip_version_value,
15472                 (void *)&cmd_set_vxlan_vni,
15473                 (void *)&cmd_set_vxlan_vni_value,
15474                 (void *)&cmd_set_vxlan_udp_src,
15475                 (void *)&cmd_set_vxlan_udp_src_value,
15476                 (void *)&cmd_set_vxlan_udp_dst,
15477                 (void *)&cmd_set_vxlan_udp_dst_value,
15478                 (void *)&cmd_set_vxlan_ip_src,
15479                 (void *)&cmd_set_vxlan_ip_src_value,
15480                 (void *)&cmd_set_vxlan_ip_dst,
15481                 (void *)&cmd_set_vxlan_ip_dst_value,
15482                 (void *)&cmd_set_vxlan_vlan,
15483                 (void *)&cmd_set_vxlan_vlan_value,
15484                 (void *)&cmd_set_vxlan_eth_src,
15485                 (void *)&cmd_set_vxlan_eth_src_value,
15486                 (void *)&cmd_set_vxlan_eth_dst,
15487                 (void *)&cmd_set_vxlan_eth_dst_value,
15488                 NULL,
15489         },
15490 };
15491
15492 /** Set NVGRE encapsulation details */
15493 struct cmd_set_nvgre_result {
15494         cmdline_fixed_string_t set;
15495         cmdline_fixed_string_t nvgre;
15496         cmdline_fixed_string_t pos_token;
15497         cmdline_fixed_string_t ip_version;
15498         uint32_t tni;
15499         cmdline_ipaddr_t ip_src;
15500         cmdline_ipaddr_t ip_dst;
15501         uint16_t tci;
15502         struct rte_ether_addr eth_src;
15503         struct rte_ether_addr eth_dst;
15504 };
15505
15506 cmdline_parse_token_string_t cmd_set_nvgre_set =
15507         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15508 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15509         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15510 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15511         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15512                                  "nvgre-with-vlan");
15513 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15514         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15515                                  "ip-version");
15516 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15517         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15518                                  "ipv4#ipv6");
15519 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15520         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15521                                  "tni");
15522 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15523         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15524 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15525         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15526                                  "ip-src");
15527 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15528         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15529 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15530         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15531                                  "ip-dst");
15532 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15533         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15534 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15535         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15536                                  "vlan-tci");
15537 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15538         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15539 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15540         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15541                                  "eth-src");
15542 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15543         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15544 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15545         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15546                                  "eth-dst");
15547 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15548         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15549
15550 static void cmd_set_nvgre_parsed(void *parsed_result,
15551         __attribute__((unused)) struct cmdline *cl,
15552         __attribute__((unused)) void *data)
15553 {
15554         struct cmd_set_nvgre_result *res = parsed_result;
15555         union {
15556                 uint32_t nvgre_tni;
15557                 uint8_t tni[4];
15558         } id = {
15559                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15560         };
15561
15562         if (strcmp(res->nvgre, "nvgre") == 0)
15563                 nvgre_encap_conf.select_vlan = 0;
15564         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15565                 nvgre_encap_conf.select_vlan = 1;
15566         if (strcmp(res->ip_version, "ipv4") == 0)
15567                 nvgre_encap_conf.select_ipv4 = 1;
15568         else if (strcmp(res->ip_version, "ipv6") == 0)
15569                 nvgre_encap_conf.select_ipv4 = 0;
15570         else
15571                 return;
15572         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15573         if (nvgre_encap_conf.select_ipv4) {
15574                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15575                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15576         } else {
15577                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15578                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15579         }
15580         if (nvgre_encap_conf.select_vlan)
15581                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15582         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15583                    RTE_ETHER_ADDR_LEN);
15584         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15585                    RTE_ETHER_ADDR_LEN);
15586 }
15587
15588 cmdline_parse_inst_t cmd_set_nvgre = {
15589         .f = cmd_set_nvgre_parsed,
15590         .data = NULL,
15591         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15592                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15593                 " eth-dst <eth-dst>",
15594         .tokens = {
15595                 (void *)&cmd_set_nvgre_set,
15596                 (void *)&cmd_set_nvgre_nvgre,
15597                 (void *)&cmd_set_nvgre_ip_version,
15598                 (void *)&cmd_set_nvgre_ip_version_value,
15599                 (void *)&cmd_set_nvgre_tni,
15600                 (void *)&cmd_set_nvgre_tni_value,
15601                 (void *)&cmd_set_nvgre_ip_src,
15602                 (void *)&cmd_set_nvgre_ip_src_value,
15603                 (void *)&cmd_set_nvgre_ip_dst,
15604                 (void *)&cmd_set_nvgre_ip_dst_value,
15605                 (void *)&cmd_set_nvgre_eth_src,
15606                 (void *)&cmd_set_nvgre_eth_src_value,
15607                 (void *)&cmd_set_nvgre_eth_dst,
15608                 (void *)&cmd_set_nvgre_eth_dst_value,
15609                 NULL,
15610         },
15611 };
15612
15613 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15614         .f = cmd_set_nvgre_parsed,
15615         .data = NULL,
15616         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15617                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15618                 " eth-src <eth-src> eth-dst <eth-dst>",
15619         .tokens = {
15620                 (void *)&cmd_set_nvgre_set,
15621                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15622                 (void *)&cmd_set_nvgre_ip_version,
15623                 (void *)&cmd_set_nvgre_ip_version_value,
15624                 (void *)&cmd_set_nvgre_tni,
15625                 (void *)&cmd_set_nvgre_tni_value,
15626                 (void *)&cmd_set_nvgre_ip_src,
15627                 (void *)&cmd_set_nvgre_ip_src_value,
15628                 (void *)&cmd_set_nvgre_ip_dst,
15629                 (void *)&cmd_set_nvgre_ip_dst_value,
15630                 (void *)&cmd_set_nvgre_vlan,
15631                 (void *)&cmd_set_nvgre_vlan_value,
15632                 (void *)&cmd_set_nvgre_eth_src,
15633                 (void *)&cmd_set_nvgre_eth_src_value,
15634                 (void *)&cmd_set_nvgre_eth_dst,
15635                 (void *)&cmd_set_nvgre_eth_dst_value,
15636                 NULL,
15637         },
15638 };
15639
15640 /** Set L2 encapsulation details */
15641 struct cmd_set_l2_encap_result {
15642         cmdline_fixed_string_t set;
15643         cmdline_fixed_string_t l2_encap;
15644         cmdline_fixed_string_t pos_token;
15645         cmdline_fixed_string_t ip_version;
15646         uint32_t vlan_present:1;
15647         uint16_t tci;
15648         struct rte_ether_addr eth_src;
15649         struct rte_ether_addr eth_dst;
15650 };
15651
15652 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15653         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15654 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15655         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15656 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15657         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15658                                  "l2_encap-with-vlan");
15659 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15660         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15661                                  "ip-version");
15662 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15663         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15664                                  "ipv4#ipv6");
15665 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15666         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15667                                  "vlan-tci");
15668 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15669         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15670 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15671         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15672                                  "eth-src");
15673 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15674         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15675 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15676         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15677                                  "eth-dst");
15678 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15679         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15680
15681 static void cmd_set_l2_encap_parsed(void *parsed_result,
15682         __attribute__((unused)) struct cmdline *cl,
15683         __attribute__((unused)) void *data)
15684 {
15685         struct cmd_set_l2_encap_result *res = parsed_result;
15686
15687         if (strcmp(res->l2_encap, "l2_encap") == 0)
15688                 l2_encap_conf.select_vlan = 0;
15689         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15690                 l2_encap_conf.select_vlan = 1;
15691         if (strcmp(res->ip_version, "ipv4") == 0)
15692                 l2_encap_conf.select_ipv4 = 1;
15693         else if (strcmp(res->ip_version, "ipv6") == 0)
15694                 l2_encap_conf.select_ipv4 = 0;
15695         else
15696                 return;
15697         if (l2_encap_conf.select_vlan)
15698                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15699         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15700                    RTE_ETHER_ADDR_LEN);
15701         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15702                    RTE_ETHER_ADDR_LEN);
15703 }
15704
15705 cmdline_parse_inst_t cmd_set_l2_encap = {
15706         .f = cmd_set_l2_encap_parsed,
15707         .data = NULL,
15708         .help_str = "set l2_encap ip-version ipv4|ipv6"
15709                 " eth-src <eth-src> eth-dst <eth-dst>",
15710         .tokens = {
15711                 (void *)&cmd_set_l2_encap_set,
15712                 (void *)&cmd_set_l2_encap_l2_encap,
15713                 (void *)&cmd_set_l2_encap_ip_version,
15714                 (void *)&cmd_set_l2_encap_ip_version_value,
15715                 (void *)&cmd_set_l2_encap_eth_src,
15716                 (void *)&cmd_set_l2_encap_eth_src_value,
15717                 (void *)&cmd_set_l2_encap_eth_dst,
15718                 (void *)&cmd_set_l2_encap_eth_dst_value,
15719                 NULL,
15720         },
15721 };
15722
15723 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15724         .f = cmd_set_l2_encap_parsed,
15725         .data = NULL,
15726         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15727                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15728         .tokens = {
15729                 (void *)&cmd_set_l2_encap_set,
15730                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15731                 (void *)&cmd_set_l2_encap_ip_version,
15732                 (void *)&cmd_set_l2_encap_ip_version_value,
15733                 (void *)&cmd_set_l2_encap_vlan,
15734                 (void *)&cmd_set_l2_encap_vlan_value,
15735                 (void *)&cmd_set_l2_encap_eth_src,
15736                 (void *)&cmd_set_l2_encap_eth_src_value,
15737                 (void *)&cmd_set_l2_encap_eth_dst,
15738                 (void *)&cmd_set_l2_encap_eth_dst_value,
15739                 NULL,
15740         },
15741 };
15742
15743 /** Set L2 decapsulation details */
15744 struct cmd_set_l2_decap_result {
15745         cmdline_fixed_string_t set;
15746         cmdline_fixed_string_t l2_decap;
15747         cmdline_fixed_string_t pos_token;
15748         uint32_t vlan_present:1;
15749 };
15750
15751 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15752         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15753 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15754         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15755                                  "l2_decap");
15756 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15757         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15758                                  "l2_decap-with-vlan");
15759
15760 static void cmd_set_l2_decap_parsed(void *parsed_result,
15761         __attribute__((unused)) struct cmdline *cl,
15762         __attribute__((unused)) void *data)
15763 {
15764         struct cmd_set_l2_decap_result *res = parsed_result;
15765
15766         if (strcmp(res->l2_decap, "l2_decap") == 0)
15767                 l2_decap_conf.select_vlan = 0;
15768         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15769                 l2_decap_conf.select_vlan = 1;
15770 }
15771
15772 cmdline_parse_inst_t cmd_set_l2_decap = {
15773         .f = cmd_set_l2_decap_parsed,
15774         .data = NULL,
15775         .help_str = "set l2_decap",
15776         .tokens = {
15777                 (void *)&cmd_set_l2_decap_set,
15778                 (void *)&cmd_set_l2_decap_l2_decap,
15779                 NULL,
15780         },
15781 };
15782
15783 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15784         .f = cmd_set_l2_decap_parsed,
15785         .data = NULL,
15786         .help_str = "set l2_decap-with-vlan",
15787         .tokens = {
15788                 (void *)&cmd_set_l2_decap_set,
15789                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15790                 NULL,
15791         },
15792 };
15793
15794 /** Set MPLSoGRE encapsulation details */
15795 struct cmd_set_mplsogre_encap_result {
15796         cmdline_fixed_string_t set;
15797         cmdline_fixed_string_t mplsogre;
15798         cmdline_fixed_string_t pos_token;
15799         cmdline_fixed_string_t ip_version;
15800         uint32_t vlan_present:1;
15801         uint32_t label;
15802         cmdline_ipaddr_t ip_src;
15803         cmdline_ipaddr_t ip_dst;
15804         uint16_t tci;
15805         struct rte_ether_addr eth_src;
15806         struct rte_ether_addr eth_dst;
15807 };
15808
15809 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15810         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15811                                  "set");
15812 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15813         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15814                                  "mplsogre_encap");
15815 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15816         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15817                                  mplsogre, "mplsogre_encap-with-vlan");
15818 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15819         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15820                                  pos_token, "ip-version");
15821 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15822         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15823                                  ip_version, "ipv4#ipv6");
15824 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15825         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15826                                  pos_token, "label");
15827 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15828         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15829                               UINT32);
15830 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15831         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15832                                  pos_token, "ip-src");
15833 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15834         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15835 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15836         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15837                                  pos_token, "ip-dst");
15838 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15839         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15840 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15841         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15842                                  pos_token, "vlan-tci");
15843 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15844         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15845                               UINT16);
15846 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15847         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15848                                  pos_token, "eth-src");
15849 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15850         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15851                                     eth_src);
15852 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15853         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15854                                  pos_token, "eth-dst");
15855 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15856         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15857                                     eth_dst);
15858
15859 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15860         __attribute__((unused)) struct cmdline *cl,
15861         __attribute__((unused)) void *data)
15862 {
15863         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15864         union {
15865                 uint32_t mplsogre_label;
15866                 uint8_t label[4];
15867         } id = {
15868                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15869         };
15870
15871         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15872                 mplsogre_encap_conf.select_vlan = 0;
15873         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15874                 mplsogre_encap_conf.select_vlan = 1;
15875         if (strcmp(res->ip_version, "ipv4") == 0)
15876                 mplsogre_encap_conf.select_ipv4 = 1;
15877         else if (strcmp(res->ip_version, "ipv6") == 0)
15878                 mplsogre_encap_conf.select_ipv4 = 0;
15879         else
15880                 return;
15881         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15882         if (mplsogre_encap_conf.select_ipv4) {
15883                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15884                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15885         } else {
15886                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15887                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15888         }
15889         if (mplsogre_encap_conf.select_vlan)
15890                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15891         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15892                    RTE_ETHER_ADDR_LEN);
15893         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15894                    RTE_ETHER_ADDR_LEN);
15895 }
15896
15897 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15898         .f = cmd_set_mplsogre_encap_parsed,
15899         .data = NULL,
15900         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15901                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15902                 " eth-dst <eth-dst>",
15903         .tokens = {
15904                 (void *)&cmd_set_mplsogre_encap_set,
15905                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15906                 (void *)&cmd_set_mplsogre_encap_ip_version,
15907                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15908                 (void *)&cmd_set_mplsogre_encap_label,
15909                 (void *)&cmd_set_mplsogre_encap_label_value,
15910                 (void *)&cmd_set_mplsogre_encap_ip_src,
15911                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15912                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15913                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15914                 (void *)&cmd_set_mplsogre_encap_eth_src,
15915                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15916                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15917                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15918                 NULL,
15919         },
15920 };
15921
15922 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15923         .f = cmd_set_mplsogre_encap_parsed,
15924         .data = NULL,
15925         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15926                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15927                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15928         .tokens = {
15929                 (void *)&cmd_set_mplsogre_encap_set,
15930                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15931                 (void *)&cmd_set_mplsogre_encap_ip_version,
15932                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15933                 (void *)&cmd_set_mplsogre_encap_label,
15934                 (void *)&cmd_set_mplsogre_encap_label_value,
15935                 (void *)&cmd_set_mplsogre_encap_ip_src,
15936                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15937                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15938                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15939                 (void *)&cmd_set_mplsogre_encap_vlan,
15940                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15941                 (void *)&cmd_set_mplsogre_encap_eth_src,
15942                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15943                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15944                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15945                 NULL,
15946         },
15947 };
15948
15949 /** Set MPLSoGRE decapsulation details */
15950 struct cmd_set_mplsogre_decap_result {
15951         cmdline_fixed_string_t set;
15952         cmdline_fixed_string_t mplsogre;
15953         cmdline_fixed_string_t pos_token;
15954         cmdline_fixed_string_t ip_version;
15955         uint32_t vlan_present:1;
15956 };
15957
15958 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15959         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15960                                  "set");
15961 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15962         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15963                                  "mplsogre_decap");
15964 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15965         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15966                                  mplsogre, "mplsogre_decap-with-vlan");
15967 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15968         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15969                                  pos_token, "ip-version");
15970 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15971         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15972                                  ip_version, "ipv4#ipv6");
15973
15974 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15975         __attribute__((unused)) struct cmdline *cl,
15976         __attribute__((unused)) void *data)
15977 {
15978         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15979
15980         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15981                 mplsogre_decap_conf.select_vlan = 0;
15982         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15983                 mplsogre_decap_conf.select_vlan = 1;
15984         if (strcmp(res->ip_version, "ipv4") == 0)
15985                 mplsogre_decap_conf.select_ipv4 = 1;
15986         else if (strcmp(res->ip_version, "ipv6") == 0)
15987                 mplsogre_decap_conf.select_ipv4 = 0;
15988 }
15989
15990 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15991         .f = cmd_set_mplsogre_decap_parsed,
15992         .data = NULL,
15993         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15994         .tokens = {
15995                 (void *)&cmd_set_mplsogre_decap_set,
15996                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15997                 (void *)&cmd_set_mplsogre_decap_ip_version,
15998                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15999                 NULL,
16000         },
16001 };
16002
16003 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16004         .f = cmd_set_mplsogre_decap_parsed,
16005         .data = NULL,
16006         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16007         .tokens = {
16008                 (void *)&cmd_set_mplsogre_decap_set,
16009                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16010                 (void *)&cmd_set_mplsogre_decap_ip_version,
16011                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16012                 NULL,
16013         },
16014 };
16015
16016 /** Set MPLSoUDP encapsulation details */
16017 struct cmd_set_mplsoudp_encap_result {
16018         cmdline_fixed_string_t set;
16019         cmdline_fixed_string_t mplsoudp;
16020         cmdline_fixed_string_t pos_token;
16021         cmdline_fixed_string_t ip_version;
16022         uint32_t vlan_present:1;
16023         uint32_t label;
16024         uint16_t udp_src;
16025         uint16_t udp_dst;
16026         cmdline_ipaddr_t ip_src;
16027         cmdline_ipaddr_t ip_dst;
16028         uint16_t tci;
16029         struct rte_ether_addr eth_src;
16030         struct rte_ether_addr eth_dst;
16031 };
16032
16033 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16034         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16035                                  "set");
16036 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16037         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16038                                  "mplsoudp_encap");
16039 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16040         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16041                                  mplsoudp, "mplsoudp_encap-with-vlan");
16042 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16043         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16044                                  pos_token, "ip-version");
16045 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16046         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16047                                  ip_version, "ipv4#ipv6");
16048 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16049         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16050                                  pos_token, "label");
16051 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16052         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16053                               UINT32);
16054 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16055         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16056                                  pos_token, "udp-src");
16057 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16058         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16059                               UINT16);
16060 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16061         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16062                                  pos_token, "udp-dst");
16063 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16064         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16065                               UINT16);
16066 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16067         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16068                                  pos_token, "ip-src");
16069 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16070         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16071 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16072         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16073                                  pos_token, "ip-dst");
16074 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16075         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16076 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16077         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16078                                  pos_token, "vlan-tci");
16079 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16080         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16081                               UINT16);
16082 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16083         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16084                                  pos_token, "eth-src");
16085 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16086         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16087                                     eth_src);
16088 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16089         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16090                                  pos_token, "eth-dst");
16091 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16092         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16093                                     eth_dst);
16094
16095 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16096         __attribute__((unused)) struct cmdline *cl,
16097         __attribute__((unused)) void *data)
16098 {
16099         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16100         union {
16101                 uint32_t mplsoudp_label;
16102                 uint8_t label[4];
16103         } id = {
16104                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16105         };
16106
16107         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16108                 mplsoudp_encap_conf.select_vlan = 0;
16109         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16110                 mplsoudp_encap_conf.select_vlan = 1;
16111         if (strcmp(res->ip_version, "ipv4") == 0)
16112                 mplsoudp_encap_conf.select_ipv4 = 1;
16113         else if (strcmp(res->ip_version, "ipv6") == 0)
16114                 mplsoudp_encap_conf.select_ipv4 = 0;
16115         else
16116                 return;
16117         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16118         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16119         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16120         if (mplsoudp_encap_conf.select_ipv4) {
16121                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16122                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16123         } else {
16124                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16125                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16126         }
16127         if (mplsoudp_encap_conf.select_vlan)
16128                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16129         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16130                    RTE_ETHER_ADDR_LEN);
16131         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16132                    RTE_ETHER_ADDR_LEN);
16133 }
16134
16135 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16136         .f = cmd_set_mplsoudp_encap_parsed,
16137         .data = NULL,
16138         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16139                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16140                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16141         .tokens = {
16142                 (void *)&cmd_set_mplsoudp_encap_set,
16143                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16144                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16145                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16146                 (void *)&cmd_set_mplsoudp_encap_label,
16147                 (void *)&cmd_set_mplsoudp_encap_label_value,
16148                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16149                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16150                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16151                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16152                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16153                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16154                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16155                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16156                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16157                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16158                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16159                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16160                 NULL,
16161         },
16162 };
16163
16164 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16165         .f = cmd_set_mplsoudp_encap_parsed,
16166         .data = NULL,
16167         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16168                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16169                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16170                 " eth-src <eth-src> eth-dst <eth-dst>",
16171         .tokens = {
16172                 (void *)&cmd_set_mplsoudp_encap_set,
16173                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16174                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16175                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16176                 (void *)&cmd_set_mplsoudp_encap_label,
16177                 (void *)&cmd_set_mplsoudp_encap_label_value,
16178                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16179                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16180                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16181                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16182                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16183                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16184                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16185                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16186                 (void *)&cmd_set_mplsoudp_encap_vlan,
16187                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16188                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16189                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16190                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16191                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16192                 NULL,
16193         },
16194 };
16195
16196 /** Set MPLSoUDP decapsulation details */
16197 struct cmd_set_mplsoudp_decap_result {
16198         cmdline_fixed_string_t set;
16199         cmdline_fixed_string_t mplsoudp;
16200         cmdline_fixed_string_t pos_token;
16201         cmdline_fixed_string_t ip_version;
16202         uint32_t vlan_present:1;
16203 };
16204
16205 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16206         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16207                                  "set");
16208 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16209         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16210                                  "mplsoudp_decap");
16211 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16212         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16213                                  mplsoudp, "mplsoudp_decap-with-vlan");
16214 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16215         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16216                                  pos_token, "ip-version");
16217 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16218         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16219                                  ip_version, "ipv4#ipv6");
16220
16221 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16222         __attribute__((unused)) struct cmdline *cl,
16223         __attribute__((unused)) void *data)
16224 {
16225         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16226
16227         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16228                 mplsoudp_decap_conf.select_vlan = 0;
16229         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16230                 mplsoudp_decap_conf.select_vlan = 1;
16231         if (strcmp(res->ip_version, "ipv4") == 0)
16232                 mplsoudp_decap_conf.select_ipv4 = 1;
16233         else if (strcmp(res->ip_version, "ipv6") == 0)
16234                 mplsoudp_decap_conf.select_ipv4 = 0;
16235 }
16236
16237 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16238         .f = cmd_set_mplsoudp_decap_parsed,
16239         .data = NULL,
16240         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16241         .tokens = {
16242                 (void *)&cmd_set_mplsoudp_decap_set,
16243                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16244                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16245                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16246                 NULL,
16247         },
16248 };
16249
16250 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16251         .f = cmd_set_mplsoudp_decap_parsed,
16252         .data = NULL,
16253         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16254         .tokens = {
16255                 (void *)&cmd_set_mplsoudp_decap_set,
16256                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16257                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16258                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16259                 NULL,
16260         },
16261 };
16262
16263 /* Strict link priority scheduling mode setting */
16264 static void
16265 cmd_strict_link_prio_parsed(
16266         void *parsed_result,
16267         __attribute__((unused)) struct cmdline *cl,
16268         __attribute__((unused)) void *data)
16269 {
16270         struct cmd_vf_tc_bw_result *res = parsed_result;
16271         int ret = -ENOTSUP;
16272
16273         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16274                 return;
16275
16276 #ifdef RTE_LIBRTE_I40E_PMD
16277         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16278 #endif
16279
16280         switch (ret) {
16281         case 0:
16282                 break;
16283         case -EINVAL:
16284                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16285                 break;
16286         case -ENODEV:
16287                 printf("invalid port_id %d\n", res->port_id);
16288                 break;
16289         case -ENOTSUP:
16290                 printf("function not implemented\n");
16291                 break;
16292         default:
16293                 printf("programming error: (%s)\n", strerror(-ret));
16294         }
16295 }
16296
16297 cmdline_parse_inst_t cmd_strict_link_prio = {
16298         .f = cmd_strict_link_prio_parsed,
16299         .data = NULL,
16300         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16301         .tokens = {
16302                 (void *)&cmd_vf_tc_bw_set,
16303                 (void *)&cmd_vf_tc_bw_tx,
16304                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16305                 (void *)&cmd_vf_tc_bw_port_id,
16306                 (void *)&cmd_vf_tc_bw_tc_map,
16307                 NULL,
16308         },
16309 };
16310
16311 /* Load dynamic device personalization*/
16312 struct cmd_ddp_add_result {
16313         cmdline_fixed_string_t ddp;
16314         cmdline_fixed_string_t add;
16315         portid_t port_id;
16316         char filepath[];
16317 };
16318
16319 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16320         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16321 cmdline_parse_token_string_t cmd_ddp_add_add =
16322         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16323 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16324         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16325 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16326         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16327
16328 static void
16329 cmd_ddp_add_parsed(
16330         void *parsed_result,
16331         __attribute__((unused)) struct cmdline *cl,
16332         __attribute__((unused)) void *data)
16333 {
16334         struct cmd_ddp_add_result *res = parsed_result;
16335         uint8_t *buff;
16336         uint32_t size;
16337         char *filepath;
16338         char *file_fld[2];
16339         int file_num;
16340         int ret = -ENOTSUP;
16341
16342         if (!all_ports_stopped()) {
16343                 printf("Please stop all ports first\n");
16344                 return;
16345         }
16346
16347         filepath = strdup(res->filepath);
16348         if (filepath == NULL) {
16349                 printf("Failed to allocate memory\n");
16350                 return;
16351         }
16352         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16353
16354         buff = open_file(file_fld[0], &size);
16355         if (!buff) {
16356                 free((void *)filepath);
16357                 return;
16358         }
16359
16360 #ifdef RTE_LIBRTE_I40E_PMD
16361         if (ret == -ENOTSUP)
16362                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16363                                                buff, size,
16364                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16365 #endif
16366
16367         if (ret == -EEXIST)
16368                 printf("Profile has already existed.\n");
16369         else if (ret < 0)
16370                 printf("Failed to load profile.\n");
16371         else if (file_num == 2)
16372                 save_file(file_fld[1], buff, size);
16373
16374         close_file(buff);
16375         free((void *)filepath);
16376 }
16377
16378 cmdline_parse_inst_t cmd_ddp_add = {
16379         .f = cmd_ddp_add_parsed,
16380         .data = NULL,
16381         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16382         .tokens = {
16383                 (void *)&cmd_ddp_add_ddp,
16384                 (void *)&cmd_ddp_add_add,
16385                 (void *)&cmd_ddp_add_port_id,
16386                 (void *)&cmd_ddp_add_filepath,
16387                 NULL,
16388         },
16389 };
16390
16391 /* Delete dynamic device personalization*/
16392 struct cmd_ddp_del_result {
16393         cmdline_fixed_string_t ddp;
16394         cmdline_fixed_string_t del;
16395         portid_t port_id;
16396         char filepath[];
16397 };
16398
16399 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16400         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16401 cmdline_parse_token_string_t cmd_ddp_del_del =
16402         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16403 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16404         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16405 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16406         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16407
16408 static void
16409 cmd_ddp_del_parsed(
16410         void *parsed_result,
16411         __attribute__((unused)) struct cmdline *cl,
16412         __attribute__((unused)) void *data)
16413 {
16414         struct cmd_ddp_del_result *res = parsed_result;
16415         uint8_t *buff;
16416         uint32_t size;
16417         int ret = -ENOTSUP;
16418
16419         if (!all_ports_stopped()) {
16420                 printf("Please stop all ports first\n");
16421                 return;
16422         }
16423
16424         buff = open_file(res->filepath, &size);
16425         if (!buff)
16426                 return;
16427
16428 #ifdef RTE_LIBRTE_I40E_PMD
16429         if (ret == -ENOTSUP)
16430                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16431                                                buff, size,
16432                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16433 #endif
16434
16435         if (ret == -EACCES)
16436                 printf("Profile does not exist.\n");
16437         else if (ret < 0)
16438                 printf("Failed to delete profile.\n");
16439
16440         close_file(buff);
16441 }
16442
16443 cmdline_parse_inst_t cmd_ddp_del = {
16444         .f = cmd_ddp_del_parsed,
16445         .data = NULL,
16446         .help_str = "ddp del <port_id> <backup_profile_path>",
16447         .tokens = {
16448                 (void *)&cmd_ddp_del_ddp,
16449                 (void *)&cmd_ddp_del_del,
16450                 (void *)&cmd_ddp_del_port_id,
16451                 (void *)&cmd_ddp_del_filepath,
16452                 NULL,
16453         },
16454 };
16455
16456 /* Get dynamic device personalization profile info */
16457 struct cmd_ddp_info_result {
16458         cmdline_fixed_string_t ddp;
16459         cmdline_fixed_string_t get;
16460         cmdline_fixed_string_t info;
16461         char filepath[];
16462 };
16463
16464 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16465         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16466 cmdline_parse_token_string_t cmd_ddp_info_get =
16467         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16468 cmdline_parse_token_string_t cmd_ddp_info_info =
16469         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16470 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16471         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16472
16473 static void
16474 cmd_ddp_info_parsed(
16475         void *parsed_result,
16476         __attribute__((unused)) struct cmdline *cl,
16477         __attribute__((unused)) void *data)
16478 {
16479         struct cmd_ddp_info_result *res = parsed_result;
16480         uint8_t *pkg;
16481         uint32_t pkg_size;
16482         int ret = -ENOTSUP;
16483 #ifdef RTE_LIBRTE_I40E_PMD
16484         uint32_t i, j, n;
16485         uint8_t *buff;
16486         uint32_t buff_size = 0;
16487         struct rte_pmd_i40e_profile_info info;
16488         uint32_t dev_num = 0;
16489         struct rte_pmd_i40e_ddp_device_id *devs;
16490         uint32_t proto_num = 0;
16491         struct rte_pmd_i40e_proto_info *proto = NULL;
16492         uint32_t pctype_num = 0;
16493         struct rte_pmd_i40e_ptype_info *pctype;
16494         uint32_t ptype_num = 0;
16495         struct rte_pmd_i40e_ptype_info *ptype;
16496         uint8_t proto_id;
16497
16498 #endif
16499
16500         pkg = open_file(res->filepath, &pkg_size);
16501         if (!pkg)
16502                 return;
16503
16504 #ifdef RTE_LIBRTE_I40E_PMD
16505         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16506                                 (uint8_t *)&info, sizeof(info),
16507                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16508         if (!ret) {
16509                 printf("Global Track id:       0x%x\n", info.track_id);
16510                 printf("Global Version:        %d.%d.%d.%d\n",
16511                         info.version.major,
16512                         info.version.minor,
16513                         info.version.update,
16514                         info.version.draft);
16515                 printf("Global Package name:   %s\n\n", info.name);
16516         }
16517
16518         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16519                                 (uint8_t *)&info, sizeof(info),
16520                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16521         if (!ret) {
16522                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16523                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16524                         info.version.major,
16525                         info.version.minor,
16526                         info.version.update,
16527                         info.version.draft);
16528                 printf("i40e Profile name:     %s\n\n", info.name);
16529         }
16530
16531         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16532                                 (uint8_t *)&buff_size, sizeof(buff_size),
16533                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16534         if (!ret && buff_size) {
16535                 buff = (uint8_t *)malloc(buff_size);
16536                 if (buff) {
16537                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16538                                                 buff, buff_size,
16539                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16540                         if (!ret)
16541                                 printf("Package Notes:\n%s\n\n", buff);
16542                         free(buff);
16543                 }
16544         }
16545
16546         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16547                                 (uint8_t *)&dev_num, sizeof(dev_num),
16548                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16549         if (!ret && dev_num) {
16550                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16551                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16552                 if (devs) {
16553                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16554                                                 (uint8_t *)devs, buff_size,
16555                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16556                         if (!ret) {
16557                                 printf("List of supported devices:\n");
16558                                 for (i = 0; i < dev_num; i++) {
16559                                         printf("  %04X:%04X %04X:%04X\n",
16560                                                 devs[i].vendor_dev_id >> 16,
16561                                                 devs[i].vendor_dev_id & 0xFFFF,
16562                                                 devs[i].sub_vendor_dev_id >> 16,
16563                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16564                                 }
16565                                 printf("\n");
16566                         }
16567                         free(devs);
16568                 }
16569         }
16570
16571         /* get information about protocols and packet types */
16572         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16573                 (uint8_t *)&proto_num, sizeof(proto_num),
16574                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16575         if (ret || !proto_num)
16576                 goto no_print_return;
16577
16578         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16579         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16580         if (!proto)
16581                 goto no_print_return;
16582
16583         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16584                                         buff_size,
16585                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16586         if (!ret) {
16587                 printf("List of used protocols:\n");
16588                 for (i = 0; i < proto_num; i++)
16589                         printf("  %2u: %s\n", proto[i].proto_id,
16590                                proto[i].name);
16591                 printf("\n");
16592         }
16593         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16594                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16595                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16596         if (ret || !pctype_num)
16597                 goto no_print_pctypes;
16598
16599         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16600         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16601         if (!pctype)
16602                 goto no_print_pctypes;
16603
16604         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16605                                         buff_size,
16606                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16607         if (ret) {
16608                 free(pctype);
16609                 goto no_print_pctypes;
16610         }
16611
16612         printf("List of defined packet classification types:\n");
16613         for (i = 0; i < pctype_num; i++) {
16614                 printf("  %2u:", pctype[i].ptype_id);
16615                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16616                         proto_id = pctype[i].protocols[j];
16617                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16618                                 for (n = 0; n < proto_num; n++) {
16619                                         if (proto[n].proto_id == proto_id) {
16620                                                 printf(" %s", proto[n].name);
16621                                                 break;
16622                                         }
16623                                 }
16624                         }
16625                 }
16626                 printf("\n");
16627         }
16628         printf("\n");
16629         free(pctype);
16630
16631 no_print_pctypes:
16632
16633         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16634                                         sizeof(ptype_num),
16635                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16636         if (ret || !ptype_num)
16637                 goto no_print_return;
16638
16639         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16640         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16641         if (!ptype)
16642                 goto no_print_return;
16643
16644         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16645                                         buff_size,
16646                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16647         if (ret) {
16648                 free(ptype);
16649                 goto no_print_return;
16650         }
16651         printf("List of defined packet types:\n");
16652         for (i = 0; i < ptype_num; i++) {
16653                 printf("  %2u:", ptype[i].ptype_id);
16654                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16655                         proto_id = ptype[i].protocols[j];
16656                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16657                                 for (n = 0; n < proto_num; n++) {
16658                                         if (proto[n].proto_id == proto_id) {
16659                                                 printf(" %s", proto[n].name);
16660                                                 break;
16661                                         }
16662                                 }
16663                         }
16664                 }
16665                 printf("\n");
16666         }
16667         free(ptype);
16668         printf("\n");
16669
16670         ret = 0;
16671 no_print_return:
16672         if (proto)
16673                 free(proto);
16674 #endif
16675         if (ret == -ENOTSUP)
16676                 printf("Function not supported in PMD driver\n");
16677         close_file(pkg);
16678 }
16679
16680 cmdline_parse_inst_t cmd_ddp_get_info = {
16681         .f = cmd_ddp_info_parsed,
16682         .data = NULL,
16683         .help_str = "ddp get info <profile_path>",
16684         .tokens = {
16685                 (void *)&cmd_ddp_info_ddp,
16686                 (void *)&cmd_ddp_info_get,
16687                 (void *)&cmd_ddp_info_info,
16688                 (void *)&cmd_ddp_info_filepath,
16689                 NULL,
16690         },
16691 };
16692
16693 /* Get dynamic device personalization profile info list*/
16694 #define PROFILE_INFO_SIZE 48
16695 #define MAX_PROFILE_NUM 16
16696
16697 struct cmd_ddp_get_list_result {
16698         cmdline_fixed_string_t ddp;
16699         cmdline_fixed_string_t get;
16700         cmdline_fixed_string_t list;
16701         portid_t port_id;
16702 };
16703
16704 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16705         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16706 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16707         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16708 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16709         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16710 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16711         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16712
16713 static void
16714 cmd_ddp_get_list_parsed(
16715         __attribute__((unused)) void *parsed_result,
16716         __attribute__((unused)) struct cmdline *cl,
16717         __attribute__((unused)) void *data)
16718 {
16719 #ifdef RTE_LIBRTE_I40E_PMD
16720         struct cmd_ddp_get_list_result *res = parsed_result;
16721         struct rte_pmd_i40e_profile_list *p_list;
16722         struct rte_pmd_i40e_profile_info *p_info;
16723         uint32_t p_num;
16724         uint32_t size;
16725         uint32_t i;
16726 #endif
16727         int ret = -ENOTSUP;
16728
16729 #ifdef RTE_LIBRTE_I40E_PMD
16730         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16731         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16732         if (!p_list)
16733                 printf("%s: Failed to malloc buffer\n", __func__);
16734
16735         if (ret == -ENOTSUP)
16736                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16737                                                 (uint8_t *)p_list, size);
16738
16739         if (!ret) {
16740                 p_num = p_list->p_count;
16741                 printf("Profile number is: %d\n\n", p_num);
16742
16743                 for (i = 0; i < p_num; i++) {
16744                         p_info = &p_list->p_info[i];
16745                         printf("Profile %d:\n", i);
16746                         printf("Track id:     0x%x\n", p_info->track_id);
16747                         printf("Version:      %d.%d.%d.%d\n",
16748                                p_info->version.major,
16749                                p_info->version.minor,
16750                                p_info->version.update,
16751                                p_info->version.draft);
16752                         printf("Profile name: %s\n\n", p_info->name);
16753                 }
16754         }
16755
16756         free(p_list);
16757 #endif
16758
16759         if (ret < 0)
16760                 printf("Failed to get ddp list\n");
16761 }
16762
16763 cmdline_parse_inst_t cmd_ddp_get_list = {
16764         .f = cmd_ddp_get_list_parsed,
16765         .data = NULL,
16766         .help_str = "ddp get list <port_id>",
16767         .tokens = {
16768                 (void *)&cmd_ddp_get_list_ddp,
16769                 (void *)&cmd_ddp_get_list_get,
16770                 (void *)&cmd_ddp_get_list_list,
16771                 (void *)&cmd_ddp_get_list_port_id,
16772                 NULL,
16773         },
16774 };
16775
16776 /* Configure input set */
16777 struct cmd_cfg_input_set_result {
16778         cmdline_fixed_string_t port;
16779         cmdline_fixed_string_t cfg;
16780         portid_t port_id;
16781         cmdline_fixed_string_t pctype;
16782         uint8_t pctype_id;
16783         cmdline_fixed_string_t inset_type;
16784         cmdline_fixed_string_t opt;
16785         cmdline_fixed_string_t field;
16786         uint8_t field_idx;
16787 };
16788
16789 static void
16790 cmd_cfg_input_set_parsed(
16791         __attribute__((unused)) void *parsed_result,
16792         __attribute__((unused)) struct cmdline *cl,
16793         __attribute__((unused)) void *data)
16794 {
16795 #ifdef RTE_LIBRTE_I40E_PMD
16796         struct cmd_cfg_input_set_result *res = parsed_result;
16797         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16798         struct rte_pmd_i40e_inset inset;
16799 #endif
16800         int ret = -ENOTSUP;
16801
16802         if (!all_ports_stopped()) {
16803                 printf("Please stop all ports first\n");
16804                 return;
16805         }
16806
16807 #ifdef RTE_LIBRTE_I40E_PMD
16808         if (!strcmp(res->inset_type, "hash_inset"))
16809                 inset_type = INSET_HASH;
16810         else if (!strcmp(res->inset_type, "fdir_inset"))
16811                 inset_type = INSET_FDIR;
16812         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16813                 inset_type = INSET_FDIR_FLX;
16814         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16815                                      &inset, inset_type);
16816         if (ret) {
16817                 printf("Failed to get input set.\n");
16818                 return;
16819         }
16820
16821         if (!strcmp(res->opt, "get")) {
16822                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16823                                                    res->field_idx);
16824                 if (ret)
16825                         printf("Field index %d is enabled.\n", res->field_idx);
16826                 else
16827                         printf("Field index %d is disabled.\n", res->field_idx);
16828                 return;
16829         } else if (!strcmp(res->opt, "set"))
16830                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16831                                                    res->field_idx);
16832         else if (!strcmp(res->opt, "clear"))
16833                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16834                                                      res->field_idx);
16835         if (ret) {
16836                 printf("Failed to configure input set field.\n");
16837                 return;
16838         }
16839
16840         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16841                                      &inset, inset_type);
16842         if (ret) {
16843                 printf("Failed to set input set.\n");
16844                 return;
16845         }
16846 #endif
16847
16848         if (ret == -ENOTSUP)
16849                 printf("Function not supported\n");
16850 }
16851
16852 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16853         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16854                                  port, "port");
16855 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16856         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16857                                  cfg, "config");
16858 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16859         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16860                               port_id, UINT16);
16861 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16862         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16863                                  pctype, "pctype");
16864 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16865         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16866                               pctype_id, UINT8);
16867 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16868         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16869                                  inset_type,
16870                                  "hash_inset#fdir_inset#fdir_flx_inset");
16871 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16872         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16873                                  opt, "get#set#clear");
16874 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16875         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16876                                  field, "field");
16877 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16878         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16879                               field_idx, UINT8);
16880
16881 cmdline_parse_inst_t cmd_cfg_input_set = {
16882         .f = cmd_cfg_input_set_parsed,
16883         .data = NULL,
16884         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16885                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16886         .tokens = {
16887                 (void *)&cmd_cfg_input_set_port,
16888                 (void *)&cmd_cfg_input_set_cfg,
16889                 (void *)&cmd_cfg_input_set_port_id,
16890                 (void *)&cmd_cfg_input_set_pctype,
16891                 (void *)&cmd_cfg_input_set_pctype_id,
16892                 (void *)&cmd_cfg_input_set_inset_type,
16893                 (void *)&cmd_cfg_input_set_opt,
16894                 (void *)&cmd_cfg_input_set_field,
16895                 (void *)&cmd_cfg_input_set_field_idx,
16896                 NULL,
16897         },
16898 };
16899
16900 /* Clear input set */
16901 struct cmd_clear_input_set_result {
16902         cmdline_fixed_string_t port;
16903         cmdline_fixed_string_t cfg;
16904         portid_t port_id;
16905         cmdline_fixed_string_t pctype;
16906         uint8_t pctype_id;
16907         cmdline_fixed_string_t inset_type;
16908         cmdline_fixed_string_t clear;
16909         cmdline_fixed_string_t all;
16910 };
16911
16912 static void
16913 cmd_clear_input_set_parsed(
16914         __attribute__((unused)) void *parsed_result,
16915         __attribute__((unused)) struct cmdline *cl,
16916         __attribute__((unused)) void *data)
16917 {
16918 #ifdef RTE_LIBRTE_I40E_PMD
16919         struct cmd_clear_input_set_result *res = parsed_result;
16920         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16921         struct rte_pmd_i40e_inset inset;
16922 #endif
16923         int ret = -ENOTSUP;
16924
16925         if (!all_ports_stopped()) {
16926                 printf("Please stop all ports first\n");
16927                 return;
16928         }
16929
16930 #ifdef RTE_LIBRTE_I40E_PMD
16931         if (!strcmp(res->inset_type, "hash_inset"))
16932                 inset_type = INSET_HASH;
16933         else if (!strcmp(res->inset_type, "fdir_inset"))
16934                 inset_type = INSET_FDIR;
16935         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16936                 inset_type = INSET_FDIR_FLX;
16937
16938         memset(&inset, 0, sizeof(inset));
16939
16940         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16941                                      &inset, inset_type);
16942         if (ret) {
16943                 printf("Failed to clear input set.\n");
16944                 return;
16945         }
16946
16947 #endif
16948
16949         if (ret == -ENOTSUP)
16950                 printf("Function not supported\n");
16951 }
16952
16953 cmdline_parse_token_string_t cmd_clear_input_set_port =
16954         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16955                                  port, "port");
16956 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16957         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16958                                  cfg, "config");
16959 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16960         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16961                               port_id, UINT16);
16962 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16963         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16964                                  pctype, "pctype");
16965 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16966         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16967                               pctype_id, UINT8);
16968 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16969         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16970                                  inset_type,
16971                                  "hash_inset#fdir_inset#fdir_flx_inset");
16972 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16973         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16974                                  clear, "clear");
16975 cmdline_parse_token_string_t cmd_clear_input_set_all =
16976         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16977                                  all, "all");
16978
16979 cmdline_parse_inst_t cmd_clear_input_set = {
16980         .f = cmd_clear_input_set_parsed,
16981         .data = NULL,
16982         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16983                     "fdir_inset|fdir_flx_inset clear all",
16984         .tokens = {
16985                 (void *)&cmd_clear_input_set_port,
16986                 (void *)&cmd_clear_input_set_cfg,
16987                 (void *)&cmd_clear_input_set_port_id,
16988                 (void *)&cmd_clear_input_set_pctype,
16989                 (void *)&cmd_clear_input_set_pctype_id,
16990                 (void *)&cmd_clear_input_set_inset_type,
16991                 (void *)&cmd_clear_input_set_clear,
16992                 (void *)&cmd_clear_input_set_all,
16993                 NULL,
16994         },
16995 };
16996
16997 /* show vf stats */
16998
16999 /* Common result structure for show vf stats */
17000 struct cmd_show_vf_stats_result {
17001         cmdline_fixed_string_t show;
17002         cmdline_fixed_string_t vf;
17003         cmdline_fixed_string_t stats;
17004         portid_t port_id;
17005         uint16_t vf_id;
17006 };
17007
17008 /* Common CLI fields show vf stats*/
17009 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17010         TOKEN_STRING_INITIALIZER
17011                 (struct cmd_show_vf_stats_result,
17012                  show, "show");
17013 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17014         TOKEN_STRING_INITIALIZER
17015                 (struct cmd_show_vf_stats_result,
17016                  vf, "vf");
17017 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17018         TOKEN_STRING_INITIALIZER
17019                 (struct cmd_show_vf_stats_result,
17020                  stats, "stats");
17021 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17022         TOKEN_NUM_INITIALIZER
17023                 (struct cmd_show_vf_stats_result,
17024                  port_id, UINT16);
17025 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17026         TOKEN_NUM_INITIALIZER
17027                 (struct cmd_show_vf_stats_result,
17028                  vf_id, UINT16);
17029
17030 static void
17031 cmd_show_vf_stats_parsed(
17032         void *parsed_result,
17033         __attribute__((unused)) struct cmdline *cl,
17034         __attribute__((unused)) void *data)
17035 {
17036         struct cmd_show_vf_stats_result *res = parsed_result;
17037         struct rte_eth_stats stats;
17038         int ret = -ENOTSUP;
17039         static const char *nic_stats_border = "########################";
17040
17041         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17042                 return;
17043
17044         memset(&stats, 0, sizeof(stats));
17045
17046 #ifdef RTE_LIBRTE_I40E_PMD
17047         if (ret == -ENOTSUP)
17048                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17049                                                 res->vf_id,
17050                                                 &stats);
17051 #endif
17052 #ifdef RTE_LIBRTE_BNXT_PMD
17053         if (ret == -ENOTSUP)
17054                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17055                                                 res->vf_id,
17056                                                 &stats);
17057 #endif
17058
17059         switch (ret) {
17060         case 0:
17061                 break;
17062         case -EINVAL:
17063                 printf("invalid vf_id %d\n", res->vf_id);
17064                 break;
17065         case -ENODEV:
17066                 printf("invalid port_id %d\n", res->port_id);
17067                 break;
17068         case -ENOTSUP:
17069                 printf("function not implemented\n");
17070                 break;
17071         default:
17072                 printf("programming error: (%s)\n", strerror(-ret));
17073         }
17074
17075         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17076                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17077
17078         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17079                "%-"PRIu64"\n",
17080                stats.ipackets, stats.imissed, stats.ibytes);
17081         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17082         printf("  RX-nombuf:  %-10"PRIu64"\n",
17083                stats.rx_nombuf);
17084         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17085                "%-"PRIu64"\n",
17086                stats.opackets, stats.oerrors, stats.obytes);
17087
17088         printf("  %s############################%s\n",
17089                                nic_stats_border, nic_stats_border);
17090 }
17091
17092 cmdline_parse_inst_t cmd_show_vf_stats = {
17093         .f = cmd_show_vf_stats_parsed,
17094         .data = NULL,
17095         .help_str = "show vf stats <port_id> <vf_id>",
17096         .tokens = {
17097                 (void *)&cmd_show_vf_stats_show,
17098                 (void *)&cmd_show_vf_stats_vf,
17099                 (void *)&cmd_show_vf_stats_stats,
17100                 (void *)&cmd_show_vf_stats_port_id,
17101                 (void *)&cmd_show_vf_stats_vf_id,
17102                 NULL,
17103         },
17104 };
17105
17106 /* clear vf stats */
17107
17108 /* Common result structure for clear vf stats */
17109 struct cmd_clear_vf_stats_result {
17110         cmdline_fixed_string_t clear;
17111         cmdline_fixed_string_t vf;
17112         cmdline_fixed_string_t stats;
17113         portid_t port_id;
17114         uint16_t vf_id;
17115 };
17116
17117 /* Common CLI fields clear vf stats*/
17118 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17119         TOKEN_STRING_INITIALIZER
17120                 (struct cmd_clear_vf_stats_result,
17121                  clear, "clear");
17122 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17123         TOKEN_STRING_INITIALIZER
17124                 (struct cmd_clear_vf_stats_result,
17125                  vf, "vf");
17126 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17127         TOKEN_STRING_INITIALIZER
17128                 (struct cmd_clear_vf_stats_result,
17129                  stats, "stats");
17130 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17131         TOKEN_NUM_INITIALIZER
17132                 (struct cmd_clear_vf_stats_result,
17133                  port_id, UINT16);
17134 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17135         TOKEN_NUM_INITIALIZER
17136                 (struct cmd_clear_vf_stats_result,
17137                  vf_id, UINT16);
17138
17139 static void
17140 cmd_clear_vf_stats_parsed(
17141         void *parsed_result,
17142         __attribute__((unused)) struct cmdline *cl,
17143         __attribute__((unused)) void *data)
17144 {
17145         struct cmd_clear_vf_stats_result *res = parsed_result;
17146         int ret = -ENOTSUP;
17147
17148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17149                 return;
17150
17151 #ifdef RTE_LIBRTE_I40E_PMD
17152         if (ret == -ENOTSUP)
17153                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17154                                                   res->vf_id);
17155 #endif
17156 #ifdef RTE_LIBRTE_BNXT_PMD
17157         if (ret == -ENOTSUP)
17158                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17159                                                   res->vf_id);
17160 #endif
17161
17162         switch (ret) {
17163         case 0:
17164                 break;
17165         case -EINVAL:
17166                 printf("invalid vf_id %d\n", res->vf_id);
17167                 break;
17168         case -ENODEV:
17169                 printf("invalid port_id %d\n", res->port_id);
17170                 break;
17171         case -ENOTSUP:
17172                 printf("function not implemented\n");
17173                 break;
17174         default:
17175                 printf("programming error: (%s)\n", strerror(-ret));
17176         }
17177 }
17178
17179 cmdline_parse_inst_t cmd_clear_vf_stats = {
17180         .f = cmd_clear_vf_stats_parsed,
17181         .data = NULL,
17182         .help_str = "clear vf stats <port_id> <vf_id>",
17183         .tokens = {
17184                 (void *)&cmd_clear_vf_stats_clear,
17185                 (void *)&cmd_clear_vf_stats_vf,
17186                 (void *)&cmd_clear_vf_stats_stats,
17187                 (void *)&cmd_clear_vf_stats_port_id,
17188                 (void *)&cmd_clear_vf_stats_vf_id,
17189                 NULL,
17190         },
17191 };
17192
17193 /* port config pctype mapping reset */
17194
17195 /* Common result structure for port config pctype mapping reset */
17196 struct cmd_pctype_mapping_reset_result {
17197         cmdline_fixed_string_t port;
17198         cmdline_fixed_string_t config;
17199         portid_t port_id;
17200         cmdline_fixed_string_t pctype;
17201         cmdline_fixed_string_t mapping;
17202         cmdline_fixed_string_t reset;
17203 };
17204
17205 /* Common CLI fields for port config pctype mapping reset*/
17206 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17207         TOKEN_STRING_INITIALIZER
17208                 (struct cmd_pctype_mapping_reset_result,
17209                  port, "port");
17210 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17211         TOKEN_STRING_INITIALIZER
17212                 (struct cmd_pctype_mapping_reset_result,
17213                  config, "config");
17214 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17215         TOKEN_NUM_INITIALIZER
17216                 (struct cmd_pctype_mapping_reset_result,
17217                  port_id, UINT16);
17218 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17219         TOKEN_STRING_INITIALIZER
17220                 (struct cmd_pctype_mapping_reset_result,
17221                  pctype, "pctype");
17222 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17223         TOKEN_STRING_INITIALIZER
17224                 (struct cmd_pctype_mapping_reset_result,
17225                  mapping, "mapping");
17226 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17227         TOKEN_STRING_INITIALIZER
17228                 (struct cmd_pctype_mapping_reset_result,
17229                  reset, "reset");
17230
17231 static void
17232 cmd_pctype_mapping_reset_parsed(
17233         void *parsed_result,
17234         __attribute__((unused)) struct cmdline *cl,
17235         __attribute__((unused)) void *data)
17236 {
17237         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17238         int ret = -ENOTSUP;
17239
17240         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17241                 return;
17242
17243 #ifdef RTE_LIBRTE_I40E_PMD
17244         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17245 #endif
17246
17247         switch (ret) {
17248         case 0:
17249                 break;
17250         case -ENODEV:
17251                 printf("invalid port_id %d\n", res->port_id);
17252                 break;
17253         case -ENOTSUP:
17254                 printf("function not implemented\n");
17255                 break;
17256         default:
17257                 printf("programming error: (%s)\n", strerror(-ret));
17258         }
17259 }
17260
17261 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17262         .f = cmd_pctype_mapping_reset_parsed,
17263         .data = NULL,
17264         .help_str = "port config <port_id> pctype mapping reset",
17265         .tokens = {
17266                 (void *)&cmd_pctype_mapping_reset_port,
17267                 (void *)&cmd_pctype_mapping_reset_config,
17268                 (void *)&cmd_pctype_mapping_reset_port_id,
17269                 (void *)&cmd_pctype_mapping_reset_pctype,
17270                 (void *)&cmd_pctype_mapping_reset_mapping,
17271                 (void *)&cmd_pctype_mapping_reset_reset,
17272                 NULL,
17273         },
17274 };
17275
17276 /* show port pctype mapping */
17277
17278 /* Common result structure for show port pctype mapping */
17279 struct cmd_pctype_mapping_get_result {
17280         cmdline_fixed_string_t show;
17281         cmdline_fixed_string_t port;
17282         portid_t port_id;
17283         cmdline_fixed_string_t pctype;
17284         cmdline_fixed_string_t mapping;
17285 };
17286
17287 /* Common CLI fields for pctype mapping get */
17288 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17289         TOKEN_STRING_INITIALIZER
17290                 (struct cmd_pctype_mapping_get_result,
17291                  show, "show");
17292 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17293         TOKEN_STRING_INITIALIZER
17294                 (struct cmd_pctype_mapping_get_result,
17295                  port, "port");
17296 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17297         TOKEN_NUM_INITIALIZER
17298                 (struct cmd_pctype_mapping_get_result,
17299                  port_id, UINT16);
17300 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17301         TOKEN_STRING_INITIALIZER
17302                 (struct cmd_pctype_mapping_get_result,
17303                  pctype, "pctype");
17304 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17305         TOKEN_STRING_INITIALIZER
17306                 (struct cmd_pctype_mapping_get_result,
17307                  mapping, "mapping");
17308
17309 static void
17310 cmd_pctype_mapping_get_parsed(
17311         void *parsed_result,
17312         __attribute__((unused)) struct cmdline *cl,
17313         __attribute__((unused)) void *data)
17314 {
17315         struct cmd_pctype_mapping_get_result *res = parsed_result;
17316         int ret = -ENOTSUP;
17317 #ifdef RTE_LIBRTE_I40E_PMD
17318         struct rte_pmd_i40e_flow_type_mapping
17319                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17320         int i, j, first_pctype;
17321 #endif
17322
17323         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17324                 return;
17325
17326 #ifdef RTE_LIBRTE_I40E_PMD
17327         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17328 #endif
17329
17330         switch (ret) {
17331         case 0:
17332                 break;
17333         case -ENODEV:
17334                 printf("invalid port_id %d\n", res->port_id);
17335                 return;
17336         case -ENOTSUP:
17337                 printf("function not implemented\n");
17338                 return;
17339         default:
17340                 printf("programming error: (%s)\n", strerror(-ret));
17341                 return;
17342         }
17343
17344 #ifdef RTE_LIBRTE_I40E_PMD
17345         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17346                 if (mapping[i].pctype != 0ULL) {
17347                         first_pctype = 1;
17348
17349                         printf("pctype: ");
17350                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17351                                 if (mapping[i].pctype & (1ULL << j)) {
17352                                         printf(first_pctype ?
17353                                                "%02d" : ",%02d", j);
17354                                         first_pctype = 0;
17355                                 }
17356                         }
17357                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17358                 }
17359         }
17360 #endif
17361 }
17362
17363 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17364         .f = cmd_pctype_mapping_get_parsed,
17365         .data = NULL,
17366         .help_str = "show port <port_id> pctype mapping",
17367         .tokens = {
17368                 (void *)&cmd_pctype_mapping_get_show,
17369                 (void *)&cmd_pctype_mapping_get_port,
17370                 (void *)&cmd_pctype_mapping_get_port_id,
17371                 (void *)&cmd_pctype_mapping_get_pctype,
17372                 (void *)&cmd_pctype_mapping_get_mapping,
17373                 NULL,
17374         },
17375 };
17376
17377 /* port config pctype mapping update */
17378
17379 /* Common result structure for port config pctype mapping update */
17380 struct cmd_pctype_mapping_update_result {
17381         cmdline_fixed_string_t port;
17382         cmdline_fixed_string_t config;
17383         portid_t port_id;
17384         cmdline_fixed_string_t pctype;
17385         cmdline_fixed_string_t mapping;
17386         cmdline_fixed_string_t update;
17387         cmdline_fixed_string_t pctype_list;
17388         uint16_t flow_type;
17389 };
17390
17391 /* Common CLI fields for pctype mapping update*/
17392 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17393         TOKEN_STRING_INITIALIZER
17394                 (struct cmd_pctype_mapping_update_result,
17395                  port, "port");
17396 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17397         TOKEN_STRING_INITIALIZER
17398                 (struct cmd_pctype_mapping_update_result,
17399                  config, "config");
17400 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17401         TOKEN_NUM_INITIALIZER
17402                 (struct cmd_pctype_mapping_update_result,
17403                  port_id, UINT16);
17404 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17405         TOKEN_STRING_INITIALIZER
17406                 (struct cmd_pctype_mapping_update_result,
17407                  pctype, "pctype");
17408 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17409         TOKEN_STRING_INITIALIZER
17410                 (struct cmd_pctype_mapping_update_result,
17411                  mapping, "mapping");
17412 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17413         TOKEN_STRING_INITIALIZER
17414                 (struct cmd_pctype_mapping_update_result,
17415                  update, "update");
17416 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17417         TOKEN_STRING_INITIALIZER
17418                 (struct cmd_pctype_mapping_update_result,
17419                  pctype_list, NULL);
17420 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17421         TOKEN_NUM_INITIALIZER
17422                 (struct cmd_pctype_mapping_update_result,
17423                  flow_type, UINT16);
17424
17425 static void
17426 cmd_pctype_mapping_update_parsed(
17427         void *parsed_result,
17428         __attribute__((unused)) struct cmdline *cl,
17429         __attribute__((unused)) void *data)
17430 {
17431         struct cmd_pctype_mapping_update_result *res = parsed_result;
17432         int ret = -ENOTSUP;
17433 #ifdef RTE_LIBRTE_I40E_PMD
17434         struct rte_pmd_i40e_flow_type_mapping mapping;
17435         unsigned int i;
17436         unsigned int nb_item;
17437         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17438 #endif
17439
17440         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17441                 return;
17442
17443 #ifdef RTE_LIBRTE_I40E_PMD
17444         nb_item = parse_item_list(res->pctype_list, "pctypes",
17445                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17446         mapping.flow_type = res->flow_type;
17447         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17448                 mapping.pctype |= (1ULL << pctype_list[i]);
17449         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17450                                                 &mapping,
17451                                                 1,
17452                                                 0);
17453 #endif
17454
17455         switch (ret) {
17456         case 0:
17457                 break;
17458         case -EINVAL:
17459                 printf("invalid pctype or flow type\n");
17460                 break;
17461         case -ENODEV:
17462                 printf("invalid port_id %d\n", res->port_id);
17463                 break;
17464         case -ENOTSUP:
17465                 printf("function not implemented\n");
17466                 break;
17467         default:
17468                 printf("programming error: (%s)\n", strerror(-ret));
17469         }
17470 }
17471
17472 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17473         .f = cmd_pctype_mapping_update_parsed,
17474         .data = NULL,
17475         .help_str = "port config <port_id> pctype mapping update"
17476         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17477         .tokens = {
17478                 (void *)&cmd_pctype_mapping_update_port,
17479                 (void *)&cmd_pctype_mapping_update_config,
17480                 (void *)&cmd_pctype_mapping_update_port_id,
17481                 (void *)&cmd_pctype_mapping_update_pctype,
17482                 (void *)&cmd_pctype_mapping_update_mapping,
17483                 (void *)&cmd_pctype_mapping_update_update,
17484                 (void *)&cmd_pctype_mapping_update_pc_type,
17485                 (void *)&cmd_pctype_mapping_update_flow_type,
17486                 NULL,
17487         },
17488 };
17489
17490 /* ptype mapping get */
17491
17492 /* Common result structure for ptype mapping get */
17493 struct cmd_ptype_mapping_get_result {
17494         cmdline_fixed_string_t ptype;
17495         cmdline_fixed_string_t mapping;
17496         cmdline_fixed_string_t get;
17497         portid_t port_id;
17498         uint8_t valid_only;
17499 };
17500
17501 /* Common CLI fields for ptype mapping get */
17502 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17503         TOKEN_STRING_INITIALIZER
17504                 (struct cmd_ptype_mapping_get_result,
17505                  ptype, "ptype");
17506 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17507         TOKEN_STRING_INITIALIZER
17508                 (struct cmd_ptype_mapping_get_result,
17509                  mapping, "mapping");
17510 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17511         TOKEN_STRING_INITIALIZER
17512                 (struct cmd_ptype_mapping_get_result,
17513                  get, "get");
17514 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17515         TOKEN_NUM_INITIALIZER
17516                 (struct cmd_ptype_mapping_get_result,
17517                  port_id, UINT16);
17518 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17519         TOKEN_NUM_INITIALIZER
17520                 (struct cmd_ptype_mapping_get_result,
17521                  valid_only, UINT8);
17522
17523 static void
17524 cmd_ptype_mapping_get_parsed(
17525         void *parsed_result,
17526         __attribute__((unused)) struct cmdline *cl,
17527         __attribute__((unused)) void *data)
17528 {
17529         struct cmd_ptype_mapping_get_result *res = parsed_result;
17530         int ret = -ENOTSUP;
17531 #ifdef RTE_LIBRTE_I40E_PMD
17532         int max_ptype_num = 256;
17533         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17534         uint16_t count;
17535         int i;
17536 #endif
17537
17538         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17539                 return;
17540
17541 #ifdef RTE_LIBRTE_I40E_PMD
17542         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17543                                         mapping,
17544                                         max_ptype_num,
17545                                         &count,
17546                                         res->valid_only);
17547 #endif
17548
17549         switch (ret) {
17550         case 0:
17551                 break;
17552         case -ENODEV:
17553                 printf("invalid port_id %d\n", res->port_id);
17554                 break;
17555         case -ENOTSUP:
17556                 printf("function not implemented\n");
17557                 break;
17558         default:
17559                 printf("programming error: (%s)\n", strerror(-ret));
17560         }
17561
17562 #ifdef RTE_LIBRTE_I40E_PMD
17563         if (!ret) {
17564                 for (i = 0; i < count; i++)
17565                         printf("%3d\t0x%08x\n",
17566                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17567         }
17568 #endif
17569 }
17570
17571 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17572         .f = cmd_ptype_mapping_get_parsed,
17573         .data = NULL,
17574         .help_str = "ptype mapping get <port_id> <valid_only>",
17575         .tokens = {
17576                 (void *)&cmd_ptype_mapping_get_ptype,
17577                 (void *)&cmd_ptype_mapping_get_mapping,
17578                 (void *)&cmd_ptype_mapping_get_get,
17579                 (void *)&cmd_ptype_mapping_get_port_id,
17580                 (void *)&cmd_ptype_mapping_get_valid_only,
17581                 NULL,
17582         },
17583 };
17584
17585 /* ptype mapping replace */
17586
17587 /* Common result structure for ptype mapping replace */
17588 struct cmd_ptype_mapping_replace_result {
17589         cmdline_fixed_string_t ptype;
17590         cmdline_fixed_string_t mapping;
17591         cmdline_fixed_string_t replace;
17592         portid_t port_id;
17593         uint32_t target;
17594         uint8_t mask;
17595         uint32_t pkt_type;
17596 };
17597
17598 /* Common CLI fields for ptype mapping replace */
17599 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17600         TOKEN_STRING_INITIALIZER
17601                 (struct cmd_ptype_mapping_replace_result,
17602                  ptype, "ptype");
17603 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17604         TOKEN_STRING_INITIALIZER
17605                 (struct cmd_ptype_mapping_replace_result,
17606                  mapping, "mapping");
17607 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17608         TOKEN_STRING_INITIALIZER
17609                 (struct cmd_ptype_mapping_replace_result,
17610                  replace, "replace");
17611 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17612         TOKEN_NUM_INITIALIZER
17613                 (struct cmd_ptype_mapping_replace_result,
17614                  port_id, UINT16);
17615 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17616         TOKEN_NUM_INITIALIZER
17617                 (struct cmd_ptype_mapping_replace_result,
17618                  target, UINT32);
17619 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17620         TOKEN_NUM_INITIALIZER
17621                 (struct cmd_ptype_mapping_replace_result,
17622                  mask, UINT8);
17623 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17624         TOKEN_NUM_INITIALIZER
17625                 (struct cmd_ptype_mapping_replace_result,
17626                  pkt_type, UINT32);
17627
17628 static void
17629 cmd_ptype_mapping_replace_parsed(
17630         void *parsed_result,
17631         __attribute__((unused)) struct cmdline *cl,
17632         __attribute__((unused)) void *data)
17633 {
17634         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17635         int ret = -ENOTSUP;
17636
17637         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17638                 return;
17639
17640 #ifdef RTE_LIBRTE_I40E_PMD
17641         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17642                                         res->target,
17643                                         res->mask,
17644                                         res->pkt_type);
17645 #endif
17646
17647         switch (ret) {
17648         case 0:
17649                 break;
17650         case -EINVAL:
17651                 printf("invalid ptype 0x%8x or 0x%8x\n",
17652                                 res->target, res->pkt_type);
17653                 break;
17654         case -ENODEV:
17655                 printf("invalid port_id %d\n", res->port_id);
17656                 break;
17657         case -ENOTSUP:
17658                 printf("function not implemented\n");
17659                 break;
17660         default:
17661                 printf("programming error: (%s)\n", strerror(-ret));
17662         }
17663 }
17664
17665 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17666         .f = cmd_ptype_mapping_replace_parsed,
17667         .data = NULL,
17668         .help_str =
17669                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17670         .tokens = {
17671                 (void *)&cmd_ptype_mapping_replace_ptype,
17672                 (void *)&cmd_ptype_mapping_replace_mapping,
17673                 (void *)&cmd_ptype_mapping_replace_replace,
17674                 (void *)&cmd_ptype_mapping_replace_port_id,
17675                 (void *)&cmd_ptype_mapping_replace_target,
17676                 (void *)&cmd_ptype_mapping_replace_mask,
17677                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17678                 NULL,
17679         },
17680 };
17681
17682 /* ptype mapping reset */
17683
17684 /* Common result structure for ptype mapping reset */
17685 struct cmd_ptype_mapping_reset_result {
17686         cmdline_fixed_string_t ptype;
17687         cmdline_fixed_string_t mapping;
17688         cmdline_fixed_string_t reset;
17689         portid_t port_id;
17690 };
17691
17692 /* Common CLI fields for ptype mapping reset*/
17693 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17694         TOKEN_STRING_INITIALIZER
17695                 (struct cmd_ptype_mapping_reset_result,
17696                  ptype, "ptype");
17697 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17698         TOKEN_STRING_INITIALIZER
17699                 (struct cmd_ptype_mapping_reset_result,
17700                  mapping, "mapping");
17701 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17702         TOKEN_STRING_INITIALIZER
17703                 (struct cmd_ptype_mapping_reset_result,
17704                  reset, "reset");
17705 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17706         TOKEN_NUM_INITIALIZER
17707                 (struct cmd_ptype_mapping_reset_result,
17708                  port_id, UINT16);
17709
17710 static void
17711 cmd_ptype_mapping_reset_parsed(
17712         void *parsed_result,
17713         __attribute__((unused)) struct cmdline *cl,
17714         __attribute__((unused)) void *data)
17715 {
17716         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17717         int ret = -ENOTSUP;
17718
17719         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17720                 return;
17721
17722 #ifdef RTE_LIBRTE_I40E_PMD
17723         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17724 #endif
17725
17726         switch (ret) {
17727         case 0:
17728                 break;
17729         case -ENODEV:
17730                 printf("invalid port_id %d\n", res->port_id);
17731                 break;
17732         case -ENOTSUP:
17733                 printf("function not implemented\n");
17734                 break;
17735         default:
17736                 printf("programming error: (%s)\n", strerror(-ret));
17737         }
17738 }
17739
17740 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17741         .f = cmd_ptype_mapping_reset_parsed,
17742         .data = NULL,
17743         .help_str = "ptype mapping reset <port_id>",
17744         .tokens = {
17745                 (void *)&cmd_ptype_mapping_reset_ptype,
17746                 (void *)&cmd_ptype_mapping_reset_mapping,
17747                 (void *)&cmd_ptype_mapping_reset_reset,
17748                 (void *)&cmd_ptype_mapping_reset_port_id,
17749                 NULL,
17750         },
17751 };
17752
17753 /* ptype mapping update */
17754
17755 /* Common result structure for ptype mapping update */
17756 struct cmd_ptype_mapping_update_result {
17757         cmdline_fixed_string_t ptype;
17758         cmdline_fixed_string_t mapping;
17759         cmdline_fixed_string_t reset;
17760         portid_t port_id;
17761         uint8_t hw_ptype;
17762         uint32_t sw_ptype;
17763 };
17764
17765 /* Common CLI fields for ptype mapping update*/
17766 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17767         TOKEN_STRING_INITIALIZER
17768                 (struct cmd_ptype_mapping_update_result,
17769                  ptype, "ptype");
17770 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17771         TOKEN_STRING_INITIALIZER
17772                 (struct cmd_ptype_mapping_update_result,
17773                  mapping, "mapping");
17774 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17775         TOKEN_STRING_INITIALIZER
17776                 (struct cmd_ptype_mapping_update_result,
17777                  reset, "update");
17778 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17779         TOKEN_NUM_INITIALIZER
17780                 (struct cmd_ptype_mapping_update_result,
17781                  port_id, UINT16);
17782 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17783         TOKEN_NUM_INITIALIZER
17784                 (struct cmd_ptype_mapping_update_result,
17785                  hw_ptype, UINT8);
17786 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17787         TOKEN_NUM_INITIALIZER
17788                 (struct cmd_ptype_mapping_update_result,
17789                  sw_ptype, UINT32);
17790
17791 static void
17792 cmd_ptype_mapping_update_parsed(
17793         void *parsed_result,
17794         __attribute__((unused)) struct cmdline *cl,
17795         __attribute__((unused)) void *data)
17796 {
17797         struct cmd_ptype_mapping_update_result *res = parsed_result;
17798         int ret = -ENOTSUP;
17799 #ifdef RTE_LIBRTE_I40E_PMD
17800         struct rte_pmd_i40e_ptype_mapping mapping;
17801 #endif
17802         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17803                 return;
17804
17805 #ifdef RTE_LIBRTE_I40E_PMD
17806         mapping.hw_ptype = res->hw_ptype;
17807         mapping.sw_ptype = res->sw_ptype;
17808         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17809                                                 &mapping,
17810                                                 1,
17811                                                 0);
17812 #endif
17813
17814         switch (ret) {
17815         case 0:
17816                 break;
17817         case -EINVAL:
17818                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17819                 break;
17820         case -ENODEV:
17821                 printf("invalid port_id %d\n", res->port_id);
17822                 break;
17823         case -ENOTSUP:
17824                 printf("function not implemented\n");
17825                 break;
17826         default:
17827                 printf("programming error: (%s)\n", strerror(-ret));
17828         }
17829 }
17830
17831 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17832         .f = cmd_ptype_mapping_update_parsed,
17833         .data = NULL,
17834         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17835         .tokens = {
17836                 (void *)&cmd_ptype_mapping_update_ptype,
17837                 (void *)&cmd_ptype_mapping_update_mapping,
17838                 (void *)&cmd_ptype_mapping_update_update,
17839                 (void *)&cmd_ptype_mapping_update_port_id,
17840                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17841                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17842                 NULL,
17843         },
17844 };
17845
17846 /* Common result structure for file commands */
17847 struct cmd_cmdfile_result {
17848         cmdline_fixed_string_t load;
17849         cmdline_fixed_string_t filename;
17850 };
17851
17852 /* Common CLI fields for file commands */
17853 cmdline_parse_token_string_t cmd_load_cmdfile =
17854         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17855 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17856         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17857
17858 static void
17859 cmd_load_from_file_parsed(
17860         void *parsed_result,
17861         __attribute__((unused)) struct cmdline *cl,
17862         __attribute__((unused)) void *data)
17863 {
17864         struct cmd_cmdfile_result *res = parsed_result;
17865
17866         cmdline_read_from_file(res->filename);
17867 }
17868
17869 cmdline_parse_inst_t cmd_load_from_file = {
17870         .f = cmd_load_from_file_parsed,
17871         .data = NULL,
17872         .help_str = "load <filename>",
17873         .tokens = {
17874                 (void *)&cmd_load_cmdfile,
17875                 (void *)&cmd_load_cmdfile_filename,
17876                 NULL,
17877         },
17878 };
17879
17880 /* Get Rx offloads capabilities */
17881 struct cmd_rx_offload_get_capa_result {
17882         cmdline_fixed_string_t show;
17883         cmdline_fixed_string_t port;
17884         portid_t port_id;
17885         cmdline_fixed_string_t rx_offload;
17886         cmdline_fixed_string_t capabilities;
17887 };
17888
17889 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17890         TOKEN_STRING_INITIALIZER
17891                 (struct cmd_rx_offload_get_capa_result,
17892                  show, "show");
17893 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17894         TOKEN_STRING_INITIALIZER
17895                 (struct cmd_rx_offload_get_capa_result,
17896                  port, "port");
17897 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17898         TOKEN_NUM_INITIALIZER
17899                 (struct cmd_rx_offload_get_capa_result,
17900                  port_id, UINT16);
17901 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17902         TOKEN_STRING_INITIALIZER
17903                 (struct cmd_rx_offload_get_capa_result,
17904                  rx_offload, "rx_offload");
17905 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17906         TOKEN_STRING_INITIALIZER
17907                 (struct cmd_rx_offload_get_capa_result,
17908                  capabilities, "capabilities");
17909
17910 static void
17911 print_rx_offloads(uint64_t offloads)
17912 {
17913         uint64_t single_offload;
17914         int begin;
17915         int end;
17916         int bit;
17917
17918         if (offloads == 0)
17919                 return;
17920
17921         begin = __builtin_ctzll(offloads);
17922         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17923
17924         single_offload = 1ULL << begin;
17925         for (bit = begin; bit < end; bit++) {
17926                 if (offloads & single_offload)
17927                         printf(" %s",
17928                                rte_eth_dev_rx_offload_name(single_offload));
17929                 single_offload <<= 1;
17930         }
17931 }
17932
17933 static void
17934 cmd_rx_offload_get_capa_parsed(
17935         void *parsed_result,
17936         __attribute__((unused)) struct cmdline *cl,
17937         __attribute__((unused)) void *data)
17938 {
17939         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17940         struct rte_eth_dev_info dev_info;
17941         portid_t port_id = res->port_id;
17942         uint64_t queue_offloads;
17943         uint64_t port_offloads;
17944         int ret;
17945
17946         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17947         if (ret != 0)
17948                 return;
17949
17950         queue_offloads = dev_info.rx_queue_offload_capa;
17951         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17952
17953         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17954         printf("  Per Queue :");
17955         print_rx_offloads(queue_offloads);
17956
17957         printf("\n");
17958         printf("  Per Port  :");
17959         print_rx_offloads(port_offloads);
17960         printf("\n\n");
17961 }
17962
17963 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17964         .f = cmd_rx_offload_get_capa_parsed,
17965         .data = NULL,
17966         .help_str = "show port <port_id> rx_offload capabilities",
17967         .tokens = {
17968                 (void *)&cmd_rx_offload_get_capa_show,
17969                 (void *)&cmd_rx_offload_get_capa_port,
17970                 (void *)&cmd_rx_offload_get_capa_port_id,
17971                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17972                 (void *)&cmd_rx_offload_get_capa_capabilities,
17973                 NULL,
17974         }
17975 };
17976
17977 /* Get Rx offloads configuration */
17978 struct cmd_rx_offload_get_configuration_result {
17979         cmdline_fixed_string_t show;
17980         cmdline_fixed_string_t port;
17981         portid_t port_id;
17982         cmdline_fixed_string_t rx_offload;
17983         cmdline_fixed_string_t configuration;
17984 };
17985
17986 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17987         TOKEN_STRING_INITIALIZER
17988                 (struct cmd_rx_offload_get_configuration_result,
17989                  show, "show");
17990 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17991         TOKEN_STRING_INITIALIZER
17992                 (struct cmd_rx_offload_get_configuration_result,
17993                  port, "port");
17994 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17995         TOKEN_NUM_INITIALIZER
17996                 (struct cmd_rx_offload_get_configuration_result,
17997                  port_id, UINT16);
17998 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17999         TOKEN_STRING_INITIALIZER
18000                 (struct cmd_rx_offload_get_configuration_result,
18001                  rx_offload, "rx_offload");
18002 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18003         TOKEN_STRING_INITIALIZER
18004                 (struct cmd_rx_offload_get_configuration_result,
18005                  configuration, "configuration");
18006
18007 static void
18008 cmd_rx_offload_get_configuration_parsed(
18009         void *parsed_result,
18010         __attribute__((unused)) struct cmdline *cl,
18011         __attribute__((unused)) void *data)
18012 {
18013         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18014         struct rte_eth_dev_info dev_info;
18015         portid_t port_id = res->port_id;
18016         struct rte_port *port = &ports[port_id];
18017         uint64_t port_offloads;
18018         uint64_t queue_offloads;
18019         uint16_t nb_rx_queues;
18020         int q;
18021         int ret;
18022
18023         printf("Rx Offloading Configuration of port %d :\n", port_id);
18024
18025         port_offloads = port->dev_conf.rxmode.offloads;
18026         printf("  Port :");
18027         print_rx_offloads(port_offloads);
18028         printf("\n");
18029
18030         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18031         if (ret != 0)
18032                 return;
18033
18034         nb_rx_queues = dev_info.nb_rx_queues;
18035         for (q = 0; q < nb_rx_queues; q++) {
18036                 queue_offloads = port->rx_conf[q].offloads;
18037                 printf("  Queue[%2d] :", q);
18038                 print_rx_offloads(queue_offloads);
18039                 printf("\n");
18040         }
18041         printf("\n");
18042 }
18043
18044 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18045         .f = cmd_rx_offload_get_configuration_parsed,
18046         .data = NULL,
18047         .help_str = "show port <port_id> rx_offload configuration",
18048         .tokens = {
18049                 (void *)&cmd_rx_offload_get_configuration_show,
18050                 (void *)&cmd_rx_offload_get_configuration_port,
18051                 (void *)&cmd_rx_offload_get_configuration_port_id,
18052                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18053                 (void *)&cmd_rx_offload_get_configuration_configuration,
18054                 NULL,
18055         }
18056 };
18057
18058 /* Enable/Disable a per port offloading */
18059 struct cmd_config_per_port_rx_offload_result {
18060         cmdline_fixed_string_t port;
18061         cmdline_fixed_string_t config;
18062         portid_t port_id;
18063         cmdline_fixed_string_t rx_offload;
18064         cmdline_fixed_string_t offload;
18065         cmdline_fixed_string_t on_off;
18066 };
18067
18068 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18069         TOKEN_STRING_INITIALIZER
18070                 (struct cmd_config_per_port_rx_offload_result,
18071                  port, "port");
18072 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18073         TOKEN_STRING_INITIALIZER
18074                 (struct cmd_config_per_port_rx_offload_result,
18075                  config, "config");
18076 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18077         TOKEN_NUM_INITIALIZER
18078                 (struct cmd_config_per_port_rx_offload_result,
18079                  port_id, UINT16);
18080 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18081         TOKEN_STRING_INITIALIZER
18082                 (struct cmd_config_per_port_rx_offload_result,
18083                  rx_offload, "rx_offload");
18084 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18085         TOKEN_STRING_INITIALIZER
18086                 (struct cmd_config_per_port_rx_offload_result,
18087                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18088                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18089                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18090                            "scatter#timestamp#security#keep_crc#rss_hash");
18091 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18092         TOKEN_STRING_INITIALIZER
18093                 (struct cmd_config_per_port_rx_offload_result,
18094                  on_off, "on#off");
18095
18096 static uint64_t
18097 search_rx_offload(const char *name)
18098 {
18099         uint64_t single_offload;
18100         const char *single_name;
18101         int found = 0;
18102         unsigned int bit;
18103
18104         single_offload = 1;
18105         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18106                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18107                 if (!strcasecmp(single_name, name)) {
18108                         found = 1;
18109                         break;
18110                 }
18111                 single_offload <<= 1;
18112         }
18113
18114         if (found)
18115                 return single_offload;
18116
18117         return 0;
18118 }
18119
18120 static void
18121 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18122                                 __attribute__((unused)) struct cmdline *cl,
18123                                 __attribute__((unused)) void *data)
18124 {
18125         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18126         portid_t port_id = res->port_id;
18127         struct rte_eth_dev_info dev_info;
18128         struct rte_port *port = &ports[port_id];
18129         uint64_t single_offload;
18130         uint16_t nb_rx_queues;
18131         int q;
18132         int ret;
18133
18134         if (port->port_status != RTE_PORT_STOPPED) {
18135                 printf("Error: Can't config offload when Port %d "
18136                        "is not stopped\n", port_id);
18137                 return;
18138         }
18139
18140         single_offload = search_rx_offload(res->offload);
18141         if (single_offload == 0) {
18142                 printf("Unknown offload name: %s\n", res->offload);
18143                 return;
18144         }
18145
18146         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18147         if (ret != 0)
18148                 return;
18149
18150         nb_rx_queues = dev_info.nb_rx_queues;
18151         if (!strcmp(res->on_off, "on")) {
18152                 port->dev_conf.rxmode.offloads |= single_offload;
18153                 for (q = 0; q < nb_rx_queues; q++)
18154                         port->rx_conf[q].offloads |= single_offload;
18155         } else {
18156                 port->dev_conf.rxmode.offloads &= ~single_offload;
18157                 for (q = 0; q < nb_rx_queues; q++)
18158                         port->rx_conf[q].offloads &= ~single_offload;
18159         }
18160
18161         cmd_reconfig_device_queue(port_id, 1, 1);
18162 }
18163
18164 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18165         .f = cmd_config_per_port_rx_offload_parsed,
18166         .data = NULL,
18167         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18168                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18169                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18170                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18171                     "on|off",
18172         .tokens = {
18173                 (void *)&cmd_config_per_port_rx_offload_result_port,
18174                 (void *)&cmd_config_per_port_rx_offload_result_config,
18175                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18176                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18177                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18178                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18179                 NULL,
18180         }
18181 };
18182
18183 /* Enable/Disable a per queue offloading */
18184 struct cmd_config_per_queue_rx_offload_result {
18185         cmdline_fixed_string_t port;
18186         portid_t port_id;
18187         cmdline_fixed_string_t rxq;
18188         uint16_t queue_id;
18189         cmdline_fixed_string_t rx_offload;
18190         cmdline_fixed_string_t offload;
18191         cmdline_fixed_string_t on_off;
18192 };
18193
18194 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18195         TOKEN_STRING_INITIALIZER
18196                 (struct cmd_config_per_queue_rx_offload_result,
18197                  port, "port");
18198 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18199         TOKEN_NUM_INITIALIZER
18200                 (struct cmd_config_per_queue_rx_offload_result,
18201                  port_id, UINT16);
18202 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18203         TOKEN_STRING_INITIALIZER
18204                 (struct cmd_config_per_queue_rx_offload_result,
18205                  rxq, "rxq");
18206 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18207         TOKEN_NUM_INITIALIZER
18208                 (struct cmd_config_per_queue_rx_offload_result,
18209                  queue_id, UINT16);
18210 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18211         TOKEN_STRING_INITIALIZER
18212                 (struct cmd_config_per_queue_rx_offload_result,
18213                  rx_offload, "rx_offload");
18214 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18215         TOKEN_STRING_INITIALIZER
18216                 (struct cmd_config_per_queue_rx_offload_result,
18217                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18218                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18219                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18220                            "scatter#timestamp#security#keep_crc");
18221 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18222         TOKEN_STRING_INITIALIZER
18223                 (struct cmd_config_per_queue_rx_offload_result,
18224                  on_off, "on#off");
18225
18226 static void
18227 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18228                                 __attribute__((unused)) struct cmdline *cl,
18229                                 __attribute__((unused)) void *data)
18230 {
18231         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18232         struct rte_eth_dev_info dev_info;
18233         portid_t port_id = res->port_id;
18234         uint16_t queue_id = res->queue_id;
18235         struct rte_port *port = &ports[port_id];
18236         uint64_t single_offload;
18237         int ret;
18238
18239         if (port->port_status != RTE_PORT_STOPPED) {
18240                 printf("Error: Can't config offload when Port %d "
18241                        "is not stopped\n", port_id);
18242                 return;
18243         }
18244
18245         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18246         if (ret != 0)
18247                 return;
18248
18249         if (queue_id >= dev_info.nb_rx_queues) {
18250                 printf("Error: input queue_id should be 0 ... "
18251                        "%d\n", dev_info.nb_rx_queues - 1);
18252                 return;
18253         }
18254
18255         single_offload = search_rx_offload(res->offload);
18256         if (single_offload == 0) {
18257                 printf("Unknown offload name: %s\n", res->offload);
18258                 return;
18259         }
18260
18261         if (!strcmp(res->on_off, "on"))
18262                 port->rx_conf[queue_id].offloads |= single_offload;
18263         else
18264                 port->rx_conf[queue_id].offloads &= ~single_offload;
18265
18266         cmd_reconfig_device_queue(port_id, 1, 1);
18267 }
18268
18269 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18270         .f = cmd_config_per_queue_rx_offload_parsed,
18271         .data = NULL,
18272         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18273                     "vlan_strip|ipv4_cksum|"
18274                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18275                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18276                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18277                     "on|off",
18278         .tokens = {
18279                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18280                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18281                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18282                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18283                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18284                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18285                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18286                 NULL,
18287         }
18288 };
18289
18290 /* Get Tx offloads capabilities */
18291 struct cmd_tx_offload_get_capa_result {
18292         cmdline_fixed_string_t show;
18293         cmdline_fixed_string_t port;
18294         portid_t port_id;
18295         cmdline_fixed_string_t tx_offload;
18296         cmdline_fixed_string_t capabilities;
18297 };
18298
18299 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18300         TOKEN_STRING_INITIALIZER
18301                 (struct cmd_tx_offload_get_capa_result,
18302                  show, "show");
18303 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18304         TOKEN_STRING_INITIALIZER
18305                 (struct cmd_tx_offload_get_capa_result,
18306                  port, "port");
18307 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18308         TOKEN_NUM_INITIALIZER
18309                 (struct cmd_tx_offload_get_capa_result,
18310                  port_id, UINT16);
18311 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18312         TOKEN_STRING_INITIALIZER
18313                 (struct cmd_tx_offload_get_capa_result,
18314                  tx_offload, "tx_offload");
18315 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18316         TOKEN_STRING_INITIALIZER
18317                 (struct cmd_tx_offload_get_capa_result,
18318                  capabilities, "capabilities");
18319
18320 static void
18321 print_tx_offloads(uint64_t offloads)
18322 {
18323         uint64_t single_offload;
18324         int begin;
18325         int end;
18326         int bit;
18327
18328         if (offloads == 0)
18329                 return;
18330
18331         begin = __builtin_ctzll(offloads);
18332         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18333
18334         single_offload = 1ULL << begin;
18335         for (bit = begin; bit < end; bit++) {
18336                 if (offloads & single_offload)
18337                         printf(" %s",
18338                                rte_eth_dev_tx_offload_name(single_offload));
18339                 single_offload <<= 1;
18340         }
18341 }
18342
18343 static void
18344 cmd_tx_offload_get_capa_parsed(
18345         void *parsed_result,
18346         __attribute__((unused)) struct cmdline *cl,
18347         __attribute__((unused)) void *data)
18348 {
18349         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18350         struct rte_eth_dev_info dev_info;
18351         portid_t port_id = res->port_id;
18352         uint64_t queue_offloads;
18353         uint64_t port_offloads;
18354         int ret;
18355
18356         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18357         if (ret != 0)
18358                 return;
18359
18360         queue_offloads = dev_info.tx_queue_offload_capa;
18361         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18362
18363         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18364         printf("  Per Queue :");
18365         print_tx_offloads(queue_offloads);
18366
18367         printf("\n");
18368         printf("  Per Port  :");
18369         print_tx_offloads(port_offloads);
18370         printf("\n\n");
18371 }
18372
18373 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18374         .f = cmd_tx_offload_get_capa_parsed,
18375         .data = NULL,
18376         .help_str = "show port <port_id> tx_offload capabilities",
18377         .tokens = {
18378                 (void *)&cmd_tx_offload_get_capa_show,
18379                 (void *)&cmd_tx_offload_get_capa_port,
18380                 (void *)&cmd_tx_offload_get_capa_port_id,
18381                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18382                 (void *)&cmd_tx_offload_get_capa_capabilities,
18383                 NULL,
18384         }
18385 };
18386
18387 /* Get Tx offloads configuration */
18388 struct cmd_tx_offload_get_configuration_result {
18389         cmdline_fixed_string_t show;
18390         cmdline_fixed_string_t port;
18391         portid_t port_id;
18392         cmdline_fixed_string_t tx_offload;
18393         cmdline_fixed_string_t configuration;
18394 };
18395
18396 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18397         TOKEN_STRING_INITIALIZER
18398                 (struct cmd_tx_offload_get_configuration_result,
18399                  show, "show");
18400 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18401         TOKEN_STRING_INITIALIZER
18402                 (struct cmd_tx_offload_get_configuration_result,
18403                  port, "port");
18404 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18405         TOKEN_NUM_INITIALIZER
18406                 (struct cmd_tx_offload_get_configuration_result,
18407                  port_id, UINT16);
18408 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18409         TOKEN_STRING_INITIALIZER
18410                 (struct cmd_tx_offload_get_configuration_result,
18411                  tx_offload, "tx_offload");
18412 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18413         TOKEN_STRING_INITIALIZER
18414                 (struct cmd_tx_offload_get_configuration_result,
18415                  configuration, "configuration");
18416
18417 static void
18418 cmd_tx_offload_get_configuration_parsed(
18419         void *parsed_result,
18420         __attribute__((unused)) struct cmdline *cl,
18421         __attribute__((unused)) void *data)
18422 {
18423         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18424         struct rte_eth_dev_info dev_info;
18425         portid_t port_id = res->port_id;
18426         struct rte_port *port = &ports[port_id];
18427         uint64_t port_offloads;
18428         uint64_t queue_offloads;
18429         uint16_t nb_tx_queues;
18430         int q;
18431         int ret;
18432
18433         printf("Tx Offloading Configuration of port %d :\n", port_id);
18434
18435         port_offloads = port->dev_conf.txmode.offloads;
18436         printf("  Port :");
18437         print_tx_offloads(port_offloads);
18438         printf("\n");
18439
18440         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18441         if (ret != 0)
18442                 return;
18443
18444         nb_tx_queues = dev_info.nb_tx_queues;
18445         for (q = 0; q < nb_tx_queues; q++) {
18446                 queue_offloads = port->tx_conf[q].offloads;
18447                 printf("  Queue[%2d] :", q);
18448                 print_tx_offloads(queue_offloads);
18449                 printf("\n");
18450         }
18451         printf("\n");
18452 }
18453
18454 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18455         .f = cmd_tx_offload_get_configuration_parsed,
18456         .data = NULL,
18457         .help_str = "show port <port_id> tx_offload configuration",
18458         .tokens = {
18459                 (void *)&cmd_tx_offload_get_configuration_show,
18460                 (void *)&cmd_tx_offload_get_configuration_port,
18461                 (void *)&cmd_tx_offload_get_configuration_port_id,
18462                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18463                 (void *)&cmd_tx_offload_get_configuration_configuration,
18464                 NULL,
18465         }
18466 };
18467
18468 /* Enable/Disable a per port offloading */
18469 struct cmd_config_per_port_tx_offload_result {
18470         cmdline_fixed_string_t port;
18471         cmdline_fixed_string_t config;
18472         portid_t port_id;
18473         cmdline_fixed_string_t tx_offload;
18474         cmdline_fixed_string_t offload;
18475         cmdline_fixed_string_t on_off;
18476 };
18477
18478 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18479         TOKEN_STRING_INITIALIZER
18480                 (struct cmd_config_per_port_tx_offload_result,
18481                  port, "port");
18482 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18483         TOKEN_STRING_INITIALIZER
18484                 (struct cmd_config_per_port_tx_offload_result,
18485                  config, "config");
18486 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18487         TOKEN_NUM_INITIALIZER
18488                 (struct cmd_config_per_port_tx_offload_result,
18489                  port_id, UINT16);
18490 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18491         TOKEN_STRING_INITIALIZER
18492                 (struct cmd_config_per_port_tx_offload_result,
18493                  tx_offload, "tx_offload");
18494 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18495         TOKEN_STRING_INITIALIZER
18496                 (struct cmd_config_per_port_tx_offload_result,
18497                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18498                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18499                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18500                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18501                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18502                           "match_metadata");
18503 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18504         TOKEN_STRING_INITIALIZER
18505                 (struct cmd_config_per_port_tx_offload_result,
18506                  on_off, "on#off");
18507
18508 static uint64_t
18509 search_tx_offload(const char *name)
18510 {
18511         uint64_t single_offload;
18512         const char *single_name;
18513         int found = 0;
18514         unsigned int bit;
18515
18516         single_offload = 1;
18517         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18518                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18519                 if (single_name == NULL)
18520                         break;
18521                 if (!strcasecmp(single_name, name)) {
18522                         found = 1;
18523                         break;
18524                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18525                         break;
18526                 single_offload <<= 1;
18527         }
18528
18529         if (found)
18530                 return single_offload;
18531
18532         return 0;
18533 }
18534
18535 static void
18536 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18537                                 __attribute__((unused)) struct cmdline *cl,
18538                                 __attribute__((unused)) void *data)
18539 {
18540         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18541         portid_t port_id = res->port_id;
18542         struct rte_eth_dev_info dev_info;
18543         struct rte_port *port = &ports[port_id];
18544         uint64_t single_offload;
18545         uint16_t nb_tx_queues;
18546         int q;
18547         int ret;
18548
18549         if (port->port_status != RTE_PORT_STOPPED) {
18550                 printf("Error: Can't config offload when Port %d "
18551                        "is not stopped\n", port_id);
18552                 return;
18553         }
18554
18555         single_offload = search_tx_offload(res->offload);
18556         if (single_offload == 0) {
18557                 printf("Unknown offload name: %s\n", res->offload);
18558                 return;
18559         }
18560
18561         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18562         if (ret != 0)
18563                 return;
18564
18565         nb_tx_queues = dev_info.nb_tx_queues;
18566         if (!strcmp(res->on_off, "on")) {
18567                 port->dev_conf.txmode.offloads |= single_offload;
18568                 for (q = 0; q < nb_tx_queues; q++)
18569                         port->tx_conf[q].offloads |= single_offload;
18570         } else {
18571                 port->dev_conf.txmode.offloads &= ~single_offload;
18572                 for (q = 0; q < nb_tx_queues; q++)
18573                         port->tx_conf[q].offloads &= ~single_offload;
18574         }
18575
18576         cmd_reconfig_device_queue(port_id, 1, 1);
18577 }
18578
18579 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18580         .f = cmd_config_per_port_tx_offload_parsed,
18581         .data = NULL,
18582         .help_str = "port config <port_id> tx_offload "
18583                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18584                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18585                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18586                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18587                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18588                     "match_metadata on|off",
18589         .tokens = {
18590                 (void *)&cmd_config_per_port_tx_offload_result_port,
18591                 (void *)&cmd_config_per_port_tx_offload_result_config,
18592                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18593                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18594                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18595                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18596                 NULL,
18597         }
18598 };
18599
18600 /* Enable/Disable a per queue offloading */
18601 struct cmd_config_per_queue_tx_offload_result {
18602         cmdline_fixed_string_t port;
18603         portid_t port_id;
18604         cmdline_fixed_string_t txq;
18605         uint16_t queue_id;
18606         cmdline_fixed_string_t tx_offload;
18607         cmdline_fixed_string_t offload;
18608         cmdline_fixed_string_t on_off;
18609 };
18610
18611 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18612         TOKEN_STRING_INITIALIZER
18613                 (struct cmd_config_per_queue_tx_offload_result,
18614                  port, "port");
18615 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18616         TOKEN_NUM_INITIALIZER
18617                 (struct cmd_config_per_queue_tx_offload_result,
18618                  port_id, UINT16);
18619 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18620         TOKEN_STRING_INITIALIZER
18621                 (struct cmd_config_per_queue_tx_offload_result,
18622                  txq, "txq");
18623 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18624         TOKEN_NUM_INITIALIZER
18625                 (struct cmd_config_per_queue_tx_offload_result,
18626                  queue_id, UINT16);
18627 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18628         TOKEN_STRING_INITIALIZER
18629                 (struct cmd_config_per_queue_tx_offload_result,
18630                  tx_offload, "tx_offload");
18631 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18632         TOKEN_STRING_INITIALIZER
18633                 (struct cmd_config_per_queue_tx_offload_result,
18634                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18635                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18636                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18637                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18638                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18639 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18640         TOKEN_STRING_INITIALIZER
18641                 (struct cmd_config_per_queue_tx_offload_result,
18642                  on_off, "on#off");
18643
18644 static void
18645 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18646                                 __attribute__((unused)) struct cmdline *cl,
18647                                 __attribute__((unused)) void *data)
18648 {
18649         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18650         struct rte_eth_dev_info dev_info;
18651         portid_t port_id = res->port_id;
18652         uint16_t queue_id = res->queue_id;
18653         struct rte_port *port = &ports[port_id];
18654         uint64_t single_offload;
18655         int ret;
18656
18657         if (port->port_status != RTE_PORT_STOPPED) {
18658                 printf("Error: Can't config offload when Port %d "
18659                        "is not stopped\n", port_id);
18660                 return;
18661         }
18662
18663         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18664         if (ret != 0)
18665                 return;
18666
18667         if (queue_id >= dev_info.nb_tx_queues) {
18668                 printf("Error: input queue_id should be 0 ... "
18669                        "%d\n", dev_info.nb_tx_queues - 1);
18670                 return;
18671         }
18672
18673         single_offload = search_tx_offload(res->offload);
18674         if (single_offload == 0) {
18675                 printf("Unknown offload name: %s\n", res->offload);
18676                 return;
18677         }
18678
18679         if (!strcmp(res->on_off, "on"))
18680                 port->tx_conf[queue_id].offloads |= single_offload;
18681         else
18682                 port->tx_conf[queue_id].offloads &= ~single_offload;
18683
18684         cmd_reconfig_device_queue(port_id, 1, 1);
18685 }
18686
18687 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18688         .f = cmd_config_per_queue_tx_offload_parsed,
18689         .data = NULL,
18690         .help_str = "port <port_id> txq <queue_id> tx_offload "
18691                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18692                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18693                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18694                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18695                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18696                     "on|off",
18697         .tokens = {
18698                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18699                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18700                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18701                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18702                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18703                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18704                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18705                 NULL,
18706         }
18707 };
18708
18709 /* *** configure tx_metadata for specific port *** */
18710 struct cmd_config_tx_metadata_specific_result {
18711         cmdline_fixed_string_t port;
18712         cmdline_fixed_string_t keyword;
18713         uint16_t port_id;
18714         cmdline_fixed_string_t item;
18715         uint32_t value;
18716 };
18717
18718 static void
18719 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18720                                 __attribute__((unused)) struct cmdline *cl,
18721                                 __attribute__((unused)) void *data)
18722 {
18723         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18724
18725         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18726                 return;
18727         ports[res->port_id].tx_metadata = res->value;
18728         /* Add/remove callback to insert valid metadata in every Tx packet. */
18729         if (ports[res->port_id].tx_metadata)
18730                 add_tx_md_callback(res->port_id);
18731         else
18732                 remove_tx_md_callback(res->port_id);
18733         rte_flow_dynf_metadata_register();
18734 }
18735
18736 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18737         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18738                         port, "port");
18739 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18740         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18741                         keyword, "config");
18742 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18743         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18744                         port_id, UINT16);
18745 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18746         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18747                         item, "tx_metadata");
18748 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18749         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18750                         value, UINT32);
18751
18752 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18753         .f = cmd_config_tx_metadata_specific_parsed,
18754         .data = NULL,
18755         .help_str = "port config <port_id> tx_metadata <value>",
18756         .tokens = {
18757                 (void *)&cmd_config_tx_metadata_specific_port,
18758                 (void *)&cmd_config_tx_metadata_specific_keyword,
18759                 (void *)&cmd_config_tx_metadata_specific_id,
18760                 (void *)&cmd_config_tx_metadata_specific_item,
18761                 (void *)&cmd_config_tx_metadata_specific_value,
18762                 NULL,
18763         },
18764 };
18765
18766 /* *** display tx_metadata per port configuration *** */
18767 struct cmd_show_tx_metadata_result {
18768         cmdline_fixed_string_t cmd_show;
18769         cmdline_fixed_string_t cmd_port;
18770         cmdline_fixed_string_t cmd_keyword;
18771         portid_t cmd_pid;
18772 };
18773
18774 static void
18775 cmd_show_tx_metadata_parsed(void *parsed_result,
18776                 __attribute__((unused)) struct cmdline *cl,
18777                 __attribute__((unused)) void *data)
18778 {
18779         struct cmd_show_tx_metadata_result *res = parsed_result;
18780
18781         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18782                 printf("invalid port id %u\n", res->cmd_pid);
18783                 return;
18784         }
18785         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18786                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18787                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18788         }
18789 }
18790
18791 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18792         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18793                         cmd_show, "show");
18794 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18795         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18796                         cmd_port, "port");
18797 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18798         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18799                         cmd_pid, UINT16);
18800 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18801         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18802                         cmd_keyword, "tx_metadata");
18803
18804 cmdline_parse_inst_t cmd_show_tx_metadata = {
18805         .f = cmd_show_tx_metadata_parsed,
18806         .data = NULL,
18807         .help_str = "show port <port_id> tx_metadata",
18808         .tokens = {
18809                 (void *)&cmd_show_tx_metadata_show,
18810                 (void *)&cmd_show_tx_metadata_port,
18811                 (void *)&cmd_show_tx_metadata_pid,
18812                 (void *)&cmd_show_tx_metadata_keyword,
18813                 NULL,
18814         },
18815 };
18816
18817 /* show port supported ptypes */
18818
18819 /* Common result structure for show port ptypes */
18820 struct cmd_show_port_supported_ptypes_result {
18821         cmdline_fixed_string_t show;
18822         cmdline_fixed_string_t port;
18823         portid_t port_id;
18824         cmdline_fixed_string_t ptypes;
18825 };
18826
18827 /* Common CLI fields for show port ptypes */
18828 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18829         TOKEN_STRING_INITIALIZER
18830                 (struct cmd_show_port_supported_ptypes_result,
18831                  show, "show");
18832 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18833         TOKEN_STRING_INITIALIZER
18834                 (struct cmd_show_port_supported_ptypes_result,
18835                  port, "port");
18836 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
18837         TOKEN_NUM_INITIALIZER
18838                 (struct cmd_show_port_supported_ptypes_result,
18839                  port_id, UINT16);
18840 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
18841         TOKEN_STRING_INITIALIZER
18842                 (struct cmd_show_port_supported_ptypes_result,
18843                  ptypes, "ptypes");
18844
18845 static void
18846 cmd_show_port_supported_ptypes_parsed(
18847         void *parsed_result,
18848         __attribute__((unused)) struct cmdline *cl,
18849         __attribute__((unused)) void *data)
18850 {
18851 #define RSVD_PTYPE_MASK       0xf0000000
18852 #define MAX_PTYPES_PER_LAYER  16
18853 #define LTYPE_NAMESIZE        32
18854 #define PTYPE_NAMESIZE        256
18855         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
18856         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
18857         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
18858         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
18859         uint16_t port_id = res->port_id;
18860         int ret, i;
18861
18862         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
18863         if (ret < 0)
18864                 return;
18865
18866         while (ptype_mask != RSVD_PTYPE_MASK) {
18867
18868                 switch (ptype_mask) {
18869                 case RTE_PTYPE_L2_MASK:
18870                         strlcpy(ltype, "L2", sizeof(ltype));
18871                         break;
18872                 case RTE_PTYPE_L3_MASK:
18873                         strlcpy(ltype, "L3", sizeof(ltype));
18874                         break;
18875                 case RTE_PTYPE_L4_MASK:
18876                         strlcpy(ltype, "L4", sizeof(ltype));
18877                         break;
18878                 case RTE_PTYPE_TUNNEL_MASK:
18879                         strlcpy(ltype, "Tunnel", sizeof(ltype));
18880                         break;
18881                 case RTE_PTYPE_INNER_L2_MASK:
18882                         strlcpy(ltype, "Inner L2", sizeof(ltype));
18883                         break;
18884                 case RTE_PTYPE_INNER_L3_MASK:
18885                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18886                         break;
18887                 case RTE_PTYPE_INNER_L4_MASK:
18888                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18889                         break;
18890                 default:
18891                         return;
18892                 }
18893
18894                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18895                                                        ptype_mask, ptypes,
18896                                                        MAX_PTYPES_PER_LAYER);
18897
18898                 if (ret > 0)
18899                         printf("Supported %s ptypes:\n", ltype);
18900                 else
18901                         printf("%s ptypes unsupported\n", ltype);
18902
18903                 for (i = 0; i < ret; ++i) {
18904                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18905                         printf("%s\n", buf);
18906                 }
18907
18908                 ptype_mask <<= 4;
18909         }
18910 }
18911
18912 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18913         .f = cmd_show_port_supported_ptypes_parsed,
18914         .data = NULL,
18915         .help_str = "show port <port_id> ptypes",
18916         .tokens = {
18917                 (void *)&cmd_show_port_supported_ptypes_show,
18918                 (void *)&cmd_show_port_supported_ptypes_port,
18919                 (void *)&cmd_show_port_supported_ptypes_port_id,
18920                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18921                 NULL,
18922         },
18923 };
18924
18925 /* *** display rx/tx descriptor status *** */
18926 struct cmd_show_rx_tx_desc_status_result {
18927         cmdline_fixed_string_t cmd_show;
18928         cmdline_fixed_string_t cmd_port;
18929         cmdline_fixed_string_t cmd_keyword;
18930         cmdline_fixed_string_t cmd_desc;
18931         cmdline_fixed_string_t cmd_status;
18932         portid_t cmd_pid;
18933         portid_t cmd_qid;
18934         portid_t cmd_did;
18935 };
18936
18937 static void
18938 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
18939                 __attribute__((unused)) struct cmdline *cl,
18940                 __attribute__((unused)) void *data)
18941 {
18942         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
18943         int rc;
18944
18945         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18946                 printf("invalid port id %u\n", res->cmd_pid);
18947                 return;
18948         }
18949
18950         if (!strcmp(res->cmd_keyword, "rxq")) {
18951                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
18952                                              res->cmd_did);
18953                 if (rc < 0) {
18954                         printf("Invalid queueid = %d\n", res->cmd_qid);
18955                         return;
18956                 }
18957                 if (rc == RTE_ETH_RX_DESC_AVAIL)
18958                         printf("Desc status = AVAILABLE\n");
18959                 else if (rc == RTE_ETH_RX_DESC_DONE)
18960                         printf("Desc status = DONE\n");
18961                 else
18962                         printf("Desc status = UNAVAILABLE\n");
18963         } else if (!strcmp(res->cmd_keyword, "txq")) {
18964                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
18965                                              res->cmd_did);
18966                 if (rc < 0) {
18967                         printf("Invalid queueid = %d\n", res->cmd_qid);
18968                         return;
18969                 }
18970                 if (rc == RTE_ETH_TX_DESC_FULL)
18971                         printf("Desc status = FULL\n");
18972                 else if (rc == RTE_ETH_TX_DESC_DONE)
18973                         printf("Desc status = DONE\n");
18974                 else
18975                         printf("Desc status = UNAVAILABLE\n");
18976         }
18977 }
18978
18979 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
18980         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18981                         cmd_show, "show");
18982 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
18983         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18984                         cmd_port, "port");
18985 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
18986         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18987                         cmd_pid, UINT16);
18988 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
18989         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18990                         cmd_keyword, "rxq#txq");
18991 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
18992         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18993                         cmd_qid, UINT16);
18994 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
18995         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18996                         cmd_desc, "desc");
18997 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
18998         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18999                         cmd_did, UINT16);
19000 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19001         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19002                         cmd_status, "status");
19003 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19004         .f = cmd_show_rx_tx_desc_status_parsed,
19005         .data = NULL,
19006         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19007                 "status",
19008         .tokens = {
19009                 (void *)&cmd_show_rx_tx_desc_status_show,
19010                 (void *)&cmd_show_rx_tx_desc_status_port,
19011                 (void *)&cmd_show_rx_tx_desc_status_pid,
19012                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19013                 (void *)&cmd_show_rx_tx_desc_status_qid,
19014                 (void *)&cmd_show_rx_tx_desc_status_desc,
19015                 (void *)&cmd_show_rx_tx_desc_status_did,
19016                 (void *)&cmd_show_rx_tx_desc_status_status,
19017                 NULL,
19018         },
19019 };
19020
19021 /* Common result structure for set port ptypes */
19022 struct cmd_set_port_ptypes_result {
19023         cmdline_fixed_string_t set;
19024         cmdline_fixed_string_t port;
19025         portid_t port_id;
19026         cmdline_fixed_string_t ptype_mask;
19027         uint32_t mask;
19028 };
19029
19030 /* Common CLI fields for set port ptypes */
19031 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19032         TOKEN_STRING_INITIALIZER
19033                 (struct cmd_set_port_ptypes_result,
19034                  set, "set");
19035 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19036         TOKEN_STRING_INITIALIZER
19037                 (struct cmd_set_port_ptypes_result,
19038                  port, "port");
19039 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19040         TOKEN_NUM_INITIALIZER
19041                 (struct cmd_set_port_ptypes_result,
19042                  port_id, UINT16);
19043 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19044         TOKEN_STRING_INITIALIZER
19045                 (struct cmd_set_port_ptypes_result,
19046                  ptype_mask, "ptype_mask");
19047 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19048         TOKEN_NUM_INITIALIZER
19049                 (struct cmd_set_port_ptypes_result,
19050                  mask, UINT32);
19051
19052 static void
19053 cmd_set_port_ptypes_parsed(
19054         void *parsed_result,
19055         __attribute__((unused)) struct cmdline *cl,
19056         __attribute__((unused)) void *data)
19057 {
19058         struct cmd_set_port_ptypes_result *res = parsed_result;
19059 #define PTYPE_NAMESIZE        256
19060         char ptype_name[PTYPE_NAMESIZE];
19061         uint16_t port_id = res->port_id;
19062         uint32_t ptype_mask = res->mask;
19063         int ret, i;
19064
19065         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19066                                                NULL, 0);
19067         if (ret <= 0) {
19068                 printf("Port %d doesn't support any ptypes.\n", port_id);
19069                 return;
19070         }
19071
19072         uint32_t ptypes[ret];
19073
19074         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19075         if (ret < 0) {
19076                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19077                 return;
19078         }
19079
19080         printf("Successfully set following ptypes for Port %d\n", port_id);
19081         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19082                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19083                 printf("%s\n", ptype_name);
19084         }
19085
19086         clear_ptypes = false;
19087 }
19088
19089 cmdline_parse_inst_t cmd_set_port_ptypes = {
19090         .f = cmd_set_port_ptypes_parsed,
19091         .data = NULL,
19092         .help_str = "set port <port_id> ptype_mask <mask>",
19093         .tokens = {
19094                 (void *)&cmd_set_port_ptypes_set,
19095                 (void *)&cmd_set_port_ptypes_port,
19096                 (void *)&cmd_set_port_ptypes_port_id,
19097                 (void *)&cmd_set_port_ptypes_mask_str,
19098                 (void *)&cmd_set_port_ptypes_mask_u32,
19099                 NULL,
19100         },
19101 };
19102
19103 /* ******************************************************************************** */
19104
19105 /* list of instructions */
19106 cmdline_parse_ctx_t main_ctx[] = {
19107         (cmdline_parse_inst_t *)&cmd_help_brief,
19108         (cmdline_parse_inst_t *)&cmd_help_long,
19109         (cmdline_parse_inst_t *)&cmd_quit,
19110         (cmdline_parse_inst_t *)&cmd_load_from_file,
19111         (cmdline_parse_inst_t *)&cmd_showport,
19112         (cmdline_parse_inst_t *)&cmd_showqueue,
19113         (cmdline_parse_inst_t *)&cmd_showportall,
19114         (cmdline_parse_inst_t *)&cmd_showdevice,
19115         (cmdline_parse_inst_t *)&cmd_showcfg,
19116         (cmdline_parse_inst_t *)&cmd_showfwdall,
19117         (cmdline_parse_inst_t *)&cmd_start,
19118         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19119         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19120         (cmdline_parse_inst_t *)&cmd_set_link_up,
19121         (cmdline_parse_inst_t *)&cmd_set_link_down,
19122         (cmdline_parse_inst_t *)&cmd_reset,
19123         (cmdline_parse_inst_t *)&cmd_set_numbers,
19124         (cmdline_parse_inst_t *)&cmd_set_log,
19125         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19126         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19127         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19128         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19129         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19130         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19131         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19132         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19133         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19134         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19135         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19136         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19137         (cmdline_parse_inst_t *)&cmd_set_link_check,
19138         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19139         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19140         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19141         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19142 #ifdef RTE_LIBRTE_PMD_BOND
19143         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19144         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19145         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19146         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19147         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19148         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19149         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19150         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19151         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19152         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19153         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19154 #endif
19155         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19156         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19157         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19158         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19159         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19160         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19161         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19162         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19163         (cmdline_parse_inst_t *)&cmd_csum_set,
19164         (cmdline_parse_inst_t *)&cmd_csum_show,
19165         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19166         (cmdline_parse_inst_t *)&cmd_tso_set,
19167         (cmdline_parse_inst_t *)&cmd_tso_show,
19168         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19169         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19170         (cmdline_parse_inst_t *)&cmd_gro_enable,
19171         (cmdline_parse_inst_t *)&cmd_gro_flush,
19172         (cmdline_parse_inst_t *)&cmd_gro_show,
19173         (cmdline_parse_inst_t *)&cmd_gso_enable,
19174         (cmdline_parse_inst_t *)&cmd_gso_size,
19175         (cmdline_parse_inst_t *)&cmd_gso_show,
19176         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19177         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19178         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19179         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19180         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19181         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19182         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19183         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19184         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19185         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19186         (cmdline_parse_inst_t *)&cmd_config_dcb,
19187         (cmdline_parse_inst_t *)&cmd_read_reg,
19188         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19189         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19190         (cmdline_parse_inst_t *)&cmd_write_reg,
19191         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19192         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19193         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19194         (cmdline_parse_inst_t *)&cmd_stop,
19195         (cmdline_parse_inst_t *)&cmd_mac_addr,
19196         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19197         (cmdline_parse_inst_t *)&cmd_set_qmap,
19198         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19199         (cmdline_parse_inst_t *)&cmd_operate_port,
19200         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19201         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19202         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19203         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19204         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19205         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19206         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19207         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19208         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19209         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19210         (cmdline_parse_inst_t *)&cmd_config_mtu,
19211         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19212         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19213         (cmdline_parse_inst_t *)&cmd_config_rss,
19214         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19215         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19216         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19217         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19218         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19219         (cmdline_parse_inst_t *)&cmd_showport_reta,
19220         (cmdline_parse_inst_t *)&cmd_config_burst,
19221         (cmdline_parse_inst_t *)&cmd_config_thresh,
19222         (cmdline_parse_inst_t *)&cmd_config_threshold,
19223         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19224         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19225         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19226         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19227         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19228         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19229         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19230         (cmdline_parse_inst_t *)&cmd_global_config,
19231         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19232         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19233         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19234         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19235         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19236         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19237         (cmdline_parse_inst_t *)&cmd_dump,
19238         (cmdline_parse_inst_t *)&cmd_dump_one,
19239         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19240         (cmdline_parse_inst_t *)&cmd_syn_filter,
19241         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19242         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19243         (cmdline_parse_inst_t *)&cmd_flex_filter,
19244         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19245         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19246         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19247         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19248         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19249         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19250         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19251         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19252         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19253         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19254         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19255         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19256         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19257         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19258         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19259         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19260         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19261         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19262         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19263         (cmdline_parse_inst_t *)&cmd_flow,
19264         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19265         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19266         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19267         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19268         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19269         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19270         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19271         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19272         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19273         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19274         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19275         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19276         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19277         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19278         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19279         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19280         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19281         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19282         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19283         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19284         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19285         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19286         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19287         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19288         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19289         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19290         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19291         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19292         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19293         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19294         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19295         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19296         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19297         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19298         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19299         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19300         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19301         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19302         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19303         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19304         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19305         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19306         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19307         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19308         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19309         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19310         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19311         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19312         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19313 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19314         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19315 #endif
19316         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19317         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19318         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19319         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19320         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19321         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19322         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19323         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19324         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19325         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19326         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19327         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19328         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19329         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19330         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19331         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19332         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19333         (cmdline_parse_inst_t *)&cmd_ddp_add,
19334         (cmdline_parse_inst_t *)&cmd_ddp_del,
19335         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19336         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19337         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19338         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19339         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19340         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19341         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19342         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19343         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19344         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19345         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19346         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19347
19348         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19349         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19350         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19351         (cmdline_parse_inst_t *)&cmd_queue_region,
19352         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19353         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19354         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19355         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19356         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19357         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19358         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19359         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19360         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19361         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19362         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19363         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19364         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19365         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19366         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19367         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19368         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19369         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19370         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19371         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19372         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19373         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19374         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19375         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19376         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19377         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19378         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19379         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19380         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19381         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19382         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19383         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19384         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19385         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19386         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19387 #ifdef RTE_LIBRTE_BPF
19388         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19389         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19390 #endif
19391         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19392         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19393         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19394         (cmdline_parse_inst_t *)&cmd_set_raw,
19395         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19396         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19397         NULL,
19398 };
19399
19400 /* read cmdline commands from file */
19401 void
19402 cmdline_read_from_file(const char *filename)
19403 {
19404         struct cmdline *cl;
19405
19406         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19407         if (cl == NULL) {
19408                 printf("Failed to create file based cmdline context: %s\n",
19409                        filename);
19410                 return;
19411         }
19412
19413         cmdline_interact(cl);
19414         cmdline_quit(cl);
19415
19416         cmdline_free(cl);
19417
19418         printf("Read CLI commands from %s\n", filename);
19419 }
19420
19421 /* prompt function, called from main on MASTER lcore */
19422 void
19423 prompt(void)
19424 {
19425         /* initialize non-constant commands */
19426         cmd_set_fwd_mode_init();
19427         cmd_set_fwd_retry_mode_init();
19428
19429         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19430         if (testpmd_cl == NULL)
19431                 return;
19432         cmdline_interact(testpmd_cl);
19433         cmdline_stdin_exit(testpmd_cl);
19434 }
19435
19436 void
19437 prompt_exit(void)
19438 {
19439         if (testpmd_cl != NULL)
19440                 cmdline_quit(testpmd_cl);
19441 }
19442
19443 static void
19444 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19445 {
19446         if (id == (portid_t)RTE_PORT_ALL) {
19447                 portid_t pid;
19448
19449                 RTE_ETH_FOREACH_DEV(pid) {
19450                         /* check if need_reconfig has been set to 1 */
19451                         if (ports[pid].need_reconfig == 0)
19452                                 ports[pid].need_reconfig = dev;
19453                         /* check if need_reconfig_queues has been set to 1 */
19454                         if (ports[pid].need_reconfig_queues == 0)
19455                                 ports[pid].need_reconfig_queues = queue;
19456                 }
19457         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19458                 /* check if need_reconfig has been set to 1 */
19459                 if (ports[id].need_reconfig == 0)
19460                         ports[id].need_reconfig = dev;
19461                 /* check if need_reconfig_queues has been set to 1 */
19462                 if (ports[id].need_reconfig_queues == 0)
19463                         ports[id].need_reconfig_queues = queue;
19464         }
19465 }