app/testpmd: add NVGRE encap/decap
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_PMD_SOFTNIC
73 #include <rte_eth_softnic.h>
74 #endif
75 #ifdef RTE_LIBRTE_BNXT_PMD
76 #include <rte_pmd_bnxt.h>
77 #endif
78 #include "testpmd.h"
79 #include "cmdline_mtr.h"
80 #include "cmdline_tm.h"
81 #include "bpf_cmd.h"
82
83 static struct cmdline *testpmd_cl;
84
85 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
86
87 /* *** Help command with introduction. *** */
88 struct cmd_help_brief_result {
89         cmdline_fixed_string_t help;
90 };
91
92 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
93                                   struct cmdline *cl,
94                                   __attribute__((unused)) void *data)
95 {
96         cmdline_printf(
97                 cl,
98                 "\n"
99                 "Help is available for the following sections:\n\n"
100                 "    help control    : Start and stop forwarding.\n"
101                 "    help display    : Displaying port, stats and config "
102                 "information.\n"
103                 "    help config     : Configuration information.\n"
104                 "    help ports      : Configuring ports.\n"
105                 "    help registers  : Reading and setting port registers.\n"
106                 "    help filters    : Filters configuration help.\n"
107                 "    help all        : All of the above sections.\n\n"
108         );
109
110 }
111
112 cmdline_parse_token_string_t cmd_help_brief_help =
113         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
114
115 cmdline_parse_inst_t cmd_help_brief = {
116         .f = cmd_help_brief_parsed,
117         .data = NULL,
118         .help_str = "help: Show help",
119         .tokens = {
120                 (void *)&cmd_help_brief_help,
121                 NULL,
122         },
123 };
124
125 /* *** Help command with help sections. *** */
126 struct cmd_help_long_result {
127         cmdline_fixed_string_t help;
128         cmdline_fixed_string_t section;
129 };
130
131 static void cmd_help_long_parsed(void *parsed_result,
132                                  struct cmdline *cl,
133                                  __attribute__((unused)) void *data)
134 {
135         int show_all = 0;
136         struct cmd_help_long_result *res = parsed_result;
137
138         if (!strcmp(res->section, "all"))
139                 show_all = 1;
140
141         if (show_all || !strcmp(res->section, "control")) {
142
143                 cmdline_printf(
144                         cl,
145                         "\n"
146                         "Control forwarding:\n"
147                         "-------------------\n\n"
148
149                         "start\n"
150                         "    Start packet forwarding with current configuration.\n\n"
151
152                         "start tx_first\n"
153                         "    Start packet forwarding with current config"
154                         " after sending one burst of packets.\n\n"
155
156                         "stop\n"
157                         "    Stop packet forwarding, and display accumulated"
158                         " statistics.\n\n"
159
160                         "quit\n"
161                         "    Quit to prompt.\n\n"
162                 );
163         }
164
165         if (show_all || !strcmp(res->section, "display")) {
166
167                 cmdline_printf(
168                         cl,
169                         "\n"
170                         "Display:\n"
171                         "--------\n\n"
172
173                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
174                         "    Display information for port_id, or all.\n\n"
175
176                         "show port X rss reta (size) (mask0,mask1,...)\n"
177                         "    Display the rss redirection table entry indicated"
178                         " by masks on port X. size is used to indicate the"
179                         " hardware supported reta size\n\n"
180
181                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
182                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
183                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
184                         "    Display the RSS hash functions and RSS hash key"
185                         " of port X\n\n"
186
187                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
188                         "    Clear information for port_id, or all.\n\n"
189
190                         "show (rxq|txq) info (port_id) (queue_id)\n"
191                         "    Display information for configured RX/TX queue.\n\n"
192
193                         "show config (rxtx|cores|fwd|txpkts)\n"
194                         "    Display the given configuration.\n\n"
195
196                         "read rxd (port_id) (queue_id) (rxd_id)\n"
197                         "    Display an RX descriptor of a port RX queue.\n\n"
198
199                         "read txd (port_id) (queue_id) (txd_id)\n"
200                         "    Display a TX descriptor of a port TX queue.\n\n"
201
202                         "ddp get list (port_id)\n"
203                         "    Get ddp profile info list\n\n"
204
205                         "ddp get info (profile_path)\n"
206                         "    Get ddp profile information.\n\n"
207
208                         "show vf stats (port_id) (vf_id)\n"
209                         "    Display a VF's statistics.\n\n"
210
211                         "clear vf stats (port_id) (vf_id)\n"
212                         "    Reset a VF's statistics.\n\n"
213
214                         "show port (port_id) pctype mapping\n"
215                         "    Get flow ptype to pctype mapping on a port\n\n"
216
217                         "show port meter stats (port_id) (meter_id) (clear)\n"
218                         "    Get meter stats on a port\n\n"
219                         "show port tm cap (port_id)\n"
220                         "       Display the port TM capability.\n\n"
221
222                         "show port tm level cap (port_id) (level_id)\n"
223                         "       Display the port TM hierarchical level capability.\n\n"
224
225                         "show port tm node cap (port_id) (node_id)\n"
226                         "       Display the port TM node capability.\n\n"
227
228                         "show port tm node type (port_id) (node_id)\n"
229                         "       Display the port TM node type.\n\n"
230
231                         "show port tm node stats (port_id) (node_id) (clear)\n"
232                         "       Display the port TM node stats.\n\n"
233
234                 );
235         }
236
237         if (show_all || !strcmp(res->section, "config")) {
238                 cmdline_printf(
239                         cl,
240                         "\n"
241                         "Configuration:\n"
242                         "--------------\n"
243                         "Configuration changes only become active when"
244                         " forwarding is started/restarted.\n\n"
245
246                         "set default\n"
247                         "    Reset forwarding to the default configuration.\n\n"
248
249                         "set verbose (level)\n"
250                         "    Set the debug verbosity level X.\n\n"
251
252                         "set log global|(type) (level)\n"
253                         "    Set the log level.\n\n"
254
255                         "set nbport (num)\n"
256                         "    Set number of ports.\n\n"
257
258                         "set nbcore (num)\n"
259                         "    Set number of cores.\n\n"
260
261                         "set coremask (mask)\n"
262                         "    Set the forwarding cores hexadecimal mask.\n\n"
263
264                         "set portmask (mask)\n"
265                         "    Set the forwarding ports hexadecimal mask.\n\n"
266
267                         "set burst (num)\n"
268                         "    Set number of packets per burst.\n\n"
269
270                         "set burst tx delay (microseconds) retry (num)\n"
271                         "    Set the transmit delay time and number of retries,"
272                         " effective when retry is enabled.\n\n"
273
274                         "set txpkts (x[,y]*)\n"
275                         "    Set the length of each segment of TXONLY"
276                         " and optionally CSUM packets.\n\n"
277
278                         "set txsplit (off|on|rand)\n"
279                         "    Set the split policy for the TX packets."
280                         " Right now only applicable for CSUM and TXONLY"
281                         " modes\n\n"
282
283                         "set corelist (x[,y]*)\n"
284                         "    Set the list of forwarding cores.\n\n"
285
286                         "set portlist (x[,y]*)\n"
287                         "    Set the list of forwarding ports.\n\n"
288
289                         "set tx loopback (port_id) (on|off)\n"
290                         "    Enable or disable tx loopback.\n\n"
291
292                         "set all queues drop (port_id) (on|off)\n"
293                         "    Set drop enable bit for all queues.\n\n"
294
295                         "set vf split drop (port_id) (vf_id) (on|off)\n"
296                         "    Set split drop enable bit for a VF from the PF.\n\n"
297
298                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299                         "    Set MAC antispoof for a VF from the PF.\n\n"
300
301                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302                         "    Enable MACsec offload.\n\n"
303
304                         "set macsec offload (port_id) off\n"
305                         "    Disable MACsec offload.\n\n"
306
307                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308                         "    Configure MACsec secure connection (SC).\n\n"
309
310                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311                         "    Configure MACsec secure association (SA).\n\n"
312
313                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
314                         "    Set VF broadcast for a VF from the PF.\n\n"
315
316                         "vlan set strip (on|off) (port_id)\n"
317                         "    Set the VLAN strip on a port.\n\n"
318
319                         "vlan set stripq (on|off) (port_id,queue_id)\n"
320                         "    Set the VLAN strip for a queue on a port.\n\n"
321
322                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324
325                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326                         "    Set VLAN insert for a VF from the PF.\n\n"
327
328                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN antispoof for a VF from the PF.\n\n"
330
331                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
332                         "    Set VLAN tag for a VF from the PF.\n\n"
333
334                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335                         "    Set a VF's max bandwidth(Mbps).\n\n"
336
337                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339
340                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342
343                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
344                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
345
346                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348
349                         "vlan set filter (on|off) (port_id)\n"
350                         "    Set the VLAN filter on a port.\n\n"
351
352                         "vlan set qinq (on|off) (port_id)\n"
353                         "    Set the VLAN QinQ (extended queue in queue)"
354                         " on a port.\n\n"
355
356                         "vlan set (inner|outer) tpid (value) (port_id)\n"
357                         "    Set the VLAN TPID for Packet Filtering on"
358                         " a port\n\n"
359
360                         "rx_vlan add (vlan_id|all) (port_id)\n"
361                         "    Add a vlan_id, or all identifiers, to the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan rm (vlan_id|all) (port_id)\n"
365                         "    Remove a vlan_id, or all identifiers, from the set"
366                         " of VLAN identifiers filtered by port_id.\n\n"
367
368                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Add a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373                         "    Remove a vlan_id, to the set of VLAN identifiers"
374                         "filtered for VF(s) from port_id.\n\n"
375
376                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379                         "   add a tunnel filter of a port.\n\n"
380
381                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   remove a tunnel filter of a port.\n\n"
385
386                         "rx_vxlan_port add (udp_port) (port_id)\n"
387                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "rx_vxlan_port rm (udp_port) (port_id)\n"
390                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
391
392                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
394                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395
396                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
397                         "    Set port based TX VLAN insertion.\n\n"
398
399                         "tx_vlan reset (port_id)\n"
400                         "    Disable hardware insertion of a VLAN header in"
401                         " packets sent on a port.\n\n"
402
403                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404                         "    Select hardware or software calculation of the"
405                         " checksum when transmitting a packet using the"
406                         " csum forward engine.\n"
407                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
408                         "    outer-ip concerns the outer IP layer in"
409                         " case the packet is recognized as a tunnel packet by"
410                         " the forward engine (vxlan, gre and ipip are supported)\n"
411                         "    Please check the NIC datasheet for HW limits.\n\n"
412
413                         "csum parse-tunnel (on|off) (tx_port_id)\n"
414                         "    If disabled, treat tunnel packets as non-tunneled"
415                         " packets (treat inner headers as payload). The port\n"
416                         "    argument is the port used for TX in csum forward"
417                         " engine.\n\n"
418
419                         "csum show (port_id)\n"
420                         "    Display tx checksum offload configuration\n\n"
421
422                         "tso set (segsize) (portid)\n"
423                         "    Enable TCP Segmentation Offload in csum forward"
424                         " engine.\n"
425                         "    Please check the NIC datasheet for HW limits.\n\n"
426
427                         "tso show (portid)"
428                         "    Display the status of TCP Segmentation Offload.\n\n"
429
430                         "set port (port_id) gro on|off\n"
431                         "    Enable or disable Generic Receive Offload in"
432                         " csum forwarding engine.\n\n"
433
434                         "show port (port_id) gro\n"
435                         "    Display GRO configuration.\n\n"
436
437                         "set gro flush (cycles)\n"
438                         "    Set the cycle to flush GROed packets from"
439                         " reassembly tables.\n\n"
440
441                         "set port (port_id) gso (on|off)"
442                         "    Enable or disable Generic Segmentation Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "set gso segsz (length)\n"
446                         "    Set max packet length for output GSO segments,"
447                         " including packet header and payload.\n\n"
448
449                         "show port (port_id) gso\n"
450                         "    Show GSO configuration.\n\n"
451
452                         "set fwd (%s)\n"
453                         "    Set packet forwarding mode.\n\n"
454
455                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
456                         "    Add a MAC address on port_id.\n\n"
457
458                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Remove a MAC address from port_id.\n\n"
460
461                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Set the default MAC address for port_id.\n\n"
463
464                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
465                         "    Add a MAC address for a VF on the port.\n\n"
466
467                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Set the MAC address for a VF from the PF.\n\n"
469
470                         "set eth-peer (port_id) (peer_addr)\n"
471                         "    set the peer address for certain port.\n\n"
472
473                         "set port (port_id) uta (mac_address|all) (on|off)\n"
474                         "    Add/Remove a or all unicast hash filter(s)"
475                         "from port X.\n\n"
476
477                         "set promisc (port_id|all) (on|off)\n"
478                         "    Set the promiscuous mode on port_id, or all.\n\n"
479
480                         "set allmulti (port_id|all) (on|off)\n"
481                         "    Set the allmulti mode on port_id, or all.\n\n"
482
483                         "set vf promisc (port_id) (vf_id) (on|off)\n"
484                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
487                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
488
489                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
490                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
491                         " (on|off) autoneg (on|off) (port_id)\n"
492                         "set flow_ctrl rx (on|off) (portid)\n"
493                         "set flow_ctrl tx (on|off) (portid)\n"
494                         "set flow_ctrl high_water (high_water) (portid)\n"
495                         "set flow_ctrl low_water (low_water) (portid)\n"
496                         "set flow_ctrl pause_time (pause_time) (portid)\n"
497                         "set flow_ctrl send_xon (send_xon) (portid)\n"
498                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
499                         "set flow_ctrl autoneg (on|off) (port_id)\n"
500                         "    Set the link flow control parameter on a port.\n\n"
501
502                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
503                         " (low_water) (pause_time) (priority) (port_id)\n"
504                         "    Set the priority flow control parameter on a"
505                         " port.\n\n"
506
507                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
508                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
509                         " queue on port.\n"
510                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
511                         " on port 0 to mapping 5.\n\n"
512
513                         "set xstats-hide-zero on|off\n"
514                         "    Set the option to hide the zero values"
515                         " for xstats display.\n"
516
517                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
518                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
519
520                         "set port (port_id) vf (vf_id) (mac_addr)"
521                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
522                         "   Add/Remove unicast or multicast MAC addr filter"
523                         " for a VF.\n\n"
524
525                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
526                         "|MPE) (on|off)\n"
527                         "    AUPE:accepts untagged VLAN;"
528                         "ROPE:accept unicast hash\n\n"
529                         "    BAM:accepts broadcast packets;"
530                         "MPE:accepts all multicast packets\n\n"
531                         "    Enable/Disable a VF receive mode of a port\n\n"
532
533                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
534                         "    Set rate limit for a queue of a port\n\n"
535
536                         "set port (port_id) vf (vf_id) rate (rate_num) "
537                         "queue_mask (queue_mask_value)\n"
538                         "    Set rate limit for queues in VF of a port\n\n"
539
540                         "set port (port_id) mirror-rule (rule_id)"
541                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
542                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
543                         "   Set pool or vlan type mirror rule on a port.\n"
544                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
545                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
546                         " to pool 0.\n\n"
547
548                         "set port (port_id) mirror-rule (rule_id)"
549                         " (uplink-mirror|downlink-mirror) dst-pool"
550                         " (pool_id) (on|off)\n"
551                         "   Set uplink or downlink type mirror rule on a port.\n"
552                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
553                         " 0 on' enable mirror income traffic to pool 0.\n\n"
554
555                         "reset port (port_id) mirror-rule (rule_id)\n"
556                         "   Reset a mirror rule.\n\n"
557
558                         "set flush_rx (on|off)\n"
559                         "   Flush (default) or don't flush RX streams before"
560                         " forwarding. Mainly used with PCAP drivers.\n\n"
561
562                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
563                         "   Set the bypass mode for the lowest port on bypass enabled"
564                         " NIC.\n\n"
565
566                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
567                         "mode (normal|bypass|isolate) (port_id)\n"
568                         "   Set the event required to initiate specified bypass mode for"
569                         " the lowest port on a bypass enabled NIC where:\n"
570                         "       timeout   = enable bypass after watchdog timeout.\n"
571                         "       os_on     = enable bypass when OS/board is powered on.\n"
572                         "       os_off    = enable bypass when OS/board is powered off.\n"
573                         "       power_on  = enable bypass when power supply is turned on.\n"
574                         "       power_off = enable bypass when power supply is turned off."
575                         "\n\n"
576
577                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
578                         "   Set the bypass watchdog timeout to 'n' seconds"
579                         " where 0 = instant.\n\n"
580
581                         "show bypass config (port_id)\n"
582                         "   Show the bypass configuration for a bypass enabled NIC"
583                         " using the lowest port on the NIC.\n\n"
584
585 #ifdef RTE_LIBRTE_PMD_BOND
586                         "create bonded device (mode) (socket)\n"
587                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
588
589                         "add bonding slave (slave_id) (port_id)\n"
590                         "       Add a slave device to a bonded device.\n\n"
591
592                         "remove bonding slave (slave_id) (port_id)\n"
593                         "       Remove a slave device from a bonded device.\n\n"
594
595                         "set bonding mode (value) (port_id)\n"
596                         "       Set the bonding mode on a bonded device.\n\n"
597
598                         "set bonding primary (slave_id) (port_id)\n"
599                         "       Set the primary slave for a bonded device.\n\n"
600
601                         "show bonding config (port_id)\n"
602                         "       Show the bonding config for port_id.\n\n"
603
604                         "set bonding mac_addr (port_id) (address)\n"
605                         "       Set the MAC address of a bonded device.\n\n"
606
607                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
608                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
609
610                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
611                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
612
613                         "set bonding mon_period (port_id) (value)\n"
614                         "       Set the bonding link status monitoring polling period in ms.\n\n"
615
616                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
617                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
618
619 #endif
620                         "set link-up port (port_id)\n"
621                         "       Set link up for a port.\n\n"
622
623                         "set link-down port (port_id)\n"
624                         "       Set link down for a port.\n\n"
625
626                         "E-tag set insertion on port-tag-id (value)"
627                         " port (port_id) vf (vf_id)\n"
628                         "    Enable E-tag insertion for a VF on a port\n\n"
629
630                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
631                         "    Disable E-tag insertion for a VF on a port\n\n"
632
633                         "E-tag set stripping (on|off) port (port_id)\n"
634                         "    Enable/disable E-tag stripping on a port\n\n"
635
636                         "E-tag set forwarding (on|off) port (port_id)\n"
637                         "    Enable/disable E-tag based forwarding"
638                         " on a port\n\n"
639
640                         "E-tag set filter add e-tag-id (value) dst-pool"
641                         " (pool_id) port (port_id)\n"
642                         "    Add an E-tag forwarding filter on a port\n\n"
643
644                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
645                         "    Delete an E-tag forwarding filter on a port\n\n"
646
647 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
648                         "set port tm hierarchy default (port_id)\n"
649                         "       Set default traffic Management hierarchy on a port\n\n"
650
651 #endif
652                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
653                         "    Load a profile package on a port\n\n"
654
655                         "ddp del (port_id) (backup_profile_path)\n"
656                         "    Delete a profile package from a port\n\n"
657
658                         "ptype mapping get (port_id) (valid_only)\n"
659                         "    Get ptype mapping on a port\n\n"
660
661                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
662                         "    Replace target with the pkt_type in ptype mapping\n\n"
663
664                         "ptype mapping reset (port_id)\n"
665                         "    Reset ptype mapping on a port\n\n"
666
667                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
668                         "    Update a ptype mapping item on a port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "queue_start_index (value) queue_num (value)\n"
672                         "    Set a queue region on a port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "flowtype (value)\n"
676                         "    Set a flowtype region index on a port\n\n"
677
678                         "set port (port_id) queue-region UP (value) region_id (value)\n"
679                         "    Set the mapping of User Priority to "
680                         "queue region on a port\n\n"
681
682                         "set port (port_id) queue-region flush (on|off)\n"
683                         "    flush all queue region related configuration\n\n"
684
685                         "show port meter cap (port_id)\n"
686                         "    Show port meter capability information\n\n"
687
688                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
689                         "    meter profile add - srtcm rfc 2697\n\n"
690
691                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
692                         "    meter profile add - trtcm rfc 2698\n\n"
693
694                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
695                         "    meter profile add - trtcm rfc 4115\n\n"
696
697                         "del port meter profile (port_id) (profile_id)\n"
698                         "    meter profile delete\n\n"
699
700                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
701                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
702                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
703                         "(dscp_tbl_entry63)]\n"
704                         "    meter create\n\n"
705
706                         "enable port meter (port_id) (mtr_id)\n"
707                         "    meter enable\n\n"
708
709                         "disable port meter (port_id) (mtr_id)\n"
710                         "    meter disable\n\n"
711
712                         "del port meter (port_id) (mtr_id)\n"
713                         "    meter delete\n\n"
714
715                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
716                         "    meter update meter profile\n\n"
717
718                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
719                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
720                         "    update meter dscp table entries\n\n"
721
722                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
723                         "(action0) [(action1) (action2)]\n"
724                         "    meter update policer action\n\n"
725
726                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
727                         "    meter update stats\n\n"
728
729                         "show port (port_id) queue-region\n"
730                         "    show all queue region related configuration info\n\n"
731
732                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
733                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
734                         "       Add port tm node private shaper profile.\n\n"
735
736                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
737                         "       Delete port tm node private shaper profile.\n\n"
738
739                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
740                         " (shaper_profile_id)\n"
741                         "       Add/update port tm node shared shaper.\n\n"
742
743                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
744                         "       Delete port tm node shared shaper.\n\n"
745
746                         "set port tm node shaper profile (port_id) (node_id)"
747                         " (shaper_profile_id)\n"
748                         "       Set port tm node shaper profile.\n\n"
749
750                         "add port tm node wred profile (port_id) (wred_profile_id)"
751                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
752                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
753                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
754                         "       Add port tm node wred profile.\n\n"
755
756                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
757                         "       Delete port tm node wred profile.\n\n"
758
759                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
760                         " (priority) (weight) (level_id) (shaper_profile_id)"
761                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
762                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
763                         "       Add port tm nonleaf node.\n\n"
764
765                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
766                         " (priority) (weight) (level_id) (shaper_profile_id)"
767                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
768                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
769                         "       Add port tm leaf node.\n\n"
770
771                         "del port tm node (port_id) (node_id)\n"
772                         "       Delete port tm node.\n\n"
773
774                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
775                         " (priority) (weight)\n"
776                         "       Set port tm node parent.\n\n"
777
778                         "suspend port tm node (port_id) (node_id)"
779                         "       Suspend tm node.\n\n"
780
781                         "resume port tm node (port_id) (node_id)"
782                         "       Resume tm node.\n\n"
783
784                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
785                         "       Commit tm hierarchy.\n\n"
786
787                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
788                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
789                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
790                         "       Configure the VXLAN encapsulation for flows.\n\n"
791
792                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
793                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
794                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
795                         " eth-dst (eth-dst)\n"
796                         "       Configure the VXLAN encapsulation for flows.\n\n"
797
798                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
799                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
800                         " (eth-dst)\n"
801                         "       Configure the NVGRE encapsulation for flows.\n\n"
802
803                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
804                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
805                         " eth-src (eth-src) eth-dst (eth-dst)\n"
806                         "       Configure the NVGRE encapsulation for flows.\n\n"
807
808                         , list_pkt_forwarding_modes()
809                 );
810         }
811
812         if (show_all || !strcmp(res->section, "ports")) {
813
814                 cmdline_printf(
815                         cl,
816                         "\n"
817                         "Port Operations:\n"
818                         "----------------\n\n"
819
820                         "port start (port_id|all)\n"
821                         "    Start all ports or port_id.\n\n"
822
823                         "port stop (port_id|all)\n"
824                         "    Stop all ports or port_id.\n\n"
825
826                         "port close (port_id|all)\n"
827                         "    Close all ports or port_id.\n\n"
828
829                         "port attach (ident)\n"
830                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
831
832                         "port detach (port_id)\n"
833                         "    Detach physical or virtual dev by port_id\n\n"
834
835                         "port config (port_id|all)"
836                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
837                         " duplex (half|full|auto)\n"
838                         "    Set speed and duplex for all ports or port_id\n\n"
839
840                         "port config (port_id|all) loopback (mode)\n"
841                         "    Set loopback mode for all ports or port_id\n\n"
842
843                         "port config all (rxq|txq|rxd|txd) (value)\n"
844                         "    Set number for rxq/txq/rxd/txd.\n\n"
845
846                         "port config all max-pkt-len (value)\n"
847                         "    Set the max packet length.\n\n"
848
849                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
850                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
851                         " (on|off)\n"
852                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
853                         " for ports.\n\n"
854
855                         "port config all rss (all|default|ip|tcp|udp|sctp|"
856                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
857                         "    Set the RSS mode.\n\n"
858
859                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
860                         "    Set the RSS redirection table.\n\n"
861
862                         "port config (port_id) dcb vt (on|off) (traffic_class)"
863                         " pfc (on|off)\n"
864                         "    Set the DCB mode.\n\n"
865
866                         "port config all burst (value)\n"
867                         "    Set the number of packets per burst.\n\n"
868
869                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
870                         " (value)\n"
871                         "    Set the ring prefetch/host/writeback threshold"
872                         " for tx/rx queue.\n\n"
873
874                         "port config all (txfreet|txrst|rxfreet) (value)\n"
875                         "    Set free threshold for rx/tx, or set"
876                         " tx rs bit threshold.\n\n"
877                         "port config mtu X value\n"
878                         "    Set the MTU of port X to a given value\n\n"
879
880                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
881                         "    Set a rx/tx queue's ring size configuration, the new"
882                         " value will take effect after command that (re-)start the port"
883                         " or command that setup the specific queue\n\n"
884
885                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
886                         "    Start/stop a rx/tx queue of port X. Only take effect"
887                         " when port X is started\n\n"
888
889                         "port (port_id) (rxq|txq) (queue_id) setup\n"
890                         "    Setup a rx/tx queue of port X.\n\n"
891
892                         "port config (port_id|all) l2-tunnel E-tag ether-type"
893                         " (value)\n"
894                         "    Set the value of E-tag ether-type.\n\n"
895
896                         "port config (port_id|all) l2-tunnel E-tag"
897                         " (enable|disable)\n"
898                         "    Enable/disable the E-tag support.\n\n"
899
900                         "port config (port_id) pctype mapping reset\n"
901                         "    Reset flow type to pctype mapping on a port\n\n"
902
903                         "port config (port_id) pctype mapping update"
904                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
905                         "    Update a flow type to pctype mapping item on a port\n\n"
906
907                         "port config (port_id) pctype (pctype_id) hash_inset|"
908                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
909                         " (field_idx)\n"
910                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
911
912                         "port config (port_id) pctype (pctype_id) hash_inset|"
913                         "fdir_inset|fdir_flx_inset clear all"
914                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
915
916                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
917                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
918                 );
919         }
920
921         if (show_all || !strcmp(res->section, "registers")) {
922
923                 cmdline_printf(
924                         cl,
925                         "\n"
926                         "Registers:\n"
927                         "----------\n\n"
928
929                         "read reg (port_id) (address)\n"
930                         "    Display value of a port register.\n\n"
931
932                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
933                         "    Display a port register bit field.\n\n"
934
935                         "read regbit (port_id) (address) (bit_x)\n"
936                         "    Display a single port register bit.\n\n"
937
938                         "write reg (port_id) (address) (value)\n"
939                         "    Set value of a port register.\n\n"
940
941                         "write regfield (port_id) (address) (bit_x) (bit_y)"
942                         " (value)\n"
943                         "    Set bit field of a port register.\n\n"
944
945                         "write regbit (port_id) (address) (bit_x) (value)\n"
946                         "    Set single bit value of a port register.\n\n"
947                 );
948         }
949         if (show_all || !strcmp(res->section, "filters")) {
950
951                 cmdline_printf(
952                         cl,
953                         "\n"
954                         "filters:\n"
955                         "--------\n\n"
956
957                         "ethertype_filter (port_id) (add|del)"
958                         " (mac_addr|mac_ignr) (mac_address) ethertype"
959                         " (ether_type) (drop|fwd) queue (queue_id)\n"
960                         "    Add/Del an ethertype filter.\n\n"
961
962                         "2tuple_filter (port_id) (add|del)"
963                         " dst_port (dst_port_value) protocol (protocol_value)"
964                         " mask (mask_value) tcp_flags (tcp_flags_value)"
965                         " priority (prio_value) queue (queue_id)\n"
966                         "    Add/Del a 2tuple filter.\n\n"
967
968                         "5tuple_filter (port_id) (add|del)"
969                         " dst_ip (dst_address) src_ip (src_address)"
970                         " dst_port (dst_port_value) src_port (src_port_value)"
971                         " protocol (protocol_value)"
972                         " mask (mask_value) tcp_flags (tcp_flags_value)"
973                         " priority (prio_value) queue (queue_id)\n"
974                         "    Add/Del a 5tuple filter.\n\n"
975
976                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
977                         "    Add/Del syn filter.\n\n"
978
979                         "flex_filter (port_id) (add|del) len (len_value)"
980                         " bytes (bytes_value) mask (mask_value)"
981                         " priority (prio_value) queue (queue_id)\n"
982                         "    Add/Del a flex filter.\n\n"
983
984                         "flow_director_filter (port_id) mode IP (add|del|update)"
985                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
986                         " src (src_ip_address) dst (dst_ip_address)"
987                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
988                         " vlan (vlan_value) flexbytes (flexbytes_value)"
989                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
990                         " fd_id (fd_id_value)\n"
991                         "    Add/Del an IP type flow director filter.\n\n"
992
993                         "flow_director_filter (port_id) mode IP (add|del|update)"
994                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
995                         " src (src_ip_address) (src_port)"
996                         " dst (dst_ip_address) (dst_port)"
997                         " tos (tos_value) ttl (ttl_value)"
998                         " vlan (vlan_value) flexbytes (flexbytes_value)"
999                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1000                         " fd_id (fd_id_value)\n"
1001                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1002
1003                         "flow_director_filter (port_id) mode IP (add|del|update)"
1004                         " flow (ipv4-sctp|ipv6-sctp)"
1005                         " src (src_ip_address) (src_port)"
1006                         " dst (dst_ip_address) (dst_port)"
1007                         " tag (verification_tag) "
1008                         " tos (tos_value) ttl (ttl_value)"
1009                         " vlan (vlan_value)"
1010                         " flexbytes (flexbytes_value) (drop|fwd)"
1011                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1012                         "    Add/Del a SCTP type flow director filter.\n\n"
1013
1014                         "flow_director_filter (port_id) mode IP (add|del|update)"
1015                         " flow l2_payload ether (ethertype)"
1016                         " flexbytes (flexbytes_value) (drop|fwd)"
1017                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1018                         "    Add/Del a l2 payload type flow director filter.\n\n"
1019
1020                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1021                         " mac (mac_address) vlan (vlan_value)"
1022                         " flexbytes (flexbytes_value) (drop|fwd)"
1023                         " queue (queue_id) fd_id (fd_id_value)\n"
1024                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1025
1026                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1027                         " mac (mac_address) vlan (vlan_value)"
1028                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1029                         " flexbytes (flexbytes_value) (drop|fwd)"
1030                         " queue (queue_id) fd_id (fd_id_value)\n"
1031                         "    Add/Del a Tunnel flow director filter.\n\n"
1032
1033                         "flow_director_filter (port_id) mode raw (add|del|update)"
1034                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1035                         " fd_id (fd_id_value) packet (packet file name)\n"
1036                         "    Add/Del a raw type flow director filter.\n\n"
1037
1038                         "flush_flow_director (port_id)\n"
1039                         "    Flush all flow director entries of a device.\n\n"
1040
1041                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1042                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1043                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1044                         "    Set flow director IP mask.\n\n"
1045
1046                         "flow_director_mask (port_id) mode MAC-VLAN"
1047                         " vlan (vlan_value)\n"
1048                         "    Set flow director MAC-VLAN mask.\n\n"
1049
1050                         "flow_director_mask (port_id) mode Tunnel"
1051                         " vlan (vlan_value) mac (mac_value)"
1052                         " tunnel-type (tunnel_type_value)"
1053                         " tunnel-id (tunnel_id_value)\n"
1054                         "    Set flow director Tunnel mask.\n\n"
1055
1056                         "flow_director_flex_mask (port_id)"
1057                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1058                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1059                         " (mask)\n"
1060                         "    Configure mask of flex payload.\n\n"
1061
1062                         "flow_director_flex_payload (port_id)"
1063                         " (raw|l2|l3|l4) (config)\n"
1064                         "    Configure flex payload selection.\n\n"
1065
1066                         "get_sym_hash_ena_per_port (port_id)\n"
1067                         "    get symmetric hash enable configuration per port.\n\n"
1068
1069                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1070                         "    set symmetric hash enable configuration per port"
1071                         " to enable or disable.\n\n"
1072
1073                         "get_hash_global_config (port_id)\n"
1074                         "    Get the global configurations of hash filters.\n\n"
1075
1076                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1077                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1078                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1079                         " (enable|disable)\n"
1080                         "    Set the global configurations of hash filters.\n\n"
1081
1082                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1083                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1084                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1085                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1086                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1087                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1088                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1089                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1090                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1091                         "fld-8th|none) (select|add)\n"
1092                         "    Set the input set for hash.\n\n"
1093
1094                         "set_fdir_input_set (port_id) "
1095                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1096                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1097                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1098                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1099                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1100                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1101                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1102                         " (select|add)\n"
1103                         "    Set the input set for FDir.\n\n"
1104
1105                         "flow validate {port_id}"
1106                         " [group {group_id}] [priority {level}]"
1107                         " [ingress] [egress]"
1108                         " pattern {item} [/ {item} [...]] / end"
1109                         " actions {action} [/ {action} [...]] / end\n"
1110                         "    Check whether a flow rule can be created.\n\n"
1111
1112                         "flow create {port_id}"
1113                         " [group {group_id}] [priority {level}]"
1114                         " [ingress] [egress]"
1115                         " pattern {item} [/ {item} [...]] / end"
1116                         " actions {action} [/ {action} [...]] / end\n"
1117                         "    Create a flow rule.\n\n"
1118
1119                         "flow destroy {port_id} rule {rule_id} [...]\n"
1120                         "    Destroy specific flow rules.\n\n"
1121
1122                         "flow flush {port_id}\n"
1123                         "    Destroy all flow rules.\n\n"
1124
1125                         "flow query {port_id} {rule_id} {action}\n"
1126                         "    Query an existing flow rule.\n\n"
1127
1128                         "flow list {port_id} [group {group_id}] [...]\n"
1129                         "    List existing flow rules sorted by priority,"
1130                         " filtered by group identifiers.\n\n"
1131
1132                         "flow isolate {port_id} {boolean}\n"
1133                         "    Restrict ingress traffic to the defined"
1134                         " flow rules\n\n"
1135                 );
1136         }
1137 }
1138
1139 cmdline_parse_token_string_t cmd_help_long_help =
1140         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1141
1142 cmdline_parse_token_string_t cmd_help_long_section =
1143         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1144                         "all#control#display#config#"
1145                         "ports#registers#filters");
1146
1147 cmdline_parse_inst_t cmd_help_long = {
1148         .f = cmd_help_long_parsed,
1149         .data = NULL,
1150         .help_str = "help all|control|display|config|ports|register|filters: "
1151                 "Show help",
1152         .tokens = {
1153                 (void *)&cmd_help_long_help,
1154                 (void *)&cmd_help_long_section,
1155                 NULL,
1156         },
1157 };
1158
1159
1160 /* *** start/stop/close all ports *** */
1161 struct cmd_operate_port_result {
1162         cmdline_fixed_string_t keyword;
1163         cmdline_fixed_string_t name;
1164         cmdline_fixed_string_t value;
1165 };
1166
1167 static void cmd_operate_port_parsed(void *parsed_result,
1168                                 __attribute__((unused)) struct cmdline *cl,
1169                                 __attribute__((unused)) void *data)
1170 {
1171         struct cmd_operate_port_result *res = parsed_result;
1172
1173         if (!strcmp(res->name, "start"))
1174                 start_port(RTE_PORT_ALL);
1175         else if (!strcmp(res->name, "stop"))
1176                 stop_port(RTE_PORT_ALL);
1177         else if (!strcmp(res->name, "close"))
1178                 close_port(RTE_PORT_ALL);
1179         else if (!strcmp(res->name, "reset"))
1180                 reset_port(RTE_PORT_ALL);
1181         else
1182                 printf("Unknown parameter\n");
1183 }
1184
1185 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1186         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1187                                                                 "port");
1188 cmdline_parse_token_string_t cmd_operate_port_all_port =
1189         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1190                                                 "start#stop#close#reset");
1191 cmdline_parse_token_string_t cmd_operate_port_all_all =
1192         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1193
1194 cmdline_parse_inst_t cmd_operate_port = {
1195         .f = cmd_operate_port_parsed,
1196         .data = NULL,
1197         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1198         .tokens = {
1199                 (void *)&cmd_operate_port_all_cmd,
1200                 (void *)&cmd_operate_port_all_port,
1201                 (void *)&cmd_operate_port_all_all,
1202                 NULL,
1203         },
1204 };
1205
1206 /* *** start/stop/close specific port *** */
1207 struct cmd_operate_specific_port_result {
1208         cmdline_fixed_string_t keyword;
1209         cmdline_fixed_string_t name;
1210         uint8_t value;
1211 };
1212
1213 static void cmd_operate_specific_port_parsed(void *parsed_result,
1214                         __attribute__((unused)) struct cmdline *cl,
1215                                 __attribute__((unused)) void *data)
1216 {
1217         struct cmd_operate_specific_port_result *res = parsed_result;
1218
1219         if (!strcmp(res->name, "start"))
1220                 start_port(res->value);
1221         else if (!strcmp(res->name, "stop"))
1222                 stop_port(res->value);
1223         else if (!strcmp(res->name, "close"))
1224                 close_port(res->value);
1225         else if (!strcmp(res->name, "reset"))
1226                 reset_port(res->value);
1227         else
1228                 printf("Unknown parameter\n");
1229 }
1230
1231 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1232         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1233                                                         keyword, "port");
1234 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1235         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1236                                                 name, "start#stop#close#reset");
1237 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1238         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1239                                                         value, UINT8);
1240
1241 cmdline_parse_inst_t cmd_operate_specific_port = {
1242         .f = cmd_operate_specific_port_parsed,
1243         .data = NULL,
1244         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1245         .tokens = {
1246                 (void *)&cmd_operate_specific_port_cmd,
1247                 (void *)&cmd_operate_specific_port_port,
1248                 (void *)&cmd_operate_specific_port_id,
1249                 NULL,
1250         },
1251 };
1252
1253 /* *** attach a specified port *** */
1254 struct cmd_operate_attach_port_result {
1255         cmdline_fixed_string_t port;
1256         cmdline_fixed_string_t keyword;
1257         cmdline_fixed_string_t identifier;
1258 };
1259
1260 static void cmd_operate_attach_port_parsed(void *parsed_result,
1261                                 __attribute__((unused)) struct cmdline *cl,
1262                                 __attribute__((unused)) void *data)
1263 {
1264         struct cmd_operate_attach_port_result *res = parsed_result;
1265
1266         if (!strcmp(res->keyword, "attach"))
1267                 attach_port(res->identifier);
1268         else
1269                 printf("Unknown parameter\n");
1270 }
1271
1272 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1273         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1274                         port, "port");
1275 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1277                         keyword, "attach");
1278 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1280                         identifier, NULL);
1281
1282 cmdline_parse_inst_t cmd_operate_attach_port = {
1283         .f = cmd_operate_attach_port_parsed,
1284         .data = NULL,
1285         .help_str = "port attach <identifier>: "
1286                 "(identifier: pci address or virtual dev name)",
1287         .tokens = {
1288                 (void *)&cmd_operate_attach_port_port,
1289                 (void *)&cmd_operate_attach_port_keyword,
1290                 (void *)&cmd_operate_attach_port_identifier,
1291                 NULL,
1292         },
1293 };
1294
1295 /* *** detach a specified port *** */
1296 struct cmd_operate_detach_port_result {
1297         cmdline_fixed_string_t port;
1298         cmdline_fixed_string_t keyword;
1299         portid_t port_id;
1300 };
1301
1302 static void cmd_operate_detach_port_parsed(void *parsed_result,
1303                                 __attribute__((unused)) struct cmdline *cl,
1304                                 __attribute__((unused)) void *data)
1305 {
1306         struct cmd_operate_detach_port_result *res = parsed_result;
1307
1308         if (!strcmp(res->keyword, "detach"))
1309                 detach_port(res->port_id);
1310         else
1311                 printf("Unknown parameter\n");
1312 }
1313
1314 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1315         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1316                         port, "port");
1317 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1318         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1319                         keyword, "detach");
1320 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1321         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1322                         port_id, UINT16);
1323
1324 cmdline_parse_inst_t cmd_operate_detach_port = {
1325         .f = cmd_operate_detach_port_parsed,
1326         .data = NULL,
1327         .help_str = "port detach <port_id>",
1328         .tokens = {
1329                 (void *)&cmd_operate_detach_port_port,
1330                 (void *)&cmd_operate_detach_port_keyword,
1331                 (void *)&cmd_operate_detach_port_port_id,
1332                 NULL,
1333         },
1334 };
1335
1336 /* *** configure speed for all ports *** */
1337 struct cmd_config_speed_all {
1338         cmdline_fixed_string_t port;
1339         cmdline_fixed_string_t keyword;
1340         cmdline_fixed_string_t all;
1341         cmdline_fixed_string_t item1;
1342         cmdline_fixed_string_t item2;
1343         cmdline_fixed_string_t value1;
1344         cmdline_fixed_string_t value2;
1345 };
1346
1347 static int
1348 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1349 {
1350
1351         int duplex;
1352
1353         if (!strcmp(duplexstr, "half")) {
1354                 duplex = ETH_LINK_HALF_DUPLEX;
1355         } else if (!strcmp(duplexstr, "full")) {
1356                 duplex = ETH_LINK_FULL_DUPLEX;
1357         } else if (!strcmp(duplexstr, "auto")) {
1358                 duplex = ETH_LINK_FULL_DUPLEX;
1359         } else {
1360                 printf("Unknown duplex parameter\n");
1361                 return -1;
1362         }
1363
1364         if (!strcmp(speedstr, "10")) {
1365                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1366                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1367         } else if (!strcmp(speedstr, "100")) {
1368                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1369                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1370         } else {
1371                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1372                         printf("Invalid speed/duplex parameters\n");
1373                         return -1;
1374                 }
1375                 if (!strcmp(speedstr, "1000")) {
1376                         *speed = ETH_LINK_SPEED_1G;
1377                 } else if (!strcmp(speedstr, "10000")) {
1378                         *speed = ETH_LINK_SPEED_10G;
1379                 } else if (!strcmp(speedstr, "25000")) {
1380                         *speed = ETH_LINK_SPEED_25G;
1381                 } else if (!strcmp(speedstr, "40000")) {
1382                         *speed = ETH_LINK_SPEED_40G;
1383                 } else if (!strcmp(speedstr, "50000")) {
1384                         *speed = ETH_LINK_SPEED_50G;
1385                 } else if (!strcmp(speedstr, "100000")) {
1386                         *speed = ETH_LINK_SPEED_100G;
1387                 } else if (!strcmp(speedstr, "auto")) {
1388                         *speed = ETH_LINK_SPEED_AUTONEG;
1389                 } else {
1390                         printf("Unknown speed parameter\n");
1391                         return -1;
1392                 }
1393         }
1394
1395         return 0;
1396 }
1397
1398 static void
1399 cmd_config_speed_all_parsed(void *parsed_result,
1400                         __attribute__((unused)) struct cmdline *cl,
1401                         __attribute__((unused)) void *data)
1402 {
1403         struct cmd_config_speed_all *res = parsed_result;
1404         uint32_t link_speed;
1405         portid_t pid;
1406
1407         if (!all_ports_stopped()) {
1408                 printf("Please stop all ports first\n");
1409                 return;
1410         }
1411
1412         if (parse_and_check_speed_duplex(res->value1, res->value2,
1413                         &link_speed) < 0)
1414                 return;
1415
1416         RTE_ETH_FOREACH_DEV(pid) {
1417                 ports[pid].dev_conf.link_speeds = link_speed;
1418         }
1419
1420         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1421 }
1422
1423 cmdline_parse_token_string_t cmd_config_speed_all_port =
1424         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1425 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1426         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1427                                                         "config");
1428 cmdline_parse_token_string_t cmd_config_speed_all_all =
1429         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1430 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1431         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1432 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1433         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1434                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1435 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1436         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1437 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1438         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1439                                                 "half#full#auto");
1440
1441 cmdline_parse_inst_t cmd_config_speed_all = {
1442         .f = cmd_config_speed_all_parsed,
1443         .data = NULL,
1444         .help_str = "port config all speed "
1445                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1446                                                         "half|full|auto",
1447         .tokens = {
1448                 (void *)&cmd_config_speed_all_port,
1449                 (void *)&cmd_config_speed_all_keyword,
1450                 (void *)&cmd_config_speed_all_all,
1451                 (void *)&cmd_config_speed_all_item1,
1452                 (void *)&cmd_config_speed_all_value1,
1453                 (void *)&cmd_config_speed_all_item2,
1454                 (void *)&cmd_config_speed_all_value2,
1455                 NULL,
1456         },
1457 };
1458
1459 /* *** configure speed for specific port *** */
1460 struct cmd_config_speed_specific {
1461         cmdline_fixed_string_t port;
1462         cmdline_fixed_string_t keyword;
1463         portid_t id;
1464         cmdline_fixed_string_t item1;
1465         cmdline_fixed_string_t item2;
1466         cmdline_fixed_string_t value1;
1467         cmdline_fixed_string_t value2;
1468 };
1469
1470 static void
1471 cmd_config_speed_specific_parsed(void *parsed_result,
1472                                 __attribute__((unused)) struct cmdline *cl,
1473                                 __attribute__((unused)) void *data)
1474 {
1475         struct cmd_config_speed_specific *res = parsed_result;
1476         uint32_t link_speed;
1477
1478         if (!all_ports_stopped()) {
1479                 printf("Please stop all ports first\n");
1480                 return;
1481         }
1482
1483         if (port_id_is_invalid(res->id, ENABLED_WARN))
1484                 return;
1485
1486         if (parse_and_check_speed_duplex(res->value1, res->value2,
1487                         &link_speed) < 0)
1488                 return;
1489
1490         ports[res->id].dev_conf.link_speeds = link_speed;
1491
1492         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1493 }
1494
1495
1496 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1497         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1498                                                                 "port");
1499 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1500         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1501                                                                 "config");
1502 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1503         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1504 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1505         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1506                                                                 "speed");
1507 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1508         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1509                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1510 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1511         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1512                                                                 "duplex");
1513 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1514         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1515                                                         "half#full#auto");
1516
1517 cmdline_parse_inst_t cmd_config_speed_specific = {
1518         .f = cmd_config_speed_specific_parsed,
1519         .data = NULL,
1520         .help_str = "port config <port_id> speed "
1521                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1522                                                         "half|full|auto",
1523         .tokens = {
1524                 (void *)&cmd_config_speed_specific_port,
1525                 (void *)&cmd_config_speed_specific_keyword,
1526                 (void *)&cmd_config_speed_specific_id,
1527                 (void *)&cmd_config_speed_specific_item1,
1528                 (void *)&cmd_config_speed_specific_value1,
1529                 (void *)&cmd_config_speed_specific_item2,
1530                 (void *)&cmd_config_speed_specific_value2,
1531                 NULL,
1532         },
1533 };
1534
1535 /* *** configure loopback for all ports *** */
1536 struct cmd_config_loopback_all {
1537         cmdline_fixed_string_t port;
1538         cmdline_fixed_string_t keyword;
1539         cmdline_fixed_string_t all;
1540         cmdline_fixed_string_t item;
1541         uint32_t mode;
1542 };
1543
1544 static void
1545 cmd_config_loopback_all_parsed(void *parsed_result,
1546                         __attribute__((unused)) struct cmdline *cl,
1547                         __attribute__((unused)) void *data)
1548 {
1549         struct cmd_config_loopback_all *res = parsed_result;
1550         portid_t pid;
1551
1552         if (!all_ports_stopped()) {
1553                 printf("Please stop all ports first\n");
1554                 return;
1555         }
1556
1557         RTE_ETH_FOREACH_DEV(pid) {
1558                 ports[pid].dev_conf.lpbk_mode = res->mode;
1559         }
1560
1561         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1562 }
1563
1564 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1566 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1568                                                         "config");
1569 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1570         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1571 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1572         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1573                                                         "loopback");
1574 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1575         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1576
1577 cmdline_parse_inst_t cmd_config_loopback_all = {
1578         .f = cmd_config_loopback_all_parsed,
1579         .data = NULL,
1580         .help_str = "port config all loopback <mode>",
1581         .tokens = {
1582                 (void *)&cmd_config_loopback_all_port,
1583                 (void *)&cmd_config_loopback_all_keyword,
1584                 (void *)&cmd_config_loopback_all_all,
1585                 (void *)&cmd_config_loopback_all_item,
1586                 (void *)&cmd_config_loopback_all_mode,
1587                 NULL,
1588         },
1589 };
1590
1591 /* *** configure loopback for specific port *** */
1592 struct cmd_config_loopback_specific {
1593         cmdline_fixed_string_t port;
1594         cmdline_fixed_string_t keyword;
1595         uint16_t port_id;
1596         cmdline_fixed_string_t item;
1597         uint32_t mode;
1598 };
1599
1600 static void
1601 cmd_config_loopback_specific_parsed(void *parsed_result,
1602                                 __attribute__((unused)) struct cmdline *cl,
1603                                 __attribute__((unused)) void *data)
1604 {
1605         struct cmd_config_loopback_specific *res = parsed_result;
1606
1607         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1608                 return;
1609
1610         if (!port_is_stopped(res->port_id)) {
1611                 printf("Please stop port %u first\n", res->port_id);
1612                 return;
1613         }
1614
1615         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1616
1617         cmd_reconfig_device_queue(res->port_id, 1, 1);
1618 }
1619
1620
1621 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1622         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1623                                                                 "port");
1624 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1625         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1626                                                                 "config");
1627 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1628         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1629                                                                 UINT16);
1630 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1632                                                                 "loopback");
1633 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1634         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1635                               UINT32);
1636
1637 cmdline_parse_inst_t cmd_config_loopback_specific = {
1638         .f = cmd_config_loopback_specific_parsed,
1639         .data = NULL,
1640         .help_str = "port config <port_id> loopback <mode>",
1641         .tokens = {
1642                 (void *)&cmd_config_loopback_specific_port,
1643                 (void *)&cmd_config_loopback_specific_keyword,
1644                 (void *)&cmd_config_loopback_specific_id,
1645                 (void *)&cmd_config_loopback_specific_item,
1646                 (void *)&cmd_config_loopback_specific_mode,
1647                 NULL,
1648         },
1649 };
1650
1651 /* *** configure txq/rxq, txd/rxd *** */
1652 struct cmd_config_rx_tx {
1653         cmdline_fixed_string_t port;
1654         cmdline_fixed_string_t keyword;
1655         cmdline_fixed_string_t all;
1656         cmdline_fixed_string_t name;
1657         uint16_t value;
1658 };
1659
1660 static void
1661 cmd_config_rx_tx_parsed(void *parsed_result,
1662                         __attribute__((unused)) struct cmdline *cl,
1663                         __attribute__((unused)) void *data)
1664 {
1665         struct cmd_config_rx_tx *res = parsed_result;
1666
1667         if (!all_ports_stopped()) {
1668                 printf("Please stop all ports first\n");
1669                 return;
1670         }
1671         if (!strcmp(res->name, "rxq")) {
1672                 if (!res->value && !nb_txq) {
1673                         printf("Warning: Either rx or tx queues should be non zero\n");
1674                         return;
1675                 }
1676                 if (check_nb_rxq(res->value) != 0)
1677                         return;
1678                 nb_rxq = res->value;
1679         }
1680         else if (!strcmp(res->name, "txq")) {
1681                 if (!res->value && !nb_rxq) {
1682                         printf("Warning: Either rx or tx queues should be non zero\n");
1683                         return;
1684                 }
1685                 if (check_nb_txq(res->value) != 0)
1686                         return;
1687                 nb_txq = res->value;
1688         }
1689         else if (!strcmp(res->name, "rxd")) {
1690                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1691                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1692                                         res->value, RTE_TEST_RX_DESC_MAX);
1693                         return;
1694                 }
1695                 nb_rxd = res->value;
1696         } else if (!strcmp(res->name, "txd")) {
1697                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1698                         printf("txd %d invalid - must be > 0 && <= %d\n",
1699                                         res->value, RTE_TEST_TX_DESC_MAX);
1700                         return;
1701                 }
1702                 nb_txd = res->value;
1703         } else {
1704                 printf("Unknown parameter\n");
1705                 return;
1706         }
1707
1708         fwd_config_setup();
1709
1710         init_port_config();
1711
1712         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1713 }
1714
1715 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1717 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1719 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1720         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1721 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1722         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1723                                                 "rxq#txq#rxd#txd");
1724 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1725         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1726
1727 cmdline_parse_inst_t cmd_config_rx_tx = {
1728         .f = cmd_config_rx_tx_parsed,
1729         .data = NULL,
1730         .help_str = "port config all rxq|txq|rxd|txd <value>",
1731         .tokens = {
1732                 (void *)&cmd_config_rx_tx_port,
1733                 (void *)&cmd_config_rx_tx_keyword,
1734                 (void *)&cmd_config_rx_tx_all,
1735                 (void *)&cmd_config_rx_tx_name,
1736                 (void *)&cmd_config_rx_tx_value,
1737                 NULL,
1738         },
1739 };
1740
1741 /* *** config max packet length *** */
1742 struct cmd_config_max_pkt_len_result {
1743         cmdline_fixed_string_t port;
1744         cmdline_fixed_string_t keyword;
1745         cmdline_fixed_string_t all;
1746         cmdline_fixed_string_t name;
1747         uint32_t value;
1748 };
1749
1750 static void
1751 cmd_config_max_pkt_len_parsed(void *parsed_result,
1752                                 __attribute__((unused)) struct cmdline *cl,
1753                                 __attribute__((unused)) void *data)
1754 {
1755         struct cmd_config_max_pkt_len_result *res = parsed_result;
1756         portid_t pid;
1757
1758         if (!all_ports_stopped()) {
1759                 printf("Please stop all ports first\n");
1760                 return;
1761         }
1762
1763         RTE_ETH_FOREACH_DEV(pid) {
1764                 struct rte_port *port = &ports[pid];
1765                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1766
1767                 if (!strcmp(res->name, "max-pkt-len")) {
1768                         if (res->value < ETHER_MIN_LEN) {
1769                                 printf("max-pkt-len can not be less than %d\n",
1770                                                 ETHER_MIN_LEN);
1771                                 return;
1772                         }
1773                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1774                                 return;
1775
1776                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1777                         if (res->value > ETHER_MAX_LEN)
1778                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1779                         else
1780                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1781                         port->dev_conf.rxmode.offloads = rx_offloads;
1782                 } else {
1783                         printf("Unknown parameter\n");
1784                         return;
1785                 }
1786         }
1787
1788         init_port_config();
1789
1790         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1791 }
1792
1793 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1795                                                                 "port");
1796 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1798                                                                 "config");
1799 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1800         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1801                                                                 "all");
1802 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1803         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1804                                                                 "max-pkt-len");
1805 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1806         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1807                                                                 UINT32);
1808
1809 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1810         .f = cmd_config_max_pkt_len_parsed,
1811         .data = NULL,
1812         .help_str = "port config all max-pkt-len <value>",
1813         .tokens = {
1814                 (void *)&cmd_config_max_pkt_len_port,
1815                 (void *)&cmd_config_max_pkt_len_keyword,
1816                 (void *)&cmd_config_max_pkt_len_all,
1817                 (void *)&cmd_config_max_pkt_len_name,
1818                 (void *)&cmd_config_max_pkt_len_value,
1819                 NULL,
1820         },
1821 };
1822
1823 /* *** configure port MTU *** */
1824 struct cmd_config_mtu_result {
1825         cmdline_fixed_string_t port;
1826         cmdline_fixed_string_t keyword;
1827         cmdline_fixed_string_t mtu;
1828         portid_t port_id;
1829         uint16_t value;
1830 };
1831
1832 static void
1833 cmd_config_mtu_parsed(void *parsed_result,
1834                       __attribute__((unused)) struct cmdline *cl,
1835                       __attribute__((unused)) void *data)
1836 {
1837         struct cmd_config_mtu_result *res = parsed_result;
1838
1839         if (res->value < ETHER_MIN_LEN) {
1840                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1841                 return;
1842         }
1843         port_mtu_set(res->port_id, res->value);
1844 }
1845
1846 cmdline_parse_token_string_t cmd_config_mtu_port =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1848                                  "port");
1849 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1851                                  "config");
1852 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1854                                  "mtu");
1855 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1856         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1857 cmdline_parse_token_num_t cmd_config_mtu_value =
1858         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1859
1860 cmdline_parse_inst_t cmd_config_mtu = {
1861         .f = cmd_config_mtu_parsed,
1862         .data = NULL,
1863         .help_str = "port config mtu <port_id> <value>",
1864         .tokens = {
1865                 (void *)&cmd_config_mtu_port,
1866                 (void *)&cmd_config_mtu_keyword,
1867                 (void *)&cmd_config_mtu_mtu,
1868                 (void *)&cmd_config_mtu_port_id,
1869                 (void *)&cmd_config_mtu_value,
1870                 NULL,
1871         },
1872 };
1873
1874 /* *** configure rx mode *** */
1875 struct cmd_config_rx_mode_flag {
1876         cmdline_fixed_string_t port;
1877         cmdline_fixed_string_t keyword;
1878         cmdline_fixed_string_t all;
1879         cmdline_fixed_string_t name;
1880         cmdline_fixed_string_t value;
1881 };
1882
1883 static void
1884 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1885                                 __attribute__((unused)) struct cmdline *cl,
1886                                 __attribute__((unused)) void *data)
1887 {
1888         struct cmd_config_rx_mode_flag *res = parsed_result;
1889         portid_t pid;
1890
1891         if (!all_ports_stopped()) {
1892                 printf("Please stop all ports first\n");
1893                 return;
1894         }
1895
1896         RTE_ETH_FOREACH_DEV(pid) {
1897                 struct rte_port *port;
1898                 uint64_t rx_offloads;
1899
1900                 port = &ports[pid];
1901                 rx_offloads = port->dev_conf.rxmode.offloads;
1902                 if (!strcmp(res->name, "crc-strip")) {
1903                         if (!strcmp(res->value, "on"))
1904                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1905                         else if (!strcmp(res->value, "off"))
1906                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1907                         else {
1908                                 printf("Unknown parameter\n");
1909                                 return;
1910                         }
1911                 } else if (!strcmp(res->name, "scatter")) {
1912                         if (!strcmp(res->value, "on")) {
1913                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1914                         } else if (!strcmp(res->value, "off")) {
1915                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1916                         } else {
1917                                 printf("Unknown parameter\n");
1918                                 return;
1919                         }
1920                 } else if (!strcmp(res->name, "rx-cksum")) {
1921                         if (!strcmp(res->value, "on"))
1922                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1923                         else if (!strcmp(res->value, "off"))
1924                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1925                         else {
1926                                 printf("Unknown parameter\n");
1927                                 return;
1928                         }
1929                 } else if (!strcmp(res->name, "rx-timestamp")) {
1930                         if (!strcmp(res->value, "on"))
1931                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1932                         else if (!strcmp(res->value, "off"))
1933                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1934                         else {
1935                                 printf("Unknown parameter\n");
1936                                 return;
1937                         }
1938                 } else if (!strcmp(res->name, "hw-vlan")) {
1939                         if (!strcmp(res->value, "on")) {
1940                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1941                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1942                         } else if (!strcmp(res->value, "off")) {
1943                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1944                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1945                         } else {
1946                                 printf("Unknown parameter\n");
1947                                 return;
1948                         }
1949                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1950                         if (!strcmp(res->value, "on"))
1951                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1952                         else if (!strcmp(res->value, "off"))
1953                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1954                         else {
1955                                 printf("Unknown parameter\n");
1956                                 return;
1957                         }
1958                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1959                         if (!strcmp(res->value, "on"))
1960                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1961                         else if (!strcmp(res->value, "off"))
1962                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1963                         else {
1964                                 printf("Unknown parameter\n");
1965                                 return;
1966                         }
1967                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1968                         if (!strcmp(res->value, "on"))
1969                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1970                         else if (!strcmp(res->value, "off"))
1971                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1972                         else {
1973                                 printf("Unknown parameter\n");
1974                                 return;
1975                         }
1976                 } else if (!strcmp(res->name, "drop-en")) {
1977                         if (!strcmp(res->value, "on"))
1978                                 rx_drop_en = 1;
1979                         else if (!strcmp(res->value, "off"))
1980                                 rx_drop_en = 0;
1981                         else {
1982                                 printf("Unknown parameter\n");
1983                                 return;
1984                         }
1985                 } else {
1986                         printf("Unknown parameter\n");
1987                         return;
1988                 }
1989                 port->dev_conf.rxmode.offloads = rx_offloads;
1990         }
1991
1992         init_port_config();
1993
1994         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1995 }
1996
1997 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1998         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1999 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2001                                                                 "config");
2002 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2003         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2004 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2005         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2006                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2007                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2008 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2009         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2010                                                         "on#off");
2011
2012 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2013         .f = cmd_config_rx_mode_flag_parsed,
2014         .data = NULL,
2015         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2016                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2017         .tokens = {
2018                 (void *)&cmd_config_rx_mode_flag_port,
2019                 (void *)&cmd_config_rx_mode_flag_keyword,
2020                 (void *)&cmd_config_rx_mode_flag_all,
2021                 (void *)&cmd_config_rx_mode_flag_name,
2022                 (void *)&cmd_config_rx_mode_flag_value,
2023                 NULL,
2024         },
2025 };
2026
2027 /* *** configure rss *** */
2028 struct cmd_config_rss {
2029         cmdline_fixed_string_t port;
2030         cmdline_fixed_string_t keyword;
2031         cmdline_fixed_string_t all;
2032         cmdline_fixed_string_t name;
2033         cmdline_fixed_string_t value;
2034 };
2035
2036 static void
2037 cmd_config_rss_parsed(void *parsed_result,
2038                         __attribute__((unused)) struct cmdline *cl,
2039                         __attribute__((unused)) void *data)
2040 {
2041         struct cmd_config_rss *res = parsed_result;
2042         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2043         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2044         int use_default = 0;
2045         int all_updated = 1;
2046         int diag;
2047         uint16_t i;
2048
2049         if (!strcmp(res->value, "all"))
2050                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2051                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2052                                         ETH_RSS_L2_PAYLOAD;
2053         else if (!strcmp(res->value, "ip"))
2054                 rss_conf.rss_hf = ETH_RSS_IP;
2055         else if (!strcmp(res->value, "udp"))
2056                 rss_conf.rss_hf = ETH_RSS_UDP;
2057         else if (!strcmp(res->value, "tcp"))
2058                 rss_conf.rss_hf = ETH_RSS_TCP;
2059         else if (!strcmp(res->value, "sctp"))
2060                 rss_conf.rss_hf = ETH_RSS_SCTP;
2061         else if (!strcmp(res->value, "ether"))
2062                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2063         else if (!strcmp(res->value, "port"))
2064                 rss_conf.rss_hf = ETH_RSS_PORT;
2065         else if (!strcmp(res->value, "vxlan"))
2066                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2067         else if (!strcmp(res->value, "geneve"))
2068                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2069         else if (!strcmp(res->value, "nvgre"))
2070                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2071         else if (!strcmp(res->value, "none"))
2072                 rss_conf.rss_hf = 0;
2073         else if (!strcmp(res->value, "default"))
2074                 use_default = 1;
2075         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2076                                                 atoi(res->value) < 64)
2077                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2078         else {
2079                 printf("Unknown parameter\n");
2080                 return;
2081         }
2082         rss_conf.rss_key = NULL;
2083         /* Update global configuration for RSS types. */
2084         RTE_ETH_FOREACH_DEV(i) {
2085                 struct rte_eth_rss_conf local_rss_conf;
2086
2087                 rte_eth_dev_info_get(i, &dev_info);
2088                 if (use_default)
2089                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2090
2091                 local_rss_conf = rss_conf;
2092                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2093                         dev_info.flow_type_rss_offloads;
2094                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2095                         printf("Port %u modified RSS hash function based on hardware support,"
2096                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2097                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2098                 }
2099                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2100                 if (diag < 0) {
2101                         all_updated = 0;
2102                         printf("Configuration of RSS hash at ethernet port %d "
2103                                 "failed with error (%d): %s.\n",
2104                                 i, -diag, strerror(-diag));
2105                 }
2106         }
2107         if (all_updated && !use_default)
2108                 rss_hf = rss_conf.rss_hf;
2109 }
2110
2111 cmdline_parse_token_string_t cmd_config_rss_port =
2112         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2113 cmdline_parse_token_string_t cmd_config_rss_keyword =
2114         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2115 cmdline_parse_token_string_t cmd_config_rss_all =
2116         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2117 cmdline_parse_token_string_t cmd_config_rss_name =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2119 cmdline_parse_token_string_t cmd_config_rss_value =
2120         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2121
2122 cmdline_parse_inst_t cmd_config_rss = {
2123         .f = cmd_config_rss_parsed,
2124         .data = NULL,
2125         .help_str = "port config all rss "
2126                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2127         .tokens = {
2128                 (void *)&cmd_config_rss_port,
2129                 (void *)&cmd_config_rss_keyword,
2130                 (void *)&cmd_config_rss_all,
2131                 (void *)&cmd_config_rss_name,
2132                 (void *)&cmd_config_rss_value,
2133                 NULL,
2134         },
2135 };
2136
2137 /* *** configure rss hash key *** */
2138 struct cmd_config_rss_hash_key {
2139         cmdline_fixed_string_t port;
2140         cmdline_fixed_string_t config;
2141         portid_t port_id;
2142         cmdline_fixed_string_t rss_hash_key;
2143         cmdline_fixed_string_t rss_type;
2144         cmdline_fixed_string_t key;
2145 };
2146
2147 static uint8_t
2148 hexa_digit_to_value(char hexa_digit)
2149 {
2150         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2151                 return (uint8_t) (hexa_digit - '0');
2152         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2153                 return (uint8_t) ((hexa_digit - 'a') + 10);
2154         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2155                 return (uint8_t) ((hexa_digit - 'A') + 10);
2156         /* Invalid hexa digit */
2157         return 0xFF;
2158 }
2159
2160 static uint8_t
2161 parse_and_check_key_hexa_digit(char *key, int idx)
2162 {
2163         uint8_t hexa_v;
2164
2165         hexa_v = hexa_digit_to_value(key[idx]);
2166         if (hexa_v == 0xFF)
2167                 printf("invalid key: character %c at position %d is not a "
2168                        "valid hexa digit\n", key[idx], idx);
2169         return hexa_v;
2170 }
2171
2172 static void
2173 cmd_config_rss_hash_key_parsed(void *parsed_result,
2174                                __attribute__((unused)) struct cmdline *cl,
2175                                __attribute__((unused)) void *data)
2176 {
2177         struct cmd_config_rss_hash_key *res = parsed_result;
2178         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2179         uint8_t xdgt0;
2180         uint8_t xdgt1;
2181         int i;
2182         struct rte_eth_dev_info dev_info;
2183         uint8_t hash_key_size;
2184         uint32_t key_len;
2185
2186         memset(&dev_info, 0, sizeof(dev_info));
2187         rte_eth_dev_info_get(res->port_id, &dev_info);
2188         if (dev_info.hash_key_size > 0 &&
2189                         dev_info.hash_key_size <= sizeof(hash_key))
2190                 hash_key_size = dev_info.hash_key_size;
2191         else {
2192                 printf("dev_info did not provide a valid hash key size\n");
2193                 return;
2194         }
2195         /* Check the length of the RSS hash key */
2196         key_len = strlen(res->key);
2197         if (key_len != (hash_key_size * 2)) {
2198                 printf("key length: %d invalid - key must be a string of %d"
2199                            " hexa-decimal numbers\n",
2200                            (int) key_len, hash_key_size * 2);
2201                 return;
2202         }
2203         /* Translate RSS hash key into binary representation */
2204         for (i = 0; i < hash_key_size; i++) {
2205                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2206                 if (xdgt0 == 0xFF)
2207                         return;
2208                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2209                 if (xdgt1 == 0xFF)
2210                         return;
2211                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2212         }
2213         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2214                         hash_key_size);
2215 }
2216
2217 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2218         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2219 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2220         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2221                                  "config");
2222 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2223         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2224 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2225         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2226                                  rss_hash_key, "rss-hash-key");
2227 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2228         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2229                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2230                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2231                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2232                                  "ipv6-tcp-ex#ipv6-udp-ex");
2233 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2234         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2235
2236 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2237         .f = cmd_config_rss_hash_key_parsed,
2238         .data = NULL,
2239         .help_str = "port config <port_id> rss-hash-key "
2240                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2241                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2242                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2243                 "<string of hex digits (variable length, NIC dependent)>",
2244         .tokens = {
2245                 (void *)&cmd_config_rss_hash_key_port,
2246                 (void *)&cmd_config_rss_hash_key_config,
2247                 (void *)&cmd_config_rss_hash_key_port_id,
2248                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2249                 (void *)&cmd_config_rss_hash_key_rss_type,
2250                 (void *)&cmd_config_rss_hash_key_value,
2251                 NULL,
2252         },
2253 };
2254
2255 /* *** configure port rxq/txq ring size *** */
2256 struct cmd_config_rxtx_ring_size {
2257         cmdline_fixed_string_t port;
2258         cmdline_fixed_string_t config;
2259         portid_t portid;
2260         cmdline_fixed_string_t rxtxq;
2261         uint16_t qid;
2262         cmdline_fixed_string_t rsize;
2263         uint16_t size;
2264 };
2265
2266 static void
2267 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2268                                  __attribute__((unused)) struct cmdline *cl,
2269                                  __attribute__((unused)) void *data)
2270 {
2271         struct cmd_config_rxtx_ring_size *res = parsed_result;
2272         struct rte_port *port;
2273         uint8_t isrx;
2274
2275         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2276                 return;
2277
2278         if (res->portid == (portid_t)RTE_PORT_ALL) {
2279                 printf("Invalid port id\n");
2280                 return;
2281         }
2282
2283         port = &ports[res->portid];
2284
2285         if (!strcmp(res->rxtxq, "rxq"))
2286                 isrx = 1;
2287         else if (!strcmp(res->rxtxq, "txq"))
2288                 isrx = 0;
2289         else {
2290                 printf("Unknown parameter\n");
2291                 return;
2292         }
2293
2294         if (isrx && rx_queue_id_is_invalid(res->qid))
2295                 return;
2296         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2297                 return;
2298
2299         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2300                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2301                        rx_free_thresh);
2302                 return;
2303         }
2304
2305         if (isrx)
2306                 port->nb_rx_desc[res->qid] = res->size;
2307         else
2308                 port->nb_tx_desc[res->qid] = res->size;
2309
2310         cmd_reconfig_device_queue(res->portid, 0, 1);
2311 }
2312
2313 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2314         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2315                                  port, "port");
2316 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2317         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2318                                  config, "config");
2319 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2320         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2321                                  portid, UINT16);
2322 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2323         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2324                                  rxtxq, "rxq#txq");
2325 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2326         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2327                               qid, UINT16);
2328 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2329         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2330                                  rsize, "ring_size");
2331 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2332         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2333                               size, UINT16);
2334
2335 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2336         .f = cmd_config_rxtx_ring_size_parsed,
2337         .data = NULL,
2338         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2339         .tokens = {
2340                 (void *)&cmd_config_rxtx_ring_size_port,
2341                 (void *)&cmd_config_rxtx_ring_size_config,
2342                 (void *)&cmd_config_rxtx_ring_size_portid,
2343                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2344                 (void *)&cmd_config_rxtx_ring_size_qid,
2345                 (void *)&cmd_config_rxtx_ring_size_rsize,
2346                 (void *)&cmd_config_rxtx_ring_size_size,
2347                 NULL,
2348         },
2349 };
2350
2351 /* *** configure port rxq/txq start/stop *** */
2352 struct cmd_config_rxtx_queue {
2353         cmdline_fixed_string_t port;
2354         portid_t portid;
2355         cmdline_fixed_string_t rxtxq;
2356         uint16_t qid;
2357         cmdline_fixed_string_t opname;
2358 };
2359
2360 static void
2361 cmd_config_rxtx_queue_parsed(void *parsed_result,
2362                         __attribute__((unused)) struct cmdline *cl,
2363                         __attribute__((unused)) void *data)
2364 {
2365         struct cmd_config_rxtx_queue *res = parsed_result;
2366         uint8_t isrx;
2367         uint8_t isstart;
2368         int ret = 0;
2369
2370         if (test_done == 0) {
2371                 printf("Please stop forwarding first\n");
2372                 return;
2373         }
2374
2375         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2376                 return;
2377
2378         if (port_is_started(res->portid) != 1) {
2379                 printf("Please start port %u first\n", res->portid);
2380                 return;
2381         }
2382
2383         if (!strcmp(res->rxtxq, "rxq"))
2384                 isrx = 1;
2385         else if (!strcmp(res->rxtxq, "txq"))
2386                 isrx = 0;
2387         else {
2388                 printf("Unknown parameter\n");
2389                 return;
2390         }
2391
2392         if (isrx && rx_queue_id_is_invalid(res->qid))
2393                 return;
2394         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2395                 return;
2396
2397         if (!strcmp(res->opname, "start"))
2398                 isstart = 1;
2399         else if (!strcmp(res->opname, "stop"))
2400                 isstart = 0;
2401         else {
2402                 printf("Unknown parameter\n");
2403                 return;
2404         }
2405
2406         if (isstart && isrx)
2407                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2408         else if (!isstart && isrx)
2409                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2410         else if (isstart && !isrx)
2411                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2412         else
2413                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2414
2415         if (ret == -ENOTSUP)
2416                 printf("Function not supported in PMD driver\n");
2417 }
2418
2419 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2420         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2421 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2422         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2423 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2424         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2425 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2426         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2427 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2428         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2429                                                 "start#stop");
2430
2431 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2432         .f = cmd_config_rxtx_queue_parsed,
2433         .data = NULL,
2434         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2435         .tokens = {
2436                 (void *)&cmd_config_rxtx_queue_port,
2437                 (void *)&cmd_config_rxtx_queue_portid,
2438                 (void *)&cmd_config_rxtx_queue_rxtxq,
2439                 (void *)&cmd_config_rxtx_queue_qid,
2440                 (void *)&cmd_config_rxtx_queue_opname,
2441                 NULL,
2442         },
2443 };
2444
2445 /* *** configure port rxq/txq setup *** */
2446 struct cmd_setup_rxtx_queue {
2447         cmdline_fixed_string_t port;
2448         portid_t portid;
2449         cmdline_fixed_string_t rxtxq;
2450         uint16_t qid;
2451         cmdline_fixed_string_t setup;
2452 };
2453
2454 /* Common CLI fields for queue setup */
2455 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2456         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2457 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2458         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2459 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2460         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2461 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2462         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2463 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2464         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2465
2466 static void
2467 cmd_setup_rxtx_queue_parsed(
2468         void *parsed_result,
2469         __attribute__((unused)) struct cmdline *cl,
2470         __attribute__((unused)) void *data)
2471 {
2472         struct cmd_setup_rxtx_queue *res = parsed_result;
2473         struct rte_port *port;
2474         struct rte_mempool *mp;
2475         unsigned int socket_id;
2476         uint8_t isrx = 0;
2477         int ret;
2478
2479         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2480                 return;
2481
2482         if (res->portid == (portid_t)RTE_PORT_ALL) {
2483                 printf("Invalid port id\n");
2484                 return;
2485         }
2486
2487         if (!strcmp(res->rxtxq, "rxq"))
2488                 isrx = 1;
2489         else if (!strcmp(res->rxtxq, "txq"))
2490                 isrx = 0;
2491         else {
2492                 printf("Unknown parameter\n");
2493                 return;
2494         }
2495
2496         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2497                 printf("Invalid rx queue\n");
2498                 return;
2499         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2500                 printf("Invalid tx queue\n");
2501                 return;
2502         }
2503
2504         port = &ports[res->portid];
2505         if (isrx) {
2506                 socket_id = rxring_numa[res->portid];
2507                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2508                         socket_id = port->socket_id;
2509
2510                 mp = mbuf_pool_find(socket_id);
2511                 if (mp == NULL) {
2512                         printf("Failed to setup RX queue: "
2513                                 "No mempool allocation"
2514                                 " on the socket %d\n",
2515                                 rxring_numa[res->portid]);
2516                         return;
2517                 }
2518                 ret = rte_eth_rx_queue_setup(res->portid,
2519                                              res->qid,
2520                                              port->nb_rx_desc[res->qid],
2521                                              socket_id,
2522                                              &port->rx_conf[res->qid],
2523                                              mp);
2524                 if (ret)
2525                         printf("Failed to setup RX queue\n");
2526         } else {
2527                 socket_id = txring_numa[res->portid];
2528                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2529                         socket_id = port->socket_id;
2530
2531                 ret = rte_eth_tx_queue_setup(res->portid,
2532                                              res->qid,
2533                                              port->nb_tx_desc[res->qid],
2534                                              socket_id,
2535                                              &port->tx_conf[res->qid]);
2536                 if (ret)
2537                         printf("Failed to setup TX queue\n");
2538         }
2539 }
2540
2541 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2542         .f = cmd_setup_rxtx_queue_parsed,
2543         .data = NULL,
2544         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2545         .tokens = {
2546                 (void *)&cmd_setup_rxtx_queue_port,
2547                 (void *)&cmd_setup_rxtx_queue_portid,
2548                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2549                 (void *)&cmd_setup_rxtx_queue_qid,
2550                 (void *)&cmd_setup_rxtx_queue_setup,
2551                 NULL,
2552         },
2553 };
2554
2555
2556 /* *** Configure RSS RETA *** */
2557 struct cmd_config_rss_reta {
2558         cmdline_fixed_string_t port;
2559         cmdline_fixed_string_t keyword;
2560         portid_t port_id;
2561         cmdline_fixed_string_t name;
2562         cmdline_fixed_string_t list_name;
2563         cmdline_fixed_string_t list_of_items;
2564 };
2565
2566 static int
2567 parse_reta_config(const char *str,
2568                   struct rte_eth_rss_reta_entry64 *reta_conf,
2569                   uint16_t nb_entries)
2570 {
2571         int i;
2572         unsigned size;
2573         uint16_t hash_index, idx, shift;
2574         uint16_t nb_queue;
2575         char s[256];
2576         const char *p, *p0 = str;
2577         char *end;
2578         enum fieldnames {
2579                 FLD_HASH_INDEX = 0,
2580                 FLD_QUEUE,
2581                 _NUM_FLD
2582         };
2583         unsigned long int_fld[_NUM_FLD];
2584         char *str_fld[_NUM_FLD];
2585
2586         while ((p = strchr(p0,'(')) != NULL) {
2587                 ++p;
2588                 if((p0 = strchr(p,')')) == NULL)
2589                         return -1;
2590
2591                 size = p0 - p;
2592                 if(size >= sizeof(s))
2593                         return -1;
2594
2595                 snprintf(s, sizeof(s), "%.*s", size, p);
2596                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2597                         return -1;
2598                 for (i = 0; i < _NUM_FLD; i++) {
2599                         errno = 0;
2600                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2601                         if (errno != 0 || end == str_fld[i] ||
2602                                         int_fld[i] > 65535)
2603                                 return -1;
2604                 }
2605
2606                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2607                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2608
2609                 if (hash_index >= nb_entries) {
2610                         printf("Invalid RETA hash index=%d\n", hash_index);
2611                         return -1;
2612                 }
2613
2614                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2615                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2616                 reta_conf[idx].mask |= (1ULL << shift);
2617                 reta_conf[idx].reta[shift] = nb_queue;
2618         }
2619
2620         return 0;
2621 }
2622
2623 static void
2624 cmd_set_rss_reta_parsed(void *parsed_result,
2625                         __attribute__((unused)) struct cmdline *cl,
2626                         __attribute__((unused)) void *data)
2627 {
2628         int ret;
2629         struct rte_eth_dev_info dev_info;
2630         struct rte_eth_rss_reta_entry64 reta_conf[8];
2631         struct cmd_config_rss_reta *res = parsed_result;
2632
2633         memset(&dev_info, 0, sizeof(dev_info));
2634         rte_eth_dev_info_get(res->port_id, &dev_info);
2635         if (dev_info.reta_size == 0) {
2636                 printf("Redirection table size is 0 which is "
2637                                         "invalid for RSS\n");
2638                 return;
2639         } else
2640                 printf("The reta size of port %d is %u\n",
2641                         res->port_id, dev_info.reta_size);
2642         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2643                 printf("Currently do not support more than %u entries of "
2644                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2645                 return;
2646         }
2647
2648         memset(reta_conf, 0, sizeof(reta_conf));
2649         if (!strcmp(res->list_name, "reta")) {
2650                 if (parse_reta_config(res->list_of_items, reta_conf,
2651                                                 dev_info.reta_size)) {
2652                         printf("Invalid RSS Redirection Table "
2653                                         "config entered\n");
2654                         return;
2655                 }
2656                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2657                                 reta_conf, dev_info.reta_size);
2658                 if (ret != 0)
2659                         printf("Bad redirection table parameter, "
2660                                         "return code = %d \n", ret);
2661         }
2662 }
2663
2664 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2665         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2666 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2667         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2668 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2669         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2670 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2671         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2672 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2673         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2674 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2675         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2676                                  NULL);
2677 cmdline_parse_inst_t cmd_config_rss_reta = {
2678         .f = cmd_set_rss_reta_parsed,
2679         .data = NULL,
2680         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2681         .tokens = {
2682                 (void *)&cmd_config_rss_reta_port,
2683                 (void *)&cmd_config_rss_reta_keyword,
2684                 (void *)&cmd_config_rss_reta_port_id,
2685                 (void *)&cmd_config_rss_reta_name,
2686                 (void *)&cmd_config_rss_reta_list_name,
2687                 (void *)&cmd_config_rss_reta_list_of_items,
2688                 NULL,
2689         },
2690 };
2691
2692 /* *** SHOW PORT RETA INFO *** */
2693 struct cmd_showport_reta {
2694         cmdline_fixed_string_t show;
2695         cmdline_fixed_string_t port;
2696         portid_t port_id;
2697         cmdline_fixed_string_t rss;
2698         cmdline_fixed_string_t reta;
2699         uint16_t size;
2700         cmdline_fixed_string_t list_of_items;
2701 };
2702
2703 static int
2704 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2705                            uint16_t nb_entries,
2706                            char *str)
2707 {
2708         uint32_t size;
2709         const char *p, *p0 = str;
2710         char s[256];
2711         char *end;
2712         char *str_fld[8];
2713         uint16_t i;
2714         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2715                         RTE_RETA_GROUP_SIZE;
2716         int ret;
2717
2718         p = strchr(p0, '(');
2719         if (p == NULL)
2720                 return -1;
2721         p++;
2722         p0 = strchr(p, ')');
2723         if (p0 == NULL)
2724                 return -1;
2725         size = p0 - p;
2726         if (size >= sizeof(s)) {
2727                 printf("The string size exceeds the internal buffer size\n");
2728                 return -1;
2729         }
2730         snprintf(s, sizeof(s), "%.*s", size, p);
2731         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2732         if (ret <= 0 || ret != num) {
2733                 printf("The bits of masks do not match the number of "
2734                                         "reta entries: %u\n", num);
2735                 return -1;
2736         }
2737         for (i = 0; i < ret; i++)
2738                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2739
2740         return 0;
2741 }
2742
2743 static void
2744 cmd_showport_reta_parsed(void *parsed_result,
2745                          __attribute__((unused)) struct cmdline *cl,
2746                          __attribute__((unused)) void *data)
2747 {
2748         struct cmd_showport_reta *res = parsed_result;
2749         struct rte_eth_rss_reta_entry64 reta_conf[8];
2750         struct rte_eth_dev_info dev_info;
2751         uint16_t max_reta_size;
2752
2753         memset(&dev_info, 0, sizeof(dev_info));
2754         rte_eth_dev_info_get(res->port_id, &dev_info);
2755         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2756         if (res->size == 0 || res->size > max_reta_size) {
2757                 printf("Invalid redirection table size: %u (1-%u)\n",
2758                         res->size, max_reta_size);
2759                 return;
2760         }
2761
2762         memset(reta_conf, 0, sizeof(reta_conf));
2763         if (showport_parse_reta_config(reta_conf, res->size,
2764                                 res->list_of_items) < 0) {
2765                 printf("Invalid string: %s for reta masks\n",
2766                                         res->list_of_items);
2767                 return;
2768         }
2769         port_rss_reta_info(res->port_id, reta_conf, res->size);
2770 }
2771
2772 cmdline_parse_token_string_t cmd_showport_reta_show =
2773         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2774 cmdline_parse_token_string_t cmd_showport_reta_port =
2775         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2776 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2777         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2778 cmdline_parse_token_string_t cmd_showport_reta_rss =
2779         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2780 cmdline_parse_token_string_t cmd_showport_reta_reta =
2781         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2782 cmdline_parse_token_num_t cmd_showport_reta_size =
2783         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2784 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2785         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2786                                         list_of_items, NULL);
2787
2788 cmdline_parse_inst_t cmd_showport_reta = {
2789         .f = cmd_showport_reta_parsed,
2790         .data = NULL,
2791         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2792         .tokens = {
2793                 (void *)&cmd_showport_reta_show,
2794                 (void *)&cmd_showport_reta_port,
2795                 (void *)&cmd_showport_reta_port_id,
2796                 (void *)&cmd_showport_reta_rss,
2797                 (void *)&cmd_showport_reta_reta,
2798                 (void *)&cmd_showport_reta_size,
2799                 (void *)&cmd_showport_reta_list_of_items,
2800                 NULL,
2801         },
2802 };
2803
2804 /* *** Show RSS hash configuration *** */
2805 struct cmd_showport_rss_hash {
2806         cmdline_fixed_string_t show;
2807         cmdline_fixed_string_t port;
2808         portid_t port_id;
2809         cmdline_fixed_string_t rss_hash;
2810         cmdline_fixed_string_t rss_type;
2811         cmdline_fixed_string_t key; /* optional argument */
2812 };
2813
2814 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2815                                 __attribute__((unused)) struct cmdline *cl,
2816                                 void *show_rss_key)
2817 {
2818         struct cmd_showport_rss_hash *res = parsed_result;
2819
2820         port_rss_hash_conf_show(res->port_id, res->rss_type,
2821                                 show_rss_key != NULL);
2822 }
2823
2824 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2825         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2826 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2827         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2828 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2829         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2830 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2831         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2832                                  "rss-hash");
2833 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2834         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2835                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2836                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2837                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2838                                  "ipv6-tcp-ex#ipv6-udp-ex");
2839 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2840         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2841
2842 cmdline_parse_inst_t cmd_showport_rss_hash = {
2843         .f = cmd_showport_rss_hash_parsed,
2844         .data = NULL,
2845         .help_str = "show port <port_id> rss-hash "
2846                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2847                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2848                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2849         .tokens = {
2850                 (void *)&cmd_showport_rss_hash_show,
2851                 (void *)&cmd_showport_rss_hash_port,
2852                 (void *)&cmd_showport_rss_hash_port_id,
2853                 (void *)&cmd_showport_rss_hash_rss_hash,
2854                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2855                 NULL,
2856         },
2857 };
2858
2859 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2860         .f = cmd_showport_rss_hash_parsed,
2861         .data = (void *)1,
2862         .help_str = "show port <port_id> rss-hash "
2863                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2864                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2865                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2866         .tokens = {
2867                 (void *)&cmd_showport_rss_hash_show,
2868                 (void *)&cmd_showport_rss_hash_port,
2869                 (void *)&cmd_showport_rss_hash_port_id,
2870                 (void *)&cmd_showport_rss_hash_rss_hash,
2871                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2872                 (void *)&cmd_showport_rss_hash_rss_key,
2873                 NULL,
2874         },
2875 };
2876
2877 /* *** Configure DCB *** */
2878 struct cmd_config_dcb {
2879         cmdline_fixed_string_t port;
2880         cmdline_fixed_string_t config;
2881         portid_t port_id;
2882         cmdline_fixed_string_t dcb;
2883         cmdline_fixed_string_t vt;
2884         cmdline_fixed_string_t vt_en;
2885         uint8_t num_tcs;
2886         cmdline_fixed_string_t pfc;
2887         cmdline_fixed_string_t pfc_en;
2888 };
2889
2890 static void
2891 cmd_config_dcb_parsed(void *parsed_result,
2892                         __attribute__((unused)) struct cmdline *cl,
2893                         __attribute__((unused)) void *data)
2894 {
2895         struct cmd_config_dcb *res = parsed_result;
2896         portid_t port_id = res->port_id;
2897         struct rte_port *port;
2898         uint8_t pfc_en;
2899         int ret;
2900
2901         port = &ports[port_id];
2902         /** Check if the port is not started **/
2903         if (port->port_status != RTE_PORT_STOPPED) {
2904                 printf("Please stop port %d first\n", port_id);
2905                 return;
2906         }
2907
2908         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2909                 printf("The invalid number of traffic class,"
2910                         " only 4 or 8 allowed.\n");
2911                 return;
2912         }
2913
2914         if (nb_fwd_lcores < res->num_tcs) {
2915                 printf("nb_cores shouldn't be less than number of TCs.\n");
2916                 return;
2917         }
2918         if (!strncmp(res->pfc_en, "on", 2))
2919                 pfc_en = 1;
2920         else
2921                 pfc_en = 0;
2922
2923         /* DCB in VT mode */
2924         if (!strncmp(res->vt_en, "on", 2))
2925                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2926                                 (enum rte_eth_nb_tcs)res->num_tcs,
2927                                 pfc_en);
2928         else
2929                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2930                                 (enum rte_eth_nb_tcs)res->num_tcs,
2931                                 pfc_en);
2932
2933
2934         if (ret != 0) {
2935                 printf("Cannot initialize network ports.\n");
2936                 return;
2937         }
2938
2939         cmd_reconfig_device_queue(port_id, 1, 1);
2940 }
2941
2942 cmdline_parse_token_string_t cmd_config_dcb_port =
2943         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2944 cmdline_parse_token_string_t cmd_config_dcb_config =
2945         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2946 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2947         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2948 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2949         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2950 cmdline_parse_token_string_t cmd_config_dcb_vt =
2951         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2952 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2953         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2954 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2955         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2956 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2957         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2958 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2959         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2960
2961 cmdline_parse_inst_t cmd_config_dcb = {
2962         .f = cmd_config_dcb_parsed,
2963         .data = NULL,
2964         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2965         .tokens = {
2966                 (void *)&cmd_config_dcb_port,
2967                 (void *)&cmd_config_dcb_config,
2968                 (void *)&cmd_config_dcb_port_id,
2969                 (void *)&cmd_config_dcb_dcb,
2970                 (void *)&cmd_config_dcb_vt,
2971                 (void *)&cmd_config_dcb_vt_en,
2972                 (void *)&cmd_config_dcb_num_tcs,
2973                 (void *)&cmd_config_dcb_pfc,
2974                 (void *)&cmd_config_dcb_pfc_en,
2975                 NULL,
2976         },
2977 };
2978
2979 /* *** configure number of packets per burst *** */
2980 struct cmd_config_burst {
2981         cmdline_fixed_string_t port;
2982         cmdline_fixed_string_t keyword;
2983         cmdline_fixed_string_t all;
2984         cmdline_fixed_string_t name;
2985         uint16_t value;
2986 };
2987
2988 static void
2989 cmd_config_burst_parsed(void *parsed_result,
2990                         __attribute__((unused)) struct cmdline *cl,
2991                         __attribute__((unused)) void *data)
2992 {
2993         struct cmd_config_burst *res = parsed_result;
2994         struct rte_eth_dev_info dev_info;
2995         uint16_t rec_nb_pkts;
2996
2997         if (!all_ports_stopped()) {
2998                 printf("Please stop all ports first\n");
2999                 return;
3000         }
3001
3002         if (!strcmp(res->name, "burst")) {
3003                 if (res->value == 0) {
3004                         /* If user gives a value of zero, query the PMD for
3005                          * its recommended Rx burst size. Testpmd uses a single
3006                          * size for all ports, so assume all ports are the same
3007                          * NIC model and use the values from Port 0.
3008                          */
3009                         rte_eth_dev_info_get(0, &dev_info);
3010                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3011
3012                         if (rec_nb_pkts == 0) {
3013                                 printf("PMD does not recommend a burst size.\n"
3014                                         "User provided value must be between"
3015                                         " 1 and %d\n", MAX_PKT_BURST);
3016                                 return;
3017                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3018                                 printf("PMD recommended burst size of %d"
3019                                         " exceeds maximum value of %d\n",
3020                                         rec_nb_pkts, MAX_PKT_BURST);
3021                                 return;
3022                         }
3023                         printf("Using PMD-provided burst value of %d\n",
3024                                 rec_nb_pkts);
3025                         nb_pkt_per_burst = rec_nb_pkts;
3026                 } else if (res->value > MAX_PKT_BURST) {
3027                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3028                         return;
3029                 } else
3030                         nb_pkt_per_burst = res->value;
3031         } else {
3032                 printf("Unknown parameter\n");
3033                 return;
3034         }
3035
3036         init_port_config();
3037
3038         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3039 }
3040
3041 cmdline_parse_token_string_t cmd_config_burst_port =
3042         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3043 cmdline_parse_token_string_t cmd_config_burst_keyword =
3044         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3045 cmdline_parse_token_string_t cmd_config_burst_all =
3046         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3047 cmdline_parse_token_string_t cmd_config_burst_name =
3048         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3049 cmdline_parse_token_num_t cmd_config_burst_value =
3050         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3051
3052 cmdline_parse_inst_t cmd_config_burst = {
3053         .f = cmd_config_burst_parsed,
3054         .data = NULL,
3055         .help_str = "port config all burst <value>",
3056         .tokens = {
3057                 (void *)&cmd_config_burst_port,
3058                 (void *)&cmd_config_burst_keyword,
3059                 (void *)&cmd_config_burst_all,
3060                 (void *)&cmd_config_burst_name,
3061                 (void *)&cmd_config_burst_value,
3062                 NULL,
3063         },
3064 };
3065
3066 /* *** configure rx/tx queues *** */
3067 struct cmd_config_thresh {
3068         cmdline_fixed_string_t port;
3069         cmdline_fixed_string_t keyword;
3070         cmdline_fixed_string_t all;
3071         cmdline_fixed_string_t name;
3072         uint8_t value;
3073 };
3074
3075 static void
3076 cmd_config_thresh_parsed(void *parsed_result,
3077                         __attribute__((unused)) struct cmdline *cl,
3078                         __attribute__((unused)) void *data)
3079 {
3080         struct cmd_config_thresh *res = parsed_result;
3081
3082         if (!all_ports_stopped()) {
3083                 printf("Please stop all ports first\n");
3084                 return;
3085         }
3086
3087         if (!strcmp(res->name, "txpt"))
3088                 tx_pthresh = res->value;
3089         else if(!strcmp(res->name, "txht"))
3090                 tx_hthresh = res->value;
3091         else if(!strcmp(res->name, "txwt"))
3092                 tx_wthresh = res->value;
3093         else if(!strcmp(res->name, "rxpt"))
3094                 rx_pthresh = res->value;
3095         else if(!strcmp(res->name, "rxht"))
3096                 rx_hthresh = res->value;
3097         else if(!strcmp(res->name, "rxwt"))
3098                 rx_wthresh = res->value;
3099         else {
3100                 printf("Unknown parameter\n");
3101                 return;
3102         }
3103
3104         init_port_config();
3105
3106         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3107 }
3108
3109 cmdline_parse_token_string_t cmd_config_thresh_port =
3110         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3111 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3112         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3113 cmdline_parse_token_string_t cmd_config_thresh_all =
3114         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3115 cmdline_parse_token_string_t cmd_config_thresh_name =
3116         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3117                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3118 cmdline_parse_token_num_t cmd_config_thresh_value =
3119         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3120
3121 cmdline_parse_inst_t cmd_config_thresh = {
3122         .f = cmd_config_thresh_parsed,
3123         .data = NULL,
3124         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3125         .tokens = {
3126                 (void *)&cmd_config_thresh_port,
3127                 (void *)&cmd_config_thresh_keyword,
3128                 (void *)&cmd_config_thresh_all,
3129                 (void *)&cmd_config_thresh_name,
3130                 (void *)&cmd_config_thresh_value,
3131                 NULL,
3132         },
3133 };
3134
3135 /* *** configure free/rs threshold *** */
3136 struct cmd_config_threshold {
3137         cmdline_fixed_string_t port;
3138         cmdline_fixed_string_t keyword;
3139         cmdline_fixed_string_t all;
3140         cmdline_fixed_string_t name;
3141         uint16_t value;
3142 };
3143
3144 static void
3145 cmd_config_threshold_parsed(void *parsed_result,
3146                         __attribute__((unused)) struct cmdline *cl,
3147                         __attribute__((unused)) void *data)
3148 {
3149         struct cmd_config_threshold *res = parsed_result;
3150
3151         if (!all_ports_stopped()) {
3152                 printf("Please stop all ports first\n");
3153                 return;
3154         }
3155
3156         if (!strcmp(res->name, "txfreet"))
3157                 tx_free_thresh = res->value;
3158         else if (!strcmp(res->name, "txrst"))
3159                 tx_rs_thresh = res->value;
3160         else if (!strcmp(res->name, "rxfreet"))
3161                 rx_free_thresh = res->value;
3162         else {
3163                 printf("Unknown parameter\n");
3164                 return;
3165         }
3166
3167         init_port_config();
3168
3169         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3170 }
3171
3172 cmdline_parse_token_string_t cmd_config_threshold_port =
3173         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3174 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3175         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3176                                                                 "config");
3177 cmdline_parse_token_string_t cmd_config_threshold_all =
3178         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3179 cmdline_parse_token_string_t cmd_config_threshold_name =
3180         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3181                                                 "txfreet#txrst#rxfreet");
3182 cmdline_parse_token_num_t cmd_config_threshold_value =
3183         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3184
3185 cmdline_parse_inst_t cmd_config_threshold = {
3186         .f = cmd_config_threshold_parsed,
3187         .data = NULL,
3188         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3189         .tokens = {
3190                 (void *)&cmd_config_threshold_port,
3191                 (void *)&cmd_config_threshold_keyword,
3192                 (void *)&cmd_config_threshold_all,
3193                 (void *)&cmd_config_threshold_name,
3194                 (void *)&cmd_config_threshold_value,
3195                 NULL,
3196         },
3197 };
3198
3199 /* *** stop *** */
3200 struct cmd_stop_result {
3201         cmdline_fixed_string_t stop;
3202 };
3203
3204 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3205                             __attribute__((unused)) struct cmdline *cl,
3206                             __attribute__((unused)) void *data)
3207 {
3208         stop_packet_forwarding();
3209 }
3210
3211 cmdline_parse_token_string_t cmd_stop_stop =
3212         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3213
3214 cmdline_parse_inst_t cmd_stop = {
3215         .f = cmd_stop_parsed,
3216         .data = NULL,
3217         .help_str = "stop: Stop packet forwarding",
3218         .tokens = {
3219                 (void *)&cmd_stop_stop,
3220                 NULL,
3221         },
3222 };
3223
3224 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3225
3226 unsigned int
3227 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3228                 unsigned int *parsed_items, int check_unique_values)
3229 {
3230         unsigned int nb_item;
3231         unsigned int value;
3232         unsigned int i;
3233         unsigned int j;
3234         int value_ok;
3235         char c;
3236
3237         /*
3238          * First parse all items in the list and store their value.
3239          */
3240         value = 0;
3241         nb_item = 0;
3242         value_ok = 0;
3243         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3244                 c = str[i];
3245                 if ((c >= '0') && (c <= '9')) {
3246                         value = (unsigned int) (value * 10 + (c - '0'));
3247                         value_ok = 1;
3248                         continue;
3249                 }
3250                 if (c != ',') {
3251                         printf("character %c is not a decimal digit\n", c);
3252                         return 0;
3253                 }
3254                 if (! value_ok) {
3255                         printf("No valid value before comma\n");
3256                         return 0;
3257                 }
3258                 if (nb_item < max_items) {
3259                         parsed_items[nb_item] = value;
3260                         value_ok = 0;
3261                         value = 0;
3262                 }
3263                 nb_item++;
3264         }
3265         if (nb_item >= max_items) {
3266                 printf("Number of %s = %u > %u (maximum items)\n",
3267                        item_name, nb_item + 1, max_items);
3268                 return 0;
3269         }
3270         parsed_items[nb_item++] = value;
3271         if (! check_unique_values)
3272                 return nb_item;
3273
3274         /*
3275          * Then, check that all values in the list are differents.
3276          * No optimization here...
3277          */
3278         for (i = 0; i < nb_item; i++) {
3279                 for (j = i + 1; j < nb_item; j++) {
3280                         if (parsed_items[j] == parsed_items[i]) {
3281                                 printf("duplicated %s %u at index %u and %u\n",
3282                                        item_name, parsed_items[i], i, j);
3283                                 return 0;
3284                         }
3285                 }
3286         }
3287         return nb_item;
3288 }
3289
3290 struct cmd_set_list_result {
3291         cmdline_fixed_string_t cmd_keyword;
3292         cmdline_fixed_string_t list_name;
3293         cmdline_fixed_string_t list_of_items;
3294 };
3295
3296 static void cmd_set_list_parsed(void *parsed_result,
3297                                 __attribute__((unused)) struct cmdline *cl,
3298                                 __attribute__((unused)) void *data)
3299 {
3300         struct cmd_set_list_result *res;
3301         union {
3302                 unsigned int lcorelist[RTE_MAX_LCORE];
3303                 unsigned int portlist[RTE_MAX_ETHPORTS];
3304         } parsed_items;
3305         unsigned int nb_item;
3306
3307         if (test_done == 0) {
3308                 printf("Please stop forwarding first\n");
3309                 return;
3310         }
3311
3312         res = parsed_result;
3313         if (!strcmp(res->list_name, "corelist")) {
3314                 nb_item = parse_item_list(res->list_of_items, "core",
3315                                           RTE_MAX_LCORE,
3316                                           parsed_items.lcorelist, 1);
3317                 if (nb_item > 0) {
3318                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3319                         fwd_config_setup();
3320                 }
3321                 return;
3322         }
3323         if (!strcmp(res->list_name, "portlist")) {
3324                 nb_item = parse_item_list(res->list_of_items, "port",
3325                                           RTE_MAX_ETHPORTS,
3326                                           parsed_items.portlist, 1);
3327                 if (nb_item > 0) {
3328                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3329                         fwd_config_setup();
3330                 }
3331         }
3332 }
3333
3334 cmdline_parse_token_string_t cmd_set_list_keyword =
3335         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3336                                  "set");
3337 cmdline_parse_token_string_t cmd_set_list_name =
3338         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3339                                  "corelist#portlist");
3340 cmdline_parse_token_string_t cmd_set_list_of_items =
3341         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3342                                  NULL);
3343
3344 cmdline_parse_inst_t cmd_set_fwd_list = {
3345         .f = cmd_set_list_parsed,
3346         .data = NULL,
3347         .help_str = "set corelist|portlist <list0[,list1]*>",
3348         .tokens = {
3349                 (void *)&cmd_set_list_keyword,
3350                 (void *)&cmd_set_list_name,
3351                 (void *)&cmd_set_list_of_items,
3352                 NULL,
3353         },
3354 };
3355
3356 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3357
3358 struct cmd_setmask_result {
3359         cmdline_fixed_string_t set;
3360         cmdline_fixed_string_t mask;
3361         uint64_t hexavalue;
3362 };
3363
3364 static void cmd_set_mask_parsed(void *parsed_result,
3365                                 __attribute__((unused)) struct cmdline *cl,
3366                                 __attribute__((unused)) void *data)
3367 {
3368         struct cmd_setmask_result *res = parsed_result;
3369
3370         if (test_done == 0) {
3371                 printf("Please stop forwarding first\n");
3372                 return;
3373         }
3374         if (!strcmp(res->mask, "coremask")) {
3375                 set_fwd_lcores_mask(res->hexavalue);
3376                 fwd_config_setup();
3377         } else if (!strcmp(res->mask, "portmask")) {
3378                 set_fwd_ports_mask(res->hexavalue);
3379                 fwd_config_setup();
3380         }
3381 }
3382
3383 cmdline_parse_token_string_t cmd_setmask_set =
3384         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3385 cmdline_parse_token_string_t cmd_setmask_mask =
3386         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3387                                  "coremask#portmask");
3388 cmdline_parse_token_num_t cmd_setmask_value =
3389         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3390
3391 cmdline_parse_inst_t cmd_set_fwd_mask = {
3392         .f = cmd_set_mask_parsed,
3393         .data = NULL,
3394         .help_str = "set coremask|portmask <hexadecimal value>",
3395         .tokens = {
3396                 (void *)&cmd_setmask_set,
3397                 (void *)&cmd_setmask_mask,
3398                 (void *)&cmd_setmask_value,
3399                 NULL,
3400         },
3401 };
3402
3403 /*
3404  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3405  */
3406 struct cmd_set_result {
3407         cmdline_fixed_string_t set;
3408         cmdline_fixed_string_t what;
3409         uint16_t value;
3410 };
3411
3412 static void cmd_set_parsed(void *parsed_result,
3413                            __attribute__((unused)) struct cmdline *cl,
3414                            __attribute__((unused)) void *data)
3415 {
3416         struct cmd_set_result *res = parsed_result;
3417         if (!strcmp(res->what, "nbport")) {
3418                 set_fwd_ports_number(res->value);
3419                 fwd_config_setup();
3420         } else if (!strcmp(res->what, "nbcore")) {
3421                 set_fwd_lcores_number(res->value);
3422                 fwd_config_setup();
3423         } else if (!strcmp(res->what, "burst"))
3424                 set_nb_pkt_per_burst(res->value);
3425         else if (!strcmp(res->what, "verbose"))
3426                 set_verbose_level(res->value);
3427 }
3428
3429 cmdline_parse_token_string_t cmd_set_set =
3430         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3431 cmdline_parse_token_string_t cmd_set_what =
3432         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3433                                  "nbport#nbcore#burst#verbose");
3434 cmdline_parse_token_num_t cmd_set_value =
3435         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3436
3437 cmdline_parse_inst_t cmd_set_numbers = {
3438         .f = cmd_set_parsed,
3439         .data = NULL,
3440         .help_str = "set nbport|nbcore|burst|verbose <value>",
3441         .tokens = {
3442                 (void *)&cmd_set_set,
3443                 (void *)&cmd_set_what,
3444                 (void *)&cmd_set_value,
3445                 NULL,
3446         },
3447 };
3448
3449 /* *** SET LOG LEVEL CONFIGURATION *** */
3450
3451 struct cmd_set_log_result {
3452         cmdline_fixed_string_t set;
3453         cmdline_fixed_string_t log;
3454         cmdline_fixed_string_t type;
3455         uint32_t level;
3456 };
3457
3458 static void
3459 cmd_set_log_parsed(void *parsed_result,
3460                    __attribute__((unused)) struct cmdline *cl,
3461                    __attribute__((unused)) void *data)
3462 {
3463         struct cmd_set_log_result *res;
3464         int ret;
3465
3466         res = parsed_result;
3467         if (!strcmp(res->type, "global"))
3468                 rte_log_set_global_level(res->level);
3469         else {
3470                 ret = rte_log_set_level_regexp(res->type, res->level);
3471                 if (ret < 0)
3472                         printf("Unable to set log level\n");
3473         }
3474 }
3475
3476 cmdline_parse_token_string_t cmd_set_log_set =
3477         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3478 cmdline_parse_token_string_t cmd_set_log_log =
3479         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3480 cmdline_parse_token_string_t cmd_set_log_type =
3481         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3482 cmdline_parse_token_num_t cmd_set_log_level =
3483         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3484
3485 cmdline_parse_inst_t cmd_set_log = {
3486         .f = cmd_set_log_parsed,
3487         .data = NULL,
3488         .help_str = "set log global|<type> <level>",
3489         .tokens = {
3490                 (void *)&cmd_set_log_set,
3491                 (void *)&cmd_set_log_log,
3492                 (void *)&cmd_set_log_type,
3493                 (void *)&cmd_set_log_level,
3494                 NULL,
3495         },
3496 };
3497
3498 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3499
3500 struct cmd_set_txpkts_result {
3501         cmdline_fixed_string_t cmd_keyword;
3502         cmdline_fixed_string_t txpkts;
3503         cmdline_fixed_string_t seg_lengths;
3504 };
3505
3506 static void
3507 cmd_set_txpkts_parsed(void *parsed_result,
3508                       __attribute__((unused)) struct cmdline *cl,
3509                       __attribute__((unused)) void *data)
3510 {
3511         struct cmd_set_txpkts_result *res;
3512         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3513         unsigned int nb_segs;
3514
3515         res = parsed_result;
3516         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3517                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3518         if (nb_segs > 0)
3519                 set_tx_pkt_segments(seg_lengths, nb_segs);
3520 }
3521
3522 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3523         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3524                                  cmd_keyword, "set");
3525 cmdline_parse_token_string_t cmd_set_txpkts_name =
3526         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3527                                  txpkts, "txpkts");
3528 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3529         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3530                                  seg_lengths, NULL);
3531
3532 cmdline_parse_inst_t cmd_set_txpkts = {
3533         .f = cmd_set_txpkts_parsed,
3534         .data = NULL,
3535         .help_str = "set txpkts <len0[,len1]*>",
3536         .tokens = {
3537                 (void *)&cmd_set_txpkts_keyword,
3538                 (void *)&cmd_set_txpkts_name,
3539                 (void *)&cmd_set_txpkts_lengths,
3540                 NULL,
3541         },
3542 };
3543
3544 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3545
3546 struct cmd_set_txsplit_result {
3547         cmdline_fixed_string_t cmd_keyword;
3548         cmdline_fixed_string_t txsplit;
3549         cmdline_fixed_string_t mode;
3550 };
3551
3552 static void
3553 cmd_set_txsplit_parsed(void *parsed_result,
3554                       __attribute__((unused)) struct cmdline *cl,
3555                       __attribute__((unused)) void *data)
3556 {
3557         struct cmd_set_txsplit_result *res;
3558
3559         res = parsed_result;
3560         set_tx_pkt_split(res->mode);
3561 }
3562
3563 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3564         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3565                                  cmd_keyword, "set");
3566 cmdline_parse_token_string_t cmd_set_txsplit_name =
3567         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3568                                  txsplit, "txsplit");
3569 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3570         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3571                                  mode, NULL);
3572
3573 cmdline_parse_inst_t cmd_set_txsplit = {
3574         .f = cmd_set_txsplit_parsed,
3575         .data = NULL,
3576         .help_str = "set txsplit on|off|rand",
3577         .tokens = {
3578                 (void *)&cmd_set_txsplit_keyword,
3579                 (void *)&cmd_set_txsplit_name,
3580                 (void *)&cmd_set_txsplit_mode,
3581                 NULL,
3582         },
3583 };
3584
3585 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3586 struct cmd_rx_vlan_filter_all_result {
3587         cmdline_fixed_string_t rx_vlan;
3588         cmdline_fixed_string_t what;
3589         cmdline_fixed_string_t all;
3590         portid_t port_id;
3591 };
3592
3593 static void
3594 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3595                               __attribute__((unused)) struct cmdline *cl,
3596                               __attribute__((unused)) void *data)
3597 {
3598         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3599
3600         if (!strcmp(res->what, "add"))
3601                 rx_vlan_all_filter_set(res->port_id, 1);
3602         else
3603                 rx_vlan_all_filter_set(res->port_id, 0);
3604 }
3605
3606 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3607         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3608                                  rx_vlan, "rx_vlan");
3609 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3610         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3611                                  what, "add#rm");
3612 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3613         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3614                                  all, "all");
3615 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3616         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3617                               port_id, UINT16);
3618
3619 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3620         .f = cmd_rx_vlan_filter_all_parsed,
3621         .data = NULL,
3622         .help_str = "rx_vlan add|rm all <port_id>: "
3623                 "Add/Remove all identifiers to/from the set of VLAN "
3624                 "identifiers filtered by a port",
3625         .tokens = {
3626                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3627                 (void *)&cmd_rx_vlan_filter_all_what,
3628                 (void *)&cmd_rx_vlan_filter_all_all,
3629                 (void *)&cmd_rx_vlan_filter_all_portid,
3630                 NULL,
3631         },
3632 };
3633
3634 /* *** VLAN OFFLOAD SET ON A PORT *** */
3635 struct cmd_vlan_offload_result {
3636         cmdline_fixed_string_t vlan;
3637         cmdline_fixed_string_t set;
3638         cmdline_fixed_string_t vlan_type;
3639         cmdline_fixed_string_t what;
3640         cmdline_fixed_string_t on;
3641         cmdline_fixed_string_t port_id;
3642 };
3643
3644 static void
3645 cmd_vlan_offload_parsed(void *parsed_result,
3646                           __attribute__((unused)) struct cmdline *cl,
3647                           __attribute__((unused)) void *data)
3648 {
3649         int on;
3650         struct cmd_vlan_offload_result *res = parsed_result;
3651         char *str;
3652         int i, len = 0;
3653         portid_t port_id = 0;
3654         unsigned int tmp;
3655
3656         str = res->port_id;
3657         len = strnlen(str, STR_TOKEN_SIZE);
3658         i = 0;
3659         /* Get port_id first */
3660         while(i < len){
3661                 if(str[i] == ',')
3662                         break;
3663
3664                 i++;
3665         }
3666         str[i]='\0';
3667         tmp = strtoul(str, NULL, 0);
3668         /* If port_id greater that what portid_t can represent, return */
3669         if(tmp >= RTE_MAX_ETHPORTS)
3670                 return;
3671         port_id = (portid_t)tmp;
3672
3673         if (!strcmp(res->on, "on"))
3674                 on = 1;
3675         else
3676                 on = 0;
3677
3678         if (!strcmp(res->what, "strip"))
3679                 rx_vlan_strip_set(port_id,  on);
3680         else if(!strcmp(res->what, "stripq")){
3681                 uint16_t queue_id = 0;
3682
3683                 /* No queue_id, return */
3684                 if(i + 1 >= len) {
3685                         printf("must specify (port,queue_id)\n");
3686                         return;
3687                 }
3688                 tmp = strtoul(str + i + 1, NULL, 0);
3689                 /* If queue_id greater that what 16-bits can represent, return */
3690                 if(tmp > 0xffff)
3691                         return;
3692
3693                 queue_id = (uint16_t)tmp;
3694                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3695         }
3696         else if (!strcmp(res->what, "filter"))
3697                 rx_vlan_filter_set(port_id, on);
3698         else
3699                 vlan_extend_set(port_id, on);
3700
3701         return;
3702 }
3703
3704 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3705         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3706                                  vlan, "vlan");
3707 cmdline_parse_token_string_t cmd_vlan_offload_set =
3708         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3709                                  set, "set");
3710 cmdline_parse_token_string_t cmd_vlan_offload_what =
3711         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3712                                  what, "strip#filter#qinq#stripq");
3713 cmdline_parse_token_string_t cmd_vlan_offload_on =
3714         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3715                               on, "on#off");
3716 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3717         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3718                               port_id, NULL);
3719
3720 cmdline_parse_inst_t cmd_vlan_offload = {
3721         .f = cmd_vlan_offload_parsed,
3722         .data = NULL,
3723         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3724                 "<port_id[,queue_id]>: "
3725                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3726         .tokens = {
3727                 (void *)&cmd_vlan_offload_vlan,
3728                 (void *)&cmd_vlan_offload_set,
3729                 (void *)&cmd_vlan_offload_what,
3730                 (void *)&cmd_vlan_offload_on,
3731                 (void *)&cmd_vlan_offload_portid,
3732                 NULL,
3733         },
3734 };
3735
3736 /* *** VLAN TPID SET ON A PORT *** */
3737 struct cmd_vlan_tpid_result {
3738         cmdline_fixed_string_t vlan;
3739         cmdline_fixed_string_t set;
3740         cmdline_fixed_string_t vlan_type;
3741         cmdline_fixed_string_t what;
3742         uint16_t tp_id;
3743         portid_t port_id;
3744 };
3745
3746 static void
3747 cmd_vlan_tpid_parsed(void *parsed_result,
3748                           __attribute__((unused)) struct cmdline *cl,
3749                           __attribute__((unused)) void *data)
3750 {
3751         struct cmd_vlan_tpid_result *res = parsed_result;
3752         enum rte_vlan_type vlan_type;
3753
3754         if (!strcmp(res->vlan_type, "inner"))
3755                 vlan_type = ETH_VLAN_TYPE_INNER;
3756         else if (!strcmp(res->vlan_type, "outer"))
3757                 vlan_type = ETH_VLAN_TYPE_OUTER;
3758         else {
3759                 printf("Unknown vlan type\n");
3760                 return;
3761         }
3762         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3763 }
3764
3765 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3766         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3767                                  vlan, "vlan");
3768 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3769         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3770                                  set, "set");
3771 cmdline_parse_token_string_t cmd_vlan_type =
3772         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3773                                  vlan_type, "inner#outer");
3774 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3775         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3776                                  what, "tpid");
3777 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3778         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3779                               tp_id, UINT16);
3780 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3781         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3782                               port_id, UINT16);
3783
3784 cmdline_parse_inst_t cmd_vlan_tpid = {
3785         .f = cmd_vlan_tpid_parsed,
3786         .data = NULL,
3787         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3788                 "Set the VLAN Ether type",
3789         .tokens = {
3790                 (void *)&cmd_vlan_tpid_vlan,
3791                 (void *)&cmd_vlan_tpid_set,
3792                 (void *)&cmd_vlan_type,
3793                 (void *)&cmd_vlan_tpid_what,
3794                 (void *)&cmd_vlan_tpid_tpid,
3795                 (void *)&cmd_vlan_tpid_portid,
3796                 NULL,
3797         },
3798 };
3799
3800 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3801 struct cmd_rx_vlan_filter_result {
3802         cmdline_fixed_string_t rx_vlan;
3803         cmdline_fixed_string_t what;
3804         uint16_t vlan_id;
3805         portid_t port_id;
3806 };
3807
3808 static void
3809 cmd_rx_vlan_filter_parsed(void *parsed_result,
3810                           __attribute__((unused)) struct cmdline *cl,
3811                           __attribute__((unused)) void *data)
3812 {
3813         struct cmd_rx_vlan_filter_result *res = parsed_result;
3814
3815         if (!strcmp(res->what, "add"))
3816                 rx_vft_set(res->port_id, res->vlan_id, 1);
3817         else
3818                 rx_vft_set(res->port_id, res->vlan_id, 0);
3819 }
3820
3821 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3822         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3823                                  rx_vlan, "rx_vlan");
3824 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3825         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3826                                  what, "add#rm");
3827 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3828         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3829                               vlan_id, UINT16);
3830 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3831         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3832                               port_id, UINT16);
3833
3834 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3835         .f = cmd_rx_vlan_filter_parsed,
3836         .data = NULL,
3837         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3838                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3839                 "identifiers filtered by a port",
3840         .tokens = {
3841                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3842                 (void *)&cmd_rx_vlan_filter_what,
3843                 (void *)&cmd_rx_vlan_filter_vlanid,
3844                 (void *)&cmd_rx_vlan_filter_portid,
3845                 NULL,
3846         },
3847 };
3848
3849 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3850 struct cmd_tx_vlan_set_result {
3851         cmdline_fixed_string_t tx_vlan;
3852         cmdline_fixed_string_t set;
3853         portid_t port_id;
3854         uint16_t vlan_id;
3855 };
3856
3857 static void
3858 cmd_tx_vlan_set_parsed(void *parsed_result,
3859                        __attribute__((unused)) struct cmdline *cl,
3860                        __attribute__((unused)) void *data)
3861 {
3862         struct cmd_tx_vlan_set_result *res = parsed_result;
3863
3864         if (!port_is_stopped(res->port_id)) {
3865                 printf("Please stop port %d first\n", res->port_id);
3866                 return;
3867         }
3868
3869         tx_vlan_set(res->port_id, res->vlan_id);
3870
3871         cmd_reconfig_device_queue(res->port_id, 1, 1);
3872 }
3873
3874 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3875         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3876                                  tx_vlan, "tx_vlan");
3877 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3878         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3879                                  set, "set");
3880 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3881         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3882                               port_id, UINT16);
3883 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3884         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3885                               vlan_id, UINT16);
3886
3887 cmdline_parse_inst_t cmd_tx_vlan_set = {
3888         .f = cmd_tx_vlan_set_parsed,
3889         .data = NULL,
3890         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3891                 "Enable hardware insertion of a single VLAN header "
3892                 "with a given TAG Identifier in packets sent on a port",
3893         .tokens = {
3894                 (void *)&cmd_tx_vlan_set_tx_vlan,
3895                 (void *)&cmd_tx_vlan_set_set,
3896                 (void *)&cmd_tx_vlan_set_portid,
3897                 (void *)&cmd_tx_vlan_set_vlanid,
3898                 NULL,
3899         },
3900 };
3901
3902 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3903 struct cmd_tx_vlan_set_qinq_result {
3904         cmdline_fixed_string_t tx_vlan;
3905         cmdline_fixed_string_t set;
3906         portid_t port_id;
3907         uint16_t vlan_id;
3908         uint16_t vlan_id_outer;
3909 };
3910
3911 static void
3912 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3913                             __attribute__((unused)) struct cmdline *cl,
3914                             __attribute__((unused)) void *data)
3915 {
3916         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3917
3918         if (!port_is_stopped(res->port_id)) {
3919                 printf("Please stop port %d first\n", res->port_id);
3920                 return;
3921         }
3922
3923         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3924
3925         cmd_reconfig_device_queue(res->port_id, 1, 1);
3926 }
3927
3928 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3929         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3930                 tx_vlan, "tx_vlan");
3931 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3932         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3933                 set, "set");
3934 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3935         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3936                 port_id, UINT16);
3937 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3938         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3939                 vlan_id, UINT16);
3940 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3941         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3942                 vlan_id_outer, UINT16);
3943
3944 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3945         .f = cmd_tx_vlan_set_qinq_parsed,
3946         .data = NULL,
3947         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3948                 "Enable hardware insertion of double VLAN header "
3949                 "with given TAG Identifiers in packets sent on a port",
3950         .tokens = {
3951                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3952                 (void *)&cmd_tx_vlan_set_qinq_set,
3953                 (void *)&cmd_tx_vlan_set_qinq_portid,
3954                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3955                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3956                 NULL,
3957         },
3958 };
3959
3960 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3961 struct cmd_tx_vlan_set_pvid_result {
3962         cmdline_fixed_string_t tx_vlan;
3963         cmdline_fixed_string_t set;
3964         cmdline_fixed_string_t pvid;
3965         portid_t port_id;
3966         uint16_t vlan_id;
3967         cmdline_fixed_string_t mode;
3968 };
3969
3970 static void
3971 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3972                             __attribute__((unused)) struct cmdline *cl,
3973                             __attribute__((unused)) void *data)
3974 {
3975         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3976
3977         if (strcmp(res->mode, "on") == 0)
3978                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3979         else
3980                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3981 }
3982
3983 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3984         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3985                                  tx_vlan, "tx_vlan");
3986 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3987         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3988                                  set, "set");
3989 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3990         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3991                                  pvid, "pvid");
3992 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3993         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3994                              port_id, UINT16);
3995 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3996         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3997                               vlan_id, UINT16);
3998 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3999         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4000                                  mode, "on#off");
4001
4002 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4003         .f = cmd_tx_vlan_set_pvid_parsed,
4004         .data = NULL,
4005         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4006         .tokens = {
4007                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4008                 (void *)&cmd_tx_vlan_set_pvid_set,
4009                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4010                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4011                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4012                 (void *)&cmd_tx_vlan_set_pvid_mode,
4013                 NULL,
4014         },
4015 };
4016
4017 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4018 struct cmd_tx_vlan_reset_result {
4019         cmdline_fixed_string_t tx_vlan;
4020         cmdline_fixed_string_t reset;
4021         portid_t port_id;
4022 };
4023
4024 static void
4025 cmd_tx_vlan_reset_parsed(void *parsed_result,
4026                          __attribute__((unused)) struct cmdline *cl,
4027                          __attribute__((unused)) void *data)
4028 {
4029         struct cmd_tx_vlan_reset_result *res = parsed_result;
4030
4031         if (!port_is_stopped(res->port_id)) {
4032                 printf("Please stop port %d first\n", res->port_id);
4033                 return;
4034         }
4035
4036         tx_vlan_reset(res->port_id);
4037
4038         cmd_reconfig_device_queue(res->port_id, 1, 1);
4039 }
4040
4041 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4042         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4043                                  tx_vlan, "tx_vlan");
4044 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4045         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4046                                  reset, "reset");
4047 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4048         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4049                               port_id, UINT16);
4050
4051 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4052         .f = cmd_tx_vlan_reset_parsed,
4053         .data = NULL,
4054         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4055                 "VLAN header in packets sent on a port",
4056         .tokens = {
4057                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4058                 (void *)&cmd_tx_vlan_reset_reset,
4059                 (void *)&cmd_tx_vlan_reset_portid,
4060                 NULL,
4061         },
4062 };
4063
4064
4065 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4066 struct cmd_csum_result {
4067         cmdline_fixed_string_t csum;
4068         cmdline_fixed_string_t mode;
4069         cmdline_fixed_string_t proto;
4070         cmdline_fixed_string_t hwsw;
4071         portid_t port_id;
4072 };
4073
4074 static void
4075 csum_show(int port_id)
4076 {
4077         struct rte_eth_dev_info dev_info;
4078         uint64_t tx_offloads;
4079
4080         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4081         printf("Parse tunnel is %s\n",
4082                 (ports[port_id].parse_tunnel) ? "on" : "off");
4083         printf("IP checksum offload is %s\n",
4084                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4085         printf("UDP checksum offload is %s\n",
4086                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4087         printf("TCP checksum offload is %s\n",
4088                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4089         printf("SCTP checksum offload is %s\n",
4090                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4091         printf("Outer-Ip checksum offload is %s\n",
4092                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4093
4094         /* display warnings if configuration is not supported by the NIC */
4095         rte_eth_dev_info_get(port_id, &dev_info);
4096         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4097                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4098                 printf("Warning: hardware IP checksum enabled but not "
4099                         "supported by port %d\n", port_id);
4100         }
4101         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4102                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4103                 printf("Warning: hardware UDP checksum enabled but not "
4104                         "supported by port %d\n", port_id);
4105         }
4106         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4107                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4108                 printf("Warning: hardware TCP checksum enabled but not "
4109                         "supported by port %d\n", port_id);
4110         }
4111         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4112                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4113                 printf("Warning: hardware SCTP checksum enabled but not "
4114                         "supported by port %d\n", port_id);
4115         }
4116         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4117                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4118                 printf("Warning: hardware outer IP checksum enabled but not "
4119                         "supported by port %d\n", port_id);
4120         }
4121 }
4122
4123 static void
4124 cmd_csum_parsed(void *parsed_result,
4125                        __attribute__((unused)) struct cmdline *cl,
4126                        __attribute__((unused)) void *data)
4127 {
4128         struct cmd_csum_result *res = parsed_result;
4129         int hw = 0;
4130         uint64_t csum_offloads = 0;
4131         struct rte_eth_dev_info dev_info;
4132
4133         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4134                 printf("invalid port %d\n", res->port_id);
4135                 return;
4136         }
4137         if (!port_is_stopped(res->port_id)) {
4138                 printf("Please stop port %d first\n", res->port_id);
4139                 return;
4140         }
4141
4142         rte_eth_dev_info_get(res->port_id, &dev_info);
4143         if (!strcmp(res->mode, "set")) {
4144
4145                 if (!strcmp(res->hwsw, "hw"))
4146                         hw = 1;
4147
4148                 if (!strcmp(res->proto, "ip")) {
4149                         if (hw == 0 || (dev_info.tx_offload_capa &
4150                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4151                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4152                         } else {
4153                                 printf("IP checksum offload is not supported "
4154                                        "by port %u\n", res->port_id);
4155                         }
4156                 } else if (!strcmp(res->proto, "udp")) {
4157                         if (hw == 0 || (dev_info.tx_offload_capa &
4158                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4159                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4160                         } else {
4161                                 printf("UDP checksum offload is not supported "
4162                                        "by port %u\n", res->port_id);
4163                         }
4164                 } else if (!strcmp(res->proto, "tcp")) {
4165                         if (hw == 0 || (dev_info.tx_offload_capa &
4166                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4167                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4168                         } else {
4169                                 printf("TCP checksum offload is not supported "
4170                                        "by port %u\n", res->port_id);
4171                         }
4172                 } else if (!strcmp(res->proto, "sctp")) {
4173                         if (hw == 0 || (dev_info.tx_offload_capa &
4174                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4175                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4176                         } else {
4177                                 printf("SCTP checksum offload is not supported "
4178                                        "by port %u\n", res->port_id);
4179                         }
4180                 } else if (!strcmp(res->proto, "outer-ip")) {
4181                         if (hw == 0 || (dev_info.tx_offload_capa &
4182                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4183                                 csum_offloads |=
4184                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4185                         } else {
4186                                 printf("Outer IP checksum offload is not "
4187                                        "supported by port %u\n", res->port_id);
4188                         }
4189                 }
4190
4191                 if (hw) {
4192                         ports[res->port_id].dev_conf.txmode.offloads |=
4193                                                         csum_offloads;
4194                 } else {
4195                         ports[res->port_id].dev_conf.txmode.offloads &=
4196                                                         (~csum_offloads);
4197                 }
4198         }
4199         csum_show(res->port_id);
4200
4201         cmd_reconfig_device_queue(res->port_id, 1, 1);
4202 }
4203
4204 cmdline_parse_token_string_t cmd_csum_csum =
4205         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4206                                 csum, "csum");
4207 cmdline_parse_token_string_t cmd_csum_mode =
4208         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4209                                 mode, "set");
4210 cmdline_parse_token_string_t cmd_csum_proto =
4211         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4212                                 proto, "ip#tcp#udp#sctp#outer-ip");
4213 cmdline_parse_token_string_t cmd_csum_hwsw =
4214         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4215                                 hwsw, "hw#sw");
4216 cmdline_parse_token_num_t cmd_csum_portid =
4217         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4218                                 port_id, UINT16);
4219
4220 cmdline_parse_inst_t cmd_csum_set = {
4221         .f = cmd_csum_parsed,
4222         .data = NULL,
4223         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4224                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4225                 "using csum forward engine",
4226         .tokens = {
4227                 (void *)&cmd_csum_csum,
4228                 (void *)&cmd_csum_mode,
4229                 (void *)&cmd_csum_proto,
4230                 (void *)&cmd_csum_hwsw,
4231                 (void *)&cmd_csum_portid,
4232                 NULL,
4233         },
4234 };
4235
4236 cmdline_parse_token_string_t cmd_csum_mode_show =
4237         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4238                                 mode, "show");
4239
4240 cmdline_parse_inst_t cmd_csum_show = {
4241         .f = cmd_csum_parsed,
4242         .data = NULL,
4243         .help_str = "csum show <port_id>: Show checksum offload configuration",
4244         .tokens = {
4245                 (void *)&cmd_csum_csum,
4246                 (void *)&cmd_csum_mode_show,
4247                 (void *)&cmd_csum_portid,
4248                 NULL,
4249         },
4250 };
4251
4252 /* Enable/disable tunnel parsing */
4253 struct cmd_csum_tunnel_result {
4254         cmdline_fixed_string_t csum;
4255         cmdline_fixed_string_t parse;
4256         cmdline_fixed_string_t onoff;
4257         portid_t port_id;
4258 };
4259
4260 static void
4261 cmd_csum_tunnel_parsed(void *parsed_result,
4262                        __attribute__((unused)) struct cmdline *cl,
4263                        __attribute__((unused)) void *data)
4264 {
4265         struct cmd_csum_tunnel_result *res = parsed_result;
4266
4267         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4268                 return;
4269
4270         if (!strcmp(res->onoff, "on"))
4271                 ports[res->port_id].parse_tunnel = 1;
4272         else
4273                 ports[res->port_id].parse_tunnel = 0;
4274
4275         csum_show(res->port_id);
4276 }
4277
4278 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4279         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4280                                 csum, "csum");
4281 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4282         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4283                                 parse, "parse_tunnel");
4284 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4285         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4286                                 onoff, "on#off");
4287 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4288         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4289                                 port_id, UINT16);
4290
4291 cmdline_parse_inst_t cmd_csum_tunnel = {
4292         .f = cmd_csum_tunnel_parsed,
4293         .data = NULL,
4294         .help_str = "csum parse_tunnel on|off <port_id>: "
4295                 "Enable/Disable parsing of tunnels for csum engine",
4296         .tokens = {
4297                 (void *)&cmd_csum_tunnel_csum,
4298                 (void *)&cmd_csum_tunnel_parse,
4299                 (void *)&cmd_csum_tunnel_onoff,
4300                 (void *)&cmd_csum_tunnel_portid,
4301                 NULL,
4302         },
4303 };
4304
4305 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4306 struct cmd_tso_set_result {
4307         cmdline_fixed_string_t tso;
4308         cmdline_fixed_string_t mode;
4309         uint16_t tso_segsz;
4310         portid_t port_id;
4311 };
4312
4313 static void
4314 cmd_tso_set_parsed(void *parsed_result,
4315                        __attribute__((unused)) struct cmdline *cl,
4316                        __attribute__((unused)) void *data)
4317 {
4318         struct cmd_tso_set_result *res = parsed_result;
4319         struct rte_eth_dev_info dev_info;
4320
4321         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4322                 return;
4323         if (!port_is_stopped(res->port_id)) {
4324                 printf("Please stop port %d first\n", res->port_id);
4325                 return;
4326         }
4327
4328         if (!strcmp(res->mode, "set"))
4329                 ports[res->port_id].tso_segsz = res->tso_segsz;
4330
4331         rte_eth_dev_info_get(res->port_id, &dev_info);
4332         if ((ports[res->port_id].tso_segsz != 0) &&
4333                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4334                 printf("Error: TSO is not supported by port %d\n",
4335                        res->port_id);
4336                 return;
4337         }
4338
4339         if (ports[res->port_id].tso_segsz == 0) {
4340                 ports[res->port_id].dev_conf.txmode.offloads &=
4341                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4342                 printf("TSO for non-tunneled packets is disabled\n");
4343         } else {
4344                 ports[res->port_id].dev_conf.txmode.offloads |=
4345                                                 DEV_TX_OFFLOAD_TCP_TSO;
4346                 printf("TSO segment size for non-tunneled packets is %d\n",
4347                         ports[res->port_id].tso_segsz);
4348         }
4349
4350         /* display warnings if configuration is not supported by the NIC */
4351         rte_eth_dev_info_get(res->port_id, &dev_info);
4352         if ((ports[res->port_id].tso_segsz != 0) &&
4353                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4354                 printf("Warning: TSO enabled but not "
4355                         "supported by port %d\n", res->port_id);
4356         }
4357
4358         cmd_reconfig_device_queue(res->port_id, 1, 1);
4359 }
4360
4361 cmdline_parse_token_string_t cmd_tso_set_tso =
4362         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4363                                 tso, "tso");
4364 cmdline_parse_token_string_t cmd_tso_set_mode =
4365         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4366                                 mode, "set");
4367 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4368         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4369                                 tso_segsz, UINT16);
4370 cmdline_parse_token_num_t cmd_tso_set_portid =
4371         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4372                                 port_id, UINT16);
4373
4374 cmdline_parse_inst_t cmd_tso_set = {
4375         .f = cmd_tso_set_parsed,
4376         .data = NULL,
4377         .help_str = "tso set <tso_segsz> <port_id>: "
4378                 "Set TSO segment size of non-tunneled packets for csum engine "
4379                 "(0 to disable)",
4380         .tokens = {
4381                 (void *)&cmd_tso_set_tso,
4382                 (void *)&cmd_tso_set_mode,
4383                 (void *)&cmd_tso_set_tso_segsz,
4384                 (void *)&cmd_tso_set_portid,
4385                 NULL,
4386         },
4387 };
4388
4389 cmdline_parse_token_string_t cmd_tso_show_mode =
4390         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4391                                 mode, "show");
4392
4393
4394 cmdline_parse_inst_t cmd_tso_show = {
4395         .f = cmd_tso_set_parsed,
4396         .data = NULL,
4397         .help_str = "tso show <port_id>: "
4398                 "Show TSO segment size of non-tunneled packets for csum engine",
4399         .tokens = {
4400                 (void *)&cmd_tso_set_tso,
4401                 (void *)&cmd_tso_show_mode,
4402                 (void *)&cmd_tso_set_portid,
4403                 NULL,
4404         },
4405 };
4406
4407 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4408 struct cmd_tunnel_tso_set_result {
4409         cmdline_fixed_string_t tso;
4410         cmdline_fixed_string_t mode;
4411         uint16_t tso_segsz;
4412         portid_t port_id;
4413 };
4414
4415 static struct rte_eth_dev_info
4416 check_tunnel_tso_nic_support(portid_t port_id)
4417 {
4418         struct rte_eth_dev_info dev_info;
4419
4420         rte_eth_dev_info_get(port_id, &dev_info);
4421         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4422                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4423                        "not enabled for port %d\n", port_id);
4424         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4425                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4426                        "not enabled for port %d\n", port_id);
4427         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4428                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4429                        "not enabled for port %d\n", port_id);
4430         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4431                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4432                        "not enabled for port %d\n", port_id);
4433         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4434                 printf("Warning: IP TUNNEL TSO not supported therefore "
4435                        "not enabled for port %d\n", port_id);
4436         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4437                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4438                        "not enabled for port %d\n", port_id);
4439         return dev_info;
4440 }
4441
4442 static void
4443 cmd_tunnel_tso_set_parsed(void *parsed_result,
4444                           __attribute__((unused)) struct cmdline *cl,
4445                           __attribute__((unused)) void *data)
4446 {
4447         struct cmd_tunnel_tso_set_result *res = parsed_result;
4448         struct rte_eth_dev_info dev_info;
4449
4450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4451                 return;
4452         if (!port_is_stopped(res->port_id)) {
4453                 printf("Please stop port %d first\n", res->port_id);
4454                 return;
4455         }
4456
4457         if (!strcmp(res->mode, "set"))
4458                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4459
4460         dev_info = check_tunnel_tso_nic_support(res->port_id);
4461         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4462                 ports[res->port_id].dev_conf.txmode.offloads &=
4463                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4464                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4465                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4466                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4467                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4468                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4469                 printf("TSO for tunneled packets is disabled\n");
4470         } else {
4471                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4472                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4473                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4474                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4475                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4476                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4477
4478                 ports[res->port_id].dev_conf.txmode.offloads |=
4479                         (tso_offloads & dev_info.tx_offload_capa);
4480                 printf("TSO segment size for tunneled packets is %d\n",
4481                         ports[res->port_id].tunnel_tso_segsz);
4482
4483                 /* Below conditions are needed to make it work:
4484                  * (1) tunnel TSO is supported by the NIC;
4485                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4486                  * are recognized;
4487                  * (3) for tunneled pkts with outer L3 of IPv4,
4488                  * "csum set outer-ip" must be set to hw, because after tso,
4489                  * total_len of outer IP header is changed, and the checksum
4490                  * of outer IP header calculated by sw should be wrong; that
4491                  * is not necessary for IPv6 tunneled pkts because there's no
4492                  * checksum in IP header anymore.
4493                  */
4494
4495                 if (!ports[res->port_id].parse_tunnel)
4496                         printf("Warning: csum parse_tunnel must be set "
4497                                 "so that tunneled packets are recognized\n");
4498                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4499                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4500                         printf("Warning: csum set outer-ip must be set to hw "
4501                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4502         }
4503
4504         cmd_reconfig_device_queue(res->port_id, 1, 1);
4505 }
4506
4507 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4508         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4509                                 tso, "tunnel_tso");
4510 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4511         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4512                                 mode, "set");
4513 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4514         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4515                                 tso_segsz, UINT16);
4516 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4517         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4518                                 port_id, UINT16);
4519
4520 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4521         .f = cmd_tunnel_tso_set_parsed,
4522         .data = NULL,
4523         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4524                 "Set TSO segment size of tunneled packets for csum engine "
4525                 "(0 to disable)",
4526         .tokens = {
4527                 (void *)&cmd_tunnel_tso_set_tso,
4528                 (void *)&cmd_tunnel_tso_set_mode,
4529                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4530                 (void *)&cmd_tunnel_tso_set_portid,
4531                 NULL,
4532         },
4533 };
4534
4535 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4536         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4537                                 mode, "show");
4538
4539
4540 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4541         .f = cmd_tunnel_tso_set_parsed,
4542         .data = NULL,
4543         .help_str = "tunnel_tso show <port_id> "
4544                 "Show TSO segment size of tunneled packets for csum engine",
4545         .tokens = {
4546                 (void *)&cmd_tunnel_tso_set_tso,
4547                 (void *)&cmd_tunnel_tso_show_mode,
4548                 (void *)&cmd_tunnel_tso_set_portid,
4549                 NULL,
4550         },
4551 };
4552
4553 /* *** SET GRO FOR A PORT *** */
4554 struct cmd_gro_enable_result {
4555         cmdline_fixed_string_t cmd_set;
4556         cmdline_fixed_string_t cmd_port;
4557         cmdline_fixed_string_t cmd_keyword;
4558         cmdline_fixed_string_t cmd_onoff;
4559         portid_t cmd_pid;
4560 };
4561
4562 static void
4563 cmd_gro_enable_parsed(void *parsed_result,
4564                 __attribute__((unused)) struct cmdline *cl,
4565                 __attribute__((unused)) void *data)
4566 {
4567         struct cmd_gro_enable_result *res;
4568
4569         res = parsed_result;
4570         if (!strcmp(res->cmd_keyword, "gro"))
4571                 setup_gro(res->cmd_onoff, res->cmd_pid);
4572 }
4573
4574 cmdline_parse_token_string_t cmd_gro_enable_set =
4575         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4576                         cmd_set, "set");
4577 cmdline_parse_token_string_t cmd_gro_enable_port =
4578         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4579                         cmd_keyword, "port");
4580 cmdline_parse_token_num_t cmd_gro_enable_pid =
4581         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4582                         cmd_pid, UINT16);
4583 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4584         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4585                         cmd_keyword, "gro");
4586 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4587         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4588                         cmd_onoff, "on#off");
4589
4590 cmdline_parse_inst_t cmd_gro_enable = {
4591         .f = cmd_gro_enable_parsed,
4592         .data = NULL,
4593         .help_str = "set port <port_id> gro on|off",
4594         .tokens = {
4595                 (void *)&cmd_gro_enable_set,
4596                 (void *)&cmd_gro_enable_port,
4597                 (void *)&cmd_gro_enable_pid,
4598                 (void *)&cmd_gro_enable_keyword,
4599                 (void *)&cmd_gro_enable_onoff,
4600                 NULL,
4601         },
4602 };
4603
4604 /* *** DISPLAY GRO CONFIGURATION *** */
4605 struct cmd_gro_show_result {
4606         cmdline_fixed_string_t cmd_show;
4607         cmdline_fixed_string_t cmd_port;
4608         cmdline_fixed_string_t cmd_keyword;
4609         portid_t cmd_pid;
4610 };
4611
4612 static void
4613 cmd_gro_show_parsed(void *parsed_result,
4614                 __attribute__((unused)) struct cmdline *cl,
4615                 __attribute__((unused)) void *data)
4616 {
4617         struct cmd_gro_show_result *res;
4618
4619         res = parsed_result;
4620         if (!strcmp(res->cmd_keyword, "gro"))
4621                 show_gro(res->cmd_pid);
4622 }
4623
4624 cmdline_parse_token_string_t cmd_gro_show_show =
4625         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4626                         cmd_show, "show");
4627 cmdline_parse_token_string_t cmd_gro_show_port =
4628         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4629                         cmd_port, "port");
4630 cmdline_parse_token_num_t cmd_gro_show_pid =
4631         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4632                         cmd_pid, UINT16);
4633 cmdline_parse_token_string_t cmd_gro_show_keyword =
4634         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4635                         cmd_keyword, "gro");
4636
4637 cmdline_parse_inst_t cmd_gro_show = {
4638         .f = cmd_gro_show_parsed,
4639         .data = NULL,
4640         .help_str = "show port <port_id> gro",
4641         .tokens = {
4642                 (void *)&cmd_gro_show_show,
4643                 (void *)&cmd_gro_show_port,
4644                 (void *)&cmd_gro_show_pid,
4645                 (void *)&cmd_gro_show_keyword,
4646                 NULL,
4647         },
4648 };
4649
4650 /* *** SET FLUSH CYCLES FOR GRO *** */
4651 struct cmd_gro_flush_result {
4652         cmdline_fixed_string_t cmd_set;
4653         cmdline_fixed_string_t cmd_keyword;
4654         cmdline_fixed_string_t cmd_flush;
4655         uint8_t cmd_cycles;
4656 };
4657
4658 static void
4659 cmd_gro_flush_parsed(void *parsed_result,
4660                 __attribute__((unused)) struct cmdline *cl,
4661                 __attribute__((unused)) void *data)
4662 {
4663         struct cmd_gro_flush_result *res;
4664
4665         res = parsed_result;
4666         if ((!strcmp(res->cmd_keyword, "gro")) &&
4667                         (!strcmp(res->cmd_flush, "flush")))
4668                 setup_gro_flush_cycles(res->cmd_cycles);
4669 }
4670
4671 cmdline_parse_token_string_t cmd_gro_flush_set =
4672         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4673                         cmd_set, "set");
4674 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4675         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4676                         cmd_keyword, "gro");
4677 cmdline_parse_token_string_t cmd_gro_flush_flush =
4678         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4679                         cmd_flush, "flush");
4680 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4681         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4682                         cmd_cycles, UINT8);
4683
4684 cmdline_parse_inst_t cmd_gro_flush = {
4685         .f = cmd_gro_flush_parsed,
4686         .data = NULL,
4687         .help_str = "set gro flush <cycles>",
4688         .tokens = {
4689                 (void *)&cmd_gro_flush_set,
4690                 (void *)&cmd_gro_flush_keyword,
4691                 (void *)&cmd_gro_flush_flush,
4692                 (void *)&cmd_gro_flush_cycles,
4693                 NULL,
4694         },
4695 };
4696
4697 /* *** ENABLE/DISABLE GSO *** */
4698 struct cmd_gso_enable_result {
4699         cmdline_fixed_string_t cmd_set;
4700         cmdline_fixed_string_t cmd_port;
4701         cmdline_fixed_string_t cmd_keyword;
4702         cmdline_fixed_string_t cmd_mode;
4703         portid_t cmd_pid;
4704 };
4705
4706 static void
4707 cmd_gso_enable_parsed(void *parsed_result,
4708                 __attribute__((unused)) struct cmdline *cl,
4709                 __attribute__((unused)) void *data)
4710 {
4711         struct cmd_gso_enable_result *res;
4712
4713         res = parsed_result;
4714         if (!strcmp(res->cmd_keyword, "gso"))
4715                 setup_gso(res->cmd_mode, res->cmd_pid);
4716 }
4717
4718 cmdline_parse_token_string_t cmd_gso_enable_set =
4719         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4720                         cmd_set, "set");
4721 cmdline_parse_token_string_t cmd_gso_enable_port =
4722         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4723                         cmd_port, "port");
4724 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4725         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4726                         cmd_keyword, "gso");
4727 cmdline_parse_token_string_t cmd_gso_enable_mode =
4728         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4729                         cmd_mode, "on#off");
4730 cmdline_parse_token_num_t cmd_gso_enable_pid =
4731         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4732                         cmd_pid, UINT16);
4733
4734 cmdline_parse_inst_t cmd_gso_enable = {
4735         .f = cmd_gso_enable_parsed,
4736         .data = NULL,
4737         .help_str = "set port <port_id> gso on|off",
4738         .tokens = {
4739                 (void *)&cmd_gso_enable_set,
4740                 (void *)&cmd_gso_enable_port,
4741                 (void *)&cmd_gso_enable_pid,
4742                 (void *)&cmd_gso_enable_keyword,
4743                 (void *)&cmd_gso_enable_mode,
4744                 NULL,
4745         },
4746 };
4747
4748 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4749 struct cmd_gso_size_result {
4750         cmdline_fixed_string_t cmd_set;
4751         cmdline_fixed_string_t cmd_keyword;
4752         cmdline_fixed_string_t cmd_segsz;
4753         uint16_t cmd_size;
4754 };
4755
4756 static void
4757 cmd_gso_size_parsed(void *parsed_result,
4758                        __attribute__((unused)) struct cmdline *cl,
4759                        __attribute__((unused)) void *data)
4760 {
4761         struct cmd_gso_size_result *res = parsed_result;
4762
4763         if (test_done == 0) {
4764                 printf("Before setting GSO segsz, please first"
4765                                 " stop fowarding\n");
4766                 return;
4767         }
4768
4769         if (!strcmp(res->cmd_keyword, "gso") &&
4770                         !strcmp(res->cmd_segsz, "segsz")) {
4771                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4772                         printf("gso_size should be larger than %zu."
4773                                         " Please input a legal value\n",
4774                                         RTE_GSO_SEG_SIZE_MIN);
4775                 else
4776                         gso_max_segment_size = res->cmd_size;
4777         }
4778 }
4779
4780 cmdline_parse_token_string_t cmd_gso_size_set =
4781         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4782                                 cmd_set, "set");
4783 cmdline_parse_token_string_t cmd_gso_size_keyword =
4784         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4785                                 cmd_keyword, "gso");
4786 cmdline_parse_token_string_t cmd_gso_size_segsz =
4787         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4788                                 cmd_segsz, "segsz");
4789 cmdline_parse_token_num_t cmd_gso_size_size =
4790         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4791                                 cmd_size, UINT16);
4792
4793 cmdline_parse_inst_t cmd_gso_size = {
4794         .f = cmd_gso_size_parsed,
4795         .data = NULL,
4796         .help_str = "set gso segsz <length>",
4797         .tokens = {
4798                 (void *)&cmd_gso_size_set,
4799                 (void *)&cmd_gso_size_keyword,
4800                 (void *)&cmd_gso_size_segsz,
4801                 (void *)&cmd_gso_size_size,
4802                 NULL,
4803         },
4804 };
4805
4806 /* *** SHOW GSO CONFIGURATION *** */
4807 struct cmd_gso_show_result {
4808         cmdline_fixed_string_t cmd_show;
4809         cmdline_fixed_string_t cmd_port;
4810         cmdline_fixed_string_t cmd_keyword;
4811         portid_t cmd_pid;
4812 };
4813
4814 static void
4815 cmd_gso_show_parsed(void *parsed_result,
4816                        __attribute__((unused)) struct cmdline *cl,
4817                        __attribute__((unused)) void *data)
4818 {
4819         struct cmd_gso_show_result *res = parsed_result;
4820
4821         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4822                 printf("invalid port id %u\n", res->cmd_pid);
4823                 return;
4824         }
4825         if (!strcmp(res->cmd_keyword, "gso")) {
4826                 if (gso_ports[res->cmd_pid].enable) {
4827                         printf("Max GSO'd packet size: %uB\n"
4828                                         "Supported GSO types: TCP/IPv4, "
4829                                         "UDP/IPv4, VxLAN with inner "
4830                                         "TCP/IPv4 packet, GRE with inner "
4831                                         "TCP/IPv4 packet\n",
4832                                         gso_max_segment_size);
4833                 } else
4834                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4835         }
4836 }
4837
4838 cmdline_parse_token_string_t cmd_gso_show_show =
4839 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4840                 cmd_show, "show");
4841 cmdline_parse_token_string_t cmd_gso_show_port =
4842 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4843                 cmd_port, "port");
4844 cmdline_parse_token_string_t cmd_gso_show_keyword =
4845         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4846                                 cmd_keyword, "gso");
4847 cmdline_parse_token_num_t cmd_gso_show_pid =
4848         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4849                                 cmd_pid, UINT16);
4850
4851 cmdline_parse_inst_t cmd_gso_show = {
4852         .f = cmd_gso_show_parsed,
4853         .data = NULL,
4854         .help_str = "show port <port_id> gso",
4855         .tokens = {
4856                 (void *)&cmd_gso_show_show,
4857                 (void *)&cmd_gso_show_port,
4858                 (void *)&cmd_gso_show_pid,
4859                 (void *)&cmd_gso_show_keyword,
4860                 NULL,
4861         },
4862 };
4863
4864 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4865 struct cmd_set_flush_rx {
4866         cmdline_fixed_string_t set;
4867         cmdline_fixed_string_t flush_rx;
4868         cmdline_fixed_string_t mode;
4869 };
4870
4871 static void
4872 cmd_set_flush_rx_parsed(void *parsed_result,
4873                 __attribute__((unused)) struct cmdline *cl,
4874                 __attribute__((unused)) void *data)
4875 {
4876         struct cmd_set_flush_rx *res = parsed_result;
4877         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4878 }
4879
4880 cmdline_parse_token_string_t cmd_setflushrx_set =
4881         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4882                         set, "set");
4883 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4884         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4885                         flush_rx, "flush_rx");
4886 cmdline_parse_token_string_t cmd_setflushrx_mode =
4887         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4888                         mode, "on#off");
4889
4890
4891 cmdline_parse_inst_t cmd_set_flush_rx = {
4892         .f = cmd_set_flush_rx_parsed,
4893         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4894         .data = NULL,
4895         .tokens = {
4896                 (void *)&cmd_setflushrx_set,
4897                 (void *)&cmd_setflushrx_flush_rx,
4898                 (void *)&cmd_setflushrx_mode,
4899                 NULL,
4900         },
4901 };
4902
4903 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4904 struct cmd_set_link_check {
4905         cmdline_fixed_string_t set;
4906         cmdline_fixed_string_t link_check;
4907         cmdline_fixed_string_t mode;
4908 };
4909
4910 static void
4911 cmd_set_link_check_parsed(void *parsed_result,
4912                 __attribute__((unused)) struct cmdline *cl,
4913                 __attribute__((unused)) void *data)
4914 {
4915         struct cmd_set_link_check *res = parsed_result;
4916         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4917 }
4918
4919 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4920         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4921                         set, "set");
4922 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4923         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4924                         link_check, "link_check");
4925 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4926         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4927                         mode, "on#off");
4928
4929
4930 cmdline_parse_inst_t cmd_set_link_check = {
4931         .f = cmd_set_link_check_parsed,
4932         .help_str = "set link_check on|off: Enable/Disable link status check "
4933                     "when starting/stopping a port",
4934         .data = NULL,
4935         .tokens = {
4936                 (void *)&cmd_setlinkcheck_set,
4937                 (void *)&cmd_setlinkcheck_link_check,
4938                 (void *)&cmd_setlinkcheck_mode,
4939                 NULL,
4940         },
4941 };
4942
4943 /* *** SET NIC BYPASS MODE *** */
4944 struct cmd_set_bypass_mode_result {
4945         cmdline_fixed_string_t set;
4946         cmdline_fixed_string_t bypass;
4947         cmdline_fixed_string_t mode;
4948         cmdline_fixed_string_t value;
4949         portid_t port_id;
4950 };
4951
4952 static void
4953 cmd_set_bypass_mode_parsed(void *parsed_result,
4954                 __attribute__((unused)) struct cmdline *cl,
4955                 __attribute__((unused)) void *data)
4956 {
4957         struct cmd_set_bypass_mode_result *res = parsed_result;
4958         portid_t port_id = res->port_id;
4959         int32_t rc = -EINVAL;
4960
4961 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4962         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4963
4964         if (!strcmp(res->value, "bypass"))
4965                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4966         else if (!strcmp(res->value, "isolate"))
4967                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4968         else
4969                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4970
4971         /* Set the bypass mode for the relevant port. */
4972         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4973 #endif
4974         if (rc != 0)
4975                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4976 }
4977
4978 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4979         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4980                         set, "set");
4981 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4982         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4983                         bypass, "bypass");
4984 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4985         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4986                         mode, "mode");
4987 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4988         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4989                         value, "normal#bypass#isolate");
4990 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4991         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4992                                 port_id, UINT16);
4993
4994 cmdline_parse_inst_t cmd_set_bypass_mode = {
4995         .f = cmd_set_bypass_mode_parsed,
4996         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4997                     "Set the NIC bypass mode for port_id",
4998         .data = NULL,
4999         .tokens = {
5000                 (void *)&cmd_setbypass_mode_set,
5001                 (void *)&cmd_setbypass_mode_bypass,
5002                 (void *)&cmd_setbypass_mode_mode,
5003                 (void *)&cmd_setbypass_mode_value,
5004                 (void *)&cmd_setbypass_mode_port,
5005                 NULL,
5006         },
5007 };
5008
5009 /* *** SET NIC BYPASS EVENT *** */
5010 struct cmd_set_bypass_event_result {
5011         cmdline_fixed_string_t set;
5012         cmdline_fixed_string_t bypass;
5013         cmdline_fixed_string_t event;
5014         cmdline_fixed_string_t event_value;
5015         cmdline_fixed_string_t mode;
5016         cmdline_fixed_string_t mode_value;
5017         portid_t port_id;
5018 };
5019
5020 static void
5021 cmd_set_bypass_event_parsed(void *parsed_result,
5022                 __attribute__((unused)) struct cmdline *cl,
5023                 __attribute__((unused)) void *data)
5024 {
5025         int32_t rc = -EINVAL;
5026         struct cmd_set_bypass_event_result *res = parsed_result;
5027         portid_t port_id = res->port_id;
5028
5029 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5030         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5031         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5032
5033         if (!strcmp(res->event_value, "timeout"))
5034                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5035         else if (!strcmp(res->event_value, "os_on"))
5036                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5037         else if (!strcmp(res->event_value, "os_off"))
5038                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5039         else if (!strcmp(res->event_value, "power_on"))
5040                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5041         else if (!strcmp(res->event_value, "power_off"))
5042                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5043         else
5044                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5045
5046         if (!strcmp(res->mode_value, "bypass"))
5047                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5048         else if (!strcmp(res->mode_value, "isolate"))
5049                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5050         else
5051                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5052
5053         /* Set the watchdog timeout. */
5054         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5055
5056                 rc = -EINVAL;
5057                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5058                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5059                                                            bypass_timeout);
5060                 }
5061                 if (rc != 0) {
5062                         printf("Failed to set timeout value %u "
5063                         "for port %d, errto code: %d.\n",
5064                         bypass_timeout, port_id, rc);
5065                 }
5066         }
5067
5068         /* Set the bypass event to transition to bypass mode. */
5069         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5070                                               bypass_mode);
5071 #endif
5072
5073         if (rc != 0)
5074                 printf("\t Failed to set bypass event for port = %d.\n",
5075                        port_id);
5076 }
5077
5078 cmdline_parse_token_string_t cmd_setbypass_event_set =
5079         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5080                         set, "set");
5081 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5082         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5083                         bypass, "bypass");
5084 cmdline_parse_token_string_t cmd_setbypass_event_event =
5085         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5086                         event, "event");
5087 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5088         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5089                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5090 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5091         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5092                         mode, "mode");
5093 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5094         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5095                         mode_value, "normal#bypass#isolate");
5096 cmdline_parse_token_num_t cmd_setbypass_event_port =
5097         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5098                                 port_id, UINT16);
5099
5100 cmdline_parse_inst_t cmd_set_bypass_event = {
5101         .f = cmd_set_bypass_event_parsed,
5102         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5103                 "power_off mode normal|bypass|isolate <port_id>: "
5104                 "Set the NIC bypass event mode for port_id",
5105         .data = NULL,
5106         .tokens = {
5107                 (void *)&cmd_setbypass_event_set,
5108                 (void *)&cmd_setbypass_event_bypass,
5109                 (void *)&cmd_setbypass_event_event,
5110                 (void *)&cmd_setbypass_event_event_value,
5111                 (void *)&cmd_setbypass_event_mode,
5112                 (void *)&cmd_setbypass_event_mode_value,
5113                 (void *)&cmd_setbypass_event_port,
5114                 NULL,
5115         },
5116 };
5117
5118
5119 /* *** SET NIC BYPASS TIMEOUT *** */
5120 struct cmd_set_bypass_timeout_result {
5121         cmdline_fixed_string_t set;
5122         cmdline_fixed_string_t bypass;
5123         cmdline_fixed_string_t timeout;
5124         cmdline_fixed_string_t value;
5125 };
5126
5127 static void
5128 cmd_set_bypass_timeout_parsed(void *parsed_result,
5129                 __attribute__((unused)) struct cmdline *cl,
5130                 __attribute__((unused)) void *data)
5131 {
5132         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5133
5134 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5135         if (!strcmp(res->value, "1.5"))
5136                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5137         else if (!strcmp(res->value, "2"))
5138                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5139         else if (!strcmp(res->value, "3"))
5140                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5141         else if (!strcmp(res->value, "4"))
5142                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5143         else if (!strcmp(res->value, "8"))
5144                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5145         else if (!strcmp(res->value, "16"))
5146                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5147         else if (!strcmp(res->value, "32"))
5148                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5149         else
5150                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5151 #endif
5152 }
5153
5154 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5156                         set, "set");
5157 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5158         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5159                         bypass, "bypass");
5160 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5161         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5162                         timeout, "timeout");
5163 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5164         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5165                         value, "0#1.5#2#3#4#8#16#32");
5166
5167 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5168         .f = cmd_set_bypass_timeout_parsed,
5169         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5170                 "Set the NIC bypass watchdog timeout in seconds",
5171         .data = NULL,
5172         .tokens = {
5173                 (void *)&cmd_setbypass_timeout_set,
5174                 (void *)&cmd_setbypass_timeout_bypass,
5175                 (void *)&cmd_setbypass_timeout_timeout,
5176                 (void *)&cmd_setbypass_timeout_value,
5177                 NULL,
5178         },
5179 };
5180
5181 /* *** SHOW NIC BYPASS MODE *** */
5182 struct cmd_show_bypass_config_result {
5183         cmdline_fixed_string_t show;
5184         cmdline_fixed_string_t bypass;
5185         cmdline_fixed_string_t config;
5186         portid_t port_id;
5187 };
5188
5189 static void
5190 cmd_show_bypass_config_parsed(void *parsed_result,
5191                 __attribute__((unused)) struct cmdline *cl,
5192                 __attribute__((unused)) void *data)
5193 {
5194         struct cmd_show_bypass_config_result *res = parsed_result;
5195         portid_t port_id = res->port_id;
5196         int rc = -EINVAL;
5197 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5198         uint32_t event_mode;
5199         uint32_t bypass_mode;
5200         uint32_t timeout = bypass_timeout;
5201         int i;
5202
5203         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5204                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5205         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5206                 {"UNKNOWN", "normal", "bypass", "isolate"};
5207         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5208                 "NONE",
5209                 "OS/board on",
5210                 "power supply on",
5211                 "OS/board off",
5212                 "power supply off",
5213                 "timeout"};
5214         int num_events = (sizeof events) / (sizeof events[0]);
5215
5216         /* Display the bypass mode.*/
5217         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5218                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5219                 return;
5220         }
5221         else {
5222                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5223                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5224
5225                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5226         }
5227
5228         /* Display the bypass timeout.*/
5229         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5230                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5231
5232         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5233
5234         /* Display the bypass events and associated modes. */
5235         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5236
5237                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5238                         printf("\tFailed to get bypass mode for event = %s\n",
5239                                 events[i]);
5240                 } else {
5241                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5242                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5243
5244                         printf("\tbypass event: %-16s = %s\n", events[i],
5245                                 modes[event_mode]);
5246                 }
5247         }
5248 #endif
5249         if (rc != 0)
5250                 printf("\tFailed to get bypass configuration for port = %d\n",
5251                        port_id);
5252 }
5253
5254 cmdline_parse_token_string_t cmd_showbypass_config_show =
5255         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5256                         show, "show");
5257 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5258         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5259                         bypass, "bypass");
5260 cmdline_parse_token_string_t cmd_showbypass_config_config =
5261         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5262                         config, "config");
5263 cmdline_parse_token_num_t cmd_showbypass_config_port =
5264         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5265                                 port_id, UINT16);
5266
5267 cmdline_parse_inst_t cmd_show_bypass_config = {
5268         .f = cmd_show_bypass_config_parsed,
5269         .help_str = "show bypass config <port_id>: "
5270                     "Show the NIC bypass config for port_id",
5271         .data = NULL,
5272         .tokens = {
5273                 (void *)&cmd_showbypass_config_show,
5274                 (void *)&cmd_showbypass_config_bypass,
5275                 (void *)&cmd_showbypass_config_config,
5276                 (void *)&cmd_showbypass_config_port,
5277                 NULL,
5278         },
5279 };
5280
5281 #ifdef RTE_LIBRTE_PMD_BOND
5282 /* *** SET BONDING MODE *** */
5283 struct cmd_set_bonding_mode_result {
5284         cmdline_fixed_string_t set;
5285         cmdline_fixed_string_t bonding;
5286         cmdline_fixed_string_t mode;
5287         uint8_t value;
5288         portid_t port_id;
5289 };
5290
5291 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5292                 __attribute__((unused))  struct cmdline *cl,
5293                 __attribute__((unused)) void *data)
5294 {
5295         struct cmd_set_bonding_mode_result *res = parsed_result;
5296         portid_t port_id = res->port_id;
5297
5298         /* Set the bonding mode for the relevant port. */
5299         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5300                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5301 }
5302
5303 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5304 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5305                 set, "set");
5306 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5307 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5308                 bonding, "bonding");
5309 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5310 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5311                 mode, "mode");
5312 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5313 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5314                 value, UINT8);
5315 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5316 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5317                 port_id, UINT16);
5318
5319 cmdline_parse_inst_t cmd_set_bonding_mode = {
5320                 .f = cmd_set_bonding_mode_parsed,
5321                 .help_str = "set bonding mode <mode_value> <port_id>: "
5322                         "Set the bonding mode for port_id",
5323                 .data = NULL,
5324                 .tokens = {
5325                                 (void *) &cmd_setbonding_mode_set,
5326                                 (void *) &cmd_setbonding_mode_bonding,
5327                                 (void *) &cmd_setbonding_mode_mode,
5328                                 (void *) &cmd_setbonding_mode_value,
5329                                 (void *) &cmd_setbonding_mode_port,
5330                                 NULL
5331                 }
5332 };
5333
5334 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5335 struct cmd_set_bonding_lacp_dedicated_queues_result {
5336         cmdline_fixed_string_t set;
5337         cmdline_fixed_string_t bonding;
5338         cmdline_fixed_string_t lacp;
5339         cmdline_fixed_string_t dedicated_queues;
5340         portid_t port_id;
5341         cmdline_fixed_string_t mode;
5342 };
5343
5344 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5345                 __attribute__((unused))  struct cmdline *cl,
5346                 __attribute__((unused)) void *data)
5347 {
5348         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5349         portid_t port_id = res->port_id;
5350         struct rte_port *port;
5351
5352         port = &ports[port_id];
5353
5354         /** Check if the port is not started **/
5355         if (port->port_status != RTE_PORT_STOPPED) {
5356                 printf("Please stop port %d first\n", port_id);
5357                 return;
5358         }
5359
5360         if (!strcmp(res->mode, "enable")) {
5361                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5362                         printf("Dedicate queues for LACP control packets"
5363                                         " enabled\n");
5364                 else
5365                         printf("Enabling dedicate queues for LACP control "
5366                                         "packets on port %d failed\n", port_id);
5367         } else if (!strcmp(res->mode, "disable")) {
5368                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5369                         printf("Dedicated queues for LACP control packets "
5370                                         "disabled\n");
5371                 else
5372                         printf("Disabling dedicated queues for LACP control "
5373                                         "traffic on port %d failed\n", port_id);
5374         }
5375 }
5376
5377 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5378 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5379                 set, "set");
5380 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5381 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5382                 bonding, "bonding");
5383 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5384 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5385                 lacp, "lacp");
5386 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5387 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5388                 dedicated_queues, "dedicated_queues");
5389 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5390 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5391                 port_id, UINT16);
5392 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5393 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5394                 mode, "enable#disable");
5395
5396 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5397                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5398                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5399                         "enable|disable: "
5400                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5401                 .data = NULL,
5402                 .tokens = {
5403                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5404                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5405                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5406                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5407                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5408                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5409                         NULL
5410                 }
5411 };
5412
5413 /* *** SET BALANCE XMIT POLICY *** */
5414 struct cmd_set_bonding_balance_xmit_policy_result {
5415         cmdline_fixed_string_t set;
5416         cmdline_fixed_string_t bonding;
5417         cmdline_fixed_string_t balance_xmit_policy;
5418         portid_t port_id;
5419         cmdline_fixed_string_t policy;
5420 };
5421
5422 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5423                 __attribute__((unused))  struct cmdline *cl,
5424                 __attribute__((unused)) void *data)
5425 {
5426         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5427         portid_t port_id = res->port_id;
5428         uint8_t policy;
5429
5430         if (!strcmp(res->policy, "l2")) {
5431                 policy = BALANCE_XMIT_POLICY_LAYER2;
5432         } else if (!strcmp(res->policy, "l23")) {
5433                 policy = BALANCE_XMIT_POLICY_LAYER23;
5434         } else if (!strcmp(res->policy, "l34")) {
5435                 policy = BALANCE_XMIT_POLICY_LAYER34;
5436         } else {
5437                 printf("\t Invalid xmit policy selection");
5438                 return;
5439         }
5440
5441         /* Set the bonding mode for the relevant port. */
5442         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5443                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5444                                 port_id);
5445         }
5446 }
5447
5448 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5449 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5450                 set, "set");
5451 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5452 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5453                 bonding, "bonding");
5454 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5455 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5456                 balance_xmit_policy, "balance_xmit_policy");
5457 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5458 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5459                 port_id, UINT16);
5460 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5461 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5462                 policy, "l2#l23#l34");
5463
5464 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5465                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5466                 .help_str = "set bonding balance_xmit_policy <port_id> "
5467                         "l2|l23|l34: "
5468                         "Set the bonding balance_xmit_policy for port_id",
5469                 .data = NULL,
5470                 .tokens = {
5471                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5472                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5473                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5474                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5475                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5476                                 NULL
5477                 }
5478 };
5479
5480 /* *** SHOW NIC BONDING CONFIGURATION *** */
5481 struct cmd_show_bonding_config_result {
5482         cmdline_fixed_string_t show;
5483         cmdline_fixed_string_t bonding;
5484         cmdline_fixed_string_t config;
5485         portid_t port_id;
5486 };
5487
5488 static void cmd_show_bonding_config_parsed(void *parsed_result,
5489                 __attribute__((unused))  struct cmdline *cl,
5490                 __attribute__((unused)) void *data)
5491 {
5492         struct cmd_show_bonding_config_result *res = parsed_result;
5493         int bonding_mode, agg_mode;
5494         portid_t slaves[RTE_MAX_ETHPORTS];
5495         int num_slaves, num_active_slaves;
5496         int primary_id;
5497         int i;
5498         portid_t port_id = res->port_id;
5499
5500         /* Display the bonding mode.*/
5501         bonding_mode = rte_eth_bond_mode_get(port_id);
5502         if (bonding_mode < 0) {
5503                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5504                 return;
5505         } else
5506                 printf("\tBonding mode: %d\n", bonding_mode);
5507
5508         if (bonding_mode == BONDING_MODE_BALANCE) {
5509                 int balance_xmit_policy;
5510
5511                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5512                 if (balance_xmit_policy < 0) {
5513                         printf("\tFailed to get balance xmit policy for port = %d\n",
5514                                         port_id);
5515                         return;
5516                 } else {
5517                         printf("\tBalance Xmit Policy: ");
5518
5519                         switch (balance_xmit_policy) {
5520                         case BALANCE_XMIT_POLICY_LAYER2:
5521                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5522                                 break;
5523                         case BALANCE_XMIT_POLICY_LAYER23:
5524                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5525                                 break;
5526                         case BALANCE_XMIT_POLICY_LAYER34:
5527                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5528                                 break;
5529                         }
5530                         printf("\n");
5531                 }
5532         }
5533
5534         if (bonding_mode == BONDING_MODE_8023AD) {
5535                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5536                 printf("\tIEEE802.3AD Aggregator Mode: ");
5537                 switch (agg_mode) {
5538                 case AGG_BANDWIDTH:
5539                         printf("bandwidth");
5540                         break;
5541                 case AGG_STABLE:
5542                         printf("stable");
5543                         break;
5544                 case AGG_COUNT:
5545                         printf("count");
5546                         break;
5547                 }
5548                 printf("\n");
5549         }
5550
5551         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5552
5553         if (num_slaves < 0) {
5554                 printf("\tFailed to get slave list for port = %d\n", port_id);
5555                 return;
5556         }
5557         if (num_slaves > 0) {
5558                 printf("\tSlaves (%d): [", num_slaves);
5559                 for (i = 0; i < num_slaves - 1; i++)
5560                         printf("%d ", slaves[i]);
5561
5562                 printf("%d]\n", slaves[num_slaves - 1]);
5563         } else {
5564                 printf("\tSlaves: []\n");
5565
5566         }
5567
5568         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5569                         RTE_MAX_ETHPORTS);
5570
5571         if (num_active_slaves < 0) {
5572                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5573                 return;
5574         }
5575         if (num_active_slaves > 0) {
5576                 printf("\tActive Slaves (%d): [", num_active_slaves);
5577                 for (i = 0; i < num_active_slaves - 1; i++)
5578                         printf("%d ", slaves[i]);
5579
5580                 printf("%d]\n", slaves[num_active_slaves - 1]);
5581
5582         } else {
5583                 printf("\tActive Slaves: []\n");
5584
5585         }
5586
5587         primary_id = rte_eth_bond_primary_get(port_id);
5588         if (primary_id < 0) {
5589                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5590                 return;
5591         } else
5592                 printf("\tPrimary: [%d]\n", primary_id);
5593
5594 }
5595
5596 cmdline_parse_token_string_t cmd_showbonding_config_show =
5597 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5598                 show, "show");
5599 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5600 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5601                 bonding, "bonding");
5602 cmdline_parse_token_string_t cmd_showbonding_config_config =
5603 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5604                 config, "config");
5605 cmdline_parse_token_num_t cmd_showbonding_config_port =
5606 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5607                 port_id, UINT16);
5608
5609 cmdline_parse_inst_t cmd_show_bonding_config = {
5610                 .f = cmd_show_bonding_config_parsed,
5611                 .help_str = "show bonding config <port_id>: "
5612                         "Show the bonding config for port_id",
5613                 .data = NULL,
5614                 .tokens = {
5615                                 (void *)&cmd_showbonding_config_show,
5616                                 (void *)&cmd_showbonding_config_bonding,
5617                                 (void *)&cmd_showbonding_config_config,
5618                                 (void *)&cmd_showbonding_config_port,
5619                                 NULL
5620                 }
5621 };
5622
5623 /* *** SET BONDING PRIMARY *** */
5624 struct cmd_set_bonding_primary_result {
5625         cmdline_fixed_string_t set;
5626         cmdline_fixed_string_t bonding;
5627         cmdline_fixed_string_t primary;
5628         portid_t slave_id;
5629         portid_t port_id;
5630 };
5631
5632 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5633                 __attribute__((unused))  struct cmdline *cl,
5634                 __attribute__((unused)) void *data)
5635 {
5636         struct cmd_set_bonding_primary_result *res = parsed_result;
5637         portid_t master_port_id = res->port_id;
5638         portid_t slave_port_id = res->slave_id;
5639
5640         /* Set the primary slave for a bonded device. */
5641         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5642                 printf("\t Failed to set primary slave for port = %d.\n",
5643                                 master_port_id);
5644                 return;
5645         }
5646         init_port_config();
5647 }
5648
5649 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5650 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5651                 set, "set");
5652 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5653 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5654                 bonding, "bonding");
5655 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5656 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5657                 primary, "primary");
5658 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5659 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5660                 slave_id, UINT16);
5661 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5662 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5663                 port_id, UINT16);
5664
5665 cmdline_parse_inst_t cmd_set_bonding_primary = {
5666                 .f = cmd_set_bonding_primary_parsed,
5667                 .help_str = "set bonding primary <slave_id> <port_id>: "
5668                         "Set the primary slave for port_id",
5669                 .data = NULL,
5670                 .tokens = {
5671                                 (void *)&cmd_setbonding_primary_set,
5672                                 (void *)&cmd_setbonding_primary_bonding,
5673                                 (void *)&cmd_setbonding_primary_primary,
5674                                 (void *)&cmd_setbonding_primary_slave,
5675                                 (void *)&cmd_setbonding_primary_port,
5676                                 NULL
5677                 }
5678 };
5679
5680 /* *** ADD SLAVE *** */
5681 struct cmd_add_bonding_slave_result {
5682         cmdline_fixed_string_t add;
5683         cmdline_fixed_string_t bonding;
5684         cmdline_fixed_string_t slave;
5685         portid_t slave_id;
5686         portid_t port_id;
5687 };
5688
5689 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5690                 __attribute__((unused))  struct cmdline *cl,
5691                 __attribute__((unused)) void *data)
5692 {
5693         struct cmd_add_bonding_slave_result *res = parsed_result;
5694         portid_t master_port_id = res->port_id;
5695         portid_t slave_port_id = res->slave_id;
5696
5697         /* add the slave for a bonded device. */
5698         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5699                 printf("\t Failed to add slave %d to master port = %d.\n",
5700                                 slave_port_id, master_port_id);
5701                 return;
5702         }
5703         init_port_config();
5704         set_port_slave_flag(slave_port_id);
5705 }
5706
5707 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5708 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5709                 add, "add");
5710 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5711 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5712                 bonding, "bonding");
5713 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5714 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5715                 slave, "slave");
5716 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5717 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5718                 slave_id, UINT16);
5719 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5720 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5721                 port_id, UINT16);
5722
5723 cmdline_parse_inst_t cmd_add_bonding_slave = {
5724                 .f = cmd_add_bonding_slave_parsed,
5725                 .help_str = "add bonding slave <slave_id> <port_id>: "
5726                         "Add a slave device to a bonded device",
5727                 .data = NULL,
5728                 .tokens = {
5729                                 (void *)&cmd_addbonding_slave_add,
5730                                 (void *)&cmd_addbonding_slave_bonding,
5731                                 (void *)&cmd_addbonding_slave_slave,
5732                                 (void *)&cmd_addbonding_slave_slaveid,
5733                                 (void *)&cmd_addbonding_slave_port,
5734                                 NULL
5735                 }
5736 };
5737
5738 /* *** REMOVE SLAVE *** */
5739 struct cmd_remove_bonding_slave_result {
5740         cmdline_fixed_string_t remove;
5741         cmdline_fixed_string_t bonding;
5742         cmdline_fixed_string_t slave;
5743         portid_t slave_id;
5744         portid_t port_id;
5745 };
5746
5747 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5748                 __attribute__((unused))  struct cmdline *cl,
5749                 __attribute__((unused)) void *data)
5750 {
5751         struct cmd_remove_bonding_slave_result *res = parsed_result;
5752         portid_t master_port_id = res->port_id;
5753         portid_t slave_port_id = res->slave_id;
5754
5755         /* remove the slave from a bonded device. */
5756         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5757                 printf("\t Failed to remove slave %d from master port = %d.\n",
5758                                 slave_port_id, master_port_id);
5759                 return;
5760         }
5761         init_port_config();
5762         clear_port_slave_flag(slave_port_id);
5763 }
5764
5765 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5766                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5767                                 remove, "remove");
5768 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5769                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5770                                 bonding, "bonding");
5771 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5772                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5773                                 slave, "slave");
5774 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5775                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5776                                 slave_id, UINT16);
5777 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5778                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5779                                 port_id, UINT16);
5780
5781 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5782                 .f = cmd_remove_bonding_slave_parsed,
5783                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5784                         "Remove a slave device from a bonded device",
5785                 .data = NULL,
5786                 .tokens = {
5787                                 (void *)&cmd_removebonding_slave_remove,
5788                                 (void *)&cmd_removebonding_slave_bonding,
5789                                 (void *)&cmd_removebonding_slave_slave,
5790                                 (void *)&cmd_removebonding_slave_slaveid,
5791                                 (void *)&cmd_removebonding_slave_port,
5792                                 NULL
5793                 }
5794 };
5795
5796 /* *** CREATE BONDED DEVICE *** */
5797 struct cmd_create_bonded_device_result {
5798         cmdline_fixed_string_t create;
5799         cmdline_fixed_string_t bonded;
5800         cmdline_fixed_string_t device;
5801         uint8_t mode;
5802         uint8_t socket;
5803 };
5804
5805 static int bond_dev_num = 0;
5806
5807 static void cmd_create_bonded_device_parsed(void *parsed_result,
5808                 __attribute__((unused))  struct cmdline *cl,
5809                 __attribute__((unused)) void *data)
5810 {
5811         struct cmd_create_bonded_device_result *res = parsed_result;
5812         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5813         int port_id;
5814
5815         if (test_done == 0) {
5816                 printf("Please stop forwarding first\n");
5817                 return;
5818         }
5819
5820         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5821                         bond_dev_num++);
5822
5823         /* Create a new bonded device. */
5824         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5825         if (port_id < 0) {
5826                 printf("\t Failed to create bonded device.\n");
5827                 return;
5828         } else {
5829                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5830                                 port_id);
5831
5832                 /* Update number of ports */
5833                 nb_ports = rte_eth_dev_count_avail();
5834                 reconfig(port_id, res->socket);
5835                 rte_eth_promiscuous_enable(port_id);
5836         }
5837
5838 }
5839
5840 cmdline_parse_token_string_t cmd_createbonded_device_create =
5841                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5842                                 create, "create");
5843 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5844                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5845                                 bonded, "bonded");
5846 cmdline_parse_token_string_t cmd_createbonded_device_device =
5847                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5848                                 device, "device");
5849 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5850                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5851                                 mode, UINT8);
5852 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5853                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5854                                 socket, UINT8);
5855
5856 cmdline_parse_inst_t cmd_create_bonded_device = {
5857                 .f = cmd_create_bonded_device_parsed,
5858                 .help_str = "create bonded device <mode> <socket>: "
5859                         "Create a new bonded device with specific bonding mode and socket",
5860                 .data = NULL,
5861                 .tokens = {
5862                                 (void *)&cmd_createbonded_device_create,
5863                                 (void *)&cmd_createbonded_device_bonded,
5864                                 (void *)&cmd_createbonded_device_device,
5865                                 (void *)&cmd_createbonded_device_mode,
5866                                 (void *)&cmd_createbonded_device_socket,
5867                                 NULL
5868                 }
5869 };
5870
5871 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5872 struct cmd_set_bond_mac_addr_result {
5873         cmdline_fixed_string_t set;
5874         cmdline_fixed_string_t bonding;
5875         cmdline_fixed_string_t mac_addr;
5876         uint16_t port_num;
5877         struct ether_addr address;
5878 };
5879
5880 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5881                 __attribute__((unused))  struct cmdline *cl,
5882                 __attribute__((unused)) void *data)
5883 {
5884         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5885         int ret;
5886
5887         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5888                 return;
5889
5890         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5891
5892         /* check the return value and print it if is < 0 */
5893         if (ret < 0)
5894                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5895 }
5896
5897 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5898                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5899 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5900                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5901                                 "bonding");
5902 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5903                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5904                                 "mac_addr");
5905 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5906                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5907                                 port_num, UINT16);
5908 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5909                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5910
5911 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5912                 .f = cmd_set_bond_mac_addr_parsed,
5913                 .data = (void *) 0,
5914                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5915                 .tokens = {
5916                                 (void *)&cmd_set_bond_mac_addr_set,
5917                                 (void *)&cmd_set_bond_mac_addr_bonding,
5918                                 (void *)&cmd_set_bond_mac_addr_mac,
5919                                 (void *)&cmd_set_bond_mac_addr_portnum,
5920                                 (void *)&cmd_set_bond_mac_addr_addr,
5921                                 NULL
5922                 }
5923 };
5924
5925
5926 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5927 struct cmd_set_bond_mon_period_result {
5928         cmdline_fixed_string_t set;
5929         cmdline_fixed_string_t bonding;
5930         cmdline_fixed_string_t mon_period;
5931         uint16_t port_num;
5932         uint32_t period_ms;
5933 };
5934
5935 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5936                 __attribute__((unused))  struct cmdline *cl,
5937                 __attribute__((unused)) void *data)
5938 {
5939         struct cmd_set_bond_mon_period_result *res = parsed_result;
5940         int ret;
5941
5942         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5943
5944         /* check the return value and print it if is < 0 */
5945         if (ret < 0)
5946                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5947 }
5948
5949 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5950                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5951                                 set, "set");
5952 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5953                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5954                                 bonding, "bonding");
5955 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5956                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5957                                 mon_period,     "mon_period");
5958 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5959                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5960                                 port_num, UINT16);
5961 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5962                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5963                                 period_ms, UINT32);
5964
5965 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5966                 .f = cmd_set_bond_mon_period_parsed,
5967                 .data = (void *) 0,
5968                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5969                 .tokens = {
5970                                 (void *)&cmd_set_bond_mon_period_set,
5971                                 (void *)&cmd_set_bond_mon_period_bonding,
5972                                 (void *)&cmd_set_bond_mon_period_mon_period,
5973                                 (void *)&cmd_set_bond_mon_period_portnum,
5974                                 (void *)&cmd_set_bond_mon_period_period_ms,
5975                                 NULL
5976                 }
5977 };
5978
5979
5980
5981 struct cmd_set_bonding_agg_mode_policy_result {
5982         cmdline_fixed_string_t set;
5983         cmdline_fixed_string_t bonding;
5984         cmdline_fixed_string_t agg_mode;
5985         uint16_t port_num;
5986         cmdline_fixed_string_t policy;
5987 };
5988
5989
5990 static void
5991 cmd_set_bonding_agg_mode(void *parsed_result,
5992                 __attribute__((unused)) struct cmdline *cl,
5993                 __attribute__((unused)) void *data)
5994 {
5995         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5996         uint8_t policy = AGG_BANDWIDTH;
5997
5998         if (!strcmp(res->policy, "bandwidth"))
5999                 policy = AGG_BANDWIDTH;
6000         else if (!strcmp(res->policy, "stable"))
6001                 policy = AGG_STABLE;
6002         else if (!strcmp(res->policy, "count"))
6003                 policy = AGG_COUNT;
6004
6005         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6006 }
6007
6008
6009 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6010         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6011                                 set, "set");
6012 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6013         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6014                                 bonding, "bonding");
6015
6016 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6017         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6018                                 agg_mode, "agg_mode");
6019
6020 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6021         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6022                                 port_num, UINT16);
6023
6024 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6025         TOKEN_STRING_INITIALIZER(
6026                         struct cmd_set_bonding_balance_xmit_policy_result,
6027                 policy, "stable#bandwidth#count");
6028
6029 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6030         .f = cmd_set_bonding_agg_mode,
6031         .data = (void *) 0,
6032         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6033         .tokens = {
6034                         (void *)&cmd_set_bonding_agg_mode_set,
6035                         (void *)&cmd_set_bonding_agg_mode_bonding,
6036                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6037                         (void *)&cmd_set_bonding_agg_mode_portnum,
6038                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6039                         NULL
6040                 }
6041 };
6042
6043
6044 #endif /* RTE_LIBRTE_PMD_BOND */
6045
6046 /* *** SET FORWARDING MODE *** */
6047 struct cmd_set_fwd_mode_result {
6048         cmdline_fixed_string_t set;
6049         cmdline_fixed_string_t fwd;
6050         cmdline_fixed_string_t mode;
6051 };
6052
6053 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6054                                     __attribute__((unused)) struct cmdline *cl,
6055                                     __attribute__((unused)) void *data)
6056 {
6057         struct cmd_set_fwd_mode_result *res = parsed_result;
6058
6059         retry_enabled = 0;
6060         set_pkt_forwarding_mode(res->mode);
6061 }
6062
6063 cmdline_parse_token_string_t cmd_setfwd_set =
6064         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6065 cmdline_parse_token_string_t cmd_setfwd_fwd =
6066         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6067 cmdline_parse_token_string_t cmd_setfwd_mode =
6068         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6069                 "" /* defined at init */);
6070
6071 cmdline_parse_inst_t cmd_set_fwd_mode = {
6072         .f = cmd_set_fwd_mode_parsed,
6073         .data = NULL,
6074         .help_str = NULL, /* defined at init */
6075         .tokens = {
6076                 (void *)&cmd_setfwd_set,
6077                 (void *)&cmd_setfwd_fwd,
6078                 (void *)&cmd_setfwd_mode,
6079                 NULL,
6080         },
6081 };
6082
6083 static void cmd_set_fwd_mode_init(void)
6084 {
6085         char *modes, *c;
6086         static char token[128];
6087         static char help[256];
6088         cmdline_parse_token_string_t *token_struct;
6089
6090         modes = list_pkt_forwarding_modes();
6091         snprintf(help, sizeof(help), "set fwd %s: "
6092                 "Set packet forwarding mode", modes);
6093         cmd_set_fwd_mode.help_str = help;
6094
6095         /* string token separator is # */
6096         for (c = token; *modes != '\0'; modes++)
6097                 if (*modes == '|')
6098                         *c++ = '#';
6099                 else
6100                         *c++ = *modes;
6101         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6102         token_struct->string_data.str = token;
6103 }
6104
6105 /* *** SET RETRY FORWARDING MODE *** */
6106 struct cmd_set_fwd_retry_mode_result {
6107         cmdline_fixed_string_t set;
6108         cmdline_fixed_string_t fwd;
6109         cmdline_fixed_string_t mode;
6110         cmdline_fixed_string_t retry;
6111 };
6112
6113 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6114                             __attribute__((unused)) struct cmdline *cl,
6115                             __attribute__((unused)) void *data)
6116 {
6117         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6118
6119         retry_enabled = 1;
6120         set_pkt_forwarding_mode(res->mode);
6121 }
6122
6123 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6124         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6125                         set, "set");
6126 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6127         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6128                         fwd, "fwd");
6129 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6130         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6131                         mode,
6132                 "" /* defined at init */);
6133 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6134         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6135                         retry, "retry");
6136
6137 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6138         .f = cmd_set_fwd_retry_mode_parsed,
6139         .data = NULL,
6140         .help_str = NULL, /* defined at init */
6141         .tokens = {
6142                 (void *)&cmd_setfwd_retry_set,
6143                 (void *)&cmd_setfwd_retry_fwd,
6144                 (void *)&cmd_setfwd_retry_mode,
6145                 (void *)&cmd_setfwd_retry_retry,
6146                 NULL,
6147         },
6148 };
6149
6150 static void cmd_set_fwd_retry_mode_init(void)
6151 {
6152         char *modes, *c;
6153         static char token[128];
6154         static char help[256];
6155         cmdline_parse_token_string_t *token_struct;
6156
6157         modes = list_pkt_forwarding_retry_modes();
6158         snprintf(help, sizeof(help), "set fwd %s retry: "
6159                 "Set packet forwarding mode with retry", modes);
6160         cmd_set_fwd_retry_mode.help_str = help;
6161
6162         /* string token separator is # */
6163         for (c = token; *modes != '\0'; modes++)
6164                 if (*modes == '|')
6165                         *c++ = '#';
6166                 else
6167                         *c++ = *modes;
6168         token_struct = (cmdline_parse_token_string_t *)
6169                 cmd_set_fwd_retry_mode.tokens[2];
6170         token_struct->string_data.str = token;
6171 }
6172
6173 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6174 struct cmd_set_burst_tx_retry_result {
6175         cmdline_fixed_string_t set;
6176         cmdline_fixed_string_t burst;
6177         cmdline_fixed_string_t tx;
6178         cmdline_fixed_string_t delay;
6179         uint32_t time;
6180         cmdline_fixed_string_t retry;
6181         uint32_t retry_num;
6182 };
6183
6184 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6185                                         __attribute__((unused)) struct cmdline *cl,
6186                                         __attribute__((unused)) void *data)
6187 {
6188         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6189
6190         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6191                 && !strcmp(res->tx, "tx")) {
6192                 if (!strcmp(res->delay, "delay"))
6193                         burst_tx_delay_time = res->time;
6194                 if (!strcmp(res->retry, "retry"))
6195                         burst_tx_retry_num = res->retry_num;
6196         }
6197
6198 }
6199
6200 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6201         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6202 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6203         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6204                                  "burst");
6205 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6206         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6207 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6208         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6209 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6210         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6211 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6212         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6213 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6214         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6215
6216 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6217         .f = cmd_set_burst_tx_retry_parsed,
6218         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6219         .tokens = {
6220                 (void *)&cmd_set_burst_tx_retry_set,
6221                 (void *)&cmd_set_burst_tx_retry_burst,
6222                 (void *)&cmd_set_burst_tx_retry_tx,
6223                 (void *)&cmd_set_burst_tx_retry_delay,
6224                 (void *)&cmd_set_burst_tx_retry_time,
6225                 (void *)&cmd_set_burst_tx_retry_retry,
6226                 (void *)&cmd_set_burst_tx_retry_retry_num,
6227                 NULL,
6228         },
6229 };
6230
6231 /* *** SET PROMISC MODE *** */
6232 struct cmd_set_promisc_mode_result {
6233         cmdline_fixed_string_t set;
6234         cmdline_fixed_string_t promisc;
6235         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6236         uint16_t port_num;               /* valid if "allports" argument == 0 */
6237         cmdline_fixed_string_t mode;
6238 };
6239
6240 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6241                                         __attribute__((unused)) struct cmdline *cl,
6242                                         void *allports)
6243 {
6244         struct cmd_set_promisc_mode_result *res = parsed_result;
6245         int enable;
6246         portid_t i;
6247
6248         if (!strcmp(res->mode, "on"))
6249                 enable = 1;
6250         else
6251                 enable = 0;
6252
6253         /* all ports */
6254         if (allports) {
6255                 RTE_ETH_FOREACH_DEV(i) {
6256                         if (enable)
6257                                 rte_eth_promiscuous_enable(i);
6258                         else
6259                                 rte_eth_promiscuous_disable(i);
6260                 }
6261         }
6262         else {
6263                 if (enable)
6264                         rte_eth_promiscuous_enable(res->port_num);
6265                 else
6266                         rte_eth_promiscuous_disable(res->port_num);
6267         }
6268 }
6269
6270 cmdline_parse_token_string_t cmd_setpromisc_set =
6271         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6272 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6273         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6274                                  "promisc");
6275 cmdline_parse_token_string_t cmd_setpromisc_portall =
6276         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6277                                  "all");
6278 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6279         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6280                               UINT16);
6281 cmdline_parse_token_string_t cmd_setpromisc_mode =
6282         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6283                                  "on#off");
6284
6285 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6286         .f = cmd_set_promisc_mode_parsed,
6287         .data = (void *)1,
6288         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6289         .tokens = {
6290                 (void *)&cmd_setpromisc_set,
6291                 (void *)&cmd_setpromisc_promisc,
6292                 (void *)&cmd_setpromisc_portall,
6293                 (void *)&cmd_setpromisc_mode,
6294                 NULL,
6295         },
6296 };
6297
6298 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6299         .f = cmd_set_promisc_mode_parsed,
6300         .data = (void *)0,
6301         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6302         .tokens = {
6303                 (void *)&cmd_setpromisc_set,
6304                 (void *)&cmd_setpromisc_promisc,
6305                 (void *)&cmd_setpromisc_portnum,
6306                 (void *)&cmd_setpromisc_mode,
6307                 NULL,
6308         },
6309 };
6310
6311 /* *** SET ALLMULTI MODE *** */
6312 struct cmd_set_allmulti_mode_result {
6313         cmdline_fixed_string_t set;
6314         cmdline_fixed_string_t allmulti;
6315         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6316         uint16_t port_num;               /* valid if "allports" argument == 0 */
6317         cmdline_fixed_string_t mode;
6318 };
6319
6320 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6321                                         __attribute__((unused)) struct cmdline *cl,
6322                                         void *allports)
6323 {
6324         struct cmd_set_allmulti_mode_result *res = parsed_result;
6325         int enable;
6326         portid_t i;
6327
6328         if (!strcmp(res->mode, "on"))
6329                 enable = 1;
6330         else
6331                 enable = 0;
6332
6333         /* all ports */
6334         if (allports) {
6335                 RTE_ETH_FOREACH_DEV(i) {
6336                         if (enable)
6337                                 rte_eth_allmulticast_enable(i);
6338                         else
6339                                 rte_eth_allmulticast_disable(i);
6340                 }
6341         }
6342         else {
6343                 if (enable)
6344                         rte_eth_allmulticast_enable(res->port_num);
6345                 else
6346                         rte_eth_allmulticast_disable(res->port_num);
6347         }
6348 }
6349
6350 cmdline_parse_token_string_t cmd_setallmulti_set =
6351         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6352 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6353         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6354                                  "allmulti");
6355 cmdline_parse_token_string_t cmd_setallmulti_portall =
6356         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6357                                  "all");
6358 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6359         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6360                               UINT16);
6361 cmdline_parse_token_string_t cmd_setallmulti_mode =
6362         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6363                                  "on#off");
6364
6365 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6366         .f = cmd_set_allmulti_mode_parsed,
6367         .data = (void *)1,
6368         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6369         .tokens = {
6370                 (void *)&cmd_setallmulti_set,
6371                 (void *)&cmd_setallmulti_allmulti,
6372                 (void *)&cmd_setallmulti_portall,
6373                 (void *)&cmd_setallmulti_mode,
6374                 NULL,
6375         },
6376 };
6377
6378 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6379         .f = cmd_set_allmulti_mode_parsed,
6380         .data = (void *)0,
6381         .help_str = "set allmulti <port_id> on|off: "
6382                 "Set allmulti mode on port_id",
6383         .tokens = {
6384                 (void *)&cmd_setallmulti_set,
6385                 (void *)&cmd_setallmulti_allmulti,
6386                 (void *)&cmd_setallmulti_portnum,
6387                 (void *)&cmd_setallmulti_mode,
6388                 NULL,
6389         },
6390 };
6391
6392 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6393 struct cmd_link_flow_ctrl_set_result {
6394         cmdline_fixed_string_t set;
6395         cmdline_fixed_string_t flow_ctrl;
6396         cmdline_fixed_string_t rx;
6397         cmdline_fixed_string_t rx_lfc_mode;
6398         cmdline_fixed_string_t tx;
6399         cmdline_fixed_string_t tx_lfc_mode;
6400         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6401         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6402         cmdline_fixed_string_t autoneg_str;
6403         cmdline_fixed_string_t autoneg;
6404         cmdline_fixed_string_t hw_str;
6405         uint32_t high_water;
6406         cmdline_fixed_string_t lw_str;
6407         uint32_t low_water;
6408         cmdline_fixed_string_t pt_str;
6409         uint16_t pause_time;
6410         cmdline_fixed_string_t xon_str;
6411         uint16_t send_xon;
6412         portid_t port_id;
6413 };
6414
6415 cmdline_parse_token_string_t cmd_lfc_set_set =
6416         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6417                                 set, "set");
6418 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6419         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6420                                 flow_ctrl, "flow_ctrl");
6421 cmdline_parse_token_string_t cmd_lfc_set_rx =
6422         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6423                                 rx, "rx");
6424 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6425         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6426                                 rx_lfc_mode, "on#off");
6427 cmdline_parse_token_string_t cmd_lfc_set_tx =
6428         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6429                                 tx, "tx");
6430 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6431         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6432                                 tx_lfc_mode, "on#off");
6433 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6434         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6435                                 hw_str, "high_water");
6436 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6437         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6438                                 high_water, UINT32);
6439 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6440         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6441                                 lw_str, "low_water");
6442 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6443         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6444                                 low_water, UINT32);
6445 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6446         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6447                                 pt_str, "pause_time");
6448 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6449         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6450                                 pause_time, UINT16);
6451 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6452         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6453                                 xon_str, "send_xon");
6454 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6455         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6456                                 send_xon, UINT16);
6457 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6458         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6459                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6460 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6461         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6462                                 mac_ctrl_frame_fwd_mode, "on#off");
6463 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6464         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6465                                 autoneg_str, "autoneg");
6466 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6467         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6468                                 autoneg, "on#off");
6469 cmdline_parse_token_num_t cmd_lfc_set_portid =
6470         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6471                                 port_id, UINT16);
6472
6473 /* forward declaration */
6474 static void
6475 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6476                               void *data);
6477
6478 cmdline_parse_inst_t cmd_link_flow_control_set = {
6479         .f = cmd_link_flow_ctrl_set_parsed,
6480         .data = NULL,
6481         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6482                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6483                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6484         .tokens = {
6485                 (void *)&cmd_lfc_set_set,
6486                 (void *)&cmd_lfc_set_flow_ctrl,
6487                 (void *)&cmd_lfc_set_rx,
6488                 (void *)&cmd_lfc_set_rx_mode,
6489                 (void *)&cmd_lfc_set_tx,
6490                 (void *)&cmd_lfc_set_tx_mode,
6491                 (void *)&cmd_lfc_set_high_water,
6492                 (void *)&cmd_lfc_set_low_water,
6493                 (void *)&cmd_lfc_set_pause_time,
6494                 (void *)&cmd_lfc_set_send_xon,
6495                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6496                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6497                 (void *)&cmd_lfc_set_autoneg_str,
6498                 (void *)&cmd_lfc_set_autoneg,
6499                 (void *)&cmd_lfc_set_portid,
6500                 NULL,
6501         },
6502 };
6503
6504 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6505         .f = cmd_link_flow_ctrl_set_parsed,
6506         .data = (void *)&cmd_link_flow_control_set_rx,
6507         .help_str = "set flow_ctrl rx on|off <port_id>: "
6508                 "Change rx flow control parameter",
6509         .tokens = {
6510                 (void *)&cmd_lfc_set_set,
6511                 (void *)&cmd_lfc_set_flow_ctrl,
6512                 (void *)&cmd_lfc_set_rx,
6513                 (void *)&cmd_lfc_set_rx_mode,
6514                 (void *)&cmd_lfc_set_portid,
6515                 NULL,
6516         },
6517 };
6518
6519 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6520         .f = cmd_link_flow_ctrl_set_parsed,
6521         .data = (void *)&cmd_link_flow_control_set_tx,
6522         .help_str = "set flow_ctrl tx on|off <port_id>: "
6523                 "Change tx flow control parameter",
6524         .tokens = {
6525                 (void *)&cmd_lfc_set_set,
6526                 (void *)&cmd_lfc_set_flow_ctrl,
6527                 (void *)&cmd_lfc_set_tx,
6528                 (void *)&cmd_lfc_set_tx_mode,
6529                 (void *)&cmd_lfc_set_portid,
6530                 NULL,
6531         },
6532 };
6533
6534 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6535         .f = cmd_link_flow_ctrl_set_parsed,
6536         .data = (void *)&cmd_link_flow_control_set_hw,
6537         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6538                 "Change high water flow control parameter",
6539         .tokens = {
6540                 (void *)&cmd_lfc_set_set,
6541                 (void *)&cmd_lfc_set_flow_ctrl,
6542                 (void *)&cmd_lfc_set_high_water_str,
6543                 (void *)&cmd_lfc_set_high_water,
6544                 (void *)&cmd_lfc_set_portid,
6545                 NULL,
6546         },
6547 };
6548
6549 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6550         .f = cmd_link_flow_ctrl_set_parsed,
6551         .data = (void *)&cmd_link_flow_control_set_lw,
6552         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6553                 "Change low water flow control parameter",
6554         .tokens = {
6555                 (void *)&cmd_lfc_set_set,
6556                 (void *)&cmd_lfc_set_flow_ctrl,
6557                 (void *)&cmd_lfc_set_low_water_str,
6558                 (void *)&cmd_lfc_set_low_water,
6559                 (void *)&cmd_lfc_set_portid,
6560                 NULL,
6561         },
6562 };
6563
6564 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6565         .f = cmd_link_flow_ctrl_set_parsed,
6566         .data = (void *)&cmd_link_flow_control_set_pt,
6567         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6568                 "Change pause time flow control parameter",
6569         .tokens = {
6570                 (void *)&cmd_lfc_set_set,
6571                 (void *)&cmd_lfc_set_flow_ctrl,
6572                 (void *)&cmd_lfc_set_pause_time_str,
6573                 (void *)&cmd_lfc_set_pause_time,
6574                 (void *)&cmd_lfc_set_portid,
6575                 NULL,
6576         },
6577 };
6578
6579 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6580         .f = cmd_link_flow_ctrl_set_parsed,
6581         .data = (void *)&cmd_link_flow_control_set_xon,
6582         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6583                 "Change send_xon flow control parameter",
6584         .tokens = {
6585                 (void *)&cmd_lfc_set_set,
6586                 (void *)&cmd_lfc_set_flow_ctrl,
6587                 (void *)&cmd_lfc_set_send_xon_str,
6588                 (void *)&cmd_lfc_set_send_xon,
6589                 (void *)&cmd_lfc_set_portid,
6590                 NULL,
6591         },
6592 };
6593
6594 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6595         .f = cmd_link_flow_ctrl_set_parsed,
6596         .data = (void *)&cmd_link_flow_control_set_macfwd,
6597         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6598                 "Change mac ctrl fwd flow control parameter",
6599         .tokens = {
6600                 (void *)&cmd_lfc_set_set,
6601                 (void *)&cmd_lfc_set_flow_ctrl,
6602                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6603                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6604                 (void *)&cmd_lfc_set_portid,
6605                 NULL,
6606         },
6607 };
6608
6609 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6610         .f = cmd_link_flow_ctrl_set_parsed,
6611         .data = (void *)&cmd_link_flow_control_set_autoneg,
6612         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6613                 "Change autoneg flow control parameter",
6614         .tokens = {
6615                 (void *)&cmd_lfc_set_set,
6616                 (void *)&cmd_lfc_set_flow_ctrl,
6617                 (void *)&cmd_lfc_set_autoneg_str,
6618                 (void *)&cmd_lfc_set_autoneg,
6619                 (void *)&cmd_lfc_set_portid,
6620                 NULL,
6621         },
6622 };
6623
6624 static void
6625 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6626                               __attribute__((unused)) struct cmdline *cl,
6627                               void *data)
6628 {
6629         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6630         cmdline_parse_inst_t *cmd = data;
6631         struct rte_eth_fc_conf fc_conf;
6632         int rx_fc_en = 0;
6633         int tx_fc_en = 0;
6634         int ret;
6635
6636         /*
6637          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6638          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6639          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6640          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6641          */
6642         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6643                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6644         };
6645
6646         /* Partial command line, retrieve current configuration */
6647         if (cmd) {
6648                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6649                 if (ret != 0) {
6650                         printf("cannot get current flow ctrl parameters, return"
6651                                "code = %d\n", ret);
6652                         return;
6653                 }
6654
6655                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6656                     (fc_conf.mode == RTE_FC_FULL))
6657                         rx_fc_en = 1;
6658                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6659                     (fc_conf.mode == RTE_FC_FULL))
6660                         tx_fc_en = 1;
6661         }
6662
6663         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6664                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6665
6666         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6667                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6668
6669         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6670
6671         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6672                 fc_conf.high_water = res->high_water;
6673
6674         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6675                 fc_conf.low_water = res->low_water;
6676
6677         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6678                 fc_conf.pause_time = res->pause_time;
6679
6680         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6681                 fc_conf.send_xon = res->send_xon;
6682
6683         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6684                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6685                         fc_conf.mac_ctrl_frame_fwd = 1;
6686                 else
6687                         fc_conf.mac_ctrl_frame_fwd = 0;
6688         }
6689
6690         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6691                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6692
6693         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6694         if (ret != 0)
6695                 printf("bad flow contrl parameter, return code = %d \n", ret);
6696 }
6697
6698 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6699 struct cmd_priority_flow_ctrl_set_result {
6700         cmdline_fixed_string_t set;
6701         cmdline_fixed_string_t pfc_ctrl;
6702         cmdline_fixed_string_t rx;
6703         cmdline_fixed_string_t rx_pfc_mode;
6704         cmdline_fixed_string_t tx;
6705         cmdline_fixed_string_t tx_pfc_mode;
6706         uint32_t high_water;
6707         uint32_t low_water;
6708         uint16_t pause_time;
6709         uint8_t  priority;
6710         portid_t port_id;
6711 };
6712
6713 static void
6714 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6715                        __attribute__((unused)) struct cmdline *cl,
6716                        __attribute__((unused)) void *data)
6717 {
6718         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6719         struct rte_eth_pfc_conf pfc_conf;
6720         int rx_fc_enable, tx_fc_enable;
6721         int ret;
6722
6723         /*
6724          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6725          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6726          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6727          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6728          */
6729         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6730                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6731         };
6732
6733         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6734         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6735         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6736         pfc_conf.fc.high_water = res->high_water;
6737         pfc_conf.fc.low_water  = res->low_water;
6738         pfc_conf.fc.pause_time = res->pause_time;
6739         pfc_conf.priority      = res->priority;
6740
6741         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6742         if (ret != 0)
6743                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6744 }
6745
6746 cmdline_parse_token_string_t cmd_pfc_set_set =
6747         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6748                                 set, "set");
6749 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6750         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6751                                 pfc_ctrl, "pfc_ctrl");
6752 cmdline_parse_token_string_t cmd_pfc_set_rx =
6753         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6754                                 rx, "rx");
6755 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6756         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6757                                 rx_pfc_mode, "on#off");
6758 cmdline_parse_token_string_t cmd_pfc_set_tx =
6759         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6760                                 tx, "tx");
6761 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6762         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6763                                 tx_pfc_mode, "on#off");
6764 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6765         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6766                                 high_water, UINT32);
6767 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6768         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6769                                 low_water, UINT32);
6770 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6771         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6772                                 pause_time, UINT16);
6773 cmdline_parse_token_num_t cmd_pfc_set_priority =
6774         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6775                                 priority, UINT8);
6776 cmdline_parse_token_num_t cmd_pfc_set_portid =
6777         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6778                                 port_id, UINT16);
6779
6780 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6781         .f = cmd_priority_flow_ctrl_set_parsed,
6782         .data = NULL,
6783         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6784                 "<pause_time> <priority> <port_id>: "
6785                 "Configure the Ethernet priority flow control",
6786         .tokens = {
6787                 (void *)&cmd_pfc_set_set,
6788                 (void *)&cmd_pfc_set_flow_ctrl,
6789                 (void *)&cmd_pfc_set_rx,
6790                 (void *)&cmd_pfc_set_rx_mode,
6791                 (void *)&cmd_pfc_set_tx,
6792                 (void *)&cmd_pfc_set_tx_mode,
6793                 (void *)&cmd_pfc_set_high_water,
6794                 (void *)&cmd_pfc_set_low_water,
6795                 (void *)&cmd_pfc_set_pause_time,
6796                 (void *)&cmd_pfc_set_priority,
6797                 (void *)&cmd_pfc_set_portid,
6798                 NULL,
6799         },
6800 };
6801
6802 /* *** RESET CONFIGURATION *** */
6803 struct cmd_reset_result {
6804         cmdline_fixed_string_t reset;
6805         cmdline_fixed_string_t def;
6806 };
6807
6808 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6809                              struct cmdline *cl,
6810                              __attribute__((unused)) void *data)
6811 {
6812         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6813         set_def_fwd_config();
6814 }
6815
6816 cmdline_parse_token_string_t cmd_reset_set =
6817         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6818 cmdline_parse_token_string_t cmd_reset_def =
6819         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6820                                  "default");
6821
6822 cmdline_parse_inst_t cmd_reset = {
6823         .f = cmd_reset_parsed,
6824         .data = NULL,
6825         .help_str = "set default: Reset default forwarding configuration",
6826         .tokens = {
6827                 (void *)&cmd_reset_set,
6828                 (void *)&cmd_reset_def,
6829                 NULL,
6830         },
6831 };
6832
6833 /* *** START FORWARDING *** */
6834 struct cmd_start_result {
6835         cmdline_fixed_string_t start;
6836 };
6837
6838 cmdline_parse_token_string_t cmd_start_start =
6839         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6840
6841 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6842                              __attribute__((unused)) struct cmdline *cl,
6843                              __attribute__((unused)) void *data)
6844 {
6845         start_packet_forwarding(0);
6846 }
6847
6848 cmdline_parse_inst_t cmd_start = {
6849         .f = cmd_start_parsed,
6850         .data = NULL,
6851         .help_str = "start: Start packet forwarding",
6852         .tokens = {
6853                 (void *)&cmd_start_start,
6854                 NULL,
6855         },
6856 };
6857
6858 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6859 struct cmd_start_tx_first_result {
6860         cmdline_fixed_string_t start;
6861         cmdline_fixed_string_t tx_first;
6862 };
6863
6864 static void
6865 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6866                           __attribute__((unused)) struct cmdline *cl,
6867                           __attribute__((unused)) void *data)
6868 {
6869         start_packet_forwarding(1);
6870 }
6871
6872 cmdline_parse_token_string_t cmd_start_tx_first_start =
6873         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6874                                  "start");
6875 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6876         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6877                                  tx_first, "tx_first");
6878
6879 cmdline_parse_inst_t cmd_start_tx_first = {
6880         .f = cmd_start_tx_first_parsed,
6881         .data = NULL,
6882         .help_str = "start tx_first: Start packet forwarding, "
6883                 "after sending 1 burst of packets",
6884         .tokens = {
6885                 (void *)&cmd_start_tx_first_start,
6886                 (void *)&cmd_start_tx_first_tx_first,
6887                 NULL,
6888         },
6889 };
6890
6891 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6892 struct cmd_start_tx_first_n_result {
6893         cmdline_fixed_string_t start;
6894         cmdline_fixed_string_t tx_first;
6895         uint32_t tx_num;
6896 };
6897
6898 static void
6899 cmd_start_tx_first_n_parsed(void *parsed_result,
6900                           __attribute__((unused)) struct cmdline *cl,
6901                           __attribute__((unused)) void *data)
6902 {
6903         struct cmd_start_tx_first_n_result *res = parsed_result;
6904
6905         start_packet_forwarding(res->tx_num);
6906 }
6907
6908 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6909         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6910                         start, "start");
6911 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6912         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6913                         tx_first, "tx_first");
6914 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6915         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6916                         tx_num, UINT32);
6917
6918 cmdline_parse_inst_t cmd_start_tx_first_n = {
6919         .f = cmd_start_tx_first_n_parsed,
6920         .data = NULL,
6921         .help_str = "start tx_first <num>: "
6922                 "packet forwarding, after sending <num> bursts of packets",
6923         .tokens = {
6924                 (void *)&cmd_start_tx_first_n_start,
6925                 (void *)&cmd_start_tx_first_n_tx_first,
6926                 (void *)&cmd_start_tx_first_n_tx_num,
6927                 NULL,
6928         },
6929 };
6930
6931 /* *** SET LINK UP *** */
6932 struct cmd_set_link_up_result {
6933         cmdline_fixed_string_t set;
6934         cmdline_fixed_string_t link_up;
6935         cmdline_fixed_string_t port;
6936         portid_t port_id;
6937 };
6938
6939 cmdline_parse_token_string_t cmd_set_link_up_set =
6940         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6941 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6942         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6943                                 "link-up");
6944 cmdline_parse_token_string_t cmd_set_link_up_port =
6945         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6946 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6947         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6948
6949 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6950                              __attribute__((unused)) struct cmdline *cl,
6951                              __attribute__((unused)) void *data)
6952 {
6953         struct cmd_set_link_up_result *res = parsed_result;
6954         dev_set_link_up(res->port_id);
6955 }
6956
6957 cmdline_parse_inst_t cmd_set_link_up = {
6958         .f = cmd_set_link_up_parsed,
6959         .data = NULL,
6960         .help_str = "set link-up port <port id>",
6961         .tokens = {
6962                 (void *)&cmd_set_link_up_set,
6963                 (void *)&cmd_set_link_up_link_up,
6964                 (void *)&cmd_set_link_up_port,
6965                 (void *)&cmd_set_link_up_port_id,
6966                 NULL,
6967         },
6968 };
6969
6970 /* *** SET LINK DOWN *** */
6971 struct cmd_set_link_down_result {
6972         cmdline_fixed_string_t set;
6973         cmdline_fixed_string_t link_down;
6974         cmdline_fixed_string_t port;
6975         portid_t port_id;
6976 };
6977
6978 cmdline_parse_token_string_t cmd_set_link_down_set =
6979         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6980 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6981         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6982                                 "link-down");
6983 cmdline_parse_token_string_t cmd_set_link_down_port =
6984         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6985 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6986         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6987
6988 static void cmd_set_link_down_parsed(
6989                                 __attribute__((unused)) void *parsed_result,
6990                                 __attribute__((unused)) struct cmdline *cl,
6991                                 __attribute__((unused)) void *data)
6992 {
6993         struct cmd_set_link_down_result *res = parsed_result;
6994         dev_set_link_down(res->port_id);
6995 }
6996
6997 cmdline_parse_inst_t cmd_set_link_down = {
6998         .f = cmd_set_link_down_parsed,
6999         .data = NULL,
7000         .help_str = "set link-down port <port id>",
7001         .tokens = {
7002                 (void *)&cmd_set_link_down_set,
7003                 (void *)&cmd_set_link_down_link_down,
7004                 (void *)&cmd_set_link_down_port,
7005                 (void *)&cmd_set_link_down_port_id,
7006                 NULL,
7007         },
7008 };
7009
7010 /* *** SHOW CFG *** */
7011 struct cmd_showcfg_result {
7012         cmdline_fixed_string_t show;
7013         cmdline_fixed_string_t cfg;
7014         cmdline_fixed_string_t what;
7015 };
7016
7017 static void cmd_showcfg_parsed(void *parsed_result,
7018                                __attribute__((unused)) struct cmdline *cl,
7019                                __attribute__((unused)) void *data)
7020 {
7021         struct cmd_showcfg_result *res = parsed_result;
7022         if (!strcmp(res->what, "rxtx"))
7023                 rxtx_config_display();
7024         else if (!strcmp(res->what, "cores"))
7025                 fwd_lcores_config_display();
7026         else if (!strcmp(res->what, "fwd"))
7027                 pkt_fwd_config_display(&cur_fwd_config);
7028         else if (!strcmp(res->what, "txpkts"))
7029                 show_tx_pkt_segments();
7030 }
7031
7032 cmdline_parse_token_string_t cmd_showcfg_show =
7033         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7034 cmdline_parse_token_string_t cmd_showcfg_port =
7035         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7036 cmdline_parse_token_string_t cmd_showcfg_what =
7037         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7038                                  "rxtx#cores#fwd#txpkts");
7039
7040 cmdline_parse_inst_t cmd_showcfg = {
7041         .f = cmd_showcfg_parsed,
7042         .data = NULL,
7043         .help_str = "show config rxtx|cores|fwd|txpkts",
7044         .tokens = {
7045                 (void *)&cmd_showcfg_show,
7046                 (void *)&cmd_showcfg_port,
7047                 (void *)&cmd_showcfg_what,
7048                 NULL,
7049         },
7050 };
7051
7052 /* *** SHOW ALL PORT INFO *** */
7053 struct cmd_showportall_result {
7054         cmdline_fixed_string_t show;
7055         cmdline_fixed_string_t port;
7056         cmdline_fixed_string_t what;
7057         cmdline_fixed_string_t all;
7058 };
7059
7060 static void cmd_showportall_parsed(void *parsed_result,
7061                                 __attribute__((unused)) struct cmdline *cl,
7062                                 __attribute__((unused)) void *data)
7063 {
7064         portid_t i;
7065
7066         struct cmd_showportall_result *res = parsed_result;
7067         if (!strcmp(res->show, "clear")) {
7068                 if (!strcmp(res->what, "stats"))
7069                         RTE_ETH_FOREACH_DEV(i)
7070                                 nic_stats_clear(i);
7071                 else if (!strcmp(res->what, "xstats"))
7072                         RTE_ETH_FOREACH_DEV(i)
7073                                 nic_xstats_clear(i);
7074         } else if (!strcmp(res->what, "info"))
7075                 RTE_ETH_FOREACH_DEV(i)
7076                         port_infos_display(i);
7077         else if (!strcmp(res->what, "stats"))
7078                 RTE_ETH_FOREACH_DEV(i)
7079                         nic_stats_display(i);
7080         else if (!strcmp(res->what, "xstats"))
7081                 RTE_ETH_FOREACH_DEV(i)
7082                         nic_xstats_display(i);
7083         else if (!strcmp(res->what, "fdir"))
7084                 RTE_ETH_FOREACH_DEV(i)
7085                         fdir_get_infos(i);
7086         else if (!strcmp(res->what, "stat_qmap"))
7087                 RTE_ETH_FOREACH_DEV(i)
7088                         nic_stats_mapping_display(i);
7089         else if (!strcmp(res->what, "dcb_tc"))
7090                 RTE_ETH_FOREACH_DEV(i)
7091                         port_dcb_info_display(i);
7092         else if (!strcmp(res->what, "cap"))
7093                 RTE_ETH_FOREACH_DEV(i)
7094                         port_offload_cap_display(i);
7095 }
7096
7097 cmdline_parse_token_string_t cmd_showportall_show =
7098         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7099                                  "show#clear");
7100 cmdline_parse_token_string_t cmd_showportall_port =
7101         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7102 cmdline_parse_token_string_t cmd_showportall_what =
7103         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7104                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7105 cmdline_parse_token_string_t cmd_showportall_all =
7106         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7107 cmdline_parse_inst_t cmd_showportall = {
7108         .f = cmd_showportall_parsed,
7109         .data = NULL,
7110         .help_str = "show|clear port "
7111                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7112         .tokens = {
7113                 (void *)&cmd_showportall_show,
7114                 (void *)&cmd_showportall_port,
7115                 (void *)&cmd_showportall_what,
7116                 (void *)&cmd_showportall_all,
7117                 NULL,
7118         },
7119 };
7120
7121 /* *** SHOW PORT INFO *** */
7122 struct cmd_showport_result {
7123         cmdline_fixed_string_t show;
7124         cmdline_fixed_string_t port;
7125         cmdline_fixed_string_t what;
7126         uint16_t portnum;
7127 };
7128
7129 static void cmd_showport_parsed(void *parsed_result,
7130                                 __attribute__((unused)) struct cmdline *cl,
7131                                 __attribute__((unused)) void *data)
7132 {
7133         struct cmd_showport_result *res = parsed_result;
7134         if (!strcmp(res->show, "clear")) {
7135                 if (!strcmp(res->what, "stats"))
7136                         nic_stats_clear(res->portnum);
7137                 else if (!strcmp(res->what, "xstats"))
7138                         nic_xstats_clear(res->portnum);
7139         } else if (!strcmp(res->what, "info"))
7140                 port_infos_display(res->portnum);
7141         else if (!strcmp(res->what, "stats"))
7142                 nic_stats_display(res->portnum);
7143         else if (!strcmp(res->what, "xstats"))
7144                 nic_xstats_display(res->portnum);
7145         else if (!strcmp(res->what, "fdir"))
7146                  fdir_get_infos(res->portnum);
7147         else if (!strcmp(res->what, "stat_qmap"))
7148                 nic_stats_mapping_display(res->portnum);
7149         else if (!strcmp(res->what, "dcb_tc"))
7150                 port_dcb_info_display(res->portnum);
7151         else if (!strcmp(res->what, "cap"))
7152                 port_offload_cap_display(res->portnum);
7153 }
7154
7155 cmdline_parse_token_string_t cmd_showport_show =
7156         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7157                                  "show#clear");
7158 cmdline_parse_token_string_t cmd_showport_port =
7159         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7160 cmdline_parse_token_string_t cmd_showport_what =
7161         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7162                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7163 cmdline_parse_token_num_t cmd_showport_portnum =
7164         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7165
7166 cmdline_parse_inst_t cmd_showport = {
7167         .f = cmd_showport_parsed,
7168         .data = NULL,
7169         .help_str = "show|clear port "
7170                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7171                 "<port_id>",
7172         .tokens = {
7173                 (void *)&cmd_showport_show,
7174                 (void *)&cmd_showport_port,
7175                 (void *)&cmd_showport_what,
7176                 (void *)&cmd_showport_portnum,
7177                 NULL,
7178         },
7179 };
7180
7181 /* *** SHOW QUEUE INFO *** */
7182 struct cmd_showqueue_result {
7183         cmdline_fixed_string_t show;
7184         cmdline_fixed_string_t type;
7185         cmdline_fixed_string_t what;
7186         uint16_t portnum;
7187         uint16_t queuenum;
7188 };
7189
7190 static void
7191 cmd_showqueue_parsed(void *parsed_result,
7192         __attribute__((unused)) struct cmdline *cl,
7193         __attribute__((unused)) void *data)
7194 {
7195         struct cmd_showqueue_result *res = parsed_result;
7196
7197         if (!strcmp(res->type, "rxq"))
7198                 rx_queue_infos_display(res->portnum, res->queuenum);
7199         else if (!strcmp(res->type, "txq"))
7200                 tx_queue_infos_display(res->portnum, res->queuenum);
7201 }
7202
7203 cmdline_parse_token_string_t cmd_showqueue_show =
7204         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7205 cmdline_parse_token_string_t cmd_showqueue_type =
7206         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7207 cmdline_parse_token_string_t cmd_showqueue_what =
7208         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7209 cmdline_parse_token_num_t cmd_showqueue_portnum =
7210         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7211 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7212         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7213
7214 cmdline_parse_inst_t cmd_showqueue = {
7215         .f = cmd_showqueue_parsed,
7216         .data = NULL,
7217         .help_str = "show rxq|txq info <port_id> <queue_id>",
7218         .tokens = {
7219                 (void *)&cmd_showqueue_show,
7220                 (void *)&cmd_showqueue_type,
7221                 (void *)&cmd_showqueue_what,
7222                 (void *)&cmd_showqueue_portnum,
7223                 (void *)&cmd_showqueue_queuenum,
7224                 NULL,
7225         },
7226 };
7227
7228 /* *** READ PORT REGISTER *** */
7229 struct cmd_read_reg_result {
7230         cmdline_fixed_string_t read;
7231         cmdline_fixed_string_t reg;
7232         portid_t port_id;
7233         uint32_t reg_off;
7234 };
7235
7236 static void
7237 cmd_read_reg_parsed(void *parsed_result,
7238                     __attribute__((unused)) struct cmdline *cl,
7239                     __attribute__((unused)) void *data)
7240 {
7241         struct cmd_read_reg_result *res = parsed_result;
7242         port_reg_display(res->port_id, res->reg_off);
7243 }
7244
7245 cmdline_parse_token_string_t cmd_read_reg_read =
7246         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7247 cmdline_parse_token_string_t cmd_read_reg_reg =
7248         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7249 cmdline_parse_token_num_t cmd_read_reg_port_id =
7250         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7251 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7252         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7253
7254 cmdline_parse_inst_t cmd_read_reg = {
7255         .f = cmd_read_reg_parsed,
7256         .data = NULL,
7257         .help_str = "read reg <port_id> <reg_off>",
7258         .tokens = {
7259                 (void *)&cmd_read_reg_read,
7260                 (void *)&cmd_read_reg_reg,
7261                 (void *)&cmd_read_reg_port_id,
7262                 (void *)&cmd_read_reg_reg_off,
7263                 NULL,
7264         },
7265 };
7266
7267 /* *** READ PORT REGISTER BIT FIELD *** */
7268 struct cmd_read_reg_bit_field_result {
7269         cmdline_fixed_string_t read;
7270         cmdline_fixed_string_t regfield;
7271         portid_t port_id;
7272         uint32_t reg_off;
7273         uint8_t bit1_pos;
7274         uint8_t bit2_pos;
7275 };
7276
7277 static void
7278 cmd_read_reg_bit_field_parsed(void *parsed_result,
7279                               __attribute__((unused)) struct cmdline *cl,
7280                               __attribute__((unused)) void *data)
7281 {
7282         struct cmd_read_reg_bit_field_result *res = parsed_result;
7283         port_reg_bit_field_display(res->port_id, res->reg_off,
7284                                    res->bit1_pos, res->bit2_pos);
7285 }
7286
7287 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7288         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7289                                  "read");
7290 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7291         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7292                                  regfield, "regfield");
7293 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7294         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7295                               UINT16);
7296 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7297         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7298                               UINT32);
7299 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7300         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7301                               UINT8);
7302 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7303         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7304                               UINT8);
7305
7306 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7307         .f = cmd_read_reg_bit_field_parsed,
7308         .data = NULL,
7309         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7310         "Read register bit field between bit_x and bit_y included",
7311         .tokens = {
7312                 (void *)&cmd_read_reg_bit_field_read,
7313                 (void *)&cmd_read_reg_bit_field_regfield,
7314                 (void *)&cmd_read_reg_bit_field_port_id,
7315                 (void *)&cmd_read_reg_bit_field_reg_off,
7316                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7317                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7318                 NULL,
7319         },
7320 };
7321
7322 /* *** READ PORT REGISTER BIT *** */
7323 struct cmd_read_reg_bit_result {
7324         cmdline_fixed_string_t read;
7325         cmdline_fixed_string_t regbit;
7326         portid_t port_id;
7327         uint32_t reg_off;
7328         uint8_t bit_pos;
7329 };
7330
7331 static void
7332 cmd_read_reg_bit_parsed(void *parsed_result,
7333                         __attribute__((unused)) struct cmdline *cl,
7334                         __attribute__((unused)) void *data)
7335 {
7336         struct cmd_read_reg_bit_result *res = parsed_result;
7337         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7338 }
7339
7340 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7341         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7342 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7343         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7344                                  regbit, "regbit");
7345 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7346         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7347 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7348         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7349 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7350         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7351
7352 cmdline_parse_inst_t cmd_read_reg_bit = {
7353         .f = cmd_read_reg_bit_parsed,
7354         .data = NULL,
7355         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7356         .tokens = {
7357                 (void *)&cmd_read_reg_bit_read,
7358                 (void *)&cmd_read_reg_bit_regbit,
7359                 (void *)&cmd_read_reg_bit_port_id,
7360                 (void *)&cmd_read_reg_bit_reg_off,
7361                 (void *)&cmd_read_reg_bit_bit_pos,
7362                 NULL,
7363         },
7364 };
7365
7366 /* *** WRITE PORT REGISTER *** */
7367 struct cmd_write_reg_result {
7368         cmdline_fixed_string_t write;
7369         cmdline_fixed_string_t reg;
7370         portid_t port_id;
7371         uint32_t reg_off;
7372         uint32_t value;
7373 };
7374
7375 static void
7376 cmd_write_reg_parsed(void *parsed_result,
7377                      __attribute__((unused)) struct cmdline *cl,
7378                      __attribute__((unused)) void *data)
7379 {
7380         struct cmd_write_reg_result *res = parsed_result;
7381         port_reg_set(res->port_id, res->reg_off, res->value);
7382 }
7383
7384 cmdline_parse_token_string_t cmd_write_reg_write =
7385         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7386 cmdline_parse_token_string_t cmd_write_reg_reg =
7387         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7388 cmdline_parse_token_num_t cmd_write_reg_port_id =
7389         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7390 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7391         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7392 cmdline_parse_token_num_t cmd_write_reg_value =
7393         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7394
7395 cmdline_parse_inst_t cmd_write_reg = {
7396         .f = cmd_write_reg_parsed,
7397         .data = NULL,
7398         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7399         .tokens = {
7400                 (void *)&cmd_write_reg_write,
7401                 (void *)&cmd_write_reg_reg,
7402                 (void *)&cmd_write_reg_port_id,
7403                 (void *)&cmd_write_reg_reg_off,
7404                 (void *)&cmd_write_reg_value,
7405                 NULL,
7406         },
7407 };
7408
7409 /* *** WRITE PORT REGISTER BIT FIELD *** */
7410 struct cmd_write_reg_bit_field_result {
7411         cmdline_fixed_string_t write;
7412         cmdline_fixed_string_t regfield;
7413         portid_t port_id;
7414         uint32_t reg_off;
7415         uint8_t bit1_pos;
7416         uint8_t bit2_pos;
7417         uint32_t value;
7418 };
7419
7420 static void
7421 cmd_write_reg_bit_field_parsed(void *parsed_result,
7422                                __attribute__((unused)) struct cmdline *cl,
7423                                __attribute__((unused)) void *data)
7424 {
7425         struct cmd_write_reg_bit_field_result *res = parsed_result;
7426         port_reg_bit_field_set(res->port_id, res->reg_off,
7427                           res->bit1_pos, res->bit2_pos, res->value);
7428 }
7429
7430 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7431         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7432                                  "write");
7433 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7434         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7435                                  regfield, "regfield");
7436 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7437         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7438                               UINT16);
7439 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7440         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7441                               UINT32);
7442 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7443         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7444                               UINT8);
7445 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7446         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7447                               UINT8);
7448 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7449         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7450                               UINT32);
7451
7452 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7453         .f = cmd_write_reg_bit_field_parsed,
7454         .data = NULL,
7455         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7456                 "<reg_value>: "
7457                 "Set register bit field between bit_x and bit_y included",
7458         .tokens = {
7459                 (void *)&cmd_write_reg_bit_field_write,
7460                 (void *)&cmd_write_reg_bit_field_regfield,
7461                 (void *)&cmd_write_reg_bit_field_port_id,
7462                 (void *)&cmd_write_reg_bit_field_reg_off,
7463                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7464                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7465                 (void *)&cmd_write_reg_bit_field_value,
7466                 NULL,
7467         },
7468 };
7469
7470 /* *** WRITE PORT REGISTER BIT *** */
7471 struct cmd_write_reg_bit_result {
7472         cmdline_fixed_string_t write;
7473         cmdline_fixed_string_t regbit;
7474         portid_t port_id;
7475         uint32_t reg_off;
7476         uint8_t bit_pos;
7477         uint8_t value;
7478 };
7479
7480 static void
7481 cmd_write_reg_bit_parsed(void *parsed_result,
7482                          __attribute__((unused)) struct cmdline *cl,
7483                          __attribute__((unused)) void *data)
7484 {
7485         struct cmd_write_reg_bit_result *res = parsed_result;
7486         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7487 }
7488
7489 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7490         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7491                                  "write");
7492 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7493         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7494                                  regbit, "regbit");
7495 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7496         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7497 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7498         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7499 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7500         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7501 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7502         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7503
7504 cmdline_parse_inst_t cmd_write_reg_bit = {
7505         .f = cmd_write_reg_bit_parsed,
7506         .data = NULL,
7507         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7508                 "0 <= bit_x <= 31",
7509         .tokens = {
7510                 (void *)&cmd_write_reg_bit_write,
7511                 (void *)&cmd_write_reg_bit_regbit,
7512                 (void *)&cmd_write_reg_bit_port_id,
7513                 (void *)&cmd_write_reg_bit_reg_off,
7514                 (void *)&cmd_write_reg_bit_bit_pos,
7515                 (void *)&cmd_write_reg_bit_value,
7516                 NULL,
7517         },
7518 };
7519
7520 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7521 struct cmd_read_rxd_txd_result {
7522         cmdline_fixed_string_t read;
7523         cmdline_fixed_string_t rxd_txd;
7524         portid_t port_id;
7525         uint16_t queue_id;
7526         uint16_t desc_id;
7527 };
7528
7529 static void
7530 cmd_read_rxd_txd_parsed(void *parsed_result,
7531                         __attribute__((unused)) struct cmdline *cl,
7532                         __attribute__((unused)) void *data)
7533 {
7534         struct cmd_read_rxd_txd_result *res = parsed_result;
7535
7536         if (!strcmp(res->rxd_txd, "rxd"))
7537                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7538         else if (!strcmp(res->rxd_txd, "txd"))
7539                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7540 }
7541
7542 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7543         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7544 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7545         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7546                                  "rxd#txd");
7547 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7548         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7549 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7550         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7551 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7552         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7553
7554 cmdline_parse_inst_t cmd_read_rxd_txd = {
7555         .f = cmd_read_rxd_txd_parsed,
7556         .data = NULL,
7557         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7558         .tokens = {
7559                 (void *)&cmd_read_rxd_txd_read,
7560                 (void *)&cmd_read_rxd_txd_rxd_txd,
7561                 (void *)&cmd_read_rxd_txd_port_id,
7562                 (void *)&cmd_read_rxd_txd_queue_id,
7563                 (void *)&cmd_read_rxd_txd_desc_id,
7564                 NULL,
7565         },
7566 };
7567
7568 /* *** QUIT *** */
7569 struct cmd_quit_result {
7570         cmdline_fixed_string_t quit;
7571 };
7572
7573 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7574                             struct cmdline *cl,
7575                             __attribute__((unused)) void *data)
7576 {
7577         pmd_test_exit();
7578         cmdline_quit(cl);
7579 }
7580
7581 cmdline_parse_token_string_t cmd_quit_quit =
7582         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7583
7584 cmdline_parse_inst_t cmd_quit = {
7585         .f = cmd_quit_parsed,
7586         .data = NULL,
7587         .help_str = "quit: Exit application",
7588         .tokens = {
7589                 (void *)&cmd_quit_quit,
7590                 NULL,
7591         },
7592 };
7593
7594 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7595 struct cmd_mac_addr_result {
7596         cmdline_fixed_string_t mac_addr_cmd;
7597         cmdline_fixed_string_t what;
7598         uint16_t port_num;
7599         struct ether_addr address;
7600 };
7601
7602 static void cmd_mac_addr_parsed(void *parsed_result,
7603                 __attribute__((unused)) struct cmdline *cl,
7604                 __attribute__((unused)) void *data)
7605 {
7606         struct cmd_mac_addr_result *res = parsed_result;
7607         int ret;
7608
7609         if (strcmp(res->what, "add") == 0)
7610                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7611         else if (strcmp(res->what, "set") == 0)
7612                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7613                                                        &res->address);
7614         else
7615                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7616
7617         /* check the return value and print it if is < 0 */
7618         if(ret < 0)
7619                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7620
7621 }
7622
7623 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7624         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7625                                 "mac_addr");
7626 cmdline_parse_token_string_t cmd_mac_addr_what =
7627         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7628                                 "add#remove#set");
7629 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7630                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7631                                         UINT16);
7632 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7633                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7634
7635 cmdline_parse_inst_t cmd_mac_addr = {
7636         .f = cmd_mac_addr_parsed,
7637         .data = (void *)0,
7638         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7639                         "Add/Remove/Set MAC address on port_id",
7640         .tokens = {
7641                 (void *)&cmd_mac_addr_cmd,
7642                 (void *)&cmd_mac_addr_what,
7643                 (void *)&cmd_mac_addr_portnum,
7644                 (void *)&cmd_mac_addr_addr,
7645                 NULL,
7646         },
7647 };
7648
7649 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7650 struct cmd_eth_peer_result {
7651         cmdline_fixed_string_t set;
7652         cmdline_fixed_string_t eth_peer;
7653         portid_t port_id;
7654         cmdline_fixed_string_t peer_addr;
7655 };
7656
7657 static void cmd_set_eth_peer_parsed(void *parsed_result,
7658                         __attribute__((unused)) struct cmdline *cl,
7659                         __attribute__((unused)) void *data)
7660 {
7661                 struct cmd_eth_peer_result *res = parsed_result;
7662
7663                 if (test_done == 0) {
7664                         printf("Please stop forwarding first\n");
7665                         return;
7666                 }
7667                 if (!strcmp(res->eth_peer, "eth-peer")) {
7668                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7669                         fwd_config_setup();
7670                 }
7671 }
7672 cmdline_parse_token_string_t cmd_eth_peer_set =
7673         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7674 cmdline_parse_token_string_t cmd_eth_peer =
7675         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7676 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7677         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7678 cmdline_parse_token_string_t cmd_eth_peer_addr =
7679         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7680
7681 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7682         .f = cmd_set_eth_peer_parsed,
7683         .data = NULL,
7684         .help_str = "set eth-peer <port_id> <peer_mac>",
7685         .tokens = {
7686                 (void *)&cmd_eth_peer_set,
7687                 (void *)&cmd_eth_peer,
7688                 (void *)&cmd_eth_peer_port_id,
7689                 (void *)&cmd_eth_peer_addr,
7690                 NULL,
7691         },
7692 };
7693
7694 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7695 struct cmd_set_qmap_result {
7696         cmdline_fixed_string_t set;
7697         cmdline_fixed_string_t qmap;
7698         cmdline_fixed_string_t what;
7699         portid_t port_id;
7700         uint16_t queue_id;
7701         uint8_t map_value;
7702 };
7703
7704 static void
7705 cmd_set_qmap_parsed(void *parsed_result,
7706                        __attribute__((unused)) struct cmdline *cl,
7707                        __attribute__((unused)) void *data)
7708 {
7709         struct cmd_set_qmap_result *res = parsed_result;
7710         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7711
7712         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7713 }
7714
7715 cmdline_parse_token_string_t cmd_setqmap_set =
7716         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7717                                  set, "set");
7718 cmdline_parse_token_string_t cmd_setqmap_qmap =
7719         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7720                                  qmap, "stat_qmap");
7721 cmdline_parse_token_string_t cmd_setqmap_what =
7722         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7723                                  what, "tx#rx");
7724 cmdline_parse_token_num_t cmd_setqmap_portid =
7725         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7726                               port_id, UINT16);
7727 cmdline_parse_token_num_t cmd_setqmap_queueid =
7728         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7729                               queue_id, UINT16);
7730 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7731         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7732                               map_value, UINT8);
7733
7734 cmdline_parse_inst_t cmd_set_qmap = {
7735         .f = cmd_set_qmap_parsed,
7736         .data = NULL,
7737         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7738                 "Set statistics mapping value on tx|rx queue_id of port_id",
7739         .tokens = {
7740                 (void *)&cmd_setqmap_set,
7741                 (void *)&cmd_setqmap_qmap,
7742                 (void *)&cmd_setqmap_what,
7743                 (void *)&cmd_setqmap_portid,
7744                 (void *)&cmd_setqmap_queueid,
7745                 (void *)&cmd_setqmap_mapvalue,
7746                 NULL,
7747         },
7748 };
7749
7750 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7751 struct cmd_set_xstats_hide_zero_result {
7752         cmdline_fixed_string_t keyword;
7753         cmdline_fixed_string_t name;
7754         cmdline_fixed_string_t on_off;
7755 };
7756
7757 static void
7758 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7759                         __attribute__((unused)) struct cmdline *cl,
7760                         __attribute__((unused)) void *data)
7761 {
7762         struct cmd_set_xstats_hide_zero_result *res;
7763         uint16_t on_off = 0;
7764
7765         res = parsed_result;
7766         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7767         set_xstats_hide_zero(on_off);
7768 }
7769
7770 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7771         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7772                                  keyword, "set");
7773 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7774         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7775                                  name, "xstats-hide-zero");
7776 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7777         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7778                                  on_off, "on#off");
7779
7780 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7781         .f = cmd_set_xstats_hide_zero_parsed,
7782         .data = NULL,
7783         .help_str = "set xstats-hide-zero on|off",
7784         .tokens = {
7785                 (void *)&cmd_set_xstats_hide_zero_keyword,
7786                 (void *)&cmd_set_xstats_hide_zero_name,
7787                 (void *)&cmd_set_xstats_hide_zero_on_off,
7788                 NULL,
7789         },
7790 };
7791
7792 /* *** CONFIGURE UNICAST HASH TABLE *** */
7793 struct cmd_set_uc_hash_table {
7794         cmdline_fixed_string_t set;
7795         cmdline_fixed_string_t port;
7796         portid_t port_id;
7797         cmdline_fixed_string_t what;
7798         struct ether_addr address;
7799         cmdline_fixed_string_t mode;
7800 };
7801
7802 static void
7803 cmd_set_uc_hash_parsed(void *parsed_result,
7804                        __attribute__((unused)) struct cmdline *cl,
7805                        __attribute__((unused)) void *data)
7806 {
7807         int ret=0;
7808         struct cmd_set_uc_hash_table *res = parsed_result;
7809
7810         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7811
7812         if (strcmp(res->what, "uta") == 0)
7813                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7814                                                 &res->address,(uint8_t)is_on);
7815         if (ret < 0)
7816                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7817
7818 }
7819
7820 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7821         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7822                                  set, "set");
7823 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7824         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7825                                  port, "port");
7826 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7827         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7828                               port_id, UINT16);
7829 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7830         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7831                                  what, "uta");
7832 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7833         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7834                                 address);
7835 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7836         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7837                                  mode, "on#off");
7838
7839 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7840         .f = cmd_set_uc_hash_parsed,
7841         .data = NULL,
7842         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7843         .tokens = {
7844                 (void *)&cmd_set_uc_hash_set,
7845                 (void *)&cmd_set_uc_hash_port,
7846                 (void *)&cmd_set_uc_hash_portid,
7847                 (void *)&cmd_set_uc_hash_what,
7848                 (void *)&cmd_set_uc_hash_mac,
7849                 (void *)&cmd_set_uc_hash_mode,
7850                 NULL,
7851         },
7852 };
7853
7854 struct cmd_set_uc_all_hash_table {
7855         cmdline_fixed_string_t set;
7856         cmdline_fixed_string_t port;
7857         portid_t port_id;
7858         cmdline_fixed_string_t what;
7859         cmdline_fixed_string_t value;
7860         cmdline_fixed_string_t mode;
7861 };
7862
7863 static void
7864 cmd_set_uc_all_hash_parsed(void *parsed_result,
7865                        __attribute__((unused)) struct cmdline *cl,
7866                        __attribute__((unused)) void *data)
7867 {
7868         int ret=0;
7869         struct cmd_set_uc_all_hash_table *res = parsed_result;
7870
7871         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7872
7873         if ((strcmp(res->what, "uta") == 0) &&
7874                 (strcmp(res->value, "all") == 0))
7875                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7876         if (ret < 0)
7877                 printf("bad unicast hash table parameter,"
7878                         "return code = %d \n", ret);
7879 }
7880
7881 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7882         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7883                                  set, "set");
7884 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7885         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7886                                  port, "port");
7887 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7888         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7889                               port_id, UINT16);
7890 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7891         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7892                                  what, "uta");
7893 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7894         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7895                                 value,"all");
7896 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7897         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7898                                  mode, "on#off");
7899
7900 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7901         .f = cmd_set_uc_all_hash_parsed,
7902         .data = NULL,
7903         .help_str = "set port <port_id> uta all on|off",
7904         .tokens = {
7905                 (void *)&cmd_set_uc_all_hash_set,
7906                 (void *)&cmd_set_uc_all_hash_port,
7907                 (void *)&cmd_set_uc_all_hash_portid,
7908                 (void *)&cmd_set_uc_all_hash_what,
7909                 (void *)&cmd_set_uc_all_hash_value,
7910                 (void *)&cmd_set_uc_all_hash_mode,
7911                 NULL,
7912         },
7913 };
7914
7915 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7916 struct cmd_set_vf_macvlan_filter {
7917         cmdline_fixed_string_t set;
7918         cmdline_fixed_string_t port;
7919         portid_t port_id;
7920         cmdline_fixed_string_t vf;
7921         uint8_t vf_id;
7922         struct ether_addr address;
7923         cmdline_fixed_string_t filter_type;
7924         cmdline_fixed_string_t mode;
7925 };
7926
7927 static void
7928 cmd_set_vf_macvlan_parsed(void *parsed_result,
7929                        __attribute__((unused)) struct cmdline *cl,
7930                        __attribute__((unused)) void *data)
7931 {
7932         int is_on, ret = 0;
7933         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7934         struct rte_eth_mac_filter filter;
7935
7936         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7937
7938         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7939
7940         /* set VF MAC filter */
7941         filter.is_vf = 1;
7942
7943         /* set VF ID */
7944         filter.dst_id = res->vf_id;
7945
7946         if (!strcmp(res->filter_type, "exact-mac"))
7947                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7948         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7949                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7950         else if (!strcmp(res->filter_type, "hashmac"))
7951                 filter.filter_type = RTE_MAC_HASH_MATCH;
7952         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7953                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7954
7955         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7956
7957         if (is_on)
7958                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7959                                         RTE_ETH_FILTER_MACVLAN,
7960                                         RTE_ETH_FILTER_ADD,
7961                                          &filter);
7962         else
7963                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7964                                         RTE_ETH_FILTER_MACVLAN,
7965                                         RTE_ETH_FILTER_DELETE,
7966                                         &filter);
7967
7968         if (ret < 0)
7969                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7970
7971 }
7972
7973 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7974         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7975                                  set, "set");
7976 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7977         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7978                                  port, "port");
7979 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7980         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7981                               port_id, UINT16);
7982 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7983         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7984                                  vf, "vf");
7985 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7986         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7987                                 vf_id, UINT8);
7988 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7989         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7990                                 address);
7991 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7992         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7993                                 filter_type, "exact-mac#exact-mac-vlan"
7994                                 "#hashmac#hashmac-vlan");
7995 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7996         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7997                                  mode, "on#off");
7998
7999 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8000         .f = cmd_set_vf_macvlan_parsed,
8001         .data = NULL,
8002         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8003                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8004                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8005                 "hash match rule: hash match of MAC and exact match of VLAN",
8006         .tokens = {
8007                 (void *)&cmd_set_vf_macvlan_set,
8008                 (void *)&cmd_set_vf_macvlan_port,
8009                 (void *)&cmd_set_vf_macvlan_portid,
8010                 (void *)&cmd_set_vf_macvlan_vf,
8011                 (void *)&cmd_set_vf_macvlan_vf_id,
8012                 (void *)&cmd_set_vf_macvlan_mac,
8013                 (void *)&cmd_set_vf_macvlan_filter_type,
8014                 (void *)&cmd_set_vf_macvlan_mode,
8015                 NULL,
8016         },
8017 };
8018
8019 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8020 struct cmd_set_vf_traffic {
8021         cmdline_fixed_string_t set;
8022         cmdline_fixed_string_t port;
8023         portid_t port_id;
8024         cmdline_fixed_string_t vf;
8025         uint8_t vf_id;
8026         cmdline_fixed_string_t what;
8027         cmdline_fixed_string_t mode;
8028 };
8029
8030 static void
8031 cmd_set_vf_traffic_parsed(void *parsed_result,
8032                        __attribute__((unused)) struct cmdline *cl,
8033                        __attribute__((unused)) void *data)
8034 {
8035         struct cmd_set_vf_traffic *res = parsed_result;
8036         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8037         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8038
8039         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8040 }
8041
8042 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8043         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8044                                  set, "set");
8045 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8046         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8047                                  port, "port");
8048 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8049         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8050                               port_id, UINT16);
8051 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8052         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8053                                  vf, "vf");
8054 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8055         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8056                               vf_id, UINT8);
8057 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8058         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8059                                  what, "tx#rx");
8060 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8061         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8062                                  mode, "on#off");
8063
8064 cmdline_parse_inst_t cmd_set_vf_traffic = {
8065         .f = cmd_set_vf_traffic_parsed,
8066         .data = NULL,
8067         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8068         .tokens = {
8069                 (void *)&cmd_setvf_traffic_set,
8070                 (void *)&cmd_setvf_traffic_port,
8071                 (void *)&cmd_setvf_traffic_portid,
8072                 (void *)&cmd_setvf_traffic_vf,
8073                 (void *)&cmd_setvf_traffic_vfid,
8074                 (void *)&cmd_setvf_traffic_what,
8075                 (void *)&cmd_setvf_traffic_mode,
8076                 NULL,
8077         },
8078 };
8079
8080 /* *** CONFIGURE VF RECEIVE MODE *** */
8081 struct cmd_set_vf_rxmode {
8082         cmdline_fixed_string_t set;
8083         cmdline_fixed_string_t port;
8084         portid_t port_id;
8085         cmdline_fixed_string_t vf;
8086         uint8_t vf_id;
8087         cmdline_fixed_string_t what;
8088         cmdline_fixed_string_t mode;
8089         cmdline_fixed_string_t on;
8090 };
8091
8092 static void
8093 cmd_set_vf_rxmode_parsed(void *parsed_result,
8094                        __attribute__((unused)) struct cmdline *cl,
8095                        __attribute__((unused)) void *data)
8096 {
8097         int ret = -ENOTSUP;
8098         uint16_t rx_mode = 0;
8099         struct cmd_set_vf_rxmode *res = parsed_result;
8100
8101         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8102         if (!strcmp(res->what,"rxmode")) {
8103                 if (!strcmp(res->mode, "AUPE"))
8104                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8105                 else if (!strcmp(res->mode, "ROPE"))
8106                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8107                 else if (!strcmp(res->mode, "BAM"))
8108                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8109                 else if (!strncmp(res->mode, "MPE",3))
8110                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8111         }
8112
8113         RTE_SET_USED(is_on);
8114
8115 #ifdef RTE_LIBRTE_IXGBE_PMD
8116         if (ret == -ENOTSUP)
8117                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8118                                                   rx_mode, (uint8_t)is_on);
8119 #endif
8120 #ifdef RTE_LIBRTE_BNXT_PMD
8121         if (ret == -ENOTSUP)
8122                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8123                                                  rx_mode, (uint8_t)is_on);
8124 #endif
8125         if (ret < 0)
8126                 printf("bad VF receive mode parameter, return code = %d \n",
8127                 ret);
8128 }
8129
8130 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8131         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8132                                  set, "set");
8133 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8134         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8135                                  port, "port");
8136 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8137         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8138                               port_id, UINT16);
8139 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8140         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8141                                  vf, "vf");
8142 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8143         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8144                               vf_id, UINT8);
8145 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8146         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8147                                  what, "rxmode");
8148 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8149         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8150                                  mode, "AUPE#ROPE#BAM#MPE");
8151 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8152         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8153                                  on, "on#off");
8154
8155 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8156         .f = cmd_set_vf_rxmode_parsed,
8157         .data = NULL,
8158         .help_str = "set port <port_id> vf <vf_id> rxmode "
8159                 "AUPE|ROPE|BAM|MPE on|off",
8160         .tokens = {
8161                 (void *)&cmd_set_vf_rxmode_set,
8162                 (void *)&cmd_set_vf_rxmode_port,
8163                 (void *)&cmd_set_vf_rxmode_portid,
8164                 (void *)&cmd_set_vf_rxmode_vf,
8165                 (void *)&cmd_set_vf_rxmode_vfid,
8166                 (void *)&cmd_set_vf_rxmode_what,
8167                 (void *)&cmd_set_vf_rxmode_mode,
8168                 (void *)&cmd_set_vf_rxmode_on,
8169                 NULL,
8170         },
8171 };
8172
8173 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8174 struct cmd_vf_mac_addr_result {
8175         cmdline_fixed_string_t mac_addr_cmd;
8176         cmdline_fixed_string_t what;
8177         cmdline_fixed_string_t port;
8178         uint16_t port_num;
8179         cmdline_fixed_string_t vf;
8180         uint8_t vf_num;
8181         struct ether_addr address;
8182 };
8183
8184 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8185                 __attribute__((unused)) struct cmdline *cl,
8186                 __attribute__((unused)) void *data)
8187 {
8188         struct cmd_vf_mac_addr_result *res = parsed_result;
8189         int ret = -ENOTSUP;
8190
8191         if (strcmp(res->what, "add") != 0)
8192                 return;
8193
8194 #ifdef RTE_LIBRTE_I40E_PMD
8195         if (ret == -ENOTSUP)
8196                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8197                                                    &res->address);
8198 #endif
8199 #ifdef RTE_LIBRTE_BNXT_PMD
8200         if (ret == -ENOTSUP)
8201                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8202                                                 res->vf_num);
8203 #endif
8204
8205         if(ret < 0)
8206                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8207
8208 }
8209
8210 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8211         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8212                                 mac_addr_cmd,"mac_addr");
8213 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8214         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8215                                 what,"add");
8216 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8217         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8218                                 port,"port");
8219 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8220         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8221                                 port_num, UINT16);
8222 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8223         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8224                                 vf,"vf");
8225 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8226         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8227                                 vf_num, UINT8);
8228 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8229         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8230                                 address);
8231
8232 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8233         .f = cmd_vf_mac_addr_parsed,
8234         .data = (void *)0,
8235         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8236                 "Add MAC address filtering for a VF on port_id",
8237         .tokens = {
8238                 (void *)&cmd_vf_mac_addr_cmd,
8239                 (void *)&cmd_vf_mac_addr_what,
8240                 (void *)&cmd_vf_mac_addr_port,
8241                 (void *)&cmd_vf_mac_addr_portnum,
8242                 (void *)&cmd_vf_mac_addr_vf,
8243                 (void *)&cmd_vf_mac_addr_vfnum,
8244                 (void *)&cmd_vf_mac_addr_addr,
8245                 NULL,
8246         },
8247 };
8248
8249 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8250 struct cmd_vf_rx_vlan_filter {
8251         cmdline_fixed_string_t rx_vlan;
8252         cmdline_fixed_string_t what;
8253         uint16_t vlan_id;
8254         cmdline_fixed_string_t port;
8255         portid_t port_id;
8256         cmdline_fixed_string_t vf;
8257         uint64_t vf_mask;
8258 };
8259
8260 static void
8261 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8262                           __attribute__((unused)) struct cmdline *cl,
8263                           __attribute__((unused)) void *data)
8264 {
8265         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8266         int ret = -ENOTSUP;
8267
8268         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8269
8270 #ifdef RTE_LIBRTE_IXGBE_PMD
8271         if (ret == -ENOTSUP)
8272                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8273                                 res->vlan_id, res->vf_mask, is_add);
8274 #endif
8275 #ifdef RTE_LIBRTE_I40E_PMD
8276         if (ret == -ENOTSUP)
8277                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8278                                 res->vlan_id, res->vf_mask, is_add);
8279 #endif
8280 #ifdef RTE_LIBRTE_BNXT_PMD
8281         if (ret == -ENOTSUP)
8282                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8283                                 res->vlan_id, res->vf_mask, is_add);
8284 #endif
8285
8286         switch (ret) {
8287         case 0:
8288                 break;
8289         case -EINVAL:
8290                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8291                                 res->vlan_id, res->vf_mask);
8292                 break;
8293         case -ENODEV:
8294                 printf("invalid port_id %d\n", res->port_id);
8295                 break;
8296         case -ENOTSUP:
8297                 printf("function not implemented or supported\n");
8298                 break;
8299         default:
8300                 printf("programming error: (%s)\n", strerror(-ret));
8301         }
8302 }
8303
8304 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8305         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8306                                  rx_vlan, "rx_vlan");
8307 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8308         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8309                                  what, "add#rm");
8310 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8311         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8312                               vlan_id, UINT16);
8313 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8314         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8315                                  port, "port");
8316 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8317         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8318                               port_id, UINT16);
8319 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8320         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8321                                  vf, "vf");
8322 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8323         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8324                               vf_mask, UINT64);
8325
8326 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8327         .f = cmd_vf_rx_vlan_filter_parsed,
8328         .data = NULL,
8329         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8330                 "(vf_mask = hexadecimal VF mask)",
8331         .tokens = {
8332                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8333                 (void *)&cmd_vf_rx_vlan_filter_what,
8334                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8335                 (void *)&cmd_vf_rx_vlan_filter_port,
8336                 (void *)&cmd_vf_rx_vlan_filter_portid,
8337                 (void *)&cmd_vf_rx_vlan_filter_vf,
8338                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8339                 NULL,
8340         },
8341 };
8342
8343 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8344 struct cmd_queue_rate_limit_result {
8345         cmdline_fixed_string_t set;
8346         cmdline_fixed_string_t port;
8347         uint16_t port_num;
8348         cmdline_fixed_string_t queue;
8349         uint8_t queue_num;
8350         cmdline_fixed_string_t rate;
8351         uint16_t rate_num;
8352 };
8353
8354 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8355                 __attribute__((unused)) struct cmdline *cl,
8356                 __attribute__((unused)) void *data)
8357 {
8358         struct cmd_queue_rate_limit_result *res = parsed_result;
8359         int ret = 0;
8360
8361         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8362                 && (strcmp(res->queue, "queue") == 0)
8363                 && (strcmp(res->rate, "rate") == 0))
8364                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8365                                         res->rate_num);
8366         if (ret < 0)
8367                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8368
8369 }
8370
8371 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8372         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8373                                 set, "set");
8374 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8375         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8376                                 port, "port");
8377 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8378         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8379                                 port_num, UINT16);
8380 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8381         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8382                                 queue, "queue");
8383 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8384         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8385                                 queue_num, UINT8);
8386 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8387         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8388                                 rate, "rate");
8389 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8390         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8391                                 rate_num, UINT16);
8392
8393 cmdline_parse_inst_t cmd_queue_rate_limit = {
8394         .f = cmd_queue_rate_limit_parsed,
8395         .data = (void *)0,
8396         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8397                 "Set rate limit for a queue on port_id",
8398         .tokens = {
8399                 (void *)&cmd_queue_rate_limit_set,
8400                 (void *)&cmd_queue_rate_limit_port,
8401                 (void *)&cmd_queue_rate_limit_portnum,
8402                 (void *)&cmd_queue_rate_limit_queue,
8403                 (void *)&cmd_queue_rate_limit_queuenum,
8404                 (void *)&cmd_queue_rate_limit_rate,
8405                 (void *)&cmd_queue_rate_limit_ratenum,
8406                 NULL,
8407         },
8408 };
8409
8410 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8411 struct cmd_vf_rate_limit_result {
8412         cmdline_fixed_string_t set;
8413         cmdline_fixed_string_t port;
8414         uint16_t port_num;
8415         cmdline_fixed_string_t vf;
8416         uint8_t vf_num;
8417         cmdline_fixed_string_t rate;
8418         uint16_t rate_num;
8419         cmdline_fixed_string_t q_msk;
8420         uint64_t q_msk_val;
8421 };
8422
8423 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8424                 __attribute__((unused)) struct cmdline *cl,
8425                 __attribute__((unused)) void *data)
8426 {
8427         struct cmd_vf_rate_limit_result *res = parsed_result;
8428         int ret = 0;
8429
8430         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8431                 && (strcmp(res->vf, "vf") == 0)
8432                 && (strcmp(res->rate, "rate") == 0)
8433                 && (strcmp(res->q_msk, "queue_mask") == 0))
8434                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8435                                         res->rate_num, res->q_msk_val);
8436         if (ret < 0)
8437                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8438
8439 }
8440
8441 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8442         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8443                                 set, "set");
8444 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8445         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8446                                 port, "port");
8447 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8448         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8449                                 port_num, UINT16);
8450 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8451         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8452                                 vf, "vf");
8453 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8454         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8455                                 vf_num, UINT8);
8456 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8457         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8458                                 rate, "rate");
8459 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8460         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8461                                 rate_num, UINT16);
8462 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8463         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8464                                 q_msk, "queue_mask");
8465 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8466         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8467                                 q_msk_val, UINT64);
8468
8469 cmdline_parse_inst_t cmd_vf_rate_limit = {
8470         .f = cmd_vf_rate_limit_parsed,
8471         .data = (void *)0,
8472         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8473                 "queue_mask <queue_mask_value>: "
8474                 "Set rate limit for queues of VF on port_id",
8475         .tokens = {
8476                 (void *)&cmd_vf_rate_limit_set,
8477                 (void *)&cmd_vf_rate_limit_port,
8478                 (void *)&cmd_vf_rate_limit_portnum,
8479                 (void *)&cmd_vf_rate_limit_vf,
8480                 (void *)&cmd_vf_rate_limit_vfnum,
8481                 (void *)&cmd_vf_rate_limit_rate,
8482                 (void *)&cmd_vf_rate_limit_ratenum,
8483                 (void *)&cmd_vf_rate_limit_q_msk,
8484                 (void *)&cmd_vf_rate_limit_q_msk_val,
8485                 NULL,
8486         },
8487 };
8488
8489 /* *** ADD TUNNEL FILTER OF A PORT *** */
8490 struct cmd_tunnel_filter_result {
8491         cmdline_fixed_string_t cmd;
8492         cmdline_fixed_string_t what;
8493         portid_t port_id;
8494         struct ether_addr outer_mac;
8495         struct ether_addr inner_mac;
8496         cmdline_ipaddr_t ip_value;
8497         uint16_t inner_vlan;
8498         cmdline_fixed_string_t tunnel_type;
8499         cmdline_fixed_string_t filter_type;
8500         uint32_t tenant_id;
8501         uint16_t queue_num;
8502 };
8503
8504 static void
8505 cmd_tunnel_filter_parsed(void *parsed_result,
8506                           __attribute__((unused)) struct cmdline *cl,
8507                           __attribute__((unused)) void *data)
8508 {
8509         struct cmd_tunnel_filter_result *res = parsed_result;
8510         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8511         int ret = 0;
8512
8513         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8514
8515         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8516         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8517         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8518
8519         if (res->ip_value.family == AF_INET) {
8520                 tunnel_filter_conf.ip_addr.ipv4_addr =
8521                         res->ip_value.addr.ipv4.s_addr;
8522                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8523         } else {
8524                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8525                         &(res->ip_value.addr.ipv6),
8526                         sizeof(struct in6_addr));
8527                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8528         }
8529
8530         if (!strcmp(res->filter_type, "imac-ivlan"))
8531                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8532         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8533                 tunnel_filter_conf.filter_type =
8534                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8535         else if (!strcmp(res->filter_type, "imac-tenid"))
8536                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8537         else if (!strcmp(res->filter_type, "imac"))
8538                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8539         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8540                 tunnel_filter_conf.filter_type =
8541                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8542         else if (!strcmp(res->filter_type, "oip"))
8543                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8544         else if (!strcmp(res->filter_type, "iip"))
8545                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8546         else {
8547                 printf("The filter type is not supported");
8548                 return;
8549         }
8550
8551         if (!strcmp(res->tunnel_type, "vxlan"))
8552                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8553         else if (!strcmp(res->tunnel_type, "nvgre"))
8554                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8555         else if (!strcmp(res->tunnel_type, "ipingre"))
8556                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8557         else {
8558                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8559                 return;
8560         }
8561
8562         tunnel_filter_conf.tenant_id = res->tenant_id;
8563         tunnel_filter_conf.queue_id = res->queue_num;
8564         if (!strcmp(res->what, "add"))
8565                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8566                                         RTE_ETH_FILTER_TUNNEL,
8567                                         RTE_ETH_FILTER_ADD,
8568                                         &tunnel_filter_conf);
8569         else
8570                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8571                                         RTE_ETH_FILTER_TUNNEL,
8572                                         RTE_ETH_FILTER_DELETE,
8573                                         &tunnel_filter_conf);
8574         if (ret < 0)
8575                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8576                                 strerror(-ret));
8577
8578 }
8579 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8580         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8581         cmd, "tunnel_filter");
8582 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8583         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8584         what, "add#rm");
8585 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8586         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8587         port_id, UINT16);
8588 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8589         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8590         outer_mac);
8591 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8592         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8593         inner_mac);
8594 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8595         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8596         inner_vlan, UINT16);
8597 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8598         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8599         ip_value);
8600 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8601         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8602         tunnel_type, "vxlan#nvgre#ipingre");
8603
8604 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8605         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8606         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8607                 "imac#omac-imac-tenid");
8608 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8609         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8610         tenant_id, UINT32);
8611 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8612         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8613         queue_num, UINT16);
8614
8615 cmdline_parse_inst_t cmd_tunnel_filter = {
8616         .f = cmd_tunnel_filter_parsed,
8617         .data = (void *)0,
8618         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8619                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8620                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8621                 "<queue_id>: Add/Rm tunnel filter of a port",
8622         .tokens = {
8623                 (void *)&cmd_tunnel_filter_cmd,
8624                 (void *)&cmd_tunnel_filter_what,
8625                 (void *)&cmd_tunnel_filter_port_id,
8626                 (void *)&cmd_tunnel_filter_outer_mac,
8627                 (void *)&cmd_tunnel_filter_inner_mac,
8628                 (void *)&cmd_tunnel_filter_ip_value,
8629                 (void *)&cmd_tunnel_filter_innner_vlan,
8630                 (void *)&cmd_tunnel_filter_tunnel_type,
8631                 (void *)&cmd_tunnel_filter_filter_type,
8632                 (void *)&cmd_tunnel_filter_tenant_id,
8633                 (void *)&cmd_tunnel_filter_queue_num,
8634                 NULL,
8635         },
8636 };
8637
8638 /* *** CONFIGURE TUNNEL UDP PORT *** */
8639 struct cmd_tunnel_udp_config {
8640         cmdline_fixed_string_t cmd;
8641         cmdline_fixed_string_t what;
8642         uint16_t udp_port;
8643         portid_t port_id;
8644 };
8645
8646 static void
8647 cmd_tunnel_udp_config_parsed(void *parsed_result,
8648                           __attribute__((unused)) struct cmdline *cl,
8649                           __attribute__((unused)) void *data)
8650 {
8651         struct cmd_tunnel_udp_config *res = parsed_result;
8652         struct rte_eth_udp_tunnel tunnel_udp;
8653         int ret;
8654
8655         tunnel_udp.udp_port = res->udp_port;
8656
8657         if (!strcmp(res->cmd, "rx_vxlan_port"))
8658                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8659
8660         if (!strcmp(res->what, "add"))
8661                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8662                                                       &tunnel_udp);
8663         else
8664                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8665                                                          &tunnel_udp);
8666
8667         if (ret < 0)
8668                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8669 }
8670
8671 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8672         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8673                                 cmd, "rx_vxlan_port");
8674 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8675         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8676                                 what, "add#rm");
8677 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8678         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8679                                 udp_port, UINT16);
8680 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8681         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8682                                 port_id, UINT16);
8683
8684 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8685         .f = cmd_tunnel_udp_config_parsed,
8686         .data = (void *)0,
8687         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8688                 "Add/Remove a tunneling UDP port filter",
8689         .tokens = {
8690                 (void *)&cmd_tunnel_udp_config_cmd,
8691                 (void *)&cmd_tunnel_udp_config_what,
8692                 (void *)&cmd_tunnel_udp_config_udp_port,
8693                 (void *)&cmd_tunnel_udp_config_port_id,
8694                 NULL,
8695         },
8696 };
8697
8698 struct cmd_config_tunnel_udp_port {
8699         cmdline_fixed_string_t port;
8700         cmdline_fixed_string_t config;
8701         portid_t port_id;
8702         cmdline_fixed_string_t udp_tunnel_port;
8703         cmdline_fixed_string_t action;
8704         cmdline_fixed_string_t tunnel_type;
8705         uint16_t udp_port;
8706 };
8707
8708 static void
8709 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8710                                __attribute__((unused)) struct cmdline *cl,
8711                                __attribute__((unused)) void *data)
8712 {
8713         struct cmd_config_tunnel_udp_port *res = parsed_result;
8714         struct rte_eth_udp_tunnel tunnel_udp;
8715         int ret = 0;
8716
8717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8718                 return;
8719
8720         tunnel_udp.udp_port = res->udp_port;
8721
8722         if (!strcmp(res->tunnel_type, "vxlan")) {
8723                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8724         } else if (!strcmp(res->tunnel_type, "geneve")) {
8725                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8726         } else {
8727                 printf("Invalid tunnel type\n");
8728                 return;
8729         }
8730
8731         if (!strcmp(res->action, "add"))
8732                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8733                                                       &tunnel_udp);
8734         else
8735                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8736                                                          &tunnel_udp);
8737
8738         if (ret < 0)
8739                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8740 }
8741
8742 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8743         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8744                                  "port");
8745 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8746         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8747                                  "config");
8748 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8749         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8750                               UINT16);
8751 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8752         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8753                                  udp_tunnel_port,
8754                                  "udp_tunnel_port");
8755 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8756         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8757                                  "add#rm");
8758 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8759         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8760                                  "vxlan#geneve");
8761 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8762         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8763                               UINT16);
8764
8765 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8766         .f = cmd_cfg_tunnel_udp_port_parsed,
8767         .data = NULL,
8768         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8769         .tokens = {
8770                 (void *)&cmd_config_tunnel_udp_port_port,
8771                 (void *)&cmd_config_tunnel_udp_port_config,
8772                 (void *)&cmd_config_tunnel_udp_port_port_id,
8773                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8774                 (void *)&cmd_config_tunnel_udp_port_action,
8775                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8776                 (void *)&cmd_config_tunnel_udp_port_value,
8777                 NULL,
8778         },
8779 };
8780
8781 /* *** GLOBAL CONFIG *** */
8782 struct cmd_global_config_result {
8783         cmdline_fixed_string_t cmd;
8784         portid_t port_id;
8785         cmdline_fixed_string_t cfg_type;
8786         uint8_t len;
8787 };
8788
8789 static void
8790 cmd_global_config_parsed(void *parsed_result,
8791                          __attribute__((unused)) struct cmdline *cl,
8792                          __attribute__((unused)) void *data)
8793 {
8794         struct cmd_global_config_result *res = parsed_result;
8795         struct rte_eth_global_cfg conf;
8796         int ret;
8797
8798         memset(&conf, 0, sizeof(conf));
8799         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8800         conf.cfg.gre_key_len = res->len;
8801         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8802                                       RTE_ETH_FILTER_SET, &conf);
8803         if (ret != 0)
8804                 printf("Global config error\n");
8805 }
8806
8807 cmdline_parse_token_string_t cmd_global_config_cmd =
8808         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8809                 "global_config");
8810 cmdline_parse_token_num_t cmd_global_config_port_id =
8811         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8812                                UINT16);
8813 cmdline_parse_token_string_t cmd_global_config_type =
8814         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8815                 cfg_type, "gre-key-len");
8816 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8817         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8818                 len, UINT8);
8819
8820 cmdline_parse_inst_t cmd_global_config = {
8821         .f = cmd_global_config_parsed,
8822         .data = (void *)NULL,
8823         .help_str = "global_config <port_id> gre-key-len <key_len>",
8824         .tokens = {
8825                 (void *)&cmd_global_config_cmd,
8826                 (void *)&cmd_global_config_port_id,
8827                 (void *)&cmd_global_config_type,
8828                 (void *)&cmd_global_config_gre_key_len,
8829                 NULL,
8830         },
8831 };
8832
8833 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8834 struct cmd_set_mirror_mask_result {
8835         cmdline_fixed_string_t set;
8836         cmdline_fixed_string_t port;
8837         portid_t port_id;
8838         cmdline_fixed_string_t mirror;
8839         uint8_t rule_id;
8840         cmdline_fixed_string_t what;
8841         cmdline_fixed_string_t value;
8842         cmdline_fixed_string_t dstpool;
8843         uint8_t dstpool_id;
8844         cmdline_fixed_string_t on;
8845 };
8846
8847 cmdline_parse_token_string_t cmd_mirror_mask_set =
8848         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8849                                 set, "set");
8850 cmdline_parse_token_string_t cmd_mirror_mask_port =
8851         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8852                                 port, "port");
8853 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8854         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8855                                 port_id, UINT16);
8856 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8857         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8858                                 mirror, "mirror-rule");
8859 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8860         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8861                                 rule_id, UINT8);
8862 cmdline_parse_token_string_t cmd_mirror_mask_what =
8863         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8864                                 what, "pool-mirror-up#pool-mirror-down"
8865                                       "#vlan-mirror");
8866 cmdline_parse_token_string_t cmd_mirror_mask_value =
8867         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8868                                 value, NULL);
8869 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8870         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8871                                 dstpool, "dst-pool");
8872 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8873         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8874                                 dstpool_id, UINT8);
8875 cmdline_parse_token_string_t cmd_mirror_mask_on =
8876         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8877                                 on, "on#off");
8878
8879 static void
8880 cmd_set_mirror_mask_parsed(void *parsed_result,
8881                        __attribute__((unused)) struct cmdline *cl,
8882                        __attribute__((unused)) void *data)
8883 {
8884         int ret,nb_item,i;
8885         struct cmd_set_mirror_mask_result *res = parsed_result;
8886         struct rte_eth_mirror_conf mr_conf;
8887
8888         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8889
8890         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8891
8892         mr_conf.dst_pool = res->dstpool_id;
8893
8894         if (!strcmp(res->what, "pool-mirror-up")) {
8895                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8896                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8897         } else if (!strcmp(res->what, "pool-mirror-down")) {
8898                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8899                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8900         } else if (!strcmp(res->what, "vlan-mirror")) {
8901                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8902                 nb_item = parse_item_list(res->value, "vlan",
8903                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8904                 if (nb_item <= 0)
8905                         return;
8906
8907                 for (i = 0; i < nb_item; i++) {
8908                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8909                                 printf("Invalid vlan_id: must be < 4096\n");
8910                                 return;
8911                         }
8912
8913                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8914                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8915                 }
8916         }
8917
8918         if (!strcmp(res->on, "on"))
8919                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8920                                                 res->rule_id, 1);
8921         else
8922                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8923                                                 res->rule_id, 0);
8924         if (ret < 0)
8925                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8926 }
8927
8928 cmdline_parse_inst_t cmd_set_mirror_mask = {
8929                 .f = cmd_set_mirror_mask_parsed,
8930                 .data = NULL,
8931                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8932                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8933                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8934                 .tokens = {
8935                         (void *)&cmd_mirror_mask_set,
8936                         (void *)&cmd_mirror_mask_port,
8937                         (void *)&cmd_mirror_mask_portid,
8938                         (void *)&cmd_mirror_mask_mirror,
8939                         (void *)&cmd_mirror_mask_ruleid,
8940                         (void *)&cmd_mirror_mask_what,
8941                         (void *)&cmd_mirror_mask_value,
8942                         (void *)&cmd_mirror_mask_dstpool,
8943                         (void *)&cmd_mirror_mask_poolid,
8944                         (void *)&cmd_mirror_mask_on,
8945                         NULL,
8946                 },
8947 };
8948
8949 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8950 struct cmd_set_mirror_link_result {
8951         cmdline_fixed_string_t set;
8952         cmdline_fixed_string_t port;
8953         portid_t port_id;
8954         cmdline_fixed_string_t mirror;
8955         uint8_t rule_id;
8956         cmdline_fixed_string_t what;
8957         cmdline_fixed_string_t dstpool;
8958         uint8_t dstpool_id;
8959         cmdline_fixed_string_t on;
8960 };
8961
8962 cmdline_parse_token_string_t cmd_mirror_link_set =
8963         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8964                                  set, "set");
8965 cmdline_parse_token_string_t cmd_mirror_link_port =
8966         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8967                                 port, "port");
8968 cmdline_parse_token_num_t cmd_mirror_link_portid =
8969         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8970                                 port_id, UINT16);
8971 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8972         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8973                                 mirror, "mirror-rule");
8974 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8975         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8976                             rule_id, UINT8);
8977 cmdline_parse_token_string_t cmd_mirror_link_what =
8978         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8979                                 what, "uplink-mirror#downlink-mirror");
8980 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8981         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8982                                 dstpool, "dst-pool");
8983 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8984         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8985                                 dstpool_id, UINT8);
8986 cmdline_parse_token_string_t cmd_mirror_link_on =
8987         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8988                                 on, "on#off");
8989
8990 static void
8991 cmd_set_mirror_link_parsed(void *parsed_result,
8992                        __attribute__((unused)) struct cmdline *cl,
8993                        __attribute__((unused)) void *data)
8994 {
8995         int ret;
8996         struct cmd_set_mirror_link_result *res = parsed_result;
8997         struct rte_eth_mirror_conf mr_conf;
8998
8999         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9000         if (!strcmp(res->what, "uplink-mirror"))
9001                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9002         else
9003                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9004
9005         mr_conf.dst_pool = res->dstpool_id;
9006
9007         if (!strcmp(res->on, "on"))
9008                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9009                                                 res->rule_id, 1);
9010         else
9011                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9012                                                 res->rule_id, 0);
9013
9014         /* check the return value and print it if is < 0 */
9015         if (ret < 0)
9016                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9017
9018 }
9019
9020 cmdline_parse_inst_t cmd_set_mirror_link = {
9021                 .f = cmd_set_mirror_link_parsed,
9022                 .data = NULL,
9023                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9024                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9025                 .tokens = {
9026                         (void *)&cmd_mirror_link_set,
9027                         (void *)&cmd_mirror_link_port,
9028                         (void *)&cmd_mirror_link_portid,
9029                         (void *)&cmd_mirror_link_mirror,
9030                         (void *)&cmd_mirror_link_ruleid,
9031                         (void *)&cmd_mirror_link_what,
9032                         (void *)&cmd_mirror_link_dstpool,
9033                         (void *)&cmd_mirror_link_poolid,
9034                         (void *)&cmd_mirror_link_on,
9035                         NULL,
9036                 },
9037 };
9038
9039 /* *** RESET VM MIRROR RULE *** */
9040 struct cmd_rm_mirror_rule_result {
9041         cmdline_fixed_string_t reset;
9042         cmdline_fixed_string_t port;
9043         portid_t port_id;
9044         cmdline_fixed_string_t mirror;
9045         uint8_t rule_id;
9046 };
9047
9048 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9049         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9050                                  reset, "reset");
9051 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9052         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9053                                 port, "port");
9054 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9055         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9056                                 port_id, UINT16);
9057 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9058         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9059                                 mirror, "mirror-rule");
9060 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9061         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9062                                 rule_id, UINT8);
9063
9064 static void
9065 cmd_reset_mirror_rule_parsed(void *parsed_result,
9066                        __attribute__((unused)) struct cmdline *cl,
9067                        __attribute__((unused)) void *data)
9068 {
9069         int ret;
9070         struct cmd_set_mirror_link_result *res = parsed_result;
9071         /* check rule_id */
9072         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9073         if(ret < 0)
9074                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9075 }
9076
9077 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9078                 .f = cmd_reset_mirror_rule_parsed,
9079                 .data = NULL,
9080                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9081                 .tokens = {
9082                         (void *)&cmd_rm_mirror_rule_reset,
9083                         (void *)&cmd_rm_mirror_rule_port,
9084                         (void *)&cmd_rm_mirror_rule_portid,
9085                         (void *)&cmd_rm_mirror_rule_mirror,
9086                         (void *)&cmd_rm_mirror_rule_ruleid,
9087                         NULL,
9088                 },
9089 };
9090
9091 /* ******************************************************************************** */
9092
9093 struct cmd_dump_result {
9094         cmdline_fixed_string_t dump;
9095 };
9096
9097 static void
9098 dump_struct_sizes(void)
9099 {
9100 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9101         DUMP_SIZE(struct rte_mbuf);
9102         DUMP_SIZE(struct rte_mempool);
9103         DUMP_SIZE(struct rte_ring);
9104 #undef DUMP_SIZE
9105 }
9106
9107 static void cmd_dump_parsed(void *parsed_result,
9108                             __attribute__((unused)) struct cmdline *cl,
9109                             __attribute__((unused)) void *data)
9110 {
9111         struct cmd_dump_result *res = parsed_result;
9112
9113         if (!strcmp(res->dump, "dump_physmem"))
9114                 rte_dump_physmem_layout(stdout);
9115         else if (!strcmp(res->dump, "dump_memzone"))
9116                 rte_memzone_dump(stdout);
9117         else if (!strcmp(res->dump, "dump_struct_sizes"))
9118                 dump_struct_sizes();
9119         else if (!strcmp(res->dump, "dump_ring"))
9120                 rte_ring_list_dump(stdout);
9121         else if (!strcmp(res->dump, "dump_mempool"))
9122                 rte_mempool_list_dump(stdout);
9123         else if (!strcmp(res->dump, "dump_devargs"))
9124                 rte_devargs_dump(stdout);
9125         else if (!strcmp(res->dump, "dump_log_types"))
9126                 rte_log_dump(stdout);
9127 }
9128
9129 cmdline_parse_token_string_t cmd_dump_dump =
9130         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9131                 "dump_physmem#"
9132                 "dump_memzone#"
9133                 "dump_struct_sizes#"
9134                 "dump_ring#"
9135                 "dump_mempool#"
9136                 "dump_devargs#"
9137                 "dump_log_types");
9138
9139 cmdline_parse_inst_t cmd_dump = {
9140         .f = cmd_dump_parsed,  /* function to call */
9141         .data = NULL,      /* 2nd arg of func */
9142         .help_str = "Dump status",
9143         .tokens = {        /* token list, NULL terminated */
9144                 (void *)&cmd_dump_dump,
9145                 NULL,
9146         },
9147 };
9148
9149 /* ******************************************************************************** */
9150
9151 struct cmd_dump_one_result {
9152         cmdline_fixed_string_t dump;
9153         cmdline_fixed_string_t name;
9154 };
9155
9156 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9157                                 __attribute__((unused)) void *data)
9158 {
9159         struct cmd_dump_one_result *res = parsed_result;
9160
9161         if (!strcmp(res->dump, "dump_ring")) {
9162                 struct rte_ring *r;
9163                 r = rte_ring_lookup(res->name);
9164                 if (r == NULL) {
9165                         cmdline_printf(cl, "Cannot find ring\n");
9166                         return;
9167                 }
9168                 rte_ring_dump(stdout, r);
9169         } else if (!strcmp(res->dump, "dump_mempool")) {
9170                 struct rte_mempool *mp;
9171                 mp = rte_mempool_lookup(res->name);
9172                 if (mp == NULL) {
9173                         cmdline_printf(cl, "Cannot find mempool\n");
9174                         return;
9175                 }
9176                 rte_mempool_dump(stdout, mp);
9177         }
9178 }
9179
9180 cmdline_parse_token_string_t cmd_dump_one_dump =
9181         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9182                                  "dump_ring#dump_mempool");
9183
9184 cmdline_parse_token_string_t cmd_dump_one_name =
9185         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9186
9187 cmdline_parse_inst_t cmd_dump_one = {
9188         .f = cmd_dump_one_parsed,  /* function to call */
9189         .data = NULL,      /* 2nd arg of func */
9190         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9191         .tokens = {        /* token list, NULL terminated */
9192                 (void *)&cmd_dump_one_dump,
9193                 (void *)&cmd_dump_one_name,
9194                 NULL,
9195         },
9196 };
9197
9198 /* *** Add/Del syn filter *** */
9199 struct cmd_syn_filter_result {
9200         cmdline_fixed_string_t filter;
9201         portid_t port_id;
9202         cmdline_fixed_string_t ops;
9203         cmdline_fixed_string_t priority;
9204         cmdline_fixed_string_t high;
9205         cmdline_fixed_string_t queue;
9206         uint16_t queue_id;
9207 };
9208
9209 static void
9210 cmd_syn_filter_parsed(void *parsed_result,
9211                         __attribute__((unused)) struct cmdline *cl,
9212                         __attribute__((unused)) void *data)
9213 {
9214         struct cmd_syn_filter_result *res = parsed_result;
9215         struct rte_eth_syn_filter syn_filter;
9216         int ret = 0;
9217
9218         ret = rte_eth_dev_filter_supported(res->port_id,
9219                                         RTE_ETH_FILTER_SYN);
9220         if (ret < 0) {
9221                 printf("syn filter is not supported on port %u.\n",
9222                                 res->port_id);
9223                 return;
9224         }
9225
9226         memset(&syn_filter, 0, sizeof(syn_filter));
9227
9228         if (!strcmp(res->ops, "add")) {
9229                 if (!strcmp(res->high, "high"))
9230                         syn_filter.hig_pri = 1;
9231                 else
9232                         syn_filter.hig_pri = 0;
9233
9234                 syn_filter.queue = res->queue_id;
9235                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9236                                                 RTE_ETH_FILTER_SYN,
9237                                                 RTE_ETH_FILTER_ADD,
9238                                                 &syn_filter);
9239         } else
9240                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9241                                                 RTE_ETH_FILTER_SYN,
9242                                                 RTE_ETH_FILTER_DELETE,
9243                                                 &syn_filter);
9244
9245         if (ret < 0)
9246                 printf("syn filter programming error: (%s)\n",
9247                                 strerror(-ret));
9248 }
9249
9250 cmdline_parse_token_string_t cmd_syn_filter_filter =
9251         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9252         filter, "syn_filter");
9253 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9254         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9255         port_id, UINT16);
9256 cmdline_parse_token_string_t cmd_syn_filter_ops =
9257         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9258         ops, "add#del");
9259 cmdline_parse_token_string_t cmd_syn_filter_priority =
9260         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9261                                 priority, "priority");
9262 cmdline_parse_token_string_t cmd_syn_filter_high =
9263         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9264                                 high, "high#low");
9265 cmdline_parse_token_string_t cmd_syn_filter_queue =
9266         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9267                                 queue, "queue");
9268 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9269         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9270                                 queue_id, UINT16);
9271
9272 cmdline_parse_inst_t cmd_syn_filter = {
9273         .f = cmd_syn_filter_parsed,
9274         .data = NULL,
9275         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9276                 "<queue_id>: Add/Delete syn filter",
9277         .tokens = {
9278                 (void *)&cmd_syn_filter_filter,
9279                 (void *)&cmd_syn_filter_port_id,
9280                 (void *)&cmd_syn_filter_ops,
9281                 (void *)&cmd_syn_filter_priority,
9282                 (void *)&cmd_syn_filter_high,
9283                 (void *)&cmd_syn_filter_queue,
9284                 (void *)&cmd_syn_filter_queue_id,
9285                 NULL,
9286         },
9287 };
9288
9289 /* *** queue region set *** */
9290 struct cmd_queue_region_result {
9291         cmdline_fixed_string_t set;
9292         cmdline_fixed_string_t port;
9293         portid_t port_id;
9294         cmdline_fixed_string_t cmd;
9295         cmdline_fixed_string_t region;
9296         uint8_t  region_id;
9297         cmdline_fixed_string_t queue_start_index;
9298         uint8_t  queue_id;
9299         cmdline_fixed_string_t queue_num;
9300         uint8_t  queue_num_value;
9301 };
9302
9303 static void
9304 cmd_queue_region_parsed(void *parsed_result,
9305                         __attribute__((unused)) struct cmdline *cl,
9306                         __attribute__((unused)) void *data)
9307 {
9308         struct cmd_queue_region_result *res = parsed_result;
9309         int ret = -ENOTSUP;
9310 #ifdef RTE_LIBRTE_I40E_PMD
9311         struct rte_pmd_i40e_queue_region_conf region_conf;
9312         enum rte_pmd_i40e_queue_region_op op_type;
9313 #endif
9314
9315         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9316                 return;
9317
9318 #ifdef RTE_LIBRTE_I40E_PMD
9319         memset(&region_conf, 0, sizeof(region_conf));
9320         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9321         region_conf.region_id = res->region_id;
9322         region_conf.queue_num = res->queue_num_value;
9323         region_conf.queue_start_index = res->queue_id;
9324
9325         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9326                                 op_type, &region_conf);
9327 #endif
9328
9329         switch (ret) {
9330         case 0:
9331                 break;
9332         case -ENOTSUP:
9333                 printf("function not implemented or supported\n");
9334                 break;
9335         default:
9336                 printf("queue region config error: (%s)\n", strerror(-ret));
9337         }
9338 }
9339
9340 cmdline_parse_token_string_t cmd_queue_region_set =
9341 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9342                 set, "set");
9343 cmdline_parse_token_string_t cmd_queue_region_port =
9344         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9345 cmdline_parse_token_num_t cmd_queue_region_port_id =
9346         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9347                                 port_id, UINT16);
9348 cmdline_parse_token_string_t cmd_queue_region_cmd =
9349         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9350                                  cmd, "queue-region");
9351 cmdline_parse_token_string_t cmd_queue_region_id =
9352         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9353                                 region, "region_id");
9354 cmdline_parse_token_num_t cmd_queue_region_index =
9355         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9356                                 region_id, UINT8);
9357 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9358         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9359                                 queue_start_index, "queue_start_index");
9360 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9361         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9362                                 queue_id, UINT8);
9363 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9364         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9365                                 queue_num, "queue_num");
9366 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9367         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9368                                 queue_num_value, UINT8);
9369
9370 cmdline_parse_inst_t cmd_queue_region = {
9371         .f = cmd_queue_region_parsed,
9372         .data = NULL,
9373         .help_str = "set port <port_id> queue-region region_id <value> "
9374                 "queue_start_index <value> queue_num <value>: Set a queue region",
9375         .tokens = {
9376                 (void *)&cmd_queue_region_set,
9377                 (void *)&cmd_queue_region_port,
9378                 (void *)&cmd_queue_region_port_id,
9379                 (void *)&cmd_queue_region_cmd,
9380                 (void *)&cmd_queue_region_id,
9381                 (void *)&cmd_queue_region_index,
9382                 (void *)&cmd_queue_region_queue_start_index,
9383                 (void *)&cmd_queue_region_queue_id,
9384                 (void *)&cmd_queue_region_queue_num,
9385                 (void *)&cmd_queue_region_queue_num_value,
9386                 NULL,
9387         },
9388 };
9389
9390 /* *** queue region and flowtype set *** */
9391 struct cmd_region_flowtype_result {
9392         cmdline_fixed_string_t set;
9393         cmdline_fixed_string_t port;
9394         portid_t port_id;
9395         cmdline_fixed_string_t cmd;
9396         cmdline_fixed_string_t region;
9397         uint8_t  region_id;
9398         cmdline_fixed_string_t flowtype;
9399         uint8_t  flowtype_id;
9400 };
9401
9402 static void
9403 cmd_region_flowtype_parsed(void *parsed_result,
9404                         __attribute__((unused)) struct cmdline *cl,
9405                         __attribute__((unused)) void *data)
9406 {
9407         struct cmd_region_flowtype_result *res = parsed_result;
9408         int ret = -ENOTSUP;
9409 #ifdef RTE_LIBRTE_I40E_PMD
9410         struct rte_pmd_i40e_queue_region_conf region_conf;
9411         enum rte_pmd_i40e_queue_region_op op_type;
9412 #endif
9413
9414         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9415                 return;
9416
9417 #ifdef RTE_LIBRTE_I40E_PMD
9418         memset(&region_conf, 0, sizeof(region_conf));
9419
9420         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9421         region_conf.region_id = res->region_id;
9422         region_conf.hw_flowtype = res->flowtype_id;
9423
9424         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9425                         op_type, &region_conf);
9426 #endif
9427
9428         switch (ret) {
9429         case 0:
9430                 break;
9431         case -ENOTSUP:
9432                 printf("function not implemented or supported\n");
9433                 break;
9434         default:
9435                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9436         }
9437 }
9438
9439 cmdline_parse_token_string_t cmd_region_flowtype_set =
9440 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9441                                 set, "set");
9442 cmdline_parse_token_string_t cmd_region_flowtype_port =
9443         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9444                                 port, "port");
9445 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9446         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9447                                 port_id, UINT16);
9448 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9449         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9450                                 cmd, "queue-region");
9451 cmdline_parse_token_string_t cmd_region_flowtype_index =
9452         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9453                                 region, "region_id");
9454 cmdline_parse_token_num_t cmd_region_flowtype_id =
9455         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9456                                 region_id, UINT8);
9457 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9458         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9459                                 flowtype, "flowtype");
9460 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9461         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9462                                 flowtype_id, UINT8);
9463 cmdline_parse_inst_t cmd_region_flowtype = {
9464         .f = cmd_region_flowtype_parsed,
9465         .data = NULL,
9466         .help_str = "set port <port_id> queue-region region_id <value> "
9467                 "flowtype <value>: Set a flowtype region index",
9468         .tokens = {
9469                 (void *)&cmd_region_flowtype_set,
9470                 (void *)&cmd_region_flowtype_port,
9471                 (void *)&cmd_region_flowtype_port_index,
9472                 (void *)&cmd_region_flowtype_cmd,
9473                 (void *)&cmd_region_flowtype_index,
9474                 (void *)&cmd_region_flowtype_id,
9475                 (void *)&cmd_region_flowtype_flow_index,
9476                 (void *)&cmd_region_flowtype_flow_id,
9477                 NULL,
9478         },
9479 };
9480
9481 /* *** User Priority (UP) to queue region (region_id) set *** */
9482 struct cmd_user_priority_region_result {
9483         cmdline_fixed_string_t set;
9484         cmdline_fixed_string_t port;
9485         portid_t port_id;
9486         cmdline_fixed_string_t cmd;
9487         cmdline_fixed_string_t user_priority;
9488         uint8_t  user_priority_id;
9489         cmdline_fixed_string_t region;
9490         uint8_t  region_id;
9491 };
9492
9493 static void
9494 cmd_user_priority_region_parsed(void *parsed_result,
9495                         __attribute__((unused)) struct cmdline *cl,
9496                         __attribute__((unused)) void *data)
9497 {
9498         struct cmd_user_priority_region_result *res = parsed_result;
9499         int ret = -ENOTSUP;
9500 #ifdef RTE_LIBRTE_I40E_PMD
9501         struct rte_pmd_i40e_queue_region_conf region_conf;
9502         enum rte_pmd_i40e_queue_region_op op_type;
9503 #endif
9504
9505         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9506                 return;
9507
9508 #ifdef RTE_LIBRTE_I40E_PMD
9509         memset(&region_conf, 0, sizeof(region_conf));
9510         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9511         region_conf.user_priority = res->user_priority_id;
9512         region_conf.region_id = res->region_id;
9513
9514         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9515                                 op_type, &region_conf);
9516 #endif
9517
9518         switch (ret) {
9519         case 0:
9520                 break;
9521         case -ENOTSUP:
9522                 printf("function not implemented or supported\n");
9523                 break;
9524         default:
9525                 printf("user_priority region config error: (%s)\n",
9526                                 strerror(-ret));
9527         }
9528 }
9529
9530 cmdline_parse_token_string_t cmd_user_priority_region_set =
9531         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9532                                 set, "set");
9533 cmdline_parse_token_string_t cmd_user_priority_region_port =
9534         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9535                                 port, "port");
9536 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9537         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9538                                 port_id, UINT16);
9539 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9540         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9541                                 cmd, "queue-region");
9542 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9543         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9544                                 user_priority, "UP");
9545 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9546         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9547                                 user_priority_id, UINT8);
9548 cmdline_parse_token_string_t cmd_user_priority_region_region =
9549         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9550                                 region, "region_id");
9551 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9552         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9553                                 region_id, UINT8);
9554
9555 cmdline_parse_inst_t cmd_user_priority_region = {
9556         .f = cmd_user_priority_region_parsed,
9557         .data = NULL,
9558         .help_str = "set port <port_id> queue-region UP <value> "
9559                 "region_id <value>: Set the mapping of User Priority (UP) "
9560                 "to queue region (region_id) ",
9561         .tokens = {
9562                 (void *)&cmd_user_priority_region_set,
9563                 (void *)&cmd_user_priority_region_port,
9564                 (void *)&cmd_user_priority_region_port_index,
9565                 (void *)&cmd_user_priority_region_cmd,
9566                 (void *)&cmd_user_priority_region_UP,
9567                 (void *)&cmd_user_priority_region_UP_id,
9568                 (void *)&cmd_user_priority_region_region,
9569                 (void *)&cmd_user_priority_region_region_id,
9570                 NULL,
9571         },
9572 };
9573
9574 /* *** flush all queue region related configuration *** */
9575 struct cmd_flush_queue_region_result {
9576         cmdline_fixed_string_t set;
9577         cmdline_fixed_string_t port;
9578         portid_t port_id;
9579         cmdline_fixed_string_t cmd;
9580         cmdline_fixed_string_t flush;
9581         cmdline_fixed_string_t what;
9582 };
9583
9584 static void
9585 cmd_flush_queue_region_parsed(void *parsed_result,
9586                         __attribute__((unused)) struct cmdline *cl,
9587                         __attribute__((unused)) void *data)
9588 {
9589         struct cmd_flush_queue_region_result *res = parsed_result;
9590         int ret = -ENOTSUP;
9591 #ifdef RTE_LIBRTE_I40E_PMD
9592         struct rte_pmd_i40e_queue_region_conf region_conf;
9593         enum rte_pmd_i40e_queue_region_op op_type;
9594 #endif
9595
9596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9597                 return;
9598
9599 #ifdef RTE_LIBRTE_I40E_PMD
9600         memset(&region_conf, 0, sizeof(region_conf));
9601
9602         if (strcmp(res->what, "on") == 0)
9603                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9604         else
9605                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9606
9607         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9608                                 op_type, &region_conf);
9609 #endif
9610
9611         switch (ret) {
9612         case 0:
9613                 break;
9614         case -ENOTSUP:
9615                 printf("function not implemented or supported\n");
9616                 break;
9617         default:
9618                 printf("queue region config flush error: (%s)\n",
9619                                 strerror(-ret));
9620         }
9621 }
9622
9623 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9624         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9625                                 set, "set");
9626 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9627         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9628                                 port, "port");
9629 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9630         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9631                                 port_id, UINT16);
9632 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9633         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9634                                 cmd, "queue-region");
9635 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9636         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9637                                 flush, "flush");
9638 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9639         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9640                                 what, "on#off");
9641
9642 cmdline_parse_inst_t cmd_flush_queue_region = {
9643         .f = cmd_flush_queue_region_parsed,
9644         .data = NULL,
9645         .help_str = "set port <port_id> queue-region flush on|off"
9646                 ": flush all queue region related configuration",
9647         .tokens = {
9648                 (void *)&cmd_flush_queue_region_set,
9649                 (void *)&cmd_flush_queue_region_port,
9650                 (void *)&cmd_flush_queue_region_port_index,
9651                 (void *)&cmd_flush_queue_region_cmd,
9652                 (void *)&cmd_flush_queue_region_flush,
9653                 (void *)&cmd_flush_queue_region_what,
9654                 NULL,
9655         },
9656 };
9657
9658 /* *** get all queue region related configuration info *** */
9659 struct cmd_show_queue_region_info {
9660         cmdline_fixed_string_t show;
9661         cmdline_fixed_string_t port;
9662         portid_t port_id;
9663         cmdline_fixed_string_t cmd;
9664 };
9665
9666 static void
9667 cmd_show_queue_region_info_parsed(void *parsed_result,
9668                         __attribute__((unused)) struct cmdline *cl,
9669                         __attribute__((unused)) void *data)
9670 {
9671         struct cmd_show_queue_region_info *res = parsed_result;
9672         int ret = -ENOTSUP;
9673 #ifdef RTE_LIBRTE_I40E_PMD
9674         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9675         enum rte_pmd_i40e_queue_region_op op_type;
9676 #endif
9677
9678         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9679                 return;
9680
9681 #ifdef RTE_LIBRTE_I40E_PMD
9682         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9683
9684         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9685
9686         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9687                                         op_type, &rte_pmd_regions);
9688
9689         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9690 #endif
9691
9692         switch (ret) {
9693         case 0:
9694                 break;
9695         case -ENOTSUP:
9696                 printf("function not implemented or supported\n");
9697                 break;
9698         default:
9699                 printf("queue region config info show error: (%s)\n",
9700                                 strerror(-ret));
9701         }
9702 }
9703
9704 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9705 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9706                                 show, "show");
9707 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9708         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9709                                 port, "port");
9710 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9711         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9712                                 port_id, UINT16);
9713 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9714         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9715                                 cmd, "queue-region");
9716
9717 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9718         .f = cmd_show_queue_region_info_parsed,
9719         .data = NULL,
9720         .help_str = "show port <port_id> queue-region"
9721                 ": show all queue region related configuration info",
9722         .tokens = {
9723                 (void *)&cmd_show_queue_region_info_get,
9724                 (void *)&cmd_show_queue_region_info_port,
9725                 (void *)&cmd_show_queue_region_info_port_index,
9726                 (void *)&cmd_show_queue_region_info_cmd,
9727                 NULL,
9728         },
9729 };
9730
9731 /* *** ADD/REMOVE A 2tuple FILTER *** */
9732 struct cmd_2tuple_filter_result {
9733         cmdline_fixed_string_t filter;
9734         portid_t port_id;
9735         cmdline_fixed_string_t ops;
9736         cmdline_fixed_string_t dst_port;
9737         uint16_t dst_port_value;
9738         cmdline_fixed_string_t protocol;
9739         uint8_t protocol_value;
9740         cmdline_fixed_string_t mask;
9741         uint8_t  mask_value;
9742         cmdline_fixed_string_t tcp_flags;
9743         uint8_t tcp_flags_value;
9744         cmdline_fixed_string_t priority;
9745         uint8_t  priority_value;
9746         cmdline_fixed_string_t queue;
9747         uint16_t  queue_id;
9748 };
9749
9750 static void
9751 cmd_2tuple_filter_parsed(void *parsed_result,
9752                         __attribute__((unused)) struct cmdline *cl,
9753                         __attribute__((unused)) void *data)
9754 {
9755         struct rte_eth_ntuple_filter filter;
9756         struct cmd_2tuple_filter_result *res = parsed_result;
9757         int ret = 0;
9758
9759         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9760         if (ret < 0) {
9761                 printf("ntuple filter is not supported on port %u.\n",
9762                         res->port_id);
9763                 return;
9764         }
9765
9766         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9767
9768         filter.flags = RTE_2TUPLE_FLAGS;
9769         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9770         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9771         filter.proto = res->protocol_value;
9772         filter.priority = res->priority_value;
9773         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9774                 printf("nonzero tcp_flags is only meaningful"
9775                         " when protocol is TCP.\n");
9776                 return;
9777         }
9778         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9779                 printf("invalid TCP flags.\n");
9780                 return;
9781         }
9782
9783         if (res->tcp_flags_value != 0) {
9784                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9785                 filter.tcp_flags = res->tcp_flags_value;
9786         }
9787
9788         /* need convert to big endian. */
9789         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9790         filter.queue = res->queue_id;
9791
9792         if (!strcmp(res->ops, "add"))
9793                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9794                                 RTE_ETH_FILTER_NTUPLE,
9795                                 RTE_ETH_FILTER_ADD,
9796                                 &filter);
9797         else
9798                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9799                                 RTE_ETH_FILTER_NTUPLE,
9800                                 RTE_ETH_FILTER_DELETE,
9801                                 &filter);
9802         if (ret < 0)
9803                 printf("2tuple filter programming error: (%s)\n",
9804                         strerror(-ret));
9805
9806 }
9807
9808 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9809         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9810                                  filter, "2tuple_filter");
9811 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9812         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9813                                 port_id, UINT16);
9814 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9815         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9816                                  ops, "add#del");
9817 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9818         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9819                                 dst_port, "dst_port");
9820 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9821         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9822                                 dst_port_value, UINT16);
9823 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9824         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9825                                 protocol, "protocol");
9826 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9827         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9828                                 protocol_value, UINT8);
9829 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9830         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9831                                 mask, "mask");
9832 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9833         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9834                                 mask_value, INT8);
9835 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9836         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9837                                 tcp_flags, "tcp_flags");
9838 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9839         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9840                                 tcp_flags_value, UINT8);
9841 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9842         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9843                                 priority, "priority");
9844 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9845         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9846                                 priority_value, UINT8);
9847 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9848         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9849                                 queue, "queue");
9850 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9851         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9852                                 queue_id, UINT16);
9853
9854 cmdline_parse_inst_t cmd_2tuple_filter = {
9855         .f = cmd_2tuple_filter_parsed,
9856         .data = NULL,
9857         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9858                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9859                 "<queue_id>: Add a 2tuple filter",
9860         .tokens = {
9861                 (void *)&cmd_2tuple_filter_filter,
9862                 (void *)&cmd_2tuple_filter_port_id,
9863                 (void *)&cmd_2tuple_filter_ops,
9864                 (void *)&cmd_2tuple_filter_dst_port,
9865                 (void *)&cmd_2tuple_filter_dst_port_value,
9866                 (void *)&cmd_2tuple_filter_protocol,
9867                 (void *)&cmd_2tuple_filter_protocol_value,
9868                 (void *)&cmd_2tuple_filter_mask,
9869                 (void *)&cmd_2tuple_filter_mask_value,
9870                 (void *)&cmd_2tuple_filter_tcp_flags,
9871                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9872                 (void *)&cmd_2tuple_filter_priority,
9873                 (void *)&cmd_2tuple_filter_priority_value,
9874                 (void *)&cmd_2tuple_filter_queue,
9875                 (void *)&cmd_2tuple_filter_queue_id,
9876                 NULL,
9877         },
9878 };
9879
9880 /* *** ADD/REMOVE A 5tuple FILTER *** */
9881 struct cmd_5tuple_filter_result {
9882         cmdline_fixed_string_t filter;
9883         portid_t port_id;
9884         cmdline_fixed_string_t ops;
9885         cmdline_fixed_string_t dst_ip;
9886         cmdline_ipaddr_t dst_ip_value;
9887         cmdline_fixed_string_t src_ip;
9888         cmdline_ipaddr_t src_ip_value;
9889         cmdline_fixed_string_t dst_port;
9890         uint16_t dst_port_value;
9891         cmdline_fixed_string_t src_port;
9892         uint16_t src_port_value;
9893         cmdline_fixed_string_t protocol;
9894         uint8_t protocol_value;
9895         cmdline_fixed_string_t mask;
9896         uint8_t  mask_value;
9897         cmdline_fixed_string_t tcp_flags;
9898         uint8_t tcp_flags_value;
9899         cmdline_fixed_string_t priority;
9900         uint8_t  priority_value;
9901         cmdline_fixed_string_t queue;
9902         uint16_t  queue_id;
9903 };
9904
9905 static void
9906 cmd_5tuple_filter_parsed(void *parsed_result,
9907                         __attribute__((unused)) struct cmdline *cl,
9908                         __attribute__((unused)) void *data)
9909 {
9910         struct rte_eth_ntuple_filter filter;
9911         struct cmd_5tuple_filter_result *res = parsed_result;
9912         int ret = 0;
9913
9914         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9915         if (ret < 0) {
9916                 printf("ntuple filter is not supported on port %u.\n",
9917                         res->port_id);
9918                 return;
9919         }
9920
9921         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9922
9923         filter.flags = RTE_5TUPLE_FLAGS;
9924         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9925         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9926         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9927         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9928         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9929         filter.proto = res->protocol_value;
9930         filter.priority = res->priority_value;
9931         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9932                 printf("nonzero tcp_flags is only meaningful"
9933                         " when protocol is TCP.\n");
9934                 return;
9935         }
9936         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9937                 printf("invalid TCP flags.\n");
9938                 return;
9939         }
9940
9941         if (res->tcp_flags_value != 0) {
9942                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9943                 filter.tcp_flags = res->tcp_flags_value;
9944         }
9945
9946         if (res->dst_ip_value.family == AF_INET)
9947                 /* no need to convert, already big endian. */
9948                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9949         else {
9950                 if (filter.dst_ip_mask == 0) {
9951                         printf("can not support ipv6 involved compare.\n");
9952                         return;
9953                 }
9954                 filter.dst_ip = 0;
9955         }
9956
9957         if (res->src_ip_value.family == AF_INET)
9958                 /* no need to convert, already big endian. */
9959                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9960         else {
9961                 if (filter.src_ip_mask == 0) {
9962                         printf("can not support ipv6 involved compare.\n");
9963                         return;
9964                 }
9965                 filter.src_ip = 0;
9966         }
9967         /* need convert to big endian. */
9968         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9969         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9970         filter.queue = res->queue_id;
9971
9972         if (!strcmp(res->ops, "add"))
9973                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9974                                 RTE_ETH_FILTER_NTUPLE,
9975                                 RTE_ETH_FILTER_ADD,
9976                                 &filter);
9977         else
9978                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9979                                 RTE_ETH_FILTER_NTUPLE,
9980                                 RTE_ETH_FILTER_DELETE,
9981                                 &filter);
9982         if (ret < 0)
9983                 printf("5tuple filter programming error: (%s)\n",
9984                         strerror(-ret));
9985 }
9986
9987 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9988         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9989                                  filter, "5tuple_filter");
9990 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9991         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9992                                 port_id, UINT16);
9993 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9994         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9995                                  ops, "add#del");
9996 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9997         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9998                                 dst_ip, "dst_ip");
9999 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10000         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10001                                 dst_ip_value);
10002 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10003         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10004                                 src_ip, "src_ip");
10005 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10006         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10007                                 src_ip_value);
10008 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10009         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10010                                 dst_port, "dst_port");
10011 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10012         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10013                                 dst_port_value, UINT16);
10014 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10015         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10016                                 src_port, "src_port");
10017 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10018         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10019                                 src_port_value, UINT16);
10020 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10021         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10022                                 protocol, "protocol");
10023 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10024         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10025                                 protocol_value, UINT8);
10026 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10027         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10028                                 mask, "mask");
10029 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10030         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10031                                 mask_value, INT8);
10032 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10033         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10034                                 tcp_flags, "tcp_flags");
10035 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10036         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10037                                 tcp_flags_value, UINT8);
10038 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10039         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10040                                 priority, "priority");
10041 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10042         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10043                                 priority_value, UINT8);
10044 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10045         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10046                                 queue, "queue");
10047 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10048         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10049                                 queue_id, UINT16);
10050
10051 cmdline_parse_inst_t cmd_5tuple_filter = {
10052         .f = cmd_5tuple_filter_parsed,
10053         .data = NULL,
10054         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10055                 "src_ip <value> dst_port <value> src_port <value> "
10056                 "protocol <value>  mask <value> tcp_flags <value> "
10057                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10058         .tokens = {
10059                 (void *)&cmd_5tuple_filter_filter,
10060                 (void *)&cmd_5tuple_filter_port_id,
10061                 (void *)&cmd_5tuple_filter_ops,
10062                 (void *)&cmd_5tuple_filter_dst_ip,
10063                 (void *)&cmd_5tuple_filter_dst_ip_value,
10064                 (void *)&cmd_5tuple_filter_src_ip,
10065                 (void *)&cmd_5tuple_filter_src_ip_value,
10066                 (void *)&cmd_5tuple_filter_dst_port,
10067                 (void *)&cmd_5tuple_filter_dst_port_value,
10068                 (void *)&cmd_5tuple_filter_src_port,
10069                 (void *)&cmd_5tuple_filter_src_port_value,
10070                 (void *)&cmd_5tuple_filter_protocol,
10071                 (void *)&cmd_5tuple_filter_protocol_value,
10072                 (void *)&cmd_5tuple_filter_mask,
10073                 (void *)&cmd_5tuple_filter_mask_value,
10074                 (void *)&cmd_5tuple_filter_tcp_flags,
10075                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10076                 (void *)&cmd_5tuple_filter_priority,
10077                 (void *)&cmd_5tuple_filter_priority_value,
10078                 (void *)&cmd_5tuple_filter_queue,
10079                 (void *)&cmd_5tuple_filter_queue_id,
10080                 NULL,
10081         },
10082 };
10083
10084 /* *** ADD/REMOVE A flex FILTER *** */
10085 struct cmd_flex_filter_result {
10086         cmdline_fixed_string_t filter;
10087         cmdline_fixed_string_t ops;
10088         portid_t port_id;
10089         cmdline_fixed_string_t len;
10090         uint8_t len_value;
10091         cmdline_fixed_string_t bytes;
10092         cmdline_fixed_string_t bytes_value;
10093         cmdline_fixed_string_t mask;
10094         cmdline_fixed_string_t mask_value;
10095         cmdline_fixed_string_t priority;
10096         uint8_t priority_value;
10097         cmdline_fixed_string_t queue;
10098         uint16_t queue_id;
10099 };
10100
10101 static int xdigit2val(unsigned char c)
10102 {
10103         int val;
10104         if (isdigit(c))
10105                 val = c - '0';
10106         else if (isupper(c))
10107                 val = c - 'A' + 10;
10108         else
10109                 val = c - 'a' + 10;
10110         return val;
10111 }
10112
10113 static void
10114 cmd_flex_filter_parsed(void *parsed_result,
10115                           __attribute__((unused)) struct cmdline *cl,
10116                           __attribute__((unused)) void *data)
10117 {
10118         int ret = 0;
10119         struct rte_eth_flex_filter filter;
10120         struct cmd_flex_filter_result *res = parsed_result;
10121         char *bytes_ptr, *mask_ptr;
10122         uint16_t len, i, j = 0;
10123         char c;
10124         int val;
10125         uint8_t byte = 0;
10126
10127         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10128                 printf("the len exceed the max length 128\n");
10129                 return;
10130         }
10131         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10132         filter.len = res->len_value;
10133         filter.priority = res->priority_value;
10134         filter.queue = res->queue_id;
10135         bytes_ptr = res->bytes_value;
10136         mask_ptr = res->mask_value;
10137
10138          /* translate bytes string to array. */
10139         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10140                 (bytes_ptr[1] == 'X')))
10141                 bytes_ptr += 2;
10142         len = strnlen(bytes_ptr, res->len_value * 2);
10143         if (len == 0 || (len % 8 != 0)) {
10144                 printf("please check len and bytes input\n");
10145                 return;
10146         }
10147         for (i = 0; i < len; i++) {
10148                 c = bytes_ptr[i];
10149                 if (isxdigit(c) == 0) {
10150                         /* invalid characters. */
10151                         printf("invalid input\n");
10152                         return;
10153                 }
10154                 val = xdigit2val(c);
10155                 if (i % 2) {
10156                         byte |= val;
10157                         filter.bytes[j] = byte;
10158                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10159                         j++;
10160                         byte = 0;
10161                 } else
10162                         byte |= val << 4;
10163         }
10164         printf("\n");
10165          /* translate mask string to uint8_t array. */
10166         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10167                 (mask_ptr[1] == 'X')))
10168                 mask_ptr += 2;
10169         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10170         if (len == 0) {
10171                 printf("invalid input\n");
10172                 return;
10173         }
10174         j = 0;
10175         byte = 0;
10176         for (i = 0; i < len; i++) {
10177                 c = mask_ptr[i];
10178                 if (isxdigit(c) == 0) {
10179                         /* invalid characters. */
10180                         printf("invalid input\n");
10181                         return;
10182                 }
10183                 val = xdigit2val(c);
10184                 if (i % 2) {
10185                         byte |= val;
10186                         filter.mask[j] = byte;
10187                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10188                         j++;
10189                         byte = 0;
10190                 } else
10191                         byte |= val << 4;
10192         }
10193         printf("\n");
10194
10195         if (!strcmp(res->ops, "add"))
10196                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10197                                 RTE_ETH_FILTER_FLEXIBLE,
10198                                 RTE_ETH_FILTER_ADD,
10199                                 &filter);
10200         else
10201                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10202                                 RTE_ETH_FILTER_FLEXIBLE,
10203                                 RTE_ETH_FILTER_DELETE,
10204                                 &filter);
10205
10206         if (ret < 0)
10207                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10208 }
10209
10210 cmdline_parse_token_string_t cmd_flex_filter_filter =
10211         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10212                                 filter, "flex_filter");
10213 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10214         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10215                                 port_id, UINT16);
10216 cmdline_parse_token_string_t cmd_flex_filter_ops =
10217         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10218                                 ops, "add#del");
10219 cmdline_parse_token_string_t cmd_flex_filter_len =
10220         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10221                                 len, "len");
10222 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10223         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10224                                 len_value, UINT8);
10225 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10226         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10227                                 bytes, "bytes");
10228 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10229         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10230                                 bytes_value, NULL);
10231 cmdline_parse_token_string_t cmd_flex_filter_mask =
10232         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10233                                 mask, "mask");
10234 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10235         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10236                                 mask_value, NULL);
10237 cmdline_parse_token_string_t cmd_flex_filter_priority =
10238         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10239                                 priority, "priority");
10240 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10241         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10242                                 priority_value, UINT8);
10243 cmdline_parse_token_string_t cmd_flex_filter_queue =
10244         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10245                                 queue, "queue");
10246 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10247         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10248                                 queue_id, UINT16);
10249 cmdline_parse_inst_t cmd_flex_filter = {
10250         .f = cmd_flex_filter_parsed,
10251         .data = NULL,
10252         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10253                 "<value> mask <value> priority <value> queue <queue_id>: "
10254                 "Add/Del a flex filter",
10255         .tokens = {
10256                 (void *)&cmd_flex_filter_filter,
10257                 (void *)&cmd_flex_filter_port_id,
10258                 (void *)&cmd_flex_filter_ops,
10259                 (void *)&cmd_flex_filter_len,
10260                 (void *)&cmd_flex_filter_len_value,
10261                 (void *)&cmd_flex_filter_bytes,
10262                 (void *)&cmd_flex_filter_bytes_value,
10263                 (void *)&cmd_flex_filter_mask,
10264                 (void *)&cmd_flex_filter_mask_value,
10265                 (void *)&cmd_flex_filter_priority,
10266                 (void *)&cmd_flex_filter_priority_value,
10267                 (void *)&cmd_flex_filter_queue,
10268                 (void *)&cmd_flex_filter_queue_id,
10269                 NULL,
10270         },
10271 };
10272
10273 /* *** Filters Control *** */
10274
10275 /* *** deal with ethertype filter *** */
10276 struct cmd_ethertype_filter_result {
10277         cmdline_fixed_string_t filter;
10278         portid_t port_id;
10279         cmdline_fixed_string_t ops;
10280         cmdline_fixed_string_t mac;
10281         struct ether_addr mac_addr;
10282         cmdline_fixed_string_t ethertype;
10283         uint16_t ethertype_value;
10284         cmdline_fixed_string_t drop;
10285         cmdline_fixed_string_t queue;
10286         uint16_t  queue_id;
10287 };
10288
10289 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10290         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10291                                  filter, "ethertype_filter");
10292 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10293         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10294                               port_id, UINT16);
10295 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10296         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10297                                  ops, "add#del");
10298 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10299         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10300                                  mac, "mac_addr#mac_ignr");
10301 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10302         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10303                                      mac_addr);
10304 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10305         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10306                                  ethertype, "ethertype");
10307 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10308         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10309                               ethertype_value, UINT16);
10310 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10311         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10312                                  drop, "drop#fwd");
10313 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10314         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10315                                  queue, "queue");
10316 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10317         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10318                               queue_id, UINT16);
10319
10320 static void
10321 cmd_ethertype_filter_parsed(void *parsed_result,
10322                           __attribute__((unused)) struct cmdline *cl,
10323                           __attribute__((unused)) void *data)
10324 {
10325         struct cmd_ethertype_filter_result *res = parsed_result;
10326         struct rte_eth_ethertype_filter filter;
10327         int ret = 0;
10328
10329         ret = rte_eth_dev_filter_supported(res->port_id,
10330                         RTE_ETH_FILTER_ETHERTYPE);
10331         if (ret < 0) {
10332                 printf("ethertype filter is not supported on port %u.\n",
10333                         res->port_id);
10334                 return;
10335         }
10336
10337         memset(&filter, 0, sizeof(filter));
10338         if (!strcmp(res->mac, "mac_addr")) {
10339                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10340                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10341                         sizeof(struct ether_addr));
10342         }
10343         if (!strcmp(res->drop, "drop"))
10344                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10345         filter.ether_type = res->ethertype_value;
10346         filter.queue = res->queue_id;
10347
10348         if (!strcmp(res->ops, "add"))
10349                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10350                                 RTE_ETH_FILTER_ETHERTYPE,
10351                                 RTE_ETH_FILTER_ADD,
10352                                 &filter);
10353         else
10354                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10355                                 RTE_ETH_FILTER_ETHERTYPE,
10356                                 RTE_ETH_FILTER_DELETE,
10357                                 &filter);
10358         if (ret < 0)
10359                 printf("ethertype filter programming error: (%s)\n",
10360                         strerror(-ret));
10361 }
10362
10363 cmdline_parse_inst_t cmd_ethertype_filter = {
10364         .f = cmd_ethertype_filter_parsed,
10365         .data = NULL,
10366         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10367                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10368                 "Add or delete an ethertype filter entry",
10369         .tokens = {
10370                 (void *)&cmd_ethertype_filter_filter,
10371                 (void *)&cmd_ethertype_filter_port_id,
10372                 (void *)&cmd_ethertype_filter_ops,
10373                 (void *)&cmd_ethertype_filter_mac,
10374                 (void *)&cmd_ethertype_filter_mac_addr,
10375                 (void *)&cmd_ethertype_filter_ethertype,
10376                 (void *)&cmd_ethertype_filter_ethertype_value,
10377                 (void *)&cmd_ethertype_filter_drop,
10378                 (void *)&cmd_ethertype_filter_queue,
10379                 (void *)&cmd_ethertype_filter_queue_id,
10380                 NULL,
10381         },
10382 };
10383
10384 /* *** deal with flow director filter *** */
10385 struct cmd_flow_director_result {
10386         cmdline_fixed_string_t flow_director_filter;
10387         portid_t port_id;
10388         cmdline_fixed_string_t mode;
10389         cmdline_fixed_string_t mode_value;
10390         cmdline_fixed_string_t ops;
10391         cmdline_fixed_string_t flow;
10392         cmdline_fixed_string_t flow_type;
10393         cmdline_fixed_string_t ether;
10394         uint16_t ether_type;
10395         cmdline_fixed_string_t src;
10396         cmdline_ipaddr_t ip_src;
10397         uint16_t port_src;
10398         cmdline_fixed_string_t dst;
10399         cmdline_ipaddr_t ip_dst;
10400         uint16_t port_dst;
10401         cmdline_fixed_string_t verify_tag;
10402         uint32_t verify_tag_value;
10403         cmdline_fixed_string_t tos;
10404         uint8_t tos_value;
10405         cmdline_fixed_string_t proto;
10406         uint8_t proto_value;
10407         cmdline_fixed_string_t ttl;
10408         uint8_t ttl_value;
10409         cmdline_fixed_string_t vlan;
10410         uint16_t vlan_value;
10411         cmdline_fixed_string_t flexbytes;
10412         cmdline_fixed_string_t flexbytes_value;
10413         cmdline_fixed_string_t pf_vf;
10414         cmdline_fixed_string_t drop;
10415         cmdline_fixed_string_t queue;
10416         uint16_t  queue_id;
10417         cmdline_fixed_string_t fd_id;
10418         uint32_t  fd_id_value;
10419         cmdline_fixed_string_t mac;
10420         struct ether_addr mac_addr;
10421         cmdline_fixed_string_t tunnel;
10422         cmdline_fixed_string_t tunnel_type;
10423         cmdline_fixed_string_t tunnel_id;
10424         uint32_t tunnel_id_value;
10425         cmdline_fixed_string_t packet;
10426         char filepath[];
10427 };
10428
10429 static inline int
10430 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10431 {
10432         char s[256];
10433         const char *p, *p0 = q_arg;
10434         char *end;
10435         unsigned long int_fld;
10436         char *str_fld[max_num];
10437         int i;
10438         unsigned size;
10439         int ret = -1;
10440
10441         p = strchr(p0, '(');
10442         if (p == NULL)
10443                 return -1;
10444         ++p;
10445         p0 = strchr(p, ')');
10446         if (p0 == NULL)
10447                 return -1;
10448
10449         size = p0 - p;
10450         if (size >= sizeof(s))
10451                 return -1;
10452
10453         snprintf(s, sizeof(s), "%.*s", size, p);
10454         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10455         if (ret < 0 || ret > max_num)
10456                 return -1;
10457         for (i = 0; i < ret; i++) {
10458                 errno = 0;
10459                 int_fld = strtoul(str_fld[i], &end, 0);
10460                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10461                         return -1;
10462                 flexbytes[i] = (uint8_t)int_fld;
10463         }
10464         return ret;
10465 }
10466
10467 static uint16_t
10468 str2flowtype(char *string)
10469 {
10470         uint8_t i = 0;
10471         static const struct {
10472                 char str[32];
10473                 uint16_t type;
10474         } flowtype_str[] = {
10475                 {"raw", RTE_ETH_FLOW_RAW},
10476                 {"ipv4", RTE_ETH_FLOW_IPV4},
10477                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10478                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10479                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10480                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10481                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10482                 {"ipv6", RTE_ETH_FLOW_IPV6},
10483                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10484                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10485                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10486                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10487                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10488                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10489         };
10490
10491         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10492                 if (!strcmp(flowtype_str[i].str, string))
10493                         return flowtype_str[i].type;
10494         }
10495
10496         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10497                 return (uint16_t)atoi(string);
10498
10499         return RTE_ETH_FLOW_UNKNOWN;
10500 }
10501
10502 static enum rte_eth_fdir_tunnel_type
10503 str2fdir_tunneltype(char *string)
10504 {
10505         uint8_t i = 0;
10506
10507         static const struct {
10508                 char str[32];
10509                 enum rte_eth_fdir_tunnel_type type;
10510         } tunneltype_str[] = {
10511                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10512                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10513         };
10514
10515         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10516                 if (!strcmp(tunneltype_str[i].str, string))
10517                         return tunneltype_str[i].type;
10518         }
10519         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10520 }
10521
10522 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10523 do { \
10524         if ((ip_addr).family == AF_INET) \
10525                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10526         else { \
10527                 printf("invalid parameter.\n"); \
10528                 return; \
10529         } \
10530 } while (0)
10531
10532 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10533 do { \
10534         if ((ip_addr).family == AF_INET6) \
10535                 rte_memcpy(&(ip), \
10536                                  &((ip_addr).addr.ipv6), \
10537                                  sizeof(struct in6_addr)); \
10538         else { \
10539                 printf("invalid parameter.\n"); \
10540                 return; \
10541         } \
10542 } while (0)
10543
10544 static void
10545 cmd_flow_director_filter_parsed(void *parsed_result,
10546                           __attribute__((unused)) struct cmdline *cl,
10547                           __attribute__((unused)) void *data)
10548 {
10549         struct cmd_flow_director_result *res = parsed_result;
10550         struct rte_eth_fdir_filter entry;
10551         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10552         char *end;
10553         unsigned long vf_id;
10554         int ret = 0;
10555
10556         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10557         if (ret < 0) {
10558                 printf("flow director is not supported on port %u.\n",
10559                         res->port_id);
10560                 return;
10561         }
10562         memset(flexbytes, 0, sizeof(flexbytes));
10563         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10564
10565         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10566                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10567                         printf("Please set mode to MAC-VLAN.\n");
10568                         return;
10569                 }
10570         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10571                 if (strcmp(res->mode_value, "Tunnel")) {
10572                         printf("Please set mode to Tunnel.\n");
10573                         return;
10574                 }
10575         } else {
10576                 if (!strcmp(res->mode_value, "raw")) {
10577 #ifdef RTE_LIBRTE_I40E_PMD
10578                         struct rte_pmd_i40e_flow_type_mapping
10579                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10580                         struct rte_pmd_i40e_pkt_template_conf conf;
10581                         uint16_t flow_type = str2flowtype(res->flow_type);
10582                         uint16_t i, port = res->port_id;
10583                         uint8_t add;
10584
10585                         memset(&conf, 0, sizeof(conf));
10586
10587                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10588                                 printf("Invalid flow type specified.\n");
10589                                 return;
10590                         }
10591                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10592                                                                  mapping);
10593                         if (ret)
10594                                 return;
10595                         if (mapping[flow_type].pctype == 0ULL) {
10596                                 printf("Invalid flow type specified.\n");
10597                                 return;
10598                         }
10599                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10600                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10601                                         conf.input.pctype = i;
10602                                         break;
10603                                 }
10604                         }
10605
10606                         conf.input.packet = open_file(res->filepath,
10607                                                 &conf.input.length);
10608                         if (!conf.input.packet)
10609                                 return;
10610                         if (!strcmp(res->drop, "drop"))
10611                                 conf.action.behavior =
10612                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10613                         else
10614                                 conf.action.behavior =
10615                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10616                         conf.action.report_status =
10617                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10618                         conf.action.rx_queue = res->queue_id;
10619                         conf.soft_id = res->fd_id_value;
10620                         add  = strcmp(res->ops, "del") ? 1 : 0;
10621                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10622                                                                         &conf,
10623                                                                         add);
10624                         if (ret < 0)
10625                                 printf("flow director config error: (%s)\n",
10626                                        strerror(-ret));
10627                         close_file(conf.input.packet);
10628 #endif
10629                         return;
10630                 } else if (strcmp(res->mode_value, "IP")) {
10631                         printf("Please set mode to IP or raw.\n");
10632                         return;
10633                 }
10634                 entry.input.flow_type = str2flowtype(res->flow_type);
10635         }
10636
10637         ret = parse_flexbytes(res->flexbytes_value,
10638                                         flexbytes,
10639                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10640         if (ret < 0) {
10641                 printf("error: Cannot parse flexbytes input.\n");
10642                 return;
10643         }
10644
10645         switch (entry.input.flow_type) {
10646         case RTE_ETH_FLOW_FRAG_IPV4:
10647         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10648                 entry.input.flow.ip4_flow.proto = res->proto_value;
10649                 /* fall-through */
10650         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10651         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10652                 IPV4_ADDR_TO_UINT(res->ip_dst,
10653                         entry.input.flow.ip4_flow.dst_ip);
10654                 IPV4_ADDR_TO_UINT(res->ip_src,
10655                         entry.input.flow.ip4_flow.src_ip);
10656                 entry.input.flow.ip4_flow.tos = res->tos_value;
10657                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10658                 /* need convert to big endian. */
10659                 entry.input.flow.udp4_flow.dst_port =
10660                                 rte_cpu_to_be_16(res->port_dst);
10661                 entry.input.flow.udp4_flow.src_port =
10662                                 rte_cpu_to_be_16(res->port_src);
10663                 break;
10664         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10665                 IPV4_ADDR_TO_UINT(res->ip_dst,
10666                         entry.input.flow.sctp4_flow.ip.dst_ip);
10667                 IPV4_ADDR_TO_UINT(res->ip_src,
10668                         entry.input.flow.sctp4_flow.ip.src_ip);
10669                 entry.input.flow.ip4_flow.tos = res->tos_value;
10670                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10671                 /* need convert to big endian. */
10672                 entry.input.flow.sctp4_flow.dst_port =
10673                                 rte_cpu_to_be_16(res->port_dst);
10674                 entry.input.flow.sctp4_flow.src_port =
10675                                 rte_cpu_to_be_16(res->port_src);
10676                 entry.input.flow.sctp4_flow.verify_tag =
10677                                 rte_cpu_to_be_32(res->verify_tag_value);
10678                 break;
10679         case RTE_ETH_FLOW_FRAG_IPV6:
10680         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10681                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10682                 /* fall-through */
10683         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10684         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10685                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10686                         entry.input.flow.ipv6_flow.dst_ip);
10687                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10688                         entry.input.flow.ipv6_flow.src_ip);
10689                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10690                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10691                 /* need convert to big endian. */
10692                 entry.input.flow.udp6_flow.dst_port =
10693                                 rte_cpu_to_be_16(res->port_dst);
10694                 entry.input.flow.udp6_flow.src_port =
10695                                 rte_cpu_to_be_16(res->port_src);
10696                 break;
10697         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10698                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10699                         entry.input.flow.sctp6_flow.ip.dst_ip);
10700                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10701                         entry.input.flow.sctp6_flow.ip.src_ip);
10702                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10703                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10704                 /* need convert to big endian. */
10705                 entry.input.flow.sctp6_flow.dst_port =
10706                                 rte_cpu_to_be_16(res->port_dst);
10707                 entry.input.flow.sctp6_flow.src_port =
10708                                 rte_cpu_to_be_16(res->port_src);
10709                 entry.input.flow.sctp6_flow.verify_tag =
10710                                 rte_cpu_to_be_32(res->verify_tag_value);
10711                 break;
10712         case RTE_ETH_FLOW_L2_PAYLOAD:
10713                 entry.input.flow.l2_flow.ether_type =
10714                         rte_cpu_to_be_16(res->ether_type);
10715                 break;
10716         default:
10717                 break;
10718         }
10719
10720         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10721                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10722                                  &res->mac_addr,
10723                                  sizeof(struct ether_addr));
10724
10725         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10726                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10727                                  &res->mac_addr,
10728                                  sizeof(struct ether_addr));
10729                 entry.input.flow.tunnel_flow.tunnel_type =
10730                         str2fdir_tunneltype(res->tunnel_type);
10731                 entry.input.flow.tunnel_flow.tunnel_id =
10732                         rte_cpu_to_be_32(res->tunnel_id_value);
10733         }
10734
10735         rte_memcpy(entry.input.flow_ext.flexbytes,
10736                    flexbytes,
10737                    RTE_ETH_FDIR_MAX_FLEXLEN);
10738
10739         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10740
10741         entry.action.flex_off = 0;  /*use 0 by default */
10742         if (!strcmp(res->drop, "drop"))
10743                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10744         else
10745                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10746
10747         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10748             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10749                 if (!strcmp(res->pf_vf, "pf"))
10750                         entry.input.flow_ext.is_vf = 0;
10751                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10752                         struct rte_eth_dev_info dev_info;
10753
10754                         memset(&dev_info, 0, sizeof(dev_info));
10755                         rte_eth_dev_info_get(res->port_id, &dev_info);
10756                         errno = 0;
10757                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10758                         if (errno != 0 || *end != '\0' ||
10759                             vf_id >= dev_info.max_vfs) {
10760                                 printf("invalid parameter %s.\n", res->pf_vf);
10761                                 return;
10762                         }
10763                         entry.input.flow_ext.is_vf = 1;
10764                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10765                 } else {
10766                         printf("invalid parameter %s.\n", res->pf_vf);
10767                         return;
10768                 }
10769         }
10770
10771         /* set to report FD ID by default */
10772         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10773         entry.action.rx_queue = res->queue_id;
10774         entry.soft_id = res->fd_id_value;
10775         if (!strcmp(res->ops, "add"))
10776                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10777                                              RTE_ETH_FILTER_ADD, &entry);
10778         else if (!strcmp(res->ops, "del"))
10779                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10780                                              RTE_ETH_FILTER_DELETE, &entry);
10781         else
10782                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10783                                              RTE_ETH_FILTER_UPDATE, &entry);
10784         if (ret < 0)
10785                 printf("flow director programming error: (%s)\n",
10786                         strerror(-ret));
10787 }
10788
10789 cmdline_parse_token_string_t cmd_flow_director_filter =
10790         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10791                                  flow_director_filter, "flow_director_filter");
10792 cmdline_parse_token_num_t cmd_flow_director_port_id =
10793         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10794                               port_id, UINT16);
10795 cmdline_parse_token_string_t cmd_flow_director_ops =
10796         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10797                                  ops, "add#del#update");
10798 cmdline_parse_token_string_t cmd_flow_director_flow =
10799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10800                                  flow, "flow");
10801 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10803                 flow_type, NULL);
10804 cmdline_parse_token_string_t cmd_flow_director_ether =
10805         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10806                                  ether, "ether");
10807 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10808         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10809                               ether_type, UINT16);
10810 cmdline_parse_token_string_t cmd_flow_director_src =
10811         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10812                                  src, "src");
10813 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10814         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10815                                  ip_src);
10816 cmdline_parse_token_num_t cmd_flow_director_port_src =
10817         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10818                               port_src, UINT16);
10819 cmdline_parse_token_string_t cmd_flow_director_dst =
10820         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10821                                  dst, "dst");
10822 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10823         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10824                                  ip_dst);
10825 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10826         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10827                               port_dst, UINT16);
10828 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10829         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10830                                   verify_tag, "verify_tag");
10831 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10832         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10833                               verify_tag_value, UINT32);
10834 cmdline_parse_token_string_t cmd_flow_director_tos =
10835         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10836                                  tos, "tos");
10837 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10838         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10839                               tos_value, UINT8);
10840 cmdline_parse_token_string_t cmd_flow_director_proto =
10841         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10842                                  proto, "proto");
10843 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10844         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10845                               proto_value, UINT8);
10846 cmdline_parse_token_string_t cmd_flow_director_ttl =
10847         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10848                                  ttl, "ttl");
10849 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10850         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10851                               ttl_value, UINT8);
10852 cmdline_parse_token_string_t cmd_flow_director_vlan =
10853         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10854                                  vlan, "vlan");
10855 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10856         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10857                               vlan_value, UINT16);
10858 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10860                                  flexbytes, "flexbytes");
10861 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10863                               flexbytes_value, NULL);
10864 cmdline_parse_token_string_t cmd_flow_director_drop =
10865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10866                                  drop, "drop#fwd");
10867 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10869                               pf_vf, NULL);
10870 cmdline_parse_token_string_t cmd_flow_director_queue =
10871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10872                                  queue, "queue");
10873 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10874         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10875                               queue_id, UINT16);
10876 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10877         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10878                                  fd_id, "fd_id");
10879 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10880         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10881                               fd_id_value, UINT32);
10882
10883 cmdline_parse_token_string_t cmd_flow_director_mode =
10884         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10885                                  mode, "mode");
10886 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10887         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10888                                  mode_value, "IP");
10889 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10890         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10891                                  mode_value, "MAC-VLAN");
10892 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10893         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10894                                  mode_value, "Tunnel");
10895 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10896         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10897                                  mode_value, "raw");
10898 cmdline_parse_token_string_t cmd_flow_director_mac =
10899         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10900                                  mac, "mac");
10901 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10902         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10903                                     mac_addr);
10904 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10905         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10906                                  tunnel, "tunnel");
10907 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10909                                  tunnel_type, "NVGRE#VxLAN");
10910 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10911         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10912                                  tunnel_id, "tunnel-id");
10913 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10914         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10915                               tunnel_id_value, UINT32);
10916 cmdline_parse_token_string_t cmd_flow_director_packet =
10917         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10918                                  packet, "packet");
10919 cmdline_parse_token_string_t cmd_flow_director_filepath =
10920         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10921                                  filepath, NULL);
10922
10923 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10924         .f = cmd_flow_director_filter_parsed,
10925         .data = NULL,
10926         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10927                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10928                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10929                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10930                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10931                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10932                 "fd_id <fd_id_value>: "
10933                 "Add or delete an ip flow director entry on NIC",
10934         .tokens = {
10935                 (void *)&cmd_flow_director_filter,
10936                 (void *)&cmd_flow_director_port_id,
10937                 (void *)&cmd_flow_director_mode,
10938                 (void *)&cmd_flow_director_mode_ip,
10939                 (void *)&cmd_flow_director_ops,
10940                 (void *)&cmd_flow_director_flow,
10941                 (void *)&cmd_flow_director_flow_type,
10942                 (void *)&cmd_flow_director_src,
10943                 (void *)&cmd_flow_director_ip_src,
10944                 (void *)&cmd_flow_director_dst,
10945                 (void *)&cmd_flow_director_ip_dst,
10946                 (void *)&cmd_flow_director_tos,
10947                 (void *)&cmd_flow_director_tos_value,
10948                 (void *)&cmd_flow_director_proto,
10949                 (void *)&cmd_flow_director_proto_value,
10950                 (void *)&cmd_flow_director_ttl,
10951                 (void *)&cmd_flow_director_ttl_value,
10952                 (void *)&cmd_flow_director_vlan,
10953                 (void *)&cmd_flow_director_vlan_value,
10954                 (void *)&cmd_flow_director_flexbytes,
10955                 (void *)&cmd_flow_director_flexbytes_value,
10956                 (void *)&cmd_flow_director_drop,
10957                 (void *)&cmd_flow_director_pf_vf,
10958                 (void *)&cmd_flow_director_queue,
10959                 (void *)&cmd_flow_director_queue_id,
10960                 (void *)&cmd_flow_director_fd_id,
10961                 (void *)&cmd_flow_director_fd_id_value,
10962                 NULL,
10963         },
10964 };
10965
10966 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10967         .f = cmd_flow_director_filter_parsed,
10968         .data = NULL,
10969         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10970                 "director entry on NIC",
10971         .tokens = {
10972                 (void *)&cmd_flow_director_filter,
10973                 (void *)&cmd_flow_director_port_id,
10974                 (void *)&cmd_flow_director_mode,
10975                 (void *)&cmd_flow_director_mode_ip,
10976                 (void *)&cmd_flow_director_ops,
10977                 (void *)&cmd_flow_director_flow,
10978                 (void *)&cmd_flow_director_flow_type,
10979                 (void *)&cmd_flow_director_src,
10980                 (void *)&cmd_flow_director_ip_src,
10981                 (void *)&cmd_flow_director_port_src,
10982                 (void *)&cmd_flow_director_dst,
10983                 (void *)&cmd_flow_director_ip_dst,
10984                 (void *)&cmd_flow_director_port_dst,
10985                 (void *)&cmd_flow_director_tos,
10986                 (void *)&cmd_flow_director_tos_value,
10987                 (void *)&cmd_flow_director_ttl,
10988                 (void *)&cmd_flow_director_ttl_value,
10989                 (void *)&cmd_flow_director_vlan,
10990                 (void *)&cmd_flow_director_vlan_value,
10991                 (void *)&cmd_flow_director_flexbytes,
10992                 (void *)&cmd_flow_director_flexbytes_value,
10993                 (void *)&cmd_flow_director_drop,
10994                 (void *)&cmd_flow_director_pf_vf,
10995                 (void *)&cmd_flow_director_queue,
10996                 (void *)&cmd_flow_director_queue_id,
10997                 (void *)&cmd_flow_director_fd_id,
10998                 (void *)&cmd_flow_director_fd_id_value,
10999                 NULL,
11000         },
11001 };
11002
11003 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11004         .f = cmd_flow_director_filter_parsed,
11005         .data = NULL,
11006         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11007                 "director entry on NIC",
11008         .tokens = {
11009                 (void *)&cmd_flow_director_filter,
11010                 (void *)&cmd_flow_director_port_id,
11011                 (void *)&cmd_flow_director_mode,
11012                 (void *)&cmd_flow_director_mode_ip,
11013                 (void *)&cmd_flow_director_ops,
11014                 (void *)&cmd_flow_director_flow,
11015                 (void *)&cmd_flow_director_flow_type,
11016                 (void *)&cmd_flow_director_src,
11017                 (void *)&cmd_flow_director_ip_src,
11018                 (void *)&cmd_flow_director_port_src,
11019                 (void *)&cmd_flow_director_dst,
11020                 (void *)&cmd_flow_director_ip_dst,
11021                 (void *)&cmd_flow_director_port_dst,
11022                 (void *)&cmd_flow_director_verify_tag,
11023                 (void *)&cmd_flow_director_verify_tag_value,
11024                 (void *)&cmd_flow_director_tos,
11025                 (void *)&cmd_flow_director_tos_value,
11026                 (void *)&cmd_flow_director_ttl,
11027                 (void *)&cmd_flow_director_ttl_value,
11028                 (void *)&cmd_flow_director_vlan,
11029                 (void *)&cmd_flow_director_vlan_value,
11030                 (void *)&cmd_flow_director_flexbytes,
11031                 (void *)&cmd_flow_director_flexbytes_value,
11032                 (void *)&cmd_flow_director_drop,
11033                 (void *)&cmd_flow_director_pf_vf,
11034                 (void *)&cmd_flow_director_queue,
11035                 (void *)&cmd_flow_director_queue_id,
11036                 (void *)&cmd_flow_director_fd_id,
11037                 (void *)&cmd_flow_director_fd_id_value,
11038                 NULL,
11039         },
11040 };
11041
11042 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11043         .f = cmd_flow_director_filter_parsed,
11044         .data = NULL,
11045         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11046                 "director entry on NIC",
11047         .tokens = {
11048                 (void *)&cmd_flow_director_filter,
11049                 (void *)&cmd_flow_director_port_id,
11050                 (void *)&cmd_flow_director_mode,
11051                 (void *)&cmd_flow_director_mode_ip,
11052                 (void *)&cmd_flow_director_ops,
11053                 (void *)&cmd_flow_director_flow,
11054                 (void *)&cmd_flow_director_flow_type,
11055                 (void *)&cmd_flow_director_ether,
11056                 (void *)&cmd_flow_director_ether_type,
11057                 (void *)&cmd_flow_director_flexbytes,
11058                 (void *)&cmd_flow_director_flexbytes_value,
11059                 (void *)&cmd_flow_director_drop,
11060                 (void *)&cmd_flow_director_pf_vf,
11061                 (void *)&cmd_flow_director_queue,
11062                 (void *)&cmd_flow_director_queue_id,
11063                 (void *)&cmd_flow_director_fd_id,
11064                 (void *)&cmd_flow_director_fd_id_value,
11065                 NULL,
11066         },
11067 };
11068
11069 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11070         .f = cmd_flow_director_filter_parsed,
11071         .data = NULL,
11072         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11073                 "director entry on NIC",
11074         .tokens = {
11075                 (void *)&cmd_flow_director_filter,
11076                 (void *)&cmd_flow_director_port_id,
11077                 (void *)&cmd_flow_director_mode,
11078                 (void *)&cmd_flow_director_mode_mac_vlan,
11079                 (void *)&cmd_flow_director_ops,
11080                 (void *)&cmd_flow_director_mac,
11081                 (void *)&cmd_flow_director_mac_addr,
11082                 (void *)&cmd_flow_director_vlan,
11083                 (void *)&cmd_flow_director_vlan_value,
11084                 (void *)&cmd_flow_director_flexbytes,
11085                 (void *)&cmd_flow_director_flexbytes_value,
11086                 (void *)&cmd_flow_director_drop,
11087                 (void *)&cmd_flow_director_queue,
11088                 (void *)&cmd_flow_director_queue_id,
11089                 (void *)&cmd_flow_director_fd_id,
11090                 (void *)&cmd_flow_director_fd_id_value,
11091                 NULL,
11092         },
11093 };
11094
11095 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11096         .f = cmd_flow_director_filter_parsed,
11097         .data = NULL,
11098         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11099                 "director entry on NIC",
11100         .tokens = {
11101                 (void *)&cmd_flow_director_filter,
11102                 (void *)&cmd_flow_director_port_id,
11103                 (void *)&cmd_flow_director_mode,
11104                 (void *)&cmd_flow_director_mode_tunnel,
11105                 (void *)&cmd_flow_director_ops,
11106                 (void *)&cmd_flow_director_mac,
11107                 (void *)&cmd_flow_director_mac_addr,
11108                 (void *)&cmd_flow_director_vlan,
11109                 (void *)&cmd_flow_director_vlan_value,
11110                 (void *)&cmd_flow_director_tunnel,
11111                 (void *)&cmd_flow_director_tunnel_type,
11112                 (void *)&cmd_flow_director_tunnel_id,
11113                 (void *)&cmd_flow_director_tunnel_id_value,
11114                 (void *)&cmd_flow_director_flexbytes,
11115                 (void *)&cmd_flow_director_flexbytes_value,
11116                 (void *)&cmd_flow_director_drop,
11117                 (void *)&cmd_flow_director_queue,
11118                 (void *)&cmd_flow_director_queue_id,
11119                 (void *)&cmd_flow_director_fd_id,
11120                 (void *)&cmd_flow_director_fd_id_value,
11121                 NULL,
11122         },
11123 };
11124
11125 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11126         .f = cmd_flow_director_filter_parsed,
11127         .data = NULL,
11128         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11129                 "director entry on NIC",
11130         .tokens = {
11131                 (void *)&cmd_flow_director_filter,
11132                 (void *)&cmd_flow_director_port_id,
11133                 (void *)&cmd_flow_director_mode,
11134                 (void *)&cmd_flow_director_mode_raw,
11135                 (void *)&cmd_flow_director_ops,
11136                 (void *)&cmd_flow_director_flow,
11137                 (void *)&cmd_flow_director_flow_type,
11138                 (void *)&cmd_flow_director_drop,
11139                 (void *)&cmd_flow_director_queue,
11140                 (void *)&cmd_flow_director_queue_id,
11141                 (void *)&cmd_flow_director_fd_id,
11142                 (void *)&cmd_flow_director_fd_id_value,
11143                 (void *)&cmd_flow_director_packet,
11144                 (void *)&cmd_flow_director_filepath,
11145                 NULL,
11146         },
11147 };
11148
11149 struct cmd_flush_flow_director_result {
11150         cmdline_fixed_string_t flush_flow_director;
11151         portid_t port_id;
11152 };
11153
11154 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11155         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11156                                  flush_flow_director, "flush_flow_director");
11157 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11158         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11159                               port_id, UINT16);
11160
11161 static void
11162 cmd_flush_flow_director_parsed(void *parsed_result,
11163                           __attribute__((unused)) struct cmdline *cl,
11164                           __attribute__((unused)) void *data)
11165 {
11166         struct cmd_flow_director_result *res = parsed_result;
11167         int ret = 0;
11168
11169         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11170         if (ret < 0) {
11171                 printf("flow director is not supported on port %u.\n",
11172                         res->port_id);
11173                 return;
11174         }
11175
11176         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11177                         RTE_ETH_FILTER_FLUSH, NULL);
11178         if (ret < 0)
11179                 printf("flow director table flushing error: (%s)\n",
11180                         strerror(-ret));
11181 }
11182
11183 cmdline_parse_inst_t cmd_flush_flow_director = {
11184         .f = cmd_flush_flow_director_parsed,
11185         .data = NULL,
11186         .help_str = "flush_flow_director <port_id>: "
11187                 "Flush all flow director entries of a device on NIC",
11188         .tokens = {
11189                 (void *)&cmd_flush_flow_director_flush,
11190                 (void *)&cmd_flush_flow_director_port_id,
11191                 NULL,
11192         },
11193 };
11194
11195 /* *** deal with flow director mask *** */
11196 struct cmd_flow_director_mask_result {
11197         cmdline_fixed_string_t flow_director_mask;
11198         portid_t port_id;
11199         cmdline_fixed_string_t mode;
11200         cmdline_fixed_string_t mode_value;
11201         cmdline_fixed_string_t vlan;
11202         uint16_t vlan_mask;
11203         cmdline_fixed_string_t src_mask;
11204         cmdline_ipaddr_t ipv4_src;
11205         cmdline_ipaddr_t ipv6_src;
11206         uint16_t port_src;
11207         cmdline_fixed_string_t dst_mask;
11208         cmdline_ipaddr_t ipv4_dst;
11209         cmdline_ipaddr_t ipv6_dst;
11210         uint16_t port_dst;
11211         cmdline_fixed_string_t mac;
11212         uint8_t mac_addr_byte_mask;
11213         cmdline_fixed_string_t tunnel_id;
11214         uint32_t tunnel_id_mask;
11215         cmdline_fixed_string_t tunnel_type;
11216         uint8_t tunnel_type_mask;
11217 };
11218
11219 static void
11220 cmd_flow_director_mask_parsed(void *parsed_result,
11221                           __attribute__((unused)) struct cmdline *cl,
11222                           __attribute__((unused)) void *data)
11223 {
11224         struct cmd_flow_director_mask_result *res = parsed_result;
11225         struct rte_eth_fdir_masks *mask;
11226         struct rte_port *port;
11227
11228         port = &ports[res->port_id];
11229         /** Check if the port is not started **/
11230         if (port->port_status != RTE_PORT_STOPPED) {
11231                 printf("Please stop port %d first\n", res->port_id);
11232                 return;
11233         }
11234
11235         mask = &port->dev_conf.fdir_conf.mask;
11236
11237         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11238                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11239                         printf("Please set mode to MAC-VLAN.\n");
11240                         return;
11241                 }
11242
11243                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11244         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11245                 if (strcmp(res->mode_value, "Tunnel")) {
11246                         printf("Please set mode to Tunnel.\n");
11247                         return;
11248                 }
11249
11250                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11251                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11252                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11253                 mask->tunnel_type_mask = res->tunnel_type_mask;
11254         } else {
11255                 if (strcmp(res->mode_value, "IP")) {
11256                         printf("Please set mode to IP.\n");
11257                         return;
11258                 }
11259
11260                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11261                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11262                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11263                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11264                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11265                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11266                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11267         }
11268
11269         cmd_reconfig_device_queue(res->port_id, 1, 1);
11270 }
11271
11272 cmdline_parse_token_string_t cmd_flow_director_mask =
11273         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11274                                  flow_director_mask, "flow_director_mask");
11275 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11276         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11277                               port_id, UINT16);
11278 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11279         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11280                                  vlan, "vlan");
11281 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11282         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11283                               vlan_mask, UINT16);
11284 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11286                                  src_mask, "src_mask");
11287 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11288         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11289                                  ipv4_src);
11290 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11291         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11292                                  ipv6_src);
11293 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11294         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11295                               port_src, UINT16);
11296 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11298                                  dst_mask, "dst_mask");
11299 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11300         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11301                                  ipv4_dst);
11302 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11303         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11304                                  ipv6_dst);
11305 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11306         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11307                               port_dst, UINT16);
11308
11309 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11311                                  mode, "mode");
11312 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11313         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11314                                  mode_value, "IP");
11315 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11316         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11317                                  mode_value, "MAC-VLAN");
11318 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11319         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11320                                  mode_value, "Tunnel");
11321 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11322         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11323                                  mac, "mac");
11324 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11325         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11326                               mac_addr_byte_mask, UINT8);
11327 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11328         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11329                                  tunnel_type, "tunnel-type");
11330 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11331         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11332                               tunnel_type_mask, UINT8);
11333 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11334         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11335                                  tunnel_id, "tunnel-id");
11336 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11337         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11338                               tunnel_id_mask, UINT32);
11339
11340 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11341         .f = cmd_flow_director_mask_parsed,
11342         .data = NULL,
11343         .help_str = "flow_director_mask ... : "
11344                 "Set IP mode flow director's mask on NIC",
11345         .tokens = {
11346                 (void *)&cmd_flow_director_mask,
11347                 (void *)&cmd_flow_director_mask_port_id,
11348                 (void *)&cmd_flow_director_mask_mode,
11349                 (void *)&cmd_flow_director_mask_mode_ip,
11350                 (void *)&cmd_flow_director_mask_vlan,
11351                 (void *)&cmd_flow_director_mask_vlan_value,
11352                 (void *)&cmd_flow_director_mask_src,
11353                 (void *)&cmd_flow_director_mask_ipv4_src,
11354                 (void *)&cmd_flow_director_mask_ipv6_src,
11355                 (void *)&cmd_flow_director_mask_port_src,
11356                 (void *)&cmd_flow_director_mask_dst,
11357                 (void *)&cmd_flow_director_mask_ipv4_dst,
11358                 (void *)&cmd_flow_director_mask_ipv6_dst,
11359                 (void *)&cmd_flow_director_mask_port_dst,
11360                 NULL,
11361         },
11362 };
11363
11364 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11365         .f = cmd_flow_director_mask_parsed,
11366         .data = NULL,
11367         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11368                 "flow director's mask on NIC",
11369         .tokens = {
11370                 (void *)&cmd_flow_director_mask,
11371                 (void *)&cmd_flow_director_mask_port_id,
11372                 (void *)&cmd_flow_director_mask_mode,
11373                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11374                 (void *)&cmd_flow_director_mask_vlan,
11375                 (void *)&cmd_flow_director_mask_vlan_value,
11376                 NULL,
11377         },
11378 };
11379
11380 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11381         .f = cmd_flow_director_mask_parsed,
11382         .data = NULL,
11383         .help_str = "flow_director_mask ... : Set tunnel mode "
11384                 "flow director's mask on NIC",
11385         .tokens = {
11386                 (void *)&cmd_flow_director_mask,
11387                 (void *)&cmd_flow_director_mask_port_id,
11388                 (void *)&cmd_flow_director_mask_mode,
11389                 (void *)&cmd_flow_director_mask_mode_tunnel,
11390                 (void *)&cmd_flow_director_mask_vlan,
11391                 (void *)&cmd_flow_director_mask_vlan_value,
11392                 (void *)&cmd_flow_director_mask_mac,
11393                 (void *)&cmd_flow_director_mask_mac_value,
11394                 (void *)&cmd_flow_director_mask_tunnel_type,
11395                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11396                 (void *)&cmd_flow_director_mask_tunnel_id,
11397                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11398                 NULL,
11399         },
11400 };
11401
11402 /* *** deal with flow director mask on flexible payload *** */
11403 struct cmd_flow_director_flex_mask_result {
11404         cmdline_fixed_string_t flow_director_flexmask;
11405         portid_t port_id;
11406         cmdline_fixed_string_t flow;
11407         cmdline_fixed_string_t flow_type;
11408         cmdline_fixed_string_t mask;
11409 };
11410
11411 static void
11412 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11413                           __attribute__((unused)) struct cmdline *cl,
11414                           __attribute__((unused)) void *data)
11415 {
11416         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11417         struct rte_eth_fdir_info fdir_info;
11418         struct rte_eth_fdir_flex_mask flex_mask;
11419         struct rte_port *port;
11420         uint64_t flow_type_mask;
11421         uint16_t i;
11422         int ret;
11423
11424         port = &ports[res->port_id];
11425         /** Check if the port is not started **/
11426         if (port->port_status != RTE_PORT_STOPPED) {
11427                 printf("Please stop port %d first\n", res->port_id);
11428                 return;
11429         }
11430
11431         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11432         ret = parse_flexbytes(res->mask,
11433                         flex_mask.mask,
11434                         RTE_ETH_FDIR_MAX_FLEXLEN);
11435         if (ret < 0) {
11436                 printf("error: Cannot parse mask input.\n");
11437                 return;
11438         }
11439
11440         memset(&fdir_info, 0, sizeof(fdir_info));
11441         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11442                                 RTE_ETH_FILTER_INFO, &fdir_info);
11443         if (ret < 0) {
11444                 printf("Cannot get FDir filter info\n");
11445                 return;
11446         }
11447
11448         if (!strcmp(res->flow_type, "none")) {
11449                 /* means don't specify the flow type */
11450                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11451                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11452                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11453                                0, sizeof(struct rte_eth_fdir_flex_mask));
11454                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11455                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11456                                  &flex_mask,
11457                                  sizeof(struct rte_eth_fdir_flex_mask));
11458                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11459                 return;
11460         }
11461         flow_type_mask = fdir_info.flow_types_mask[0];
11462         if (!strcmp(res->flow_type, "all")) {
11463                 if (!flow_type_mask) {
11464                         printf("No flow type supported\n");
11465                         return;
11466                 }
11467                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11468                         if (flow_type_mask & (1ULL << i)) {
11469                                 flex_mask.flow_type = i;
11470                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11471                         }
11472                 }
11473                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11474                 return;
11475         }
11476         flex_mask.flow_type = str2flowtype(res->flow_type);
11477         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11478                 printf("Flow type %s not supported on port %d\n",
11479                                 res->flow_type, res->port_id);
11480                 return;
11481         }
11482         fdir_set_flex_mask(res->port_id, &flex_mask);
11483         cmd_reconfig_device_queue(res->port_id, 1, 1);
11484 }
11485
11486 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11487         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11488                                  flow_director_flexmask,
11489                                  "flow_director_flex_mask");
11490 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11491         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11492                               port_id, UINT16);
11493 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11494         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11495                                  flow, "flow");
11496 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11497         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11498                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11499                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11500 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11501         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11502                                  mask, NULL);
11503
11504 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11505         .f = cmd_flow_director_flex_mask_parsed,
11506         .data = NULL,
11507         .help_str = "flow_director_flex_mask ... : "
11508                 "Set flow director's flex mask on NIC",
11509         .tokens = {
11510                 (void *)&cmd_flow_director_flexmask,
11511                 (void *)&cmd_flow_director_flexmask_port_id,
11512                 (void *)&cmd_flow_director_flexmask_flow,
11513                 (void *)&cmd_flow_director_flexmask_flow_type,
11514                 (void *)&cmd_flow_director_flexmask_mask,
11515                 NULL,
11516         },
11517 };
11518
11519 /* *** deal with flow director flexible payload configuration *** */
11520 struct cmd_flow_director_flexpayload_result {
11521         cmdline_fixed_string_t flow_director_flexpayload;
11522         portid_t port_id;
11523         cmdline_fixed_string_t payload_layer;
11524         cmdline_fixed_string_t payload_cfg;
11525 };
11526
11527 static inline int
11528 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11529 {
11530         char s[256];
11531         const char *p, *p0 = q_arg;
11532         char *end;
11533         unsigned long int_fld;
11534         char *str_fld[max_num];
11535         int i;
11536         unsigned size;
11537         int ret = -1;
11538
11539         p = strchr(p0, '(');
11540         if (p == NULL)
11541                 return -1;
11542         ++p;
11543         p0 = strchr(p, ')');
11544         if (p0 == NULL)
11545                 return -1;
11546
11547         size = p0 - p;
11548         if (size >= sizeof(s))
11549                 return -1;
11550
11551         snprintf(s, sizeof(s), "%.*s", size, p);
11552         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11553         if (ret < 0 || ret > max_num)
11554                 return -1;
11555         for (i = 0; i < ret; i++) {
11556                 errno = 0;
11557                 int_fld = strtoul(str_fld[i], &end, 0);
11558                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11559                         return -1;
11560                 offsets[i] = (uint16_t)int_fld;
11561         }
11562         return ret;
11563 }
11564
11565 static void
11566 cmd_flow_director_flxpld_parsed(void *parsed_result,
11567                           __attribute__((unused)) struct cmdline *cl,
11568                           __attribute__((unused)) void *data)
11569 {
11570         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11571         struct rte_eth_flex_payload_cfg flex_cfg;
11572         struct rte_port *port;
11573         int ret = 0;
11574
11575         port = &ports[res->port_id];
11576         /** Check if the port is not started **/
11577         if (port->port_status != RTE_PORT_STOPPED) {
11578                 printf("Please stop port %d first\n", res->port_id);
11579                 return;
11580         }
11581
11582         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11583
11584         if (!strcmp(res->payload_layer, "raw"))
11585                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11586         else if (!strcmp(res->payload_layer, "l2"))
11587                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11588         else if (!strcmp(res->payload_layer, "l3"))
11589                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11590         else if (!strcmp(res->payload_layer, "l4"))
11591                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11592
11593         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11594                             RTE_ETH_FDIR_MAX_FLEXLEN);
11595         if (ret < 0) {
11596                 printf("error: Cannot parse flex payload input.\n");
11597                 return;
11598         }
11599
11600         fdir_set_flex_payload(res->port_id, &flex_cfg);
11601         cmd_reconfig_device_queue(res->port_id, 1, 1);
11602 }
11603
11604 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11606                                  flow_director_flexpayload,
11607                                  "flow_director_flex_payload");
11608 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11609         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11610                               port_id, UINT16);
11611 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11612         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11613                                  payload_layer, "raw#l2#l3#l4");
11614 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11615         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11616                                  payload_cfg, NULL);
11617
11618 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11619         .f = cmd_flow_director_flxpld_parsed,
11620         .data = NULL,
11621         .help_str = "flow_director_flexpayload ... : "
11622                 "Set flow director's flex payload on NIC",
11623         .tokens = {
11624                 (void *)&cmd_flow_director_flexpayload,
11625                 (void *)&cmd_flow_director_flexpayload_port_id,
11626                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11627                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11628                 NULL,
11629         },
11630 };
11631
11632 /* Generic flow interface command. */
11633 extern cmdline_parse_inst_t cmd_flow;
11634
11635 /* *** Classification Filters Control *** */
11636 /* *** Get symmetric hash enable per port *** */
11637 struct cmd_get_sym_hash_ena_per_port_result {
11638         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11639         portid_t port_id;
11640 };
11641
11642 static void
11643 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11644                                  __rte_unused struct cmdline *cl,
11645                                  __rte_unused void *data)
11646 {
11647         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11648         struct rte_eth_hash_filter_info info;
11649         int ret;
11650
11651         if (rte_eth_dev_filter_supported(res->port_id,
11652                                 RTE_ETH_FILTER_HASH) < 0) {
11653                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11654                                                         res->port_id);
11655                 return;
11656         }
11657
11658         memset(&info, 0, sizeof(info));
11659         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11660         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11661                                                 RTE_ETH_FILTER_GET, &info);
11662
11663         if (ret < 0) {
11664                 printf("Cannot get symmetric hash enable per port "
11665                                         "on port %u\n", res->port_id);
11666                 return;
11667         }
11668
11669         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11670                                 "enabled" : "disabled", res->port_id);
11671 }
11672
11673 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11674         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11675                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11676 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11677         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11678                 port_id, UINT16);
11679
11680 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11681         .f = cmd_get_sym_hash_per_port_parsed,
11682         .data = NULL,
11683         .help_str = "get_sym_hash_ena_per_port <port_id>",
11684         .tokens = {
11685                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11686                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11687                 NULL,
11688         },
11689 };
11690
11691 /* *** Set symmetric hash enable per port *** */
11692 struct cmd_set_sym_hash_ena_per_port_result {
11693         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11694         cmdline_fixed_string_t enable;
11695         portid_t port_id;
11696 };
11697
11698 static void
11699 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11700                                  __rte_unused struct cmdline *cl,
11701                                  __rte_unused void *data)
11702 {
11703         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11704         struct rte_eth_hash_filter_info info;
11705         int ret;
11706
11707         if (rte_eth_dev_filter_supported(res->port_id,
11708                                 RTE_ETH_FILTER_HASH) < 0) {
11709                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11710                                                         res->port_id);
11711                 return;
11712         }
11713
11714         memset(&info, 0, sizeof(info));
11715         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11716         if (!strcmp(res->enable, "enable"))
11717                 info.info.enable = 1;
11718         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11719                                         RTE_ETH_FILTER_SET, &info);
11720         if (ret < 0) {
11721                 printf("Cannot set symmetric hash enable per port on "
11722                                         "port %u\n", res->port_id);
11723                 return;
11724         }
11725         printf("Symmetric hash has been set to %s on port %u\n",
11726                                         res->enable, res->port_id);
11727 }
11728
11729 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11730         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11731                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11732 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11733         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11734                 port_id, UINT16);
11735 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11736         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11737                 enable, "enable#disable");
11738
11739 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11740         .f = cmd_set_sym_hash_per_port_parsed,
11741         .data = NULL,
11742         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11743         .tokens = {
11744                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11745                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11746                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11747                 NULL,
11748         },
11749 };
11750
11751 /* Get global config of hash function */
11752 struct cmd_get_hash_global_config_result {
11753         cmdline_fixed_string_t get_hash_global_config;
11754         portid_t port_id;
11755 };
11756
11757 static char *
11758 flowtype_to_str(uint16_t ftype)
11759 {
11760         uint16_t i;
11761         static struct {
11762                 char str[16];
11763                 uint16_t ftype;
11764         } ftype_table[] = {
11765                 {"ipv4", RTE_ETH_FLOW_IPV4},
11766                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11767                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11768                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11769                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11770                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11771                 {"ipv6", RTE_ETH_FLOW_IPV6},
11772                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11773                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11774                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11775                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11776                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11777                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11778                 {"port", RTE_ETH_FLOW_PORT},
11779                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11780                 {"geneve", RTE_ETH_FLOW_GENEVE},
11781                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11782         };
11783
11784         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11785                 if (ftype_table[i].ftype == ftype)
11786                         return ftype_table[i].str;
11787         }
11788
11789         return NULL;
11790 }
11791
11792 static void
11793 cmd_get_hash_global_config_parsed(void *parsed_result,
11794                                   __rte_unused struct cmdline *cl,
11795                                   __rte_unused void *data)
11796 {
11797         struct cmd_get_hash_global_config_result *res = parsed_result;
11798         struct rte_eth_hash_filter_info info;
11799         uint32_t idx, offset;
11800         uint16_t i;
11801         char *str;
11802         int ret;
11803
11804         if (rte_eth_dev_filter_supported(res->port_id,
11805                         RTE_ETH_FILTER_HASH) < 0) {
11806                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11807                                                         res->port_id);
11808                 return;
11809         }
11810
11811         memset(&info, 0, sizeof(info));
11812         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11813         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11814                                         RTE_ETH_FILTER_GET, &info);
11815         if (ret < 0) {
11816                 printf("Cannot get hash global configurations by port %d\n",
11817                                                         res->port_id);
11818                 return;
11819         }
11820
11821         switch (info.info.global_conf.hash_func) {
11822         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11823                 printf("Hash function is Toeplitz\n");
11824                 break;
11825         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11826                 printf("Hash function is Simple XOR\n");
11827                 break;
11828         default:
11829                 printf("Unknown hash function\n");
11830                 break;
11831         }
11832
11833         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11834                 idx = i / UINT64_BIT;
11835                 offset = i % UINT64_BIT;
11836                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11837                                                 (1ULL << offset)))
11838                         continue;
11839                 str = flowtype_to_str(i);
11840                 if (!str)
11841                         continue;
11842                 printf("Symmetric hash is %s globally for flow type %s "
11843                                                         "by port %d\n",
11844                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11845                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11846                                                         res->port_id);
11847         }
11848 }
11849
11850 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11851         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11852                 get_hash_global_config, "get_hash_global_config");
11853 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11854         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11855                 port_id, UINT16);
11856
11857 cmdline_parse_inst_t cmd_get_hash_global_config = {
11858         .f = cmd_get_hash_global_config_parsed,
11859         .data = NULL,
11860         .help_str = "get_hash_global_config <port_id>",
11861         .tokens = {
11862                 (void *)&cmd_get_hash_global_config_all,
11863                 (void *)&cmd_get_hash_global_config_port_id,
11864                 NULL,
11865         },
11866 };
11867
11868 /* Set global config of hash function */
11869 struct cmd_set_hash_global_config_result {
11870         cmdline_fixed_string_t set_hash_global_config;
11871         portid_t port_id;
11872         cmdline_fixed_string_t hash_func;
11873         cmdline_fixed_string_t flow_type;
11874         cmdline_fixed_string_t enable;
11875 };
11876
11877 static void
11878 cmd_set_hash_global_config_parsed(void *parsed_result,
11879                                   __rte_unused struct cmdline *cl,
11880                                   __rte_unused void *data)
11881 {
11882         struct cmd_set_hash_global_config_result *res = parsed_result;
11883         struct rte_eth_hash_filter_info info;
11884         uint32_t ftype, idx, offset;
11885         int ret;
11886
11887         if (rte_eth_dev_filter_supported(res->port_id,
11888                                 RTE_ETH_FILTER_HASH) < 0) {
11889                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11890                                                         res->port_id);
11891                 return;
11892         }
11893         memset(&info, 0, sizeof(info));
11894         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11895         if (!strcmp(res->hash_func, "toeplitz"))
11896                 info.info.global_conf.hash_func =
11897                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11898         else if (!strcmp(res->hash_func, "simple_xor"))
11899                 info.info.global_conf.hash_func =
11900                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11901         else if (!strcmp(res->hash_func, "default"))
11902                 info.info.global_conf.hash_func =
11903                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11904
11905         ftype = str2flowtype(res->flow_type);
11906         idx = ftype / UINT64_BIT;
11907         offset = ftype % UINT64_BIT;
11908         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11909         if (!strcmp(res->enable, "enable"))
11910                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11911                                                 (1ULL << offset);
11912         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11913                                         RTE_ETH_FILTER_SET, &info);
11914         if (ret < 0)
11915                 printf("Cannot set global hash configurations by port %d\n",
11916                                                         res->port_id);
11917         else
11918                 printf("Global hash configurations have been set "
11919                         "succcessfully by port %d\n", res->port_id);
11920 }
11921
11922 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11923         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11924                 set_hash_global_config, "set_hash_global_config");
11925 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11926         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11927                 port_id, UINT16);
11928 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11929         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11930                 hash_func, "toeplitz#simple_xor#default");
11931 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11932         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11933                 flow_type,
11934                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11935                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11936 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11937         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11938                 enable, "enable#disable");
11939
11940 cmdline_parse_inst_t cmd_set_hash_global_config = {
11941         .f = cmd_set_hash_global_config_parsed,
11942         .data = NULL,
11943         .help_str = "set_hash_global_config <port_id> "
11944                 "toeplitz|simple_xor|default "
11945                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11946                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11947                 "l2_payload enable|disable",
11948         .tokens = {
11949                 (void *)&cmd_set_hash_global_config_all,
11950                 (void *)&cmd_set_hash_global_config_port_id,
11951                 (void *)&cmd_set_hash_global_config_hash_func,
11952                 (void *)&cmd_set_hash_global_config_flow_type,
11953                 (void *)&cmd_set_hash_global_config_enable,
11954                 NULL,
11955         },
11956 };
11957
11958 /* Set hash input set */
11959 struct cmd_set_hash_input_set_result {
11960         cmdline_fixed_string_t set_hash_input_set;
11961         portid_t port_id;
11962         cmdline_fixed_string_t flow_type;
11963         cmdline_fixed_string_t inset_field;
11964         cmdline_fixed_string_t select;
11965 };
11966
11967 static enum rte_eth_input_set_field
11968 str2inset(char *string)
11969 {
11970         uint16_t i;
11971
11972         static const struct {
11973                 char str[32];
11974                 enum rte_eth_input_set_field inset;
11975         } inset_table[] = {
11976                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11977                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11978                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11979                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11980                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11981                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11982                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11983                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11984                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11985                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11986                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11987                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11988                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11989                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11990                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11991                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11992                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11993                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11994                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11995                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11996                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11997                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11998                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11999                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12000                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12001                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12002                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12003                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12004                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12005                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12006                 {"none", RTE_ETH_INPUT_SET_NONE},
12007         };
12008
12009         for (i = 0; i < RTE_DIM(inset_table); i++) {
12010                 if (!strcmp(string, inset_table[i].str))
12011                         return inset_table[i].inset;
12012         }
12013
12014         return RTE_ETH_INPUT_SET_UNKNOWN;
12015 }
12016
12017 static void
12018 cmd_set_hash_input_set_parsed(void *parsed_result,
12019                               __rte_unused struct cmdline *cl,
12020                               __rte_unused void *data)
12021 {
12022         struct cmd_set_hash_input_set_result *res = parsed_result;
12023         struct rte_eth_hash_filter_info info;
12024
12025         memset(&info, 0, sizeof(info));
12026         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12027         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12028         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12029         info.info.input_set_conf.inset_size = 1;
12030         if (!strcmp(res->select, "select"))
12031                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12032         else if (!strcmp(res->select, "add"))
12033                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12034         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12035                                 RTE_ETH_FILTER_SET, &info);
12036 }
12037
12038 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12039         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12040                 set_hash_input_set, "set_hash_input_set");
12041 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12042         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12043                 port_id, UINT16);
12044 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12045         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12046                 flow_type, NULL);
12047 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12048         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12049                 inset_field,
12050                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12051                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12052                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12053                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12054                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12055                 "fld-8th#none");
12056 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12057         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12058                 select, "select#add");
12059
12060 cmdline_parse_inst_t cmd_set_hash_input_set = {
12061         .f = cmd_set_hash_input_set_parsed,
12062         .data = NULL,
12063         .help_str = "set_hash_input_set <port_id> "
12064         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12065         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12066         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12067         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12068         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12069         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12070         "fld-7th|fld-8th|none select|add",
12071         .tokens = {
12072                 (void *)&cmd_set_hash_input_set_cmd,
12073                 (void *)&cmd_set_hash_input_set_port_id,
12074                 (void *)&cmd_set_hash_input_set_flow_type,
12075                 (void *)&cmd_set_hash_input_set_field,
12076                 (void *)&cmd_set_hash_input_set_select,
12077                 NULL,
12078         },
12079 };
12080
12081 /* Set flow director input set */
12082 struct cmd_set_fdir_input_set_result {
12083         cmdline_fixed_string_t set_fdir_input_set;
12084         portid_t port_id;
12085         cmdline_fixed_string_t flow_type;
12086         cmdline_fixed_string_t inset_field;
12087         cmdline_fixed_string_t select;
12088 };
12089
12090 static void
12091 cmd_set_fdir_input_set_parsed(void *parsed_result,
12092         __rte_unused struct cmdline *cl,
12093         __rte_unused void *data)
12094 {
12095         struct cmd_set_fdir_input_set_result *res = parsed_result;
12096         struct rte_eth_fdir_filter_info info;
12097
12098         memset(&info, 0, sizeof(info));
12099         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12100         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12101         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12102         info.info.input_set_conf.inset_size = 1;
12103         if (!strcmp(res->select, "select"))
12104                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12105         else if (!strcmp(res->select, "add"))
12106                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12107         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12108                 RTE_ETH_FILTER_SET, &info);
12109 }
12110
12111 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12112         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12113         set_fdir_input_set, "set_fdir_input_set");
12114 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12115         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12116         port_id, UINT16);
12117 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12118         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12119         flow_type,
12120         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12121         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12122 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12123         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12124         inset_field,
12125         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12126         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12127         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12128         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12129         "sctp-veri-tag#none");
12130 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12131         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12132         select, "select#add");
12133
12134 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12135         .f = cmd_set_fdir_input_set_parsed,
12136         .data = NULL,
12137         .help_str = "set_fdir_input_set <port_id> "
12138         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12139         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12140         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12141         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12142         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12143         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12144         "sctp-veri-tag|none select|add",
12145         .tokens = {
12146                 (void *)&cmd_set_fdir_input_set_cmd,
12147                 (void *)&cmd_set_fdir_input_set_port_id,
12148                 (void *)&cmd_set_fdir_input_set_flow_type,
12149                 (void *)&cmd_set_fdir_input_set_field,
12150                 (void *)&cmd_set_fdir_input_set_select,
12151                 NULL,
12152         },
12153 };
12154
12155 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12156 struct cmd_mcast_addr_result {
12157         cmdline_fixed_string_t mcast_addr_cmd;
12158         cmdline_fixed_string_t what;
12159         uint16_t port_num;
12160         struct ether_addr mc_addr;
12161 };
12162
12163 static void cmd_mcast_addr_parsed(void *parsed_result,
12164                 __attribute__((unused)) struct cmdline *cl,
12165                 __attribute__((unused)) void *data)
12166 {
12167         struct cmd_mcast_addr_result *res = parsed_result;
12168
12169         if (!is_multicast_ether_addr(&res->mc_addr)) {
12170                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12171                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12172                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12173                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12174                 return;
12175         }
12176         if (strcmp(res->what, "add") == 0)
12177                 mcast_addr_add(res->port_num, &res->mc_addr);
12178         else
12179                 mcast_addr_remove(res->port_num, &res->mc_addr);
12180 }
12181
12182 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12183         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12184                                  mcast_addr_cmd, "mcast_addr");
12185 cmdline_parse_token_string_t cmd_mcast_addr_what =
12186         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12187                                  "add#remove");
12188 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12189         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12190 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12191         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12192
12193 cmdline_parse_inst_t cmd_mcast_addr = {
12194         .f = cmd_mcast_addr_parsed,
12195         .data = (void *)0,
12196         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12197                 "Add/Remove multicast MAC address on port_id",
12198         .tokens = {
12199                 (void *)&cmd_mcast_addr_cmd,
12200                 (void *)&cmd_mcast_addr_what,
12201                 (void *)&cmd_mcast_addr_portnum,
12202                 (void *)&cmd_mcast_addr_addr,
12203                 NULL,
12204         },
12205 };
12206
12207 /* l2 tunnel config
12208  * only support E-tag now.
12209  */
12210
12211 /* Ether type config */
12212 struct cmd_config_l2_tunnel_eth_type_result {
12213         cmdline_fixed_string_t port;
12214         cmdline_fixed_string_t config;
12215         cmdline_fixed_string_t all;
12216         portid_t id;
12217         cmdline_fixed_string_t l2_tunnel;
12218         cmdline_fixed_string_t l2_tunnel_type;
12219         cmdline_fixed_string_t eth_type;
12220         uint16_t eth_type_val;
12221 };
12222
12223 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12224         TOKEN_STRING_INITIALIZER
12225                 (struct cmd_config_l2_tunnel_eth_type_result,
12226                  port, "port");
12227 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12228         TOKEN_STRING_INITIALIZER
12229                 (struct cmd_config_l2_tunnel_eth_type_result,
12230                  config, "config");
12231 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12232         TOKEN_STRING_INITIALIZER
12233                 (struct cmd_config_l2_tunnel_eth_type_result,
12234                  all, "all");
12235 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12236         TOKEN_NUM_INITIALIZER
12237                 (struct cmd_config_l2_tunnel_eth_type_result,
12238                  id, UINT16);
12239 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12240         TOKEN_STRING_INITIALIZER
12241                 (struct cmd_config_l2_tunnel_eth_type_result,
12242                  l2_tunnel, "l2-tunnel");
12243 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12244         TOKEN_STRING_INITIALIZER
12245                 (struct cmd_config_l2_tunnel_eth_type_result,
12246                  l2_tunnel_type, "E-tag");
12247 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12248         TOKEN_STRING_INITIALIZER
12249                 (struct cmd_config_l2_tunnel_eth_type_result,
12250                  eth_type, "ether-type");
12251 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12252         TOKEN_NUM_INITIALIZER
12253                 (struct cmd_config_l2_tunnel_eth_type_result,
12254                  eth_type_val, UINT16);
12255
12256 static enum rte_eth_tunnel_type
12257 str2fdir_l2_tunnel_type(char *string)
12258 {
12259         uint32_t i = 0;
12260
12261         static const struct {
12262                 char str[32];
12263                 enum rte_eth_tunnel_type type;
12264         } l2_tunnel_type_str[] = {
12265                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12266         };
12267
12268         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12269                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12270                         return l2_tunnel_type_str[i].type;
12271         }
12272         return RTE_TUNNEL_TYPE_NONE;
12273 }
12274
12275 /* ether type config for all ports */
12276 static void
12277 cmd_config_l2_tunnel_eth_type_all_parsed
12278         (void *parsed_result,
12279          __attribute__((unused)) struct cmdline *cl,
12280          __attribute__((unused)) void *data)
12281 {
12282         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12283         struct rte_eth_l2_tunnel_conf entry;
12284         portid_t pid;
12285
12286         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12287         entry.ether_type = res->eth_type_val;
12288
12289         RTE_ETH_FOREACH_DEV(pid) {
12290                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12291         }
12292 }
12293
12294 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12295         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12296         .data = NULL,
12297         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12298         .tokens = {
12299                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12300                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12301                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12302                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12303                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12304                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12305                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12306                 NULL,
12307         },
12308 };
12309
12310 /* ether type config for a specific port */
12311 static void
12312 cmd_config_l2_tunnel_eth_type_specific_parsed(
12313         void *parsed_result,
12314         __attribute__((unused)) struct cmdline *cl,
12315         __attribute__((unused)) void *data)
12316 {
12317         struct cmd_config_l2_tunnel_eth_type_result *res =
12318                  parsed_result;
12319         struct rte_eth_l2_tunnel_conf entry;
12320
12321         if (port_id_is_invalid(res->id, ENABLED_WARN))
12322                 return;
12323
12324         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12325         entry.ether_type = res->eth_type_val;
12326
12327         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12328 }
12329
12330 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12331         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12332         .data = NULL,
12333         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12334         .tokens = {
12335                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12336                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12337                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12338                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12339                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12340                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12341                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12342                 NULL,
12343         },
12344 };
12345
12346 /* Enable/disable l2 tunnel */
12347 struct cmd_config_l2_tunnel_en_dis_result {
12348         cmdline_fixed_string_t port;
12349         cmdline_fixed_string_t config;
12350         cmdline_fixed_string_t all;
12351         portid_t id;
12352         cmdline_fixed_string_t l2_tunnel;
12353         cmdline_fixed_string_t l2_tunnel_type;
12354         cmdline_fixed_string_t en_dis;
12355 };
12356
12357 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12358         TOKEN_STRING_INITIALIZER
12359                 (struct cmd_config_l2_tunnel_en_dis_result,
12360                  port, "port");
12361 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12362         TOKEN_STRING_INITIALIZER
12363                 (struct cmd_config_l2_tunnel_en_dis_result,
12364                  config, "config");
12365 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12366         TOKEN_STRING_INITIALIZER
12367                 (struct cmd_config_l2_tunnel_en_dis_result,
12368                  all, "all");
12369 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12370         TOKEN_NUM_INITIALIZER
12371                 (struct cmd_config_l2_tunnel_en_dis_result,
12372                  id, UINT16);
12373 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12374         TOKEN_STRING_INITIALIZER
12375                 (struct cmd_config_l2_tunnel_en_dis_result,
12376                  l2_tunnel, "l2-tunnel");
12377 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12378         TOKEN_STRING_INITIALIZER
12379                 (struct cmd_config_l2_tunnel_en_dis_result,
12380                  l2_tunnel_type, "E-tag");
12381 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12382         TOKEN_STRING_INITIALIZER
12383                 (struct cmd_config_l2_tunnel_en_dis_result,
12384                  en_dis, "enable#disable");
12385
12386 /* enable/disable l2 tunnel for all ports */
12387 static void
12388 cmd_config_l2_tunnel_en_dis_all_parsed(
12389         void *parsed_result,
12390         __attribute__((unused)) struct cmdline *cl,
12391         __attribute__((unused)) void *data)
12392 {
12393         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12394         struct rte_eth_l2_tunnel_conf entry;
12395         portid_t pid;
12396         uint8_t en;
12397
12398         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12399
12400         if (!strcmp("enable", res->en_dis))
12401                 en = 1;
12402         else
12403                 en = 0;
12404
12405         RTE_ETH_FOREACH_DEV(pid) {
12406                 rte_eth_dev_l2_tunnel_offload_set(pid,
12407                                                   &entry,
12408                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12409                                                   en);
12410         }
12411 }
12412
12413 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12414         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12415         .data = NULL,
12416         .help_str = "port config all l2-tunnel E-tag enable|disable",
12417         .tokens = {
12418                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12419                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12420                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12421                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12422                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12423                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12424                 NULL,
12425         },
12426 };
12427
12428 /* enable/disable l2 tunnel for a port */
12429 static void
12430 cmd_config_l2_tunnel_en_dis_specific_parsed(
12431         void *parsed_result,
12432         __attribute__((unused)) struct cmdline *cl,
12433         __attribute__((unused)) void *data)
12434 {
12435         struct cmd_config_l2_tunnel_en_dis_result *res =
12436                 parsed_result;
12437         struct rte_eth_l2_tunnel_conf entry;
12438
12439         if (port_id_is_invalid(res->id, ENABLED_WARN))
12440                 return;
12441
12442         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12443
12444         if (!strcmp("enable", res->en_dis))
12445                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12446                                                   &entry,
12447                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12448                                                   1);
12449         else
12450                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12451                                                   &entry,
12452                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12453                                                   0);
12454 }
12455
12456 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12457         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12458         .data = NULL,
12459         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12460         .tokens = {
12461                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12462                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12463                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12464                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12465                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12466                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12467                 NULL,
12468         },
12469 };
12470
12471 /* E-tag configuration */
12472
12473 /* Common result structure for all E-tag configuration */
12474 struct cmd_config_e_tag_result {
12475         cmdline_fixed_string_t e_tag;
12476         cmdline_fixed_string_t set;
12477         cmdline_fixed_string_t insertion;
12478         cmdline_fixed_string_t stripping;
12479         cmdline_fixed_string_t forwarding;
12480         cmdline_fixed_string_t filter;
12481         cmdline_fixed_string_t add;
12482         cmdline_fixed_string_t del;
12483         cmdline_fixed_string_t on;
12484         cmdline_fixed_string_t off;
12485         cmdline_fixed_string_t on_off;
12486         cmdline_fixed_string_t port_tag_id;
12487         uint32_t port_tag_id_val;
12488         cmdline_fixed_string_t e_tag_id;
12489         uint16_t e_tag_id_val;
12490         cmdline_fixed_string_t dst_pool;
12491         uint8_t dst_pool_val;
12492         cmdline_fixed_string_t port;
12493         portid_t port_id;
12494         cmdline_fixed_string_t vf;
12495         uint8_t vf_id;
12496 };
12497
12498 /* Common CLI fields for all E-tag configuration */
12499 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12500         TOKEN_STRING_INITIALIZER
12501                 (struct cmd_config_e_tag_result,
12502                  e_tag, "E-tag");
12503 cmdline_parse_token_string_t cmd_config_e_tag_set =
12504         TOKEN_STRING_INITIALIZER
12505                 (struct cmd_config_e_tag_result,
12506                  set, "set");
12507 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12508         TOKEN_STRING_INITIALIZER
12509                 (struct cmd_config_e_tag_result,
12510                  insertion, "insertion");
12511 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12512         TOKEN_STRING_INITIALIZER
12513                 (struct cmd_config_e_tag_result,
12514                  stripping, "stripping");
12515 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12516         TOKEN_STRING_INITIALIZER
12517                 (struct cmd_config_e_tag_result,
12518                  forwarding, "forwarding");
12519 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12520         TOKEN_STRING_INITIALIZER
12521                 (struct cmd_config_e_tag_result,
12522                  filter, "filter");
12523 cmdline_parse_token_string_t cmd_config_e_tag_add =
12524         TOKEN_STRING_INITIALIZER
12525                 (struct cmd_config_e_tag_result,
12526                  add, "add");
12527 cmdline_parse_token_string_t cmd_config_e_tag_del =
12528         TOKEN_STRING_INITIALIZER
12529                 (struct cmd_config_e_tag_result,
12530                  del, "del");
12531 cmdline_parse_token_string_t cmd_config_e_tag_on =
12532         TOKEN_STRING_INITIALIZER
12533                 (struct cmd_config_e_tag_result,
12534                  on, "on");
12535 cmdline_parse_token_string_t cmd_config_e_tag_off =
12536         TOKEN_STRING_INITIALIZER
12537                 (struct cmd_config_e_tag_result,
12538                  off, "off");
12539 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12540         TOKEN_STRING_INITIALIZER
12541                 (struct cmd_config_e_tag_result,
12542                  on_off, "on#off");
12543 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12544         TOKEN_STRING_INITIALIZER
12545                 (struct cmd_config_e_tag_result,
12546                  port_tag_id, "port-tag-id");
12547 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12548         TOKEN_NUM_INITIALIZER
12549                 (struct cmd_config_e_tag_result,
12550                  port_tag_id_val, UINT32);
12551 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12552         TOKEN_STRING_INITIALIZER
12553                 (struct cmd_config_e_tag_result,
12554                  e_tag_id, "e-tag-id");
12555 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12556         TOKEN_NUM_INITIALIZER
12557                 (struct cmd_config_e_tag_result,
12558                  e_tag_id_val, UINT16);
12559 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12560         TOKEN_STRING_INITIALIZER
12561                 (struct cmd_config_e_tag_result,
12562                  dst_pool, "dst-pool");
12563 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12564         TOKEN_NUM_INITIALIZER
12565                 (struct cmd_config_e_tag_result,
12566                  dst_pool_val, UINT8);
12567 cmdline_parse_token_string_t cmd_config_e_tag_port =
12568         TOKEN_STRING_INITIALIZER
12569                 (struct cmd_config_e_tag_result,
12570                  port, "port");
12571 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12572         TOKEN_NUM_INITIALIZER
12573                 (struct cmd_config_e_tag_result,
12574                  port_id, UINT16);
12575 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12576         TOKEN_STRING_INITIALIZER
12577                 (struct cmd_config_e_tag_result,
12578                  vf, "vf");
12579 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12580         TOKEN_NUM_INITIALIZER
12581                 (struct cmd_config_e_tag_result,
12582                  vf_id, UINT8);
12583
12584 /* E-tag insertion configuration */
12585 static void
12586 cmd_config_e_tag_insertion_en_parsed(
12587         void *parsed_result,
12588         __attribute__((unused)) struct cmdline *cl,
12589         __attribute__((unused)) void *data)
12590 {
12591         struct cmd_config_e_tag_result *res =
12592                 parsed_result;
12593         struct rte_eth_l2_tunnel_conf entry;
12594
12595         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12596                 return;
12597
12598         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12599         entry.tunnel_id = res->port_tag_id_val;
12600         entry.vf_id = res->vf_id;
12601         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12602                                           &entry,
12603                                           ETH_L2_TUNNEL_INSERTION_MASK,
12604                                           1);
12605 }
12606
12607 static void
12608 cmd_config_e_tag_insertion_dis_parsed(
12609         void *parsed_result,
12610         __attribute__((unused)) struct cmdline *cl,
12611         __attribute__((unused)) void *data)
12612 {
12613         struct cmd_config_e_tag_result *res =
12614                 parsed_result;
12615         struct rte_eth_l2_tunnel_conf entry;
12616
12617         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12618                 return;
12619
12620         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12621         entry.vf_id = res->vf_id;
12622
12623         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12624                                           &entry,
12625                                           ETH_L2_TUNNEL_INSERTION_MASK,
12626                                           0);
12627 }
12628
12629 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12630         .f = cmd_config_e_tag_insertion_en_parsed,
12631         .data = NULL,
12632         .help_str = "E-tag ... : E-tag insertion enable",
12633         .tokens = {
12634                 (void *)&cmd_config_e_tag_e_tag,
12635                 (void *)&cmd_config_e_tag_set,
12636                 (void *)&cmd_config_e_tag_insertion,
12637                 (void *)&cmd_config_e_tag_on,
12638                 (void *)&cmd_config_e_tag_port_tag_id,
12639                 (void *)&cmd_config_e_tag_port_tag_id_val,
12640                 (void *)&cmd_config_e_tag_port,
12641                 (void *)&cmd_config_e_tag_port_id,
12642                 (void *)&cmd_config_e_tag_vf,
12643                 (void *)&cmd_config_e_tag_vf_id,
12644                 NULL,
12645         },
12646 };
12647
12648 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12649         .f = cmd_config_e_tag_insertion_dis_parsed,
12650         .data = NULL,
12651         .help_str = "E-tag ... : E-tag insertion disable",
12652         .tokens = {
12653                 (void *)&cmd_config_e_tag_e_tag,
12654                 (void *)&cmd_config_e_tag_set,
12655                 (void *)&cmd_config_e_tag_insertion,
12656                 (void *)&cmd_config_e_tag_off,
12657                 (void *)&cmd_config_e_tag_port,
12658                 (void *)&cmd_config_e_tag_port_id,
12659                 (void *)&cmd_config_e_tag_vf,
12660                 (void *)&cmd_config_e_tag_vf_id,
12661                 NULL,
12662         },
12663 };
12664
12665 /* E-tag stripping configuration */
12666 static void
12667 cmd_config_e_tag_stripping_parsed(
12668         void *parsed_result,
12669         __attribute__((unused)) struct cmdline *cl,
12670         __attribute__((unused)) void *data)
12671 {
12672         struct cmd_config_e_tag_result *res =
12673                 parsed_result;
12674         struct rte_eth_l2_tunnel_conf entry;
12675
12676         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12677                 return;
12678
12679         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12680
12681         if (!strcmp(res->on_off, "on"))
12682                 rte_eth_dev_l2_tunnel_offload_set
12683                         (res->port_id,
12684                          &entry,
12685                          ETH_L2_TUNNEL_STRIPPING_MASK,
12686                          1);
12687         else
12688                 rte_eth_dev_l2_tunnel_offload_set
12689                         (res->port_id,
12690                          &entry,
12691                          ETH_L2_TUNNEL_STRIPPING_MASK,
12692                          0);
12693 }
12694
12695 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12696         .f = cmd_config_e_tag_stripping_parsed,
12697         .data = NULL,
12698         .help_str = "E-tag ... : E-tag stripping enable/disable",
12699         .tokens = {
12700                 (void *)&cmd_config_e_tag_e_tag,
12701                 (void *)&cmd_config_e_tag_set,
12702                 (void *)&cmd_config_e_tag_stripping,
12703                 (void *)&cmd_config_e_tag_on_off,
12704                 (void *)&cmd_config_e_tag_port,
12705                 (void *)&cmd_config_e_tag_port_id,
12706                 NULL,
12707         },
12708 };
12709
12710 /* E-tag forwarding configuration */
12711 static void
12712 cmd_config_e_tag_forwarding_parsed(
12713         void *parsed_result,
12714         __attribute__((unused)) struct cmdline *cl,
12715         __attribute__((unused)) void *data)
12716 {
12717         struct cmd_config_e_tag_result *res = parsed_result;
12718         struct rte_eth_l2_tunnel_conf entry;
12719
12720         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12721                 return;
12722
12723         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12724
12725         if (!strcmp(res->on_off, "on"))
12726                 rte_eth_dev_l2_tunnel_offload_set
12727                         (res->port_id,
12728                          &entry,
12729                          ETH_L2_TUNNEL_FORWARDING_MASK,
12730                          1);
12731         else
12732                 rte_eth_dev_l2_tunnel_offload_set
12733                         (res->port_id,
12734                          &entry,
12735                          ETH_L2_TUNNEL_FORWARDING_MASK,
12736                          0);
12737 }
12738
12739 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12740         .f = cmd_config_e_tag_forwarding_parsed,
12741         .data = NULL,
12742         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12743         .tokens = {
12744                 (void *)&cmd_config_e_tag_e_tag,
12745                 (void *)&cmd_config_e_tag_set,
12746                 (void *)&cmd_config_e_tag_forwarding,
12747                 (void *)&cmd_config_e_tag_on_off,
12748                 (void *)&cmd_config_e_tag_port,
12749                 (void *)&cmd_config_e_tag_port_id,
12750                 NULL,
12751         },
12752 };
12753
12754 /* E-tag filter configuration */
12755 static void
12756 cmd_config_e_tag_filter_add_parsed(
12757         void *parsed_result,
12758         __attribute__((unused)) struct cmdline *cl,
12759         __attribute__((unused)) void *data)
12760 {
12761         struct cmd_config_e_tag_result *res = parsed_result;
12762         struct rte_eth_l2_tunnel_conf entry;
12763         int ret = 0;
12764
12765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12766                 return;
12767
12768         if (res->e_tag_id_val > 0x3fff) {
12769                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12770                 return;
12771         }
12772
12773         ret = rte_eth_dev_filter_supported(res->port_id,
12774                                            RTE_ETH_FILTER_L2_TUNNEL);
12775         if (ret < 0) {
12776                 printf("E-tag filter is not supported on port %u.\n",
12777                        res->port_id);
12778                 return;
12779         }
12780
12781         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12782         entry.tunnel_id = res->e_tag_id_val;
12783         entry.pool = res->dst_pool_val;
12784
12785         ret = rte_eth_dev_filter_ctrl(res->port_id,
12786                                       RTE_ETH_FILTER_L2_TUNNEL,
12787                                       RTE_ETH_FILTER_ADD,
12788                                       &entry);
12789         if (ret < 0)
12790                 printf("E-tag filter programming error: (%s)\n",
12791                        strerror(-ret));
12792 }
12793
12794 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12795         .f = cmd_config_e_tag_filter_add_parsed,
12796         .data = NULL,
12797         .help_str = "E-tag ... : E-tag filter add",
12798         .tokens = {
12799                 (void *)&cmd_config_e_tag_e_tag,
12800                 (void *)&cmd_config_e_tag_set,
12801                 (void *)&cmd_config_e_tag_filter,
12802                 (void *)&cmd_config_e_tag_add,
12803                 (void *)&cmd_config_e_tag_e_tag_id,
12804                 (void *)&cmd_config_e_tag_e_tag_id_val,
12805                 (void *)&cmd_config_e_tag_dst_pool,
12806                 (void *)&cmd_config_e_tag_dst_pool_val,
12807                 (void *)&cmd_config_e_tag_port,
12808                 (void *)&cmd_config_e_tag_port_id,
12809                 NULL,
12810         },
12811 };
12812
12813 static void
12814 cmd_config_e_tag_filter_del_parsed(
12815         void *parsed_result,
12816         __attribute__((unused)) struct cmdline *cl,
12817         __attribute__((unused)) void *data)
12818 {
12819         struct cmd_config_e_tag_result *res = parsed_result;
12820         struct rte_eth_l2_tunnel_conf entry;
12821         int ret = 0;
12822
12823         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12824                 return;
12825
12826         if (res->e_tag_id_val > 0x3fff) {
12827                 printf("e-tag-id must be less than 0x3fff.\n");
12828                 return;
12829         }
12830
12831         ret = rte_eth_dev_filter_supported(res->port_id,
12832                                            RTE_ETH_FILTER_L2_TUNNEL);
12833         if (ret < 0) {
12834                 printf("E-tag filter is not supported on port %u.\n",
12835                        res->port_id);
12836                 return;
12837         }
12838
12839         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12840         entry.tunnel_id = res->e_tag_id_val;
12841
12842         ret = rte_eth_dev_filter_ctrl(res->port_id,
12843                                       RTE_ETH_FILTER_L2_TUNNEL,
12844                                       RTE_ETH_FILTER_DELETE,
12845                                       &entry);
12846         if (ret < 0)
12847                 printf("E-tag filter programming error: (%s)\n",
12848                        strerror(-ret));
12849 }
12850
12851 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12852         .f = cmd_config_e_tag_filter_del_parsed,
12853         .data = NULL,
12854         .help_str = "E-tag ... : E-tag filter delete",
12855         .tokens = {
12856                 (void *)&cmd_config_e_tag_e_tag,
12857                 (void *)&cmd_config_e_tag_set,
12858                 (void *)&cmd_config_e_tag_filter,
12859                 (void *)&cmd_config_e_tag_del,
12860                 (void *)&cmd_config_e_tag_e_tag_id,
12861                 (void *)&cmd_config_e_tag_e_tag_id_val,
12862                 (void *)&cmd_config_e_tag_port,
12863                 (void *)&cmd_config_e_tag_port_id,
12864                 NULL,
12865         },
12866 };
12867
12868 /* vf vlan anti spoof configuration */
12869
12870 /* Common result structure for vf vlan anti spoof */
12871 struct cmd_vf_vlan_anti_spoof_result {
12872         cmdline_fixed_string_t set;
12873         cmdline_fixed_string_t vf;
12874         cmdline_fixed_string_t vlan;
12875         cmdline_fixed_string_t antispoof;
12876         portid_t port_id;
12877         uint32_t vf_id;
12878         cmdline_fixed_string_t on_off;
12879 };
12880
12881 /* Common CLI fields for vf vlan anti spoof enable disable */
12882 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12883         TOKEN_STRING_INITIALIZER
12884                 (struct cmd_vf_vlan_anti_spoof_result,
12885                  set, "set");
12886 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12887         TOKEN_STRING_INITIALIZER
12888                 (struct cmd_vf_vlan_anti_spoof_result,
12889                  vf, "vf");
12890 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12891         TOKEN_STRING_INITIALIZER
12892                 (struct cmd_vf_vlan_anti_spoof_result,
12893                  vlan, "vlan");
12894 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12895         TOKEN_STRING_INITIALIZER
12896                 (struct cmd_vf_vlan_anti_spoof_result,
12897                  antispoof, "antispoof");
12898 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12899         TOKEN_NUM_INITIALIZER
12900                 (struct cmd_vf_vlan_anti_spoof_result,
12901                  port_id, UINT16);
12902 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12903         TOKEN_NUM_INITIALIZER
12904                 (struct cmd_vf_vlan_anti_spoof_result,
12905                  vf_id, UINT32);
12906 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12907         TOKEN_STRING_INITIALIZER
12908                 (struct cmd_vf_vlan_anti_spoof_result,
12909                  on_off, "on#off");
12910
12911 static void
12912 cmd_set_vf_vlan_anti_spoof_parsed(
12913         void *parsed_result,
12914         __attribute__((unused)) struct cmdline *cl,
12915         __attribute__((unused)) void *data)
12916 {
12917         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12918         int ret = -ENOTSUP;
12919
12920         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12921
12922         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12923                 return;
12924
12925 #ifdef RTE_LIBRTE_IXGBE_PMD
12926         if (ret == -ENOTSUP)
12927                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12928                                 res->vf_id, is_on);
12929 #endif
12930 #ifdef RTE_LIBRTE_I40E_PMD
12931         if (ret == -ENOTSUP)
12932                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12933                                 res->vf_id, is_on);
12934 #endif
12935 #ifdef RTE_LIBRTE_BNXT_PMD
12936         if (ret == -ENOTSUP)
12937                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12938                                 res->vf_id, is_on);
12939 #endif
12940
12941         switch (ret) {
12942         case 0:
12943                 break;
12944         case -EINVAL:
12945                 printf("invalid vf_id %d\n", res->vf_id);
12946                 break;
12947         case -ENODEV:
12948                 printf("invalid port_id %d\n", res->port_id);
12949                 break;
12950         case -ENOTSUP:
12951                 printf("function not implemented\n");
12952                 break;
12953         default:
12954                 printf("programming error: (%s)\n", strerror(-ret));
12955         }
12956 }
12957
12958 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12959         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12960         .data = NULL,
12961         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12962         .tokens = {
12963                 (void *)&cmd_vf_vlan_anti_spoof_set,
12964                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12965                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12966                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12967                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12968                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12969                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12970                 NULL,
12971         },
12972 };
12973
12974 /* vf mac anti spoof configuration */
12975
12976 /* Common result structure for vf mac anti spoof */
12977 struct cmd_vf_mac_anti_spoof_result {
12978         cmdline_fixed_string_t set;
12979         cmdline_fixed_string_t vf;
12980         cmdline_fixed_string_t mac;
12981         cmdline_fixed_string_t antispoof;
12982         portid_t port_id;
12983         uint32_t vf_id;
12984         cmdline_fixed_string_t on_off;
12985 };
12986
12987 /* Common CLI fields for vf mac anti spoof enable disable */
12988 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12989         TOKEN_STRING_INITIALIZER
12990                 (struct cmd_vf_mac_anti_spoof_result,
12991                  set, "set");
12992 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12993         TOKEN_STRING_INITIALIZER
12994                 (struct cmd_vf_mac_anti_spoof_result,
12995                  vf, "vf");
12996 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12997         TOKEN_STRING_INITIALIZER
12998                 (struct cmd_vf_mac_anti_spoof_result,
12999                  mac, "mac");
13000 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13001         TOKEN_STRING_INITIALIZER
13002                 (struct cmd_vf_mac_anti_spoof_result,
13003                  antispoof, "antispoof");
13004 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13005         TOKEN_NUM_INITIALIZER
13006                 (struct cmd_vf_mac_anti_spoof_result,
13007                  port_id, UINT16);
13008 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13009         TOKEN_NUM_INITIALIZER
13010                 (struct cmd_vf_mac_anti_spoof_result,
13011                  vf_id, UINT32);
13012 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13013         TOKEN_STRING_INITIALIZER
13014                 (struct cmd_vf_mac_anti_spoof_result,
13015                  on_off, "on#off");
13016
13017 static void
13018 cmd_set_vf_mac_anti_spoof_parsed(
13019         void *parsed_result,
13020         __attribute__((unused)) struct cmdline *cl,
13021         __attribute__((unused)) void *data)
13022 {
13023         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13024         int ret = -ENOTSUP;
13025
13026         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13027
13028         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13029                 return;
13030
13031 #ifdef RTE_LIBRTE_IXGBE_PMD
13032         if (ret == -ENOTSUP)
13033                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13034                         res->vf_id, is_on);
13035 #endif
13036 #ifdef RTE_LIBRTE_I40E_PMD
13037         if (ret == -ENOTSUP)
13038                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13039                         res->vf_id, is_on);
13040 #endif
13041 #ifdef RTE_LIBRTE_BNXT_PMD
13042         if (ret == -ENOTSUP)
13043                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13044                         res->vf_id, is_on);
13045 #endif
13046
13047         switch (ret) {
13048         case 0:
13049                 break;
13050         case -EINVAL:
13051                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13052                 break;
13053         case -ENODEV:
13054                 printf("invalid port_id %d\n", res->port_id);
13055                 break;
13056         case -ENOTSUP:
13057                 printf("function not implemented\n");
13058                 break;
13059         default:
13060                 printf("programming error: (%s)\n", strerror(-ret));
13061         }
13062 }
13063
13064 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13065         .f = cmd_set_vf_mac_anti_spoof_parsed,
13066         .data = NULL,
13067         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13068         .tokens = {
13069                 (void *)&cmd_vf_mac_anti_spoof_set,
13070                 (void *)&cmd_vf_mac_anti_spoof_vf,
13071                 (void *)&cmd_vf_mac_anti_spoof_mac,
13072                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13073                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13074                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13075                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13076                 NULL,
13077         },
13078 };
13079
13080 /* vf vlan strip queue configuration */
13081
13082 /* Common result structure for vf mac anti spoof */
13083 struct cmd_vf_vlan_stripq_result {
13084         cmdline_fixed_string_t set;
13085         cmdline_fixed_string_t vf;
13086         cmdline_fixed_string_t vlan;
13087         cmdline_fixed_string_t stripq;
13088         portid_t port_id;
13089         uint16_t vf_id;
13090         cmdline_fixed_string_t on_off;
13091 };
13092
13093 /* Common CLI fields for vf vlan strip enable disable */
13094 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13095         TOKEN_STRING_INITIALIZER
13096                 (struct cmd_vf_vlan_stripq_result,
13097                  set, "set");
13098 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13099         TOKEN_STRING_INITIALIZER
13100                 (struct cmd_vf_vlan_stripq_result,
13101                  vf, "vf");
13102 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13103         TOKEN_STRING_INITIALIZER
13104                 (struct cmd_vf_vlan_stripq_result,
13105                  vlan, "vlan");
13106 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13107         TOKEN_STRING_INITIALIZER
13108                 (struct cmd_vf_vlan_stripq_result,
13109                  stripq, "stripq");
13110 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13111         TOKEN_NUM_INITIALIZER
13112                 (struct cmd_vf_vlan_stripq_result,
13113                  port_id, UINT16);
13114 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13115         TOKEN_NUM_INITIALIZER
13116                 (struct cmd_vf_vlan_stripq_result,
13117                  vf_id, UINT16);
13118 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13119         TOKEN_STRING_INITIALIZER
13120                 (struct cmd_vf_vlan_stripq_result,
13121                  on_off, "on#off");
13122
13123 static void
13124 cmd_set_vf_vlan_stripq_parsed(
13125         void *parsed_result,
13126         __attribute__((unused)) struct cmdline *cl,
13127         __attribute__((unused)) void *data)
13128 {
13129         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13130         int ret = -ENOTSUP;
13131
13132         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13133
13134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13135                 return;
13136
13137 #ifdef RTE_LIBRTE_IXGBE_PMD
13138         if (ret == -ENOTSUP)
13139                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13140                         res->vf_id, is_on);
13141 #endif
13142 #ifdef RTE_LIBRTE_I40E_PMD
13143         if (ret == -ENOTSUP)
13144                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13145                         res->vf_id, is_on);
13146 #endif
13147 #ifdef RTE_LIBRTE_BNXT_PMD
13148         if (ret == -ENOTSUP)
13149                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13150                         res->vf_id, is_on);
13151 #endif
13152
13153         switch (ret) {
13154         case 0:
13155                 break;
13156         case -EINVAL:
13157                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13158                 break;
13159         case -ENODEV:
13160                 printf("invalid port_id %d\n", res->port_id);
13161                 break;
13162         case -ENOTSUP:
13163                 printf("function not implemented\n");
13164                 break;
13165         default:
13166                 printf("programming error: (%s)\n", strerror(-ret));
13167         }
13168 }
13169
13170 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13171         .f = cmd_set_vf_vlan_stripq_parsed,
13172         .data = NULL,
13173         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13174         .tokens = {
13175                 (void *)&cmd_vf_vlan_stripq_set,
13176                 (void *)&cmd_vf_vlan_stripq_vf,
13177                 (void *)&cmd_vf_vlan_stripq_vlan,
13178                 (void *)&cmd_vf_vlan_stripq_stripq,
13179                 (void *)&cmd_vf_vlan_stripq_port_id,
13180                 (void *)&cmd_vf_vlan_stripq_vf_id,
13181                 (void *)&cmd_vf_vlan_stripq_on_off,
13182                 NULL,
13183         },
13184 };
13185
13186 /* vf vlan insert configuration */
13187
13188 /* Common result structure for vf vlan insert */
13189 struct cmd_vf_vlan_insert_result {
13190         cmdline_fixed_string_t set;
13191         cmdline_fixed_string_t vf;
13192         cmdline_fixed_string_t vlan;
13193         cmdline_fixed_string_t insert;
13194         portid_t port_id;
13195         uint16_t vf_id;
13196         uint16_t vlan_id;
13197 };
13198
13199 /* Common CLI fields for vf vlan insert enable disable */
13200 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13201         TOKEN_STRING_INITIALIZER
13202                 (struct cmd_vf_vlan_insert_result,
13203                  set, "set");
13204 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13205         TOKEN_STRING_INITIALIZER
13206                 (struct cmd_vf_vlan_insert_result,
13207                  vf, "vf");
13208 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13209         TOKEN_STRING_INITIALIZER
13210                 (struct cmd_vf_vlan_insert_result,
13211                  vlan, "vlan");
13212 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13213         TOKEN_STRING_INITIALIZER
13214                 (struct cmd_vf_vlan_insert_result,
13215                  insert, "insert");
13216 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13217         TOKEN_NUM_INITIALIZER
13218                 (struct cmd_vf_vlan_insert_result,
13219                  port_id, UINT16);
13220 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13221         TOKEN_NUM_INITIALIZER
13222                 (struct cmd_vf_vlan_insert_result,
13223                  vf_id, UINT16);
13224 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13225         TOKEN_NUM_INITIALIZER
13226                 (struct cmd_vf_vlan_insert_result,
13227                  vlan_id, UINT16);
13228
13229 static void
13230 cmd_set_vf_vlan_insert_parsed(
13231         void *parsed_result,
13232         __attribute__((unused)) struct cmdline *cl,
13233         __attribute__((unused)) void *data)
13234 {
13235         struct cmd_vf_vlan_insert_result *res = parsed_result;
13236         int ret = -ENOTSUP;
13237
13238         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13239                 return;
13240
13241 #ifdef RTE_LIBRTE_IXGBE_PMD
13242         if (ret == -ENOTSUP)
13243                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13244                         res->vlan_id);
13245 #endif
13246 #ifdef RTE_LIBRTE_I40E_PMD
13247         if (ret == -ENOTSUP)
13248                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13249                         res->vlan_id);
13250 #endif
13251 #ifdef RTE_LIBRTE_BNXT_PMD
13252         if (ret == -ENOTSUP)
13253                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13254                         res->vlan_id);
13255 #endif
13256
13257         switch (ret) {
13258         case 0:
13259                 break;
13260         case -EINVAL:
13261                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13262                 break;
13263         case -ENODEV:
13264                 printf("invalid port_id %d\n", res->port_id);
13265                 break;
13266         case -ENOTSUP:
13267                 printf("function not implemented\n");
13268                 break;
13269         default:
13270                 printf("programming error: (%s)\n", strerror(-ret));
13271         }
13272 }
13273
13274 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13275         .f = cmd_set_vf_vlan_insert_parsed,
13276         .data = NULL,
13277         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13278         .tokens = {
13279                 (void *)&cmd_vf_vlan_insert_set,
13280                 (void *)&cmd_vf_vlan_insert_vf,
13281                 (void *)&cmd_vf_vlan_insert_vlan,
13282                 (void *)&cmd_vf_vlan_insert_insert,
13283                 (void *)&cmd_vf_vlan_insert_port_id,
13284                 (void *)&cmd_vf_vlan_insert_vf_id,
13285                 (void *)&cmd_vf_vlan_insert_vlan_id,
13286                 NULL,
13287         },
13288 };
13289
13290 /* tx loopback configuration */
13291
13292 /* Common result structure for tx loopback */
13293 struct cmd_tx_loopback_result {
13294         cmdline_fixed_string_t set;
13295         cmdline_fixed_string_t tx;
13296         cmdline_fixed_string_t loopback;
13297         portid_t port_id;
13298         cmdline_fixed_string_t on_off;
13299 };
13300
13301 /* Common CLI fields for tx loopback enable disable */
13302 cmdline_parse_token_string_t cmd_tx_loopback_set =
13303         TOKEN_STRING_INITIALIZER
13304                 (struct cmd_tx_loopback_result,
13305                  set, "set");
13306 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13307         TOKEN_STRING_INITIALIZER
13308                 (struct cmd_tx_loopback_result,
13309                  tx, "tx");
13310 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13311         TOKEN_STRING_INITIALIZER
13312                 (struct cmd_tx_loopback_result,
13313                  loopback, "loopback");
13314 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13315         TOKEN_NUM_INITIALIZER
13316                 (struct cmd_tx_loopback_result,
13317                  port_id, UINT16);
13318 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13319         TOKEN_STRING_INITIALIZER
13320                 (struct cmd_tx_loopback_result,
13321                  on_off, "on#off");
13322
13323 static void
13324 cmd_set_tx_loopback_parsed(
13325         void *parsed_result,
13326         __attribute__((unused)) struct cmdline *cl,
13327         __attribute__((unused)) void *data)
13328 {
13329         struct cmd_tx_loopback_result *res = parsed_result;
13330         int ret = -ENOTSUP;
13331
13332         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13333
13334         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13335                 return;
13336
13337 #ifdef RTE_LIBRTE_IXGBE_PMD
13338         if (ret == -ENOTSUP)
13339                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13340 #endif
13341 #ifdef RTE_LIBRTE_I40E_PMD
13342         if (ret == -ENOTSUP)
13343                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13344 #endif
13345 #ifdef RTE_LIBRTE_BNXT_PMD
13346         if (ret == -ENOTSUP)
13347                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13348 #endif
13349 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13350         if (ret == -ENOTSUP)
13351                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13352 #endif
13353
13354         switch (ret) {
13355         case 0:
13356                 break;
13357         case -EINVAL:
13358                 printf("invalid is_on %d\n", is_on);
13359                 break;
13360         case -ENODEV:
13361                 printf("invalid port_id %d\n", res->port_id);
13362                 break;
13363         case -ENOTSUP:
13364                 printf("function not implemented\n");
13365                 break;
13366         default:
13367                 printf("programming error: (%s)\n", strerror(-ret));
13368         }
13369 }
13370
13371 cmdline_parse_inst_t cmd_set_tx_loopback = {
13372         .f = cmd_set_tx_loopback_parsed,
13373         .data = NULL,
13374         .help_str = "set tx loopback <port_id> on|off",
13375         .tokens = {
13376                 (void *)&cmd_tx_loopback_set,
13377                 (void *)&cmd_tx_loopback_tx,
13378                 (void *)&cmd_tx_loopback_loopback,
13379                 (void *)&cmd_tx_loopback_port_id,
13380                 (void *)&cmd_tx_loopback_on_off,
13381                 NULL,
13382         },
13383 };
13384
13385 /* all queues drop enable configuration */
13386
13387 /* Common result structure for all queues drop enable */
13388 struct cmd_all_queues_drop_en_result {
13389         cmdline_fixed_string_t set;
13390         cmdline_fixed_string_t all;
13391         cmdline_fixed_string_t queues;
13392         cmdline_fixed_string_t drop;
13393         portid_t port_id;
13394         cmdline_fixed_string_t on_off;
13395 };
13396
13397 /* Common CLI fields for tx loopback enable disable */
13398 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13399         TOKEN_STRING_INITIALIZER
13400                 (struct cmd_all_queues_drop_en_result,
13401                  set, "set");
13402 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13403         TOKEN_STRING_INITIALIZER
13404                 (struct cmd_all_queues_drop_en_result,
13405                  all, "all");
13406 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13407         TOKEN_STRING_INITIALIZER
13408                 (struct cmd_all_queues_drop_en_result,
13409                  queues, "queues");
13410 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13411         TOKEN_STRING_INITIALIZER
13412                 (struct cmd_all_queues_drop_en_result,
13413                  drop, "drop");
13414 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13415         TOKEN_NUM_INITIALIZER
13416                 (struct cmd_all_queues_drop_en_result,
13417                  port_id, UINT16);
13418 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13419         TOKEN_STRING_INITIALIZER
13420                 (struct cmd_all_queues_drop_en_result,
13421                  on_off, "on#off");
13422
13423 static void
13424 cmd_set_all_queues_drop_en_parsed(
13425         void *parsed_result,
13426         __attribute__((unused)) struct cmdline *cl,
13427         __attribute__((unused)) void *data)
13428 {
13429         struct cmd_all_queues_drop_en_result *res = parsed_result;
13430         int ret = -ENOTSUP;
13431         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13432
13433         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13434                 return;
13435
13436 #ifdef RTE_LIBRTE_IXGBE_PMD
13437         if (ret == -ENOTSUP)
13438                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13439 #endif
13440 #ifdef RTE_LIBRTE_BNXT_PMD
13441         if (ret == -ENOTSUP)
13442                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13443 #endif
13444         switch (ret) {
13445         case 0:
13446                 break;
13447         case -EINVAL:
13448                 printf("invalid is_on %d\n", is_on);
13449                 break;
13450         case -ENODEV:
13451                 printf("invalid port_id %d\n", res->port_id);
13452                 break;
13453         case -ENOTSUP:
13454                 printf("function not implemented\n");
13455                 break;
13456         default:
13457                 printf("programming error: (%s)\n", strerror(-ret));
13458         }
13459 }
13460
13461 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13462         .f = cmd_set_all_queues_drop_en_parsed,
13463         .data = NULL,
13464         .help_str = "set all queues drop <port_id> on|off",
13465         .tokens = {
13466                 (void *)&cmd_all_queues_drop_en_set,
13467                 (void *)&cmd_all_queues_drop_en_all,
13468                 (void *)&cmd_all_queues_drop_en_queues,
13469                 (void *)&cmd_all_queues_drop_en_drop,
13470                 (void *)&cmd_all_queues_drop_en_port_id,
13471                 (void *)&cmd_all_queues_drop_en_on_off,
13472                 NULL,
13473         },
13474 };
13475
13476 /* vf split drop enable configuration */
13477
13478 /* Common result structure for vf split drop enable */
13479 struct cmd_vf_split_drop_en_result {
13480         cmdline_fixed_string_t set;
13481         cmdline_fixed_string_t vf;
13482         cmdline_fixed_string_t split;
13483         cmdline_fixed_string_t drop;
13484         portid_t port_id;
13485         uint16_t vf_id;
13486         cmdline_fixed_string_t on_off;
13487 };
13488
13489 /* Common CLI fields for vf split drop enable disable */
13490 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13491         TOKEN_STRING_INITIALIZER
13492                 (struct cmd_vf_split_drop_en_result,
13493                  set, "set");
13494 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13495         TOKEN_STRING_INITIALIZER
13496                 (struct cmd_vf_split_drop_en_result,
13497                  vf, "vf");
13498 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13499         TOKEN_STRING_INITIALIZER
13500                 (struct cmd_vf_split_drop_en_result,
13501                  split, "split");
13502 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13503         TOKEN_STRING_INITIALIZER
13504                 (struct cmd_vf_split_drop_en_result,
13505                  drop, "drop");
13506 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13507         TOKEN_NUM_INITIALIZER
13508                 (struct cmd_vf_split_drop_en_result,
13509                  port_id, UINT16);
13510 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13511         TOKEN_NUM_INITIALIZER
13512                 (struct cmd_vf_split_drop_en_result,
13513                  vf_id, UINT16);
13514 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13515         TOKEN_STRING_INITIALIZER
13516                 (struct cmd_vf_split_drop_en_result,
13517                  on_off, "on#off");
13518
13519 static void
13520 cmd_set_vf_split_drop_en_parsed(
13521         void *parsed_result,
13522         __attribute__((unused)) struct cmdline *cl,
13523         __attribute__((unused)) void *data)
13524 {
13525         struct cmd_vf_split_drop_en_result *res = parsed_result;
13526         int ret = -ENOTSUP;
13527         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13528
13529         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13530                 return;
13531
13532 #ifdef RTE_LIBRTE_IXGBE_PMD
13533         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13534                         is_on);
13535 #endif
13536         switch (ret) {
13537         case 0:
13538                 break;
13539         case -EINVAL:
13540                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13541                 break;
13542         case -ENODEV:
13543                 printf("invalid port_id %d\n", res->port_id);
13544                 break;
13545         case -ENOTSUP:
13546                 printf("not supported on port %d\n", res->port_id);
13547                 break;
13548         default:
13549                 printf("programming error: (%s)\n", strerror(-ret));
13550         }
13551 }
13552
13553 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13554         .f = cmd_set_vf_split_drop_en_parsed,
13555         .data = NULL,
13556         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13557         .tokens = {
13558                 (void *)&cmd_vf_split_drop_en_set,
13559                 (void *)&cmd_vf_split_drop_en_vf,
13560                 (void *)&cmd_vf_split_drop_en_split,
13561                 (void *)&cmd_vf_split_drop_en_drop,
13562                 (void *)&cmd_vf_split_drop_en_port_id,
13563                 (void *)&cmd_vf_split_drop_en_vf_id,
13564                 (void *)&cmd_vf_split_drop_en_on_off,
13565                 NULL,
13566         },
13567 };
13568
13569 /* vf mac address configuration */
13570
13571 /* Common result structure for vf mac address */
13572 struct cmd_set_vf_mac_addr_result {
13573         cmdline_fixed_string_t set;
13574         cmdline_fixed_string_t vf;
13575         cmdline_fixed_string_t mac;
13576         cmdline_fixed_string_t addr;
13577         portid_t port_id;
13578         uint16_t vf_id;
13579         struct ether_addr mac_addr;
13580
13581 };
13582
13583 /* Common CLI fields for vf split drop enable disable */
13584 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13585         TOKEN_STRING_INITIALIZER
13586                 (struct cmd_set_vf_mac_addr_result,
13587                  set, "set");
13588 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13589         TOKEN_STRING_INITIALIZER
13590                 (struct cmd_set_vf_mac_addr_result,
13591                  vf, "vf");
13592 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13593         TOKEN_STRING_INITIALIZER
13594                 (struct cmd_set_vf_mac_addr_result,
13595                  mac, "mac");
13596 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13597         TOKEN_STRING_INITIALIZER
13598                 (struct cmd_set_vf_mac_addr_result,
13599                  addr, "addr");
13600 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13601         TOKEN_NUM_INITIALIZER
13602                 (struct cmd_set_vf_mac_addr_result,
13603                  port_id, UINT16);
13604 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13605         TOKEN_NUM_INITIALIZER
13606                 (struct cmd_set_vf_mac_addr_result,
13607                  vf_id, UINT16);
13608 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13609         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13610                  mac_addr);
13611
13612 static void
13613 cmd_set_vf_mac_addr_parsed(
13614         void *parsed_result,
13615         __attribute__((unused)) struct cmdline *cl,
13616         __attribute__((unused)) void *data)
13617 {
13618         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13619         int ret = -ENOTSUP;
13620
13621         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13622                 return;
13623
13624 #ifdef RTE_LIBRTE_IXGBE_PMD
13625         if (ret == -ENOTSUP)
13626                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13627                                 &res->mac_addr);
13628 #endif
13629 #ifdef RTE_LIBRTE_I40E_PMD
13630         if (ret == -ENOTSUP)
13631                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13632                                 &res->mac_addr);
13633 #endif
13634 #ifdef RTE_LIBRTE_BNXT_PMD
13635         if (ret == -ENOTSUP)
13636                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13637                                 &res->mac_addr);
13638 #endif
13639
13640         switch (ret) {
13641         case 0:
13642                 break;
13643         case -EINVAL:
13644                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13645                 break;
13646         case -ENODEV:
13647                 printf("invalid port_id %d\n", res->port_id);
13648                 break;
13649         case -ENOTSUP:
13650                 printf("function not implemented\n");
13651                 break;
13652         default:
13653                 printf("programming error: (%s)\n", strerror(-ret));
13654         }
13655 }
13656
13657 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13658         .f = cmd_set_vf_mac_addr_parsed,
13659         .data = NULL,
13660         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13661         .tokens = {
13662                 (void *)&cmd_set_vf_mac_addr_set,
13663                 (void *)&cmd_set_vf_mac_addr_vf,
13664                 (void *)&cmd_set_vf_mac_addr_mac,
13665                 (void *)&cmd_set_vf_mac_addr_addr,
13666                 (void *)&cmd_set_vf_mac_addr_port_id,
13667                 (void *)&cmd_set_vf_mac_addr_vf_id,
13668                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13669                 NULL,
13670         },
13671 };
13672
13673 /* MACsec configuration */
13674
13675 /* Common result structure for MACsec offload enable */
13676 struct cmd_macsec_offload_on_result {
13677         cmdline_fixed_string_t set;
13678         cmdline_fixed_string_t macsec;
13679         cmdline_fixed_string_t offload;
13680         portid_t port_id;
13681         cmdline_fixed_string_t on;
13682         cmdline_fixed_string_t encrypt;
13683         cmdline_fixed_string_t en_on_off;
13684         cmdline_fixed_string_t replay_protect;
13685         cmdline_fixed_string_t rp_on_off;
13686 };
13687
13688 /* Common CLI fields for MACsec offload disable */
13689 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13690         TOKEN_STRING_INITIALIZER
13691                 (struct cmd_macsec_offload_on_result,
13692                  set, "set");
13693 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13694         TOKEN_STRING_INITIALIZER
13695                 (struct cmd_macsec_offload_on_result,
13696                  macsec, "macsec");
13697 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13698         TOKEN_STRING_INITIALIZER
13699                 (struct cmd_macsec_offload_on_result,
13700                  offload, "offload");
13701 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13702         TOKEN_NUM_INITIALIZER
13703                 (struct cmd_macsec_offload_on_result,
13704                  port_id, UINT16);
13705 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13706         TOKEN_STRING_INITIALIZER
13707                 (struct cmd_macsec_offload_on_result,
13708                  on, "on");
13709 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13710         TOKEN_STRING_INITIALIZER
13711                 (struct cmd_macsec_offload_on_result,
13712                  encrypt, "encrypt");
13713 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13714         TOKEN_STRING_INITIALIZER
13715                 (struct cmd_macsec_offload_on_result,
13716                  en_on_off, "on#off");
13717 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13718         TOKEN_STRING_INITIALIZER
13719                 (struct cmd_macsec_offload_on_result,
13720                  replay_protect, "replay-protect");
13721 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13722         TOKEN_STRING_INITIALIZER
13723                 (struct cmd_macsec_offload_on_result,
13724                  rp_on_off, "on#off");
13725
13726 static void
13727 cmd_set_macsec_offload_on_parsed(
13728         void *parsed_result,
13729         __attribute__((unused)) struct cmdline *cl,
13730         __attribute__((unused)) void *data)
13731 {
13732         struct cmd_macsec_offload_on_result *res = parsed_result;
13733         int ret = -ENOTSUP;
13734         portid_t port_id = res->port_id;
13735         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13736         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13737         struct rte_eth_dev_info dev_info;
13738
13739         if (port_id_is_invalid(port_id, ENABLED_WARN))
13740                 return;
13741         if (!port_is_stopped(port_id)) {
13742                 printf("Please stop port %d first\n", port_id);
13743                 return;
13744         }
13745
13746         rte_eth_dev_info_get(port_id, &dev_info);
13747         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13748 #ifdef RTE_LIBRTE_IXGBE_PMD
13749                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13750 #endif
13751         }
13752         RTE_SET_USED(en);
13753         RTE_SET_USED(rp);
13754
13755         switch (ret) {
13756         case 0:
13757                 ports[port_id].dev_conf.txmode.offloads |=
13758                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13759                 cmd_reconfig_device_queue(port_id, 1, 1);
13760                 break;
13761         case -ENODEV:
13762                 printf("invalid port_id %d\n", port_id);
13763                 break;
13764         case -ENOTSUP:
13765                 printf("not supported on port %d\n", port_id);
13766                 break;
13767         default:
13768                 printf("programming error: (%s)\n", strerror(-ret));
13769         }
13770 }
13771
13772 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13773         .f = cmd_set_macsec_offload_on_parsed,
13774         .data = NULL,
13775         .help_str = "set macsec offload <port_id> on "
13776                 "encrypt on|off replay-protect on|off",
13777         .tokens = {
13778                 (void *)&cmd_macsec_offload_on_set,
13779                 (void *)&cmd_macsec_offload_on_macsec,
13780                 (void *)&cmd_macsec_offload_on_offload,
13781                 (void *)&cmd_macsec_offload_on_port_id,
13782                 (void *)&cmd_macsec_offload_on_on,
13783                 (void *)&cmd_macsec_offload_on_encrypt,
13784                 (void *)&cmd_macsec_offload_on_en_on_off,
13785                 (void *)&cmd_macsec_offload_on_replay_protect,
13786                 (void *)&cmd_macsec_offload_on_rp_on_off,
13787                 NULL,
13788         },
13789 };
13790
13791 /* Common result structure for MACsec offload disable */
13792 struct cmd_macsec_offload_off_result {
13793         cmdline_fixed_string_t set;
13794         cmdline_fixed_string_t macsec;
13795         cmdline_fixed_string_t offload;
13796         portid_t port_id;
13797         cmdline_fixed_string_t off;
13798 };
13799
13800 /* Common CLI fields for MACsec offload disable */
13801 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13802         TOKEN_STRING_INITIALIZER
13803                 (struct cmd_macsec_offload_off_result,
13804                  set, "set");
13805 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13806         TOKEN_STRING_INITIALIZER
13807                 (struct cmd_macsec_offload_off_result,
13808                  macsec, "macsec");
13809 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13810         TOKEN_STRING_INITIALIZER
13811                 (struct cmd_macsec_offload_off_result,
13812                  offload, "offload");
13813 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13814         TOKEN_NUM_INITIALIZER
13815                 (struct cmd_macsec_offload_off_result,
13816                  port_id, UINT16);
13817 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13818         TOKEN_STRING_INITIALIZER
13819                 (struct cmd_macsec_offload_off_result,
13820                  off, "off");
13821
13822 static void
13823 cmd_set_macsec_offload_off_parsed(
13824         void *parsed_result,
13825         __attribute__((unused)) struct cmdline *cl,
13826         __attribute__((unused)) void *data)
13827 {
13828         struct cmd_macsec_offload_off_result *res = parsed_result;
13829         int ret = -ENOTSUP;
13830         struct rte_eth_dev_info dev_info;
13831         portid_t port_id = res->port_id;
13832
13833         if (port_id_is_invalid(port_id, ENABLED_WARN))
13834                 return;
13835         if (!port_is_stopped(port_id)) {
13836                 printf("Please stop port %d first\n", port_id);
13837                 return;
13838         }
13839
13840         rte_eth_dev_info_get(port_id, &dev_info);
13841         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13842 #ifdef RTE_LIBRTE_IXGBE_PMD
13843                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13844 #endif
13845         }
13846         switch (ret) {
13847         case 0:
13848                 ports[port_id].dev_conf.txmode.offloads &=
13849                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13850                 cmd_reconfig_device_queue(port_id, 1, 1);
13851                 break;
13852         case -ENODEV:
13853                 printf("invalid port_id %d\n", port_id);
13854                 break;
13855         case -ENOTSUP:
13856                 printf("not supported on port %d\n", port_id);
13857                 break;
13858         default:
13859                 printf("programming error: (%s)\n", strerror(-ret));
13860         }
13861 }
13862
13863 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13864         .f = cmd_set_macsec_offload_off_parsed,
13865         .data = NULL,
13866         .help_str = "set macsec offload <port_id> off",
13867         .tokens = {
13868                 (void *)&cmd_macsec_offload_off_set,
13869                 (void *)&cmd_macsec_offload_off_macsec,
13870                 (void *)&cmd_macsec_offload_off_offload,
13871                 (void *)&cmd_macsec_offload_off_port_id,
13872                 (void *)&cmd_macsec_offload_off_off,
13873                 NULL,
13874         },
13875 };
13876
13877 /* Common result structure for MACsec secure connection configure */
13878 struct cmd_macsec_sc_result {
13879         cmdline_fixed_string_t set;
13880         cmdline_fixed_string_t macsec;
13881         cmdline_fixed_string_t sc;
13882         cmdline_fixed_string_t tx_rx;
13883         portid_t port_id;
13884         struct ether_addr mac;
13885         uint16_t pi;
13886 };
13887
13888 /* Common CLI fields for MACsec secure connection configure */
13889 cmdline_parse_token_string_t cmd_macsec_sc_set =
13890         TOKEN_STRING_INITIALIZER
13891                 (struct cmd_macsec_sc_result,
13892                  set, "set");
13893 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13894         TOKEN_STRING_INITIALIZER
13895                 (struct cmd_macsec_sc_result,
13896                  macsec, "macsec");
13897 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13898         TOKEN_STRING_INITIALIZER
13899                 (struct cmd_macsec_sc_result,
13900                  sc, "sc");
13901 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13902         TOKEN_STRING_INITIALIZER
13903                 (struct cmd_macsec_sc_result,
13904                  tx_rx, "tx#rx");
13905 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13906         TOKEN_NUM_INITIALIZER
13907                 (struct cmd_macsec_sc_result,
13908                  port_id, UINT16);
13909 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13910         TOKEN_ETHERADDR_INITIALIZER
13911                 (struct cmd_macsec_sc_result,
13912                  mac);
13913 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13914         TOKEN_NUM_INITIALIZER
13915                 (struct cmd_macsec_sc_result,
13916                  pi, UINT16);
13917
13918 static void
13919 cmd_set_macsec_sc_parsed(
13920         void *parsed_result,
13921         __attribute__((unused)) struct cmdline *cl,
13922         __attribute__((unused)) void *data)
13923 {
13924         struct cmd_macsec_sc_result *res = parsed_result;
13925         int ret = -ENOTSUP;
13926         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13927
13928 #ifdef RTE_LIBRTE_IXGBE_PMD
13929         ret = is_tx ?
13930                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13931                                 res->mac.addr_bytes) :
13932                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13933                                 res->mac.addr_bytes, res->pi);
13934 #endif
13935         RTE_SET_USED(is_tx);
13936
13937         switch (ret) {
13938         case 0:
13939                 break;
13940         case -ENODEV:
13941                 printf("invalid port_id %d\n", res->port_id);
13942                 break;
13943         case -ENOTSUP:
13944                 printf("not supported on port %d\n", res->port_id);
13945                 break;
13946         default:
13947                 printf("programming error: (%s)\n", strerror(-ret));
13948         }
13949 }
13950
13951 cmdline_parse_inst_t cmd_set_macsec_sc = {
13952         .f = cmd_set_macsec_sc_parsed,
13953         .data = NULL,
13954         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13955         .tokens = {
13956                 (void *)&cmd_macsec_sc_set,
13957                 (void *)&cmd_macsec_sc_macsec,
13958                 (void *)&cmd_macsec_sc_sc,
13959                 (void *)&cmd_macsec_sc_tx_rx,
13960                 (void *)&cmd_macsec_sc_port_id,
13961                 (void *)&cmd_macsec_sc_mac,
13962                 (void *)&cmd_macsec_sc_pi,
13963                 NULL,
13964         },
13965 };
13966
13967 /* Common result structure for MACsec secure connection configure */
13968 struct cmd_macsec_sa_result {
13969         cmdline_fixed_string_t set;
13970         cmdline_fixed_string_t macsec;
13971         cmdline_fixed_string_t sa;
13972         cmdline_fixed_string_t tx_rx;
13973         portid_t port_id;
13974         uint8_t idx;
13975         uint8_t an;
13976         uint32_t pn;
13977         cmdline_fixed_string_t key;
13978 };
13979
13980 /* Common CLI fields for MACsec secure connection configure */
13981 cmdline_parse_token_string_t cmd_macsec_sa_set =
13982         TOKEN_STRING_INITIALIZER
13983                 (struct cmd_macsec_sa_result,
13984                  set, "set");
13985 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13986         TOKEN_STRING_INITIALIZER
13987                 (struct cmd_macsec_sa_result,
13988                  macsec, "macsec");
13989 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13990         TOKEN_STRING_INITIALIZER
13991                 (struct cmd_macsec_sa_result,
13992                  sa, "sa");
13993 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13994         TOKEN_STRING_INITIALIZER
13995                 (struct cmd_macsec_sa_result,
13996                  tx_rx, "tx#rx");
13997 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13998         TOKEN_NUM_INITIALIZER
13999                 (struct cmd_macsec_sa_result,
14000                  port_id, UINT16);
14001 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14002         TOKEN_NUM_INITIALIZER
14003                 (struct cmd_macsec_sa_result,
14004                  idx, UINT8);
14005 cmdline_parse_token_num_t cmd_macsec_sa_an =
14006         TOKEN_NUM_INITIALIZER
14007                 (struct cmd_macsec_sa_result,
14008                  an, UINT8);
14009 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14010         TOKEN_NUM_INITIALIZER
14011                 (struct cmd_macsec_sa_result,
14012                  pn, UINT32);
14013 cmdline_parse_token_string_t cmd_macsec_sa_key =
14014         TOKEN_STRING_INITIALIZER
14015                 (struct cmd_macsec_sa_result,
14016                  key, NULL);
14017
14018 static void
14019 cmd_set_macsec_sa_parsed(
14020         void *parsed_result,
14021         __attribute__((unused)) struct cmdline *cl,
14022         __attribute__((unused)) void *data)
14023 {
14024         struct cmd_macsec_sa_result *res = parsed_result;
14025         int ret = -ENOTSUP;
14026         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14027         uint8_t key[16] = { 0 };
14028         uint8_t xdgt0;
14029         uint8_t xdgt1;
14030         int key_len;
14031         int i;
14032
14033         key_len = strlen(res->key) / 2;
14034         if (key_len > 16)
14035                 key_len = 16;
14036
14037         for (i = 0; i < key_len; i++) {
14038                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14039                 if (xdgt0 == 0xFF)
14040                         return;
14041                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14042                 if (xdgt1 == 0xFF)
14043                         return;
14044                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14045         }
14046
14047 #ifdef RTE_LIBRTE_IXGBE_PMD
14048         ret = is_tx ?
14049                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14050                         res->idx, res->an, res->pn, key) :
14051                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14052                         res->idx, res->an, res->pn, key);
14053 #endif
14054         RTE_SET_USED(is_tx);
14055         RTE_SET_USED(key);
14056
14057         switch (ret) {
14058         case 0:
14059                 break;
14060         case -EINVAL:
14061                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14062                 break;
14063         case -ENODEV:
14064                 printf("invalid port_id %d\n", res->port_id);
14065                 break;
14066         case -ENOTSUP:
14067                 printf("not supported on port %d\n", res->port_id);
14068                 break;
14069         default:
14070                 printf("programming error: (%s)\n", strerror(-ret));
14071         }
14072 }
14073
14074 cmdline_parse_inst_t cmd_set_macsec_sa = {
14075         .f = cmd_set_macsec_sa_parsed,
14076         .data = NULL,
14077         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14078         .tokens = {
14079                 (void *)&cmd_macsec_sa_set,
14080                 (void *)&cmd_macsec_sa_macsec,
14081                 (void *)&cmd_macsec_sa_sa,
14082                 (void *)&cmd_macsec_sa_tx_rx,
14083                 (void *)&cmd_macsec_sa_port_id,
14084                 (void *)&cmd_macsec_sa_idx,
14085                 (void *)&cmd_macsec_sa_an,
14086                 (void *)&cmd_macsec_sa_pn,
14087                 (void *)&cmd_macsec_sa_key,
14088                 NULL,
14089         },
14090 };
14091
14092 /* VF unicast promiscuous mode configuration */
14093
14094 /* Common result structure for VF unicast promiscuous mode */
14095 struct cmd_vf_promisc_result {
14096         cmdline_fixed_string_t set;
14097         cmdline_fixed_string_t vf;
14098         cmdline_fixed_string_t promisc;
14099         portid_t port_id;
14100         uint32_t vf_id;
14101         cmdline_fixed_string_t on_off;
14102 };
14103
14104 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14105 cmdline_parse_token_string_t cmd_vf_promisc_set =
14106         TOKEN_STRING_INITIALIZER
14107                 (struct cmd_vf_promisc_result,
14108                  set, "set");
14109 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14110         TOKEN_STRING_INITIALIZER
14111                 (struct cmd_vf_promisc_result,
14112                  vf, "vf");
14113 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14114         TOKEN_STRING_INITIALIZER
14115                 (struct cmd_vf_promisc_result,
14116                  promisc, "promisc");
14117 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14118         TOKEN_NUM_INITIALIZER
14119                 (struct cmd_vf_promisc_result,
14120                  port_id, UINT16);
14121 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14122         TOKEN_NUM_INITIALIZER
14123                 (struct cmd_vf_promisc_result,
14124                  vf_id, UINT32);
14125 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14126         TOKEN_STRING_INITIALIZER
14127                 (struct cmd_vf_promisc_result,
14128                  on_off, "on#off");
14129
14130 static void
14131 cmd_set_vf_promisc_parsed(
14132         void *parsed_result,
14133         __attribute__((unused)) struct cmdline *cl,
14134         __attribute__((unused)) void *data)
14135 {
14136         struct cmd_vf_promisc_result *res = parsed_result;
14137         int ret = -ENOTSUP;
14138
14139         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14140
14141         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14142                 return;
14143
14144 #ifdef RTE_LIBRTE_I40E_PMD
14145         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14146                                                   res->vf_id, is_on);
14147 #endif
14148
14149         switch (ret) {
14150         case 0:
14151                 break;
14152         case -EINVAL:
14153                 printf("invalid vf_id %d\n", res->vf_id);
14154                 break;
14155         case -ENODEV:
14156                 printf("invalid port_id %d\n", res->port_id);
14157                 break;
14158         case -ENOTSUP:
14159                 printf("function not implemented\n");
14160                 break;
14161         default:
14162                 printf("programming error: (%s)\n", strerror(-ret));
14163         }
14164 }
14165
14166 cmdline_parse_inst_t cmd_set_vf_promisc = {
14167         .f = cmd_set_vf_promisc_parsed,
14168         .data = NULL,
14169         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14170                 "Set unicast promiscuous mode for a VF from the PF",
14171         .tokens = {
14172                 (void *)&cmd_vf_promisc_set,
14173                 (void *)&cmd_vf_promisc_vf,
14174                 (void *)&cmd_vf_promisc_promisc,
14175                 (void *)&cmd_vf_promisc_port_id,
14176                 (void *)&cmd_vf_promisc_vf_id,
14177                 (void *)&cmd_vf_promisc_on_off,
14178                 NULL,
14179         },
14180 };
14181
14182 /* VF multicast promiscuous mode configuration */
14183
14184 /* Common result structure for VF multicast promiscuous mode */
14185 struct cmd_vf_allmulti_result {
14186         cmdline_fixed_string_t set;
14187         cmdline_fixed_string_t vf;
14188         cmdline_fixed_string_t allmulti;
14189         portid_t port_id;
14190         uint32_t vf_id;
14191         cmdline_fixed_string_t on_off;
14192 };
14193
14194 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14195 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14196         TOKEN_STRING_INITIALIZER
14197                 (struct cmd_vf_allmulti_result,
14198                  set, "set");
14199 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14200         TOKEN_STRING_INITIALIZER
14201                 (struct cmd_vf_allmulti_result,
14202                  vf, "vf");
14203 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14204         TOKEN_STRING_INITIALIZER
14205                 (struct cmd_vf_allmulti_result,
14206                  allmulti, "allmulti");
14207 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14208         TOKEN_NUM_INITIALIZER
14209                 (struct cmd_vf_allmulti_result,
14210                  port_id, UINT16);
14211 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14212         TOKEN_NUM_INITIALIZER
14213                 (struct cmd_vf_allmulti_result,
14214                  vf_id, UINT32);
14215 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14216         TOKEN_STRING_INITIALIZER
14217                 (struct cmd_vf_allmulti_result,
14218                  on_off, "on#off");
14219
14220 static void
14221 cmd_set_vf_allmulti_parsed(
14222         void *parsed_result,
14223         __attribute__((unused)) struct cmdline *cl,
14224         __attribute__((unused)) void *data)
14225 {
14226         struct cmd_vf_allmulti_result *res = parsed_result;
14227         int ret = -ENOTSUP;
14228
14229         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14230
14231         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14232                 return;
14233
14234 #ifdef RTE_LIBRTE_I40E_PMD
14235         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14236                                                     res->vf_id, is_on);
14237 #endif
14238
14239         switch (ret) {
14240         case 0:
14241                 break;
14242         case -EINVAL:
14243                 printf("invalid vf_id %d\n", res->vf_id);
14244                 break;
14245         case -ENODEV:
14246                 printf("invalid port_id %d\n", res->port_id);
14247                 break;
14248         case -ENOTSUP:
14249                 printf("function not implemented\n");
14250                 break;
14251         default:
14252                 printf("programming error: (%s)\n", strerror(-ret));
14253         }
14254 }
14255
14256 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14257         .f = cmd_set_vf_allmulti_parsed,
14258         .data = NULL,
14259         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14260                 "Set multicast promiscuous mode for a VF from the PF",
14261         .tokens = {
14262                 (void *)&cmd_vf_allmulti_set,
14263                 (void *)&cmd_vf_allmulti_vf,
14264                 (void *)&cmd_vf_allmulti_allmulti,
14265                 (void *)&cmd_vf_allmulti_port_id,
14266                 (void *)&cmd_vf_allmulti_vf_id,
14267                 (void *)&cmd_vf_allmulti_on_off,
14268                 NULL,
14269         },
14270 };
14271
14272 /* vf broadcast mode configuration */
14273
14274 /* Common result structure for vf broadcast */
14275 struct cmd_set_vf_broadcast_result {
14276         cmdline_fixed_string_t set;
14277         cmdline_fixed_string_t vf;
14278         cmdline_fixed_string_t broadcast;
14279         portid_t port_id;
14280         uint16_t vf_id;
14281         cmdline_fixed_string_t on_off;
14282 };
14283
14284 /* Common CLI fields for vf broadcast enable disable */
14285 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14286         TOKEN_STRING_INITIALIZER
14287                 (struct cmd_set_vf_broadcast_result,
14288                  set, "set");
14289 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14290         TOKEN_STRING_INITIALIZER
14291                 (struct cmd_set_vf_broadcast_result,
14292                  vf, "vf");
14293 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14294         TOKEN_STRING_INITIALIZER
14295                 (struct cmd_set_vf_broadcast_result,
14296                  broadcast, "broadcast");
14297 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14298         TOKEN_NUM_INITIALIZER
14299                 (struct cmd_set_vf_broadcast_result,
14300                  port_id, UINT16);
14301 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14302         TOKEN_NUM_INITIALIZER
14303                 (struct cmd_set_vf_broadcast_result,
14304                  vf_id, UINT16);
14305 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14306         TOKEN_STRING_INITIALIZER
14307                 (struct cmd_set_vf_broadcast_result,
14308                  on_off, "on#off");
14309
14310 static void
14311 cmd_set_vf_broadcast_parsed(
14312         void *parsed_result,
14313         __attribute__((unused)) struct cmdline *cl,
14314         __attribute__((unused)) void *data)
14315 {
14316         struct cmd_set_vf_broadcast_result *res = parsed_result;
14317         int ret = -ENOTSUP;
14318
14319         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14320
14321         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14322                 return;
14323
14324 #ifdef RTE_LIBRTE_I40E_PMD
14325         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14326                                             res->vf_id, is_on);
14327 #endif
14328
14329         switch (ret) {
14330         case 0:
14331                 break;
14332         case -EINVAL:
14333                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14334                 break;
14335         case -ENODEV:
14336                 printf("invalid port_id %d\n", res->port_id);
14337                 break;
14338         case -ENOTSUP:
14339                 printf("function not implemented\n");
14340                 break;
14341         default:
14342                 printf("programming error: (%s)\n", strerror(-ret));
14343         }
14344 }
14345
14346 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14347         .f = cmd_set_vf_broadcast_parsed,
14348         .data = NULL,
14349         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14350         .tokens = {
14351                 (void *)&cmd_set_vf_broadcast_set,
14352                 (void *)&cmd_set_vf_broadcast_vf,
14353                 (void *)&cmd_set_vf_broadcast_broadcast,
14354                 (void *)&cmd_set_vf_broadcast_port_id,
14355                 (void *)&cmd_set_vf_broadcast_vf_id,
14356                 (void *)&cmd_set_vf_broadcast_on_off,
14357                 NULL,
14358         },
14359 };
14360
14361 /* vf vlan tag configuration */
14362
14363 /* Common result structure for vf vlan tag */
14364 struct cmd_set_vf_vlan_tag_result {
14365         cmdline_fixed_string_t set;
14366         cmdline_fixed_string_t vf;
14367         cmdline_fixed_string_t vlan;
14368         cmdline_fixed_string_t tag;
14369         portid_t port_id;
14370         uint16_t vf_id;
14371         cmdline_fixed_string_t on_off;
14372 };
14373
14374 /* Common CLI fields for vf vlan tag enable disable */
14375 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14376         TOKEN_STRING_INITIALIZER
14377                 (struct cmd_set_vf_vlan_tag_result,
14378                  set, "set");
14379 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14380         TOKEN_STRING_INITIALIZER
14381                 (struct cmd_set_vf_vlan_tag_result,
14382                  vf, "vf");
14383 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14384         TOKEN_STRING_INITIALIZER
14385                 (struct cmd_set_vf_vlan_tag_result,
14386                  vlan, "vlan");
14387 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14388         TOKEN_STRING_INITIALIZER
14389                 (struct cmd_set_vf_vlan_tag_result,
14390                  tag, "tag");
14391 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14392         TOKEN_NUM_INITIALIZER
14393                 (struct cmd_set_vf_vlan_tag_result,
14394                  port_id, UINT16);
14395 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14396         TOKEN_NUM_INITIALIZER
14397                 (struct cmd_set_vf_vlan_tag_result,
14398                  vf_id, UINT16);
14399 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14400         TOKEN_STRING_INITIALIZER
14401                 (struct cmd_set_vf_vlan_tag_result,
14402                  on_off, "on#off");
14403
14404 static void
14405 cmd_set_vf_vlan_tag_parsed(
14406         void *parsed_result,
14407         __attribute__((unused)) struct cmdline *cl,
14408         __attribute__((unused)) void *data)
14409 {
14410         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14411         int ret = -ENOTSUP;
14412
14413         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14414
14415         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14416                 return;
14417
14418 #ifdef RTE_LIBRTE_I40E_PMD
14419         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14420                                            res->vf_id, is_on);
14421 #endif
14422
14423         switch (ret) {
14424         case 0:
14425                 break;
14426         case -EINVAL:
14427                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14428                 break;
14429         case -ENODEV:
14430                 printf("invalid port_id %d\n", res->port_id);
14431                 break;
14432         case -ENOTSUP:
14433                 printf("function not implemented\n");
14434                 break;
14435         default:
14436                 printf("programming error: (%s)\n", strerror(-ret));
14437         }
14438 }
14439
14440 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14441         .f = cmd_set_vf_vlan_tag_parsed,
14442         .data = NULL,
14443         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14444         .tokens = {
14445                 (void *)&cmd_set_vf_vlan_tag_set,
14446                 (void *)&cmd_set_vf_vlan_tag_vf,
14447                 (void *)&cmd_set_vf_vlan_tag_vlan,
14448                 (void *)&cmd_set_vf_vlan_tag_tag,
14449                 (void *)&cmd_set_vf_vlan_tag_port_id,
14450                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14451                 (void *)&cmd_set_vf_vlan_tag_on_off,
14452                 NULL,
14453         },
14454 };
14455
14456 /* Common definition of VF and TC TX bandwidth configuration */
14457 struct cmd_vf_tc_bw_result {
14458         cmdline_fixed_string_t set;
14459         cmdline_fixed_string_t vf;
14460         cmdline_fixed_string_t tc;
14461         cmdline_fixed_string_t tx;
14462         cmdline_fixed_string_t min_bw;
14463         cmdline_fixed_string_t max_bw;
14464         cmdline_fixed_string_t strict_link_prio;
14465         portid_t port_id;
14466         uint16_t vf_id;
14467         uint8_t tc_no;
14468         uint32_t bw;
14469         cmdline_fixed_string_t bw_list;
14470         uint8_t tc_map;
14471 };
14472
14473 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14474         TOKEN_STRING_INITIALIZER
14475                 (struct cmd_vf_tc_bw_result,
14476                  set, "set");
14477 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14478         TOKEN_STRING_INITIALIZER
14479                 (struct cmd_vf_tc_bw_result,
14480                  vf, "vf");
14481 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14482         TOKEN_STRING_INITIALIZER
14483                 (struct cmd_vf_tc_bw_result,
14484                  tc, "tc");
14485 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14486         TOKEN_STRING_INITIALIZER
14487                 (struct cmd_vf_tc_bw_result,
14488                  tx, "tx");
14489 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14490         TOKEN_STRING_INITIALIZER
14491                 (struct cmd_vf_tc_bw_result,
14492                  strict_link_prio, "strict-link-priority");
14493 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14494         TOKEN_STRING_INITIALIZER
14495                 (struct cmd_vf_tc_bw_result,
14496                  min_bw, "min-bandwidth");
14497 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14498         TOKEN_STRING_INITIALIZER
14499                 (struct cmd_vf_tc_bw_result,
14500                  max_bw, "max-bandwidth");
14501 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14502         TOKEN_NUM_INITIALIZER
14503                 (struct cmd_vf_tc_bw_result,
14504                  port_id, UINT16);
14505 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14506         TOKEN_NUM_INITIALIZER
14507                 (struct cmd_vf_tc_bw_result,
14508                  vf_id, UINT16);
14509 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14510         TOKEN_NUM_INITIALIZER
14511                 (struct cmd_vf_tc_bw_result,
14512                  tc_no, UINT8);
14513 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14514         TOKEN_NUM_INITIALIZER
14515                 (struct cmd_vf_tc_bw_result,
14516                  bw, UINT32);
14517 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14518         TOKEN_STRING_INITIALIZER
14519                 (struct cmd_vf_tc_bw_result,
14520                  bw_list, NULL);
14521 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14522         TOKEN_NUM_INITIALIZER
14523                 (struct cmd_vf_tc_bw_result,
14524                  tc_map, UINT8);
14525
14526 /* VF max bandwidth setting */
14527 static void
14528 cmd_vf_max_bw_parsed(
14529         void *parsed_result,
14530         __attribute__((unused)) struct cmdline *cl,
14531         __attribute__((unused)) void *data)
14532 {
14533         struct cmd_vf_tc_bw_result *res = parsed_result;
14534         int ret = -ENOTSUP;
14535
14536         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14537                 return;
14538
14539 #ifdef RTE_LIBRTE_I40E_PMD
14540         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14541                                          res->vf_id, res->bw);
14542 #endif
14543
14544         switch (ret) {
14545         case 0:
14546                 break;
14547         case -EINVAL:
14548                 printf("invalid vf_id %d or bandwidth %d\n",
14549                        res->vf_id, res->bw);
14550                 break;
14551         case -ENODEV:
14552                 printf("invalid port_id %d\n", res->port_id);
14553                 break;
14554         case -ENOTSUP:
14555                 printf("function not implemented\n");
14556                 break;
14557         default:
14558                 printf("programming error: (%s)\n", strerror(-ret));
14559         }
14560 }
14561
14562 cmdline_parse_inst_t cmd_vf_max_bw = {
14563         .f = cmd_vf_max_bw_parsed,
14564         .data = NULL,
14565         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14566         .tokens = {
14567                 (void *)&cmd_vf_tc_bw_set,
14568                 (void *)&cmd_vf_tc_bw_vf,
14569                 (void *)&cmd_vf_tc_bw_tx,
14570                 (void *)&cmd_vf_tc_bw_max_bw,
14571                 (void *)&cmd_vf_tc_bw_port_id,
14572                 (void *)&cmd_vf_tc_bw_vf_id,
14573                 (void *)&cmd_vf_tc_bw_bw,
14574                 NULL,
14575         },
14576 };
14577
14578 static int
14579 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14580                            uint8_t *tc_num,
14581                            char *str)
14582 {
14583         uint32_t size;
14584         const char *p, *p0 = str;
14585         char s[256];
14586         char *end;
14587         char *str_fld[16];
14588         uint16_t i;
14589         int ret;
14590
14591         p = strchr(p0, '(');
14592         if (p == NULL) {
14593                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14594                 return -1;
14595         }
14596         p++;
14597         p0 = strchr(p, ')');
14598         if (p0 == NULL) {
14599                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14600                 return -1;
14601         }
14602         size = p0 - p;
14603         if (size >= sizeof(s)) {
14604                 printf("The string size exceeds the internal buffer size\n");
14605                 return -1;
14606         }
14607         snprintf(s, sizeof(s), "%.*s", size, p);
14608         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14609         if (ret <= 0) {
14610                 printf("Failed to get the bandwidth list. ");
14611                 return -1;
14612         }
14613         *tc_num = ret;
14614         for (i = 0; i < ret; i++)
14615                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14616
14617         return 0;
14618 }
14619
14620 /* TC min bandwidth setting */
14621 static void
14622 cmd_vf_tc_min_bw_parsed(
14623         void *parsed_result,
14624         __attribute__((unused)) struct cmdline *cl,
14625         __attribute__((unused)) void *data)
14626 {
14627         struct cmd_vf_tc_bw_result *res = parsed_result;
14628         uint8_t tc_num;
14629         uint8_t bw[16];
14630         int ret = -ENOTSUP;
14631
14632         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14633                 return;
14634
14635         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14636         if (ret)
14637                 return;
14638
14639 #ifdef RTE_LIBRTE_I40E_PMD
14640         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14641                                               tc_num, bw);
14642 #endif
14643
14644         switch (ret) {
14645         case 0:
14646                 break;
14647         case -EINVAL:
14648                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14649                 break;
14650         case -ENODEV:
14651                 printf("invalid port_id %d\n", res->port_id);
14652                 break;
14653         case -ENOTSUP:
14654                 printf("function not implemented\n");
14655                 break;
14656         default:
14657                 printf("programming error: (%s)\n", strerror(-ret));
14658         }
14659 }
14660
14661 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14662         .f = cmd_vf_tc_min_bw_parsed,
14663         .data = NULL,
14664         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14665                     " <bw1, bw2, ...>",
14666         .tokens = {
14667                 (void *)&cmd_vf_tc_bw_set,
14668                 (void *)&cmd_vf_tc_bw_vf,
14669                 (void *)&cmd_vf_tc_bw_tc,
14670                 (void *)&cmd_vf_tc_bw_tx,
14671                 (void *)&cmd_vf_tc_bw_min_bw,
14672                 (void *)&cmd_vf_tc_bw_port_id,
14673                 (void *)&cmd_vf_tc_bw_vf_id,
14674                 (void *)&cmd_vf_tc_bw_bw_list,
14675                 NULL,
14676         },
14677 };
14678
14679 static void
14680 cmd_tc_min_bw_parsed(
14681         void *parsed_result,
14682         __attribute__((unused)) struct cmdline *cl,
14683         __attribute__((unused)) void *data)
14684 {
14685         struct cmd_vf_tc_bw_result *res = parsed_result;
14686         struct rte_port *port;
14687         uint8_t tc_num;
14688         uint8_t bw[16];
14689         int ret = -ENOTSUP;
14690
14691         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14692                 return;
14693
14694         port = &ports[res->port_id];
14695         /** Check if the port is not started **/
14696         if (port->port_status != RTE_PORT_STOPPED) {
14697                 printf("Please stop port %d first\n", res->port_id);
14698                 return;
14699         }
14700
14701         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14702         if (ret)
14703                 return;
14704
14705 #ifdef RTE_LIBRTE_IXGBE_PMD
14706         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14707 #endif
14708
14709         switch (ret) {
14710         case 0:
14711                 break;
14712         case -EINVAL:
14713                 printf("invalid bandwidth\n");
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_tc_min_bw = {
14727         .f = cmd_tc_min_bw_parsed,
14728         .data = NULL,
14729         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14730         .tokens = {
14731                 (void *)&cmd_vf_tc_bw_set,
14732                 (void *)&cmd_vf_tc_bw_tc,
14733                 (void *)&cmd_vf_tc_bw_tx,
14734                 (void *)&cmd_vf_tc_bw_min_bw,
14735                 (void *)&cmd_vf_tc_bw_port_id,
14736                 (void *)&cmd_vf_tc_bw_bw_list,
14737                 NULL,
14738         },
14739 };
14740
14741 /* TC max bandwidth setting */
14742 static void
14743 cmd_vf_tc_max_bw_parsed(
14744         void *parsed_result,
14745         __attribute__((unused)) struct cmdline *cl,
14746         __attribute__((unused)) void *data)
14747 {
14748         struct cmd_vf_tc_bw_result *res = parsed_result;
14749         int ret = -ENOTSUP;
14750
14751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14752                 return;
14753
14754 #ifdef RTE_LIBRTE_I40E_PMD
14755         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14756                                             res->tc_no, res->bw);
14757 #endif
14758
14759         switch (ret) {
14760         case 0:
14761                 break;
14762         case -EINVAL:
14763                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14764                        res->vf_id, res->tc_no, res->bw);
14765                 break;
14766         case -ENODEV:
14767                 printf("invalid port_id %d\n", res->port_id);
14768                 break;
14769         case -ENOTSUP:
14770                 printf("function not implemented\n");
14771                 break;
14772         default:
14773                 printf("programming error: (%s)\n", strerror(-ret));
14774         }
14775 }
14776
14777 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14778         .f = cmd_vf_tc_max_bw_parsed,
14779         .data = NULL,
14780         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14781                     " <bandwidth>",
14782         .tokens = {
14783                 (void *)&cmd_vf_tc_bw_set,
14784                 (void *)&cmd_vf_tc_bw_vf,
14785                 (void *)&cmd_vf_tc_bw_tc,
14786                 (void *)&cmd_vf_tc_bw_tx,
14787                 (void *)&cmd_vf_tc_bw_max_bw,
14788                 (void *)&cmd_vf_tc_bw_port_id,
14789                 (void *)&cmd_vf_tc_bw_vf_id,
14790                 (void *)&cmd_vf_tc_bw_tc_no,
14791                 (void *)&cmd_vf_tc_bw_bw,
14792                 NULL,
14793         },
14794 };
14795
14796
14797 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14798
14799 /* *** Set Port default Traffic Management Hierarchy *** */
14800 struct cmd_set_port_tm_hierarchy_default_result {
14801         cmdline_fixed_string_t set;
14802         cmdline_fixed_string_t port;
14803         cmdline_fixed_string_t tm;
14804         cmdline_fixed_string_t hierarchy;
14805         cmdline_fixed_string_t def;
14806         portid_t port_id;
14807 };
14808
14809 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14810         TOKEN_STRING_INITIALIZER(
14811                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14812 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14813         TOKEN_STRING_INITIALIZER(
14814                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14815 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14816         TOKEN_STRING_INITIALIZER(
14817                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14818 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14819         TOKEN_STRING_INITIALIZER(
14820                 struct cmd_set_port_tm_hierarchy_default_result,
14821                         hierarchy, "hierarchy");
14822 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14823         TOKEN_STRING_INITIALIZER(
14824                 struct cmd_set_port_tm_hierarchy_default_result,
14825                         def, "default");
14826 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14827         TOKEN_NUM_INITIALIZER(
14828                 struct cmd_set_port_tm_hierarchy_default_result,
14829                         port_id, UINT16);
14830
14831 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14832         __attribute__((unused)) struct cmdline *cl,
14833         __attribute__((unused)) void *data)
14834 {
14835         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14836         struct rte_port *p;
14837         portid_t port_id = res->port_id;
14838
14839         if (port_id_is_invalid(port_id, ENABLED_WARN))
14840                 return;
14841
14842         p = &ports[port_id];
14843
14844         /* Forward mode: tm */
14845         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
14846                 printf("  softnicfwd mode not enabled(error)\n");
14847                 return;
14848         }
14849
14850         /* Set the default tm hierarchy */
14851         p->softport.default_tm_hierarchy_enable = 1;
14852 }
14853
14854 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14855         .f = cmd_set_port_tm_hierarchy_default_parsed,
14856         .data = NULL,
14857         .help_str = "set port tm hierarchy default <port_id>",
14858         .tokens = {
14859                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14860                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14861                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14862                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14863                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14864                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14865                 NULL,
14866         },
14867 };
14868 #endif
14869
14870 /** Set VXLAN encapsulation details */
14871 struct cmd_set_vxlan_result {
14872         cmdline_fixed_string_t set;
14873         cmdline_fixed_string_t vxlan;
14874         cmdline_fixed_string_t pos_token;
14875         cmdline_fixed_string_t ip_version;
14876         uint32_t vlan_present:1;
14877         uint32_t vni;
14878         uint16_t udp_src;
14879         uint16_t udp_dst;
14880         cmdline_ipaddr_t ip_src;
14881         cmdline_ipaddr_t ip_dst;
14882         uint16_t tci;
14883         struct ether_addr eth_src;
14884         struct ether_addr eth_dst;
14885 };
14886
14887 cmdline_parse_token_string_t cmd_set_vxlan_set =
14888         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
14889 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
14890         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
14891 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
14892         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14893                                  "vxlan-with-vlan");
14894 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
14895         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14896                                  "ip-version");
14897 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
14898         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
14899                                  "ipv4#ipv6");
14900 cmdline_parse_token_string_t cmd_set_vxlan_vni =
14901         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14902                                  "vni");
14903 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
14904         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
14905 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
14906         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14907                                  "udp-src");
14908 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
14909         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
14910 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
14911         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14912                                  "udp-dst");
14913 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
14914         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
14915 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
14916         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14917                                  "ip-src");
14918 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
14919         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
14920 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
14921         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14922                                  "ip-dst");
14923 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
14924         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
14925 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
14926         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14927                                  "vlan-tci");
14928 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
14929         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
14930 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
14931         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14932                                  "eth-src");
14933 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
14934         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
14935 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
14936         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14937                                  "eth-dst");
14938 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
14939         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
14940
14941 static void cmd_set_vxlan_parsed(void *parsed_result,
14942         __attribute__((unused)) struct cmdline *cl,
14943         __attribute__((unused)) void *data)
14944 {
14945         struct cmd_set_vxlan_result *res = parsed_result;
14946         union {
14947                 uint32_t vxlan_id;
14948                 uint8_t vni[4];
14949         } id = {
14950                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
14951         };
14952
14953         if (strcmp(res->vxlan, "vxlan") == 0)
14954                 vxlan_encap_conf.select_vlan = 0;
14955         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
14956                 vxlan_encap_conf.select_vlan = 1;
14957         if (strcmp(res->ip_version, "ipv4") == 0)
14958                 vxlan_encap_conf.select_ipv4 = 1;
14959         else if (strcmp(res->ip_version, "ipv6") == 0)
14960                 vxlan_encap_conf.select_ipv4 = 0;
14961         else
14962                 return;
14963         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
14964         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14965         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14966         if (vxlan_encap_conf.select_ipv4) {
14967                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
14968                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
14969         } else {
14970                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
14971                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
14972         }
14973         if (vxlan_encap_conf.select_vlan)
14974                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14975         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
14976                    ETHER_ADDR_LEN);
14977         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14978                    ETHER_ADDR_LEN);
14979 }
14980
14981 cmdline_parse_inst_t cmd_set_vxlan = {
14982         .f = cmd_set_vxlan_parsed,
14983         .data = NULL,
14984         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
14985                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
14986                 " eth-src <eth-src> eth-dst <eth-dst>",
14987         .tokens = {
14988                 (void *)&cmd_set_vxlan_set,
14989                 (void *)&cmd_set_vxlan_vxlan,
14990                 (void *)&cmd_set_vxlan_ip_version,
14991                 (void *)&cmd_set_vxlan_ip_version_value,
14992                 (void *)&cmd_set_vxlan_vni,
14993                 (void *)&cmd_set_vxlan_vni_value,
14994                 (void *)&cmd_set_vxlan_udp_src,
14995                 (void *)&cmd_set_vxlan_udp_src_value,
14996                 (void *)&cmd_set_vxlan_udp_dst,
14997                 (void *)&cmd_set_vxlan_udp_dst_value,
14998                 (void *)&cmd_set_vxlan_ip_src,
14999                 (void *)&cmd_set_vxlan_ip_src_value,
15000                 (void *)&cmd_set_vxlan_ip_dst,
15001                 (void *)&cmd_set_vxlan_ip_dst_value,
15002                 (void *)&cmd_set_vxlan_eth_src,
15003                 (void *)&cmd_set_vxlan_eth_src_value,
15004                 (void *)&cmd_set_vxlan_eth_dst,
15005                 (void *)&cmd_set_vxlan_eth_dst_value,
15006                 NULL,
15007         },
15008 };
15009
15010 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15011         .f = cmd_set_vxlan_parsed,
15012         .data = NULL,
15013         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15014                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15015                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15016                 " <eth-dst>",
15017         .tokens = {
15018                 (void *)&cmd_set_vxlan_set,
15019                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15020                 (void *)&cmd_set_vxlan_ip_version,
15021                 (void *)&cmd_set_vxlan_ip_version_value,
15022                 (void *)&cmd_set_vxlan_vni,
15023                 (void *)&cmd_set_vxlan_vni_value,
15024                 (void *)&cmd_set_vxlan_udp_src,
15025                 (void *)&cmd_set_vxlan_udp_src_value,
15026                 (void *)&cmd_set_vxlan_udp_dst,
15027                 (void *)&cmd_set_vxlan_udp_dst_value,
15028                 (void *)&cmd_set_vxlan_ip_src,
15029                 (void *)&cmd_set_vxlan_ip_src_value,
15030                 (void *)&cmd_set_vxlan_ip_dst,
15031                 (void *)&cmd_set_vxlan_ip_dst_value,
15032                 (void *)&cmd_set_vxlan_vlan,
15033                 (void *)&cmd_set_vxlan_vlan_value,
15034                 (void *)&cmd_set_vxlan_eth_src,
15035                 (void *)&cmd_set_vxlan_eth_src_value,
15036                 (void *)&cmd_set_vxlan_eth_dst,
15037                 (void *)&cmd_set_vxlan_eth_dst_value,
15038                 NULL,
15039         },
15040 };
15041
15042 /** Set NVGRE encapsulation details */
15043 struct cmd_set_nvgre_result {
15044         cmdline_fixed_string_t set;
15045         cmdline_fixed_string_t nvgre;
15046         cmdline_fixed_string_t pos_token;
15047         cmdline_fixed_string_t ip_version;
15048         uint32_t tni;
15049         cmdline_ipaddr_t ip_src;
15050         cmdline_ipaddr_t ip_dst;
15051         uint16_t tci;
15052         struct ether_addr eth_src;
15053         struct ether_addr eth_dst;
15054 };
15055
15056 cmdline_parse_token_string_t cmd_set_nvgre_set =
15057         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15058 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15059         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15060 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15061         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15062                                  "nvgre-with-vlan");
15063 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15064         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15065                                  "ip-version");
15066 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15067         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15068                                  "ipv4#ipv6");
15069 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15070         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15071                                  "tni");
15072 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15073         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15074 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15075         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15076                                  "ip-src");
15077 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15078         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15079 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15080         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15081                                  "ip-dst");
15082 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15083         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15084 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15085         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15086                                  "vlan-tci");
15087 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15088         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15089 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15090         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15091                                  "eth-src");
15092 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15093         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15094 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15095         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15096                                  "eth-dst");
15097 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15098         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15099
15100 static void cmd_set_nvgre_parsed(void *parsed_result,
15101         __attribute__((unused)) struct cmdline *cl,
15102         __attribute__((unused)) void *data)
15103 {
15104         struct cmd_set_nvgre_result *res = parsed_result;
15105         union {
15106                 uint32_t nvgre_tni;
15107                 uint8_t tni[4];
15108         } id = {
15109                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15110         };
15111
15112         if (strcmp(res->nvgre, "nvgre") == 0)
15113                 nvgre_encap_conf.select_vlan = 0;
15114         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15115                 nvgre_encap_conf.select_vlan = 1;
15116         if (strcmp(res->ip_version, "ipv4") == 0)
15117                 nvgre_encap_conf.select_ipv4 = 1;
15118         else if (strcmp(res->ip_version, "ipv6") == 0)
15119                 nvgre_encap_conf.select_ipv4 = 0;
15120         else
15121                 return;
15122         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15123         if (nvgre_encap_conf.select_ipv4) {
15124                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15125                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15126         } else {
15127                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15128                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15129         }
15130         if (nvgre_encap_conf.select_vlan)
15131                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15132         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15133                    ETHER_ADDR_LEN);
15134         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15135                    ETHER_ADDR_LEN);
15136 }
15137
15138 cmdline_parse_inst_t cmd_set_nvgre = {
15139         .f = cmd_set_nvgre_parsed,
15140         .data = NULL,
15141         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15142                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15143                 " eth-dst <eth-dst>",
15144         .tokens = {
15145                 (void *)&cmd_set_nvgre_set,
15146                 (void *)&cmd_set_nvgre_nvgre,
15147                 (void *)&cmd_set_nvgre_ip_version,
15148                 (void *)&cmd_set_nvgre_ip_version_value,
15149                 (void *)&cmd_set_nvgre_tni,
15150                 (void *)&cmd_set_nvgre_tni_value,
15151                 (void *)&cmd_set_nvgre_ip_src,
15152                 (void *)&cmd_set_nvgre_ip_src_value,
15153                 (void *)&cmd_set_nvgre_ip_dst,
15154                 (void *)&cmd_set_nvgre_ip_dst_value,
15155                 (void *)&cmd_set_nvgre_eth_src,
15156                 (void *)&cmd_set_nvgre_eth_src_value,
15157                 (void *)&cmd_set_nvgre_eth_dst,
15158                 (void *)&cmd_set_nvgre_eth_dst_value,
15159                 NULL,
15160         },
15161 };
15162
15163 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15164         .f = cmd_set_nvgre_parsed,
15165         .data = NULL,
15166         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15167                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15168                 " eth-src <eth-src> eth-dst <eth-dst>",
15169         .tokens = {
15170                 (void *)&cmd_set_nvgre_set,
15171                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15172                 (void *)&cmd_set_nvgre_ip_version,
15173                 (void *)&cmd_set_nvgre_ip_version_value,
15174                 (void *)&cmd_set_nvgre_tni,
15175                 (void *)&cmd_set_nvgre_tni_value,
15176                 (void *)&cmd_set_nvgre_ip_src,
15177                 (void *)&cmd_set_nvgre_ip_src_value,
15178                 (void *)&cmd_set_nvgre_ip_dst,
15179                 (void *)&cmd_set_nvgre_ip_dst_value,
15180                 (void *)&cmd_set_nvgre_vlan,
15181                 (void *)&cmd_set_nvgre_vlan_value,
15182                 (void *)&cmd_set_nvgre_eth_src,
15183                 (void *)&cmd_set_nvgre_eth_src_value,
15184                 (void *)&cmd_set_nvgre_eth_dst,
15185                 (void *)&cmd_set_nvgre_eth_dst_value,
15186                 NULL,
15187         },
15188 };
15189
15190 /* Strict link priority scheduling mode setting */
15191 static void
15192 cmd_strict_link_prio_parsed(
15193         void *parsed_result,
15194         __attribute__((unused)) struct cmdline *cl,
15195         __attribute__((unused)) void *data)
15196 {
15197         struct cmd_vf_tc_bw_result *res = parsed_result;
15198         int ret = -ENOTSUP;
15199
15200         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15201                 return;
15202
15203 #ifdef RTE_LIBRTE_I40E_PMD
15204         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15205 #endif
15206
15207         switch (ret) {
15208         case 0:
15209                 break;
15210         case -EINVAL:
15211                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15212                 break;
15213         case -ENODEV:
15214                 printf("invalid port_id %d\n", res->port_id);
15215                 break;
15216         case -ENOTSUP:
15217                 printf("function not implemented\n");
15218                 break;
15219         default:
15220                 printf("programming error: (%s)\n", strerror(-ret));
15221         }
15222 }
15223
15224 cmdline_parse_inst_t cmd_strict_link_prio = {
15225         .f = cmd_strict_link_prio_parsed,
15226         .data = NULL,
15227         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
15228         .tokens = {
15229                 (void *)&cmd_vf_tc_bw_set,
15230                 (void *)&cmd_vf_tc_bw_tx,
15231                 (void *)&cmd_vf_tc_bw_strict_link_prio,
15232                 (void *)&cmd_vf_tc_bw_port_id,
15233                 (void *)&cmd_vf_tc_bw_tc_map,
15234                 NULL,
15235         },
15236 };
15237
15238 /* Load dynamic device personalization*/
15239 struct cmd_ddp_add_result {
15240         cmdline_fixed_string_t ddp;
15241         cmdline_fixed_string_t add;
15242         portid_t port_id;
15243         char filepath[];
15244 };
15245
15246 cmdline_parse_token_string_t cmd_ddp_add_ddp =
15247         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
15248 cmdline_parse_token_string_t cmd_ddp_add_add =
15249         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
15250 cmdline_parse_token_num_t cmd_ddp_add_port_id =
15251         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
15252 cmdline_parse_token_string_t cmd_ddp_add_filepath =
15253         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
15254
15255 static void
15256 cmd_ddp_add_parsed(
15257         void *parsed_result,
15258         __attribute__((unused)) struct cmdline *cl,
15259         __attribute__((unused)) void *data)
15260 {
15261         struct cmd_ddp_add_result *res = parsed_result;
15262         uint8_t *buff;
15263         uint32_t size;
15264         char *filepath;
15265         char *file_fld[2];
15266         int file_num;
15267         int ret = -ENOTSUP;
15268
15269         if (!all_ports_stopped()) {
15270                 printf("Please stop all ports first\n");
15271                 return;
15272         }
15273
15274         filepath = strdup(res->filepath);
15275         if (filepath == NULL) {
15276                 printf("Failed to allocate memory\n");
15277                 return;
15278         }
15279         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
15280
15281         buff = open_file(file_fld[0], &size);
15282         if (!buff) {
15283                 free((void *)filepath);
15284                 return;
15285         }
15286
15287 #ifdef RTE_LIBRTE_I40E_PMD
15288         if (ret == -ENOTSUP)
15289                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15290                                                buff, size,
15291                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
15292 #endif
15293
15294         if (ret == -EEXIST)
15295                 printf("Profile has already existed.\n");
15296         else if (ret < 0)
15297                 printf("Failed to load profile.\n");
15298         else if (file_num == 2)
15299                 save_file(file_fld[1], buff, size);
15300
15301         close_file(buff);
15302         free((void *)filepath);
15303 }
15304
15305 cmdline_parse_inst_t cmd_ddp_add = {
15306         .f = cmd_ddp_add_parsed,
15307         .data = NULL,
15308         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
15309         .tokens = {
15310                 (void *)&cmd_ddp_add_ddp,
15311                 (void *)&cmd_ddp_add_add,
15312                 (void *)&cmd_ddp_add_port_id,
15313                 (void *)&cmd_ddp_add_filepath,
15314                 NULL,
15315         },
15316 };
15317
15318 /* Delete dynamic device personalization*/
15319 struct cmd_ddp_del_result {
15320         cmdline_fixed_string_t ddp;
15321         cmdline_fixed_string_t del;
15322         portid_t port_id;
15323         char filepath[];
15324 };
15325
15326 cmdline_parse_token_string_t cmd_ddp_del_ddp =
15327         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
15328 cmdline_parse_token_string_t cmd_ddp_del_del =
15329         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
15330 cmdline_parse_token_num_t cmd_ddp_del_port_id =
15331         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
15332 cmdline_parse_token_string_t cmd_ddp_del_filepath =
15333         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
15334
15335 static void
15336 cmd_ddp_del_parsed(
15337         void *parsed_result,
15338         __attribute__((unused)) struct cmdline *cl,
15339         __attribute__((unused)) void *data)
15340 {
15341         struct cmd_ddp_del_result *res = parsed_result;
15342         uint8_t *buff;
15343         uint32_t size;
15344         int ret = -ENOTSUP;
15345
15346         if (!all_ports_stopped()) {
15347                 printf("Please stop all ports first\n");
15348                 return;
15349         }
15350
15351         buff = open_file(res->filepath, &size);
15352         if (!buff)
15353                 return;
15354
15355 #ifdef RTE_LIBRTE_I40E_PMD
15356         if (ret == -ENOTSUP)
15357                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15358                                                buff, size,
15359                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15360 #endif
15361
15362         if (ret == -EACCES)
15363                 printf("Profile does not exist.\n");
15364         else if (ret < 0)
15365                 printf("Failed to delete profile.\n");
15366
15367         close_file(buff);
15368 }
15369
15370 cmdline_parse_inst_t cmd_ddp_del = {
15371         .f = cmd_ddp_del_parsed,
15372         .data = NULL,
15373         .help_str = "ddp del <port_id> <backup_profile_path>",
15374         .tokens = {
15375                 (void *)&cmd_ddp_del_ddp,
15376                 (void *)&cmd_ddp_del_del,
15377                 (void *)&cmd_ddp_del_port_id,
15378                 (void *)&cmd_ddp_del_filepath,
15379                 NULL,
15380         },
15381 };
15382
15383 /* Get dynamic device personalization profile info */
15384 struct cmd_ddp_info_result {
15385         cmdline_fixed_string_t ddp;
15386         cmdline_fixed_string_t get;
15387         cmdline_fixed_string_t info;
15388         char filepath[];
15389 };
15390
15391 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15392         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15393 cmdline_parse_token_string_t cmd_ddp_info_get =
15394         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15395 cmdline_parse_token_string_t cmd_ddp_info_info =
15396         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15397 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15398         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15399
15400 static void
15401 cmd_ddp_info_parsed(
15402         void *parsed_result,
15403         __attribute__((unused)) struct cmdline *cl,
15404         __attribute__((unused)) void *data)
15405 {
15406         struct cmd_ddp_info_result *res = parsed_result;
15407         uint8_t *pkg;
15408         uint32_t pkg_size;
15409         int ret = -ENOTSUP;
15410 #ifdef RTE_LIBRTE_I40E_PMD
15411         uint32_t i, j, n;
15412         uint8_t *buff;
15413         uint32_t buff_size = 0;
15414         struct rte_pmd_i40e_profile_info info;
15415         uint32_t dev_num = 0;
15416         struct rte_pmd_i40e_ddp_device_id *devs;
15417         uint32_t proto_num = 0;
15418         struct rte_pmd_i40e_proto_info *proto = NULL;
15419         uint32_t pctype_num = 0;
15420         struct rte_pmd_i40e_ptype_info *pctype;
15421         uint32_t ptype_num = 0;
15422         struct rte_pmd_i40e_ptype_info *ptype;
15423         uint8_t proto_id;
15424
15425 #endif
15426
15427         pkg = open_file(res->filepath, &pkg_size);
15428         if (!pkg)
15429                 return;
15430
15431 #ifdef RTE_LIBRTE_I40E_PMD
15432         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15433                                 (uint8_t *)&info, sizeof(info),
15434                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15435         if (!ret) {
15436                 printf("Global Track id:       0x%x\n", info.track_id);
15437                 printf("Global Version:        %d.%d.%d.%d\n",
15438                         info.version.major,
15439                         info.version.minor,
15440                         info.version.update,
15441                         info.version.draft);
15442                 printf("Global Package name:   %s\n\n", info.name);
15443         }
15444
15445         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15446                                 (uint8_t *)&info, sizeof(info),
15447                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15448         if (!ret) {
15449                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15450                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15451                         info.version.major,
15452                         info.version.minor,
15453                         info.version.update,
15454                         info.version.draft);
15455                 printf("i40e Profile name:     %s\n\n", info.name);
15456         }
15457
15458         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15459                                 (uint8_t *)&buff_size, sizeof(buff_size),
15460                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15461         if (!ret && buff_size) {
15462                 buff = (uint8_t *)malloc(buff_size);
15463                 if (buff) {
15464                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15465                                                 buff, buff_size,
15466                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15467                         if (!ret)
15468                                 printf("Package Notes:\n%s\n\n", buff);
15469                         free(buff);
15470                 }
15471         }
15472
15473         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15474                                 (uint8_t *)&dev_num, sizeof(dev_num),
15475                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15476         if (!ret && dev_num) {
15477                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15478                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15479                 if (devs) {
15480                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15481                                                 (uint8_t *)devs, buff_size,
15482                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15483                         if (!ret) {
15484                                 printf("List of supported devices:\n");
15485                                 for (i = 0; i < dev_num; i++) {
15486                                         printf("  %04X:%04X %04X:%04X\n",
15487                                                 devs[i].vendor_dev_id >> 16,
15488                                                 devs[i].vendor_dev_id & 0xFFFF,
15489                                                 devs[i].sub_vendor_dev_id >> 16,
15490                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15491                                 }
15492                                 printf("\n");
15493                         }
15494                         free(devs);
15495                 }
15496         }
15497
15498         /* get information about protocols and packet types */
15499         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15500                 (uint8_t *)&proto_num, sizeof(proto_num),
15501                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15502         if (ret || !proto_num)
15503                 goto no_print_return;
15504
15505         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15506         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15507         if (!proto)
15508                 goto no_print_return;
15509
15510         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15511                                         buff_size,
15512                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15513         if (!ret) {
15514                 printf("List of used protocols:\n");
15515                 for (i = 0; i < proto_num; i++)
15516                         printf("  %2u: %s\n", proto[i].proto_id,
15517                                proto[i].name);
15518                 printf("\n");
15519         }
15520         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15521                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15522                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15523         if (ret || !pctype_num)
15524                 goto no_print_pctypes;
15525
15526         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15527         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15528         if (!pctype)
15529                 goto no_print_pctypes;
15530
15531         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15532                                         buff_size,
15533                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15534         if (ret) {
15535                 free(pctype);
15536                 goto no_print_pctypes;
15537         }
15538
15539         printf("List of defined packet classification types:\n");
15540         for (i = 0; i < pctype_num; i++) {
15541                 printf("  %2u:", pctype[i].ptype_id);
15542                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15543                         proto_id = pctype[i].protocols[j];
15544                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15545                                 for (n = 0; n < proto_num; n++) {
15546                                         if (proto[n].proto_id == proto_id) {
15547                                                 printf(" %s", proto[n].name);
15548                                                 break;
15549                                         }
15550                                 }
15551                         }
15552                 }
15553                 printf("\n");
15554         }
15555         printf("\n");
15556         free(pctype);
15557
15558 no_print_pctypes:
15559
15560         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15561                                         sizeof(ptype_num),
15562                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15563         if (ret || !ptype_num)
15564                 goto no_print_return;
15565
15566         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15567         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15568         if (!ptype)
15569                 goto no_print_return;
15570
15571         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15572                                         buff_size,
15573                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15574         if (ret) {
15575                 free(ptype);
15576                 goto no_print_return;
15577         }
15578         printf("List of defined packet types:\n");
15579         for (i = 0; i < ptype_num; i++) {
15580                 printf("  %2u:", ptype[i].ptype_id);
15581                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15582                         proto_id = ptype[i].protocols[j];
15583                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15584                                 for (n = 0; n < proto_num; n++) {
15585                                         if (proto[n].proto_id == proto_id) {
15586                                                 printf(" %s", proto[n].name);
15587                                                 break;
15588                                         }
15589                                 }
15590                         }
15591                 }
15592                 printf("\n");
15593         }
15594         free(ptype);
15595         printf("\n");
15596
15597         ret = 0;
15598 no_print_return:
15599         if (proto)
15600                 free(proto);
15601 #endif
15602         if (ret == -ENOTSUP)
15603                 printf("Function not supported in PMD driver\n");
15604         close_file(pkg);
15605 }
15606
15607 cmdline_parse_inst_t cmd_ddp_get_info = {
15608         .f = cmd_ddp_info_parsed,
15609         .data = NULL,
15610         .help_str = "ddp get info <profile_path>",
15611         .tokens = {
15612                 (void *)&cmd_ddp_info_ddp,
15613                 (void *)&cmd_ddp_info_get,
15614                 (void *)&cmd_ddp_info_info,
15615                 (void *)&cmd_ddp_info_filepath,
15616                 NULL,
15617         },
15618 };
15619
15620 /* Get dynamic device personalization profile info list*/
15621 #define PROFILE_INFO_SIZE 48
15622 #define MAX_PROFILE_NUM 16
15623
15624 struct cmd_ddp_get_list_result {
15625         cmdline_fixed_string_t ddp;
15626         cmdline_fixed_string_t get;
15627         cmdline_fixed_string_t list;
15628         portid_t port_id;
15629 };
15630
15631 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15632         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15633 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15634         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15635 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15636         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15637 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15638         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15639
15640 static void
15641 cmd_ddp_get_list_parsed(
15642         __attribute__((unused)) void *parsed_result,
15643         __attribute__((unused)) struct cmdline *cl,
15644         __attribute__((unused)) void *data)
15645 {
15646 #ifdef RTE_LIBRTE_I40E_PMD
15647         struct cmd_ddp_get_list_result *res = parsed_result;
15648         struct rte_pmd_i40e_profile_list *p_list;
15649         struct rte_pmd_i40e_profile_info *p_info;
15650         uint32_t p_num;
15651         uint32_t size;
15652         uint32_t i;
15653 #endif
15654         int ret = -ENOTSUP;
15655
15656 #ifdef RTE_LIBRTE_I40E_PMD
15657         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15658         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15659         if (!p_list)
15660                 printf("%s: Failed to malloc buffer\n", __func__);
15661
15662         if (ret == -ENOTSUP)
15663                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15664                                                 (uint8_t *)p_list, size);
15665
15666         if (!ret) {
15667                 p_num = p_list->p_count;
15668                 printf("Profile number is: %d\n\n", p_num);
15669
15670                 for (i = 0; i < p_num; i++) {
15671                         p_info = &p_list->p_info[i];
15672                         printf("Profile %d:\n", i);
15673                         printf("Track id:     0x%x\n", p_info->track_id);
15674                         printf("Version:      %d.%d.%d.%d\n",
15675                                p_info->version.major,
15676                                p_info->version.minor,
15677                                p_info->version.update,
15678                                p_info->version.draft);
15679                         printf("Profile name: %s\n\n", p_info->name);
15680                 }
15681         }
15682
15683         free(p_list);
15684 #endif
15685
15686         if (ret < 0)
15687                 printf("Failed to get ddp list\n");
15688 }
15689
15690 cmdline_parse_inst_t cmd_ddp_get_list = {
15691         .f = cmd_ddp_get_list_parsed,
15692         .data = NULL,
15693         .help_str = "ddp get list <port_id>",
15694         .tokens = {
15695                 (void *)&cmd_ddp_get_list_ddp,
15696                 (void *)&cmd_ddp_get_list_get,
15697                 (void *)&cmd_ddp_get_list_list,
15698                 (void *)&cmd_ddp_get_list_port_id,
15699                 NULL,
15700         },
15701 };
15702
15703 /* Configure input set */
15704 struct cmd_cfg_input_set_result {
15705         cmdline_fixed_string_t port;
15706         cmdline_fixed_string_t cfg;
15707         portid_t port_id;
15708         cmdline_fixed_string_t pctype;
15709         uint8_t pctype_id;
15710         cmdline_fixed_string_t inset_type;
15711         cmdline_fixed_string_t opt;
15712         cmdline_fixed_string_t field;
15713         uint8_t field_idx;
15714 };
15715
15716 static void
15717 cmd_cfg_input_set_parsed(
15718         __attribute__((unused)) void *parsed_result,
15719         __attribute__((unused)) struct cmdline *cl,
15720         __attribute__((unused)) void *data)
15721 {
15722 #ifdef RTE_LIBRTE_I40E_PMD
15723         struct cmd_cfg_input_set_result *res = parsed_result;
15724         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15725         struct rte_pmd_i40e_inset inset;
15726 #endif
15727         int ret = -ENOTSUP;
15728
15729         if (!all_ports_stopped()) {
15730                 printf("Please stop all ports first\n");
15731                 return;
15732         }
15733
15734 #ifdef RTE_LIBRTE_I40E_PMD
15735         if (!strcmp(res->inset_type, "hash_inset"))
15736                 inset_type = INSET_HASH;
15737         else if (!strcmp(res->inset_type, "fdir_inset"))
15738                 inset_type = INSET_FDIR;
15739         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15740                 inset_type = INSET_FDIR_FLX;
15741         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15742                                      &inset, inset_type);
15743         if (ret) {
15744                 printf("Failed to get input set.\n");
15745                 return;
15746         }
15747
15748         if (!strcmp(res->opt, "get")) {
15749                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15750                                                    res->field_idx);
15751                 if (ret)
15752                         printf("Field index %d is enabled.\n", res->field_idx);
15753                 else
15754                         printf("Field index %d is disabled.\n", res->field_idx);
15755                 return;
15756         } else if (!strcmp(res->opt, "set"))
15757                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15758                                                    res->field_idx);
15759         else if (!strcmp(res->opt, "clear"))
15760                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15761                                                      res->field_idx);
15762         if (ret) {
15763                 printf("Failed to configure input set field.\n");
15764                 return;
15765         }
15766
15767         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15768                                      &inset, inset_type);
15769         if (ret) {
15770                 printf("Failed to set input set.\n");
15771                 return;
15772         }
15773 #endif
15774
15775         if (ret == -ENOTSUP)
15776                 printf("Function not supported\n");
15777 }
15778
15779 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15780         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15781                                  port, "port");
15782 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15783         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15784                                  cfg, "config");
15785 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15786         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15787                               port_id, UINT16);
15788 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15789         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15790                                  pctype, "pctype");
15791 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15792         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15793                               pctype_id, UINT8);
15794 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15795         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15796                                  inset_type,
15797                                  "hash_inset#fdir_inset#fdir_flx_inset");
15798 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15799         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15800                                  opt, "get#set#clear");
15801 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15802         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15803                                  field, "field");
15804 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15805         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15806                               field_idx, UINT8);
15807
15808 cmdline_parse_inst_t cmd_cfg_input_set = {
15809         .f = cmd_cfg_input_set_parsed,
15810         .data = NULL,
15811         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15812                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15813         .tokens = {
15814                 (void *)&cmd_cfg_input_set_port,
15815                 (void *)&cmd_cfg_input_set_cfg,
15816                 (void *)&cmd_cfg_input_set_port_id,
15817                 (void *)&cmd_cfg_input_set_pctype,
15818                 (void *)&cmd_cfg_input_set_pctype_id,
15819                 (void *)&cmd_cfg_input_set_inset_type,
15820                 (void *)&cmd_cfg_input_set_opt,
15821                 (void *)&cmd_cfg_input_set_field,
15822                 (void *)&cmd_cfg_input_set_field_idx,
15823                 NULL,
15824         },
15825 };
15826
15827 /* Clear input set */
15828 struct cmd_clear_input_set_result {
15829         cmdline_fixed_string_t port;
15830         cmdline_fixed_string_t cfg;
15831         portid_t port_id;
15832         cmdline_fixed_string_t pctype;
15833         uint8_t pctype_id;
15834         cmdline_fixed_string_t inset_type;
15835         cmdline_fixed_string_t clear;
15836         cmdline_fixed_string_t all;
15837 };
15838
15839 static void
15840 cmd_clear_input_set_parsed(
15841         __attribute__((unused)) void *parsed_result,
15842         __attribute__((unused)) struct cmdline *cl,
15843         __attribute__((unused)) void *data)
15844 {
15845 #ifdef RTE_LIBRTE_I40E_PMD
15846         struct cmd_clear_input_set_result *res = parsed_result;
15847         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15848         struct rte_pmd_i40e_inset inset;
15849 #endif
15850         int ret = -ENOTSUP;
15851
15852         if (!all_ports_stopped()) {
15853                 printf("Please stop all ports first\n");
15854                 return;
15855         }
15856
15857 #ifdef RTE_LIBRTE_I40E_PMD
15858         if (!strcmp(res->inset_type, "hash_inset"))
15859                 inset_type = INSET_HASH;
15860         else if (!strcmp(res->inset_type, "fdir_inset"))
15861                 inset_type = INSET_FDIR;
15862         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15863                 inset_type = INSET_FDIR_FLX;
15864
15865         memset(&inset, 0, sizeof(inset));
15866
15867         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15868                                      &inset, inset_type);
15869         if (ret) {
15870                 printf("Failed to clear input set.\n");
15871                 return;
15872         }
15873
15874 #endif
15875
15876         if (ret == -ENOTSUP)
15877                 printf("Function not supported\n");
15878 }
15879
15880 cmdline_parse_token_string_t cmd_clear_input_set_port =
15881         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15882                                  port, "port");
15883 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15884         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15885                                  cfg, "config");
15886 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15887         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15888                               port_id, UINT16);
15889 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15890         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15891                                  pctype, "pctype");
15892 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15893         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15894                               pctype_id, UINT8);
15895 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15896         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15897                                  inset_type,
15898                                  "hash_inset#fdir_inset#fdir_flx_inset");
15899 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15900         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15901                                  clear, "clear");
15902 cmdline_parse_token_string_t cmd_clear_input_set_all =
15903         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15904                                  all, "all");
15905
15906 cmdline_parse_inst_t cmd_clear_input_set = {
15907         .f = cmd_clear_input_set_parsed,
15908         .data = NULL,
15909         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15910                     "fdir_inset|fdir_flx_inset clear all",
15911         .tokens = {
15912                 (void *)&cmd_clear_input_set_port,
15913                 (void *)&cmd_clear_input_set_cfg,
15914                 (void *)&cmd_clear_input_set_port_id,
15915                 (void *)&cmd_clear_input_set_pctype,
15916                 (void *)&cmd_clear_input_set_pctype_id,
15917                 (void *)&cmd_clear_input_set_inset_type,
15918                 (void *)&cmd_clear_input_set_clear,
15919                 (void *)&cmd_clear_input_set_all,
15920                 NULL,
15921         },
15922 };
15923
15924 /* show vf stats */
15925
15926 /* Common result structure for show vf stats */
15927 struct cmd_show_vf_stats_result {
15928         cmdline_fixed_string_t show;
15929         cmdline_fixed_string_t vf;
15930         cmdline_fixed_string_t stats;
15931         portid_t port_id;
15932         uint16_t vf_id;
15933 };
15934
15935 /* Common CLI fields show vf stats*/
15936 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15937         TOKEN_STRING_INITIALIZER
15938                 (struct cmd_show_vf_stats_result,
15939                  show, "show");
15940 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15941         TOKEN_STRING_INITIALIZER
15942                 (struct cmd_show_vf_stats_result,
15943                  vf, "vf");
15944 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15945         TOKEN_STRING_INITIALIZER
15946                 (struct cmd_show_vf_stats_result,
15947                  stats, "stats");
15948 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15949         TOKEN_NUM_INITIALIZER
15950                 (struct cmd_show_vf_stats_result,
15951                  port_id, UINT16);
15952 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15953         TOKEN_NUM_INITIALIZER
15954                 (struct cmd_show_vf_stats_result,
15955                  vf_id, UINT16);
15956
15957 static void
15958 cmd_show_vf_stats_parsed(
15959         void *parsed_result,
15960         __attribute__((unused)) struct cmdline *cl,
15961         __attribute__((unused)) void *data)
15962 {
15963         struct cmd_show_vf_stats_result *res = parsed_result;
15964         struct rte_eth_stats stats;
15965         int ret = -ENOTSUP;
15966         static const char *nic_stats_border = "########################";
15967
15968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15969                 return;
15970
15971         memset(&stats, 0, sizeof(stats));
15972
15973 #ifdef RTE_LIBRTE_I40E_PMD
15974         if (ret == -ENOTSUP)
15975                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15976                                                 res->vf_id,
15977                                                 &stats);
15978 #endif
15979 #ifdef RTE_LIBRTE_BNXT_PMD
15980         if (ret == -ENOTSUP)
15981                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15982                                                 res->vf_id,
15983                                                 &stats);
15984 #endif
15985
15986         switch (ret) {
15987         case 0:
15988                 break;
15989         case -EINVAL:
15990                 printf("invalid vf_id %d\n", res->vf_id);
15991                 break;
15992         case -ENODEV:
15993                 printf("invalid port_id %d\n", res->port_id);
15994                 break;
15995         case -ENOTSUP:
15996                 printf("function not implemented\n");
15997                 break;
15998         default:
15999                 printf("programming error: (%s)\n", strerror(-ret));
16000         }
16001
16002         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16003                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16004
16005         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16006                "%-"PRIu64"\n",
16007                stats.ipackets, stats.imissed, stats.ibytes);
16008         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16009         printf("  RX-nombuf:  %-10"PRIu64"\n",
16010                stats.rx_nombuf);
16011         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16012                "%-"PRIu64"\n",
16013                stats.opackets, stats.oerrors, stats.obytes);
16014
16015         printf("  %s############################%s\n",
16016                                nic_stats_border, nic_stats_border);
16017 }
16018
16019 cmdline_parse_inst_t cmd_show_vf_stats = {
16020         .f = cmd_show_vf_stats_parsed,
16021         .data = NULL,
16022         .help_str = "show vf stats <port_id> <vf_id>",
16023         .tokens = {
16024                 (void *)&cmd_show_vf_stats_show,
16025                 (void *)&cmd_show_vf_stats_vf,
16026                 (void *)&cmd_show_vf_stats_stats,
16027                 (void *)&cmd_show_vf_stats_port_id,
16028                 (void *)&cmd_show_vf_stats_vf_id,
16029                 NULL,
16030         },
16031 };
16032
16033 /* clear vf stats */
16034
16035 /* Common result structure for clear vf stats */
16036 struct cmd_clear_vf_stats_result {
16037         cmdline_fixed_string_t clear;
16038         cmdline_fixed_string_t vf;
16039         cmdline_fixed_string_t stats;
16040         portid_t port_id;
16041         uint16_t vf_id;
16042 };
16043
16044 /* Common CLI fields clear vf stats*/
16045 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16046         TOKEN_STRING_INITIALIZER
16047                 (struct cmd_clear_vf_stats_result,
16048                  clear, "clear");
16049 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16050         TOKEN_STRING_INITIALIZER
16051                 (struct cmd_clear_vf_stats_result,
16052                  vf, "vf");
16053 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16054         TOKEN_STRING_INITIALIZER
16055                 (struct cmd_clear_vf_stats_result,
16056                  stats, "stats");
16057 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16058         TOKEN_NUM_INITIALIZER
16059                 (struct cmd_clear_vf_stats_result,
16060                  port_id, UINT16);
16061 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16062         TOKEN_NUM_INITIALIZER
16063                 (struct cmd_clear_vf_stats_result,
16064                  vf_id, UINT16);
16065
16066 static void
16067 cmd_clear_vf_stats_parsed(
16068         void *parsed_result,
16069         __attribute__((unused)) struct cmdline *cl,
16070         __attribute__((unused)) void *data)
16071 {
16072         struct cmd_clear_vf_stats_result *res = parsed_result;
16073         int ret = -ENOTSUP;
16074
16075         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16076                 return;
16077
16078 #ifdef RTE_LIBRTE_I40E_PMD
16079         if (ret == -ENOTSUP)
16080                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16081                                                   res->vf_id);
16082 #endif
16083 #ifdef RTE_LIBRTE_BNXT_PMD
16084         if (ret == -ENOTSUP)
16085                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16086                                                   res->vf_id);
16087 #endif
16088
16089         switch (ret) {
16090         case 0:
16091                 break;
16092         case -EINVAL:
16093                 printf("invalid vf_id %d\n", res->vf_id);
16094                 break;
16095         case -ENODEV:
16096                 printf("invalid port_id %d\n", res->port_id);
16097                 break;
16098         case -ENOTSUP:
16099                 printf("function not implemented\n");
16100                 break;
16101         default:
16102                 printf("programming error: (%s)\n", strerror(-ret));
16103         }
16104 }
16105
16106 cmdline_parse_inst_t cmd_clear_vf_stats = {
16107         .f = cmd_clear_vf_stats_parsed,
16108         .data = NULL,
16109         .help_str = "clear vf stats <port_id> <vf_id>",
16110         .tokens = {
16111                 (void *)&cmd_clear_vf_stats_clear,
16112                 (void *)&cmd_clear_vf_stats_vf,
16113                 (void *)&cmd_clear_vf_stats_stats,
16114                 (void *)&cmd_clear_vf_stats_port_id,
16115                 (void *)&cmd_clear_vf_stats_vf_id,
16116                 NULL,
16117         },
16118 };
16119
16120 /* port config pctype mapping reset */
16121
16122 /* Common result structure for port config pctype mapping reset */
16123 struct cmd_pctype_mapping_reset_result {
16124         cmdline_fixed_string_t port;
16125         cmdline_fixed_string_t config;
16126         portid_t port_id;
16127         cmdline_fixed_string_t pctype;
16128         cmdline_fixed_string_t mapping;
16129         cmdline_fixed_string_t reset;
16130 };
16131
16132 /* Common CLI fields for port config pctype mapping reset*/
16133 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16134         TOKEN_STRING_INITIALIZER
16135                 (struct cmd_pctype_mapping_reset_result,
16136                  port, "port");
16137 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16138         TOKEN_STRING_INITIALIZER
16139                 (struct cmd_pctype_mapping_reset_result,
16140                  config, "config");
16141 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16142         TOKEN_NUM_INITIALIZER
16143                 (struct cmd_pctype_mapping_reset_result,
16144                  port_id, UINT16);
16145 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16146         TOKEN_STRING_INITIALIZER
16147                 (struct cmd_pctype_mapping_reset_result,
16148                  pctype, "pctype");
16149 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16150         TOKEN_STRING_INITIALIZER
16151                 (struct cmd_pctype_mapping_reset_result,
16152                  mapping, "mapping");
16153 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16154         TOKEN_STRING_INITIALIZER
16155                 (struct cmd_pctype_mapping_reset_result,
16156                  reset, "reset");
16157
16158 static void
16159 cmd_pctype_mapping_reset_parsed(
16160         void *parsed_result,
16161         __attribute__((unused)) struct cmdline *cl,
16162         __attribute__((unused)) void *data)
16163 {
16164         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16165         int ret = -ENOTSUP;
16166
16167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16168                 return;
16169
16170 #ifdef RTE_LIBRTE_I40E_PMD
16171         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16172 #endif
16173
16174         switch (ret) {
16175         case 0:
16176                 break;
16177         case -ENODEV:
16178                 printf("invalid port_id %d\n", res->port_id);
16179                 break;
16180         case -ENOTSUP:
16181                 printf("function not implemented\n");
16182                 break;
16183         default:
16184                 printf("programming error: (%s)\n", strerror(-ret));
16185         }
16186 }
16187
16188 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16189         .f = cmd_pctype_mapping_reset_parsed,
16190         .data = NULL,
16191         .help_str = "port config <port_id> pctype mapping reset",
16192         .tokens = {
16193                 (void *)&cmd_pctype_mapping_reset_port,
16194                 (void *)&cmd_pctype_mapping_reset_config,
16195                 (void *)&cmd_pctype_mapping_reset_port_id,
16196                 (void *)&cmd_pctype_mapping_reset_pctype,
16197                 (void *)&cmd_pctype_mapping_reset_mapping,
16198                 (void *)&cmd_pctype_mapping_reset_reset,
16199                 NULL,
16200         },
16201 };
16202
16203 /* show port pctype mapping */
16204
16205 /* Common result structure for show port pctype mapping */
16206 struct cmd_pctype_mapping_get_result {
16207         cmdline_fixed_string_t show;
16208         cmdline_fixed_string_t port;
16209         portid_t port_id;
16210         cmdline_fixed_string_t pctype;
16211         cmdline_fixed_string_t mapping;
16212 };
16213
16214 /* Common CLI fields for pctype mapping get */
16215 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16216         TOKEN_STRING_INITIALIZER
16217                 (struct cmd_pctype_mapping_get_result,
16218                  show, "show");
16219 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16220         TOKEN_STRING_INITIALIZER
16221                 (struct cmd_pctype_mapping_get_result,
16222                  port, "port");
16223 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
16224         TOKEN_NUM_INITIALIZER
16225                 (struct cmd_pctype_mapping_get_result,
16226                  port_id, UINT16);
16227 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
16228         TOKEN_STRING_INITIALIZER
16229                 (struct cmd_pctype_mapping_get_result,
16230                  pctype, "pctype");
16231 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
16232         TOKEN_STRING_INITIALIZER
16233                 (struct cmd_pctype_mapping_get_result,
16234                  mapping, "mapping");
16235
16236 static void
16237 cmd_pctype_mapping_get_parsed(
16238         void *parsed_result,
16239         __attribute__((unused)) struct cmdline *cl,
16240         __attribute__((unused)) void *data)
16241 {
16242         struct cmd_pctype_mapping_get_result *res = parsed_result;
16243         int ret = -ENOTSUP;
16244 #ifdef RTE_LIBRTE_I40E_PMD
16245         struct rte_pmd_i40e_flow_type_mapping
16246                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
16247         int i, j, first_pctype;
16248 #endif
16249
16250         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16251                 return;
16252
16253 #ifdef RTE_LIBRTE_I40E_PMD
16254         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
16255 #endif
16256
16257         switch (ret) {
16258         case 0:
16259                 break;
16260         case -ENODEV:
16261                 printf("invalid port_id %d\n", res->port_id);
16262                 return;
16263         case -ENOTSUP:
16264                 printf("function not implemented\n");
16265                 return;
16266         default:
16267                 printf("programming error: (%s)\n", strerror(-ret));
16268                 return;
16269         }
16270
16271 #ifdef RTE_LIBRTE_I40E_PMD
16272         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
16273                 if (mapping[i].pctype != 0ULL) {
16274                         first_pctype = 1;
16275
16276                         printf("pctype: ");
16277                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
16278                                 if (mapping[i].pctype & (1ULL << j)) {
16279                                         printf(first_pctype ?
16280                                                "%02d" : ",%02d", j);
16281                                         first_pctype = 0;
16282                                 }
16283                         }
16284                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
16285                 }
16286         }
16287 #endif
16288 }
16289
16290 cmdline_parse_inst_t cmd_pctype_mapping_get = {
16291         .f = cmd_pctype_mapping_get_parsed,
16292         .data = NULL,
16293         .help_str = "show port <port_id> pctype mapping",
16294         .tokens = {
16295                 (void *)&cmd_pctype_mapping_get_show,
16296                 (void *)&cmd_pctype_mapping_get_port,
16297                 (void *)&cmd_pctype_mapping_get_port_id,
16298                 (void *)&cmd_pctype_mapping_get_pctype,
16299                 (void *)&cmd_pctype_mapping_get_mapping,
16300                 NULL,
16301         },
16302 };
16303
16304 /* port config pctype mapping update */
16305
16306 /* Common result structure for port config pctype mapping update */
16307 struct cmd_pctype_mapping_update_result {
16308         cmdline_fixed_string_t port;
16309         cmdline_fixed_string_t config;
16310         portid_t port_id;
16311         cmdline_fixed_string_t pctype;
16312         cmdline_fixed_string_t mapping;
16313         cmdline_fixed_string_t update;
16314         cmdline_fixed_string_t pctype_list;
16315         uint16_t flow_type;
16316 };
16317
16318 /* Common CLI fields for pctype mapping update*/
16319 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
16320         TOKEN_STRING_INITIALIZER
16321                 (struct cmd_pctype_mapping_update_result,
16322                  port, "port");
16323 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
16324         TOKEN_STRING_INITIALIZER
16325                 (struct cmd_pctype_mapping_update_result,
16326                  config, "config");
16327 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
16328         TOKEN_NUM_INITIALIZER
16329                 (struct cmd_pctype_mapping_update_result,
16330                  port_id, UINT16);
16331 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
16332         TOKEN_STRING_INITIALIZER
16333                 (struct cmd_pctype_mapping_update_result,
16334                  pctype, "pctype");
16335 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
16336         TOKEN_STRING_INITIALIZER
16337                 (struct cmd_pctype_mapping_update_result,
16338                  mapping, "mapping");
16339 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16340         TOKEN_STRING_INITIALIZER
16341                 (struct cmd_pctype_mapping_update_result,
16342                  update, "update");
16343 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16344         TOKEN_STRING_INITIALIZER
16345                 (struct cmd_pctype_mapping_update_result,
16346                  pctype_list, NULL);
16347 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16348         TOKEN_NUM_INITIALIZER
16349                 (struct cmd_pctype_mapping_update_result,
16350                  flow_type, UINT16);
16351
16352 static void
16353 cmd_pctype_mapping_update_parsed(
16354         void *parsed_result,
16355         __attribute__((unused)) struct cmdline *cl,
16356         __attribute__((unused)) void *data)
16357 {
16358         struct cmd_pctype_mapping_update_result *res = parsed_result;
16359         int ret = -ENOTSUP;
16360 #ifdef RTE_LIBRTE_I40E_PMD
16361         struct rte_pmd_i40e_flow_type_mapping mapping;
16362         unsigned int i;
16363         unsigned int nb_item;
16364         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16365 #endif
16366
16367         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16368                 return;
16369
16370 #ifdef RTE_LIBRTE_I40E_PMD
16371         nb_item = parse_item_list(res->pctype_list, "pctypes",
16372                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16373         mapping.flow_type = res->flow_type;
16374         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16375                 mapping.pctype |= (1ULL << pctype_list[i]);
16376         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16377                                                 &mapping,
16378                                                 1,
16379                                                 0);
16380 #endif
16381
16382         switch (ret) {
16383         case 0:
16384                 break;
16385         case -EINVAL:
16386                 printf("invalid pctype or flow type\n");
16387                 break;
16388         case -ENODEV:
16389                 printf("invalid port_id %d\n", res->port_id);
16390                 break;
16391         case -ENOTSUP:
16392                 printf("function not implemented\n");
16393                 break;
16394         default:
16395                 printf("programming error: (%s)\n", strerror(-ret));
16396         }
16397 }
16398
16399 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16400         .f = cmd_pctype_mapping_update_parsed,
16401         .data = NULL,
16402         .help_str = "port config <port_id> pctype mapping update"
16403         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16404         .tokens = {
16405                 (void *)&cmd_pctype_mapping_update_port,
16406                 (void *)&cmd_pctype_mapping_update_config,
16407                 (void *)&cmd_pctype_mapping_update_port_id,
16408                 (void *)&cmd_pctype_mapping_update_pctype,
16409                 (void *)&cmd_pctype_mapping_update_mapping,
16410                 (void *)&cmd_pctype_mapping_update_update,
16411                 (void *)&cmd_pctype_mapping_update_pc_type,
16412                 (void *)&cmd_pctype_mapping_update_flow_type,
16413                 NULL,
16414         },
16415 };
16416
16417 /* ptype mapping get */
16418
16419 /* Common result structure for ptype mapping get */
16420 struct cmd_ptype_mapping_get_result {
16421         cmdline_fixed_string_t ptype;
16422         cmdline_fixed_string_t mapping;
16423         cmdline_fixed_string_t get;
16424         portid_t port_id;
16425         uint8_t valid_only;
16426 };
16427
16428 /* Common CLI fields for ptype mapping get */
16429 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16430         TOKEN_STRING_INITIALIZER
16431                 (struct cmd_ptype_mapping_get_result,
16432                  ptype, "ptype");
16433 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16434         TOKEN_STRING_INITIALIZER
16435                 (struct cmd_ptype_mapping_get_result,
16436                  mapping, "mapping");
16437 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16438         TOKEN_STRING_INITIALIZER
16439                 (struct cmd_ptype_mapping_get_result,
16440                  get, "get");
16441 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16442         TOKEN_NUM_INITIALIZER
16443                 (struct cmd_ptype_mapping_get_result,
16444                  port_id, UINT16);
16445 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16446         TOKEN_NUM_INITIALIZER
16447                 (struct cmd_ptype_mapping_get_result,
16448                  valid_only, UINT8);
16449
16450 static void
16451 cmd_ptype_mapping_get_parsed(
16452         void *parsed_result,
16453         __attribute__((unused)) struct cmdline *cl,
16454         __attribute__((unused)) void *data)
16455 {
16456         struct cmd_ptype_mapping_get_result *res = parsed_result;
16457         int ret = -ENOTSUP;
16458 #ifdef RTE_LIBRTE_I40E_PMD
16459         int max_ptype_num = 256;
16460         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16461         uint16_t count;
16462         int i;
16463 #endif
16464
16465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16466                 return;
16467
16468 #ifdef RTE_LIBRTE_I40E_PMD
16469         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16470                                         mapping,
16471                                         max_ptype_num,
16472                                         &count,
16473                                         res->valid_only);
16474 #endif
16475
16476         switch (ret) {
16477         case 0:
16478                 break;
16479         case -ENODEV:
16480                 printf("invalid port_id %d\n", res->port_id);
16481                 break;
16482         case -ENOTSUP:
16483                 printf("function not implemented\n");
16484                 break;
16485         default:
16486                 printf("programming error: (%s)\n", strerror(-ret));
16487         }
16488
16489 #ifdef RTE_LIBRTE_I40E_PMD
16490         if (!ret) {
16491                 for (i = 0; i < count; i++)
16492                         printf("%3d\t0x%08x\n",
16493                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16494         }
16495 #endif
16496 }
16497
16498 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16499         .f = cmd_ptype_mapping_get_parsed,
16500         .data = NULL,
16501         .help_str = "ptype mapping get <port_id> <valid_only>",
16502         .tokens = {
16503                 (void *)&cmd_ptype_mapping_get_ptype,
16504                 (void *)&cmd_ptype_mapping_get_mapping,
16505                 (void *)&cmd_ptype_mapping_get_get,
16506                 (void *)&cmd_ptype_mapping_get_port_id,
16507                 (void *)&cmd_ptype_mapping_get_valid_only,
16508                 NULL,
16509         },
16510 };
16511
16512 /* ptype mapping replace */
16513
16514 /* Common result structure for ptype mapping replace */
16515 struct cmd_ptype_mapping_replace_result {
16516         cmdline_fixed_string_t ptype;
16517         cmdline_fixed_string_t mapping;
16518         cmdline_fixed_string_t replace;
16519         portid_t port_id;
16520         uint32_t target;
16521         uint8_t mask;
16522         uint32_t pkt_type;
16523 };
16524
16525 /* Common CLI fields for ptype mapping replace */
16526 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16527         TOKEN_STRING_INITIALIZER
16528                 (struct cmd_ptype_mapping_replace_result,
16529                  ptype, "ptype");
16530 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16531         TOKEN_STRING_INITIALIZER
16532                 (struct cmd_ptype_mapping_replace_result,
16533                  mapping, "mapping");
16534 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16535         TOKEN_STRING_INITIALIZER
16536                 (struct cmd_ptype_mapping_replace_result,
16537                  replace, "replace");
16538 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16539         TOKEN_NUM_INITIALIZER
16540                 (struct cmd_ptype_mapping_replace_result,
16541                  port_id, UINT16);
16542 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16543         TOKEN_NUM_INITIALIZER
16544                 (struct cmd_ptype_mapping_replace_result,
16545                  target, UINT32);
16546 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16547         TOKEN_NUM_INITIALIZER
16548                 (struct cmd_ptype_mapping_replace_result,
16549                  mask, UINT8);
16550 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16551         TOKEN_NUM_INITIALIZER
16552                 (struct cmd_ptype_mapping_replace_result,
16553                  pkt_type, UINT32);
16554
16555 static void
16556 cmd_ptype_mapping_replace_parsed(
16557         void *parsed_result,
16558         __attribute__((unused)) struct cmdline *cl,
16559         __attribute__((unused)) void *data)
16560 {
16561         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16562         int ret = -ENOTSUP;
16563
16564         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16565                 return;
16566
16567 #ifdef RTE_LIBRTE_I40E_PMD
16568         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16569                                         res->target,
16570                                         res->mask,
16571                                         res->pkt_type);
16572 #endif
16573
16574         switch (ret) {
16575         case 0:
16576                 break;
16577         case -EINVAL:
16578                 printf("invalid ptype 0x%8x or 0x%8x\n",
16579                                 res->target, res->pkt_type);
16580                 break;
16581         case -ENODEV:
16582                 printf("invalid port_id %d\n", res->port_id);
16583                 break;
16584         case -ENOTSUP:
16585                 printf("function not implemented\n");
16586                 break;
16587         default:
16588                 printf("programming error: (%s)\n", strerror(-ret));
16589         }
16590 }
16591
16592 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16593         .f = cmd_ptype_mapping_replace_parsed,
16594         .data = NULL,
16595         .help_str =
16596                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16597         .tokens = {
16598                 (void *)&cmd_ptype_mapping_replace_ptype,
16599                 (void *)&cmd_ptype_mapping_replace_mapping,
16600                 (void *)&cmd_ptype_mapping_replace_replace,
16601                 (void *)&cmd_ptype_mapping_replace_port_id,
16602                 (void *)&cmd_ptype_mapping_replace_target,
16603                 (void *)&cmd_ptype_mapping_replace_mask,
16604                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16605                 NULL,
16606         },
16607 };
16608
16609 /* ptype mapping reset */
16610
16611 /* Common result structure for ptype mapping reset */
16612 struct cmd_ptype_mapping_reset_result {
16613         cmdline_fixed_string_t ptype;
16614         cmdline_fixed_string_t mapping;
16615         cmdline_fixed_string_t reset;
16616         portid_t port_id;
16617 };
16618
16619 /* Common CLI fields for ptype mapping reset*/
16620 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16621         TOKEN_STRING_INITIALIZER
16622                 (struct cmd_ptype_mapping_reset_result,
16623                  ptype, "ptype");
16624 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16625         TOKEN_STRING_INITIALIZER
16626                 (struct cmd_ptype_mapping_reset_result,
16627                  mapping, "mapping");
16628 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16629         TOKEN_STRING_INITIALIZER
16630                 (struct cmd_ptype_mapping_reset_result,
16631                  reset, "reset");
16632 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16633         TOKEN_NUM_INITIALIZER
16634                 (struct cmd_ptype_mapping_reset_result,
16635                  port_id, UINT16);
16636
16637 static void
16638 cmd_ptype_mapping_reset_parsed(
16639         void *parsed_result,
16640         __attribute__((unused)) struct cmdline *cl,
16641         __attribute__((unused)) void *data)
16642 {
16643         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16644         int ret = -ENOTSUP;
16645
16646         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16647                 return;
16648
16649 #ifdef RTE_LIBRTE_I40E_PMD
16650         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16651 #endif
16652
16653         switch (ret) {
16654         case 0:
16655                 break;
16656         case -ENODEV:
16657                 printf("invalid port_id %d\n", res->port_id);
16658                 break;
16659         case -ENOTSUP:
16660                 printf("function not implemented\n");
16661                 break;
16662         default:
16663                 printf("programming error: (%s)\n", strerror(-ret));
16664         }
16665 }
16666
16667 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16668         .f = cmd_ptype_mapping_reset_parsed,
16669         .data = NULL,
16670         .help_str = "ptype mapping reset <port_id>",
16671         .tokens = {
16672                 (void *)&cmd_ptype_mapping_reset_ptype,
16673                 (void *)&cmd_ptype_mapping_reset_mapping,
16674                 (void *)&cmd_ptype_mapping_reset_reset,
16675                 (void *)&cmd_ptype_mapping_reset_port_id,
16676                 NULL,
16677         },
16678 };
16679
16680 /* ptype mapping update */
16681
16682 /* Common result structure for ptype mapping update */
16683 struct cmd_ptype_mapping_update_result {
16684         cmdline_fixed_string_t ptype;
16685         cmdline_fixed_string_t mapping;
16686         cmdline_fixed_string_t reset;
16687         portid_t port_id;
16688         uint8_t hw_ptype;
16689         uint32_t sw_ptype;
16690 };
16691
16692 /* Common CLI fields for ptype mapping update*/
16693 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16694         TOKEN_STRING_INITIALIZER
16695                 (struct cmd_ptype_mapping_update_result,
16696                  ptype, "ptype");
16697 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16698         TOKEN_STRING_INITIALIZER
16699                 (struct cmd_ptype_mapping_update_result,
16700                  mapping, "mapping");
16701 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16702         TOKEN_STRING_INITIALIZER
16703                 (struct cmd_ptype_mapping_update_result,
16704                  reset, "update");
16705 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16706         TOKEN_NUM_INITIALIZER
16707                 (struct cmd_ptype_mapping_update_result,
16708                  port_id, UINT16);
16709 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16710         TOKEN_NUM_INITIALIZER
16711                 (struct cmd_ptype_mapping_update_result,
16712                  hw_ptype, UINT8);
16713 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16714         TOKEN_NUM_INITIALIZER
16715                 (struct cmd_ptype_mapping_update_result,
16716                  sw_ptype, UINT32);
16717
16718 static void
16719 cmd_ptype_mapping_update_parsed(
16720         void *parsed_result,
16721         __attribute__((unused)) struct cmdline *cl,
16722         __attribute__((unused)) void *data)
16723 {
16724         struct cmd_ptype_mapping_update_result *res = parsed_result;
16725         int ret = -ENOTSUP;
16726 #ifdef RTE_LIBRTE_I40E_PMD
16727         struct rte_pmd_i40e_ptype_mapping mapping;
16728 #endif
16729         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16730                 return;
16731
16732 #ifdef RTE_LIBRTE_I40E_PMD
16733         mapping.hw_ptype = res->hw_ptype;
16734         mapping.sw_ptype = res->sw_ptype;
16735         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16736                                                 &mapping,
16737                                                 1,
16738                                                 0);
16739 #endif
16740
16741         switch (ret) {
16742         case 0:
16743                 break;
16744         case -EINVAL:
16745                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16746                 break;
16747         case -ENODEV:
16748                 printf("invalid port_id %d\n", res->port_id);
16749                 break;
16750         case -ENOTSUP:
16751                 printf("function not implemented\n");
16752                 break;
16753         default:
16754                 printf("programming error: (%s)\n", strerror(-ret));
16755         }
16756 }
16757
16758 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16759         .f = cmd_ptype_mapping_update_parsed,
16760         .data = NULL,
16761         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16762         .tokens = {
16763                 (void *)&cmd_ptype_mapping_update_ptype,
16764                 (void *)&cmd_ptype_mapping_update_mapping,
16765                 (void *)&cmd_ptype_mapping_update_update,
16766                 (void *)&cmd_ptype_mapping_update_port_id,
16767                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16768                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16769                 NULL,
16770         },
16771 };
16772
16773 /* Common result structure for file commands */
16774 struct cmd_cmdfile_result {
16775         cmdline_fixed_string_t load;
16776         cmdline_fixed_string_t filename;
16777 };
16778
16779 /* Common CLI fields for file commands */
16780 cmdline_parse_token_string_t cmd_load_cmdfile =
16781         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16782 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16783         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16784
16785 static void
16786 cmd_load_from_file_parsed(
16787         void *parsed_result,
16788         __attribute__((unused)) struct cmdline *cl,
16789         __attribute__((unused)) void *data)
16790 {
16791         struct cmd_cmdfile_result *res = parsed_result;
16792
16793         cmdline_read_from_file(res->filename);
16794 }
16795
16796 cmdline_parse_inst_t cmd_load_from_file = {
16797         .f = cmd_load_from_file_parsed,
16798         .data = NULL,
16799         .help_str = "load <filename>",
16800         .tokens = {
16801                 (void *)&cmd_load_cmdfile,
16802                 (void *)&cmd_load_cmdfile_filename,
16803                 NULL,
16804         },
16805 };
16806
16807 /* Get Rx offloads capabilities */
16808 struct cmd_rx_offload_get_capa_result {
16809         cmdline_fixed_string_t show;
16810         cmdline_fixed_string_t port;
16811         portid_t port_id;
16812         cmdline_fixed_string_t rx_offload;
16813         cmdline_fixed_string_t capabilities;
16814 };
16815
16816 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16817         TOKEN_STRING_INITIALIZER
16818                 (struct cmd_rx_offload_get_capa_result,
16819                  show, "show");
16820 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16821         TOKEN_STRING_INITIALIZER
16822                 (struct cmd_rx_offload_get_capa_result,
16823                  port, "port");
16824 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16825         TOKEN_NUM_INITIALIZER
16826                 (struct cmd_rx_offload_get_capa_result,
16827                  port_id, UINT16);
16828 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16829         TOKEN_STRING_INITIALIZER
16830                 (struct cmd_rx_offload_get_capa_result,
16831                  rx_offload, "rx_offload");
16832 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16833         TOKEN_STRING_INITIALIZER
16834                 (struct cmd_rx_offload_get_capa_result,
16835                  capabilities, "capabilities");
16836
16837 static void
16838 print_rx_offloads(uint64_t offloads)
16839 {
16840         uint64_t single_offload;
16841         int begin;
16842         int end;
16843         int bit;
16844
16845         if (offloads == 0)
16846                 return;
16847
16848         begin = __builtin_ctzll(offloads);
16849         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16850
16851         single_offload = 1 << begin;
16852         for (bit = begin; bit < end; bit++) {
16853                 if (offloads & single_offload)
16854                         printf(" %s",
16855                                rte_eth_dev_rx_offload_name(single_offload));
16856                 single_offload <<= 1;
16857         }
16858 }
16859
16860 static void
16861 cmd_rx_offload_get_capa_parsed(
16862         void *parsed_result,
16863         __attribute__((unused)) struct cmdline *cl,
16864         __attribute__((unused)) void *data)
16865 {
16866         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16867         struct rte_eth_dev_info dev_info;
16868         portid_t port_id = res->port_id;
16869         uint64_t queue_offloads;
16870         uint64_t port_offloads;
16871
16872         rte_eth_dev_info_get(port_id, &dev_info);
16873         queue_offloads = dev_info.rx_queue_offload_capa;
16874         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16875
16876         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16877         printf("  Per Queue :");
16878         print_rx_offloads(queue_offloads);
16879
16880         printf("\n");
16881         printf("  Per Port  :");
16882         print_rx_offloads(port_offloads);
16883         printf("\n\n");
16884 }
16885
16886 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16887         .f = cmd_rx_offload_get_capa_parsed,
16888         .data = NULL,
16889         .help_str = "show port <port_id> rx_offload capabilities",
16890         .tokens = {
16891                 (void *)&cmd_rx_offload_get_capa_show,
16892                 (void *)&cmd_rx_offload_get_capa_port,
16893                 (void *)&cmd_rx_offload_get_capa_port_id,
16894                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16895                 (void *)&cmd_rx_offload_get_capa_capabilities,
16896                 NULL,
16897         }
16898 };
16899
16900 /* Get Rx offloads configuration */
16901 struct cmd_rx_offload_get_configuration_result {
16902         cmdline_fixed_string_t show;
16903         cmdline_fixed_string_t port;
16904         portid_t port_id;
16905         cmdline_fixed_string_t rx_offload;
16906         cmdline_fixed_string_t configuration;
16907 };
16908
16909 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16910         TOKEN_STRING_INITIALIZER
16911                 (struct cmd_rx_offload_get_configuration_result,
16912                  show, "show");
16913 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16914         TOKEN_STRING_INITIALIZER
16915                 (struct cmd_rx_offload_get_configuration_result,
16916                  port, "port");
16917 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16918         TOKEN_NUM_INITIALIZER
16919                 (struct cmd_rx_offload_get_configuration_result,
16920                  port_id, UINT16);
16921 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16922         TOKEN_STRING_INITIALIZER
16923                 (struct cmd_rx_offload_get_configuration_result,
16924                  rx_offload, "rx_offload");
16925 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16926         TOKEN_STRING_INITIALIZER
16927                 (struct cmd_rx_offload_get_configuration_result,
16928                  configuration, "configuration");
16929
16930 static void
16931 cmd_rx_offload_get_configuration_parsed(
16932         void *parsed_result,
16933         __attribute__((unused)) struct cmdline *cl,
16934         __attribute__((unused)) void *data)
16935 {
16936         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16937         struct rte_eth_dev_info dev_info;
16938         portid_t port_id = res->port_id;
16939         struct rte_port *port = &ports[port_id];
16940         uint64_t port_offloads;
16941         uint64_t queue_offloads;
16942         uint16_t nb_rx_queues;
16943         int q;
16944
16945         printf("Rx Offloading Configuration of port %d :\n", port_id);
16946
16947         port_offloads = port->dev_conf.rxmode.offloads;
16948         printf("  Port :");
16949         print_rx_offloads(port_offloads);
16950         printf("\n");
16951
16952         rte_eth_dev_info_get(port_id, &dev_info);
16953         nb_rx_queues = dev_info.nb_rx_queues;
16954         for (q = 0; q < nb_rx_queues; q++) {
16955                 queue_offloads = port->rx_conf[q].offloads;
16956                 printf("  Queue[%2d] :", q);
16957                 print_rx_offloads(queue_offloads);
16958                 printf("\n");
16959         }
16960         printf("\n");
16961 }
16962
16963 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16964         .f = cmd_rx_offload_get_configuration_parsed,
16965         .data = NULL,
16966         .help_str = "show port <port_id> rx_offload configuration",
16967         .tokens = {
16968                 (void *)&cmd_rx_offload_get_configuration_show,
16969                 (void *)&cmd_rx_offload_get_configuration_port,
16970                 (void *)&cmd_rx_offload_get_configuration_port_id,
16971                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16972                 (void *)&cmd_rx_offload_get_configuration_configuration,
16973                 NULL,
16974         }
16975 };
16976
16977 /* Enable/Disable a per port offloading */
16978 struct cmd_config_per_port_rx_offload_result {
16979         cmdline_fixed_string_t port;
16980         cmdline_fixed_string_t config;
16981         portid_t port_id;
16982         cmdline_fixed_string_t rx_offload;
16983         cmdline_fixed_string_t offload;
16984         cmdline_fixed_string_t on_off;
16985 };
16986
16987 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16988         TOKEN_STRING_INITIALIZER
16989                 (struct cmd_config_per_port_rx_offload_result,
16990                  port, "port");
16991 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16992         TOKEN_STRING_INITIALIZER
16993                 (struct cmd_config_per_port_rx_offload_result,
16994                  config, "config");
16995 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16996         TOKEN_NUM_INITIALIZER
16997                 (struct cmd_config_per_port_rx_offload_result,
16998                  port_id, UINT16);
16999 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17000         TOKEN_STRING_INITIALIZER
17001                 (struct cmd_config_per_port_rx_offload_result,
17002                  rx_offload, "rx_offload");
17003 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17004         TOKEN_STRING_INITIALIZER
17005                 (struct cmd_config_per_port_rx_offload_result,
17006                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17007                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17008                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17009                            "crc_strip#scatter#timestamp#security");
17010 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17011         TOKEN_STRING_INITIALIZER
17012                 (struct cmd_config_per_port_rx_offload_result,
17013                  on_off, "on#off");
17014
17015 static uint64_t
17016 search_rx_offload(const char *name)
17017 {
17018         uint64_t single_offload;
17019         const char *single_name;
17020         int found = 0;
17021         unsigned int bit;
17022
17023         single_offload = 1;
17024         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17025                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17026                 if (!strcasecmp(single_name, name)) {
17027                         found = 1;
17028                         break;
17029                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17030                         break;
17031                 else if (single_name == NULL)
17032                         break;
17033                 single_offload <<= 1;
17034         }
17035
17036         if (found)
17037                 return single_offload;
17038
17039         return 0;
17040 }
17041
17042 static void
17043 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17044                                 __attribute__((unused)) struct cmdline *cl,
17045                                 __attribute__((unused)) void *data)
17046 {
17047         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17048         portid_t port_id = res->port_id;
17049         struct rte_eth_dev_info dev_info;
17050         struct rte_port *port = &ports[port_id];
17051         uint64_t single_offload;
17052         uint16_t nb_rx_queues;
17053         int q;
17054
17055         if (port->port_status != RTE_PORT_STOPPED) {
17056                 printf("Error: Can't config offload when Port %d "
17057                        "is not stopped\n", port_id);
17058                 return;
17059         }
17060
17061         single_offload = search_rx_offload(res->offload);
17062         if (single_offload == 0) {
17063                 printf("Unknown offload name: %s\n", res->offload);
17064                 return;
17065         }
17066
17067         rte_eth_dev_info_get(port_id, &dev_info);
17068         nb_rx_queues = dev_info.nb_rx_queues;
17069         if (!strcmp(res->on_off, "on")) {
17070                 port->dev_conf.rxmode.offloads |= single_offload;
17071                 for (q = 0; q < nb_rx_queues; q++)
17072                         port->rx_conf[q].offloads |= single_offload;
17073         } else {
17074                 port->dev_conf.rxmode.offloads &= ~single_offload;
17075                 for (q = 0; q < nb_rx_queues; q++)
17076                         port->rx_conf[q].offloads &= ~single_offload;
17077         }
17078
17079         cmd_reconfig_device_queue(port_id, 1, 1);
17080 }
17081
17082 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17083         .f = cmd_config_per_port_rx_offload_parsed,
17084         .data = NULL,
17085         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17086                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17087                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17088                     "jumbo_frame|crc_strip|scatter|timestamp|security "
17089                     "on|off",
17090         .tokens = {
17091                 (void *)&cmd_config_per_port_rx_offload_result_port,
17092                 (void *)&cmd_config_per_port_rx_offload_result_config,
17093                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17094                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17095                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17096                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17097                 NULL,
17098         }
17099 };
17100
17101 /* Enable/Disable a per queue offloading */
17102 struct cmd_config_per_queue_rx_offload_result {
17103         cmdline_fixed_string_t port;
17104         portid_t port_id;
17105         cmdline_fixed_string_t rxq;
17106         uint16_t queue_id;
17107         cmdline_fixed_string_t rx_offload;
17108         cmdline_fixed_string_t offload;
17109         cmdline_fixed_string_t on_off;
17110 };
17111
17112 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17113         TOKEN_STRING_INITIALIZER
17114                 (struct cmd_config_per_queue_rx_offload_result,
17115                  port, "port");
17116 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17117         TOKEN_NUM_INITIALIZER
17118                 (struct cmd_config_per_queue_rx_offload_result,
17119                  port_id, UINT16);
17120 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17121         TOKEN_STRING_INITIALIZER
17122                 (struct cmd_config_per_queue_rx_offload_result,
17123                  rxq, "rxq");
17124 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17125         TOKEN_NUM_INITIALIZER
17126                 (struct cmd_config_per_queue_rx_offload_result,
17127                  queue_id, UINT16);
17128 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17129         TOKEN_STRING_INITIALIZER
17130                 (struct cmd_config_per_queue_rx_offload_result,
17131                  rx_offload, "rx_offload");
17132 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17133         TOKEN_STRING_INITIALIZER
17134                 (struct cmd_config_per_queue_rx_offload_result,
17135                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17136                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17137                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17138                            "crc_strip#scatter#timestamp#security");
17139 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17140         TOKEN_STRING_INITIALIZER
17141                 (struct cmd_config_per_queue_rx_offload_result,
17142                  on_off, "on#off");
17143
17144 static void
17145 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17146                                 __attribute__((unused)) struct cmdline *cl,
17147                                 __attribute__((unused)) void *data)
17148 {
17149         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17150         struct rte_eth_dev_info dev_info;
17151         portid_t port_id = res->port_id;
17152         uint16_t queue_id = res->queue_id;
17153         struct rte_port *port = &ports[port_id];
17154         uint64_t single_offload;
17155
17156         if (port->port_status != RTE_PORT_STOPPED) {
17157                 printf("Error: Can't config offload when Port %d "
17158                        "is not stopped\n", port_id);
17159                 return;
17160         }
17161
17162         rte_eth_dev_info_get(port_id, &dev_info);
17163         if (queue_id >= dev_info.nb_rx_queues) {
17164                 printf("Error: input queue_id should be 0 ... "
17165                        "%d\n", dev_info.nb_rx_queues - 1);
17166                 return;
17167         }
17168
17169         single_offload = search_rx_offload(res->offload);
17170         if (single_offload == 0) {
17171                 printf("Unknown offload name: %s\n", res->offload);
17172                 return;
17173         }
17174
17175         if (!strcmp(res->on_off, "on"))
17176                 port->rx_conf[queue_id].offloads |= single_offload;
17177         else
17178                 port->rx_conf[queue_id].offloads &= ~single_offload;
17179
17180         cmd_reconfig_device_queue(port_id, 1, 1);
17181 }
17182
17183 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17184         .f = cmd_config_per_queue_rx_offload_parsed,
17185         .data = NULL,
17186         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17187                     "vlan_strip|ipv4_cksum|"
17188                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17189                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17190                     "jumbo_frame|crc_strip|scatter|timestamp|security "
17191                     "on|off",
17192         .tokens = {
17193                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17194                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17195                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17196                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17197                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17198                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17199                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17200                 NULL,
17201         }
17202 };
17203
17204 /* Get Tx offloads capabilities */
17205 struct cmd_tx_offload_get_capa_result {
17206         cmdline_fixed_string_t show;
17207         cmdline_fixed_string_t port;
17208         portid_t port_id;
17209         cmdline_fixed_string_t tx_offload;
17210         cmdline_fixed_string_t capabilities;
17211 };
17212
17213 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17214         TOKEN_STRING_INITIALIZER
17215                 (struct cmd_tx_offload_get_capa_result,
17216                  show, "show");
17217 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17218         TOKEN_STRING_INITIALIZER
17219                 (struct cmd_tx_offload_get_capa_result,
17220                  port, "port");
17221 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17222         TOKEN_NUM_INITIALIZER
17223                 (struct cmd_tx_offload_get_capa_result,
17224                  port_id, UINT16);
17225 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
17226         TOKEN_STRING_INITIALIZER
17227                 (struct cmd_tx_offload_get_capa_result,
17228                  tx_offload, "tx_offload");
17229 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
17230         TOKEN_STRING_INITIALIZER
17231                 (struct cmd_tx_offload_get_capa_result,
17232                  capabilities, "capabilities");
17233
17234 static void
17235 print_tx_offloads(uint64_t offloads)
17236 {
17237         uint64_t single_offload;
17238         int begin;
17239         int end;
17240         int bit;
17241
17242         if (offloads == 0)
17243                 return;
17244
17245         begin = __builtin_ctzll(offloads);
17246         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17247
17248         single_offload = 1 << begin;
17249         for (bit = begin; bit < end; bit++) {
17250                 if (offloads & single_offload)
17251                         printf(" %s",
17252                                rte_eth_dev_tx_offload_name(single_offload));
17253                 single_offload <<= 1;
17254         }
17255 }
17256
17257 static void
17258 cmd_tx_offload_get_capa_parsed(
17259         void *parsed_result,
17260         __attribute__((unused)) struct cmdline *cl,
17261         __attribute__((unused)) void *data)
17262 {
17263         struct cmd_tx_offload_get_capa_result *res = parsed_result;
17264         struct rte_eth_dev_info dev_info;
17265         portid_t port_id = res->port_id;
17266         uint64_t queue_offloads;
17267         uint64_t port_offloads;
17268
17269         rte_eth_dev_info_get(port_id, &dev_info);
17270         queue_offloads = dev_info.tx_queue_offload_capa;
17271         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
17272
17273         printf("Tx Offloading Capabilities of port %d :\n", port_id);
17274         printf("  Per Queue :");
17275         print_tx_offloads(queue_offloads);
17276
17277         printf("\n");
17278         printf("  Per Port  :");
17279         print_tx_offloads(port_offloads);
17280         printf("\n\n");
17281 }
17282
17283 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
17284         .f = cmd_tx_offload_get_capa_parsed,
17285         .data = NULL,
17286         .help_str = "show port <port_id> tx_offload capabilities",
17287         .tokens = {
17288                 (void *)&cmd_tx_offload_get_capa_show,
17289                 (void *)&cmd_tx_offload_get_capa_port,
17290                 (void *)&cmd_tx_offload_get_capa_port_id,
17291                 (void *)&cmd_tx_offload_get_capa_tx_offload,
17292                 (void *)&cmd_tx_offload_get_capa_capabilities,
17293                 NULL,
17294         }
17295 };
17296
17297 /* Get Tx offloads configuration */
17298 struct cmd_tx_offload_get_configuration_result {
17299         cmdline_fixed_string_t show;
17300         cmdline_fixed_string_t port;
17301         portid_t port_id;
17302         cmdline_fixed_string_t tx_offload;
17303         cmdline_fixed_string_t configuration;
17304 };
17305
17306 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
17307         TOKEN_STRING_INITIALIZER
17308                 (struct cmd_tx_offload_get_configuration_result,
17309                  show, "show");
17310 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
17311         TOKEN_STRING_INITIALIZER
17312                 (struct cmd_tx_offload_get_configuration_result,
17313                  port, "port");
17314 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
17315         TOKEN_NUM_INITIALIZER
17316                 (struct cmd_tx_offload_get_configuration_result,
17317                  port_id, UINT16);
17318 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
17319         TOKEN_STRING_INITIALIZER
17320                 (struct cmd_tx_offload_get_configuration_result,
17321                  tx_offload, "tx_offload");
17322 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
17323         TOKEN_STRING_INITIALIZER
17324                 (struct cmd_tx_offload_get_configuration_result,
17325                  configuration, "configuration");
17326
17327 static void
17328 cmd_tx_offload_get_configuration_parsed(
17329         void *parsed_result,
17330         __attribute__((unused)) struct cmdline *cl,
17331         __attribute__((unused)) void *data)
17332 {
17333         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
17334         struct rte_eth_dev_info dev_info;
17335         portid_t port_id = res->port_id;
17336         struct rte_port *port = &ports[port_id];
17337         uint64_t port_offloads;
17338         uint64_t queue_offloads;
17339         uint16_t nb_tx_queues;
17340         int q;
17341
17342         printf("Tx Offloading Configuration of port %d :\n", port_id);
17343
17344         port_offloads = port->dev_conf.txmode.offloads;
17345         printf("  Port :");
17346         print_tx_offloads(port_offloads);
17347         printf("\n");
17348
17349         rte_eth_dev_info_get(port_id, &dev_info);
17350         nb_tx_queues = dev_info.nb_tx_queues;
17351         for (q = 0; q < nb_tx_queues; q++) {
17352                 queue_offloads = port->tx_conf[q].offloads;
17353                 printf("  Queue[%2d] :", q);
17354                 print_tx_offloads(queue_offloads);
17355                 printf("\n");
17356         }
17357         printf("\n");
17358 }
17359
17360 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17361         .f = cmd_tx_offload_get_configuration_parsed,
17362         .data = NULL,
17363         .help_str = "show port <port_id> tx_offload configuration",
17364         .tokens = {
17365                 (void *)&cmd_tx_offload_get_configuration_show,
17366                 (void *)&cmd_tx_offload_get_configuration_port,
17367                 (void *)&cmd_tx_offload_get_configuration_port_id,
17368                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17369                 (void *)&cmd_tx_offload_get_configuration_configuration,
17370                 NULL,
17371         }
17372 };
17373
17374 /* Enable/Disable a per port offloading */
17375 struct cmd_config_per_port_tx_offload_result {
17376         cmdline_fixed_string_t port;
17377         cmdline_fixed_string_t config;
17378         portid_t port_id;
17379         cmdline_fixed_string_t tx_offload;
17380         cmdline_fixed_string_t offload;
17381         cmdline_fixed_string_t on_off;
17382 };
17383
17384 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17385         TOKEN_STRING_INITIALIZER
17386                 (struct cmd_config_per_port_tx_offload_result,
17387                  port, "port");
17388 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17389         TOKEN_STRING_INITIALIZER
17390                 (struct cmd_config_per_port_tx_offload_result,
17391                  config, "config");
17392 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17393         TOKEN_NUM_INITIALIZER
17394                 (struct cmd_config_per_port_tx_offload_result,
17395                  port_id, UINT16);
17396 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17397         TOKEN_STRING_INITIALIZER
17398                 (struct cmd_config_per_port_tx_offload_result,
17399                  tx_offload, "tx_offload");
17400 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17401         TOKEN_STRING_INITIALIZER
17402                 (struct cmd_config_per_port_tx_offload_result,
17403                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17404                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17405                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17406                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17407                           "mt_lockfree#multi_segs#fast_free#security");
17408 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17409         TOKEN_STRING_INITIALIZER
17410                 (struct cmd_config_per_port_tx_offload_result,
17411                  on_off, "on#off");
17412
17413 static uint64_t
17414 search_tx_offload(const char *name)
17415 {
17416         uint64_t single_offload;
17417         const char *single_name;
17418         int found = 0;
17419         unsigned int bit;
17420
17421         single_offload = 1;
17422         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17423                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17424                 if (!strcasecmp(single_name, name)) {
17425                         found = 1;
17426                         break;
17427                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17428                         break;
17429                 else if (single_name == NULL)
17430                         break;
17431                 single_offload <<= 1;
17432         }
17433
17434         if (found)
17435                 return single_offload;
17436
17437         return 0;
17438 }
17439
17440 static void
17441 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17442                                 __attribute__((unused)) struct cmdline *cl,
17443                                 __attribute__((unused)) void *data)
17444 {
17445         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17446         portid_t port_id = res->port_id;
17447         struct rte_eth_dev_info dev_info;
17448         struct rte_port *port = &ports[port_id];
17449         uint64_t single_offload;
17450         uint16_t nb_tx_queues;
17451         int q;
17452
17453         if (port->port_status != RTE_PORT_STOPPED) {
17454                 printf("Error: Can't config offload when Port %d "
17455                        "is not stopped\n", port_id);
17456                 return;
17457         }
17458
17459         single_offload = search_tx_offload(res->offload);
17460         if (single_offload == 0) {
17461                 printf("Unknown offload name: %s\n", res->offload);
17462                 return;
17463         }
17464
17465         rte_eth_dev_info_get(port_id, &dev_info);
17466         nb_tx_queues = dev_info.nb_tx_queues;
17467         if (!strcmp(res->on_off, "on")) {
17468                 port->dev_conf.txmode.offloads |= single_offload;
17469                 for (q = 0; q < nb_tx_queues; q++)
17470                         port->tx_conf[q].offloads |= single_offload;
17471         } else {
17472                 port->dev_conf.txmode.offloads &= ~single_offload;
17473                 for (q = 0; q < nb_tx_queues; q++)
17474                         port->tx_conf[q].offloads &= ~single_offload;
17475         }
17476
17477         cmd_reconfig_device_queue(port_id, 1, 1);
17478 }
17479
17480 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17481         .f = cmd_config_per_port_tx_offload_parsed,
17482         .data = NULL,
17483         .help_str = "port config <port_id> tx_offload "
17484                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17485                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17486                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17487                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17488                     "mt_lockfree|multi_segs|fast_free|security "
17489                     "on|off",
17490         .tokens = {
17491                 (void *)&cmd_config_per_port_tx_offload_result_port,
17492                 (void *)&cmd_config_per_port_tx_offload_result_config,
17493                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17494                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17495                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17496                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17497                 NULL,
17498         }
17499 };
17500
17501 /* Enable/Disable a per queue offloading */
17502 struct cmd_config_per_queue_tx_offload_result {
17503         cmdline_fixed_string_t port;
17504         portid_t port_id;
17505         cmdline_fixed_string_t txq;
17506         uint16_t queue_id;
17507         cmdline_fixed_string_t tx_offload;
17508         cmdline_fixed_string_t offload;
17509         cmdline_fixed_string_t on_off;
17510 };
17511
17512 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17513         TOKEN_STRING_INITIALIZER
17514                 (struct cmd_config_per_queue_tx_offload_result,
17515                  port, "port");
17516 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17517         TOKEN_NUM_INITIALIZER
17518                 (struct cmd_config_per_queue_tx_offload_result,
17519                  port_id, UINT16);
17520 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17521         TOKEN_STRING_INITIALIZER
17522                 (struct cmd_config_per_queue_tx_offload_result,
17523                  txq, "txq");
17524 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17525         TOKEN_NUM_INITIALIZER
17526                 (struct cmd_config_per_queue_tx_offload_result,
17527                  queue_id, UINT16);
17528 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17529         TOKEN_STRING_INITIALIZER
17530                 (struct cmd_config_per_queue_tx_offload_result,
17531                  tx_offload, "tx_offload");
17532 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17533         TOKEN_STRING_INITIALIZER
17534                 (struct cmd_config_per_queue_tx_offload_result,
17535                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17536                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17537                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17538                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17539                           "mt_lockfree#multi_segs#fast_free#security");
17540 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17541         TOKEN_STRING_INITIALIZER
17542                 (struct cmd_config_per_queue_tx_offload_result,
17543                  on_off, "on#off");
17544
17545 static void
17546 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17547                                 __attribute__((unused)) struct cmdline *cl,
17548                                 __attribute__((unused)) void *data)
17549 {
17550         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17551         struct rte_eth_dev_info dev_info;
17552         portid_t port_id = res->port_id;
17553         uint16_t queue_id = res->queue_id;
17554         struct rte_port *port = &ports[port_id];
17555         uint64_t single_offload;
17556
17557         if (port->port_status != RTE_PORT_STOPPED) {
17558                 printf("Error: Can't config offload when Port %d "
17559                        "is not stopped\n", port_id);
17560                 return;
17561         }
17562
17563         rte_eth_dev_info_get(port_id, &dev_info);
17564         if (queue_id >= dev_info.nb_tx_queues) {
17565                 printf("Error: input queue_id should be 0 ... "
17566                        "%d\n", dev_info.nb_tx_queues - 1);
17567                 return;
17568         }
17569
17570         single_offload = search_tx_offload(res->offload);
17571         if (single_offload == 0) {
17572                 printf("Unknown offload name: %s\n", res->offload);
17573                 return;
17574         }
17575
17576         if (!strcmp(res->on_off, "on"))
17577                 port->tx_conf[queue_id].offloads |= single_offload;
17578         else
17579                 port->tx_conf[queue_id].offloads &= ~single_offload;
17580
17581         cmd_reconfig_device_queue(port_id, 1, 1);
17582 }
17583
17584 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17585         .f = cmd_config_per_queue_tx_offload_parsed,
17586         .data = NULL,
17587         .help_str = "port <port_id> txq <queue_id> tx_offload "
17588                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17589                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17590                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17591                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17592                     "mt_lockfree|multi_segs|fast_free|security "
17593                     "on|off",
17594         .tokens = {
17595                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17596                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17597                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17598                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17599                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17600                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17601                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17602                 NULL,
17603         }
17604 };
17605
17606 /* ******************************************************************************** */
17607
17608 /* list of instructions */
17609 cmdline_parse_ctx_t main_ctx[] = {
17610         (cmdline_parse_inst_t *)&cmd_help_brief,
17611         (cmdline_parse_inst_t *)&cmd_help_long,
17612         (cmdline_parse_inst_t *)&cmd_quit,
17613         (cmdline_parse_inst_t *)&cmd_load_from_file,
17614         (cmdline_parse_inst_t *)&cmd_showport,
17615         (cmdline_parse_inst_t *)&cmd_showqueue,
17616         (cmdline_parse_inst_t *)&cmd_showportall,
17617         (cmdline_parse_inst_t *)&cmd_showcfg,
17618         (cmdline_parse_inst_t *)&cmd_start,
17619         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17620         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17621         (cmdline_parse_inst_t *)&cmd_set_link_up,
17622         (cmdline_parse_inst_t *)&cmd_set_link_down,
17623         (cmdline_parse_inst_t *)&cmd_reset,
17624         (cmdline_parse_inst_t *)&cmd_set_numbers,
17625         (cmdline_parse_inst_t *)&cmd_set_log,
17626         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17627         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17628         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17629         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17630         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17631         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17632         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17633         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17634         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17635         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17636         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17637         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17638         (cmdline_parse_inst_t *)&cmd_set_link_check,
17639         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17640         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17641         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17642         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17643 #ifdef RTE_LIBRTE_PMD_BOND
17644         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17645         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17646         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17647         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17648         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17649         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17650         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17651         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17652         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17653         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17654         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17655 #endif
17656         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17657         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17658         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17659         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17660         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17661         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17662         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17663         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17664         (cmdline_parse_inst_t *)&cmd_csum_set,
17665         (cmdline_parse_inst_t *)&cmd_csum_show,
17666         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17667         (cmdline_parse_inst_t *)&cmd_tso_set,
17668         (cmdline_parse_inst_t *)&cmd_tso_show,
17669         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17670         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17671         (cmdline_parse_inst_t *)&cmd_gro_enable,
17672         (cmdline_parse_inst_t *)&cmd_gro_flush,
17673         (cmdline_parse_inst_t *)&cmd_gro_show,
17674         (cmdline_parse_inst_t *)&cmd_gso_enable,
17675         (cmdline_parse_inst_t *)&cmd_gso_size,
17676         (cmdline_parse_inst_t *)&cmd_gso_show,
17677         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17678         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17679         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17680         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17681         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17682         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17683         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17684         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17685         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17686         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17687         (cmdline_parse_inst_t *)&cmd_config_dcb,
17688         (cmdline_parse_inst_t *)&cmd_read_reg,
17689         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17690         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17691         (cmdline_parse_inst_t *)&cmd_write_reg,
17692         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17693         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17694         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17695         (cmdline_parse_inst_t *)&cmd_stop,
17696         (cmdline_parse_inst_t *)&cmd_mac_addr,
17697         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17698         (cmdline_parse_inst_t *)&cmd_set_qmap,
17699         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17700         (cmdline_parse_inst_t *)&cmd_operate_port,
17701         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17702         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17703         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17704         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17705         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17706         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17707         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17708         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17709         (cmdline_parse_inst_t *)&cmd_config_mtu,
17710         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17711         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17712         (cmdline_parse_inst_t *)&cmd_config_rss,
17713         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17714         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17715         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17716         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17717         (cmdline_parse_inst_t *)&cmd_showport_reta,
17718         (cmdline_parse_inst_t *)&cmd_config_burst,
17719         (cmdline_parse_inst_t *)&cmd_config_thresh,
17720         (cmdline_parse_inst_t *)&cmd_config_threshold,
17721         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17722         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17723         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17724         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17725         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17726         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17727         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17728         (cmdline_parse_inst_t *)&cmd_global_config,
17729         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17730         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17731         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17732         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17733         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17734         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17735         (cmdline_parse_inst_t *)&cmd_dump,
17736         (cmdline_parse_inst_t *)&cmd_dump_one,
17737         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17738         (cmdline_parse_inst_t *)&cmd_syn_filter,
17739         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17740         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17741         (cmdline_parse_inst_t *)&cmd_flex_filter,
17742         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17743         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17744         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17745         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17746         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17747         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17748         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17749         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17750         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17751         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17752         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17753         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17754         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17755         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17756         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17757         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17758         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17759         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17760         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17761         (cmdline_parse_inst_t *)&cmd_flow,
17762         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17763         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17764         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17765         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17766         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17767         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17768         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17769         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17770         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17771         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17772         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17773         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17774         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17775         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17776         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17777         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17778         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17779         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17780         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17781         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17782         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17783         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17784         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17785         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17786         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17787         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17788         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17789         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17790         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17791         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17792         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17793         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17794         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17795         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17796         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17797         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17798         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17799         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17800         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17801         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17802         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17803         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17804         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17805         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17806         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17807         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17808         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17809         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17810         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17811 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17812         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17813 #endif
17814         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17815         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17816         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17817         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17818         (cmdline_parse_inst_t *)&cmd_ddp_add,
17819         (cmdline_parse_inst_t *)&cmd_ddp_del,
17820         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17821         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17822         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17823         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17824         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17825         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17826         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17827         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17828         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17829         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17830
17831         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17832         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17833         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17834         (cmdline_parse_inst_t *)&cmd_queue_region,
17835         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17836         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17837         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17838         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17839         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17840         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17841         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17842         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17843         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17844         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17845         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17846         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17847         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17848         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17849         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17850         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17851         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17852         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17853         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17854         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17855         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17856         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17857         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17858         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17859         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17860         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17861         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17862         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17863         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17864         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17865         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17866         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17867 #ifdef RTE_LIBRTE_BPF
17868         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17869         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17870 #endif
17871         NULL,
17872 };
17873
17874 /* read cmdline commands from file */
17875 void
17876 cmdline_read_from_file(const char *filename)
17877 {
17878         struct cmdline *cl;
17879
17880         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17881         if (cl == NULL) {
17882                 printf("Failed to create file based cmdline context: %s\n",
17883                        filename);
17884                 return;
17885         }
17886
17887         cmdline_interact(cl);
17888         cmdline_quit(cl);
17889
17890         cmdline_free(cl);
17891
17892         printf("Read CLI commands from %s\n", filename);
17893 }
17894
17895 /* prompt function, called from main on MASTER lcore */
17896 void
17897 prompt(void)
17898 {
17899         int status;
17900
17901         /* initialize non-constant commands */
17902         cmd_set_fwd_mode_init();
17903         cmd_set_fwd_retry_mode_init();
17904
17905 #if defined RTE_LIBRTE_PMD_SOFTNIC
17906         portid_t softnic_portid, pid;
17907         uint8_t softnic_enable = 0;
17908
17909         if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
17910                 RTE_ETH_FOREACH_DEV(pid) {
17911                         struct rte_port *port = &ports[pid];
17912                         const char *driver = port->dev_info.driver_name;
17913
17914                         if (strcmp(driver, "net_softnic") == 0) {
17915                                 softnic_portid = pid;
17916                                 softnic_enable = 1;
17917                                 break;
17918                         }
17919                 }
17920         }
17921 #endif
17922
17923         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17924         if (testpmd_cl == NULL)
17925                 return;
17926
17927         for (;;) {
17928                 status = cmdline_poll(testpmd_cl);
17929                 if (status < 0)
17930                         rte_panic("CLI poll error (%" PRId32 ")\n", status);
17931                 else if (status == RDLINE_EXITED) {
17932                         cmdline_stdin_exit(testpmd_cl);
17933                         rte_exit(0, "\n");
17934                 }
17935
17936 #if defined RTE_LIBRTE_PMD_SOFTNIC
17937
17938         if ((softnic_enable == 1) &&
17939                 (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0))
17940                 rte_pmd_softnic_manage(softnic_portid);
17941 #endif
17942         }
17943 }
17944
17945 void
17946 prompt_exit(void)
17947 {
17948         if (testpmd_cl != NULL)
17949                 cmdline_quit(testpmd_cl);
17950 }
17951
17952 static void
17953 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17954 {
17955         if (id == (portid_t)RTE_PORT_ALL) {
17956                 portid_t pid;
17957
17958                 RTE_ETH_FOREACH_DEV(pid) {
17959                         /* check if need_reconfig has been set to 1 */
17960                         if (ports[pid].need_reconfig == 0)
17961                                 ports[pid].need_reconfig = dev;
17962                         /* check if need_reconfig_queues has been set to 1 */
17963                         if (ports[pid].need_reconfig_queues == 0)
17964                                 ports[pid].need_reconfig_queues = queue;
17965                 }
17966         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17967                 /* check if need_reconfig has been set to 1 */
17968                 if (ports[id].need_reconfig == 0)
17969                         ports[id].need_reconfig = dev;
17970                 /* check if need_reconfig_queues has been set to 1 */
17971                 if (ports[id].need_reconfig_queues == 0)
17972                         ports[id].need_reconfig_queues = queue;
17973         }
17974 }