6b9444f42d92a83de771a4a42dbc6dabf4c0ecf2
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_flow.h>
48 #include <rte_gro.h>
49
50 #include <cmdline_rdline.h>
51 #include <cmdline_parse.h>
52 #include <cmdline_parse_num.h>
53 #include <cmdline_parse_string.h>
54 #include <cmdline_parse_ipaddr.h>
55 #include <cmdline_parse_etheraddr.h>
56 #include <cmdline_socket.h>
57 #include <cmdline.h>
58 #ifdef RTE_LIBRTE_PMD_BOND
59 #include <rte_eth_bond.h>
60 #include <rte_eth_bond_8023ad.h>
61 #endif
62 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
63 #include <rte_pmd_dpaa.h>
64 #endif
65 #ifdef RTE_LIBRTE_IXGBE_PMD
66 #include <rte_pmd_ixgbe.h>
67 #endif
68 #ifdef RTE_LIBRTE_I40E_PMD
69 #include <rte_pmd_i40e.h>
70 #endif
71 #ifdef RTE_LIBRTE_BNXT_PMD
72 #include <rte_pmd_bnxt.h>
73 #endif
74 #include "testpmd.h"
75 #include "cmdline_mtr.h"
76 #include "cmdline_tm.h"
77 #include "bpf_cmd.h"
78
79 static struct cmdline *testpmd_cl;
80
81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
82
83 /* *** Help command with introduction. *** */
84 struct cmd_help_brief_result {
85         cmdline_fixed_string_t help;
86 };
87
88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
89                                   struct cmdline *cl,
90                                   __attribute__((unused)) void *data)
91 {
92         cmdline_printf(
93                 cl,
94                 "\n"
95                 "Help is available for the following sections:\n\n"
96                 "    help control                    : Start and stop forwarding.\n"
97                 "    help display                    : Displaying port, stats and config "
98                 "information.\n"
99                 "    help config                     : Configuration information.\n"
100                 "    help ports                      : Configuring ports.\n"
101                 "    help registers                  : Reading and setting port registers.\n"
102                 "    help filters                    : Filters configuration help.\n"
103                 "    help traffic_management         : Traffic Management commmands.\n"
104                 "    help devices                    : Device related cmds.\n"
105                 "    help all                        : All of the above sections.\n\n"
106         );
107
108 }
109
110 cmdline_parse_token_string_t cmd_help_brief_help =
111         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
112
113 cmdline_parse_inst_t cmd_help_brief = {
114         .f = cmd_help_brief_parsed,
115         .data = NULL,
116         .help_str = "help: Show help",
117         .tokens = {
118                 (void *)&cmd_help_brief_help,
119                 NULL,
120         },
121 };
122
123 /* *** Help command with help sections. *** */
124 struct cmd_help_long_result {
125         cmdline_fixed_string_t help;
126         cmdline_fixed_string_t section;
127 };
128
129 static void cmd_help_long_parsed(void *parsed_result,
130                                  struct cmdline *cl,
131                                  __attribute__((unused)) void *data)
132 {
133         int show_all = 0;
134         struct cmd_help_long_result *res = parsed_result;
135
136         if (!strcmp(res->section, "all"))
137                 show_all = 1;
138
139         if (show_all || !strcmp(res->section, "control")) {
140
141                 cmdline_printf(
142                         cl,
143                         "\n"
144                         "Control forwarding:\n"
145                         "-------------------\n\n"
146
147                         "start\n"
148                         "    Start packet forwarding with current configuration.\n\n"
149
150                         "start tx_first\n"
151                         "    Start packet forwarding with current config"
152                         " after sending one burst of packets.\n\n"
153
154                         "stop\n"
155                         "    Stop packet forwarding, and display accumulated"
156                         " statistics.\n\n"
157
158                         "quit\n"
159                         "    Quit to prompt.\n\n"
160                 );
161         }
162
163         if (show_all || !strcmp(res->section, "display")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Display:\n"
169                         "--------\n\n"
170
171                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
172                         "    Display information for port_id, or all.\n\n"
173
174                         "show port X rss reta (size) (mask0,mask1,...)\n"
175                         "    Display the rss redirection table entry indicated"
176                         " by masks on port X. size is used to indicate the"
177                         " hardware supported reta size\n\n"
178
179                         "show port (port_id) rss-hash [key]\n"
180                         "    Display the RSS hash functions and RSS hash key of port\n\n"
181
182                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
183                         "    Clear information for port_id, or all.\n\n"
184
185                         "show (rxq|txq) info (port_id) (queue_id)\n"
186                         "    Display information for configured RX/TX queue.\n\n"
187
188                         "show config (rxtx|cores|fwd|txpkts)\n"
189                         "    Display the given configuration.\n\n"
190
191                         "read rxd (port_id) (queue_id) (rxd_id)\n"
192                         "    Display an RX descriptor of a port RX queue.\n\n"
193
194                         "read txd (port_id) (queue_id) (txd_id)\n"
195                         "    Display a TX descriptor of a port TX queue.\n\n"
196
197                         "ddp get list (port_id)\n"
198                         "    Get ddp profile info list\n\n"
199
200                         "ddp get info (profile_path)\n"
201                         "    Get ddp profile information.\n\n"
202
203                         "show vf stats (port_id) (vf_id)\n"
204                         "    Display a VF's statistics.\n\n"
205
206                         "clear vf stats (port_id) (vf_id)\n"
207                         "    Reset a VF's statistics.\n\n"
208
209                         "show port (port_id) pctype mapping\n"
210                         "    Get flow ptype to pctype mapping on a port\n\n"
211
212                         "show port meter stats (port_id) (meter_id) (clear)\n"
213                         "    Get meter stats on a port\n\n"
214
215                         "show fwd stats all\n"
216                         "    Display statistics for all fwd engines.\n\n"
217
218                         "clear fwd stats all\n"
219                         "    Clear statistics for all fwd engines.\n\n"
220
221                         "show port (port_id) rx_offload capabilities\n"
222                         "    List all per queue and per port Rx offloading"
223                         " capabilities of a port\n\n"
224
225                         "show port (port_id) rx_offload configuration\n"
226                         "    List port level and all queue level"
227                         " Rx offloading configuration\n\n"
228
229                         "show port (port_id) tx_offload capabilities\n"
230                         "    List all per queue and per port"
231                         " Tx offloading capabilities of a port\n\n"
232
233                         "show port (port_id) tx_offload configuration\n"
234                         "    List port level and all queue level"
235                         " Tx offloading configuration\n\n"
236
237                         "show port (port_id) tx_metadata\n"
238                         "    Show Tx metadata value set"
239                         " for a specific port\n\n"
240
241                         "show device info (<identifier>|all)"
242                         "       Show general information about devices probed.\n\n"
243                 );
244         }
245
246         if (show_all || !strcmp(res->section, "config")) {
247                 cmdline_printf(
248                         cl,
249                         "\n"
250                         "Configuration:\n"
251                         "--------------\n"
252                         "Configuration changes only become active when"
253                         " forwarding is started/restarted.\n\n"
254
255                         "set default\n"
256                         "    Reset forwarding to the default configuration.\n\n"
257
258                         "set verbose (level)\n"
259                         "    Set the debug verbosity level X.\n\n"
260
261                         "set log global|(type) (level)\n"
262                         "    Set the log level.\n\n"
263
264                         "set nbport (num)\n"
265                         "    Set number of ports.\n\n"
266
267                         "set nbcore (num)\n"
268                         "    Set number of cores.\n\n"
269
270                         "set coremask (mask)\n"
271                         "    Set the forwarding cores hexadecimal mask.\n\n"
272
273                         "set portmask (mask)\n"
274                         "    Set the forwarding ports hexadecimal mask.\n\n"
275
276                         "set burst (num)\n"
277                         "    Set number of packets per burst.\n\n"
278
279                         "set burst tx delay (microseconds) retry (num)\n"
280                         "    Set the transmit delay time and number of retries,"
281                         " effective when retry is enabled.\n\n"
282
283                         "set txpkts (x[,y]*)\n"
284                         "    Set the length of each segment of TXONLY"
285                         " and optionally CSUM packets.\n\n"
286
287                         "set txsplit (off|on|rand)\n"
288                         "    Set the split policy for the TX packets."
289                         " Right now only applicable for CSUM and TXONLY"
290                         " modes\n\n"
291
292                         "set corelist (x[,y]*)\n"
293                         "    Set the list of forwarding cores.\n\n"
294
295                         "set portlist (x[,y]*)\n"
296                         "    Set the list of forwarding ports.\n\n"
297
298                         "set port setup on (iterator|event)\n"
299                         "    Select how attached port is retrieved for setup.\n\n"
300
301                         "set tx loopback (port_id) (on|off)\n"
302                         "    Enable or disable tx loopback.\n\n"
303
304                         "set all queues drop (port_id) (on|off)\n"
305                         "    Set drop enable bit for all queues.\n\n"
306
307                         "set vf split drop (port_id) (vf_id) (on|off)\n"
308                         "    Set split drop enable bit for a VF from the PF.\n\n"
309
310                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
311                         "    Set MAC antispoof for a VF from the PF.\n\n"
312
313                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
314                         "    Enable MACsec offload.\n\n"
315
316                         "set macsec offload (port_id) off\n"
317                         "    Disable MACsec offload.\n\n"
318
319                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
320                         "    Configure MACsec secure connection (SC).\n\n"
321
322                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
323                         "    Configure MACsec secure association (SA).\n\n"
324
325                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
326                         "    Set VF broadcast for a VF from the PF.\n\n"
327
328                         "vlan set strip (on|off) (port_id)\n"
329                         "    Set the VLAN strip on a port.\n\n"
330
331                         "vlan set stripq (on|off) (port_id,queue_id)\n"
332                         "    Set the VLAN strip for a queue on a port.\n\n"
333
334                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
335                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
336
337                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
338                         "    Set VLAN insert for a VF from the PF.\n\n"
339
340                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
341                         "    Set VLAN antispoof for a VF from the PF.\n\n"
342
343                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
344                         "    Set VLAN tag for a VF from the PF.\n\n"
345
346                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
347                         "    Set a VF's max bandwidth(Mbps).\n\n"
348
349                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
350                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
351
352                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
353                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
354
355                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
356                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
357
358                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
359                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
360
361                         "vlan set filter (on|off) (port_id)\n"
362                         "    Set the VLAN filter on a port.\n\n"
363
364                         "vlan set qinq (on|off) (port_id)\n"
365                         "    Set the VLAN QinQ (extended queue in queue)"
366                         " on a port.\n\n"
367
368                         "vlan set (inner|outer) tpid (value) (port_id)\n"
369                         "    Set the VLAN TPID for Packet Filtering on"
370                         " a port\n\n"
371
372                         "rx_vlan add (vlan_id|all) (port_id)\n"
373                         "    Add a vlan_id, or all identifiers, to the set"
374                         " of VLAN identifiers filtered by port_id.\n\n"
375
376                         "rx_vlan rm (vlan_id|all) (port_id)\n"
377                         "    Remove a vlan_id, or all identifiers, from the set"
378                         " of VLAN identifiers filtered by port_id.\n\n"
379
380                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
381                         "    Add a vlan_id, to the set of VLAN identifiers"
382                         "filtered for VF(s) from port_id.\n\n"
383
384                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
385                         "    Remove a vlan_id, to the set of VLAN identifiers"
386                         "filtered for VF(s) from port_id.\n\n"
387
388                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
389                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
390                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
391                         "   add a tunnel filter of a port.\n\n"
392
393                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
394                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
395                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
396                         "   remove a tunnel filter of a port.\n\n"
397
398                         "rx_vxlan_port add (udp_port) (port_id)\n"
399                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
400
401                         "rx_vxlan_port rm (udp_port) (port_id)\n"
402                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
403
404                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
405                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
406                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
407
408                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
409                         "    Set port based TX VLAN insertion.\n\n"
410
411                         "tx_vlan reset (port_id)\n"
412                         "    Disable hardware insertion of a VLAN header in"
413                         " packets sent on a port.\n\n"
414
415                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
416                         "    Select hardware or software calculation of the"
417                         " checksum when transmitting a packet using the"
418                         " csum forward engine.\n"
419                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
420                         "    outer-ip concerns the outer IP layer in"
421                         "    outer-udp concerns the outer UDP layer in"
422                         " case the packet is recognized as a tunnel packet by"
423                         " the forward engine (vxlan, gre and ipip are supported)\n"
424                         "    Please check the NIC datasheet for HW limits.\n\n"
425
426                         "csum parse-tunnel (on|off) (tx_port_id)\n"
427                         "    If disabled, treat tunnel packets as non-tunneled"
428                         " packets (treat inner headers as payload). The port\n"
429                         "    argument is the port used for TX in csum forward"
430                         " engine.\n\n"
431
432                         "csum show (port_id)\n"
433                         "    Display tx checksum offload configuration\n\n"
434
435                         "tso set (segsize) (portid)\n"
436                         "    Enable TCP Segmentation Offload in csum forward"
437                         " engine.\n"
438                         "    Please check the NIC datasheet for HW limits.\n\n"
439
440                         "tso show (portid)"
441                         "    Display the status of TCP Segmentation Offload.\n\n"
442
443                         "set port (port_id) gro on|off\n"
444                         "    Enable or disable Generic Receive Offload in"
445                         " csum forwarding engine.\n\n"
446
447                         "show port (port_id) gro\n"
448                         "    Display GRO configuration.\n\n"
449
450                         "set gro flush (cycles)\n"
451                         "    Set the cycle to flush GROed packets from"
452                         " reassembly tables.\n\n"
453
454                         "set port (port_id) gso (on|off)"
455                         "    Enable or disable Generic Segmentation Offload in"
456                         " csum forwarding engine.\n\n"
457
458                         "set gso segsz (length)\n"
459                         "    Set max packet length for output GSO segments,"
460                         " including packet header and payload.\n\n"
461
462                         "show port (port_id) gso\n"
463                         "    Show GSO configuration.\n\n"
464
465                         "set fwd (%s)\n"
466                         "    Set packet forwarding mode.\n\n"
467
468                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
469                         "    Add a MAC address on port_id.\n\n"
470
471                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
472                         "    Remove a MAC address from port_id.\n\n"
473
474                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Set the default MAC address for port_id.\n\n"
476
477                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
478                         "    Add a MAC address for a VF on the port.\n\n"
479
480                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the MAC address for a VF from the PF.\n\n"
482
483                         "set eth-peer (port_id) (peer_addr)\n"
484                         "    set the peer address for certain port.\n\n"
485
486                         "set port (port_id) uta (mac_address|all) (on|off)\n"
487                         "    Add/Remove a or all unicast hash filter(s)"
488                         "from port X.\n\n"
489
490                         "set promisc (port_id|all) (on|off)\n"
491                         "    Set the promiscuous mode on port_id, or all.\n\n"
492
493                         "set allmulti (port_id|all) (on|off)\n"
494                         "    Set the allmulti mode on port_id, or all.\n\n"
495
496                         "set vf promisc (port_id) (vf_id) (on|off)\n"
497                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
498
499                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
500                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
503                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
504                         " (on|off) autoneg (on|off) (port_id)\n"
505                         "set flow_ctrl rx (on|off) (portid)\n"
506                         "set flow_ctrl tx (on|off) (portid)\n"
507                         "set flow_ctrl high_water (high_water) (portid)\n"
508                         "set flow_ctrl low_water (low_water) (portid)\n"
509                         "set flow_ctrl pause_time (pause_time) (portid)\n"
510                         "set flow_ctrl send_xon (send_xon) (portid)\n"
511                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
512                         "set flow_ctrl autoneg (on|off) (port_id)\n"
513                         "    Set the link flow control parameter on a port.\n\n"
514
515                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (priority) (port_id)\n"
517                         "    Set the priority flow control parameter on a"
518                         " port.\n\n"
519
520                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
521                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
522                         " queue on port.\n"
523                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
524                         " on port 0 to mapping 5.\n\n"
525
526                         "set xstats-hide-zero on|off\n"
527                         "    Set the option to hide the zero values"
528                         " for xstats display.\n"
529
530                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
531                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
532
533                         "set port (port_id) vf (vf_id) (mac_addr)"
534                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
535                         "   Add/Remove unicast or multicast MAC addr filter"
536                         " for a VF.\n\n"
537
538                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
539                         "|MPE) (on|off)\n"
540                         "    AUPE:accepts untagged VLAN;"
541                         "ROPE:accept unicast hash\n\n"
542                         "    BAM:accepts broadcast packets;"
543                         "MPE:accepts all multicast packets\n\n"
544                         "    Enable/Disable a VF receive mode of a port\n\n"
545
546                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
547                         "    Set rate limit for a queue of a port\n\n"
548
549                         "set port (port_id) vf (vf_id) rate (rate_num) "
550                         "queue_mask (queue_mask_value)\n"
551                         "    Set rate limit for queues in VF of a port\n\n"
552
553                         "set port (port_id) mirror-rule (rule_id)"
554                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
555                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
556                         "   Set pool or vlan type mirror rule on a port.\n"
557                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
558                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
559                         " to pool 0.\n\n"
560
561                         "set port (port_id) mirror-rule (rule_id)"
562                         " (uplink-mirror|downlink-mirror) dst-pool"
563                         " (pool_id) (on|off)\n"
564                         "   Set uplink or downlink type mirror rule on a port.\n"
565                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
566                         " 0 on' enable mirror income traffic to pool 0.\n\n"
567
568                         "reset port (port_id) mirror-rule (rule_id)\n"
569                         "   Reset a mirror rule.\n\n"
570
571                         "set flush_rx (on|off)\n"
572                         "   Flush (default) or don't flush RX streams before"
573                         " forwarding. Mainly used with PCAP drivers.\n\n"
574
575                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
576                         "   Set the bypass mode for the lowest port on bypass enabled"
577                         " NIC.\n\n"
578
579                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
580                         "mode (normal|bypass|isolate) (port_id)\n"
581                         "   Set the event required to initiate specified bypass mode for"
582                         " the lowest port on a bypass enabled NIC where:\n"
583                         "       timeout   = enable bypass after watchdog timeout.\n"
584                         "       os_on     = enable bypass when OS/board is powered on.\n"
585                         "       os_off    = enable bypass when OS/board is powered off.\n"
586                         "       power_on  = enable bypass when power supply is turned on.\n"
587                         "       power_off = enable bypass when power supply is turned off."
588                         "\n\n"
589
590                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
591                         "   Set the bypass watchdog timeout to 'n' seconds"
592                         " where 0 = instant.\n\n"
593
594                         "show bypass config (port_id)\n"
595                         "   Show the bypass configuration for a bypass enabled NIC"
596                         " using the lowest port on the NIC.\n\n"
597
598 #ifdef RTE_LIBRTE_PMD_BOND
599                         "create bonded device (mode) (socket)\n"
600                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
601
602                         "add bonding slave (slave_id) (port_id)\n"
603                         "       Add a slave device to a bonded device.\n\n"
604
605                         "remove bonding slave (slave_id) (port_id)\n"
606                         "       Remove a slave device from a bonded device.\n\n"
607
608                         "set bonding mode (value) (port_id)\n"
609                         "       Set the bonding mode on a bonded device.\n\n"
610
611                         "set bonding primary (slave_id) (port_id)\n"
612                         "       Set the primary slave for a bonded device.\n\n"
613
614                         "show bonding config (port_id)\n"
615                         "       Show the bonding config for port_id.\n\n"
616
617                         "set bonding mac_addr (port_id) (address)\n"
618                         "       Set the MAC address of a bonded device.\n\n"
619
620                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
621                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
622
623                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
624                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
625
626                         "set bonding mon_period (port_id) (value)\n"
627                         "       Set the bonding link status monitoring polling period in ms.\n\n"
628
629                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
630                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
631
632 #endif
633                         "set link-up port (port_id)\n"
634                         "       Set link up for a port.\n\n"
635
636                         "set link-down port (port_id)\n"
637                         "       Set link down for a port.\n\n"
638
639                         "E-tag set insertion on port-tag-id (value)"
640                         " port (port_id) vf (vf_id)\n"
641                         "    Enable E-tag insertion for a VF on a port\n\n"
642
643                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
644                         "    Disable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set stripping (on|off) port (port_id)\n"
647                         "    Enable/disable E-tag stripping on a port\n\n"
648
649                         "E-tag set forwarding (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag based forwarding"
651                         " on a port\n\n"
652
653                         "E-tag set filter add e-tag-id (value) dst-pool"
654                         " (pool_id) port (port_id)\n"
655                         "    Add an E-tag forwarding filter on a port\n\n"
656
657                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
658                         "    Delete an E-tag forwarding filter on a port\n\n"
659
660                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
661                         "    Load a profile package on a port\n\n"
662
663                         "ddp del (port_id) (backup_profile_path)\n"
664                         "    Delete a profile package from a port\n\n"
665
666                         "ptype mapping get (port_id) (valid_only)\n"
667                         "    Get ptype mapping on a port\n\n"
668
669                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
670                         "    Replace target with the pkt_type in ptype mapping\n\n"
671
672                         "ptype mapping reset (port_id)\n"
673                         "    Reset ptype mapping on a port\n\n"
674
675                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
676                         "    Update a ptype mapping item on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "queue_start_index (value) queue_num (value)\n"
680                         "    Set a queue region on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "flowtype (value)\n"
684                         "    Set a flowtype region index on a port\n\n"
685
686                         "set port (port_id) queue-region UP (value) region_id (value)\n"
687                         "    Set the mapping of User Priority to "
688                         "queue region on a port\n\n"
689
690                         "set port (port_id) queue-region flush (on|off)\n"
691                         "    flush all queue region related configuration\n\n"
692
693                         "show port meter cap (port_id)\n"
694                         "    Show port meter capability information\n\n"
695
696                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
697                         "    meter profile add - srtcm rfc 2697\n\n"
698
699                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
700                         "    meter profile add - trtcm rfc 2698\n\n"
701
702                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
703                         "    meter profile add - trtcm rfc 4115\n\n"
704
705                         "del port meter profile (port_id) (profile_id)\n"
706                         "    meter profile delete\n\n"
707
708                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
709                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
711                         "(dscp_tbl_entry63)]\n"
712                         "    meter create\n\n"
713
714                         "enable port meter (port_id) (mtr_id)\n"
715                         "    meter enable\n\n"
716
717                         "disable port meter (port_id) (mtr_id)\n"
718                         "    meter disable\n\n"
719
720                         "del port meter (port_id) (mtr_id)\n"
721                         "    meter delete\n\n"
722
723                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
724                         "    meter update meter profile\n\n"
725
726                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
727                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
728                         "    update meter dscp table entries\n\n"
729
730                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
731                         "(action0) [(action1) (action2)]\n"
732                         "    meter update policer action\n\n"
733
734                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
735                         "    meter update stats\n\n"
736
737                         "show port (port_id) queue-region\n"
738                         "    show all queue region related configuration info\n\n"
739
740                         , list_pkt_forwarding_modes()
741                 );
742         }
743
744         if (show_all || !strcmp(res->section, "ports")) {
745
746                 cmdline_printf(
747                         cl,
748                         "\n"
749                         "Port Operations:\n"
750                         "----------------\n\n"
751
752                         "port start (port_id|all)\n"
753                         "    Start all ports or port_id.\n\n"
754
755                         "port stop (port_id|all)\n"
756                         "    Stop all ports or port_id.\n\n"
757
758                         "port close (port_id|all)\n"
759                         "    Close all ports or port_id.\n\n"
760
761                         "port attach (ident)\n"
762                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
763
764                         "port detach (port_id)\n"
765                         "    Detach physical or virtual dev by port_id\n\n"
766
767                         "port config (port_id|all)"
768                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
769                         " duplex (half|full|auto)\n"
770                         "    Set speed and duplex for all ports or port_id\n\n"
771
772                         "port config (port_id|all) loopback (mode)\n"
773                         "    Set loopback mode for all ports or port_id\n\n"
774
775                         "port config all (rxq|txq|rxd|txd) (value)\n"
776                         "    Set number for rxq/txq/rxd/txd.\n\n"
777
778                         "port config all max-pkt-len (value)\n"
779                         "    Set the max packet length.\n\n"
780
781                         "port config all drop-en (on|off)\n"
782                         "    Enable or disable packet drop on all RX queues of all ports when no "
783                         "receive buffers available.\n\n"
784
785                         "port config all rss (all|default|ip|tcp|udp|sctp|"
786                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
787                         "    Set the RSS mode.\n\n"
788
789                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
790                         "    Set the RSS redirection table.\n\n"
791
792                         "port config (port_id) dcb vt (on|off) (traffic_class)"
793                         " pfc (on|off)\n"
794                         "    Set the DCB mode.\n\n"
795
796                         "port config all burst (value)\n"
797                         "    Set the number of packets per burst.\n\n"
798
799                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
800                         " (value)\n"
801                         "    Set the ring prefetch/host/writeback threshold"
802                         " for tx/rx queue.\n\n"
803
804                         "port config all (txfreet|txrst|rxfreet) (value)\n"
805                         "    Set free threshold for rx/tx, or set"
806                         " tx rs bit threshold.\n\n"
807                         "port config mtu X value\n"
808                         "    Set the MTU of port X to a given value\n\n"
809
810                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
811                         "    Set a rx/tx queue's ring size configuration, the new"
812                         " value will take effect after command that (re-)start the port"
813                         " or command that setup the specific queue\n\n"
814
815                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
816                         "    Start/stop a rx/tx queue of port X. Only take effect"
817                         " when port X is started\n\n"
818
819                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
820                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
821                         " take effect when port X is stopped.\n\n"
822
823                         "port (port_id) (rxq|txq) (queue_id) setup\n"
824                         "    Setup a rx/tx queue of port X.\n\n"
825
826                         "port config (port_id|all) l2-tunnel E-tag ether-type"
827                         " (value)\n"
828                         "    Set the value of E-tag ether-type.\n\n"
829
830                         "port config (port_id|all) l2-tunnel E-tag"
831                         " (enable|disable)\n"
832                         "    Enable/disable the E-tag support.\n\n"
833
834                         "port config (port_id) pctype mapping reset\n"
835                         "    Reset flow type to pctype mapping on a port\n\n"
836
837                         "port config (port_id) pctype mapping update"
838                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
839                         "    Update a flow type to pctype mapping item on a port\n\n"
840
841                         "port config (port_id) pctype (pctype_id) hash_inset|"
842                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
843                         " (field_idx)\n"
844                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
845
846                         "port config (port_id) pctype (pctype_id) hash_inset|"
847                         "fdir_inset|fdir_flx_inset clear all"
848                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
849
850                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
851                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
852
853                         "port config <port_id> rx_offload vlan_strip|"
854                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
855                         "outer_ipv4_cksum|macsec_strip|header_split|"
856                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
857                         "scatter|timestamp|security|keep_crc on|off\n"
858                         "     Enable or disable a per port Rx offloading"
859                         " on all Rx queues of a port\n\n"
860
861                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
862                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
863                         "outer_ipv4_cksum|macsec_strip|header_split|"
864                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
865                         "scatter|timestamp|security|keep_crc on|off\n"
866                         "    Enable or disable a per queue Rx offloading"
867                         " only on a specific Rx queue\n\n"
868
869                         "port config (port_id) tx_offload vlan_insert|"
870                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
871                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
872                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
873                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
874                         "security|match_metadata on|off\n"
875                         "    Enable or disable a per port Tx offloading"
876                         " on all Tx queues of a port\n\n"
877
878                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
879                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
880                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
881                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
882                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
883                         " on|off\n"
884                         "    Enable or disable a per queue Tx offloading"
885                         " only on a specific Tx queue\n\n"
886
887                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
888                         "    Load an eBPF program as a callback"
889                         " for particular RX/TX queue\n\n"
890
891                         "bpf-unload rx|tx (port) (queue)\n"
892                         "    Unload previously loaded eBPF program"
893                         " for particular RX/TX queue\n\n"
894
895                         "port config (port_id) tx_metadata (value)\n"
896                         "    Set Tx metadata value per port. Testpmd will add this value"
897                         " to any Tx packet sent from this port\n\n"
898                 );
899         }
900
901         if (show_all || !strcmp(res->section, "registers")) {
902
903                 cmdline_printf(
904                         cl,
905                         "\n"
906                         "Registers:\n"
907                         "----------\n\n"
908
909                         "read reg (port_id) (address)\n"
910                         "    Display value of a port register.\n\n"
911
912                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
913                         "    Display a port register bit field.\n\n"
914
915                         "read regbit (port_id) (address) (bit_x)\n"
916                         "    Display a single port register bit.\n\n"
917
918                         "write reg (port_id) (address) (value)\n"
919                         "    Set value of a port register.\n\n"
920
921                         "write regfield (port_id) (address) (bit_x) (bit_y)"
922                         " (value)\n"
923                         "    Set bit field of a port register.\n\n"
924
925                         "write regbit (port_id) (address) (bit_x) (value)\n"
926                         "    Set single bit value of a port register.\n\n"
927                 );
928         }
929         if (show_all || !strcmp(res->section, "filters")) {
930
931                 cmdline_printf(
932                         cl,
933                         "\n"
934                         "filters:\n"
935                         "--------\n\n"
936
937                         "ethertype_filter (port_id) (add|del)"
938                         " (mac_addr|mac_ignr) (mac_address) ethertype"
939                         " (ether_type) (drop|fwd) queue (queue_id)\n"
940                         "    Add/Del an ethertype filter.\n\n"
941
942                         "2tuple_filter (port_id) (add|del)"
943                         " dst_port (dst_port_value) protocol (protocol_value)"
944                         " mask (mask_value) tcp_flags (tcp_flags_value)"
945                         " priority (prio_value) queue (queue_id)\n"
946                         "    Add/Del a 2tuple filter.\n\n"
947
948                         "5tuple_filter (port_id) (add|del)"
949                         " dst_ip (dst_address) src_ip (src_address)"
950                         " dst_port (dst_port_value) src_port (src_port_value)"
951                         " protocol (protocol_value)"
952                         " mask (mask_value) tcp_flags (tcp_flags_value)"
953                         " priority (prio_value) queue (queue_id)\n"
954                         "    Add/Del a 5tuple filter.\n\n"
955
956                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
957                         "    Add/Del syn filter.\n\n"
958
959                         "flex_filter (port_id) (add|del) len (len_value)"
960                         " bytes (bytes_value) mask (mask_value)"
961                         " priority (prio_value) queue (queue_id)\n"
962                         "    Add/Del a flex filter.\n\n"
963
964                         "flow_director_filter (port_id) mode IP (add|del|update)"
965                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
966                         " src (src_ip_address) dst (dst_ip_address)"
967                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
968                         " vlan (vlan_value) flexbytes (flexbytes_value)"
969                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
970                         " fd_id (fd_id_value)\n"
971                         "    Add/Del an IP type flow director filter.\n\n"
972
973                         "flow_director_filter (port_id) mode IP (add|del|update)"
974                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
975                         " src (src_ip_address) (src_port)"
976                         " dst (dst_ip_address) (dst_port)"
977                         " tos (tos_value) ttl (ttl_value)"
978                         " vlan (vlan_value) flexbytes (flexbytes_value)"
979                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
980                         " fd_id (fd_id_value)\n"
981                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
982
983                         "flow_director_filter (port_id) mode IP (add|del|update)"
984                         " flow (ipv4-sctp|ipv6-sctp)"
985                         " src (src_ip_address) (src_port)"
986                         " dst (dst_ip_address) (dst_port)"
987                         " tag (verification_tag) "
988                         " tos (tos_value) ttl (ttl_value)"
989                         " vlan (vlan_value)"
990                         " flexbytes (flexbytes_value) (drop|fwd)"
991                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
992                         "    Add/Del a SCTP type flow director filter.\n\n"
993
994                         "flow_director_filter (port_id) mode IP (add|del|update)"
995                         " flow l2_payload ether (ethertype)"
996                         " flexbytes (flexbytes_value) (drop|fwd)"
997                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
998                         "    Add/Del a l2 payload type flow director filter.\n\n"
999
1000                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1001                         " mac (mac_address) vlan (vlan_value)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1007                         " mac (mac_address) vlan (vlan_value)"
1008                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1009                         " flexbytes (flexbytes_value) (drop|fwd)"
1010                         " queue (queue_id) fd_id (fd_id_value)\n"
1011                         "    Add/Del a Tunnel flow director filter.\n\n"
1012
1013                         "flow_director_filter (port_id) mode raw (add|del|update)"
1014                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1015                         " fd_id (fd_id_value) packet (packet file name)\n"
1016                         "    Add/Del a raw type flow director filter.\n\n"
1017
1018                         "flush_flow_director (port_id)\n"
1019                         "    Flush all flow director entries of a device.\n\n"
1020
1021                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1022                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1023                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1024                         "    Set flow director IP mask.\n\n"
1025
1026                         "flow_director_mask (port_id) mode MAC-VLAN"
1027                         " vlan (vlan_value)\n"
1028                         "    Set flow director MAC-VLAN mask.\n\n"
1029
1030                         "flow_director_mask (port_id) mode Tunnel"
1031                         " vlan (vlan_value) mac (mac_value)"
1032                         " tunnel-type (tunnel_type_value)"
1033                         " tunnel-id (tunnel_id_value)\n"
1034                         "    Set flow director Tunnel mask.\n\n"
1035
1036                         "flow_director_flex_mask (port_id)"
1037                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1038                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1039                         " (mask)\n"
1040                         "    Configure mask of flex payload.\n\n"
1041
1042                         "flow_director_flex_payload (port_id)"
1043                         " (raw|l2|l3|l4) (config)\n"
1044                         "    Configure flex payload selection.\n\n"
1045
1046                         "get_sym_hash_ena_per_port (port_id)\n"
1047                         "    get symmetric hash enable configuration per port.\n\n"
1048
1049                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1050                         "    set symmetric hash enable configuration per port"
1051                         " to enable or disable.\n\n"
1052
1053                         "get_hash_global_config (port_id)\n"
1054                         "    Get the global configurations of hash filters.\n\n"
1055
1056                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1057                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1058                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1059                         " (enable|disable)\n"
1060                         "    Set the global configurations of hash filters.\n\n"
1061
1062                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1063                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1064                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1065                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1066                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1067                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1068                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1069                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1070                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1071                         "fld-8th|none) (select|add)\n"
1072                         "    Set the input set for hash.\n\n"
1073
1074                         "set_fdir_input_set (port_id) "
1075                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1076                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1078                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1079                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1080                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1081                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1082                         " (select|add)\n"
1083                         "    Set the input set for FDir.\n\n"
1084
1085                         "flow validate {port_id}"
1086                         " [group {group_id}] [priority {level}]"
1087                         " [ingress] [egress]"
1088                         " pattern {item} [/ {item} [...]] / end"
1089                         " actions {action} [/ {action} [...]] / end\n"
1090                         "    Check whether a flow rule can be created.\n\n"
1091
1092                         "flow create {port_id}"
1093                         " [group {group_id}] [priority {level}]"
1094                         " [ingress] [egress]"
1095                         " pattern {item} [/ {item} [...]] / end"
1096                         " actions {action} [/ {action} [...]] / end\n"
1097                         "    Create a flow rule.\n\n"
1098
1099                         "flow destroy {port_id} rule {rule_id} [...]\n"
1100                         "    Destroy specific flow rules.\n\n"
1101
1102                         "flow flush {port_id}\n"
1103                         "    Destroy all flow rules.\n\n"
1104
1105                         "flow query {port_id} {rule_id} {action}\n"
1106                         "    Query an existing flow rule.\n\n"
1107
1108                         "flow list {port_id} [group {group_id}] [...]\n"
1109                         "    List existing flow rules sorted by priority,"
1110                         " filtered by group identifiers.\n\n"
1111
1112                         "flow isolate {port_id} {boolean}\n"
1113                         "    Restrict ingress traffic to the defined"
1114                         " flow rules\n\n"
1115
1116                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1117                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1118                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1119                         "       Configure the VXLAN encapsulation for flows.\n\n"
1120
1121                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1122                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1123                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1124                         " eth-dst (eth-dst)\n"
1125                         "       Configure the VXLAN encapsulation for flows.\n\n"
1126
1127                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1128                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1129                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1130                         " eth-dst (eth-dst)\n"
1131                         "       Configure the VXLAN encapsulation for flows.\n\n"
1132
1133                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1134                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1135                         " (eth-dst)\n"
1136                         "       Configure the NVGRE encapsulation for flows.\n\n"
1137
1138                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1139                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1140                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1141                         "       Configure the NVGRE encapsulation for flows.\n\n"
1142
1143                         "set raw_encap {flow items}\n"
1144                         "       Configure the encapsulation with raw data.\n\n"
1145
1146                         "set raw_decap {flow items}\n"
1147                         "       Configure the decapsulation with raw data.\n\n"
1148
1149                 );
1150         }
1151
1152         if (show_all || !strcmp(res->section, "traffic_management")) {
1153                 cmdline_printf(
1154                         cl,
1155                         "\n"
1156                         "Traffic Management:\n"
1157                         "--------------\n"
1158                         "show port tm cap (port_id)\n"
1159                         "       Display the port TM capability.\n\n"
1160
1161                         "show port tm level cap (port_id) (level_id)\n"
1162                         "       Display the port TM hierarchical level capability.\n\n"
1163
1164                         "show port tm node cap (port_id) (node_id)\n"
1165                         "       Display the port TM node capability.\n\n"
1166
1167                         "show port tm node type (port_id) (node_id)\n"
1168                         "       Display the port TM node type.\n\n"
1169
1170                         "show port tm node stats (port_id) (node_id) (clear)\n"
1171                         "       Display the port TM node stats.\n\n"
1172
1173 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1174                         "set port tm hierarchy default (port_id)\n"
1175                         "       Set default traffic Management hierarchy on a port\n\n"
1176 #endif
1177
1178                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1179                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1180                         " (packet_length_adjust)\n"
1181                         "       Add port tm node private shaper profile.\n\n"
1182
1183                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1184                         "       Delete port tm node private shaper profile.\n\n"
1185
1186                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1187                         " (shaper_profile_id)\n"
1188                         "       Add/update port tm node shared shaper.\n\n"
1189
1190                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1191                         "       Delete port tm node shared shaper.\n\n"
1192
1193                         "set port tm node shaper profile (port_id) (node_id)"
1194                         " (shaper_profile_id)\n"
1195                         "       Set port tm node shaper profile.\n\n"
1196
1197                         "add port tm node wred profile (port_id) (wred_profile_id)"
1198                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1199                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1200                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1201                         "       Add port tm node wred profile.\n\n"
1202
1203                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1204                         "       Delete port tm node wred profile.\n\n"
1205
1206                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1207                         " (priority) (weight) (level_id) (shaper_profile_id)"
1208                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1209                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1210                         "       Add port tm nonleaf node.\n\n"
1211
1212                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1213                         " (priority) (weight) (level_id) (shaper_profile_id)"
1214                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1215                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1216                         "       Add port tm leaf node.\n\n"
1217
1218                         "del port tm node (port_id) (node_id)\n"
1219                         "       Delete port tm node.\n\n"
1220
1221                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1222                         " (priority) (weight)\n"
1223                         "       Set port tm node parent.\n\n"
1224
1225                         "suspend port tm node (port_id) (node_id)"
1226                         "       Suspend tm node.\n\n"
1227
1228                         "resume port tm node (port_id) (node_id)"
1229                         "       Resume tm node.\n\n"
1230
1231                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1232                         "       Commit tm hierarchy.\n\n"
1233
1234                         "set port tm mark ip_ecn (port) (green) (yellow)"
1235                         " (red)\n"
1236                         "    Enables/Disables the traffic management marking"
1237                         " for IP ECN (Explicit Congestion Notification)"
1238                         " packets on a given port\n\n"
1239
1240                         "set port tm mark ip_dscp (port) (green) (yellow)"
1241                         " (red)\n"
1242                         "    Enables/Disables the traffic management marking"
1243                         " on the port for IP dscp packets\n\n"
1244
1245                         "set port tm mark vlan_dei (port) (green) (yellow)"
1246                         " (red)\n"
1247                         "    Enables/Disables the traffic management marking"
1248                         " on the port for VLAN packets with DEI enabled\n\n"
1249                 );
1250         }
1251
1252         if (show_all || !strcmp(res->section, "devices")) {
1253                 cmdline_printf(
1254                         cl,
1255                         "\n"
1256                         "Device Operations:\n"
1257                         "--------------\n"
1258                         "device detach (identifier)\n"
1259                         "       Detach device by identifier.\n\n"
1260                 );
1261         }
1262
1263 }
1264
1265 cmdline_parse_token_string_t cmd_help_long_help =
1266         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1267
1268 cmdline_parse_token_string_t cmd_help_long_section =
1269         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1270                         "all#control#display#config#"
1271                         "ports#registers#filters#traffic_management#devices");
1272
1273 cmdline_parse_inst_t cmd_help_long = {
1274         .f = cmd_help_long_parsed,
1275         .data = NULL,
1276         .help_str = "help all|control|display|config|ports|register|"
1277                 "filters|traffic_management|devices: "
1278                 "Show help",
1279         .tokens = {
1280                 (void *)&cmd_help_long_help,
1281                 (void *)&cmd_help_long_section,
1282                 NULL,
1283         },
1284 };
1285
1286
1287 /* *** start/stop/close all ports *** */
1288 struct cmd_operate_port_result {
1289         cmdline_fixed_string_t keyword;
1290         cmdline_fixed_string_t name;
1291         cmdline_fixed_string_t value;
1292 };
1293
1294 static void cmd_operate_port_parsed(void *parsed_result,
1295                                 __attribute__((unused)) struct cmdline *cl,
1296                                 __attribute__((unused)) void *data)
1297 {
1298         struct cmd_operate_port_result *res = parsed_result;
1299
1300         if (!strcmp(res->name, "start"))
1301                 start_port(RTE_PORT_ALL);
1302         else if (!strcmp(res->name, "stop"))
1303                 stop_port(RTE_PORT_ALL);
1304         else if (!strcmp(res->name, "close"))
1305                 close_port(RTE_PORT_ALL);
1306         else if (!strcmp(res->name, "reset"))
1307                 reset_port(RTE_PORT_ALL);
1308         else
1309                 printf("Unknown parameter\n");
1310 }
1311
1312 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1313         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1314                                                                 "port");
1315 cmdline_parse_token_string_t cmd_operate_port_all_port =
1316         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1317                                                 "start#stop#close#reset");
1318 cmdline_parse_token_string_t cmd_operate_port_all_all =
1319         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1320
1321 cmdline_parse_inst_t cmd_operate_port = {
1322         .f = cmd_operate_port_parsed,
1323         .data = NULL,
1324         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1325         .tokens = {
1326                 (void *)&cmd_operate_port_all_cmd,
1327                 (void *)&cmd_operate_port_all_port,
1328                 (void *)&cmd_operate_port_all_all,
1329                 NULL,
1330         },
1331 };
1332
1333 /* *** start/stop/close specific port *** */
1334 struct cmd_operate_specific_port_result {
1335         cmdline_fixed_string_t keyword;
1336         cmdline_fixed_string_t name;
1337         uint8_t value;
1338 };
1339
1340 static void cmd_operate_specific_port_parsed(void *parsed_result,
1341                         __attribute__((unused)) struct cmdline *cl,
1342                                 __attribute__((unused)) void *data)
1343 {
1344         struct cmd_operate_specific_port_result *res = parsed_result;
1345
1346         if (!strcmp(res->name, "start"))
1347                 start_port(res->value);
1348         else if (!strcmp(res->name, "stop"))
1349                 stop_port(res->value);
1350         else if (!strcmp(res->name, "close"))
1351                 close_port(res->value);
1352         else if (!strcmp(res->name, "reset"))
1353                 reset_port(res->value);
1354         else
1355                 printf("Unknown parameter\n");
1356 }
1357
1358 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1359         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1360                                                         keyword, "port");
1361 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1362         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1363                                                 name, "start#stop#close#reset");
1364 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1365         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1366                                                         value, UINT8);
1367
1368 cmdline_parse_inst_t cmd_operate_specific_port = {
1369         .f = cmd_operate_specific_port_parsed,
1370         .data = NULL,
1371         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1372         .tokens = {
1373                 (void *)&cmd_operate_specific_port_cmd,
1374                 (void *)&cmd_operate_specific_port_port,
1375                 (void *)&cmd_operate_specific_port_id,
1376                 NULL,
1377         },
1378 };
1379
1380 /* *** enable port setup (after attach) via iterator or event *** */
1381 struct cmd_set_port_setup_on_result {
1382         cmdline_fixed_string_t set;
1383         cmdline_fixed_string_t port;
1384         cmdline_fixed_string_t setup;
1385         cmdline_fixed_string_t on;
1386         cmdline_fixed_string_t mode;
1387 };
1388
1389 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1390                                 __attribute__((unused)) struct cmdline *cl,
1391                                 __attribute__((unused)) void *data)
1392 {
1393         struct cmd_set_port_setup_on_result *res = parsed_result;
1394
1395         if (strcmp(res->mode, "event") == 0)
1396                 setup_on_probe_event = true;
1397         else if (strcmp(res->mode, "iterator") == 0)
1398                 setup_on_probe_event = false;
1399         else
1400                 printf("Unknown mode\n");
1401 }
1402
1403 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1404         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1405                         set, "set");
1406 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1407         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1408                         port, "port");
1409 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1410         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1411                         setup, "setup");
1412 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1413         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1414                         on, "on");
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         mode, "iterator#event");
1418
1419 cmdline_parse_inst_t cmd_set_port_setup_on = {
1420         .f = cmd_set_port_setup_on_parsed,
1421         .data = NULL,
1422         .help_str = "set port setup on iterator|event",
1423         .tokens = {
1424                 (void *)&cmd_set_port_setup_on_set,
1425                 (void *)&cmd_set_port_setup_on_port,
1426                 (void *)&cmd_set_port_setup_on_setup,
1427                 (void *)&cmd_set_port_setup_on_on,
1428                 (void *)&cmd_set_port_setup_on_mode,
1429                 NULL,
1430         },
1431 };
1432
1433 /* *** attach a specified port *** */
1434 struct cmd_operate_attach_port_result {
1435         cmdline_fixed_string_t port;
1436         cmdline_fixed_string_t keyword;
1437         cmdline_fixed_string_t identifier;
1438 };
1439
1440 static void cmd_operate_attach_port_parsed(void *parsed_result,
1441                                 __attribute__((unused)) struct cmdline *cl,
1442                                 __attribute__((unused)) void *data)
1443 {
1444         struct cmd_operate_attach_port_result *res = parsed_result;
1445
1446         if (!strcmp(res->keyword, "attach"))
1447                 attach_port(res->identifier);
1448         else
1449                 printf("Unknown parameter\n");
1450 }
1451
1452 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1453         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1454                         port, "port");
1455 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1456         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1457                         keyword, "attach");
1458 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1459         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1460                         identifier, NULL);
1461
1462 cmdline_parse_inst_t cmd_operate_attach_port = {
1463         .f = cmd_operate_attach_port_parsed,
1464         .data = NULL,
1465         .help_str = "port attach <identifier>: "
1466                 "(identifier: pci address or virtual dev name)",
1467         .tokens = {
1468                 (void *)&cmd_operate_attach_port_port,
1469                 (void *)&cmd_operate_attach_port_keyword,
1470                 (void *)&cmd_operate_attach_port_identifier,
1471                 NULL,
1472         },
1473 };
1474
1475 /* *** detach a specified port *** */
1476 struct cmd_operate_detach_port_result {
1477         cmdline_fixed_string_t port;
1478         cmdline_fixed_string_t keyword;
1479         portid_t port_id;
1480 };
1481
1482 static void cmd_operate_detach_port_parsed(void *parsed_result,
1483                                 __attribute__((unused)) struct cmdline *cl,
1484                                 __attribute__((unused)) void *data)
1485 {
1486         struct cmd_operate_detach_port_result *res = parsed_result;
1487
1488         if (!strcmp(res->keyword, "detach"))
1489                 detach_port_device(res->port_id);
1490         else
1491                 printf("Unknown parameter\n");
1492 }
1493
1494 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1495         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1496                         port, "port");
1497 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1498         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1499                         keyword, "detach");
1500 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1501         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1502                         port_id, UINT16);
1503
1504 cmdline_parse_inst_t cmd_operate_detach_port = {
1505         .f = cmd_operate_detach_port_parsed,
1506         .data = NULL,
1507         .help_str = "port detach <port_id>",
1508         .tokens = {
1509                 (void *)&cmd_operate_detach_port_port,
1510                 (void *)&cmd_operate_detach_port_keyword,
1511                 (void *)&cmd_operate_detach_port_port_id,
1512                 NULL,
1513         },
1514 };
1515
1516 /* *** detach device by identifier *** */
1517 struct cmd_operate_detach_device_result {
1518         cmdline_fixed_string_t device;
1519         cmdline_fixed_string_t keyword;
1520         cmdline_fixed_string_t identifier;
1521 };
1522
1523 static void cmd_operate_detach_device_parsed(void *parsed_result,
1524                                 __attribute__((unused)) struct cmdline *cl,
1525                                 __attribute__((unused)) void *data)
1526 {
1527         struct cmd_operate_detach_device_result *res = parsed_result;
1528
1529         if (!strcmp(res->keyword, "detach"))
1530                 detach_device(res->identifier);
1531         else
1532                 printf("Unknown parameter\n");
1533 }
1534
1535 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1536         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1537                         device, "device");
1538 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1539         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1540                         keyword, "detach");
1541 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1542         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1543                         identifier, NULL);
1544
1545 cmdline_parse_inst_t cmd_operate_detach_device = {
1546         .f = cmd_operate_detach_device_parsed,
1547         .data = NULL,
1548         .help_str = "device detach <identifier>:"
1549                 "(identifier: pci address or virtual dev name)",
1550         .tokens = {
1551                 (void *)&cmd_operate_detach_device_device,
1552                 (void *)&cmd_operate_detach_device_keyword,
1553                 (void *)&cmd_operate_detach_device_identifier,
1554                 NULL,
1555         },
1556 };
1557 /* *** configure speed for all ports *** */
1558 struct cmd_config_speed_all {
1559         cmdline_fixed_string_t port;
1560         cmdline_fixed_string_t keyword;
1561         cmdline_fixed_string_t all;
1562         cmdline_fixed_string_t item1;
1563         cmdline_fixed_string_t item2;
1564         cmdline_fixed_string_t value1;
1565         cmdline_fixed_string_t value2;
1566 };
1567
1568 static int
1569 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1570 {
1571
1572         int duplex;
1573
1574         if (!strcmp(duplexstr, "half")) {
1575                 duplex = ETH_LINK_HALF_DUPLEX;
1576         } else if (!strcmp(duplexstr, "full")) {
1577                 duplex = ETH_LINK_FULL_DUPLEX;
1578         } else if (!strcmp(duplexstr, "auto")) {
1579                 duplex = ETH_LINK_FULL_DUPLEX;
1580         } else {
1581                 printf("Unknown duplex parameter\n");
1582                 return -1;
1583         }
1584
1585         if (!strcmp(speedstr, "10")) {
1586                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1587                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1588         } else if (!strcmp(speedstr, "100")) {
1589                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1590                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1591         } else {
1592                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1593                         printf("Invalid speed/duplex parameters\n");
1594                         return -1;
1595                 }
1596                 if (!strcmp(speedstr, "1000")) {
1597                         *speed = ETH_LINK_SPEED_1G;
1598                 } else if (!strcmp(speedstr, "10000")) {
1599                         *speed = ETH_LINK_SPEED_10G;
1600                 } else if (!strcmp(speedstr, "25000")) {
1601                         *speed = ETH_LINK_SPEED_25G;
1602                 } else if (!strcmp(speedstr, "40000")) {
1603                         *speed = ETH_LINK_SPEED_40G;
1604                 } else if (!strcmp(speedstr, "50000")) {
1605                         *speed = ETH_LINK_SPEED_50G;
1606                 } else if (!strcmp(speedstr, "100000")) {
1607                         *speed = ETH_LINK_SPEED_100G;
1608                 } else if (!strcmp(speedstr, "auto")) {
1609                         *speed = ETH_LINK_SPEED_AUTONEG;
1610                 } else {
1611                         printf("Unknown speed parameter\n");
1612                         return -1;
1613                 }
1614         }
1615
1616         return 0;
1617 }
1618
1619 static void
1620 cmd_config_speed_all_parsed(void *parsed_result,
1621                         __attribute__((unused)) struct cmdline *cl,
1622                         __attribute__((unused)) void *data)
1623 {
1624         struct cmd_config_speed_all *res = parsed_result;
1625         uint32_t link_speed;
1626         portid_t pid;
1627
1628         if (!all_ports_stopped()) {
1629                 printf("Please stop all ports first\n");
1630                 return;
1631         }
1632
1633         if (parse_and_check_speed_duplex(res->value1, res->value2,
1634                         &link_speed) < 0)
1635                 return;
1636
1637         RTE_ETH_FOREACH_DEV(pid) {
1638                 ports[pid].dev_conf.link_speeds = link_speed;
1639         }
1640
1641         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1642 }
1643
1644 cmdline_parse_token_string_t cmd_config_speed_all_port =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1646 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1648                                                         "config");
1649 cmdline_parse_token_string_t cmd_config_speed_all_all =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1651 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1653 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1654         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1655                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1656 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1657         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1658 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1660                                                 "half#full#auto");
1661
1662 cmdline_parse_inst_t cmd_config_speed_all = {
1663         .f = cmd_config_speed_all_parsed,
1664         .data = NULL,
1665         .help_str = "port config all speed "
1666                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1667                                                         "half|full|auto",
1668         .tokens = {
1669                 (void *)&cmd_config_speed_all_port,
1670                 (void *)&cmd_config_speed_all_keyword,
1671                 (void *)&cmd_config_speed_all_all,
1672                 (void *)&cmd_config_speed_all_item1,
1673                 (void *)&cmd_config_speed_all_value1,
1674                 (void *)&cmd_config_speed_all_item2,
1675                 (void *)&cmd_config_speed_all_value2,
1676                 NULL,
1677         },
1678 };
1679
1680 /* *** configure speed for specific port *** */
1681 struct cmd_config_speed_specific {
1682         cmdline_fixed_string_t port;
1683         cmdline_fixed_string_t keyword;
1684         portid_t id;
1685         cmdline_fixed_string_t item1;
1686         cmdline_fixed_string_t item2;
1687         cmdline_fixed_string_t value1;
1688         cmdline_fixed_string_t value2;
1689 };
1690
1691 static void
1692 cmd_config_speed_specific_parsed(void *parsed_result,
1693                                 __attribute__((unused)) struct cmdline *cl,
1694                                 __attribute__((unused)) void *data)
1695 {
1696         struct cmd_config_speed_specific *res = parsed_result;
1697         uint32_t link_speed;
1698
1699         if (!all_ports_stopped()) {
1700                 printf("Please stop all ports first\n");
1701                 return;
1702         }
1703
1704         if (port_id_is_invalid(res->id, ENABLED_WARN))
1705                 return;
1706
1707         if (parse_and_check_speed_duplex(res->value1, res->value2,
1708                         &link_speed) < 0)
1709                 return;
1710
1711         ports[res->id].dev_conf.link_speeds = link_speed;
1712
1713         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1714 }
1715
1716
1717 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1719                                                                 "port");
1720 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1722                                                                 "config");
1723 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1724         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1725 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1726         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1727                                                                 "speed");
1728 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1730                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1731 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1733                                                                 "duplex");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1736                                                         "half#full#auto");
1737
1738 cmdline_parse_inst_t cmd_config_speed_specific = {
1739         .f = cmd_config_speed_specific_parsed,
1740         .data = NULL,
1741         .help_str = "port config <port_id> speed "
1742                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1743                                                         "half|full|auto",
1744         .tokens = {
1745                 (void *)&cmd_config_speed_specific_port,
1746                 (void *)&cmd_config_speed_specific_keyword,
1747                 (void *)&cmd_config_speed_specific_id,
1748                 (void *)&cmd_config_speed_specific_item1,
1749                 (void *)&cmd_config_speed_specific_value1,
1750                 (void *)&cmd_config_speed_specific_item2,
1751                 (void *)&cmd_config_speed_specific_value2,
1752                 NULL,
1753         },
1754 };
1755
1756 /* *** configure loopback for all ports *** */
1757 struct cmd_config_loopback_all {
1758         cmdline_fixed_string_t port;
1759         cmdline_fixed_string_t keyword;
1760         cmdline_fixed_string_t all;
1761         cmdline_fixed_string_t item;
1762         uint32_t mode;
1763 };
1764
1765 static void
1766 cmd_config_loopback_all_parsed(void *parsed_result,
1767                         __attribute__((unused)) struct cmdline *cl,
1768                         __attribute__((unused)) void *data)
1769 {
1770         struct cmd_config_loopback_all *res = parsed_result;
1771         portid_t pid;
1772
1773         if (!all_ports_stopped()) {
1774                 printf("Please stop all ports first\n");
1775                 return;
1776         }
1777
1778         RTE_ETH_FOREACH_DEV(pid) {
1779                 ports[pid].dev_conf.lpbk_mode = res->mode;
1780         }
1781
1782         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1783 }
1784
1785 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1786         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1787 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1789                                                         "config");
1790 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1792 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1794                                                         "loopback");
1795 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1796         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1797
1798 cmdline_parse_inst_t cmd_config_loopback_all = {
1799         .f = cmd_config_loopback_all_parsed,
1800         .data = NULL,
1801         .help_str = "port config all loopback <mode>",
1802         .tokens = {
1803                 (void *)&cmd_config_loopback_all_port,
1804                 (void *)&cmd_config_loopback_all_keyword,
1805                 (void *)&cmd_config_loopback_all_all,
1806                 (void *)&cmd_config_loopback_all_item,
1807                 (void *)&cmd_config_loopback_all_mode,
1808                 NULL,
1809         },
1810 };
1811
1812 /* *** configure loopback for specific port *** */
1813 struct cmd_config_loopback_specific {
1814         cmdline_fixed_string_t port;
1815         cmdline_fixed_string_t keyword;
1816         uint16_t port_id;
1817         cmdline_fixed_string_t item;
1818         uint32_t mode;
1819 };
1820
1821 static void
1822 cmd_config_loopback_specific_parsed(void *parsed_result,
1823                                 __attribute__((unused)) struct cmdline *cl,
1824                                 __attribute__((unused)) void *data)
1825 {
1826         struct cmd_config_loopback_specific *res = parsed_result;
1827
1828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1829                 return;
1830
1831         if (!port_is_stopped(res->port_id)) {
1832                 printf("Please stop port %u first\n", res->port_id);
1833                 return;
1834         }
1835
1836         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1837
1838         cmd_reconfig_device_queue(res->port_id, 1, 1);
1839 }
1840
1841
1842 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1843         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1844                                                                 "port");
1845 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1847                                                                 "config");
1848 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1849         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1850                                                                 UINT16);
1851 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1853                                                                 "loopback");
1854 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1855         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1856                               UINT32);
1857
1858 cmdline_parse_inst_t cmd_config_loopback_specific = {
1859         .f = cmd_config_loopback_specific_parsed,
1860         .data = NULL,
1861         .help_str = "port config <port_id> loopback <mode>",
1862         .tokens = {
1863                 (void *)&cmd_config_loopback_specific_port,
1864                 (void *)&cmd_config_loopback_specific_keyword,
1865                 (void *)&cmd_config_loopback_specific_id,
1866                 (void *)&cmd_config_loopback_specific_item,
1867                 (void *)&cmd_config_loopback_specific_mode,
1868                 NULL,
1869         },
1870 };
1871
1872 /* *** configure txq/rxq, txd/rxd *** */
1873 struct cmd_config_rx_tx {
1874         cmdline_fixed_string_t port;
1875         cmdline_fixed_string_t keyword;
1876         cmdline_fixed_string_t all;
1877         cmdline_fixed_string_t name;
1878         uint16_t value;
1879 };
1880
1881 static void
1882 cmd_config_rx_tx_parsed(void *parsed_result,
1883                         __attribute__((unused)) struct cmdline *cl,
1884                         __attribute__((unused)) void *data)
1885 {
1886         struct cmd_config_rx_tx *res = parsed_result;
1887
1888         if (!all_ports_stopped()) {
1889                 printf("Please stop all ports first\n");
1890                 return;
1891         }
1892         if (!strcmp(res->name, "rxq")) {
1893                 if (!res->value && !nb_txq) {
1894                         printf("Warning: Either rx or tx queues should be non zero\n");
1895                         return;
1896                 }
1897                 if (check_nb_rxq(res->value) != 0)
1898                         return;
1899                 nb_rxq = res->value;
1900         }
1901         else if (!strcmp(res->name, "txq")) {
1902                 if (!res->value && !nb_rxq) {
1903                         printf("Warning: Either rx or tx queues should be non zero\n");
1904                         return;
1905                 }
1906                 if (check_nb_txq(res->value) != 0)
1907                         return;
1908                 nb_txq = res->value;
1909         }
1910         else if (!strcmp(res->name, "rxd")) {
1911                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1912                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1913                                         res->value, RTE_TEST_RX_DESC_MAX);
1914                         return;
1915                 }
1916                 nb_rxd = res->value;
1917         } else if (!strcmp(res->name, "txd")) {
1918                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1919                         printf("txd %d invalid - must be > 0 && <= %d\n",
1920                                         res->value, RTE_TEST_TX_DESC_MAX);
1921                         return;
1922                 }
1923                 nb_txd = res->value;
1924         } else {
1925                 printf("Unknown parameter\n");
1926                 return;
1927         }
1928
1929         fwd_config_setup();
1930
1931         init_port_config();
1932
1933         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1934 }
1935
1936 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1938 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1940 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1941         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1942 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1943         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1944                                                 "rxq#txq#rxd#txd");
1945 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1946         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1947
1948 cmdline_parse_inst_t cmd_config_rx_tx = {
1949         .f = cmd_config_rx_tx_parsed,
1950         .data = NULL,
1951         .help_str = "port config all rxq|txq|rxd|txd <value>",
1952         .tokens = {
1953                 (void *)&cmd_config_rx_tx_port,
1954                 (void *)&cmd_config_rx_tx_keyword,
1955                 (void *)&cmd_config_rx_tx_all,
1956                 (void *)&cmd_config_rx_tx_name,
1957                 (void *)&cmd_config_rx_tx_value,
1958                 NULL,
1959         },
1960 };
1961
1962 /* *** config max packet length *** */
1963 struct cmd_config_max_pkt_len_result {
1964         cmdline_fixed_string_t port;
1965         cmdline_fixed_string_t keyword;
1966         cmdline_fixed_string_t all;
1967         cmdline_fixed_string_t name;
1968         uint32_t value;
1969 };
1970
1971 static void
1972 cmd_config_max_pkt_len_parsed(void *parsed_result,
1973                                 __attribute__((unused)) struct cmdline *cl,
1974                                 __attribute__((unused)) void *data)
1975 {
1976         struct cmd_config_max_pkt_len_result *res = parsed_result;
1977         portid_t pid;
1978
1979         if (!all_ports_stopped()) {
1980                 printf("Please stop all ports first\n");
1981                 return;
1982         }
1983
1984         RTE_ETH_FOREACH_DEV(pid) {
1985                 struct rte_port *port = &ports[pid];
1986                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1987
1988                 if (!strcmp(res->name, "max-pkt-len")) {
1989                         if (res->value < RTE_ETHER_MIN_LEN) {
1990                                 printf("max-pkt-len can not be less than %d\n",
1991                                                 RTE_ETHER_MIN_LEN);
1992                                 return;
1993                         }
1994                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1995                                 return;
1996
1997                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1998                         if (res->value > RTE_ETHER_MAX_LEN)
1999                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2000                         else
2001                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2002                         port->dev_conf.rxmode.offloads = rx_offloads;
2003                 } else {
2004                         printf("Unknown parameter\n");
2005                         return;
2006                 }
2007         }
2008
2009         init_port_config();
2010
2011         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2012 }
2013
2014 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2015         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2016                                                                 "port");
2017 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2018         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2019                                                                 "config");
2020 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2022                                                                 "all");
2023 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2024         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2025                                                                 "max-pkt-len");
2026 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2027         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2028                                                                 UINT32);
2029
2030 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2031         .f = cmd_config_max_pkt_len_parsed,
2032         .data = NULL,
2033         .help_str = "port config all max-pkt-len <value>",
2034         .tokens = {
2035                 (void *)&cmd_config_max_pkt_len_port,
2036                 (void *)&cmd_config_max_pkt_len_keyword,
2037                 (void *)&cmd_config_max_pkt_len_all,
2038                 (void *)&cmd_config_max_pkt_len_name,
2039                 (void *)&cmd_config_max_pkt_len_value,
2040                 NULL,
2041         },
2042 };
2043
2044 /* *** configure port MTU *** */
2045 struct cmd_config_mtu_result {
2046         cmdline_fixed_string_t port;
2047         cmdline_fixed_string_t keyword;
2048         cmdline_fixed_string_t mtu;
2049         portid_t port_id;
2050         uint16_t value;
2051 };
2052
2053 static void
2054 cmd_config_mtu_parsed(void *parsed_result,
2055                       __attribute__((unused)) struct cmdline *cl,
2056                       __attribute__((unused)) void *data)
2057 {
2058         struct cmd_config_mtu_result *res = parsed_result;
2059
2060         if (res->value < RTE_ETHER_MIN_LEN) {
2061                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2062                 return;
2063         }
2064         port_mtu_set(res->port_id, res->value);
2065 }
2066
2067 cmdline_parse_token_string_t cmd_config_mtu_port =
2068         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2069                                  "port");
2070 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2071         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2072                                  "config");
2073 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2074         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2075                                  "mtu");
2076 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2077         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2078 cmdline_parse_token_num_t cmd_config_mtu_value =
2079         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2080
2081 cmdline_parse_inst_t cmd_config_mtu = {
2082         .f = cmd_config_mtu_parsed,
2083         .data = NULL,
2084         .help_str = "port config mtu <port_id> <value>",
2085         .tokens = {
2086                 (void *)&cmd_config_mtu_port,
2087                 (void *)&cmd_config_mtu_keyword,
2088                 (void *)&cmd_config_mtu_mtu,
2089                 (void *)&cmd_config_mtu_port_id,
2090                 (void *)&cmd_config_mtu_value,
2091                 NULL,
2092         },
2093 };
2094
2095 /* *** configure rx mode *** */
2096 struct cmd_config_rx_mode_flag {
2097         cmdline_fixed_string_t port;
2098         cmdline_fixed_string_t keyword;
2099         cmdline_fixed_string_t all;
2100         cmdline_fixed_string_t name;
2101         cmdline_fixed_string_t value;
2102 };
2103
2104 static void
2105 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2106                                 __attribute__((unused)) struct cmdline *cl,
2107                                 __attribute__((unused)) void *data)
2108 {
2109         struct cmd_config_rx_mode_flag *res = parsed_result;
2110
2111         if (!all_ports_stopped()) {
2112                 printf("Please stop all ports first\n");
2113                 return;
2114         }
2115
2116         if (!strcmp(res->name, "drop-en")) {
2117                 if (!strcmp(res->value, "on"))
2118                         rx_drop_en = 1;
2119                 else if (!strcmp(res->value, "off"))
2120                         rx_drop_en = 0;
2121                 else {
2122                         printf("Unknown parameter\n");
2123                         return;
2124                 }
2125         } else {
2126                 printf("Unknown parameter\n");
2127                 return;
2128         }
2129
2130         init_port_config();
2131
2132         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2133 }
2134
2135 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2139                                                                 "config");
2140 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2142 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2143         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2144                                         "drop-en");
2145 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2147                                                         "on#off");
2148
2149 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2150         .f = cmd_config_rx_mode_flag_parsed,
2151         .data = NULL,
2152         .help_str = "port config all drop-en on|off",
2153         .tokens = {
2154                 (void *)&cmd_config_rx_mode_flag_port,
2155                 (void *)&cmd_config_rx_mode_flag_keyword,
2156                 (void *)&cmd_config_rx_mode_flag_all,
2157                 (void *)&cmd_config_rx_mode_flag_name,
2158                 (void *)&cmd_config_rx_mode_flag_value,
2159                 NULL,
2160         },
2161 };
2162
2163 /* *** configure rss *** */
2164 struct cmd_config_rss {
2165         cmdline_fixed_string_t port;
2166         cmdline_fixed_string_t keyword;
2167         cmdline_fixed_string_t all;
2168         cmdline_fixed_string_t name;
2169         cmdline_fixed_string_t value;
2170 };
2171
2172 static void
2173 cmd_config_rss_parsed(void *parsed_result,
2174                         __attribute__((unused)) struct cmdline *cl,
2175                         __attribute__((unused)) void *data)
2176 {
2177         struct cmd_config_rss *res = parsed_result;
2178         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2179         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2180         int use_default = 0;
2181         int all_updated = 1;
2182         int diag;
2183         uint16_t i;
2184         int ret;
2185
2186         if (!strcmp(res->value, "all"))
2187                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2188                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2189                                         ETH_RSS_L2_PAYLOAD;
2190         else if (!strcmp(res->value, "ip"))
2191                 rss_conf.rss_hf = ETH_RSS_IP;
2192         else if (!strcmp(res->value, "udp"))
2193                 rss_conf.rss_hf = ETH_RSS_UDP;
2194         else if (!strcmp(res->value, "tcp"))
2195                 rss_conf.rss_hf = ETH_RSS_TCP;
2196         else if (!strcmp(res->value, "sctp"))
2197                 rss_conf.rss_hf = ETH_RSS_SCTP;
2198         else if (!strcmp(res->value, "ether"))
2199                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2200         else if (!strcmp(res->value, "port"))
2201                 rss_conf.rss_hf = ETH_RSS_PORT;
2202         else if (!strcmp(res->value, "vxlan"))
2203                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2204         else if (!strcmp(res->value, "geneve"))
2205                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2206         else if (!strcmp(res->value, "nvgre"))
2207                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2208         else if (!strcmp(res->value, "none"))
2209                 rss_conf.rss_hf = 0;
2210         else if (!strcmp(res->value, "default"))
2211                 use_default = 1;
2212         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2213                                                 atoi(res->value) < 64)
2214                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2215         else {
2216                 printf("Unknown parameter\n");
2217                 return;
2218         }
2219         rss_conf.rss_key = NULL;
2220         /* Update global configuration for RSS types. */
2221         RTE_ETH_FOREACH_DEV(i) {
2222                 struct rte_eth_rss_conf local_rss_conf;
2223
2224                 ret = eth_dev_info_get_print_err(i, &dev_info);
2225                 if (ret != 0)
2226                         return;
2227
2228                 if (use_default)
2229                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2230
2231                 local_rss_conf = rss_conf;
2232                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2233                         dev_info.flow_type_rss_offloads;
2234                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2235                         printf("Port %u modified RSS hash function based on hardware support,"
2236                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2237                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2238                 }
2239                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2240                 if (diag < 0) {
2241                         all_updated = 0;
2242                         printf("Configuration of RSS hash at ethernet port %d "
2243                                 "failed with error (%d): %s.\n",
2244                                 i, -diag, strerror(-diag));
2245                 }
2246         }
2247         if (all_updated && !use_default)
2248                 rss_hf = rss_conf.rss_hf;
2249 }
2250
2251 cmdline_parse_token_string_t cmd_config_rss_port =
2252         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2253 cmdline_parse_token_string_t cmd_config_rss_keyword =
2254         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2255 cmdline_parse_token_string_t cmd_config_rss_all =
2256         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2257 cmdline_parse_token_string_t cmd_config_rss_name =
2258         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2259 cmdline_parse_token_string_t cmd_config_rss_value =
2260         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2261
2262 cmdline_parse_inst_t cmd_config_rss = {
2263         .f = cmd_config_rss_parsed,
2264         .data = NULL,
2265         .help_str = "port config all rss "
2266                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2267         .tokens = {
2268                 (void *)&cmd_config_rss_port,
2269                 (void *)&cmd_config_rss_keyword,
2270                 (void *)&cmd_config_rss_all,
2271                 (void *)&cmd_config_rss_name,
2272                 (void *)&cmd_config_rss_value,
2273                 NULL,
2274         },
2275 };
2276
2277 /* *** configure rss hash key *** */
2278 struct cmd_config_rss_hash_key {
2279         cmdline_fixed_string_t port;
2280         cmdline_fixed_string_t config;
2281         portid_t port_id;
2282         cmdline_fixed_string_t rss_hash_key;
2283         cmdline_fixed_string_t rss_type;
2284         cmdline_fixed_string_t key;
2285 };
2286
2287 static uint8_t
2288 hexa_digit_to_value(char hexa_digit)
2289 {
2290         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2291                 return (uint8_t) (hexa_digit - '0');
2292         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2293                 return (uint8_t) ((hexa_digit - 'a') + 10);
2294         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2295                 return (uint8_t) ((hexa_digit - 'A') + 10);
2296         /* Invalid hexa digit */
2297         return 0xFF;
2298 }
2299
2300 static uint8_t
2301 parse_and_check_key_hexa_digit(char *key, int idx)
2302 {
2303         uint8_t hexa_v;
2304
2305         hexa_v = hexa_digit_to_value(key[idx]);
2306         if (hexa_v == 0xFF)
2307                 printf("invalid key: character %c at position %d is not a "
2308                        "valid hexa digit\n", key[idx], idx);
2309         return hexa_v;
2310 }
2311
2312 static void
2313 cmd_config_rss_hash_key_parsed(void *parsed_result,
2314                                __attribute__((unused)) struct cmdline *cl,
2315                                __attribute__((unused)) void *data)
2316 {
2317         struct cmd_config_rss_hash_key *res = parsed_result;
2318         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2319         uint8_t xdgt0;
2320         uint8_t xdgt1;
2321         int i;
2322         struct rte_eth_dev_info dev_info;
2323         uint8_t hash_key_size;
2324         uint32_t key_len;
2325         int ret;
2326
2327         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2328         if (ret != 0)
2329                 return;
2330
2331         if (dev_info.hash_key_size > 0 &&
2332                         dev_info.hash_key_size <= sizeof(hash_key))
2333                 hash_key_size = dev_info.hash_key_size;
2334         else {
2335                 printf("dev_info did not provide a valid hash key size\n");
2336                 return;
2337         }
2338         /* Check the length of the RSS hash key */
2339         key_len = strlen(res->key);
2340         if (key_len != (hash_key_size * 2)) {
2341                 printf("key length: %d invalid - key must be a string of %d"
2342                            " hexa-decimal numbers\n",
2343                            (int) key_len, hash_key_size * 2);
2344                 return;
2345         }
2346         /* Translate RSS hash key into binary representation */
2347         for (i = 0; i < hash_key_size; i++) {
2348                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2349                 if (xdgt0 == 0xFF)
2350                         return;
2351                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2352                 if (xdgt1 == 0xFF)
2353                         return;
2354                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2355         }
2356         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2357                         hash_key_size);
2358 }
2359
2360 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2361         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2362 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2363         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2364                                  "config");
2365 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2366         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2367 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2368         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2369                                  rss_hash_key, "rss-hash-key");
2370 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2372                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2373                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2374                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2375                                  "ipv6-tcp-ex#ipv6-udp-ex");
2376 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2378
2379 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2380         .f = cmd_config_rss_hash_key_parsed,
2381         .data = NULL,
2382         .help_str = "port config <port_id> rss-hash-key "
2383                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2384                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2385                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2386                 "<string of hex digits (variable length, NIC dependent)>",
2387         .tokens = {
2388                 (void *)&cmd_config_rss_hash_key_port,
2389                 (void *)&cmd_config_rss_hash_key_config,
2390                 (void *)&cmd_config_rss_hash_key_port_id,
2391                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2392                 (void *)&cmd_config_rss_hash_key_rss_type,
2393                 (void *)&cmd_config_rss_hash_key_value,
2394                 NULL,
2395         },
2396 };
2397
2398 /* *** configure port rxq/txq ring size *** */
2399 struct cmd_config_rxtx_ring_size {
2400         cmdline_fixed_string_t port;
2401         cmdline_fixed_string_t config;
2402         portid_t portid;
2403         cmdline_fixed_string_t rxtxq;
2404         uint16_t qid;
2405         cmdline_fixed_string_t rsize;
2406         uint16_t size;
2407 };
2408
2409 static void
2410 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2411                                  __attribute__((unused)) struct cmdline *cl,
2412                                  __attribute__((unused)) void *data)
2413 {
2414         struct cmd_config_rxtx_ring_size *res = parsed_result;
2415         struct rte_port *port;
2416         uint8_t isrx;
2417
2418         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2419                 return;
2420
2421         if (res->portid == (portid_t)RTE_PORT_ALL) {
2422                 printf("Invalid port id\n");
2423                 return;
2424         }
2425
2426         port = &ports[res->portid];
2427
2428         if (!strcmp(res->rxtxq, "rxq"))
2429                 isrx = 1;
2430         else if (!strcmp(res->rxtxq, "txq"))
2431                 isrx = 0;
2432         else {
2433                 printf("Unknown parameter\n");
2434                 return;
2435         }
2436
2437         if (isrx && rx_queue_id_is_invalid(res->qid))
2438                 return;
2439         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2440                 return;
2441
2442         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2443                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2444                        rx_free_thresh);
2445                 return;
2446         }
2447
2448         if (isrx)
2449                 port->nb_rx_desc[res->qid] = res->size;
2450         else
2451                 port->nb_tx_desc[res->qid] = res->size;
2452
2453         cmd_reconfig_device_queue(res->portid, 0, 1);
2454 }
2455
2456 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2457         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2458                                  port, "port");
2459 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2460         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2461                                  config, "config");
2462 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2463         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2464                                  portid, UINT16);
2465 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2466         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2467                                  rxtxq, "rxq#txq");
2468 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2469         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2470                               qid, UINT16);
2471 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2472         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2473                                  rsize, "ring_size");
2474 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2475         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2476                               size, UINT16);
2477
2478 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2479         .f = cmd_config_rxtx_ring_size_parsed,
2480         .data = NULL,
2481         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2482         .tokens = {
2483                 (void *)&cmd_config_rxtx_ring_size_port,
2484                 (void *)&cmd_config_rxtx_ring_size_config,
2485                 (void *)&cmd_config_rxtx_ring_size_portid,
2486                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2487                 (void *)&cmd_config_rxtx_ring_size_qid,
2488                 (void *)&cmd_config_rxtx_ring_size_rsize,
2489                 (void *)&cmd_config_rxtx_ring_size_size,
2490                 NULL,
2491         },
2492 };
2493
2494 /* *** configure port rxq/txq start/stop *** */
2495 struct cmd_config_rxtx_queue {
2496         cmdline_fixed_string_t port;
2497         portid_t portid;
2498         cmdline_fixed_string_t rxtxq;
2499         uint16_t qid;
2500         cmdline_fixed_string_t opname;
2501 };
2502
2503 static void
2504 cmd_config_rxtx_queue_parsed(void *parsed_result,
2505                         __attribute__((unused)) struct cmdline *cl,
2506                         __attribute__((unused)) void *data)
2507 {
2508         struct cmd_config_rxtx_queue *res = parsed_result;
2509         uint8_t isrx;
2510         uint8_t isstart;
2511         int ret = 0;
2512
2513         if (test_done == 0) {
2514                 printf("Please stop forwarding first\n");
2515                 return;
2516         }
2517
2518         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2519                 return;
2520
2521         if (port_is_started(res->portid) != 1) {
2522                 printf("Please start port %u first\n", res->portid);
2523                 return;
2524         }
2525
2526         if (!strcmp(res->rxtxq, "rxq"))
2527                 isrx = 1;
2528         else if (!strcmp(res->rxtxq, "txq"))
2529                 isrx = 0;
2530         else {
2531                 printf("Unknown parameter\n");
2532                 return;
2533         }
2534
2535         if (isrx && rx_queue_id_is_invalid(res->qid))
2536                 return;
2537         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2538                 return;
2539
2540         if (!strcmp(res->opname, "start"))
2541                 isstart = 1;
2542         else if (!strcmp(res->opname, "stop"))
2543                 isstart = 0;
2544         else {
2545                 printf("Unknown parameter\n");
2546                 return;
2547         }
2548
2549         if (isstart && isrx)
2550                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2551         else if (!isstart && isrx)
2552                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2553         else if (isstart && !isrx)
2554                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2555         else
2556                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2557
2558         if (ret == -ENOTSUP)
2559                 printf("Function not supported in PMD driver\n");
2560 }
2561
2562 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2563         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2564 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2565         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2566 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2567         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2568 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2569         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2570 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2571         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2572                                                 "start#stop");
2573
2574 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2575         .f = cmd_config_rxtx_queue_parsed,
2576         .data = NULL,
2577         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2578         .tokens = {
2579                 (void *)&cmd_config_rxtx_queue_port,
2580                 (void *)&cmd_config_rxtx_queue_portid,
2581                 (void *)&cmd_config_rxtx_queue_rxtxq,
2582                 (void *)&cmd_config_rxtx_queue_qid,
2583                 (void *)&cmd_config_rxtx_queue_opname,
2584                 NULL,
2585         },
2586 };
2587
2588 /* *** configure port rxq/txq deferred start on/off *** */
2589 struct cmd_config_deferred_start_rxtx_queue {
2590         cmdline_fixed_string_t port;
2591         portid_t port_id;
2592         cmdline_fixed_string_t rxtxq;
2593         uint16_t qid;
2594         cmdline_fixed_string_t opname;
2595         cmdline_fixed_string_t state;
2596 };
2597
2598 static void
2599 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2600                         __attribute__((unused)) struct cmdline *cl,
2601                         __attribute__((unused)) void *data)
2602 {
2603         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2604         struct rte_port *port;
2605         uint8_t isrx;
2606         uint8_t ison;
2607         uint8_t needreconfig = 0;
2608
2609         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2610                 return;
2611
2612         if (port_is_started(res->port_id) != 0) {
2613                 printf("Please stop port %u first\n", res->port_id);
2614                 return;
2615         }
2616
2617         port = &ports[res->port_id];
2618
2619         isrx = !strcmp(res->rxtxq, "rxq");
2620
2621         if (isrx && rx_queue_id_is_invalid(res->qid))
2622                 return;
2623         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2624                 return;
2625
2626         ison = !strcmp(res->state, "on");
2627
2628         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2629                 port->rx_conf[res->qid].rx_deferred_start = ison;
2630                 needreconfig = 1;
2631         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2632                 port->tx_conf[res->qid].tx_deferred_start = ison;
2633                 needreconfig = 1;
2634         }
2635
2636         if (needreconfig)
2637                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2638 }
2639
2640 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2641         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2642                                                 port, "port");
2643 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2644         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2645                                                 port_id, UINT16);
2646 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2647         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2648                                                 rxtxq, "rxq#txq");
2649 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2650         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2651                                                 qid, UINT16);
2652 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2654                                                 opname, "deferred_start");
2655 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2656         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2657                                                 state, "on#off");
2658
2659 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2660         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2661         .data = NULL,
2662         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2663         .tokens = {
2664                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2665                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2666                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2667                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2668                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2669                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2670                 NULL,
2671         },
2672 };
2673
2674 /* *** configure port rxq/txq setup *** */
2675 struct cmd_setup_rxtx_queue {
2676         cmdline_fixed_string_t port;
2677         portid_t portid;
2678         cmdline_fixed_string_t rxtxq;
2679         uint16_t qid;
2680         cmdline_fixed_string_t setup;
2681 };
2682
2683 /* Common CLI fields for queue setup */
2684 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2685         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2686 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2687         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2688 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2689         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2690 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2691         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2692 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2693         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2694
2695 static void
2696 cmd_setup_rxtx_queue_parsed(
2697         void *parsed_result,
2698         __attribute__((unused)) struct cmdline *cl,
2699         __attribute__((unused)) void *data)
2700 {
2701         struct cmd_setup_rxtx_queue *res = parsed_result;
2702         struct rte_port *port;
2703         struct rte_mempool *mp;
2704         unsigned int socket_id;
2705         uint8_t isrx = 0;
2706         int ret;
2707
2708         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2709                 return;
2710
2711         if (res->portid == (portid_t)RTE_PORT_ALL) {
2712                 printf("Invalid port id\n");
2713                 return;
2714         }
2715
2716         if (!strcmp(res->rxtxq, "rxq"))
2717                 isrx = 1;
2718         else if (!strcmp(res->rxtxq, "txq"))
2719                 isrx = 0;
2720         else {
2721                 printf("Unknown parameter\n");
2722                 return;
2723         }
2724
2725         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2726                 printf("Invalid rx queue\n");
2727                 return;
2728         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2729                 printf("Invalid tx queue\n");
2730                 return;
2731         }
2732
2733         port = &ports[res->portid];
2734         if (isrx) {
2735                 socket_id = rxring_numa[res->portid];
2736                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2737                         socket_id = port->socket_id;
2738
2739                 mp = mbuf_pool_find(socket_id);
2740                 if (mp == NULL) {
2741                         printf("Failed to setup RX queue: "
2742                                 "No mempool allocation"
2743                                 " on the socket %d\n",
2744                                 rxring_numa[res->portid]);
2745                         return;
2746                 }
2747                 ret = rte_eth_rx_queue_setup(res->portid,
2748                                              res->qid,
2749                                              port->nb_rx_desc[res->qid],
2750                                              socket_id,
2751                                              &port->rx_conf[res->qid],
2752                                              mp);
2753                 if (ret)
2754                         printf("Failed to setup RX queue\n");
2755         } else {
2756                 socket_id = txring_numa[res->portid];
2757                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2758                         socket_id = port->socket_id;
2759
2760                 ret = rte_eth_tx_queue_setup(res->portid,
2761                                              res->qid,
2762                                              port->nb_tx_desc[res->qid],
2763                                              socket_id,
2764                                              &port->tx_conf[res->qid]);
2765                 if (ret)
2766                         printf("Failed to setup TX queue\n");
2767         }
2768 }
2769
2770 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2771         .f = cmd_setup_rxtx_queue_parsed,
2772         .data = NULL,
2773         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2774         .tokens = {
2775                 (void *)&cmd_setup_rxtx_queue_port,
2776                 (void *)&cmd_setup_rxtx_queue_portid,
2777                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2778                 (void *)&cmd_setup_rxtx_queue_qid,
2779                 (void *)&cmd_setup_rxtx_queue_setup,
2780                 NULL,
2781         },
2782 };
2783
2784
2785 /* *** Configure RSS RETA *** */
2786 struct cmd_config_rss_reta {
2787         cmdline_fixed_string_t port;
2788         cmdline_fixed_string_t keyword;
2789         portid_t port_id;
2790         cmdline_fixed_string_t name;
2791         cmdline_fixed_string_t list_name;
2792         cmdline_fixed_string_t list_of_items;
2793 };
2794
2795 static int
2796 parse_reta_config(const char *str,
2797                   struct rte_eth_rss_reta_entry64 *reta_conf,
2798                   uint16_t nb_entries)
2799 {
2800         int i;
2801         unsigned size;
2802         uint16_t hash_index, idx, shift;
2803         uint16_t nb_queue;
2804         char s[256];
2805         const char *p, *p0 = str;
2806         char *end;
2807         enum fieldnames {
2808                 FLD_HASH_INDEX = 0,
2809                 FLD_QUEUE,
2810                 _NUM_FLD
2811         };
2812         unsigned long int_fld[_NUM_FLD];
2813         char *str_fld[_NUM_FLD];
2814
2815         while ((p = strchr(p0,'(')) != NULL) {
2816                 ++p;
2817                 if((p0 = strchr(p,')')) == NULL)
2818                         return -1;
2819
2820                 size = p0 - p;
2821                 if(size >= sizeof(s))
2822                         return -1;
2823
2824                 snprintf(s, sizeof(s), "%.*s", size, p);
2825                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2826                         return -1;
2827                 for (i = 0; i < _NUM_FLD; i++) {
2828                         errno = 0;
2829                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2830                         if (errno != 0 || end == str_fld[i] ||
2831                                         int_fld[i] > 65535)
2832                                 return -1;
2833                 }
2834
2835                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2836                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2837
2838                 if (hash_index >= nb_entries) {
2839                         printf("Invalid RETA hash index=%d\n", hash_index);
2840                         return -1;
2841                 }
2842
2843                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2844                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2845                 reta_conf[idx].mask |= (1ULL << shift);
2846                 reta_conf[idx].reta[shift] = nb_queue;
2847         }
2848
2849         return 0;
2850 }
2851
2852 static void
2853 cmd_set_rss_reta_parsed(void *parsed_result,
2854                         __attribute__((unused)) struct cmdline *cl,
2855                         __attribute__((unused)) void *data)
2856 {
2857         int ret;
2858         struct rte_eth_dev_info dev_info;
2859         struct rte_eth_rss_reta_entry64 reta_conf[8];
2860         struct cmd_config_rss_reta *res = parsed_result;
2861
2862         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2863         if (ret != 0)
2864                 return;
2865
2866         if (dev_info.reta_size == 0) {
2867                 printf("Redirection table size is 0 which is "
2868                                         "invalid for RSS\n");
2869                 return;
2870         } else
2871                 printf("The reta size of port %d is %u\n",
2872                         res->port_id, dev_info.reta_size);
2873         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2874                 printf("Currently do not support more than %u entries of "
2875                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2876                 return;
2877         }
2878
2879         memset(reta_conf, 0, sizeof(reta_conf));
2880         if (!strcmp(res->list_name, "reta")) {
2881                 if (parse_reta_config(res->list_of_items, reta_conf,
2882                                                 dev_info.reta_size)) {
2883                         printf("Invalid RSS Redirection Table "
2884                                         "config entered\n");
2885                         return;
2886                 }
2887                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2888                                 reta_conf, dev_info.reta_size);
2889                 if (ret != 0)
2890                         printf("Bad redirection table parameter, "
2891                                         "return code = %d \n", ret);
2892         }
2893 }
2894
2895 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2896         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2897 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2898         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2899 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2900         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2901 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2903 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2904         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2905 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2906         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2907                                  NULL);
2908 cmdline_parse_inst_t cmd_config_rss_reta = {
2909         .f = cmd_set_rss_reta_parsed,
2910         .data = NULL,
2911         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2912         .tokens = {
2913                 (void *)&cmd_config_rss_reta_port,
2914                 (void *)&cmd_config_rss_reta_keyword,
2915                 (void *)&cmd_config_rss_reta_port_id,
2916                 (void *)&cmd_config_rss_reta_name,
2917                 (void *)&cmd_config_rss_reta_list_name,
2918                 (void *)&cmd_config_rss_reta_list_of_items,
2919                 NULL,
2920         },
2921 };
2922
2923 /* *** SHOW PORT RETA INFO *** */
2924 struct cmd_showport_reta {
2925         cmdline_fixed_string_t show;
2926         cmdline_fixed_string_t port;
2927         portid_t port_id;
2928         cmdline_fixed_string_t rss;
2929         cmdline_fixed_string_t reta;
2930         uint16_t size;
2931         cmdline_fixed_string_t list_of_items;
2932 };
2933
2934 static int
2935 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2936                            uint16_t nb_entries,
2937                            char *str)
2938 {
2939         uint32_t size;
2940         const char *p, *p0 = str;
2941         char s[256];
2942         char *end;
2943         char *str_fld[8];
2944         uint16_t i;
2945         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2946                         RTE_RETA_GROUP_SIZE;
2947         int ret;
2948
2949         p = strchr(p0, '(');
2950         if (p == NULL)
2951                 return -1;
2952         p++;
2953         p0 = strchr(p, ')');
2954         if (p0 == NULL)
2955                 return -1;
2956         size = p0 - p;
2957         if (size >= sizeof(s)) {
2958                 printf("The string size exceeds the internal buffer size\n");
2959                 return -1;
2960         }
2961         snprintf(s, sizeof(s), "%.*s", size, p);
2962         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2963         if (ret <= 0 || ret != num) {
2964                 printf("The bits of masks do not match the number of "
2965                                         "reta entries: %u\n", num);
2966                 return -1;
2967         }
2968         for (i = 0; i < ret; i++)
2969                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2970
2971         return 0;
2972 }
2973
2974 static void
2975 cmd_showport_reta_parsed(void *parsed_result,
2976                          __attribute__((unused)) struct cmdline *cl,
2977                          __attribute__((unused)) void *data)
2978 {
2979         struct cmd_showport_reta *res = parsed_result;
2980         struct rte_eth_rss_reta_entry64 reta_conf[8];
2981         struct rte_eth_dev_info dev_info;
2982         uint16_t max_reta_size;
2983         int ret;
2984
2985         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2986         if (ret != 0)
2987                 return;
2988
2989         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2990         if (res->size == 0 || res->size > max_reta_size) {
2991                 printf("Invalid redirection table size: %u (1-%u)\n",
2992                         res->size, max_reta_size);
2993                 return;
2994         }
2995
2996         memset(reta_conf, 0, sizeof(reta_conf));
2997         if (showport_parse_reta_config(reta_conf, res->size,
2998                                 res->list_of_items) < 0) {
2999                 printf("Invalid string: %s for reta masks\n",
3000                                         res->list_of_items);
3001                 return;
3002         }
3003         port_rss_reta_info(res->port_id, reta_conf, res->size);
3004 }
3005
3006 cmdline_parse_token_string_t cmd_showport_reta_show =
3007         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3008 cmdline_parse_token_string_t cmd_showport_reta_port =
3009         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3010 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3011         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3012 cmdline_parse_token_string_t cmd_showport_reta_rss =
3013         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3014 cmdline_parse_token_string_t cmd_showport_reta_reta =
3015         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3016 cmdline_parse_token_num_t cmd_showport_reta_size =
3017         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3018 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3019         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3020                                         list_of_items, NULL);
3021
3022 cmdline_parse_inst_t cmd_showport_reta = {
3023         .f = cmd_showport_reta_parsed,
3024         .data = NULL,
3025         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3026         .tokens = {
3027                 (void *)&cmd_showport_reta_show,
3028                 (void *)&cmd_showport_reta_port,
3029                 (void *)&cmd_showport_reta_port_id,
3030                 (void *)&cmd_showport_reta_rss,
3031                 (void *)&cmd_showport_reta_reta,
3032                 (void *)&cmd_showport_reta_size,
3033                 (void *)&cmd_showport_reta_list_of_items,
3034                 NULL,
3035         },
3036 };
3037
3038 /* *** Show RSS hash configuration *** */
3039 struct cmd_showport_rss_hash {
3040         cmdline_fixed_string_t show;
3041         cmdline_fixed_string_t port;
3042         portid_t port_id;
3043         cmdline_fixed_string_t rss_hash;
3044         cmdline_fixed_string_t rss_type;
3045         cmdline_fixed_string_t key; /* optional argument */
3046 };
3047
3048 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3049                                 __attribute__((unused)) struct cmdline *cl,
3050                                 void *show_rss_key)
3051 {
3052         struct cmd_showport_rss_hash *res = parsed_result;
3053
3054         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3055 }
3056
3057 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3058         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3059 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3060         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3061 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3062         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3063 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3064         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3065                                  "rss-hash");
3066 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3067         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3068
3069 cmdline_parse_inst_t cmd_showport_rss_hash = {
3070         .f = cmd_showport_rss_hash_parsed,
3071         .data = NULL,
3072         .help_str = "show port <port_id> rss-hash",
3073         .tokens = {
3074                 (void *)&cmd_showport_rss_hash_show,
3075                 (void *)&cmd_showport_rss_hash_port,
3076                 (void *)&cmd_showport_rss_hash_port_id,
3077                 (void *)&cmd_showport_rss_hash_rss_hash,
3078                 NULL,
3079         },
3080 };
3081
3082 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3083         .f = cmd_showport_rss_hash_parsed,
3084         .data = (void *)1,
3085         .help_str = "show port <port_id> rss-hash key",
3086         .tokens = {
3087                 (void *)&cmd_showport_rss_hash_show,
3088                 (void *)&cmd_showport_rss_hash_port,
3089                 (void *)&cmd_showport_rss_hash_port_id,
3090                 (void *)&cmd_showport_rss_hash_rss_hash,
3091                 (void *)&cmd_showport_rss_hash_rss_key,
3092                 NULL,
3093         },
3094 };
3095
3096 /* *** Configure DCB *** */
3097 struct cmd_config_dcb {
3098         cmdline_fixed_string_t port;
3099         cmdline_fixed_string_t config;
3100         portid_t port_id;
3101         cmdline_fixed_string_t dcb;
3102         cmdline_fixed_string_t vt;
3103         cmdline_fixed_string_t vt_en;
3104         uint8_t num_tcs;
3105         cmdline_fixed_string_t pfc;
3106         cmdline_fixed_string_t pfc_en;
3107 };
3108
3109 static void
3110 cmd_config_dcb_parsed(void *parsed_result,
3111                         __attribute__((unused)) struct cmdline *cl,
3112                         __attribute__((unused)) void *data)
3113 {
3114         struct cmd_config_dcb *res = parsed_result;
3115         portid_t port_id = res->port_id;
3116         struct rte_port *port;
3117         uint8_t pfc_en;
3118         int ret;
3119
3120         port = &ports[port_id];
3121         /** Check if the port is not started **/
3122         if (port->port_status != RTE_PORT_STOPPED) {
3123                 printf("Please stop port %d first\n", port_id);
3124                 return;
3125         }
3126
3127         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3128                 printf("The invalid number of traffic class,"
3129                         " only 4 or 8 allowed.\n");
3130                 return;
3131         }
3132
3133         if (nb_fwd_lcores < res->num_tcs) {
3134                 printf("nb_cores shouldn't be less than number of TCs.\n");
3135                 return;
3136         }
3137         if (!strncmp(res->pfc_en, "on", 2))
3138                 pfc_en = 1;
3139         else
3140                 pfc_en = 0;
3141
3142         /* DCB in VT mode */
3143         if (!strncmp(res->vt_en, "on", 2))
3144                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3145                                 (enum rte_eth_nb_tcs)res->num_tcs,
3146                                 pfc_en);
3147         else
3148                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3149                                 (enum rte_eth_nb_tcs)res->num_tcs,
3150                                 pfc_en);
3151
3152
3153         if (ret != 0) {
3154                 printf("Cannot initialize network ports.\n");
3155                 return;
3156         }
3157
3158         cmd_reconfig_device_queue(port_id, 1, 1);
3159 }
3160
3161 cmdline_parse_token_string_t cmd_config_dcb_port =
3162         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3163 cmdline_parse_token_string_t cmd_config_dcb_config =
3164         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3165 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3166         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3167 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3168         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3169 cmdline_parse_token_string_t cmd_config_dcb_vt =
3170         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3171 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3172         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3173 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3174         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3175 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3176         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3177 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3178         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3179
3180 cmdline_parse_inst_t cmd_config_dcb = {
3181         .f = cmd_config_dcb_parsed,
3182         .data = NULL,
3183         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3184         .tokens = {
3185                 (void *)&cmd_config_dcb_port,
3186                 (void *)&cmd_config_dcb_config,
3187                 (void *)&cmd_config_dcb_port_id,
3188                 (void *)&cmd_config_dcb_dcb,
3189                 (void *)&cmd_config_dcb_vt,
3190                 (void *)&cmd_config_dcb_vt_en,
3191                 (void *)&cmd_config_dcb_num_tcs,
3192                 (void *)&cmd_config_dcb_pfc,
3193                 (void *)&cmd_config_dcb_pfc_en,
3194                 NULL,
3195         },
3196 };
3197
3198 /* *** configure number of packets per burst *** */
3199 struct cmd_config_burst {
3200         cmdline_fixed_string_t port;
3201         cmdline_fixed_string_t keyword;
3202         cmdline_fixed_string_t all;
3203         cmdline_fixed_string_t name;
3204         uint16_t value;
3205 };
3206
3207 static void
3208 cmd_config_burst_parsed(void *parsed_result,
3209                         __attribute__((unused)) struct cmdline *cl,
3210                         __attribute__((unused)) void *data)
3211 {
3212         struct cmd_config_burst *res = parsed_result;
3213         struct rte_eth_dev_info dev_info;
3214         uint16_t rec_nb_pkts;
3215         int ret;
3216
3217         if (!all_ports_stopped()) {
3218                 printf("Please stop all ports first\n");
3219                 return;
3220         }
3221
3222         if (!strcmp(res->name, "burst")) {
3223                 if (res->value == 0) {
3224                         /* If user gives a value of zero, query the PMD for
3225                          * its recommended Rx burst size. Testpmd uses a single
3226                          * size for all ports, so assume all ports are the same
3227                          * NIC model and use the values from Port 0.
3228                          */
3229                         ret = eth_dev_info_get_print_err(0, &dev_info);
3230                         if (ret != 0)
3231                                 return;
3232
3233                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3234
3235                         if (rec_nb_pkts == 0) {
3236                                 printf("PMD does not recommend a burst size.\n"
3237                                         "User provided value must be between"
3238                                         " 1 and %d\n", MAX_PKT_BURST);
3239                                 return;
3240                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3241                                 printf("PMD recommended burst size of %d"
3242                                         " exceeds maximum value of %d\n",
3243                                         rec_nb_pkts, MAX_PKT_BURST);
3244                                 return;
3245                         }
3246                         printf("Using PMD-provided burst value of %d\n",
3247                                 rec_nb_pkts);
3248                         nb_pkt_per_burst = rec_nb_pkts;
3249                 } else if (res->value > MAX_PKT_BURST) {
3250                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3251                         return;
3252                 } else
3253                         nb_pkt_per_burst = res->value;
3254         } else {
3255                 printf("Unknown parameter\n");
3256                 return;
3257         }
3258
3259         init_port_config();
3260
3261         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3262 }
3263
3264 cmdline_parse_token_string_t cmd_config_burst_port =
3265         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3266 cmdline_parse_token_string_t cmd_config_burst_keyword =
3267         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3268 cmdline_parse_token_string_t cmd_config_burst_all =
3269         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3270 cmdline_parse_token_string_t cmd_config_burst_name =
3271         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3272 cmdline_parse_token_num_t cmd_config_burst_value =
3273         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3274
3275 cmdline_parse_inst_t cmd_config_burst = {
3276         .f = cmd_config_burst_parsed,
3277         .data = NULL,
3278         .help_str = "port config all burst <value>",
3279         .tokens = {
3280                 (void *)&cmd_config_burst_port,
3281                 (void *)&cmd_config_burst_keyword,
3282                 (void *)&cmd_config_burst_all,
3283                 (void *)&cmd_config_burst_name,
3284                 (void *)&cmd_config_burst_value,
3285                 NULL,
3286         },
3287 };
3288
3289 /* *** configure rx/tx queues *** */
3290 struct cmd_config_thresh {
3291         cmdline_fixed_string_t port;
3292         cmdline_fixed_string_t keyword;
3293         cmdline_fixed_string_t all;
3294         cmdline_fixed_string_t name;
3295         uint8_t value;
3296 };
3297
3298 static void
3299 cmd_config_thresh_parsed(void *parsed_result,
3300                         __attribute__((unused)) struct cmdline *cl,
3301                         __attribute__((unused)) void *data)
3302 {
3303         struct cmd_config_thresh *res = parsed_result;
3304
3305         if (!all_ports_stopped()) {
3306                 printf("Please stop all ports first\n");
3307                 return;
3308         }
3309
3310         if (!strcmp(res->name, "txpt"))
3311                 tx_pthresh = res->value;
3312         else if(!strcmp(res->name, "txht"))
3313                 tx_hthresh = res->value;
3314         else if(!strcmp(res->name, "txwt"))
3315                 tx_wthresh = res->value;
3316         else if(!strcmp(res->name, "rxpt"))
3317                 rx_pthresh = res->value;
3318         else if(!strcmp(res->name, "rxht"))
3319                 rx_hthresh = res->value;
3320         else if(!strcmp(res->name, "rxwt"))
3321                 rx_wthresh = res->value;
3322         else {
3323                 printf("Unknown parameter\n");
3324                 return;
3325         }
3326
3327         init_port_config();
3328
3329         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3330 }
3331
3332 cmdline_parse_token_string_t cmd_config_thresh_port =
3333         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3334 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3335         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3336 cmdline_parse_token_string_t cmd_config_thresh_all =
3337         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3338 cmdline_parse_token_string_t cmd_config_thresh_name =
3339         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3340                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3341 cmdline_parse_token_num_t cmd_config_thresh_value =
3342         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3343
3344 cmdline_parse_inst_t cmd_config_thresh = {
3345         .f = cmd_config_thresh_parsed,
3346         .data = NULL,
3347         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3348         .tokens = {
3349                 (void *)&cmd_config_thresh_port,
3350                 (void *)&cmd_config_thresh_keyword,
3351                 (void *)&cmd_config_thresh_all,
3352                 (void *)&cmd_config_thresh_name,
3353                 (void *)&cmd_config_thresh_value,
3354                 NULL,
3355         },
3356 };
3357
3358 /* *** configure free/rs threshold *** */
3359 struct cmd_config_threshold {
3360         cmdline_fixed_string_t port;
3361         cmdline_fixed_string_t keyword;
3362         cmdline_fixed_string_t all;
3363         cmdline_fixed_string_t name;
3364         uint16_t value;
3365 };
3366
3367 static void
3368 cmd_config_threshold_parsed(void *parsed_result,
3369                         __attribute__((unused)) struct cmdline *cl,
3370                         __attribute__((unused)) void *data)
3371 {
3372         struct cmd_config_threshold *res = parsed_result;
3373
3374         if (!all_ports_stopped()) {
3375                 printf("Please stop all ports first\n");
3376                 return;
3377         }
3378
3379         if (!strcmp(res->name, "txfreet"))
3380                 tx_free_thresh = res->value;
3381         else if (!strcmp(res->name, "txrst"))
3382                 tx_rs_thresh = res->value;
3383         else if (!strcmp(res->name, "rxfreet"))
3384                 rx_free_thresh = res->value;
3385         else {
3386                 printf("Unknown parameter\n");
3387                 return;
3388         }
3389
3390         init_port_config();
3391
3392         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3393 }
3394
3395 cmdline_parse_token_string_t cmd_config_threshold_port =
3396         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3397 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3398         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3399                                                                 "config");
3400 cmdline_parse_token_string_t cmd_config_threshold_all =
3401         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3402 cmdline_parse_token_string_t cmd_config_threshold_name =
3403         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3404                                                 "txfreet#txrst#rxfreet");
3405 cmdline_parse_token_num_t cmd_config_threshold_value =
3406         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3407
3408 cmdline_parse_inst_t cmd_config_threshold = {
3409         .f = cmd_config_threshold_parsed,
3410         .data = NULL,
3411         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3412         .tokens = {
3413                 (void *)&cmd_config_threshold_port,
3414                 (void *)&cmd_config_threshold_keyword,
3415                 (void *)&cmd_config_threshold_all,
3416                 (void *)&cmd_config_threshold_name,
3417                 (void *)&cmd_config_threshold_value,
3418                 NULL,
3419         },
3420 };
3421
3422 /* *** stop *** */
3423 struct cmd_stop_result {
3424         cmdline_fixed_string_t stop;
3425 };
3426
3427 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3428                             __attribute__((unused)) struct cmdline *cl,
3429                             __attribute__((unused)) void *data)
3430 {
3431         stop_packet_forwarding();
3432 }
3433
3434 cmdline_parse_token_string_t cmd_stop_stop =
3435         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3436
3437 cmdline_parse_inst_t cmd_stop = {
3438         .f = cmd_stop_parsed,
3439         .data = NULL,
3440         .help_str = "stop: Stop packet forwarding",
3441         .tokens = {
3442                 (void *)&cmd_stop_stop,
3443                 NULL,
3444         },
3445 };
3446
3447 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3448
3449 unsigned int
3450 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3451                 unsigned int *parsed_items, int check_unique_values)
3452 {
3453         unsigned int nb_item;
3454         unsigned int value;
3455         unsigned int i;
3456         unsigned int j;
3457         int value_ok;
3458         char c;
3459
3460         /*
3461          * First parse all items in the list and store their value.
3462          */
3463         value = 0;
3464         nb_item = 0;
3465         value_ok = 0;
3466         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3467                 c = str[i];
3468                 if ((c >= '0') && (c <= '9')) {
3469                         value = (unsigned int) (value * 10 + (c - '0'));
3470                         value_ok = 1;
3471                         continue;
3472                 }
3473                 if (c != ',') {
3474                         printf("character %c is not a decimal digit\n", c);
3475                         return 0;
3476                 }
3477                 if (! value_ok) {
3478                         printf("No valid value before comma\n");
3479                         return 0;
3480                 }
3481                 if (nb_item < max_items) {
3482                         parsed_items[nb_item] = value;
3483                         value_ok = 0;
3484                         value = 0;
3485                 }
3486                 nb_item++;
3487         }
3488         if (nb_item >= max_items) {
3489                 printf("Number of %s = %u > %u (maximum items)\n",
3490                        item_name, nb_item + 1, max_items);
3491                 return 0;
3492         }
3493         parsed_items[nb_item++] = value;
3494         if (! check_unique_values)
3495                 return nb_item;
3496
3497         /*
3498          * Then, check that all values in the list are differents.
3499          * No optimization here...
3500          */
3501         for (i = 0; i < nb_item; i++) {
3502                 for (j = i + 1; j < nb_item; j++) {
3503                         if (parsed_items[j] == parsed_items[i]) {
3504                                 printf("duplicated %s %u at index %u and %u\n",
3505                                        item_name, parsed_items[i], i, j);
3506                                 return 0;
3507                         }
3508                 }
3509         }
3510         return nb_item;
3511 }
3512
3513 struct cmd_set_list_result {
3514         cmdline_fixed_string_t cmd_keyword;
3515         cmdline_fixed_string_t list_name;
3516         cmdline_fixed_string_t list_of_items;
3517 };
3518
3519 static void cmd_set_list_parsed(void *parsed_result,
3520                                 __attribute__((unused)) struct cmdline *cl,
3521                                 __attribute__((unused)) void *data)
3522 {
3523         struct cmd_set_list_result *res;
3524         union {
3525                 unsigned int lcorelist[RTE_MAX_LCORE];
3526                 unsigned int portlist[RTE_MAX_ETHPORTS];
3527         } parsed_items;
3528         unsigned int nb_item;
3529
3530         if (test_done == 0) {
3531                 printf("Please stop forwarding first\n");
3532                 return;
3533         }
3534
3535         res = parsed_result;
3536         if (!strcmp(res->list_name, "corelist")) {
3537                 nb_item = parse_item_list(res->list_of_items, "core",
3538                                           RTE_MAX_LCORE,
3539                                           parsed_items.lcorelist, 1);
3540                 if (nb_item > 0) {
3541                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3542                         fwd_config_setup();
3543                 }
3544                 return;
3545         }
3546         if (!strcmp(res->list_name, "portlist")) {
3547                 nb_item = parse_item_list(res->list_of_items, "port",
3548                                           RTE_MAX_ETHPORTS,
3549                                           parsed_items.portlist, 1);
3550                 if (nb_item > 0) {
3551                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3552                         fwd_config_setup();
3553                 }
3554         }
3555 }
3556
3557 cmdline_parse_token_string_t cmd_set_list_keyword =
3558         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3559                                  "set");
3560 cmdline_parse_token_string_t cmd_set_list_name =
3561         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3562                                  "corelist#portlist");
3563 cmdline_parse_token_string_t cmd_set_list_of_items =
3564         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3565                                  NULL);
3566
3567 cmdline_parse_inst_t cmd_set_fwd_list = {
3568         .f = cmd_set_list_parsed,
3569         .data = NULL,
3570         .help_str = "set corelist|portlist <list0[,list1]*>",
3571         .tokens = {
3572                 (void *)&cmd_set_list_keyword,
3573                 (void *)&cmd_set_list_name,
3574                 (void *)&cmd_set_list_of_items,
3575                 NULL,
3576         },
3577 };
3578
3579 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3580
3581 struct cmd_setmask_result {
3582         cmdline_fixed_string_t set;
3583         cmdline_fixed_string_t mask;
3584         uint64_t hexavalue;
3585 };
3586
3587 static void cmd_set_mask_parsed(void *parsed_result,
3588                                 __attribute__((unused)) struct cmdline *cl,
3589                                 __attribute__((unused)) void *data)
3590 {
3591         struct cmd_setmask_result *res = parsed_result;
3592
3593         if (test_done == 0) {
3594                 printf("Please stop forwarding first\n");
3595                 return;
3596         }
3597         if (!strcmp(res->mask, "coremask")) {
3598                 set_fwd_lcores_mask(res->hexavalue);
3599                 fwd_config_setup();
3600         } else if (!strcmp(res->mask, "portmask")) {
3601                 set_fwd_ports_mask(res->hexavalue);
3602                 fwd_config_setup();
3603         }
3604 }
3605
3606 cmdline_parse_token_string_t cmd_setmask_set =
3607         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3608 cmdline_parse_token_string_t cmd_setmask_mask =
3609         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3610                                  "coremask#portmask");
3611 cmdline_parse_token_num_t cmd_setmask_value =
3612         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3613
3614 cmdline_parse_inst_t cmd_set_fwd_mask = {
3615         .f = cmd_set_mask_parsed,
3616         .data = NULL,
3617         .help_str = "set coremask|portmask <hexadecimal value>",
3618         .tokens = {
3619                 (void *)&cmd_setmask_set,
3620                 (void *)&cmd_setmask_mask,
3621                 (void *)&cmd_setmask_value,
3622                 NULL,
3623         },
3624 };
3625
3626 /*
3627  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3628  */
3629 struct cmd_set_result {
3630         cmdline_fixed_string_t set;
3631         cmdline_fixed_string_t what;
3632         uint16_t value;
3633 };
3634
3635 static void cmd_set_parsed(void *parsed_result,
3636                            __attribute__((unused)) struct cmdline *cl,
3637                            __attribute__((unused)) void *data)
3638 {
3639         struct cmd_set_result *res = parsed_result;
3640         if (!strcmp(res->what, "nbport")) {
3641                 set_fwd_ports_number(res->value);
3642                 fwd_config_setup();
3643         } else if (!strcmp(res->what, "nbcore")) {
3644                 set_fwd_lcores_number(res->value);
3645                 fwd_config_setup();
3646         } else if (!strcmp(res->what, "burst"))
3647                 set_nb_pkt_per_burst(res->value);
3648         else if (!strcmp(res->what, "verbose"))
3649                 set_verbose_level(res->value);
3650 }
3651
3652 cmdline_parse_token_string_t cmd_set_set =
3653         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3654 cmdline_parse_token_string_t cmd_set_what =
3655         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3656                                  "nbport#nbcore#burst#verbose");
3657 cmdline_parse_token_num_t cmd_set_value =
3658         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3659
3660 cmdline_parse_inst_t cmd_set_numbers = {
3661         .f = cmd_set_parsed,
3662         .data = NULL,
3663         .help_str = "set nbport|nbcore|burst|verbose <value>",
3664         .tokens = {
3665                 (void *)&cmd_set_set,
3666                 (void *)&cmd_set_what,
3667                 (void *)&cmd_set_value,
3668                 NULL,
3669         },
3670 };
3671
3672 /* *** SET LOG LEVEL CONFIGURATION *** */
3673
3674 struct cmd_set_log_result {
3675         cmdline_fixed_string_t set;
3676         cmdline_fixed_string_t log;
3677         cmdline_fixed_string_t type;
3678         uint32_t level;
3679 };
3680
3681 static void
3682 cmd_set_log_parsed(void *parsed_result,
3683                    __attribute__((unused)) struct cmdline *cl,
3684                    __attribute__((unused)) void *data)
3685 {
3686         struct cmd_set_log_result *res;
3687         int ret;
3688
3689         res = parsed_result;
3690         if (!strcmp(res->type, "global"))
3691                 rte_log_set_global_level(res->level);
3692         else {
3693                 ret = rte_log_set_level_regexp(res->type, res->level);
3694                 if (ret < 0)
3695                         printf("Unable to set log level\n");
3696         }
3697 }
3698
3699 cmdline_parse_token_string_t cmd_set_log_set =
3700         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3701 cmdline_parse_token_string_t cmd_set_log_log =
3702         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3703 cmdline_parse_token_string_t cmd_set_log_type =
3704         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3705 cmdline_parse_token_num_t cmd_set_log_level =
3706         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3707
3708 cmdline_parse_inst_t cmd_set_log = {
3709         .f = cmd_set_log_parsed,
3710         .data = NULL,
3711         .help_str = "set log global|<type> <level>",
3712         .tokens = {
3713                 (void *)&cmd_set_log_set,
3714                 (void *)&cmd_set_log_log,
3715                 (void *)&cmd_set_log_type,
3716                 (void *)&cmd_set_log_level,
3717                 NULL,
3718         },
3719 };
3720
3721 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3722
3723 struct cmd_set_txpkts_result {
3724         cmdline_fixed_string_t cmd_keyword;
3725         cmdline_fixed_string_t txpkts;
3726         cmdline_fixed_string_t seg_lengths;
3727 };
3728
3729 static void
3730 cmd_set_txpkts_parsed(void *parsed_result,
3731                       __attribute__((unused)) struct cmdline *cl,
3732                       __attribute__((unused)) void *data)
3733 {
3734         struct cmd_set_txpkts_result *res;
3735         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3736         unsigned int nb_segs;
3737
3738         res = parsed_result;
3739         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3740                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3741         if (nb_segs > 0)
3742                 set_tx_pkt_segments(seg_lengths, nb_segs);
3743 }
3744
3745 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3746         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3747                                  cmd_keyword, "set");
3748 cmdline_parse_token_string_t cmd_set_txpkts_name =
3749         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3750                                  txpkts, "txpkts");
3751 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3752         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3753                                  seg_lengths, NULL);
3754
3755 cmdline_parse_inst_t cmd_set_txpkts = {
3756         .f = cmd_set_txpkts_parsed,
3757         .data = NULL,
3758         .help_str = "set txpkts <len0[,len1]*>",
3759         .tokens = {
3760                 (void *)&cmd_set_txpkts_keyword,
3761                 (void *)&cmd_set_txpkts_name,
3762                 (void *)&cmd_set_txpkts_lengths,
3763                 NULL,
3764         },
3765 };
3766
3767 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3768
3769 struct cmd_set_txsplit_result {
3770         cmdline_fixed_string_t cmd_keyword;
3771         cmdline_fixed_string_t txsplit;
3772         cmdline_fixed_string_t mode;
3773 };
3774
3775 static void
3776 cmd_set_txsplit_parsed(void *parsed_result,
3777                       __attribute__((unused)) struct cmdline *cl,
3778                       __attribute__((unused)) void *data)
3779 {
3780         struct cmd_set_txsplit_result *res;
3781
3782         res = parsed_result;
3783         set_tx_pkt_split(res->mode);
3784 }
3785
3786 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3787         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3788                                  cmd_keyword, "set");
3789 cmdline_parse_token_string_t cmd_set_txsplit_name =
3790         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3791                                  txsplit, "txsplit");
3792 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3793         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3794                                  mode, NULL);
3795
3796 cmdline_parse_inst_t cmd_set_txsplit = {
3797         .f = cmd_set_txsplit_parsed,
3798         .data = NULL,
3799         .help_str = "set txsplit on|off|rand",
3800         .tokens = {
3801                 (void *)&cmd_set_txsplit_keyword,
3802                 (void *)&cmd_set_txsplit_name,
3803                 (void *)&cmd_set_txsplit_mode,
3804                 NULL,
3805         },
3806 };
3807
3808 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3809 struct cmd_rx_vlan_filter_all_result {
3810         cmdline_fixed_string_t rx_vlan;
3811         cmdline_fixed_string_t what;
3812         cmdline_fixed_string_t all;
3813         portid_t port_id;
3814 };
3815
3816 static void
3817 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3818                               __attribute__((unused)) struct cmdline *cl,
3819                               __attribute__((unused)) void *data)
3820 {
3821         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3822
3823         if (!strcmp(res->what, "add"))
3824                 rx_vlan_all_filter_set(res->port_id, 1);
3825         else
3826                 rx_vlan_all_filter_set(res->port_id, 0);
3827 }
3828
3829 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3830         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3831                                  rx_vlan, "rx_vlan");
3832 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3833         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3834                                  what, "add#rm");
3835 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3836         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3837                                  all, "all");
3838 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3839         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3840                               port_id, UINT16);
3841
3842 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3843         .f = cmd_rx_vlan_filter_all_parsed,
3844         .data = NULL,
3845         .help_str = "rx_vlan add|rm all <port_id>: "
3846                 "Add/Remove all identifiers to/from the set of VLAN "
3847                 "identifiers filtered by a port",
3848         .tokens = {
3849                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3850                 (void *)&cmd_rx_vlan_filter_all_what,
3851                 (void *)&cmd_rx_vlan_filter_all_all,
3852                 (void *)&cmd_rx_vlan_filter_all_portid,
3853                 NULL,
3854         },
3855 };
3856
3857 /* *** VLAN OFFLOAD SET ON A PORT *** */
3858 struct cmd_vlan_offload_result {
3859         cmdline_fixed_string_t vlan;
3860         cmdline_fixed_string_t set;
3861         cmdline_fixed_string_t vlan_type;
3862         cmdline_fixed_string_t what;
3863         cmdline_fixed_string_t on;
3864         cmdline_fixed_string_t port_id;
3865 };
3866
3867 static void
3868 cmd_vlan_offload_parsed(void *parsed_result,
3869                           __attribute__((unused)) struct cmdline *cl,
3870                           __attribute__((unused)) void *data)
3871 {
3872         int on;
3873         struct cmd_vlan_offload_result *res = parsed_result;
3874         char *str;
3875         int i, len = 0;
3876         portid_t port_id = 0;
3877         unsigned int tmp;
3878
3879         str = res->port_id;
3880         len = strnlen(str, STR_TOKEN_SIZE);
3881         i = 0;
3882         /* Get port_id first */
3883         while(i < len){
3884                 if(str[i] == ',')
3885                         break;
3886
3887                 i++;
3888         }
3889         str[i]='\0';
3890         tmp = strtoul(str, NULL, 0);
3891         /* If port_id greater that what portid_t can represent, return */
3892         if(tmp >= RTE_MAX_ETHPORTS)
3893                 return;
3894         port_id = (portid_t)tmp;
3895
3896         if (!strcmp(res->on, "on"))
3897                 on = 1;
3898         else
3899                 on = 0;
3900
3901         if (!strcmp(res->what, "strip"))
3902                 rx_vlan_strip_set(port_id,  on);
3903         else if(!strcmp(res->what, "stripq")){
3904                 uint16_t queue_id = 0;
3905
3906                 /* No queue_id, return */
3907                 if(i + 1 >= len) {
3908                         printf("must specify (port,queue_id)\n");
3909                         return;
3910                 }
3911                 tmp = strtoul(str + i + 1, NULL, 0);
3912                 /* If queue_id greater that what 16-bits can represent, return */
3913                 if(tmp > 0xffff)
3914                         return;
3915
3916                 queue_id = (uint16_t)tmp;
3917                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3918         }
3919         else if (!strcmp(res->what, "filter"))
3920                 rx_vlan_filter_set(port_id, on);
3921         else
3922                 vlan_extend_set(port_id, on);
3923
3924         return;
3925 }
3926
3927 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3928         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3929                                  vlan, "vlan");
3930 cmdline_parse_token_string_t cmd_vlan_offload_set =
3931         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3932                                  set, "set");
3933 cmdline_parse_token_string_t cmd_vlan_offload_what =
3934         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3935                                  what, "strip#filter#qinq#stripq");
3936 cmdline_parse_token_string_t cmd_vlan_offload_on =
3937         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3938                               on, "on#off");
3939 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3940         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3941                               port_id, NULL);
3942
3943 cmdline_parse_inst_t cmd_vlan_offload = {
3944         .f = cmd_vlan_offload_parsed,
3945         .data = NULL,
3946         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3947                 "<port_id[,queue_id]>: "
3948                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3949         .tokens = {
3950                 (void *)&cmd_vlan_offload_vlan,
3951                 (void *)&cmd_vlan_offload_set,
3952                 (void *)&cmd_vlan_offload_what,
3953                 (void *)&cmd_vlan_offload_on,
3954                 (void *)&cmd_vlan_offload_portid,
3955                 NULL,
3956         },
3957 };
3958
3959 /* *** VLAN TPID SET ON A PORT *** */
3960 struct cmd_vlan_tpid_result {
3961         cmdline_fixed_string_t vlan;
3962         cmdline_fixed_string_t set;
3963         cmdline_fixed_string_t vlan_type;
3964         cmdline_fixed_string_t what;
3965         uint16_t tp_id;
3966         portid_t port_id;
3967 };
3968
3969 static void
3970 cmd_vlan_tpid_parsed(void *parsed_result,
3971                           __attribute__((unused)) struct cmdline *cl,
3972                           __attribute__((unused)) void *data)
3973 {
3974         struct cmd_vlan_tpid_result *res = parsed_result;
3975         enum rte_vlan_type vlan_type;
3976
3977         if (!strcmp(res->vlan_type, "inner"))
3978                 vlan_type = ETH_VLAN_TYPE_INNER;
3979         else if (!strcmp(res->vlan_type, "outer"))
3980                 vlan_type = ETH_VLAN_TYPE_OUTER;
3981         else {
3982                 printf("Unknown vlan type\n");
3983                 return;
3984         }
3985         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3986 }
3987
3988 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3989         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3990                                  vlan, "vlan");
3991 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3992         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3993                                  set, "set");
3994 cmdline_parse_token_string_t cmd_vlan_type =
3995         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3996                                  vlan_type, "inner#outer");
3997 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3998         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3999                                  what, "tpid");
4000 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4001         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4002                               tp_id, UINT16);
4003 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4004         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4005                               port_id, UINT16);
4006
4007 cmdline_parse_inst_t cmd_vlan_tpid = {
4008         .f = cmd_vlan_tpid_parsed,
4009         .data = NULL,
4010         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4011                 "Set the VLAN Ether type",
4012         .tokens = {
4013                 (void *)&cmd_vlan_tpid_vlan,
4014                 (void *)&cmd_vlan_tpid_set,
4015                 (void *)&cmd_vlan_type,
4016                 (void *)&cmd_vlan_tpid_what,
4017                 (void *)&cmd_vlan_tpid_tpid,
4018                 (void *)&cmd_vlan_tpid_portid,
4019                 NULL,
4020         },
4021 };
4022
4023 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4024 struct cmd_rx_vlan_filter_result {
4025         cmdline_fixed_string_t rx_vlan;
4026         cmdline_fixed_string_t what;
4027         uint16_t vlan_id;
4028         portid_t port_id;
4029 };
4030
4031 static void
4032 cmd_rx_vlan_filter_parsed(void *parsed_result,
4033                           __attribute__((unused)) struct cmdline *cl,
4034                           __attribute__((unused)) void *data)
4035 {
4036         struct cmd_rx_vlan_filter_result *res = parsed_result;
4037
4038         if (!strcmp(res->what, "add"))
4039                 rx_vft_set(res->port_id, res->vlan_id, 1);
4040         else
4041                 rx_vft_set(res->port_id, res->vlan_id, 0);
4042 }
4043
4044 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4045         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4046                                  rx_vlan, "rx_vlan");
4047 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4048         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4049                                  what, "add#rm");
4050 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4051         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4052                               vlan_id, UINT16);
4053 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4054         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4055                               port_id, UINT16);
4056
4057 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4058         .f = cmd_rx_vlan_filter_parsed,
4059         .data = NULL,
4060         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4061                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4062                 "identifiers filtered by a port",
4063         .tokens = {
4064                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4065                 (void *)&cmd_rx_vlan_filter_what,
4066                 (void *)&cmd_rx_vlan_filter_vlanid,
4067                 (void *)&cmd_rx_vlan_filter_portid,
4068                 NULL,
4069         },
4070 };
4071
4072 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4073 struct cmd_tx_vlan_set_result {
4074         cmdline_fixed_string_t tx_vlan;
4075         cmdline_fixed_string_t set;
4076         portid_t port_id;
4077         uint16_t vlan_id;
4078 };
4079
4080 static void
4081 cmd_tx_vlan_set_parsed(void *parsed_result,
4082                        __attribute__((unused)) struct cmdline *cl,
4083                        __attribute__((unused)) void *data)
4084 {
4085         struct cmd_tx_vlan_set_result *res = parsed_result;
4086
4087         if (!port_is_stopped(res->port_id)) {
4088                 printf("Please stop port %d first\n", res->port_id);
4089                 return;
4090         }
4091
4092         tx_vlan_set(res->port_id, res->vlan_id);
4093
4094         cmd_reconfig_device_queue(res->port_id, 1, 1);
4095 }
4096
4097 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4098         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4099                                  tx_vlan, "tx_vlan");
4100 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4101         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4102                                  set, "set");
4103 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4104         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4105                               port_id, UINT16);
4106 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4107         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4108                               vlan_id, UINT16);
4109
4110 cmdline_parse_inst_t cmd_tx_vlan_set = {
4111         .f = cmd_tx_vlan_set_parsed,
4112         .data = NULL,
4113         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4114                 "Enable hardware insertion of a single VLAN header "
4115                 "with a given TAG Identifier in packets sent on a port",
4116         .tokens = {
4117                 (void *)&cmd_tx_vlan_set_tx_vlan,
4118                 (void *)&cmd_tx_vlan_set_set,
4119                 (void *)&cmd_tx_vlan_set_portid,
4120                 (void *)&cmd_tx_vlan_set_vlanid,
4121                 NULL,
4122         },
4123 };
4124
4125 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4126 struct cmd_tx_vlan_set_qinq_result {
4127         cmdline_fixed_string_t tx_vlan;
4128         cmdline_fixed_string_t set;
4129         portid_t port_id;
4130         uint16_t vlan_id;
4131         uint16_t vlan_id_outer;
4132 };
4133
4134 static void
4135 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4136                             __attribute__((unused)) struct cmdline *cl,
4137                             __attribute__((unused)) void *data)
4138 {
4139         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4140
4141         if (!port_is_stopped(res->port_id)) {
4142                 printf("Please stop port %d first\n", res->port_id);
4143                 return;
4144         }
4145
4146         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4147
4148         cmd_reconfig_device_queue(res->port_id, 1, 1);
4149 }
4150
4151 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4152         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4153                 tx_vlan, "tx_vlan");
4154 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4155         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4156                 set, "set");
4157 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4158         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4159                 port_id, UINT16);
4160 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4161         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4162                 vlan_id, UINT16);
4163 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4164         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4165                 vlan_id_outer, UINT16);
4166
4167 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4168         .f = cmd_tx_vlan_set_qinq_parsed,
4169         .data = NULL,
4170         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4171                 "Enable hardware insertion of double VLAN header "
4172                 "with given TAG Identifiers in packets sent on a port",
4173         .tokens = {
4174                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4175                 (void *)&cmd_tx_vlan_set_qinq_set,
4176                 (void *)&cmd_tx_vlan_set_qinq_portid,
4177                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4178                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4179                 NULL,
4180         },
4181 };
4182
4183 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4184 struct cmd_tx_vlan_set_pvid_result {
4185         cmdline_fixed_string_t tx_vlan;
4186         cmdline_fixed_string_t set;
4187         cmdline_fixed_string_t pvid;
4188         portid_t port_id;
4189         uint16_t vlan_id;
4190         cmdline_fixed_string_t mode;
4191 };
4192
4193 static void
4194 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4195                             __attribute__((unused)) struct cmdline *cl,
4196                             __attribute__((unused)) void *data)
4197 {
4198         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4199
4200         if (strcmp(res->mode, "on") == 0)
4201                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4202         else
4203                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4204 }
4205
4206 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4207         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4208                                  tx_vlan, "tx_vlan");
4209 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4210         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4211                                  set, "set");
4212 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4213         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4214                                  pvid, "pvid");
4215 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4216         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4217                              port_id, UINT16);
4218 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4219         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4220                               vlan_id, UINT16);
4221 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4222         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4223                                  mode, "on#off");
4224
4225 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4226         .f = cmd_tx_vlan_set_pvid_parsed,
4227         .data = NULL,
4228         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4229         .tokens = {
4230                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4231                 (void *)&cmd_tx_vlan_set_pvid_set,
4232                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4233                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4234                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4235                 (void *)&cmd_tx_vlan_set_pvid_mode,
4236                 NULL,
4237         },
4238 };
4239
4240 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4241 struct cmd_tx_vlan_reset_result {
4242         cmdline_fixed_string_t tx_vlan;
4243         cmdline_fixed_string_t reset;
4244         portid_t port_id;
4245 };
4246
4247 static void
4248 cmd_tx_vlan_reset_parsed(void *parsed_result,
4249                          __attribute__((unused)) struct cmdline *cl,
4250                          __attribute__((unused)) void *data)
4251 {
4252         struct cmd_tx_vlan_reset_result *res = parsed_result;
4253
4254         if (!port_is_stopped(res->port_id)) {
4255                 printf("Please stop port %d first\n", res->port_id);
4256                 return;
4257         }
4258
4259         tx_vlan_reset(res->port_id);
4260
4261         cmd_reconfig_device_queue(res->port_id, 1, 1);
4262 }
4263
4264 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4265         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4266                                  tx_vlan, "tx_vlan");
4267 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4268         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4269                                  reset, "reset");
4270 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4271         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4272                               port_id, UINT16);
4273
4274 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4275         .f = cmd_tx_vlan_reset_parsed,
4276         .data = NULL,
4277         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4278                 "VLAN header in packets sent on a port",
4279         .tokens = {
4280                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4281                 (void *)&cmd_tx_vlan_reset_reset,
4282                 (void *)&cmd_tx_vlan_reset_portid,
4283                 NULL,
4284         },
4285 };
4286
4287
4288 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4289 struct cmd_csum_result {
4290         cmdline_fixed_string_t csum;
4291         cmdline_fixed_string_t mode;
4292         cmdline_fixed_string_t proto;
4293         cmdline_fixed_string_t hwsw;
4294         portid_t port_id;
4295 };
4296
4297 static void
4298 csum_show(int port_id)
4299 {
4300         struct rte_eth_dev_info dev_info;
4301         uint64_t tx_offloads;
4302         int ret;
4303
4304         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4305         printf("Parse tunnel is %s\n",
4306                 (ports[port_id].parse_tunnel) ? "on" : "off");
4307         printf("IP checksum offload is %s\n",
4308                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4309         printf("UDP checksum offload is %s\n",
4310                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4311         printf("TCP checksum offload is %s\n",
4312                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4313         printf("SCTP checksum offload is %s\n",
4314                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4315         printf("Outer-Ip checksum offload is %s\n",
4316                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4317         printf("Outer-Udp checksum offload is %s\n",
4318                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4319
4320         /* display warnings if configuration is not supported by the NIC */
4321         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4322         if (ret != 0)
4323                 return;
4324
4325         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4326                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4327                 printf("Warning: hardware IP checksum enabled but not "
4328                         "supported by port %d\n", port_id);
4329         }
4330         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4331                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4332                 printf("Warning: hardware UDP checksum enabled but not "
4333                         "supported by port %d\n", port_id);
4334         }
4335         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4336                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4337                 printf("Warning: hardware TCP checksum enabled but not "
4338                         "supported by port %d\n", port_id);
4339         }
4340         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4341                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4342                 printf("Warning: hardware SCTP checksum enabled but not "
4343                         "supported by port %d\n", port_id);
4344         }
4345         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4346                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4347                 printf("Warning: hardware outer IP checksum enabled but not "
4348                         "supported by port %d\n", port_id);
4349         }
4350         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4351                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4352                         == 0) {
4353                 printf("Warning: hardware outer UDP checksum enabled but not "
4354                         "supported by port %d\n", port_id);
4355         }
4356 }
4357
4358 static void
4359 cmd_config_queue_tx_offloads(struct rte_port *port)
4360 {
4361         int k;
4362
4363         /* Apply queue tx offloads configuration */
4364         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4365                 port->tx_conf[k].offloads =
4366                         port->dev_conf.txmode.offloads;
4367 }
4368
4369 static void
4370 cmd_csum_parsed(void *parsed_result,
4371                        __attribute__((unused)) struct cmdline *cl,
4372                        __attribute__((unused)) void *data)
4373 {
4374         struct cmd_csum_result *res = parsed_result;
4375         int hw = 0;
4376         uint64_t csum_offloads = 0;
4377         struct rte_eth_dev_info dev_info;
4378         int ret;
4379
4380         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4381                 printf("invalid port %d\n", res->port_id);
4382                 return;
4383         }
4384         if (!port_is_stopped(res->port_id)) {
4385                 printf("Please stop port %d first\n", res->port_id);
4386                 return;
4387         }
4388
4389         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4390         if (ret != 0)
4391                 return;
4392
4393         if (!strcmp(res->mode, "set")) {
4394
4395                 if (!strcmp(res->hwsw, "hw"))
4396                         hw = 1;
4397
4398                 if (!strcmp(res->proto, "ip")) {
4399                         if (hw == 0 || (dev_info.tx_offload_capa &
4400                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4401                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4402                         } else {
4403                                 printf("IP checksum offload is not supported "
4404                                        "by port %u\n", res->port_id);
4405                         }
4406                 } else if (!strcmp(res->proto, "udp")) {
4407                         if (hw == 0 || (dev_info.tx_offload_capa &
4408                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4409                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4410                         } else {
4411                                 printf("UDP checksum offload is not supported "
4412                                        "by port %u\n", res->port_id);
4413                         }
4414                 } else if (!strcmp(res->proto, "tcp")) {
4415                         if (hw == 0 || (dev_info.tx_offload_capa &
4416                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4417                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4418                         } else {
4419                                 printf("TCP checksum offload is not supported "
4420                                        "by port %u\n", res->port_id);
4421                         }
4422                 } else if (!strcmp(res->proto, "sctp")) {
4423                         if (hw == 0 || (dev_info.tx_offload_capa &
4424                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4425                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4426                         } else {
4427                                 printf("SCTP checksum offload is not supported "
4428                                        "by port %u\n", res->port_id);
4429                         }
4430                 } else if (!strcmp(res->proto, "outer-ip")) {
4431                         if (hw == 0 || (dev_info.tx_offload_capa &
4432                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4433                                 csum_offloads |=
4434                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4435                         } else {
4436                                 printf("Outer IP checksum offload is not "
4437                                        "supported by port %u\n", res->port_id);
4438                         }
4439                 } else if (!strcmp(res->proto, "outer-udp")) {
4440                         if (hw == 0 || (dev_info.tx_offload_capa &
4441                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4442                                 csum_offloads |=
4443                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4444                         } else {
4445                                 printf("Outer UDP checksum offload is not "
4446                                        "supported by port %u\n", res->port_id);
4447                         }
4448                 }
4449
4450                 if (hw) {
4451                         ports[res->port_id].dev_conf.txmode.offloads |=
4452                                                         csum_offloads;
4453                 } else {
4454                         ports[res->port_id].dev_conf.txmode.offloads &=
4455                                                         (~csum_offloads);
4456                 }
4457                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4458         }
4459         csum_show(res->port_id);
4460
4461         cmd_reconfig_device_queue(res->port_id, 1, 1);
4462 }
4463
4464 cmdline_parse_token_string_t cmd_csum_csum =
4465         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4466                                 csum, "csum");
4467 cmdline_parse_token_string_t cmd_csum_mode =
4468         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4469                                 mode, "set");
4470 cmdline_parse_token_string_t cmd_csum_proto =
4471         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4472                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4473 cmdline_parse_token_string_t cmd_csum_hwsw =
4474         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4475                                 hwsw, "hw#sw");
4476 cmdline_parse_token_num_t cmd_csum_portid =
4477         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4478                                 port_id, UINT16);
4479
4480 cmdline_parse_inst_t cmd_csum_set = {
4481         .f = cmd_csum_parsed,
4482         .data = NULL,
4483         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4484                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4485                 "using csum forward engine",
4486         .tokens = {
4487                 (void *)&cmd_csum_csum,
4488                 (void *)&cmd_csum_mode,
4489                 (void *)&cmd_csum_proto,
4490                 (void *)&cmd_csum_hwsw,
4491                 (void *)&cmd_csum_portid,
4492                 NULL,
4493         },
4494 };
4495
4496 cmdline_parse_token_string_t cmd_csum_mode_show =
4497         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4498                                 mode, "show");
4499
4500 cmdline_parse_inst_t cmd_csum_show = {
4501         .f = cmd_csum_parsed,
4502         .data = NULL,
4503         .help_str = "csum show <port_id>: Show checksum offload configuration",
4504         .tokens = {
4505                 (void *)&cmd_csum_csum,
4506                 (void *)&cmd_csum_mode_show,
4507                 (void *)&cmd_csum_portid,
4508                 NULL,
4509         },
4510 };
4511
4512 /* Enable/disable tunnel parsing */
4513 struct cmd_csum_tunnel_result {
4514         cmdline_fixed_string_t csum;
4515         cmdline_fixed_string_t parse;
4516         cmdline_fixed_string_t onoff;
4517         portid_t port_id;
4518 };
4519
4520 static void
4521 cmd_csum_tunnel_parsed(void *parsed_result,
4522                        __attribute__((unused)) struct cmdline *cl,
4523                        __attribute__((unused)) void *data)
4524 {
4525         struct cmd_csum_tunnel_result *res = parsed_result;
4526
4527         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4528                 return;
4529
4530         if (!strcmp(res->onoff, "on"))
4531                 ports[res->port_id].parse_tunnel = 1;
4532         else
4533                 ports[res->port_id].parse_tunnel = 0;
4534
4535         csum_show(res->port_id);
4536 }
4537
4538 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4539         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4540                                 csum, "csum");
4541 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4542         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4543                                 parse, "parse-tunnel");
4544 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4545         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4546                                 onoff, "on#off");
4547 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4548         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4549                                 port_id, UINT16);
4550
4551 cmdline_parse_inst_t cmd_csum_tunnel = {
4552         .f = cmd_csum_tunnel_parsed,
4553         .data = NULL,
4554         .help_str = "csum parse-tunnel on|off <port_id>: "
4555                 "Enable/Disable parsing of tunnels for csum engine",
4556         .tokens = {
4557                 (void *)&cmd_csum_tunnel_csum,
4558                 (void *)&cmd_csum_tunnel_parse,
4559                 (void *)&cmd_csum_tunnel_onoff,
4560                 (void *)&cmd_csum_tunnel_portid,
4561                 NULL,
4562         },
4563 };
4564
4565 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4566 struct cmd_tso_set_result {
4567         cmdline_fixed_string_t tso;
4568         cmdline_fixed_string_t mode;
4569         uint16_t tso_segsz;
4570         portid_t port_id;
4571 };
4572
4573 static void
4574 cmd_tso_set_parsed(void *parsed_result,
4575                        __attribute__((unused)) struct cmdline *cl,
4576                        __attribute__((unused)) void *data)
4577 {
4578         struct cmd_tso_set_result *res = parsed_result;
4579         struct rte_eth_dev_info dev_info;
4580         int ret;
4581
4582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4583                 return;
4584         if (!port_is_stopped(res->port_id)) {
4585                 printf("Please stop port %d first\n", res->port_id);
4586                 return;
4587         }
4588
4589         if (!strcmp(res->mode, "set"))
4590                 ports[res->port_id].tso_segsz = res->tso_segsz;
4591
4592         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4593         if (ret != 0)
4594                 return;
4595
4596         if ((ports[res->port_id].tso_segsz != 0) &&
4597                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4598                 printf("Error: TSO is not supported by port %d\n",
4599                        res->port_id);
4600                 return;
4601         }
4602
4603         if (ports[res->port_id].tso_segsz == 0) {
4604                 ports[res->port_id].dev_conf.txmode.offloads &=
4605                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4606                 printf("TSO for non-tunneled packets is disabled\n");
4607         } else {
4608                 ports[res->port_id].dev_conf.txmode.offloads |=
4609                                                 DEV_TX_OFFLOAD_TCP_TSO;
4610                 printf("TSO segment size for non-tunneled packets is %d\n",
4611                         ports[res->port_id].tso_segsz);
4612         }
4613         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4614
4615         /* display warnings if configuration is not supported by the NIC */
4616         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4617         if (ret != 0)
4618                 return;
4619
4620         if ((ports[res->port_id].tso_segsz != 0) &&
4621                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4622                 printf("Warning: TSO enabled but not "
4623                         "supported by port %d\n", res->port_id);
4624         }
4625
4626         cmd_reconfig_device_queue(res->port_id, 1, 1);
4627 }
4628
4629 cmdline_parse_token_string_t cmd_tso_set_tso =
4630         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4631                                 tso, "tso");
4632 cmdline_parse_token_string_t cmd_tso_set_mode =
4633         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4634                                 mode, "set");
4635 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4636         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4637                                 tso_segsz, UINT16);
4638 cmdline_parse_token_num_t cmd_tso_set_portid =
4639         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4640                                 port_id, UINT16);
4641
4642 cmdline_parse_inst_t cmd_tso_set = {
4643         .f = cmd_tso_set_parsed,
4644         .data = NULL,
4645         .help_str = "tso set <tso_segsz> <port_id>: "
4646                 "Set TSO segment size of non-tunneled packets for csum engine "
4647                 "(0 to disable)",
4648         .tokens = {
4649                 (void *)&cmd_tso_set_tso,
4650                 (void *)&cmd_tso_set_mode,
4651                 (void *)&cmd_tso_set_tso_segsz,
4652                 (void *)&cmd_tso_set_portid,
4653                 NULL,
4654         },
4655 };
4656
4657 cmdline_parse_token_string_t cmd_tso_show_mode =
4658         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4659                                 mode, "show");
4660
4661
4662 cmdline_parse_inst_t cmd_tso_show = {
4663         .f = cmd_tso_set_parsed,
4664         .data = NULL,
4665         .help_str = "tso show <port_id>: "
4666                 "Show TSO segment size of non-tunneled packets for csum engine",
4667         .tokens = {
4668                 (void *)&cmd_tso_set_tso,
4669                 (void *)&cmd_tso_show_mode,
4670                 (void *)&cmd_tso_set_portid,
4671                 NULL,
4672         },
4673 };
4674
4675 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4676 struct cmd_tunnel_tso_set_result {
4677         cmdline_fixed_string_t tso;
4678         cmdline_fixed_string_t mode;
4679         uint16_t tso_segsz;
4680         portid_t port_id;
4681 };
4682
4683 static struct rte_eth_dev_info
4684 check_tunnel_tso_nic_support(portid_t port_id)
4685 {
4686         struct rte_eth_dev_info dev_info;
4687
4688         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4689                 return dev_info;
4690
4691         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4692                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4693                        "not enabled for port %d\n", port_id);
4694         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4695                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4696                        "not enabled for port %d\n", port_id);
4697         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4698                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4699                        "not enabled for port %d\n", port_id);
4700         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4701                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4702                        "not enabled for port %d\n", port_id);
4703         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4704                 printf("Warning: IP TUNNEL TSO not supported therefore "
4705                        "not enabled for port %d\n", port_id);
4706         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4707                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4708                        "not enabled for port %d\n", port_id);
4709         return dev_info;
4710 }
4711
4712 static void
4713 cmd_tunnel_tso_set_parsed(void *parsed_result,
4714                           __attribute__((unused)) struct cmdline *cl,
4715                           __attribute__((unused)) void *data)
4716 {
4717         struct cmd_tunnel_tso_set_result *res = parsed_result;
4718         struct rte_eth_dev_info dev_info;
4719
4720         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4721                 return;
4722         if (!port_is_stopped(res->port_id)) {
4723                 printf("Please stop port %d first\n", res->port_id);
4724                 return;
4725         }
4726
4727         if (!strcmp(res->mode, "set"))
4728                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4729
4730         dev_info = check_tunnel_tso_nic_support(res->port_id);
4731         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4732                 ports[res->port_id].dev_conf.txmode.offloads &=
4733                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4734                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4735                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4736                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4737                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4738                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4739                 printf("TSO for tunneled packets is disabled\n");
4740         } else {
4741                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4742                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4743                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4744                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4745                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4746                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4747
4748                 ports[res->port_id].dev_conf.txmode.offloads |=
4749                         (tso_offloads & dev_info.tx_offload_capa);
4750                 printf("TSO segment size for tunneled packets is %d\n",
4751                         ports[res->port_id].tunnel_tso_segsz);
4752
4753                 /* Below conditions are needed to make it work:
4754                  * (1) tunnel TSO is supported by the NIC;
4755                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4756                  * are recognized;
4757                  * (3) for tunneled pkts with outer L3 of IPv4,
4758                  * "csum set outer-ip" must be set to hw, because after tso,
4759                  * total_len of outer IP header is changed, and the checksum
4760                  * of outer IP header calculated by sw should be wrong; that
4761                  * is not necessary for IPv6 tunneled pkts because there's no
4762                  * checksum in IP header anymore.
4763                  */
4764
4765                 if (!ports[res->port_id].parse_tunnel)
4766                         printf("Warning: csum parse_tunnel must be set "
4767                                 "so that tunneled packets are recognized\n");
4768                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4769                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4770                         printf("Warning: csum set outer-ip must be set to hw "
4771                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4772         }
4773
4774         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4775         cmd_reconfig_device_queue(res->port_id, 1, 1);
4776 }
4777
4778 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4779         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4780                                 tso, "tunnel_tso");
4781 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4782         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4783                                 mode, "set");
4784 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4785         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4786                                 tso_segsz, UINT16);
4787 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4788         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4789                                 port_id, UINT16);
4790
4791 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4792         .f = cmd_tunnel_tso_set_parsed,
4793         .data = NULL,
4794         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4795                 "Set TSO segment size of tunneled packets for csum engine "
4796                 "(0 to disable)",
4797         .tokens = {
4798                 (void *)&cmd_tunnel_tso_set_tso,
4799                 (void *)&cmd_tunnel_tso_set_mode,
4800                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4801                 (void *)&cmd_tunnel_tso_set_portid,
4802                 NULL,
4803         },
4804 };
4805
4806 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4807         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4808                                 mode, "show");
4809
4810
4811 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4812         .f = cmd_tunnel_tso_set_parsed,
4813         .data = NULL,
4814         .help_str = "tunnel_tso show <port_id> "
4815                 "Show TSO segment size of tunneled packets for csum engine",
4816         .tokens = {
4817                 (void *)&cmd_tunnel_tso_set_tso,
4818                 (void *)&cmd_tunnel_tso_show_mode,
4819                 (void *)&cmd_tunnel_tso_set_portid,
4820                 NULL,
4821         },
4822 };
4823
4824 /* *** SET GRO FOR A PORT *** */
4825 struct cmd_gro_enable_result {
4826         cmdline_fixed_string_t cmd_set;
4827         cmdline_fixed_string_t cmd_port;
4828         cmdline_fixed_string_t cmd_keyword;
4829         cmdline_fixed_string_t cmd_onoff;
4830         portid_t cmd_pid;
4831 };
4832
4833 static void
4834 cmd_gro_enable_parsed(void *parsed_result,
4835                 __attribute__((unused)) struct cmdline *cl,
4836                 __attribute__((unused)) void *data)
4837 {
4838         struct cmd_gro_enable_result *res;
4839
4840         res = parsed_result;
4841         if (!strcmp(res->cmd_keyword, "gro"))
4842                 setup_gro(res->cmd_onoff, res->cmd_pid);
4843 }
4844
4845 cmdline_parse_token_string_t cmd_gro_enable_set =
4846         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4847                         cmd_set, "set");
4848 cmdline_parse_token_string_t cmd_gro_enable_port =
4849         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4850                         cmd_keyword, "port");
4851 cmdline_parse_token_num_t cmd_gro_enable_pid =
4852         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4853                         cmd_pid, UINT16);
4854 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4855         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4856                         cmd_keyword, "gro");
4857 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4858         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4859                         cmd_onoff, "on#off");
4860
4861 cmdline_parse_inst_t cmd_gro_enable = {
4862         .f = cmd_gro_enable_parsed,
4863         .data = NULL,
4864         .help_str = "set port <port_id> gro on|off",
4865         .tokens = {
4866                 (void *)&cmd_gro_enable_set,
4867                 (void *)&cmd_gro_enable_port,
4868                 (void *)&cmd_gro_enable_pid,
4869                 (void *)&cmd_gro_enable_keyword,
4870                 (void *)&cmd_gro_enable_onoff,
4871                 NULL,
4872         },
4873 };
4874
4875 /* *** DISPLAY GRO CONFIGURATION *** */
4876 struct cmd_gro_show_result {
4877         cmdline_fixed_string_t cmd_show;
4878         cmdline_fixed_string_t cmd_port;
4879         cmdline_fixed_string_t cmd_keyword;
4880         portid_t cmd_pid;
4881 };
4882
4883 static void
4884 cmd_gro_show_parsed(void *parsed_result,
4885                 __attribute__((unused)) struct cmdline *cl,
4886                 __attribute__((unused)) void *data)
4887 {
4888         struct cmd_gro_show_result *res;
4889
4890         res = parsed_result;
4891         if (!strcmp(res->cmd_keyword, "gro"))
4892                 show_gro(res->cmd_pid);
4893 }
4894
4895 cmdline_parse_token_string_t cmd_gro_show_show =
4896         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4897                         cmd_show, "show");
4898 cmdline_parse_token_string_t cmd_gro_show_port =
4899         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4900                         cmd_port, "port");
4901 cmdline_parse_token_num_t cmd_gro_show_pid =
4902         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4903                         cmd_pid, UINT16);
4904 cmdline_parse_token_string_t cmd_gro_show_keyword =
4905         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4906                         cmd_keyword, "gro");
4907
4908 cmdline_parse_inst_t cmd_gro_show = {
4909         .f = cmd_gro_show_parsed,
4910         .data = NULL,
4911         .help_str = "show port <port_id> gro",
4912         .tokens = {
4913                 (void *)&cmd_gro_show_show,
4914                 (void *)&cmd_gro_show_port,
4915                 (void *)&cmd_gro_show_pid,
4916                 (void *)&cmd_gro_show_keyword,
4917                 NULL,
4918         },
4919 };
4920
4921 /* *** SET FLUSH CYCLES FOR GRO *** */
4922 struct cmd_gro_flush_result {
4923         cmdline_fixed_string_t cmd_set;
4924         cmdline_fixed_string_t cmd_keyword;
4925         cmdline_fixed_string_t cmd_flush;
4926         uint8_t cmd_cycles;
4927 };
4928
4929 static void
4930 cmd_gro_flush_parsed(void *parsed_result,
4931                 __attribute__((unused)) struct cmdline *cl,
4932                 __attribute__((unused)) void *data)
4933 {
4934         struct cmd_gro_flush_result *res;
4935
4936         res = parsed_result;
4937         if ((!strcmp(res->cmd_keyword, "gro")) &&
4938                         (!strcmp(res->cmd_flush, "flush")))
4939                 setup_gro_flush_cycles(res->cmd_cycles);
4940 }
4941
4942 cmdline_parse_token_string_t cmd_gro_flush_set =
4943         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4944                         cmd_set, "set");
4945 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4946         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4947                         cmd_keyword, "gro");
4948 cmdline_parse_token_string_t cmd_gro_flush_flush =
4949         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4950                         cmd_flush, "flush");
4951 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4952         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4953                         cmd_cycles, UINT8);
4954
4955 cmdline_parse_inst_t cmd_gro_flush = {
4956         .f = cmd_gro_flush_parsed,
4957         .data = NULL,
4958         .help_str = "set gro flush <cycles>",
4959         .tokens = {
4960                 (void *)&cmd_gro_flush_set,
4961                 (void *)&cmd_gro_flush_keyword,
4962                 (void *)&cmd_gro_flush_flush,
4963                 (void *)&cmd_gro_flush_cycles,
4964                 NULL,
4965         },
4966 };
4967
4968 /* *** ENABLE/DISABLE GSO *** */
4969 struct cmd_gso_enable_result {
4970         cmdline_fixed_string_t cmd_set;
4971         cmdline_fixed_string_t cmd_port;
4972         cmdline_fixed_string_t cmd_keyword;
4973         cmdline_fixed_string_t cmd_mode;
4974         portid_t cmd_pid;
4975 };
4976
4977 static void
4978 cmd_gso_enable_parsed(void *parsed_result,
4979                 __attribute__((unused)) struct cmdline *cl,
4980                 __attribute__((unused)) void *data)
4981 {
4982         struct cmd_gso_enable_result *res;
4983
4984         res = parsed_result;
4985         if (!strcmp(res->cmd_keyword, "gso"))
4986                 setup_gso(res->cmd_mode, res->cmd_pid);
4987 }
4988
4989 cmdline_parse_token_string_t cmd_gso_enable_set =
4990         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4991                         cmd_set, "set");
4992 cmdline_parse_token_string_t cmd_gso_enable_port =
4993         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4994                         cmd_port, "port");
4995 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4996         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4997                         cmd_keyword, "gso");
4998 cmdline_parse_token_string_t cmd_gso_enable_mode =
4999         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5000                         cmd_mode, "on#off");
5001 cmdline_parse_token_num_t cmd_gso_enable_pid =
5002         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5003                         cmd_pid, UINT16);
5004
5005 cmdline_parse_inst_t cmd_gso_enable = {
5006         .f = cmd_gso_enable_parsed,
5007         .data = NULL,
5008         .help_str = "set port <port_id> gso on|off",
5009         .tokens = {
5010                 (void *)&cmd_gso_enable_set,
5011                 (void *)&cmd_gso_enable_port,
5012                 (void *)&cmd_gso_enable_pid,
5013                 (void *)&cmd_gso_enable_keyword,
5014                 (void *)&cmd_gso_enable_mode,
5015                 NULL,
5016         },
5017 };
5018
5019 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5020 struct cmd_gso_size_result {
5021         cmdline_fixed_string_t cmd_set;
5022         cmdline_fixed_string_t cmd_keyword;
5023         cmdline_fixed_string_t cmd_segsz;
5024         uint16_t cmd_size;
5025 };
5026
5027 static void
5028 cmd_gso_size_parsed(void *parsed_result,
5029                        __attribute__((unused)) struct cmdline *cl,
5030                        __attribute__((unused)) void *data)
5031 {
5032         struct cmd_gso_size_result *res = parsed_result;
5033
5034         if (test_done == 0) {
5035                 printf("Before setting GSO segsz, please first"
5036                                 " stop fowarding\n");
5037                 return;
5038         }
5039
5040         if (!strcmp(res->cmd_keyword, "gso") &&
5041                         !strcmp(res->cmd_segsz, "segsz")) {
5042                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5043                         printf("gso_size should be larger than %zu."
5044                                         " Please input a legal value\n",
5045                                         RTE_GSO_SEG_SIZE_MIN);
5046                 else
5047                         gso_max_segment_size = res->cmd_size;
5048         }
5049 }
5050
5051 cmdline_parse_token_string_t cmd_gso_size_set =
5052         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5053                                 cmd_set, "set");
5054 cmdline_parse_token_string_t cmd_gso_size_keyword =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5056                                 cmd_keyword, "gso");
5057 cmdline_parse_token_string_t cmd_gso_size_segsz =
5058         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5059                                 cmd_segsz, "segsz");
5060 cmdline_parse_token_num_t cmd_gso_size_size =
5061         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5062                                 cmd_size, UINT16);
5063
5064 cmdline_parse_inst_t cmd_gso_size = {
5065         .f = cmd_gso_size_parsed,
5066         .data = NULL,
5067         .help_str = "set gso segsz <length>",
5068         .tokens = {
5069                 (void *)&cmd_gso_size_set,
5070                 (void *)&cmd_gso_size_keyword,
5071                 (void *)&cmd_gso_size_segsz,
5072                 (void *)&cmd_gso_size_size,
5073                 NULL,
5074         },
5075 };
5076
5077 /* *** SHOW GSO CONFIGURATION *** */
5078 struct cmd_gso_show_result {
5079         cmdline_fixed_string_t cmd_show;
5080         cmdline_fixed_string_t cmd_port;
5081         cmdline_fixed_string_t cmd_keyword;
5082         portid_t cmd_pid;
5083 };
5084
5085 static void
5086 cmd_gso_show_parsed(void *parsed_result,
5087                        __attribute__((unused)) struct cmdline *cl,
5088                        __attribute__((unused)) void *data)
5089 {
5090         struct cmd_gso_show_result *res = parsed_result;
5091
5092         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5093                 printf("invalid port id %u\n", res->cmd_pid);
5094                 return;
5095         }
5096         if (!strcmp(res->cmd_keyword, "gso")) {
5097                 if (gso_ports[res->cmd_pid].enable) {
5098                         printf("Max GSO'd packet size: %uB\n"
5099                                         "Supported GSO types: TCP/IPv4, "
5100                                         "UDP/IPv4, VxLAN with inner "
5101                                         "TCP/IPv4 packet, GRE with inner "
5102                                         "TCP/IPv4 packet\n",
5103                                         gso_max_segment_size);
5104                 } else
5105                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5106         }
5107 }
5108
5109 cmdline_parse_token_string_t cmd_gso_show_show =
5110 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5111                 cmd_show, "show");
5112 cmdline_parse_token_string_t cmd_gso_show_port =
5113 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5114                 cmd_port, "port");
5115 cmdline_parse_token_string_t cmd_gso_show_keyword =
5116         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5117                                 cmd_keyword, "gso");
5118 cmdline_parse_token_num_t cmd_gso_show_pid =
5119         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5120                                 cmd_pid, UINT16);
5121
5122 cmdline_parse_inst_t cmd_gso_show = {
5123         .f = cmd_gso_show_parsed,
5124         .data = NULL,
5125         .help_str = "show port <port_id> gso",
5126         .tokens = {
5127                 (void *)&cmd_gso_show_show,
5128                 (void *)&cmd_gso_show_port,
5129                 (void *)&cmd_gso_show_pid,
5130                 (void *)&cmd_gso_show_keyword,
5131                 NULL,
5132         },
5133 };
5134
5135 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5136 struct cmd_set_flush_rx {
5137         cmdline_fixed_string_t set;
5138         cmdline_fixed_string_t flush_rx;
5139         cmdline_fixed_string_t mode;
5140 };
5141
5142 static void
5143 cmd_set_flush_rx_parsed(void *parsed_result,
5144                 __attribute__((unused)) struct cmdline *cl,
5145                 __attribute__((unused)) void *data)
5146 {
5147         struct cmd_set_flush_rx *res = parsed_result;
5148         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5149 }
5150
5151 cmdline_parse_token_string_t cmd_setflushrx_set =
5152         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5153                         set, "set");
5154 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5156                         flush_rx, "flush_rx");
5157 cmdline_parse_token_string_t cmd_setflushrx_mode =
5158         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5159                         mode, "on#off");
5160
5161
5162 cmdline_parse_inst_t cmd_set_flush_rx = {
5163         .f = cmd_set_flush_rx_parsed,
5164         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5165         .data = NULL,
5166         .tokens = {
5167                 (void *)&cmd_setflushrx_set,
5168                 (void *)&cmd_setflushrx_flush_rx,
5169                 (void *)&cmd_setflushrx_mode,
5170                 NULL,
5171         },
5172 };
5173
5174 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5175 struct cmd_set_link_check {
5176         cmdline_fixed_string_t set;
5177         cmdline_fixed_string_t link_check;
5178         cmdline_fixed_string_t mode;
5179 };
5180
5181 static void
5182 cmd_set_link_check_parsed(void *parsed_result,
5183                 __attribute__((unused)) struct cmdline *cl,
5184                 __attribute__((unused)) void *data)
5185 {
5186         struct cmd_set_link_check *res = parsed_result;
5187         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5188 }
5189
5190 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5191         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5192                         set, "set");
5193 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5194         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5195                         link_check, "link_check");
5196 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5197         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5198                         mode, "on#off");
5199
5200
5201 cmdline_parse_inst_t cmd_set_link_check = {
5202         .f = cmd_set_link_check_parsed,
5203         .help_str = "set link_check on|off: Enable/Disable link status check "
5204                     "when starting/stopping a port",
5205         .data = NULL,
5206         .tokens = {
5207                 (void *)&cmd_setlinkcheck_set,
5208                 (void *)&cmd_setlinkcheck_link_check,
5209                 (void *)&cmd_setlinkcheck_mode,
5210                 NULL,
5211         },
5212 };
5213
5214 /* *** SET NIC BYPASS MODE *** */
5215 struct cmd_set_bypass_mode_result {
5216         cmdline_fixed_string_t set;
5217         cmdline_fixed_string_t bypass;
5218         cmdline_fixed_string_t mode;
5219         cmdline_fixed_string_t value;
5220         portid_t port_id;
5221 };
5222
5223 static void
5224 cmd_set_bypass_mode_parsed(void *parsed_result,
5225                 __attribute__((unused)) struct cmdline *cl,
5226                 __attribute__((unused)) void *data)
5227 {
5228         struct cmd_set_bypass_mode_result *res = parsed_result;
5229         portid_t port_id = res->port_id;
5230         int32_t rc = -EINVAL;
5231
5232 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5233         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5234
5235         if (!strcmp(res->value, "bypass"))
5236                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5237         else if (!strcmp(res->value, "isolate"))
5238                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5239         else
5240                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5241
5242         /* Set the bypass mode for the relevant port. */
5243         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5244 #endif
5245         if (rc != 0)
5246                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5247 }
5248
5249 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5250         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5251                         set, "set");
5252 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5253         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5254                         bypass, "bypass");
5255 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5256         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5257                         mode, "mode");
5258 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5259         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5260                         value, "normal#bypass#isolate");
5261 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5262         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5263                                 port_id, UINT16);
5264
5265 cmdline_parse_inst_t cmd_set_bypass_mode = {
5266         .f = cmd_set_bypass_mode_parsed,
5267         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5268                     "Set the NIC bypass mode for port_id",
5269         .data = NULL,
5270         .tokens = {
5271                 (void *)&cmd_setbypass_mode_set,
5272                 (void *)&cmd_setbypass_mode_bypass,
5273                 (void *)&cmd_setbypass_mode_mode,
5274                 (void *)&cmd_setbypass_mode_value,
5275                 (void *)&cmd_setbypass_mode_port,
5276                 NULL,
5277         },
5278 };
5279
5280 /* *** SET NIC BYPASS EVENT *** */
5281 struct cmd_set_bypass_event_result {
5282         cmdline_fixed_string_t set;
5283         cmdline_fixed_string_t bypass;
5284         cmdline_fixed_string_t event;
5285         cmdline_fixed_string_t event_value;
5286         cmdline_fixed_string_t mode;
5287         cmdline_fixed_string_t mode_value;
5288         portid_t port_id;
5289 };
5290
5291 static void
5292 cmd_set_bypass_event_parsed(void *parsed_result,
5293                 __attribute__((unused)) struct cmdline *cl,
5294                 __attribute__((unused)) void *data)
5295 {
5296         int32_t rc = -EINVAL;
5297         struct cmd_set_bypass_event_result *res = parsed_result;
5298         portid_t port_id = res->port_id;
5299
5300 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5301         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5302         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5303
5304         if (!strcmp(res->event_value, "timeout"))
5305                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5306         else if (!strcmp(res->event_value, "os_on"))
5307                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5308         else if (!strcmp(res->event_value, "os_off"))
5309                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5310         else if (!strcmp(res->event_value, "power_on"))
5311                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5312         else if (!strcmp(res->event_value, "power_off"))
5313                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5314         else
5315                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5316
5317         if (!strcmp(res->mode_value, "bypass"))
5318                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5319         else if (!strcmp(res->mode_value, "isolate"))
5320                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5321         else
5322                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5323
5324         /* Set the watchdog timeout. */
5325         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5326
5327                 rc = -EINVAL;
5328                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5329                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5330                                                            bypass_timeout);
5331                 }
5332                 if (rc != 0) {
5333                         printf("Failed to set timeout value %u "
5334                         "for port %d, errto code: %d.\n",
5335                         bypass_timeout, port_id, rc);
5336                 }
5337         }
5338
5339         /* Set the bypass event to transition to bypass mode. */
5340         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5341                                               bypass_mode);
5342 #endif
5343
5344         if (rc != 0)
5345                 printf("\t Failed to set bypass event for port = %d.\n",
5346                        port_id);
5347 }
5348
5349 cmdline_parse_token_string_t cmd_setbypass_event_set =
5350         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5351                         set, "set");
5352 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5353         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5354                         bypass, "bypass");
5355 cmdline_parse_token_string_t cmd_setbypass_event_event =
5356         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5357                         event, "event");
5358 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5359         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5360                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5361 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5362         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5363                         mode, "mode");
5364 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5365         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5366                         mode_value, "normal#bypass#isolate");
5367 cmdline_parse_token_num_t cmd_setbypass_event_port =
5368         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5369                                 port_id, UINT16);
5370
5371 cmdline_parse_inst_t cmd_set_bypass_event = {
5372         .f = cmd_set_bypass_event_parsed,
5373         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5374                 "power_off mode normal|bypass|isolate <port_id>: "
5375                 "Set the NIC bypass event mode for port_id",
5376         .data = NULL,
5377         .tokens = {
5378                 (void *)&cmd_setbypass_event_set,
5379                 (void *)&cmd_setbypass_event_bypass,
5380                 (void *)&cmd_setbypass_event_event,
5381                 (void *)&cmd_setbypass_event_event_value,
5382                 (void *)&cmd_setbypass_event_mode,
5383                 (void *)&cmd_setbypass_event_mode_value,
5384                 (void *)&cmd_setbypass_event_port,
5385                 NULL,
5386         },
5387 };
5388
5389
5390 /* *** SET NIC BYPASS TIMEOUT *** */
5391 struct cmd_set_bypass_timeout_result {
5392         cmdline_fixed_string_t set;
5393         cmdline_fixed_string_t bypass;
5394         cmdline_fixed_string_t timeout;
5395         cmdline_fixed_string_t value;
5396 };
5397
5398 static void
5399 cmd_set_bypass_timeout_parsed(void *parsed_result,
5400                 __attribute__((unused)) struct cmdline *cl,
5401                 __attribute__((unused)) void *data)
5402 {
5403         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5404
5405 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5406         if (!strcmp(res->value, "1.5"))
5407                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5408         else if (!strcmp(res->value, "2"))
5409                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5410         else if (!strcmp(res->value, "3"))
5411                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5412         else if (!strcmp(res->value, "4"))
5413                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5414         else if (!strcmp(res->value, "8"))
5415                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5416         else if (!strcmp(res->value, "16"))
5417                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5418         else if (!strcmp(res->value, "32"))
5419                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5420         else
5421                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5422 #endif
5423 }
5424
5425 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5426         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5427                         set, "set");
5428 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5429         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5430                         bypass, "bypass");
5431 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5432         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5433                         timeout, "timeout");
5434 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5435         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5436                         value, "0#1.5#2#3#4#8#16#32");
5437
5438 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5439         .f = cmd_set_bypass_timeout_parsed,
5440         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5441                 "Set the NIC bypass watchdog timeout in seconds",
5442         .data = NULL,
5443         .tokens = {
5444                 (void *)&cmd_setbypass_timeout_set,
5445                 (void *)&cmd_setbypass_timeout_bypass,
5446                 (void *)&cmd_setbypass_timeout_timeout,
5447                 (void *)&cmd_setbypass_timeout_value,
5448                 NULL,
5449         },
5450 };
5451
5452 /* *** SHOW NIC BYPASS MODE *** */
5453 struct cmd_show_bypass_config_result {
5454         cmdline_fixed_string_t show;
5455         cmdline_fixed_string_t bypass;
5456         cmdline_fixed_string_t config;
5457         portid_t port_id;
5458 };
5459
5460 static void
5461 cmd_show_bypass_config_parsed(void *parsed_result,
5462                 __attribute__((unused)) struct cmdline *cl,
5463                 __attribute__((unused)) void *data)
5464 {
5465         struct cmd_show_bypass_config_result *res = parsed_result;
5466         portid_t port_id = res->port_id;
5467         int rc = -EINVAL;
5468 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5469         uint32_t event_mode;
5470         uint32_t bypass_mode;
5471         uint32_t timeout = bypass_timeout;
5472         int i;
5473
5474         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5475                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5476         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5477                 {"UNKNOWN", "normal", "bypass", "isolate"};
5478         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5479                 "NONE",
5480                 "OS/board on",
5481                 "power supply on",
5482                 "OS/board off",
5483                 "power supply off",
5484                 "timeout"};
5485         int num_events = (sizeof events) / (sizeof events[0]);
5486
5487         /* Display the bypass mode.*/
5488         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5489                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5490                 return;
5491         }
5492         else {
5493                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5494                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5495
5496                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5497         }
5498
5499         /* Display the bypass timeout.*/
5500         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5501                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5502
5503         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5504
5505         /* Display the bypass events and associated modes. */
5506         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5507
5508                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5509                         printf("\tFailed to get bypass mode for event = %s\n",
5510                                 events[i]);
5511                 } else {
5512                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5513                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5514
5515                         printf("\tbypass event: %-16s = %s\n", events[i],
5516                                 modes[event_mode]);
5517                 }
5518         }
5519 #endif
5520         if (rc != 0)
5521                 printf("\tFailed to get bypass configuration for port = %d\n",
5522                        port_id);
5523 }
5524
5525 cmdline_parse_token_string_t cmd_showbypass_config_show =
5526         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5527                         show, "show");
5528 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5529         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5530                         bypass, "bypass");
5531 cmdline_parse_token_string_t cmd_showbypass_config_config =
5532         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5533                         config, "config");
5534 cmdline_parse_token_num_t cmd_showbypass_config_port =
5535         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5536                                 port_id, UINT16);
5537
5538 cmdline_parse_inst_t cmd_show_bypass_config = {
5539         .f = cmd_show_bypass_config_parsed,
5540         .help_str = "show bypass config <port_id>: "
5541                     "Show the NIC bypass config for port_id",
5542         .data = NULL,
5543         .tokens = {
5544                 (void *)&cmd_showbypass_config_show,
5545                 (void *)&cmd_showbypass_config_bypass,
5546                 (void *)&cmd_showbypass_config_config,
5547                 (void *)&cmd_showbypass_config_port,
5548                 NULL,
5549         },
5550 };
5551
5552 #ifdef RTE_LIBRTE_PMD_BOND
5553 /* *** SET BONDING MODE *** */
5554 struct cmd_set_bonding_mode_result {
5555         cmdline_fixed_string_t set;
5556         cmdline_fixed_string_t bonding;
5557         cmdline_fixed_string_t mode;
5558         uint8_t value;
5559         portid_t port_id;
5560 };
5561
5562 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5563                 __attribute__((unused))  struct cmdline *cl,
5564                 __attribute__((unused)) void *data)
5565 {
5566         struct cmd_set_bonding_mode_result *res = parsed_result;
5567         portid_t port_id = res->port_id;
5568
5569         /* Set the bonding mode for the relevant port. */
5570         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5571                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5572 }
5573
5574 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5575 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5576                 set, "set");
5577 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5578 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5579                 bonding, "bonding");
5580 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5581 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5582                 mode, "mode");
5583 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5584 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5585                 value, UINT8);
5586 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5587 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5588                 port_id, UINT16);
5589
5590 cmdline_parse_inst_t cmd_set_bonding_mode = {
5591                 .f = cmd_set_bonding_mode_parsed,
5592                 .help_str = "set bonding mode <mode_value> <port_id>: "
5593                         "Set the bonding mode for port_id",
5594                 .data = NULL,
5595                 .tokens = {
5596                                 (void *) &cmd_setbonding_mode_set,
5597                                 (void *) &cmd_setbonding_mode_bonding,
5598                                 (void *) &cmd_setbonding_mode_mode,
5599                                 (void *) &cmd_setbonding_mode_value,
5600                                 (void *) &cmd_setbonding_mode_port,
5601                                 NULL
5602                 }
5603 };
5604
5605 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5606 struct cmd_set_bonding_lacp_dedicated_queues_result {
5607         cmdline_fixed_string_t set;
5608         cmdline_fixed_string_t bonding;
5609         cmdline_fixed_string_t lacp;
5610         cmdline_fixed_string_t dedicated_queues;
5611         portid_t port_id;
5612         cmdline_fixed_string_t mode;
5613 };
5614
5615 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5616                 __attribute__((unused))  struct cmdline *cl,
5617                 __attribute__((unused)) void *data)
5618 {
5619         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5620         portid_t port_id = res->port_id;
5621         struct rte_port *port;
5622
5623         port = &ports[port_id];
5624
5625         /** Check if the port is not started **/
5626         if (port->port_status != RTE_PORT_STOPPED) {
5627                 printf("Please stop port %d first\n", port_id);
5628                 return;
5629         }
5630
5631         if (!strcmp(res->mode, "enable")) {
5632                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5633                         printf("Dedicate queues for LACP control packets"
5634                                         " enabled\n");
5635                 else
5636                         printf("Enabling dedicate queues for LACP control "
5637                                         "packets on port %d failed\n", port_id);
5638         } else if (!strcmp(res->mode, "disable")) {
5639                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5640                         printf("Dedicated queues for LACP control packets "
5641                                         "disabled\n");
5642                 else
5643                         printf("Disabling dedicated queues for LACP control "
5644                                         "traffic on port %d failed\n", port_id);
5645         }
5646 }
5647
5648 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5649 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5650                 set, "set");
5651 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5652 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5653                 bonding, "bonding");
5654 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5655 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5656                 lacp, "lacp");
5657 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5658 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5659                 dedicated_queues, "dedicated_queues");
5660 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5661 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5662                 port_id, UINT16);
5663 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5664 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5665                 mode, "enable#disable");
5666
5667 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5668                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5669                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5670                         "enable|disable: "
5671                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5672                 .data = NULL,
5673                 .tokens = {
5674                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5675                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5676                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5677                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5678                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5679                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5680                         NULL
5681                 }
5682 };
5683
5684 /* *** SET BALANCE XMIT POLICY *** */
5685 struct cmd_set_bonding_balance_xmit_policy_result {
5686         cmdline_fixed_string_t set;
5687         cmdline_fixed_string_t bonding;
5688         cmdline_fixed_string_t balance_xmit_policy;
5689         portid_t port_id;
5690         cmdline_fixed_string_t policy;
5691 };
5692
5693 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5694                 __attribute__((unused))  struct cmdline *cl,
5695                 __attribute__((unused)) void *data)
5696 {
5697         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5698         portid_t port_id = res->port_id;
5699         uint8_t policy;
5700
5701         if (!strcmp(res->policy, "l2")) {
5702                 policy = BALANCE_XMIT_POLICY_LAYER2;
5703         } else if (!strcmp(res->policy, "l23")) {
5704                 policy = BALANCE_XMIT_POLICY_LAYER23;
5705         } else if (!strcmp(res->policy, "l34")) {
5706                 policy = BALANCE_XMIT_POLICY_LAYER34;
5707         } else {
5708                 printf("\t Invalid xmit policy selection");
5709                 return;
5710         }
5711
5712         /* Set the bonding mode for the relevant port. */
5713         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5714                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5715                                 port_id);
5716         }
5717 }
5718
5719 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5720 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5721                 set, "set");
5722 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5724                 bonding, "bonding");
5725 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5726 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5727                 balance_xmit_policy, "balance_xmit_policy");
5728 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5729 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5730                 port_id, UINT16);
5731 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5732 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5733                 policy, "l2#l23#l34");
5734
5735 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5736                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5737                 .help_str = "set bonding balance_xmit_policy <port_id> "
5738                         "l2|l23|l34: "
5739                         "Set the bonding balance_xmit_policy for port_id",
5740                 .data = NULL,
5741                 .tokens = {
5742                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5743                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5744                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5745                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5746                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5747                                 NULL
5748                 }
5749 };
5750
5751 /* *** SHOW NIC BONDING CONFIGURATION *** */
5752 struct cmd_show_bonding_config_result {
5753         cmdline_fixed_string_t show;
5754         cmdline_fixed_string_t bonding;
5755         cmdline_fixed_string_t config;
5756         portid_t port_id;
5757 };
5758
5759 static void cmd_show_bonding_config_parsed(void *parsed_result,
5760                 __attribute__((unused))  struct cmdline *cl,
5761                 __attribute__((unused)) void *data)
5762 {
5763         struct cmd_show_bonding_config_result *res = parsed_result;
5764         int bonding_mode, agg_mode;
5765         portid_t slaves[RTE_MAX_ETHPORTS];
5766         int num_slaves, num_active_slaves;
5767         int primary_id;
5768         int i;
5769         portid_t port_id = res->port_id;
5770
5771         /* Display the bonding mode.*/
5772         bonding_mode = rte_eth_bond_mode_get(port_id);
5773         if (bonding_mode < 0) {
5774                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5775                 return;
5776         } else
5777                 printf("\tBonding mode: %d\n", bonding_mode);
5778
5779         if (bonding_mode == BONDING_MODE_BALANCE) {
5780                 int balance_xmit_policy;
5781
5782                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5783                 if (balance_xmit_policy < 0) {
5784                         printf("\tFailed to get balance xmit policy for port = %d\n",
5785                                         port_id);
5786                         return;
5787                 } else {
5788                         printf("\tBalance Xmit Policy: ");
5789
5790                         switch (balance_xmit_policy) {
5791                         case BALANCE_XMIT_POLICY_LAYER2:
5792                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5793                                 break;
5794                         case BALANCE_XMIT_POLICY_LAYER23:
5795                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5796                                 break;
5797                         case BALANCE_XMIT_POLICY_LAYER34:
5798                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5799                                 break;
5800                         }
5801                         printf("\n");
5802                 }
5803         }
5804
5805         if (bonding_mode == BONDING_MODE_8023AD) {
5806                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5807                 printf("\tIEEE802.3AD Aggregator Mode: ");
5808                 switch (agg_mode) {
5809                 case AGG_BANDWIDTH:
5810                         printf("bandwidth");
5811                         break;
5812                 case AGG_STABLE:
5813                         printf("stable");
5814                         break;
5815                 case AGG_COUNT:
5816                         printf("count");
5817                         break;
5818                 }
5819                 printf("\n");
5820         }
5821
5822         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5823
5824         if (num_slaves < 0) {
5825                 printf("\tFailed to get slave list for port = %d\n", port_id);
5826                 return;
5827         }
5828         if (num_slaves > 0) {
5829                 printf("\tSlaves (%d): [", num_slaves);
5830                 for (i = 0; i < num_slaves - 1; i++)
5831                         printf("%d ", slaves[i]);
5832
5833                 printf("%d]\n", slaves[num_slaves - 1]);
5834         } else {
5835                 printf("\tSlaves: []\n");
5836
5837         }
5838
5839         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5840                         RTE_MAX_ETHPORTS);
5841
5842         if (num_active_slaves < 0) {
5843                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5844                 return;
5845         }
5846         if (num_active_slaves > 0) {
5847                 printf("\tActive Slaves (%d): [", num_active_slaves);
5848                 for (i = 0; i < num_active_slaves - 1; i++)
5849                         printf("%d ", slaves[i]);
5850
5851                 printf("%d]\n", slaves[num_active_slaves - 1]);
5852
5853         } else {
5854                 printf("\tActive Slaves: []\n");
5855
5856         }
5857
5858         primary_id = rte_eth_bond_primary_get(port_id);
5859         if (primary_id < 0) {
5860                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5861                 return;
5862         } else
5863                 printf("\tPrimary: [%d]\n", primary_id);
5864
5865 }
5866
5867 cmdline_parse_token_string_t cmd_showbonding_config_show =
5868 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5869                 show, "show");
5870 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5871 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5872                 bonding, "bonding");
5873 cmdline_parse_token_string_t cmd_showbonding_config_config =
5874 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5875                 config, "config");
5876 cmdline_parse_token_num_t cmd_showbonding_config_port =
5877 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5878                 port_id, UINT16);
5879
5880 cmdline_parse_inst_t cmd_show_bonding_config = {
5881                 .f = cmd_show_bonding_config_parsed,
5882                 .help_str = "show bonding config <port_id>: "
5883                         "Show the bonding config for port_id",
5884                 .data = NULL,
5885                 .tokens = {
5886                                 (void *)&cmd_showbonding_config_show,
5887                                 (void *)&cmd_showbonding_config_bonding,
5888                                 (void *)&cmd_showbonding_config_config,
5889                                 (void *)&cmd_showbonding_config_port,
5890                                 NULL
5891                 }
5892 };
5893
5894 /* *** SET BONDING PRIMARY *** */
5895 struct cmd_set_bonding_primary_result {
5896         cmdline_fixed_string_t set;
5897         cmdline_fixed_string_t bonding;
5898         cmdline_fixed_string_t primary;
5899         portid_t slave_id;
5900         portid_t port_id;
5901 };
5902
5903 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5904                 __attribute__((unused))  struct cmdline *cl,
5905                 __attribute__((unused)) void *data)
5906 {
5907         struct cmd_set_bonding_primary_result *res = parsed_result;
5908         portid_t master_port_id = res->port_id;
5909         portid_t slave_port_id = res->slave_id;
5910
5911         /* Set the primary slave for a bonded device. */
5912         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5913                 printf("\t Failed to set primary slave for port = %d.\n",
5914                                 master_port_id);
5915                 return;
5916         }
5917         init_port_config();
5918 }
5919
5920 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5922                 set, "set");
5923 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5925                 bonding, "bonding");
5926 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5928                 primary, "primary");
5929 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5930 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5931                 slave_id, UINT16);
5932 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5933 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5934                 port_id, UINT16);
5935
5936 cmdline_parse_inst_t cmd_set_bonding_primary = {
5937                 .f = cmd_set_bonding_primary_parsed,
5938                 .help_str = "set bonding primary <slave_id> <port_id>: "
5939                         "Set the primary slave for port_id",
5940                 .data = NULL,
5941                 .tokens = {
5942                                 (void *)&cmd_setbonding_primary_set,
5943                                 (void *)&cmd_setbonding_primary_bonding,
5944                                 (void *)&cmd_setbonding_primary_primary,
5945                                 (void *)&cmd_setbonding_primary_slave,
5946                                 (void *)&cmd_setbonding_primary_port,
5947                                 NULL
5948                 }
5949 };
5950
5951 /* *** ADD SLAVE *** */
5952 struct cmd_add_bonding_slave_result {
5953         cmdline_fixed_string_t add;
5954         cmdline_fixed_string_t bonding;
5955         cmdline_fixed_string_t slave;
5956         portid_t slave_id;
5957         portid_t port_id;
5958 };
5959
5960 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5961                 __attribute__((unused))  struct cmdline *cl,
5962                 __attribute__((unused)) void *data)
5963 {
5964         struct cmd_add_bonding_slave_result *res = parsed_result;
5965         portid_t master_port_id = res->port_id;
5966         portid_t slave_port_id = res->slave_id;
5967
5968         /* add the slave for a bonded device. */
5969         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5970                 printf("\t Failed to add slave %d to master port = %d.\n",
5971                                 slave_port_id, master_port_id);
5972                 return;
5973         }
5974         init_port_config();
5975         set_port_slave_flag(slave_port_id);
5976 }
5977
5978 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5979 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5980                 add, "add");
5981 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5982 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5983                 bonding, "bonding");
5984 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5985 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5986                 slave, "slave");
5987 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5988 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5989                 slave_id, UINT16);
5990 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5991 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5992                 port_id, UINT16);
5993
5994 cmdline_parse_inst_t cmd_add_bonding_slave = {
5995                 .f = cmd_add_bonding_slave_parsed,
5996                 .help_str = "add bonding slave <slave_id> <port_id>: "
5997                         "Add a slave device to a bonded device",
5998                 .data = NULL,
5999                 .tokens = {
6000                                 (void *)&cmd_addbonding_slave_add,
6001                                 (void *)&cmd_addbonding_slave_bonding,
6002                                 (void *)&cmd_addbonding_slave_slave,
6003                                 (void *)&cmd_addbonding_slave_slaveid,
6004                                 (void *)&cmd_addbonding_slave_port,
6005                                 NULL
6006                 }
6007 };
6008
6009 /* *** REMOVE SLAVE *** */
6010 struct cmd_remove_bonding_slave_result {
6011         cmdline_fixed_string_t remove;
6012         cmdline_fixed_string_t bonding;
6013         cmdline_fixed_string_t slave;
6014         portid_t slave_id;
6015         portid_t port_id;
6016 };
6017
6018 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6019                 __attribute__((unused))  struct cmdline *cl,
6020                 __attribute__((unused)) void *data)
6021 {
6022         struct cmd_remove_bonding_slave_result *res = parsed_result;
6023         portid_t master_port_id = res->port_id;
6024         portid_t slave_port_id = res->slave_id;
6025
6026         /* remove the slave from a bonded device. */
6027         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6028                 printf("\t Failed to remove slave %d from master port = %d.\n",
6029                                 slave_port_id, master_port_id);
6030                 return;
6031         }
6032         init_port_config();
6033         clear_port_slave_flag(slave_port_id);
6034 }
6035
6036 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6037                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6038                                 remove, "remove");
6039 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6040                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6041                                 bonding, "bonding");
6042 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6043                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6044                                 slave, "slave");
6045 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6046                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6047                                 slave_id, UINT16);
6048 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6049                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6050                                 port_id, UINT16);
6051
6052 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6053                 .f = cmd_remove_bonding_slave_parsed,
6054                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6055                         "Remove a slave device from a bonded device",
6056                 .data = NULL,
6057                 .tokens = {
6058                                 (void *)&cmd_removebonding_slave_remove,
6059                                 (void *)&cmd_removebonding_slave_bonding,
6060                                 (void *)&cmd_removebonding_slave_slave,
6061                                 (void *)&cmd_removebonding_slave_slaveid,
6062                                 (void *)&cmd_removebonding_slave_port,
6063                                 NULL
6064                 }
6065 };
6066
6067 /* *** CREATE BONDED DEVICE *** */
6068 struct cmd_create_bonded_device_result {
6069         cmdline_fixed_string_t create;
6070         cmdline_fixed_string_t bonded;
6071         cmdline_fixed_string_t device;
6072         uint8_t mode;
6073         uint8_t socket;
6074 };
6075
6076 static int bond_dev_num = 0;
6077
6078 static void cmd_create_bonded_device_parsed(void *parsed_result,
6079                 __attribute__((unused))  struct cmdline *cl,
6080                 __attribute__((unused)) void *data)
6081 {
6082         struct cmd_create_bonded_device_result *res = parsed_result;
6083         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6084         int port_id;
6085         int ret;
6086
6087         if (test_done == 0) {
6088                 printf("Please stop forwarding first\n");
6089                 return;
6090         }
6091
6092         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6093                         bond_dev_num++);
6094
6095         /* Create a new bonded device. */
6096         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6097         if (port_id < 0) {
6098                 printf("\t Failed to create bonded device.\n");
6099                 return;
6100         } else {
6101                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6102                                 port_id);
6103
6104                 /* Update number of ports */
6105                 nb_ports = rte_eth_dev_count_avail();
6106                 reconfig(port_id, res->socket);
6107                 ret = rte_eth_promiscuous_enable(port_id);
6108                 if (ret != 0)
6109                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6110                                 port_id, rte_strerror(-ret));
6111
6112                 ports[port_id].need_setup = 0;
6113                 ports[port_id].port_status = RTE_PORT_STOPPED;
6114         }
6115
6116 }
6117
6118 cmdline_parse_token_string_t cmd_createbonded_device_create =
6119                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6120                                 create, "create");
6121 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6122                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6123                                 bonded, "bonded");
6124 cmdline_parse_token_string_t cmd_createbonded_device_device =
6125                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6126                                 device, "device");
6127 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6128                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6129                                 mode, UINT8);
6130 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6131                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6132                                 socket, UINT8);
6133
6134 cmdline_parse_inst_t cmd_create_bonded_device = {
6135                 .f = cmd_create_bonded_device_parsed,
6136                 .help_str = "create bonded device <mode> <socket>: "
6137                         "Create a new bonded device with specific bonding mode and socket",
6138                 .data = NULL,
6139                 .tokens = {
6140                                 (void *)&cmd_createbonded_device_create,
6141                                 (void *)&cmd_createbonded_device_bonded,
6142                                 (void *)&cmd_createbonded_device_device,
6143                                 (void *)&cmd_createbonded_device_mode,
6144                                 (void *)&cmd_createbonded_device_socket,
6145                                 NULL
6146                 }
6147 };
6148
6149 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6150 struct cmd_set_bond_mac_addr_result {
6151         cmdline_fixed_string_t set;
6152         cmdline_fixed_string_t bonding;
6153         cmdline_fixed_string_t mac_addr;
6154         uint16_t port_num;
6155         struct rte_ether_addr address;
6156 };
6157
6158 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6159                 __attribute__((unused))  struct cmdline *cl,
6160                 __attribute__((unused)) void *data)
6161 {
6162         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6163         int ret;
6164
6165         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6166                 return;
6167
6168         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6169
6170         /* check the return value and print it if is < 0 */
6171         if (ret < 0)
6172                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6173 }
6174
6175 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6176                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6177 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6178                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6179                                 "bonding");
6180 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6181                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6182                                 "mac_addr");
6183 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6184                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6185                                 port_num, UINT16);
6186 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6187                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6188
6189 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6190                 .f = cmd_set_bond_mac_addr_parsed,
6191                 .data = (void *) 0,
6192                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6193                 .tokens = {
6194                                 (void *)&cmd_set_bond_mac_addr_set,
6195                                 (void *)&cmd_set_bond_mac_addr_bonding,
6196                                 (void *)&cmd_set_bond_mac_addr_mac,
6197                                 (void *)&cmd_set_bond_mac_addr_portnum,
6198                                 (void *)&cmd_set_bond_mac_addr_addr,
6199                                 NULL
6200                 }
6201 };
6202
6203
6204 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6205 struct cmd_set_bond_mon_period_result {
6206         cmdline_fixed_string_t set;
6207         cmdline_fixed_string_t bonding;
6208         cmdline_fixed_string_t mon_period;
6209         uint16_t port_num;
6210         uint32_t period_ms;
6211 };
6212
6213 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6214                 __attribute__((unused))  struct cmdline *cl,
6215                 __attribute__((unused)) void *data)
6216 {
6217         struct cmd_set_bond_mon_period_result *res = parsed_result;
6218         int ret;
6219
6220         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6221
6222         /* check the return value and print it if is < 0 */
6223         if (ret < 0)
6224                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6225 }
6226
6227 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6228                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6229                                 set, "set");
6230 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6231                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6232                                 bonding, "bonding");
6233 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6234                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6235                                 mon_period,     "mon_period");
6236 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6237                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6238                                 port_num, UINT16);
6239 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6240                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6241                                 period_ms, UINT32);
6242
6243 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6244                 .f = cmd_set_bond_mon_period_parsed,
6245                 .data = (void *) 0,
6246                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6247                 .tokens = {
6248                                 (void *)&cmd_set_bond_mon_period_set,
6249                                 (void *)&cmd_set_bond_mon_period_bonding,
6250                                 (void *)&cmd_set_bond_mon_period_mon_period,
6251                                 (void *)&cmd_set_bond_mon_period_portnum,
6252                                 (void *)&cmd_set_bond_mon_period_period_ms,
6253                                 NULL
6254                 }
6255 };
6256
6257
6258
6259 struct cmd_set_bonding_agg_mode_policy_result {
6260         cmdline_fixed_string_t set;
6261         cmdline_fixed_string_t bonding;
6262         cmdline_fixed_string_t agg_mode;
6263         uint16_t port_num;
6264         cmdline_fixed_string_t policy;
6265 };
6266
6267
6268 static void
6269 cmd_set_bonding_agg_mode(void *parsed_result,
6270                 __attribute__((unused)) struct cmdline *cl,
6271                 __attribute__((unused)) void *data)
6272 {
6273         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6274         uint8_t policy = AGG_BANDWIDTH;
6275
6276         if (!strcmp(res->policy, "bandwidth"))
6277                 policy = AGG_BANDWIDTH;
6278         else if (!strcmp(res->policy, "stable"))
6279                 policy = AGG_STABLE;
6280         else if (!strcmp(res->policy, "count"))
6281                 policy = AGG_COUNT;
6282
6283         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6284 }
6285
6286
6287 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6288         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6289                                 set, "set");
6290 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6291         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6292                                 bonding, "bonding");
6293
6294 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6295         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6296                                 agg_mode, "agg_mode");
6297
6298 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6299         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6300                                 port_num, UINT16);
6301
6302 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6303         TOKEN_STRING_INITIALIZER(
6304                         struct cmd_set_bonding_balance_xmit_policy_result,
6305                 policy, "stable#bandwidth#count");
6306
6307 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6308         .f = cmd_set_bonding_agg_mode,
6309         .data = (void *) 0,
6310         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6311         .tokens = {
6312                         (void *)&cmd_set_bonding_agg_mode_set,
6313                         (void *)&cmd_set_bonding_agg_mode_bonding,
6314                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6315                         (void *)&cmd_set_bonding_agg_mode_portnum,
6316                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6317                         NULL
6318                 }
6319 };
6320
6321
6322 #endif /* RTE_LIBRTE_PMD_BOND */
6323
6324 /* *** SET FORWARDING MODE *** */
6325 struct cmd_set_fwd_mode_result {
6326         cmdline_fixed_string_t set;
6327         cmdline_fixed_string_t fwd;
6328         cmdline_fixed_string_t mode;
6329 };
6330
6331 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6332                                     __attribute__((unused)) struct cmdline *cl,
6333                                     __attribute__((unused)) void *data)
6334 {
6335         struct cmd_set_fwd_mode_result *res = parsed_result;
6336
6337         retry_enabled = 0;
6338         set_pkt_forwarding_mode(res->mode);
6339 }
6340
6341 cmdline_parse_token_string_t cmd_setfwd_set =
6342         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6343 cmdline_parse_token_string_t cmd_setfwd_fwd =
6344         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6345 cmdline_parse_token_string_t cmd_setfwd_mode =
6346         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6347                 "" /* defined at init */);
6348
6349 cmdline_parse_inst_t cmd_set_fwd_mode = {
6350         .f = cmd_set_fwd_mode_parsed,
6351         .data = NULL,
6352         .help_str = NULL, /* defined at init */
6353         .tokens = {
6354                 (void *)&cmd_setfwd_set,
6355                 (void *)&cmd_setfwd_fwd,
6356                 (void *)&cmd_setfwd_mode,
6357                 NULL,
6358         },
6359 };
6360
6361 static void cmd_set_fwd_mode_init(void)
6362 {
6363         char *modes, *c;
6364         static char token[128];
6365         static char help[256];
6366         cmdline_parse_token_string_t *token_struct;
6367
6368         modes = list_pkt_forwarding_modes();
6369         snprintf(help, sizeof(help), "set fwd %s: "
6370                 "Set packet forwarding mode", modes);
6371         cmd_set_fwd_mode.help_str = help;
6372
6373         /* string token separator is # */
6374         for (c = token; *modes != '\0'; modes++)
6375                 if (*modes == '|')
6376                         *c++ = '#';
6377                 else
6378                         *c++ = *modes;
6379         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6380         token_struct->string_data.str = token;
6381 }
6382
6383 /* *** SET RETRY FORWARDING MODE *** */
6384 struct cmd_set_fwd_retry_mode_result {
6385         cmdline_fixed_string_t set;
6386         cmdline_fixed_string_t fwd;
6387         cmdline_fixed_string_t mode;
6388         cmdline_fixed_string_t retry;
6389 };
6390
6391 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6392                             __attribute__((unused)) struct cmdline *cl,
6393                             __attribute__((unused)) void *data)
6394 {
6395         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6396
6397         retry_enabled = 1;
6398         set_pkt_forwarding_mode(res->mode);
6399 }
6400
6401 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6402         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6403                         set, "set");
6404 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6405         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6406                         fwd, "fwd");
6407 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6408         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6409                         mode,
6410                 "" /* defined at init */);
6411 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6412         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6413                         retry, "retry");
6414
6415 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6416         .f = cmd_set_fwd_retry_mode_parsed,
6417         .data = NULL,
6418         .help_str = NULL, /* defined at init */
6419         .tokens = {
6420                 (void *)&cmd_setfwd_retry_set,
6421                 (void *)&cmd_setfwd_retry_fwd,
6422                 (void *)&cmd_setfwd_retry_mode,
6423                 (void *)&cmd_setfwd_retry_retry,
6424                 NULL,
6425         },
6426 };
6427
6428 static void cmd_set_fwd_retry_mode_init(void)
6429 {
6430         char *modes, *c;
6431         static char token[128];
6432         static char help[256];
6433         cmdline_parse_token_string_t *token_struct;
6434
6435         modes = list_pkt_forwarding_retry_modes();
6436         snprintf(help, sizeof(help), "set fwd %s retry: "
6437                 "Set packet forwarding mode with retry", modes);
6438         cmd_set_fwd_retry_mode.help_str = help;
6439
6440         /* string token separator is # */
6441         for (c = token; *modes != '\0'; modes++)
6442                 if (*modes == '|')
6443                         *c++ = '#';
6444                 else
6445                         *c++ = *modes;
6446         token_struct = (cmdline_parse_token_string_t *)
6447                 cmd_set_fwd_retry_mode.tokens[2];
6448         token_struct->string_data.str = token;
6449 }
6450
6451 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6452 struct cmd_set_burst_tx_retry_result {
6453         cmdline_fixed_string_t set;
6454         cmdline_fixed_string_t burst;
6455         cmdline_fixed_string_t tx;
6456         cmdline_fixed_string_t delay;
6457         uint32_t time;
6458         cmdline_fixed_string_t retry;
6459         uint32_t retry_num;
6460 };
6461
6462 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6463                                         __attribute__((unused)) struct cmdline *cl,
6464                                         __attribute__((unused)) void *data)
6465 {
6466         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6467
6468         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6469                 && !strcmp(res->tx, "tx")) {
6470                 if (!strcmp(res->delay, "delay"))
6471                         burst_tx_delay_time = res->time;
6472                 if (!strcmp(res->retry, "retry"))
6473                         burst_tx_retry_num = res->retry_num;
6474         }
6475
6476 }
6477
6478 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6479         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6480 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6481         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6482                                  "burst");
6483 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6485 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6486         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6487 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6488         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6489 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6490         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6491 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6492         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6493
6494 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6495         .f = cmd_set_burst_tx_retry_parsed,
6496         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6497         .tokens = {
6498                 (void *)&cmd_set_burst_tx_retry_set,
6499                 (void *)&cmd_set_burst_tx_retry_burst,
6500                 (void *)&cmd_set_burst_tx_retry_tx,
6501                 (void *)&cmd_set_burst_tx_retry_delay,
6502                 (void *)&cmd_set_burst_tx_retry_time,
6503                 (void *)&cmd_set_burst_tx_retry_retry,
6504                 (void *)&cmd_set_burst_tx_retry_retry_num,
6505                 NULL,
6506         },
6507 };
6508
6509 /* *** SET PROMISC MODE *** */
6510 struct cmd_set_promisc_mode_result {
6511         cmdline_fixed_string_t set;
6512         cmdline_fixed_string_t promisc;
6513         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6514         uint16_t port_num;               /* valid if "allports" argument == 0 */
6515         cmdline_fixed_string_t mode;
6516 };
6517
6518 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6519                                         __attribute__((unused)) struct cmdline *cl,
6520                                         void *allports)
6521 {
6522         struct cmd_set_promisc_mode_result *res = parsed_result;
6523         int enable;
6524         portid_t i;
6525
6526         if (!strcmp(res->mode, "on"))
6527                 enable = 1;
6528         else
6529                 enable = 0;
6530
6531         /* all ports */
6532         if (allports) {
6533                 RTE_ETH_FOREACH_DEV(i)
6534                         eth_set_promisc_mode(i, enable);
6535         } else {
6536                 eth_set_promisc_mode(res->port_num, enable);
6537         }
6538 }
6539
6540 cmdline_parse_token_string_t cmd_setpromisc_set =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6542 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6543         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6544                                  "promisc");
6545 cmdline_parse_token_string_t cmd_setpromisc_portall =
6546         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6547                                  "all");
6548 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6549         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6550                               UINT16);
6551 cmdline_parse_token_string_t cmd_setpromisc_mode =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6553                                  "on#off");
6554
6555 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6556         .f = cmd_set_promisc_mode_parsed,
6557         .data = (void *)1,
6558         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6559         .tokens = {
6560                 (void *)&cmd_setpromisc_set,
6561                 (void *)&cmd_setpromisc_promisc,
6562                 (void *)&cmd_setpromisc_portall,
6563                 (void *)&cmd_setpromisc_mode,
6564                 NULL,
6565         },
6566 };
6567
6568 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6569         .f = cmd_set_promisc_mode_parsed,
6570         .data = (void *)0,
6571         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6572         .tokens = {
6573                 (void *)&cmd_setpromisc_set,
6574                 (void *)&cmd_setpromisc_promisc,
6575                 (void *)&cmd_setpromisc_portnum,
6576                 (void *)&cmd_setpromisc_mode,
6577                 NULL,
6578         },
6579 };
6580
6581 /* *** SET ALLMULTI MODE *** */
6582 struct cmd_set_allmulti_mode_result {
6583         cmdline_fixed_string_t set;
6584         cmdline_fixed_string_t allmulti;
6585         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6586         uint16_t port_num;               /* valid if "allports" argument == 0 */
6587         cmdline_fixed_string_t mode;
6588 };
6589
6590 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6591                                         __attribute__((unused)) struct cmdline *cl,
6592                                         void *allports)
6593 {
6594         struct cmd_set_allmulti_mode_result *res = parsed_result;
6595         int enable;
6596         portid_t i;
6597
6598         if (!strcmp(res->mode, "on"))
6599                 enable = 1;
6600         else
6601                 enable = 0;
6602
6603         /* all ports */
6604         if (allports) {
6605                 RTE_ETH_FOREACH_DEV(i) {
6606                         if (enable)
6607                                 rte_eth_allmulticast_enable(i);
6608                         else
6609                                 rte_eth_allmulticast_disable(i);
6610                 }
6611         }
6612         else {
6613                 if (enable)
6614                         rte_eth_allmulticast_enable(res->port_num);
6615                 else
6616                         rte_eth_allmulticast_disable(res->port_num);
6617         }
6618 }
6619
6620 cmdline_parse_token_string_t cmd_setallmulti_set =
6621         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6622 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6623         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6624                                  "allmulti");
6625 cmdline_parse_token_string_t cmd_setallmulti_portall =
6626         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6627                                  "all");
6628 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6629         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6630                               UINT16);
6631 cmdline_parse_token_string_t cmd_setallmulti_mode =
6632         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6633                                  "on#off");
6634
6635 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6636         .f = cmd_set_allmulti_mode_parsed,
6637         .data = (void *)1,
6638         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6639         .tokens = {
6640                 (void *)&cmd_setallmulti_set,
6641                 (void *)&cmd_setallmulti_allmulti,
6642                 (void *)&cmd_setallmulti_portall,
6643                 (void *)&cmd_setallmulti_mode,
6644                 NULL,
6645         },
6646 };
6647
6648 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6649         .f = cmd_set_allmulti_mode_parsed,
6650         .data = (void *)0,
6651         .help_str = "set allmulti <port_id> on|off: "
6652                 "Set allmulti mode on port_id",
6653         .tokens = {
6654                 (void *)&cmd_setallmulti_set,
6655                 (void *)&cmd_setallmulti_allmulti,
6656                 (void *)&cmd_setallmulti_portnum,
6657                 (void *)&cmd_setallmulti_mode,
6658                 NULL,
6659         },
6660 };
6661
6662 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6663 struct cmd_link_flow_ctrl_set_result {
6664         cmdline_fixed_string_t set;
6665         cmdline_fixed_string_t flow_ctrl;
6666         cmdline_fixed_string_t rx;
6667         cmdline_fixed_string_t rx_lfc_mode;
6668         cmdline_fixed_string_t tx;
6669         cmdline_fixed_string_t tx_lfc_mode;
6670         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6671         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6672         cmdline_fixed_string_t autoneg_str;
6673         cmdline_fixed_string_t autoneg;
6674         cmdline_fixed_string_t hw_str;
6675         uint32_t high_water;
6676         cmdline_fixed_string_t lw_str;
6677         uint32_t low_water;
6678         cmdline_fixed_string_t pt_str;
6679         uint16_t pause_time;
6680         cmdline_fixed_string_t xon_str;
6681         uint16_t send_xon;
6682         portid_t port_id;
6683 };
6684
6685 cmdline_parse_token_string_t cmd_lfc_set_set =
6686         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6687                                 set, "set");
6688 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6689         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6690                                 flow_ctrl, "flow_ctrl");
6691 cmdline_parse_token_string_t cmd_lfc_set_rx =
6692         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6693                                 rx, "rx");
6694 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6695         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6696                                 rx_lfc_mode, "on#off");
6697 cmdline_parse_token_string_t cmd_lfc_set_tx =
6698         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6699                                 tx, "tx");
6700 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6701         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6702                                 tx_lfc_mode, "on#off");
6703 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6704         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6705                                 hw_str, "high_water");
6706 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6707         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6708                                 high_water, UINT32);
6709 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6710         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6711                                 lw_str, "low_water");
6712 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6713         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6714                                 low_water, UINT32);
6715 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6716         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6717                                 pt_str, "pause_time");
6718 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6719         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6720                                 pause_time, UINT16);
6721 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6722         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6723                                 xon_str, "send_xon");
6724 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6725         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6726                                 send_xon, UINT16);
6727 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6728         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6729                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6730 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6731         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6732                                 mac_ctrl_frame_fwd_mode, "on#off");
6733 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6734         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6735                                 autoneg_str, "autoneg");
6736 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6737         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6738                                 autoneg, "on#off");
6739 cmdline_parse_token_num_t cmd_lfc_set_portid =
6740         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6741                                 port_id, UINT16);
6742
6743 /* forward declaration */
6744 static void
6745 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6746                               void *data);
6747
6748 cmdline_parse_inst_t cmd_link_flow_control_set = {
6749         .f = cmd_link_flow_ctrl_set_parsed,
6750         .data = NULL,
6751         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6752                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6753                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6754         .tokens = {
6755                 (void *)&cmd_lfc_set_set,
6756                 (void *)&cmd_lfc_set_flow_ctrl,
6757                 (void *)&cmd_lfc_set_rx,
6758                 (void *)&cmd_lfc_set_rx_mode,
6759                 (void *)&cmd_lfc_set_tx,
6760                 (void *)&cmd_lfc_set_tx_mode,
6761                 (void *)&cmd_lfc_set_high_water,
6762                 (void *)&cmd_lfc_set_low_water,
6763                 (void *)&cmd_lfc_set_pause_time,
6764                 (void *)&cmd_lfc_set_send_xon,
6765                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6766                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6767                 (void *)&cmd_lfc_set_autoneg_str,
6768                 (void *)&cmd_lfc_set_autoneg,
6769                 (void *)&cmd_lfc_set_portid,
6770                 NULL,
6771         },
6772 };
6773
6774 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6775         .f = cmd_link_flow_ctrl_set_parsed,
6776         .data = (void *)&cmd_link_flow_control_set_rx,
6777         .help_str = "set flow_ctrl rx on|off <port_id>: "
6778                 "Change rx flow control parameter",
6779         .tokens = {
6780                 (void *)&cmd_lfc_set_set,
6781                 (void *)&cmd_lfc_set_flow_ctrl,
6782                 (void *)&cmd_lfc_set_rx,
6783                 (void *)&cmd_lfc_set_rx_mode,
6784                 (void *)&cmd_lfc_set_portid,
6785                 NULL,
6786         },
6787 };
6788
6789 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6790         .f = cmd_link_flow_ctrl_set_parsed,
6791         .data = (void *)&cmd_link_flow_control_set_tx,
6792         .help_str = "set flow_ctrl tx on|off <port_id>: "
6793                 "Change tx flow control parameter",
6794         .tokens = {
6795                 (void *)&cmd_lfc_set_set,
6796                 (void *)&cmd_lfc_set_flow_ctrl,
6797                 (void *)&cmd_lfc_set_tx,
6798                 (void *)&cmd_lfc_set_tx_mode,
6799                 (void *)&cmd_lfc_set_portid,
6800                 NULL,
6801         },
6802 };
6803
6804 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6805         .f = cmd_link_flow_ctrl_set_parsed,
6806         .data = (void *)&cmd_link_flow_control_set_hw,
6807         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6808                 "Change high water flow control parameter",
6809         .tokens = {
6810                 (void *)&cmd_lfc_set_set,
6811                 (void *)&cmd_lfc_set_flow_ctrl,
6812                 (void *)&cmd_lfc_set_high_water_str,
6813                 (void *)&cmd_lfc_set_high_water,
6814                 (void *)&cmd_lfc_set_portid,
6815                 NULL,
6816         },
6817 };
6818
6819 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6820         .f = cmd_link_flow_ctrl_set_parsed,
6821         .data = (void *)&cmd_link_flow_control_set_lw,
6822         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6823                 "Change low water flow control parameter",
6824         .tokens = {
6825                 (void *)&cmd_lfc_set_set,
6826                 (void *)&cmd_lfc_set_flow_ctrl,
6827                 (void *)&cmd_lfc_set_low_water_str,
6828                 (void *)&cmd_lfc_set_low_water,
6829                 (void *)&cmd_lfc_set_portid,
6830                 NULL,
6831         },
6832 };
6833
6834 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6835         .f = cmd_link_flow_ctrl_set_parsed,
6836         .data = (void *)&cmd_link_flow_control_set_pt,
6837         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6838                 "Change pause time flow control parameter",
6839         .tokens = {
6840                 (void *)&cmd_lfc_set_set,
6841                 (void *)&cmd_lfc_set_flow_ctrl,
6842                 (void *)&cmd_lfc_set_pause_time_str,
6843                 (void *)&cmd_lfc_set_pause_time,
6844                 (void *)&cmd_lfc_set_portid,
6845                 NULL,
6846         },
6847 };
6848
6849 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6850         .f = cmd_link_flow_ctrl_set_parsed,
6851         .data = (void *)&cmd_link_flow_control_set_xon,
6852         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6853                 "Change send_xon flow control parameter",
6854         .tokens = {
6855                 (void *)&cmd_lfc_set_set,
6856                 (void *)&cmd_lfc_set_flow_ctrl,
6857                 (void *)&cmd_lfc_set_send_xon_str,
6858                 (void *)&cmd_lfc_set_send_xon,
6859                 (void *)&cmd_lfc_set_portid,
6860                 NULL,
6861         },
6862 };
6863
6864 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6865         .f = cmd_link_flow_ctrl_set_parsed,
6866         .data = (void *)&cmd_link_flow_control_set_macfwd,
6867         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6868                 "Change mac ctrl fwd flow control parameter",
6869         .tokens = {
6870                 (void *)&cmd_lfc_set_set,
6871                 (void *)&cmd_lfc_set_flow_ctrl,
6872                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6873                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6874                 (void *)&cmd_lfc_set_portid,
6875                 NULL,
6876         },
6877 };
6878
6879 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6880         .f = cmd_link_flow_ctrl_set_parsed,
6881         .data = (void *)&cmd_link_flow_control_set_autoneg,
6882         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6883                 "Change autoneg flow control parameter",
6884         .tokens = {
6885                 (void *)&cmd_lfc_set_set,
6886                 (void *)&cmd_lfc_set_flow_ctrl,
6887                 (void *)&cmd_lfc_set_autoneg_str,
6888                 (void *)&cmd_lfc_set_autoneg,
6889                 (void *)&cmd_lfc_set_portid,
6890                 NULL,
6891         },
6892 };
6893
6894 static void
6895 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6896                               __attribute__((unused)) struct cmdline *cl,
6897                               void *data)
6898 {
6899         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6900         cmdline_parse_inst_t *cmd = data;
6901         struct rte_eth_fc_conf fc_conf;
6902         int rx_fc_en = 0;
6903         int tx_fc_en = 0;
6904         int ret;
6905
6906         /*
6907          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6908          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6909          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6910          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6911          */
6912         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6913                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6914         };
6915
6916         /* Partial command line, retrieve current configuration */
6917         if (cmd) {
6918                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6919                 if (ret != 0) {
6920                         printf("cannot get current flow ctrl parameters, return"
6921                                "code = %d\n", ret);
6922                         return;
6923                 }
6924
6925                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6926                     (fc_conf.mode == RTE_FC_FULL))
6927                         rx_fc_en = 1;
6928                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6929                     (fc_conf.mode == RTE_FC_FULL))
6930                         tx_fc_en = 1;
6931         }
6932
6933         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6934                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6935
6936         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6937                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6938
6939         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6940
6941         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6942                 fc_conf.high_water = res->high_water;
6943
6944         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6945                 fc_conf.low_water = res->low_water;
6946
6947         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6948                 fc_conf.pause_time = res->pause_time;
6949
6950         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6951                 fc_conf.send_xon = res->send_xon;
6952
6953         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6954                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6955                         fc_conf.mac_ctrl_frame_fwd = 1;
6956                 else
6957                         fc_conf.mac_ctrl_frame_fwd = 0;
6958         }
6959
6960         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6961                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6962
6963         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6964         if (ret != 0)
6965                 printf("bad flow contrl parameter, return code = %d \n", ret);
6966 }
6967
6968 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6969 struct cmd_priority_flow_ctrl_set_result {
6970         cmdline_fixed_string_t set;
6971         cmdline_fixed_string_t pfc_ctrl;
6972         cmdline_fixed_string_t rx;
6973         cmdline_fixed_string_t rx_pfc_mode;
6974         cmdline_fixed_string_t tx;
6975         cmdline_fixed_string_t tx_pfc_mode;
6976         uint32_t high_water;
6977         uint32_t low_water;
6978         uint16_t pause_time;
6979         uint8_t  priority;
6980         portid_t port_id;
6981 };
6982
6983 static void
6984 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6985                        __attribute__((unused)) struct cmdline *cl,
6986                        __attribute__((unused)) void *data)
6987 {
6988         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6989         struct rte_eth_pfc_conf pfc_conf;
6990         int rx_fc_enable, tx_fc_enable;
6991         int ret;
6992
6993         /*
6994          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6995          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6996          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6997          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6998          */
6999         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7000                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7001         };
7002
7003         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7004         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7005         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7006         pfc_conf.fc.high_water = res->high_water;
7007         pfc_conf.fc.low_water  = res->low_water;
7008         pfc_conf.fc.pause_time = res->pause_time;
7009         pfc_conf.priority      = res->priority;
7010
7011         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7012         if (ret != 0)
7013                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7014 }
7015
7016 cmdline_parse_token_string_t cmd_pfc_set_set =
7017         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7018                                 set, "set");
7019 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7020         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7021                                 pfc_ctrl, "pfc_ctrl");
7022 cmdline_parse_token_string_t cmd_pfc_set_rx =
7023         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7024                                 rx, "rx");
7025 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7026         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7027                                 rx_pfc_mode, "on#off");
7028 cmdline_parse_token_string_t cmd_pfc_set_tx =
7029         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7030                                 tx, "tx");
7031 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7032         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7033                                 tx_pfc_mode, "on#off");
7034 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7035         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7036                                 high_water, UINT32);
7037 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7038         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7039                                 low_water, UINT32);
7040 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7041         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7042                                 pause_time, UINT16);
7043 cmdline_parse_token_num_t cmd_pfc_set_priority =
7044         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7045                                 priority, UINT8);
7046 cmdline_parse_token_num_t cmd_pfc_set_portid =
7047         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7048                                 port_id, UINT16);
7049
7050 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7051         .f = cmd_priority_flow_ctrl_set_parsed,
7052         .data = NULL,
7053         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7054                 "<pause_time> <priority> <port_id>: "
7055                 "Configure the Ethernet priority flow control",
7056         .tokens = {
7057                 (void *)&cmd_pfc_set_set,
7058                 (void *)&cmd_pfc_set_flow_ctrl,
7059                 (void *)&cmd_pfc_set_rx,
7060                 (void *)&cmd_pfc_set_rx_mode,
7061                 (void *)&cmd_pfc_set_tx,
7062                 (void *)&cmd_pfc_set_tx_mode,
7063                 (void *)&cmd_pfc_set_high_water,
7064                 (void *)&cmd_pfc_set_low_water,
7065                 (void *)&cmd_pfc_set_pause_time,
7066                 (void *)&cmd_pfc_set_priority,
7067                 (void *)&cmd_pfc_set_portid,
7068                 NULL,
7069         },
7070 };
7071
7072 /* *** RESET CONFIGURATION *** */
7073 struct cmd_reset_result {
7074         cmdline_fixed_string_t reset;
7075         cmdline_fixed_string_t def;
7076 };
7077
7078 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7079                              struct cmdline *cl,
7080                              __attribute__((unused)) void *data)
7081 {
7082         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7083         set_def_fwd_config();
7084 }
7085
7086 cmdline_parse_token_string_t cmd_reset_set =
7087         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7088 cmdline_parse_token_string_t cmd_reset_def =
7089         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7090                                  "default");
7091
7092 cmdline_parse_inst_t cmd_reset = {
7093         .f = cmd_reset_parsed,
7094         .data = NULL,
7095         .help_str = "set default: Reset default forwarding configuration",
7096         .tokens = {
7097                 (void *)&cmd_reset_set,
7098                 (void *)&cmd_reset_def,
7099                 NULL,
7100         },
7101 };
7102
7103 /* *** START FORWARDING *** */
7104 struct cmd_start_result {
7105         cmdline_fixed_string_t start;
7106 };
7107
7108 cmdline_parse_token_string_t cmd_start_start =
7109         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7110
7111 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7112                              __attribute__((unused)) struct cmdline *cl,
7113                              __attribute__((unused)) void *data)
7114 {
7115         start_packet_forwarding(0);
7116 }
7117
7118 cmdline_parse_inst_t cmd_start = {
7119         .f = cmd_start_parsed,
7120         .data = NULL,
7121         .help_str = "start: Start packet forwarding",
7122         .tokens = {
7123                 (void *)&cmd_start_start,
7124                 NULL,
7125         },
7126 };
7127
7128 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7129 struct cmd_start_tx_first_result {
7130         cmdline_fixed_string_t start;
7131         cmdline_fixed_string_t tx_first;
7132 };
7133
7134 static void
7135 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7136                           __attribute__((unused)) struct cmdline *cl,
7137                           __attribute__((unused)) void *data)
7138 {
7139         start_packet_forwarding(1);
7140 }
7141
7142 cmdline_parse_token_string_t cmd_start_tx_first_start =
7143         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7144                                  "start");
7145 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7146         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7147                                  tx_first, "tx_first");
7148
7149 cmdline_parse_inst_t cmd_start_tx_first = {
7150         .f = cmd_start_tx_first_parsed,
7151         .data = NULL,
7152         .help_str = "start tx_first: Start packet forwarding, "
7153                 "after sending 1 burst of packets",
7154         .tokens = {
7155                 (void *)&cmd_start_tx_first_start,
7156                 (void *)&cmd_start_tx_first_tx_first,
7157                 NULL,
7158         },
7159 };
7160
7161 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7162 struct cmd_start_tx_first_n_result {
7163         cmdline_fixed_string_t start;
7164         cmdline_fixed_string_t tx_first;
7165         uint32_t tx_num;
7166 };
7167
7168 static void
7169 cmd_start_tx_first_n_parsed(void *parsed_result,
7170                           __attribute__((unused)) struct cmdline *cl,
7171                           __attribute__((unused)) void *data)
7172 {
7173         struct cmd_start_tx_first_n_result *res = parsed_result;
7174
7175         start_packet_forwarding(res->tx_num);
7176 }
7177
7178 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7179         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7180                         start, "start");
7181 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7182         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7183                         tx_first, "tx_first");
7184 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7185         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7186                         tx_num, UINT32);
7187
7188 cmdline_parse_inst_t cmd_start_tx_first_n = {
7189         .f = cmd_start_tx_first_n_parsed,
7190         .data = NULL,
7191         .help_str = "start tx_first <num>: "
7192                 "packet forwarding, after sending <num> bursts of packets",
7193         .tokens = {
7194                 (void *)&cmd_start_tx_first_n_start,
7195                 (void *)&cmd_start_tx_first_n_tx_first,
7196                 (void *)&cmd_start_tx_first_n_tx_num,
7197                 NULL,
7198         },
7199 };
7200
7201 /* *** SET LINK UP *** */
7202 struct cmd_set_link_up_result {
7203         cmdline_fixed_string_t set;
7204         cmdline_fixed_string_t link_up;
7205         cmdline_fixed_string_t port;
7206         portid_t port_id;
7207 };
7208
7209 cmdline_parse_token_string_t cmd_set_link_up_set =
7210         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7211 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7212         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7213                                 "link-up");
7214 cmdline_parse_token_string_t cmd_set_link_up_port =
7215         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7216 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7217         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7218
7219 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7220                              __attribute__((unused)) struct cmdline *cl,
7221                              __attribute__((unused)) void *data)
7222 {
7223         struct cmd_set_link_up_result *res = parsed_result;
7224         dev_set_link_up(res->port_id);
7225 }
7226
7227 cmdline_parse_inst_t cmd_set_link_up = {
7228         .f = cmd_set_link_up_parsed,
7229         .data = NULL,
7230         .help_str = "set link-up port <port id>",
7231         .tokens = {
7232                 (void *)&cmd_set_link_up_set,
7233                 (void *)&cmd_set_link_up_link_up,
7234                 (void *)&cmd_set_link_up_port,
7235                 (void *)&cmd_set_link_up_port_id,
7236                 NULL,
7237         },
7238 };
7239
7240 /* *** SET LINK DOWN *** */
7241 struct cmd_set_link_down_result {
7242         cmdline_fixed_string_t set;
7243         cmdline_fixed_string_t link_down;
7244         cmdline_fixed_string_t port;
7245         portid_t port_id;
7246 };
7247
7248 cmdline_parse_token_string_t cmd_set_link_down_set =
7249         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7250 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7251         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7252                                 "link-down");
7253 cmdline_parse_token_string_t cmd_set_link_down_port =
7254         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7255 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7256         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7257
7258 static void cmd_set_link_down_parsed(
7259                                 __attribute__((unused)) void *parsed_result,
7260                                 __attribute__((unused)) struct cmdline *cl,
7261                                 __attribute__((unused)) void *data)
7262 {
7263         struct cmd_set_link_down_result *res = parsed_result;
7264         dev_set_link_down(res->port_id);
7265 }
7266
7267 cmdline_parse_inst_t cmd_set_link_down = {
7268         .f = cmd_set_link_down_parsed,
7269         .data = NULL,
7270         .help_str = "set link-down port <port id>",
7271         .tokens = {
7272                 (void *)&cmd_set_link_down_set,
7273                 (void *)&cmd_set_link_down_link_down,
7274                 (void *)&cmd_set_link_down_port,
7275                 (void *)&cmd_set_link_down_port_id,
7276                 NULL,
7277         },
7278 };
7279
7280 /* *** SHOW CFG *** */
7281 struct cmd_showcfg_result {
7282         cmdline_fixed_string_t show;
7283         cmdline_fixed_string_t cfg;
7284         cmdline_fixed_string_t what;
7285 };
7286
7287 static void cmd_showcfg_parsed(void *parsed_result,
7288                                __attribute__((unused)) struct cmdline *cl,
7289                                __attribute__((unused)) void *data)
7290 {
7291         struct cmd_showcfg_result *res = parsed_result;
7292         if (!strcmp(res->what, "rxtx"))
7293                 rxtx_config_display();
7294         else if (!strcmp(res->what, "cores"))
7295                 fwd_lcores_config_display();
7296         else if (!strcmp(res->what, "fwd"))
7297                 pkt_fwd_config_display(&cur_fwd_config);
7298         else if (!strcmp(res->what, "txpkts"))
7299                 show_tx_pkt_segments();
7300 }
7301
7302 cmdline_parse_token_string_t cmd_showcfg_show =
7303         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7304 cmdline_parse_token_string_t cmd_showcfg_port =
7305         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7306 cmdline_parse_token_string_t cmd_showcfg_what =
7307         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7308                                  "rxtx#cores#fwd#txpkts");
7309
7310 cmdline_parse_inst_t cmd_showcfg = {
7311         .f = cmd_showcfg_parsed,
7312         .data = NULL,
7313         .help_str = "show config rxtx|cores|fwd|txpkts",
7314         .tokens = {
7315                 (void *)&cmd_showcfg_show,
7316                 (void *)&cmd_showcfg_port,
7317                 (void *)&cmd_showcfg_what,
7318                 NULL,
7319         },
7320 };
7321
7322 /* *** SHOW ALL PORT INFO *** */
7323 struct cmd_showportall_result {
7324         cmdline_fixed_string_t show;
7325         cmdline_fixed_string_t port;
7326         cmdline_fixed_string_t what;
7327         cmdline_fixed_string_t all;
7328 };
7329
7330 static void cmd_showportall_parsed(void *parsed_result,
7331                                 __attribute__((unused)) struct cmdline *cl,
7332                                 __attribute__((unused)) void *data)
7333 {
7334         portid_t i;
7335
7336         struct cmd_showportall_result *res = parsed_result;
7337         if (!strcmp(res->show, "clear")) {
7338                 if (!strcmp(res->what, "stats"))
7339                         RTE_ETH_FOREACH_DEV(i)
7340                                 nic_stats_clear(i);
7341                 else if (!strcmp(res->what, "xstats"))
7342                         RTE_ETH_FOREACH_DEV(i)
7343                                 nic_xstats_clear(i);
7344         } else if (!strcmp(res->what, "info"))
7345                 RTE_ETH_FOREACH_DEV(i)
7346                         port_infos_display(i);
7347         else if (!strcmp(res->what, "summary")) {
7348                 port_summary_header_display();
7349                 RTE_ETH_FOREACH_DEV(i)
7350                         port_summary_display(i);
7351         }
7352         else if (!strcmp(res->what, "stats"))
7353                 RTE_ETH_FOREACH_DEV(i)
7354                         nic_stats_display(i);
7355         else if (!strcmp(res->what, "xstats"))
7356                 RTE_ETH_FOREACH_DEV(i)
7357                         nic_xstats_display(i);
7358         else if (!strcmp(res->what, "fdir"))
7359                 RTE_ETH_FOREACH_DEV(i)
7360                         fdir_get_infos(i);
7361         else if (!strcmp(res->what, "stat_qmap"))
7362                 RTE_ETH_FOREACH_DEV(i)
7363                         nic_stats_mapping_display(i);
7364         else if (!strcmp(res->what, "dcb_tc"))
7365                 RTE_ETH_FOREACH_DEV(i)
7366                         port_dcb_info_display(i);
7367         else if (!strcmp(res->what, "cap"))
7368                 RTE_ETH_FOREACH_DEV(i)
7369                         port_offload_cap_display(i);
7370 }
7371
7372 cmdline_parse_token_string_t cmd_showportall_show =
7373         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7374                                  "show#clear");
7375 cmdline_parse_token_string_t cmd_showportall_port =
7376         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7377 cmdline_parse_token_string_t cmd_showportall_what =
7378         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7379                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7380 cmdline_parse_token_string_t cmd_showportall_all =
7381         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7382 cmdline_parse_inst_t cmd_showportall = {
7383         .f = cmd_showportall_parsed,
7384         .data = NULL,
7385         .help_str = "show|clear port "
7386                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7387         .tokens = {
7388                 (void *)&cmd_showportall_show,
7389                 (void *)&cmd_showportall_port,
7390                 (void *)&cmd_showportall_what,
7391                 (void *)&cmd_showportall_all,
7392                 NULL,
7393         },
7394 };
7395
7396 /* *** SHOW PORT INFO *** */
7397 struct cmd_showport_result {
7398         cmdline_fixed_string_t show;
7399         cmdline_fixed_string_t port;
7400         cmdline_fixed_string_t what;
7401         uint16_t portnum;
7402 };
7403
7404 static void cmd_showport_parsed(void *parsed_result,
7405                                 __attribute__((unused)) struct cmdline *cl,
7406                                 __attribute__((unused)) void *data)
7407 {
7408         struct cmd_showport_result *res = parsed_result;
7409         if (!strcmp(res->show, "clear")) {
7410                 if (!strcmp(res->what, "stats"))
7411                         nic_stats_clear(res->portnum);
7412                 else if (!strcmp(res->what, "xstats"))
7413                         nic_xstats_clear(res->portnum);
7414         } else if (!strcmp(res->what, "info"))
7415                 port_infos_display(res->portnum);
7416         else if (!strcmp(res->what, "summary")) {
7417                 port_summary_header_display();
7418                 port_summary_display(res->portnum);
7419         }
7420         else if (!strcmp(res->what, "stats"))
7421                 nic_stats_display(res->portnum);
7422         else if (!strcmp(res->what, "xstats"))
7423                 nic_xstats_display(res->portnum);
7424         else if (!strcmp(res->what, "fdir"))
7425                  fdir_get_infos(res->portnum);
7426         else if (!strcmp(res->what, "stat_qmap"))
7427                 nic_stats_mapping_display(res->portnum);
7428         else if (!strcmp(res->what, "dcb_tc"))
7429                 port_dcb_info_display(res->portnum);
7430         else if (!strcmp(res->what, "cap"))
7431                 port_offload_cap_display(res->portnum);
7432 }
7433
7434 cmdline_parse_token_string_t cmd_showport_show =
7435         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7436                                  "show#clear");
7437 cmdline_parse_token_string_t cmd_showport_port =
7438         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7439 cmdline_parse_token_string_t cmd_showport_what =
7440         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7441                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7442 cmdline_parse_token_num_t cmd_showport_portnum =
7443         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7444
7445 cmdline_parse_inst_t cmd_showport = {
7446         .f = cmd_showport_parsed,
7447         .data = NULL,
7448         .help_str = "show|clear port "
7449                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7450                 "<port_id>",
7451         .tokens = {
7452                 (void *)&cmd_showport_show,
7453                 (void *)&cmd_showport_port,
7454                 (void *)&cmd_showport_what,
7455                 (void *)&cmd_showport_portnum,
7456                 NULL,
7457         },
7458 };
7459
7460 /* *** SHOW DEVICE INFO *** */
7461 struct cmd_showdevice_result {
7462         cmdline_fixed_string_t show;
7463         cmdline_fixed_string_t device;
7464         cmdline_fixed_string_t what;
7465         cmdline_fixed_string_t identifier;
7466 };
7467
7468 static void cmd_showdevice_parsed(void *parsed_result,
7469                                 __attribute__((unused)) struct cmdline *cl,
7470                                 __attribute__((unused)) void *data)
7471 {
7472         struct cmd_showdevice_result *res = parsed_result;
7473         if (!strcmp(res->what, "info")) {
7474                 if (!strcmp(res->identifier, "all"))
7475                         device_infos_display(NULL);
7476                 else
7477                         device_infos_display(res->identifier);
7478         }
7479 }
7480
7481 cmdline_parse_token_string_t cmd_showdevice_show =
7482         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7483                                  "show");
7484 cmdline_parse_token_string_t cmd_showdevice_device =
7485         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7486 cmdline_parse_token_string_t cmd_showdevice_what =
7487         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7488                                  "info");
7489 cmdline_parse_token_string_t cmd_showdevice_identifier =
7490         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7491                         identifier, NULL);
7492
7493 cmdline_parse_inst_t cmd_showdevice = {
7494         .f = cmd_showdevice_parsed,
7495         .data = NULL,
7496         .help_str = "show device info <identifier>|all",
7497         .tokens = {
7498                 (void *)&cmd_showdevice_show,
7499                 (void *)&cmd_showdevice_device,
7500                 (void *)&cmd_showdevice_what,
7501                 (void *)&cmd_showdevice_identifier,
7502                 NULL,
7503         },
7504 };
7505 /* *** SHOW QUEUE INFO *** */
7506 struct cmd_showqueue_result {
7507         cmdline_fixed_string_t show;
7508         cmdline_fixed_string_t type;
7509         cmdline_fixed_string_t what;
7510         uint16_t portnum;
7511         uint16_t queuenum;
7512 };
7513
7514 static void
7515 cmd_showqueue_parsed(void *parsed_result,
7516         __attribute__((unused)) struct cmdline *cl,
7517         __attribute__((unused)) void *data)
7518 {
7519         struct cmd_showqueue_result *res = parsed_result;
7520
7521         if (!strcmp(res->type, "rxq"))
7522                 rx_queue_infos_display(res->portnum, res->queuenum);
7523         else if (!strcmp(res->type, "txq"))
7524                 tx_queue_infos_display(res->portnum, res->queuenum);
7525 }
7526
7527 cmdline_parse_token_string_t cmd_showqueue_show =
7528         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7529 cmdline_parse_token_string_t cmd_showqueue_type =
7530         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7531 cmdline_parse_token_string_t cmd_showqueue_what =
7532         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7533 cmdline_parse_token_num_t cmd_showqueue_portnum =
7534         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7535 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7536         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7537
7538 cmdline_parse_inst_t cmd_showqueue = {
7539         .f = cmd_showqueue_parsed,
7540         .data = NULL,
7541         .help_str = "show rxq|txq info <port_id> <queue_id>",
7542         .tokens = {
7543                 (void *)&cmd_showqueue_show,
7544                 (void *)&cmd_showqueue_type,
7545                 (void *)&cmd_showqueue_what,
7546                 (void *)&cmd_showqueue_portnum,
7547                 (void *)&cmd_showqueue_queuenum,
7548                 NULL,
7549         },
7550 };
7551
7552 /* show/clear fwd engine statistics */
7553 struct fwd_result {
7554         cmdline_fixed_string_t action;
7555         cmdline_fixed_string_t fwd;
7556         cmdline_fixed_string_t stats;
7557         cmdline_fixed_string_t all;
7558 };
7559
7560 cmdline_parse_token_string_t cmd_fwd_action =
7561         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7562 cmdline_parse_token_string_t cmd_fwd_fwd =
7563         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7564 cmdline_parse_token_string_t cmd_fwd_stats =
7565         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7566 cmdline_parse_token_string_t cmd_fwd_all =
7567         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7568
7569 static void
7570 cmd_showfwdall_parsed(void *parsed_result,
7571                       __rte_unused struct cmdline *cl,
7572                       __rte_unused void *data)
7573 {
7574         struct fwd_result *res = parsed_result;
7575
7576         if (!strcmp(res->action, "show"))
7577                 fwd_stats_display();
7578         else
7579                 fwd_stats_reset();
7580 }
7581
7582 static cmdline_parse_inst_t cmd_showfwdall = {
7583         .f = cmd_showfwdall_parsed,
7584         .data = NULL,
7585         .help_str = "show|clear fwd stats all",
7586         .tokens = {
7587                 (void *)&cmd_fwd_action,
7588                 (void *)&cmd_fwd_fwd,
7589                 (void *)&cmd_fwd_stats,
7590                 (void *)&cmd_fwd_all,
7591                 NULL,
7592         },
7593 };
7594
7595 /* *** READ PORT REGISTER *** */
7596 struct cmd_read_reg_result {
7597         cmdline_fixed_string_t read;
7598         cmdline_fixed_string_t reg;
7599         portid_t port_id;
7600         uint32_t reg_off;
7601 };
7602
7603 static void
7604 cmd_read_reg_parsed(void *parsed_result,
7605                     __attribute__((unused)) struct cmdline *cl,
7606                     __attribute__((unused)) void *data)
7607 {
7608         struct cmd_read_reg_result *res = parsed_result;
7609         port_reg_display(res->port_id, res->reg_off);
7610 }
7611
7612 cmdline_parse_token_string_t cmd_read_reg_read =
7613         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7614 cmdline_parse_token_string_t cmd_read_reg_reg =
7615         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7616 cmdline_parse_token_num_t cmd_read_reg_port_id =
7617         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7618 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7619         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7620
7621 cmdline_parse_inst_t cmd_read_reg = {
7622         .f = cmd_read_reg_parsed,
7623         .data = NULL,
7624         .help_str = "read reg <port_id> <reg_off>",
7625         .tokens = {
7626                 (void *)&cmd_read_reg_read,
7627                 (void *)&cmd_read_reg_reg,
7628                 (void *)&cmd_read_reg_port_id,
7629                 (void *)&cmd_read_reg_reg_off,
7630                 NULL,
7631         },
7632 };
7633
7634 /* *** READ PORT REGISTER BIT FIELD *** */
7635 struct cmd_read_reg_bit_field_result {
7636         cmdline_fixed_string_t read;
7637         cmdline_fixed_string_t regfield;
7638         portid_t port_id;
7639         uint32_t reg_off;
7640         uint8_t bit1_pos;
7641         uint8_t bit2_pos;
7642 };
7643
7644 static void
7645 cmd_read_reg_bit_field_parsed(void *parsed_result,
7646                               __attribute__((unused)) struct cmdline *cl,
7647                               __attribute__((unused)) void *data)
7648 {
7649         struct cmd_read_reg_bit_field_result *res = parsed_result;
7650         port_reg_bit_field_display(res->port_id, res->reg_off,
7651                                    res->bit1_pos, res->bit2_pos);
7652 }
7653
7654 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7655         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7656                                  "read");
7657 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7658         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7659                                  regfield, "regfield");
7660 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7661         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7662                               UINT16);
7663 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7664         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7665                               UINT32);
7666 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7667         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7668                               UINT8);
7669 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7670         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7671                               UINT8);
7672
7673 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7674         .f = cmd_read_reg_bit_field_parsed,
7675         .data = NULL,
7676         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7677         "Read register bit field between bit_x and bit_y included",
7678         .tokens = {
7679                 (void *)&cmd_read_reg_bit_field_read,
7680                 (void *)&cmd_read_reg_bit_field_regfield,
7681                 (void *)&cmd_read_reg_bit_field_port_id,
7682                 (void *)&cmd_read_reg_bit_field_reg_off,
7683                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7684                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7685                 NULL,
7686         },
7687 };
7688
7689 /* *** READ PORT REGISTER BIT *** */
7690 struct cmd_read_reg_bit_result {
7691         cmdline_fixed_string_t read;
7692         cmdline_fixed_string_t regbit;
7693         portid_t port_id;
7694         uint32_t reg_off;
7695         uint8_t bit_pos;
7696 };
7697
7698 static void
7699 cmd_read_reg_bit_parsed(void *parsed_result,
7700                         __attribute__((unused)) struct cmdline *cl,
7701                         __attribute__((unused)) void *data)
7702 {
7703         struct cmd_read_reg_bit_result *res = parsed_result;
7704         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7705 }
7706
7707 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7708         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7709 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7710         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7711                                  regbit, "regbit");
7712 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7713         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7714 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7715         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7716 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7717         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7718
7719 cmdline_parse_inst_t cmd_read_reg_bit = {
7720         .f = cmd_read_reg_bit_parsed,
7721         .data = NULL,
7722         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7723         .tokens = {
7724                 (void *)&cmd_read_reg_bit_read,
7725                 (void *)&cmd_read_reg_bit_regbit,
7726                 (void *)&cmd_read_reg_bit_port_id,
7727                 (void *)&cmd_read_reg_bit_reg_off,
7728                 (void *)&cmd_read_reg_bit_bit_pos,
7729                 NULL,
7730         },
7731 };
7732
7733 /* *** WRITE PORT REGISTER *** */
7734 struct cmd_write_reg_result {
7735         cmdline_fixed_string_t write;
7736         cmdline_fixed_string_t reg;
7737         portid_t port_id;
7738         uint32_t reg_off;
7739         uint32_t value;
7740 };
7741
7742 static void
7743 cmd_write_reg_parsed(void *parsed_result,
7744                      __attribute__((unused)) struct cmdline *cl,
7745                      __attribute__((unused)) void *data)
7746 {
7747         struct cmd_write_reg_result *res = parsed_result;
7748         port_reg_set(res->port_id, res->reg_off, res->value);
7749 }
7750
7751 cmdline_parse_token_string_t cmd_write_reg_write =
7752         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7753 cmdline_parse_token_string_t cmd_write_reg_reg =
7754         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7755 cmdline_parse_token_num_t cmd_write_reg_port_id =
7756         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7757 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7758         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7759 cmdline_parse_token_num_t cmd_write_reg_value =
7760         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7761
7762 cmdline_parse_inst_t cmd_write_reg = {
7763         .f = cmd_write_reg_parsed,
7764         .data = NULL,
7765         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7766         .tokens = {
7767                 (void *)&cmd_write_reg_write,
7768                 (void *)&cmd_write_reg_reg,
7769                 (void *)&cmd_write_reg_port_id,
7770                 (void *)&cmd_write_reg_reg_off,
7771                 (void *)&cmd_write_reg_value,
7772                 NULL,
7773         },
7774 };
7775
7776 /* *** WRITE PORT REGISTER BIT FIELD *** */
7777 struct cmd_write_reg_bit_field_result {
7778         cmdline_fixed_string_t write;
7779         cmdline_fixed_string_t regfield;
7780         portid_t port_id;
7781         uint32_t reg_off;
7782         uint8_t bit1_pos;
7783         uint8_t bit2_pos;
7784         uint32_t value;
7785 };
7786
7787 static void
7788 cmd_write_reg_bit_field_parsed(void *parsed_result,
7789                                __attribute__((unused)) struct cmdline *cl,
7790                                __attribute__((unused)) void *data)
7791 {
7792         struct cmd_write_reg_bit_field_result *res = parsed_result;
7793         port_reg_bit_field_set(res->port_id, res->reg_off,
7794                           res->bit1_pos, res->bit2_pos, res->value);
7795 }
7796
7797 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7798         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7799                                  "write");
7800 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7801         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7802                                  regfield, "regfield");
7803 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7804         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7805                               UINT16);
7806 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7807         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7808                               UINT32);
7809 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7810         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7811                               UINT8);
7812 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7813         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7814                               UINT8);
7815 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7816         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7817                               UINT32);
7818
7819 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7820         .f = cmd_write_reg_bit_field_parsed,
7821         .data = NULL,
7822         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7823                 "<reg_value>: "
7824                 "Set register bit field between bit_x and bit_y included",
7825         .tokens = {
7826                 (void *)&cmd_write_reg_bit_field_write,
7827                 (void *)&cmd_write_reg_bit_field_regfield,
7828                 (void *)&cmd_write_reg_bit_field_port_id,
7829                 (void *)&cmd_write_reg_bit_field_reg_off,
7830                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7831                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7832                 (void *)&cmd_write_reg_bit_field_value,
7833                 NULL,
7834         },
7835 };
7836
7837 /* *** WRITE PORT REGISTER BIT *** */
7838 struct cmd_write_reg_bit_result {
7839         cmdline_fixed_string_t write;
7840         cmdline_fixed_string_t regbit;
7841         portid_t port_id;
7842         uint32_t reg_off;
7843         uint8_t bit_pos;
7844         uint8_t value;
7845 };
7846
7847 static void
7848 cmd_write_reg_bit_parsed(void *parsed_result,
7849                          __attribute__((unused)) struct cmdline *cl,
7850                          __attribute__((unused)) void *data)
7851 {
7852         struct cmd_write_reg_bit_result *res = parsed_result;
7853         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7854 }
7855
7856 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7857         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7858                                  "write");
7859 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7860         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7861                                  regbit, "regbit");
7862 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7863         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7864 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7865         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7866 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7867         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7868 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7869         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7870
7871 cmdline_parse_inst_t cmd_write_reg_bit = {
7872         .f = cmd_write_reg_bit_parsed,
7873         .data = NULL,
7874         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7875                 "0 <= bit_x <= 31",
7876         .tokens = {
7877                 (void *)&cmd_write_reg_bit_write,
7878                 (void *)&cmd_write_reg_bit_regbit,
7879                 (void *)&cmd_write_reg_bit_port_id,
7880                 (void *)&cmd_write_reg_bit_reg_off,
7881                 (void *)&cmd_write_reg_bit_bit_pos,
7882                 (void *)&cmd_write_reg_bit_value,
7883                 NULL,
7884         },
7885 };
7886
7887 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7888 struct cmd_read_rxd_txd_result {
7889         cmdline_fixed_string_t read;
7890         cmdline_fixed_string_t rxd_txd;
7891         portid_t port_id;
7892         uint16_t queue_id;
7893         uint16_t desc_id;
7894 };
7895
7896 static void
7897 cmd_read_rxd_txd_parsed(void *parsed_result,
7898                         __attribute__((unused)) struct cmdline *cl,
7899                         __attribute__((unused)) void *data)
7900 {
7901         struct cmd_read_rxd_txd_result *res = parsed_result;
7902
7903         if (!strcmp(res->rxd_txd, "rxd"))
7904                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7905         else if (!strcmp(res->rxd_txd, "txd"))
7906                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7907 }
7908
7909 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7910         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7911 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7912         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7913                                  "rxd#txd");
7914 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7915         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7916 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7917         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7918 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7919         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7920
7921 cmdline_parse_inst_t cmd_read_rxd_txd = {
7922         .f = cmd_read_rxd_txd_parsed,
7923         .data = NULL,
7924         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7925         .tokens = {
7926                 (void *)&cmd_read_rxd_txd_read,
7927                 (void *)&cmd_read_rxd_txd_rxd_txd,
7928                 (void *)&cmd_read_rxd_txd_port_id,
7929                 (void *)&cmd_read_rxd_txd_queue_id,
7930                 (void *)&cmd_read_rxd_txd_desc_id,
7931                 NULL,
7932         },
7933 };
7934
7935 /* *** QUIT *** */
7936 struct cmd_quit_result {
7937         cmdline_fixed_string_t quit;
7938 };
7939
7940 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7941                             struct cmdline *cl,
7942                             __attribute__((unused)) void *data)
7943 {
7944         cmdline_quit(cl);
7945 }
7946
7947 cmdline_parse_token_string_t cmd_quit_quit =
7948         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7949
7950 cmdline_parse_inst_t cmd_quit = {
7951         .f = cmd_quit_parsed,
7952         .data = NULL,
7953         .help_str = "quit: Exit application",
7954         .tokens = {
7955                 (void *)&cmd_quit_quit,
7956                 NULL,
7957         },
7958 };
7959
7960 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7961 struct cmd_mac_addr_result {
7962         cmdline_fixed_string_t mac_addr_cmd;
7963         cmdline_fixed_string_t what;
7964         uint16_t port_num;
7965         struct rte_ether_addr address;
7966 };
7967
7968 static void cmd_mac_addr_parsed(void *parsed_result,
7969                 __attribute__((unused)) struct cmdline *cl,
7970                 __attribute__((unused)) void *data)
7971 {
7972         struct cmd_mac_addr_result *res = parsed_result;
7973         int ret;
7974
7975         if (strcmp(res->what, "add") == 0)
7976                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7977         else if (strcmp(res->what, "set") == 0)
7978                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7979                                                        &res->address);
7980         else
7981                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7982
7983         /* check the return value and print it if is < 0 */
7984         if(ret < 0)
7985                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7986
7987 }
7988
7989 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7990         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7991                                 "mac_addr");
7992 cmdline_parse_token_string_t cmd_mac_addr_what =
7993         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7994                                 "add#remove#set");
7995 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7996                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7997                                         UINT16);
7998 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7999                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8000
8001 cmdline_parse_inst_t cmd_mac_addr = {
8002         .f = cmd_mac_addr_parsed,
8003         .data = (void *)0,
8004         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8005                         "Add/Remove/Set MAC address on port_id",
8006         .tokens = {
8007                 (void *)&cmd_mac_addr_cmd,
8008                 (void *)&cmd_mac_addr_what,
8009                 (void *)&cmd_mac_addr_portnum,
8010                 (void *)&cmd_mac_addr_addr,
8011                 NULL,
8012         },
8013 };
8014
8015 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8016 struct cmd_eth_peer_result {
8017         cmdline_fixed_string_t set;
8018         cmdline_fixed_string_t eth_peer;
8019         portid_t port_id;
8020         cmdline_fixed_string_t peer_addr;
8021 };
8022
8023 static void cmd_set_eth_peer_parsed(void *parsed_result,
8024                         __attribute__((unused)) struct cmdline *cl,
8025                         __attribute__((unused)) void *data)
8026 {
8027                 struct cmd_eth_peer_result *res = parsed_result;
8028
8029                 if (test_done == 0) {
8030                         printf("Please stop forwarding first\n");
8031                         return;
8032                 }
8033                 if (!strcmp(res->eth_peer, "eth-peer")) {
8034                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8035                         fwd_config_setup();
8036                 }
8037 }
8038 cmdline_parse_token_string_t cmd_eth_peer_set =
8039         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8040 cmdline_parse_token_string_t cmd_eth_peer =
8041         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8042 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8043         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8044 cmdline_parse_token_string_t cmd_eth_peer_addr =
8045         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8046
8047 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8048         .f = cmd_set_eth_peer_parsed,
8049         .data = NULL,
8050         .help_str = "set eth-peer <port_id> <peer_mac>",
8051         .tokens = {
8052                 (void *)&cmd_eth_peer_set,
8053                 (void *)&cmd_eth_peer,
8054                 (void *)&cmd_eth_peer_port_id,
8055                 (void *)&cmd_eth_peer_addr,
8056                 NULL,
8057         },
8058 };
8059
8060 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8061 struct cmd_set_qmap_result {
8062         cmdline_fixed_string_t set;
8063         cmdline_fixed_string_t qmap;
8064         cmdline_fixed_string_t what;
8065         portid_t port_id;
8066         uint16_t queue_id;
8067         uint8_t map_value;
8068 };
8069
8070 static void
8071 cmd_set_qmap_parsed(void *parsed_result,
8072                        __attribute__((unused)) struct cmdline *cl,
8073                        __attribute__((unused)) void *data)
8074 {
8075         struct cmd_set_qmap_result *res = parsed_result;
8076         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8077
8078         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8079 }
8080
8081 cmdline_parse_token_string_t cmd_setqmap_set =
8082         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8083                                  set, "set");
8084 cmdline_parse_token_string_t cmd_setqmap_qmap =
8085         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8086                                  qmap, "stat_qmap");
8087 cmdline_parse_token_string_t cmd_setqmap_what =
8088         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8089                                  what, "tx#rx");
8090 cmdline_parse_token_num_t cmd_setqmap_portid =
8091         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8092                               port_id, UINT16);
8093 cmdline_parse_token_num_t cmd_setqmap_queueid =
8094         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8095                               queue_id, UINT16);
8096 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8097         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8098                               map_value, UINT8);
8099
8100 cmdline_parse_inst_t cmd_set_qmap = {
8101         .f = cmd_set_qmap_parsed,
8102         .data = NULL,
8103         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8104                 "Set statistics mapping value on tx|rx queue_id of port_id",
8105         .tokens = {
8106                 (void *)&cmd_setqmap_set,
8107                 (void *)&cmd_setqmap_qmap,
8108                 (void *)&cmd_setqmap_what,
8109                 (void *)&cmd_setqmap_portid,
8110                 (void *)&cmd_setqmap_queueid,
8111                 (void *)&cmd_setqmap_mapvalue,
8112                 NULL,
8113         },
8114 };
8115
8116 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8117 struct cmd_set_xstats_hide_zero_result {
8118         cmdline_fixed_string_t keyword;
8119         cmdline_fixed_string_t name;
8120         cmdline_fixed_string_t on_off;
8121 };
8122
8123 static void
8124 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8125                         __attribute__((unused)) struct cmdline *cl,
8126                         __attribute__((unused)) void *data)
8127 {
8128         struct cmd_set_xstats_hide_zero_result *res;
8129         uint16_t on_off = 0;
8130
8131         res = parsed_result;
8132         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8133         set_xstats_hide_zero(on_off);
8134 }
8135
8136 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8137         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8138                                  keyword, "set");
8139 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8140         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8141                                  name, "xstats-hide-zero");
8142 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8143         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8144                                  on_off, "on#off");
8145
8146 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8147         .f = cmd_set_xstats_hide_zero_parsed,
8148         .data = NULL,
8149         .help_str = "set xstats-hide-zero on|off",
8150         .tokens = {
8151                 (void *)&cmd_set_xstats_hide_zero_keyword,
8152                 (void *)&cmd_set_xstats_hide_zero_name,
8153                 (void *)&cmd_set_xstats_hide_zero_on_off,
8154                 NULL,
8155         },
8156 };
8157
8158 /* *** CONFIGURE UNICAST HASH TABLE *** */
8159 struct cmd_set_uc_hash_table {
8160         cmdline_fixed_string_t set;
8161         cmdline_fixed_string_t port;
8162         portid_t port_id;
8163         cmdline_fixed_string_t what;
8164         struct rte_ether_addr address;
8165         cmdline_fixed_string_t mode;
8166 };
8167
8168 static void
8169 cmd_set_uc_hash_parsed(void *parsed_result,
8170                        __attribute__((unused)) struct cmdline *cl,
8171                        __attribute__((unused)) void *data)
8172 {
8173         int ret=0;
8174         struct cmd_set_uc_hash_table *res = parsed_result;
8175
8176         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8177
8178         if (strcmp(res->what, "uta") == 0)
8179                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8180                                                 &res->address,(uint8_t)is_on);
8181         if (ret < 0)
8182                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8183
8184 }
8185
8186 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8187         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8188                                  set, "set");
8189 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8190         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8191                                  port, "port");
8192 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8193         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8194                               port_id, UINT16);
8195 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8196         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8197                                  what, "uta");
8198 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8199         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8200                                 address);
8201 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8202         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8203                                  mode, "on#off");
8204
8205 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8206         .f = cmd_set_uc_hash_parsed,
8207         .data = NULL,
8208         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8209         .tokens = {
8210                 (void *)&cmd_set_uc_hash_set,
8211                 (void *)&cmd_set_uc_hash_port,
8212                 (void *)&cmd_set_uc_hash_portid,
8213                 (void *)&cmd_set_uc_hash_what,
8214                 (void *)&cmd_set_uc_hash_mac,
8215                 (void *)&cmd_set_uc_hash_mode,
8216                 NULL,
8217         },
8218 };
8219
8220 struct cmd_set_uc_all_hash_table {
8221         cmdline_fixed_string_t set;
8222         cmdline_fixed_string_t port;
8223         portid_t port_id;
8224         cmdline_fixed_string_t what;
8225         cmdline_fixed_string_t value;
8226         cmdline_fixed_string_t mode;
8227 };
8228
8229 static void
8230 cmd_set_uc_all_hash_parsed(void *parsed_result,
8231                        __attribute__((unused)) struct cmdline *cl,
8232                        __attribute__((unused)) void *data)
8233 {
8234         int ret=0;
8235         struct cmd_set_uc_all_hash_table *res = parsed_result;
8236
8237         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8238
8239         if ((strcmp(res->what, "uta") == 0) &&
8240                 (strcmp(res->value, "all") == 0))
8241                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8242         if (ret < 0)
8243                 printf("bad unicast hash table parameter,"
8244                         "return code = %d \n", ret);
8245 }
8246
8247 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8248         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8249                                  set, "set");
8250 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8251         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8252                                  port, "port");
8253 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8254         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8255                               port_id, UINT16);
8256 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8257         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8258                                  what, "uta");
8259 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8260         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8261                                 value,"all");
8262 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8263         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8264                                  mode, "on#off");
8265
8266 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8267         .f = cmd_set_uc_all_hash_parsed,
8268         .data = NULL,
8269         .help_str = "set port <port_id> uta all on|off",
8270         .tokens = {
8271                 (void *)&cmd_set_uc_all_hash_set,
8272                 (void *)&cmd_set_uc_all_hash_port,
8273                 (void *)&cmd_set_uc_all_hash_portid,
8274                 (void *)&cmd_set_uc_all_hash_what,
8275                 (void *)&cmd_set_uc_all_hash_value,
8276                 (void *)&cmd_set_uc_all_hash_mode,
8277                 NULL,
8278         },
8279 };
8280
8281 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8282 struct cmd_set_vf_macvlan_filter {
8283         cmdline_fixed_string_t set;
8284         cmdline_fixed_string_t port;
8285         portid_t port_id;
8286         cmdline_fixed_string_t vf;
8287         uint8_t vf_id;
8288         struct rte_ether_addr address;
8289         cmdline_fixed_string_t filter_type;
8290         cmdline_fixed_string_t mode;
8291 };
8292
8293 static void
8294 cmd_set_vf_macvlan_parsed(void *parsed_result,
8295                        __attribute__((unused)) struct cmdline *cl,
8296                        __attribute__((unused)) void *data)
8297 {
8298         int is_on, ret = 0;
8299         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8300         struct rte_eth_mac_filter filter;
8301
8302         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8303
8304         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8305
8306         /* set VF MAC filter */
8307         filter.is_vf = 1;
8308
8309         /* set VF ID */
8310         filter.dst_id = res->vf_id;
8311
8312         if (!strcmp(res->filter_type, "exact-mac"))
8313                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8314         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8315                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8316         else if (!strcmp(res->filter_type, "hashmac"))
8317                 filter.filter_type = RTE_MAC_HASH_MATCH;
8318         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8319                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8320
8321         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8322
8323         if (is_on)
8324                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8325                                         RTE_ETH_FILTER_MACVLAN,
8326                                         RTE_ETH_FILTER_ADD,
8327                                          &filter);
8328         else
8329                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8330                                         RTE_ETH_FILTER_MACVLAN,
8331                                         RTE_ETH_FILTER_DELETE,
8332                                         &filter);
8333
8334         if (ret < 0)
8335                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8336
8337 }
8338
8339 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8341                                  set, "set");
8342 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8343         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8344                                  port, "port");
8345 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8346         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8347                               port_id, UINT16);
8348 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8349         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8350                                  vf, "vf");
8351 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8352         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8353                                 vf_id, UINT8);
8354 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8355         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8356                                 address);
8357 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8358         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8359                                 filter_type, "exact-mac#exact-mac-vlan"
8360                                 "#hashmac#hashmac-vlan");
8361 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8362         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8363                                  mode, "on#off");
8364
8365 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8366         .f = cmd_set_vf_macvlan_parsed,
8367         .data = NULL,
8368         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8369                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8370                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8371                 "hash match rule: hash match of MAC and exact match of VLAN",
8372         .tokens = {
8373                 (void *)&cmd_set_vf_macvlan_set,
8374                 (void *)&cmd_set_vf_macvlan_port,
8375                 (void *)&cmd_set_vf_macvlan_portid,
8376                 (void *)&cmd_set_vf_macvlan_vf,
8377                 (void *)&cmd_set_vf_macvlan_vf_id,
8378                 (void *)&cmd_set_vf_macvlan_mac,
8379                 (void *)&cmd_set_vf_macvlan_filter_type,
8380                 (void *)&cmd_set_vf_macvlan_mode,
8381                 NULL,
8382         },
8383 };
8384
8385 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8386 struct cmd_set_vf_traffic {
8387         cmdline_fixed_string_t set;
8388         cmdline_fixed_string_t port;
8389         portid_t port_id;
8390         cmdline_fixed_string_t vf;
8391         uint8_t vf_id;
8392         cmdline_fixed_string_t what;
8393         cmdline_fixed_string_t mode;
8394 };
8395
8396 static void
8397 cmd_set_vf_traffic_parsed(void *parsed_result,
8398                        __attribute__((unused)) struct cmdline *cl,
8399                        __attribute__((unused)) void *data)
8400 {
8401         struct cmd_set_vf_traffic *res = parsed_result;
8402         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8403         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8404
8405         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8406 }
8407
8408 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8409         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8410                                  set, "set");
8411 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8412         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8413                                  port, "port");
8414 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8415         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8416                               port_id, UINT16);
8417 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8418         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8419                                  vf, "vf");
8420 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8421         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8422                               vf_id, UINT8);
8423 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8424         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8425                                  what, "tx#rx");
8426 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8427         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8428                                  mode, "on#off");
8429
8430 cmdline_parse_inst_t cmd_set_vf_traffic = {
8431         .f = cmd_set_vf_traffic_parsed,
8432         .data = NULL,
8433         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8434         .tokens = {
8435                 (void *)&cmd_setvf_traffic_set,
8436                 (void *)&cmd_setvf_traffic_port,
8437                 (void *)&cmd_setvf_traffic_portid,
8438                 (void *)&cmd_setvf_traffic_vf,
8439                 (void *)&cmd_setvf_traffic_vfid,
8440                 (void *)&cmd_setvf_traffic_what,
8441                 (void *)&cmd_setvf_traffic_mode,
8442                 NULL,
8443         },
8444 };
8445
8446 /* *** CONFIGURE VF RECEIVE MODE *** */
8447 struct cmd_set_vf_rxmode {
8448         cmdline_fixed_string_t set;
8449         cmdline_fixed_string_t port;
8450         portid_t port_id;
8451         cmdline_fixed_string_t vf;
8452         uint8_t vf_id;
8453         cmdline_fixed_string_t what;
8454         cmdline_fixed_string_t mode;
8455         cmdline_fixed_string_t on;
8456 };
8457
8458 static void
8459 cmd_set_vf_rxmode_parsed(void *parsed_result,
8460                        __attribute__((unused)) struct cmdline *cl,
8461                        __attribute__((unused)) void *data)
8462 {
8463         int ret = -ENOTSUP;
8464         uint16_t vf_rxmode = 0;
8465         struct cmd_set_vf_rxmode *res = parsed_result;
8466
8467         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8468         if (!strcmp(res->what,"rxmode")) {
8469                 if (!strcmp(res->mode, "AUPE"))
8470                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8471                 else if (!strcmp(res->mode, "ROPE"))
8472                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8473                 else if (!strcmp(res->mode, "BAM"))
8474                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8475                 else if (!strncmp(res->mode, "MPE",3))
8476                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8477         }
8478
8479         RTE_SET_USED(is_on);
8480
8481 #ifdef RTE_LIBRTE_IXGBE_PMD
8482         if (ret == -ENOTSUP)
8483                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8484                                                   vf_rxmode, (uint8_t)is_on);
8485 #endif
8486 #ifdef RTE_LIBRTE_BNXT_PMD
8487         if (ret == -ENOTSUP)
8488                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8489                                                  vf_rxmode, (uint8_t)is_on);
8490 #endif
8491         if (ret < 0)
8492                 printf("bad VF receive mode parameter, return code = %d \n",
8493                 ret);
8494 }
8495
8496 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8497         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8498                                  set, "set");
8499 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8500         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8501                                  port, "port");
8502 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8503         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8504                               port_id, UINT16);
8505 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8506         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8507                                  vf, "vf");
8508 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8509         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8510                               vf_id, UINT8);
8511 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8512         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8513                                  what, "rxmode");
8514 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8515         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8516                                  mode, "AUPE#ROPE#BAM#MPE");
8517 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8518         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8519                                  on, "on#off");
8520
8521 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8522         .f = cmd_set_vf_rxmode_parsed,
8523         .data = NULL,
8524         .help_str = "set port <port_id> vf <vf_id> rxmode "
8525                 "AUPE|ROPE|BAM|MPE on|off",
8526         .tokens = {
8527                 (void *)&cmd_set_vf_rxmode_set,
8528                 (void *)&cmd_set_vf_rxmode_port,
8529                 (void *)&cmd_set_vf_rxmode_portid,
8530                 (void *)&cmd_set_vf_rxmode_vf,
8531                 (void *)&cmd_set_vf_rxmode_vfid,
8532                 (void *)&cmd_set_vf_rxmode_what,
8533                 (void *)&cmd_set_vf_rxmode_mode,
8534                 (void *)&cmd_set_vf_rxmode_on,
8535                 NULL,
8536         },
8537 };
8538
8539 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8540 struct cmd_vf_mac_addr_result {
8541         cmdline_fixed_string_t mac_addr_cmd;
8542         cmdline_fixed_string_t what;
8543         cmdline_fixed_string_t port;
8544         uint16_t port_num;
8545         cmdline_fixed_string_t vf;
8546         uint8_t vf_num;
8547         struct rte_ether_addr address;
8548 };
8549
8550 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8551                 __attribute__((unused)) struct cmdline *cl,
8552                 __attribute__((unused)) void *data)
8553 {
8554         struct cmd_vf_mac_addr_result *res = parsed_result;
8555         int ret = -ENOTSUP;
8556
8557         if (strcmp(res->what, "add") != 0)
8558                 return;
8559
8560 #ifdef RTE_LIBRTE_I40E_PMD
8561         if (ret == -ENOTSUP)
8562                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8563                                                    &res->address);
8564 #endif
8565 #ifdef RTE_LIBRTE_BNXT_PMD
8566         if (ret == -ENOTSUP)
8567                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8568                                                 res->vf_num);
8569 #endif
8570
8571         if(ret < 0)
8572                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8573
8574 }
8575
8576 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8577         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8578                                 mac_addr_cmd,"mac_addr");
8579 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8580         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8581                                 what,"add");
8582 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8583         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8584                                 port,"port");
8585 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8586         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8587                                 port_num, UINT16);
8588 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8589         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8590                                 vf,"vf");
8591 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8592         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8593                                 vf_num, UINT8);
8594 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8595         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8596                                 address);
8597
8598 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8599         .f = cmd_vf_mac_addr_parsed,
8600         .data = (void *)0,
8601         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8602                 "Add MAC address filtering for a VF on port_id",
8603         .tokens = {
8604                 (void *)&cmd_vf_mac_addr_cmd,
8605                 (void *)&cmd_vf_mac_addr_what,
8606                 (void *)&cmd_vf_mac_addr_port,
8607                 (void *)&cmd_vf_mac_addr_portnum,
8608                 (void *)&cmd_vf_mac_addr_vf,
8609                 (void *)&cmd_vf_mac_addr_vfnum,
8610                 (void *)&cmd_vf_mac_addr_addr,
8611                 NULL,
8612         },
8613 };
8614
8615 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8616 struct cmd_vf_rx_vlan_filter {
8617         cmdline_fixed_string_t rx_vlan;
8618         cmdline_fixed_string_t what;
8619         uint16_t vlan_id;
8620         cmdline_fixed_string_t port;
8621         portid_t port_id;
8622         cmdline_fixed_string_t vf;
8623         uint64_t vf_mask;
8624 };
8625
8626 static void
8627 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8628                           __attribute__((unused)) struct cmdline *cl,
8629                           __attribute__((unused)) void *data)
8630 {
8631         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8632         int ret = -ENOTSUP;
8633
8634         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8635
8636 #ifdef RTE_LIBRTE_IXGBE_PMD
8637         if (ret == -ENOTSUP)
8638                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8639                                 res->vlan_id, res->vf_mask, is_add);
8640 #endif
8641 #ifdef RTE_LIBRTE_I40E_PMD
8642         if (ret == -ENOTSUP)
8643                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8644                                 res->vlan_id, res->vf_mask, is_add);
8645 #endif
8646 #ifdef RTE_LIBRTE_BNXT_PMD
8647         if (ret == -ENOTSUP)
8648                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8649                                 res->vlan_id, res->vf_mask, is_add);
8650 #endif
8651
8652         switch (ret) {
8653         case 0:
8654                 break;
8655         case -EINVAL:
8656                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8657                                 res->vlan_id, res->vf_mask);
8658                 break;
8659         case -ENODEV:
8660                 printf("invalid port_id %d\n", res->port_id);
8661                 break;
8662         case -ENOTSUP:
8663                 printf("function not implemented or supported\n");
8664                 break;
8665         default:
8666                 printf("programming error: (%s)\n", strerror(-ret));
8667         }
8668 }
8669
8670 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8671         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8672                                  rx_vlan, "rx_vlan");
8673 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8674         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8675                                  what, "add#rm");
8676 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8677         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8678                               vlan_id, UINT16);
8679 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8680         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8681                                  port, "port");
8682 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8683         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8684                               port_id, UINT16);
8685 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8686         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8687                                  vf, "vf");
8688 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8689         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8690                               vf_mask, UINT64);
8691
8692 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8693         .f = cmd_vf_rx_vlan_filter_parsed,
8694         .data = NULL,
8695         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8696                 "(vf_mask = hexadecimal VF mask)",
8697         .tokens = {
8698                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8699                 (void *)&cmd_vf_rx_vlan_filter_what,
8700                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8701                 (void *)&cmd_vf_rx_vlan_filter_port,
8702                 (void *)&cmd_vf_rx_vlan_filter_portid,
8703                 (void *)&cmd_vf_rx_vlan_filter_vf,
8704                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8705                 NULL,
8706         },
8707 };
8708
8709 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8710 struct cmd_queue_rate_limit_result {
8711         cmdline_fixed_string_t set;
8712         cmdline_fixed_string_t port;
8713         uint16_t port_num;
8714         cmdline_fixed_string_t queue;
8715         uint8_t queue_num;
8716         cmdline_fixed_string_t rate;
8717         uint16_t rate_num;
8718 };
8719
8720 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8721                 __attribute__((unused)) struct cmdline *cl,
8722                 __attribute__((unused)) void *data)
8723 {
8724         struct cmd_queue_rate_limit_result *res = parsed_result;
8725         int ret = 0;
8726
8727         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8728                 && (strcmp(res->queue, "queue") == 0)
8729                 && (strcmp(res->rate, "rate") == 0))
8730                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8731                                         res->rate_num);
8732         if (ret < 0)
8733                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8734
8735 }
8736
8737 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8738         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8739                                 set, "set");
8740 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8741         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8742                                 port, "port");
8743 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8744         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8745                                 port_num, UINT16);
8746 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8747         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8748                                 queue, "queue");
8749 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8750         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8751                                 queue_num, UINT8);
8752 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8753         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8754                                 rate, "rate");
8755 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8756         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8757                                 rate_num, UINT16);
8758
8759 cmdline_parse_inst_t cmd_queue_rate_limit = {
8760         .f = cmd_queue_rate_limit_parsed,
8761         .data = (void *)0,
8762         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8763                 "Set rate limit for a queue on port_id",
8764         .tokens = {
8765                 (void *)&cmd_queue_rate_limit_set,
8766                 (void *)&cmd_queue_rate_limit_port,
8767                 (void *)&cmd_queue_rate_limit_portnum,
8768                 (void *)&cmd_queue_rate_limit_queue,
8769                 (void *)&cmd_queue_rate_limit_queuenum,
8770                 (void *)&cmd_queue_rate_limit_rate,
8771                 (void *)&cmd_queue_rate_limit_ratenum,
8772                 NULL,
8773         },
8774 };
8775
8776 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8777 struct cmd_vf_rate_limit_result {
8778         cmdline_fixed_string_t set;
8779         cmdline_fixed_string_t port;
8780         uint16_t port_num;
8781         cmdline_fixed_string_t vf;
8782         uint8_t vf_num;
8783         cmdline_fixed_string_t rate;
8784         uint16_t rate_num;
8785         cmdline_fixed_string_t q_msk;
8786         uint64_t q_msk_val;
8787 };
8788
8789 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8790                 __attribute__((unused)) struct cmdline *cl,
8791                 __attribute__((unused)) void *data)
8792 {
8793         struct cmd_vf_rate_limit_result *res = parsed_result;
8794         int ret = 0;
8795
8796         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8797                 && (strcmp(res->vf, "vf") == 0)
8798                 && (strcmp(res->rate, "rate") == 0)
8799                 && (strcmp(res->q_msk, "queue_mask") == 0))
8800                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8801                                         res->rate_num, res->q_msk_val);
8802         if (ret < 0)
8803                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8804
8805 }
8806
8807 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8808         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8809                                 set, "set");
8810 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8811         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8812                                 port, "port");
8813 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8814         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8815                                 port_num, UINT16);
8816 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8817         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8818                                 vf, "vf");
8819 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8820         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8821                                 vf_num, UINT8);
8822 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8823         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8824                                 rate, "rate");
8825 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8826         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8827                                 rate_num, UINT16);
8828 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8829         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8830                                 q_msk, "queue_mask");
8831 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8832         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8833                                 q_msk_val, UINT64);
8834
8835 cmdline_parse_inst_t cmd_vf_rate_limit = {
8836         .f = cmd_vf_rate_limit_parsed,
8837         .data = (void *)0,
8838         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8839                 "queue_mask <queue_mask_value>: "
8840                 "Set rate limit for queues of VF on port_id",
8841         .tokens = {
8842                 (void *)&cmd_vf_rate_limit_set,
8843                 (void *)&cmd_vf_rate_limit_port,
8844                 (void *)&cmd_vf_rate_limit_portnum,
8845                 (void *)&cmd_vf_rate_limit_vf,
8846                 (void *)&cmd_vf_rate_limit_vfnum,
8847                 (void *)&cmd_vf_rate_limit_rate,
8848                 (void *)&cmd_vf_rate_limit_ratenum,
8849                 (void *)&cmd_vf_rate_limit_q_msk,
8850                 (void *)&cmd_vf_rate_limit_q_msk_val,
8851                 NULL,
8852         },
8853 };
8854
8855 /* *** ADD TUNNEL FILTER OF A PORT *** */
8856 struct cmd_tunnel_filter_result {
8857         cmdline_fixed_string_t cmd;
8858         cmdline_fixed_string_t what;
8859         portid_t port_id;
8860         struct rte_ether_addr outer_mac;
8861         struct rte_ether_addr inner_mac;
8862         cmdline_ipaddr_t ip_value;
8863         uint16_t inner_vlan;
8864         cmdline_fixed_string_t tunnel_type;
8865         cmdline_fixed_string_t filter_type;
8866         uint32_t tenant_id;
8867         uint16_t queue_num;
8868 };
8869
8870 static void
8871 cmd_tunnel_filter_parsed(void *parsed_result,
8872                           __attribute__((unused)) struct cmdline *cl,
8873                           __attribute__((unused)) void *data)
8874 {
8875         struct cmd_tunnel_filter_result *res = parsed_result;
8876         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8877         int ret = 0;
8878
8879         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8880
8881         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8882         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8883         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8884
8885         if (res->ip_value.family == AF_INET) {
8886                 tunnel_filter_conf.ip_addr.ipv4_addr =
8887                         res->ip_value.addr.ipv4.s_addr;
8888                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8889         } else {
8890                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8891                         &(res->ip_value.addr.ipv6),
8892                         sizeof(struct in6_addr));
8893                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8894         }
8895
8896         if (!strcmp(res->filter_type, "imac-ivlan"))
8897                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8898         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8899                 tunnel_filter_conf.filter_type =
8900                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8901         else if (!strcmp(res->filter_type, "imac-tenid"))
8902                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8903         else if (!strcmp(res->filter_type, "imac"))
8904                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8905         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8906                 tunnel_filter_conf.filter_type =
8907                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8908         else if (!strcmp(res->filter_type, "oip"))
8909                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8910         else if (!strcmp(res->filter_type, "iip"))
8911                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8912         else {
8913                 printf("The filter type is not supported");
8914                 return;
8915         }
8916
8917         if (!strcmp(res->tunnel_type, "vxlan"))
8918                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8919         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8920                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8921         else if (!strcmp(res->tunnel_type, "nvgre"))
8922                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8923         else if (!strcmp(res->tunnel_type, "ipingre"))
8924                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8925         else {
8926                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8927                 return;
8928         }
8929
8930         tunnel_filter_conf.tenant_id = res->tenant_id;
8931         tunnel_filter_conf.queue_id = res->queue_num;
8932         if (!strcmp(res->what, "add"))
8933                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8934                                         RTE_ETH_FILTER_TUNNEL,
8935                                         RTE_ETH_FILTER_ADD,
8936                                         &tunnel_filter_conf);
8937         else
8938                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8939                                         RTE_ETH_FILTER_TUNNEL,
8940                                         RTE_ETH_FILTER_DELETE,
8941                                         &tunnel_filter_conf);
8942         if (ret < 0)
8943                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8944                                 strerror(-ret));
8945
8946 }
8947 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8948         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8949         cmd, "tunnel_filter");
8950 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8951         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8952         what, "add#rm");
8953 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8954         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8955         port_id, UINT16);
8956 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8957         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8958         outer_mac);
8959 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8960         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8961         inner_mac);
8962 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8963         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8964         inner_vlan, UINT16);
8965 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8966         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8967         ip_value);
8968 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8969         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8970         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8971
8972 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8973         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8974         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8975                 "imac#omac-imac-tenid");
8976 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8977         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8978         tenant_id, UINT32);
8979 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8980         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8981         queue_num, UINT16);
8982
8983 cmdline_parse_inst_t cmd_tunnel_filter = {
8984         .f = cmd_tunnel_filter_parsed,
8985         .data = (void *)0,
8986         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8987                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8988                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8989                 "<queue_id>: Add/Rm tunnel filter of a port",
8990         .tokens = {
8991                 (void *)&cmd_tunnel_filter_cmd,
8992                 (void *)&cmd_tunnel_filter_what,
8993                 (void *)&cmd_tunnel_filter_port_id,
8994                 (void *)&cmd_tunnel_filter_outer_mac,
8995                 (void *)&cmd_tunnel_filter_inner_mac,
8996                 (void *)&cmd_tunnel_filter_ip_value,
8997                 (void *)&cmd_tunnel_filter_innner_vlan,
8998                 (void *)&cmd_tunnel_filter_tunnel_type,
8999                 (void *)&cmd_tunnel_filter_filter_type,
9000                 (void *)&cmd_tunnel_filter_tenant_id,
9001                 (void *)&cmd_tunnel_filter_queue_num,
9002                 NULL,
9003         },
9004 };
9005
9006 /* *** CONFIGURE TUNNEL UDP PORT *** */
9007 struct cmd_tunnel_udp_config {
9008         cmdline_fixed_string_t cmd;
9009         cmdline_fixed_string_t what;
9010         uint16_t udp_port;
9011         portid_t port_id;
9012 };
9013
9014 static void
9015 cmd_tunnel_udp_config_parsed(void *parsed_result,
9016                           __attribute__((unused)) struct cmdline *cl,
9017                           __attribute__((unused)) void *data)
9018 {
9019         struct cmd_tunnel_udp_config *res = parsed_result;
9020         struct rte_eth_udp_tunnel tunnel_udp;
9021         int ret;
9022
9023         tunnel_udp.udp_port = res->udp_port;
9024
9025         if (!strcmp(res->cmd, "rx_vxlan_port"))
9026                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9027
9028         if (!strcmp(res->what, "add"))
9029                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9030                                                       &tunnel_udp);
9031         else
9032                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9033                                                          &tunnel_udp);
9034
9035         if (ret < 0)
9036                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9037 }
9038
9039 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9040         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9041                                 cmd, "rx_vxlan_port");
9042 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9043         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9044                                 what, "add#rm");
9045 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9046         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9047                                 udp_port, UINT16);
9048 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9049         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9050                                 port_id, UINT16);
9051
9052 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9053         .f = cmd_tunnel_udp_config_parsed,
9054         .data = (void *)0,
9055         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9056                 "Add/Remove a tunneling UDP port filter",
9057         .tokens = {
9058                 (void *)&cmd_tunnel_udp_config_cmd,
9059                 (void *)&cmd_tunnel_udp_config_what,
9060                 (void *)&cmd_tunnel_udp_config_udp_port,
9061                 (void *)&cmd_tunnel_udp_config_port_id,
9062                 NULL,
9063         },
9064 };
9065
9066 struct cmd_config_tunnel_udp_port {
9067         cmdline_fixed_string_t port;
9068         cmdline_fixed_string_t config;
9069         portid_t port_id;
9070         cmdline_fixed_string_t udp_tunnel_port;
9071         cmdline_fixed_string_t action;
9072         cmdline_fixed_string_t tunnel_type;
9073         uint16_t udp_port;
9074 };
9075
9076 static void
9077 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9078                                __attribute__((unused)) struct cmdline *cl,
9079                                __attribute__((unused)) void *data)
9080 {
9081         struct cmd_config_tunnel_udp_port *res = parsed_result;
9082         struct rte_eth_udp_tunnel tunnel_udp;
9083         int ret = 0;
9084
9085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9086                 return;
9087
9088         tunnel_udp.udp_port = res->udp_port;
9089
9090         if (!strcmp(res->tunnel_type, "vxlan")) {
9091                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9092         } else if (!strcmp(res->tunnel_type, "geneve")) {
9093                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9094         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9095                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9096         } else {
9097                 printf("Invalid tunnel type\n");
9098                 return;
9099         }
9100
9101         if (!strcmp(res->action, "add"))
9102                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9103                                                       &tunnel_udp);
9104         else
9105                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9106                                                          &tunnel_udp);
9107
9108         if (ret < 0)
9109                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9110 }
9111
9112 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9113         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9114                                  "port");
9115 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9116         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9117                                  "config");
9118 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9119         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9120                               UINT16);
9121 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9122         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9123                                  udp_tunnel_port,
9124                                  "udp_tunnel_port");
9125 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9126         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9127                                  "add#rm");
9128 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9129         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9130                                  "vxlan#geneve#vxlan-gpe");
9131 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9132         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9133                               UINT16);
9134
9135 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9136         .f = cmd_cfg_tunnel_udp_port_parsed,
9137         .data = NULL,
9138         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9139         .tokens = {
9140                 (void *)&cmd_config_tunnel_udp_port_port,
9141                 (void *)&cmd_config_tunnel_udp_port_config,
9142                 (void *)&cmd_config_tunnel_udp_port_port_id,
9143                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9144                 (void *)&cmd_config_tunnel_udp_port_action,
9145                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9146                 (void *)&cmd_config_tunnel_udp_port_value,
9147                 NULL,
9148         },
9149 };
9150
9151 /* *** GLOBAL CONFIG *** */
9152 struct cmd_global_config_result {
9153         cmdline_fixed_string_t cmd;
9154         portid_t port_id;
9155         cmdline_fixed_string_t cfg_type;
9156         uint8_t len;
9157 };
9158
9159 static void
9160 cmd_global_config_parsed(void *parsed_result,
9161                          __attribute__((unused)) struct cmdline *cl,
9162                          __attribute__((unused)) void *data)
9163 {
9164         struct cmd_global_config_result *res = parsed_result;
9165         struct rte_eth_global_cfg conf;
9166         int ret;
9167
9168         memset(&conf, 0, sizeof(conf));
9169         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9170         conf.cfg.gre_key_len = res->len;
9171         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9172                                       RTE_ETH_FILTER_SET, &conf);
9173         if (ret != 0)
9174                 printf("Global config error\n");
9175 }
9176
9177 cmdline_parse_token_string_t cmd_global_config_cmd =
9178         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9179                 "global_config");
9180 cmdline_parse_token_num_t cmd_global_config_port_id =
9181         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9182                                UINT16);
9183 cmdline_parse_token_string_t cmd_global_config_type =
9184         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9185                 cfg_type, "gre-key-len");
9186 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9187         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9188                 len, UINT8);
9189
9190 cmdline_parse_inst_t cmd_global_config = {
9191         .f = cmd_global_config_parsed,
9192         .data = (void *)NULL,
9193         .help_str = "global_config <port_id> gre-key-len <key_len>",
9194         .tokens = {
9195                 (void *)&cmd_global_config_cmd,
9196                 (void *)&cmd_global_config_port_id,
9197                 (void *)&cmd_global_config_type,
9198                 (void *)&cmd_global_config_gre_key_len,
9199                 NULL,
9200         },
9201 };
9202
9203 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9204 struct cmd_set_mirror_mask_result {
9205         cmdline_fixed_string_t set;
9206         cmdline_fixed_string_t port;
9207         portid_t port_id;
9208         cmdline_fixed_string_t mirror;
9209         uint8_t rule_id;
9210         cmdline_fixed_string_t what;
9211         cmdline_fixed_string_t value;
9212         cmdline_fixed_string_t dstpool;
9213         uint8_t dstpool_id;
9214         cmdline_fixed_string_t on;
9215 };
9216
9217 cmdline_parse_token_string_t cmd_mirror_mask_set =
9218         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9219                                 set, "set");
9220 cmdline_parse_token_string_t cmd_mirror_mask_port =
9221         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9222                                 port, "port");
9223 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9224         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9225                                 port_id, UINT16);
9226 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9227         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9228                                 mirror, "mirror-rule");
9229 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9230         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9231                                 rule_id, UINT8);
9232 cmdline_parse_token_string_t cmd_mirror_mask_what =
9233         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9234                                 what, "pool-mirror-up#pool-mirror-down"
9235                                       "#vlan-mirror");
9236 cmdline_parse_token_string_t cmd_mirror_mask_value =
9237         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9238                                 value, NULL);
9239 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9240         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9241                                 dstpool, "dst-pool");
9242 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9243         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9244                                 dstpool_id, UINT8);
9245 cmdline_parse_token_string_t cmd_mirror_mask_on =
9246         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9247                                 on, "on#off");
9248
9249 static void
9250 cmd_set_mirror_mask_parsed(void *parsed_result,
9251                        __attribute__((unused)) struct cmdline *cl,
9252                        __attribute__((unused)) void *data)
9253 {
9254         int ret,nb_item,i;
9255         struct cmd_set_mirror_mask_result *res = parsed_result;
9256         struct rte_eth_mirror_conf mr_conf;
9257
9258         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9259
9260         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9261
9262         mr_conf.dst_pool = res->dstpool_id;
9263
9264         if (!strcmp(res->what, "pool-mirror-up")) {
9265                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9266                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9267         } else if (!strcmp(res->what, "pool-mirror-down")) {
9268                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9269                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9270         } else if (!strcmp(res->what, "vlan-mirror")) {
9271                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9272                 nb_item = parse_item_list(res->value, "vlan",
9273                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9274                 if (nb_item <= 0)
9275                         return;
9276
9277                 for (i = 0; i < nb_item; i++) {
9278                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9279                                 printf("Invalid vlan_id: must be < 4096\n");
9280                                 return;
9281                         }
9282
9283                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9284                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9285                 }
9286         }
9287
9288         if (!strcmp(res->on, "on"))
9289                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9290                                                 res->rule_id, 1);
9291         else
9292                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9293                                                 res->rule_id, 0);
9294         if (ret < 0)
9295                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9296 }
9297
9298 cmdline_parse_inst_t cmd_set_mirror_mask = {
9299                 .f = cmd_set_mirror_mask_parsed,
9300                 .data = NULL,
9301                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9302                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9303                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9304                 .tokens = {
9305                         (void *)&cmd_mirror_mask_set,
9306                         (void *)&cmd_mirror_mask_port,
9307                         (void *)&cmd_mirror_mask_portid,
9308                         (void *)&cmd_mirror_mask_mirror,
9309                         (void *)&cmd_mirror_mask_ruleid,
9310                         (void *)&cmd_mirror_mask_what,
9311                         (void *)&cmd_mirror_mask_value,
9312                         (void *)&cmd_mirror_mask_dstpool,
9313                         (void *)&cmd_mirror_mask_poolid,
9314                         (void *)&cmd_mirror_mask_on,
9315                         NULL,
9316                 },
9317 };
9318
9319 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9320 struct cmd_set_mirror_link_result {
9321         cmdline_fixed_string_t set;
9322         cmdline_fixed_string_t port;
9323         portid_t port_id;
9324         cmdline_fixed_string_t mirror;
9325         uint8_t rule_id;
9326         cmdline_fixed_string_t what;
9327         cmdline_fixed_string_t dstpool;
9328         uint8_t dstpool_id;
9329         cmdline_fixed_string_t on;
9330 };
9331
9332 cmdline_parse_token_string_t cmd_mirror_link_set =
9333         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9334                                  set, "set");
9335 cmdline_parse_token_string_t cmd_mirror_link_port =
9336         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9337                                 port, "port");
9338 cmdline_parse_token_num_t cmd_mirror_link_portid =
9339         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9340                                 port_id, UINT16);
9341 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9342         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9343                                 mirror, "mirror-rule");
9344 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9345         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9346                             rule_id, UINT8);
9347 cmdline_parse_token_string_t cmd_mirror_link_what =
9348         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9349                                 what, "uplink-mirror#downlink-mirror");
9350 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9351         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9352                                 dstpool, "dst-pool");
9353 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9354         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9355                                 dstpool_id, UINT8);
9356 cmdline_parse_token_string_t cmd_mirror_link_on =
9357         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9358                                 on, "on#off");
9359
9360 static void
9361 cmd_set_mirror_link_parsed(void *parsed_result,
9362                        __attribute__((unused)) struct cmdline *cl,
9363                        __attribute__((unused)) void *data)
9364 {
9365         int ret;
9366         struct cmd_set_mirror_link_result *res = parsed_result;
9367         struct rte_eth_mirror_conf mr_conf;
9368
9369         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9370         if (!strcmp(res->what, "uplink-mirror"))
9371                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9372         else
9373                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9374
9375         mr_conf.dst_pool = res->dstpool_id;
9376
9377         if (!strcmp(res->on, "on"))
9378                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9379                                                 res->rule_id, 1);
9380         else
9381                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9382                                                 res->rule_id, 0);
9383
9384         /* check the return value and print it if is < 0 */
9385         if (ret < 0)
9386                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9387
9388 }
9389
9390 cmdline_parse_inst_t cmd_set_mirror_link = {
9391                 .f = cmd_set_mirror_link_parsed,
9392                 .data = NULL,
9393                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9394                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9395                 .tokens = {
9396                         (void *)&cmd_mirror_link_set,
9397                         (void *)&cmd_mirror_link_port,
9398                         (void *)&cmd_mirror_link_portid,
9399                         (void *)&cmd_mirror_link_mirror,
9400                         (void *)&cmd_mirror_link_ruleid,
9401                         (void *)&cmd_mirror_link_what,
9402                         (void *)&cmd_mirror_link_dstpool,
9403                         (void *)&cmd_mirror_link_poolid,
9404                         (void *)&cmd_mirror_link_on,
9405                         NULL,
9406                 },
9407 };
9408
9409 /* *** RESET VM MIRROR RULE *** */
9410 struct cmd_rm_mirror_rule_result {
9411         cmdline_fixed_string_t reset;
9412         cmdline_fixed_string_t port;
9413         portid_t port_id;
9414         cmdline_fixed_string_t mirror;
9415         uint8_t rule_id;
9416 };
9417
9418 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9419         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9420                                  reset, "reset");
9421 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9422         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9423                                 port, "port");
9424 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9425         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9426                                 port_id, UINT16);
9427 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9428         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9429                                 mirror, "mirror-rule");
9430 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9431         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9432                                 rule_id, UINT8);
9433
9434 static void
9435 cmd_reset_mirror_rule_parsed(void *parsed_result,
9436                        __attribute__((unused)) struct cmdline *cl,
9437                        __attribute__((unused)) void *data)
9438 {
9439         int ret;
9440         struct cmd_set_mirror_link_result *res = parsed_result;
9441         /* check rule_id */
9442         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9443         if(ret < 0)
9444                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9445 }
9446
9447 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9448                 .f = cmd_reset_mirror_rule_parsed,
9449                 .data = NULL,
9450                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9451                 .tokens = {
9452                         (void *)&cmd_rm_mirror_rule_reset,
9453                         (void *)&cmd_rm_mirror_rule_port,
9454                         (void *)&cmd_rm_mirror_rule_portid,
9455                         (void *)&cmd_rm_mirror_rule_mirror,
9456                         (void *)&cmd_rm_mirror_rule_ruleid,
9457                         NULL,
9458                 },
9459 };
9460
9461 /* ******************************************************************************** */
9462
9463 struct cmd_dump_result {
9464         cmdline_fixed_string_t dump;
9465 };
9466
9467 static void
9468 dump_struct_sizes(void)
9469 {
9470 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9471         DUMP_SIZE(struct rte_mbuf);
9472         DUMP_SIZE(struct rte_mempool);
9473         DUMP_SIZE(struct rte_ring);
9474 #undef DUMP_SIZE
9475 }
9476
9477 static void cmd_dump_parsed(void *parsed_result,
9478                             __attribute__((unused)) struct cmdline *cl,
9479                             __attribute__((unused)) void *data)
9480 {
9481         struct cmd_dump_result *res = parsed_result;
9482
9483         if (!strcmp(res->dump, "dump_physmem"))
9484                 rte_dump_physmem_layout(stdout);
9485         else if (!strcmp(res->dump, "dump_memzone"))
9486                 rte_memzone_dump(stdout);
9487         else if (!strcmp(res->dump, "dump_struct_sizes"))
9488                 dump_struct_sizes();
9489         else if (!strcmp(res->dump, "dump_ring"))
9490                 rte_ring_list_dump(stdout);
9491         else if (!strcmp(res->dump, "dump_mempool"))
9492                 rte_mempool_list_dump(stdout);
9493         else if (!strcmp(res->dump, "dump_devargs"))
9494                 rte_devargs_dump(stdout);
9495         else if (!strcmp(res->dump, "dump_log_types"))
9496                 rte_log_dump(stdout);
9497 }
9498
9499 cmdline_parse_token_string_t cmd_dump_dump =
9500         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9501                 "dump_physmem#"
9502                 "dump_memzone#"
9503                 "dump_struct_sizes#"
9504                 "dump_ring#"
9505                 "dump_mempool#"
9506                 "dump_devargs#"
9507                 "dump_log_types");
9508
9509 cmdline_parse_inst_t cmd_dump = {
9510         .f = cmd_dump_parsed,  /* function to call */
9511         .data = NULL,      /* 2nd arg of func */
9512         .help_str = "Dump status",
9513         .tokens = {        /* token list, NULL terminated */
9514                 (void *)&cmd_dump_dump,
9515                 NULL,
9516         },
9517 };
9518
9519 /* ******************************************************************************** */
9520
9521 struct cmd_dump_one_result {
9522         cmdline_fixed_string_t dump;
9523         cmdline_fixed_string_t name;
9524 };
9525
9526 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9527                                 __attribute__((unused)) void *data)
9528 {
9529         struct cmd_dump_one_result *res = parsed_result;
9530
9531         if (!strcmp(res->dump, "dump_ring")) {
9532                 struct rte_ring *r;
9533                 r = rte_ring_lookup(res->name);
9534                 if (r == NULL) {
9535                         cmdline_printf(cl, "Cannot find ring\n");
9536                         return;
9537                 }
9538                 rte_ring_dump(stdout, r);
9539         } else if (!strcmp(res->dump, "dump_mempool")) {
9540                 struct rte_mempool *mp;
9541                 mp = rte_mempool_lookup(res->name);
9542                 if (mp == NULL) {
9543                         cmdline_printf(cl, "Cannot find mempool\n");
9544                         return;
9545                 }
9546                 rte_mempool_dump(stdout, mp);
9547         }
9548 }
9549
9550 cmdline_parse_token_string_t cmd_dump_one_dump =
9551         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9552                                  "dump_ring#dump_mempool");
9553
9554 cmdline_parse_token_string_t cmd_dump_one_name =
9555         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9556
9557 cmdline_parse_inst_t cmd_dump_one = {
9558         .f = cmd_dump_one_parsed,  /* function to call */
9559         .data = NULL,      /* 2nd arg of func */
9560         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9561         .tokens = {        /* token list, NULL terminated */
9562                 (void *)&cmd_dump_one_dump,
9563                 (void *)&cmd_dump_one_name,
9564                 NULL,
9565         },
9566 };
9567
9568 /* *** Add/Del syn filter *** */
9569 struct cmd_syn_filter_result {
9570         cmdline_fixed_string_t filter;
9571         portid_t port_id;
9572         cmdline_fixed_string_t ops;
9573         cmdline_fixed_string_t priority;
9574         cmdline_fixed_string_t high;
9575         cmdline_fixed_string_t queue;
9576         uint16_t queue_id;
9577 };
9578
9579 static void
9580 cmd_syn_filter_parsed(void *parsed_result,
9581                         __attribute__((unused)) struct cmdline *cl,
9582                         __attribute__((unused)) void *data)
9583 {
9584         struct cmd_syn_filter_result *res = parsed_result;
9585         struct rte_eth_syn_filter syn_filter;
9586         int ret = 0;
9587
9588         ret = rte_eth_dev_filter_supported(res->port_id,
9589                                         RTE_ETH_FILTER_SYN);
9590         if (ret < 0) {
9591                 printf("syn filter is not supported on port %u.\n",
9592                                 res->port_id);
9593                 return;
9594         }
9595
9596         memset(&syn_filter, 0, sizeof(syn_filter));
9597
9598         if (!strcmp(res->ops, "add")) {
9599                 if (!strcmp(res->high, "high"))
9600                         syn_filter.hig_pri = 1;
9601                 else
9602                         syn_filter.hig_pri = 0;
9603
9604                 syn_filter.queue = res->queue_id;
9605                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9606                                                 RTE_ETH_FILTER_SYN,
9607                                                 RTE_ETH_FILTER_ADD,
9608                                                 &syn_filter);
9609         } else
9610                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9611                                                 RTE_ETH_FILTER_SYN,
9612                                                 RTE_ETH_FILTER_DELETE,
9613                                                 &syn_filter);
9614
9615         if (ret < 0)
9616                 printf("syn filter programming error: (%s)\n",
9617                                 strerror(-ret));
9618 }
9619
9620 cmdline_parse_token_string_t cmd_syn_filter_filter =
9621         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9622         filter, "syn_filter");
9623 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9624         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9625         port_id, UINT16);
9626 cmdline_parse_token_string_t cmd_syn_filter_ops =
9627         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9628         ops, "add#del");
9629 cmdline_parse_token_string_t cmd_syn_filter_priority =
9630         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9631                                 priority, "priority");
9632 cmdline_parse_token_string_t cmd_syn_filter_high =
9633         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9634                                 high, "high#low");
9635 cmdline_parse_token_string_t cmd_syn_filter_queue =
9636         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9637                                 queue, "queue");
9638 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9639         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9640                                 queue_id, UINT16);
9641
9642 cmdline_parse_inst_t cmd_syn_filter = {
9643         .f = cmd_syn_filter_parsed,
9644         .data = NULL,
9645         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9646                 "<queue_id>: Add/Delete syn filter",
9647         .tokens = {
9648                 (void *)&cmd_syn_filter_filter,
9649                 (void *)&cmd_syn_filter_port_id,
9650                 (void *)&cmd_syn_filter_ops,
9651                 (void *)&cmd_syn_filter_priority,
9652                 (void *)&cmd_syn_filter_high,
9653                 (void *)&cmd_syn_filter_queue,
9654                 (void *)&cmd_syn_filter_queue_id,
9655                 NULL,
9656         },
9657 };
9658
9659 /* *** queue region set *** */
9660 struct cmd_queue_region_result {
9661         cmdline_fixed_string_t set;
9662         cmdline_fixed_string_t port;
9663         portid_t port_id;
9664         cmdline_fixed_string_t cmd;
9665         cmdline_fixed_string_t region;
9666         uint8_t  region_id;
9667         cmdline_fixed_string_t queue_start_index;
9668         uint8_t  queue_id;
9669         cmdline_fixed_string_t queue_num;
9670         uint8_t  queue_num_value;
9671 };
9672
9673 static void
9674 cmd_queue_region_parsed(void *parsed_result,
9675                         __attribute__((unused)) struct cmdline *cl,
9676                         __attribute__((unused)) void *data)
9677 {
9678         struct cmd_queue_region_result *res = parsed_result;
9679         int ret = -ENOTSUP;
9680 #ifdef RTE_LIBRTE_I40E_PMD
9681         struct rte_pmd_i40e_queue_region_conf region_conf;
9682         enum rte_pmd_i40e_queue_region_op op_type;
9683 #endif
9684
9685         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9686                 return;
9687
9688 #ifdef RTE_LIBRTE_I40E_PMD
9689         memset(&region_conf, 0, sizeof(region_conf));
9690         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9691         region_conf.region_id = res->region_id;
9692         region_conf.queue_num = res->queue_num_value;
9693         region_conf.queue_start_index = res->queue_id;
9694
9695         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9696                                 op_type, &region_conf);
9697 #endif
9698
9699         switch (ret) {
9700         case 0:
9701                 break;
9702         case -ENOTSUP:
9703                 printf("function not implemented or supported\n");
9704                 break;
9705         default:
9706                 printf("queue region config error: (%s)\n", strerror(-ret));
9707         }
9708 }
9709
9710 cmdline_parse_token_string_t cmd_queue_region_set =
9711 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9712                 set, "set");
9713 cmdline_parse_token_string_t cmd_queue_region_port =
9714         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9715 cmdline_parse_token_num_t cmd_queue_region_port_id =
9716         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9717                                 port_id, UINT16);
9718 cmdline_parse_token_string_t cmd_queue_region_cmd =
9719         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9720                                  cmd, "queue-region");
9721 cmdline_parse_token_string_t cmd_queue_region_id =
9722         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9723                                 region, "region_id");
9724 cmdline_parse_token_num_t cmd_queue_region_index =
9725         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9726                                 region_id, UINT8);
9727 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9728         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9729                                 queue_start_index, "queue_start_index");
9730 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9731         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9732                                 queue_id, UINT8);
9733 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9734         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9735                                 queue_num, "queue_num");
9736 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9737         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9738                                 queue_num_value, UINT8);
9739
9740 cmdline_parse_inst_t cmd_queue_region = {
9741         .f = cmd_queue_region_parsed,
9742         .data = NULL,
9743         .help_str = "set port <port_id> queue-region region_id <value> "
9744                 "queue_start_index <value> queue_num <value>: Set a queue region",
9745         .tokens = {
9746                 (void *)&cmd_queue_region_set,
9747                 (void *)&cmd_queue_region_port,
9748                 (void *)&cmd_queue_region_port_id,
9749                 (void *)&cmd_queue_region_cmd,
9750                 (void *)&cmd_queue_region_id,
9751                 (void *)&cmd_queue_region_index,
9752                 (void *)&cmd_queue_region_queue_start_index,
9753                 (void *)&cmd_queue_region_queue_id,
9754                 (void *)&cmd_queue_region_queue_num,
9755                 (void *)&cmd_queue_region_queue_num_value,
9756                 NULL,
9757         },
9758 };
9759
9760 /* *** queue region and flowtype set *** */
9761 struct cmd_region_flowtype_result {
9762         cmdline_fixed_string_t set;
9763         cmdline_fixed_string_t port;
9764         portid_t port_id;
9765         cmdline_fixed_string_t cmd;
9766         cmdline_fixed_string_t region;
9767         uint8_t  region_id;
9768         cmdline_fixed_string_t flowtype;
9769         uint8_t  flowtype_id;
9770 };
9771
9772 static void
9773 cmd_region_flowtype_parsed(void *parsed_result,
9774                         __attribute__((unused)) struct cmdline *cl,
9775                         __attribute__((unused)) void *data)
9776 {
9777         struct cmd_region_flowtype_result *res = parsed_result;
9778         int ret = -ENOTSUP;
9779 #ifdef RTE_LIBRTE_I40E_PMD
9780         struct rte_pmd_i40e_queue_region_conf region_conf;
9781         enum rte_pmd_i40e_queue_region_op op_type;
9782 #endif
9783
9784         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9785                 return;
9786
9787 #ifdef RTE_LIBRTE_I40E_PMD
9788         memset(&region_conf, 0, sizeof(region_conf));
9789
9790         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9791         region_conf.region_id = res->region_id;
9792         region_conf.hw_flowtype = res->flowtype_id;
9793
9794         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9795                         op_type, &region_conf);
9796 #endif
9797
9798         switch (ret) {
9799         case 0:
9800                 break;
9801         case -ENOTSUP:
9802                 printf("function not implemented or supported\n");
9803                 break;
9804         default:
9805                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9806         }
9807 }
9808
9809 cmdline_parse_token_string_t cmd_region_flowtype_set =
9810 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9811                                 set, "set");
9812 cmdline_parse_token_string_t cmd_region_flowtype_port =
9813         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9814                                 port, "port");
9815 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9816         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9817                                 port_id, UINT16);
9818 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9819         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9820                                 cmd, "queue-region");
9821 cmdline_parse_token_string_t cmd_region_flowtype_index =
9822         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 region, "region_id");
9824 cmdline_parse_token_num_t cmd_region_flowtype_id =
9825         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 region_id, UINT8);
9827 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9828         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9829                                 flowtype, "flowtype");
9830 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9831         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9832                                 flowtype_id, UINT8);
9833 cmdline_parse_inst_t cmd_region_flowtype = {
9834         .f = cmd_region_flowtype_parsed,
9835         .data = NULL,
9836         .help_str = "set port <port_id> queue-region region_id <value> "
9837                 "flowtype <value>: Set a flowtype region index",
9838         .tokens = {
9839                 (void *)&cmd_region_flowtype_set,
9840                 (void *)&cmd_region_flowtype_port,
9841                 (void *)&cmd_region_flowtype_port_index,
9842                 (void *)&cmd_region_flowtype_cmd,
9843                 (void *)&cmd_region_flowtype_index,
9844                 (void *)&cmd_region_flowtype_id,
9845                 (void *)&cmd_region_flowtype_flow_index,
9846                 (void *)&cmd_region_flowtype_flow_id,
9847                 NULL,
9848         },
9849 };
9850
9851 /* *** User Priority (UP) to queue region (region_id) set *** */
9852 struct cmd_user_priority_region_result {
9853         cmdline_fixed_string_t set;
9854         cmdline_fixed_string_t port;
9855         portid_t port_id;
9856         cmdline_fixed_string_t cmd;
9857         cmdline_fixed_string_t user_priority;
9858         uint8_t  user_priority_id;
9859         cmdline_fixed_string_t region;
9860         uint8_t  region_id;
9861 };
9862
9863 static void
9864 cmd_user_priority_region_parsed(void *parsed_result,
9865                         __attribute__((unused)) struct cmdline *cl,
9866                         __attribute__((unused)) void *data)
9867 {
9868         struct cmd_user_priority_region_result *res = parsed_result;
9869         int ret = -ENOTSUP;
9870 #ifdef RTE_LIBRTE_I40E_PMD
9871         struct rte_pmd_i40e_queue_region_conf region_conf;
9872         enum rte_pmd_i40e_queue_region_op op_type;
9873 #endif
9874
9875         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9876                 return;
9877
9878 #ifdef RTE_LIBRTE_I40E_PMD
9879         memset(&region_conf, 0, sizeof(region_conf));
9880         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9881         region_conf.user_priority = res->user_priority_id;
9882         region_conf.region_id = res->region_id;
9883
9884         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9885                                 op_type, &region_conf);
9886 #endif
9887
9888         switch (ret) {
9889         case 0:
9890                 break;
9891         case -ENOTSUP:
9892                 printf("function not implemented or supported\n");
9893                 break;
9894         default:
9895                 printf("user_priority region config error: (%s)\n",
9896                                 strerror(-ret));
9897         }
9898 }
9899
9900 cmdline_parse_token_string_t cmd_user_priority_region_set =
9901         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9902                                 set, "set");
9903 cmdline_parse_token_string_t cmd_user_priority_region_port =
9904         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9905                                 port, "port");
9906 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9907         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9908                                 port_id, UINT16);
9909 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9910         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9911                                 cmd, "queue-region");
9912 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9913         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 user_priority, "UP");
9915 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9916         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 user_priority_id, UINT8);
9918 cmdline_parse_token_string_t cmd_user_priority_region_region =
9919         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9920                                 region, "region_id");
9921 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9922         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9923                                 region_id, UINT8);
9924
9925 cmdline_parse_inst_t cmd_user_priority_region = {
9926         .f = cmd_user_priority_region_parsed,
9927         .data = NULL,
9928         .help_str = "set port <port_id> queue-region UP <value> "
9929                 "region_id <value>: Set the mapping of User Priority (UP) "
9930                 "to queue region (region_id) ",
9931         .tokens = {
9932                 (void *)&cmd_user_priority_region_set,
9933                 (void *)&cmd_user_priority_region_port,
9934                 (void *)&cmd_user_priority_region_port_index,
9935                 (void *)&cmd_user_priority_region_cmd,
9936                 (void *)&cmd_user_priority_region_UP,
9937                 (void *)&cmd_user_priority_region_UP_id,
9938                 (void *)&cmd_user_priority_region_region,
9939                 (void *)&cmd_user_priority_region_region_id,
9940                 NULL,
9941         },
9942 };
9943
9944 /* *** flush all queue region related configuration *** */
9945 struct cmd_flush_queue_region_result {
9946         cmdline_fixed_string_t set;
9947         cmdline_fixed_string_t port;
9948         portid_t port_id;
9949         cmdline_fixed_string_t cmd;
9950         cmdline_fixed_string_t flush;
9951         cmdline_fixed_string_t what;
9952 };
9953
9954 static void
9955 cmd_flush_queue_region_parsed(void *parsed_result,
9956                         __attribute__((unused)) struct cmdline *cl,
9957                         __attribute__((unused)) void *data)
9958 {
9959         struct cmd_flush_queue_region_result *res = parsed_result;
9960         int ret = -ENOTSUP;
9961 #ifdef RTE_LIBRTE_I40E_PMD
9962         struct rte_pmd_i40e_queue_region_conf region_conf;
9963         enum rte_pmd_i40e_queue_region_op op_type;
9964 #endif
9965
9966         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9967                 return;
9968
9969 #ifdef RTE_LIBRTE_I40E_PMD
9970         memset(&region_conf, 0, sizeof(region_conf));
9971
9972         if (strcmp(res->what, "on") == 0)
9973                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9974         else
9975                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9976
9977         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9978                                 op_type, &region_conf);
9979 #endif
9980
9981         switch (ret) {
9982         case 0:
9983                 break;
9984         case -ENOTSUP:
9985                 printf("function not implemented or supported\n");
9986                 break;
9987         default:
9988                 printf("queue region config flush error: (%s)\n",
9989                                 strerror(-ret));
9990         }
9991 }
9992
9993 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9994         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9995                                 set, "set");
9996 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9997         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9998                                 port, "port");
9999 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10000         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10001                                 port_id, UINT16);
10002 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10004                                 cmd, "queue-region");
10005 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10006         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10007                                 flush, "flush");
10008 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10009         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10010                                 what, "on#off");
10011
10012 cmdline_parse_inst_t cmd_flush_queue_region = {
10013         .f = cmd_flush_queue_region_parsed,
10014         .data = NULL,
10015         .help_str = "set port <port_id> queue-region flush on|off"
10016                 ": flush all queue region related configuration",
10017         .tokens = {
10018                 (void *)&cmd_flush_queue_region_set,
10019                 (void *)&cmd_flush_queue_region_port,
10020                 (void *)&cmd_flush_queue_region_port_index,
10021                 (void *)&cmd_flush_queue_region_cmd,
10022                 (void *)&cmd_flush_queue_region_flush,
10023                 (void *)&cmd_flush_queue_region_what,
10024                 NULL,
10025         },
10026 };
10027
10028 /* *** get all queue region related configuration info *** */
10029 struct cmd_show_queue_region_info {
10030         cmdline_fixed_string_t show;
10031         cmdline_fixed_string_t port;
10032         portid_t port_id;
10033         cmdline_fixed_string_t cmd;
10034 };
10035
10036 static void
10037 cmd_show_queue_region_info_parsed(void *parsed_result,
10038                         __attribute__((unused)) struct cmdline *cl,
10039                         __attribute__((unused)) void *data)
10040 {
10041         struct cmd_show_queue_region_info *res = parsed_result;
10042         int ret = -ENOTSUP;
10043 #ifdef RTE_LIBRTE_I40E_PMD
10044         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10045         enum rte_pmd_i40e_queue_region_op op_type;
10046 #endif
10047
10048         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10049                 return;
10050
10051 #ifdef RTE_LIBRTE_I40E_PMD
10052         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10053
10054         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10055
10056         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10057                                         op_type, &rte_pmd_regions);
10058
10059         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10060 #endif
10061
10062         switch (ret) {
10063         case 0:
10064                 break;
10065         case -ENOTSUP:
10066                 printf("function not implemented or supported\n");
10067                 break;
10068         default:
10069                 printf("queue region config info show error: (%s)\n",
10070                                 strerror(-ret));
10071         }
10072 }
10073
10074 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10075 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10076                                 show, "show");
10077 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10078         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10079                                 port, "port");
10080 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10081         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10082                                 port_id, UINT16);
10083 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10084         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10085                                 cmd, "queue-region");
10086
10087 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10088         .f = cmd_show_queue_region_info_parsed,
10089         .data = NULL,
10090         .help_str = "show port <port_id> queue-region"
10091                 ": show all queue region related configuration info",
10092         .tokens = {
10093                 (void *)&cmd_show_queue_region_info_get,
10094                 (void *)&cmd_show_queue_region_info_port,
10095                 (void *)&cmd_show_queue_region_info_port_index,
10096                 (void *)&cmd_show_queue_region_info_cmd,
10097                 NULL,
10098         },
10099 };
10100
10101 /* *** ADD/REMOVE A 2tuple FILTER *** */
10102 struct cmd_2tuple_filter_result {
10103         cmdline_fixed_string_t filter;
10104         portid_t port_id;
10105         cmdline_fixed_string_t ops;
10106         cmdline_fixed_string_t dst_port;
10107         uint16_t dst_port_value;
10108         cmdline_fixed_string_t protocol;
10109         uint8_t protocol_value;
10110         cmdline_fixed_string_t mask;
10111         uint8_t  mask_value;
10112         cmdline_fixed_string_t tcp_flags;
10113         uint8_t tcp_flags_value;
10114         cmdline_fixed_string_t priority;
10115         uint8_t  priority_value;
10116         cmdline_fixed_string_t queue;
10117         uint16_t  queue_id;
10118 };
10119
10120 static void
10121 cmd_2tuple_filter_parsed(void *parsed_result,
10122                         __attribute__((unused)) struct cmdline *cl,
10123                         __attribute__((unused)) void *data)
10124 {
10125         struct rte_eth_ntuple_filter filter;
10126         struct cmd_2tuple_filter_result *res = parsed_result;
10127         int ret = 0;
10128
10129         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10130         if (ret < 0) {
10131                 printf("ntuple filter is not supported on port %u.\n",
10132                         res->port_id);
10133                 return;
10134         }
10135
10136         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10137
10138         filter.flags = RTE_2TUPLE_FLAGS;
10139         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10140         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10141         filter.proto = res->protocol_value;
10142         filter.priority = res->priority_value;
10143         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10144                 printf("nonzero tcp_flags is only meaningful"
10145                         " when protocol is TCP.\n");
10146                 return;
10147         }
10148         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10149                 printf("invalid TCP flags.\n");
10150                 return;
10151         }
10152
10153         if (res->tcp_flags_value != 0) {
10154                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10155                 filter.tcp_flags = res->tcp_flags_value;
10156         }
10157
10158         /* need convert to big endian. */
10159         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10160         filter.queue = res->queue_id;
10161
10162         if (!strcmp(res->ops, "add"))
10163                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10164                                 RTE_ETH_FILTER_NTUPLE,
10165                                 RTE_ETH_FILTER_ADD,
10166                                 &filter);
10167         else
10168                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10169                                 RTE_ETH_FILTER_NTUPLE,
10170                                 RTE_ETH_FILTER_DELETE,
10171                                 &filter);
10172         if (ret < 0)
10173                 printf("2tuple filter programming error: (%s)\n",
10174                         strerror(-ret));
10175
10176 }
10177
10178 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10179         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10180                                  filter, "2tuple_filter");
10181 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10182         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10183                                 port_id, UINT16);
10184 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10185         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10186                                  ops, "add#del");
10187 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10188         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10189                                 dst_port, "dst_port");
10190 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10191         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10192                                 dst_port_value, UINT16);
10193 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10194         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10195                                 protocol, "protocol");
10196 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10197         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10198                                 protocol_value, UINT8);
10199 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10200         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10201                                 mask, "mask");
10202 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10203         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10204                                 mask_value, INT8);
10205 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10206         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10207                                 tcp_flags, "tcp_flags");
10208 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10209         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10210                                 tcp_flags_value, UINT8);
10211 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10212         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10213                                 priority, "priority");
10214 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10215         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10216                                 priority_value, UINT8);
10217 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10218         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10219                                 queue, "queue");
10220 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10221         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10222                                 queue_id, UINT16);
10223
10224 cmdline_parse_inst_t cmd_2tuple_filter = {
10225         .f = cmd_2tuple_filter_parsed,
10226         .data = NULL,
10227         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10228                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10229                 "<queue_id>: Add a 2tuple filter",
10230         .tokens = {
10231                 (void *)&cmd_2tuple_filter_filter,
10232                 (void *)&cmd_2tuple_filter_port_id,
10233                 (void *)&cmd_2tuple_filter_ops,
10234                 (void *)&cmd_2tuple_filter_dst_port,
10235                 (void *)&cmd_2tuple_filter_dst_port_value,
10236                 (void *)&cmd_2tuple_filter_protocol,
10237                 (void *)&cmd_2tuple_filter_protocol_value,
10238                 (void *)&cmd_2tuple_filter_mask,
10239                 (void *)&cmd_2tuple_filter_mask_value,
10240                 (void *)&cmd_2tuple_filter_tcp_flags,
10241                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10242                 (void *)&cmd_2tuple_filter_priority,
10243                 (void *)&cmd_2tuple_filter_priority_value,
10244                 (void *)&cmd_2tuple_filter_queue,
10245                 (void *)&cmd_2tuple_filter_queue_id,
10246                 NULL,
10247         },
10248 };
10249
10250 /* *** ADD/REMOVE A 5tuple FILTER *** */
10251 struct cmd_5tuple_filter_result {
10252         cmdline_fixed_string_t filter;
10253         portid_t port_id;
10254         cmdline_fixed_string_t ops;
10255         cmdline_fixed_string_t dst_ip;
10256         cmdline_ipaddr_t dst_ip_value;
10257         cmdline_fixed_string_t src_ip;
10258         cmdline_ipaddr_t src_ip_value;
10259         cmdline_fixed_string_t dst_port;
10260         uint16_t dst_port_value;
10261         cmdline_fixed_string_t src_port;
10262         uint16_t src_port_value;
10263         cmdline_fixed_string_t protocol;
10264         uint8_t protocol_value;
10265         cmdline_fixed_string_t mask;
10266         uint8_t  mask_value;
10267         cmdline_fixed_string_t tcp_flags;
10268         uint8_t tcp_flags_value;
10269         cmdline_fixed_string_t priority;
10270         uint8_t  priority_value;
10271         cmdline_fixed_string_t queue;
10272         uint16_t  queue_id;
10273 };
10274
10275 static void
10276 cmd_5tuple_filter_parsed(void *parsed_result,
10277                         __attribute__((unused)) struct cmdline *cl,
10278                         __attribute__((unused)) void *data)
10279 {
10280         struct rte_eth_ntuple_filter filter;
10281         struct cmd_5tuple_filter_result *res = parsed_result;
10282         int ret = 0;
10283
10284         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10285         if (ret < 0) {
10286                 printf("ntuple filter is not supported on port %u.\n",
10287                         res->port_id);
10288                 return;
10289         }
10290
10291         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10292
10293         filter.flags = RTE_5TUPLE_FLAGS;
10294         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10295         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10296         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10297         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10298         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10299         filter.proto = res->protocol_value;
10300         filter.priority = res->priority_value;
10301         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10302                 printf("nonzero tcp_flags is only meaningful"
10303                         " when protocol is TCP.\n");
10304                 return;
10305         }
10306         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10307                 printf("invalid TCP flags.\n");
10308                 return;
10309         }
10310
10311         if (res->tcp_flags_value != 0) {
10312                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10313                 filter.tcp_flags = res->tcp_flags_value;
10314         }
10315
10316         if (res->dst_ip_value.family == AF_INET)
10317                 /* no need to convert, already big endian. */
10318                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10319         else {
10320                 if (filter.dst_ip_mask == 0) {
10321                         printf("can not support ipv6 involved compare.\n");
10322                         return;
10323                 }
10324                 filter.dst_ip = 0;
10325         }
10326
10327         if (res->src_ip_value.family == AF_INET)
10328                 /* no need to convert, already big endian. */
10329                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10330         else {
10331                 if (filter.src_ip_mask == 0) {
10332                         printf("can not support ipv6 involved compare.\n");
10333                         return;
10334                 }
10335                 filter.src_ip = 0;
10336         }
10337         /* need convert to big endian. */
10338         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10339         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10340         filter.queue = res->queue_id;
10341
10342         if (!strcmp(res->ops, "add"))
10343                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10344                                 RTE_ETH_FILTER_NTUPLE,
10345                                 RTE_ETH_FILTER_ADD,
10346                                 &filter);
10347         else
10348                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10349                                 RTE_ETH_FILTER_NTUPLE,
10350                                 RTE_ETH_FILTER_DELETE,
10351                                 &filter);
10352         if (ret < 0)
10353                 printf("5tuple filter programming error: (%s)\n",
10354                         strerror(-ret));
10355 }
10356
10357 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10358         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10359                                  filter, "5tuple_filter");
10360 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10361         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10362                                 port_id, UINT16);
10363 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10364         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10365                                  ops, "add#del");
10366 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10367         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10368                                 dst_ip, "dst_ip");
10369 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10370         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10371                                 dst_ip_value);
10372 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10373         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10374                                 src_ip, "src_ip");
10375 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10376         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10377                                 src_ip_value);
10378 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10379         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10380                                 dst_port, "dst_port");
10381 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10382         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10383                                 dst_port_value, UINT16);
10384 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10385         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10386                                 src_port, "src_port");
10387 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10388         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10389                                 src_port_value, UINT16);
10390 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10391         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10392                                 protocol, "protocol");
10393 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10394         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10395                                 protocol_value, UINT8);
10396 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10397         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10398                                 mask, "mask");
10399 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10400         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10401                                 mask_value, INT8);
10402 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10403         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10404                                 tcp_flags, "tcp_flags");
10405 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10406         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10407                                 tcp_flags_value, UINT8);
10408 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10409         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10410                                 priority, "priority");
10411 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10412         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10413                                 priority_value, UINT8);
10414 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10415         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10416                                 queue, "queue");
10417 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10418         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10419                                 queue_id, UINT16);
10420
10421 cmdline_parse_inst_t cmd_5tuple_filter = {
10422         .f = cmd_5tuple_filter_parsed,
10423         .data = NULL,
10424         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10425                 "src_ip <value> dst_port <value> src_port <value> "
10426                 "protocol <value>  mask <value> tcp_flags <value> "
10427                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10428         .tokens = {
10429                 (void *)&cmd_5tuple_filter_filter,
10430                 (void *)&cmd_5tuple_filter_port_id,
10431                 (void *)&cmd_5tuple_filter_ops,
10432                 (void *)&cmd_5tuple_filter_dst_ip,
10433                 (void *)&cmd_5tuple_filter_dst_ip_value,
10434                 (void *)&cmd_5tuple_filter_src_ip,
10435                 (void *)&cmd_5tuple_filter_src_ip_value,
10436                 (void *)&cmd_5tuple_filter_dst_port,
10437                 (void *)&cmd_5tuple_filter_dst_port_value,
10438                 (void *)&cmd_5tuple_filter_src_port,
10439                 (void *)&cmd_5tuple_filter_src_port_value,
10440                 (void *)&cmd_5tuple_filter_protocol,
10441                 (void *)&cmd_5tuple_filter_protocol_value,
10442                 (void *)&cmd_5tuple_filter_mask,
10443                 (void *)&cmd_5tuple_filter_mask_value,
10444                 (void *)&cmd_5tuple_filter_tcp_flags,
10445                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10446                 (void *)&cmd_5tuple_filter_priority,
10447                 (void *)&cmd_5tuple_filter_priority_value,
10448                 (void *)&cmd_5tuple_filter_queue,
10449                 (void *)&cmd_5tuple_filter_queue_id,
10450                 NULL,
10451         },
10452 };
10453
10454 /* *** ADD/REMOVE A flex FILTER *** */
10455 struct cmd_flex_filter_result {
10456         cmdline_fixed_string_t filter;
10457         cmdline_fixed_string_t ops;
10458         portid_t port_id;
10459         cmdline_fixed_string_t len;
10460         uint8_t len_value;
10461         cmdline_fixed_string_t bytes;
10462         cmdline_fixed_string_t bytes_value;
10463         cmdline_fixed_string_t mask;
10464         cmdline_fixed_string_t mask_value;
10465         cmdline_fixed_string_t priority;
10466         uint8_t priority_value;
10467         cmdline_fixed_string_t queue;
10468         uint16_t queue_id;
10469 };
10470
10471 static int xdigit2val(unsigned char c)
10472 {
10473         int val;
10474         if (isdigit(c))
10475                 val = c - '0';
10476         else if (isupper(c))
10477                 val = c - 'A' + 10;
10478         else
10479                 val = c - 'a' + 10;
10480         return val;
10481 }
10482
10483 static void
10484 cmd_flex_filter_parsed(void *parsed_result,
10485                           __attribute__((unused)) struct cmdline *cl,
10486                           __attribute__((unused)) void *data)
10487 {
10488         int ret = 0;
10489         struct rte_eth_flex_filter filter;
10490         struct cmd_flex_filter_result *res = parsed_result;
10491         char *bytes_ptr, *mask_ptr;
10492         uint16_t len, i, j = 0;
10493         char c;
10494         int val;
10495         uint8_t byte = 0;
10496
10497         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10498                 printf("the len exceed the max length 128\n");
10499                 return;
10500         }
10501         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10502         filter.len = res->len_value;
10503         filter.priority = res->priority_value;
10504         filter.queue = res->queue_id;
10505         bytes_ptr = res->bytes_value;
10506         mask_ptr = res->mask_value;
10507
10508          /* translate bytes string to array. */
10509         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10510                 (bytes_ptr[1] == 'X')))
10511                 bytes_ptr += 2;
10512         len = strnlen(bytes_ptr, res->len_value * 2);
10513         if (len == 0 || (len % 8 != 0)) {
10514                 printf("please check len and bytes input\n");
10515                 return;
10516         }
10517         for (i = 0; i < len; i++) {
10518                 c = bytes_ptr[i];
10519                 if (isxdigit(c) == 0) {
10520                         /* invalid characters. */
10521                         printf("invalid input\n");
10522                         return;
10523                 }
10524                 val = xdigit2val(c);
10525                 if (i % 2) {
10526                         byte |= val;
10527                         filter.bytes[j] = byte;
10528                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10529                         j++;
10530                         byte = 0;
10531                 } else
10532                         byte |= val << 4;
10533         }
10534         printf("\n");
10535          /* translate mask string to uint8_t array. */
10536         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10537                 (mask_ptr[1] == 'X')))
10538                 mask_ptr += 2;
10539         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10540         if (len == 0) {
10541                 printf("invalid input\n");
10542                 return;
10543         }
10544         j = 0;
10545         byte = 0;
10546         for (i = 0; i < len; i++) {
10547                 c = mask_ptr[i];
10548                 if (isxdigit(c) == 0) {
10549                         /* invalid characters. */
10550                         printf("invalid input\n");
10551                         return;
10552                 }
10553                 val = xdigit2val(c);
10554                 if (i % 2) {
10555                         byte |= val;
10556                         filter.mask[j] = byte;
10557                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10558                         j++;
10559                         byte = 0;
10560                 } else
10561                         byte |= val << 4;
10562         }
10563         printf("\n");
10564
10565         if (!strcmp(res->ops, "add"))
10566                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10567                                 RTE_ETH_FILTER_FLEXIBLE,
10568                                 RTE_ETH_FILTER_ADD,
10569                                 &filter);
10570         else
10571                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10572                                 RTE_ETH_FILTER_FLEXIBLE,
10573                                 RTE_ETH_FILTER_DELETE,
10574                                 &filter);
10575
10576         if (ret < 0)
10577                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10578 }
10579
10580 cmdline_parse_token_string_t cmd_flex_filter_filter =
10581         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10582                                 filter, "flex_filter");
10583 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10584         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10585                                 port_id, UINT16);
10586 cmdline_parse_token_string_t cmd_flex_filter_ops =
10587         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10588                                 ops, "add#del");
10589 cmdline_parse_token_string_t cmd_flex_filter_len =
10590         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10591                                 len, "len");
10592 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10593         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10594                                 len_value, UINT8);
10595 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10597                                 bytes, "bytes");
10598 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10600                                 bytes_value, NULL);
10601 cmdline_parse_token_string_t cmd_flex_filter_mask =
10602         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10603                                 mask, "mask");
10604 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10605         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10606                                 mask_value, NULL);
10607 cmdline_parse_token_string_t cmd_flex_filter_priority =
10608         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10609                                 priority, "priority");
10610 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10611         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10612                                 priority_value, UINT8);
10613 cmdline_parse_token_string_t cmd_flex_filter_queue =
10614         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10615                                 queue, "queue");
10616 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10617         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10618                                 queue_id, UINT16);
10619 cmdline_parse_inst_t cmd_flex_filter = {
10620         .f = cmd_flex_filter_parsed,
10621         .data = NULL,
10622         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10623                 "<value> mask <value> priority <value> queue <queue_id>: "
10624                 "Add/Del a flex filter",
10625         .tokens = {
10626                 (void *)&cmd_flex_filter_filter,
10627                 (void *)&cmd_flex_filter_port_id,
10628                 (void *)&cmd_flex_filter_ops,
10629                 (void *)&cmd_flex_filter_len,
10630                 (void *)&cmd_flex_filter_len_value,
10631                 (void *)&cmd_flex_filter_bytes,
10632                 (void *)&cmd_flex_filter_bytes_value,
10633                 (void *)&cmd_flex_filter_mask,
10634                 (void *)&cmd_flex_filter_mask_value,
10635                 (void *)&cmd_flex_filter_priority,
10636                 (void *)&cmd_flex_filter_priority_value,
10637                 (void *)&cmd_flex_filter_queue,
10638                 (void *)&cmd_flex_filter_queue_id,
10639                 NULL,
10640         },
10641 };
10642
10643 /* *** Filters Control *** */
10644
10645 /* *** deal with ethertype filter *** */
10646 struct cmd_ethertype_filter_result {
10647         cmdline_fixed_string_t filter;
10648         portid_t port_id;
10649         cmdline_fixed_string_t ops;
10650         cmdline_fixed_string_t mac;
10651         struct rte_ether_addr mac_addr;
10652         cmdline_fixed_string_t ethertype;
10653         uint16_t ethertype_value;
10654         cmdline_fixed_string_t drop;
10655         cmdline_fixed_string_t queue;
10656         uint16_t  queue_id;
10657 };
10658
10659 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10660         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10661                                  filter, "ethertype_filter");
10662 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10663         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10664                               port_id, UINT16);
10665 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10666         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10667                                  ops, "add#del");
10668 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10669         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10670                                  mac, "mac_addr#mac_ignr");
10671 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10672         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10673                                      mac_addr);
10674 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10675         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10676                                  ethertype, "ethertype");
10677 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10678         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10679                               ethertype_value, UINT16);
10680 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10681         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10682                                  drop, "drop#fwd");
10683 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10684         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10685                                  queue, "queue");
10686 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10687         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10688                               queue_id, UINT16);
10689
10690 static void
10691 cmd_ethertype_filter_parsed(void *parsed_result,
10692                           __attribute__((unused)) struct cmdline *cl,
10693                           __attribute__((unused)) void *data)
10694 {
10695         struct cmd_ethertype_filter_result *res = parsed_result;
10696         struct rte_eth_ethertype_filter filter;
10697         int ret = 0;
10698
10699         ret = rte_eth_dev_filter_supported(res->port_id,
10700                         RTE_ETH_FILTER_ETHERTYPE);
10701         if (ret < 0) {
10702                 printf("ethertype filter is not supported on port %u.\n",
10703                         res->port_id);
10704                 return;
10705         }
10706
10707         memset(&filter, 0, sizeof(filter));
10708         if (!strcmp(res->mac, "mac_addr")) {
10709                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10710                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10711                         sizeof(struct rte_ether_addr));
10712         }
10713         if (!strcmp(res->drop, "drop"))
10714                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10715         filter.ether_type = res->ethertype_value;
10716         filter.queue = res->queue_id;
10717
10718         if (!strcmp(res->ops, "add"))
10719                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10720                                 RTE_ETH_FILTER_ETHERTYPE,
10721                                 RTE_ETH_FILTER_ADD,
10722                                 &filter);
10723         else
10724                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10725                                 RTE_ETH_FILTER_ETHERTYPE,
10726                                 RTE_ETH_FILTER_DELETE,
10727                                 &filter);
10728         if (ret < 0)
10729                 printf("ethertype filter programming error: (%s)\n",
10730                         strerror(-ret));
10731 }
10732
10733 cmdline_parse_inst_t cmd_ethertype_filter = {
10734         .f = cmd_ethertype_filter_parsed,
10735         .data = NULL,
10736         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10737                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10738                 "Add or delete an ethertype filter entry",
10739         .tokens = {
10740                 (void *)&cmd_ethertype_filter_filter,
10741                 (void *)&cmd_ethertype_filter_port_id,
10742                 (void *)&cmd_ethertype_filter_ops,
10743                 (void *)&cmd_ethertype_filter_mac,
10744                 (void *)&cmd_ethertype_filter_mac_addr,
10745                 (void *)&cmd_ethertype_filter_ethertype,
10746                 (void *)&cmd_ethertype_filter_ethertype_value,
10747                 (void *)&cmd_ethertype_filter_drop,
10748                 (void *)&cmd_ethertype_filter_queue,
10749                 (void *)&cmd_ethertype_filter_queue_id,
10750                 NULL,
10751         },
10752 };
10753
10754 /* *** deal with flow director filter *** */
10755 struct cmd_flow_director_result {
10756         cmdline_fixed_string_t flow_director_filter;
10757         portid_t port_id;
10758         cmdline_fixed_string_t mode;
10759         cmdline_fixed_string_t mode_value;
10760         cmdline_fixed_string_t ops;
10761         cmdline_fixed_string_t flow;
10762         cmdline_fixed_string_t flow_type;
10763         cmdline_fixed_string_t ether;
10764         uint16_t ether_type;
10765         cmdline_fixed_string_t src;
10766         cmdline_ipaddr_t ip_src;
10767         uint16_t port_src;
10768         cmdline_fixed_string_t dst;
10769         cmdline_ipaddr_t ip_dst;
10770         uint16_t port_dst;
10771         cmdline_fixed_string_t verify_tag;
10772         uint32_t verify_tag_value;
10773         cmdline_fixed_string_t tos;
10774         uint8_t tos_value;
10775         cmdline_fixed_string_t proto;
10776         uint8_t proto_value;
10777         cmdline_fixed_string_t ttl;
10778         uint8_t ttl_value;
10779         cmdline_fixed_string_t vlan;
10780         uint16_t vlan_value;
10781         cmdline_fixed_string_t flexbytes;
10782         cmdline_fixed_string_t flexbytes_value;
10783         cmdline_fixed_string_t pf_vf;
10784         cmdline_fixed_string_t drop;
10785         cmdline_fixed_string_t queue;
10786         uint16_t  queue_id;
10787         cmdline_fixed_string_t fd_id;
10788         uint32_t  fd_id_value;
10789         cmdline_fixed_string_t mac;
10790         struct rte_ether_addr mac_addr;
10791         cmdline_fixed_string_t tunnel;
10792         cmdline_fixed_string_t tunnel_type;
10793         cmdline_fixed_string_t tunnel_id;
10794         uint32_t tunnel_id_value;
10795         cmdline_fixed_string_t packet;
10796         char filepath[];
10797 };
10798
10799 static inline int
10800 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10801 {
10802         char s[256];
10803         const char *p, *p0 = q_arg;
10804         char *end;
10805         unsigned long int_fld;
10806         char *str_fld[max_num];
10807         int i;
10808         unsigned size;
10809         int ret = -1;
10810
10811         p = strchr(p0, '(');
10812         if (p == NULL)
10813                 return -1;
10814         ++p;
10815         p0 = strchr(p, ')');
10816         if (p0 == NULL)
10817                 return -1;
10818
10819         size = p0 - p;
10820         if (size >= sizeof(s))
10821                 return -1;
10822
10823         snprintf(s, sizeof(s), "%.*s", size, p);
10824         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10825         if (ret < 0 || ret > max_num)
10826                 return -1;
10827         for (i = 0; i < ret; i++) {
10828                 errno = 0;
10829                 int_fld = strtoul(str_fld[i], &end, 0);
10830                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10831                         return -1;
10832                 flexbytes[i] = (uint8_t)int_fld;
10833         }
10834         return ret;
10835 }
10836
10837 static uint16_t
10838 str2flowtype(char *string)
10839 {
10840         uint8_t i = 0;
10841         static const struct {
10842                 char str[32];
10843                 uint16_t type;
10844         } flowtype_str[] = {
10845                 {"raw", RTE_ETH_FLOW_RAW},
10846                 {"ipv4", RTE_ETH_FLOW_IPV4},
10847                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10848                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10849                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10850                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10851                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10852                 {"ipv6", RTE_ETH_FLOW_IPV6},
10853                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10854                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10855                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10856                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10857                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10858                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10859         };
10860
10861         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10862                 if (!strcmp(flowtype_str[i].str, string))
10863                         return flowtype_str[i].type;
10864         }
10865
10866         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10867                 return (uint16_t)atoi(string);
10868
10869         return RTE_ETH_FLOW_UNKNOWN;
10870 }
10871
10872 static enum rte_eth_fdir_tunnel_type
10873 str2fdir_tunneltype(char *string)
10874 {
10875         uint8_t i = 0;
10876
10877         static const struct {
10878                 char str[32];
10879                 enum rte_eth_fdir_tunnel_type type;
10880         } tunneltype_str[] = {
10881                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10882                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10883         };
10884
10885         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10886                 if (!strcmp(tunneltype_str[i].str, string))
10887                         return tunneltype_str[i].type;
10888         }
10889         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10890 }
10891
10892 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10893 do { \
10894         if ((ip_addr).family == AF_INET) \
10895                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10896         else { \
10897                 printf("invalid parameter.\n"); \
10898                 return; \
10899         } \
10900 } while (0)
10901
10902 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10903 do { \
10904         if ((ip_addr).family == AF_INET6) \
10905                 rte_memcpy(&(ip), \
10906                                  &((ip_addr).addr.ipv6), \
10907                                  sizeof(struct in6_addr)); \
10908         else { \
10909                 printf("invalid parameter.\n"); \
10910                 return; \
10911         } \
10912 } while (0)
10913
10914 static void
10915 cmd_flow_director_filter_parsed(void *parsed_result,
10916                           __attribute__((unused)) struct cmdline *cl,
10917                           __attribute__((unused)) void *data)
10918 {
10919         struct cmd_flow_director_result *res = parsed_result;
10920         struct rte_eth_fdir_filter entry;
10921         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10922         char *end;
10923         unsigned long vf_id;
10924         int ret = 0;
10925
10926         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10927         if (ret < 0) {
10928                 printf("flow director is not supported on port %u.\n",
10929                         res->port_id);
10930                 return;
10931         }
10932         memset(flexbytes, 0, sizeof(flexbytes));
10933         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10934
10935         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10936                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10937                         printf("Please set mode to MAC-VLAN.\n");
10938                         return;
10939                 }
10940         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10941                 if (strcmp(res->mode_value, "Tunnel")) {
10942                         printf("Please set mode to Tunnel.\n");
10943                         return;
10944                 }
10945         } else {
10946                 if (!strcmp(res->mode_value, "raw")) {
10947 #ifdef RTE_LIBRTE_I40E_PMD
10948                         struct rte_pmd_i40e_flow_type_mapping
10949                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10950                         struct rte_pmd_i40e_pkt_template_conf conf;
10951                         uint16_t flow_type = str2flowtype(res->flow_type);
10952                         uint16_t i, port = res->port_id;
10953                         uint8_t add;
10954
10955                         memset(&conf, 0, sizeof(conf));
10956
10957                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10958                                 printf("Invalid flow type specified.\n");
10959                                 return;
10960                         }
10961                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10962                                                                  mapping);
10963                         if (ret)
10964                                 return;
10965                         if (mapping[flow_type].pctype == 0ULL) {
10966                                 printf("Invalid flow type specified.\n");
10967                                 return;
10968                         }
10969                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10970                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10971                                         conf.input.pctype = i;
10972                                         break;
10973                                 }
10974                         }
10975
10976                         conf.input.packet = open_file(res->filepath,
10977                                                 &conf.input.length);
10978                         if (!conf.input.packet)
10979                                 return;
10980                         if (!strcmp(res->drop, "drop"))
10981                                 conf.action.behavior =
10982                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10983                         else
10984                                 conf.action.behavior =
10985                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10986                         conf.action.report_status =
10987                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10988                         conf.action.rx_queue = res->queue_id;
10989                         conf.soft_id = res->fd_id_value;
10990                         add  = strcmp(res->ops, "del") ? 1 : 0;
10991                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10992                                                                         &conf,
10993                                                                         add);
10994                         if (ret < 0)
10995                                 printf("flow director config error: (%s)\n",
10996                                        strerror(-ret));
10997                         close_file(conf.input.packet);
10998 #endif
10999                         return;
11000                 } else if (strcmp(res->mode_value, "IP")) {
11001                         printf("Please set mode to IP or raw.\n");
11002                         return;
11003                 }
11004                 entry.input.flow_type = str2flowtype(res->flow_type);
11005         }
11006
11007         ret = parse_flexbytes(res->flexbytes_value,
11008                                         flexbytes,
11009                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11010         if (ret < 0) {
11011                 printf("error: Cannot parse flexbytes input.\n");
11012                 return;
11013         }
11014
11015         switch (entry.input.flow_type) {
11016         case RTE_ETH_FLOW_FRAG_IPV4:
11017         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11018                 entry.input.flow.ip4_flow.proto = res->proto_value;
11019                 /* fall-through */
11020         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11021         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11022                 IPV4_ADDR_TO_UINT(res->ip_dst,
11023                         entry.input.flow.ip4_flow.dst_ip);
11024                 IPV4_ADDR_TO_UINT(res->ip_src,
11025                         entry.input.flow.ip4_flow.src_ip);
11026                 entry.input.flow.ip4_flow.tos = res->tos_value;
11027                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11028                 /* need convert to big endian. */
11029                 entry.input.flow.udp4_flow.dst_port =
11030                                 rte_cpu_to_be_16(res->port_dst);
11031                 entry.input.flow.udp4_flow.src_port =
11032                                 rte_cpu_to_be_16(res->port_src);
11033                 break;
11034         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11035                 IPV4_ADDR_TO_UINT(res->ip_dst,
11036                         entry.input.flow.sctp4_flow.ip.dst_ip);
11037                 IPV4_ADDR_TO_UINT(res->ip_src,
11038                         entry.input.flow.sctp4_flow.ip.src_ip);
11039                 entry.input.flow.ip4_flow.tos = res->tos_value;
11040                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11041                 /* need convert to big endian. */
11042                 entry.input.flow.sctp4_flow.dst_port =
11043                                 rte_cpu_to_be_16(res->port_dst);
11044                 entry.input.flow.sctp4_flow.src_port =
11045                                 rte_cpu_to_be_16(res->port_src);
11046                 entry.input.flow.sctp4_flow.verify_tag =
11047                                 rte_cpu_to_be_32(res->verify_tag_value);
11048                 break;
11049         case RTE_ETH_FLOW_FRAG_IPV6:
11050         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11051                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11052                 /* fall-through */
11053         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11054         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11055                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11056                         entry.input.flow.ipv6_flow.dst_ip);
11057                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11058                         entry.input.flow.ipv6_flow.src_ip);
11059                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11060                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11061                 /* need convert to big endian. */
11062                 entry.input.flow.udp6_flow.dst_port =
11063                                 rte_cpu_to_be_16(res->port_dst);
11064                 entry.input.flow.udp6_flow.src_port =
11065                                 rte_cpu_to_be_16(res->port_src);
11066                 break;
11067         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11068                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11069                         entry.input.flow.sctp6_flow.ip.dst_ip);
11070                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11071                         entry.input.flow.sctp6_flow.ip.src_ip);
11072                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11073                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11074                 /* need convert to big endian. */
11075                 entry.input.flow.sctp6_flow.dst_port =
11076                                 rte_cpu_to_be_16(res->port_dst);
11077                 entry.input.flow.sctp6_flow.src_port =
11078                                 rte_cpu_to_be_16(res->port_src);
11079                 entry.input.flow.sctp6_flow.verify_tag =
11080                                 rte_cpu_to_be_32(res->verify_tag_value);
11081                 break;
11082         case RTE_ETH_FLOW_L2_PAYLOAD:
11083                 entry.input.flow.l2_flow.ether_type =
11084                         rte_cpu_to_be_16(res->ether_type);
11085                 break;
11086         default:
11087                 break;
11088         }
11089
11090         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11091                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11092                                  &res->mac_addr,
11093                                  sizeof(struct rte_ether_addr));
11094
11095         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11096                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11097                                  &res->mac_addr,
11098                                  sizeof(struct rte_ether_addr));
11099                 entry.input.flow.tunnel_flow.tunnel_type =
11100                         str2fdir_tunneltype(res->tunnel_type);
11101                 entry.input.flow.tunnel_flow.tunnel_id =
11102                         rte_cpu_to_be_32(res->tunnel_id_value);
11103         }
11104
11105         rte_memcpy(entry.input.flow_ext.flexbytes,
11106                    flexbytes,
11107                    RTE_ETH_FDIR_MAX_FLEXLEN);
11108
11109         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11110
11111         entry.action.flex_off = 0;  /*use 0 by default */
11112         if (!strcmp(res->drop, "drop"))
11113                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11114         else
11115                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11116
11117         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11118             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11119                 if (!strcmp(res->pf_vf, "pf"))
11120                         entry.input.flow_ext.is_vf = 0;
11121                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11122                         struct rte_eth_dev_info dev_info;
11123
11124                         ret = eth_dev_info_get_print_err(res->port_id,
11125                                                 &dev_info);
11126                         if (ret != 0)
11127                                 return;
11128
11129                         errno = 0;
11130                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11131                         if (errno != 0 || *end != '\0' ||
11132                             vf_id >= dev_info.max_vfs) {
11133                                 printf("invalid parameter %s.\n", res->pf_vf);
11134                                 return;
11135                         }
11136                         entry.input.flow_ext.is_vf = 1;
11137                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11138                 } else {
11139                         printf("invalid parameter %s.\n", res->pf_vf);
11140                         return;
11141                 }
11142         }
11143
11144         /* set to report FD ID by default */
11145         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11146         entry.action.rx_queue = res->queue_id;
11147         entry.soft_id = res->fd_id_value;
11148         if (!strcmp(res->ops, "add"))
11149                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11150                                              RTE_ETH_FILTER_ADD, &entry);
11151         else if (!strcmp(res->ops, "del"))
11152                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11153                                              RTE_ETH_FILTER_DELETE, &entry);
11154         else
11155                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11156                                              RTE_ETH_FILTER_UPDATE, &entry);
11157         if (ret < 0)
11158                 printf("flow director programming error: (%s)\n",
11159                         strerror(-ret));
11160 }
11161
11162 cmdline_parse_token_string_t cmd_flow_director_filter =
11163         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11164                                  flow_director_filter, "flow_director_filter");
11165 cmdline_parse_token_num_t cmd_flow_director_port_id =
11166         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11167                               port_id, UINT16);
11168 cmdline_parse_token_string_t cmd_flow_director_ops =
11169         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11170                                  ops, "add#del#update");
11171 cmdline_parse_token_string_t cmd_flow_director_flow =
11172         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11173                                  flow, "flow");
11174 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11175         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11176                 flow_type, NULL);
11177 cmdline_parse_token_string_t cmd_flow_director_ether =
11178         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11179                                  ether, "ether");
11180 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11181         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11182                               ether_type, UINT16);
11183 cmdline_parse_token_string_t cmd_flow_director_src =
11184         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11185                                  src, "src");
11186 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11187         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11188                                  ip_src);
11189 cmdline_parse_token_num_t cmd_flow_director_port_src =
11190         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11191                               port_src, UINT16);
11192 cmdline_parse_token_string_t cmd_flow_director_dst =
11193         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11194                                  dst, "dst");
11195 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11196         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11197                                  ip_dst);
11198 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11199         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11200                               port_dst, UINT16);
11201 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11203                                   verify_tag, "verify_tag");
11204 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11205         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11206                               verify_tag_value, UINT32);
11207 cmdline_parse_token_string_t cmd_flow_director_tos =
11208         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11209                                  tos, "tos");
11210 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11211         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11212                               tos_value, UINT8);
11213 cmdline_parse_token_string_t cmd_flow_director_proto =
11214         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11215                                  proto, "proto");
11216 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11217         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11218                               proto_value, UINT8);
11219 cmdline_parse_token_string_t cmd_flow_director_ttl =
11220         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11221                                  ttl, "ttl");
11222 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11223         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11224                               ttl_value, UINT8);
11225 cmdline_parse_token_string_t cmd_flow_director_vlan =
11226         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11227                                  vlan, "vlan");
11228 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11229         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11230                               vlan_value, UINT16);
11231 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11233                                  flexbytes, "flexbytes");
11234 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11235         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11236                               flexbytes_value, NULL);
11237 cmdline_parse_token_string_t cmd_flow_director_drop =
11238         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11239                                  drop, "drop#fwd");
11240 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11242                               pf_vf, NULL);
11243 cmdline_parse_token_string_t cmd_flow_director_queue =
11244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11245                                  queue, "queue");
11246 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11247         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11248                               queue_id, UINT16);
11249 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11251                                  fd_id, "fd_id");
11252 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11253         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11254                               fd_id_value, UINT32);
11255
11256 cmdline_parse_token_string_t cmd_flow_director_mode =
11257         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11258                                  mode, "mode");
11259 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11261                                  mode_value, "IP");
11262 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11264                                  mode_value, "MAC-VLAN");
11265 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11267                                  mode_value, "Tunnel");
11268 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11270                                  mode_value, "raw");
11271 cmdline_parse_token_string_t cmd_flow_director_mac =
11272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11273                                  mac, "mac");
11274 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11275         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11276                                     mac_addr);
11277 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11279                                  tunnel, "tunnel");
11280 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11281         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11282                                  tunnel_type, "NVGRE#VxLAN");
11283 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11285                                  tunnel_id, "tunnel-id");
11286 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11287         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11288                               tunnel_id_value, UINT32);
11289 cmdline_parse_token_string_t cmd_flow_director_packet =
11290         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11291                                  packet, "packet");
11292 cmdline_parse_token_string_t cmd_flow_director_filepath =
11293         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11294                                  filepath, NULL);
11295
11296 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11297         .f = cmd_flow_director_filter_parsed,
11298         .data = NULL,
11299         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11300                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11301                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11302                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11303                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11304                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11305                 "fd_id <fd_id_value>: "
11306                 "Add or delete an ip flow director entry on NIC",
11307         .tokens = {
11308                 (void *)&cmd_flow_director_filter,
11309                 (void *)&cmd_flow_director_port_id,
11310                 (void *)&cmd_flow_director_mode,
11311                 (void *)&cmd_flow_director_mode_ip,
11312                 (void *)&cmd_flow_director_ops,
11313                 (void *)&cmd_flow_director_flow,
11314                 (void *)&cmd_flow_director_flow_type,
11315                 (void *)&cmd_flow_director_src,
11316                 (void *)&cmd_flow_director_ip_src,
11317                 (void *)&cmd_flow_director_dst,
11318                 (void *)&cmd_flow_director_ip_dst,
11319                 (void *)&cmd_flow_director_tos,
11320                 (void *)&cmd_flow_director_tos_value,
11321                 (void *)&cmd_flow_director_proto,
11322                 (void *)&cmd_flow_director_proto_value,
11323                 (void *)&cmd_flow_director_ttl,
11324                 (void *)&cmd_flow_director_ttl_value,
11325                 (void *)&cmd_flow_director_vlan,
11326                 (void *)&cmd_flow_director_vlan_value,
11327                 (void *)&cmd_flow_director_flexbytes,
11328                 (void *)&cmd_flow_director_flexbytes_value,
11329                 (void *)&cmd_flow_director_drop,
11330                 (void *)&cmd_flow_director_pf_vf,
11331                 (void *)&cmd_flow_director_queue,
11332                 (void *)&cmd_flow_director_queue_id,
11333                 (void *)&cmd_flow_director_fd_id,
11334                 (void *)&cmd_flow_director_fd_id_value,
11335                 NULL,
11336         },
11337 };
11338
11339 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11340         .f = cmd_flow_director_filter_parsed,
11341         .data = NULL,
11342         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11343                 "director entry on NIC",
11344         .tokens = {
11345                 (void *)&cmd_flow_director_filter,
11346                 (void *)&cmd_flow_director_port_id,
11347                 (void *)&cmd_flow_director_mode,
11348                 (void *)&cmd_flow_director_mode_ip,
11349                 (void *)&cmd_flow_director_ops,
11350                 (void *)&cmd_flow_director_flow,
11351                 (void *)&cmd_flow_director_flow_type,
11352                 (void *)&cmd_flow_director_src,
11353                 (void *)&cmd_flow_director_ip_src,
11354                 (void *)&cmd_flow_director_port_src,
11355                 (void *)&cmd_flow_director_dst,
11356                 (void *)&cmd_flow_director_ip_dst,
11357                 (void *)&cmd_flow_director_port_dst,
11358                 (void *)&cmd_flow_director_tos,
11359                 (void *)&cmd_flow_director_tos_value,
11360                 (void *)&cmd_flow_director_ttl,
11361                 (void *)&cmd_flow_director_ttl_value,
11362                 (void *)&cmd_flow_director_vlan,
11363                 (void *)&cmd_flow_director_vlan_value,
11364                 (void *)&cmd_flow_director_flexbytes,
11365                 (void *)&cmd_flow_director_flexbytes_value,
11366                 (void *)&cmd_flow_director_drop,
11367                 (void *)&cmd_flow_director_pf_vf,
11368                 (void *)&cmd_flow_director_queue,
11369                 (void *)&cmd_flow_director_queue_id,
11370                 (void *)&cmd_flow_director_fd_id,
11371                 (void *)&cmd_flow_director_fd_id_value,
11372                 NULL,
11373         },
11374 };
11375
11376 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11377         .f = cmd_flow_director_filter_parsed,
11378         .data = NULL,
11379         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11380                 "director entry on NIC",
11381         .tokens = {
11382                 (void *)&cmd_flow_director_filter,
11383                 (void *)&cmd_flow_director_port_id,
11384                 (void *)&cmd_flow_director_mode,
11385                 (void *)&cmd_flow_director_mode_ip,
11386                 (void *)&cmd_flow_director_ops,
11387                 (void *)&cmd_flow_director_flow,
11388                 (void *)&cmd_flow_director_flow_type,
11389                 (void *)&cmd_flow_director_src,
11390                 (void *)&cmd_flow_director_ip_src,
11391                 (void *)&cmd_flow_director_port_src,
11392                 (void *)&cmd_flow_director_dst,
11393                 (void *)&cmd_flow_director_ip_dst,
11394                 (void *)&cmd_flow_director_port_dst,
11395                 (void *)&cmd_flow_director_verify_tag,
11396                 (void *)&cmd_flow_director_verify_tag_value,
11397                 (void *)&cmd_flow_director_tos,
11398                 (void *)&cmd_flow_director_tos_value,
11399                 (void *)&cmd_flow_director_ttl,
11400                 (void *)&cmd_flow_director_ttl_value,
11401                 (void *)&cmd_flow_director_vlan,
11402                 (void *)&cmd_flow_director_vlan_value,
11403                 (void *)&cmd_flow_director_flexbytes,
11404                 (void *)&cmd_flow_director_flexbytes_value,
11405                 (void *)&cmd_flow_director_drop,
11406                 (void *)&cmd_flow_director_pf_vf,
11407                 (void *)&cmd_flow_director_queue,
11408                 (void *)&cmd_flow_director_queue_id,
11409                 (void *)&cmd_flow_director_fd_id,
11410                 (void *)&cmd_flow_director_fd_id_value,
11411                 NULL,
11412         },
11413 };
11414
11415 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11416         .f = cmd_flow_director_filter_parsed,
11417         .data = NULL,
11418         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11419                 "director entry on NIC",
11420         .tokens = {
11421                 (void *)&cmd_flow_director_filter,
11422                 (void *)&cmd_flow_director_port_id,
11423                 (void *)&cmd_flow_director_mode,
11424                 (void *)&cmd_flow_director_mode_ip,
11425                 (void *)&cmd_flow_director_ops,
11426                 (void *)&cmd_flow_director_flow,
11427                 (void *)&cmd_flow_director_flow_type,
11428                 (void *)&cmd_flow_director_ether,
11429                 (void *)&cmd_flow_director_ether_type,
11430                 (void *)&cmd_flow_director_flexbytes,
11431                 (void *)&cmd_flow_director_flexbytes_value,
11432                 (void *)&cmd_flow_director_drop,
11433                 (void *)&cmd_flow_director_pf_vf,
11434                 (void *)&cmd_flow_director_queue,
11435                 (void *)&cmd_flow_director_queue_id,
11436                 (void *)&cmd_flow_director_fd_id,
11437                 (void *)&cmd_flow_director_fd_id_value,
11438                 NULL,
11439         },
11440 };
11441
11442 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11443         .f = cmd_flow_director_filter_parsed,
11444         .data = NULL,
11445         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11446                 "director entry on NIC",
11447         .tokens = {
11448                 (void *)&cmd_flow_director_filter,
11449                 (void *)&cmd_flow_director_port_id,
11450                 (void *)&cmd_flow_director_mode,
11451                 (void *)&cmd_flow_director_mode_mac_vlan,
11452                 (void *)&cmd_flow_director_ops,
11453                 (void *)&cmd_flow_director_mac,
11454                 (void *)&cmd_flow_director_mac_addr,
11455                 (void *)&cmd_flow_director_vlan,
11456                 (void *)&cmd_flow_director_vlan_value,
11457                 (void *)&cmd_flow_director_flexbytes,
11458                 (void *)&cmd_flow_director_flexbytes_value,
11459                 (void *)&cmd_flow_director_drop,
11460                 (void *)&cmd_flow_director_queue,
11461                 (void *)&cmd_flow_director_queue_id,
11462                 (void *)&cmd_flow_director_fd_id,
11463                 (void *)&cmd_flow_director_fd_id_value,
11464                 NULL,
11465         },
11466 };
11467
11468 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11469         .f = cmd_flow_director_filter_parsed,
11470         .data = NULL,
11471         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11472                 "director entry on NIC",
11473         .tokens = {
11474                 (void *)&cmd_flow_director_filter,
11475                 (void *)&cmd_flow_director_port_id,
11476                 (void *)&cmd_flow_director_mode,
11477                 (void *)&cmd_flow_director_mode_tunnel,
11478                 (void *)&cmd_flow_director_ops,
11479                 (void *)&cmd_flow_director_mac,
11480                 (void *)&cmd_flow_director_mac_addr,
11481                 (void *)&cmd_flow_director_vlan,
11482                 (void *)&cmd_flow_director_vlan_value,
11483                 (void *)&cmd_flow_director_tunnel,
11484                 (void *)&cmd_flow_director_tunnel_type,
11485                 (void *)&cmd_flow_director_tunnel_id,
11486                 (void *)&cmd_flow_director_tunnel_id_value,
11487                 (void *)&cmd_flow_director_flexbytes,
11488                 (void *)&cmd_flow_director_flexbytes_value,
11489                 (void *)&cmd_flow_director_drop,
11490                 (void *)&cmd_flow_director_queue,
11491                 (void *)&cmd_flow_director_queue_id,
11492                 (void *)&cmd_flow_director_fd_id,
11493                 (void *)&cmd_flow_director_fd_id_value,
11494                 NULL,
11495         },
11496 };
11497
11498 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11499         .f = cmd_flow_director_filter_parsed,
11500         .data = NULL,
11501         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11502                 "director entry on NIC",
11503         .tokens = {
11504                 (void *)&cmd_flow_director_filter,
11505                 (void *)&cmd_flow_director_port_id,
11506                 (void *)&cmd_flow_director_mode,
11507                 (void *)&cmd_flow_director_mode_raw,
11508                 (void *)&cmd_flow_director_ops,
11509                 (void *)&cmd_flow_director_flow,
11510                 (void *)&cmd_flow_director_flow_type,
11511                 (void *)&cmd_flow_director_drop,
11512                 (void *)&cmd_flow_director_queue,
11513                 (void *)&cmd_flow_director_queue_id,
11514                 (void *)&cmd_flow_director_fd_id,
11515                 (void *)&cmd_flow_director_fd_id_value,
11516                 (void *)&cmd_flow_director_packet,
11517                 (void *)&cmd_flow_director_filepath,
11518                 NULL,
11519         },
11520 };
11521
11522 struct cmd_flush_flow_director_result {
11523         cmdline_fixed_string_t flush_flow_director;
11524         portid_t port_id;
11525 };
11526
11527 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11528         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11529                                  flush_flow_director, "flush_flow_director");
11530 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11531         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11532                               port_id, UINT16);
11533
11534 static void
11535 cmd_flush_flow_director_parsed(void *parsed_result,
11536                           __attribute__((unused)) struct cmdline *cl,
11537                           __attribute__((unused)) void *data)
11538 {
11539         struct cmd_flow_director_result *res = parsed_result;
11540         int ret = 0;
11541
11542         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11543         if (ret < 0) {
11544                 printf("flow director is not supported on port %u.\n",
11545                         res->port_id);
11546                 return;
11547         }
11548
11549         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11550                         RTE_ETH_FILTER_FLUSH, NULL);
11551         if (ret < 0)
11552                 printf("flow director table flushing error: (%s)\n",
11553                         strerror(-ret));
11554 }
11555
11556 cmdline_parse_inst_t cmd_flush_flow_director = {
11557         .f = cmd_flush_flow_director_parsed,
11558         .data = NULL,
11559         .help_str = "flush_flow_director <port_id>: "
11560                 "Flush all flow director entries of a device on NIC",
11561         .tokens = {
11562                 (void *)&cmd_flush_flow_director_flush,
11563                 (void *)&cmd_flush_flow_director_port_id,
11564                 NULL,
11565         },
11566 };
11567
11568 /* *** deal with flow director mask *** */
11569 struct cmd_flow_director_mask_result {
11570         cmdline_fixed_string_t flow_director_mask;
11571         portid_t port_id;
11572         cmdline_fixed_string_t mode;
11573         cmdline_fixed_string_t mode_value;
11574         cmdline_fixed_string_t vlan;
11575         uint16_t vlan_mask;
11576         cmdline_fixed_string_t src_mask;
11577         cmdline_ipaddr_t ipv4_src;
11578         cmdline_ipaddr_t ipv6_src;
11579         uint16_t port_src;
11580         cmdline_fixed_string_t dst_mask;
11581         cmdline_ipaddr_t ipv4_dst;
11582         cmdline_ipaddr_t ipv6_dst;
11583         uint16_t port_dst;
11584         cmdline_fixed_string_t mac;
11585         uint8_t mac_addr_byte_mask;
11586         cmdline_fixed_string_t tunnel_id;
11587         uint32_t tunnel_id_mask;
11588         cmdline_fixed_string_t tunnel_type;
11589         uint8_t tunnel_type_mask;
11590 };
11591
11592 static void
11593 cmd_flow_director_mask_parsed(void *parsed_result,
11594                           __attribute__((unused)) struct cmdline *cl,
11595                           __attribute__((unused)) void *data)
11596 {
11597         struct cmd_flow_director_mask_result *res = parsed_result;
11598         struct rte_eth_fdir_masks *mask;
11599         struct rte_port *port;
11600
11601         port = &ports[res->port_id];
11602         /** Check if the port is not started **/
11603         if (port->port_status != RTE_PORT_STOPPED) {
11604                 printf("Please stop port %d first\n", res->port_id);
11605                 return;
11606         }
11607
11608         mask = &port->dev_conf.fdir_conf.mask;
11609
11610         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11611                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11612                         printf("Please set mode to MAC-VLAN.\n");
11613                         return;
11614                 }
11615
11616                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11617         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11618                 if (strcmp(res->mode_value, "Tunnel")) {
11619                         printf("Please set mode to Tunnel.\n");
11620                         return;
11621                 }
11622
11623                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11624                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11625                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11626                 mask->tunnel_type_mask = res->tunnel_type_mask;
11627         } else {
11628                 if (strcmp(res->mode_value, "IP")) {
11629                         printf("Please set mode to IP.\n");
11630                         return;
11631                 }
11632
11633                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11634                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11635                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11636                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11637                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11638                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11639                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11640         }
11641
11642         cmd_reconfig_device_queue(res->port_id, 1, 1);
11643 }
11644
11645 cmdline_parse_token_string_t cmd_flow_director_mask =
11646         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11647                                  flow_director_mask, "flow_director_mask");
11648 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11649         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11650                               port_id, UINT16);
11651 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11652         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11653                                  vlan, "vlan");
11654 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11655         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11656                               vlan_mask, UINT16);
11657 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11658         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11659                                  src_mask, "src_mask");
11660 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11661         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11662                                  ipv4_src);
11663 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11664         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11665                                  ipv6_src);
11666 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11667         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11668                               port_src, UINT16);
11669 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11671                                  dst_mask, "dst_mask");
11672 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11673         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11674                                  ipv4_dst);
11675 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11676         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11677                                  ipv6_dst);
11678 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11679         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11680                               port_dst, UINT16);
11681
11682 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11684                                  mode, "mode");
11685 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11686         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11687                                  mode_value, "IP");
11688 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11689         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11690                                  mode_value, "MAC-VLAN");
11691 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11692         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11693                                  mode_value, "Tunnel");
11694 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11695         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11696                                  mac, "mac");
11697 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11698         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11699                               mac_addr_byte_mask, UINT8);
11700 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11701         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11702                                  tunnel_type, "tunnel-type");
11703 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11704         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11705                               tunnel_type_mask, UINT8);
11706 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11707         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11708                                  tunnel_id, "tunnel-id");
11709 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11710         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11711                               tunnel_id_mask, UINT32);
11712
11713 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11714         .f = cmd_flow_director_mask_parsed,
11715         .data = NULL,
11716         .help_str = "flow_director_mask ... : "
11717                 "Set IP mode flow director's mask on NIC",
11718         .tokens = {
11719                 (void *)&cmd_flow_director_mask,
11720                 (void *)&cmd_flow_director_mask_port_id,
11721                 (void *)&cmd_flow_director_mask_mode,
11722                 (void *)&cmd_flow_director_mask_mode_ip,
11723                 (void *)&cmd_flow_director_mask_vlan,
11724                 (void *)&cmd_flow_director_mask_vlan_value,
11725                 (void *)&cmd_flow_director_mask_src,
11726                 (void *)&cmd_flow_director_mask_ipv4_src,
11727                 (void *)&cmd_flow_director_mask_ipv6_src,
11728                 (void *)&cmd_flow_director_mask_port_src,
11729                 (void *)&cmd_flow_director_mask_dst,
11730                 (void *)&cmd_flow_director_mask_ipv4_dst,
11731                 (void *)&cmd_flow_director_mask_ipv6_dst,
11732                 (void *)&cmd_flow_director_mask_port_dst,
11733                 NULL,
11734         },
11735 };
11736
11737 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11738         .f = cmd_flow_director_mask_parsed,
11739         .data = NULL,
11740         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11741                 "flow director's mask on NIC",
11742         .tokens = {
11743                 (void *)&cmd_flow_director_mask,
11744                 (void *)&cmd_flow_director_mask_port_id,
11745                 (void *)&cmd_flow_director_mask_mode,
11746                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11747                 (void *)&cmd_flow_director_mask_vlan,
11748                 (void *)&cmd_flow_director_mask_vlan_value,
11749                 NULL,
11750         },
11751 };
11752
11753 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11754         .f = cmd_flow_director_mask_parsed,
11755         .data = NULL,
11756         .help_str = "flow_director_mask ... : Set tunnel mode "
11757                 "flow director's mask on NIC",
11758         .tokens = {
11759                 (void *)&cmd_flow_director_mask,
11760                 (void *)&cmd_flow_director_mask_port_id,
11761                 (void *)&cmd_flow_director_mask_mode,
11762                 (void *)&cmd_flow_director_mask_mode_tunnel,
11763                 (void *)&cmd_flow_director_mask_vlan,
11764                 (void *)&cmd_flow_director_mask_vlan_value,
11765                 (void *)&cmd_flow_director_mask_mac,
11766                 (void *)&cmd_flow_director_mask_mac_value,
11767                 (void *)&cmd_flow_director_mask_tunnel_type,
11768                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11769                 (void *)&cmd_flow_director_mask_tunnel_id,
11770                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11771                 NULL,
11772         },
11773 };
11774
11775 /* *** deal with flow director mask on flexible payload *** */
11776 struct cmd_flow_director_flex_mask_result {
11777         cmdline_fixed_string_t flow_director_flexmask;
11778         portid_t port_id;
11779         cmdline_fixed_string_t flow;
11780         cmdline_fixed_string_t flow_type;
11781         cmdline_fixed_string_t mask;
11782 };
11783
11784 static void
11785 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11786                           __attribute__((unused)) struct cmdline *cl,
11787                           __attribute__((unused)) void *data)
11788 {
11789         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11790         struct rte_eth_fdir_info fdir_info;
11791         struct rte_eth_fdir_flex_mask flex_mask;
11792         struct rte_port *port;
11793         uint64_t flow_type_mask;
11794         uint16_t i;
11795         int ret;
11796
11797         port = &ports[res->port_id];
11798         /** Check if the port is not started **/
11799         if (port->port_status != RTE_PORT_STOPPED) {
11800                 printf("Please stop port %d first\n", res->port_id);
11801                 return;
11802         }
11803
11804         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11805         ret = parse_flexbytes(res->mask,
11806                         flex_mask.mask,
11807                         RTE_ETH_FDIR_MAX_FLEXLEN);
11808         if (ret < 0) {
11809                 printf("error: Cannot parse mask input.\n");
11810                 return;
11811         }
11812
11813         memset(&fdir_info, 0, sizeof(fdir_info));
11814         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11815                                 RTE_ETH_FILTER_INFO, &fdir_info);
11816         if (ret < 0) {
11817                 printf("Cannot get FDir filter info\n");
11818                 return;
11819         }
11820
11821         if (!strcmp(res->flow_type, "none")) {
11822                 /* means don't specify the flow type */
11823                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11824                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11825                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11826                                0, sizeof(struct rte_eth_fdir_flex_mask));
11827                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11828                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11829                                  &flex_mask,
11830                                  sizeof(struct rte_eth_fdir_flex_mask));
11831                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11832                 return;
11833         }
11834         flow_type_mask = fdir_info.flow_types_mask[0];
11835         if (!strcmp(res->flow_type, "all")) {
11836                 if (!flow_type_mask) {
11837                         printf("No flow type supported\n");
11838                         return;
11839                 }
11840                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11841                         if (flow_type_mask & (1ULL << i)) {
11842                                 flex_mask.flow_type = i;
11843                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11844                         }
11845                 }
11846                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11847                 return;
11848         }
11849         flex_mask.flow_type = str2flowtype(res->flow_type);
11850         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11851                 printf("Flow type %s not supported on port %d\n",
11852                                 res->flow_type, res->port_id);
11853                 return;
11854         }
11855         fdir_set_flex_mask(res->port_id, &flex_mask);
11856         cmd_reconfig_device_queue(res->port_id, 1, 1);
11857 }
11858
11859 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11860         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11861                                  flow_director_flexmask,
11862                                  "flow_director_flex_mask");
11863 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11864         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11865                               port_id, UINT16);
11866 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11867         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11868                                  flow, "flow");
11869 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11870         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11871                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11872                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11873 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11875                                  mask, NULL);
11876
11877 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11878         .f = cmd_flow_director_flex_mask_parsed,
11879         .data = NULL,
11880         .help_str = "flow_director_flex_mask ... : "
11881                 "Set flow director's flex mask on NIC",
11882         .tokens = {
11883                 (void *)&cmd_flow_director_flexmask,
11884                 (void *)&cmd_flow_director_flexmask_port_id,
11885                 (void *)&cmd_flow_director_flexmask_flow,
11886                 (void *)&cmd_flow_director_flexmask_flow_type,
11887                 (void *)&cmd_flow_director_flexmask_mask,
11888                 NULL,
11889         },
11890 };
11891
11892 /* *** deal with flow director flexible payload configuration *** */
11893 struct cmd_flow_director_flexpayload_result {
11894         cmdline_fixed_string_t flow_director_flexpayload;
11895         portid_t port_id;
11896         cmdline_fixed_string_t payload_layer;
11897         cmdline_fixed_string_t payload_cfg;
11898 };
11899
11900 static inline int
11901 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11902 {
11903         char s[256];
11904         const char *p, *p0 = q_arg;
11905         char *end;
11906         unsigned long int_fld;
11907         char *str_fld[max_num];
11908         int i;
11909         unsigned size;
11910         int ret = -1;
11911
11912         p = strchr(p0, '(');
11913         if (p == NULL)
11914                 return -1;
11915         ++p;
11916         p0 = strchr(p, ')');
11917         if (p0 == NULL)
11918                 return -1;
11919
11920         size = p0 - p;
11921         if (size >= sizeof(s))
11922                 return -1;
11923
11924         snprintf(s, sizeof(s), "%.*s", size, p);
11925         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11926         if (ret < 0 || ret > max_num)
11927                 return -1;
11928         for (i = 0; i < ret; i++) {
11929                 errno = 0;
11930                 int_fld = strtoul(str_fld[i], &end, 0);
11931                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11932                         return -1;
11933                 offsets[i] = (uint16_t)int_fld;
11934         }
11935         return ret;
11936 }
11937
11938 static void
11939 cmd_flow_director_flxpld_parsed(void *parsed_result,
11940                           __attribute__((unused)) struct cmdline *cl,
11941                           __attribute__((unused)) void *data)
11942 {
11943         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11944         struct rte_eth_flex_payload_cfg flex_cfg;
11945         struct rte_port *port;
11946         int ret = 0;
11947
11948         port = &ports[res->port_id];
11949         /** Check if the port is not started **/
11950         if (port->port_status != RTE_PORT_STOPPED) {
11951                 printf("Please stop port %d first\n", res->port_id);
11952                 return;
11953         }
11954
11955         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11956
11957         if (!strcmp(res->payload_layer, "raw"))
11958                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11959         else if (!strcmp(res->payload_layer, "l2"))
11960                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11961         else if (!strcmp(res->payload_layer, "l3"))
11962                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11963         else if (!strcmp(res->payload_layer, "l4"))
11964                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11965
11966         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11967                             RTE_ETH_FDIR_MAX_FLEXLEN);
11968         if (ret < 0) {
11969                 printf("error: Cannot parse flex payload input.\n");
11970                 return;
11971         }
11972
11973         fdir_set_flex_payload(res->port_id, &flex_cfg);
11974         cmd_reconfig_device_queue(res->port_id, 1, 1);
11975 }
11976
11977 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11978         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11979                                  flow_director_flexpayload,
11980                                  "flow_director_flex_payload");
11981 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11982         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11983                               port_id, UINT16);
11984 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11985         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11986                                  payload_layer, "raw#l2#l3#l4");
11987 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11988         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11989                                  payload_cfg, NULL);
11990
11991 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11992         .f = cmd_flow_director_flxpld_parsed,
11993         .data = NULL,
11994         .help_str = "flow_director_flexpayload ... : "
11995                 "Set flow director's flex payload on NIC",
11996         .tokens = {
11997                 (void *)&cmd_flow_director_flexpayload,
11998                 (void *)&cmd_flow_director_flexpayload_port_id,
11999                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12000                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12001                 NULL,
12002         },
12003 };
12004
12005 /* Generic flow interface command. */
12006 extern cmdline_parse_inst_t cmd_flow;
12007
12008 /* *** Classification Filters Control *** */
12009 /* *** Get symmetric hash enable per port *** */
12010 struct cmd_get_sym_hash_ena_per_port_result {
12011         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12012         portid_t port_id;
12013 };
12014
12015 static void
12016 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12017                                  __rte_unused struct cmdline *cl,
12018                                  __rte_unused void *data)
12019 {
12020         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12021         struct rte_eth_hash_filter_info info;
12022         int ret;
12023
12024         if (rte_eth_dev_filter_supported(res->port_id,
12025                                 RTE_ETH_FILTER_HASH) < 0) {
12026                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12027                                                         res->port_id);
12028                 return;
12029         }
12030
12031         memset(&info, 0, sizeof(info));
12032         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12033         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12034                                                 RTE_ETH_FILTER_GET, &info);
12035
12036         if (ret < 0) {
12037                 printf("Cannot get symmetric hash enable per port "
12038                                         "on port %u\n", res->port_id);
12039                 return;
12040         }
12041
12042         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12043                                 "enabled" : "disabled", res->port_id);
12044 }
12045
12046 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12047         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12048                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12049 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12050         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12051                 port_id, UINT16);
12052
12053 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12054         .f = cmd_get_sym_hash_per_port_parsed,
12055         .data = NULL,
12056         .help_str = "get_sym_hash_ena_per_port <port_id>",
12057         .tokens = {
12058                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12059                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12060                 NULL,
12061         },
12062 };
12063
12064 /* *** Set symmetric hash enable per port *** */
12065 struct cmd_set_sym_hash_ena_per_port_result {
12066         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12067         cmdline_fixed_string_t enable;
12068         portid_t port_id;
12069 };
12070
12071 static void
12072 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12073                                  __rte_unused struct cmdline *cl,
12074                                  __rte_unused void *data)
12075 {
12076         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12077         struct rte_eth_hash_filter_info info;
12078         int ret;
12079
12080         if (rte_eth_dev_filter_supported(res->port_id,
12081                                 RTE_ETH_FILTER_HASH) < 0) {
12082                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12083                                                         res->port_id);
12084                 return;
12085         }
12086
12087         memset(&info, 0, sizeof(info));
12088         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12089         if (!strcmp(res->enable, "enable"))
12090                 info.info.enable = 1;
12091         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12092                                         RTE_ETH_FILTER_SET, &info);
12093         if (ret < 0) {
12094                 printf("Cannot set symmetric hash enable per port on "
12095                                         "port %u\n", res->port_id);
12096                 return;
12097         }
12098         printf("Symmetric hash has been set to %s on port %u\n",
12099                                         res->enable, res->port_id);
12100 }
12101
12102 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12103         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12104                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12105 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12106         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12107                 port_id, UINT16);
12108 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12109         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12110                 enable, "enable#disable");
12111
12112 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12113         .f = cmd_set_sym_hash_per_port_parsed,
12114         .data = NULL,
12115         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12116         .tokens = {
12117                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12118                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12119                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12120                 NULL,
12121         },
12122 };
12123
12124 /* Get global config of hash function */
12125 struct cmd_get_hash_global_config_result {
12126         cmdline_fixed_string_t get_hash_global_config;
12127         portid_t port_id;
12128 };
12129
12130 static char *
12131 flowtype_to_str(uint16_t ftype)
12132 {
12133         uint16_t i;
12134         static struct {
12135                 char str[16];
12136                 uint16_t ftype;
12137         } ftype_table[] = {
12138                 {"ipv4", RTE_ETH_FLOW_IPV4},
12139                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12140                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12141                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12142                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12143                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12144                 {"ipv6", RTE_ETH_FLOW_IPV6},
12145                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12146                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12147                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12148                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12149                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12150                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12151                 {"port", RTE_ETH_FLOW_PORT},
12152                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12153                 {"geneve", RTE_ETH_FLOW_GENEVE},
12154                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12155                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12156         };
12157
12158         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12159                 if (ftype_table[i].ftype == ftype)
12160                         return ftype_table[i].str;
12161         }
12162
12163         return NULL;
12164 }
12165
12166 static void
12167 cmd_get_hash_global_config_parsed(void *parsed_result,
12168                                   __rte_unused struct cmdline *cl,
12169                                   __rte_unused void *data)
12170 {
12171         struct cmd_get_hash_global_config_result *res = parsed_result;
12172         struct rte_eth_hash_filter_info info;
12173         uint32_t idx, offset;
12174         uint16_t i;
12175         char *str;
12176         int ret;
12177
12178         if (rte_eth_dev_filter_supported(res->port_id,
12179                         RTE_ETH_FILTER_HASH) < 0) {
12180                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12181                                                         res->port_id);
12182                 return;
12183         }
12184
12185         memset(&info, 0, sizeof(info));
12186         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12187         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12188                                         RTE_ETH_FILTER_GET, &info);
12189         if (ret < 0) {
12190                 printf("Cannot get hash global configurations by port %d\n",
12191                                                         res->port_id);
12192                 return;
12193         }
12194
12195         switch (info.info.global_conf.hash_func) {
12196         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12197                 printf("Hash function is Toeplitz\n");
12198                 break;
12199         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12200                 printf("Hash function is Simple XOR\n");
12201                 break;
12202         default:
12203                 printf("Unknown hash function\n");
12204                 break;
12205         }
12206
12207         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12208                 idx = i / UINT64_BIT;
12209                 offset = i % UINT64_BIT;
12210                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12211                                                 (1ULL << offset)))
12212                         continue;
12213                 str = flowtype_to_str(i);
12214                 if (!str)
12215                         continue;
12216                 printf("Symmetric hash is %s globally for flow type %s "
12217                                                         "by port %d\n",
12218                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12219                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12220                                                         res->port_id);
12221         }
12222 }
12223
12224 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12225         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12226                 get_hash_global_config, "get_hash_global_config");
12227 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12228         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12229                 port_id, UINT16);
12230
12231 cmdline_parse_inst_t cmd_get_hash_global_config = {
12232         .f = cmd_get_hash_global_config_parsed,
12233         .data = NULL,
12234         .help_str = "get_hash_global_config <port_id>",
12235         .tokens = {
12236                 (void *)&cmd_get_hash_global_config_all,
12237                 (void *)&cmd_get_hash_global_config_port_id,
12238                 NULL,
12239         },
12240 };
12241
12242 /* Set global config of hash function */
12243 struct cmd_set_hash_global_config_result {
12244         cmdline_fixed_string_t set_hash_global_config;
12245         portid_t port_id;
12246         cmdline_fixed_string_t hash_func;
12247         cmdline_fixed_string_t flow_type;
12248         cmdline_fixed_string_t enable;
12249 };
12250
12251 static void
12252 cmd_set_hash_global_config_parsed(void *parsed_result,
12253                                   __rte_unused struct cmdline *cl,
12254                                   __rte_unused void *data)
12255 {
12256         struct cmd_set_hash_global_config_result *res = parsed_result;
12257         struct rte_eth_hash_filter_info info;
12258         uint32_t ftype, idx, offset;
12259         int ret;
12260
12261         if (rte_eth_dev_filter_supported(res->port_id,
12262                                 RTE_ETH_FILTER_HASH) < 0) {
12263                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12264                                                         res->port_id);
12265                 return;
12266         }
12267         memset(&info, 0, sizeof(info));
12268         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12269         if (!strcmp(res->hash_func, "toeplitz"))
12270                 info.info.global_conf.hash_func =
12271                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12272         else if (!strcmp(res->hash_func, "simple_xor"))
12273                 info.info.global_conf.hash_func =
12274                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12275         else if (!strcmp(res->hash_func, "default"))
12276                 info.info.global_conf.hash_func =
12277                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12278
12279         ftype = str2flowtype(res->flow_type);
12280         idx = ftype / UINT64_BIT;
12281         offset = ftype % UINT64_BIT;
12282         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12283         if (!strcmp(res->enable, "enable"))
12284                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12285                                                 (1ULL << offset);
12286         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12287                                         RTE_ETH_FILTER_SET, &info);
12288         if (ret < 0)
12289                 printf("Cannot set global hash configurations by port %d\n",
12290                                                         res->port_id);
12291         else
12292                 printf("Global hash configurations have been set "
12293                         "successfully by port %d\n", res->port_id);
12294 }
12295
12296 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12297         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12298                 set_hash_global_config, "set_hash_global_config");
12299 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12300         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12301                 port_id, UINT16);
12302 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12303         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12304                 hash_func, "toeplitz#simple_xor#default");
12305 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12306         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12307                 flow_type,
12308                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12309                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12310 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12311         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12312                 enable, "enable#disable");
12313
12314 cmdline_parse_inst_t cmd_set_hash_global_config = {
12315         .f = cmd_set_hash_global_config_parsed,
12316         .data = NULL,
12317         .help_str = "set_hash_global_config <port_id> "
12318                 "toeplitz|simple_xor|default "
12319                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12320                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12321                 "l2_payload enable|disable",
12322         .tokens = {
12323                 (void *)&cmd_set_hash_global_config_all,
12324                 (void *)&cmd_set_hash_global_config_port_id,
12325                 (void *)&cmd_set_hash_global_config_hash_func,
12326                 (void *)&cmd_set_hash_global_config_flow_type,
12327                 (void *)&cmd_set_hash_global_config_enable,
12328                 NULL,
12329         },
12330 };
12331
12332 /* Set hash input set */
12333 struct cmd_set_hash_input_set_result {
12334         cmdline_fixed_string_t set_hash_input_set;
12335         portid_t port_id;
12336         cmdline_fixed_string_t flow_type;
12337         cmdline_fixed_string_t inset_field;
12338         cmdline_fixed_string_t select;
12339 };
12340
12341 static enum rte_eth_input_set_field
12342 str2inset(char *string)
12343 {
12344         uint16_t i;
12345
12346         static const struct {
12347                 char str[32];
12348                 enum rte_eth_input_set_field inset;
12349         } inset_table[] = {
12350                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12351                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12352                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12353                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12354                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12355                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12356                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12357                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12358                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12359                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12360                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12361                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12362                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12363                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12364                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12365                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12366                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12367                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12368                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12369                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12370                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12371                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12372                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12373                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12374                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12375                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12376                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12377                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12378                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12379                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12380                 {"none", RTE_ETH_INPUT_SET_NONE},
12381         };
12382
12383         for (i = 0; i < RTE_DIM(inset_table); i++) {
12384                 if (!strcmp(string, inset_table[i].str))
12385                         return inset_table[i].inset;
12386         }
12387
12388         return RTE_ETH_INPUT_SET_UNKNOWN;
12389 }
12390
12391 static void
12392 cmd_set_hash_input_set_parsed(void *parsed_result,
12393                               __rte_unused struct cmdline *cl,
12394                               __rte_unused void *data)
12395 {
12396         struct cmd_set_hash_input_set_result *res = parsed_result;
12397         struct rte_eth_hash_filter_info info;
12398
12399         memset(&info, 0, sizeof(info));
12400         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12401         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12402         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12403         info.info.input_set_conf.inset_size = 1;
12404         if (!strcmp(res->select, "select"))
12405                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12406         else if (!strcmp(res->select, "add"))
12407                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12408         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12409                                 RTE_ETH_FILTER_SET, &info);
12410 }
12411
12412 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12413         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12414                 set_hash_input_set, "set_hash_input_set");
12415 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12416         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12417                 port_id, UINT16);
12418 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12419         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12420                 flow_type, NULL);
12421 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12422         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12423                 inset_field,
12424                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12425                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12426                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12427                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12428                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12429                 "fld-8th#none");
12430 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12431         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12432                 select, "select#add");
12433
12434 cmdline_parse_inst_t cmd_set_hash_input_set = {
12435         .f = cmd_set_hash_input_set_parsed,
12436         .data = NULL,
12437         .help_str = "set_hash_input_set <port_id> "
12438         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12439         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12440         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12441         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12442         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12443         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12444         "fld-7th|fld-8th|none select|add",
12445         .tokens = {
12446                 (void *)&cmd_set_hash_input_set_cmd,
12447                 (void *)&cmd_set_hash_input_set_port_id,
12448                 (void *)&cmd_set_hash_input_set_flow_type,
12449                 (void *)&cmd_set_hash_input_set_field,
12450                 (void *)&cmd_set_hash_input_set_select,
12451                 NULL,
12452         },
12453 };
12454
12455 /* Set flow director input set */
12456 struct cmd_set_fdir_input_set_result {
12457         cmdline_fixed_string_t set_fdir_input_set;
12458         portid_t port_id;
12459         cmdline_fixed_string_t flow_type;
12460         cmdline_fixed_string_t inset_field;
12461         cmdline_fixed_string_t select;
12462 };
12463
12464 static void
12465 cmd_set_fdir_input_set_parsed(void *parsed_result,
12466         __rte_unused struct cmdline *cl,
12467         __rte_unused void *data)
12468 {
12469         struct cmd_set_fdir_input_set_result *res = parsed_result;
12470         struct rte_eth_fdir_filter_info info;
12471
12472         memset(&info, 0, sizeof(info));
12473         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12474         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12475         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12476         info.info.input_set_conf.inset_size = 1;
12477         if (!strcmp(res->select, "select"))
12478                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12479         else if (!strcmp(res->select, "add"))
12480                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12481         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12482                 RTE_ETH_FILTER_SET, &info);
12483 }
12484
12485 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12486         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12487         set_fdir_input_set, "set_fdir_input_set");
12488 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12489         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12490         port_id, UINT16);
12491 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12492         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12493         flow_type,
12494         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12495         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12496 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12497         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12498         inset_field,
12499         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12500         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12501         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12502         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12503         "sctp-veri-tag#none");
12504 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12505         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12506         select, "select#add");
12507
12508 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12509         .f = cmd_set_fdir_input_set_parsed,
12510         .data = NULL,
12511         .help_str = "set_fdir_input_set <port_id> "
12512         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12513         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12514         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12515         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12516         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12517         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12518         "sctp-veri-tag|none select|add",
12519         .tokens = {
12520                 (void *)&cmd_set_fdir_input_set_cmd,
12521                 (void *)&cmd_set_fdir_input_set_port_id,
12522                 (void *)&cmd_set_fdir_input_set_flow_type,
12523                 (void *)&cmd_set_fdir_input_set_field,
12524                 (void *)&cmd_set_fdir_input_set_select,
12525                 NULL,
12526         },
12527 };
12528
12529 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12530 struct cmd_mcast_addr_result {
12531         cmdline_fixed_string_t mcast_addr_cmd;
12532         cmdline_fixed_string_t what;
12533         uint16_t port_num;
12534         struct rte_ether_addr mc_addr;
12535 };
12536
12537 static void cmd_mcast_addr_parsed(void *parsed_result,
12538                 __attribute__((unused)) struct cmdline *cl,
12539                 __attribute__((unused)) void *data)
12540 {
12541         struct cmd_mcast_addr_result *res = parsed_result;
12542
12543         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12544                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12545                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12546                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12547                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12548                 return;
12549         }
12550         if (strcmp(res->what, "add") == 0)
12551                 mcast_addr_add(res->port_num, &res->mc_addr);
12552         else
12553                 mcast_addr_remove(res->port_num, &res->mc_addr);
12554 }
12555
12556 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12557         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12558                                  mcast_addr_cmd, "mcast_addr");
12559 cmdline_parse_token_string_t cmd_mcast_addr_what =
12560         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12561                                  "add#remove");
12562 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12563         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12564 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12565         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12566
12567 cmdline_parse_inst_t cmd_mcast_addr = {
12568         .f = cmd_mcast_addr_parsed,
12569         .data = (void *)0,
12570         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12571                 "Add/Remove multicast MAC address on port_id",
12572         .tokens = {
12573                 (void *)&cmd_mcast_addr_cmd,
12574                 (void *)&cmd_mcast_addr_what,
12575                 (void *)&cmd_mcast_addr_portnum,
12576                 (void *)&cmd_mcast_addr_addr,
12577                 NULL,
12578         },
12579 };
12580
12581 /* l2 tunnel config
12582  * only support E-tag now.
12583  */
12584
12585 /* Ether type config */
12586 struct cmd_config_l2_tunnel_eth_type_result {
12587         cmdline_fixed_string_t port;
12588         cmdline_fixed_string_t config;
12589         cmdline_fixed_string_t all;
12590         portid_t id;
12591         cmdline_fixed_string_t l2_tunnel;
12592         cmdline_fixed_string_t l2_tunnel_type;
12593         cmdline_fixed_string_t eth_type;
12594         uint16_t eth_type_val;
12595 };
12596
12597 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12598         TOKEN_STRING_INITIALIZER
12599                 (struct cmd_config_l2_tunnel_eth_type_result,
12600                  port, "port");
12601 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12602         TOKEN_STRING_INITIALIZER
12603                 (struct cmd_config_l2_tunnel_eth_type_result,
12604                  config, "config");
12605 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12606         TOKEN_STRING_INITIALIZER
12607                 (struct cmd_config_l2_tunnel_eth_type_result,
12608                  all, "all");
12609 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12610         TOKEN_NUM_INITIALIZER
12611                 (struct cmd_config_l2_tunnel_eth_type_result,
12612                  id, UINT16);
12613 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12614         TOKEN_STRING_INITIALIZER
12615                 (struct cmd_config_l2_tunnel_eth_type_result,
12616                  l2_tunnel, "l2-tunnel");
12617 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12618         TOKEN_STRING_INITIALIZER
12619                 (struct cmd_config_l2_tunnel_eth_type_result,
12620                  l2_tunnel_type, "E-tag");
12621 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12622         TOKEN_STRING_INITIALIZER
12623                 (struct cmd_config_l2_tunnel_eth_type_result,
12624                  eth_type, "ether-type");
12625 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12626         TOKEN_NUM_INITIALIZER
12627                 (struct cmd_config_l2_tunnel_eth_type_result,
12628                  eth_type_val, UINT16);
12629
12630 static enum rte_eth_tunnel_type
12631 str2fdir_l2_tunnel_type(char *string)
12632 {
12633         uint32_t i = 0;
12634
12635         static const struct {
12636                 char str[32];
12637                 enum rte_eth_tunnel_type type;
12638         } l2_tunnel_type_str[] = {
12639                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12640         };
12641
12642         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12643                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12644                         return l2_tunnel_type_str[i].type;
12645         }
12646         return RTE_TUNNEL_TYPE_NONE;
12647 }
12648
12649 /* ether type config for all ports */
12650 static void
12651 cmd_config_l2_tunnel_eth_type_all_parsed
12652         (void *parsed_result,
12653          __attribute__((unused)) struct cmdline *cl,
12654          __attribute__((unused)) void *data)
12655 {
12656         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12657         struct rte_eth_l2_tunnel_conf entry;
12658         portid_t pid;
12659
12660         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12661         entry.ether_type = res->eth_type_val;
12662
12663         RTE_ETH_FOREACH_DEV(pid) {
12664                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12665         }
12666 }
12667
12668 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12669         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12670         .data = NULL,
12671         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12672         .tokens = {
12673                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12674                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12675                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12676                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12677                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12678                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12679                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12680                 NULL,
12681         },
12682 };
12683
12684 /* ether type config for a specific port */
12685 static void
12686 cmd_config_l2_tunnel_eth_type_specific_parsed(
12687         void *parsed_result,
12688         __attribute__((unused)) struct cmdline *cl,
12689         __attribute__((unused)) void *data)
12690 {
12691         struct cmd_config_l2_tunnel_eth_type_result *res =
12692                  parsed_result;
12693         struct rte_eth_l2_tunnel_conf entry;
12694
12695         if (port_id_is_invalid(res->id, ENABLED_WARN))
12696                 return;
12697
12698         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12699         entry.ether_type = res->eth_type_val;
12700
12701         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12702 }
12703
12704 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12705         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12706         .data = NULL,
12707         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12708         .tokens = {
12709                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12710                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12711                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12712                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12713                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12714                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12715                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12716                 NULL,
12717         },
12718 };
12719
12720 /* Enable/disable l2 tunnel */
12721 struct cmd_config_l2_tunnel_en_dis_result {
12722         cmdline_fixed_string_t port;
12723         cmdline_fixed_string_t config;
12724         cmdline_fixed_string_t all;
12725         portid_t id;
12726         cmdline_fixed_string_t l2_tunnel;
12727         cmdline_fixed_string_t l2_tunnel_type;
12728         cmdline_fixed_string_t en_dis;
12729 };
12730
12731 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12732         TOKEN_STRING_INITIALIZER
12733                 (struct cmd_config_l2_tunnel_en_dis_result,
12734                  port, "port");
12735 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12736         TOKEN_STRING_INITIALIZER
12737                 (struct cmd_config_l2_tunnel_en_dis_result,
12738                  config, "config");
12739 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12740         TOKEN_STRING_INITIALIZER
12741                 (struct cmd_config_l2_tunnel_en_dis_result,
12742                  all, "all");
12743 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12744         TOKEN_NUM_INITIALIZER
12745                 (struct cmd_config_l2_tunnel_en_dis_result,
12746                  id, UINT16);
12747 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12748         TOKEN_STRING_INITIALIZER
12749                 (struct cmd_config_l2_tunnel_en_dis_result,
12750                  l2_tunnel, "l2-tunnel");
12751 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12752         TOKEN_STRING_INITIALIZER
12753                 (struct cmd_config_l2_tunnel_en_dis_result,
12754                  l2_tunnel_type, "E-tag");
12755 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12756         TOKEN_STRING_INITIALIZER
12757                 (struct cmd_config_l2_tunnel_en_dis_result,
12758                  en_dis, "enable#disable");
12759
12760 /* enable/disable l2 tunnel for all ports */
12761 static void
12762 cmd_config_l2_tunnel_en_dis_all_parsed(
12763         void *parsed_result,
12764         __attribute__((unused)) struct cmdline *cl,
12765         __attribute__((unused)) void *data)
12766 {
12767         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12768         struct rte_eth_l2_tunnel_conf entry;
12769         portid_t pid;
12770         uint8_t en;
12771
12772         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12773
12774         if (!strcmp("enable", res->en_dis))
12775                 en = 1;
12776         else
12777                 en = 0;
12778
12779         RTE_ETH_FOREACH_DEV(pid) {
12780                 rte_eth_dev_l2_tunnel_offload_set(pid,
12781                                                   &entry,
12782                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12783                                                   en);
12784         }
12785 }
12786
12787 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12788         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12789         .data = NULL,
12790         .help_str = "port config all l2-tunnel E-tag enable|disable",
12791         .tokens = {
12792                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12793                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12794                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12795                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12796                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12797                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12798                 NULL,
12799         },
12800 };
12801
12802 /* enable/disable l2 tunnel for a port */
12803 static void
12804 cmd_config_l2_tunnel_en_dis_specific_parsed(
12805         void *parsed_result,
12806         __attribute__((unused)) struct cmdline *cl,
12807         __attribute__((unused)) void *data)
12808 {
12809         struct cmd_config_l2_tunnel_en_dis_result *res =
12810                 parsed_result;
12811         struct rte_eth_l2_tunnel_conf entry;
12812
12813         if (port_id_is_invalid(res->id, ENABLED_WARN))
12814                 return;
12815
12816         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12817
12818         if (!strcmp("enable", res->en_dis))
12819                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12820                                                   &entry,
12821                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12822                                                   1);
12823         else
12824                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12825                                                   &entry,
12826                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12827                                                   0);
12828 }
12829
12830 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12831         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12832         .data = NULL,
12833         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12834         .tokens = {
12835                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12836                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12837                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12838                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12839                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12840                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12841                 NULL,
12842         },
12843 };
12844
12845 /* E-tag configuration */
12846
12847 /* Common result structure for all E-tag configuration */
12848 struct cmd_config_e_tag_result {
12849         cmdline_fixed_string_t e_tag;
12850         cmdline_fixed_string_t set;
12851         cmdline_fixed_string_t insertion;
12852         cmdline_fixed_string_t stripping;
12853         cmdline_fixed_string_t forwarding;
12854         cmdline_fixed_string_t filter;
12855         cmdline_fixed_string_t add;
12856         cmdline_fixed_string_t del;
12857         cmdline_fixed_string_t on;
12858         cmdline_fixed_string_t off;
12859         cmdline_fixed_string_t on_off;
12860         cmdline_fixed_string_t port_tag_id;
12861         uint32_t port_tag_id_val;
12862         cmdline_fixed_string_t e_tag_id;
12863         uint16_t e_tag_id_val;
12864         cmdline_fixed_string_t dst_pool;
12865         uint8_t dst_pool_val;
12866         cmdline_fixed_string_t port;
12867         portid_t port_id;
12868         cmdline_fixed_string_t vf;
12869         uint8_t vf_id;
12870 };
12871
12872 /* Common CLI fields for all E-tag configuration */
12873 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12874         TOKEN_STRING_INITIALIZER
12875                 (struct cmd_config_e_tag_result,
12876                  e_tag, "E-tag");
12877 cmdline_parse_token_string_t cmd_config_e_tag_set =
12878         TOKEN_STRING_INITIALIZER
12879                 (struct cmd_config_e_tag_result,
12880                  set, "set");
12881 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12882         TOKEN_STRING_INITIALIZER
12883                 (struct cmd_config_e_tag_result,
12884                  insertion, "insertion");
12885 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12886         TOKEN_STRING_INITIALIZER
12887                 (struct cmd_config_e_tag_result,
12888                  stripping, "stripping");
12889 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12890         TOKEN_STRING_INITIALIZER
12891                 (struct cmd_config_e_tag_result,
12892                  forwarding, "forwarding");
12893 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12894         TOKEN_STRING_INITIALIZER
12895                 (struct cmd_config_e_tag_result,
12896                  filter, "filter");
12897 cmdline_parse_token_string_t cmd_config_e_tag_add =
12898         TOKEN_STRING_INITIALIZER
12899                 (struct cmd_config_e_tag_result,
12900                  add, "add");
12901 cmdline_parse_token_string_t cmd_config_e_tag_del =
12902         TOKEN_STRING_INITIALIZER
12903                 (struct cmd_config_e_tag_result,
12904                  del, "del");
12905 cmdline_parse_token_string_t cmd_config_e_tag_on =
12906         TOKEN_STRING_INITIALIZER
12907                 (struct cmd_config_e_tag_result,
12908                  on, "on");
12909 cmdline_parse_token_string_t cmd_config_e_tag_off =
12910         TOKEN_STRING_INITIALIZER
12911                 (struct cmd_config_e_tag_result,
12912                  off, "off");
12913 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12914         TOKEN_STRING_INITIALIZER
12915                 (struct cmd_config_e_tag_result,
12916                  on_off, "on#off");
12917 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12918         TOKEN_STRING_INITIALIZER
12919                 (struct cmd_config_e_tag_result,
12920                  port_tag_id, "port-tag-id");
12921 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12922         TOKEN_NUM_INITIALIZER
12923                 (struct cmd_config_e_tag_result,
12924                  port_tag_id_val, UINT32);
12925 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12926         TOKEN_STRING_INITIALIZER
12927                 (struct cmd_config_e_tag_result,
12928                  e_tag_id, "e-tag-id");
12929 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12930         TOKEN_NUM_INITIALIZER
12931                 (struct cmd_config_e_tag_result,
12932                  e_tag_id_val, UINT16);
12933 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12934         TOKEN_STRING_INITIALIZER
12935                 (struct cmd_config_e_tag_result,
12936                  dst_pool, "dst-pool");
12937 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12938         TOKEN_NUM_INITIALIZER
12939                 (struct cmd_config_e_tag_result,
12940                  dst_pool_val, UINT8);
12941 cmdline_parse_token_string_t cmd_config_e_tag_port =
12942         TOKEN_STRING_INITIALIZER
12943                 (struct cmd_config_e_tag_result,
12944                  port, "port");
12945 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12946         TOKEN_NUM_INITIALIZER
12947                 (struct cmd_config_e_tag_result,
12948                  port_id, UINT16);
12949 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12950         TOKEN_STRING_INITIALIZER
12951                 (struct cmd_config_e_tag_result,
12952                  vf, "vf");
12953 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12954         TOKEN_NUM_INITIALIZER
12955                 (struct cmd_config_e_tag_result,
12956                  vf_id, UINT8);
12957
12958 /* E-tag insertion configuration */
12959 static void
12960 cmd_config_e_tag_insertion_en_parsed(
12961         void *parsed_result,
12962         __attribute__((unused)) struct cmdline *cl,
12963         __attribute__((unused)) void *data)
12964 {
12965         struct cmd_config_e_tag_result *res =
12966                 parsed_result;
12967         struct rte_eth_l2_tunnel_conf entry;
12968
12969         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12970                 return;
12971
12972         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12973         entry.tunnel_id = res->port_tag_id_val;
12974         entry.vf_id = res->vf_id;
12975         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12976                                           &entry,
12977                                           ETH_L2_TUNNEL_INSERTION_MASK,
12978                                           1);
12979 }
12980
12981 static void
12982 cmd_config_e_tag_insertion_dis_parsed(
12983         void *parsed_result,
12984         __attribute__((unused)) struct cmdline *cl,
12985         __attribute__((unused)) void *data)
12986 {
12987         struct cmd_config_e_tag_result *res =
12988                 parsed_result;
12989         struct rte_eth_l2_tunnel_conf entry;
12990
12991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12992                 return;
12993
12994         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12995         entry.vf_id = res->vf_id;
12996
12997         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12998                                           &entry,
12999                                           ETH_L2_TUNNEL_INSERTION_MASK,
13000                                           0);
13001 }
13002
13003 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13004         .f = cmd_config_e_tag_insertion_en_parsed,
13005         .data = NULL,
13006         .help_str = "E-tag ... : E-tag insertion enable",
13007         .tokens = {
13008                 (void *)&cmd_config_e_tag_e_tag,
13009                 (void *)&cmd_config_e_tag_set,
13010                 (void *)&cmd_config_e_tag_insertion,
13011                 (void *)&cmd_config_e_tag_on,
13012                 (void *)&cmd_config_e_tag_port_tag_id,
13013                 (void *)&cmd_config_e_tag_port_tag_id_val,
13014                 (void *)&cmd_config_e_tag_port,
13015                 (void *)&cmd_config_e_tag_port_id,
13016                 (void *)&cmd_config_e_tag_vf,
13017                 (void *)&cmd_config_e_tag_vf_id,
13018                 NULL,
13019         },
13020 };
13021
13022 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13023         .f = cmd_config_e_tag_insertion_dis_parsed,
13024         .data = NULL,
13025         .help_str = "E-tag ... : E-tag insertion disable",
13026         .tokens = {
13027                 (void *)&cmd_config_e_tag_e_tag,
13028                 (void *)&cmd_config_e_tag_set,
13029                 (void *)&cmd_config_e_tag_insertion,
13030                 (void *)&cmd_config_e_tag_off,
13031                 (void *)&cmd_config_e_tag_port,
13032                 (void *)&cmd_config_e_tag_port_id,
13033                 (void *)&cmd_config_e_tag_vf,
13034                 (void *)&cmd_config_e_tag_vf_id,
13035                 NULL,
13036         },
13037 };
13038
13039 /* E-tag stripping configuration */
13040 static void
13041 cmd_config_e_tag_stripping_parsed(
13042         void *parsed_result,
13043         __attribute__((unused)) struct cmdline *cl,
13044         __attribute__((unused)) void *data)
13045 {
13046         struct cmd_config_e_tag_result *res =
13047                 parsed_result;
13048         struct rte_eth_l2_tunnel_conf entry;
13049
13050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13051                 return;
13052
13053         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13054
13055         if (!strcmp(res->on_off, "on"))
13056                 rte_eth_dev_l2_tunnel_offload_set
13057                         (res->port_id,
13058                          &entry,
13059                          ETH_L2_TUNNEL_STRIPPING_MASK,
13060                          1);
13061         else
13062                 rte_eth_dev_l2_tunnel_offload_set
13063                         (res->port_id,
13064                          &entry,
13065                          ETH_L2_TUNNEL_STRIPPING_MASK,
13066                          0);
13067 }
13068
13069 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13070         .f = cmd_config_e_tag_stripping_parsed,
13071         .data = NULL,
13072         .help_str = "E-tag ... : E-tag stripping enable/disable",
13073         .tokens = {
13074                 (void *)&cmd_config_e_tag_e_tag,
13075                 (void *)&cmd_config_e_tag_set,
13076                 (void *)&cmd_config_e_tag_stripping,
13077                 (void *)&cmd_config_e_tag_on_off,
13078                 (void *)&cmd_config_e_tag_port,
13079                 (void *)&cmd_config_e_tag_port_id,
13080                 NULL,
13081         },
13082 };
13083
13084 /* E-tag forwarding configuration */
13085 static void
13086 cmd_config_e_tag_forwarding_parsed(
13087         void *parsed_result,
13088         __attribute__((unused)) struct cmdline *cl,
13089         __attribute__((unused)) void *data)
13090 {
13091         struct cmd_config_e_tag_result *res = parsed_result;
13092         struct rte_eth_l2_tunnel_conf entry;
13093
13094         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13095                 return;
13096
13097         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13098
13099         if (!strcmp(res->on_off, "on"))
13100                 rte_eth_dev_l2_tunnel_offload_set
13101                         (res->port_id,
13102                          &entry,
13103                          ETH_L2_TUNNEL_FORWARDING_MASK,
13104                          1);
13105         else
13106                 rte_eth_dev_l2_tunnel_offload_set
13107                         (res->port_id,
13108                          &entry,
13109                          ETH_L2_TUNNEL_FORWARDING_MASK,
13110                          0);
13111 }
13112
13113 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13114         .f = cmd_config_e_tag_forwarding_parsed,
13115         .data = NULL,
13116         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13117         .tokens = {
13118                 (void *)&cmd_config_e_tag_e_tag,
13119                 (void *)&cmd_config_e_tag_set,
13120                 (void *)&cmd_config_e_tag_forwarding,
13121                 (void *)&cmd_config_e_tag_on_off,
13122                 (void *)&cmd_config_e_tag_port,
13123                 (void *)&cmd_config_e_tag_port_id,
13124                 NULL,
13125         },
13126 };
13127
13128 /* E-tag filter configuration */
13129 static void
13130 cmd_config_e_tag_filter_add_parsed(
13131         void *parsed_result,
13132         __attribute__((unused)) struct cmdline *cl,
13133         __attribute__((unused)) void *data)
13134 {
13135         struct cmd_config_e_tag_result *res = parsed_result;
13136         struct rte_eth_l2_tunnel_conf entry;
13137         int ret = 0;
13138
13139         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13140                 return;
13141
13142         if (res->e_tag_id_val > 0x3fff) {
13143                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13144                 return;
13145         }
13146
13147         ret = rte_eth_dev_filter_supported(res->port_id,
13148                                            RTE_ETH_FILTER_L2_TUNNEL);
13149         if (ret < 0) {
13150                 printf("E-tag filter is not supported on port %u.\n",
13151                        res->port_id);
13152                 return;
13153         }
13154
13155         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13156         entry.tunnel_id = res->e_tag_id_val;
13157         entry.pool = res->dst_pool_val;
13158
13159         ret = rte_eth_dev_filter_ctrl(res->port_id,
13160                                       RTE_ETH_FILTER_L2_TUNNEL,
13161                                       RTE_ETH_FILTER_ADD,
13162                                       &entry);
13163         if (ret < 0)
13164                 printf("E-tag filter programming error: (%s)\n",
13165                        strerror(-ret));
13166 }
13167
13168 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13169         .f = cmd_config_e_tag_filter_add_parsed,
13170         .data = NULL,
13171         .help_str = "E-tag ... : E-tag filter add",
13172         .tokens = {
13173                 (void *)&cmd_config_e_tag_e_tag,
13174                 (void *)&cmd_config_e_tag_set,
13175                 (void *)&cmd_config_e_tag_filter,
13176                 (void *)&cmd_config_e_tag_add,
13177                 (void *)&cmd_config_e_tag_e_tag_id,
13178                 (void *)&cmd_config_e_tag_e_tag_id_val,
13179                 (void *)&cmd_config_e_tag_dst_pool,
13180                 (void *)&cmd_config_e_tag_dst_pool_val,
13181                 (void *)&cmd_config_e_tag_port,
13182                 (void *)&cmd_config_e_tag_port_id,
13183                 NULL,
13184         },
13185 };
13186
13187 static void
13188 cmd_config_e_tag_filter_del_parsed(
13189         void *parsed_result,
13190         __attribute__((unused)) struct cmdline *cl,
13191         __attribute__((unused)) void *data)
13192 {
13193         struct cmd_config_e_tag_result *res = parsed_result;
13194         struct rte_eth_l2_tunnel_conf entry;
13195         int ret = 0;
13196
13197         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13198                 return;
13199
13200         if (res->e_tag_id_val > 0x3fff) {
13201                 printf("e-tag-id must be less than 0x3fff.\n");
13202                 return;
13203         }
13204
13205         ret = rte_eth_dev_filter_supported(res->port_id,
13206                                            RTE_ETH_FILTER_L2_TUNNEL);
13207         if (ret < 0) {
13208                 printf("E-tag filter is not supported on port %u.\n",
13209                        res->port_id);
13210                 return;
13211         }
13212
13213         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13214         entry.tunnel_id = res->e_tag_id_val;
13215
13216         ret = rte_eth_dev_filter_ctrl(res->port_id,
13217                                       RTE_ETH_FILTER_L2_TUNNEL,
13218                                       RTE_ETH_FILTER_DELETE,
13219                                       &entry);
13220         if (ret < 0)
13221                 printf("E-tag filter programming error: (%s)\n",
13222                        strerror(-ret));
13223 }
13224
13225 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13226         .f = cmd_config_e_tag_filter_del_parsed,
13227         .data = NULL,
13228         .help_str = "E-tag ... : E-tag filter delete",
13229         .tokens = {
13230                 (void *)&cmd_config_e_tag_e_tag,
13231                 (void *)&cmd_config_e_tag_set,
13232                 (void *)&cmd_config_e_tag_filter,
13233                 (void *)&cmd_config_e_tag_del,
13234                 (void *)&cmd_config_e_tag_e_tag_id,
13235                 (void *)&cmd_config_e_tag_e_tag_id_val,
13236                 (void *)&cmd_config_e_tag_port,
13237                 (void *)&cmd_config_e_tag_port_id,
13238                 NULL,
13239         },
13240 };
13241
13242 /* vf vlan anti spoof configuration */
13243
13244 /* Common result structure for vf vlan anti spoof */
13245 struct cmd_vf_vlan_anti_spoof_result {
13246         cmdline_fixed_string_t set;
13247         cmdline_fixed_string_t vf;
13248         cmdline_fixed_string_t vlan;
13249         cmdline_fixed_string_t antispoof;
13250         portid_t port_id;
13251         uint32_t vf_id;
13252         cmdline_fixed_string_t on_off;
13253 };
13254
13255 /* Common CLI fields for vf vlan anti spoof enable disable */
13256 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13257         TOKEN_STRING_INITIALIZER
13258                 (struct cmd_vf_vlan_anti_spoof_result,
13259                  set, "set");
13260 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13261         TOKEN_STRING_INITIALIZER
13262                 (struct cmd_vf_vlan_anti_spoof_result,
13263                  vf, "vf");
13264 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13265         TOKEN_STRING_INITIALIZER
13266                 (struct cmd_vf_vlan_anti_spoof_result,
13267                  vlan, "vlan");
13268 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13269         TOKEN_STRING_INITIALIZER
13270                 (struct cmd_vf_vlan_anti_spoof_result,
13271                  antispoof, "antispoof");
13272 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13273         TOKEN_NUM_INITIALIZER
13274                 (struct cmd_vf_vlan_anti_spoof_result,
13275                  port_id, UINT16);
13276 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13277         TOKEN_NUM_INITIALIZER
13278                 (struct cmd_vf_vlan_anti_spoof_result,
13279                  vf_id, UINT32);
13280 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13281         TOKEN_STRING_INITIALIZER
13282                 (struct cmd_vf_vlan_anti_spoof_result,
13283                  on_off, "on#off");
13284
13285 static void
13286 cmd_set_vf_vlan_anti_spoof_parsed(
13287         void *parsed_result,
13288         __attribute__((unused)) struct cmdline *cl,
13289         __attribute__((unused)) void *data)
13290 {
13291         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13292         int ret = -ENOTSUP;
13293
13294         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13295
13296         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13297                 return;
13298
13299 #ifdef RTE_LIBRTE_IXGBE_PMD
13300         if (ret == -ENOTSUP)
13301                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13302                                 res->vf_id, is_on);
13303 #endif
13304 #ifdef RTE_LIBRTE_I40E_PMD
13305         if (ret == -ENOTSUP)
13306                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13307                                 res->vf_id, is_on);
13308 #endif
13309 #ifdef RTE_LIBRTE_BNXT_PMD
13310         if (ret == -ENOTSUP)
13311                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13312                                 res->vf_id, is_on);
13313 #endif
13314
13315         switch (ret) {
13316         case 0:
13317                 break;
13318         case -EINVAL:
13319                 printf("invalid vf_id %d\n", res->vf_id);
13320                 break;
13321         case -ENODEV:
13322                 printf("invalid port_id %d\n", res->port_id);
13323                 break;
13324         case -ENOTSUP:
13325                 printf("function not implemented\n");
13326                 break;
13327         default:
13328                 printf("programming error: (%s)\n", strerror(-ret));
13329         }
13330 }
13331
13332 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13333         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13334         .data = NULL,
13335         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13336         .tokens = {
13337                 (void *)&cmd_vf_vlan_anti_spoof_set,
13338                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13339                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13340                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13341                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13342                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13343                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13344                 NULL,
13345         },
13346 };
13347
13348 /* vf mac anti spoof configuration */
13349
13350 /* Common result structure for vf mac anti spoof */
13351 struct cmd_vf_mac_anti_spoof_result {
13352         cmdline_fixed_string_t set;
13353         cmdline_fixed_string_t vf;
13354         cmdline_fixed_string_t mac;
13355         cmdline_fixed_string_t antispoof;
13356         portid_t port_id;
13357         uint32_t vf_id;
13358         cmdline_fixed_string_t on_off;
13359 };
13360
13361 /* Common CLI fields for vf mac anti spoof enable disable */
13362 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13363         TOKEN_STRING_INITIALIZER
13364                 (struct cmd_vf_mac_anti_spoof_result,
13365                  set, "set");
13366 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13367         TOKEN_STRING_INITIALIZER
13368                 (struct cmd_vf_mac_anti_spoof_result,
13369                  vf, "vf");
13370 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13371         TOKEN_STRING_INITIALIZER
13372                 (struct cmd_vf_mac_anti_spoof_result,
13373                  mac, "mac");
13374 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13375         TOKEN_STRING_INITIALIZER
13376                 (struct cmd_vf_mac_anti_spoof_result,
13377                  antispoof, "antispoof");
13378 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13379         TOKEN_NUM_INITIALIZER
13380                 (struct cmd_vf_mac_anti_spoof_result,
13381                  port_id, UINT16);
13382 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13383         TOKEN_NUM_INITIALIZER
13384                 (struct cmd_vf_mac_anti_spoof_result,
13385                  vf_id, UINT32);
13386 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13387         TOKEN_STRING_INITIALIZER
13388                 (struct cmd_vf_mac_anti_spoof_result,
13389                  on_off, "on#off");
13390
13391 static void
13392 cmd_set_vf_mac_anti_spoof_parsed(
13393         void *parsed_result,
13394         __attribute__((unused)) struct cmdline *cl,
13395         __attribute__((unused)) void *data)
13396 {
13397         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13398         int ret = -ENOTSUP;
13399
13400         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13401
13402         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13403                 return;
13404
13405 #ifdef RTE_LIBRTE_IXGBE_PMD
13406         if (ret == -ENOTSUP)
13407                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13408                         res->vf_id, is_on);
13409 #endif
13410 #ifdef RTE_LIBRTE_I40E_PMD
13411         if (ret == -ENOTSUP)
13412                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13413                         res->vf_id, is_on);
13414 #endif
13415 #ifdef RTE_LIBRTE_BNXT_PMD
13416         if (ret == -ENOTSUP)
13417                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13418                         res->vf_id, is_on);
13419 #endif
13420
13421         switch (ret) {
13422         case 0:
13423                 break;
13424         case -EINVAL:
13425                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13426                 break;
13427         case -ENODEV:
13428                 printf("invalid port_id %d\n", res->port_id);
13429                 break;
13430         case -ENOTSUP:
13431                 printf("function not implemented\n");
13432                 break;
13433         default:
13434                 printf("programming error: (%s)\n", strerror(-ret));
13435         }
13436 }
13437
13438 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13439         .f = cmd_set_vf_mac_anti_spoof_parsed,
13440         .data = NULL,
13441         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13442         .tokens = {
13443                 (void *)&cmd_vf_mac_anti_spoof_set,
13444                 (void *)&cmd_vf_mac_anti_spoof_vf,
13445                 (void *)&cmd_vf_mac_anti_spoof_mac,
13446                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13447                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13448                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13449                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13450                 NULL,
13451         },
13452 };
13453
13454 /* vf vlan strip queue configuration */
13455
13456 /* Common result structure for vf mac anti spoof */
13457 struct cmd_vf_vlan_stripq_result {
13458         cmdline_fixed_string_t set;
13459         cmdline_fixed_string_t vf;
13460         cmdline_fixed_string_t vlan;
13461         cmdline_fixed_string_t stripq;
13462         portid_t port_id;
13463         uint16_t vf_id;
13464         cmdline_fixed_string_t on_off;
13465 };
13466
13467 /* Common CLI fields for vf vlan strip enable disable */
13468 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13469         TOKEN_STRING_INITIALIZER
13470                 (struct cmd_vf_vlan_stripq_result,
13471                  set, "set");
13472 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13473         TOKEN_STRING_INITIALIZER
13474                 (struct cmd_vf_vlan_stripq_result,
13475                  vf, "vf");
13476 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13477         TOKEN_STRING_INITIALIZER
13478                 (struct cmd_vf_vlan_stripq_result,
13479                  vlan, "vlan");
13480 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13481         TOKEN_STRING_INITIALIZER
13482                 (struct cmd_vf_vlan_stripq_result,
13483                  stripq, "stripq");
13484 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13485         TOKEN_NUM_INITIALIZER
13486                 (struct cmd_vf_vlan_stripq_result,
13487                  port_id, UINT16);
13488 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13489         TOKEN_NUM_INITIALIZER
13490                 (struct cmd_vf_vlan_stripq_result,
13491                  vf_id, UINT16);
13492 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13493         TOKEN_STRING_INITIALIZER
13494                 (struct cmd_vf_vlan_stripq_result,
13495                  on_off, "on#off");
13496
13497 static void
13498 cmd_set_vf_vlan_stripq_parsed(
13499         void *parsed_result,
13500         __attribute__((unused)) struct cmdline *cl,
13501         __attribute__((unused)) void *data)
13502 {
13503         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13504         int ret = -ENOTSUP;
13505
13506         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13507
13508         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13509                 return;
13510
13511 #ifdef RTE_LIBRTE_IXGBE_PMD
13512         if (ret == -ENOTSUP)
13513                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13514                         res->vf_id, is_on);
13515 #endif
13516 #ifdef RTE_LIBRTE_I40E_PMD
13517         if (ret == -ENOTSUP)
13518                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13519                         res->vf_id, is_on);
13520 #endif
13521 #ifdef RTE_LIBRTE_BNXT_PMD
13522         if (ret == -ENOTSUP)
13523                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13524                         res->vf_id, is_on);
13525 #endif
13526
13527         switch (ret) {
13528         case 0:
13529                 break;
13530         case -EINVAL:
13531                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13532                 break;
13533         case -ENODEV:
13534                 printf("invalid port_id %d\n", res->port_id);
13535                 break;
13536         case -ENOTSUP:
13537                 printf("function not implemented\n");
13538                 break;
13539         default:
13540                 printf("programming error: (%s)\n", strerror(-ret));
13541         }
13542 }
13543
13544 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13545         .f = cmd_set_vf_vlan_stripq_parsed,
13546         .data = NULL,
13547         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13548         .tokens = {
13549                 (void *)&cmd_vf_vlan_stripq_set,
13550                 (void *)&cmd_vf_vlan_stripq_vf,
13551                 (void *)&cmd_vf_vlan_stripq_vlan,
13552                 (void *)&cmd_vf_vlan_stripq_stripq,
13553                 (void *)&cmd_vf_vlan_stripq_port_id,
13554                 (void *)&cmd_vf_vlan_stripq_vf_id,
13555                 (void *)&cmd_vf_vlan_stripq_on_off,
13556                 NULL,
13557         },
13558 };
13559
13560 /* vf vlan insert configuration */
13561
13562 /* Common result structure for vf vlan insert */
13563 struct cmd_vf_vlan_insert_result {
13564         cmdline_fixed_string_t set;
13565         cmdline_fixed_string_t vf;
13566         cmdline_fixed_string_t vlan;
13567         cmdline_fixed_string_t insert;
13568         portid_t port_id;
13569         uint16_t vf_id;
13570         uint16_t vlan_id;
13571 };
13572
13573 /* Common CLI fields for vf vlan insert enable disable */
13574 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13575         TOKEN_STRING_INITIALIZER
13576                 (struct cmd_vf_vlan_insert_result,
13577                  set, "set");
13578 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13579         TOKEN_STRING_INITIALIZER
13580                 (struct cmd_vf_vlan_insert_result,
13581                  vf, "vf");
13582 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_vf_vlan_insert_result,
13585                  vlan, "vlan");
13586 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13587         TOKEN_STRING_INITIALIZER
13588                 (struct cmd_vf_vlan_insert_result,
13589                  insert, "insert");
13590 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13591         TOKEN_NUM_INITIALIZER
13592                 (struct cmd_vf_vlan_insert_result,
13593                  port_id, UINT16);
13594 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13595         TOKEN_NUM_INITIALIZER
13596                 (struct cmd_vf_vlan_insert_result,
13597                  vf_id, UINT16);
13598 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13599         TOKEN_NUM_INITIALIZER
13600                 (struct cmd_vf_vlan_insert_result,
13601                  vlan_id, UINT16);
13602
13603 static void
13604 cmd_set_vf_vlan_insert_parsed(
13605         void *parsed_result,
13606         __attribute__((unused)) struct cmdline *cl,
13607         __attribute__((unused)) void *data)
13608 {
13609         struct cmd_vf_vlan_insert_result *res = parsed_result;
13610         int ret = -ENOTSUP;
13611
13612         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13613                 return;
13614
13615 #ifdef RTE_LIBRTE_IXGBE_PMD
13616         if (ret == -ENOTSUP)
13617                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13618                         res->vlan_id);
13619 #endif
13620 #ifdef RTE_LIBRTE_I40E_PMD
13621         if (ret == -ENOTSUP)
13622                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13623                         res->vlan_id);
13624 #endif
13625 #ifdef RTE_LIBRTE_BNXT_PMD
13626         if (ret == -ENOTSUP)
13627                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13628                         res->vlan_id);
13629 #endif
13630
13631         switch (ret) {
13632         case 0:
13633                 break;
13634         case -EINVAL:
13635                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13636                 break;
13637         case -ENODEV:
13638                 printf("invalid port_id %d\n", res->port_id);
13639                 break;
13640         case -ENOTSUP:
13641                 printf("function not implemented\n");
13642                 break;
13643         default:
13644                 printf("programming error: (%s)\n", strerror(-ret));
13645         }
13646 }
13647
13648 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13649         .f = cmd_set_vf_vlan_insert_parsed,
13650         .data = NULL,
13651         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13652         .tokens = {
13653                 (void *)&cmd_vf_vlan_insert_set,
13654                 (void *)&cmd_vf_vlan_insert_vf,
13655                 (void *)&cmd_vf_vlan_insert_vlan,
13656                 (void *)&cmd_vf_vlan_insert_insert,
13657                 (void *)&cmd_vf_vlan_insert_port_id,
13658                 (void *)&cmd_vf_vlan_insert_vf_id,
13659                 (void *)&cmd_vf_vlan_insert_vlan_id,
13660                 NULL,
13661         },
13662 };
13663
13664 /* tx loopback configuration */
13665
13666 /* Common result structure for tx loopback */
13667 struct cmd_tx_loopback_result {
13668         cmdline_fixed_string_t set;
13669         cmdline_fixed_string_t tx;
13670         cmdline_fixed_string_t loopback;
13671         portid_t port_id;
13672         cmdline_fixed_string_t on_off;
13673 };
13674
13675 /* Common CLI fields for tx loopback enable disable */
13676 cmdline_parse_token_string_t cmd_tx_loopback_set =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_tx_loopback_result,
13679                  set, "set");
13680 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13681         TOKEN_STRING_INITIALIZER
13682                 (struct cmd_tx_loopback_result,
13683                  tx, "tx");
13684 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_tx_loopback_result,
13687                  loopback, "loopback");
13688 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13689         TOKEN_NUM_INITIALIZER
13690                 (struct cmd_tx_loopback_result,
13691                  port_id, UINT16);
13692 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13693         TOKEN_STRING_INITIALIZER
13694                 (struct cmd_tx_loopback_result,
13695                  on_off, "on#off");
13696
13697 static void
13698 cmd_set_tx_loopback_parsed(
13699         void *parsed_result,
13700         __attribute__((unused)) struct cmdline *cl,
13701         __attribute__((unused)) void *data)
13702 {
13703         struct cmd_tx_loopback_result *res = parsed_result;
13704         int ret = -ENOTSUP;
13705
13706         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13707
13708         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13709                 return;
13710
13711 #ifdef RTE_LIBRTE_IXGBE_PMD
13712         if (ret == -ENOTSUP)
13713                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13714 #endif
13715 #ifdef RTE_LIBRTE_I40E_PMD
13716         if (ret == -ENOTSUP)
13717                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13718 #endif
13719 #ifdef RTE_LIBRTE_BNXT_PMD
13720         if (ret == -ENOTSUP)
13721                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13722 #endif
13723 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13724         if (ret == -ENOTSUP)
13725                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13726 #endif
13727
13728         switch (ret) {
13729         case 0:
13730                 break;
13731         case -EINVAL:
13732                 printf("invalid is_on %d\n", is_on);
13733                 break;
13734         case -ENODEV:
13735                 printf("invalid port_id %d\n", res->port_id);
13736                 break;
13737         case -ENOTSUP:
13738                 printf("function not implemented\n");
13739                 break;
13740         default:
13741                 printf("programming error: (%s)\n", strerror(-ret));
13742         }
13743 }
13744
13745 cmdline_parse_inst_t cmd_set_tx_loopback = {
13746         .f = cmd_set_tx_loopback_parsed,
13747         .data = NULL,
13748         .help_str = "set tx loopback <port_id> on|off",
13749         .tokens = {
13750                 (void *)&cmd_tx_loopback_set,
13751                 (void *)&cmd_tx_loopback_tx,
13752                 (void *)&cmd_tx_loopback_loopback,
13753                 (void *)&cmd_tx_loopback_port_id,
13754                 (void *)&cmd_tx_loopback_on_off,
13755                 NULL,
13756         },
13757 };
13758
13759 /* all queues drop enable configuration */
13760
13761 /* Common result structure for all queues drop enable */
13762 struct cmd_all_queues_drop_en_result {
13763         cmdline_fixed_string_t set;
13764         cmdline_fixed_string_t all;
13765         cmdline_fixed_string_t queues;
13766         cmdline_fixed_string_t drop;
13767         portid_t port_id;
13768         cmdline_fixed_string_t on_off;
13769 };
13770
13771 /* Common CLI fields for tx loopback enable disable */
13772 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13773         TOKEN_STRING_INITIALIZER
13774                 (struct cmd_all_queues_drop_en_result,
13775                  set, "set");
13776 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13777         TOKEN_STRING_INITIALIZER
13778                 (struct cmd_all_queues_drop_en_result,
13779                  all, "all");
13780 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13781         TOKEN_STRING_INITIALIZER
13782                 (struct cmd_all_queues_drop_en_result,
13783                  queues, "queues");
13784 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13785         TOKEN_STRING_INITIALIZER
13786                 (struct cmd_all_queues_drop_en_result,
13787                  drop, "drop");
13788 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13789         TOKEN_NUM_INITIALIZER
13790                 (struct cmd_all_queues_drop_en_result,
13791                  port_id, UINT16);
13792 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13793         TOKEN_STRING_INITIALIZER
13794                 (struct cmd_all_queues_drop_en_result,
13795                  on_off, "on#off");
13796
13797 static void
13798 cmd_set_all_queues_drop_en_parsed(
13799         void *parsed_result,
13800         __attribute__((unused)) struct cmdline *cl,
13801         __attribute__((unused)) void *data)
13802 {
13803         struct cmd_all_queues_drop_en_result *res = parsed_result;
13804         int ret = -ENOTSUP;
13805         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13806
13807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13808                 return;
13809
13810 #ifdef RTE_LIBRTE_IXGBE_PMD
13811         if (ret == -ENOTSUP)
13812                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13813 #endif
13814 #ifdef RTE_LIBRTE_BNXT_PMD
13815         if (ret == -ENOTSUP)
13816                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13817 #endif
13818         switch (ret) {
13819         case 0:
13820                 break;
13821         case -EINVAL:
13822                 printf("invalid is_on %d\n", is_on);
13823                 break;
13824         case -ENODEV:
13825                 printf("invalid port_id %d\n", res->port_id);
13826                 break;
13827         case -ENOTSUP:
13828                 printf("function not implemented\n");
13829                 break;
13830         default:
13831                 printf("programming error: (%s)\n", strerror(-ret));
13832         }
13833 }
13834
13835 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13836         .f = cmd_set_all_queues_drop_en_parsed,
13837         .data = NULL,
13838         .help_str = "set all queues drop <port_id> on|off",
13839         .tokens = {
13840                 (void *)&cmd_all_queues_drop_en_set,
13841                 (void *)&cmd_all_queues_drop_en_all,
13842                 (void *)&cmd_all_queues_drop_en_queues,
13843                 (void *)&cmd_all_queues_drop_en_drop,
13844                 (void *)&cmd_all_queues_drop_en_port_id,
13845                 (void *)&cmd_all_queues_drop_en_on_off,
13846                 NULL,
13847         },
13848 };
13849
13850 /* vf split drop enable configuration */
13851
13852 /* Common result structure for vf split drop enable */
13853 struct cmd_vf_split_drop_en_result {
13854         cmdline_fixed_string_t set;
13855         cmdline_fixed_string_t vf;
13856         cmdline_fixed_string_t split;
13857         cmdline_fixed_string_t drop;
13858         portid_t port_id;
13859         uint16_t vf_id;
13860         cmdline_fixed_string_t on_off;
13861 };
13862
13863 /* Common CLI fields for vf split drop enable disable */
13864 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13865         TOKEN_STRING_INITIALIZER
13866                 (struct cmd_vf_split_drop_en_result,
13867                  set, "set");
13868 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_vf_split_drop_en_result,
13871                  vf, "vf");
13872 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13873         TOKEN_STRING_INITIALIZER
13874                 (struct cmd_vf_split_drop_en_result,
13875                  split, "split");
13876 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13877         TOKEN_STRING_INITIALIZER
13878                 (struct cmd_vf_split_drop_en_result,
13879                  drop, "drop");
13880 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13881         TOKEN_NUM_INITIALIZER
13882                 (struct cmd_vf_split_drop_en_result,
13883                  port_id, UINT16);
13884 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13885         TOKEN_NUM_INITIALIZER
13886                 (struct cmd_vf_split_drop_en_result,
13887                  vf_id, UINT16);
13888 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13889         TOKEN_STRING_INITIALIZER
13890                 (struct cmd_vf_split_drop_en_result,
13891                  on_off, "on#off");
13892
13893 static void
13894 cmd_set_vf_split_drop_en_parsed(
13895         void *parsed_result,
13896         __attribute__((unused)) struct cmdline *cl,
13897         __attribute__((unused)) void *data)
13898 {
13899         struct cmd_vf_split_drop_en_result *res = parsed_result;
13900         int ret = -ENOTSUP;
13901         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13902
13903         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13904                 return;
13905
13906 #ifdef RTE_LIBRTE_IXGBE_PMD
13907         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13908                         is_on);
13909 #endif
13910         switch (ret) {
13911         case 0:
13912                 break;
13913         case -EINVAL:
13914                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13915                 break;
13916         case -ENODEV:
13917                 printf("invalid port_id %d\n", res->port_id);
13918                 break;
13919         case -ENOTSUP:
13920                 printf("not supported on port %d\n", res->port_id);
13921                 break;
13922         default:
13923                 printf("programming error: (%s)\n", strerror(-ret));
13924         }
13925 }
13926
13927 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13928         .f = cmd_set_vf_split_drop_en_parsed,
13929         .data = NULL,
13930         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13931         .tokens = {
13932                 (void *)&cmd_vf_split_drop_en_set,
13933                 (void *)&cmd_vf_split_drop_en_vf,
13934                 (void *)&cmd_vf_split_drop_en_split,
13935                 (void *)&cmd_vf_split_drop_en_drop,
13936                 (void *)&cmd_vf_split_drop_en_port_id,
13937                 (void *)&cmd_vf_split_drop_en_vf_id,
13938                 (void *)&cmd_vf_split_drop_en_on_off,
13939                 NULL,
13940         },
13941 };
13942
13943 /* vf mac address configuration */
13944
13945 /* Common result structure for vf mac address */
13946 struct cmd_set_vf_mac_addr_result {
13947         cmdline_fixed_string_t set;
13948         cmdline_fixed_string_t vf;
13949         cmdline_fixed_string_t mac;
13950         cmdline_fixed_string_t addr;
13951         portid_t port_id;
13952         uint16_t vf_id;
13953         struct rte_ether_addr mac_addr;
13954
13955 };
13956
13957 /* Common CLI fields for vf split drop enable disable */
13958 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13959         TOKEN_STRING_INITIALIZER
13960                 (struct cmd_set_vf_mac_addr_result,
13961                  set, "set");
13962 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13963         TOKEN_STRING_INITIALIZER
13964                 (struct cmd_set_vf_mac_addr_result,
13965                  vf, "vf");
13966 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13967         TOKEN_STRING_INITIALIZER
13968                 (struct cmd_set_vf_mac_addr_result,
13969                  mac, "mac");
13970 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13971         TOKEN_STRING_INITIALIZER
13972                 (struct cmd_set_vf_mac_addr_result,
13973                  addr, "addr");
13974 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13975         TOKEN_NUM_INITIALIZER
13976                 (struct cmd_set_vf_mac_addr_result,
13977                  port_id, UINT16);
13978 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13979         TOKEN_NUM_INITIALIZER
13980                 (struct cmd_set_vf_mac_addr_result,
13981                  vf_id, UINT16);
13982 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13983         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13984                  mac_addr);
13985
13986 static void
13987 cmd_set_vf_mac_addr_parsed(
13988         void *parsed_result,
13989         __attribute__((unused)) struct cmdline *cl,
13990         __attribute__((unused)) void *data)
13991 {
13992         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13993         int ret = -ENOTSUP;
13994
13995         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13996                 return;
13997
13998 #ifdef RTE_LIBRTE_IXGBE_PMD
13999         if (ret == -ENOTSUP)
14000                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14001                                 &res->mac_addr);
14002 #endif
14003 #ifdef RTE_LIBRTE_I40E_PMD
14004         if (ret == -ENOTSUP)
14005                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14006                                 &res->mac_addr);
14007 #endif
14008 #ifdef RTE_LIBRTE_BNXT_PMD
14009         if (ret == -ENOTSUP)
14010                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14011                                 &res->mac_addr);
14012 #endif
14013
14014         switch (ret) {
14015         case 0:
14016                 break;
14017         case -EINVAL:
14018                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14019                 break;
14020         case -ENODEV:
14021                 printf("invalid port_id %d\n", res->port_id);
14022                 break;
14023         case -ENOTSUP:
14024                 printf("function not implemented\n");
14025                 break;
14026         default:
14027                 printf("programming error: (%s)\n", strerror(-ret));
14028         }
14029 }
14030
14031 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14032         .f = cmd_set_vf_mac_addr_parsed,
14033         .data = NULL,
14034         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14035         .tokens = {
14036                 (void *)&cmd_set_vf_mac_addr_set,
14037                 (void *)&cmd_set_vf_mac_addr_vf,
14038                 (void *)&cmd_set_vf_mac_addr_mac,
14039                 (void *)&cmd_set_vf_mac_addr_addr,
14040                 (void *)&cmd_set_vf_mac_addr_port_id,
14041                 (void *)&cmd_set_vf_mac_addr_vf_id,
14042                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14043                 NULL,
14044         },
14045 };
14046
14047 /* MACsec configuration */
14048
14049 /* Common result structure for MACsec offload enable */
14050 struct cmd_macsec_offload_on_result {
14051         cmdline_fixed_string_t set;
14052         cmdline_fixed_string_t macsec;
14053         cmdline_fixed_string_t offload;
14054         portid_t port_id;
14055         cmdline_fixed_string_t on;
14056         cmdline_fixed_string_t encrypt;
14057         cmdline_fixed_string_t en_on_off;
14058         cmdline_fixed_string_t replay_protect;
14059         cmdline_fixed_string_t rp_on_off;
14060 };
14061
14062 /* Common CLI fields for MACsec offload disable */
14063 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14064         TOKEN_STRING_INITIALIZER
14065                 (struct cmd_macsec_offload_on_result,
14066                  set, "set");
14067 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14068         TOKEN_STRING_INITIALIZER
14069                 (struct cmd_macsec_offload_on_result,
14070                  macsec, "macsec");
14071 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14072         TOKEN_STRING_INITIALIZER
14073                 (struct cmd_macsec_offload_on_result,
14074                  offload, "offload");
14075 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14076         TOKEN_NUM_INITIALIZER
14077                 (struct cmd_macsec_offload_on_result,
14078                  port_id, UINT16);
14079 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14080         TOKEN_STRING_INITIALIZER
14081                 (struct cmd_macsec_offload_on_result,
14082                  on, "on");
14083 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14084         TOKEN_STRING_INITIALIZER
14085                 (struct cmd_macsec_offload_on_result,
14086                  encrypt, "encrypt");
14087 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14088         TOKEN_STRING_INITIALIZER
14089                 (struct cmd_macsec_offload_on_result,
14090                  en_on_off, "on#off");
14091 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14092         TOKEN_STRING_INITIALIZER
14093                 (struct cmd_macsec_offload_on_result,
14094                  replay_protect, "replay-protect");
14095 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14096         TOKEN_STRING_INITIALIZER
14097                 (struct cmd_macsec_offload_on_result,
14098                  rp_on_off, "on#off");
14099
14100 static void
14101 cmd_set_macsec_offload_on_parsed(
14102         void *parsed_result,
14103         __attribute__((unused)) struct cmdline *cl,
14104         __attribute__((unused)) void *data)
14105 {
14106         struct cmd_macsec_offload_on_result *res = parsed_result;
14107         int ret = -ENOTSUP;
14108         portid_t port_id = res->port_id;
14109         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14110         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14111         struct rte_eth_dev_info dev_info;
14112
14113         if (port_id_is_invalid(port_id, ENABLED_WARN))
14114                 return;
14115         if (!port_is_stopped(port_id)) {
14116                 printf("Please stop port %d first\n", port_id);
14117                 return;
14118         }
14119
14120         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14121         if (ret != 0)
14122                 return;
14123
14124         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14125 #ifdef RTE_LIBRTE_IXGBE_PMD
14126                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14127 #endif
14128         }
14129         RTE_SET_USED(en);
14130         RTE_SET_USED(rp);
14131
14132         switch (ret) {
14133         case 0:
14134                 ports[port_id].dev_conf.txmode.offloads |=
14135                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14136                 cmd_reconfig_device_queue(port_id, 1, 1);
14137                 break;
14138         case -ENODEV:
14139                 printf("invalid port_id %d\n", port_id);
14140                 break;
14141         case -ENOTSUP:
14142                 printf("not supported on port %d\n", port_id);
14143                 break;
14144         default:
14145                 printf("programming error: (%s)\n", strerror(-ret));
14146         }
14147 }
14148
14149 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14150         .f = cmd_set_macsec_offload_on_parsed,
14151         .data = NULL,
14152         .help_str = "set macsec offload <port_id> on "
14153                 "encrypt on|off replay-protect on|off",
14154         .tokens = {
14155                 (void *)&cmd_macsec_offload_on_set,
14156                 (void *)&cmd_macsec_offload_on_macsec,
14157                 (void *)&cmd_macsec_offload_on_offload,
14158                 (void *)&cmd_macsec_offload_on_port_id,
14159                 (void *)&cmd_macsec_offload_on_on,
14160                 (void *)&cmd_macsec_offload_on_encrypt,
14161                 (void *)&cmd_macsec_offload_on_en_on_off,
14162                 (void *)&cmd_macsec_offload_on_replay_protect,
14163                 (void *)&cmd_macsec_offload_on_rp_on_off,
14164                 NULL,
14165         },
14166 };
14167
14168 /* Common result structure for MACsec offload disable */
14169 struct cmd_macsec_offload_off_result {
14170         cmdline_fixed_string_t set;
14171         cmdline_fixed_string_t macsec;
14172         cmdline_fixed_string_t offload;
14173         portid_t port_id;
14174         cmdline_fixed_string_t off;
14175 };
14176
14177 /* Common CLI fields for MACsec offload disable */
14178 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14179         TOKEN_STRING_INITIALIZER
14180                 (struct cmd_macsec_offload_off_result,
14181                  set, "set");
14182 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14183         TOKEN_STRING_INITIALIZER
14184                 (struct cmd_macsec_offload_off_result,
14185                  macsec, "macsec");
14186 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14187         TOKEN_STRING_INITIALIZER
14188                 (struct cmd_macsec_offload_off_result,
14189                  offload, "offload");
14190 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14191         TOKEN_NUM_INITIALIZER
14192                 (struct cmd_macsec_offload_off_result,
14193                  port_id, UINT16);
14194 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14195         TOKEN_STRING_INITIALIZER
14196                 (struct cmd_macsec_offload_off_result,
14197                  off, "off");
14198
14199 static void
14200 cmd_set_macsec_offload_off_parsed(
14201         void *parsed_result,
14202         __attribute__((unused)) struct cmdline *cl,
14203         __attribute__((unused)) void *data)
14204 {
14205         struct cmd_macsec_offload_off_result *res = parsed_result;
14206         int ret = -ENOTSUP;
14207         struct rte_eth_dev_info dev_info;
14208         portid_t port_id = res->port_id;
14209
14210         if (port_id_is_invalid(port_id, ENABLED_WARN))
14211                 return;
14212         if (!port_is_stopped(port_id)) {
14213                 printf("Please stop port %d first\n", port_id);
14214                 return;
14215         }
14216
14217         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14218         if (ret != 0)
14219                 return;
14220
14221         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14222 #ifdef RTE_LIBRTE_IXGBE_PMD
14223                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14224 #endif
14225         }
14226         switch (ret) {
14227         case 0:
14228                 ports[port_id].dev_conf.txmode.offloads &=
14229                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14230                 cmd_reconfig_device_queue(port_id, 1, 1);
14231                 break;
14232         case -ENODEV:
14233                 printf("invalid port_id %d\n", port_id);
14234                 break;
14235         case -ENOTSUP:
14236                 printf("not supported on port %d\n", port_id);
14237                 break;
14238         default:
14239                 printf("programming error: (%s)\n", strerror(-ret));
14240         }
14241 }
14242
14243 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14244         .f = cmd_set_macsec_offload_off_parsed,
14245         .data = NULL,
14246         .help_str = "set macsec offload <port_id> off",
14247         .tokens = {
14248                 (void *)&cmd_macsec_offload_off_set,
14249                 (void *)&cmd_macsec_offload_off_macsec,
14250                 (void *)&cmd_macsec_offload_off_offload,
14251                 (void *)&cmd_macsec_offload_off_port_id,
14252                 (void *)&cmd_macsec_offload_off_off,
14253                 NULL,
14254         },
14255 };
14256
14257 /* Common result structure for MACsec secure connection configure */
14258 struct cmd_macsec_sc_result {
14259         cmdline_fixed_string_t set;
14260         cmdline_fixed_string_t macsec;
14261         cmdline_fixed_string_t sc;
14262         cmdline_fixed_string_t tx_rx;
14263         portid_t port_id;
14264         struct rte_ether_addr mac;
14265         uint16_t pi;
14266 };
14267
14268 /* Common CLI fields for MACsec secure connection configure */
14269 cmdline_parse_token_string_t cmd_macsec_sc_set =
14270         TOKEN_STRING_INITIALIZER
14271                 (struct cmd_macsec_sc_result,
14272                  set, "set");
14273 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14274         TOKEN_STRING_INITIALIZER
14275                 (struct cmd_macsec_sc_result,
14276                  macsec, "macsec");
14277 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14278         TOKEN_STRING_INITIALIZER
14279                 (struct cmd_macsec_sc_result,
14280                  sc, "sc");
14281 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14282         TOKEN_STRING_INITIALIZER
14283                 (struct cmd_macsec_sc_result,
14284                  tx_rx, "tx#rx");
14285 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14286         TOKEN_NUM_INITIALIZER
14287                 (struct cmd_macsec_sc_result,
14288                  port_id, UINT16);
14289 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14290         TOKEN_ETHERADDR_INITIALIZER
14291                 (struct cmd_macsec_sc_result,
14292                  mac);
14293 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14294         TOKEN_NUM_INITIALIZER
14295                 (struct cmd_macsec_sc_result,
14296                  pi, UINT16);
14297
14298 static void
14299 cmd_set_macsec_sc_parsed(
14300         void *parsed_result,
14301         __attribute__((unused)) struct cmdline *cl,
14302         __attribute__((unused)) void *data)
14303 {
14304         struct cmd_macsec_sc_result *res = parsed_result;
14305         int ret = -ENOTSUP;
14306         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14307
14308 #ifdef RTE_LIBRTE_IXGBE_PMD
14309         ret = is_tx ?
14310                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14311                                 res->mac.addr_bytes) :
14312                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14313                                 res->mac.addr_bytes, res->pi);
14314 #endif
14315         RTE_SET_USED(is_tx);
14316
14317         switch (ret) {
14318         case 0:
14319                 break;
14320         case -ENODEV:
14321                 printf("invalid port_id %d\n", res->port_id);
14322                 break;
14323         case -ENOTSUP:
14324                 printf("not supported on port %d\n", res->port_id);
14325                 break;
14326         default:
14327                 printf("programming error: (%s)\n", strerror(-ret));
14328         }
14329 }
14330
14331 cmdline_parse_inst_t cmd_set_macsec_sc = {
14332         .f = cmd_set_macsec_sc_parsed,
14333         .data = NULL,
14334         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14335         .tokens = {
14336                 (void *)&cmd_macsec_sc_set,
14337                 (void *)&cmd_macsec_sc_macsec,
14338                 (void *)&cmd_macsec_sc_sc,
14339                 (void *)&cmd_macsec_sc_tx_rx,
14340                 (void *)&cmd_macsec_sc_port_id,
14341                 (void *)&cmd_macsec_sc_mac,
14342                 (void *)&cmd_macsec_sc_pi,
14343                 NULL,
14344         },
14345 };
14346
14347 /* Common result structure for MACsec secure connection configure */
14348 struct cmd_macsec_sa_result {
14349         cmdline_fixed_string_t set;
14350         cmdline_fixed_string_t macsec;
14351         cmdline_fixed_string_t sa;
14352         cmdline_fixed_string_t tx_rx;
14353         portid_t port_id;
14354         uint8_t idx;
14355         uint8_t an;
14356         uint32_t pn;
14357         cmdline_fixed_string_t key;
14358 };
14359
14360 /* Common CLI fields for MACsec secure connection configure */
14361 cmdline_parse_token_string_t cmd_macsec_sa_set =
14362         TOKEN_STRING_INITIALIZER
14363                 (struct cmd_macsec_sa_result,
14364                  set, "set");
14365 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14366         TOKEN_STRING_INITIALIZER
14367                 (struct cmd_macsec_sa_result,
14368                  macsec, "macsec");
14369 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_macsec_sa_result,
14372                  sa, "sa");
14373 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14374         TOKEN_STRING_INITIALIZER
14375                 (struct cmd_macsec_sa_result,
14376                  tx_rx, "tx#rx");
14377 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14378         TOKEN_NUM_INITIALIZER
14379                 (struct cmd_macsec_sa_result,
14380                  port_id, UINT16);
14381 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14382         TOKEN_NUM_INITIALIZER
14383                 (struct cmd_macsec_sa_result,
14384                  idx, UINT8);
14385 cmdline_parse_token_num_t cmd_macsec_sa_an =
14386         TOKEN_NUM_INITIALIZER
14387                 (struct cmd_macsec_sa_result,
14388                  an, UINT8);
14389 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14390         TOKEN_NUM_INITIALIZER
14391                 (struct cmd_macsec_sa_result,
14392                  pn, UINT32);
14393 cmdline_parse_token_string_t cmd_macsec_sa_key =
14394         TOKEN_STRING_INITIALIZER
14395                 (struct cmd_macsec_sa_result,
14396                  key, NULL);
14397
14398 static void
14399 cmd_set_macsec_sa_parsed(
14400         void *parsed_result,
14401         __attribute__((unused)) struct cmdline *cl,
14402         __attribute__((unused)) void *data)
14403 {
14404         struct cmd_macsec_sa_result *res = parsed_result;
14405         int ret = -ENOTSUP;
14406         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14407         uint8_t key[16] = { 0 };
14408         uint8_t xdgt0;
14409         uint8_t xdgt1;
14410         int key_len;
14411         int i;
14412
14413         key_len = strlen(res->key) / 2;
14414         if (key_len > 16)
14415                 key_len = 16;
14416
14417         for (i = 0; i < key_len; i++) {
14418                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14419                 if (xdgt0 == 0xFF)
14420                         return;
14421                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14422                 if (xdgt1 == 0xFF)
14423                         return;
14424                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14425         }
14426
14427 #ifdef RTE_LIBRTE_IXGBE_PMD
14428         ret = is_tx ?
14429                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14430                         res->idx, res->an, res->pn, key) :
14431                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14432                         res->idx, res->an, res->pn, key);
14433 #endif
14434         RTE_SET_USED(is_tx);
14435         RTE_SET_USED(key);
14436
14437         switch (ret) {
14438         case 0:
14439                 break;
14440         case -EINVAL:
14441                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14442                 break;
14443         case -ENODEV:
14444                 printf("invalid port_id %d\n", res->port_id);
14445                 break;
14446         case -ENOTSUP:
14447                 printf("not supported on port %d\n", res->port_id);
14448                 break;
14449         default:
14450                 printf("programming error: (%s)\n", strerror(-ret));
14451         }
14452 }
14453
14454 cmdline_parse_inst_t cmd_set_macsec_sa = {
14455         .f = cmd_set_macsec_sa_parsed,
14456         .data = NULL,
14457         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14458         .tokens = {
14459                 (void *)&cmd_macsec_sa_set,
14460                 (void *)&cmd_macsec_sa_macsec,
14461                 (void *)&cmd_macsec_sa_sa,
14462                 (void *)&cmd_macsec_sa_tx_rx,
14463                 (void *)&cmd_macsec_sa_port_id,
14464                 (void *)&cmd_macsec_sa_idx,
14465                 (void *)&cmd_macsec_sa_an,
14466                 (void *)&cmd_macsec_sa_pn,
14467                 (void *)&cmd_macsec_sa_key,
14468                 NULL,
14469         },
14470 };
14471
14472 /* VF unicast promiscuous mode configuration */
14473
14474 /* Common result structure for VF unicast promiscuous mode */
14475 struct cmd_vf_promisc_result {
14476         cmdline_fixed_string_t set;
14477         cmdline_fixed_string_t vf;
14478         cmdline_fixed_string_t promisc;
14479         portid_t port_id;
14480         uint32_t vf_id;
14481         cmdline_fixed_string_t on_off;
14482 };
14483
14484 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14485 cmdline_parse_token_string_t cmd_vf_promisc_set =
14486         TOKEN_STRING_INITIALIZER
14487                 (struct cmd_vf_promisc_result,
14488                  set, "set");
14489 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14490         TOKEN_STRING_INITIALIZER
14491                 (struct cmd_vf_promisc_result,
14492                  vf, "vf");
14493 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14494         TOKEN_STRING_INITIALIZER
14495                 (struct cmd_vf_promisc_result,
14496                  promisc, "promisc");
14497 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14498         TOKEN_NUM_INITIALIZER
14499                 (struct cmd_vf_promisc_result,
14500                  port_id, UINT16);
14501 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14502         TOKEN_NUM_INITIALIZER
14503                 (struct cmd_vf_promisc_result,
14504                  vf_id, UINT32);
14505 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14506         TOKEN_STRING_INITIALIZER
14507                 (struct cmd_vf_promisc_result,
14508                  on_off, "on#off");
14509
14510 static void
14511 cmd_set_vf_promisc_parsed(
14512         void *parsed_result,
14513         __attribute__((unused)) struct cmdline *cl,
14514         __attribute__((unused)) void *data)
14515 {
14516         struct cmd_vf_promisc_result *res = parsed_result;
14517         int ret = -ENOTSUP;
14518
14519         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14520
14521         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14522                 return;
14523
14524 #ifdef RTE_LIBRTE_I40E_PMD
14525         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14526                                                   res->vf_id, is_on);
14527 #endif
14528
14529         switch (ret) {
14530         case 0:
14531                 break;
14532         case -EINVAL:
14533                 printf("invalid vf_id %d\n", res->vf_id);
14534                 break;
14535         case -ENODEV:
14536                 printf("invalid port_id %d\n", res->port_id);
14537                 break;
14538         case -ENOTSUP:
14539                 printf("function not implemented\n");
14540                 break;
14541         default:
14542                 printf("programming error: (%s)\n", strerror(-ret));
14543         }
14544 }
14545
14546 cmdline_parse_inst_t cmd_set_vf_promisc = {
14547         .f = cmd_set_vf_promisc_parsed,
14548         .data = NULL,
14549         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14550                 "Set unicast promiscuous mode for a VF from the PF",
14551         .tokens = {
14552                 (void *)&cmd_vf_promisc_set,
14553                 (void *)&cmd_vf_promisc_vf,
14554                 (void *)&cmd_vf_promisc_promisc,
14555                 (void *)&cmd_vf_promisc_port_id,
14556                 (void *)&cmd_vf_promisc_vf_id,
14557                 (void *)&cmd_vf_promisc_on_off,
14558                 NULL,
14559         },
14560 };
14561
14562 /* VF multicast promiscuous mode configuration */
14563
14564 /* Common result structure for VF multicast promiscuous mode */
14565 struct cmd_vf_allmulti_result {
14566         cmdline_fixed_string_t set;
14567         cmdline_fixed_string_t vf;
14568         cmdline_fixed_string_t allmulti;
14569         portid_t port_id;
14570         uint32_t vf_id;
14571         cmdline_fixed_string_t on_off;
14572 };
14573
14574 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14575 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14576         TOKEN_STRING_INITIALIZER
14577                 (struct cmd_vf_allmulti_result,
14578                  set, "set");
14579 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14580         TOKEN_STRING_INITIALIZER
14581                 (struct cmd_vf_allmulti_result,
14582                  vf, "vf");
14583 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14584         TOKEN_STRING_INITIALIZER
14585                 (struct cmd_vf_allmulti_result,
14586                  allmulti, "allmulti");
14587 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14588         TOKEN_NUM_INITIALIZER
14589                 (struct cmd_vf_allmulti_result,
14590                  port_id, UINT16);
14591 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14592         TOKEN_NUM_INITIALIZER
14593                 (struct cmd_vf_allmulti_result,
14594                  vf_id, UINT32);
14595 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14596         TOKEN_STRING_INITIALIZER
14597                 (struct cmd_vf_allmulti_result,
14598                  on_off, "on#off");
14599
14600 static void
14601 cmd_set_vf_allmulti_parsed(
14602         void *parsed_result,
14603         __attribute__((unused)) struct cmdline *cl,
14604         __attribute__((unused)) void *data)
14605 {
14606         struct cmd_vf_allmulti_result *res = parsed_result;
14607         int ret = -ENOTSUP;
14608
14609         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14610
14611         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14612                 return;
14613
14614 #ifdef RTE_LIBRTE_I40E_PMD
14615         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14616                                                     res->vf_id, is_on);
14617 #endif
14618
14619         switch (ret) {
14620         case 0:
14621                 break;
14622         case -EINVAL:
14623                 printf("invalid vf_id %d\n", res->vf_id);
14624                 break;
14625         case -ENODEV:
14626                 printf("invalid port_id %d\n", res->port_id);
14627                 break;
14628         case -ENOTSUP:
14629                 printf("function not implemented\n");
14630                 break;
14631         default:
14632                 printf("programming error: (%s)\n", strerror(-ret));
14633         }
14634 }
14635
14636 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14637         .f = cmd_set_vf_allmulti_parsed,
14638         .data = NULL,
14639         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14640                 "Set multicast promiscuous mode for a VF from the PF",
14641         .tokens = {
14642                 (void *)&cmd_vf_allmulti_set,
14643                 (void *)&cmd_vf_allmulti_vf,
14644                 (void *)&cmd_vf_allmulti_allmulti,
14645                 (void *)&cmd_vf_allmulti_port_id,
14646                 (void *)&cmd_vf_allmulti_vf_id,
14647                 (void *)&cmd_vf_allmulti_on_off,
14648                 NULL,
14649         },
14650 };
14651
14652 /* vf broadcast mode configuration */
14653
14654 /* Common result structure for vf broadcast */
14655 struct cmd_set_vf_broadcast_result {
14656         cmdline_fixed_string_t set;
14657         cmdline_fixed_string_t vf;
14658         cmdline_fixed_string_t broadcast;
14659         portid_t port_id;
14660         uint16_t vf_id;
14661         cmdline_fixed_string_t on_off;
14662 };
14663
14664 /* Common CLI fields for vf broadcast enable disable */
14665 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14666         TOKEN_STRING_INITIALIZER
14667                 (struct cmd_set_vf_broadcast_result,
14668                  set, "set");
14669 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14670         TOKEN_STRING_INITIALIZER
14671                 (struct cmd_set_vf_broadcast_result,
14672                  vf, "vf");
14673 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14674         TOKEN_STRING_INITIALIZER
14675                 (struct cmd_set_vf_broadcast_result,
14676                  broadcast, "broadcast");
14677 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14678         TOKEN_NUM_INITIALIZER
14679                 (struct cmd_set_vf_broadcast_result,
14680                  port_id, UINT16);
14681 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14682         TOKEN_NUM_INITIALIZER
14683                 (struct cmd_set_vf_broadcast_result,
14684                  vf_id, UINT16);
14685 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14686         TOKEN_STRING_INITIALIZER
14687                 (struct cmd_set_vf_broadcast_result,
14688                  on_off, "on#off");
14689
14690 static void
14691 cmd_set_vf_broadcast_parsed(
14692         void *parsed_result,
14693         __attribute__((unused)) struct cmdline *cl,
14694         __attribute__((unused)) void *data)
14695 {
14696         struct cmd_set_vf_broadcast_result *res = parsed_result;
14697         int ret = -ENOTSUP;
14698
14699         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14700
14701         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14702                 return;
14703
14704 #ifdef RTE_LIBRTE_I40E_PMD
14705         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14706                                             res->vf_id, is_on);
14707 #endif
14708
14709         switch (ret) {
14710         case 0:
14711                 break;
14712         case -EINVAL:
14713                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14714                 break;
14715         case -ENODEV:
14716                 printf("invalid port_id %d\n", res->port_id);
14717                 break;
14718         case -ENOTSUP:
14719                 printf("function not implemented\n");
14720                 break;
14721         default:
14722                 printf("programming error: (%s)\n", strerror(-ret));
14723         }
14724 }
14725
14726 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14727         .f = cmd_set_vf_broadcast_parsed,
14728         .data = NULL,
14729         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14730         .tokens = {
14731                 (void *)&cmd_set_vf_broadcast_set,
14732                 (void *)&cmd_set_vf_broadcast_vf,
14733                 (void *)&cmd_set_vf_broadcast_broadcast,
14734                 (void *)&cmd_set_vf_broadcast_port_id,
14735                 (void *)&cmd_set_vf_broadcast_vf_id,
14736                 (void *)&cmd_set_vf_broadcast_on_off,
14737                 NULL,
14738         },
14739 };
14740
14741 /* vf vlan tag configuration */
14742
14743 /* Common result structure for vf vlan tag */
14744 struct cmd_set_vf_vlan_tag_result {
14745         cmdline_fixed_string_t set;
14746         cmdline_fixed_string_t vf;
14747         cmdline_fixed_string_t vlan;
14748         cmdline_fixed_string_t tag;
14749         portid_t port_id;
14750         uint16_t vf_id;
14751         cmdline_fixed_string_t on_off;
14752 };
14753
14754 /* Common CLI fields for vf vlan tag enable disable */
14755 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14756         TOKEN_STRING_INITIALIZER
14757                 (struct cmd_set_vf_vlan_tag_result,
14758                  set, "set");
14759 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14760         TOKEN_STRING_INITIALIZER
14761                 (struct cmd_set_vf_vlan_tag_result,
14762                  vf, "vf");
14763 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14764         TOKEN_STRING_INITIALIZER
14765                 (struct cmd_set_vf_vlan_tag_result,
14766                  vlan, "vlan");
14767 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14768         TOKEN_STRING_INITIALIZER
14769                 (struct cmd_set_vf_vlan_tag_result,
14770                  tag, "tag");
14771 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14772         TOKEN_NUM_INITIALIZER
14773                 (struct cmd_set_vf_vlan_tag_result,
14774                  port_id, UINT16);
14775 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14776         TOKEN_NUM_INITIALIZER
14777                 (struct cmd_set_vf_vlan_tag_result,
14778                  vf_id, UINT16);
14779 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14780         TOKEN_STRING_INITIALIZER
14781                 (struct cmd_set_vf_vlan_tag_result,
14782                  on_off, "on#off");
14783
14784 static void
14785 cmd_set_vf_vlan_tag_parsed(
14786         void *parsed_result,
14787         __attribute__((unused)) struct cmdline *cl,
14788         __attribute__((unused)) void *data)
14789 {
14790         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14791         int ret = -ENOTSUP;
14792
14793         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14794
14795         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14796                 return;
14797
14798 #ifdef RTE_LIBRTE_I40E_PMD
14799         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14800                                            res->vf_id, is_on);
14801 #endif
14802
14803         switch (ret) {
14804         case 0:
14805                 break;
14806         case -EINVAL:
14807                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14808                 break;
14809         case -ENODEV:
14810                 printf("invalid port_id %d\n", res->port_id);
14811                 break;
14812         case -ENOTSUP:
14813                 printf("function not implemented\n");
14814                 break;
14815         default:
14816                 printf("programming error: (%s)\n", strerror(-ret));
14817         }
14818 }
14819
14820 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14821         .f = cmd_set_vf_vlan_tag_parsed,
14822         .data = NULL,
14823         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14824         .tokens = {
14825                 (void *)&cmd_set_vf_vlan_tag_set,
14826                 (void *)&cmd_set_vf_vlan_tag_vf,
14827                 (void *)&cmd_set_vf_vlan_tag_vlan,
14828                 (void *)&cmd_set_vf_vlan_tag_tag,
14829                 (void *)&cmd_set_vf_vlan_tag_port_id,
14830                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14831                 (void *)&cmd_set_vf_vlan_tag_on_off,
14832                 NULL,
14833         },
14834 };
14835
14836 /* Common definition of VF and TC TX bandwidth configuration */
14837 struct cmd_vf_tc_bw_result {
14838         cmdline_fixed_string_t set;
14839         cmdline_fixed_string_t vf;
14840         cmdline_fixed_string_t tc;
14841         cmdline_fixed_string_t tx;
14842         cmdline_fixed_string_t min_bw;
14843         cmdline_fixed_string_t max_bw;
14844         cmdline_fixed_string_t strict_link_prio;
14845         portid_t port_id;
14846         uint16_t vf_id;
14847         uint8_t tc_no;
14848         uint32_t bw;
14849         cmdline_fixed_string_t bw_list;
14850         uint8_t tc_map;
14851 };
14852
14853 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14854         TOKEN_STRING_INITIALIZER
14855                 (struct cmd_vf_tc_bw_result,
14856                  set, "set");
14857 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14858         TOKEN_STRING_INITIALIZER
14859                 (struct cmd_vf_tc_bw_result,
14860                  vf, "vf");
14861 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14862         TOKEN_STRING_INITIALIZER
14863                 (struct cmd_vf_tc_bw_result,
14864                  tc, "tc");
14865 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14866         TOKEN_STRING_INITIALIZER
14867                 (struct cmd_vf_tc_bw_result,
14868                  tx, "tx");
14869 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14870         TOKEN_STRING_INITIALIZER
14871                 (struct cmd_vf_tc_bw_result,
14872                  strict_link_prio, "strict-link-priority");
14873 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14874         TOKEN_STRING_INITIALIZER
14875                 (struct cmd_vf_tc_bw_result,
14876                  min_bw, "min-bandwidth");
14877 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14878         TOKEN_STRING_INITIALIZER
14879                 (struct cmd_vf_tc_bw_result,
14880                  max_bw, "max-bandwidth");
14881 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14882         TOKEN_NUM_INITIALIZER
14883                 (struct cmd_vf_tc_bw_result,
14884                  port_id, UINT16);
14885 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14886         TOKEN_NUM_INITIALIZER
14887                 (struct cmd_vf_tc_bw_result,
14888                  vf_id, UINT16);
14889 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14890         TOKEN_NUM_INITIALIZER
14891                 (struct cmd_vf_tc_bw_result,
14892                  tc_no, UINT8);
14893 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14894         TOKEN_NUM_INITIALIZER
14895                 (struct cmd_vf_tc_bw_result,
14896                  bw, UINT32);
14897 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14898         TOKEN_STRING_INITIALIZER
14899                 (struct cmd_vf_tc_bw_result,
14900                  bw_list, NULL);
14901 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14902         TOKEN_NUM_INITIALIZER
14903                 (struct cmd_vf_tc_bw_result,
14904                  tc_map, UINT8);
14905
14906 /* VF max bandwidth setting */
14907 static void
14908 cmd_vf_max_bw_parsed(
14909         void *parsed_result,
14910         __attribute__((unused)) struct cmdline *cl,
14911         __attribute__((unused)) void *data)
14912 {
14913         struct cmd_vf_tc_bw_result *res = parsed_result;
14914         int ret = -ENOTSUP;
14915
14916         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14917                 return;
14918
14919 #ifdef RTE_LIBRTE_I40E_PMD
14920         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14921                                          res->vf_id, res->bw);
14922 #endif
14923
14924         switch (ret) {
14925         case 0:
14926                 break;
14927         case -EINVAL:
14928                 printf("invalid vf_id %d or bandwidth %d\n",
14929                        res->vf_id, res->bw);
14930                 break;
14931         case -ENODEV:
14932                 printf("invalid port_id %d\n", res->port_id);
14933                 break;
14934         case -ENOTSUP:
14935                 printf("function not implemented\n");
14936                 break;
14937         default:
14938                 printf("programming error: (%s)\n", strerror(-ret));
14939         }
14940 }
14941
14942 cmdline_parse_inst_t cmd_vf_max_bw = {
14943         .f = cmd_vf_max_bw_parsed,
14944         .data = NULL,
14945         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14946         .tokens = {
14947                 (void *)&cmd_vf_tc_bw_set,
14948                 (void *)&cmd_vf_tc_bw_vf,
14949                 (void *)&cmd_vf_tc_bw_tx,
14950                 (void *)&cmd_vf_tc_bw_max_bw,
14951                 (void *)&cmd_vf_tc_bw_port_id,
14952                 (void *)&cmd_vf_tc_bw_vf_id,
14953                 (void *)&cmd_vf_tc_bw_bw,
14954                 NULL,
14955         },
14956 };
14957
14958 static int
14959 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14960                            uint8_t *tc_num,
14961                            char *str)
14962 {
14963         uint32_t size;
14964         const char *p, *p0 = str;
14965         char s[256];
14966         char *end;
14967         char *str_fld[16];
14968         uint16_t i;
14969         int ret;
14970
14971         p = strchr(p0, '(');
14972         if (p == NULL) {
14973                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14974                 return -1;
14975         }
14976         p++;
14977         p0 = strchr(p, ')');
14978         if (p0 == NULL) {
14979                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14980                 return -1;
14981         }
14982         size = p0 - p;
14983         if (size >= sizeof(s)) {
14984                 printf("The string size exceeds the internal buffer size\n");
14985                 return -1;
14986         }
14987         snprintf(s, sizeof(s), "%.*s", size, p);
14988         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14989         if (ret <= 0) {
14990                 printf("Failed to get the bandwidth list. ");
14991                 return -1;
14992         }
14993         *tc_num = ret;
14994         for (i = 0; i < ret; i++)
14995                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14996
14997         return 0;
14998 }
14999
15000 /* TC min bandwidth setting */
15001 static void
15002 cmd_vf_tc_min_bw_parsed(
15003         void *parsed_result,
15004         __attribute__((unused)) struct cmdline *cl,
15005         __attribute__((unused)) void *data)
15006 {
15007         struct cmd_vf_tc_bw_result *res = parsed_result;
15008         uint8_t tc_num;
15009         uint8_t bw[16];
15010         int ret = -ENOTSUP;
15011
15012         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15013                 return;
15014
15015         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15016         if (ret)
15017                 return;
15018
15019 #ifdef RTE_LIBRTE_I40E_PMD
15020         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15021                                               tc_num, bw);
15022 #endif
15023
15024         switch (ret) {
15025         case 0:
15026                 break;
15027         case -EINVAL:
15028                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15029                 break;
15030         case -ENODEV:
15031                 printf("invalid port_id %d\n", res->port_id);
15032                 break;
15033         case -ENOTSUP:
15034                 printf("function not implemented\n");
15035                 break;
15036         default:
15037                 printf("programming error: (%s)\n", strerror(-ret));
15038         }
15039 }
15040
15041 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15042         .f = cmd_vf_tc_min_bw_parsed,
15043         .data = NULL,
15044         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15045                     " <bw1, bw2, ...>",
15046         .tokens = {
15047                 (void *)&cmd_vf_tc_bw_set,
15048                 (void *)&cmd_vf_tc_bw_vf,
15049                 (void *)&cmd_vf_tc_bw_tc,
15050                 (void *)&cmd_vf_tc_bw_tx,
15051                 (void *)&cmd_vf_tc_bw_min_bw,
15052                 (void *)&cmd_vf_tc_bw_port_id,
15053                 (void *)&cmd_vf_tc_bw_vf_id,
15054                 (void *)&cmd_vf_tc_bw_bw_list,
15055                 NULL,
15056         },
15057 };
15058
15059 static void
15060 cmd_tc_min_bw_parsed(
15061         void *parsed_result,
15062         __attribute__((unused)) struct cmdline *cl,
15063         __attribute__((unused)) void *data)
15064 {
15065         struct cmd_vf_tc_bw_result *res = parsed_result;
15066         struct rte_port *port;
15067         uint8_t tc_num;
15068         uint8_t bw[16];
15069         int ret = -ENOTSUP;
15070
15071         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15072                 return;
15073
15074         port = &ports[res->port_id];
15075         /** Check if the port is not started **/
15076         if (port->port_status != RTE_PORT_STOPPED) {
15077                 printf("Please stop port %d first\n", res->port_id);
15078                 return;
15079         }
15080
15081         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15082         if (ret)
15083                 return;
15084
15085 #ifdef RTE_LIBRTE_IXGBE_PMD
15086         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15087 #endif
15088
15089         switch (ret) {
15090         case 0:
15091                 break;
15092         case -EINVAL:
15093                 printf("invalid bandwidth\n");
15094                 break;
15095         case -ENODEV:
15096                 printf("invalid port_id %d\n", res->port_id);
15097                 break;
15098         case -ENOTSUP:
15099                 printf("function not implemented\n");
15100                 break;
15101         default:
15102                 printf("programming error: (%s)\n", strerror(-ret));
15103         }
15104 }
15105
15106 cmdline_parse_inst_t cmd_tc_min_bw = {
15107         .f = cmd_tc_min_bw_parsed,
15108         .data = NULL,
15109         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15110         .tokens = {
15111                 (void *)&cmd_vf_tc_bw_set,
15112                 (void *)&cmd_vf_tc_bw_tc,
15113                 (void *)&cmd_vf_tc_bw_tx,
15114                 (void *)&cmd_vf_tc_bw_min_bw,
15115                 (void *)&cmd_vf_tc_bw_port_id,
15116                 (void *)&cmd_vf_tc_bw_bw_list,
15117                 NULL,
15118         },
15119 };
15120
15121 /* TC max bandwidth setting */
15122 static void
15123 cmd_vf_tc_max_bw_parsed(
15124         void *parsed_result,
15125         __attribute__((unused)) struct cmdline *cl,
15126         __attribute__((unused)) void *data)
15127 {
15128         struct cmd_vf_tc_bw_result *res = parsed_result;
15129         int ret = -ENOTSUP;
15130
15131         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15132                 return;
15133
15134 #ifdef RTE_LIBRTE_I40E_PMD
15135         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15136                                             res->tc_no, res->bw);
15137 #endif
15138
15139         switch (ret) {
15140         case 0:
15141                 break;
15142         case -EINVAL:
15143                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15144                        res->vf_id, res->tc_no, res->bw);
15145                 break;
15146         case -ENODEV:
15147                 printf("invalid port_id %d\n", res->port_id);
15148                 break;
15149         case -ENOTSUP:
15150                 printf("function not implemented\n");
15151                 break;
15152         default:
15153                 printf("programming error: (%s)\n", strerror(-ret));
15154         }
15155 }
15156
15157 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15158         .f = cmd_vf_tc_max_bw_parsed,
15159         .data = NULL,
15160         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15161                     " <bandwidth>",
15162         .tokens = {
15163                 (void *)&cmd_vf_tc_bw_set,
15164                 (void *)&cmd_vf_tc_bw_vf,
15165                 (void *)&cmd_vf_tc_bw_tc,
15166                 (void *)&cmd_vf_tc_bw_tx,
15167                 (void *)&cmd_vf_tc_bw_max_bw,
15168                 (void *)&cmd_vf_tc_bw_port_id,
15169                 (void *)&cmd_vf_tc_bw_vf_id,
15170                 (void *)&cmd_vf_tc_bw_tc_no,
15171                 (void *)&cmd_vf_tc_bw_bw,
15172                 NULL,
15173         },
15174 };
15175
15176
15177 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15178
15179 /* *** Set Port default Traffic Management Hierarchy *** */
15180 struct cmd_set_port_tm_hierarchy_default_result {
15181         cmdline_fixed_string_t set;
15182         cmdline_fixed_string_t port;
15183         cmdline_fixed_string_t tm;
15184         cmdline_fixed_string_t hierarchy;
15185         cmdline_fixed_string_t def;
15186         portid_t port_id;
15187 };
15188
15189 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15190         TOKEN_STRING_INITIALIZER(
15191                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15192 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15193         TOKEN_STRING_INITIALIZER(
15194                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15195 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15196         TOKEN_STRING_INITIALIZER(
15197                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15198 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15199         TOKEN_STRING_INITIALIZER(
15200                 struct cmd_set_port_tm_hierarchy_default_result,
15201                         hierarchy, "hierarchy");
15202 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15203         TOKEN_STRING_INITIALIZER(
15204                 struct cmd_set_port_tm_hierarchy_default_result,
15205                         def, "default");
15206 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15207         TOKEN_NUM_INITIALIZER(
15208                 struct cmd_set_port_tm_hierarchy_default_result,
15209                         port_id, UINT16);
15210
15211 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15212         __attribute__((unused)) struct cmdline *cl,
15213         __attribute__((unused)) void *data)
15214 {
15215         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15216         struct rte_port *p;
15217         portid_t port_id = res->port_id;
15218
15219         if (port_id_is_invalid(port_id, ENABLED_WARN))
15220                 return;
15221
15222         p = &ports[port_id];
15223
15224         /* Forward mode: tm */
15225         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15226                 printf("  softnicfwd mode not enabled(error)\n");
15227                 return;
15228         }
15229
15230         /* Set the default tm hierarchy */
15231         p->softport.default_tm_hierarchy_enable = 1;
15232 }
15233
15234 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15235         .f = cmd_set_port_tm_hierarchy_default_parsed,
15236         .data = NULL,
15237         .help_str = "set port tm hierarchy default <port_id>",
15238         .tokens = {
15239                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15240                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15241                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15242                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15243                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15244                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15245                 NULL,
15246         },
15247 };
15248 #endif
15249
15250 /** Set VXLAN encapsulation details */
15251 struct cmd_set_vxlan_result {
15252         cmdline_fixed_string_t set;
15253         cmdline_fixed_string_t vxlan;
15254         cmdline_fixed_string_t pos_token;
15255         cmdline_fixed_string_t ip_version;
15256         uint32_t vlan_present:1;
15257         uint32_t vni;
15258         uint16_t udp_src;
15259         uint16_t udp_dst;
15260         cmdline_ipaddr_t ip_src;
15261         cmdline_ipaddr_t ip_dst;
15262         uint16_t tci;
15263         uint8_t tos;
15264         uint8_t ttl;
15265         struct rte_ether_addr eth_src;
15266         struct rte_ether_addr eth_dst;
15267 };
15268
15269 cmdline_parse_token_string_t cmd_set_vxlan_set =
15270         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15271 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15272         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15273 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15274         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15275                                  "vxlan-tos-ttl");
15276 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15277         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15278                                  "vxlan-with-vlan");
15279 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15280         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15281                                  "ip-version");
15282 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15283         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15284                                  "ipv4#ipv6");
15285 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15286         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15287                                  "vni");
15288 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15289         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15290 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15291         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15292                                  "udp-src");
15293 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15294         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15295 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15296         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15297                                  "udp-dst");
15298 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15299         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15300 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15301         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15302                                  "ip-tos");
15303 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15304         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15305 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15306         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15307                                  "ip-ttl");
15308 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15309         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15310 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15311         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15312                                  "ip-src");
15313 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15314         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15315 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15316         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15317                                  "ip-dst");
15318 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15319         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15320 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15321         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15322                                  "vlan-tci");
15323 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15324         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15325 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15326         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15327                                  "eth-src");
15328 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15329         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15330 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15331         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15332                                  "eth-dst");
15333 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15334         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15335
15336 static void cmd_set_vxlan_parsed(void *parsed_result,
15337         __attribute__((unused)) struct cmdline *cl,
15338         __attribute__((unused)) void *data)
15339 {
15340         struct cmd_set_vxlan_result *res = parsed_result;
15341         union {
15342                 uint32_t vxlan_id;
15343                 uint8_t vni[4];
15344         } id = {
15345                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15346         };
15347
15348         vxlan_encap_conf.select_tos_ttl = 0;
15349         if (strcmp(res->vxlan, "vxlan") == 0)
15350                 vxlan_encap_conf.select_vlan = 0;
15351         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15352                 vxlan_encap_conf.select_vlan = 1;
15353         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15354                 vxlan_encap_conf.select_vlan = 0;
15355                 vxlan_encap_conf.select_tos_ttl = 1;
15356         }
15357         if (strcmp(res->ip_version, "ipv4") == 0)
15358                 vxlan_encap_conf.select_ipv4 = 1;
15359         else if (strcmp(res->ip_version, "ipv6") == 0)
15360                 vxlan_encap_conf.select_ipv4 = 0;
15361         else
15362                 return;
15363         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15364         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15365         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15366         vxlan_encap_conf.ip_tos = res->tos;
15367         vxlan_encap_conf.ip_ttl = res->ttl;
15368         if (vxlan_encap_conf.select_ipv4) {
15369                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15370                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15371         } else {
15372                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15373                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15374         }
15375         if (vxlan_encap_conf.select_vlan)
15376                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15377         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15378                    RTE_ETHER_ADDR_LEN);
15379         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15380                    RTE_ETHER_ADDR_LEN);
15381 }
15382
15383 cmdline_parse_inst_t cmd_set_vxlan = {
15384         .f = cmd_set_vxlan_parsed,
15385         .data = NULL,
15386         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15387                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15388                 " eth-src <eth-src> eth-dst <eth-dst>",
15389         .tokens = {
15390                 (void *)&cmd_set_vxlan_set,
15391                 (void *)&cmd_set_vxlan_vxlan,
15392                 (void *)&cmd_set_vxlan_ip_version,
15393                 (void *)&cmd_set_vxlan_ip_version_value,
15394                 (void *)&cmd_set_vxlan_vni,
15395                 (void *)&cmd_set_vxlan_vni_value,
15396                 (void *)&cmd_set_vxlan_udp_src,
15397                 (void *)&cmd_set_vxlan_udp_src_value,
15398                 (void *)&cmd_set_vxlan_udp_dst,
15399                 (void *)&cmd_set_vxlan_udp_dst_value,
15400                 (void *)&cmd_set_vxlan_ip_src,
15401                 (void *)&cmd_set_vxlan_ip_src_value,
15402                 (void *)&cmd_set_vxlan_ip_dst,
15403                 (void *)&cmd_set_vxlan_ip_dst_value,
15404                 (void *)&cmd_set_vxlan_eth_src,
15405                 (void *)&cmd_set_vxlan_eth_src_value,
15406                 (void *)&cmd_set_vxlan_eth_dst,
15407                 (void *)&cmd_set_vxlan_eth_dst_value,
15408                 NULL,
15409         },
15410 };
15411
15412 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15413         .f = cmd_set_vxlan_parsed,
15414         .data = NULL,
15415         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15416                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15417                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15418                 " eth-dst <eth-dst>",
15419         .tokens = {
15420                 (void *)&cmd_set_vxlan_set,
15421                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15422                 (void *)&cmd_set_vxlan_ip_version,
15423                 (void *)&cmd_set_vxlan_ip_version_value,
15424                 (void *)&cmd_set_vxlan_vni,
15425                 (void *)&cmd_set_vxlan_vni_value,
15426                 (void *)&cmd_set_vxlan_udp_src,
15427                 (void *)&cmd_set_vxlan_udp_src_value,
15428                 (void *)&cmd_set_vxlan_udp_dst,
15429                 (void *)&cmd_set_vxlan_udp_dst_value,
15430                 (void *)&cmd_set_vxlan_ip_tos,
15431                 (void *)&cmd_set_vxlan_ip_tos_value,
15432                 (void *)&cmd_set_vxlan_ip_ttl,
15433                 (void *)&cmd_set_vxlan_ip_ttl_value,
15434                 (void *)&cmd_set_vxlan_ip_src,
15435                 (void *)&cmd_set_vxlan_ip_src_value,
15436                 (void *)&cmd_set_vxlan_ip_dst,
15437                 (void *)&cmd_set_vxlan_ip_dst_value,
15438                 (void *)&cmd_set_vxlan_eth_src,
15439                 (void *)&cmd_set_vxlan_eth_src_value,
15440                 (void *)&cmd_set_vxlan_eth_dst,
15441                 (void *)&cmd_set_vxlan_eth_dst_value,
15442                 NULL,
15443         },
15444 };
15445
15446 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15447         .f = cmd_set_vxlan_parsed,
15448         .data = NULL,
15449         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15450                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15451                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15452                 " <eth-dst>",
15453         .tokens = {
15454                 (void *)&cmd_set_vxlan_set,
15455                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15456                 (void *)&cmd_set_vxlan_ip_version,
15457                 (void *)&cmd_set_vxlan_ip_version_value,
15458                 (void *)&cmd_set_vxlan_vni,
15459                 (void *)&cmd_set_vxlan_vni_value,
15460                 (void *)&cmd_set_vxlan_udp_src,
15461                 (void *)&cmd_set_vxlan_udp_src_value,
15462                 (void *)&cmd_set_vxlan_udp_dst,
15463                 (void *)&cmd_set_vxlan_udp_dst_value,
15464                 (void *)&cmd_set_vxlan_ip_src,
15465                 (void *)&cmd_set_vxlan_ip_src_value,
15466                 (void *)&cmd_set_vxlan_ip_dst,
15467                 (void *)&cmd_set_vxlan_ip_dst_value,
15468                 (void *)&cmd_set_vxlan_vlan,
15469                 (void *)&cmd_set_vxlan_vlan_value,
15470                 (void *)&cmd_set_vxlan_eth_src,
15471                 (void *)&cmd_set_vxlan_eth_src_value,
15472                 (void *)&cmd_set_vxlan_eth_dst,
15473                 (void *)&cmd_set_vxlan_eth_dst_value,
15474                 NULL,
15475         },
15476 };
15477
15478 /** Set NVGRE encapsulation details */
15479 struct cmd_set_nvgre_result {
15480         cmdline_fixed_string_t set;
15481         cmdline_fixed_string_t nvgre;
15482         cmdline_fixed_string_t pos_token;
15483         cmdline_fixed_string_t ip_version;
15484         uint32_t tni;
15485         cmdline_ipaddr_t ip_src;
15486         cmdline_ipaddr_t ip_dst;
15487         uint16_t tci;
15488         struct rte_ether_addr eth_src;
15489         struct rte_ether_addr eth_dst;
15490 };
15491
15492 cmdline_parse_token_string_t cmd_set_nvgre_set =
15493         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15494 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15495         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15496 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15497         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15498                                  "nvgre-with-vlan");
15499 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15500         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15501                                  "ip-version");
15502 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15503         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15504                                  "ipv4#ipv6");
15505 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15506         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15507                                  "tni");
15508 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15509         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15510 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15511         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15512                                  "ip-src");
15513 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15514         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15515 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15516         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15517                                  "ip-dst");
15518 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15519         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15520 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15521         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15522                                  "vlan-tci");
15523 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15524         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15525 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15526         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15527                                  "eth-src");
15528 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15529         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15530 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15531         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15532                                  "eth-dst");
15533 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15534         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15535
15536 static void cmd_set_nvgre_parsed(void *parsed_result,
15537         __attribute__((unused)) struct cmdline *cl,
15538         __attribute__((unused)) void *data)
15539 {
15540         struct cmd_set_nvgre_result *res = parsed_result;
15541         union {
15542                 uint32_t nvgre_tni;
15543                 uint8_t tni[4];
15544         } id = {
15545                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15546         };
15547
15548         if (strcmp(res->nvgre, "nvgre") == 0)
15549                 nvgre_encap_conf.select_vlan = 0;
15550         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15551                 nvgre_encap_conf.select_vlan = 1;
15552         if (strcmp(res->ip_version, "ipv4") == 0)
15553                 nvgre_encap_conf.select_ipv4 = 1;
15554         else if (strcmp(res->ip_version, "ipv6") == 0)
15555                 nvgre_encap_conf.select_ipv4 = 0;
15556         else
15557                 return;
15558         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15559         if (nvgre_encap_conf.select_ipv4) {
15560                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15561                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15562         } else {
15563                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15564                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15565         }
15566         if (nvgre_encap_conf.select_vlan)
15567                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15568         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15569                    RTE_ETHER_ADDR_LEN);
15570         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15571                    RTE_ETHER_ADDR_LEN);
15572 }
15573
15574 cmdline_parse_inst_t cmd_set_nvgre = {
15575         .f = cmd_set_nvgre_parsed,
15576         .data = NULL,
15577         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15578                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15579                 " eth-dst <eth-dst>",
15580         .tokens = {
15581                 (void *)&cmd_set_nvgre_set,
15582                 (void *)&cmd_set_nvgre_nvgre,
15583                 (void *)&cmd_set_nvgre_ip_version,
15584                 (void *)&cmd_set_nvgre_ip_version_value,
15585                 (void *)&cmd_set_nvgre_tni,
15586                 (void *)&cmd_set_nvgre_tni_value,
15587                 (void *)&cmd_set_nvgre_ip_src,
15588                 (void *)&cmd_set_nvgre_ip_src_value,
15589                 (void *)&cmd_set_nvgre_ip_dst,
15590                 (void *)&cmd_set_nvgre_ip_dst_value,
15591                 (void *)&cmd_set_nvgre_eth_src,
15592                 (void *)&cmd_set_nvgre_eth_src_value,
15593                 (void *)&cmd_set_nvgre_eth_dst,
15594                 (void *)&cmd_set_nvgre_eth_dst_value,
15595                 NULL,
15596         },
15597 };
15598
15599 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15600         .f = cmd_set_nvgre_parsed,
15601         .data = NULL,
15602         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15603                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15604                 " eth-src <eth-src> eth-dst <eth-dst>",
15605         .tokens = {
15606                 (void *)&cmd_set_nvgre_set,
15607                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15608                 (void *)&cmd_set_nvgre_ip_version,
15609                 (void *)&cmd_set_nvgre_ip_version_value,
15610                 (void *)&cmd_set_nvgre_tni,
15611                 (void *)&cmd_set_nvgre_tni_value,
15612                 (void *)&cmd_set_nvgre_ip_src,
15613                 (void *)&cmd_set_nvgre_ip_src_value,
15614                 (void *)&cmd_set_nvgre_ip_dst,
15615                 (void *)&cmd_set_nvgre_ip_dst_value,
15616                 (void *)&cmd_set_nvgre_vlan,
15617                 (void *)&cmd_set_nvgre_vlan_value,
15618                 (void *)&cmd_set_nvgre_eth_src,
15619                 (void *)&cmd_set_nvgre_eth_src_value,
15620                 (void *)&cmd_set_nvgre_eth_dst,
15621                 (void *)&cmd_set_nvgre_eth_dst_value,
15622                 NULL,
15623         },
15624 };
15625
15626 /** Set L2 encapsulation details */
15627 struct cmd_set_l2_encap_result {
15628         cmdline_fixed_string_t set;
15629         cmdline_fixed_string_t l2_encap;
15630         cmdline_fixed_string_t pos_token;
15631         cmdline_fixed_string_t ip_version;
15632         uint32_t vlan_present:1;
15633         uint16_t tci;
15634         struct rte_ether_addr eth_src;
15635         struct rte_ether_addr eth_dst;
15636 };
15637
15638 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15639         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15640 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15641         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15642 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15643         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15644                                  "l2_encap-with-vlan");
15645 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15646         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15647                                  "ip-version");
15648 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15649         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15650                                  "ipv4#ipv6");
15651 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15652         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15653                                  "vlan-tci");
15654 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15655         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15656 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15657         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15658                                  "eth-src");
15659 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15660         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15661 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15662         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15663                                  "eth-dst");
15664 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15665         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15666
15667 static void cmd_set_l2_encap_parsed(void *parsed_result,
15668         __attribute__((unused)) struct cmdline *cl,
15669         __attribute__((unused)) void *data)
15670 {
15671         struct cmd_set_l2_encap_result *res = parsed_result;
15672
15673         if (strcmp(res->l2_encap, "l2_encap") == 0)
15674                 l2_encap_conf.select_vlan = 0;
15675         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15676                 l2_encap_conf.select_vlan = 1;
15677         if (strcmp(res->ip_version, "ipv4") == 0)
15678                 l2_encap_conf.select_ipv4 = 1;
15679         else if (strcmp(res->ip_version, "ipv6") == 0)
15680                 l2_encap_conf.select_ipv4 = 0;
15681         else
15682                 return;
15683         if (l2_encap_conf.select_vlan)
15684                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15685         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15686                    RTE_ETHER_ADDR_LEN);
15687         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15688                    RTE_ETHER_ADDR_LEN);
15689 }
15690
15691 cmdline_parse_inst_t cmd_set_l2_encap = {
15692         .f = cmd_set_l2_encap_parsed,
15693         .data = NULL,
15694         .help_str = "set l2_encap ip-version ipv4|ipv6"
15695                 " eth-src <eth-src> eth-dst <eth-dst>",
15696         .tokens = {
15697                 (void *)&cmd_set_l2_encap_set,
15698                 (void *)&cmd_set_l2_encap_l2_encap,
15699                 (void *)&cmd_set_l2_encap_ip_version,
15700                 (void *)&cmd_set_l2_encap_ip_version_value,
15701                 (void *)&cmd_set_l2_encap_eth_src,
15702                 (void *)&cmd_set_l2_encap_eth_src_value,
15703                 (void *)&cmd_set_l2_encap_eth_dst,
15704                 (void *)&cmd_set_l2_encap_eth_dst_value,
15705                 NULL,
15706         },
15707 };
15708
15709 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15710         .f = cmd_set_l2_encap_parsed,
15711         .data = NULL,
15712         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15713                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15714         .tokens = {
15715                 (void *)&cmd_set_l2_encap_set,
15716                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15717                 (void *)&cmd_set_l2_encap_ip_version,
15718                 (void *)&cmd_set_l2_encap_ip_version_value,
15719                 (void *)&cmd_set_l2_encap_vlan,
15720                 (void *)&cmd_set_l2_encap_vlan_value,
15721                 (void *)&cmd_set_l2_encap_eth_src,
15722                 (void *)&cmd_set_l2_encap_eth_src_value,
15723                 (void *)&cmd_set_l2_encap_eth_dst,
15724                 (void *)&cmd_set_l2_encap_eth_dst_value,
15725                 NULL,
15726         },
15727 };
15728
15729 /** Set L2 decapsulation details */
15730 struct cmd_set_l2_decap_result {
15731         cmdline_fixed_string_t set;
15732         cmdline_fixed_string_t l2_decap;
15733         cmdline_fixed_string_t pos_token;
15734         uint32_t vlan_present:1;
15735 };
15736
15737 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15738         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15739 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15740         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15741                                  "l2_decap");
15742 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15743         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15744                                  "l2_decap-with-vlan");
15745
15746 static void cmd_set_l2_decap_parsed(void *parsed_result,
15747         __attribute__((unused)) struct cmdline *cl,
15748         __attribute__((unused)) void *data)
15749 {
15750         struct cmd_set_l2_decap_result *res = parsed_result;
15751
15752         if (strcmp(res->l2_decap, "l2_decap") == 0)
15753                 l2_decap_conf.select_vlan = 0;
15754         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15755                 l2_decap_conf.select_vlan = 1;
15756 }
15757
15758 cmdline_parse_inst_t cmd_set_l2_decap = {
15759         .f = cmd_set_l2_decap_parsed,
15760         .data = NULL,
15761         .help_str = "set l2_decap",
15762         .tokens = {
15763                 (void *)&cmd_set_l2_decap_set,
15764                 (void *)&cmd_set_l2_decap_l2_decap,
15765                 NULL,
15766         },
15767 };
15768
15769 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15770         .f = cmd_set_l2_decap_parsed,
15771         .data = NULL,
15772         .help_str = "set l2_decap-with-vlan",
15773         .tokens = {
15774                 (void *)&cmd_set_l2_decap_set,
15775                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15776                 NULL,
15777         },
15778 };
15779
15780 /** Set MPLSoGRE encapsulation details */
15781 struct cmd_set_mplsogre_encap_result {
15782         cmdline_fixed_string_t set;
15783         cmdline_fixed_string_t mplsogre;
15784         cmdline_fixed_string_t pos_token;
15785         cmdline_fixed_string_t ip_version;
15786         uint32_t vlan_present:1;
15787         uint32_t label;
15788         cmdline_ipaddr_t ip_src;
15789         cmdline_ipaddr_t ip_dst;
15790         uint16_t tci;
15791         struct rte_ether_addr eth_src;
15792         struct rte_ether_addr eth_dst;
15793 };
15794
15795 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15796         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15797                                  "set");
15798 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15799         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15800                                  "mplsogre_encap");
15801 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15802         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15803                                  mplsogre, "mplsogre_encap-with-vlan");
15804 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15805         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15806                                  pos_token, "ip-version");
15807 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15808         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15809                                  ip_version, "ipv4#ipv6");
15810 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15811         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15812                                  pos_token, "label");
15813 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15814         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15815                               UINT32);
15816 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15817         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15818                                  pos_token, "ip-src");
15819 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15820         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15821 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15822         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15823                                  pos_token, "ip-dst");
15824 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15825         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15826 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15827         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15828                                  pos_token, "vlan-tci");
15829 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15830         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15831                               UINT16);
15832 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15833         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15834                                  pos_token, "eth-src");
15835 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15836         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15837                                     eth_src);
15838 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15839         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15840                                  pos_token, "eth-dst");
15841 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15842         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15843                                     eth_dst);
15844
15845 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15846         __attribute__((unused)) struct cmdline *cl,
15847         __attribute__((unused)) void *data)
15848 {
15849         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15850         union {
15851                 uint32_t mplsogre_label;
15852                 uint8_t label[4];
15853         } id = {
15854                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15855         };
15856
15857         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15858                 mplsogre_encap_conf.select_vlan = 0;
15859         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15860                 mplsogre_encap_conf.select_vlan = 1;
15861         if (strcmp(res->ip_version, "ipv4") == 0)
15862                 mplsogre_encap_conf.select_ipv4 = 1;
15863         else if (strcmp(res->ip_version, "ipv6") == 0)
15864                 mplsogre_encap_conf.select_ipv4 = 0;
15865         else
15866                 return;
15867         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15868         if (mplsogre_encap_conf.select_ipv4) {
15869                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15870                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15871         } else {
15872                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15873                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15874         }
15875         if (mplsogre_encap_conf.select_vlan)
15876                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15877         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15878                    RTE_ETHER_ADDR_LEN);
15879         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15880                    RTE_ETHER_ADDR_LEN);
15881 }
15882
15883 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15884         .f = cmd_set_mplsogre_encap_parsed,
15885         .data = NULL,
15886         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15887                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15888                 " eth-dst <eth-dst>",
15889         .tokens = {
15890                 (void *)&cmd_set_mplsogre_encap_set,
15891                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15892                 (void *)&cmd_set_mplsogre_encap_ip_version,
15893                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15894                 (void *)&cmd_set_mplsogre_encap_label,
15895                 (void *)&cmd_set_mplsogre_encap_label_value,
15896                 (void *)&cmd_set_mplsogre_encap_ip_src,
15897                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15898                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15899                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15900                 (void *)&cmd_set_mplsogre_encap_eth_src,
15901                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15902                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15903                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15904                 NULL,
15905         },
15906 };
15907
15908 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15909         .f = cmd_set_mplsogre_encap_parsed,
15910         .data = NULL,
15911         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15912                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15913                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15914         .tokens = {
15915                 (void *)&cmd_set_mplsogre_encap_set,
15916                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15917                 (void *)&cmd_set_mplsogre_encap_ip_version,
15918                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15919                 (void *)&cmd_set_mplsogre_encap_label,
15920                 (void *)&cmd_set_mplsogre_encap_label_value,
15921                 (void *)&cmd_set_mplsogre_encap_ip_src,
15922                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15923                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15924                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15925                 (void *)&cmd_set_mplsogre_encap_vlan,
15926                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15927                 (void *)&cmd_set_mplsogre_encap_eth_src,
15928                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15929                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15930                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15931                 NULL,
15932         },
15933 };
15934
15935 /** Set MPLSoGRE decapsulation details */
15936 struct cmd_set_mplsogre_decap_result {
15937         cmdline_fixed_string_t set;
15938         cmdline_fixed_string_t mplsogre;
15939         cmdline_fixed_string_t pos_token;
15940         cmdline_fixed_string_t ip_version;
15941         uint32_t vlan_present:1;
15942 };
15943
15944 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15945         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15946                                  "set");
15947 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15948         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15949                                  "mplsogre_decap");
15950 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15951         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15952                                  mplsogre, "mplsogre_decap-with-vlan");
15953 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15954         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15955                                  pos_token, "ip-version");
15956 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15957         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15958                                  ip_version, "ipv4#ipv6");
15959
15960 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15961         __attribute__((unused)) struct cmdline *cl,
15962         __attribute__((unused)) void *data)
15963 {
15964         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15965
15966         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15967                 mplsogre_decap_conf.select_vlan = 0;
15968         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15969                 mplsogre_decap_conf.select_vlan = 1;
15970         if (strcmp(res->ip_version, "ipv4") == 0)
15971                 mplsogre_decap_conf.select_ipv4 = 1;
15972         else if (strcmp(res->ip_version, "ipv6") == 0)
15973                 mplsogre_decap_conf.select_ipv4 = 0;
15974 }
15975
15976 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15977         .f = cmd_set_mplsogre_decap_parsed,
15978         .data = NULL,
15979         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15980         .tokens = {
15981                 (void *)&cmd_set_mplsogre_decap_set,
15982                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15983                 (void *)&cmd_set_mplsogre_decap_ip_version,
15984                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15985                 NULL,
15986         },
15987 };
15988
15989 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15990         .f = cmd_set_mplsogre_decap_parsed,
15991         .data = NULL,
15992         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15993         .tokens = {
15994                 (void *)&cmd_set_mplsogre_decap_set,
15995                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15996                 (void *)&cmd_set_mplsogre_decap_ip_version,
15997                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15998                 NULL,
15999         },
16000 };
16001
16002 /** Set MPLSoUDP encapsulation details */
16003 struct cmd_set_mplsoudp_encap_result {
16004         cmdline_fixed_string_t set;
16005         cmdline_fixed_string_t mplsoudp;
16006         cmdline_fixed_string_t pos_token;
16007         cmdline_fixed_string_t ip_version;
16008         uint32_t vlan_present:1;
16009         uint32_t label;
16010         uint16_t udp_src;
16011         uint16_t udp_dst;
16012         cmdline_ipaddr_t ip_src;
16013         cmdline_ipaddr_t ip_dst;
16014         uint16_t tci;
16015         struct rte_ether_addr eth_src;
16016         struct rte_ether_addr eth_dst;
16017 };
16018
16019 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16020         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16021                                  "set");
16022 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16023         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16024                                  "mplsoudp_encap");
16025 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16026         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16027                                  mplsoudp, "mplsoudp_encap-with-vlan");
16028 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16029         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16030                                  pos_token, "ip-version");
16031 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16032         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16033                                  ip_version, "ipv4#ipv6");
16034 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16035         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16036                                  pos_token, "label");
16037 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16038         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16039                               UINT32);
16040 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16041         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16042                                  pos_token, "udp-src");
16043 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16044         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16045                               UINT16);
16046 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16047         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16048                                  pos_token, "udp-dst");
16049 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16050         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16051                               UINT16);
16052 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16053         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16054                                  pos_token, "ip-src");
16055 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16056         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16057 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16058         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16059                                  pos_token, "ip-dst");
16060 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16061         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16062 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16063         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16064                                  pos_token, "vlan-tci");
16065 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16066         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16067                               UINT16);
16068 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16069         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16070                                  pos_token, "eth-src");
16071 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16072         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16073                                     eth_src);
16074 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16075         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16076                                  pos_token, "eth-dst");
16077 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16078         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16079                                     eth_dst);
16080
16081 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16082         __attribute__((unused)) struct cmdline *cl,
16083         __attribute__((unused)) void *data)
16084 {
16085         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16086         union {
16087                 uint32_t mplsoudp_label;
16088                 uint8_t label[4];
16089         } id = {
16090                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16091         };
16092
16093         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16094                 mplsoudp_encap_conf.select_vlan = 0;
16095         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16096                 mplsoudp_encap_conf.select_vlan = 1;
16097         if (strcmp(res->ip_version, "ipv4") == 0)
16098                 mplsoudp_encap_conf.select_ipv4 = 1;
16099         else if (strcmp(res->ip_version, "ipv6") == 0)
16100                 mplsoudp_encap_conf.select_ipv4 = 0;
16101         else
16102                 return;
16103         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16104         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16105         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16106         if (mplsoudp_encap_conf.select_ipv4) {
16107                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16108                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16109         } else {
16110                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16111                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16112         }
16113         if (mplsoudp_encap_conf.select_vlan)
16114                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16115         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16116                    RTE_ETHER_ADDR_LEN);
16117         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16118                    RTE_ETHER_ADDR_LEN);
16119 }
16120
16121 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16122         .f = cmd_set_mplsoudp_encap_parsed,
16123         .data = NULL,
16124         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16125                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16126                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16127         .tokens = {
16128                 (void *)&cmd_set_mplsoudp_encap_set,
16129                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16130                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16131                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16132                 (void *)&cmd_set_mplsoudp_encap_label,
16133                 (void *)&cmd_set_mplsoudp_encap_label_value,
16134                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16135                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16136                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16137                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16138                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16139                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16140                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16141                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16142                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16143                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16144                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16145                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16146                 NULL,
16147         },
16148 };
16149
16150 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16151         .f = cmd_set_mplsoudp_encap_parsed,
16152         .data = NULL,
16153         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16154                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16155                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16156                 " eth-src <eth-src> eth-dst <eth-dst>",
16157         .tokens = {
16158                 (void *)&cmd_set_mplsoudp_encap_set,
16159                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16160                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16161                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16162                 (void *)&cmd_set_mplsoudp_encap_label,
16163                 (void *)&cmd_set_mplsoudp_encap_label_value,
16164                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16165                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16166                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16167                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16168                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16169                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16170                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16171                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16172                 (void *)&cmd_set_mplsoudp_encap_vlan,
16173                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16174                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16175                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16176                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16177                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16178                 NULL,
16179         },
16180 };
16181
16182 /** Set MPLSoUDP decapsulation details */
16183 struct cmd_set_mplsoudp_decap_result {
16184         cmdline_fixed_string_t set;
16185         cmdline_fixed_string_t mplsoudp;
16186         cmdline_fixed_string_t pos_token;
16187         cmdline_fixed_string_t ip_version;
16188         uint32_t vlan_present:1;
16189 };
16190
16191 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16193                                  "set");
16194 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16195         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16196                                  "mplsoudp_decap");
16197 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16199                                  mplsoudp, "mplsoudp_decap-with-vlan");
16200 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16201         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16202                                  pos_token, "ip-version");
16203 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16204         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16205                                  ip_version, "ipv4#ipv6");
16206
16207 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16208         __attribute__((unused)) struct cmdline *cl,
16209         __attribute__((unused)) void *data)
16210 {
16211         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16212
16213         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16214                 mplsoudp_decap_conf.select_vlan = 0;
16215         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16216                 mplsoudp_decap_conf.select_vlan = 1;
16217         if (strcmp(res->ip_version, "ipv4") == 0)
16218                 mplsoudp_decap_conf.select_ipv4 = 1;
16219         else if (strcmp(res->ip_version, "ipv6") == 0)
16220                 mplsoudp_decap_conf.select_ipv4 = 0;
16221 }
16222
16223 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16224         .f = cmd_set_mplsoudp_decap_parsed,
16225         .data = NULL,
16226         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16227         .tokens = {
16228                 (void *)&cmd_set_mplsoudp_decap_set,
16229                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16230                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16231                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16232                 NULL,
16233         },
16234 };
16235
16236 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16237         .f = cmd_set_mplsoudp_decap_parsed,
16238         .data = NULL,
16239         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16240         .tokens = {
16241                 (void *)&cmd_set_mplsoudp_decap_set,
16242                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16243                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16244                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16245                 NULL,
16246         },
16247 };
16248
16249 /* Strict link priority scheduling mode setting */
16250 static void
16251 cmd_strict_link_prio_parsed(
16252         void *parsed_result,
16253         __attribute__((unused)) struct cmdline *cl,
16254         __attribute__((unused)) void *data)
16255 {
16256         struct cmd_vf_tc_bw_result *res = parsed_result;
16257         int ret = -ENOTSUP;
16258
16259         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16260                 return;
16261
16262 #ifdef RTE_LIBRTE_I40E_PMD
16263         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16264 #endif
16265
16266         switch (ret) {
16267         case 0:
16268                 break;
16269         case -EINVAL:
16270                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16271                 break;
16272         case -ENODEV:
16273                 printf("invalid port_id %d\n", res->port_id);
16274                 break;
16275         case -ENOTSUP:
16276                 printf("function not implemented\n");
16277                 break;
16278         default:
16279                 printf("programming error: (%s)\n", strerror(-ret));
16280         }
16281 }
16282
16283 cmdline_parse_inst_t cmd_strict_link_prio = {
16284         .f = cmd_strict_link_prio_parsed,
16285         .data = NULL,
16286         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16287         .tokens = {
16288                 (void *)&cmd_vf_tc_bw_set,
16289                 (void *)&cmd_vf_tc_bw_tx,
16290                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16291                 (void *)&cmd_vf_tc_bw_port_id,
16292                 (void *)&cmd_vf_tc_bw_tc_map,
16293                 NULL,
16294         },
16295 };
16296
16297 /* Load dynamic device personalization*/
16298 struct cmd_ddp_add_result {
16299         cmdline_fixed_string_t ddp;
16300         cmdline_fixed_string_t add;
16301         portid_t port_id;
16302         char filepath[];
16303 };
16304
16305 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16306         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16307 cmdline_parse_token_string_t cmd_ddp_add_add =
16308         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16309 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16310         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16311 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16312         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16313
16314 static void
16315 cmd_ddp_add_parsed(
16316         void *parsed_result,
16317         __attribute__((unused)) struct cmdline *cl,
16318         __attribute__((unused)) void *data)
16319 {
16320         struct cmd_ddp_add_result *res = parsed_result;
16321         uint8_t *buff;
16322         uint32_t size;
16323         char *filepath;
16324         char *file_fld[2];
16325         int file_num;
16326         int ret = -ENOTSUP;
16327
16328         if (!all_ports_stopped()) {
16329                 printf("Please stop all ports first\n");
16330                 return;
16331         }
16332
16333         filepath = strdup(res->filepath);
16334         if (filepath == NULL) {
16335                 printf("Failed to allocate memory\n");
16336                 return;
16337         }
16338         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16339
16340         buff = open_file(file_fld[0], &size);
16341         if (!buff) {
16342                 free((void *)filepath);
16343                 return;
16344         }
16345
16346 #ifdef RTE_LIBRTE_I40E_PMD
16347         if (ret == -ENOTSUP)
16348                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16349                                                buff, size,
16350                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16351 #endif
16352
16353         if (ret == -EEXIST)
16354                 printf("Profile has already existed.\n");
16355         else if (ret < 0)
16356                 printf("Failed to load profile.\n");
16357         else if (file_num == 2)
16358                 save_file(file_fld[1], buff, size);
16359
16360         close_file(buff);
16361         free((void *)filepath);
16362 }
16363
16364 cmdline_parse_inst_t cmd_ddp_add = {
16365         .f = cmd_ddp_add_parsed,
16366         .data = NULL,
16367         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16368         .tokens = {
16369                 (void *)&cmd_ddp_add_ddp,
16370                 (void *)&cmd_ddp_add_add,
16371                 (void *)&cmd_ddp_add_port_id,
16372                 (void *)&cmd_ddp_add_filepath,
16373                 NULL,
16374         },
16375 };
16376
16377 /* Delete dynamic device personalization*/
16378 struct cmd_ddp_del_result {
16379         cmdline_fixed_string_t ddp;
16380         cmdline_fixed_string_t del;
16381         portid_t port_id;
16382         char filepath[];
16383 };
16384
16385 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16386         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16387 cmdline_parse_token_string_t cmd_ddp_del_del =
16388         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16389 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16390         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16391 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16392         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16393
16394 static void
16395 cmd_ddp_del_parsed(
16396         void *parsed_result,
16397         __attribute__((unused)) struct cmdline *cl,
16398         __attribute__((unused)) void *data)
16399 {
16400         struct cmd_ddp_del_result *res = parsed_result;
16401         uint8_t *buff;
16402         uint32_t size;
16403         int ret = -ENOTSUP;
16404
16405         if (!all_ports_stopped()) {
16406                 printf("Please stop all ports first\n");
16407                 return;
16408         }
16409
16410         buff = open_file(res->filepath, &size);
16411         if (!buff)
16412                 return;
16413
16414 #ifdef RTE_LIBRTE_I40E_PMD
16415         if (ret == -ENOTSUP)
16416                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16417                                                buff, size,
16418                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16419 #endif
16420
16421         if (ret == -EACCES)
16422                 printf("Profile does not exist.\n");
16423         else if (ret < 0)
16424                 printf("Failed to delete profile.\n");
16425
16426         close_file(buff);
16427 }
16428
16429 cmdline_parse_inst_t cmd_ddp_del = {
16430         .f = cmd_ddp_del_parsed,
16431         .data = NULL,
16432         .help_str = "ddp del <port_id> <backup_profile_path>",
16433         .tokens = {
16434                 (void *)&cmd_ddp_del_ddp,
16435                 (void *)&cmd_ddp_del_del,
16436                 (void *)&cmd_ddp_del_port_id,
16437                 (void *)&cmd_ddp_del_filepath,
16438                 NULL,
16439         },
16440 };
16441
16442 /* Get dynamic device personalization profile info */
16443 struct cmd_ddp_info_result {
16444         cmdline_fixed_string_t ddp;
16445         cmdline_fixed_string_t get;
16446         cmdline_fixed_string_t info;
16447         char filepath[];
16448 };
16449
16450 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16451         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16452 cmdline_parse_token_string_t cmd_ddp_info_get =
16453         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16454 cmdline_parse_token_string_t cmd_ddp_info_info =
16455         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16456 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16457         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16458
16459 static void
16460 cmd_ddp_info_parsed(
16461         void *parsed_result,
16462         __attribute__((unused)) struct cmdline *cl,
16463         __attribute__((unused)) void *data)
16464 {
16465         struct cmd_ddp_info_result *res = parsed_result;
16466         uint8_t *pkg;
16467         uint32_t pkg_size;
16468         int ret = -ENOTSUP;
16469 #ifdef RTE_LIBRTE_I40E_PMD
16470         uint32_t i, j, n;
16471         uint8_t *buff;
16472         uint32_t buff_size = 0;
16473         struct rte_pmd_i40e_profile_info info;
16474         uint32_t dev_num = 0;
16475         struct rte_pmd_i40e_ddp_device_id *devs;
16476         uint32_t proto_num = 0;
16477         struct rte_pmd_i40e_proto_info *proto = NULL;
16478         uint32_t pctype_num = 0;
16479         struct rte_pmd_i40e_ptype_info *pctype;
16480         uint32_t ptype_num = 0;
16481         struct rte_pmd_i40e_ptype_info *ptype;
16482         uint8_t proto_id;
16483
16484 #endif
16485
16486         pkg = open_file(res->filepath, &pkg_size);
16487         if (!pkg)
16488                 return;
16489
16490 #ifdef RTE_LIBRTE_I40E_PMD
16491         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16492                                 (uint8_t *)&info, sizeof(info),
16493                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16494         if (!ret) {
16495                 printf("Global Track id:       0x%x\n", info.track_id);
16496                 printf("Global Version:        %d.%d.%d.%d\n",
16497                         info.version.major,
16498                         info.version.minor,
16499                         info.version.update,
16500                         info.version.draft);
16501                 printf("Global Package name:   %s\n\n", info.name);
16502         }
16503
16504         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16505                                 (uint8_t *)&info, sizeof(info),
16506                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16507         if (!ret) {
16508                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16509                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16510                         info.version.major,
16511                         info.version.minor,
16512                         info.version.update,
16513                         info.version.draft);
16514                 printf("i40e Profile name:     %s\n\n", info.name);
16515         }
16516
16517         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16518                                 (uint8_t *)&buff_size, sizeof(buff_size),
16519                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16520         if (!ret && buff_size) {
16521                 buff = (uint8_t *)malloc(buff_size);
16522                 if (buff) {
16523                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16524                                                 buff, buff_size,
16525                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16526                         if (!ret)
16527                                 printf("Package Notes:\n%s\n\n", buff);
16528                         free(buff);
16529                 }
16530         }
16531
16532         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16533                                 (uint8_t *)&dev_num, sizeof(dev_num),
16534                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16535         if (!ret && dev_num) {
16536                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16537                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16538                 if (devs) {
16539                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16540                                                 (uint8_t *)devs, buff_size,
16541                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16542                         if (!ret) {
16543                                 printf("List of supported devices:\n");
16544                                 for (i = 0; i < dev_num; i++) {
16545                                         printf("  %04X:%04X %04X:%04X\n",
16546                                                 devs[i].vendor_dev_id >> 16,
16547                                                 devs[i].vendor_dev_id & 0xFFFF,
16548                                                 devs[i].sub_vendor_dev_id >> 16,
16549                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16550                                 }
16551                                 printf("\n");
16552                         }
16553                         free(devs);
16554                 }
16555         }
16556
16557         /* get information about protocols and packet types */
16558         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16559                 (uint8_t *)&proto_num, sizeof(proto_num),
16560                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16561         if (ret || !proto_num)
16562                 goto no_print_return;
16563
16564         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16565         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16566         if (!proto)
16567                 goto no_print_return;
16568
16569         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16570                                         buff_size,
16571                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16572         if (!ret) {
16573                 printf("List of used protocols:\n");
16574                 for (i = 0; i < proto_num; i++)
16575                         printf("  %2u: %s\n", proto[i].proto_id,
16576                                proto[i].name);
16577                 printf("\n");
16578         }
16579         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16580                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16581                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16582         if (ret || !pctype_num)
16583                 goto no_print_pctypes;
16584
16585         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16586         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16587         if (!pctype)
16588                 goto no_print_pctypes;
16589
16590         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16591                                         buff_size,
16592                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16593         if (ret) {
16594                 free(pctype);
16595                 goto no_print_pctypes;
16596         }
16597
16598         printf("List of defined packet classification types:\n");
16599         for (i = 0; i < pctype_num; i++) {
16600                 printf("  %2u:", pctype[i].ptype_id);
16601                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16602                         proto_id = pctype[i].protocols[j];
16603                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16604                                 for (n = 0; n < proto_num; n++) {
16605                                         if (proto[n].proto_id == proto_id) {
16606                                                 printf(" %s", proto[n].name);
16607                                                 break;
16608                                         }
16609                                 }
16610                         }
16611                 }
16612                 printf("\n");
16613         }
16614         printf("\n");
16615         free(pctype);
16616
16617 no_print_pctypes:
16618
16619         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16620                                         sizeof(ptype_num),
16621                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16622         if (ret || !ptype_num)
16623                 goto no_print_return;
16624
16625         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16626         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16627         if (!ptype)
16628                 goto no_print_return;
16629
16630         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16631                                         buff_size,
16632                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16633         if (ret) {
16634                 free(ptype);
16635                 goto no_print_return;
16636         }
16637         printf("List of defined packet types:\n");
16638         for (i = 0; i < ptype_num; i++) {
16639                 printf("  %2u:", ptype[i].ptype_id);
16640                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16641                         proto_id = ptype[i].protocols[j];
16642                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16643                                 for (n = 0; n < proto_num; n++) {
16644                                         if (proto[n].proto_id == proto_id) {
16645                                                 printf(" %s", proto[n].name);
16646                                                 break;
16647                                         }
16648                                 }
16649                         }
16650                 }
16651                 printf("\n");
16652         }
16653         free(ptype);
16654         printf("\n");
16655
16656         ret = 0;
16657 no_print_return:
16658         if (proto)
16659                 free(proto);
16660 #endif
16661         if (ret == -ENOTSUP)
16662                 printf("Function not supported in PMD driver\n");
16663         close_file(pkg);
16664 }
16665
16666 cmdline_parse_inst_t cmd_ddp_get_info = {
16667         .f = cmd_ddp_info_parsed,
16668         .data = NULL,
16669         .help_str = "ddp get info <profile_path>",
16670         .tokens = {
16671                 (void *)&cmd_ddp_info_ddp,
16672                 (void *)&cmd_ddp_info_get,
16673                 (void *)&cmd_ddp_info_info,
16674                 (void *)&cmd_ddp_info_filepath,
16675                 NULL,
16676         },
16677 };
16678
16679 /* Get dynamic device personalization profile info list*/
16680 #define PROFILE_INFO_SIZE 48
16681 #define MAX_PROFILE_NUM 16
16682
16683 struct cmd_ddp_get_list_result {
16684         cmdline_fixed_string_t ddp;
16685         cmdline_fixed_string_t get;
16686         cmdline_fixed_string_t list;
16687         portid_t port_id;
16688 };
16689
16690 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16691         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16692 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16693         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16694 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16695         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16696 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16697         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16698
16699 static void
16700 cmd_ddp_get_list_parsed(
16701         __attribute__((unused)) void *parsed_result,
16702         __attribute__((unused)) struct cmdline *cl,
16703         __attribute__((unused)) void *data)
16704 {
16705 #ifdef RTE_LIBRTE_I40E_PMD
16706         struct cmd_ddp_get_list_result *res = parsed_result;
16707         struct rte_pmd_i40e_profile_list *p_list;
16708         struct rte_pmd_i40e_profile_info *p_info;
16709         uint32_t p_num;
16710         uint32_t size;
16711         uint32_t i;
16712 #endif
16713         int ret = -ENOTSUP;
16714
16715 #ifdef RTE_LIBRTE_I40E_PMD
16716         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16717         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16718         if (!p_list)
16719                 printf("%s: Failed to malloc buffer\n", __func__);
16720
16721         if (ret == -ENOTSUP)
16722                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16723                                                 (uint8_t *)p_list, size);
16724
16725         if (!ret) {
16726                 p_num = p_list->p_count;
16727                 printf("Profile number is: %d\n\n", p_num);
16728
16729                 for (i = 0; i < p_num; i++) {
16730                         p_info = &p_list->p_info[i];
16731                         printf("Profile %d:\n", i);
16732                         printf("Track id:     0x%x\n", p_info->track_id);
16733                         printf("Version:      %d.%d.%d.%d\n",
16734                                p_info->version.major,
16735                                p_info->version.minor,
16736                                p_info->version.update,
16737                                p_info->version.draft);
16738                         printf("Profile name: %s\n\n", p_info->name);
16739                 }
16740         }
16741
16742         free(p_list);
16743 #endif
16744
16745         if (ret < 0)
16746                 printf("Failed to get ddp list\n");
16747 }
16748
16749 cmdline_parse_inst_t cmd_ddp_get_list = {
16750         .f = cmd_ddp_get_list_parsed,
16751         .data = NULL,
16752         .help_str = "ddp get list <port_id>",
16753         .tokens = {
16754                 (void *)&cmd_ddp_get_list_ddp,
16755                 (void *)&cmd_ddp_get_list_get,
16756                 (void *)&cmd_ddp_get_list_list,
16757                 (void *)&cmd_ddp_get_list_port_id,
16758                 NULL,
16759         },
16760 };
16761
16762 /* Configure input set */
16763 struct cmd_cfg_input_set_result {
16764         cmdline_fixed_string_t port;
16765         cmdline_fixed_string_t cfg;
16766         portid_t port_id;
16767         cmdline_fixed_string_t pctype;
16768         uint8_t pctype_id;
16769         cmdline_fixed_string_t inset_type;
16770         cmdline_fixed_string_t opt;
16771         cmdline_fixed_string_t field;
16772         uint8_t field_idx;
16773 };
16774
16775 static void
16776 cmd_cfg_input_set_parsed(
16777         __attribute__((unused)) void *parsed_result,
16778         __attribute__((unused)) struct cmdline *cl,
16779         __attribute__((unused)) void *data)
16780 {
16781 #ifdef RTE_LIBRTE_I40E_PMD
16782         struct cmd_cfg_input_set_result *res = parsed_result;
16783         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16784         struct rte_pmd_i40e_inset inset;
16785 #endif
16786         int ret = -ENOTSUP;
16787
16788         if (!all_ports_stopped()) {
16789                 printf("Please stop all ports first\n");
16790                 return;
16791         }
16792
16793 #ifdef RTE_LIBRTE_I40E_PMD
16794         if (!strcmp(res->inset_type, "hash_inset"))
16795                 inset_type = INSET_HASH;
16796         else if (!strcmp(res->inset_type, "fdir_inset"))
16797                 inset_type = INSET_FDIR;
16798         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16799                 inset_type = INSET_FDIR_FLX;
16800         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16801                                      &inset, inset_type);
16802         if (ret) {
16803                 printf("Failed to get input set.\n");
16804                 return;
16805         }
16806
16807         if (!strcmp(res->opt, "get")) {
16808                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16809                                                    res->field_idx);
16810                 if (ret)
16811                         printf("Field index %d is enabled.\n", res->field_idx);
16812                 else
16813                         printf("Field index %d is disabled.\n", res->field_idx);
16814                 return;
16815         } else if (!strcmp(res->opt, "set"))
16816                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16817                                                    res->field_idx);
16818         else if (!strcmp(res->opt, "clear"))
16819                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16820                                                      res->field_idx);
16821         if (ret) {
16822                 printf("Failed to configure input set field.\n");
16823                 return;
16824         }
16825
16826         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16827                                      &inset, inset_type);
16828         if (ret) {
16829                 printf("Failed to set input set.\n");
16830                 return;
16831         }
16832 #endif
16833
16834         if (ret == -ENOTSUP)
16835                 printf("Function not supported\n");
16836 }
16837
16838 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16839         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16840                                  port, "port");
16841 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16842         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16843                                  cfg, "config");
16844 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16845         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16846                               port_id, UINT16);
16847 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16848         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16849                                  pctype, "pctype");
16850 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16851         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16852                               pctype_id, UINT8);
16853 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16854         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16855                                  inset_type,
16856                                  "hash_inset#fdir_inset#fdir_flx_inset");
16857 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16858         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16859                                  opt, "get#set#clear");
16860 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16861         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16862                                  field, "field");
16863 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16864         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16865                               field_idx, UINT8);
16866
16867 cmdline_parse_inst_t cmd_cfg_input_set = {
16868         .f = cmd_cfg_input_set_parsed,
16869         .data = NULL,
16870         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16871                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16872         .tokens = {
16873                 (void *)&cmd_cfg_input_set_port,
16874                 (void *)&cmd_cfg_input_set_cfg,
16875                 (void *)&cmd_cfg_input_set_port_id,
16876                 (void *)&cmd_cfg_input_set_pctype,
16877                 (void *)&cmd_cfg_input_set_pctype_id,
16878                 (void *)&cmd_cfg_input_set_inset_type,
16879                 (void *)&cmd_cfg_input_set_opt,
16880                 (void *)&cmd_cfg_input_set_field,
16881                 (void *)&cmd_cfg_input_set_field_idx,
16882                 NULL,
16883         },
16884 };
16885
16886 /* Clear input set */
16887 struct cmd_clear_input_set_result {
16888         cmdline_fixed_string_t port;
16889         cmdline_fixed_string_t cfg;
16890         portid_t port_id;
16891         cmdline_fixed_string_t pctype;
16892         uint8_t pctype_id;
16893         cmdline_fixed_string_t inset_type;
16894         cmdline_fixed_string_t clear;
16895         cmdline_fixed_string_t all;
16896 };
16897
16898 static void
16899 cmd_clear_input_set_parsed(
16900         __attribute__((unused)) void *parsed_result,
16901         __attribute__((unused)) struct cmdline *cl,
16902         __attribute__((unused)) void *data)
16903 {
16904 #ifdef RTE_LIBRTE_I40E_PMD
16905         struct cmd_clear_input_set_result *res = parsed_result;
16906         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16907         struct rte_pmd_i40e_inset inset;
16908 #endif
16909         int ret = -ENOTSUP;
16910
16911         if (!all_ports_stopped()) {
16912                 printf("Please stop all ports first\n");
16913                 return;
16914         }
16915
16916 #ifdef RTE_LIBRTE_I40E_PMD
16917         if (!strcmp(res->inset_type, "hash_inset"))
16918                 inset_type = INSET_HASH;
16919         else if (!strcmp(res->inset_type, "fdir_inset"))
16920                 inset_type = INSET_FDIR;
16921         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16922                 inset_type = INSET_FDIR_FLX;
16923
16924         memset(&inset, 0, sizeof(inset));
16925
16926         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16927                                      &inset, inset_type);
16928         if (ret) {
16929                 printf("Failed to clear input set.\n");
16930                 return;
16931         }
16932
16933 #endif
16934
16935         if (ret == -ENOTSUP)
16936                 printf("Function not supported\n");
16937 }
16938
16939 cmdline_parse_token_string_t cmd_clear_input_set_port =
16940         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16941                                  port, "port");
16942 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16943         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16944                                  cfg, "config");
16945 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16946         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16947                               port_id, UINT16);
16948 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16949         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16950                                  pctype, "pctype");
16951 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16952         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16953                               pctype_id, UINT8);
16954 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16955         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16956                                  inset_type,
16957                                  "hash_inset#fdir_inset#fdir_flx_inset");
16958 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16959         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16960                                  clear, "clear");
16961 cmdline_parse_token_string_t cmd_clear_input_set_all =
16962         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16963                                  all, "all");
16964
16965 cmdline_parse_inst_t cmd_clear_input_set = {
16966         .f = cmd_clear_input_set_parsed,
16967         .data = NULL,
16968         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16969                     "fdir_inset|fdir_flx_inset clear all",
16970         .tokens = {
16971                 (void *)&cmd_clear_input_set_port,
16972                 (void *)&cmd_clear_input_set_cfg,
16973                 (void *)&cmd_clear_input_set_port_id,
16974                 (void *)&cmd_clear_input_set_pctype,
16975                 (void *)&cmd_clear_input_set_pctype_id,
16976                 (void *)&cmd_clear_input_set_inset_type,
16977                 (void *)&cmd_clear_input_set_clear,
16978                 (void *)&cmd_clear_input_set_all,
16979                 NULL,
16980         },
16981 };
16982
16983 /* show vf stats */
16984
16985 /* Common result structure for show vf stats */
16986 struct cmd_show_vf_stats_result {
16987         cmdline_fixed_string_t show;
16988         cmdline_fixed_string_t vf;
16989         cmdline_fixed_string_t stats;
16990         portid_t port_id;
16991         uint16_t vf_id;
16992 };
16993
16994 /* Common CLI fields show vf stats*/
16995 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16996         TOKEN_STRING_INITIALIZER
16997                 (struct cmd_show_vf_stats_result,
16998                  show, "show");
16999 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17000         TOKEN_STRING_INITIALIZER
17001                 (struct cmd_show_vf_stats_result,
17002                  vf, "vf");
17003 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17004         TOKEN_STRING_INITIALIZER
17005                 (struct cmd_show_vf_stats_result,
17006                  stats, "stats");
17007 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17008         TOKEN_NUM_INITIALIZER
17009                 (struct cmd_show_vf_stats_result,
17010                  port_id, UINT16);
17011 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17012         TOKEN_NUM_INITIALIZER
17013                 (struct cmd_show_vf_stats_result,
17014                  vf_id, UINT16);
17015
17016 static void
17017 cmd_show_vf_stats_parsed(
17018         void *parsed_result,
17019         __attribute__((unused)) struct cmdline *cl,
17020         __attribute__((unused)) void *data)
17021 {
17022         struct cmd_show_vf_stats_result *res = parsed_result;
17023         struct rte_eth_stats stats;
17024         int ret = -ENOTSUP;
17025         static const char *nic_stats_border = "########################";
17026
17027         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17028                 return;
17029
17030         memset(&stats, 0, sizeof(stats));
17031
17032 #ifdef RTE_LIBRTE_I40E_PMD
17033         if (ret == -ENOTSUP)
17034                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17035                                                 res->vf_id,
17036                                                 &stats);
17037 #endif
17038 #ifdef RTE_LIBRTE_BNXT_PMD
17039         if (ret == -ENOTSUP)
17040                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17041                                                 res->vf_id,
17042                                                 &stats);
17043 #endif
17044
17045         switch (ret) {
17046         case 0:
17047                 break;
17048         case -EINVAL:
17049                 printf("invalid vf_id %d\n", res->vf_id);
17050                 break;
17051         case -ENODEV:
17052                 printf("invalid port_id %d\n", res->port_id);
17053                 break;
17054         case -ENOTSUP:
17055                 printf("function not implemented\n");
17056                 break;
17057         default:
17058                 printf("programming error: (%s)\n", strerror(-ret));
17059         }
17060
17061         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17062                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17063
17064         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17065                "%-"PRIu64"\n",
17066                stats.ipackets, stats.imissed, stats.ibytes);
17067         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17068         printf("  RX-nombuf:  %-10"PRIu64"\n",
17069                stats.rx_nombuf);
17070         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17071                "%-"PRIu64"\n",
17072                stats.opackets, stats.oerrors, stats.obytes);
17073
17074         printf("  %s############################%s\n",
17075                                nic_stats_border, nic_stats_border);
17076 }
17077
17078 cmdline_parse_inst_t cmd_show_vf_stats = {
17079         .f = cmd_show_vf_stats_parsed,
17080         .data = NULL,
17081         .help_str = "show vf stats <port_id> <vf_id>",
17082         .tokens = {
17083                 (void *)&cmd_show_vf_stats_show,
17084                 (void *)&cmd_show_vf_stats_vf,
17085                 (void *)&cmd_show_vf_stats_stats,
17086                 (void *)&cmd_show_vf_stats_port_id,
17087                 (void *)&cmd_show_vf_stats_vf_id,
17088                 NULL,
17089         },
17090 };
17091
17092 /* clear vf stats */
17093
17094 /* Common result structure for clear vf stats */
17095 struct cmd_clear_vf_stats_result {
17096         cmdline_fixed_string_t clear;
17097         cmdline_fixed_string_t vf;
17098         cmdline_fixed_string_t stats;
17099         portid_t port_id;
17100         uint16_t vf_id;
17101 };
17102
17103 /* Common CLI fields clear vf stats*/
17104 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17105         TOKEN_STRING_INITIALIZER
17106                 (struct cmd_clear_vf_stats_result,
17107                  clear, "clear");
17108 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17109         TOKEN_STRING_INITIALIZER
17110                 (struct cmd_clear_vf_stats_result,
17111                  vf, "vf");
17112 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17113         TOKEN_STRING_INITIALIZER
17114                 (struct cmd_clear_vf_stats_result,
17115                  stats, "stats");
17116 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17117         TOKEN_NUM_INITIALIZER
17118                 (struct cmd_clear_vf_stats_result,
17119                  port_id, UINT16);
17120 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17121         TOKEN_NUM_INITIALIZER
17122                 (struct cmd_clear_vf_stats_result,
17123                  vf_id, UINT16);
17124
17125 static void
17126 cmd_clear_vf_stats_parsed(
17127         void *parsed_result,
17128         __attribute__((unused)) struct cmdline *cl,
17129         __attribute__((unused)) void *data)
17130 {
17131         struct cmd_clear_vf_stats_result *res = parsed_result;
17132         int ret = -ENOTSUP;
17133
17134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17135                 return;
17136
17137 #ifdef RTE_LIBRTE_I40E_PMD
17138         if (ret == -ENOTSUP)
17139                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17140                                                   res->vf_id);
17141 #endif
17142 #ifdef RTE_LIBRTE_BNXT_PMD
17143         if (ret == -ENOTSUP)
17144                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17145                                                   res->vf_id);
17146 #endif
17147
17148         switch (ret) {
17149         case 0:
17150                 break;
17151         case -EINVAL:
17152                 printf("invalid vf_id %d\n", res->vf_id);
17153                 break;
17154         case -ENODEV:
17155                 printf("invalid port_id %d\n", res->port_id);
17156                 break;
17157         case -ENOTSUP:
17158                 printf("function not implemented\n");
17159                 break;
17160         default:
17161                 printf("programming error: (%s)\n", strerror(-ret));
17162         }
17163 }
17164
17165 cmdline_parse_inst_t cmd_clear_vf_stats = {
17166         .f = cmd_clear_vf_stats_parsed,
17167         .data = NULL,
17168         .help_str = "clear vf stats <port_id> <vf_id>",
17169         .tokens = {
17170                 (void *)&cmd_clear_vf_stats_clear,
17171                 (void *)&cmd_clear_vf_stats_vf,
17172                 (void *)&cmd_clear_vf_stats_stats,
17173                 (void *)&cmd_clear_vf_stats_port_id,
17174                 (void *)&cmd_clear_vf_stats_vf_id,
17175                 NULL,
17176         },
17177 };
17178
17179 /* port config pctype mapping reset */
17180
17181 /* Common result structure for port config pctype mapping reset */
17182 struct cmd_pctype_mapping_reset_result {
17183         cmdline_fixed_string_t port;
17184         cmdline_fixed_string_t config;
17185         portid_t port_id;
17186         cmdline_fixed_string_t pctype;
17187         cmdline_fixed_string_t mapping;
17188         cmdline_fixed_string_t reset;
17189 };
17190
17191 /* Common CLI fields for port config pctype mapping reset*/
17192 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17193         TOKEN_STRING_INITIALIZER
17194                 (struct cmd_pctype_mapping_reset_result,
17195                  port, "port");
17196 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17197         TOKEN_STRING_INITIALIZER
17198                 (struct cmd_pctype_mapping_reset_result,
17199                  config, "config");
17200 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17201         TOKEN_NUM_INITIALIZER
17202                 (struct cmd_pctype_mapping_reset_result,
17203                  port_id, UINT16);
17204 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17205         TOKEN_STRING_INITIALIZER
17206                 (struct cmd_pctype_mapping_reset_result,
17207                  pctype, "pctype");
17208 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17209         TOKEN_STRING_INITIALIZER
17210                 (struct cmd_pctype_mapping_reset_result,
17211                  mapping, "mapping");
17212 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17213         TOKEN_STRING_INITIALIZER
17214                 (struct cmd_pctype_mapping_reset_result,
17215                  reset, "reset");
17216
17217 static void
17218 cmd_pctype_mapping_reset_parsed(
17219         void *parsed_result,
17220         __attribute__((unused)) struct cmdline *cl,
17221         __attribute__((unused)) void *data)
17222 {
17223         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17224         int ret = -ENOTSUP;
17225
17226         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17227                 return;
17228
17229 #ifdef RTE_LIBRTE_I40E_PMD
17230         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17231 #endif
17232
17233         switch (ret) {
17234         case 0:
17235                 break;
17236         case -ENODEV:
17237                 printf("invalid port_id %d\n", res->port_id);
17238                 break;
17239         case -ENOTSUP:
17240                 printf("function not implemented\n");
17241                 break;
17242         default:
17243                 printf("programming error: (%s)\n", strerror(-ret));
17244         }
17245 }
17246
17247 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17248         .f = cmd_pctype_mapping_reset_parsed,
17249         .data = NULL,
17250         .help_str = "port config <port_id> pctype mapping reset",
17251         .tokens = {
17252                 (void *)&cmd_pctype_mapping_reset_port,
17253                 (void *)&cmd_pctype_mapping_reset_config,
17254                 (void *)&cmd_pctype_mapping_reset_port_id,
17255                 (void *)&cmd_pctype_mapping_reset_pctype,
17256                 (void *)&cmd_pctype_mapping_reset_mapping,
17257                 (void *)&cmd_pctype_mapping_reset_reset,
17258                 NULL,
17259         },
17260 };
17261
17262 /* show port pctype mapping */
17263
17264 /* Common result structure for show port pctype mapping */
17265 struct cmd_pctype_mapping_get_result {
17266         cmdline_fixed_string_t show;
17267         cmdline_fixed_string_t port;
17268         portid_t port_id;
17269         cmdline_fixed_string_t pctype;
17270         cmdline_fixed_string_t mapping;
17271 };
17272
17273 /* Common CLI fields for pctype mapping get */
17274 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17275         TOKEN_STRING_INITIALIZER
17276                 (struct cmd_pctype_mapping_get_result,
17277                  show, "show");
17278 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17279         TOKEN_STRING_INITIALIZER
17280                 (struct cmd_pctype_mapping_get_result,
17281                  port, "port");
17282 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17283         TOKEN_NUM_INITIALIZER
17284                 (struct cmd_pctype_mapping_get_result,
17285                  port_id, UINT16);
17286 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17287         TOKEN_STRING_INITIALIZER
17288                 (struct cmd_pctype_mapping_get_result,
17289                  pctype, "pctype");
17290 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17291         TOKEN_STRING_INITIALIZER
17292                 (struct cmd_pctype_mapping_get_result,
17293                  mapping, "mapping");
17294
17295 static void
17296 cmd_pctype_mapping_get_parsed(
17297         void *parsed_result,
17298         __attribute__((unused)) struct cmdline *cl,
17299         __attribute__((unused)) void *data)
17300 {
17301         struct cmd_pctype_mapping_get_result *res = parsed_result;
17302         int ret = -ENOTSUP;
17303 #ifdef RTE_LIBRTE_I40E_PMD
17304         struct rte_pmd_i40e_flow_type_mapping
17305                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17306         int i, j, first_pctype;
17307 #endif
17308
17309         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17310                 return;
17311
17312 #ifdef RTE_LIBRTE_I40E_PMD
17313         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17314 #endif
17315
17316         switch (ret) {
17317         case 0:
17318                 break;
17319         case -ENODEV:
17320                 printf("invalid port_id %d\n", res->port_id);
17321                 return;
17322         case -ENOTSUP:
17323                 printf("function not implemented\n");
17324                 return;
17325         default:
17326                 printf("programming error: (%s)\n", strerror(-ret));
17327                 return;
17328         }
17329
17330 #ifdef RTE_LIBRTE_I40E_PMD
17331         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17332                 if (mapping[i].pctype != 0ULL) {
17333                         first_pctype = 1;
17334
17335                         printf("pctype: ");
17336                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17337                                 if (mapping[i].pctype & (1ULL << j)) {
17338                                         printf(first_pctype ?
17339                                                "%02d" : ",%02d", j);
17340                                         first_pctype = 0;
17341                                 }
17342                         }
17343                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17344                 }
17345         }
17346 #endif
17347 }
17348
17349 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17350         .f = cmd_pctype_mapping_get_parsed,
17351         .data = NULL,
17352         .help_str = "show port <port_id> pctype mapping",
17353         .tokens = {
17354                 (void *)&cmd_pctype_mapping_get_show,
17355                 (void *)&cmd_pctype_mapping_get_port,
17356                 (void *)&cmd_pctype_mapping_get_port_id,
17357                 (void *)&cmd_pctype_mapping_get_pctype,
17358                 (void *)&cmd_pctype_mapping_get_mapping,
17359                 NULL,
17360         },
17361 };
17362
17363 /* port config pctype mapping update */
17364
17365 /* Common result structure for port config pctype mapping update */
17366 struct cmd_pctype_mapping_update_result {
17367         cmdline_fixed_string_t port;
17368         cmdline_fixed_string_t config;
17369         portid_t port_id;
17370         cmdline_fixed_string_t pctype;
17371         cmdline_fixed_string_t mapping;
17372         cmdline_fixed_string_t update;
17373         cmdline_fixed_string_t pctype_list;
17374         uint16_t flow_type;
17375 };
17376
17377 /* Common CLI fields for pctype mapping update*/
17378 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17379         TOKEN_STRING_INITIALIZER
17380                 (struct cmd_pctype_mapping_update_result,
17381                  port, "port");
17382 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17383         TOKEN_STRING_INITIALIZER
17384                 (struct cmd_pctype_mapping_update_result,
17385                  config, "config");
17386 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17387         TOKEN_NUM_INITIALIZER
17388                 (struct cmd_pctype_mapping_update_result,
17389                  port_id, UINT16);
17390 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17391         TOKEN_STRING_INITIALIZER
17392                 (struct cmd_pctype_mapping_update_result,
17393                  pctype, "pctype");
17394 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17395         TOKEN_STRING_INITIALIZER
17396                 (struct cmd_pctype_mapping_update_result,
17397                  mapping, "mapping");
17398 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17399         TOKEN_STRING_INITIALIZER
17400                 (struct cmd_pctype_mapping_update_result,
17401                  update, "update");
17402 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17403         TOKEN_STRING_INITIALIZER
17404                 (struct cmd_pctype_mapping_update_result,
17405                  pctype_list, NULL);
17406 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17407         TOKEN_NUM_INITIALIZER
17408                 (struct cmd_pctype_mapping_update_result,
17409                  flow_type, UINT16);
17410
17411 static void
17412 cmd_pctype_mapping_update_parsed(
17413         void *parsed_result,
17414         __attribute__((unused)) struct cmdline *cl,
17415         __attribute__((unused)) void *data)
17416 {
17417         struct cmd_pctype_mapping_update_result *res = parsed_result;
17418         int ret = -ENOTSUP;
17419 #ifdef RTE_LIBRTE_I40E_PMD
17420         struct rte_pmd_i40e_flow_type_mapping mapping;
17421         unsigned int i;
17422         unsigned int nb_item;
17423         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17424 #endif
17425
17426         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17427                 return;
17428
17429 #ifdef RTE_LIBRTE_I40E_PMD
17430         nb_item = parse_item_list(res->pctype_list, "pctypes",
17431                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17432         mapping.flow_type = res->flow_type;
17433         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17434                 mapping.pctype |= (1ULL << pctype_list[i]);
17435         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17436                                                 &mapping,
17437                                                 1,
17438                                                 0);
17439 #endif
17440
17441         switch (ret) {
17442         case 0:
17443                 break;
17444         case -EINVAL:
17445                 printf("invalid pctype or flow type\n");
17446                 break;
17447         case -ENODEV:
17448                 printf("invalid port_id %d\n", res->port_id);
17449                 break;
17450         case -ENOTSUP:
17451                 printf("function not implemented\n");
17452                 break;
17453         default:
17454                 printf("programming error: (%s)\n", strerror(-ret));
17455         }
17456 }
17457
17458 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17459         .f = cmd_pctype_mapping_update_parsed,
17460         .data = NULL,
17461         .help_str = "port config <port_id> pctype mapping update"
17462         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17463         .tokens = {
17464                 (void *)&cmd_pctype_mapping_update_port,
17465                 (void *)&cmd_pctype_mapping_update_config,
17466                 (void *)&cmd_pctype_mapping_update_port_id,
17467                 (void *)&cmd_pctype_mapping_update_pctype,
17468                 (void *)&cmd_pctype_mapping_update_mapping,
17469                 (void *)&cmd_pctype_mapping_update_update,
17470                 (void *)&cmd_pctype_mapping_update_pc_type,
17471                 (void *)&cmd_pctype_mapping_update_flow_type,
17472                 NULL,
17473         },
17474 };
17475
17476 /* ptype mapping get */
17477
17478 /* Common result structure for ptype mapping get */
17479 struct cmd_ptype_mapping_get_result {
17480         cmdline_fixed_string_t ptype;
17481         cmdline_fixed_string_t mapping;
17482         cmdline_fixed_string_t get;
17483         portid_t port_id;
17484         uint8_t valid_only;
17485 };
17486
17487 /* Common CLI fields for ptype mapping get */
17488 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17489         TOKEN_STRING_INITIALIZER
17490                 (struct cmd_ptype_mapping_get_result,
17491                  ptype, "ptype");
17492 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17493         TOKEN_STRING_INITIALIZER
17494                 (struct cmd_ptype_mapping_get_result,
17495                  mapping, "mapping");
17496 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17497         TOKEN_STRING_INITIALIZER
17498                 (struct cmd_ptype_mapping_get_result,
17499                  get, "get");
17500 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17501         TOKEN_NUM_INITIALIZER
17502                 (struct cmd_ptype_mapping_get_result,
17503                  port_id, UINT16);
17504 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17505         TOKEN_NUM_INITIALIZER
17506                 (struct cmd_ptype_mapping_get_result,
17507                  valid_only, UINT8);
17508
17509 static void
17510 cmd_ptype_mapping_get_parsed(
17511         void *parsed_result,
17512         __attribute__((unused)) struct cmdline *cl,
17513         __attribute__((unused)) void *data)
17514 {
17515         struct cmd_ptype_mapping_get_result *res = parsed_result;
17516         int ret = -ENOTSUP;
17517 #ifdef RTE_LIBRTE_I40E_PMD
17518         int max_ptype_num = 256;
17519         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17520         uint16_t count;
17521         int i;
17522 #endif
17523
17524         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17525                 return;
17526
17527 #ifdef RTE_LIBRTE_I40E_PMD
17528         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17529                                         mapping,
17530                                         max_ptype_num,
17531                                         &count,
17532                                         res->valid_only);
17533 #endif
17534
17535         switch (ret) {
17536         case 0:
17537                 break;
17538         case -ENODEV:
17539                 printf("invalid port_id %d\n", res->port_id);
17540                 break;
17541         case -ENOTSUP:
17542                 printf("function not implemented\n");
17543                 break;
17544         default:
17545                 printf("programming error: (%s)\n", strerror(-ret));
17546         }
17547
17548 #ifdef RTE_LIBRTE_I40E_PMD
17549         if (!ret) {
17550                 for (i = 0; i < count; i++)
17551                         printf("%3d\t0x%08x\n",
17552                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17553         }
17554 #endif
17555 }
17556
17557 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17558         .f = cmd_ptype_mapping_get_parsed,
17559         .data = NULL,
17560         .help_str = "ptype mapping get <port_id> <valid_only>",
17561         .tokens = {
17562                 (void *)&cmd_ptype_mapping_get_ptype,
17563                 (void *)&cmd_ptype_mapping_get_mapping,
17564                 (void *)&cmd_ptype_mapping_get_get,
17565                 (void *)&cmd_ptype_mapping_get_port_id,
17566                 (void *)&cmd_ptype_mapping_get_valid_only,
17567                 NULL,
17568         },
17569 };
17570
17571 /* ptype mapping replace */
17572
17573 /* Common result structure for ptype mapping replace */
17574 struct cmd_ptype_mapping_replace_result {
17575         cmdline_fixed_string_t ptype;
17576         cmdline_fixed_string_t mapping;
17577         cmdline_fixed_string_t replace;
17578         portid_t port_id;
17579         uint32_t target;
17580         uint8_t mask;
17581         uint32_t pkt_type;
17582 };
17583
17584 /* Common CLI fields for ptype mapping replace */
17585 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17586         TOKEN_STRING_INITIALIZER
17587                 (struct cmd_ptype_mapping_replace_result,
17588                  ptype, "ptype");
17589 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17590         TOKEN_STRING_INITIALIZER
17591                 (struct cmd_ptype_mapping_replace_result,
17592                  mapping, "mapping");
17593 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17594         TOKEN_STRING_INITIALIZER
17595                 (struct cmd_ptype_mapping_replace_result,
17596                  replace, "replace");
17597 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17598         TOKEN_NUM_INITIALIZER
17599                 (struct cmd_ptype_mapping_replace_result,
17600                  port_id, UINT16);
17601 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17602         TOKEN_NUM_INITIALIZER
17603                 (struct cmd_ptype_mapping_replace_result,
17604                  target, UINT32);
17605 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17606         TOKEN_NUM_INITIALIZER
17607                 (struct cmd_ptype_mapping_replace_result,
17608                  mask, UINT8);
17609 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17610         TOKEN_NUM_INITIALIZER
17611                 (struct cmd_ptype_mapping_replace_result,
17612                  pkt_type, UINT32);
17613
17614 static void
17615 cmd_ptype_mapping_replace_parsed(
17616         void *parsed_result,
17617         __attribute__((unused)) struct cmdline *cl,
17618         __attribute__((unused)) void *data)
17619 {
17620         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17621         int ret = -ENOTSUP;
17622
17623         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17624                 return;
17625
17626 #ifdef RTE_LIBRTE_I40E_PMD
17627         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17628                                         res->target,
17629                                         res->mask,
17630                                         res->pkt_type);
17631 #endif
17632
17633         switch (ret) {
17634         case 0:
17635                 break;
17636         case -EINVAL:
17637                 printf("invalid ptype 0x%8x or 0x%8x\n",
17638                                 res->target, res->pkt_type);
17639                 break;
17640         case -ENODEV:
17641                 printf("invalid port_id %d\n", res->port_id);
17642                 break;
17643         case -ENOTSUP:
17644                 printf("function not implemented\n");
17645                 break;
17646         default:
17647                 printf("programming error: (%s)\n", strerror(-ret));
17648         }
17649 }
17650
17651 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17652         .f = cmd_ptype_mapping_replace_parsed,
17653         .data = NULL,
17654         .help_str =
17655                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17656         .tokens = {
17657                 (void *)&cmd_ptype_mapping_replace_ptype,
17658                 (void *)&cmd_ptype_mapping_replace_mapping,
17659                 (void *)&cmd_ptype_mapping_replace_replace,
17660                 (void *)&cmd_ptype_mapping_replace_port_id,
17661                 (void *)&cmd_ptype_mapping_replace_target,
17662                 (void *)&cmd_ptype_mapping_replace_mask,
17663                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17664                 NULL,
17665         },
17666 };
17667
17668 /* ptype mapping reset */
17669
17670 /* Common result structure for ptype mapping reset */
17671 struct cmd_ptype_mapping_reset_result {
17672         cmdline_fixed_string_t ptype;
17673         cmdline_fixed_string_t mapping;
17674         cmdline_fixed_string_t reset;
17675         portid_t port_id;
17676 };
17677
17678 /* Common CLI fields for ptype mapping reset*/
17679 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17680         TOKEN_STRING_INITIALIZER
17681                 (struct cmd_ptype_mapping_reset_result,
17682                  ptype, "ptype");
17683 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17684         TOKEN_STRING_INITIALIZER
17685                 (struct cmd_ptype_mapping_reset_result,
17686                  mapping, "mapping");
17687 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17688         TOKEN_STRING_INITIALIZER
17689                 (struct cmd_ptype_mapping_reset_result,
17690                  reset, "reset");
17691 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17692         TOKEN_NUM_INITIALIZER
17693                 (struct cmd_ptype_mapping_reset_result,
17694                  port_id, UINT16);
17695
17696 static void
17697 cmd_ptype_mapping_reset_parsed(
17698         void *parsed_result,
17699         __attribute__((unused)) struct cmdline *cl,
17700         __attribute__((unused)) void *data)
17701 {
17702         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17703         int ret = -ENOTSUP;
17704
17705         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17706                 return;
17707
17708 #ifdef RTE_LIBRTE_I40E_PMD
17709         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17710 #endif
17711
17712         switch (ret) {
17713         case 0:
17714                 break;
17715         case -ENODEV:
17716                 printf("invalid port_id %d\n", res->port_id);
17717                 break;
17718         case -ENOTSUP:
17719                 printf("function not implemented\n");
17720                 break;
17721         default:
17722                 printf("programming error: (%s)\n", strerror(-ret));
17723         }
17724 }
17725
17726 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17727         .f = cmd_ptype_mapping_reset_parsed,
17728         .data = NULL,
17729         .help_str = "ptype mapping reset <port_id>",
17730         .tokens = {
17731                 (void *)&cmd_ptype_mapping_reset_ptype,
17732                 (void *)&cmd_ptype_mapping_reset_mapping,
17733                 (void *)&cmd_ptype_mapping_reset_reset,
17734                 (void *)&cmd_ptype_mapping_reset_port_id,
17735                 NULL,
17736         },
17737 };
17738
17739 /* ptype mapping update */
17740
17741 /* Common result structure for ptype mapping update */
17742 struct cmd_ptype_mapping_update_result {
17743         cmdline_fixed_string_t ptype;
17744         cmdline_fixed_string_t mapping;
17745         cmdline_fixed_string_t reset;
17746         portid_t port_id;
17747         uint8_t hw_ptype;
17748         uint32_t sw_ptype;
17749 };
17750
17751 /* Common CLI fields for ptype mapping update*/
17752 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17753         TOKEN_STRING_INITIALIZER
17754                 (struct cmd_ptype_mapping_update_result,
17755                  ptype, "ptype");
17756 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17757         TOKEN_STRING_INITIALIZER
17758                 (struct cmd_ptype_mapping_update_result,
17759                  mapping, "mapping");
17760 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17761         TOKEN_STRING_INITIALIZER
17762                 (struct cmd_ptype_mapping_update_result,
17763                  reset, "update");
17764 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17765         TOKEN_NUM_INITIALIZER
17766                 (struct cmd_ptype_mapping_update_result,
17767                  port_id, UINT16);
17768 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17769         TOKEN_NUM_INITIALIZER
17770                 (struct cmd_ptype_mapping_update_result,
17771                  hw_ptype, UINT8);
17772 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17773         TOKEN_NUM_INITIALIZER
17774                 (struct cmd_ptype_mapping_update_result,
17775                  sw_ptype, UINT32);
17776
17777 static void
17778 cmd_ptype_mapping_update_parsed(
17779         void *parsed_result,
17780         __attribute__((unused)) struct cmdline *cl,
17781         __attribute__((unused)) void *data)
17782 {
17783         struct cmd_ptype_mapping_update_result *res = parsed_result;
17784         int ret = -ENOTSUP;
17785 #ifdef RTE_LIBRTE_I40E_PMD
17786         struct rte_pmd_i40e_ptype_mapping mapping;
17787 #endif
17788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17789                 return;
17790
17791 #ifdef RTE_LIBRTE_I40E_PMD
17792         mapping.hw_ptype = res->hw_ptype;
17793         mapping.sw_ptype = res->sw_ptype;
17794         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17795                                                 &mapping,
17796                                                 1,
17797                                                 0);
17798 #endif
17799
17800         switch (ret) {
17801         case 0:
17802                 break;
17803         case -EINVAL:
17804                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17805                 break;
17806         case -ENODEV:
17807                 printf("invalid port_id %d\n", res->port_id);
17808                 break;
17809         case -ENOTSUP:
17810                 printf("function not implemented\n");
17811                 break;
17812         default:
17813                 printf("programming error: (%s)\n", strerror(-ret));
17814         }
17815 }
17816
17817 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17818         .f = cmd_ptype_mapping_update_parsed,
17819         .data = NULL,
17820         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17821         .tokens = {
17822                 (void *)&cmd_ptype_mapping_update_ptype,
17823                 (void *)&cmd_ptype_mapping_update_mapping,
17824                 (void *)&cmd_ptype_mapping_update_update,
17825                 (void *)&cmd_ptype_mapping_update_port_id,
17826                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17827                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17828                 NULL,
17829         },
17830 };
17831
17832 /* Common result structure for file commands */
17833 struct cmd_cmdfile_result {
17834         cmdline_fixed_string_t load;
17835         cmdline_fixed_string_t filename;
17836 };
17837
17838 /* Common CLI fields for file commands */
17839 cmdline_parse_token_string_t cmd_load_cmdfile =
17840         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17841 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17842         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17843
17844 static void
17845 cmd_load_from_file_parsed(
17846         void *parsed_result,
17847         __attribute__((unused)) struct cmdline *cl,
17848         __attribute__((unused)) void *data)
17849 {
17850         struct cmd_cmdfile_result *res = parsed_result;
17851
17852         cmdline_read_from_file(res->filename);
17853 }
17854
17855 cmdline_parse_inst_t cmd_load_from_file = {
17856         .f = cmd_load_from_file_parsed,
17857         .data = NULL,
17858         .help_str = "load <filename>",
17859         .tokens = {
17860                 (void *)&cmd_load_cmdfile,
17861                 (void *)&cmd_load_cmdfile_filename,
17862                 NULL,
17863         },
17864 };
17865
17866 /* Get Rx offloads capabilities */
17867 struct cmd_rx_offload_get_capa_result {
17868         cmdline_fixed_string_t show;
17869         cmdline_fixed_string_t port;
17870         portid_t port_id;
17871         cmdline_fixed_string_t rx_offload;
17872         cmdline_fixed_string_t capabilities;
17873 };
17874
17875 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17876         TOKEN_STRING_INITIALIZER
17877                 (struct cmd_rx_offload_get_capa_result,
17878                  show, "show");
17879 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17880         TOKEN_STRING_INITIALIZER
17881                 (struct cmd_rx_offload_get_capa_result,
17882                  port, "port");
17883 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17884         TOKEN_NUM_INITIALIZER
17885                 (struct cmd_rx_offload_get_capa_result,
17886                  port_id, UINT16);
17887 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17888         TOKEN_STRING_INITIALIZER
17889                 (struct cmd_rx_offload_get_capa_result,
17890                  rx_offload, "rx_offload");
17891 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17892         TOKEN_STRING_INITIALIZER
17893                 (struct cmd_rx_offload_get_capa_result,
17894                  capabilities, "capabilities");
17895
17896 static void
17897 print_rx_offloads(uint64_t offloads)
17898 {
17899         uint64_t single_offload;
17900         int begin;
17901         int end;
17902         int bit;
17903
17904         if (offloads == 0)
17905                 return;
17906
17907         begin = __builtin_ctzll(offloads);
17908         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17909
17910         single_offload = 1ULL << begin;
17911         for (bit = begin; bit < end; bit++) {
17912                 if (offloads & single_offload)
17913                         printf(" %s",
17914                                rte_eth_dev_rx_offload_name(single_offload));
17915                 single_offload <<= 1;
17916         }
17917 }
17918
17919 static void
17920 cmd_rx_offload_get_capa_parsed(
17921         void *parsed_result,
17922         __attribute__((unused)) struct cmdline *cl,
17923         __attribute__((unused)) void *data)
17924 {
17925         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17926         struct rte_eth_dev_info dev_info;
17927         portid_t port_id = res->port_id;
17928         uint64_t queue_offloads;
17929         uint64_t port_offloads;
17930         int ret;
17931
17932         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17933         if (ret != 0)
17934                 return;
17935
17936         queue_offloads = dev_info.rx_queue_offload_capa;
17937         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17938
17939         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17940         printf("  Per Queue :");
17941         print_rx_offloads(queue_offloads);
17942
17943         printf("\n");
17944         printf("  Per Port  :");
17945         print_rx_offloads(port_offloads);
17946         printf("\n\n");
17947 }
17948
17949 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17950         .f = cmd_rx_offload_get_capa_parsed,
17951         .data = NULL,
17952         .help_str = "show port <port_id> rx_offload capabilities",
17953         .tokens = {
17954                 (void *)&cmd_rx_offload_get_capa_show,
17955                 (void *)&cmd_rx_offload_get_capa_port,
17956                 (void *)&cmd_rx_offload_get_capa_port_id,
17957                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17958                 (void *)&cmd_rx_offload_get_capa_capabilities,
17959                 NULL,
17960         }
17961 };
17962
17963 /* Get Rx offloads configuration */
17964 struct cmd_rx_offload_get_configuration_result {
17965         cmdline_fixed_string_t show;
17966         cmdline_fixed_string_t port;
17967         portid_t port_id;
17968         cmdline_fixed_string_t rx_offload;
17969         cmdline_fixed_string_t configuration;
17970 };
17971
17972 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17973         TOKEN_STRING_INITIALIZER
17974                 (struct cmd_rx_offload_get_configuration_result,
17975                  show, "show");
17976 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17977         TOKEN_STRING_INITIALIZER
17978                 (struct cmd_rx_offload_get_configuration_result,
17979                  port, "port");
17980 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17981         TOKEN_NUM_INITIALIZER
17982                 (struct cmd_rx_offload_get_configuration_result,
17983                  port_id, UINT16);
17984 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17985         TOKEN_STRING_INITIALIZER
17986                 (struct cmd_rx_offload_get_configuration_result,
17987                  rx_offload, "rx_offload");
17988 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17989         TOKEN_STRING_INITIALIZER
17990                 (struct cmd_rx_offload_get_configuration_result,
17991                  configuration, "configuration");
17992
17993 static void
17994 cmd_rx_offload_get_configuration_parsed(
17995         void *parsed_result,
17996         __attribute__((unused)) struct cmdline *cl,
17997         __attribute__((unused)) void *data)
17998 {
17999         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18000         struct rte_eth_dev_info dev_info;
18001         portid_t port_id = res->port_id;
18002         struct rte_port *port = &ports[port_id];
18003         uint64_t port_offloads;
18004         uint64_t queue_offloads;
18005         uint16_t nb_rx_queues;
18006         int q;
18007         int ret;
18008
18009         printf("Rx Offloading Configuration of port %d :\n", port_id);
18010
18011         port_offloads = port->dev_conf.rxmode.offloads;
18012         printf("  Port :");
18013         print_rx_offloads(port_offloads);
18014         printf("\n");
18015
18016         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18017         if (ret != 0)
18018                 return;
18019
18020         nb_rx_queues = dev_info.nb_rx_queues;
18021         for (q = 0; q < nb_rx_queues; q++) {
18022                 queue_offloads = port->rx_conf[q].offloads;
18023                 printf("  Queue[%2d] :", q);
18024                 print_rx_offloads(queue_offloads);
18025                 printf("\n");
18026         }
18027         printf("\n");
18028 }
18029
18030 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18031         .f = cmd_rx_offload_get_configuration_parsed,
18032         .data = NULL,
18033         .help_str = "show port <port_id> rx_offload configuration",
18034         .tokens = {
18035                 (void *)&cmd_rx_offload_get_configuration_show,
18036                 (void *)&cmd_rx_offload_get_configuration_port,
18037                 (void *)&cmd_rx_offload_get_configuration_port_id,
18038                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18039                 (void *)&cmd_rx_offload_get_configuration_configuration,
18040                 NULL,
18041         }
18042 };
18043
18044 /* Enable/Disable a per port offloading */
18045 struct cmd_config_per_port_rx_offload_result {
18046         cmdline_fixed_string_t port;
18047         cmdline_fixed_string_t config;
18048         portid_t port_id;
18049         cmdline_fixed_string_t rx_offload;
18050         cmdline_fixed_string_t offload;
18051         cmdline_fixed_string_t on_off;
18052 };
18053
18054 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18055         TOKEN_STRING_INITIALIZER
18056                 (struct cmd_config_per_port_rx_offload_result,
18057                  port, "port");
18058 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18059         TOKEN_STRING_INITIALIZER
18060                 (struct cmd_config_per_port_rx_offload_result,
18061                  config, "config");
18062 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18063         TOKEN_NUM_INITIALIZER
18064                 (struct cmd_config_per_port_rx_offload_result,
18065                  port_id, UINT16);
18066 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18067         TOKEN_STRING_INITIALIZER
18068                 (struct cmd_config_per_port_rx_offload_result,
18069                  rx_offload, "rx_offload");
18070 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18071         TOKEN_STRING_INITIALIZER
18072                 (struct cmd_config_per_port_rx_offload_result,
18073                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18074                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18075                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18076                            "crc_strip#scatter#timestamp#security#keep_crc");
18077 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18078         TOKEN_STRING_INITIALIZER
18079                 (struct cmd_config_per_port_rx_offload_result,
18080                  on_off, "on#off");
18081
18082 static uint64_t
18083 search_rx_offload(const char *name)
18084 {
18085         uint64_t single_offload;
18086         const char *single_name;
18087         int found = 0;
18088         unsigned int bit;
18089
18090         single_offload = 1;
18091         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18092                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18093                 if (!strcasecmp(single_name, name)) {
18094                         found = 1;
18095                         break;
18096                 }
18097                 single_offload <<= 1;
18098         }
18099
18100         if (found)
18101                 return single_offload;
18102
18103         return 0;
18104 }
18105
18106 static void
18107 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18108                                 __attribute__((unused)) struct cmdline *cl,
18109                                 __attribute__((unused)) void *data)
18110 {
18111         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18112         portid_t port_id = res->port_id;
18113         struct rte_eth_dev_info dev_info;
18114         struct rte_port *port = &ports[port_id];
18115         uint64_t single_offload;
18116         uint16_t nb_rx_queues;
18117         int q;
18118         int ret;
18119
18120         if (port->port_status != RTE_PORT_STOPPED) {
18121                 printf("Error: Can't config offload when Port %d "
18122                        "is not stopped\n", port_id);
18123                 return;
18124         }
18125
18126         single_offload = search_rx_offload(res->offload);
18127         if (single_offload == 0) {
18128                 printf("Unknown offload name: %s\n", res->offload);
18129                 return;
18130         }
18131
18132         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18133         if (ret != 0)
18134                 return;
18135
18136         nb_rx_queues = dev_info.nb_rx_queues;
18137         if (!strcmp(res->on_off, "on")) {
18138                 port->dev_conf.rxmode.offloads |= single_offload;
18139                 for (q = 0; q < nb_rx_queues; q++)
18140                         port->rx_conf[q].offloads |= single_offload;
18141         } else {
18142                 port->dev_conf.rxmode.offloads &= ~single_offload;
18143                 for (q = 0; q < nb_rx_queues; q++)
18144                         port->rx_conf[q].offloads &= ~single_offload;
18145         }
18146
18147         cmd_reconfig_device_queue(port_id, 1, 1);
18148 }
18149
18150 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18151         .f = cmd_config_per_port_rx_offload_parsed,
18152         .data = NULL,
18153         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18154                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18155                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18156                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18157                     "on|off",
18158         .tokens = {
18159                 (void *)&cmd_config_per_port_rx_offload_result_port,
18160                 (void *)&cmd_config_per_port_rx_offload_result_config,
18161                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18162                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18163                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18164                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18165                 NULL,
18166         }
18167 };
18168
18169 /* Enable/Disable a per queue offloading */
18170 struct cmd_config_per_queue_rx_offload_result {
18171         cmdline_fixed_string_t port;
18172         portid_t port_id;
18173         cmdline_fixed_string_t rxq;
18174         uint16_t queue_id;
18175         cmdline_fixed_string_t rx_offload;
18176         cmdline_fixed_string_t offload;
18177         cmdline_fixed_string_t on_off;
18178 };
18179
18180 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18181         TOKEN_STRING_INITIALIZER
18182                 (struct cmd_config_per_queue_rx_offload_result,
18183                  port, "port");
18184 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18185         TOKEN_NUM_INITIALIZER
18186                 (struct cmd_config_per_queue_rx_offload_result,
18187                  port_id, UINT16);
18188 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18189         TOKEN_STRING_INITIALIZER
18190                 (struct cmd_config_per_queue_rx_offload_result,
18191                  rxq, "rxq");
18192 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18193         TOKEN_NUM_INITIALIZER
18194                 (struct cmd_config_per_queue_rx_offload_result,
18195                  queue_id, UINT16);
18196 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18197         TOKEN_STRING_INITIALIZER
18198                 (struct cmd_config_per_queue_rx_offload_result,
18199                  rx_offload, "rx_offload");
18200 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18201         TOKEN_STRING_INITIALIZER
18202                 (struct cmd_config_per_queue_rx_offload_result,
18203                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18204                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18205                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18206                            "crc_strip#scatter#timestamp#security#keep_crc");
18207 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18208         TOKEN_STRING_INITIALIZER
18209                 (struct cmd_config_per_queue_rx_offload_result,
18210                  on_off, "on#off");
18211
18212 static void
18213 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18214                                 __attribute__((unused)) struct cmdline *cl,
18215                                 __attribute__((unused)) void *data)
18216 {
18217         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18218         struct rte_eth_dev_info dev_info;
18219         portid_t port_id = res->port_id;
18220         uint16_t queue_id = res->queue_id;
18221         struct rte_port *port = &ports[port_id];
18222         uint64_t single_offload;
18223         int ret;
18224
18225         if (port->port_status != RTE_PORT_STOPPED) {
18226                 printf("Error: Can't config offload when Port %d "
18227                        "is not stopped\n", port_id);
18228                 return;
18229         }
18230
18231         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18232         if (ret != 0)
18233                 return;
18234
18235         if (queue_id >= dev_info.nb_rx_queues) {
18236                 printf("Error: input queue_id should be 0 ... "
18237                        "%d\n", dev_info.nb_rx_queues - 1);
18238                 return;
18239         }
18240
18241         single_offload = search_rx_offload(res->offload);
18242         if (single_offload == 0) {
18243                 printf("Unknown offload name: %s\n", res->offload);
18244                 return;
18245         }
18246
18247         if (!strcmp(res->on_off, "on"))
18248                 port->rx_conf[queue_id].offloads |= single_offload;
18249         else
18250                 port->rx_conf[queue_id].offloads &= ~single_offload;
18251
18252         cmd_reconfig_device_queue(port_id, 1, 1);
18253 }
18254
18255 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18256         .f = cmd_config_per_queue_rx_offload_parsed,
18257         .data = NULL,
18258         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18259                     "vlan_strip|ipv4_cksum|"
18260                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18261                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18262                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18263                     "on|off",
18264         .tokens = {
18265                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18266                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18267                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18268                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18269                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18270                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18271                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18272                 NULL,
18273         }
18274 };
18275
18276 /* Get Tx offloads capabilities */
18277 struct cmd_tx_offload_get_capa_result {
18278         cmdline_fixed_string_t show;
18279         cmdline_fixed_string_t port;
18280         portid_t port_id;
18281         cmdline_fixed_string_t tx_offload;
18282         cmdline_fixed_string_t capabilities;
18283 };
18284
18285 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18286         TOKEN_STRING_INITIALIZER
18287                 (struct cmd_tx_offload_get_capa_result,
18288                  show, "show");
18289 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18290         TOKEN_STRING_INITIALIZER
18291                 (struct cmd_tx_offload_get_capa_result,
18292                  port, "port");
18293 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18294         TOKEN_NUM_INITIALIZER
18295                 (struct cmd_tx_offload_get_capa_result,
18296                  port_id, UINT16);
18297 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18298         TOKEN_STRING_INITIALIZER
18299                 (struct cmd_tx_offload_get_capa_result,
18300                  tx_offload, "tx_offload");
18301 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18302         TOKEN_STRING_INITIALIZER
18303                 (struct cmd_tx_offload_get_capa_result,
18304                  capabilities, "capabilities");
18305
18306 static void
18307 print_tx_offloads(uint64_t offloads)
18308 {
18309         uint64_t single_offload;
18310         int begin;
18311         int end;
18312         int bit;
18313
18314         if (offloads == 0)
18315                 return;
18316
18317         begin = __builtin_ctzll(offloads);
18318         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18319
18320         single_offload = 1ULL << begin;
18321         for (bit = begin; bit < end; bit++) {
18322                 if (offloads & single_offload)
18323                         printf(" %s",
18324                                rte_eth_dev_tx_offload_name(single_offload));
18325                 single_offload <<= 1;
18326         }
18327 }
18328
18329 static void
18330 cmd_tx_offload_get_capa_parsed(
18331         void *parsed_result,
18332         __attribute__((unused)) struct cmdline *cl,
18333         __attribute__((unused)) void *data)
18334 {
18335         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18336         struct rte_eth_dev_info dev_info;
18337         portid_t port_id = res->port_id;
18338         uint64_t queue_offloads;
18339         uint64_t port_offloads;
18340         int ret;
18341
18342         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18343         if (ret != 0)
18344                 return;
18345
18346         queue_offloads = dev_info.tx_queue_offload_capa;
18347         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18348
18349         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18350         printf("  Per Queue :");
18351         print_tx_offloads(queue_offloads);
18352
18353         printf("\n");
18354         printf("  Per Port  :");
18355         print_tx_offloads(port_offloads);
18356         printf("\n\n");
18357 }
18358
18359 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18360         .f = cmd_tx_offload_get_capa_parsed,
18361         .data = NULL,
18362         .help_str = "show port <port_id> tx_offload capabilities",
18363         .tokens = {
18364                 (void *)&cmd_tx_offload_get_capa_show,
18365                 (void *)&cmd_tx_offload_get_capa_port,
18366                 (void *)&cmd_tx_offload_get_capa_port_id,
18367                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18368                 (void *)&cmd_tx_offload_get_capa_capabilities,
18369                 NULL,
18370         }
18371 };
18372
18373 /* Get Tx offloads configuration */
18374 struct cmd_tx_offload_get_configuration_result {
18375         cmdline_fixed_string_t show;
18376         cmdline_fixed_string_t port;
18377         portid_t port_id;
18378         cmdline_fixed_string_t tx_offload;
18379         cmdline_fixed_string_t configuration;
18380 };
18381
18382 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18383         TOKEN_STRING_INITIALIZER
18384                 (struct cmd_tx_offload_get_configuration_result,
18385                  show, "show");
18386 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18387         TOKEN_STRING_INITIALIZER
18388                 (struct cmd_tx_offload_get_configuration_result,
18389                  port, "port");
18390 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18391         TOKEN_NUM_INITIALIZER
18392                 (struct cmd_tx_offload_get_configuration_result,
18393                  port_id, UINT16);
18394 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18395         TOKEN_STRING_INITIALIZER
18396                 (struct cmd_tx_offload_get_configuration_result,
18397                  tx_offload, "tx_offload");
18398 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18399         TOKEN_STRING_INITIALIZER
18400                 (struct cmd_tx_offload_get_configuration_result,
18401                  configuration, "configuration");
18402
18403 static void
18404 cmd_tx_offload_get_configuration_parsed(
18405         void *parsed_result,
18406         __attribute__((unused)) struct cmdline *cl,
18407         __attribute__((unused)) void *data)
18408 {
18409         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18410         struct rte_eth_dev_info dev_info;
18411         portid_t port_id = res->port_id;
18412         struct rte_port *port = &ports[port_id];
18413         uint64_t port_offloads;
18414         uint64_t queue_offloads;
18415         uint16_t nb_tx_queues;
18416         int q;
18417         int ret;
18418
18419         printf("Tx Offloading Configuration of port %d :\n", port_id);
18420
18421         port_offloads = port->dev_conf.txmode.offloads;
18422         printf("  Port :");
18423         print_tx_offloads(port_offloads);
18424         printf("\n");
18425
18426         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18427         if (ret != 0)
18428                 return;
18429
18430         nb_tx_queues = dev_info.nb_tx_queues;
18431         for (q = 0; q < nb_tx_queues; q++) {
18432                 queue_offloads = port->tx_conf[q].offloads;
18433                 printf("  Queue[%2d] :", q);
18434                 print_tx_offloads(queue_offloads);
18435                 printf("\n");
18436         }
18437         printf("\n");
18438 }
18439
18440 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18441         .f = cmd_tx_offload_get_configuration_parsed,
18442         .data = NULL,
18443         .help_str = "show port <port_id> tx_offload configuration",
18444         .tokens = {
18445                 (void *)&cmd_tx_offload_get_configuration_show,
18446                 (void *)&cmd_tx_offload_get_configuration_port,
18447                 (void *)&cmd_tx_offload_get_configuration_port_id,
18448                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18449                 (void *)&cmd_tx_offload_get_configuration_configuration,
18450                 NULL,
18451         }
18452 };
18453
18454 /* Enable/Disable a per port offloading */
18455 struct cmd_config_per_port_tx_offload_result {
18456         cmdline_fixed_string_t port;
18457         cmdline_fixed_string_t config;
18458         portid_t port_id;
18459         cmdline_fixed_string_t tx_offload;
18460         cmdline_fixed_string_t offload;
18461         cmdline_fixed_string_t on_off;
18462 };
18463
18464 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18465         TOKEN_STRING_INITIALIZER
18466                 (struct cmd_config_per_port_tx_offload_result,
18467                  port, "port");
18468 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18469         TOKEN_STRING_INITIALIZER
18470                 (struct cmd_config_per_port_tx_offload_result,
18471                  config, "config");
18472 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18473         TOKEN_NUM_INITIALIZER
18474                 (struct cmd_config_per_port_tx_offload_result,
18475                  port_id, UINT16);
18476 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18477         TOKEN_STRING_INITIALIZER
18478                 (struct cmd_config_per_port_tx_offload_result,
18479                  tx_offload, "tx_offload");
18480 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18481         TOKEN_STRING_INITIALIZER
18482                 (struct cmd_config_per_port_tx_offload_result,
18483                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18484                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18485                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18486                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18487                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18488                           "match_metadata");
18489 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18490         TOKEN_STRING_INITIALIZER
18491                 (struct cmd_config_per_port_tx_offload_result,
18492                  on_off, "on#off");
18493
18494 static uint64_t
18495 search_tx_offload(const char *name)
18496 {
18497         uint64_t single_offload;
18498         const char *single_name;
18499         int found = 0;
18500         unsigned int bit;
18501
18502         single_offload = 1;
18503         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18504                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18505                 if (single_name == NULL)
18506                         break;
18507                 if (!strcasecmp(single_name, name)) {
18508                         found = 1;
18509                         break;
18510                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18511                         break;
18512                 single_offload <<= 1;
18513         }
18514
18515         if (found)
18516                 return single_offload;
18517
18518         return 0;
18519 }
18520
18521 static void
18522 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18523                                 __attribute__((unused)) struct cmdline *cl,
18524                                 __attribute__((unused)) void *data)
18525 {
18526         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18527         portid_t port_id = res->port_id;
18528         struct rte_eth_dev_info dev_info;
18529         struct rte_port *port = &ports[port_id];
18530         uint64_t single_offload;
18531         uint16_t nb_tx_queues;
18532         int q;
18533         int ret;
18534
18535         if (port->port_status != RTE_PORT_STOPPED) {
18536                 printf("Error: Can't config offload when Port %d "
18537                        "is not stopped\n", port_id);
18538                 return;
18539         }
18540
18541         single_offload = search_tx_offload(res->offload);
18542         if (single_offload == 0) {
18543                 printf("Unknown offload name: %s\n", res->offload);
18544                 return;
18545         }
18546
18547         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18548         if (ret != 0)
18549                 return;
18550
18551         nb_tx_queues = dev_info.nb_tx_queues;
18552         if (!strcmp(res->on_off, "on")) {
18553                 port->dev_conf.txmode.offloads |= single_offload;
18554                 for (q = 0; q < nb_tx_queues; q++)
18555                         port->tx_conf[q].offloads |= single_offload;
18556         } else {
18557                 port->dev_conf.txmode.offloads &= ~single_offload;
18558                 for (q = 0; q < nb_tx_queues; q++)
18559                         port->tx_conf[q].offloads &= ~single_offload;
18560         }
18561
18562         cmd_reconfig_device_queue(port_id, 1, 1);
18563 }
18564
18565 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18566         .f = cmd_config_per_port_tx_offload_parsed,
18567         .data = NULL,
18568         .help_str = "port config <port_id> tx_offload "
18569                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18570                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18571                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18572                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18573                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18574                     "match_metadata on|off",
18575         .tokens = {
18576                 (void *)&cmd_config_per_port_tx_offload_result_port,
18577                 (void *)&cmd_config_per_port_tx_offload_result_config,
18578                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18579                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18580                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18581                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18582                 NULL,
18583         }
18584 };
18585
18586 /* Enable/Disable a per queue offloading */
18587 struct cmd_config_per_queue_tx_offload_result {
18588         cmdline_fixed_string_t port;
18589         portid_t port_id;
18590         cmdline_fixed_string_t txq;
18591         uint16_t queue_id;
18592         cmdline_fixed_string_t tx_offload;
18593         cmdline_fixed_string_t offload;
18594         cmdline_fixed_string_t on_off;
18595 };
18596
18597 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18598         TOKEN_STRING_INITIALIZER
18599                 (struct cmd_config_per_queue_tx_offload_result,
18600                  port, "port");
18601 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18602         TOKEN_NUM_INITIALIZER
18603                 (struct cmd_config_per_queue_tx_offload_result,
18604                  port_id, UINT16);
18605 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18606         TOKEN_STRING_INITIALIZER
18607                 (struct cmd_config_per_queue_tx_offload_result,
18608                  txq, "txq");
18609 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18610         TOKEN_NUM_INITIALIZER
18611                 (struct cmd_config_per_queue_tx_offload_result,
18612                  queue_id, UINT16);
18613 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18614         TOKEN_STRING_INITIALIZER
18615                 (struct cmd_config_per_queue_tx_offload_result,
18616                  tx_offload, "tx_offload");
18617 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18618         TOKEN_STRING_INITIALIZER
18619                 (struct cmd_config_per_queue_tx_offload_result,
18620                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18621                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18622                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18623                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18624                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18625 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18626         TOKEN_STRING_INITIALIZER
18627                 (struct cmd_config_per_queue_tx_offload_result,
18628                  on_off, "on#off");
18629
18630 static void
18631 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18632                                 __attribute__((unused)) struct cmdline *cl,
18633                                 __attribute__((unused)) void *data)
18634 {
18635         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18636         struct rte_eth_dev_info dev_info;
18637         portid_t port_id = res->port_id;
18638         uint16_t queue_id = res->queue_id;
18639         struct rte_port *port = &ports[port_id];
18640         uint64_t single_offload;
18641         int ret;
18642
18643         if (port->port_status != RTE_PORT_STOPPED) {
18644                 printf("Error: Can't config offload when Port %d "
18645                        "is not stopped\n", port_id);
18646                 return;
18647         }
18648
18649         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18650         if (ret != 0)
18651                 return;
18652
18653         if (queue_id >= dev_info.nb_tx_queues) {
18654                 printf("Error: input queue_id should be 0 ... "
18655                        "%d\n", dev_info.nb_tx_queues - 1);
18656                 return;
18657         }
18658
18659         single_offload = search_tx_offload(res->offload);
18660         if (single_offload == 0) {
18661                 printf("Unknown offload name: %s\n", res->offload);
18662                 return;
18663         }
18664
18665         if (!strcmp(res->on_off, "on"))
18666                 port->tx_conf[queue_id].offloads |= single_offload;
18667         else
18668                 port->tx_conf[queue_id].offloads &= ~single_offload;
18669
18670         cmd_reconfig_device_queue(port_id, 1, 1);
18671 }
18672
18673 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18674         .f = cmd_config_per_queue_tx_offload_parsed,
18675         .data = NULL,
18676         .help_str = "port <port_id> txq <queue_id> tx_offload "
18677                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18678                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18679                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18680                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18681                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18682                     "on|off",
18683         .tokens = {
18684                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18685                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18686                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18687                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18688                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18689                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18690                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18691                 NULL,
18692         }
18693 };
18694
18695 /* *** configure tx_metadata for specific port *** */
18696 struct cmd_config_tx_metadata_specific_result {
18697         cmdline_fixed_string_t port;
18698         cmdline_fixed_string_t keyword;
18699         uint16_t port_id;
18700         cmdline_fixed_string_t item;
18701         uint32_t value;
18702 };
18703
18704 static void
18705 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18706                                 __attribute__((unused)) struct cmdline *cl,
18707                                 __attribute__((unused)) void *data)
18708 {
18709         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18710
18711         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18712                 return;
18713         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18714         /* Add/remove callback to insert valid metadata in every Tx packet. */
18715         if (ports[res->port_id].tx_metadata)
18716                 add_tx_md_callback(res->port_id);
18717         else
18718                 remove_tx_md_callback(res->port_id);
18719 }
18720
18721 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18722         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18723                         port, "port");
18724 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18725         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18726                         keyword, "config");
18727 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18728         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18729                         port_id, UINT16);
18730 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18731         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18732                         item, "tx_metadata");
18733 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18734         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18735                         value, UINT32);
18736
18737 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18738         .f = cmd_config_tx_metadata_specific_parsed,
18739         .data = NULL,
18740         .help_str = "port config <port_id> tx_metadata <value>",
18741         .tokens = {
18742                 (void *)&cmd_config_tx_metadata_specific_port,
18743                 (void *)&cmd_config_tx_metadata_specific_keyword,
18744                 (void *)&cmd_config_tx_metadata_specific_id,
18745                 (void *)&cmd_config_tx_metadata_specific_item,
18746                 (void *)&cmd_config_tx_metadata_specific_value,
18747                 NULL,
18748         },
18749 };
18750
18751 /* *** display tx_metadata per port configuration *** */
18752 struct cmd_show_tx_metadata_result {
18753         cmdline_fixed_string_t cmd_show;
18754         cmdline_fixed_string_t cmd_port;
18755         cmdline_fixed_string_t cmd_keyword;
18756         portid_t cmd_pid;
18757 };
18758
18759 static void
18760 cmd_show_tx_metadata_parsed(void *parsed_result,
18761                 __attribute__((unused)) struct cmdline *cl,
18762                 __attribute__((unused)) void *data)
18763 {
18764         struct cmd_show_tx_metadata_result *res = parsed_result;
18765
18766         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18767                 printf("invalid port id %u\n", res->cmd_pid);
18768                 return;
18769         }
18770         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18771                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18772                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18773         }
18774 }
18775
18776 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18777         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18778                         cmd_show, "show");
18779 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18780         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18781                         cmd_port, "port");
18782 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18783         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18784                         cmd_pid, UINT16);
18785 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18786         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18787                         cmd_keyword, "tx_metadata");
18788
18789 cmdline_parse_inst_t cmd_show_tx_metadata = {
18790         .f = cmd_show_tx_metadata_parsed,
18791         .data = NULL,
18792         .help_str = "show port <port_id> tx_metadata",
18793         .tokens = {
18794                 (void *)&cmd_show_tx_metadata_show,
18795                 (void *)&cmd_show_tx_metadata_port,
18796                 (void *)&cmd_show_tx_metadata_pid,
18797                 (void *)&cmd_show_tx_metadata_keyword,
18798                 NULL,
18799         },
18800 };
18801
18802 /* ******************************************************************************** */
18803
18804 /* list of instructions */
18805 cmdline_parse_ctx_t main_ctx[] = {
18806         (cmdline_parse_inst_t *)&cmd_help_brief,
18807         (cmdline_parse_inst_t *)&cmd_help_long,
18808         (cmdline_parse_inst_t *)&cmd_quit,
18809         (cmdline_parse_inst_t *)&cmd_load_from_file,
18810         (cmdline_parse_inst_t *)&cmd_showport,
18811         (cmdline_parse_inst_t *)&cmd_showqueue,
18812         (cmdline_parse_inst_t *)&cmd_showportall,
18813         (cmdline_parse_inst_t *)&cmd_showdevice,
18814         (cmdline_parse_inst_t *)&cmd_showcfg,
18815         (cmdline_parse_inst_t *)&cmd_showfwdall,
18816         (cmdline_parse_inst_t *)&cmd_start,
18817         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18818         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18819         (cmdline_parse_inst_t *)&cmd_set_link_up,
18820         (cmdline_parse_inst_t *)&cmd_set_link_down,
18821         (cmdline_parse_inst_t *)&cmd_reset,
18822         (cmdline_parse_inst_t *)&cmd_set_numbers,
18823         (cmdline_parse_inst_t *)&cmd_set_log,
18824         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18825         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18826         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18827         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18828         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18829         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18830         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18831         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18832         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18833         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18834         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18835         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18836         (cmdline_parse_inst_t *)&cmd_set_link_check,
18837         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18838         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18839         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18840         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18841 #ifdef RTE_LIBRTE_PMD_BOND
18842         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18843         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18844         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18845         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18846         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18847         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18848         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18849         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18850         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18851         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18852         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18853 #endif
18854         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18855         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18856         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18857         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18858         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18859         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18860         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18861         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18862         (cmdline_parse_inst_t *)&cmd_csum_set,
18863         (cmdline_parse_inst_t *)&cmd_csum_show,
18864         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18865         (cmdline_parse_inst_t *)&cmd_tso_set,
18866         (cmdline_parse_inst_t *)&cmd_tso_show,
18867         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18868         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18869         (cmdline_parse_inst_t *)&cmd_gro_enable,
18870         (cmdline_parse_inst_t *)&cmd_gro_flush,
18871         (cmdline_parse_inst_t *)&cmd_gro_show,
18872         (cmdline_parse_inst_t *)&cmd_gso_enable,
18873         (cmdline_parse_inst_t *)&cmd_gso_size,
18874         (cmdline_parse_inst_t *)&cmd_gso_show,
18875         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18876         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18877         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18878         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18879         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18880         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18881         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18882         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18883         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18884         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18885         (cmdline_parse_inst_t *)&cmd_config_dcb,
18886         (cmdline_parse_inst_t *)&cmd_read_reg,
18887         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18888         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18889         (cmdline_parse_inst_t *)&cmd_write_reg,
18890         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18891         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18892         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18893         (cmdline_parse_inst_t *)&cmd_stop,
18894         (cmdline_parse_inst_t *)&cmd_mac_addr,
18895         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18896         (cmdline_parse_inst_t *)&cmd_set_qmap,
18897         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18898         (cmdline_parse_inst_t *)&cmd_operate_port,
18899         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18900         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18901         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18902         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18903         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18904         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18905         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18906         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18907         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18908         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18909         (cmdline_parse_inst_t *)&cmd_config_mtu,
18910         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18911         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18912         (cmdline_parse_inst_t *)&cmd_config_rss,
18913         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18914         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18915         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18916         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18917         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18918         (cmdline_parse_inst_t *)&cmd_showport_reta,
18919         (cmdline_parse_inst_t *)&cmd_config_burst,
18920         (cmdline_parse_inst_t *)&cmd_config_thresh,
18921         (cmdline_parse_inst_t *)&cmd_config_threshold,
18922         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18923         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18924         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18925         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18926         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18927         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18928         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18929         (cmdline_parse_inst_t *)&cmd_global_config,
18930         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18931         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18932         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18933         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18934         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18935         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18936         (cmdline_parse_inst_t *)&cmd_dump,
18937         (cmdline_parse_inst_t *)&cmd_dump_one,
18938         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18939         (cmdline_parse_inst_t *)&cmd_syn_filter,
18940         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18941         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18942         (cmdline_parse_inst_t *)&cmd_flex_filter,
18943         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18944         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18945         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18946         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18947         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18948         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18949         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18950         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18951         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18952         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18953         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18954         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18955         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18956         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18957         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18958         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18959         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18960         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18961         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18962         (cmdline_parse_inst_t *)&cmd_flow,
18963         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18964         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18965         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18966         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18967         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18968         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18969         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18970         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18971         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18972         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18973         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18974         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18975         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18976         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18977         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18978         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18979         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18980         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18981         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18982         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18983         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18984         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18985         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18986         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18987         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18988         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18989         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18990         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18991         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18992         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18993         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18994         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18995         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18996         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18997         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18998         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18999         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19000         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19001         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19002         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19003         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19004         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19005         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19006         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19007         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19008         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19009         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19010         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19011         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19012 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19013         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19014 #endif
19015         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19016         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19017         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19018         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19019         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19020         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19021         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19022         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19023         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19024         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19025         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19026         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19027         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19028         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19029         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19030         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19031         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19032         (cmdline_parse_inst_t *)&cmd_ddp_add,
19033         (cmdline_parse_inst_t *)&cmd_ddp_del,
19034         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19035         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19036         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19037         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19038         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19039         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19040         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19041         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19042         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19043         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19044
19045         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19046         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19047         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19048         (cmdline_parse_inst_t *)&cmd_queue_region,
19049         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19050         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19051         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19052         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19053         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19054         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19055         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19056         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19057         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19058         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19059         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19060         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19061         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19062         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19063         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19064         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19065         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19066         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19067         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19068         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19069         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19070         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19071         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19072         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19073         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19074         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19075         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19076         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19077         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19078         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19079         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19080         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19081         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19082         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19083         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19084 #ifdef RTE_LIBRTE_BPF
19085         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19086         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19087 #endif
19088         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19089         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19090         (cmdline_parse_inst_t *)&cmd_set_raw,
19091         NULL,
19092 };
19093
19094 /* read cmdline commands from file */
19095 void
19096 cmdline_read_from_file(const char *filename)
19097 {
19098         struct cmdline *cl;
19099
19100         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19101         if (cl == NULL) {
19102                 printf("Failed to create file based cmdline context: %s\n",
19103                        filename);
19104                 return;
19105         }
19106
19107         cmdline_interact(cl);
19108         cmdline_quit(cl);
19109
19110         cmdline_free(cl);
19111
19112         printf("Read CLI commands from %s\n", filename);
19113 }
19114
19115 /* prompt function, called from main on MASTER lcore */
19116 void
19117 prompt(void)
19118 {
19119         /* initialize non-constant commands */
19120         cmd_set_fwd_mode_init();
19121         cmd_set_fwd_retry_mode_init();
19122
19123         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19124         if (testpmd_cl == NULL)
19125                 return;
19126         cmdline_interact(testpmd_cl);
19127         cmdline_stdin_exit(testpmd_cl);
19128 }
19129
19130 void
19131 prompt_exit(void)
19132 {
19133         if (testpmd_cl != NULL)
19134                 cmdline_quit(testpmd_cl);
19135 }
19136
19137 static void
19138 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19139 {
19140         if (id == (portid_t)RTE_PORT_ALL) {
19141                 portid_t pid;
19142
19143                 RTE_ETH_FOREACH_DEV(pid) {
19144                         /* check if need_reconfig has been set to 1 */
19145                         if (ports[pid].need_reconfig == 0)
19146                                 ports[pid].need_reconfig = dev;
19147                         /* check if need_reconfig_queues has been set to 1 */
19148                         if (ports[pid].need_reconfig_queues == 0)
19149                                 ports[pid].need_reconfig_queues = queue;
19150                 }
19151         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19152                 /* check if need_reconfig has been set to 1 */
19153                 if (ports[id].need_reconfig == 0)
19154                         ports[id].need_reconfig = dev;
19155                 /* check if need_reconfig_queues has been set to 1 */
19156                 if (ports[id].need_reconfig_queues == 0)
19157                         ports[id].need_reconfig_queues = queue;
19158         }
19159 }