app/testpmd: fix RSS flow action configuration
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.h"
78
79 static struct cmdline *testpmd_cl;
80
81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
82
83 /* *** Help command with introduction. *** */
84 struct cmd_help_brief_result {
85         cmdline_fixed_string_t help;
86 };
87
88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
89                                   struct cmdline *cl,
90                                   __attribute__((unused)) void *data)
91 {
92         cmdline_printf(
93                 cl,
94                 "\n"
95                 "Help is available for the following sections:\n\n"
96                 "    help control    : Start and stop forwarding.\n"
97                 "    help display    : Displaying port, stats and config "
98                 "information.\n"
99                 "    help config     : Configuration information.\n"
100                 "    help ports      : Configuring ports.\n"
101                 "    help registers  : Reading and setting port registers.\n"
102                 "    help filters    : Filters configuration help.\n"
103                 "    help all        : All of the above sections.\n\n"
104         );
105
106 }
107
108 cmdline_parse_token_string_t cmd_help_brief_help =
109         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
110
111 cmdline_parse_inst_t cmd_help_brief = {
112         .f = cmd_help_brief_parsed,
113         .data = NULL,
114         .help_str = "help: Show help",
115         .tokens = {
116                 (void *)&cmd_help_brief_help,
117                 NULL,
118         },
119 };
120
121 /* *** Help command with help sections. *** */
122 struct cmd_help_long_result {
123         cmdline_fixed_string_t help;
124         cmdline_fixed_string_t section;
125 };
126
127 static void cmd_help_long_parsed(void *parsed_result,
128                                  struct cmdline *cl,
129                                  __attribute__((unused)) void *data)
130 {
131         int show_all = 0;
132         struct cmd_help_long_result *res = parsed_result;
133
134         if (!strcmp(res->section, "all"))
135                 show_all = 1;
136
137         if (show_all || !strcmp(res->section, "control")) {
138
139                 cmdline_printf(
140                         cl,
141                         "\n"
142                         "Control forwarding:\n"
143                         "-------------------\n\n"
144
145                         "start\n"
146                         "    Start packet forwarding with current configuration.\n\n"
147
148                         "start tx_first\n"
149                         "    Start packet forwarding with current config"
150                         " after sending one burst of packets.\n\n"
151
152                         "stop\n"
153                         "    Stop packet forwarding, and display accumulated"
154                         " statistics.\n\n"
155
156                         "quit\n"
157                         "    Quit to prompt.\n\n"
158                 );
159         }
160
161         if (show_all || !strcmp(res->section, "display")) {
162
163                 cmdline_printf(
164                         cl,
165                         "\n"
166                         "Display:\n"
167                         "--------\n\n"
168
169                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
170                         "    Display information for port_id, or all.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
178                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
179                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
180                         "    Display the RSS hash functions and RSS hash key"
181                         " of port X\n\n"
182
183                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
184                         "    Clear information for port_id, or all.\n\n"
185
186                         "show (rxq|txq) info (port_id) (queue_id)\n"
187                         "    Display information for configured RX/TX queue.\n\n"
188
189                         "show config (rxtx|cores|fwd|txpkts)\n"
190                         "    Display the given configuration.\n\n"
191
192                         "read rxd (port_id) (queue_id) (rxd_id)\n"
193                         "    Display an RX descriptor of a port RX queue.\n\n"
194
195                         "read txd (port_id) (queue_id) (txd_id)\n"
196                         "    Display a TX descriptor of a port TX queue.\n\n"
197
198                         "ddp get list (port_id)\n"
199                         "    Get ddp profile info list\n\n"
200
201                         "ddp get info (profile_path)\n"
202                         "    Get ddp profile information.\n\n"
203
204                         "show vf stats (port_id) (vf_id)\n"
205                         "    Display a VF's statistics.\n\n"
206
207                         "clear vf stats (port_id) (vf_id)\n"
208                         "    Reset a VF's statistics.\n\n"
209
210                         "show port (port_id) pctype mapping\n"
211                         "    Get flow ptype to pctype mapping on a port\n\n"
212
213                         "show port meter stats (port_id) (meter_id) (clear)\n"
214                         "    Get meter stats on a port\n\n"
215                         "show port tm cap (port_id)\n"
216                         "       Display the port TM capability.\n\n"
217
218                         "show port tm level cap (port_id) (level_id)\n"
219                         "       Display the port TM hierarchical level capability.\n\n"
220
221                         "show port tm node cap (port_id) (node_id)\n"
222                         "       Display the port TM node capability.\n\n"
223
224                         "show port tm node type (port_id) (node_id)\n"
225                         "       Display the port TM node type.\n\n"
226
227                         "show port tm node stats (port_id) (node_id) (clear)\n"
228                         "       Display the port TM node stats.\n\n"
229
230                 );
231         }
232
233         if (show_all || !strcmp(res->section, "config")) {
234                 cmdline_printf(
235                         cl,
236                         "\n"
237                         "Configuration:\n"
238                         "--------------\n"
239                         "Configuration changes only become active when"
240                         " forwarding is started/restarted.\n\n"
241
242                         "set default\n"
243                         "    Reset forwarding to the default configuration.\n\n"
244
245                         "set verbose (level)\n"
246                         "    Set the debug verbosity level X.\n\n"
247
248                         "set log global|(type) (level)\n"
249                         "    Set the log level.\n\n"
250
251                         "set nbport (num)\n"
252                         "    Set number of ports.\n\n"
253
254                         "set nbcore (num)\n"
255                         "    Set number of cores.\n\n"
256
257                         "set coremask (mask)\n"
258                         "    Set the forwarding cores hexadecimal mask.\n\n"
259
260                         "set portmask (mask)\n"
261                         "    Set the forwarding ports hexadecimal mask.\n\n"
262
263                         "set burst (num)\n"
264                         "    Set number of packets per burst.\n\n"
265
266                         "set burst tx delay (microseconds) retry (num)\n"
267                         "    Set the transmit delay time and number of retries,"
268                         " effective when retry is enabled.\n\n"
269
270                         "set txpkts (x[,y]*)\n"
271                         "    Set the length of each segment of TXONLY"
272                         " and optionally CSUM packets.\n\n"
273
274                         "set txsplit (off|on|rand)\n"
275                         "    Set the split policy for the TX packets."
276                         " Right now only applicable for CSUM and TXONLY"
277                         " modes\n\n"
278
279                         "set corelist (x[,y]*)\n"
280                         "    Set the list of forwarding cores.\n\n"
281
282                         "set portlist (x[,y]*)\n"
283                         "    Set the list of forwarding ports.\n\n"
284
285                         "set tx loopback (port_id) (on|off)\n"
286                         "    Enable or disable tx loopback.\n\n"
287
288                         "set all queues drop (port_id) (on|off)\n"
289                         "    Set drop enable bit for all queues.\n\n"
290
291                         "set vf split drop (port_id) (vf_id) (on|off)\n"
292                         "    Set split drop enable bit for a VF from the PF.\n\n"
293
294                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
295                         "    Set MAC antispoof for a VF from the PF.\n\n"
296
297                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
298                         "    Enable MACsec offload.\n\n"
299
300                         "set macsec offload (port_id) off\n"
301                         "    Disable MACsec offload.\n\n"
302
303                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
304                         "    Configure MACsec secure connection (SC).\n\n"
305
306                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
307                         "    Configure MACsec secure association (SA).\n\n"
308
309                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
310                         "    Set VF broadcast for a VF from the PF.\n\n"
311
312                         "vlan set strip (on|off) (port_id)\n"
313                         "    Set the VLAN strip on a port.\n\n"
314
315                         "vlan set stripq (on|off) (port_id,queue_id)\n"
316                         "    Set the VLAN strip for a queue on a port.\n\n"
317
318                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
319                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
320
321                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
322                         "    Set VLAN insert for a VF from the PF.\n\n"
323
324                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
325                         "    Set VLAN antispoof for a VF from the PF.\n\n"
326
327                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
328                         "    Set VLAN tag for a VF from the PF.\n\n"
329
330                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
331                         "    Set a VF's max bandwidth(Mbps).\n\n"
332
333                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
334                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
335
336                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
337                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
338
339                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
340                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
341
342                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
343                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
344
345                         "vlan set filter (on|off) (port_id)\n"
346                         "    Set the VLAN filter on a port.\n\n"
347
348                         "vlan set qinq (on|off) (port_id)\n"
349                         "    Set the VLAN QinQ (extended queue in queue)"
350                         " on a port.\n\n"
351
352                         "vlan set (inner|outer) tpid (value) (port_id)\n"
353                         "    Set the VLAN TPID for Packet Filtering on"
354                         " a port\n\n"
355
356                         "rx_vlan add (vlan_id|all) (port_id)\n"
357                         "    Add a vlan_id, or all identifiers, to the set"
358                         " of VLAN identifiers filtered by port_id.\n\n"
359
360                         "rx_vlan rm (vlan_id|all) (port_id)\n"
361                         "    Remove a vlan_id, or all identifiers, from the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
365                         "    Add a vlan_id, to the set of VLAN identifiers"
366                         "filtered for VF(s) from port_id.\n\n"
367
368                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Remove a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
373                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
374                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
375                         "   add a tunnel filter of a port.\n\n"
376
377                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
378                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
379                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
380                         "   remove a tunnel filter of a port.\n\n"
381
382                         "rx_vxlan_port add (udp_port) (port_id)\n"
383                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
384
385                         "rx_vxlan_port rm (udp_port) (port_id)\n"
386                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
387
388                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
389                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
390                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
391
392                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
393                         "    Set port based TX VLAN insertion.\n\n"
394
395                         "tx_vlan reset (port_id)\n"
396                         "    Disable hardware insertion of a VLAN header in"
397                         " packets sent on a port.\n\n"
398
399                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
400                         "    Select hardware or software calculation of the"
401                         " checksum when transmitting a packet using the"
402                         " csum forward engine.\n"
403                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
404                         "    outer-ip concerns the outer IP layer in"
405                         " case the packet is recognized as a tunnel packet by"
406                         " the forward engine (vxlan, gre and ipip are supported)\n"
407                         "    Please check the NIC datasheet for HW limits.\n\n"
408
409                         "csum parse-tunnel (on|off) (tx_port_id)\n"
410                         "    If disabled, treat tunnel packets as non-tunneled"
411                         " packets (treat inner headers as payload). The port\n"
412                         "    argument is the port used for TX in csum forward"
413                         " engine.\n\n"
414
415                         "csum show (port_id)\n"
416                         "    Display tx checksum offload configuration\n\n"
417
418                         "tso set (segsize) (portid)\n"
419                         "    Enable TCP Segmentation Offload in csum forward"
420                         " engine.\n"
421                         "    Please check the NIC datasheet for HW limits.\n\n"
422
423                         "tso show (portid)"
424                         "    Display the status of TCP Segmentation Offload.\n\n"
425
426                         "set port (port_id) gro on|off\n"
427                         "    Enable or disable Generic Receive Offload in"
428                         " csum forwarding engine.\n\n"
429
430                         "show port (port_id) gro\n"
431                         "    Display GRO configuration.\n\n"
432
433                         "set gro flush (cycles)\n"
434                         "    Set the cycle to flush GROed packets from"
435                         " reassembly tables.\n\n"
436
437                         "set port (port_id) gso (on|off)"
438                         "    Enable or disable Generic Segmentation Offload in"
439                         " csum forwarding engine.\n\n"
440
441                         "set gso segsz (length)\n"
442                         "    Set max packet length for output GSO segments,"
443                         " including packet header and payload.\n\n"
444
445                         "show port (port_id) gso\n"
446                         "    Show GSO configuration.\n\n"
447
448                         "set fwd (%s)\n"
449                         "    Set packet forwarding mode.\n\n"
450
451                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
452                         "    Add a MAC address on port_id.\n\n"
453
454                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
455                         "    Remove a MAC address from port_id.\n\n"
456
457                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
458                         "    Set the default MAC address for port_id.\n\n"
459
460                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
461                         "    Add a MAC address for a VF on the port.\n\n"
462
463                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
464                         "    Set the MAC address for a VF from the PF.\n\n"
465
466                         "set eth-peer (port_id) (peer_addr)\n"
467                         "    set the peer address for certain port.\n\n"
468
469                         "set port (port_id) uta (mac_address|all) (on|off)\n"
470                         "    Add/Remove a or all unicast hash filter(s)"
471                         "from port X.\n\n"
472
473                         "set promisc (port_id|all) (on|off)\n"
474                         "    Set the promiscuous mode on port_id, or all.\n\n"
475
476                         "set allmulti (port_id|all) (on|off)\n"
477                         "    Set the allmulti mode on port_id, or all.\n\n"
478
479                         "set vf promisc (port_id) (vf_id) (on|off)\n"
480                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
481
482                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
483                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
484
485                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
486                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
487                         " (on|off) autoneg (on|off) (port_id)\n"
488                         "set flow_ctrl rx (on|off) (portid)\n"
489                         "set flow_ctrl tx (on|off) (portid)\n"
490                         "set flow_ctrl high_water (high_water) (portid)\n"
491                         "set flow_ctrl low_water (low_water) (portid)\n"
492                         "set flow_ctrl pause_time (pause_time) (portid)\n"
493                         "set flow_ctrl send_xon (send_xon) (portid)\n"
494                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
495                         "set flow_ctrl autoneg (on|off) (port_id)\n"
496                         "    Set the link flow control parameter on a port.\n\n"
497
498                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
499                         " (low_water) (pause_time) (priority) (port_id)\n"
500                         "    Set the priority flow control parameter on a"
501                         " port.\n\n"
502
503                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
504                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
505                         " queue on port.\n"
506                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
507                         " on port 0 to mapping 5.\n\n"
508
509                         "set xstats-hide-zero on|off\n"
510                         "    Set the option to hide the zero values"
511                         " for xstats display.\n"
512
513                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
514                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
515
516                         "set port (port_id) vf (vf_id) (mac_addr)"
517                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
518                         "   Add/Remove unicast or multicast MAC addr filter"
519                         " for a VF.\n\n"
520
521                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
522                         "|MPE) (on|off)\n"
523                         "    AUPE:accepts untagged VLAN;"
524                         "ROPE:accept unicast hash\n\n"
525                         "    BAM:accepts broadcast packets;"
526                         "MPE:accepts all multicast packets\n\n"
527                         "    Enable/Disable a VF receive mode of a port\n\n"
528
529                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
530                         "    Set rate limit for a queue of a port\n\n"
531
532                         "set port (port_id) vf (vf_id) rate (rate_num) "
533                         "queue_mask (queue_mask_value)\n"
534                         "    Set rate limit for queues in VF of a port\n\n"
535
536                         "set port (port_id) mirror-rule (rule_id)"
537                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
538                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
539                         "   Set pool or vlan type mirror rule on a port.\n"
540                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
541                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
542                         " to pool 0.\n\n"
543
544                         "set port (port_id) mirror-rule (rule_id)"
545                         " (uplink-mirror|downlink-mirror) dst-pool"
546                         " (pool_id) (on|off)\n"
547                         "   Set uplink or downlink type mirror rule on a port.\n"
548                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
549                         " 0 on' enable mirror income traffic to pool 0.\n\n"
550
551                         "reset port (port_id) mirror-rule (rule_id)\n"
552                         "   Reset a mirror rule.\n\n"
553
554                         "set flush_rx (on|off)\n"
555                         "   Flush (default) or don't flush RX streams before"
556                         " forwarding. Mainly used with PCAP drivers.\n\n"
557
558                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
559                         "   Set the bypass mode for the lowest port on bypass enabled"
560                         " NIC.\n\n"
561
562                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
563                         "mode (normal|bypass|isolate) (port_id)\n"
564                         "   Set the event required to initiate specified bypass mode for"
565                         " the lowest port on a bypass enabled NIC where:\n"
566                         "       timeout   = enable bypass after watchdog timeout.\n"
567                         "       os_on     = enable bypass when OS/board is powered on.\n"
568                         "       os_off    = enable bypass when OS/board is powered off.\n"
569                         "       power_on  = enable bypass when power supply is turned on.\n"
570                         "       power_off = enable bypass when power supply is turned off."
571                         "\n\n"
572
573                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
574                         "   Set the bypass watchdog timeout to 'n' seconds"
575                         " where 0 = instant.\n\n"
576
577                         "show bypass config (port_id)\n"
578                         "   Show the bypass configuration for a bypass enabled NIC"
579                         " using the lowest port on the NIC.\n\n"
580
581 #ifdef RTE_LIBRTE_PMD_BOND
582                         "create bonded device (mode) (socket)\n"
583                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
584
585                         "add bonding slave (slave_id) (port_id)\n"
586                         "       Add a slave device to a bonded device.\n\n"
587
588                         "remove bonding slave (slave_id) (port_id)\n"
589                         "       Remove a slave device from a bonded device.\n\n"
590
591                         "set bonding mode (value) (port_id)\n"
592                         "       Set the bonding mode on a bonded device.\n\n"
593
594                         "set bonding primary (slave_id) (port_id)\n"
595                         "       Set the primary slave for a bonded device.\n\n"
596
597                         "show bonding config (port_id)\n"
598                         "       Show the bonding config for port_id.\n\n"
599
600                         "set bonding mac_addr (port_id) (address)\n"
601                         "       Set the MAC address of a bonded device.\n\n"
602
603                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
604                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
605
606                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
607                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
608
609                         "set bonding mon_period (port_id) (value)\n"
610                         "       Set the bonding link status monitoring polling period in ms.\n\n"
611
612                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
613                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
614
615 #endif
616                         "set link-up port (port_id)\n"
617                         "       Set link up for a port.\n\n"
618
619                         "set link-down port (port_id)\n"
620                         "       Set link down for a port.\n\n"
621
622                         "E-tag set insertion on port-tag-id (value)"
623                         " port (port_id) vf (vf_id)\n"
624                         "    Enable E-tag insertion for a VF on a port\n\n"
625
626                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
627                         "    Disable E-tag insertion for a VF on a port\n\n"
628
629                         "E-tag set stripping (on|off) port (port_id)\n"
630                         "    Enable/disable E-tag stripping on a port\n\n"
631
632                         "E-tag set forwarding (on|off) port (port_id)\n"
633                         "    Enable/disable E-tag based forwarding"
634                         " on a port\n\n"
635
636                         "E-tag set filter add e-tag-id (value) dst-pool"
637                         " (pool_id) port (port_id)\n"
638                         "    Add an E-tag forwarding filter on a port\n\n"
639
640                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
641                         "    Delete an E-tag forwarding filter on a port\n\n"
642
643 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
644                         "set port tm hierarchy default (port_id)\n"
645                         "       Set default traffic Management hierarchy on a port\n\n"
646
647 #endif
648                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
649                         "    Load a profile package on a port\n\n"
650
651                         "ddp del (port_id) (backup_profile_path)\n"
652                         "    Delete a profile package from a port\n\n"
653
654                         "ptype mapping get (port_id) (valid_only)\n"
655                         "    Get ptype mapping on a port\n\n"
656
657                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
658                         "    Replace target with the pkt_type in ptype mapping\n\n"
659
660                         "ptype mapping reset (port_id)\n"
661                         "    Reset ptype mapping on a port\n\n"
662
663                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
664                         "    Update a ptype mapping item on a port\n\n"
665
666                         "set port (port_id) queue-region region_id (value) "
667                         "queue_start_index (value) queue_num (value)\n"
668                         "    Set a queue region on a port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "flowtype (value)\n"
672                         "    Set a flowtype region index on a port\n\n"
673
674                         "set port (port_id) queue-region UP (value) region_id (value)\n"
675                         "    Set the mapping of User Priority to "
676                         "queue region on a port\n\n"
677
678                         "set port (port_id) queue-region flush (on|off)\n"
679                         "    flush all queue region related configuration\n\n"
680
681                         "show port meter cap (port_id)\n"
682                         "    Show port meter capability information\n\n"
683
684                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
685                         "    meter profile add - srtcm rfc 2697\n\n"
686
687                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
688                         "    meter profile add - trtcm rfc 2698\n\n"
689
690                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
691                         "    meter profile add - trtcm rfc 4115\n\n"
692
693                         "del port meter profile (port_id) (profile_id)\n"
694                         "    meter profile delete\n\n"
695
696                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
697                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
698                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
699                         "(dscp_tbl_entry63)]\n"
700                         "    meter create\n\n"
701
702                         "enable port meter (port_id) (mtr_id)\n"
703                         "    meter enable\n\n"
704
705                         "disable port meter (port_id) (mtr_id)\n"
706                         "    meter disable\n\n"
707
708                         "del port meter (port_id) (mtr_id)\n"
709                         "    meter delete\n\n"
710
711                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
712                         "    meter update meter profile\n\n"
713
714                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
715                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
716                         "    update meter dscp table entries\n\n"
717
718                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
719                         "(action0) [(action1) (action2)]\n"
720                         "    meter update policer action\n\n"
721
722                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
723                         "    meter update stats\n\n"
724
725                         "show port (port_id) queue-region\n"
726                         "    show all queue region related configuration info\n\n"
727
728                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
729                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
730                         "       Add port tm node private shaper profile.\n\n"
731
732                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
733                         "       Delete port tm node private shaper profile.\n\n"
734
735                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
736                         " (shaper_profile_id)\n"
737                         "       Add/update port tm node shared shaper.\n\n"
738
739                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
740                         "       Delete port tm node shared shaper.\n\n"
741
742                         "set port tm node shaper profile (port_id) (node_id)"
743                         " (shaper_profile_id)\n"
744                         "       Set port tm node shaper profile.\n\n"
745
746                         "add port tm node wred profile (port_id) (wred_profile_id)"
747                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
748                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
749                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
750                         "       Add port tm node wred profile.\n\n"
751
752                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
753                         "       Delete port tm node wred profile.\n\n"
754
755                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
756                         " (priority) (weight) (level_id) (shaper_profile_id)"
757                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
758                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
759                         "       Add port tm nonleaf node.\n\n"
760
761                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
762                         " (priority) (weight) (level_id) (shaper_profile_id)"
763                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
764                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
765                         "       Add port tm leaf node.\n\n"
766
767                         "del port tm node (port_id) (node_id)\n"
768                         "       Delete port tm node.\n\n"
769
770                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
771                         " (priority) (weight)\n"
772                         "       Set port tm node parent.\n\n"
773
774                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
775                         "       Commit tm hierarchy.\n\n"
776
777                         , list_pkt_forwarding_modes()
778                 );
779         }
780
781         if (show_all || !strcmp(res->section, "ports")) {
782
783                 cmdline_printf(
784                         cl,
785                         "\n"
786                         "Port Operations:\n"
787                         "----------------\n\n"
788
789                         "port start (port_id|all)\n"
790                         "    Start all ports or port_id.\n\n"
791
792                         "port stop (port_id|all)\n"
793                         "    Stop all ports or port_id.\n\n"
794
795                         "port close (port_id|all)\n"
796                         "    Close all ports or port_id.\n\n"
797
798                         "port attach (ident)\n"
799                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
800
801                         "port detach (port_id)\n"
802                         "    Detach physical or virtual dev by port_id\n\n"
803
804                         "port config (port_id|all)"
805                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
806                         " duplex (half|full|auto)\n"
807                         "    Set speed and duplex for all ports or port_id\n\n"
808
809                         "port config (port_id|all) loopback (mode)\n"
810                         "    Set loopback mode for all ports or port_id\n\n"
811
812                         "port config all (rxq|txq|rxd|txd) (value)\n"
813                         "    Set number for rxq/txq/rxd/txd.\n\n"
814
815                         "port config all max-pkt-len (value)\n"
816                         "    Set the max packet length.\n\n"
817
818                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
819                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
820                         " (on|off)\n"
821                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
822                         " for ports.\n\n"
823
824                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
825                         "geneve|nvgre|none|<flowtype_id>)\n"
826                         "    Set the RSS mode.\n\n"
827
828                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
829                         "    Set the RSS redirection table.\n\n"
830
831                         "port config (port_id) dcb vt (on|off) (traffic_class)"
832                         " pfc (on|off)\n"
833                         "    Set the DCB mode.\n\n"
834
835                         "port config all burst (value)\n"
836                         "    Set the number of packets per burst.\n\n"
837
838                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
839                         " (value)\n"
840                         "    Set the ring prefetch/host/writeback threshold"
841                         " for tx/rx queue.\n\n"
842
843                         "port config all (txfreet|txrst|rxfreet) (value)\n"
844                         "    Set free threshold for rx/tx, or set"
845                         " tx rs bit threshold.\n\n"
846                         "port config mtu X value\n"
847                         "    Set the MTU of port X to a given value\n\n"
848
849                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
850                         "    Start/stop a rx/tx queue of port X. Only take effect"
851                         " when port X is started\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag ether-type"
854                         " (value)\n"
855                         "    Set the value of E-tag ether-type.\n\n"
856
857                         "port config (port_id|all) l2-tunnel E-tag"
858                         " (enable|disable)\n"
859                         "    Enable/disable the E-tag support.\n\n"
860
861                         "port config (port_id) pctype mapping reset\n"
862                         "    Reset flow type to pctype mapping on a port\n\n"
863
864                         "port config (port_id) pctype mapping update"
865                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
866                         "    Update a flow type to pctype mapping item on a port\n\n"
867
868                         "port config (port_id) pctype (pctype_id) hash_inset|"
869                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
870                         " (field_idx)\n"
871                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
872
873                         "port config (port_id) pctype (pctype_id) hash_inset|"
874                         "fdir_inset|fdir_flx_inset clear all"
875                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
876                 );
877         }
878
879         if (show_all || !strcmp(res->section, "registers")) {
880
881                 cmdline_printf(
882                         cl,
883                         "\n"
884                         "Registers:\n"
885                         "----------\n\n"
886
887                         "read reg (port_id) (address)\n"
888                         "    Display value of a port register.\n\n"
889
890                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
891                         "    Display a port register bit field.\n\n"
892
893                         "read regbit (port_id) (address) (bit_x)\n"
894                         "    Display a single port register bit.\n\n"
895
896                         "write reg (port_id) (address) (value)\n"
897                         "    Set value of a port register.\n\n"
898
899                         "write regfield (port_id) (address) (bit_x) (bit_y)"
900                         " (value)\n"
901                         "    Set bit field of a port register.\n\n"
902
903                         "write regbit (port_id) (address) (bit_x) (value)\n"
904                         "    Set single bit value of a port register.\n\n"
905                 );
906         }
907         if (show_all || !strcmp(res->section, "filters")) {
908
909                 cmdline_printf(
910                         cl,
911                         "\n"
912                         "filters:\n"
913                         "--------\n\n"
914
915                         "ethertype_filter (port_id) (add|del)"
916                         " (mac_addr|mac_ignr) (mac_address) ethertype"
917                         " (ether_type) (drop|fwd) queue (queue_id)\n"
918                         "    Add/Del an ethertype filter.\n\n"
919
920                         "2tuple_filter (port_id) (add|del)"
921                         " dst_port (dst_port_value) protocol (protocol_value)"
922                         " mask (mask_value) tcp_flags (tcp_flags_value)"
923                         " priority (prio_value) queue (queue_id)\n"
924                         "    Add/Del a 2tuple filter.\n\n"
925
926                         "5tuple_filter (port_id) (add|del)"
927                         " dst_ip (dst_address) src_ip (src_address)"
928                         " dst_port (dst_port_value) src_port (src_port_value)"
929                         " protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 5tuple filter.\n\n"
933
934                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
935                         "    Add/Del syn filter.\n\n"
936
937                         "flex_filter (port_id) (add|del) len (len_value)"
938                         " bytes (bytes_value) mask (mask_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a flex filter.\n\n"
941
942                         "flow_director_filter (port_id) mode IP (add|del|update)"
943                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
944                         " src (src_ip_address) dst (dst_ip_address)"
945                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
946                         " vlan (vlan_value) flexbytes (flexbytes_value)"
947                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
948                         " fd_id (fd_id_value)\n"
949                         "    Add/Del an IP type flow director filter.\n\n"
950
951                         "flow_director_filter (port_id) mode IP (add|del|update)"
952                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
953                         " src (src_ip_address) (src_port)"
954                         " dst (dst_ip_address) (dst_port)"
955                         " tos (tos_value) ttl (ttl_value)"
956                         " vlan (vlan_value) flexbytes (flexbytes_value)"
957                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
958                         " fd_id (fd_id_value)\n"
959                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
960
961                         "flow_director_filter (port_id) mode IP (add|del|update)"
962                         " flow (ipv4-sctp|ipv6-sctp)"
963                         " src (src_ip_address) (src_port)"
964                         " dst (dst_ip_address) (dst_port)"
965                         " tag (verification_tag) "
966                         " tos (tos_value) ttl (ttl_value)"
967                         " vlan (vlan_value)"
968                         " flexbytes (flexbytes_value) (drop|fwd)"
969                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
970                         "    Add/Del a SCTP type flow director filter.\n\n"
971
972                         "flow_director_filter (port_id) mode IP (add|del|update)"
973                         " flow l2_payload ether (ethertype)"
974                         " flexbytes (flexbytes_value) (drop|fwd)"
975                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
976                         "    Add/Del a l2 payload type flow director filter.\n\n"
977
978                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
979                         " mac (mac_address) vlan (vlan_value)"
980                         " flexbytes (flexbytes_value) (drop|fwd)"
981                         " queue (queue_id) fd_id (fd_id_value)\n"
982                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
983
984                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
985                         " mac (mac_address) vlan (vlan_value)"
986                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
987                         " flexbytes (flexbytes_value) (drop|fwd)"
988                         " queue (queue_id) fd_id (fd_id_value)\n"
989                         "    Add/Del a Tunnel flow director filter.\n\n"
990
991                         "flow_director_filter (port_id) mode raw (add|del|update)"
992                         " flow (flow_id) (drop|fwd) queue (queue_id)"
993                         " fd_id (fd_id_value) packet (packet file name)\n"
994                         "    Add/Del a raw type flow director filter.\n\n"
995
996                         "flush_flow_director (port_id)\n"
997                         "    Flush all flow director entries of a device.\n\n"
998
999                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1000                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1001                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1002                         "    Set flow director IP mask.\n\n"
1003
1004                         "flow_director_mask (port_id) mode MAC-VLAN"
1005                         " vlan (vlan_value)\n"
1006                         "    Set flow director MAC-VLAN mask.\n\n"
1007
1008                         "flow_director_mask (port_id) mode Tunnel"
1009                         " vlan (vlan_value) mac (mac_value)"
1010                         " tunnel-type (tunnel_type_value)"
1011                         " tunnel-id (tunnel_id_value)\n"
1012                         "    Set flow director Tunnel mask.\n\n"
1013
1014                         "flow_director_flex_mask (port_id)"
1015                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1016                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1017                         " (mask)\n"
1018                         "    Configure mask of flex payload.\n\n"
1019
1020                         "flow_director_flex_payload (port_id)"
1021                         " (raw|l2|l3|l4) (config)\n"
1022                         "    Configure flex payload selection.\n\n"
1023
1024                         "get_sym_hash_ena_per_port (port_id)\n"
1025                         "    get symmetric hash enable configuration per port.\n\n"
1026
1027                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1028                         "    set symmetric hash enable configuration per port"
1029                         " to enable or disable.\n\n"
1030
1031                         "get_hash_global_config (port_id)\n"
1032                         "    Get the global configurations of hash filters.\n\n"
1033
1034                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1035                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1036                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1037                         " (enable|disable)\n"
1038                         "    Set the global configurations of hash filters.\n\n"
1039
1040                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1041                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1042                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1043                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1044                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1045                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1046                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1047                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1048                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1049                         "fld-8th|none) (select|add)\n"
1050                         "    Set the input set for hash.\n\n"
1051
1052                         "set_fdir_input_set (port_id) "
1053                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1054                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1055                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1056                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1057                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1058                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1059                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1060                         " (select|add)\n"
1061                         "    Set the input set for FDir.\n\n"
1062
1063                         "flow validate {port_id}"
1064                         " [group {group_id}] [priority {level}]"
1065                         " [ingress] [egress]"
1066                         " pattern {item} [/ {item} [...]] / end"
1067                         " actions {action} [/ {action} [...]] / end\n"
1068                         "    Check whether a flow rule can be created.\n\n"
1069
1070                         "flow create {port_id}"
1071                         " [group {group_id}] [priority {level}]"
1072                         " [ingress] [egress]"
1073                         " pattern {item} [/ {item} [...]] / end"
1074                         " actions {action} [/ {action} [...]] / end\n"
1075                         "    Create a flow rule.\n\n"
1076
1077                         "flow destroy {port_id} rule {rule_id} [...]\n"
1078                         "    Destroy specific flow rules.\n\n"
1079
1080                         "flow flush {port_id}\n"
1081                         "    Destroy all flow rules.\n\n"
1082
1083                         "flow query {port_id} {rule_id} {action}\n"
1084                         "    Query an existing flow rule.\n\n"
1085
1086                         "flow list {port_id} [group {group_id}] [...]\n"
1087                         "    List existing flow rules sorted by priority,"
1088                         " filtered by group identifiers.\n\n"
1089
1090                         "flow isolate {port_id} {boolean}\n"
1091                         "    Restrict ingress traffic to the defined"
1092                         " flow rules\n\n"
1093                 );
1094         }
1095 }
1096
1097 cmdline_parse_token_string_t cmd_help_long_help =
1098         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1099
1100 cmdline_parse_token_string_t cmd_help_long_section =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1102                         "all#control#display#config#"
1103                         "ports#registers#filters");
1104
1105 cmdline_parse_inst_t cmd_help_long = {
1106         .f = cmd_help_long_parsed,
1107         .data = NULL,
1108         .help_str = "help all|control|display|config|ports|register|filters: "
1109                 "Show help",
1110         .tokens = {
1111                 (void *)&cmd_help_long_help,
1112                 (void *)&cmd_help_long_section,
1113                 NULL,
1114         },
1115 };
1116
1117
1118 /* *** start/stop/close all ports *** */
1119 struct cmd_operate_port_result {
1120         cmdline_fixed_string_t keyword;
1121         cmdline_fixed_string_t name;
1122         cmdline_fixed_string_t value;
1123 };
1124
1125 static void cmd_operate_port_parsed(void *parsed_result,
1126                                 __attribute__((unused)) struct cmdline *cl,
1127                                 __attribute__((unused)) void *data)
1128 {
1129         struct cmd_operate_port_result *res = parsed_result;
1130
1131         if (!strcmp(res->name, "start"))
1132                 start_port(RTE_PORT_ALL);
1133         else if (!strcmp(res->name, "stop"))
1134                 stop_port(RTE_PORT_ALL);
1135         else if (!strcmp(res->name, "close"))
1136                 close_port(RTE_PORT_ALL);
1137         else if (!strcmp(res->name, "reset"))
1138                 reset_port(RTE_PORT_ALL);
1139         else
1140                 printf("Unknown parameter\n");
1141 }
1142
1143 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1144         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1145                                                                 "port");
1146 cmdline_parse_token_string_t cmd_operate_port_all_port =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1148                                                 "start#stop#close#reset");
1149 cmdline_parse_token_string_t cmd_operate_port_all_all =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1151
1152 cmdline_parse_inst_t cmd_operate_port = {
1153         .f = cmd_operate_port_parsed,
1154         .data = NULL,
1155         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1156         .tokens = {
1157                 (void *)&cmd_operate_port_all_cmd,
1158                 (void *)&cmd_operate_port_all_port,
1159                 (void *)&cmd_operate_port_all_all,
1160                 NULL,
1161         },
1162 };
1163
1164 /* *** start/stop/close specific port *** */
1165 struct cmd_operate_specific_port_result {
1166         cmdline_fixed_string_t keyword;
1167         cmdline_fixed_string_t name;
1168         uint8_t value;
1169 };
1170
1171 static void cmd_operate_specific_port_parsed(void *parsed_result,
1172                         __attribute__((unused)) struct cmdline *cl,
1173                                 __attribute__((unused)) void *data)
1174 {
1175         struct cmd_operate_specific_port_result *res = parsed_result;
1176
1177         if (!strcmp(res->name, "start"))
1178                 start_port(res->value);
1179         else if (!strcmp(res->name, "stop"))
1180                 stop_port(res->value);
1181         else if (!strcmp(res->name, "close"))
1182                 close_port(res->value);
1183         else if (!strcmp(res->name, "reset"))
1184                 reset_port(res->value);
1185         else
1186                 printf("Unknown parameter\n");
1187 }
1188
1189 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1190         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1191                                                         keyword, "port");
1192 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                 name, "start#stop#close#reset");
1195 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1196         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                         value, UINT8);
1198
1199 cmdline_parse_inst_t cmd_operate_specific_port = {
1200         .f = cmd_operate_specific_port_parsed,
1201         .data = NULL,
1202         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1203         .tokens = {
1204                 (void *)&cmd_operate_specific_port_cmd,
1205                 (void *)&cmd_operate_specific_port_port,
1206                 (void *)&cmd_operate_specific_port_id,
1207                 NULL,
1208         },
1209 };
1210
1211 /* *** attach a specified port *** */
1212 struct cmd_operate_attach_port_result {
1213         cmdline_fixed_string_t port;
1214         cmdline_fixed_string_t keyword;
1215         cmdline_fixed_string_t identifier;
1216 };
1217
1218 static void cmd_operate_attach_port_parsed(void *parsed_result,
1219                                 __attribute__((unused)) struct cmdline *cl,
1220                                 __attribute__((unused)) void *data)
1221 {
1222         struct cmd_operate_attach_port_result *res = parsed_result;
1223
1224         if (!strcmp(res->keyword, "attach"))
1225                 attach_port(res->identifier);
1226         else
1227                 printf("Unknown parameter\n");
1228 }
1229
1230 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1231         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1232                         port, "port");
1233 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         keyword, "attach");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         identifier, NULL);
1239
1240 cmdline_parse_inst_t cmd_operate_attach_port = {
1241         .f = cmd_operate_attach_port_parsed,
1242         .data = NULL,
1243         .help_str = "port attach <identifier>: "
1244                 "(identifier: pci address or virtual dev name)",
1245         .tokens = {
1246                 (void *)&cmd_operate_attach_port_port,
1247                 (void *)&cmd_operate_attach_port_keyword,
1248                 (void *)&cmd_operate_attach_port_identifier,
1249                 NULL,
1250         },
1251 };
1252
1253 /* *** detach a specified port *** */
1254 struct cmd_operate_detach_port_result {
1255         cmdline_fixed_string_t port;
1256         cmdline_fixed_string_t keyword;
1257         portid_t port_id;
1258 };
1259
1260 static void cmd_operate_detach_port_parsed(void *parsed_result,
1261                                 __attribute__((unused)) struct cmdline *cl,
1262                                 __attribute__((unused)) void *data)
1263 {
1264         struct cmd_operate_detach_port_result *res = parsed_result;
1265
1266         if (!strcmp(res->keyword, "detach"))
1267                 detach_port(res->port_id);
1268         else
1269                 printf("Unknown parameter\n");
1270 }
1271
1272 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1273         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1274                         port, "port");
1275 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         keyword, "detach");
1278 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1279         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         port_id, UINT16);
1281
1282 cmdline_parse_inst_t cmd_operate_detach_port = {
1283         .f = cmd_operate_detach_port_parsed,
1284         .data = NULL,
1285         .help_str = "port detach <port_id>",
1286         .tokens = {
1287                 (void *)&cmd_operate_detach_port_port,
1288                 (void *)&cmd_operate_detach_port_keyword,
1289                 (void *)&cmd_operate_detach_port_port_id,
1290                 NULL,
1291         },
1292 };
1293
1294 /* *** configure speed for all ports *** */
1295 struct cmd_config_speed_all {
1296         cmdline_fixed_string_t port;
1297         cmdline_fixed_string_t keyword;
1298         cmdline_fixed_string_t all;
1299         cmdline_fixed_string_t item1;
1300         cmdline_fixed_string_t item2;
1301         cmdline_fixed_string_t value1;
1302         cmdline_fixed_string_t value2;
1303 };
1304
1305 static int
1306 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1307 {
1308
1309         int duplex;
1310
1311         if (!strcmp(duplexstr, "half")) {
1312                 duplex = ETH_LINK_HALF_DUPLEX;
1313         } else if (!strcmp(duplexstr, "full")) {
1314                 duplex = ETH_LINK_FULL_DUPLEX;
1315         } else if (!strcmp(duplexstr, "auto")) {
1316                 duplex = ETH_LINK_FULL_DUPLEX;
1317         } else {
1318                 printf("Unknown duplex parameter\n");
1319                 return -1;
1320         }
1321
1322         if (!strcmp(speedstr, "10")) {
1323                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1324                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1325         } else if (!strcmp(speedstr, "100")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1328         } else {
1329                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1330                         printf("Invalid speed/duplex parameters\n");
1331                         return -1;
1332                 }
1333                 if (!strcmp(speedstr, "1000")) {
1334                         *speed = ETH_LINK_SPEED_1G;
1335                 } else if (!strcmp(speedstr, "10000")) {
1336                         *speed = ETH_LINK_SPEED_10G;
1337                 } else if (!strcmp(speedstr, "25000")) {
1338                         *speed = ETH_LINK_SPEED_25G;
1339                 } else if (!strcmp(speedstr, "40000")) {
1340                         *speed = ETH_LINK_SPEED_40G;
1341                 } else if (!strcmp(speedstr, "50000")) {
1342                         *speed = ETH_LINK_SPEED_50G;
1343                 } else if (!strcmp(speedstr, "100000")) {
1344                         *speed = ETH_LINK_SPEED_100G;
1345                 } else if (!strcmp(speedstr, "auto")) {
1346                         *speed = ETH_LINK_SPEED_AUTONEG;
1347                 } else {
1348                         printf("Unknown speed parameter\n");
1349                         return -1;
1350                 }
1351         }
1352
1353         return 0;
1354 }
1355
1356 static void
1357 cmd_config_speed_all_parsed(void *parsed_result,
1358                         __attribute__((unused)) struct cmdline *cl,
1359                         __attribute__((unused)) void *data)
1360 {
1361         struct cmd_config_speed_all *res = parsed_result;
1362         uint32_t link_speed;
1363         portid_t pid;
1364
1365         if (!all_ports_stopped()) {
1366                 printf("Please stop all ports first\n");
1367                 return;
1368         }
1369
1370         if (parse_and_check_speed_duplex(res->value1, res->value2,
1371                         &link_speed) < 0)
1372                 return;
1373
1374         RTE_ETH_FOREACH_DEV(pid) {
1375                 ports[pid].dev_conf.link_speeds = link_speed;
1376         }
1377
1378         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1379 }
1380
1381 cmdline_parse_token_string_t cmd_config_speed_all_port =
1382         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1383 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1384         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1385                                                         "config");
1386 cmdline_parse_token_string_t cmd_config_speed_all_all =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1388 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1389         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1390 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1391         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1392                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1393 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1395 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1396         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1397                                                 "half#full#auto");
1398
1399 cmdline_parse_inst_t cmd_config_speed_all = {
1400         .f = cmd_config_speed_all_parsed,
1401         .data = NULL,
1402         .help_str = "port config all speed "
1403                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1404                                                         "half|full|auto",
1405         .tokens = {
1406                 (void *)&cmd_config_speed_all_port,
1407                 (void *)&cmd_config_speed_all_keyword,
1408                 (void *)&cmd_config_speed_all_all,
1409                 (void *)&cmd_config_speed_all_item1,
1410                 (void *)&cmd_config_speed_all_value1,
1411                 (void *)&cmd_config_speed_all_item2,
1412                 (void *)&cmd_config_speed_all_value2,
1413                 NULL,
1414         },
1415 };
1416
1417 /* *** configure speed for specific port *** */
1418 struct cmd_config_speed_specific {
1419         cmdline_fixed_string_t port;
1420         cmdline_fixed_string_t keyword;
1421         uint8_t id;
1422         cmdline_fixed_string_t item1;
1423         cmdline_fixed_string_t item2;
1424         cmdline_fixed_string_t value1;
1425         cmdline_fixed_string_t value2;
1426 };
1427
1428 static void
1429 cmd_config_speed_specific_parsed(void *parsed_result,
1430                                 __attribute__((unused)) struct cmdline *cl,
1431                                 __attribute__((unused)) void *data)
1432 {
1433         struct cmd_config_speed_specific *res = parsed_result;
1434         uint32_t link_speed;
1435
1436         if (!all_ports_stopped()) {
1437                 printf("Please stop all ports first\n");
1438                 return;
1439         }
1440
1441         if (port_id_is_invalid(res->id, ENABLED_WARN))
1442                 return;
1443
1444         if (parse_and_check_speed_duplex(res->value1, res->value2,
1445                         &link_speed) < 0)
1446                 return;
1447
1448         ports[res->id].dev_conf.link_speeds = link_speed;
1449
1450         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1451 }
1452
1453
1454 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1455         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1456                                                                 "port");
1457 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1459                                                                 "config");
1460 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1461         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1462 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1464                                                                 "speed");
1465 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1467                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1470                                                                 "duplex");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1473                                                         "half#full#auto");
1474
1475 cmdline_parse_inst_t cmd_config_speed_specific = {
1476         .f = cmd_config_speed_specific_parsed,
1477         .data = NULL,
1478         .help_str = "port config <port_id> speed "
1479                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1480                                                         "half|full|auto",
1481         .tokens = {
1482                 (void *)&cmd_config_speed_specific_port,
1483                 (void *)&cmd_config_speed_specific_keyword,
1484                 (void *)&cmd_config_speed_specific_id,
1485                 (void *)&cmd_config_speed_specific_item1,
1486                 (void *)&cmd_config_speed_specific_value1,
1487                 (void *)&cmd_config_speed_specific_item2,
1488                 (void *)&cmd_config_speed_specific_value2,
1489                 NULL,
1490         },
1491 };
1492
1493 /* *** configure loopback for all ports *** */
1494 struct cmd_config_loopback_all {
1495         cmdline_fixed_string_t port;
1496         cmdline_fixed_string_t keyword;
1497         cmdline_fixed_string_t all;
1498         cmdline_fixed_string_t item;
1499         uint32_t mode;
1500 };
1501
1502 static void
1503 cmd_config_loopback_all_parsed(void *parsed_result,
1504                         __attribute__((unused)) struct cmdline *cl,
1505                         __attribute__((unused)) void *data)
1506 {
1507         struct cmd_config_loopback_all *res = parsed_result;
1508         portid_t pid;
1509
1510         if (!all_ports_stopped()) {
1511                 printf("Please stop all ports first\n");
1512                 return;
1513         }
1514
1515         RTE_ETH_FOREACH_DEV(pid) {
1516                 ports[pid].dev_conf.lpbk_mode = res->mode;
1517         }
1518
1519         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1520 }
1521
1522 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1523         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1524 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1525         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1526                                                         "config");
1527 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1528         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1529 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1530         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1531                                                         "loopback");
1532 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1533         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1534
1535 cmdline_parse_inst_t cmd_config_loopback_all = {
1536         .f = cmd_config_loopback_all_parsed,
1537         .data = NULL,
1538         .help_str = "port config all loopback <mode>",
1539         .tokens = {
1540                 (void *)&cmd_config_loopback_all_port,
1541                 (void *)&cmd_config_loopback_all_keyword,
1542                 (void *)&cmd_config_loopback_all_all,
1543                 (void *)&cmd_config_loopback_all_item,
1544                 (void *)&cmd_config_loopback_all_mode,
1545                 NULL,
1546         },
1547 };
1548
1549 /* *** configure loopback for specific port *** */
1550 struct cmd_config_loopback_specific {
1551         cmdline_fixed_string_t port;
1552         cmdline_fixed_string_t keyword;
1553         uint16_t port_id;
1554         cmdline_fixed_string_t item;
1555         uint32_t mode;
1556 };
1557
1558 static void
1559 cmd_config_loopback_specific_parsed(void *parsed_result,
1560                                 __attribute__((unused)) struct cmdline *cl,
1561                                 __attribute__((unused)) void *data)
1562 {
1563         struct cmd_config_loopback_specific *res = parsed_result;
1564
1565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1566                 return;
1567
1568         if (!port_is_stopped(res->port_id)) {
1569                 printf("Please stop port %u first\n", res->port_id);
1570                 return;
1571         }
1572
1573         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1574
1575         cmd_reconfig_device_queue(res->port_id, 1, 1);
1576 }
1577
1578
1579 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1580         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1581                                                                 "port");
1582 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1584                                                                 "config");
1585 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1586         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1587                                                                 UINT16);
1588 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1589         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1590                                                                 "loopback");
1591 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1592         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1593                               UINT32);
1594
1595 cmdline_parse_inst_t cmd_config_loopback_specific = {
1596         .f = cmd_config_loopback_specific_parsed,
1597         .data = NULL,
1598         .help_str = "port config <port_id> loopback <mode>",
1599         .tokens = {
1600                 (void *)&cmd_config_loopback_specific_port,
1601                 (void *)&cmd_config_loopback_specific_keyword,
1602                 (void *)&cmd_config_loopback_specific_id,
1603                 (void *)&cmd_config_loopback_specific_item,
1604                 (void *)&cmd_config_loopback_specific_mode,
1605                 NULL,
1606         },
1607 };
1608
1609 /* *** configure txq/rxq, txd/rxd *** */
1610 struct cmd_config_rx_tx {
1611         cmdline_fixed_string_t port;
1612         cmdline_fixed_string_t keyword;
1613         cmdline_fixed_string_t all;
1614         cmdline_fixed_string_t name;
1615         uint16_t value;
1616 };
1617
1618 static void
1619 cmd_config_rx_tx_parsed(void *parsed_result,
1620                         __attribute__((unused)) struct cmdline *cl,
1621                         __attribute__((unused)) void *data)
1622 {
1623         struct cmd_config_rx_tx *res = parsed_result;
1624
1625         if (!all_ports_stopped()) {
1626                 printf("Please stop all ports first\n");
1627                 return;
1628         }
1629         if (!strcmp(res->name, "rxq")) {
1630                 if (!res->value && !nb_txq) {
1631                         printf("Warning: Either rx or tx queues should be non zero\n");
1632                         return;
1633                 }
1634                 if (check_nb_rxq(res->value) != 0)
1635                         return;
1636                 nb_rxq = res->value;
1637         }
1638         else if (!strcmp(res->name, "txq")) {
1639                 if (!res->value && !nb_rxq) {
1640                         printf("Warning: Either rx or tx queues should be non zero\n");
1641                         return;
1642                 }
1643                 if (check_nb_txq(res->value) != 0)
1644                         return;
1645                 nb_txq = res->value;
1646         }
1647         else if (!strcmp(res->name, "rxd")) {
1648                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1649                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1650                                         res->value, RTE_TEST_RX_DESC_MAX);
1651                         return;
1652                 }
1653                 nb_rxd = res->value;
1654         } else if (!strcmp(res->name, "txd")) {
1655                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1656                         printf("txd %d invalid - must be > 0 && <= %d\n",
1657                                         res->value, RTE_TEST_TX_DESC_MAX);
1658                         return;
1659                 }
1660                 nb_txd = res->value;
1661         } else {
1662                 printf("Unknown parameter\n");
1663                 return;
1664         }
1665
1666         fwd_config_setup();
1667
1668         init_port_config();
1669
1670         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1671 }
1672
1673 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1675 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1676         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1677 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1679 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1680         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1681                                                 "rxq#txq#rxd#txd");
1682 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1683         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1684
1685 cmdline_parse_inst_t cmd_config_rx_tx = {
1686         .f = cmd_config_rx_tx_parsed,
1687         .data = NULL,
1688         .help_str = "port config all rxq|txq|rxd|txd <value>",
1689         .tokens = {
1690                 (void *)&cmd_config_rx_tx_port,
1691                 (void *)&cmd_config_rx_tx_keyword,
1692                 (void *)&cmd_config_rx_tx_all,
1693                 (void *)&cmd_config_rx_tx_name,
1694                 (void *)&cmd_config_rx_tx_value,
1695                 NULL,
1696         },
1697 };
1698
1699 /* *** config max packet length *** */
1700 struct cmd_config_max_pkt_len_result {
1701         cmdline_fixed_string_t port;
1702         cmdline_fixed_string_t keyword;
1703         cmdline_fixed_string_t all;
1704         cmdline_fixed_string_t name;
1705         uint32_t value;
1706 };
1707
1708 static void
1709 cmd_config_max_pkt_len_parsed(void *parsed_result,
1710                                 __attribute__((unused)) struct cmdline *cl,
1711                                 __attribute__((unused)) void *data)
1712 {
1713         struct cmd_config_max_pkt_len_result *res = parsed_result;
1714         portid_t pid;
1715
1716         if (!all_ports_stopped()) {
1717                 printf("Please stop all ports first\n");
1718                 return;
1719         }
1720
1721         RTE_ETH_FOREACH_DEV(pid) {
1722                 struct rte_port *port = &ports[pid];
1723                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1724
1725                 if (!strcmp(res->name, "max-pkt-len")) {
1726                         if (res->value < ETHER_MIN_LEN) {
1727                                 printf("max-pkt-len can not be less than %d\n",
1728                                                 ETHER_MIN_LEN);
1729                                 return;
1730                         }
1731                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1732                                 return;
1733
1734                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1735                         if (res->value > ETHER_MAX_LEN)
1736                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1737                         else
1738                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1739                         port->dev_conf.rxmode.offloads = rx_offloads;
1740                 } else {
1741                         printf("Unknown parameter\n");
1742                         return;
1743                 }
1744         }
1745
1746         init_port_config();
1747
1748         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1749 }
1750
1751 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1752         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1753                                                                 "port");
1754 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1756                                                                 "config");
1757 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1758         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1759                                                                 "all");
1760 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1761         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1762                                                                 "max-pkt-len");
1763 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1764         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1765                                                                 UINT32);
1766
1767 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1768         .f = cmd_config_max_pkt_len_parsed,
1769         .data = NULL,
1770         .help_str = "port config all max-pkt-len <value>",
1771         .tokens = {
1772                 (void *)&cmd_config_max_pkt_len_port,
1773                 (void *)&cmd_config_max_pkt_len_keyword,
1774                 (void *)&cmd_config_max_pkt_len_all,
1775                 (void *)&cmd_config_max_pkt_len_name,
1776                 (void *)&cmd_config_max_pkt_len_value,
1777                 NULL,
1778         },
1779 };
1780
1781 /* *** configure port MTU *** */
1782 struct cmd_config_mtu_result {
1783         cmdline_fixed_string_t port;
1784         cmdline_fixed_string_t keyword;
1785         cmdline_fixed_string_t mtu;
1786         portid_t port_id;
1787         uint16_t value;
1788 };
1789
1790 static void
1791 cmd_config_mtu_parsed(void *parsed_result,
1792                       __attribute__((unused)) struct cmdline *cl,
1793                       __attribute__((unused)) void *data)
1794 {
1795         struct cmd_config_mtu_result *res = parsed_result;
1796
1797         if (res->value < ETHER_MIN_LEN) {
1798                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1799                 return;
1800         }
1801         port_mtu_set(res->port_id, res->value);
1802 }
1803
1804 cmdline_parse_token_string_t cmd_config_mtu_port =
1805         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1806                                  "port");
1807 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1809                                  "config");
1810 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1812                                  "mtu");
1813 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1814         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1815 cmdline_parse_token_num_t cmd_config_mtu_value =
1816         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1817
1818 cmdline_parse_inst_t cmd_config_mtu = {
1819         .f = cmd_config_mtu_parsed,
1820         .data = NULL,
1821         .help_str = "port config mtu <port_id> <value>",
1822         .tokens = {
1823                 (void *)&cmd_config_mtu_port,
1824                 (void *)&cmd_config_mtu_keyword,
1825                 (void *)&cmd_config_mtu_mtu,
1826                 (void *)&cmd_config_mtu_port_id,
1827                 (void *)&cmd_config_mtu_value,
1828                 NULL,
1829         },
1830 };
1831
1832 /* *** configure rx mode *** */
1833 struct cmd_config_rx_mode_flag {
1834         cmdline_fixed_string_t port;
1835         cmdline_fixed_string_t keyword;
1836         cmdline_fixed_string_t all;
1837         cmdline_fixed_string_t name;
1838         cmdline_fixed_string_t value;
1839 };
1840
1841 static void
1842 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1843                                 __attribute__((unused)) struct cmdline *cl,
1844                                 __attribute__((unused)) void *data)
1845 {
1846         struct cmd_config_rx_mode_flag *res = parsed_result;
1847         portid_t pid;
1848
1849         if (!all_ports_stopped()) {
1850                 printf("Please stop all ports first\n");
1851                 return;
1852         }
1853
1854         RTE_ETH_FOREACH_DEV(pid) {
1855                 struct rte_port *port;
1856                 uint64_t rx_offloads;
1857
1858                 port = &ports[pid];
1859                 rx_offloads = port->dev_conf.rxmode.offloads;
1860                 if (!strcmp(res->name, "crc-strip")) {
1861                         if (!strcmp(res->value, "on"))
1862                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1863                         else if (!strcmp(res->value, "off"))
1864                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1865                         else {
1866                                 printf("Unknown parameter\n");
1867                                 return;
1868                         }
1869                 } else if (!strcmp(res->name, "scatter")) {
1870                         if (!strcmp(res->value, "on")) {
1871                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1872                         } else if (!strcmp(res->value, "off")) {
1873                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1874                         } else {
1875                                 printf("Unknown parameter\n");
1876                                 return;
1877                         }
1878                 } else if (!strcmp(res->name, "rx-cksum")) {
1879                         if (!strcmp(res->value, "on"))
1880                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1881                         else if (!strcmp(res->value, "off"))
1882                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1883                         else {
1884                                 printf("Unknown parameter\n");
1885                                 return;
1886                         }
1887                 } else if (!strcmp(res->name, "rx-timestamp")) {
1888                         if (!strcmp(res->value, "on"))
1889                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1890                         else if (!strcmp(res->value, "off"))
1891                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1892                         else {
1893                                 printf("Unknown parameter\n");
1894                                 return;
1895                         }
1896                 } else if (!strcmp(res->name, "hw-vlan")) {
1897                         if (!strcmp(res->value, "on")) {
1898                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1899                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1900                         } else if (!strcmp(res->value, "off")) {
1901                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1902                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1903                         } else {
1904                                 printf("Unknown parameter\n");
1905                                 return;
1906                         }
1907                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1908                         if (!strcmp(res->value, "on"))
1909                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1910                         else if (!strcmp(res->value, "off"))
1911                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1912                         else {
1913                                 printf("Unknown parameter\n");
1914                                 return;
1915                         }
1916                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1917                         if (!strcmp(res->value, "on"))
1918                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1919                         else if (!strcmp(res->value, "off"))
1920                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1921                         else {
1922                                 printf("Unknown parameter\n");
1923                                 return;
1924                         }
1925                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1926                         if (!strcmp(res->value, "on"))
1927                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1928                         else if (!strcmp(res->value, "off"))
1929                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1930                         else {
1931                                 printf("Unknown parameter\n");
1932                                 return;
1933                         }
1934                 } else if (!strcmp(res->name, "drop-en")) {
1935                         if (!strcmp(res->value, "on"))
1936                                 rx_drop_en = 1;
1937                         else if (!strcmp(res->value, "off"))
1938                                 rx_drop_en = 0;
1939                         else {
1940                                 printf("Unknown parameter\n");
1941                                 return;
1942                         }
1943                 } else {
1944                         printf("Unknown parameter\n");
1945                         return;
1946                 }
1947                 port->dev_conf.rxmode.offloads = rx_offloads;
1948         }
1949
1950         init_port_config();
1951
1952         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1953 }
1954
1955 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1956         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1957 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1959                                                                 "config");
1960 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1962 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1963         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1964                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1965                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1966 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1968                                                         "on#off");
1969
1970 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1971         .f = cmd_config_rx_mode_flag_parsed,
1972         .data = NULL,
1973         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1974                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1975         .tokens = {
1976                 (void *)&cmd_config_rx_mode_flag_port,
1977                 (void *)&cmd_config_rx_mode_flag_keyword,
1978                 (void *)&cmd_config_rx_mode_flag_all,
1979                 (void *)&cmd_config_rx_mode_flag_name,
1980                 (void *)&cmd_config_rx_mode_flag_value,
1981                 NULL,
1982         },
1983 };
1984
1985 /* *** configure rss *** */
1986 struct cmd_config_rss {
1987         cmdline_fixed_string_t port;
1988         cmdline_fixed_string_t keyword;
1989         cmdline_fixed_string_t all;
1990         cmdline_fixed_string_t name;
1991         cmdline_fixed_string_t value;
1992 };
1993
1994 static void
1995 cmd_config_rss_parsed(void *parsed_result,
1996                         __attribute__((unused)) struct cmdline *cl,
1997                         __attribute__((unused)) void *data)
1998 {
1999         struct cmd_config_rss *res = parsed_result;
2000         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2001         int diag;
2002         uint16_t i;
2003
2004         if (!strcmp(res->value, "all"))
2005                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2006                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2007                                         ETH_RSS_L2_PAYLOAD;
2008         else if (!strcmp(res->value, "ip"))
2009                 rss_conf.rss_hf = ETH_RSS_IP;
2010         else if (!strcmp(res->value, "udp"))
2011                 rss_conf.rss_hf = ETH_RSS_UDP;
2012         else if (!strcmp(res->value, "tcp"))
2013                 rss_conf.rss_hf = ETH_RSS_TCP;
2014         else if (!strcmp(res->value, "sctp"))
2015                 rss_conf.rss_hf = ETH_RSS_SCTP;
2016         else if (!strcmp(res->value, "ether"))
2017                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2018         else if (!strcmp(res->value, "port"))
2019                 rss_conf.rss_hf = ETH_RSS_PORT;
2020         else if (!strcmp(res->value, "vxlan"))
2021                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2022         else if (!strcmp(res->value, "geneve"))
2023                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2024         else if (!strcmp(res->value, "nvgre"))
2025                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2026         else if (!strcmp(res->value, "none"))
2027                 rss_conf.rss_hf = 0;
2028         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2029                                                 atoi(res->value) < 64)
2030                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2031         else {
2032                 printf("Unknown parameter\n");
2033                 return;
2034         }
2035         rss_conf.rss_key = NULL;
2036         /* Update global configuration for RSS types. */
2037         rss_hf = rss_conf.rss_hf;
2038         RTE_ETH_FOREACH_DEV(i) {
2039                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2040                 if (diag < 0)
2041                         printf("Configuration of RSS hash at ethernet port %d "
2042                                 "failed with error (%d): %s.\n",
2043                                 i, -diag, strerror(-diag));
2044         }
2045 }
2046
2047 cmdline_parse_token_string_t cmd_config_rss_port =
2048         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2049 cmdline_parse_token_string_t cmd_config_rss_keyword =
2050         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2051 cmdline_parse_token_string_t cmd_config_rss_all =
2052         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2053 cmdline_parse_token_string_t cmd_config_rss_name =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2055 cmdline_parse_token_string_t cmd_config_rss_value =
2056         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2057
2058 cmdline_parse_inst_t cmd_config_rss = {
2059         .f = cmd_config_rss_parsed,
2060         .data = NULL,
2061         .help_str = "port config all rss "
2062                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2063         .tokens = {
2064                 (void *)&cmd_config_rss_port,
2065                 (void *)&cmd_config_rss_keyword,
2066                 (void *)&cmd_config_rss_all,
2067                 (void *)&cmd_config_rss_name,
2068                 (void *)&cmd_config_rss_value,
2069                 NULL,
2070         },
2071 };
2072
2073 /* *** configure rss hash key *** */
2074 struct cmd_config_rss_hash_key {
2075         cmdline_fixed_string_t port;
2076         cmdline_fixed_string_t config;
2077         portid_t port_id;
2078         cmdline_fixed_string_t rss_hash_key;
2079         cmdline_fixed_string_t rss_type;
2080         cmdline_fixed_string_t key;
2081 };
2082
2083 static uint8_t
2084 hexa_digit_to_value(char hexa_digit)
2085 {
2086         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2087                 return (uint8_t) (hexa_digit - '0');
2088         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2089                 return (uint8_t) ((hexa_digit - 'a') + 10);
2090         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2091                 return (uint8_t) ((hexa_digit - 'A') + 10);
2092         /* Invalid hexa digit */
2093         return 0xFF;
2094 }
2095
2096 static uint8_t
2097 parse_and_check_key_hexa_digit(char *key, int idx)
2098 {
2099         uint8_t hexa_v;
2100
2101         hexa_v = hexa_digit_to_value(key[idx]);
2102         if (hexa_v == 0xFF)
2103                 printf("invalid key: character %c at position %d is not a "
2104                        "valid hexa digit\n", key[idx], idx);
2105         return hexa_v;
2106 }
2107
2108 static void
2109 cmd_config_rss_hash_key_parsed(void *parsed_result,
2110                                __attribute__((unused)) struct cmdline *cl,
2111                                __attribute__((unused)) void *data)
2112 {
2113         struct cmd_config_rss_hash_key *res = parsed_result;
2114         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2115         uint8_t xdgt0;
2116         uint8_t xdgt1;
2117         int i;
2118         struct rte_eth_dev_info dev_info;
2119         uint8_t hash_key_size;
2120         uint32_t key_len;
2121
2122         memset(&dev_info, 0, sizeof(dev_info));
2123         rte_eth_dev_info_get(res->port_id, &dev_info);
2124         if (dev_info.hash_key_size > 0 &&
2125                         dev_info.hash_key_size <= sizeof(hash_key))
2126                 hash_key_size = dev_info.hash_key_size;
2127         else {
2128                 printf("dev_info did not provide a valid hash key size\n");
2129                 return;
2130         }
2131         /* Check the length of the RSS hash key */
2132         key_len = strlen(res->key);
2133         if (key_len != (hash_key_size * 2)) {
2134                 printf("key length: %d invalid - key must be a string of %d"
2135                            " hexa-decimal numbers\n",
2136                            (int) key_len, hash_key_size * 2);
2137                 return;
2138         }
2139         /* Translate RSS hash key into binary representation */
2140         for (i = 0; i < hash_key_size; i++) {
2141                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2142                 if (xdgt0 == 0xFF)
2143                         return;
2144                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2145                 if (xdgt1 == 0xFF)
2146                         return;
2147                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2148         }
2149         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2150                         hash_key_size);
2151 }
2152
2153 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2155 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2157                                  "config");
2158 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2159         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2160 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2161         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2162                                  rss_hash_key, "rss-hash-key");
2163 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2164         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2165                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2166                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2167                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2168                                  "ipv6-tcp-ex#ipv6-udp-ex");
2169 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2170         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2171
2172 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2173         .f = cmd_config_rss_hash_key_parsed,
2174         .data = NULL,
2175         .help_str = "port config <port_id> rss-hash-key "
2176                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2177                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2178                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2179                 "<string of hex digits (variable length, NIC dependent)>",
2180         .tokens = {
2181                 (void *)&cmd_config_rss_hash_key_port,
2182                 (void *)&cmd_config_rss_hash_key_config,
2183                 (void *)&cmd_config_rss_hash_key_port_id,
2184                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2185                 (void *)&cmd_config_rss_hash_key_rss_type,
2186                 (void *)&cmd_config_rss_hash_key_value,
2187                 NULL,
2188         },
2189 };
2190
2191 /* *** configure port rxq/txq start/stop *** */
2192 struct cmd_config_rxtx_queue {
2193         cmdline_fixed_string_t port;
2194         portid_t portid;
2195         cmdline_fixed_string_t rxtxq;
2196         uint16_t qid;
2197         cmdline_fixed_string_t opname;
2198 };
2199
2200 static void
2201 cmd_config_rxtx_queue_parsed(void *parsed_result,
2202                         __attribute__((unused)) struct cmdline *cl,
2203                         __attribute__((unused)) void *data)
2204 {
2205         struct cmd_config_rxtx_queue *res = parsed_result;
2206         uint8_t isrx;
2207         uint8_t isstart;
2208         int ret = 0;
2209
2210         if (test_done == 0) {
2211                 printf("Please stop forwarding first\n");
2212                 return;
2213         }
2214
2215         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2216                 return;
2217
2218         if (port_is_started(res->portid) != 1) {
2219                 printf("Please start port %u first\n", res->portid);
2220                 return;
2221         }
2222
2223         if (!strcmp(res->rxtxq, "rxq"))
2224                 isrx = 1;
2225         else if (!strcmp(res->rxtxq, "txq"))
2226                 isrx = 0;
2227         else {
2228                 printf("Unknown parameter\n");
2229                 return;
2230         }
2231
2232         if (isrx && rx_queue_id_is_invalid(res->qid))
2233                 return;
2234         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2235                 return;
2236
2237         if (!strcmp(res->opname, "start"))
2238                 isstart = 1;
2239         else if (!strcmp(res->opname, "stop"))
2240                 isstart = 0;
2241         else {
2242                 printf("Unknown parameter\n");
2243                 return;
2244         }
2245
2246         if (isstart && isrx)
2247                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2248         else if (!isstart && isrx)
2249                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2250         else if (isstart && !isrx)
2251                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2252         else
2253                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2254
2255         if (ret == -ENOTSUP)
2256                 printf("Function not supported in PMD driver\n");
2257 }
2258
2259 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2260         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2261 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2262         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2263 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2264         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2265 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2266         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2267 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2268         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2269                                                 "start#stop");
2270
2271 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2272         .f = cmd_config_rxtx_queue_parsed,
2273         .data = NULL,
2274         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2275         .tokens = {
2276                 (void *)&cmd_config_speed_all_port,
2277                 (void *)&cmd_config_rxtx_queue_portid,
2278                 (void *)&cmd_config_rxtx_queue_rxtxq,
2279                 (void *)&cmd_config_rxtx_queue_qid,
2280                 (void *)&cmd_config_rxtx_queue_opname,
2281                 NULL,
2282         },
2283 };
2284
2285 /* *** Configure RSS RETA *** */
2286 struct cmd_config_rss_reta {
2287         cmdline_fixed_string_t port;
2288         cmdline_fixed_string_t keyword;
2289         portid_t port_id;
2290         cmdline_fixed_string_t name;
2291         cmdline_fixed_string_t list_name;
2292         cmdline_fixed_string_t list_of_items;
2293 };
2294
2295 static int
2296 parse_reta_config(const char *str,
2297                   struct rte_eth_rss_reta_entry64 *reta_conf,
2298                   uint16_t nb_entries)
2299 {
2300         int i;
2301         unsigned size;
2302         uint16_t hash_index, idx, shift;
2303         uint16_t nb_queue;
2304         char s[256];
2305         const char *p, *p0 = str;
2306         char *end;
2307         enum fieldnames {
2308                 FLD_HASH_INDEX = 0,
2309                 FLD_QUEUE,
2310                 _NUM_FLD
2311         };
2312         unsigned long int_fld[_NUM_FLD];
2313         char *str_fld[_NUM_FLD];
2314
2315         while ((p = strchr(p0,'(')) != NULL) {
2316                 ++p;
2317                 if((p0 = strchr(p,')')) == NULL)
2318                         return -1;
2319
2320                 size = p0 - p;
2321                 if(size >= sizeof(s))
2322                         return -1;
2323
2324                 snprintf(s, sizeof(s), "%.*s", size, p);
2325                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2326                         return -1;
2327                 for (i = 0; i < _NUM_FLD; i++) {
2328                         errno = 0;
2329                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2330                         if (errno != 0 || end == str_fld[i] ||
2331                                         int_fld[i] > 65535)
2332                                 return -1;
2333                 }
2334
2335                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2336                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2337
2338                 if (hash_index >= nb_entries) {
2339                         printf("Invalid RETA hash index=%d\n", hash_index);
2340                         return -1;
2341                 }
2342
2343                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2344                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2345                 reta_conf[idx].mask |= (1ULL << shift);
2346                 reta_conf[idx].reta[shift] = nb_queue;
2347         }
2348
2349         return 0;
2350 }
2351
2352 static void
2353 cmd_set_rss_reta_parsed(void *parsed_result,
2354                         __attribute__((unused)) struct cmdline *cl,
2355                         __attribute__((unused)) void *data)
2356 {
2357         int ret;
2358         struct rte_eth_dev_info dev_info;
2359         struct rte_eth_rss_reta_entry64 reta_conf[8];
2360         struct cmd_config_rss_reta *res = parsed_result;
2361
2362         memset(&dev_info, 0, sizeof(dev_info));
2363         rte_eth_dev_info_get(res->port_id, &dev_info);
2364         if (dev_info.reta_size == 0) {
2365                 printf("Redirection table size is 0 which is "
2366                                         "invalid for RSS\n");
2367                 return;
2368         } else
2369                 printf("The reta size of port %d is %u\n",
2370                         res->port_id, dev_info.reta_size);
2371         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2372                 printf("Currently do not support more than %u entries of "
2373                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2374                 return;
2375         }
2376
2377         memset(reta_conf, 0, sizeof(reta_conf));
2378         if (!strcmp(res->list_name, "reta")) {
2379                 if (parse_reta_config(res->list_of_items, reta_conf,
2380                                                 dev_info.reta_size)) {
2381                         printf("Invalid RSS Redirection Table "
2382                                         "config entered\n");
2383                         return;
2384                 }
2385                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2386                                 reta_conf, dev_info.reta_size);
2387                 if (ret != 0)
2388                         printf("Bad redirection table parameter, "
2389                                         "return code = %d \n", ret);
2390         }
2391 }
2392
2393 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2394         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2395 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2396         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2397 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2398         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2399 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2401 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2402         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2403 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2404         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2405                                  NULL);
2406 cmdline_parse_inst_t cmd_config_rss_reta = {
2407         .f = cmd_set_rss_reta_parsed,
2408         .data = NULL,
2409         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2410         .tokens = {
2411                 (void *)&cmd_config_rss_reta_port,
2412                 (void *)&cmd_config_rss_reta_keyword,
2413                 (void *)&cmd_config_rss_reta_port_id,
2414                 (void *)&cmd_config_rss_reta_name,
2415                 (void *)&cmd_config_rss_reta_list_name,
2416                 (void *)&cmd_config_rss_reta_list_of_items,
2417                 NULL,
2418         },
2419 };
2420
2421 /* *** SHOW PORT RETA INFO *** */
2422 struct cmd_showport_reta {
2423         cmdline_fixed_string_t show;
2424         cmdline_fixed_string_t port;
2425         portid_t port_id;
2426         cmdline_fixed_string_t rss;
2427         cmdline_fixed_string_t reta;
2428         uint16_t size;
2429         cmdline_fixed_string_t list_of_items;
2430 };
2431
2432 static int
2433 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2434                            uint16_t nb_entries,
2435                            char *str)
2436 {
2437         uint32_t size;
2438         const char *p, *p0 = str;
2439         char s[256];
2440         char *end;
2441         char *str_fld[8];
2442         uint16_t i;
2443         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2444                         RTE_RETA_GROUP_SIZE;
2445         int ret;
2446
2447         p = strchr(p0, '(');
2448         if (p == NULL)
2449                 return -1;
2450         p++;
2451         p0 = strchr(p, ')');
2452         if (p0 == NULL)
2453                 return -1;
2454         size = p0 - p;
2455         if (size >= sizeof(s)) {
2456                 printf("The string size exceeds the internal buffer size\n");
2457                 return -1;
2458         }
2459         snprintf(s, sizeof(s), "%.*s", size, p);
2460         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2461         if (ret <= 0 || ret != num) {
2462                 printf("The bits of masks do not match the number of "
2463                                         "reta entries: %u\n", num);
2464                 return -1;
2465         }
2466         for (i = 0; i < ret; i++)
2467                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2468
2469         return 0;
2470 }
2471
2472 static void
2473 cmd_showport_reta_parsed(void *parsed_result,
2474                          __attribute__((unused)) struct cmdline *cl,
2475                          __attribute__((unused)) void *data)
2476 {
2477         struct cmd_showport_reta *res = parsed_result;
2478         struct rte_eth_rss_reta_entry64 reta_conf[8];
2479         struct rte_eth_dev_info dev_info;
2480         uint16_t max_reta_size;
2481
2482         memset(&dev_info, 0, sizeof(dev_info));
2483         rte_eth_dev_info_get(res->port_id, &dev_info);
2484         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2485         if (res->size == 0 || res->size > max_reta_size) {
2486                 printf("Invalid redirection table size: %u (1-%u)\n",
2487                         res->size, max_reta_size);
2488                 return;
2489         }
2490
2491         memset(reta_conf, 0, sizeof(reta_conf));
2492         if (showport_parse_reta_config(reta_conf, res->size,
2493                                 res->list_of_items) < 0) {
2494                 printf("Invalid string: %s for reta masks\n",
2495                                         res->list_of_items);
2496                 return;
2497         }
2498         port_rss_reta_info(res->port_id, reta_conf, res->size);
2499 }
2500
2501 cmdline_parse_token_string_t cmd_showport_reta_show =
2502         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2503 cmdline_parse_token_string_t cmd_showport_reta_port =
2504         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2505 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2506         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2507 cmdline_parse_token_string_t cmd_showport_reta_rss =
2508         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2509 cmdline_parse_token_string_t cmd_showport_reta_reta =
2510         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2511 cmdline_parse_token_num_t cmd_showport_reta_size =
2512         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2513 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2514         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2515                                         list_of_items, NULL);
2516
2517 cmdline_parse_inst_t cmd_showport_reta = {
2518         .f = cmd_showport_reta_parsed,
2519         .data = NULL,
2520         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2521         .tokens = {
2522                 (void *)&cmd_showport_reta_show,
2523                 (void *)&cmd_showport_reta_port,
2524                 (void *)&cmd_showport_reta_port_id,
2525                 (void *)&cmd_showport_reta_rss,
2526                 (void *)&cmd_showport_reta_reta,
2527                 (void *)&cmd_showport_reta_size,
2528                 (void *)&cmd_showport_reta_list_of_items,
2529                 NULL,
2530         },
2531 };
2532
2533 /* *** Show RSS hash configuration *** */
2534 struct cmd_showport_rss_hash {
2535         cmdline_fixed_string_t show;
2536         cmdline_fixed_string_t port;
2537         portid_t port_id;
2538         cmdline_fixed_string_t rss_hash;
2539         cmdline_fixed_string_t rss_type;
2540         cmdline_fixed_string_t key; /* optional argument */
2541 };
2542
2543 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2544                                 __attribute__((unused)) struct cmdline *cl,
2545                                 void *show_rss_key)
2546 {
2547         struct cmd_showport_rss_hash *res = parsed_result;
2548
2549         port_rss_hash_conf_show(res->port_id, res->rss_type,
2550                                 show_rss_key != NULL);
2551 }
2552
2553 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2554         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2555 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2556         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2557 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2558         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2559 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2560         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2561                                  "rss-hash");
2562 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2563         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2564                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2565                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2566                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2567                                  "ipv6-tcp-ex#ipv6-udp-ex");
2568 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2569         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2570
2571 cmdline_parse_inst_t cmd_showport_rss_hash = {
2572         .f = cmd_showport_rss_hash_parsed,
2573         .data = NULL,
2574         .help_str = "show port <port_id> rss-hash "
2575                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2576                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2577                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2578         .tokens = {
2579                 (void *)&cmd_showport_rss_hash_show,
2580                 (void *)&cmd_showport_rss_hash_port,
2581                 (void *)&cmd_showport_rss_hash_port_id,
2582                 (void *)&cmd_showport_rss_hash_rss_hash,
2583                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2584                 NULL,
2585         },
2586 };
2587
2588 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2589         .f = cmd_showport_rss_hash_parsed,
2590         .data = (void *)1,
2591         .help_str = "show port <port_id> rss-hash "
2592                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2593                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2594                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2595         .tokens = {
2596                 (void *)&cmd_showport_rss_hash_show,
2597                 (void *)&cmd_showport_rss_hash_port,
2598                 (void *)&cmd_showport_rss_hash_port_id,
2599                 (void *)&cmd_showport_rss_hash_rss_hash,
2600                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2601                 (void *)&cmd_showport_rss_hash_rss_key,
2602                 NULL,
2603         },
2604 };
2605
2606 /* *** Configure DCB *** */
2607 struct cmd_config_dcb {
2608         cmdline_fixed_string_t port;
2609         cmdline_fixed_string_t config;
2610         portid_t port_id;
2611         cmdline_fixed_string_t dcb;
2612         cmdline_fixed_string_t vt;
2613         cmdline_fixed_string_t vt_en;
2614         uint8_t num_tcs;
2615         cmdline_fixed_string_t pfc;
2616         cmdline_fixed_string_t pfc_en;
2617 };
2618
2619 static void
2620 cmd_config_dcb_parsed(void *parsed_result,
2621                         __attribute__((unused)) struct cmdline *cl,
2622                         __attribute__((unused)) void *data)
2623 {
2624         struct cmd_config_dcb *res = parsed_result;
2625         portid_t port_id = res->port_id;
2626         struct rte_port *port;
2627         uint8_t pfc_en;
2628         int ret;
2629
2630         port = &ports[port_id];
2631         /** Check if the port is not started **/
2632         if (port->port_status != RTE_PORT_STOPPED) {
2633                 printf("Please stop port %d first\n", port_id);
2634                 return;
2635         }
2636
2637         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2638                 printf("The invalid number of traffic class,"
2639                         " only 4 or 8 allowed.\n");
2640                 return;
2641         }
2642
2643         if (nb_fwd_lcores < res->num_tcs) {
2644                 printf("nb_cores shouldn't be less than number of TCs.\n");
2645                 return;
2646         }
2647         if (!strncmp(res->pfc_en, "on", 2))
2648                 pfc_en = 1;
2649         else
2650                 pfc_en = 0;
2651
2652         /* DCB in VT mode */
2653         if (!strncmp(res->vt_en, "on", 2))
2654                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2655                                 (enum rte_eth_nb_tcs)res->num_tcs,
2656                                 pfc_en);
2657         else
2658                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2659                                 (enum rte_eth_nb_tcs)res->num_tcs,
2660                                 pfc_en);
2661
2662
2663         if (ret != 0) {
2664                 printf("Cannot initialize network ports.\n");
2665                 return;
2666         }
2667
2668         cmd_reconfig_device_queue(port_id, 1, 1);
2669 }
2670
2671 cmdline_parse_token_string_t cmd_config_dcb_port =
2672         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2673 cmdline_parse_token_string_t cmd_config_dcb_config =
2674         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2675 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2676         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2677 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2678         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2679 cmdline_parse_token_string_t cmd_config_dcb_vt =
2680         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2681 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2682         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2683 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2684         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2685 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2686         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2687 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2689
2690 cmdline_parse_inst_t cmd_config_dcb = {
2691         .f = cmd_config_dcb_parsed,
2692         .data = NULL,
2693         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2694         .tokens = {
2695                 (void *)&cmd_config_dcb_port,
2696                 (void *)&cmd_config_dcb_config,
2697                 (void *)&cmd_config_dcb_port_id,
2698                 (void *)&cmd_config_dcb_dcb,
2699                 (void *)&cmd_config_dcb_vt,
2700                 (void *)&cmd_config_dcb_vt_en,
2701                 (void *)&cmd_config_dcb_num_tcs,
2702                 (void *)&cmd_config_dcb_pfc,
2703                 (void *)&cmd_config_dcb_pfc_en,
2704                 NULL,
2705         },
2706 };
2707
2708 /* *** configure number of packets per burst *** */
2709 struct cmd_config_burst {
2710         cmdline_fixed_string_t port;
2711         cmdline_fixed_string_t keyword;
2712         cmdline_fixed_string_t all;
2713         cmdline_fixed_string_t name;
2714         uint16_t value;
2715 };
2716
2717 static void
2718 cmd_config_burst_parsed(void *parsed_result,
2719                         __attribute__((unused)) struct cmdline *cl,
2720                         __attribute__((unused)) void *data)
2721 {
2722         struct cmd_config_burst *res = parsed_result;
2723         struct rte_eth_dev_info dev_info;
2724         uint16_t rec_nb_pkts;
2725
2726         if (!all_ports_stopped()) {
2727                 printf("Please stop all ports first\n");
2728                 return;
2729         }
2730
2731         if (!strcmp(res->name, "burst")) {
2732                 if (res->value == 0) {
2733                         /* If user gives a value of zero, query the PMD for
2734                          * its recommended Rx burst size. Testpmd uses a single
2735                          * size for all ports, so assume all ports are the same
2736                          * NIC model and use the values from Port 0.
2737                          */
2738                         rte_eth_dev_info_get(0, &dev_info);
2739                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2740
2741                         if (rec_nb_pkts == 0) {
2742                                 printf("PMD does not recommend a burst size.\n"
2743                                         "User provided value must be between"
2744                                         " 1 and %d\n", MAX_PKT_BURST);
2745                                 return;
2746                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2747                                 printf("PMD recommended burst size of %d"
2748                                         " exceeds maximum value of %d\n",
2749                                         rec_nb_pkts, MAX_PKT_BURST);
2750                                 return;
2751                         }
2752                         printf("Using PMD-provided burst value of %d\n",
2753                                 rec_nb_pkts);
2754                         nb_pkt_per_burst = rec_nb_pkts;
2755                 } else if (res->value > MAX_PKT_BURST) {
2756                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2757                         return;
2758                 } else
2759                         nb_pkt_per_burst = res->value;
2760         } else {
2761                 printf("Unknown parameter\n");
2762                 return;
2763         }
2764
2765         init_port_config();
2766
2767         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2768 }
2769
2770 cmdline_parse_token_string_t cmd_config_burst_port =
2771         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2772 cmdline_parse_token_string_t cmd_config_burst_keyword =
2773         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2774 cmdline_parse_token_string_t cmd_config_burst_all =
2775         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2776 cmdline_parse_token_string_t cmd_config_burst_name =
2777         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2778 cmdline_parse_token_num_t cmd_config_burst_value =
2779         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2780
2781 cmdline_parse_inst_t cmd_config_burst = {
2782         .f = cmd_config_burst_parsed,
2783         .data = NULL,
2784         .help_str = "port config all burst <value>",
2785         .tokens = {
2786                 (void *)&cmd_config_burst_port,
2787                 (void *)&cmd_config_burst_keyword,
2788                 (void *)&cmd_config_burst_all,
2789                 (void *)&cmd_config_burst_name,
2790                 (void *)&cmd_config_burst_value,
2791                 NULL,
2792         },
2793 };
2794
2795 /* *** configure rx/tx queues *** */
2796 struct cmd_config_thresh {
2797         cmdline_fixed_string_t port;
2798         cmdline_fixed_string_t keyword;
2799         cmdline_fixed_string_t all;
2800         cmdline_fixed_string_t name;
2801         uint8_t value;
2802 };
2803
2804 static void
2805 cmd_config_thresh_parsed(void *parsed_result,
2806                         __attribute__((unused)) struct cmdline *cl,
2807                         __attribute__((unused)) void *data)
2808 {
2809         struct cmd_config_thresh *res = parsed_result;
2810
2811         if (!all_ports_stopped()) {
2812                 printf("Please stop all ports first\n");
2813                 return;
2814         }
2815
2816         if (!strcmp(res->name, "txpt"))
2817                 tx_pthresh = res->value;
2818         else if(!strcmp(res->name, "txht"))
2819                 tx_hthresh = res->value;
2820         else if(!strcmp(res->name, "txwt"))
2821                 tx_wthresh = res->value;
2822         else if(!strcmp(res->name, "rxpt"))
2823                 rx_pthresh = res->value;
2824         else if(!strcmp(res->name, "rxht"))
2825                 rx_hthresh = res->value;
2826         else if(!strcmp(res->name, "rxwt"))
2827                 rx_wthresh = res->value;
2828         else {
2829                 printf("Unknown parameter\n");
2830                 return;
2831         }
2832
2833         init_port_config();
2834
2835         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2836 }
2837
2838 cmdline_parse_token_string_t cmd_config_thresh_port =
2839         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2840 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2841         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2842 cmdline_parse_token_string_t cmd_config_thresh_all =
2843         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2844 cmdline_parse_token_string_t cmd_config_thresh_name =
2845         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2846                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2847 cmdline_parse_token_num_t cmd_config_thresh_value =
2848         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2849
2850 cmdline_parse_inst_t cmd_config_thresh = {
2851         .f = cmd_config_thresh_parsed,
2852         .data = NULL,
2853         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2854         .tokens = {
2855                 (void *)&cmd_config_thresh_port,
2856                 (void *)&cmd_config_thresh_keyword,
2857                 (void *)&cmd_config_thresh_all,
2858                 (void *)&cmd_config_thresh_name,
2859                 (void *)&cmd_config_thresh_value,
2860                 NULL,
2861         },
2862 };
2863
2864 /* *** configure free/rs threshold *** */
2865 struct cmd_config_threshold {
2866         cmdline_fixed_string_t port;
2867         cmdline_fixed_string_t keyword;
2868         cmdline_fixed_string_t all;
2869         cmdline_fixed_string_t name;
2870         uint16_t value;
2871 };
2872
2873 static void
2874 cmd_config_threshold_parsed(void *parsed_result,
2875                         __attribute__((unused)) struct cmdline *cl,
2876                         __attribute__((unused)) void *data)
2877 {
2878         struct cmd_config_threshold *res = parsed_result;
2879
2880         if (!all_ports_stopped()) {
2881                 printf("Please stop all ports first\n");
2882                 return;
2883         }
2884
2885         if (!strcmp(res->name, "txfreet"))
2886                 tx_free_thresh = res->value;
2887         else if (!strcmp(res->name, "txrst"))
2888                 tx_rs_thresh = res->value;
2889         else if (!strcmp(res->name, "rxfreet"))
2890                 rx_free_thresh = res->value;
2891         else {
2892                 printf("Unknown parameter\n");
2893                 return;
2894         }
2895
2896         init_port_config();
2897
2898         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2899 }
2900
2901 cmdline_parse_token_string_t cmd_config_threshold_port =
2902         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2903 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2904         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2905                                                                 "config");
2906 cmdline_parse_token_string_t cmd_config_threshold_all =
2907         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2908 cmdline_parse_token_string_t cmd_config_threshold_name =
2909         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2910                                                 "txfreet#txrst#rxfreet");
2911 cmdline_parse_token_num_t cmd_config_threshold_value =
2912         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2913
2914 cmdline_parse_inst_t cmd_config_threshold = {
2915         .f = cmd_config_threshold_parsed,
2916         .data = NULL,
2917         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2918         .tokens = {
2919                 (void *)&cmd_config_threshold_port,
2920                 (void *)&cmd_config_threshold_keyword,
2921                 (void *)&cmd_config_threshold_all,
2922                 (void *)&cmd_config_threshold_name,
2923                 (void *)&cmd_config_threshold_value,
2924                 NULL,
2925         },
2926 };
2927
2928 /* *** stop *** */
2929 struct cmd_stop_result {
2930         cmdline_fixed_string_t stop;
2931 };
2932
2933 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2934                             __attribute__((unused)) struct cmdline *cl,
2935                             __attribute__((unused)) void *data)
2936 {
2937         stop_packet_forwarding();
2938 }
2939
2940 cmdline_parse_token_string_t cmd_stop_stop =
2941         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2942
2943 cmdline_parse_inst_t cmd_stop = {
2944         .f = cmd_stop_parsed,
2945         .data = NULL,
2946         .help_str = "stop: Stop packet forwarding",
2947         .tokens = {
2948                 (void *)&cmd_stop_stop,
2949                 NULL,
2950         },
2951 };
2952
2953 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2954
2955 unsigned int
2956 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2957                 unsigned int *parsed_items, int check_unique_values)
2958 {
2959         unsigned int nb_item;
2960         unsigned int value;
2961         unsigned int i;
2962         unsigned int j;
2963         int value_ok;
2964         char c;
2965
2966         /*
2967          * First parse all items in the list and store their value.
2968          */
2969         value = 0;
2970         nb_item = 0;
2971         value_ok = 0;
2972         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2973                 c = str[i];
2974                 if ((c >= '0') && (c <= '9')) {
2975                         value = (unsigned int) (value * 10 + (c - '0'));
2976                         value_ok = 1;
2977                         continue;
2978                 }
2979                 if (c != ',') {
2980                         printf("character %c is not a decimal digit\n", c);
2981                         return 0;
2982                 }
2983                 if (! value_ok) {
2984                         printf("No valid value before comma\n");
2985                         return 0;
2986                 }
2987                 if (nb_item < max_items) {
2988                         parsed_items[nb_item] = value;
2989                         value_ok = 0;
2990                         value = 0;
2991                 }
2992                 nb_item++;
2993         }
2994         if (nb_item >= max_items) {
2995                 printf("Number of %s = %u > %u (maximum items)\n",
2996                        item_name, nb_item + 1, max_items);
2997                 return 0;
2998         }
2999         parsed_items[nb_item++] = value;
3000         if (! check_unique_values)
3001                 return nb_item;
3002
3003         /*
3004          * Then, check that all values in the list are differents.
3005          * No optimization here...
3006          */
3007         for (i = 0; i < nb_item; i++) {
3008                 for (j = i + 1; j < nb_item; j++) {
3009                         if (parsed_items[j] == parsed_items[i]) {
3010                                 printf("duplicated %s %u at index %u and %u\n",
3011                                        item_name, parsed_items[i], i, j);
3012                                 return 0;
3013                         }
3014                 }
3015         }
3016         return nb_item;
3017 }
3018
3019 struct cmd_set_list_result {
3020         cmdline_fixed_string_t cmd_keyword;
3021         cmdline_fixed_string_t list_name;
3022         cmdline_fixed_string_t list_of_items;
3023 };
3024
3025 static void cmd_set_list_parsed(void *parsed_result,
3026                                 __attribute__((unused)) struct cmdline *cl,
3027                                 __attribute__((unused)) void *data)
3028 {
3029         struct cmd_set_list_result *res;
3030         union {
3031                 unsigned int lcorelist[RTE_MAX_LCORE];
3032                 unsigned int portlist[RTE_MAX_ETHPORTS];
3033         } parsed_items;
3034         unsigned int nb_item;
3035
3036         if (test_done == 0) {
3037                 printf("Please stop forwarding first\n");
3038                 return;
3039         }
3040
3041         res = parsed_result;
3042         if (!strcmp(res->list_name, "corelist")) {
3043                 nb_item = parse_item_list(res->list_of_items, "core",
3044                                           RTE_MAX_LCORE,
3045                                           parsed_items.lcorelist, 1);
3046                 if (nb_item > 0) {
3047                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3048                         fwd_config_setup();
3049                 }
3050                 return;
3051         }
3052         if (!strcmp(res->list_name, "portlist")) {
3053                 nb_item = parse_item_list(res->list_of_items, "port",
3054                                           RTE_MAX_ETHPORTS,
3055                                           parsed_items.portlist, 1);
3056                 if (nb_item > 0) {
3057                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3058                         fwd_config_setup();
3059                 }
3060         }
3061 }
3062
3063 cmdline_parse_token_string_t cmd_set_list_keyword =
3064         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3065                                  "set");
3066 cmdline_parse_token_string_t cmd_set_list_name =
3067         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3068                                  "corelist#portlist");
3069 cmdline_parse_token_string_t cmd_set_list_of_items =
3070         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3071                                  NULL);
3072
3073 cmdline_parse_inst_t cmd_set_fwd_list = {
3074         .f = cmd_set_list_parsed,
3075         .data = NULL,
3076         .help_str = "set corelist|portlist <list0[,list1]*>",
3077         .tokens = {
3078                 (void *)&cmd_set_list_keyword,
3079                 (void *)&cmd_set_list_name,
3080                 (void *)&cmd_set_list_of_items,
3081                 NULL,
3082         },
3083 };
3084
3085 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3086
3087 struct cmd_setmask_result {
3088         cmdline_fixed_string_t set;
3089         cmdline_fixed_string_t mask;
3090         uint64_t hexavalue;
3091 };
3092
3093 static void cmd_set_mask_parsed(void *parsed_result,
3094                                 __attribute__((unused)) struct cmdline *cl,
3095                                 __attribute__((unused)) void *data)
3096 {
3097         struct cmd_setmask_result *res = parsed_result;
3098
3099         if (test_done == 0) {
3100                 printf("Please stop forwarding first\n");
3101                 return;
3102         }
3103         if (!strcmp(res->mask, "coremask")) {
3104                 set_fwd_lcores_mask(res->hexavalue);
3105                 fwd_config_setup();
3106         } else if (!strcmp(res->mask, "portmask")) {
3107                 set_fwd_ports_mask(res->hexavalue);
3108                 fwd_config_setup();
3109         }
3110 }
3111
3112 cmdline_parse_token_string_t cmd_setmask_set =
3113         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3114 cmdline_parse_token_string_t cmd_setmask_mask =
3115         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3116                                  "coremask#portmask");
3117 cmdline_parse_token_num_t cmd_setmask_value =
3118         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3119
3120 cmdline_parse_inst_t cmd_set_fwd_mask = {
3121         .f = cmd_set_mask_parsed,
3122         .data = NULL,
3123         .help_str = "set coremask|portmask <hexadecimal value>",
3124         .tokens = {
3125                 (void *)&cmd_setmask_set,
3126                 (void *)&cmd_setmask_mask,
3127                 (void *)&cmd_setmask_value,
3128                 NULL,
3129         },
3130 };
3131
3132 /*
3133  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3134  */
3135 struct cmd_set_result {
3136         cmdline_fixed_string_t set;
3137         cmdline_fixed_string_t what;
3138         uint16_t value;
3139 };
3140
3141 static void cmd_set_parsed(void *parsed_result,
3142                            __attribute__((unused)) struct cmdline *cl,
3143                            __attribute__((unused)) void *data)
3144 {
3145         struct cmd_set_result *res = parsed_result;
3146         if (!strcmp(res->what, "nbport")) {
3147                 set_fwd_ports_number(res->value);
3148                 fwd_config_setup();
3149         } else if (!strcmp(res->what, "nbcore")) {
3150                 set_fwd_lcores_number(res->value);
3151                 fwd_config_setup();
3152         } else if (!strcmp(res->what, "burst"))
3153                 set_nb_pkt_per_burst(res->value);
3154         else if (!strcmp(res->what, "verbose"))
3155                 set_verbose_level(res->value);
3156 }
3157
3158 cmdline_parse_token_string_t cmd_set_set =
3159         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3160 cmdline_parse_token_string_t cmd_set_what =
3161         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3162                                  "nbport#nbcore#burst#verbose");
3163 cmdline_parse_token_num_t cmd_set_value =
3164         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3165
3166 cmdline_parse_inst_t cmd_set_numbers = {
3167         .f = cmd_set_parsed,
3168         .data = NULL,
3169         .help_str = "set nbport|nbcore|burst|verbose <value>",
3170         .tokens = {
3171                 (void *)&cmd_set_set,
3172                 (void *)&cmd_set_what,
3173                 (void *)&cmd_set_value,
3174                 NULL,
3175         },
3176 };
3177
3178 /* *** SET LOG LEVEL CONFIGURATION *** */
3179
3180 struct cmd_set_log_result {
3181         cmdline_fixed_string_t set;
3182         cmdline_fixed_string_t log;
3183         cmdline_fixed_string_t type;
3184         uint32_t level;
3185 };
3186
3187 static void
3188 cmd_set_log_parsed(void *parsed_result,
3189                    __attribute__((unused)) struct cmdline *cl,
3190                    __attribute__((unused)) void *data)
3191 {
3192         struct cmd_set_log_result *res;
3193         int ret;
3194
3195         res = parsed_result;
3196         if (!strcmp(res->type, "global"))
3197                 rte_log_set_global_level(res->level);
3198         else {
3199                 ret = rte_log_set_level_regexp(res->type, res->level);
3200                 if (ret < 0)
3201                         printf("Unable to set log level\n");
3202         }
3203 }
3204
3205 cmdline_parse_token_string_t cmd_set_log_set =
3206         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3207 cmdline_parse_token_string_t cmd_set_log_log =
3208         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3209 cmdline_parse_token_string_t cmd_set_log_type =
3210         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3211 cmdline_parse_token_num_t cmd_set_log_level =
3212         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3213
3214 cmdline_parse_inst_t cmd_set_log = {
3215         .f = cmd_set_log_parsed,
3216         .data = NULL,
3217         .help_str = "set log global|<type> <level>",
3218         .tokens = {
3219                 (void *)&cmd_set_log_set,
3220                 (void *)&cmd_set_log_log,
3221                 (void *)&cmd_set_log_type,
3222                 (void *)&cmd_set_log_level,
3223                 NULL,
3224         },
3225 };
3226
3227 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3228
3229 struct cmd_set_txpkts_result {
3230         cmdline_fixed_string_t cmd_keyword;
3231         cmdline_fixed_string_t txpkts;
3232         cmdline_fixed_string_t seg_lengths;
3233 };
3234
3235 static void
3236 cmd_set_txpkts_parsed(void *parsed_result,
3237                       __attribute__((unused)) struct cmdline *cl,
3238                       __attribute__((unused)) void *data)
3239 {
3240         struct cmd_set_txpkts_result *res;
3241         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3242         unsigned int nb_segs;
3243
3244         res = parsed_result;
3245         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3246                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3247         if (nb_segs > 0)
3248                 set_tx_pkt_segments(seg_lengths, nb_segs);
3249 }
3250
3251 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3252         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3253                                  cmd_keyword, "set");
3254 cmdline_parse_token_string_t cmd_set_txpkts_name =
3255         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3256                                  txpkts, "txpkts");
3257 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3258         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3259                                  seg_lengths, NULL);
3260
3261 cmdline_parse_inst_t cmd_set_txpkts = {
3262         .f = cmd_set_txpkts_parsed,
3263         .data = NULL,
3264         .help_str = "set txpkts <len0[,len1]*>",
3265         .tokens = {
3266                 (void *)&cmd_set_txpkts_keyword,
3267                 (void *)&cmd_set_txpkts_name,
3268                 (void *)&cmd_set_txpkts_lengths,
3269                 NULL,
3270         },
3271 };
3272
3273 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3274
3275 struct cmd_set_txsplit_result {
3276         cmdline_fixed_string_t cmd_keyword;
3277         cmdline_fixed_string_t txsplit;
3278         cmdline_fixed_string_t mode;
3279 };
3280
3281 static void
3282 cmd_set_txsplit_parsed(void *parsed_result,
3283                       __attribute__((unused)) struct cmdline *cl,
3284                       __attribute__((unused)) void *data)
3285 {
3286         struct cmd_set_txsplit_result *res;
3287
3288         res = parsed_result;
3289         set_tx_pkt_split(res->mode);
3290 }
3291
3292 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3293         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3294                                  cmd_keyword, "set");
3295 cmdline_parse_token_string_t cmd_set_txsplit_name =
3296         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3297                                  txsplit, "txsplit");
3298 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3299         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3300                                  mode, NULL);
3301
3302 cmdline_parse_inst_t cmd_set_txsplit = {
3303         .f = cmd_set_txsplit_parsed,
3304         .data = NULL,
3305         .help_str = "set txsplit on|off|rand",
3306         .tokens = {
3307                 (void *)&cmd_set_txsplit_keyword,
3308                 (void *)&cmd_set_txsplit_name,
3309                 (void *)&cmd_set_txsplit_mode,
3310                 NULL,
3311         },
3312 };
3313
3314 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3315 struct cmd_rx_vlan_filter_all_result {
3316         cmdline_fixed_string_t rx_vlan;
3317         cmdline_fixed_string_t what;
3318         cmdline_fixed_string_t all;
3319         portid_t port_id;
3320 };
3321
3322 static void
3323 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3324                               __attribute__((unused)) struct cmdline *cl,
3325                               __attribute__((unused)) void *data)
3326 {
3327         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3328
3329         if (!strcmp(res->what, "add"))
3330                 rx_vlan_all_filter_set(res->port_id, 1);
3331         else
3332                 rx_vlan_all_filter_set(res->port_id, 0);
3333 }
3334
3335 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3336         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3337                                  rx_vlan, "rx_vlan");
3338 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3339         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3340                                  what, "add#rm");
3341 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3342         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3343                                  all, "all");
3344 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3345         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3346                               port_id, UINT16);
3347
3348 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3349         .f = cmd_rx_vlan_filter_all_parsed,
3350         .data = NULL,
3351         .help_str = "rx_vlan add|rm all <port_id>: "
3352                 "Add/Remove all identifiers to/from the set of VLAN "
3353                 "identifiers filtered by a port",
3354         .tokens = {
3355                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3356                 (void *)&cmd_rx_vlan_filter_all_what,
3357                 (void *)&cmd_rx_vlan_filter_all_all,
3358                 (void *)&cmd_rx_vlan_filter_all_portid,
3359                 NULL,
3360         },
3361 };
3362
3363 /* *** VLAN OFFLOAD SET ON A PORT *** */
3364 struct cmd_vlan_offload_result {
3365         cmdline_fixed_string_t vlan;
3366         cmdline_fixed_string_t set;
3367         cmdline_fixed_string_t vlan_type;
3368         cmdline_fixed_string_t what;
3369         cmdline_fixed_string_t on;
3370         cmdline_fixed_string_t port_id;
3371 };
3372
3373 static void
3374 cmd_vlan_offload_parsed(void *parsed_result,
3375                           __attribute__((unused)) struct cmdline *cl,
3376                           __attribute__((unused)) void *data)
3377 {
3378         int on;
3379         struct cmd_vlan_offload_result *res = parsed_result;
3380         char *str;
3381         int i, len = 0;
3382         portid_t port_id = 0;
3383         unsigned int tmp;
3384
3385         str = res->port_id;
3386         len = strnlen(str, STR_TOKEN_SIZE);
3387         i = 0;
3388         /* Get port_id first */
3389         while(i < len){
3390                 if(str[i] == ',')
3391                         break;
3392
3393                 i++;
3394         }
3395         str[i]='\0';
3396         tmp = strtoul(str, NULL, 0);
3397         /* If port_id greater that what portid_t can represent, return */
3398         if(tmp >= RTE_MAX_ETHPORTS)
3399                 return;
3400         port_id = (portid_t)tmp;
3401
3402         if (!strcmp(res->on, "on"))
3403                 on = 1;
3404         else
3405                 on = 0;
3406
3407         if (!strcmp(res->what, "strip"))
3408                 rx_vlan_strip_set(port_id,  on);
3409         else if(!strcmp(res->what, "stripq")){
3410                 uint16_t queue_id = 0;
3411
3412                 /* No queue_id, return */
3413                 if(i + 1 >= len) {
3414                         printf("must specify (port,queue_id)\n");
3415                         return;
3416                 }
3417                 tmp = strtoul(str + i + 1, NULL, 0);
3418                 /* If queue_id greater that what 16-bits can represent, return */
3419                 if(tmp > 0xffff)
3420                         return;
3421
3422                 queue_id = (uint16_t)tmp;
3423                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3424         }
3425         else if (!strcmp(res->what, "filter"))
3426                 rx_vlan_filter_set(port_id, on);
3427         else
3428                 vlan_extend_set(port_id, on);
3429
3430         return;
3431 }
3432
3433 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3434         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3435                                  vlan, "vlan");
3436 cmdline_parse_token_string_t cmd_vlan_offload_set =
3437         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3438                                  set, "set");
3439 cmdline_parse_token_string_t cmd_vlan_offload_what =
3440         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3441                                  what, "strip#filter#qinq#stripq");
3442 cmdline_parse_token_string_t cmd_vlan_offload_on =
3443         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3444                               on, "on#off");
3445 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3446         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3447                               port_id, NULL);
3448
3449 cmdline_parse_inst_t cmd_vlan_offload = {
3450         .f = cmd_vlan_offload_parsed,
3451         .data = NULL,
3452         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3453                 "<port_id[,queue_id]>: "
3454                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3455         .tokens = {
3456                 (void *)&cmd_vlan_offload_vlan,
3457                 (void *)&cmd_vlan_offload_set,
3458                 (void *)&cmd_vlan_offload_what,
3459                 (void *)&cmd_vlan_offload_on,
3460                 (void *)&cmd_vlan_offload_portid,
3461                 NULL,
3462         },
3463 };
3464
3465 /* *** VLAN TPID SET ON A PORT *** */
3466 struct cmd_vlan_tpid_result {
3467         cmdline_fixed_string_t vlan;
3468         cmdline_fixed_string_t set;
3469         cmdline_fixed_string_t vlan_type;
3470         cmdline_fixed_string_t what;
3471         uint16_t tp_id;
3472         portid_t port_id;
3473 };
3474
3475 static void
3476 cmd_vlan_tpid_parsed(void *parsed_result,
3477                           __attribute__((unused)) struct cmdline *cl,
3478                           __attribute__((unused)) void *data)
3479 {
3480         struct cmd_vlan_tpid_result *res = parsed_result;
3481         enum rte_vlan_type vlan_type;
3482
3483         if (!strcmp(res->vlan_type, "inner"))
3484                 vlan_type = ETH_VLAN_TYPE_INNER;
3485         else if (!strcmp(res->vlan_type, "outer"))
3486                 vlan_type = ETH_VLAN_TYPE_OUTER;
3487         else {
3488                 printf("Unknown vlan type\n");
3489                 return;
3490         }
3491         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3492 }
3493
3494 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3495         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3496                                  vlan, "vlan");
3497 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3498         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3499                                  set, "set");
3500 cmdline_parse_token_string_t cmd_vlan_type =
3501         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3502                                  vlan_type, "inner#outer");
3503 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3504         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3505                                  what, "tpid");
3506 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3507         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3508                               tp_id, UINT16);
3509 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3510         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3511                               port_id, UINT16);
3512
3513 cmdline_parse_inst_t cmd_vlan_tpid = {
3514         .f = cmd_vlan_tpid_parsed,
3515         .data = NULL,
3516         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3517                 "Set the VLAN Ether type",
3518         .tokens = {
3519                 (void *)&cmd_vlan_tpid_vlan,
3520                 (void *)&cmd_vlan_tpid_set,
3521                 (void *)&cmd_vlan_type,
3522                 (void *)&cmd_vlan_tpid_what,
3523                 (void *)&cmd_vlan_tpid_tpid,
3524                 (void *)&cmd_vlan_tpid_portid,
3525                 NULL,
3526         },
3527 };
3528
3529 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3530 struct cmd_rx_vlan_filter_result {
3531         cmdline_fixed_string_t rx_vlan;
3532         cmdline_fixed_string_t what;
3533         uint16_t vlan_id;
3534         portid_t port_id;
3535 };
3536
3537 static void
3538 cmd_rx_vlan_filter_parsed(void *parsed_result,
3539                           __attribute__((unused)) struct cmdline *cl,
3540                           __attribute__((unused)) void *data)
3541 {
3542         struct cmd_rx_vlan_filter_result *res = parsed_result;
3543
3544         if (!strcmp(res->what, "add"))
3545                 rx_vft_set(res->port_id, res->vlan_id, 1);
3546         else
3547                 rx_vft_set(res->port_id, res->vlan_id, 0);
3548 }
3549
3550 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3551         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3552                                  rx_vlan, "rx_vlan");
3553 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3554         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3555                                  what, "add#rm");
3556 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3557         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3558                               vlan_id, UINT16);
3559 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3560         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3561                               port_id, UINT16);
3562
3563 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3564         .f = cmd_rx_vlan_filter_parsed,
3565         .data = NULL,
3566         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3567                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3568                 "identifiers filtered by a port",
3569         .tokens = {
3570                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3571                 (void *)&cmd_rx_vlan_filter_what,
3572                 (void *)&cmd_rx_vlan_filter_vlanid,
3573                 (void *)&cmd_rx_vlan_filter_portid,
3574                 NULL,
3575         },
3576 };
3577
3578 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3579 struct cmd_tx_vlan_set_result {
3580         cmdline_fixed_string_t tx_vlan;
3581         cmdline_fixed_string_t set;
3582         portid_t port_id;
3583         uint16_t vlan_id;
3584 };
3585
3586 static void
3587 cmd_tx_vlan_set_parsed(void *parsed_result,
3588                        __attribute__((unused)) struct cmdline *cl,
3589                        __attribute__((unused)) void *data)
3590 {
3591         struct cmd_tx_vlan_set_result *res = parsed_result;
3592
3593         if (!port_is_stopped(res->port_id)) {
3594                 printf("Please stop port %d first\n", res->port_id);
3595                 return;
3596         }
3597
3598         tx_vlan_set(res->port_id, res->vlan_id);
3599
3600         cmd_reconfig_device_queue(res->port_id, 1, 1);
3601 }
3602
3603 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3604         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3605                                  tx_vlan, "tx_vlan");
3606 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3607         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3608                                  set, "set");
3609 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3610         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3611                               port_id, UINT16);
3612 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3613         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3614                               vlan_id, UINT16);
3615
3616 cmdline_parse_inst_t cmd_tx_vlan_set = {
3617         .f = cmd_tx_vlan_set_parsed,
3618         .data = NULL,
3619         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3620                 "Enable hardware insertion of a single VLAN header "
3621                 "with a given TAG Identifier in packets sent on a port",
3622         .tokens = {
3623                 (void *)&cmd_tx_vlan_set_tx_vlan,
3624                 (void *)&cmd_tx_vlan_set_set,
3625                 (void *)&cmd_tx_vlan_set_portid,
3626                 (void *)&cmd_tx_vlan_set_vlanid,
3627                 NULL,
3628         },
3629 };
3630
3631 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3632 struct cmd_tx_vlan_set_qinq_result {
3633         cmdline_fixed_string_t tx_vlan;
3634         cmdline_fixed_string_t set;
3635         portid_t port_id;
3636         uint16_t vlan_id;
3637         uint16_t vlan_id_outer;
3638 };
3639
3640 static void
3641 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3642                             __attribute__((unused)) struct cmdline *cl,
3643                             __attribute__((unused)) void *data)
3644 {
3645         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3646
3647         if (!port_is_stopped(res->port_id)) {
3648                 printf("Please stop port %d first\n", res->port_id);
3649                 return;
3650         }
3651
3652         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3653
3654         cmd_reconfig_device_queue(res->port_id, 1, 1);
3655 }
3656
3657 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3658         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3659                 tx_vlan, "tx_vlan");
3660 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3661         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3662                 set, "set");
3663 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3664         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3665                 port_id, UINT16);
3666 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3667         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3668                 vlan_id, UINT16);
3669 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3670         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3671                 vlan_id_outer, UINT16);
3672
3673 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3674         .f = cmd_tx_vlan_set_qinq_parsed,
3675         .data = NULL,
3676         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3677                 "Enable hardware insertion of double VLAN header "
3678                 "with given TAG Identifiers in packets sent on a port",
3679         .tokens = {
3680                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3681                 (void *)&cmd_tx_vlan_set_qinq_set,
3682                 (void *)&cmd_tx_vlan_set_qinq_portid,
3683                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3684                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3685                 NULL,
3686         },
3687 };
3688
3689 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3690 struct cmd_tx_vlan_set_pvid_result {
3691         cmdline_fixed_string_t tx_vlan;
3692         cmdline_fixed_string_t set;
3693         cmdline_fixed_string_t pvid;
3694         portid_t port_id;
3695         uint16_t vlan_id;
3696         cmdline_fixed_string_t mode;
3697 };
3698
3699 static void
3700 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3701                             __attribute__((unused)) struct cmdline *cl,
3702                             __attribute__((unused)) void *data)
3703 {
3704         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3705
3706         if (strcmp(res->mode, "on") == 0)
3707                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3708         else
3709                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3710 }
3711
3712 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3713         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3714                                  tx_vlan, "tx_vlan");
3715 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3716         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3717                                  set, "set");
3718 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3719         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3720                                  pvid, "pvid");
3721 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3722         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3723                              port_id, UINT16);
3724 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3725         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3726                               vlan_id, UINT16);
3727 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3728         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3729                                  mode, "on#off");
3730
3731 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3732         .f = cmd_tx_vlan_set_pvid_parsed,
3733         .data = NULL,
3734         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3735         .tokens = {
3736                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3737                 (void *)&cmd_tx_vlan_set_pvid_set,
3738                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3739                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3740                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3741                 (void *)&cmd_tx_vlan_set_pvid_mode,
3742                 NULL,
3743         },
3744 };
3745
3746 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3747 struct cmd_tx_vlan_reset_result {
3748         cmdline_fixed_string_t tx_vlan;
3749         cmdline_fixed_string_t reset;
3750         portid_t port_id;
3751 };
3752
3753 static void
3754 cmd_tx_vlan_reset_parsed(void *parsed_result,
3755                          __attribute__((unused)) struct cmdline *cl,
3756                          __attribute__((unused)) void *data)
3757 {
3758         struct cmd_tx_vlan_reset_result *res = parsed_result;
3759
3760         if (!port_is_stopped(res->port_id)) {
3761                 printf("Please stop port %d first\n", res->port_id);
3762                 return;
3763         }
3764
3765         tx_vlan_reset(res->port_id);
3766
3767         cmd_reconfig_device_queue(res->port_id, 1, 1);
3768 }
3769
3770 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3771         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3772                                  tx_vlan, "tx_vlan");
3773 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3774         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3775                                  reset, "reset");
3776 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3777         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3778                               port_id, UINT16);
3779
3780 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3781         .f = cmd_tx_vlan_reset_parsed,
3782         .data = NULL,
3783         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3784                 "VLAN header in packets sent on a port",
3785         .tokens = {
3786                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3787                 (void *)&cmd_tx_vlan_reset_reset,
3788                 (void *)&cmd_tx_vlan_reset_portid,
3789                 NULL,
3790         },
3791 };
3792
3793
3794 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3795 struct cmd_csum_result {
3796         cmdline_fixed_string_t csum;
3797         cmdline_fixed_string_t mode;
3798         cmdline_fixed_string_t proto;
3799         cmdline_fixed_string_t hwsw;
3800         portid_t port_id;
3801 };
3802
3803 static void
3804 csum_show(int port_id)
3805 {
3806         struct rte_eth_dev_info dev_info;
3807         uint64_t tx_offloads;
3808
3809         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
3810         printf("Parse tunnel is %s\n",
3811                 (ports[port_id].parse_tunnel) ? "on" : "off");
3812         printf("IP checksum offload is %s\n",
3813                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
3814         printf("UDP checksum offload is %s\n",
3815                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3816         printf("TCP checksum offload is %s\n",
3817                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3818         printf("SCTP checksum offload is %s\n",
3819                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3820         printf("Outer-Ip checksum offload is %s\n",
3821                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
3822
3823         /* display warnings if configuration is not supported by the NIC */
3824         rte_eth_dev_info_get(port_id, &dev_info);
3825         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
3826                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3827                 printf("Warning: hardware IP checksum enabled but not "
3828                         "supported by port %d\n", port_id);
3829         }
3830         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
3831                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3832                 printf("Warning: hardware UDP checksum enabled but not "
3833                         "supported by port %d\n", port_id);
3834         }
3835         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
3836                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3837                 printf("Warning: hardware TCP checksum enabled but not "
3838                         "supported by port %d\n", port_id);
3839         }
3840         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
3841                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3842                 printf("Warning: hardware SCTP checksum enabled but not "
3843                         "supported by port %d\n", port_id);
3844         }
3845         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
3846                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3847                 printf("Warning: hardware outer IP checksum enabled but not "
3848                         "supported by port %d\n", port_id);
3849         }
3850 }
3851
3852 static void
3853 cmd_csum_parsed(void *parsed_result,
3854                        __attribute__((unused)) struct cmdline *cl,
3855                        __attribute__((unused)) void *data)
3856 {
3857         struct cmd_csum_result *res = parsed_result;
3858         int hw = 0;
3859         uint64_t csum_offloads = 0;
3860         struct rte_eth_dev_info dev_info;
3861
3862         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3863                 printf("invalid port %d\n", res->port_id);
3864                 return;
3865         }
3866         if (!port_is_stopped(res->port_id)) {
3867                 printf("Please stop port %d first\n", res->port_id);
3868                 return;
3869         }
3870
3871         rte_eth_dev_info_get(res->port_id, &dev_info);
3872         if (!strcmp(res->mode, "set")) {
3873
3874                 if (!strcmp(res->hwsw, "hw"))
3875                         hw = 1;
3876
3877                 if (!strcmp(res->proto, "ip")) {
3878                         if (hw == 0 || (dev_info.tx_offload_capa &
3879                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
3880                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
3881                         } else {
3882                                 printf("IP checksum offload is not supported "
3883                                        "by port %u\n", res->port_id);
3884                         }
3885                 } else if (!strcmp(res->proto, "udp")) {
3886                         if (hw == 0 || (dev_info.tx_offload_capa &
3887                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
3888                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
3889                         } else {
3890                                 printf("UDP checksum offload is not supported "
3891                                        "by port %u\n", res->port_id);
3892                         }
3893                 } else if (!strcmp(res->proto, "tcp")) {
3894                         if (hw == 0 || (dev_info.tx_offload_capa &
3895                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
3896                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
3897                         } else {
3898                                 printf("TCP checksum offload is not supported "
3899                                        "by port %u\n", res->port_id);
3900                         }
3901                 } else if (!strcmp(res->proto, "sctp")) {
3902                         if (hw == 0 || (dev_info.tx_offload_capa &
3903                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
3904                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
3905                         } else {
3906                                 printf("SCTP checksum offload is not supported "
3907                                        "by port %u\n", res->port_id);
3908                         }
3909                 } else if (!strcmp(res->proto, "outer-ip")) {
3910                         if (hw == 0 || (dev_info.tx_offload_capa &
3911                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
3912                                 csum_offloads |=
3913                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3914                         } else {
3915                                 printf("Outer IP checksum offload is not "
3916                                        "supported by port %u\n", res->port_id);
3917                         }
3918                 }
3919
3920                 if (hw) {
3921                         ports[res->port_id].dev_conf.txmode.offloads |=
3922                                                         csum_offloads;
3923                 } else {
3924                         ports[res->port_id].dev_conf.txmode.offloads &=
3925                                                         (~csum_offloads);
3926                 }
3927         }
3928         csum_show(res->port_id);
3929
3930         cmd_reconfig_device_queue(res->port_id, 1, 1);
3931 }
3932
3933 cmdline_parse_token_string_t cmd_csum_csum =
3934         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3935                                 csum, "csum");
3936 cmdline_parse_token_string_t cmd_csum_mode =
3937         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3938                                 mode, "set");
3939 cmdline_parse_token_string_t cmd_csum_proto =
3940         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3941                                 proto, "ip#tcp#udp#sctp#outer-ip");
3942 cmdline_parse_token_string_t cmd_csum_hwsw =
3943         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3944                                 hwsw, "hw#sw");
3945 cmdline_parse_token_num_t cmd_csum_portid =
3946         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3947                                 port_id, UINT16);
3948
3949 cmdline_parse_inst_t cmd_csum_set = {
3950         .f = cmd_csum_parsed,
3951         .data = NULL,
3952         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3953                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3954                 "using csum forward engine",
3955         .tokens = {
3956                 (void *)&cmd_csum_csum,
3957                 (void *)&cmd_csum_mode,
3958                 (void *)&cmd_csum_proto,
3959                 (void *)&cmd_csum_hwsw,
3960                 (void *)&cmd_csum_portid,
3961                 NULL,
3962         },
3963 };
3964
3965 cmdline_parse_token_string_t cmd_csum_mode_show =
3966         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3967                                 mode, "show");
3968
3969 cmdline_parse_inst_t cmd_csum_show = {
3970         .f = cmd_csum_parsed,
3971         .data = NULL,
3972         .help_str = "csum show <port_id>: Show checksum offload configuration",
3973         .tokens = {
3974                 (void *)&cmd_csum_csum,
3975                 (void *)&cmd_csum_mode_show,
3976                 (void *)&cmd_csum_portid,
3977                 NULL,
3978         },
3979 };
3980
3981 /* Enable/disable tunnel parsing */
3982 struct cmd_csum_tunnel_result {
3983         cmdline_fixed_string_t csum;
3984         cmdline_fixed_string_t parse;
3985         cmdline_fixed_string_t onoff;
3986         portid_t port_id;
3987 };
3988
3989 static void
3990 cmd_csum_tunnel_parsed(void *parsed_result,
3991                        __attribute__((unused)) struct cmdline *cl,
3992                        __attribute__((unused)) void *data)
3993 {
3994         struct cmd_csum_tunnel_result *res = parsed_result;
3995
3996         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3997                 return;
3998
3999         if (!strcmp(res->onoff, "on"))
4000                 ports[res->port_id].parse_tunnel = 1;
4001         else
4002                 ports[res->port_id].parse_tunnel = 0;
4003
4004         csum_show(res->port_id);
4005 }
4006
4007 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4008         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4009                                 csum, "csum");
4010 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4011         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4012                                 parse, "parse_tunnel");
4013 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4014         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4015                                 onoff, "on#off");
4016 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4017         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4018                                 port_id, UINT16);
4019
4020 cmdline_parse_inst_t cmd_csum_tunnel = {
4021         .f = cmd_csum_tunnel_parsed,
4022         .data = NULL,
4023         .help_str = "csum parse_tunnel on|off <port_id>: "
4024                 "Enable/Disable parsing of tunnels for csum engine",
4025         .tokens = {
4026                 (void *)&cmd_csum_tunnel_csum,
4027                 (void *)&cmd_csum_tunnel_parse,
4028                 (void *)&cmd_csum_tunnel_onoff,
4029                 (void *)&cmd_csum_tunnel_portid,
4030                 NULL,
4031         },
4032 };
4033
4034 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4035 struct cmd_tso_set_result {
4036         cmdline_fixed_string_t tso;
4037         cmdline_fixed_string_t mode;
4038         uint16_t tso_segsz;
4039         portid_t port_id;
4040 };
4041
4042 static void
4043 cmd_tso_set_parsed(void *parsed_result,
4044                        __attribute__((unused)) struct cmdline *cl,
4045                        __attribute__((unused)) void *data)
4046 {
4047         struct cmd_tso_set_result *res = parsed_result;
4048         struct rte_eth_dev_info dev_info;
4049
4050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4051                 return;
4052         if (!port_is_stopped(res->port_id)) {
4053                 printf("Please stop port %d first\n", res->port_id);
4054                 return;
4055         }
4056
4057         if (!strcmp(res->mode, "set"))
4058                 ports[res->port_id].tso_segsz = res->tso_segsz;
4059
4060         rte_eth_dev_info_get(res->port_id, &dev_info);
4061         if ((ports[res->port_id].tso_segsz != 0) &&
4062                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4063                 printf("Error: TSO is not supported by port %d\n",
4064                        res->port_id);
4065                 return;
4066         }
4067
4068         if (ports[res->port_id].tso_segsz == 0) {
4069                 ports[res->port_id].dev_conf.txmode.offloads &=
4070                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4071                 printf("TSO for non-tunneled packets is disabled\n");
4072         } else {
4073                 ports[res->port_id].dev_conf.txmode.offloads |=
4074                                                 DEV_TX_OFFLOAD_TCP_TSO;
4075                 printf("TSO segment size for non-tunneled packets is %d\n",
4076                         ports[res->port_id].tso_segsz);
4077         }
4078
4079         /* display warnings if configuration is not supported by the NIC */
4080         rte_eth_dev_info_get(res->port_id, &dev_info);
4081         if ((ports[res->port_id].tso_segsz != 0) &&
4082                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4083                 printf("Warning: TSO enabled but not "
4084                         "supported by port %d\n", res->port_id);
4085         }
4086
4087         cmd_reconfig_device_queue(res->port_id, 1, 1);
4088 }
4089
4090 cmdline_parse_token_string_t cmd_tso_set_tso =
4091         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4092                                 tso, "tso");
4093 cmdline_parse_token_string_t cmd_tso_set_mode =
4094         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4095                                 mode, "set");
4096 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4097         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4098                                 tso_segsz, UINT16);
4099 cmdline_parse_token_num_t cmd_tso_set_portid =
4100         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4101                                 port_id, UINT16);
4102
4103 cmdline_parse_inst_t cmd_tso_set = {
4104         .f = cmd_tso_set_parsed,
4105         .data = NULL,
4106         .help_str = "tso set <tso_segsz> <port_id>: "
4107                 "Set TSO segment size of non-tunneled packets for csum engine "
4108                 "(0 to disable)",
4109         .tokens = {
4110                 (void *)&cmd_tso_set_tso,
4111                 (void *)&cmd_tso_set_mode,
4112                 (void *)&cmd_tso_set_tso_segsz,
4113                 (void *)&cmd_tso_set_portid,
4114                 NULL,
4115         },
4116 };
4117
4118 cmdline_parse_token_string_t cmd_tso_show_mode =
4119         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4120                                 mode, "show");
4121
4122
4123 cmdline_parse_inst_t cmd_tso_show = {
4124         .f = cmd_tso_set_parsed,
4125         .data = NULL,
4126         .help_str = "tso show <port_id>: "
4127                 "Show TSO segment size of non-tunneled packets for csum engine",
4128         .tokens = {
4129                 (void *)&cmd_tso_set_tso,
4130                 (void *)&cmd_tso_show_mode,
4131                 (void *)&cmd_tso_set_portid,
4132                 NULL,
4133         },
4134 };
4135
4136 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4137 struct cmd_tunnel_tso_set_result {
4138         cmdline_fixed_string_t tso;
4139         cmdline_fixed_string_t mode;
4140         uint16_t tso_segsz;
4141         portid_t port_id;
4142 };
4143
4144 static struct rte_eth_dev_info
4145 check_tunnel_tso_nic_support(portid_t port_id)
4146 {
4147         struct rte_eth_dev_info dev_info;
4148
4149         rte_eth_dev_info_get(port_id, &dev_info);
4150         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4151                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4152                        "not enabled for port %d\n", port_id);
4153         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4154                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4155                        "not enabled for port %d\n", port_id);
4156         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4157                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4158                        "not enabled for port %d\n", port_id);
4159         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4160                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4161                        "not enabled for port %d\n", port_id);
4162         return dev_info;
4163 }
4164
4165 static void
4166 cmd_tunnel_tso_set_parsed(void *parsed_result,
4167                           __attribute__((unused)) struct cmdline *cl,
4168                           __attribute__((unused)) void *data)
4169 {
4170         struct cmd_tunnel_tso_set_result *res = parsed_result;
4171         struct rte_eth_dev_info dev_info;
4172
4173         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4174                 return;
4175         if (!port_is_stopped(res->port_id)) {
4176                 printf("Please stop port %d first\n", res->port_id);
4177                 return;
4178         }
4179
4180         if (!strcmp(res->mode, "set"))
4181                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4182
4183         dev_info = check_tunnel_tso_nic_support(res->port_id);
4184         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4185                 ports[res->port_id].dev_conf.txmode.offloads &=
4186                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4187                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4188                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4189                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4190                 printf("TSO for tunneled packets is disabled\n");
4191         } else {
4192                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4193                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4194                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4195                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO);
4196
4197                 ports[res->port_id].dev_conf.txmode.offloads |=
4198                         (tso_offloads & dev_info.tx_offload_capa);
4199                 printf("TSO segment size for tunneled packets is %d\n",
4200                         ports[res->port_id].tunnel_tso_segsz);
4201
4202                 /* Below conditions are needed to make it work:
4203                  * (1) tunnel TSO is supported by the NIC;
4204                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4205                  * are recognized;
4206                  * (3) for tunneled pkts with outer L3 of IPv4,
4207                  * "csum set outer-ip" must be set to hw, because after tso,
4208                  * total_len of outer IP header is changed, and the checksum
4209                  * of outer IP header calculated by sw should be wrong; that
4210                  * is not necessary for IPv6 tunneled pkts because there's no
4211                  * checksum in IP header anymore.
4212                  */
4213
4214                 if (!ports[res->port_id].parse_tunnel)
4215                         printf("Warning: csum parse_tunnel must be set "
4216                                 "so that tunneled packets are recognized\n");
4217                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4218                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4219                         printf("Warning: csum set outer-ip must be set to hw "
4220                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4221         }
4222
4223         cmd_reconfig_device_queue(res->port_id, 1, 1);
4224 }
4225
4226 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4227         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4228                                 tso, "tunnel_tso");
4229 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4230         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4231                                 mode, "set");
4232 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4233         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4234                                 tso_segsz, UINT16);
4235 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4236         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4237                                 port_id, UINT16);
4238
4239 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4240         .f = cmd_tunnel_tso_set_parsed,
4241         .data = NULL,
4242         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4243                 "Set TSO segment size of tunneled packets for csum engine "
4244                 "(0 to disable)",
4245         .tokens = {
4246                 (void *)&cmd_tunnel_tso_set_tso,
4247                 (void *)&cmd_tunnel_tso_set_mode,
4248                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4249                 (void *)&cmd_tunnel_tso_set_portid,
4250                 NULL,
4251         },
4252 };
4253
4254 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4255         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4256                                 mode, "show");
4257
4258
4259 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4260         .f = cmd_tunnel_tso_set_parsed,
4261         .data = NULL,
4262         .help_str = "tunnel_tso show <port_id> "
4263                 "Show TSO segment size of tunneled packets for csum engine",
4264         .tokens = {
4265                 (void *)&cmd_tunnel_tso_set_tso,
4266                 (void *)&cmd_tunnel_tso_show_mode,
4267                 (void *)&cmd_tunnel_tso_set_portid,
4268                 NULL,
4269         },
4270 };
4271
4272 /* *** SET GRO FOR A PORT *** */
4273 struct cmd_gro_enable_result {
4274         cmdline_fixed_string_t cmd_set;
4275         cmdline_fixed_string_t cmd_port;
4276         cmdline_fixed_string_t cmd_keyword;
4277         cmdline_fixed_string_t cmd_onoff;
4278         portid_t cmd_pid;
4279 };
4280
4281 static void
4282 cmd_gro_enable_parsed(void *parsed_result,
4283                 __attribute__((unused)) struct cmdline *cl,
4284                 __attribute__((unused)) void *data)
4285 {
4286         struct cmd_gro_enable_result *res;
4287
4288         res = parsed_result;
4289         if (!strcmp(res->cmd_keyword, "gro"))
4290                 setup_gro(res->cmd_onoff, res->cmd_pid);
4291 }
4292
4293 cmdline_parse_token_string_t cmd_gro_enable_set =
4294         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4295                         cmd_set, "set");
4296 cmdline_parse_token_string_t cmd_gro_enable_port =
4297         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4298                         cmd_keyword, "port");
4299 cmdline_parse_token_num_t cmd_gro_enable_pid =
4300         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4301                         cmd_pid, UINT16);
4302 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4303         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4304                         cmd_keyword, "gro");
4305 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4306         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4307                         cmd_onoff, "on#off");
4308
4309 cmdline_parse_inst_t cmd_gro_enable = {
4310         .f = cmd_gro_enable_parsed,
4311         .data = NULL,
4312         .help_str = "set port <port_id> gro on|off",
4313         .tokens = {
4314                 (void *)&cmd_gro_enable_set,
4315                 (void *)&cmd_gro_enable_port,
4316                 (void *)&cmd_gro_enable_pid,
4317                 (void *)&cmd_gro_enable_keyword,
4318                 (void *)&cmd_gro_enable_onoff,
4319                 NULL,
4320         },
4321 };
4322
4323 /* *** DISPLAY GRO CONFIGURATION *** */
4324 struct cmd_gro_show_result {
4325         cmdline_fixed_string_t cmd_show;
4326         cmdline_fixed_string_t cmd_port;
4327         cmdline_fixed_string_t cmd_keyword;
4328         portid_t cmd_pid;
4329 };
4330
4331 static void
4332 cmd_gro_show_parsed(void *parsed_result,
4333                 __attribute__((unused)) struct cmdline *cl,
4334                 __attribute__((unused)) void *data)
4335 {
4336         struct cmd_gro_show_result *res;
4337
4338         res = parsed_result;
4339         if (!strcmp(res->cmd_keyword, "gro"))
4340                 show_gro(res->cmd_pid);
4341 }
4342
4343 cmdline_parse_token_string_t cmd_gro_show_show =
4344         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4345                         cmd_show, "show");
4346 cmdline_parse_token_string_t cmd_gro_show_port =
4347         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4348                         cmd_port, "port");
4349 cmdline_parse_token_num_t cmd_gro_show_pid =
4350         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4351                         cmd_pid, UINT16);
4352 cmdline_parse_token_string_t cmd_gro_show_keyword =
4353         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4354                         cmd_keyword, "gro");
4355
4356 cmdline_parse_inst_t cmd_gro_show = {
4357         .f = cmd_gro_show_parsed,
4358         .data = NULL,
4359         .help_str = "show port <port_id> gro",
4360         .tokens = {
4361                 (void *)&cmd_gro_show_show,
4362                 (void *)&cmd_gro_show_port,
4363                 (void *)&cmd_gro_show_pid,
4364                 (void *)&cmd_gro_show_keyword,
4365                 NULL,
4366         },
4367 };
4368
4369 /* *** SET FLUSH CYCLES FOR GRO *** */
4370 struct cmd_gro_flush_result {
4371         cmdline_fixed_string_t cmd_set;
4372         cmdline_fixed_string_t cmd_keyword;
4373         cmdline_fixed_string_t cmd_flush;
4374         uint8_t cmd_cycles;
4375 };
4376
4377 static void
4378 cmd_gro_flush_parsed(void *parsed_result,
4379                 __attribute__((unused)) struct cmdline *cl,
4380                 __attribute__((unused)) void *data)
4381 {
4382         struct cmd_gro_flush_result *res;
4383
4384         res = parsed_result;
4385         if ((!strcmp(res->cmd_keyword, "gro")) &&
4386                         (!strcmp(res->cmd_flush, "flush")))
4387                 setup_gro_flush_cycles(res->cmd_cycles);
4388 }
4389
4390 cmdline_parse_token_string_t cmd_gro_flush_set =
4391         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4392                         cmd_set, "set");
4393 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4394         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4395                         cmd_keyword, "gro");
4396 cmdline_parse_token_string_t cmd_gro_flush_flush =
4397         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4398                         cmd_flush, "flush");
4399 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4400         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4401                         cmd_cycles, UINT8);
4402
4403 cmdline_parse_inst_t cmd_gro_flush = {
4404         .f = cmd_gro_flush_parsed,
4405         .data = NULL,
4406         .help_str = "set gro flush <cycles>",
4407         .tokens = {
4408                 (void *)&cmd_gro_flush_set,
4409                 (void *)&cmd_gro_flush_keyword,
4410                 (void *)&cmd_gro_flush_flush,
4411                 (void *)&cmd_gro_flush_cycles,
4412                 NULL,
4413         },
4414 };
4415
4416 /* *** ENABLE/DISABLE GSO *** */
4417 struct cmd_gso_enable_result {
4418         cmdline_fixed_string_t cmd_set;
4419         cmdline_fixed_string_t cmd_port;
4420         cmdline_fixed_string_t cmd_keyword;
4421         cmdline_fixed_string_t cmd_mode;
4422         portid_t cmd_pid;
4423 };
4424
4425 static void
4426 cmd_gso_enable_parsed(void *parsed_result,
4427                 __attribute__((unused)) struct cmdline *cl,
4428                 __attribute__((unused)) void *data)
4429 {
4430         struct cmd_gso_enable_result *res;
4431
4432         res = parsed_result;
4433         if (!strcmp(res->cmd_keyword, "gso"))
4434                 setup_gso(res->cmd_mode, res->cmd_pid);
4435 }
4436
4437 cmdline_parse_token_string_t cmd_gso_enable_set =
4438         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4439                         cmd_set, "set");
4440 cmdline_parse_token_string_t cmd_gso_enable_port =
4441         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4442                         cmd_port, "port");
4443 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4444         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4445                         cmd_keyword, "gso");
4446 cmdline_parse_token_string_t cmd_gso_enable_mode =
4447         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4448                         cmd_mode, "on#off");
4449 cmdline_parse_token_num_t cmd_gso_enable_pid =
4450         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4451                         cmd_pid, UINT16);
4452
4453 cmdline_parse_inst_t cmd_gso_enable = {
4454         .f = cmd_gso_enable_parsed,
4455         .data = NULL,
4456         .help_str = "set port <port_id> gso on|off",
4457         .tokens = {
4458                 (void *)&cmd_gso_enable_set,
4459                 (void *)&cmd_gso_enable_port,
4460                 (void *)&cmd_gso_enable_pid,
4461                 (void *)&cmd_gso_enable_keyword,
4462                 (void *)&cmd_gso_enable_mode,
4463                 NULL,
4464         },
4465 };
4466
4467 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4468 struct cmd_gso_size_result {
4469         cmdline_fixed_string_t cmd_set;
4470         cmdline_fixed_string_t cmd_keyword;
4471         cmdline_fixed_string_t cmd_segsz;
4472         uint16_t cmd_size;
4473 };
4474
4475 static void
4476 cmd_gso_size_parsed(void *parsed_result,
4477                        __attribute__((unused)) struct cmdline *cl,
4478                        __attribute__((unused)) void *data)
4479 {
4480         struct cmd_gso_size_result *res = parsed_result;
4481
4482         if (test_done == 0) {
4483                 printf("Before setting GSO segsz, please first"
4484                                 " stop fowarding\n");
4485                 return;
4486         }
4487
4488         if (!strcmp(res->cmd_keyword, "gso") &&
4489                         !strcmp(res->cmd_segsz, "segsz")) {
4490                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4491                         printf("gso_size should be larger than %zu."
4492                                         " Please input a legal value\n",
4493                                         RTE_GSO_SEG_SIZE_MIN);
4494                 else
4495                         gso_max_segment_size = res->cmd_size;
4496         }
4497 }
4498
4499 cmdline_parse_token_string_t cmd_gso_size_set =
4500         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4501                                 cmd_set, "set");
4502 cmdline_parse_token_string_t cmd_gso_size_keyword =
4503         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4504                                 cmd_keyword, "gso");
4505 cmdline_parse_token_string_t cmd_gso_size_segsz =
4506         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4507                                 cmd_segsz, "segsz");
4508 cmdline_parse_token_num_t cmd_gso_size_size =
4509         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4510                                 cmd_size, UINT16);
4511
4512 cmdline_parse_inst_t cmd_gso_size = {
4513         .f = cmd_gso_size_parsed,
4514         .data = NULL,
4515         .help_str = "set gso segsz <length>",
4516         .tokens = {
4517                 (void *)&cmd_gso_size_set,
4518                 (void *)&cmd_gso_size_keyword,
4519                 (void *)&cmd_gso_size_segsz,
4520                 (void *)&cmd_gso_size_size,
4521                 NULL,
4522         },
4523 };
4524
4525 /* *** SHOW GSO CONFIGURATION *** */
4526 struct cmd_gso_show_result {
4527         cmdline_fixed_string_t cmd_show;
4528         cmdline_fixed_string_t cmd_port;
4529         cmdline_fixed_string_t cmd_keyword;
4530         portid_t cmd_pid;
4531 };
4532
4533 static void
4534 cmd_gso_show_parsed(void *parsed_result,
4535                        __attribute__((unused)) struct cmdline *cl,
4536                        __attribute__((unused)) void *data)
4537 {
4538         struct cmd_gso_show_result *res = parsed_result;
4539
4540         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4541                 printf("invalid port id %u\n", res->cmd_pid);
4542                 return;
4543         }
4544         if (!strcmp(res->cmd_keyword, "gso")) {
4545                 if (gso_ports[res->cmd_pid].enable) {
4546                         printf("Max GSO'd packet size: %uB\n"
4547                                         "Supported GSO types: TCP/IPv4, "
4548                                         "VxLAN with inner TCP/IPv4 packet, "
4549                                         "GRE with inner TCP/IPv4  packet\n",
4550                                         gso_max_segment_size);
4551                 } else
4552                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4553         }
4554 }
4555
4556 cmdline_parse_token_string_t cmd_gso_show_show =
4557 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4558                 cmd_show, "show");
4559 cmdline_parse_token_string_t cmd_gso_show_port =
4560 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4561                 cmd_port, "port");
4562 cmdline_parse_token_string_t cmd_gso_show_keyword =
4563         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4564                                 cmd_keyword, "gso");
4565 cmdline_parse_token_num_t cmd_gso_show_pid =
4566         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4567                                 cmd_pid, UINT16);
4568
4569 cmdline_parse_inst_t cmd_gso_show = {
4570         .f = cmd_gso_show_parsed,
4571         .data = NULL,
4572         .help_str = "show port <port_id> gso",
4573         .tokens = {
4574                 (void *)&cmd_gso_show_show,
4575                 (void *)&cmd_gso_show_port,
4576                 (void *)&cmd_gso_show_pid,
4577                 (void *)&cmd_gso_show_keyword,
4578                 NULL,
4579         },
4580 };
4581
4582 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4583 struct cmd_set_flush_rx {
4584         cmdline_fixed_string_t set;
4585         cmdline_fixed_string_t flush_rx;
4586         cmdline_fixed_string_t mode;
4587 };
4588
4589 static void
4590 cmd_set_flush_rx_parsed(void *parsed_result,
4591                 __attribute__((unused)) struct cmdline *cl,
4592                 __attribute__((unused)) void *data)
4593 {
4594         struct cmd_set_flush_rx *res = parsed_result;
4595         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4596 }
4597
4598 cmdline_parse_token_string_t cmd_setflushrx_set =
4599         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4600                         set, "set");
4601 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4602         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4603                         flush_rx, "flush_rx");
4604 cmdline_parse_token_string_t cmd_setflushrx_mode =
4605         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4606                         mode, "on#off");
4607
4608
4609 cmdline_parse_inst_t cmd_set_flush_rx = {
4610         .f = cmd_set_flush_rx_parsed,
4611         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4612         .data = NULL,
4613         .tokens = {
4614                 (void *)&cmd_setflushrx_set,
4615                 (void *)&cmd_setflushrx_flush_rx,
4616                 (void *)&cmd_setflushrx_mode,
4617                 NULL,
4618         },
4619 };
4620
4621 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4622 struct cmd_set_link_check {
4623         cmdline_fixed_string_t set;
4624         cmdline_fixed_string_t link_check;
4625         cmdline_fixed_string_t mode;
4626 };
4627
4628 static void
4629 cmd_set_link_check_parsed(void *parsed_result,
4630                 __attribute__((unused)) struct cmdline *cl,
4631                 __attribute__((unused)) void *data)
4632 {
4633         struct cmd_set_link_check *res = parsed_result;
4634         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4635 }
4636
4637 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4638         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4639                         set, "set");
4640 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4641         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4642                         link_check, "link_check");
4643 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4644         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4645                         mode, "on#off");
4646
4647
4648 cmdline_parse_inst_t cmd_set_link_check = {
4649         .f = cmd_set_link_check_parsed,
4650         .help_str = "set link_check on|off: Enable/Disable link status check "
4651                     "when starting/stopping a port",
4652         .data = NULL,
4653         .tokens = {
4654                 (void *)&cmd_setlinkcheck_set,
4655                 (void *)&cmd_setlinkcheck_link_check,
4656                 (void *)&cmd_setlinkcheck_mode,
4657                 NULL,
4658         },
4659 };
4660
4661 /* *** SET NIC BYPASS MODE *** */
4662 struct cmd_set_bypass_mode_result {
4663         cmdline_fixed_string_t set;
4664         cmdline_fixed_string_t bypass;
4665         cmdline_fixed_string_t mode;
4666         cmdline_fixed_string_t value;
4667         portid_t port_id;
4668 };
4669
4670 static void
4671 cmd_set_bypass_mode_parsed(void *parsed_result,
4672                 __attribute__((unused)) struct cmdline *cl,
4673                 __attribute__((unused)) void *data)
4674 {
4675         struct cmd_set_bypass_mode_result *res = parsed_result;
4676         portid_t port_id = res->port_id;
4677         int32_t rc = -EINVAL;
4678
4679 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4680         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4681
4682         if (!strcmp(res->value, "bypass"))
4683                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4684         else if (!strcmp(res->value, "isolate"))
4685                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4686         else
4687                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4688
4689         /* Set the bypass mode for the relevant port. */
4690         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4691 #endif
4692         if (rc != 0)
4693                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4694 }
4695
4696 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4697         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4698                         set, "set");
4699 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4700         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4701                         bypass, "bypass");
4702 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4703         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4704                         mode, "mode");
4705 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4706         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4707                         value, "normal#bypass#isolate");
4708 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4709         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4710                                 port_id, UINT16);
4711
4712 cmdline_parse_inst_t cmd_set_bypass_mode = {
4713         .f = cmd_set_bypass_mode_parsed,
4714         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4715                     "Set the NIC bypass mode for port_id",
4716         .data = NULL,
4717         .tokens = {
4718                 (void *)&cmd_setbypass_mode_set,
4719                 (void *)&cmd_setbypass_mode_bypass,
4720                 (void *)&cmd_setbypass_mode_mode,
4721                 (void *)&cmd_setbypass_mode_value,
4722                 (void *)&cmd_setbypass_mode_port,
4723                 NULL,
4724         },
4725 };
4726
4727 /* *** SET NIC BYPASS EVENT *** */
4728 struct cmd_set_bypass_event_result {
4729         cmdline_fixed_string_t set;
4730         cmdline_fixed_string_t bypass;
4731         cmdline_fixed_string_t event;
4732         cmdline_fixed_string_t event_value;
4733         cmdline_fixed_string_t mode;
4734         cmdline_fixed_string_t mode_value;
4735         portid_t port_id;
4736 };
4737
4738 static void
4739 cmd_set_bypass_event_parsed(void *parsed_result,
4740                 __attribute__((unused)) struct cmdline *cl,
4741                 __attribute__((unused)) void *data)
4742 {
4743         int32_t rc = -EINVAL;
4744         struct cmd_set_bypass_event_result *res = parsed_result;
4745         portid_t port_id = res->port_id;
4746
4747 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4748         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4749         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4750
4751         if (!strcmp(res->event_value, "timeout"))
4752                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4753         else if (!strcmp(res->event_value, "os_on"))
4754                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4755         else if (!strcmp(res->event_value, "os_off"))
4756                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4757         else if (!strcmp(res->event_value, "power_on"))
4758                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4759         else if (!strcmp(res->event_value, "power_off"))
4760                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4761         else
4762                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4763
4764         if (!strcmp(res->mode_value, "bypass"))
4765                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4766         else if (!strcmp(res->mode_value, "isolate"))
4767                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4768         else
4769                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4770
4771         /* Set the watchdog timeout. */
4772         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4773
4774                 rc = -EINVAL;
4775                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4776                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4777                                                            bypass_timeout);
4778                 }
4779                 if (rc != 0) {
4780                         printf("Failed to set timeout value %u "
4781                         "for port %d, errto code: %d.\n",
4782                         bypass_timeout, port_id, rc);
4783                 }
4784         }
4785
4786         /* Set the bypass event to transition to bypass mode. */
4787         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4788                                               bypass_mode);
4789 #endif
4790
4791         if (rc != 0)
4792                 printf("\t Failed to set bypass event for port = %d.\n",
4793                        port_id);
4794 }
4795
4796 cmdline_parse_token_string_t cmd_setbypass_event_set =
4797         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4798                         set, "set");
4799 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4800         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4801                         bypass, "bypass");
4802 cmdline_parse_token_string_t cmd_setbypass_event_event =
4803         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4804                         event, "event");
4805 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4806         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4807                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4808 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4809         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4810                         mode, "mode");
4811 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4812         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4813                         mode_value, "normal#bypass#isolate");
4814 cmdline_parse_token_num_t cmd_setbypass_event_port =
4815         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4816                                 port_id, UINT16);
4817
4818 cmdline_parse_inst_t cmd_set_bypass_event = {
4819         .f = cmd_set_bypass_event_parsed,
4820         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4821                 "power_off mode normal|bypass|isolate <port_id>: "
4822                 "Set the NIC bypass event mode for port_id",
4823         .data = NULL,
4824         .tokens = {
4825                 (void *)&cmd_setbypass_event_set,
4826                 (void *)&cmd_setbypass_event_bypass,
4827                 (void *)&cmd_setbypass_event_event,
4828                 (void *)&cmd_setbypass_event_event_value,
4829                 (void *)&cmd_setbypass_event_mode,
4830                 (void *)&cmd_setbypass_event_mode_value,
4831                 (void *)&cmd_setbypass_event_port,
4832                 NULL,
4833         },
4834 };
4835
4836
4837 /* *** SET NIC BYPASS TIMEOUT *** */
4838 struct cmd_set_bypass_timeout_result {
4839         cmdline_fixed_string_t set;
4840         cmdline_fixed_string_t bypass;
4841         cmdline_fixed_string_t timeout;
4842         cmdline_fixed_string_t value;
4843 };
4844
4845 static void
4846 cmd_set_bypass_timeout_parsed(void *parsed_result,
4847                 __attribute__((unused)) struct cmdline *cl,
4848                 __attribute__((unused)) void *data)
4849 {
4850         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4851
4852 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4853         if (!strcmp(res->value, "1.5"))
4854                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4855         else if (!strcmp(res->value, "2"))
4856                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4857         else if (!strcmp(res->value, "3"))
4858                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4859         else if (!strcmp(res->value, "4"))
4860                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4861         else if (!strcmp(res->value, "8"))
4862                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4863         else if (!strcmp(res->value, "16"))
4864                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4865         else if (!strcmp(res->value, "32"))
4866                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4867         else
4868                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4869 #endif
4870 }
4871
4872 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4873         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4874                         set, "set");
4875 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4876         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4877                         bypass, "bypass");
4878 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4879         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4880                         timeout, "timeout");
4881 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4882         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4883                         value, "0#1.5#2#3#4#8#16#32");
4884
4885 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4886         .f = cmd_set_bypass_timeout_parsed,
4887         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4888                 "Set the NIC bypass watchdog timeout in seconds",
4889         .data = NULL,
4890         .tokens = {
4891                 (void *)&cmd_setbypass_timeout_set,
4892                 (void *)&cmd_setbypass_timeout_bypass,
4893                 (void *)&cmd_setbypass_timeout_timeout,
4894                 (void *)&cmd_setbypass_timeout_value,
4895                 NULL,
4896         },
4897 };
4898
4899 /* *** SHOW NIC BYPASS MODE *** */
4900 struct cmd_show_bypass_config_result {
4901         cmdline_fixed_string_t show;
4902         cmdline_fixed_string_t bypass;
4903         cmdline_fixed_string_t config;
4904         portid_t port_id;
4905 };
4906
4907 static void
4908 cmd_show_bypass_config_parsed(void *parsed_result,
4909                 __attribute__((unused)) struct cmdline *cl,
4910                 __attribute__((unused)) void *data)
4911 {
4912         struct cmd_show_bypass_config_result *res = parsed_result;
4913         portid_t port_id = res->port_id;
4914         int rc = -EINVAL;
4915 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4916         uint32_t event_mode;
4917         uint32_t bypass_mode;
4918         uint32_t timeout = bypass_timeout;
4919         int i;
4920
4921         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4922                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4923         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4924                 {"UNKNOWN", "normal", "bypass", "isolate"};
4925         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4926                 "NONE",
4927                 "OS/board on",
4928                 "power supply on",
4929                 "OS/board off",
4930                 "power supply off",
4931                 "timeout"};
4932         int num_events = (sizeof events) / (sizeof events[0]);
4933
4934         /* Display the bypass mode.*/
4935         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4936                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4937                 return;
4938         }
4939         else {
4940                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4941                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4942
4943                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4944         }
4945
4946         /* Display the bypass timeout.*/
4947         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4948                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4949
4950         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4951
4952         /* Display the bypass events and associated modes. */
4953         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4954
4955                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4956                         printf("\tFailed to get bypass mode for event = %s\n",
4957                                 events[i]);
4958                 } else {
4959                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4960                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4961
4962                         printf("\tbypass event: %-16s = %s\n", events[i],
4963                                 modes[event_mode]);
4964                 }
4965         }
4966 #endif
4967         if (rc != 0)
4968                 printf("\tFailed to get bypass configuration for port = %d\n",
4969                        port_id);
4970 }
4971
4972 cmdline_parse_token_string_t cmd_showbypass_config_show =
4973         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4974                         show, "show");
4975 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4976         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4977                         bypass, "bypass");
4978 cmdline_parse_token_string_t cmd_showbypass_config_config =
4979         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4980                         config, "config");
4981 cmdline_parse_token_num_t cmd_showbypass_config_port =
4982         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4983                                 port_id, UINT16);
4984
4985 cmdline_parse_inst_t cmd_show_bypass_config = {
4986         .f = cmd_show_bypass_config_parsed,
4987         .help_str = "show bypass config <port_id>: "
4988                     "Show the NIC bypass config for port_id",
4989         .data = NULL,
4990         .tokens = {
4991                 (void *)&cmd_showbypass_config_show,
4992                 (void *)&cmd_showbypass_config_bypass,
4993                 (void *)&cmd_showbypass_config_config,
4994                 (void *)&cmd_showbypass_config_port,
4995                 NULL,
4996         },
4997 };
4998
4999 #ifdef RTE_LIBRTE_PMD_BOND
5000 /* *** SET BONDING MODE *** */
5001 struct cmd_set_bonding_mode_result {
5002         cmdline_fixed_string_t set;
5003         cmdline_fixed_string_t bonding;
5004         cmdline_fixed_string_t mode;
5005         uint8_t value;
5006         portid_t port_id;
5007 };
5008
5009 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5010                 __attribute__((unused))  struct cmdline *cl,
5011                 __attribute__((unused)) void *data)
5012 {
5013         struct cmd_set_bonding_mode_result *res = parsed_result;
5014         portid_t port_id = res->port_id;
5015
5016         /* Set the bonding mode for the relevant port. */
5017         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5018                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5019 }
5020
5021 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5022 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5023                 set, "set");
5024 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5025 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5026                 bonding, "bonding");
5027 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5028 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5029                 mode, "mode");
5030 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5031 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5032                 value, UINT8);
5033 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5034 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5035                 port_id, UINT16);
5036
5037 cmdline_parse_inst_t cmd_set_bonding_mode = {
5038                 .f = cmd_set_bonding_mode_parsed,
5039                 .help_str = "set bonding mode <mode_value> <port_id>: "
5040                         "Set the bonding mode for port_id",
5041                 .data = NULL,
5042                 .tokens = {
5043                                 (void *) &cmd_setbonding_mode_set,
5044                                 (void *) &cmd_setbonding_mode_bonding,
5045                                 (void *) &cmd_setbonding_mode_mode,
5046                                 (void *) &cmd_setbonding_mode_value,
5047                                 (void *) &cmd_setbonding_mode_port,
5048                                 NULL
5049                 }
5050 };
5051
5052 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5053 struct cmd_set_bonding_lacp_dedicated_queues_result {
5054         cmdline_fixed_string_t set;
5055         cmdline_fixed_string_t bonding;
5056         cmdline_fixed_string_t lacp;
5057         cmdline_fixed_string_t dedicated_queues;
5058         portid_t port_id;
5059         cmdline_fixed_string_t mode;
5060 };
5061
5062 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5063                 __attribute__((unused))  struct cmdline *cl,
5064                 __attribute__((unused)) void *data)
5065 {
5066         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5067         portid_t port_id = res->port_id;
5068         struct rte_port *port;
5069
5070         port = &ports[port_id];
5071
5072         /** Check if the port is not started **/
5073         if (port->port_status != RTE_PORT_STOPPED) {
5074                 printf("Please stop port %d first\n", port_id);
5075                 return;
5076         }
5077
5078         if (!strcmp(res->mode, "enable")) {
5079                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5080                         printf("Dedicate queues for LACP control packets"
5081                                         " enabled\n");
5082                 else
5083                         printf("Enabling dedicate queues for LACP control "
5084                                         "packets on port %d failed\n", port_id);
5085         } else if (!strcmp(res->mode, "disable")) {
5086                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5087                         printf("Dedicated queues for LACP control packets "
5088                                         "disabled\n");
5089                 else
5090                         printf("Disabling dedicated queues for LACP control "
5091                                         "traffic on port %d failed\n", port_id);
5092         }
5093 }
5094
5095 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5096 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5097                 set, "set");
5098 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5099 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5100                 bonding, "bonding");
5101 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5102 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5103                 lacp, "lacp");
5104 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5105 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5106                 dedicated_queues, "dedicated_queues");
5107 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5108 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5109                 port_id, UINT16);
5110 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5111 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5112                 mode, "enable#disable");
5113
5114 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5115                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5116                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5117                         "enable|disable: "
5118                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5119                 .data = NULL,
5120                 .tokens = {
5121                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5122                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5123                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5124                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5125                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5126                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5127                         NULL
5128                 }
5129 };
5130
5131 /* *** SET BALANCE XMIT POLICY *** */
5132 struct cmd_set_bonding_balance_xmit_policy_result {
5133         cmdline_fixed_string_t set;
5134         cmdline_fixed_string_t bonding;
5135         cmdline_fixed_string_t balance_xmit_policy;
5136         portid_t port_id;
5137         cmdline_fixed_string_t policy;
5138 };
5139
5140 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5141                 __attribute__((unused))  struct cmdline *cl,
5142                 __attribute__((unused)) void *data)
5143 {
5144         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5145         portid_t port_id = res->port_id;
5146         uint8_t policy;
5147
5148         if (!strcmp(res->policy, "l2")) {
5149                 policy = BALANCE_XMIT_POLICY_LAYER2;
5150         } else if (!strcmp(res->policy, "l23")) {
5151                 policy = BALANCE_XMIT_POLICY_LAYER23;
5152         } else if (!strcmp(res->policy, "l34")) {
5153                 policy = BALANCE_XMIT_POLICY_LAYER34;
5154         } else {
5155                 printf("\t Invalid xmit policy selection");
5156                 return;
5157         }
5158
5159         /* Set the bonding mode for the relevant port. */
5160         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5161                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5162                                 port_id);
5163         }
5164 }
5165
5166 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5167 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5168                 set, "set");
5169 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5170 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5171                 bonding, "bonding");
5172 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5173 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5174                 balance_xmit_policy, "balance_xmit_policy");
5175 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5176 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5177                 port_id, UINT16);
5178 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5179 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5180                 policy, "l2#l23#l34");
5181
5182 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5183                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5184                 .help_str = "set bonding balance_xmit_policy <port_id> "
5185                         "l2|l23|l34: "
5186                         "Set the bonding balance_xmit_policy for port_id",
5187                 .data = NULL,
5188                 .tokens = {
5189                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5190                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5191                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5192                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5193                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5194                                 NULL
5195                 }
5196 };
5197
5198 /* *** SHOW NIC BONDING CONFIGURATION *** */
5199 struct cmd_show_bonding_config_result {
5200         cmdline_fixed_string_t show;
5201         cmdline_fixed_string_t bonding;
5202         cmdline_fixed_string_t config;
5203         portid_t port_id;
5204 };
5205
5206 static void cmd_show_bonding_config_parsed(void *parsed_result,
5207                 __attribute__((unused))  struct cmdline *cl,
5208                 __attribute__((unused)) void *data)
5209 {
5210         struct cmd_show_bonding_config_result *res = parsed_result;
5211         int bonding_mode, agg_mode;
5212         portid_t slaves[RTE_MAX_ETHPORTS];
5213         int num_slaves, num_active_slaves;
5214         int primary_id;
5215         int i;
5216         portid_t port_id = res->port_id;
5217
5218         /* Display the bonding mode.*/
5219         bonding_mode = rte_eth_bond_mode_get(port_id);
5220         if (bonding_mode < 0) {
5221                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5222                 return;
5223         } else
5224                 printf("\tBonding mode: %d\n", bonding_mode);
5225
5226         if (bonding_mode == BONDING_MODE_BALANCE) {
5227                 int balance_xmit_policy;
5228
5229                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5230                 if (balance_xmit_policy < 0) {
5231                         printf("\tFailed to get balance xmit policy for port = %d\n",
5232                                         port_id);
5233                         return;
5234                 } else {
5235                         printf("\tBalance Xmit Policy: ");
5236
5237                         switch (balance_xmit_policy) {
5238                         case BALANCE_XMIT_POLICY_LAYER2:
5239                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5240                                 break;
5241                         case BALANCE_XMIT_POLICY_LAYER23:
5242                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5243                                 break;
5244                         case BALANCE_XMIT_POLICY_LAYER34:
5245                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5246                                 break;
5247                         }
5248                         printf("\n");
5249                 }
5250         }
5251
5252         if (bonding_mode == BONDING_MODE_8023AD) {
5253                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5254                 printf("\tIEEE802.3AD Aggregator Mode: ");
5255                 switch (agg_mode) {
5256                 case AGG_BANDWIDTH:
5257                         printf("bandwidth");
5258                         break;
5259                 case AGG_STABLE:
5260                         printf("stable");
5261                         break;
5262                 case AGG_COUNT:
5263                         printf("count");
5264                         break;
5265                 }
5266                 printf("\n");
5267         }
5268
5269         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5270
5271         if (num_slaves < 0) {
5272                 printf("\tFailed to get slave list for port = %d\n", port_id);
5273                 return;
5274         }
5275         if (num_slaves > 0) {
5276                 printf("\tSlaves (%d): [", num_slaves);
5277                 for (i = 0; i < num_slaves - 1; i++)
5278                         printf("%d ", slaves[i]);
5279
5280                 printf("%d]\n", slaves[num_slaves - 1]);
5281         } else {
5282                 printf("\tSlaves: []\n");
5283
5284         }
5285
5286         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5287                         RTE_MAX_ETHPORTS);
5288
5289         if (num_active_slaves < 0) {
5290                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5291                 return;
5292         }
5293         if (num_active_slaves > 0) {
5294                 printf("\tActive Slaves (%d): [", num_active_slaves);
5295                 for (i = 0; i < num_active_slaves - 1; i++)
5296                         printf("%d ", slaves[i]);
5297
5298                 printf("%d]\n", slaves[num_active_slaves - 1]);
5299
5300         } else {
5301                 printf("\tActive Slaves: []\n");
5302
5303         }
5304
5305         primary_id = rte_eth_bond_primary_get(port_id);
5306         if (primary_id < 0) {
5307                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5308                 return;
5309         } else
5310                 printf("\tPrimary: [%d]\n", primary_id);
5311
5312 }
5313
5314 cmdline_parse_token_string_t cmd_showbonding_config_show =
5315 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5316                 show, "show");
5317 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5318 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5319                 bonding, "bonding");
5320 cmdline_parse_token_string_t cmd_showbonding_config_config =
5321 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5322                 config, "config");
5323 cmdline_parse_token_num_t cmd_showbonding_config_port =
5324 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5325                 port_id, UINT16);
5326
5327 cmdline_parse_inst_t cmd_show_bonding_config = {
5328                 .f = cmd_show_bonding_config_parsed,
5329                 .help_str = "show bonding config <port_id>: "
5330                         "Show the bonding config for port_id",
5331                 .data = NULL,
5332                 .tokens = {
5333                                 (void *)&cmd_showbonding_config_show,
5334                                 (void *)&cmd_showbonding_config_bonding,
5335                                 (void *)&cmd_showbonding_config_config,
5336                                 (void *)&cmd_showbonding_config_port,
5337                                 NULL
5338                 }
5339 };
5340
5341 /* *** SET BONDING PRIMARY *** */
5342 struct cmd_set_bonding_primary_result {
5343         cmdline_fixed_string_t set;
5344         cmdline_fixed_string_t bonding;
5345         cmdline_fixed_string_t primary;
5346         portid_t slave_id;
5347         portid_t port_id;
5348 };
5349
5350 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5351                 __attribute__((unused))  struct cmdline *cl,
5352                 __attribute__((unused)) void *data)
5353 {
5354         struct cmd_set_bonding_primary_result *res = parsed_result;
5355         portid_t master_port_id = res->port_id;
5356         portid_t slave_port_id = res->slave_id;
5357
5358         /* Set the primary slave for a bonded device. */
5359         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5360                 printf("\t Failed to set primary slave for port = %d.\n",
5361                                 master_port_id);
5362                 return;
5363         }
5364         init_port_config();
5365 }
5366
5367 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5368 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5369                 set, "set");
5370 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5371 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5372                 bonding, "bonding");
5373 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5374 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5375                 primary, "primary");
5376 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5377 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5378                 slave_id, UINT16);
5379 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5380 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5381                 port_id, UINT16);
5382
5383 cmdline_parse_inst_t cmd_set_bonding_primary = {
5384                 .f = cmd_set_bonding_primary_parsed,
5385                 .help_str = "set bonding primary <slave_id> <port_id>: "
5386                         "Set the primary slave for port_id",
5387                 .data = NULL,
5388                 .tokens = {
5389                                 (void *)&cmd_setbonding_primary_set,
5390                                 (void *)&cmd_setbonding_primary_bonding,
5391                                 (void *)&cmd_setbonding_primary_primary,
5392                                 (void *)&cmd_setbonding_primary_slave,
5393                                 (void *)&cmd_setbonding_primary_port,
5394                                 NULL
5395                 }
5396 };
5397
5398 /* *** ADD SLAVE *** */
5399 struct cmd_add_bonding_slave_result {
5400         cmdline_fixed_string_t add;
5401         cmdline_fixed_string_t bonding;
5402         cmdline_fixed_string_t slave;
5403         portid_t slave_id;
5404         portid_t port_id;
5405 };
5406
5407 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5408                 __attribute__((unused))  struct cmdline *cl,
5409                 __attribute__((unused)) void *data)
5410 {
5411         struct cmd_add_bonding_slave_result *res = parsed_result;
5412         portid_t master_port_id = res->port_id;
5413         portid_t slave_port_id = res->slave_id;
5414
5415         /* add the slave for a bonded device. */
5416         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5417                 printf("\t Failed to add slave %d to master port = %d.\n",
5418                                 slave_port_id, master_port_id);
5419                 return;
5420         }
5421         init_port_config();
5422         set_port_slave_flag(slave_port_id);
5423 }
5424
5425 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5426 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5427                 add, "add");
5428 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5429 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5430                 bonding, "bonding");
5431 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5432 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5433                 slave, "slave");
5434 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5435 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5436                 slave_id, UINT16);
5437 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5438 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5439                 port_id, UINT16);
5440
5441 cmdline_parse_inst_t cmd_add_bonding_slave = {
5442                 .f = cmd_add_bonding_slave_parsed,
5443                 .help_str = "add bonding slave <slave_id> <port_id>: "
5444                         "Add a slave device to a bonded device",
5445                 .data = NULL,
5446                 .tokens = {
5447                                 (void *)&cmd_addbonding_slave_add,
5448                                 (void *)&cmd_addbonding_slave_bonding,
5449                                 (void *)&cmd_addbonding_slave_slave,
5450                                 (void *)&cmd_addbonding_slave_slaveid,
5451                                 (void *)&cmd_addbonding_slave_port,
5452                                 NULL
5453                 }
5454 };
5455
5456 /* *** REMOVE SLAVE *** */
5457 struct cmd_remove_bonding_slave_result {
5458         cmdline_fixed_string_t remove;
5459         cmdline_fixed_string_t bonding;
5460         cmdline_fixed_string_t slave;
5461         portid_t slave_id;
5462         portid_t port_id;
5463 };
5464
5465 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5466                 __attribute__((unused))  struct cmdline *cl,
5467                 __attribute__((unused)) void *data)
5468 {
5469         struct cmd_remove_bonding_slave_result *res = parsed_result;
5470         portid_t master_port_id = res->port_id;
5471         portid_t slave_port_id = res->slave_id;
5472
5473         /* remove the slave from a bonded device. */
5474         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5475                 printf("\t Failed to remove slave %d from master port = %d.\n",
5476                                 slave_port_id, master_port_id);
5477                 return;
5478         }
5479         init_port_config();
5480         clear_port_slave_flag(slave_port_id);
5481 }
5482
5483 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5484                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5485                                 remove, "remove");
5486 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5487                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5488                                 bonding, "bonding");
5489 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5490                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5491                                 slave, "slave");
5492 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5493                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5494                                 slave_id, UINT16);
5495 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5496                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5497                                 port_id, UINT16);
5498
5499 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5500                 .f = cmd_remove_bonding_slave_parsed,
5501                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5502                         "Remove a slave device from a bonded device",
5503                 .data = NULL,
5504                 .tokens = {
5505                                 (void *)&cmd_removebonding_slave_remove,
5506                                 (void *)&cmd_removebonding_slave_bonding,
5507                                 (void *)&cmd_removebonding_slave_slave,
5508                                 (void *)&cmd_removebonding_slave_slaveid,
5509                                 (void *)&cmd_removebonding_slave_port,
5510                                 NULL
5511                 }
5512 };
5513
5514 /* *** CREATE BONDED DEVICE *** */
5515 struct cmd_create_bonded_device_result {
5516         cmdline_fixed_string_t create;
5517         cmdline_fixed_string_t bonded;
5518         cmdline_fixed_string_t device;
5519         uint8_t mode;
5520         uint8_t socket;
5521 };
5522
5523 static int bond_dev_num = 0;
5524
5525 static void cmd_create_bonded_device_parsed(void *parsed_result,
5526                 __attribute__((unused))  struct cmdline *cl,
5527                 __attribute__((unused)) void *data)
5528 {
5529         struct cmd_create_bonded_device_result *res = parsed_result;
5530         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5531         int port_id;
5532
5533         if (test_done == 0) {
5534                 printf("Please stop forwarding first\n");
5535                 return;
5536         }
5537
5538         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5539                         bond_dev_num++);
5540
5541         /* Create a new bonded device. */
5542         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5543         if (port_id < 0) {
5544                 printf("\t Failed to create bonded device.\n");
5545                 return;
5546         } else {
5547                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5548                                 port_id);
5549
5550                 /* Update number of ports */
5551                 nb_ports = rte_eth_dev_count_avail();
5552                 reconfig(port_id, res->socket);
5553                 rte_eth_promiscuous_enable(port_id);
5554         }
5555
5556 }
5557
5558 cmdline_parse_token_string_t cmd_createbonded_device_create =
5559                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5560                                 create, "create");
5561 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5562                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5563                                 bonded, "bonded");
5564 cmdline_parse_token_string_t cmd_createbonded_device_device =
5565                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5566                                 device, "device");
5567 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5568                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5569                                 mode, UINT8);
5570 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5571                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5572                                 socket, UINT8);
5573
5574 cmdline_parse_inst_t cmd_create_bonded_device = {
5575                 .f = cmd_create_bonded_device_parsed,
5576                 .help_str = "create bonded device <mode> <socket>: "
5577                         "Create a new bonded device with specific bonding mode and socket",
5578                 .data = NULL,
5579                 .tokens = {
5580                                 (void *)&cmd_createbonded_device_create,
5581                                 (void *)&cmd_createbonded_device_bonded,
5582                                 (void *)&cmd_createbonded_device_device,
5583                                 (void *)&cmd_createbonded_device_mode,
5584                                 (void *)&cmd_createbonded_device_socket,
5585                                 NULL
5586                 }
5587 };
5588
5589 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5590 struct cmd_set_bond_mac_addr_result {
5591         cmdline_fixed_string_t set;
5592         cmdline_fixed_string_t bonding;
5593         cmdline_fixed_string_t mac_addr;
5594         uint16_t port_num;
5595         struct ether_addr address;
5596 };
5597
5598 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5599                 __attribute__((unused))  struct cmdline *cl,
5600                 __attribute__((unused)) void *data)
5601 {
5602         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5603         int ret;
5604
5605         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5606                 return;
5607
5608         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5609
5610         /* check the return value and print it if is < 0 */
5611         if (ret < 0)
5612                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5613 }
5614
5615 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5616                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5617 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5618                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5619                                 "bonding");
5620 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5621                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5622                                 "mac_addr");
5623 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5624                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5625                                 port_num, UINT16);
5626 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5627                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5628
5629 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5630                 .f = cmd_set_bond_mac_addr_parsed,
5631                 .data = (void *) 0,
5632                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5633                 .tokens = {
5634                                 (void *)&cmd_set_bond_mac_addr_set,
5635                                 (void *)&cmd_set_bond_mac_addr_bonding,
5636                                 (void *)&cmd_set_bond_mac_addr_mac,
5637                                 (void *)&cmd_set_bond_mac_addr_portnum,
5638                                 (void *)&cmd_set_bond_mac_addr_addr,
5639                                 NULL
5640                 }
5641 };
5642
5643
5644 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5645 struct cmd_set_bond_mon_period_result {
5646         cmdline_fixed_string_t set;
5647         cmdline_fixed_string_t bonding;
5648         cmdline_fixed_string_t mon_period;
5649         uint16_t port_num;
5650         uint32_t period_ms;
5651 };
5652
5653 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5654                 __attribute__((unused))  struct cmdline *cl,
5655                 __attribute__((unused)) void *data)
5656 {
5657         struct cmd_set_bond_mon_period_result *res = parsed_result;
5658         int ret;
5659
5660         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5661
5662         /* check the return value and print it if is < 0 */
5663         if (ret < 0)
5664                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5665 }
5666
5667 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5668                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5669                                 set, "set");
5670 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5671                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5672                                 bonding, "bonding");
5673 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5674                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5675                                 mon_period,     "mon_period");
5676 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5677                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5678                                 port_num, UINT16);
5679 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5680                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5681                                 period_ms, UINT32);
5682
5683 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5684                 .f = cmd_set_bond_mon_period_parsed,
5685                 .data = (void *) 0,
5686                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5687                 .tokens = {
5688                                 (void *)&cmd_set_bond_mon_period_set,
5689                                 (void *)&cmd_set_bond_mon_period_bonding,
5690                                 (void *)&cmd_set_bond_mon_period_mon_period,
5691                                 (void *)&cmd_set_bond_mon_period_portnum,
5692                                 (void *)&cmd_set_bond_mon_period_period_ms,
5693                                 NULL
5694                 }
5695 };
5696
5697
5698
5699 struct cmd_set_bonding_agg_mode_policy_result {
5700         cmdline_fixed_string_t set;
5701         cmdline_fixed_string_t bonding;
5702         cmdline_fixed_string_t agg_mode;
5703         uint16_t port_num;
5704         cmdline_fixed_string_t policy;
5705 };
5706
5707
5708 static void
5709 cmd_set_bonding_agg_mode(void *parsed_result,
5710                 __attribute__((unused)) struct cmdline *cl,
5711                 __attribute__((unused)) void *data)
5712 {
5713         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5714         uint8_t policy = AGG_BANDWIDTH;
5715
5716         if (!strcmp(res->policy, "bandwidth"))
5717                 policy = AGG_BANDWIDTH;
5718         else if (!strcmp(res->policy, "stable"))
5719                 policy = AGG_STABLE;
5720         else if (!strcmp(res->policy, "count"))
5721                 policy = AGG_COUNT;
5722
5723         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5724 }
5725
5726
5727 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5728         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5729                                 set, "set");
5730 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5731         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5732                                 bonding, "bonding");
5733
5734 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5735         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5736                                 agg_mode, "agg_mode");
5737
5738 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5739         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5740                                 port_num, UINT16);
5741
5742 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5743         TOKEN_STRING_INITIALIZER(
5744                         struct cmd_set_bonding_balance_xmit_policy_result,
5745                 policy, "stable#bandwidth#count");
5746
5747 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5748         .f = cmd_set_bonding_agg_mode,
5749         .data = (void *) 0,
5750         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5751         .tokens = {
5752                         (void *)&cmd_set_bonding_agg_mode_set,
5753                         (void *)&cmd_set_bonding_agg_mode_bonding,
5754                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5755                         (void *)&cmd_set_bonding_agg_mode_portnum,
5756                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5757                         NULL
5758                 }
5759 };
5760
5761
5762 #endif /* RTE_LIBRTE_PMD_BOND */
5763
5764 /* *** SET FORWARDING MODE *** */
5765 struct cmd_set_fwd_mode_result {
5766         cmdline_fixed_string_t set;
5767         cmdline_fixed_string_t fwd;
5768         cmdline_fixed_string_t mode;
5769 };
5770
5771 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5772                                     __attribute__((unused)) struct cmdline *cl,
5773                                     __attribute__((unused)) void *data)
5774 {
5775         struct cmd_set_fwd_mode_result *res = parsed_result;
5776
5777         retry_enabled = 0;
5778         set_pkt_forwarding_mode(res->mode);
5779 }
5780
5781 cmdline_parse_token_string_t cmd_setfwd_set =
5782         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5783 cmdline_parse_token_string_t cmd_setfwd_fwd =
5784         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5785 cmdline_parse_token_string_t cmd_setfwd_mode =
5786         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5787                 "" /* defined at init */);
5788
5789 cmdline_parse_inst_t cmd_set_fwd_mode = {
5790         .f = cmd_set_fwd_mode_parsed,
5791         .data = NULL,
5792         .help_str = NULL, /* defined at init */
5793         .tokens = {
5794                 (void *)&cmd_setfwd_set,
5795                 (void *)&cmd_setfwd_fwd,
5796                 (void *)&cmd_setfwd_mode,
5797                 NULL,
5798         },
5799 };
5800
5801 static void cmd_set_fwd_mode_init(void)
5802 {
5803         char *modes, *c;
5804         static char token[128];
5805         static char help[256];
5806         cmdline_parse_token_string_t *token_struct;
5807
5808         modes = list_pkt_forwarding_modes();
5809         snprintf(help, sizeof(help), "set fwd %s: "
5810                 "Set packet forwarding mode", modes);
5811         cmd_set_fwd_mode.help_str = help;
5812
5813         /* string token separator is # */
5814         for (c = token; *modes != '\0'; modes++)
5815                 if (*modes == '|')
5816                         *c++ = '#';
5817                 else
5818                         *c++ = *modes;
5819         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5820         token_struct->string_data.str = token;
5821 }
5822
5823 /* *** SET RETRY FORWARDING MODE *** */
5824 struct cmd_set_fwd_retry_mode_result {
5825         cmdline_fixed_string_t set;
5826         cmdline_fixed_string_t fwd;
5827         cmdline_fixed_string_t mode;
5828         cmdline_fixed_string_t retry;
5829 };
5830
5831 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5832                             __attribute__((unused)) struct cmdline *cl,
5833                             __attribute__((unused)) void *data)
5834 {
5835         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5836
5837         retry_enabled = 1;
5838         set_pkt_forwarding_mode(res->mode);
5839 }
5840
5841 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5842         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5843                         set, "set");
5844 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5845         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5846                         fwd, "fwd");
5847 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5848         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5849                         mode,
5850                 "" /* defined at init */);
5851 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5852         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5853                         retry, "retry");
5854
5855 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5856         .f = cmd_set_fwd_retry_mode_parsed,
5857         .data = NULL,
5858         .help_str = NULL, /* defined at init */
5859         .tokens = {
5860                 (void *)&cmd_setfwd_retry_set,
5861                 (void *)&cmd_setfwd_retry_fwd,
5862                 (void *)&cmd_setfwd_retry_mode,
5863                 (void *)&cmd_setfwd_retry_retry,
5864                 NULL,
5865         },
5866 };
5867
5868 static void cmd_set_fwd_retry_mode_init(void)
5869 {
5870         char *modes, *c;
5871         static char token[128];
5872         static char help[256];
5873         cmdline_parse_token_string_t *token_struct;
5874
5875         modes = list_pkt_forwarding_retry_modes();
5876         snprintf(help, sizeof(help), "set fwd %s retry: "
5877                 "Set packet forwarding mode with retry", modes);
5878         cmd_set_fwd_retry_mode.help_str = help;
5879
5880         /* string token separator is # */
5881         for (c = token; *modes != '\0'; modes++)
5882                 if (*modes == '|')
5883                         *c++ = '#';
5884                 else
5885                         *c++ = *modes;
5886         token_struct = (cmdline_parse_token_string_t *)
5887                 cmd_set_fwd_retry_mode.tokens[2];
5888         token_struct->string_data.str = token;
5889 }
5890
5891 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5892 struct cmd_set_burst_tx_retry_result {
5893         cmdline_fixed_string_t set;
5894         cmdline_fixed_string_t burst;
5895         cmdline_fixed_string_t tx;
5896         cmdline_fixed_string_t delay;
5897         uint32_t time;
5898         cmdline_fixed_string_t retry;
5899         uint32_t retry_num;
5900 };
5901
5902 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5903                                         __attribute__((unused)) struct cmdline *cl,
5904                                         __attribute__((unused)) void *data)
5905 {
5906         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5907
5908         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5909                 && !strcmp(res->tx, "tx")) {
5910                 if (!strcmp(res->delay, "delay"))
5911                         burst_tx_delay_time = res->time;
5912                 if (!strcmp(res->retry, "retry"))
5913                         burst_tx_retry_num = res->retry_num;
5914         }
5915
5916 }
5917
5918 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5919         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5920 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5921         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5922                                  "burst");
5923 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5924         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5925 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5926         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5927 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5928         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5929 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5930         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5931 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5932         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5933
5934 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5935         .f = cmd_set_burst_tx_retry_parsed,
5936         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5937         .tokens = {
5938                 (void *)&cmd_set_burst_tx_retry_set,
5939                 (void *)&cmd_set_burst_tx_retry_burst,
5940                 (void *)&cmd_set_burst_tx_retry_tx,
5941                 (void *)&cmd_set_burst_tx_retry_delay,
5942                 (void *)&cmd_set_burst_tx_retry_time,
5943                 (void *)&cmd_set_burst_tx_retry_retry,
5944                 (void *)&cmd_set_burst_tx_retry_retry_num,
5945                 NULL,
5946         },
5947 };
5948
5949 /* *** SET PROMISC MODE *** */
5950 struct cmd_set_promisc_mode_result {
5951         cmdline_fixed_string_t set;
5952         cmdline_fixed_string_t promisc;
5953         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5954         uint16_t port_num;               /* valid if "allports" argument == 0 */
5955         cmdline_fixed_string_t mode;
5956 };
5957
5958 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5959                                         __attribute__((unused)) struct cmdline *cl,
5960                                         void *allports)
5961 {
5962         struct cmd_set_promisc_mode_result *res = parsed_result;
5963         int enable;
5964         portid_t i;
5965
5966         if (!strcmp(res->mode, "on"))
5967                 enable = 1;
5968         else
5969                 enable = 0;
5970
5971         /* all ports */
5972         if (allports) {
5973                 RTE_ETH_FOREACH_DEV(i) {
5974                         if (enable)
5975                                 rte_eth_promiscuous_enable(i);
5976                         else
5977                                 rte_eth_promiscuous_disable(i);
5978                 }
5979         }
5980         else {
5981                 if (enable)
5982                         rte_eth_promiscuous_enable(res->port_num);
5983                 else
5984                         rte_eth_promiscuous_disable(res->port_num);
5985         }
5986 }
5987
5988 cmdline_parse_token_string_t cmd_setpromisc_set =
5989         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5990 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5991         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5992                                  "promisc");
5993 cmdline_parse_token_string_t cmd_setpromisc_portall =
5994         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5995                                  "all");
5996 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5997         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5998                               UINT16);
5999 cmdline_parse_token_string_t cmd_setpromisc_mode =
6000         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6001                                  "on#off");
6002
6003 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6004         .f = cmd_set_promisc_mode_parsed,
6005         .data = (void *)1,
6006         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6007         .tokens = {
6008                 (void *)&cmd_setpromisc_set,
6009                 (void *)&cmd_setpromisc_promisc,
6010                 (void *)&cmd_setpromisc_portall,
6011                 (void *)&cmd_setpromisc_mode,
6012                 NULL,
6013         },
6014 };
6015
6016 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6017         .f = cmd_set_promisc_mode_parsed,
6018         .data = (void *)0,
6019         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6020         .tokens = {
6021                 (void *)&cmd_setpromisc_set,
6022                 (void *)&cmd_setpromisc_promisc,
6023                 (void *)&cmd_setpromisc_portnum,
6024                 (void *)&cmd_setpromisc_mode,
6025                 NULL,
6026         },
6027 };
6028
6029 /* *** SET ALLMULTI MODE *** */
6030 struct cmd_set_allmulti_mode_result {
6031         cmdline_fixed_string_t set;
6032         cmdline_fixed_string_t allmulti;
6033         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6034         uint16_t port_num;               /* valid if "allports" argument == 0 */
6035         cmdline_fixed_string_t mode;
6036 };
6037
6038 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6039                                         __attribute__((unused)) struct cmdline *cl,
6040                                         void *allports)
6041 {
6042         struct cmd_set_allmulti_mode_result *res = parsed_result;
6043         int enable;
6044         portid_t i;
6045
6046         if (!strcmp(res->mode, "on"))
6047                 enable = 1;
6048         else
6049                 enable = 0;
6050
6051         /* all ports */
6052         if (allports) {
6053                 RTE_ETH_FOREACH_DEV(i) {
6054                         if (enable)
6055                                 rte_eth_allmulticast_enable(i);
6056                         else
6057                                 rte_eth_allmulticast_disable(i);
6058                 }
6059         }
6060         else {
6061                 if (enable)
6062                         rte_eth_allmulticast_enable(res->port_num);
6063                 else
6064                         rte_eth_allmulticast_disable(res->port_num);
6065         }
6066 }
6067
6068 cmdline_parse_token_string_t cmd_setallmulti_set =
6069         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6070 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6071         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6072                                  "allmulti");
6073 cmdline_parse_token_string_t cmd_setallmulti_portall =
6074         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6075                                  "all");
6076 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6077         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6078                               UINT16);
6079 cmdline_parse_token_string_t cmd_setallmulti_mode =
6080         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6081                                  "on#off");
6082
6083 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6084         .f = cmd_set_allmulti_mode_parsed,
6085         .data = (void *)1,
6086         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6087         .tokens = {
6088                 (void *)&cmd_setallmulti_set,
6089                 (void *)&cmd_setallmulti_allmulti,
6090                 (void *)&cmd_setallmulti_portall,
6091                 (void *)&cmd_setallmulti_mode,
6092                 NULL,
6093         },
6094 };
6095
6096 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6097         .f = cmd_set_allmulti_mode_parsed,
6098         .data = (void *)0,
6099         .help_str = "set allmulti <port_id> on|off: "
6100                 "Set allmulti mode on port_id",
6101         .tokens = {
6102                 (void *)&cmd_setallmulti_set,
6103                 (void *)&cmd_setallmulti_allmulti,
6104                 (void *)&cmd_setallmulti_portnum,
6105                 (void *)&cmd_setallmulti_mode,
6106                 NULL,
6107         },
6108 };
6109
6110 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6111 struct cmd_link_flow_ctrl_set_result {
6112         cmdline_fixed_string_t set;
6113         cmdline_fixed_string_t flow_ctrl;
6114         cmdline_fixed_string_t rx;
6115         cmdline_fixed_string_t rx_lfc_mode;
6116         cmdline_fixed_string_t tx;
6117         cmdline_fixed_string_t tx_lfc_mode;
6118         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6119         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6120         cmdline_fixed_string_t autoneg_str;
6121         cmdline_fixed_string_t autoneg;
6122         cmdline_fixed_string_t hw_str;
6123         uint32_t high_water;
6124         cmdline_fixed_string_t lw_str;
6125         uint32_t low_water;
6126         cmdline_fixed_string_t pt_str;
6127         uint16_t pause_time;
6128         cmdline_fixed_string_t xon_str;
6129         uint16_t send_xon;
6130         portid_t port_id;
6131 };
6132
6133 cmdline_parse_token_string_t cmd_lfc_set_set =
6134         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6135                                 set, "set");
6136 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6137         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6138                                 flow_ctrl, "flow_ctrl");
6139 cmdline_parse_token_string_t cmd_lfc_set_rx =
6140         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6141                                 rx, "rx");
6142 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6143         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6144                                 rx_lfc_mode, "on#off");
6145 cmdline_parse_token_string_t cmd_lfc_set_tx =
6146         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6147                                 tx, "tx");
6148 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6149         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6150                                 tx_lfc_mode, "on#off");
6151 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6152         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6153                                 hw_str, "high_water");
6154 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6155         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6156                                 high_water, UINT32);
6157 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6158         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6159                                 lw_str, "low_water");
6160 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6161         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6162                                 low_water, UINT32);
6163 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6164         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6165                                 pt_str, "pause_time");
6166 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6167         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6168                                 pause_time, UINT16);
6169 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6170         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6171                                 xon_str, "send_xon");
6172 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6173         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6174                                 send_xon, UINT16);
6175 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6176         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6177                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6178 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6179         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6180                                 mac_ctrl_frame_fwd_mode, "on#off");
6181 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6182         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6183                                 autoneg_str, "autoneg");
6184 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6185         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6186                                 autoneg, "on#off");
6187 cmdline_parse_token_num_t cmd_lfc_set_portid =
6188         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6189                                 port_id, UINT16);
6190
6191 /* forward declaration */
6192 static void
6193 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6194                               void *data);
6195
6196 cmdline_parse_inst_t cmd_link_flow_control_set = {
6197         .f = cmd_link_flow_ctrl_set_parsed,
6198         .data = NULL,
6199         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6200                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6201                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6202         .tokens = {
6203                 (void *)&cmd_lfc_set_set,
6204                 (void *)&cmd_lfc_set_flow_ctrl,
6205                 (void *)&cmd_lfc_set_rx,
6206                 (void *)&cmd_lfc_set_rx_mode,
6207                 (void *)&cmd_lfc_set_tx,
6208                 (void *)&cmd_lfc_set_tx_mode,
6209                 (void *)&cmd_lfc_set_high_water,
6210                 (void *)&cmd_lfc_set_low_water,
6211                 (void *)&cmd_lfc_set_pause_time,
6212                 (void *)&cmd_lfc_set_send_xon,
6213                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6214                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6215                 (void *)&cmd_lfc_set_autoneg_str,
6216                 (void *)&cmd_lfc_set_autoneg,
6217                 (void *)&cmd_lfc_set_portid,
6218                 NULL,
6219         },
6220 };
6221
6222 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6223         .f = cmd_link_flow_ctrl_set_parsed,
6224         .data = (void *)&cmd_link_flow_control_set_rx,
6225         .help_str = "set flow_ctrl rx on|off <port_id>: "
6226                 "Change rx flow control parameter",
6227         .tokens = {
6228                 (void *)&cmd_lfc_set_set,
6229                 (void *)&cmd_lfc_set_flow_ctrl,
6230                 (void *)&cmd_lfc_set_rx,
6231                 (void *)&cmd_lfc_set_rx_mode,
6232                 (void *)&cmd_lfc_set_portid,
6233                 NULL,
6234         },
6235 };
6236
6237 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6238         .f = cmd_link_flow_ctrl_set_parsed,
6239         .data = (void *)&cmd_link_flow_control_set_tx,
6240         .help_str = "set flow_ctrl tx on|off <port_id>: "
6241                 "Change tx flow control parameter",
6242         .tokens = {
6243                 (void *)&cmd_lfc_set_set,
6244                 (void *)&cmd_lfc_set_flow_ctrl,
6245                 (void *)&cmd_lfc_set_tx,
6246                 (void *)&cmd_lfc_set_tx_mode,
6247                 (void *)&cmd_lfc_set_portid,
6248                 NULL,
6249         },
6250 };
6251
6252 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6253         .f = cmd_link_flow_ctrl_set_parsed,
6254         .data = (void *)&cmd_link_flow_control_set_hw,
6255         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6256                 "Change high water flow control parameter",
6257         .tokens = {
6258                 (void *)&cmd_lfc_set_set,
6259                 (void *)&cmd_lfc_set_flow_ctrl,
6260                 (void *)&cmd_lfc_set_high_water_str,
6261                 (void *)&cmd_lfc_set_high_water,
6262                 (void *)&cmd_lfc_set_portid,
6263                 NULL,
6264         },
6265 };
6266
6267 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6268         .f = cmd_link_flow_ctrl_set_parsed,
6269         .data = (void *)&cmd_link_flow_control_set_lw,
6270         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6271                 "Change low water flow control parameter",
6272         .tokens = {
6273                 (void *)&cmd_lfc_set_set,
6274                 (void *)&cmd_lfc_set_flow_ctrl,
6275                 (void *)&cmd_lfc_set_low_water_str,
6276                 (void *)&cmd_lfc_set_low_water,
6277                 (void *)&cmd_lfc_set_portid,
6278                 NULL,
6279         },
6280 };
6281
6282 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6283         .f = cmd_link_flow_ctrl_set_parsed,
6284         .data = (void *)&cmd_link_flow_control_set_pt,
6285         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6286                 "Change pause time flow control parameter",
6287         .tokens = {
6288                 (void *)&cmd_lfc_set_set,
6289                 (void *)&cmd_lfc_set_flow_ctrl,
6290                 (void *)&cmd_lfc_set_pause_time_str,
6291                 (void *)&cmd_lfc_set_pause_time,
6292                 (void *)&cmd_lfc_set_portid,
6293                 NULL,
6294         },
6295 };
6296
6297 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6298         .f = cmd_link_flow_ctrl_set_parsed,
6299         .data = (void *)&cmd_link_flow_control_set_xon,
6300         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6301                 "Change send_xon flow control parameter",
6302         .tokens = {
6303                 (void *)&cmd_lfc_set_set,
6304                 (void *)&cmd_lfc_set_flow_ctrl,
6305                 (void *)&cmd_lfc_set_send_xon_str,
6306                 (void *)&cmd_lfc_set_send_xon,
6307                 (void *)&cmd_lfc_set_portid,
6308                 NULL,
6309         },
6310 };
6311
6312 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6313         .f = cmd_link_flow_ctrl_set_parsed,
6314         .data = (void *)&cmd_link_flow_control_set_macfwd,
6315         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6316                 "Change mac ctrl fwd flow control parameter",
6317         .tokens = {
6318                 (void *)&cmd_lfc_set_set,
6319                 (void *)&cmd_lfc_set_flow_ctrl,
6320                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6321                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6322                 (void *)&cmd_lfc_set_portid,
6323                 NULL,
6324         },
6325 };
6326
6327 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6328         .f = cmd_link_flow_ctrl_set_parsed,
6329         .data = (void *)&cmd_link_flow_control_set_autoneg,
6330         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6331                 "Change autoneg flow control parameter",
6332         .tokens = {
6333                 (void *)&cmd_lfc_set_set,
6334                 (void *)&cmd_lfc_set_flow_ctrl,
6335                 (void *)&cmd_lfc_set_autoneg_str,
6336                 (void *)&cmd_lfc_set_autoneg,
6337                 (void *)&cmd_lfc_set_portid,
6338                 NULL,
6339         },
6340 };
6341
6342 static void
6343 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6344                               __attribute__((unused)) struct cmdline *cl,
6345                               void *data)
6346 {
6347         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6348         cmdline_parse_inst_t *cmd = data;
6349         struct rte_eth_fc_conf fc_conf;
6350         int rx_fc_en = 0;
6351         int tx_fc_en = 0;
6352         int ret;
6353
6354         /*
6355          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6356          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6357          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6358          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6359          */
6360         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6361                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6362         };
6363
6364         /* Partial command line, retrieve current configuration */
6365         if (cmd) {
6366                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6367                 if (ret != 0) {
6368                         printf("cannot get current flow ctrl parameters, return"
6369                                "code = %d\n", ret);
6370                         return;
6371                 }
6372
6373                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6374                     (fc_conf.mode == RTE_FC_FULL))
6375                         rx_fc_en = 1;
6376                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6377                     (fc_conf.mode == RTE_FC_FULL))
6378                         tx_fc_en = 1;
6379         }
6380
6381         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6382                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6383
6384         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6385                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6386
6387         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6388
6389         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6390                 fc_conf.high_water = res->high_water;
6391
6392         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6393                 fc_conf.low_water = res->low_water;
6394
6395         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6396                 fc_conf.pause_time = res->pause_time;
6397
6398         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6399                 fc_conf.send_xon = res->send_xon;
6400
6401         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6402                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6403                         fc_conf.mac_ctrl_frame_fwd = 1;
6404                 else
6405                         fc_conf.mac_ctrl_frame_fwd = 0;
6406         }
6407
6408         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6409                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6410
6411         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6412         if (ret != 0)
6413                 printf("bad flow contrl parameter, return code = %d \n", ret);
6414 }
6415
6416 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6417 struct cmd_priority_flow_ctrl_set_result {
6418         cmdline_fixed_string_t set;
6419         cmdline_fixed_string_t pfc_ctrl;
6420         cmdline_fixed_string_t rx;
6421         cmdline_fixed_string_t rx_pfc_mode;
6422         cmdline_fixed_string_t tx;
6423         cmdline_fixed_string_t tx_pfc_mode;
6424         uint32_t high_water;
6425         uint32_t low_water;
6426         uint16_t pause_time;
6427         uint8_t  priority;
6428         portid_t port_id;
6429 };
6430
6431 static void
6432 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6433                        __attribute__((unused)) struct cmdline *cl,
6434                        __attribute__((unused)) void *data)
6435 {
6436         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6437         struct rte_eth_pfc_conf pfc_conf;
6438         int rx_fc_enable, tx_fc_enable;
6439         int ret;
6440
6441         /*
6442          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6443          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6444          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6445          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6446          */
6447         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6448                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6449         };
6450
6451         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6452         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6453         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6454         pfc_conf.fc.high_water = res->high_water;
6455         pfc_conf.fc.low_water  = res->low_water;
6456         pfc_conf.fc.pause_time = res->pause_time;
6457         pfc_conf.priority      = res->priority;
6458
6459         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6460         if (ret != 0)
6461                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6462 }
6463
6464 cmdline_parse_token_string_t cmd_pfc_set_set =
6465         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6466                                 set, "set");
6467 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6468         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6469                                 pfc_ctrl, "pfc_ctrl");
6470 cmdline_parse_token_string_t cmd_pfc_set_rx =
6471         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6472                                 rx, "rx");
6473 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6474         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6475                                 rx_pfc_mode, "on#off");
6476 cmdline_parse_token_string_t cmd_pfc_set_tx =
6477         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6478                                 tx, "tx");
6479 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6480         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6481                                 tx_pfc_mode, "on#off");
6482 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6483         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6484                                 high_water, UINT32);
6485 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6486         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6487                                 low_water, UINT32);
6488 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6489         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6490                                 pause_time, UINT16);
6491 cmdline_parse_token_num_t cmd_pfc_set_priority =
6492         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6493                                 priority, UINT8);
6494 cmdline_parse_token_num_t cmd_pfc_set_portid =
6495         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6496                                 port_id, UINT16);
6497
6498 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6499         .f = cmd_priority_flow_ctrl_set_parsed,
6500         .data = NULL,
6501         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6502                 "<pause_time> <priority> <port_id>: "
6503                 "Configure the Ethernet priority flow control",
6504         .tokens = {
6505                 (void *)&cmd_pfc_set_set,
6506                 (void *)&cmd_pfc_set_flow_ctrl,
6507                 (void *)&cmd_pfc_set_rx,
6508                 (void *)&cmd_pfc_set_rx_mode,
6509                 (void *)&cmd_pfc_set_tx,
6510                 (void *)&cmd_pfc_set_tx_mode,
6511                 (void *)&cmd_pfc_set_high_water,
6512                 (void *)&cmd_pfc_set_low_water,
6513                 (void *)&cmd_pfc_set_pause_time,
6514                 (void *)&cmd_pfc_set_priority,
6515                 (void *)&cmd_pfc_set_portid,
6516                 NULL,
6517         },
6518 };
6519
6520 /* *** RESET CONFIGURATION *** */
6521 struct cmd_reset_result {
6522         cmdline_fixed_string_t reset;
6523         cmdline_fixed_string_t def;
6524 };
6525
6526 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6527                              struct cmdline *cl,
6528                              __attribute__((unused)) void *data)
6529 {
6530         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6531         set_def_fwd_config();
6532 }
6533
6534 cmdline_parse_token_string_t cmd_reset_set =
6535         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6536 cmdline_parse_token_string_t cmd_reset_def =
6537         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6538                                  "default");
6539
6540 cmdline_parse_inst_t cmd_reset = {
6541         .f = cmd_reset_parsed,
6542         .data = NULL,
6543         .help_str = "set default: Reset default forwarding configuration",
6544         .tokens = {
6545                 (void *)&cmd_reset_set,
6546                 (void *)&cmd_reset_def,
6547                 NULL,
6548         },
6549 };
6550
6551 /* *** START FORWARDING *** */
6552 struct cmd_start_result {
6553         cmdline_fixed_string_t start;
6554 };
6555
6556 cmdline_parse_token_string_t cmd_start_start =
6557         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6558
6559 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6560                              __attribute__((unused)) struct cmdline *cl,
6561                              __attribute__((unused)) void *data)
6562 {
6563         start_packet_forwarding(0);
6564 }
6565
6566 cmdline_parse_inst_t cmd_start = {
6567         .f = cmd_start_parsed,
6568         .data = NULL,
6569         .help_str = "start: Start packet forwarding",
6570         .tokens = {
6571                 (void *)&cmd_start_start,
6572                 NULL,
6573         },
6574 };
6575
6576 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6577 struct cmd_start_tx_first_result {
6578         cmdline_fixed_string_t start;
6579         cmdline_fixed_string_t tx_first;
6580 };
6581
6582 static void
6583 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6584                           __attribute__((unused)) struct cmdline *cl,
6585                           __attribute__((unused)) void *data)
6586 {
6587         start_packet_forwarding(1);
6588 }
6589
6590 cmdline_parse_token_string_t cmd_start_tx_first_start =
6591         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6592                                  "start");
6593 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6594         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6595                                  tx_first, "tx_first");
6596
6597 cmdline_parse_inst_t cmd_start_tx_first = {
6598         .f = cmd_start_tx_first_parsed,
6599         .data = NULL,
6600         .help_str = "start tx_first: Start packet forwarding, "
6601                 "after sending 1 burst of packets",
6602         .tokens = {
6603                 (void *)&cmd_start_tx_first_start,
6604                 (void *)&cmd_start_tx_first_tx_first,
6605                 NULL,
6606         },
6607 };
6608
6609 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6610 struct cmd_start_tx_first_n_result {
6611         cmdline_fixed_string_t start;
6612         cmdline_fixed_string_t tx_first;
6613         uint32_t tx_num;
6614 };
6615
6616 static void
6617 cmd_start_tx_first_n_parsed(void *parsed_result,
6618                           __attribute__((unused)) struct cmdline *cl,
6619                           __attribute__((unused)) void *data)
6620 {
6621         struct cmd_start_tx_first_n_result *res = parsed_result;
6622
6623         start_packet_forwarding(res->tx_num);
6624 }
6625
6626 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6627         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6628                         start, "start");
6629 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6630         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6631                         tx_first, "tx_first");
6632 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6633         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6634                         tx_num, UINT32);
6635
6636 cmdline_parse_inst_t cmd_start_tx_first_n = {
6637         .f = cmd_start_tx_first_n_parsed,
6638         .data = NULL,
6639         .help_str = "start tx_first <num>: "
6640                 "packet forwarding, after sending <num> bursts of packets",
6641         .tokens = {
6642                 (void *)&cmd_start_tx_first_n_start,
6643                 (void *)&cmd_start_tx_first_n_tx_first,
6644                 (void *)&cmd_start_tx_first_n_tx_num,
6645                 NULL,
6646         },
6647 };
6648
6649 /* *** SET LINK UP *** */
6650 struct cmd_set_link_up_result {
6651         cmdline_fixed_string_t set;
6652         cmdline_fixed_string_t link_up;
6653         cmdline_fixed_string_t port;
6654         portid_t port_id;
6655 };
6656
6657 cmdline_parse_token_string_t cmd_set_link_up_set =
6658         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6659 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6660         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6661                                 "link-up");
6662 cmdline_parse_token_string_t cmd_set_link_up_port =
6663         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6664 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6665         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6666
6667 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6668                              __attribute__((unused)) struct cmdline *cl,
6669                              __attribute__((unused)) void *data)
6670 {
6671         struct cmd_set_link_up_result *res = parsed_result;
6672         dev_set_link_up(res->port_id);
6673 }
6674
6675 cmdline_parse_inst_t cmd_set_link_up = {
6676         .f = cmd_set_link_up_parsed,
6677         .data = NULL,
6678         .help_str = "set link-up port <port id>",
6679         .tokens = {
6680                 (void *)&cmd_set_link_up_set,
6681                 (void *)&cmd_set_link_up_link_up,
6682                 (void *)&cmd_set_link_up_port,
6683                 (void *)&cmd_set_link_up_port_id,
6684                 NULL,
6685         },
6686 };
6687
6688 /* *** SET LINK DOWN *** */
6689 struct cmd_set_link_down_result {
6690         cmdline_fixed_string_t set;
6691         cmdline_fixed_string_t link_down;
6692         cmdline_fixed_string_t port;
6693         portid_t port_id;
6694 };
6695
6696 cmdline_parse_token_string_t cmd_set_link_down_set =
6697         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6698 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6699         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6700                                 "link-down");
6701 cmdline_parse_token_string_t cmd_set_link_down_port =
6702         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6703 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6704         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6705
6706 static void cmd_set_link_down_parsed(
6707                                 __attribute__((unused)) void *parsed_result,
6708                                 __attribute__((unused)) struct cmdline *cl,
6709                                 __attribute__((unused)) void *data)
6710 {
6711         struct cmd_set_link_down_result *res = parsed_result;
6712         dev_set_link_down(res->port_id);
6713 }
6714
6715 cmdline_parse_inst_t cmd_set_link_down = {
6716         .f = cmd_set_link_down_parsed,
6717         .data = NULL,
6718         .help_str = "set link-down port <port id>",
6719         .tokens = {
6720                 (void *)&cmd_set_link_down_set,
6721                 (void *)&cmd_set_link_down_link_down,
6722                 (void *)&cmd_set_link_down_port,
6723                 (void *)&cmd_set_link_down_port_id,
6724                 NULL,
6725         },
6726 };
6727
6728 /* *** SHOW CFG *** */
6729 struct cmd_showcfg_result {
6730         cmdline_fixed_string_t show;
6731         cmdline_fixed_string_t cfg;
6732         cmdline_fixed_string_t what;
6733 };
6734
6735 static void cmd_showcfg_parsed(void *parsed_result,
6736                                __attribute__((unused)) struct cmdline *cl,
6737                                __attribute__((unused)) void *data)
6738 {
6739         struct cmd_showcfg_result *res = parsed_result;
6740         if (!strcmp(res->what, "rxtx"))
6741                 rxtx_config_display();
6742         else if (!strcmp(res->what, "cores"))
6743                 fwd_lcores_config_display();
6744         else if (!strcmp(res->what, "fwd"))
6745                 pkt_fwd_config_display(&cur_fwd_config);
6746         else if (!strcmp(res->what, "txpkts"))
6747                 show_tx_pkt_segments();
6748 }
6749
6750 cmdline_parse_token_string_t cmd_showcfg_show =
6751         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6752 cmdline_parse_token_string_t cmd_showcfg_port =
6753         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6754 cmdline_parse_token_string_t cmd_showcfg_what =
6755         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6756                                  "rxtx#cores#fwd#txpkts");
6757
6758 cmdline_parse_inst_t cmd_showcfg = {
6759         .f = cmd_showcfg_parsed,
6760         .data = NULL,
6761         .help_str = "show config rxtx|cores|fwd|txpkts",
6762         .tokens = {
6763                 (void *)&cmd_showcfg_show,
6764                 (void *)&cmd_showcfg_port,
6765                 (void *)&cmd_showcfg_what,
6766                 NULL,
6767         },
6768 };
6769
6770 /* *** SHOW ALL PORT INFO *** */
6771 struct cmd_showportall_result {
6772         cmdline_fixed_string_t show;
6773         cmdline_fixed_string_t port;
6774         cmdline_fixed_string_t what;
6775         cmdline_fixed_string_t all;
6776 };
6777
6778 static void cmd_showportall_parsed(void *parsed_result,
6779                                 __attribute__((unused)) struct cmdline *cl,
6780                                 __attribute__((unused)) void *data)
6781 {
6782         portid_t i;
6783
6784         struct cmd_showportall_result *res = parsed_result;
6785         if (!strcmp(res->show, "clear")) {
6786                 if (!strcmp(res->what, "stats"))
6787                         RTE_ETH_FOREACH_DEV(i)
6788                                 nic_stats_clear(i);
6789                 else if (!strcmp(res->what, "xstats"))
6790                         RTE_ETH_FOREACH_DEV(i)
6791                                 nic_xstats_clear(i);
6792         } else if (!strcmp(res->what, "info"))
6793                 RTE_ETH_FOREACH_DEV(i)
6794                         port_infos_display(i);
6795         else if (!strcmp(res->what, "stats"))
6796                 RTE_ETH_FOREACH_DEV(i)
6797                         nic_stats_display(i);
6798         else if (!strcmp(res->what, "xstats"))
6799                 RTE_ETH_FOREACH_DEV(i)
6800                         nic_xstats_display(i);
6801         else if (!strcmp(res->what, "fdir"))
6802                 RTE_ETH_FOREACH_DEV(i)
6803                         fdir_get_infos(i);
6804         else if (!strcmp(res->what, "stat_qmap"))
6805                 RTE_ETH_FOREACH_DEV(i)
6806                         nic_stats_mapping_display(i);
6807         else if (!strcmp(res->what, "dcb_tc"))
6808                 RTE_ETH_FOREACH_DEV(i)
6809                         port_dcb_info_display(i);
6810         else if (!strcmp(res->what, "cap"))
6811                 RTE_ETH_FOREACH_DEV(i)
6812                         port_offload_cap_display(i);
6813 }
6814
6815 cmdline_parse_token_string_t cmd_showportall_show =
6816         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6817                                  "show#clear");
6818 cmdline_parse_token_string_t cmd_showportall_port =
6819         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6820 cmdline_parse_token_string_t cmd_showportall_what =
6821         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6822                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6823 cmdline_parse_token_string_t cmd_showportall_all =
6824         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6825 cmdline_parse_inst_t cmd_showportall = {
6826         .f = cmd_showportall_parsed,
6827         .data = NULL,
6828         .help_str = "show|clear port "
6829                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6830         .tokens = {
6831                 (void *)&cmd_showportall_show,
6832                 (void *)&cmd_showportall_port,
6833                 (void *)&cmd_showportall_what,
6834                 (void *)&cmd_showportall_all,
6835                 NULL,
6836         },
6837 };
6838
6839 /* *** SHOW PORT INFO *** */
6840 struct cmd_showport_result {
6841         cmdline_fixed_string_t show;
6842         cmdline_fixed_string_t port;
6843         cmdline_fixed_string_t what;
6844         uint16_t portnum;
6845 };
6846
6847 static void cmd_showport_parsed(void *parsed_result,
6848                                 __attribute__((unused)) struct cmdline *cl,
6849                                 __attribute__((unused)) void *data)
6850 {
6851         struct cmd_showport_result *res = parsed_result;
6852         if (!strcmp(res->show, "clear")) {
6853                 if (!strcmp(res->what, "stats"))
6854                         nic_stats_clear(res->portnum);
6855                 else if (!strcmp(res->what, "xstats"))
6856                         nic_xstats_clear(res->portnum);
6857         } else if (!strcmp(res->what, "info"))
6858                 port_infos_display(res->portnum);
6859         else if (!strcmp(res->what, "stats"))
6860                 nic_stats_display(res->portnum);
6861         else if (!strcmp(res->what, "xstats"))
6862                 nic_xstats_display(res->portnum);
6863         else if (!strcmp(res->what, "fdir"))
6864                  fdir_get_infos(res->portnum);
6865         else if (!strcmp(res->what, "stat_qmap"))
6866                 nic_stats_mapping_display(res->portnum);
6867         else if (!strcmp(res->what, "dcb_tc"))
6868                 port_dcb_info_display(res->portnum);
6869         else if (!strcmp(res->what, "cap"))
6870                 port_offload_cap_display(res->portnum);
6871 }
6872
6873 cmdline_parse_token_string_t cmd_showport_show =
6874         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6875                                  "show#clear");
6876 cmdline_parse_token_string_t cmd_showport_port =
6877         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6878 cmdline_parse_token_string_t cmd_showport_what =
6879         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6880                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6881 cmdline_parse_token_num_t cmd_showport_portnum =
6882         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6883
6884 cmdline_parse_inst_t cmd_showport = {
6885         .f = cmd_showport_parsed,
6886         .data = NULL,
6887         .help_str = "show|clear port "
6888                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6889                 "<port_id>",
6890         .tokens = {
6891                 (void *)&cmd_showport_show,
6892                 (void *)&cmd_showport_port,
6893                 (void *)&cmd_showport_what,
6894                 (void *)&cmd_showport_portnum,
6895                 NULL,
6896         },
6897 };
6898
6899 /* *** SHOW QUEUE INFO *** */
6900 struct cmd_showqueue_result {
6901         cmdline_fixed_string_t show;
6902         cmdline_fixed_string_t type;
6903         cmdline_fixed_string_t what;
6904         uint16_t portnum;
6905         uint16_t queuenum;
6906 };
6907
6908 static void
6909 cmd_showqueue_parsed(void *parsed_result,
6910         __attribute__((unused)) struct cmdline *cl,
6911         __attribute__((unused)) void *data)
6912 {
6913         struct cmd_showqueue_result *res = parsed_result;
6914
6915         if (!strcmp(res->type, "rxq"))
6916                 rx_queue_infos_display(res->portnum, res->queuenum);
6917         else if (!strcmp(res->type, "txq"))
6918                 tx_queue_infos_display(res->portnum, res->queuenum);
6919 }
6920
6921 cmdline_parse_token_string_t cmd_showqueue_show =
6922         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6923 cmdline_parse_token_string_t cmd_showqueue_type =
6924         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6925 cmdline_parse_token_string_t cmd_showqueue_what =
6926         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6927 cmdline_parse_token_num_t cmd_showqueue_portnum =
6928         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6929 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6930         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6931
6932 cmdline_parse_inst_t cmd_showqueue = {
6933         .f = cmd_showqueue_parsed,
6934         .data = NULL,
6935         .help_str = "show rxq|txq info <port_id> <queue_id>",
6936         .tokens = {
6937                 (void *)&cmd_showqueue_show,
6938                 (void *)&cmd_showqueue_type,
6939                 (void *)&cmd_showqueue_what,
6940                 (void *)&cmd_showqueue_portnum,
6941                 (void *)&cmd_showqueue_queuenum,
6942                 NULL,
6943         },
6944 };
6945
6946 /* *** READ PORT REGISTER *** */
6947 struct cmd_read_reg_result {
6948         cmdline_fixed_string_t read;
6949         cmdline_fixed_string_t reg;
6950         portid_t port_id;
6951         uint32_t reg_off;
6952 };
6953
6954 static void
6955 cmd_read_reg_parsed(void *parsed_result,
6956                     __attribute__((unused)) struct cmdline *cl,
6957                     __attribute__((unused)) void *data)
6958 {
6959         struct cmd_read_reg_result *res = parsed_result;
6960         port_reg_display(res->port_id, res->reg_off);
6961 }
6962
6963 cmdline_parse_token_string_t cmd_read_reg_read =
6964         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6965 cmdline_parse_token_string_t cmd_read_reg_reg =
6966         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6967 cmdline_parse_token_num_t cmd_read_reg_port_id =
6968         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6969 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6970         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6971
6972 cmdline_parse_inst_t cmd_read_reg = {
6973         .f = cmd_read_reg_parsed,
6974         .data = NULL,
6975         .help_str = "read reg <port_id> <reg_off>",
6976         .tokens = {
6977                 (void *)&cmd_read_reg_read,
6978                 (void *)&cmd_read_reg_reg,
6979                 (void *)&cmd_read_reg_port_id,
6980                 (void *)&cmd_read_reg_reg_off,
6981                 NULL,
6982         },
6983 };
6984
6985 /* *** READ PORT REGISTER BIT FIELD *** */
6986 struct cmd_read_reg_bit_field_result {
6987         cmdline_fixed_string_t read;
6988         cmdline_fixed_string_t regfield;
6989         portid_t port_id;
6990         uint32_t reg_off;
6991         uint8_t bit1_pos;
6992         uint8_t bit2_pos;
6993 };
6994
6995 static void
6996 cmd_read_reg_bit_field_parsed(void *parsed_result,
6997                               __attribute__((unused)) struct cmdline *cl,
6998                               __attribute__((unused)) void *data)
6999 {
7000         struct cmd_read_reg_bit_field_result *res = parsed_result;
7001         port_reg_bit_field_display(res->port_id, res->reg_off,
7002                                    res->bit1_pos, res->bit2_pos);
7003 }
7004
7005 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7006         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7007                                  "read");
7008 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7009         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7010                                  regfield, "regfield");
7011 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7012         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7013                               UINT16);
7014 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7015         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7016                               UINT32);
7017 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7018         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7019                               UINT8);
7020 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7021         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7022                               UINT8);
7023
7024 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7025         .f = cmd_read_reg_bit_field_parsed,
7026         .data = NULL,
7027         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7028         "Read register bit field between bit_x and bit_y included",
7029         .tokens = {
7030                 (void *)&cmd_read_reg_bit_field_read,
7031                 (void *)&cmd_read_reg_bit_field_regfield,
7032                 (void *)&cmd_read_reg_bit_field_port_id,
7033                 (void *)&cmd_read_reg_bit_field_reg_off,
7034                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7035                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7036                 NULL,
7037         },
7038 };
7039
7040 /* *** READ PORT REGISTER BIT *** */
7041 struct cmd_read_reg_bit_result {
7042         cmdline_fixed_string_t read;
7043         cmdline_fixed_string_t regbit;
7044         portid_t port_id;
7045         uint32_t reg_off;
7046         uint8_t bit_pos;
7047 };
7048
7049 static void
7050 cmd_read_reg_bit_parsed(void *parsed_result,
7051                         __attribute__((unused)) struct cmdline *cl,
7052                         __attribute__((unused)) void *data)
7053 {
7054         struct cmd_read_reg_bit_result *res = parsed_result;
7055         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7056 }
7057
7058 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7059         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7060 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7061         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7062                                  regbit, "regbit");
7063 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7064         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7065 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7066         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7067 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7068         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7069
7070 cmdline_parse_inst_t cmd_read_reg_bit = {
7071         .f = cmd_read_reg_bit_parsed,
7072         .data = NULL,
7073         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7074         .tokens = {
7075                 (void *)&cmd_read_reg_bit_read,
7076                 (void *)&cmd_read_reg_bit_regbit,
7077                 (void *)&cmd_read_reg_bit_port_id,
7078                 (void *)&cmd_read_reg_bit_reg_off,
7079                 (void *)&cmd_read_reg_bit_bit_pos,
7080                 NULL,
7081         },
7082 };
7083
7084 /* *** WRITE PORT REGISTER *** */
7085 struct cmd_write_reg_result {
7086         cmdline_fixed_string_t write;
7087         cmdline_fixed_string_t reg;
7088         portid_t port_id;
7089         uint32_t reg_off;
7090         uint32_t value;
7091 };
7092
7093 static void
7094 cmd_write_reg_parsed(void *parsed_result,
7095                      __attribute__((unused)) struct cmdline *cl,
7096                      __attribute__((unused)) void *data)
7097 {
7098         struct cmd_write_reg_result *res = parsed_result;
7099         port_reg_set(res->port_id, res->reg_off, res->value);
7100 }
7101
7102 cmdline_parse_token_string_t cmd_write_reg_write =
7103         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7104 cmdline_parse_token_string_t cmd_write_reg_reg =
7105         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7106 cmdline_parse_token_num_t cmd_write_reg_port_id =
7107         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7108 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7109         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7110 cmdline_parse_token_num_t cmd_write_reg_value =
7111         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7112
7113 cmdline_parse_inst_t cmd_write_reg = {
7114         .f = cmd_write_reg_parsed,
7115         .data = NULL,
7116         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7117         .tokens = {
7118                 (void *)&cmd_write_reg_write,
7119                 (void *)&cmd_write_reg_reg,
7120                 (void *)&cmd_write_reg_port_id,
7121                 (void *)&cmd_write_reg_reg_off,
7122                 (void *)&cmd_write_reg_value,
7123                 NULL,
7124         },
7125 };
7126
7127 /* *** WRITE PORT REGISTER BIT FIELD *** */
7128 struct cmd_write_reg_bit_field_result {
7129         cmdline_fixed_string_t write;
7130         cmdline_fixed_string_t regfield;
7131         portid_t port_id;
7132         uint32_t reg_off;
7133         uint8_t bit1_pos;
7134         uint8_t bit2_pos;
7135         uint32_t value;
7136 };
7137
7138 static void
7139 cmd_write_reg_bit_field_parsed(void *parsed_result,
7140                                __attribute__((unused)) struct cmdline *cl,
7141                                __attribute__((unused)) void *data)
7142 {
7143         struct cmd_write_reg_bit_field_result *res = parsed_result;
7144         port_reg_bit_field_set(res->port_id, res->reg_off,
7145                           res->bit1_pos, res->bit2_pos, res->value);
7146 }
7147
7148 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7149         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7150                                  "write");
7151 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7152         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7153                                  regfield, "regfield");
7154 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7155         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7156                               UINT16);
7157 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7158         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7159                               UINT32);
7160 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7161         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7162                               UINT8);
7163 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7164         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7165                               UINT8);
7166 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7167         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7168                               UINT32);
7169
7170 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7171         .f = cmd_write_reg_bit_field_parsed,
7172         .data = NULL,
7173         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7174                 "<reg_value>: "
7175                 "Set register bit field between bit_x and bit_y included",
7176         .tokens = {
7177                 (void *)&cmd_write_reg_bit_field_write,
7178                 (void *)&cmd_write_reg_bit_field_regfield,
7179                 (void *)&cmd_write_reg_bit_field_port_id,
7180                 (void *)&cmd_write_reg_bit_field_reg_off,
7181                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7182                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7183                 (void *)&cmd_write_reg_bit_field_value,
7184                 NULL,
7185         },
7186 };
7187
7188 /* *** WRITE PORT REGISTER BIT *** */
7189 struct cmd_write_reg_bit_result {
7190         cmdline_fixed_string_t write;
7191         cmdline_fixed_string_t regbit;
7192         portid_t port_id;
7193         uint32_t reg_off;
7194         uint8_t bit_pos;
7195         uint8_t value;
7196 };
7197
7198 static void
7199 cmd_write_reg_bit_parsed(void *parsed_result,
7200                          __attribute__((unused)) struct cmdline *cl,
7201                          __attribute__((unused)) void *data)
7202 {
7203         struct cmd_write_reg_bit_result *res = parsed_result;
7204         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7205 }
7206
7207 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7208         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7209                                  "write");
7210 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7211         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7212                                  regbit, "regbit");
7213 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7214         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7215 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7216         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7217 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7218         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7219 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7220         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7221
7222 cmdline_parse_inst_t cmd_write_reg_bit = {
7223         .f = cmd_write_reg_bit_parsed,
7224         .data = NULL,
7225         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7226                 "0 <= bit_x <= 31",
7227         .tokens = {
7228                 (void *)&cmd_write_reg_bit_write,
7229                 (void *)&cmd_write_reg_bit_regbit,
7230                 (void *)&cmd_write_reg_bit_port_id,
7231                 (void *)&cmd_write_reg_bit_reg_off,
7232                 (void *)&cmd_write_reg_bit_bit_pos,
7233                 (void *)&cmd_write_reg_bit_value,
7234                 NULL,
7235         },
7236 };
7237
7238 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7239 struct cmd_read_rxd_txd_result {
7240         cmdline_fixed_string_t read;
7241         cmdline_fixed_string_t rxd_txd;
7242         portid_t port_id;
7243         uint16_t queue_id;
7244         uint16_t desc_id;
7245 };
7246
7247 static void
7248 cmd_read_rxd_txd_parsed(void *parsed_result,
7249                         __attribute__((unused)) struct cmdline *cl,
7250                         __attribute__((unused)) void *data)
7251 {
7252         struct cmd_read_rxd_txd_result *res = parsed_result;
7253
7254         if (!strcmp(res->rxd_txd, "rxd"))
7255                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7256         else if (!strcmp(res->rxd_txd, "txd"))
7257                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7258 }
7259
7260 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7261         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7262 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7263         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7264                                  "rxd#txd");
7265 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7266         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7267 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7268         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7269 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7270         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7271
7272 cmdline_parse_inst_t cmd_read_rxd_txd = {
7273         .f = cmd_read_rxd_txd_parsed,
7274         .data = NULL,
7275         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7276         .tokens = {
7277                 (void *)&cmd_read_rxd_txd_read,
7278                 (void *)&cmd_read_rxd_txd_rxd_txd,
7279                 (void *)&cmd_read_rxd_txd_port_id,
7280                 (void *)&cmd_read_rxd_txd_queue_id,
7281                 (void *)&cmd_read_rxd_txd_desc_id,
7282                 NULL,
7283         },
7284 };
7285
7286 /* *** QUIT *** */
7287 struct cmd_quit_result {
7288         cmdline_fixed_string_t quit;
7289 };
7290
7291 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7292                             struct cmdline *cl,
7293                             __attribute__((unused)) void *data)
7294 {
7295         pmd_test_exit();
7296         cmdline_quit(cl);
7297 }
7298
7299 cmdline_parse_token_string_t cmd_quit_quit =
7300         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7301
7302 cmdline_parse_inst_t cmd_quit = {
7303         .f = cmd_quit_parsed,
7304         .data = NULL,
7305         .help_str = "quit: Exit application",
7306         .tokens = {
7307                 (void *)&cmd_quit_quit,
7308                 NULL,
7309         },
7310 };
7311
7312 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7313 struct cmd_mac_addr_result {
7314         cmdline_fixed_string_t mac_addr_cmd;
7315         cmdline_fixed_string_t what;
7316         uint16_t port_num;
7317         struct ether_addr address;
7318 };
7319
7320 static void cmd_mac_addr_parsed(void *parsed_result,
7321                 __attribute__((unused)) struct cmdline *cl,
7322                 __attribute__((unused)) void *data)
7323 {
7324         struct cmd_mac_addr_result *res = parsed_result;
7325         int ret;
7326
7327         if (strcmp(res->what, "add") == 0)
7328                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7329         else if (strcmp(res->what, "set") == 0)
7330                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7331                                                        &res->address);
7332         else
7333                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7334
7335         /* check the return value and print it if is < 0 */
7336         if(ret < 0)
7337                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7338
7339 }
7340
7341 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7342         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7343                                 "mac_addr");
7344 cmdline_parse_token_string_t cmd_mac_addr_what =
7345         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7346                                 "add#remove#set");
7347 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7348                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7349                                         UINT16);
7350 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7351                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7352
7353 cmdline_parse_inst_t cmd_mac_addr = {
7354         .f = cmd_mac_addr_parsed,
7355         .data = (void *)0,
7356         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7357                         "Add/Remove/Set MAC address on port_id",
7358         .tokens = {
7359                 (void *)&cmd_mac_addr_cmd,
7360                 (void *)&cmd_mac_addr_what,
7361                 (void *)&cmd_mac_addr_portnum,
7362                 (void *)&cmd_mac_addr_addr,
7363                 NULL,
7364         },
7365 };
7366
7367 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7368 struct cmd_eth_peer_result {
7369         cmdline_fixed_string_t set;
7370         cmdline_fixed_string_t eth_peer;
7371         portid_t port_id;
7372         cmdline_fixed_string_t peer_addr;
7373 };
7374
7375 static void cmd_set_eth_peer_parsed(void *parsed_result,
7376                         __attribute__((unused)) struct cmdline *cl,
7377                         __attribute__((unused)) void *data)
7378 {
7379                 struct cmd_eth_peer_result *res = parsed_result;
7380
7381                 if (test_done == 0) {
7382                         printf("Please stop forwarding first\n");
7383                         return;
7384                 }
7385                 if (!strcmp(res->eth_peer, "eth-peer")) {
7386                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7387                         fwd_config_setup();
7388                 }
7389 }
7390 cmdline_parse_token_string_t cmd_eth_peer_set =
7391         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7392 cmdline_parse_token_string_t cmd_eth_peer =
7393         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7394 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7395         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7396 cmdline_parse_token_string_t cmd_eth_peer_addr =
7397         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7398
7399 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7400         .f = cmd_set_eth_peer_parsed,
7401         .data = NULL,
7402         .help_str = "set eth-peer <port_id> <peer_mac>",
7403         .tokens = {
7404                 (void *)&cmd_eth_peer_set,
7405                 (void *)&cmd_eth_peer,
7406                 (void *)&cmd_eth_peer_port_id,
7407                 (void *)&cmd_eth_peer_addr,
7408                 NULL,
7409         },
7410 };
7411
7412 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7413 struct cmd_set_qmap_result {
7414         cmdline_fixed_string_t set;
7415         cmdline_fixed_string_t qmap;
7416         cmdline_fixed_string_t what;
7417         portid_t port_id;
7418         uint16_t queue_id;
7419         uint8_t map_value;
7420 };
7421
7422 static void
7423 cmd_set_qmap_parsed(void *parsed_result,
7424                        __attribute__((unused)) struct cmdline *cl,
7425                        __attribute__((unused)) void *data)
7426 {
7427         struct cmd_set_qmap_result *res = parsed_result;
7428         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7429
7430         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7431 }
7432
7433 cmdline_parse_token_string_t cmd_setqmap_set =
7434         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7435                                  set, "set");
7436 cmdline_parse_token_string_t cmd_setqmap_qmap =
7437         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7438                                  qmap, "stat_qmap");
7439 cmdline_parse_token_string_t cmd_setqmap_what =
7440         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7441                                  what, "tx#rx");
7442 cmdline_parse_token_num_t cmd_setqmap_portid =
7443         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7444                               port_id, UINT16);
7445 cmdline_parse_token_num_t cmd_setqmap_queueid =
7446         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7447                               queue_id, UINT16);
7448 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7449         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7450                               map_value, UINT8);
7451
7452 cmdline_parse_inst_t cmd_set_qmap = {
7453         .f = cmd_set_qmap_parsed,
7454         .data = NULL,
7455         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7456                 "Set statistics mapping value on tx|rx queue_id of port_id",
7457         .tokens = {
7458                 (void *)&cmd_setqmap_set,
7459                 (void *)&cmd_setqmap_qmap,
7460                 (void *)&cmd_setqmap_what,
7461                 (void *)&cmd_setqmap_portid,
7462                 (void *)&cmd_setqmap_queueid,
7463                 (void *)&cmd_setqmap_mapvalue,
7464                 NULL,
7465         },
7466 };
7467
7468 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7469 struct cmd_set_xstats_hide_zero_result {
7470         cmdline_fixed_string_t keyword;
7471         cmdline_fixed_string_t name;
7472         cmdline_fixed_string_t on_off;
7473 };
7474
7475 static void
7476 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7477                         __attribute__((unused)) struct cmdline *cl,
7478                         __attribute__((unused)) void *data)
7479 {
7480         struct cmd_set_xstats_hide_zero_result *res;
7481         uint16_t on_off = 0;
7482
7483         res = parsed_result;
7484         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7485         set_xstats_hide_zero(on_off);
7486 }
7487
7488 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7489         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7490                                  keyword, "set");
7491 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7492         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7493                                  name, "xstats-hide-zero");
7494 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7495         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7496                                  on_off, "on#off");
7497
7498 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7499         .f = cmd_set_xstats_hide_zero_parsed,
7500         .data = NULL,
7501         .help_str = "set xstats-hide-zero on|off",
7502         .tokens = {
7503                 (void *)&cmd_set_xstats_hide_zero_keyword,
7504                 (void *)&cmd_set_xstats_hide_zero_name,
7505                 (void *)&cmd_set_xstats_hide_zero_on_off,
7506                 NULL,
7507         },
7508 };
7509
7510 /* *** CONFIGURE UNICAST HASH TABLE *** */
7511 struct cmd_set_uc_hash_table {
7512         cmdline_fixed_string_t set;
7513         cmdline_fixed_string_t port;
7514         portid_t port_id;
7515         cmdline_fixed_string_t what;
7516         struct ether_addr address;
7517         cmdline_fixed_string_t mode;
7518 };
7519
7520 static void
7521 cmd_set_uc_hash_parsed(void *parsed_result,
7522                        __attribute__((unused)) struct cmdline *cl,
7523                        __attribute__((unused)) void *data)
7524 {
7525         int ret=0;
7526         struct cmd_set_uc_hash_table *res = parsed_result;
7527
7528         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7529
7530         if (strcmp(res->what, "uta") == 0)
7531                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7532                                                 &res->address,(uint8_t)is_on);
7533         if (ret < 0)
7534                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7535
7536 }
7537
7538 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7539         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7540                                  set, "set");
7541 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7542         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7543                                  port, "port");
7544 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7545         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7546                               port_id, UINT16);
7547 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7548         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7549                                  what, "uta");
7550 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7551         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7552                                 address);
7553 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7554         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7555                                  mode, "on#off");
7556
7557 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7558         .f = cmd_set_uc_hash_parsed,
7559         .data = NULL,
7560         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7561         .tokens = {
7562                 (void *)&cmd_set_uc_hash_set,
7563                 (void *)&cmd_set_uc_hash_port,
7564                 (void *)&cmd_set_uc_hash_portid,
7565                 (void *)&cmd_set_uc_hash_what,
7566                 (void *)&cmd_set_uc_hash_mac,
7567                 (void *)&cmd_set_uc_hash_mode,
7568                 NULL,
7569         },
7570 };
7571
7572 struct cmd_set_uc_all_hash_table {
7573         cmdline_fixed_string_t set;
7574         cmdline_fixed_string_t port;
7575         portid_t port_id;
7576         cmdline_fixed_string_t what;
7577         cmdline_fixed_string_t value;
7578         cmdline_fixed_string_t mode;
7579 };
7580
7581 static void
7582 cmd_set_uc_all_hash_parsed(void *parsed_result,
7583                        __attribute__((unused)) struct cmdline *cl,
7584                        __attribute__((unused)) void *data)
7585 {
7586         int ret=0;
7587         struct cmd_set_uc_all_hash_table *res = parsed_result;
7588
7589         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7590
7591         if ((strcmp(res->what, "uta") == 0) &&
7592                 (strcmp(res->value, "all") == 0))
7593                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7594         if (ret < 0)
7595                 printf("bad unicast hash table parameter,"
7596                         "return code = %d \n", ret);
7597 }
7598
7599 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7600         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7601                                  set, "set");
7602 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7603         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7604                                  port, "port");
7605 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7606         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7607                               port_id, UINT16);
7608 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7609         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7610                                  what, "uta");
7611 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7612         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7613                                 value,"all");
7614 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7615         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7616                                  mode, "on#off");
7617
7618 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7619         .f = cmd_set_uc_all_hash_parsed,
7620         .data = NULL,
7621         .help_str = "set port <port_id> uta all on|off",
7622         .tokens = {
7623                 (void *)&cmd_set_uc_all_hash_set,
7624                 (void *)&cmd_set_uc_all_hash_port,
7625                 (void *)&cmd_set_uc_all_hash_portid,
7626                 (void *)&cmd_set_uc_all_hash_what,
7627                 (void *)&cmd_set_uc_all_hash_value,
7628                 (void *)&cmd_set_uc_all_hash_mode,
7629                 NULL,
7630         },
7631 };
7632
7633 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7634 struct cmd_set_vf_macvlan_filter {
7635         cmdline_fixed_string_t set;
7636         cmdline_fixed_string_t port;
7637         portid_t port_id;
7638         cmdline_fixed_string_t vf;
7639         uint8_t vf_id;
7640         struct ether_addr address;
7641         cmdline_fixed_string_t filter_type;
7642         cmdline_fixed_string_t mode;
7643 };
7644
7645 static void
7646 cmd_set_vf_macvlan_parsed(void *parsed_result,
7647                        __attribute__((unused)) struct cmdline *cl,
7648                        __attribute__((unused)) void *data)
7649 {
7650         int is_on, ret = 0;
7651         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7652         struct rte_eth_mac_filter filter;
7653
7654         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7655
7656         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7657
7658         /* set VF MAC filter */
7659         filter.is_vf = 1;
7660
7661         /* set VF ID */
7662         filter.dst_id = res->vf_id;
7663
7664         if (!strcmp(res->filter_type, "exact-mac"))
7665                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7666         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7667                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7668         else if (!strcmp(res->filter_type, "hashmac"))
7669                 filter.filter_type = RTE_MAC_HASH_MATCH;
7670         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7671                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7672
7673         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7674
7675         if (is_on)
7676                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7677                                         RTE_ETH_FILTER_MACVLAN,
7678                                         RTE_ETH_FILTER_ADD,
7679                                          &filter);
7680         else
7681                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7682                                         RTE_ETH_FILTER_MACVLAN,
7683                                         RTE_ETH_FILTER_DELETE,
7684                                         &filter);
7685
7686         if (ret < 0)
7687                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7688
7689 }
7690
7691 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7692         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7693                                  set, "set");
7694 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7695         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7696                                  port, "port");
7697 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7698         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7699                               port_id, UINT16);
7700 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7701         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7702                                  vf, "vf");
7703 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7704         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7705                                 vf_id, UINT8);
7706 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7707         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7708                                 address);
7709 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7710         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7711                                 filter_type, "exact-mac#exact-mac-vlan"
7712                                 "#hashmac#hashmac-vlan");
7713 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7714         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7715                                  mode, "on#off");
7716
7717 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7718         .f = cmd_set_vf_macvlan_parsed,
7719         .data = NULL,
7720         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7721                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7722                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7723                 "hash match rule: hash match of MAC and exact match of VLAN",
7724         .tokens = {
7725                 (void *)&cmd_set_vf_macvlan_set,
7726                 (void *)&cmd_set_vf_macvlan_port,
7727                 (void *)&cmd_set_vf_macvlan_portid,
7728                 (void *)&cmd_set_vf_macvlan_vf,
7729                 (void *)&cmd_set_vf_macvlan_vf_id,
7730                 (void *)&cmd_set_vf_macvlan_mac,
7731                 (void *)&cmd_set_vf_macvlan_filter_type,
7732                 (void *)&cmd_set_vf_macvlan_mode,
7733                 NULL,
7734         },
7735 };
7736
7737 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7738 struct cmd_set_vf_traffic {
7739         cmdline_fixed_string_t set;
7740         cmdline_fixed_string_t port;
7741         portid_t port_id;
7742         cmdline_fixed_string_t vf;
7743         uint8_t vf_id;
7744         cmdline_fixed_string_t what;
7745         cmdline_fixed_string_t mode;
7746 };
7747
7748 static void
7749 cmd_set_vf_traffic_parsed(void *parsed_result,
7750                        __attribute__((unused)) struct cmdline *cl,
7751                        __attribute__((unused)) void *data)
7752 {
7753         struct cmd_set_vf_traffic *res = parsed_result;
7754         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7755         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7756
7757         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7758 }
7759
7760 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7761         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7762                                  set, "set");
7763 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7764         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7765                                  port, "port");
7766 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7767         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7768                               port_id, UINT16);
7769 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7770         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7771                                  vf, "vf");
7772 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7773         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7774                               vf_id, UINT8);
7775 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7776         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7777                                  what, "tx#rx");
7778 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7779         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7780                                  mode, "on#off");
7781
7782 cmdline_parse_inst_t cmd_set_vf_traffic = {
7783         .f = cmd_set_vf_traffic_parsed,
7784         .data = NULL,
7785         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7786         .tokens = {
7787                 (void *)&cmd_setvf_traffic_set,
7788                 (void *)&cmd_setvf_traffic_port,
7789                 (void *)&cmd_setvf_traffic_portid,
7790                 (void *)&cmd_setvf_traffic_vf,
7791                 (void *)&cmd_setvf_traffic_vfid,
7792                 (void *)&cmd_setvf_traffic_what,
7793                 (void *)&cmd_setvf_traffic_mode,
7794                 NULL,
7795         },
7796 };
7797
7798 /* *** CONFIGURE VF RECEIVE MODE *** */
7799 struct cmd_set_vf_rxmode {
7800         cmdline_fixed_string_t set;
7801         cmdline_fixed_string_t port;
7802         portid_t port_id;
7803         cmdline_fixed_string_t vf;
7804         uint8_t vf_id;
7805         cmdline_fixed_string_t what;
7806         cmdline_fixed_string_t mode;
7807         cmdline_fixed_string_t on;
7808 };
7809
7810 static void
7811 cmd_set_vf_rxmode_parsed(void *parsed_result,
7812                        __attribute__((unused)) struct cmdline *cl,
7813                        __attribute__((unused)) void *data)
7814 {
7815         int ret = -ENOTSUP;
7816         uint16_t rx_mode = 0;
7817         struct cmd_set_vf_rxmode *res = parsed_result;
7818
7819         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7820         if (!strcmp(res->what,"rxmode")) {
7821                 if (!strcmp(res->mode, "AUPE"))
7822                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7823                 else if (!strcmp(res->mode, "ROPE"))
7824                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7825                 else if (!strcmp(res->mode, "BAM"))
7826                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7827                 else if (!strncmp(res->mode, "MPE",3))
7828                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7829         }
7830
7831         RTE_SET_USED(is_on);
7832
7833 #ifdef RTE_LIBRTE_IXGBE_PMD
7834         if (ret == -ENOTSUP)
7835                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7836                                                   rx_mode, (uint8_t)is_on);
7837 #endif
7838 #ifdef RTE_LIBRTE_BNXT_PMD
7839         if (ret == -ENOTSUP)
7840                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7841                                                  rx_mode, (uint8_t)is_on);
7842 #endif
7843         if (ret < 0)
7844                 printf("bad VF receive mode parameter, return code = %d \n",
7845                 ret);
7846 }
7847
7848 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7849         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7850                                  set, "set");
7851 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7852         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7853                                  port, "port");
7854 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7855         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7856                               port_id, UINT16);
7857 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7858         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7859                                  vf, "vf");
7860 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7861         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7862                               vf_id, UINT8);
7863 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7864         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7865                                  what, "rxmode");
7866 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7867         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7868                                  mode, "AUPE#ROPE#BAM#MPE");
7869 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7870         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7871                                  on, "on#off");
7872
7873 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7874         .f = cmd_set_vf_rxmode_parsed,
7875         .data = NULL,
7876         .help_str = "set port <port_id> vf <vf_id> rxmode "
7877                 "AUPE|ROPE|BAM|MPE on|off",
7878         .tokens = {
7879                 (void *)&cmd_set_vf_rxmode_set,
7880                 (void *)&cmd_set_vf_rxmode_port,
7881                 (void *)&cmd_set_vf_rxmode_portid,
7882                 (void *)&cmd_set_vf_rxmode_vf,
7883                 (void *)&cmd_set_vf_rxmode_vfid,
7884                 (void *)&cmd_set_vf_rxmode_what,
7885                 (void *)&cmd_set_vf_rxmode_mode,
7886                 (void *)&cmd_set_vf_rxmode_on,
7887                 NULL,
7888         },
7889 };
7890
7891 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7892 struct cmd_vf_mac_addr_result {
7893         cmdline_fixed_string_t mac_addr_cmd;
7894         cmdline_fixed_string_t what;
7895         cmdline_fixed_string_t port;
7896         uint16_t port_num;
7897         cmdline_fixed_string_t vf;
7898         uint8_t vf_num;
7899         struct ether_addr address;
7900 };
7901
7902 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7903                 __attribute__((unused)) struct cmdline *cl,
7904                 __attribute__((unused)) void *data)
7905 {
7906         struct cmd_vf_mac_addr_result *res = parsed_result;
7907         int ret = -ENOTSUP;
7908
7909         if (strcmp(res->what, "add") != 0)
7910                 return;
7911
7912 #ifdef RTE_LIBRTE_I40E_PMD
7913         if (ret == -ENOTSUP)
7914                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7915                                                    &res->address);
7916 #endif
7917 #ifdef RTE_LIBRTE_BNXT_PMD
7918         if (ret == -ENOTSUP)
7919                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7920                                                 res->vf_num);
7921 #endif
7922
7923         if(ret < 0)
7924                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7925
7926 }
7927
7928 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7929         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7930                                 mac_addr_cmd,"mac_addr");
7931 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7932         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7933                                 what,"add");
7934 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7935         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7936                                 port,"port");
7937 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7938         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7939                                 port_num, UINT16);
7940 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7941         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7942                                 vf,"vf");
7943 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7944         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7945                                 vf_num, UINT8);
7946 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7947         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7948                                 address);
7949
7950 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7951         .f = cmd_vf_mac_addr_parsed,
7952         .data = (void *)0,
7953         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7954                 "Add MAC address filtering for a VF on port_id",
7955         .tokens = {
7956                 (void *)&cmd_vf_mac_addr_cmd,
7957                 (void *)&cmd_vf_mac_addr_what,
7958                 (void *)&cmd_vf_mac_addr_port,
7959                 (void *)&cmd_vf_mac_addr_portnum,
7960                 (void *)&cmd_vf_mac_addr_vf,
7961                 (void *)&cmd_vf_mac_addr_vfnum,
7962                 (void *)&cmd_vf_mac_addr_addr,
7963                 NULL,
7964         },
7965 };
7966
7967 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7968 struct cmd_vf_rx_vlan_filter {
7969         cmdline_fixed_string_t rx_vlan;
7970         cmdline_fixed_string_t what;
7971         uint16_t vlan_id;
7972         cmdline_fixed_string_t port;
7973         portid_t port_id;
7974         cmdline_fixed_string_t vf;
7975         uint64_t vf_mask;
7976 };
7977
7978 static void
7979 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7980                           __attribute__((unused)) struct cmdline *cl,
7981                           __attribute__((unused)) void *data)
7982 {
7983         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7984         int ret = -ENOTSUP;
7985
7986         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7987
7988 #ifdef RTE_LIBRTE_IXGBE_PMD
7989         if (ret == -ENOTSUP)
7990                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7991                                 res->vlan_id, res->vf_mask, is_add);
7992 #endif
7993 #ifdef RTE_LIBRTE_I40E_PMD
7994         if (ret == -ENOTSUP)
7995                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7996                                 res->vlan_id, res->vf_mask, is_add);
7997 #endif
7998 #ifdef RTE_LIBRTE_BNXT_PMD
7999         if (ret == -ENOTSUP)
8000                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8001                                 res->vlan_id, res->vf_mask, is_add);
8002 #endif
8003
8004         switch (ret) {
8005         case 0:
8006                 break;
8007         case -EINVAL:
8008                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8009                                 res->vlan_id, res->vf_mask);
8010                 break;
8011         case -ENODEV:
8012                 printf("invalid port_id %d\n", res->port_id);
8013                 break;
8014         case -ENOTSUP:
8015                 printf("function not implemented or supported\n");
8016                 break;
8017         default:
8018                 printf("programming error: (%s)\n", strerror(-ret));
8019         }
8020 }
8021
8022 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8023         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8024                                  rx_vlan, "rx_vlan");
8025 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8026         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8027                                  what, "add#rm");
8028 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8029         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8030                               vlan_id, UINT16);
8031 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8032         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8033                                  port, "port");
8034 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8035         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8036                               port_id, UINT16);
8037 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8038         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8039                                  vf, "vf");
8040 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8041         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8042                               vf_mask, UINT64);
8043
8044 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8045         .f = cmd_vf_rx_vlan_filter_parsed,
8046         .data = NULL,
8047         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8048                 "(vf_mask = hexadecimal VF mask)",
8049         .tokens = {
8050                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8051                 (void *)&cmd_vf_rx_vlan_filter_what,
8052                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8053                 (void *)&cmd_vf_rx_vlan_filter_port,
8054                 (void *)&cmd_vf_rx_vlan_filter_portid,
8055                 (void *)&cmd_vf_rx_vlan_filter_vf,
8056                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8057                 NULL,
8058         },
8059 };
8060
8061 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8062 struct cmd_queue_rate_limit_result {
8063         cmdline_fixed_string_t set;
8064         cmdline_fixed_string_t port;
8065         uint16_t port_num;
8066         cmdline_fixed_string_t queue;
8067         uint8_t queue_num;
8068         cmdline_fixed_string_t rate;
8069         uint16_t rate_num;
8070 };
8071
8072 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8073                 __attribute__((unused)) struct cmdline *cl,
8074                 __attribute__((unused)) void *data)
8075 {
8076         struct cmd_queue_rate_limit_result *res = parsed_result;
8077         int ret = 0;
8078
8079         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8080                 && (strcmp(res->queue, "queue") == 0)
8081                 && (strcmp(res->rate, "rate") == 0))
8082                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8083                                         res->rate_num);
8084         if (ret < 0)
8085                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8086
8087 }
8088
8089 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8090         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8091                                 set, "set");
8092 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8093         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8094                                 port, "port");
8095 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8096         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8097                                 port_num, UINT16);
8098 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8099         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8100                                 queue, "queue");
8101 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8102         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8103                                 queue_num, UINT8);
8104 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8105         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8106                                 rate, "rate");
8107 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8108         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8109                                 rate_num, UINT16);
8110
8111 cmdline_parse_inst_t cmd_queue_rate_limit = {
8112         .f = cmd_queue_rate_limit_parsed,
8113         .data = (void *)0,
8114         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8115                 "Set rate limit for a queue on port_id",
8116         .tokens = {
8117                 (void *)&cmd_queue_rate_limit_set,
8118                 (void *)&cmd_queue_rate_limit_port,
8119                 (void *)&cmd_queue_rate_limit_portnum,
8120                 (void *)&cmd_queue_rate_limit_queue,
8121                 (void *)&cmd_queue_rate_limit_queuenum,
8122                 (void *)&cmd_queue_rate_limit_rate,
8123                 (void *)&cmd_queue_rate_limit_ratenum,
8124                 NULL,
8125         },
8126 };
8127
8128 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8129 struct cmd_vf_rate_limit_result {
8130         cmdline_fixed_string_t set;
8131         cmdline_fixed_string_t port;
8132         uint16_t port_num;
8133         cmdline_fixed_string_t vf;
8134         uint8_t vf_num;
8135         cmdline_fixed_string_t rate;
8136         uint16_t rate_num;
8137         cmdline_fixed_string_t q_msk;
8138         uint64_t q_msk_val;
8139 };
8140
8141 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8142                 __attribute__((unused)) struct cmdline *cl,
8143                 __attribute__((unused)) void *data)
8144 {
8145         struct cmd_vf_rate_limit_result *res = parsed_result;
8146         int ret = 0;
8147
8148         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8149                 && (strcmp(res->vf, "vf") == 0)
8150                 && (strcmp(res->rate, "rate") == 0)
8151                 && (strcmp(res->q_msk, "queue_mask") == 0))
8152                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8153                                         res->rate_num, res->q_msk_val);
8154         if (ret < 0)
8155                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8156
8157 }
8158
8159 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8160         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8161                                 set, "set");
8162 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8163         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8164                                 port, "port");
8165 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8166         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8167                                 port_num, UINT16);
8168 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8169         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8170                                 vf, "vf");
8171 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8172         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8173                                 vf_num, UINT8);
8174 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8175         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8176                                 rate, "rate");
8177 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8178         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8179                                 rate_num, UINT16);
8180 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8181         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8182                                 q_msk, "queue_mask");
8183 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8184         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8185                                 q_msk_val, UINT64);
8186
8187 cmdline_parse_inst_t cmd_vf_rate_limit = {
8188         .f = cmd_vf_rate_limit_parsed,
8189         .data = (void *)0,
8190         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8191                 "queue_mask <queue_mask_value>: "
8192                 "Set rate limit for queues of VF on port_id",
8193         .tokens = {
8194                 (void *)&cmd_vf_rate_limit_set,
8195                 (void *)&cmd_vf_rate_limit_port,
8196                 (void *)&cmd_vf_rate_limit_portnum,
8197                 (void *)&cmd_vf_rate_limit_vf,
8198                 (void *)&cmd_vf_rate_limit_vfnum,
8199                 (void *)&cmd_vf_rate_limit_rate,
8200                 (void *)&cmd_vf_rate_limit_ratenum,
8201                 (void *)&cmd_vf_rate_limit_q_msk,
8202                 (void *)&cmd_vf_rate_limit_q_msk_val,
8203                 NULL,
8204         },
8205 };
8206
8207 /* *** ADD TUNNEL FILTER OF A PORT *** */
8208 struct cmd_tunnel_filter_result {
8209         cmdline_fixed_string_t cmd;
8210         cmdline_fixed_string_t what;
8211         portid_t port_id;
8212         struct ether_addr outer_mac;
8213         struct ether_addr inner_mac;
8214         cmdline_ipaddr_t ip_value;
8215         uint16_t inner_vlan;
8216         cmdline_fixed_string_t tunnel_type;
8217         cmdline_fixed_string_t filter_type;
8218         uint32_t tenant_id;
8219         uint16_t queue_num;
8220 };
8221
8222 static void
8223 cmd_tunnel_filter_parsed(void *parsed_result,
8224                           __attribute__((unused)) struct cmdline *cl,
8225                           __attribute__((unused)) void *data)
8226 {
8227         struct cmd_tunnel_filter_result *res = parsed_result;
8228         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8229         int ret = 0;
8230
8231         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8232
8233         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8234         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8235         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8236
8237         if (res->ip_value.family == AF_INET) {
8238                 tunnel_filter_conf.ip_addr.ipv4_addr =
8239                         res->ip_value.addr.ipv4.s_addr;
8240                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8241         } else {
8242                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8243                         &(res->ip_value.addr.ipv6),
8244                         sizeof(struct in6_addr));
8245                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8246         }
8247
8248         if (!strcmp(res->filter_type, "imac-ivlan"))
8249                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8250         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8251                 tunnel_filter_conf.filter_type =
8252                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8253         else if (!strcmp(res->filter_type, "imac-tenid"))
8254                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8255         else if (!strcmp(res->filter_type, "imac"))
8256                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8257         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8258                 tunnel_filter_conf.filter_type =
8259                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8260         else if (!strcmp(res->filter_type, "oip"))
8261                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8262         else if (!strcmp(res->filter_type, "iip"))
8263                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8264         else {
8265                 printf("The filter type is not supported");
8266                 return;
8267         }
8268
8269         if (!strcmp(res->tunnel_type, "vxlan"))
8270                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8271         else if (!strcmp(res->tunnel_type, "nvgre"))
8272                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8273         else if (!strcmp(res->tunnel_type, "ipingre"))
8274                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8275         else {
8276                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8277                 return;
8278         }
8279
8280         tunnel_filter_conf.tenant_id = res->tenant_id;
8281         tunnel_filter_conf.queue_id = res->queue_num;
8282         if (!strcmp(res->what, "add"))
8283                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8284                                         RTE_ETH_FILTER_TUNNEL,
8285                                         RTE_ETH_FILTER_ADD,
8286                                         &tunnel_filter_conf);
8287         else
8288                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8289                                         RTE_ETH_FILTER_TUNNEL,
8290                                         RTE_ETH_FILTER_DELETE,
8291                                         &tunnel_filter_conf);
8292         if (ret < 0)
8293                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8294                                 strerror(-ret));
8295
8296 }
8297 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8298         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8299         cmd, "tunnel_filter");
8300 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8301         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8302         what, "add#rm");
8303 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8304         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8305         port_id, UINT16);
8306 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8307         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8308         outer_mac);
8309 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8310         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8311         inner_mac);
8312 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8313         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8314         inner_vlan, UINT16);
8315 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8316         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8317         ip_value);
8318 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8319         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8320         tunnel_type, "vxlan#nvgre#ipingre");
8321
8322 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8323         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8324         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8325                 "imac#omac-imac-tenid");
8326 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8327         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8328         tenant_id, UINT32);
8329 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8330         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8331         queue_num, UINT16);
8332
8333 cmdline_parse_inst_t cmd_tunnel_filter = {
8334         .f = cmd_tunnel_filter_parsed,
8335         .data = (void *)0,
8336         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8337                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8338                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8339                 "<queue_id>: Add/Rm tunnel filter of a port",
8340         .tokens = {
8341                 (void *)&cmd_tunnel_filter_cmd,
8342                 (void *)&cmd_tunnel_filter_what,
8343                 (void *)&cmd_tunnel_filter_port_id,
8344                 (void *)&cmd_tunnel_filter_outer_mac,
8345                 (void *)&cmd_tunnel_filter_inner_mac,
8346                 (void *)&cmd_tunnel_filter_ip_value,
8347                 (void *)&cmd_tunnel_filter_innner_vlan,
8348                 (void *)&cmd_tunnel_filter_tunnel_type,
8349                 (void *)&cmd_tunnel_filter_filter_type,
8350                 (void *)&cmd_tunnel_filter_tenant_id,
8351                 (void *)&cmd_tunnel_filter_queue_num,
8352                 NULL,
8353         },
8354 };
8355
8356 /* *** CONFIGURE TUNNEL UDP PORT *** */
8357 struct cmd_tunnel_udp_config {
8358         cmdline_fixed_string_t cmd;
8359         cmdline_fixed_string_t what;
8360         uint16_t udp_port;
8361         portid_t port_id;
8362 };
8363
8364 static void
8365 cmd_tunnel_udp_config_parsed(void *parsed_result,
8366                           __attribute__((unused)) struct cmdline *cl,
8367                           __attribute__((unused)) void *data)
8368 {
8369         struct cmd_tunnel_udp_config *res = parsed_result;
8370         struct rte_eth_udp_tunnel tunnel_udp;
8371         int ret;
8372
8373         tunnel_udp.udp_port = res->udp_port;
8374
8375         if (!strcmp(res->cmd, "rx_vxlan_port"))
8376                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8377
8378         if (!strcmp(res->what, "add"))
8379                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8380                                                       &tunnel_udp);
8381         else
8382                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8383                                                          &tunnel_udp);
8384
8385         if (ret < 0)
8386                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8387 }
8388
8389 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8390         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8391                                 cmd, "rx_vxlan_port");
8392 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8393         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8394                                 what, "add#rm");
8395 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8396         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8397                                 udp_port, UINT16);
8398 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8399         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8400                                 port_id, UINT16);
8401
8402 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8403         .f = cmd_tunnel_udp_config_parsed,
8404         .data = (void *)0,
8405         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8406                 "Add/Remove a tunneling UDP port filter",
8407         .tokens = {
8408                 (void *)&cmd_tunnel_udp_config_cmd,
8409                 (void *)&cmd_tunnel_udp_config_what,
8410                 (void *)&cmd_tunnel_udp_config_udp_port,
8411                 (void *)&cmd_tunnel_udp_config_port_id,
8412                 NULL,
8413         },
8414 };
8415
8416 /* *** GLOBAL CONFIG *** */
8417 struct cmd_global_config_result {
8418         cmdline_fixed_string_t cmd;
8419         portid_t port_id;
8420         cmdline_fixed_string_t cfg_type;
8421         uint8_t len;
8422 };
8423
8424 static void
8425 cmd_global_config_parsed(void *parsed_result,
8426                          __attribute__((unused)) struct cmdline *cl,
8427                          __attribute__((unused)) void *data)
8428 {
8429         struct cmd_global_config_result *res = parsed_result;
8430         struct rte_eth_global_cfg conf;
8431         int ret;
8432
8433         memset(&conf, 0, sizeof(conf));
8434         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8435         conf.cfg.gre_key_len = res->len;
8436         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8437                                       RTE_ETH_FILTER_SET, &conf);
8438         if (ret != 0)
8439                 printf("Global config error\n");
8440 }
8441
8442 cmdline_parse_token_string_t cmd_global_config_cmd =
8443         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8444                 "global_config");
8445 cmdline_parse_token_num_t cmd_global_config_port_id =
8446         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8447                                UINT16);
8448 cmdline_parse_token_string_t cmd_global_config_type =
8449         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8450                 cfg_type, "gre-key-len");
8451 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8452         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8453                 len, UINT8);
8454
8455 cmdline_parse_inst_t cmd_global_config = {
8456         .f = cmd_global_config_parsed,
8457         .data = (void *)NULL,
8458         .help_str = "global_config <port_id> gre-key-len <key_len>",
8459         .tokens = {
8460                 (void *)&cmd_global_config_cmd,
8461                 (void *)&cmd_global_config_port_id,
8462                 (void *)&cmd_global_config_type,
8463                 (void *)&cmd_global_config_gre_key_len,
8464                 NULL,
8465         },
8466 };
8467
8468 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8469 struct cmd_set_mirror_mask_result {
8470         cmdline_fixed_string_t set;
8471         cmdline_fixed_string_t port;
8472         portid_t port_id;
8473         cmdline_fixed_string_t mirror;
8474         uint8_t rule_id;
8475         cmdline_fixed_string_t what;
8476         cmdline_fixed_string_t value;
8477         cmdline_fixed_string_t dstpool;
8478         uint8_t dstpool_id;
8479         cmdline_fixed_string_t on;
8480 };
8481
8482 cmdline_parse_token_string_t cmd_mirror_mask_set =
8483         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8484                                 set, "set");
8485 cmdline_parse_token_string_t cmd_mirror_mask_port =
8486         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8487                                 port, "port");
8488 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8489         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8490                                 port_id, UINT16);
8491 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8492         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8493                                 mirror, "mirror-rule");
8494 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8495         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8496                                 rule_id, UINT8);
8497 cmdline_parse_token_string_t cmd_mirror_mask_what =
8498         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8499                                 what, "pool-mirror-up#pool-mirror-down"
8500                                       "#vlan-mirror");
8501 cmdline_parse_token_string_t cmd_mirror_mask_value =
8502         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8503                                 value, NULL);
8504 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8505         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8506                                 dstpool, "dst-pool");
8507 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8508         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8509                                 dstpool_id, UINT8);
8510 cmdline_parse_token_string_t cmd_mirror_mask_on =
8511         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8512                                 on, "on#off");
8513
8514 static void
8515 cmd_set_mirror_mask_parsed(void *parsed_result,
8516                        __attribute__((unused)) struct cmdline *cl,
8517                        __attribute__((unused)) void *data)
8518 {
8519         int ret,nb_item,i;
8520         struct cmd_set_mirror_mask_result *res = parsed_result;
8521         struct rte_eth_mirror_conf mr_conf;
8522
8523         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8524
8525         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8526
8527         mr_conf.dst_pool = res->dstpool_id;
8528
8529         if (!strcmp(res->what, "pool-mirror-up")) {
8530                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8531                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8532         } else if (!strcmp(res->what, "pool-mirror-down")) {
8533                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8534                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8535         } else if (!strcmp(res->what, "vlan-mirror")) {
8536                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8537                 nb_item = parse_item_list(res->value, "vlan",
8538                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8539                 if (nb_item <= 0)
8540                         return;
8541
8542                 for (i = 0; i < nb_item; i++) {
8543                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8544                                 printf("Invalid vlan_id: must be < 4096\n");
8545                                 return;
8546                         }
8547
8548                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8549                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8550                 }
8551         }
8552
8553         if (!strcmp(res->on, "on"))
8554                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8555                                                 res->rule_id, 1);
8556         else
8557                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8558                                                 res->rule_id, 0);
8559         if (ret < 0)
8560                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8561 }
8562
8563 cmdline_parse_inst_t cmd_set_mirror_mask = {
8564                 .f = cmd_set_mirror_mask_parsed,
8565                 .data = NULL,
8566                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8567                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8568                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8569                 .tokens = {
8570                         (void *)&cmd_mirror_mask_set,
8571                         (void *)&cmd_mirror_mask_port,
8572                         (void *)&cmd_mirror_mask_portid,
8573                         (void *)&cmd_mirror_mask_mirror,
8574                         (void *)&cmd_mirror_mask_ruleid,
8575                         (void *)&cmd_mirror_mask_what,
8576                         (void *)&cmd_mirror_mask_value,
8577                         (void *)&cmd_mirror_mask_dstpool,
8578                         (void *)&cmd_mirror_mask_poolid,
8579                         (void *)&cmd_mirror_mask_on,
8580                         NULL,
8581                 },
8582 };
8583
8584 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8585 struct cmd_set_mirror_link_result {
8586         cmdline_fixed_string_t set;
8587         cmdline_fixed_string_t port;
8588         portid_t port_id;
8589         cmdline_fixed_string_t mirror;
8590         uint8_t rule_id;
8591         cmdline_fixed_string_t what;
8592         cmdline_fixed_string_t dstpool;
8593         uint8_t dstpool_id;
8594         cmdline_fixed_string_t on;
8595 };
8596
8597 cmdline_parse_token_string_t cmd_mirror_link_set =
8598         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8599                                  set, "set");
8600 cmdline_parse_token_string_t cmd_mirror_link_port =
8601         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8602                                 port, "port");
8603 cmdline_parse_token_num_t cmd_mirror_link_portid =
8604         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8605                                 port_id, UINT16);
8606 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8607         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8608                                 mirror, "mirror-rule");
8609 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8610         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8611                             rule_id, UINT8);
8612 cmdline_parse_token_string_t cmd_mirror_link_what =
8613         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8614                                 what, "uplink-mirror#downlink-mirror");
8615 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8616         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8617                                 dstpool, "dst-pool");
8618 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8619         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8620                                 dstpool_id, UINT8);
8621 cmdline_parse_token_string_t cmd_mirror_link_on =
8622         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8623                                 on, "on#off");
8624
8625 static void
8626 cmd_set_mirror_link_parsed(void *parsed_result,
8627                        __attribute__((unused)) struct cmdline *cl,
8628                        __attribute__((unused)) void *data)
8629 {
8630         int ret;
8631         struct cmd_set_mirror_link_result *res = parsed_result;
8632         struct rte_eth_mirror_conf mr_conf;
8633
8634         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8635         if (!strcmp(res->what, "uplink-mirror"))
8636                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8637         else
8638                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8639
8640         mr_conf.dst_pool = res->dstpool_id;
8641
8642         if (!strcmp(res->on, "on"))
8643                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8644                                                 res->rule_id, 1);
8645         else
8646                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8647                                                 res->rule_id, 0);
8648
8649         /* check the return value and print it if is < 0 */
8650         if (ret < 0)
8651                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8652
8653 }
8654
8655 cmdline_parse_inst_t cmd_set_mirror_link = {
8656                 .f = cmd_set_mirror_link_parsed,
8657                 .data = NULL,
8658                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8659                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8660                 .tokens = {
8661                         (void *)&cmd_mirror_link_set,
8662                         (void *)&cmd_mirror_link_port,
8663                         (void *)&cmd_mirror_link_portid,
8664                         (void *)&cmd_mirror_link_mirror,
8665                         (void *)&cmd_mirror_link_ruleid,
8666                         (void *)&cmd_mirror_link_what,
8667                         (void *)&cmd_mirror_link_dstpool,
8668                         (void *)&cmd_mirror_link_poolid,
8669                         (void *)&cmd_mirror_link_on,
8670                         NULL,
8671                 },
8672 };
8673
8674 /* *** RESET VM MIRROR RULE *** */
8675 struct cmd_rm_mirror_rule_result {
8676         cmdline_fixed_string_t reset;
8677         cmdline_fixed_string_t port;
8678         portid_t port_id;
8679         cmdline_fixed_string_t mirror;
8680         uint8_t rule_id;
8681 };
8682
8683 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8684         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8685                                  reset, "reset");
8686 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8687         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8688                                 port, "port");
8689 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8690         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8691                                 port_id, UINT16);
8692 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8693         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8694                                 mirror, "mirror-rule");
8695 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8696         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8697                                 rule_id, UINT8);
8698
8699 static void
8700 cmd_reset_mirror_rule_parsed(void *parsed_result,
8701                        __attribute__((unused)) struct cmdline *cl,
8702                        __attribute__((unused)) void *data)
8703 {
8704         int ret;
8705         struct cmd_set_mirror_link_result *res = parsed_result;
8706         /* check rule_id */
8707         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8708         if(ret < 0)
8709                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8710 }
8711
8712 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8713                 .f = cmd_reset_mirror_rule_parsed,
8714                 .data = NULL,
8715                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8716                 .tokens = {
8717                         (void *)&cmd_rm_mirror_rule_reset,
8718                         (void *)&cmd_rm_mirror_rule_port,
8719                         (void *)&cmd_rm_mirror_rule_portid,
8720                         (void *)&cmd_rm_mirror_rule_mirror,
8721                         (void *)&cmd_rm_mirror_rule_ruleid,
8722                         NULL,
8723                 },
8724 };
8725
8726 /* ******************************************************************************** */
8727
8728 struct cmd_dump_result {
8729         cmdline_fixed_string_t dump;
8730 };
8731
8732 static void
8733 dump_struct_sizes(void)
8734 {
8735 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8736         DUMP_SIZE(struct rte_mbuf);
8737         DUMP_SIZE(struct rte_mempool);
8738         DUMP_SIZE(struct rte_ring);
8739 #undef DUMP_SIZE
8740 }
8741
8742 static void cmd_dump_parsed(void *parsed_result,
8743                             __attribute__((unused)) struct cmdline *cl,
8744                             __attribute__((unused)) void *data)
8745 {
8746         struct cmd_dump_result *res = parsed_result;
8747
8748         if (!strcmp(res->dump, "dump_physmem"))
8749                 rte_dump_physmem_layout(stdout);
8750         else if (!strcmp(res->dump, "dump_memzone"))
8751                 rte_memzone_dump(stdout);
8752         else if (!strcmp(res->dump, "dump_struct_sizes"))
8753                 dump_struct_sizes();
8754         else if (!strcmp(res->dump, "dump_ring"))
8755                 rte_ring_list_dump(stdout);
8756         else if (!strcmp(res->dump, "dump_mempool"))
8757                 rte_mempool_list_dump(stdout);
8758         else if (!strcmp(res->dump, "dump_devargs"))
8759                 rte_devargs_dump(stdout);
8760         else if (!strcmp(res->dump, "dump_log_types"))
8761                 rte_log_dump(stdout);
8762 }
8763
8764 cmdline_parse_token_string_t cmd_dump_dump =
8765         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8766                 "dump_physmem#"
8767                 "dump_memzone#"
8768                 "dump_struct_sizes#"
8769                 "dump_ring#"
8770                 "dump_mempool#"
8771                 "dump_devargs#"
8772                 "dump_log_types");
8773
8774 cmdline_parse_inst_t cmd_dump = {
8775         .f = cmd_dump_parsed,  /* function to call */
8776         .data = NULL,      /* 2nd arg of func */
8777         .help_str = "Dump status",
8778         .tokens = {        /* token list, NULL terminated */
8779                 (void *)&cmd_dump_dump,
8780                 NULL,
8781         },
8782 };
8783
8784 /* ******************************************************************************** */
8785
8786 struct cmd_dump_one_result {
8787         cmdline_fixed_string_t dump;
8788         cmdline_fixed_string_t name;
8789 };
8790
8791 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8792                                 __attribute__((unused)) void *data)
8793 {
8794         struct cmd_dump_one_result *res = parsed_result;
8795
8796         if (!strcmp(res->dump, "dump_ring")) {
8797                 struct rte_ring *r;
8798                 r = rte_ring_lookup(res->name);
8799                 if (r == NULL) {
8800                         cmdline_printf(cl, "Cannot find ring\n");
8801                         return;
8802                 }
8803                 rte_ring_dump(stdout, r);
8804         } else if (!strcmp(res->dump, "dump_mempool")) {
8805                 struct rte_mempool *mp;
8806                 mp = rte_mempool_lookup(res->name);
8807                 if (mp == NULL) {
8808                         cmdline_printf(cl, "Cannot find mempool\n");
8809                         return;
8810                 }
8811                 rte_mempool_dump(stdout, mp);
8812         }
8813 }
8814
8815 cmdline_parse_token_string_t cmd_dump_one_dump =
8816         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8817                                  "dump_ring#dump_mempool");
8818
8819 cmdline_parse_token_string_t cmd_dump_one_name =
8820         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8821
8822 cmdline_parse_inst_t cmd_dump_one = {
8823         .f = cmd_dump_one_parsed,  /* function to call */
8824         .data = NULL,      /* 2nd arg of func */
8825         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8826         .tokens = {        /* token list, NULL terminated */
8827                 (void *)&cmd_dump_one_dump,
8828                 (void *)&cmd_dump_one_name,
8829                 NULL,
8830         },
8831 };
8832
8833 /* *** Add/Del syn filter *** */
8834 struct cmd_syn_filter_result {
8835         cmdline_fixed_string_t filter;
8836         portid_t port_id;
8837         cmdline_fixed_string_t ops;
8838         cmdline_fixed_string_t priority;
8839         cmdline_fixed_string_t high;
8840         cmdline_fixed_string_t queue;
8841         uint16_t queue_id;
8842 };
8843
8844 static void
8845 cmd_syn_filter_parsed(void *parsed_result,
8846                         __attribute__((unused)) struct cmdline *cl,
8847                         __attribute__((unused)) void *data)
8848 {
8849         struct cmd_syn_filter_result *res = parsed_result;
8850         struct rte_eth_syn_filter syn_filter;
8851         int ret = 0;
8852
8853         ret = rte_eth_dev_filter_supported(res->port_id,
8854                                         RTE_ETH_FILTER_SYN);
8855         if (ret < 0) {
8856                 printf("syn filter is not supported on port %u.\n",
8857                                 res->port_id);
8858                 return;
8859         }
8860
8861         memset(&syn_filter, 0, sizeof(syn_filter));
8862
8863         if (!strcmp(res->ops, "add")) {
8864                 if (!strcmp(res->high, "high"))
8865                         syn_filter.hig_pri = 1;
8866                 else
8867                         syn_filter.hig_pri = 0;
8868
8869                 syn_filter.queue = res->queue_id;
8870                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8871                                                 RTE_ETH_FILTER_SYN,
8872                                                 RTE_ETH_FILTER_ADD,
8873                                                 &syn_filter);
8874         } else
8875                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8876                                                 RTE_ETH_FILTER_SYN,
8877                                                 RTE_ETH_FILTER_DELETE,
8878                                                 &syn_filter);
8879
8880         if (ret < 0)
8881                 printf("syn filter programming error: (%s)\n",
8882                                 strerror(-ret));
8883 }
8884
8885 cmdline_parse_token_string_t cmd_syn_filter_filter =
8886         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8887         filter, "syn_filter");
8888 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8889         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8890         port_id, UINT16);
8891 cmdline_parse_token_string_t cmd_syn_filter_ops =
8892         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8893         ops, "add#del");
8894 cmdline_parse_token_string_t cmd_syn_filter_priority =
8895         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8896                                 priority, "priority");
8897 cmdline_parse_token_string_t cmd_syn_filter_high =
8898         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8899                                 high, "high#low");
8900 cmdline_parse_token_string_t cmd_syn_filter_queue =
8901         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8902                                 queue, "queue");
8903 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8904         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8905                                 queue_id, UINT16);
8906
8907 cmdline_parse_inst_t cmd_syn_filter = {
8908         .f = cmd_syn_filter_parsed,
8909         .data = NULL,
8910         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8911                 "<queue_id>: Add/Delete syn filter",
8912         .tokens = {
8913                 (void *)&cmd_syn_filter_filter,
8914                 (void *)&cmd_syn_filter_port_id,
8915                 (void *)&cmd_syn_filter_ops,
8916                 (void *)&cmd_syn_filter_priority,
8917                 (void *)&cmd_syn_filter_high,
8918                 (void *)&cmd_syn_filter_queue,
8919                 (void *)&cmd_syn_filter_queue_id,
8920                 NULL,
8921         },
8922 };
8923
8924 /* *** queue region set *** */
8925 struct cmd_queue_region_result {
8926         cmdline_fixed_string_t set;
8927         cmdline_fixed_string_t port;
8928         portid_t port_id;
8929         cmdline_fixed_string_t cmd;
8930         cmdline_fixed_string_t region;
8931         uint8_t  region_id;
8932         cmdline_fixed_string_t queue_start_index;
8933         uint8_t  queue_id;
8934         cmdline_fixed_string_t queue_num;
8935         uint8_t  queue_num_value;
8936 };
8937
8938 static void
8939 cmd_queue_region_parsed(void *parsed_result,
8940                         __attribute__((unused)) struct cmdline *cl,
8941                         __attribute__((unused)) void *data)
8942 {
8943         struct cmd_queue_region_result *res = parsed_result;
8944         int ret = -ENOTSUP;
8945 #ifdef RTE_LIBRTE_I40E_PMD
8946         struct rte_pmd_i40e_queue_region_conf region_conf;
8947         enum rte_pmd_i40e_queue_region_op op_type;
8948 #endif
8949
8950         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8951                 return;
8952
8953 #ifdef RTE_LIBRTE_I40E_PMD
8954         memset(&region_conf, 0, sizeof(region_conf));
8955         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8956         region_conf.region_id = res->region_id;
8957         region_conf.queue_num = res->queue_num_value;
8958         region_conf.queue_start_index = res->queue_id;
8959
8960         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8961                                 op_type, &region_conf);
8962 #endif
8963
8964         switch (ret) {
8965         case 0:
8966                 break;
8967         case -ENOTSUP:
8968                 printf("function not implemented or supported\n");
8969                 break;
8970         default:
8971                 printf("queue region config error: (%s)\n", strerror(-ret));
8972         }
8973 }
8974
8975 cmdline_parse_token_string_t cmd_queue_region_set =
8976 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8977                 set, "set");
8978 cmdline_parse_token_string_t cmd_queue_region_port =
8979         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8980 cmdline_parse_token_num_t cmd_queue_region_port_id =
8981         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8982                                 port_id, UINT16);
8983 cmdline_parse_token_string_t cmd_queue_region_cmd =
8984         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8985                                  cmd, "queue-region");
8986 cmdline_parse_token_string_t cmd_queue_region_id =
8987         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8988                                 region, "region_id");
8989 cmdline_parse_token_num_t cmd_queue_region_index =
8990         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8991                                 region_id, UINT8);
8992 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8993         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8994                                 queue_start_index, "queue_start_index");
8995 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8996         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8997                                 queue_id, UINT8);
8998 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8999         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9000                                 queue_num, "queue_num");
9001 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9002         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9003                                 queue_num_value, UINT8);
9004
9005 cmdline_parse_inst_t cmd_queue_region = {
9006         .f = cmd_queue_region_parsed,
9007         .data = NULL,
9008         .help_str = "set port <port_id> queue-region region_id <value> "
9009                 "queue_start_index <value> queue_num <value>: Set a queue region",
9010         .tokens = {
9011                 (void *)&cmd_queue_region_set,
9012                 (void *)&cmd_queue_region_port,
9013                 (void *)&cmd_queue_region_port_id,
9014                 (void *)&cmd_queue_region_cmd,
9015                 (void *)&cmd_queue_region_id,
9016                 (void *)&cmd_queue_region_index,
9017                 (void *)&cmd_queue_region_queue_start_index,
9018                 (void *)&cmd_queue_region_queue_id,
9019                 (void *)&cmd_queue_region_queue_num,
9020                 (void *)&cmd_queue_region_queue_num_value,
9021                 NULL,
9022         },
9023 };
9024
9025 /* *** queue region and flowtype set *** */
9026 struct cmd_region_flowtype_result {
9027         cmdline_fixed_string_t set;
9028         cmdline_fixed_string_t port;
9029         portid_t port_id;
9030         cmdline_fixed_string_t cmd;
9031         cmdline_fixed_string_t region;
9032         uint8_t  region_id;
9033         cmdline_fixed_string_t flowtype;
9034         uint8_t  flowtype_id;
9035 };
9036
9037 static void
9038 cmd_region_flowtype_parsed(void *parsed_result,
9039                         __attribute__((unused)) struct cmdline *cl,
9040                         __attribute__((unused)) void *data)
9041 {
9042         struct cmd_region_flowtype_result *res = parsed_result;
9043         int ret = -ENOTSUP;
9044 #ifdef RTE_LIBRTE_I40E_PMD
9045         struct rte_pmd_i40e_queue_region_conf region_conf;
9046         enum rte_pmd_i40e_queue_region_op op_type;
9047 #endif
9048
9049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9050                 return;
9051
9052 #ifdef RTE_LIBRTE_I40E_PMD
9053         memset(&region_conf, 0, sizeof(region_conf));
9054
9055         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9056         region_conf.region_id = res->region_id;
9057         region_conf.hw_flowtype = res->flowtype_id;
9058
9059         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9060                         op_type, &region_conf);
9061 #endif
9062
9063         switch (ret) {
9064         case 0:
9065                 break;
9066         case -ENOTSUP:
9067                 printf("function not implemented or supported\n");
9068                 break;
9069         default:
9070                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9071         }
9072 }
9073
9074 cmdline_parse_token_string_t cmd_region_flowtype_set =
9075 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9076                                 set, "set");
9077 cmdline_parse_token_string_t cmd_region_flowtype_port =
9078         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9079                                 port, "port");
9080 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9081         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9082                                 port_id, UINT16);
9083 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9084         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9085                                 cmd, "queue-region");
9086 cmdline_parse_token_string_t cmd_region_flowtype_index =
9087         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9088                                 region, "region_id");
9089 cmdline_parse_token_num_t cmd_region_flowtype_id =
9090         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9091                                 region_id, UINT8);
9092 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9093         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9094                                 flowtype, "flowtype");
9095 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9096         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9097                                 flowtype_id, UINT8);
9098 cmdline_parse_inst_t cmd_region_flowtype = {
9099         .f = cmd_region_flowtype_parsed,
9100         .data = NULL,
9101         .help_str = "set port <port_id> queue-region region_id <value> "
9102                 "flowtype <value>: Set a flowtype region index",
9103         .tokens = {
9104                 (void *)&cmd_region_flowtype_set,
9105                 (void *)&cmd_region_flowtype_port,
9106                 (void *)&cmd_region_flowtype_port_index,
9107                 (void *)&cmd_region_flowtype_cmd,
9108                 (void *)&cmd_region_flowtype_index,
9109                 (void *)&cmd_region_flowtype_id,
9110                 (void *)&cmd_region_flowtype_flow_index,
9111                 (void *)&cmd_region_flowtype_flow_id,
9112                 NULL,
9113         },
9114 };
9115
9116 /* *** User Priority (UP) to queue region (region_id) set *** */
9117 struct cmd_user_priority_region_result {
9118         cmdline_fixed_string_t set;
9119         cmdline_fixed_string_t port;
9120         portid_t port_id;
9121         cmdline_fixed_string_t cmd;
9122         cmdline_fixed_string_t user_priority;
9123         uint8_t  user_priority_id;
9124         cmdline_fixed_string_t region;
9125         uint8_t  region_id;
9126 };
9127
9128 static void
9129 cmd_user_priority_region_parsed(void *parsed_result,
9130                         __attribute__((unused)) struct cmdline *cl,
9131                         __attribute__((unused)) void *data)
9132 {
9133         struct cmd_user_priority_region_result *res = parsed_result;
9134         int ret = -ENOTSUP;
9135 #ifdef RTE_LIBRTE_I40E_PMD
9136         struct rte_pmd_i40e_queue_region_conf region_conf;
9137         enum rte_pmd_i40e_queue_region_op op_type;
9138 #endif
9139
9140         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9141                 return;
9142
9143 #ifdef RTE_LIBRTE_I40E_PMD
9144         memset(&region_conf, 0, sizeof(region_conf));
9145         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9146         region_conf.user_priority = res->user_priority_id;
9147         region_conf.region_id = res->region_id;
9148
9149         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9150                                 op_type, &region_conf);
9151 #endif
9152
9153         switch (ret) {
9154         case 0:
9155                 break;
9156         case -ENOTSUP:
9157                 printf("function not implemented or supported\n");
9158                 break;
9159         default:
9160                 printf("user_priority region config error: (%s)\n",
9161                                 strerror(-ret));
9162         }
9163 }
9164
9165 cmdline_parse_token_string_t cmd_user_priority_region_set =
9166         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9167                                 set, "set");
9168 cmdline_parse_token_string_t cmd_user_priority_region_port =
9169         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9170                                 port, "port");
9171 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9172         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9173                                 port_id, UINT16);
9174 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9175         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9176                                 cmd, "queue-region");
9177 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9178         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9179                                 user_priority, "UP");
9180 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9181         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9182                                 user_priority_id, UINT8);
9183 cmdline_parse_token_string_t cmd_user_priority_region_region =
9184         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9185                                 region, "region_id");
9186 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9187         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9188                                 region_id, UINT8);
9189
9190 cmdline_parse_inst_t cmd_user_priority_region = {
9191         .f = cmd_user_priority_region_parsed,
9192         .data = NULL,
9193         .help_str = "set port <port_id> queue-region UP <value> "
9194                 "region_id <value>: Set the mapping of User Priority (UP) "
9195                 "to queue region (region_id) ",
9196         .tokens = {
9197                 (void *)&cmd_user_priority_region_set,
9198                 (void *)&cmd_user_priority_region_port,
9199                 (void *)&cmd_user_priority_region_port_index,
9200                 (void *)&cmd_user_priority_region_cmd,
9201                 (void *)&cmd_user_priority_region_UP,
9202                 (void *)&cmd_user_priority_region_UP_id,
9203                 (void *)&cmd_user_priority_region_region,
9204                 (void *)&cmd_user_priority_region_region_id,
9205                 NULL,
9206         },
9207 };
9208
9209 /* *** flush all queue region related configuration *** */
9210 struct cmd_flush_queue_region_result {
9211         cmdline_fixed_string_t set;
9212         cmdline_fixed_string_t port;
9213         portid_t port_id;
9214         cmdline_fixed_string_t cmd;
9215         cmdline_fixed_string_t flush;
9216         cmdline_fixed_string_t what;
9217 };
9218
9219 static void
9220 cmd_flush_queue_region_parsed(void *parsed_result,
9221                         __attribute__((unused)) struct cmdline *cl,
9222                         __attribute__((unused)) void *data)
9223 {
9224         struct cmd_flush_queue_region_result *res = parsed_result;
9225         int ret = -ENOTSUP;
9226 #ifdef RTE_LIBRTE_I40E_PMD
9227         struct rte_pmd_i40e_queue_region_conf region_conf;
9228         enum rte_pmd_i40e_queue_region_op op_type;
9229 #endif
9230
9231         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9232                 return;
9233
9234 #ifdef RTE_LIBRTE_I40E_PMD
9235         memset(&region_conf, 0, sizeof(region_conf));
9236
9237         if (strcmp(res->what, "on") == 0)
9238                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9239         else
9240                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9241
9242         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9243                                 op_type, &region_conf);
9244 #endif
9245
9246         switch (ret) {
9247         case 0:
9248                 break;
9249         case -ENOTSUP:
9250                 printf("function not implemented or supported\n");
9251                 break;
9252         default:
9253                 printf("queue region config flush error: (%s)\n",
9254                                 strerror(-ret));
9255         }
9256 }
9257
9258 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9259         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9260                                 set, "set");
9261 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9262         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9263                                 port, "port");
9264 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9265         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9266                                 port_id, UINT16);
9267 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9268         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9269                                 cmd, "queue-region");
9270 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9271         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9272                                 flush, "flush");
9273 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9274         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9275                                 what, "on#off");
9276
9277 cmdline_parse_inst_t cmd_flush_queue_region = {
9278         .f = cmd_flush_queue_region_parsed,
9279         .data = NULL,
9280         .help_str = "set port <port_id> queue-region flush on|off"
9281                 ": flush all queue region related configuration",
9282         .tokens = {
9283                 (void *)&cmd_flush_queue_region_set,
9284                 (void *)&cmd_flush_queue_region_port,
9285                 (void *)&cmd_flush_queue_region_port_index,
9286                 (void *)&cmd_flush_queue_region_cmd,
9287                 (void *)&cmd_flush_queue_region_flush,
9288                 (void *)&cmd_flush_queue_region_what,
9289                 NULL,
9290         },
9291 };
9292
9293 /* *** get all queue region related configuration info *** */
9294 struct cmd_show_queue_region_info {
9295         cmdline_fixed_string_t show;
9296         cmdline_fixed_string_t port;
9297         portid_t port_id;
9298         cmdline_fixed_string_t cmd;
9299 };
9300
9301 static void
9302 cmd_show_queue_region_info_parsed(void *parsed_result,
9303                         __attribute__((unused)) struct cmdline *cl,
9304                         __attribute__((unused)) void *data)
9305 {
9306         struct cmd_show_queue_region_info *res = parsed_result;
9307         int ret = -ENOTSUP;
9308 #ifdef RTE_LIBRTE_I40E_PMD
9309         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9310         enum rte_pmd_i40e_queue_region_op op_type;
9311 #endif
9312
9313         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9314                 return;
9315
9316 #ifdef RTE_LIBRTE_I40E_PMD
9317         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9318
9319         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9320
9321         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9322                                         op_type, &rte_pmd_regions);
9323
9324         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9325 #endif
9326
9327         switch (ret) {
9328         case 0:
9329                 break;
9330         case -ENOTSUP:
9331                 printf("function not implemented or supported\n");
9332                 break;
9333         default:
9334                 printf("queue region config info show error: (%s)\n",
9335                                 strerror(-ret));
9336         }
9337 }
9338
9339 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9340 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9341                                 show, "show");
9342 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9343         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9344                                 port, "port");
9345 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9346         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9347                                 port_id, UINT16);
9348 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9349         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9350                                 cmd, "queue-region");
9351
9352 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9353         .f = cmd_show_queue_region_info_parsed,
9354         .data = NULL,
9355         .help_str = "show port <port_id> queue-region"
9356                 ": show all queue region related configuration info",
9357         .tokens = {
9358                 (void *)&cmd_show_queue_region_info_get,
9359                 (void *)&cmd_show_queue_region_info_port,
9360                 (void *)&cmd_show_queue_region_info_port_index,
9361                 (void *)&cmd_show_queue_region_info_cmd,
9362                 NULL,
9363         },
9364 };
9365
9366 /* *** ADD/REMOVE A 2tuple FILTER *** */
9367 struct cmd_2tuple_filter_result {
9368         cmdline_fixed_string_t filter;
9369         portid_t port_id;
9370         cmdline_fixed_string_t ops;
9371         cmdline_fixed_string_t dst_port;
9372         uint16_t dst_port_value;
9373         cmdline_fixed_string_t protocol;
9374         uint8_t protocol_value;
9375         cmdline_fixed_string_t mask;
9376         uint8_t  mask_value;
9377         cmdline_fixed_string_t tcp_flags;
9378         uint8_t tcp_flags_value;
9379         cmdline_fixed_string_t priority;
9380         uint8_t  priority_value;
9381         cmdline_fixed_string_t queue;
9382         uint16_t  queue_id;
9383 };
9384
9385 static void
9386 cmd_2tuple_filter_parsed(void *parsed_result,
9387                         __attribute__((unused)) struct cmdline *cl,
9388                         __attribute__((unused)) void *data)
9389 {
9390         struct rte_eth_ntuple_filter filter;
9391         struct cmd_2tuple_filter_result *res = parsed_result;
9392         int ret = 0;
9393
9394         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9395         if (ret < 0) {
9396                 printf("ntuple filter is not supported on port %u.\n",
9397                         res->port_id);
9398                 return;
9399         }
9400
9401         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9402
9403         filter.flags = RTE_2TUPLE_FLAGS;
9404         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9405         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9406         filter.proto = res->protocol_value;
9407         filter.priority = res->priority_value;
9408         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9409                 printf("nonzero tcp_flags is only meaningful"
9410                         " when protocol is TCP.\n");
9411                 return;
9412         }
9413         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9414                 printf("invalid TCP flags.\n");
9415                 return;
9416         }
9417
9418         if (res->tcp_flags_value != 0) {
9419                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9420                 filter.tcp_flags = res->tcp_flags_value;
9421         }
9422
9423         /* need convert to big endian. */
9424         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9425         filter.queue = res->queue_id;
9426
9427         if (!strcmp(res->ops, "add"))
9428                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9429                                 RTE_ETH_FILTER_NTUPLE,
9430                                 RTE_ETH_FILTER_ADD,
9431                                 &filter);
9432         else
9433                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9434                                 RTE_ETH_FILTER_NTUPLE,
9435                                 RTE_ETH_FILTER_DELETE,
9436                                 &filter);
9437         if (ret < 0)
9438                 printf("2tuple filter programming error: (%s)\n",
9439                         strerror(-ret));
9440
9441 }
9442
9443 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9444         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9445                                  filter, "2tuple_filter");
9446 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9447         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9448                                 port_id, UINT16);
9449 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9450         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9451                                  ops, "add#del");
9452 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9453         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9454                                 dst_port, "dst_port");
9455 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9456         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9457                                 dst_port_value, UINT16);
9458 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9459         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9460                                 protocol, "protocol");
9461 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9462         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9463                                 protocol_value, UINT8);
9464 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9465         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9466                                 mask, "mask");
9467 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9468         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9469                                 mask_value, INT8);
9470 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9471         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9472                                 tcp_flags, "tcp_flags");
9473 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9474         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9475                                 tcp_flags_value, UINT8);
9476 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9477         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9478                                 priority, "priority");
9479 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9480         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9481                                 priority_value, UINT8);
9482 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9483         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9484                                 queue, "queue");
9485 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9486         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9487                                 queue_id, UINT16);
9488
9489 cmdline_parse_inst_t cmd_2tuple_filter = {
9490         .f = cmd_2tuple_filter_parsed,
9491         .data = NULL,
9492         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9493                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9494                 "<queue_id>: Add a 2tuple filter",
9495         .tokens = {
9496                 (void *)&cmd_2tuple_filter_filter,
9497                 (void *)&cmd_2tuple_filter_port_id,
9498                 (void *)&cmd_2tuple_filter_ops,
9499                 (void *)&cmd_2tuple_filter_dst_port,
9500                 (void *)&cmd_2tuple_filter_dst_port_value,
9501                 (void *)&cmd_2tuple_filter_protocol,
9502                 (void *)&cmd_2tuple_filter_protocol_value,
9503                 (void *)&cmd_2tuple_filter_mask,
9504                 (void *)&cmd_2tuple_filter_mask_value,
9505                 (void *)&cmd_2tuple_filter_tcp_flags,
9506                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9507                 (void *)&cmd_2tuple_filter_priority,
9508                 (void *)&cmd_2tuple_filter_priority_value,
9509                 (void *)&cmd_2tuple_filter_queue,
9510                 (void *)&cmd_2tuple_filter_queue_id,
9511                 NULL,
9512         },
9513 };
9514
9515 /* *** ADD/REMOVE A 5tuple FILTER *** */
9516 struct cmd_5tuple_filter_result {
9517         cmdline_fixed_string_t filter;
9518         portid_t port_id;
9519         cmdline_fixed_string_t ops;
9520         cmdline_fixed_string_t dst_ip;
9521         cmdline_ipaddr_t dst_ip_value;
9522         cmdline_fixed_string_t src_ip;
9523         cmdline_ipaddr_t src_ip_value;
9524         cmdline_fixed_string_t dst_port;
9525         uint16_t dst_port_value;
9526         cmdline_fixed_string_t src_port;
9527         uint16_t src_port_value;
9528         cmdline_fixed_string_t protocol;
9529         uint8_t protocol_value;
9530         cmdline_fixed_string_t mask;
9531         uint8_t  mask_value;
9532         cmdline_fixed_string_t tcp_flags;
9533         uint8_t tcp_flags_value;
9534         cmdline_fixed_string_t priority;
9535         uint8_t  priority_value;
9536         cmdline_fixed_string_t queue;
9537         uint16_t  queue_id;
9538 };
9539
9540 static void
9541 cmd_5tuple_filter_parsed(void *parsed_result,
9542                         __attribute__((unused)) struct cmdline *cl,
9543                         __attribute__((unused)) void *data)
9544 {
9545         struct rte_eth_ntuple_filter filter;
9546         struct cmd_5tuple_filter_result *res = parsed_result;
9547         int ret = 0;
9548
9549         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9550         if (ret < 0) {
9551                 printf("ntuple filter is not supported on port %u.\n",
9552                         res->port_id);
9553                 return;
9554         }
9555
9556         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9557
9558         filter.flags = RTE_5TUPLE_FLAGS;
9559         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9560         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9561         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9562         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9563         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9564         filter.proto = res->protocol_value;
9565         filter.priority = res->priority_value;
9566         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9567                 printf("nonzero tcp_flags is only meaningful"
9568                         " when protocol is TCP.\n");
9569                 return;
9570         }
9571         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9572                 printf("invalid TCP flags.\n");
9573                 return;
9574         }
9575
9576         if (res->tcp_flags_value != 0) {
9577                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9578                 filter.tcp_flags = res->tcp_flags_value;
9579         }
9580
9581         if (res->dst_ip_value.family == AF_INET)
9582                 /* no need to convert, already big endian. */
9583                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9584         else {
9585                 if (filter.dst_ip_mask == 0) {
9586                         printf("can not support ipv6 involved compare.\n");
9587                         return;
9588                 }
9589                 filter.dst_ip = 0;
9590         }
9591
9592         if (res->src_ip_value.family == AF_INET)
9593                 /* no need to convert, already big endian. */
9594                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9595         else {
9596                 if (filter.src_ip_mask == 0) {
9597                         printf("can not support ipv6 involved compare.\n");
9598                         return;
9599                 }
9600                 filter.src_ip = 0;
9601         }
9602         /* need convert to big endian. */
9603         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9604         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9605         filter.queue = res->queue_id;
9606
9607         if (!strcmp(res->ops, "add"))
9608                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9609                                 RTE_ETH_FILTER_NTUPLE,
9610                                 RTE_ETH_FILTER_ADD,
9611                                 &filter);
9612         else
9613                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9614                                 RTE_ETH_FILTER_NTUPLE,
9615                                 RTE_ETH_FILTER_DELETE,
9616                                 &filter);
9617         if (ret < 0)
9618                 printf("5tuple filter programming error: (%s)\n",
9619                         strerror(-ret));
9620 }
9621
9622 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9623         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9624                                  filter, "5tuple_filter");
9625 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9626         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9627                                 port_id, UINT16);
9628 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9629         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9630                                  ops, "add#del");
9631 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9632         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9633                                 dst_ip, "dst_ip");
9634 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9635         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9636                                 dst_ip_value);
9637 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9638         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9639                                 src_ip, "src_ip");
9640 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9641         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9642                                 src_ip_value);
9643 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9644         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9645                                 dst_port, "dst_port");
9646 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9647         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9648                                 dst_port_value, UINT16);
9649 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9650         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9651                                 src_port, "src_port");
9652 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9653         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9654                                 src_port_value, UINT16);
9655 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9656         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9657                                 protocol, "protocol");
9658 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9659         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9660                                 protocol_value, UINT8);
9661 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9662         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9663                                 mask, "mask");
9664 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9665         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9666                                 mask_value, INT8);
9667 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9668         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9669                                 tcp_flags, "tcp_flags");
9670 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9671         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9672                                 tcp_flags_value, UINT8);
9673 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9674         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9675                                 priority, "priority");
9676 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9677         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9678                                 priority_value, UINT8);
9679 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9680         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9681                                 queue, "queue");
9682 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9683         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9684                                 queue_id, UINT16);
9685
9686 cmdline_parse_inst_t cmd_5tuple_filter = {
9687         .f = cmd_5tuple_filter_parsed,
9688         .data = NULL,
9689         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9690                 "src_ip <value> dst_port <value> src_port <value> "
9691                 "protocol <value>  mask <value> tcp_flags <value> "
9692                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9693         .tokens = {
9694                 (void *)&cmd_5tuple_filter_filter,
9695                 (void *)&cmd_5tuple_filter_port_id,
9696                 (void *)&cmd_5tuple_filter_ops,
9697                 (void *)&cmd_5tuple_filter_dst_ip,
9698                 (void *)&cmd_5tuple_filter_dst_ip_value,
9699                 (void *)&cmd_5tuple_filter_src_ip,
9700                 (void *)&cmd_5tuple_filter_src_ip_value,
9701                 (void *)&cmd_5tuple_filter_dst_port,
9702                 (void *)&cmd_5tuple_filter_dst_port_value,
9703                 (void *)&cmd_5tuple_filter_src_port,
9704                 (void *)&cmd_5tuple_filter_src_port_value,
9705                 (void *)&cmd_5tuple_filter_protocol,
9706                 (void *)&cmd_5tuple_filter_protocol_value,
9707                 (void *)&cmd_5tuple_filter_mask,
9708                 (void *)&cmd_5tuple_filter_mask_value,
9709                 (void *)&cmd_5tuple_filter_tcp_flags,
9710                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9711                 (void *)&cmd_5tuple_filter_priority,
9712                 (void *)&cmd_5tuple_filter_priority_value,
9713                 (void *)&cmd_5tuple_filter_queue,
9714                 (void *)&cmd_5tuple_filter_queue_id,
9715                 NULL,
9716         },
9717 };
9718
9719 /* *** ADD/REMOVE A flex FILTER *** */
9720 struct cmd_flex_filter_result {
9721         cmdline_fixed_string_t filter;
9722         cmdline_fixed_string_t ops;
9723         portid_t port_id;
9724         cmdline_fixed_string_t len;
9725         uint8_t len_value;
9726         cmdline_fixed_string_t bytes;
9727         cmdline_fixed_string_t bytes_value;
9728         cmdline_fixed_string_t mask;
9729         cmdline_fixed_string_t mask_value;
9730         cmdline_fixed_string_t priority;
9731         uint8_t priority_value;
9732         cmdline_fixed_string_t queue;
9733         uint16_t queue_id;
9734 };
9735
9736 static int xdigit2val(unsigned char c)
9737 {
9738         int val;
9739         if (isdigit(c))
9740                 val = c - '0';
9741         else if (isupper(c))
9742                 val = c - 'A' + 10;
9743         else
9744                 val = c - 'a' + 10;
9745         return val;
9746 }
9747
9748 static void
9749 cmd_flex_filter_parsed(void *parsed_result,
9750                           __attribute__((unused)) struct cmdline *cl,
9751                           __attribute__((unused)) void *data)
9752 {
9753         int ret = 0;
9754         struct rte_eth_flex_filter filter;
9755         struct cmd_flex_filter_result *res = parsed_result;
9756         char *bytes_ptr, *mask_ptr;
9757         uint16_t len, i, j = 0;
9758         char c;
9759         int val;
9760         uint8_t byte = 0;
9761
9762         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9763                 printf("the len exceed the max length 128\n");
9764                 return;
9765         }
9766         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9767         filter.len = res->len_value;
9768         filter.priority = res->priority_value;
9769         filter.queue = res->queue_id;
9770         bytes_ptr = res->bytes_value;
9771         mask_ptr = res->mask_value;
9772
9773          /* translate bytes string to array. */
9774         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9775                 (bytes_ptr[1] == 'X')))
9776                 bytes_ptr += 2;
9777         len = strnlen(bytes_ptr, res->len_value * 2);
9778         if (len == 0 || (len % 8 != 0)) {
9779                 printf("please check len and bytes input\n");
9780                 return;
9781         }
9782         for (i = 0; i < len; i++) {
9783                 c = bytes_ptr[i];
9784                 if (isxdigit(c) == 0) {
9785                         /* invalid characters. */
9786                         printf("invalid input\n");
9787                         return;
9788                 }
9789                 val = xdigit2val(c);
9790                 if (i % 2) {
9791                         byte |= val;
9792                         filter.bytes[j] = byte;
9793                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9794                         j++;
9795                         byte = 0;
9796                 } else
9797                         byte |= val << 4;
9798         }
9799         printf("\n");
9800          /* translate mask string to uint8_t array. */
9801         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9802                 (mask_ptr[1] == 'X')))
9803                 mask_ptr += 2;
9804         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9805         if (len == 0) {
9806                 printf("invalid input\n");
9807                 return;
9808         }
9809         j = 0;
9810         byte = 0;
9811         for (i = 0; i < len; i++) {
9812                 c = mask_ptr[i];
9813                 if (isxdigit(c) == 0) {
9814                         /* invalid characters. */
9815                         printf("invalid input\n");
9816                         return;
9817                 }
9818                 val = xdigit2val(c);
9819                 if (i % 2) {
9820                         byte |= val;
9821                         filter.mask[j] = byte;
9822                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9823                         j++;
9824                         byte = 0;
9825                 } else
9826                         byte |= val << 4;
9827         }
9828         printf("\n");
9829
9830         if (!strcmp(res->ops, "add"))
9831                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9832                                 RTE_ETH_FILTER_FLEXIBLE,
9833                                 RTE_ETH_FILTER_ADD,
9834                                 &filter);
9835         else
9836                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9837                                 RTE_ETH_FILTER_FLEXIBLE,
9838                                 RTE_ETH_FILTER_DELETE,
9839                                 &filter);
9840
9841         if (ret < 0)
9842                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9843 }
9844
9845 cmdline_parse_token_string_t cmd_flex_filter_filter =
9846         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9847                                 filter, "flex_filter");
9848 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9849         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9850                                 port_id, UINT16);
9851 cmdline_parse_token_string_t cmd_flex_filter_ops =
9852         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9853                                 ops, "add#del");
9854 cmdline_parse_token_string_t cmd_flex_filter_len =
9855         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9856                                 len, "len");
9857 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9858         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9859                                 len_value, UINT8);
9860 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9861         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9862                                 bytes, "bytes");
9863 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9864         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9865                                 bytes_value, NULL);
9866 cmdline_parse_token_string_t cmd_flex_filter_mask =
9867         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9868                                 mask, "mask");
9869 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9870         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9871                                 mask_value, NULL);
9872 cmdline_parse_token_string_t cmd_flex_filter_priority =
9873         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9874                                 priority, "priority");
9875 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9876         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9877                                 priority_value, UINT8);
9878 cmdline_parse_token_string_t cmd_flex_filter_queue =
9879         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9880                                 queue, "queue");
9881 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9882         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9883                                 queue_id, UINT16);
9884 cmdline_parse_inst_t cmd_flex_filter = {
9885         .f = cmd_flex_filter_parsed,
9886         .data = NULL,
9887         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9888                 "<value> mask <value> priority <value> queue <queue_id>: "
9889                 "Add/Del a flex filter",
9890         .tokens = {
9891                 (void *)&cmd_flex_filter_filter,
9892                 (void *)&cmd_flex_filter_port_id,
9893                 (void *)&cmd_flex_filter_ops,
9894                 (void *)&cmd_flex_filter_len,
9895                 (void *)&cmd_flex_filter_len_value,
9896                 (void *)&cmd_flex_filter_bytes,
9897                 (void *)&cmd_flex_filter_bytes_value,
9898                 (void *)&cmd_flex_filter_mask,
9899                 (void *)&cmd_flex_filter_mask_value,
9900                 (void *)&cmd_flex_filter_priority,
9901                 (void *)&cmd_flex_filter_priority_value,
9902                 (void *)&cmd_flex_filter_queue,
9903                 (void *)&cmd_flex_filter_queue_id,
9904                 NULL,
9905         },
9906 };
9907
9908 /* *** Filters Control *** */
9909
9910 /* *** deal with ethertype filter *** */
9911 struct cmd_ethertype_filter_result {
9912         cmdline_fixed_string_t filter;
9913         portid_t port_id;
9914         cmdline_fixed_string_t ops;
9915         cmdline_fixed_string_t mac;
9916         struct ether_addr mac_addr;
9917         cmdline_fixed_string_t ethertype;
9918         uint16_t ethertype_value;
9919         cmdline_fixed_string_t drop;
9920         cmdline_fixed_string_t queue;
9921         uint16_t  queue_id;
9922 };
9923
9924 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9925         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9926                                  filter, "ethertype_filter");
9927 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9928         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9929                               port_id, UINT16);
9930 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9931         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9932                                  ops, "add#del");
9933 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9934         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9935                                  mac, "mac_addr#mac_ignr");
9936 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9937         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9938                                      mac_addr);
9939 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9940         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9941                                  ethertype, "ethertype");
9942 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9943         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9944                               ethertype_value, UINT16);
9945 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9946         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9947                                  drop, "drop#fwd");
9948 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9949         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9950                                  queue, "queue");
9951 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9952         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9953                               queue_id, UINT16);
9954
9955 static void
9956 cmd_ethertype_filter_parsed(void *parsed_result,
9957                           __attribute__((unused)) struct cmdline *cl,
9958                           __attribute__((unused)) void *data)
9959 {
9960         struct cmd_ethertype_filter_result *res = parsed_result;
9961         struct rte_eth_ethertype_filter filter;
9962         int ret = 0;
9963
9964         ret = rte_eth_dev_filter_supported(res->port_id,
9965                         RTE_ETH_FILTER_ETHERTYPE);
9966         if (ret < 0) {
9967                 printf("ethertype filter is not supported on port %u.\n",
9968                         res->port_id);
9969                 return;
9970         }
9971
9972         memset(&filter, 0, sizeof(filter));
9973         if (!strcmp(res->mac, "mac_addr")) {
9974                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9975                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9976                         sizeof(struct ether_addr));
9977         }
9978         if (!strcmp(res->drop, "drop"))
9979                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9980         filter.ether_type = res->ethertype_value;
9981         filter.queue = res->queue_id;
9982
9983         if (!strcmp(res->ops, "add"))
9984                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9985                                 RTE_ETH_FILTER_ETHERTYPE,
9986                                 RTE_ETH_FILTER_ADD,
9987                                 &filter);
9988         else
9989                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9990                                 RTE_ETH_FILTER_ETHERTYPE,
9991                                 RTE_ETH_FILTER_DELETE,
9992                                 &filter);
9993         if (ret < 0)
9994                 printf("ethertype filter programming error: (%s)\n",
9995                         strerror(-ret));
9996 }
9997
9998 cmdline_parse_inst_t cmd_ethertype_filter = {
9999         .f = cmd_ethertype_filter_parsed,
10000         .data = NULL,
10001         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10002                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10003                 "Add or delete an ethertype filter entry",
10004         .tokens = {
10005                 (void *)&cmd_ethertype_filter_filter,
10006                 (void *)&cmd_ethertype_filter_port_id,
10007                 (void *)&cmd_ethertype_filter_ops,
10008                 (void *)&cmd_ethertype_filter_mac,
10009                 (void *)&cmd_ethertype_filter_mac_addr,
10010                 (void *)&cmd_ethertype_filter_ethertype,
10011                 (void *)&cmd_ethertype_filter_ethertype_value,
10012                 (void *)&cmd_ethertype_filter_drop,
10013                 (void *)&cmd_ethertype_filter_queue,
10014                 (void *)&cmd_ethertype_filter_queue_id,
10015                 NULL,
10016         },
10017 };
10018
10019 /* *** deal with flow director filter *** */
10020 struct cmd_flow_director_result {
10021         cmdline_fixed_string_t flow_director_filter;
10022         portid_t port_id;
10023         cmdline_fixed_string_t mode;
10024         cmdline_fixed_string_t mode_value;
10025         cmdline_fixed_string_t ops;
10026         cmdline_fixed_string_t flow;
10027         cmdline_fixed_string_t flow_type;
10028         cmdline_fixed_string_t ether;
10029         uint16_t ether_type;
10030         cmdline_fixed_string_t src;
10031         cmdline_ipaddr_t ip_src;
10032         uint16_t port_src;
10033         cmdline_fixed_string_t dst;
10034         cmdline_ipaddr_t ip_dst;
10035         uint16_t port_dst;
10036         cmdline_fixed_string_t verify_tag;
10037         uint32_t verify_tag_value;
10038         cmdline_fixed_string_t tos;
10039         uint8_t tos_value;
10040         cmdline_fixed_string_t proto;
10041         uint8_t proto_value;
10042         cmdline_fixed_string_t ttl;
10043         uint8_t ttl_value;
10044         cmdline_fixed_string_t vlan;
10045         uint16_t vlan_value;
10046         cmdline_fixed_string_t flexbytes;
10047         cmdline_fixed_string_t flexbytes_value;
10048         cmdline_fixed_string_t pf_vf;
10049         cmdline_fixed_string_t drop;
10050         cmdline_fixed_string_t queue;
10051         uint16_t  queue_id;
10052         cmdline_fixed_string_t fd_id;
10053         uint32_t  fd_id_value;
10054         cmdline_fixed_string_t mac;
10055         struct ether_addr mac_addr;
10056         cmdline_fixed_string_t tunnel;
10057         cmdline_fixed_string_t tunnel_type;
10058         cmdline_fixed_string_t tunnel_id;
10059         uint32_t tunnel_id_value;
10060         cmdline_fixed_string_t packet;
10061         char filepath[];
10062 };
10063
10064 static inline int
10065 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10066 {
10067         char s[256];
10068         const char *p, *p0 = q_arg;
10069         char *end;
10070         unsigned long int_fld;
10071         char *str_fld[max_num];
10072         int i;
10073         unsigned size;
10074         int ret = -1;
10075
10076         p = strchr(p0, '(');
10077         if (p == NULL)
10078                 return -1;
10079         ++p;
10080         p0 = strchr(p, ')');
10081         if (p0 == NULL)
10082                 return -1;
10083
10084         size = p0 - p;
10085         if (size >= sizeof(s))
10086                 return -1;
10087
10088         snprintf(s, sizeof(s), "%.*s", size, p);
10089         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10090         if (ret < 0 || ret > max_num)
10091                 return -1;
10092         for (i = 0; i < ret; i++) {
10093                 errno = 0;
10094                 int_fld = strtoul(str_fld[i], &end, 0);
10095                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10096                         return -1;
10097                 flexbytes[i] = (uint8_t)int_fld;
10098         }
10099         return ret;
10100 }
10101
10102 static uint16_t
10103 str2flowtype(char *string)
10104 {
10105         uint8_t i = 0;
10106         static const struct {
10107                 char str[32];
10108                 uint16_t type;
10109         } flowtype_str[] = {
10110                 {"raw", RTE_ETH_FLOW_RAW},
10111                 {"ipv4", RTE_ETH_FLOW_IPV4},
10112                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10113                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10114                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10115                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10116                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10117                 {"ipv6", RTE_ETH_FLOW_IPV6},
10118                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10119                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10120                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10121                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10122                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10123                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10124         };
10125
10126         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10127                 if (!strcmp(flowtype_str[i].str, string))
10128                         return flowtype_str[i].type;
10129         }
10130
10131         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10132                 return (uint16_t)atoi(string);
10133
10134         return RTE_ETH_FLOW_UNKNOWN;
10135 }
10136
10137 static enum rte_eth_fdir_tunnel_type
10138 str2fdir_tunneltype(char *string)
10139 {
10140         uint8_t i = 0;
10141
10142         static const struct {
10143                 char str[32];
10144                 enum rte_eth_fdir_tunnel_type type;
10145         } tunneltype_str[] = {
10146                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10147                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10148         };
10149
10150         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10151                 if (!strcmp(tunneltype_str[i].str, string))
10152                         return tunneltype_str[i].type;
10153         }
10154         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10155 }
10156
10157 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10158 do { \
10159         if ((ip_addr).family == AF_INET) \
10160                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10161         else { \
10162                 printf("invalid parameter.\n"); \
10163                 return; \
10164         } \
10165 } while (0)
10166
10167 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10168 do { \
10169         if ((ip_addr).family == AF_INET6) \
10170                 rte_memcpy(&(ip), \
10171                                  &((ip_addr).addr.ipv6), \
10172                                  sizeof(struct in6_addr)); \
10173         else { \
10174                 printf("invalid parameter.\n"); \
10175                 return; \
10176         } \
10177 } while (0)
10178
10179 static void
10180 cmd_flow_director_filter_parsed(void *parsed_result,
10181                           __attribute__((unused)) struct cmdline *cl,
10182                           __attribute__((unused)) void *data)
10183 {
10184         struct cmd_flow_director_result *res = parsed_result;
10185         struct rte_eth_fdir_filter entry;
10186         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10187         char *end;
10188         unsigned long vf_id;
10189         int ret = 0;
10190
10191         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10192         if (ret < 0) {
10193                 printf("flow director is not supported on port %u.\n",
10194                         res->port_id);
10195                 return;
10196         }
10197         memset(flexbytes, 0, sizeof(flexbytes));
10198         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10199
10200         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10201                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10202                         printf("Please set mode to MAC-VLAN.\n");
10203                         return;
10204                 }
10205         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10206                 if (strcmp(res->mode_value, "Tunnel")) {
10207                         printf("Please set mode to Tunnel.\n");
10208                         return;
10209                 }
10210         } else {
10211                 if (!strcmp(res->mode_value, "raw")) {
10212 #ifdef RTE_LIBRTE_I40E_PMD
10213                         struct rte_pmd_i40e_flow_type_mapping
10214                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10215                         struct rte_pmd_i40e_pkt_template_conf conf;
10216                         uint16_t flow_type = str2flowtype(res->flow_type);
10217                         uint16_t i, port = res->port_id;
10218                         uint8_t add;
10219
10220                         memset(&conf, 0, sizeof(conf));
10221
10222                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10223                                 printf("Invalid flow type specified.\n");
10224                                 return;
10225                         }
10226                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10227                                                                  mapping);
10228                         if (ret)
10229                                 return;
10230                         if (mapping[flow_type].pctype == 0ULL) {
10231                                 printf("Invalid flow type specified.\n");
10232                                 return;
10233                         }
10234                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10235                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10236                                         conf.input.pctype = i;
10237                                         break;
10238                                 }
10239                         }
10240
10241                         conf.input.packet = open_file(res->filepath,
10242                                                 &conf.input.length);
10243                         if (!conf.input.packet)
10244                                 return;
10245                         if (!strcmp(res->drop, "drop"))
10246                                 conf.action.behavior =
10247                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10248                         else
10249                                 conf.action.behavior =
10250                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10251                         conf.action.report_status =
10252                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10253                         conf.action.rx_queue = res->queue_id;
10254                         conf.soft_id = res->fd_id_value;
10255                         add  = strcmp(res->ops, "del") ? 1 : 0;
10256                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10257                                                                         &conf,
10258                                                                         add);
10259                         if (ret < 0)
10260                                 printf("flow director config error: (%s)\n",
10261                                        strerror(-ret));
10262                         close_file(conf.input.packet);
10263 #endif
10264                         return;
10265                 } else if (strcmp(res->mode_value, "IP")) {
10266                         printf("Please set mode to IP or raw.\n");
10267                         return;
10268                 }
10269                 entry.input.flow_type = str2flowtype(res->flow_type);
10270         }
10271
10272         ret = parse_flexbytes(res->flexbytes_value,
10273                                         flexbytes,
10274                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10275         if (ret < 0) {
10276                 printf("error: Cannot parse flexbytes input.\n");
10277                 return;
10278         }
10279
10280         switch (entry.input.flow_type) {
10281         case RTE_ETH_FLOW_FRAG_IPV4:
10282         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10283                 entry.input.flow.ip4_flow.proto = res->proto_value;
10284                 /* fall-through */
10285         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10286         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10287                 IPV4_ADDR_TO_UINT(res->ip_dst,
10288                         entry.input.flow.ip4_flow.dst_ip);
10289                 IPV4_ADDR_TO_UINT(res->ip_src,
10290                         entry.input.flow.ip4_flow.src_ip);
10291                 entry.input.flow.ip4_flow.tos = res->tos_value;
10292                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10293                 /* need convert to big endian. */
10294                 entry.input.flow.udp4_flow.dst_port =
10295                                 rte_cpu_to_be_16(res->port_dst);
10296                 entry.input.flow.udp4_flow.src_port =
10297                                 rte_cpu_to_be_16(res->port_src);
10298                 break;
10299         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10300                 IPV4_ADDR_TO_UINT(res->ip_dst,
10301                         entry.input.flow.sctp4_flow.ip.dst_ip);
10302                 IPV4_ADDR_TO_UINT(res->ip_src,
10303                         entry.input.flow.sctp4_flow.ip.src_ip);
10304                 entry.input.flow.ip4_flow.tos = res->tos_value;
10305                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10306                 /* need convert to big endian. */
10307                 entry.input.flow.sctp4_flow.dst_port =
10308                                 rte_cpu_to_be_16(res->port_dst);
10309                 entry.input.flow.sctp4_flow.src_port =
10310                                 rte_cpu_to_be_16(res->port_src);
10311                 entry.input.flow.sctp4_flow.verify_tag =
10312                                 rte_cpu_to_be_32(res->verify_tag_value);
10313                 break;
10314         case RTE_ETH_FLOW_FRAG_IPV6:
10315         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10316                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10317                 /* fall-through */
10318         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10319         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10320                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10321                         entry.input.flow.ipv6_flow.dst_ip);
10322                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10323                         entry.input.flow.ipv6_flow.src_ip);
10324                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10325                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10326                 /* need convert to big endian. */
10327                 entry.input.flow.udp6_flow.dst_port =
10328                                 rte_cpu_to_be_16(res->port_dst);
10329                 entry.input.flow.udp6_flow.src_port =
10330                                 rte_cpu_to_be_16(res->port_src);
10331                 break;
10332         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10333                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10334                         entry.input.flow.sctp6_flow.ip.dst_ip);
10335                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10336                         entry.input.flow.sctp6_flow.ip.src_ip);
10337                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10338                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10339                 /* need convert to big endian. */
10340                 entry.input.flow.sctp6_flow.dst_port =
10341                                 rte_cpu_to_be_16(res->port_dst);
10342                 entry.input.flow.sctp6_flow.src_port =
10343                                 rte_cpu_to_be_16(res->port_src);
10344                 entry.input.flow.sctp6_flow.verify_tag =
10345                                 rte_cpu_to_be_32(res->verify_tag_value);
10346                 break;
10347         case RTE_ETH_FLOW_L2_PAYLOAD:
10348                 entry.input.flow.l2_flow.ether_type =
10349                         rte_cpu_to_be_16(res->ether_type);
10350                 break;
10351         default:
10352                 break;
10353         }
10354
10355         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10356                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10357                                  &res->mac_addr,
10358                                  sizeof(struct ether_addr));
10359
10360         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10361                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10362                                  &res->mac_addr,
10363                                  sizeof(struct ether_addr));
10364                 entry.input.flow.tunnel_flow.tunnel_type =
10365                         str2fdir_tunneltype(res->tunnel_type);
10366                 entry.input.flow.tunnel_flow.tunnel_id =
10367                         rte_cpu_to_be_32(res->tunnel_id_value);
10368         }
10369
10370         rte_memcpy(entry.input.flow_ext.flexbytes,
10371                    flexbytes,
10372                    RTE_ETH_FDIR_MAX_FLEXLEN);
10373
10374         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10375
10376         entry.action.flex_off = 0;  /*use 0 by default */
10377         if (!strcmp(res->drop, "drop"))
10378                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10379         else
10380                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10381
10382         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10383             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10384                 if (!strcmp(res->pf_vf, "pf"))
10385                         entry.input.flow_ext.is_vf = 0;
10386                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10387                         struct rte_eth_dev_info dev_info;
10388
10389                         memset(&dev_info, 0, sizeof(dev_info));
10390                         rte_eth_dev_info_get(res->port_id, &dev_info);
10391                         errno = 0;
10392                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10393                         if (errno != 0 || *end != '\0' ||
10394                             vf_id >= dev_info.max_vfs) {
10395                                 printf("invalid parameter %s.\n", res->pf_vf);
10396                                 return;
10397                         }
10398                         entry.input.flow_ext.is_vf = 1;
10399                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10400                 } else {
10401                         printf("invalid parameter %s.\n", res->pf_vf);
10402                         return;
10403                 }
10404         }
10405
10406         /* set to report FD ID by default */
10407         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10408         entry.action.rx_queue = res->queue_id;
10409         entry.soft_id = res->fd_id_value;
10410         if (!strcmp(res->ops, "add"))
10411                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10412                                              RTE_ETH_FILTER_ADD, &entry);
10413         else if (!strcmp(res->ops, "del"))
10414                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10415                                              RTE_ETH_FILTER_DELETE, &entry);
10416         else
10417                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10418                                              RTE_ETH_FILTER_UPDATE, &entry);
10419         if (ret < 0)
10420                 printf("flow director programming error: (%s)\n",
10421                         strerror(-ret));
10422 }
10423
10424 cmdline_parse_token_string_t cmd_flow_director_filter =
10425         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10426                                  flow_director_filter, "flow_director_filter");
10427 cmdline_parse_token_num_t cmd_flow_director_port_id =
10428         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10429                               port_id, UINT16);
10430 cmdline_parse_token_string_t cmd_flow_director_ops =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10432                                  ops, "add#del#update");
10433 cmdline_parse_token_string_t cmd_flow_director_flow =
10434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10435                                  flow, "flow");
10436 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10438                 flow_type, NULL);
10439 cmdline_parse_token_string_t cmd_flow_director_ether =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10441                                  ether, "ether");
10442 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10444                               ether_type, UINT16);
10445 cmdline_parse_token_string_t cmd_flow_director_src =
10446         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10447                                  src, "src");
10448 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10449         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10450                                  ip_src);
10451 cmdline_parse_token_num_t cmd_flow_director_port_src =
10452         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10453                               port_src, UINT16);
10454 cmdline_parse_token_string_t cmd_flow_director_dst =
10455         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10456                                  dst, "dst");
10457 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10458         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10459                                  ip_dst);
10460 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10461         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10462                               port_dst, UINT16);
10463 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10464         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10465                                   verify_tag, "verify_tag");
10466 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10467         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10468                               verify_tag_value, UINT32);
10469 cmdline_parse_token_string_t cmd_flow_director_tos =
10470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10471                                  tos, "tos");
10472 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10473         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10474                               tos_value, UINT8);
10475 cmdline_parse_token_string_t cmd_flow_director_proto =
10476         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10477                                  proto, "proto");
10478 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10479         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10480                               proto_value, UINT8);
10481 cmdline_parse_token_string_t cmd_flow_director_ttl =
10482         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10483                                  ttl, "ttl");
10484 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10485         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10486                               ttl_value, UINT8);
10487 cmdline_parse_token_string_t cmd_flow_director_vlan =
10488         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10489                                  vlan, "vlan");
10490 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10491         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10492                               vlan_value, UINT16);
10493 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10494         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10495                                  flexbytes, "flexbytes");
10496 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10497         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10498                               flexbytes_value, NULL);
10499 cmdline_parse_token_string_t cmd_flow_director_drop =
10500         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10501                                  drop, "drop#fwd");
10502 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10503         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10504                               pf_vf, NULL);
10505 cmdline_parse_token_string_t cmd_flow_director_queue =
10506         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10507                                  queue, "queue");
10508 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10509         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10510                               queue_id, UINT16);
10511 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10512         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10513                                  fd_id, "fd_id");
10514 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10515         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10516                               fd_id_value, UINT32);
10517
10518 cmdline_parse_token_string_t cmd_flow_director_mode =
10519         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10520                                  mode, "mode");
10521 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10522         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10523                                  mode_value, "IP");
10524 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10525         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10526                                  mode_value, "MAC-VLAN");
10527 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10528         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10529                                  mode_value, "Tunnel");
10530 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10531         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10532                                  mode_value, "raw");
10533 cmdline_parse_token_string_t cmd_flow_director_mac =
10534         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10535                                  mac, "mac");
10536 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10537         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10538                                     mac_addr);
10539 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10540         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10541                                  tunnel, "tunnel");
10542 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10543         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10544                                  tunnel_type, "NVGRE#VxLAN");
10545 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10546         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10547                                  tunnel_id, "tunnel-id");
10548 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10549         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10550                               tunnel_id_value, UINT32);
10551 cmdline_parse_token_string_t cmd_flow_director_packet =
10552         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10553                                  packet, "packet");
10554 cmdline_parse_token_string_t cmd_flow_director_filepath =
10555         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10556                                  filepath, NULL);
10557
10558 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10559         .f = cmd_flow_director_filter_parsed,
10560         .data = NULL,
10561         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10562                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10563                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10564                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10565                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10566                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10567                 "fd_id <fd_id_value>: "
10568                 "Add or delete an ip flow director entry on NIC",
10569         .tokens = {
10570                 (void *)&cmd_flow_director_filter,
10571                 (void *)&cmd_flow_director_port_id,
10572                 (void *)&cmd_flow_director_mode,
10573                 (void *)&cmd_flow_director_mode_ip,
10574                 (void *)&cmd_flow_director_ops,
10575                 (void *)&cmd_flow_director_flow,
10576                 (void *)&cmd_flow_director_flow_type,
10577                 (void *)&cmd_flow_director_src,
10578                 (void *)&cmd_flow_director_ip_src,
10579                 (void *)&cmd_flow_director_dst,
10580                 (void *)&cmd_flow_director_ip_dst,
10581                 (void *)&cmd_flow_director_tos,
10582                 (void *)&cmd_flow_director_tos_value,
10583                 (void *)&cmd_flow_director_proto,
10584                 (void *)&cmd_flow_director_proto_value,
10585                 (void *)&cmd_flow_director_ttl,
10586                 (void *)&cmd_flow_director_ttl_value,
10587                 (void *)&cmd_flow_director_vlan,
10588                 (void *)&cmd_flow_director_vlan_value,
10589                 (void *)&cmd_flow_director_flexbytes,
10590                 (void *)&cmd_flow_director_flexbytes_value,
10591                 (void *)&cmd_flow_director_drop,
10592                 (void *)&cmd_flow_director_pf_vf,
10593                 (void *)&cmd_flow_director_queue,
10594                 (void *)&cmd_flow_director_queue_id,
10595                 (void *)&cmd_flow_director_fd_id,
10596                 (void *)&cmd_flow_director_fd_id_value,
10597                 NULL,
10598         },
10599 };
10600
10601 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10602         .f = cmd_flow_director_filter_parsed,
10603         .data = NULL,
10604         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10605                 "director entry on NIC",
10606         .tokens = {
10607                 (void *)&cmd_flow_director_filter,
10608                 (void *)&cmd_flow_director_port_id,
10609                 (void *)&cmd_flow_director_mode,
10610                 (void *)&cmd_flow_director_mode_ip,
10611                 (void *)&cmd_flow_director_ops,
10612                 (void *)&cmd_flow_director_flow,
10613                 (void *)&cmd_flow_director_flow_type,
10614                 (void *)&cmd_flow_director_src,
10615                 (void *)&cmd_flow_director_ip_src,
10616                 (void *)&cmd_flow_director_port_src,
10617                 (void *)&cmd_flow_director_dst,
10618                 (void *)&cmd_flow_director_ip_dst,
10619                 (void *)&cmd_flow_director_port_dst,
10620                 (void *)&cmd_flow_director_tos,
10621                 (void *)&cmd_flow_director_tos_value,
10622                 (void *)&cmd_flow_director_ttl,
10623                 (void *)&cmd_flow_director_ttl_value,
10624                 (void *)&cmd_flow_director_vlan,
10625                 (void *)&cmd_flow_director_vlan_value,
10626                 (void *)&cmd_flow_director_flexbytes,
10627                 (void *)&cmd_flow_director_flexbytes_value,
10628                 (void *)&cmd_flow_director_drop,
10629                 (void *)&cmd_flow_director_pf_vf,
10630                 (void *)&cmd_flow_director_queue,
10631                 (void *)&cmd_flow_director_queue_id,
10632                 (void *)&cmd_flow_director_fd_id,
10633                 (void *)&cmd_flow_director_fd_id_value,
10634                 NULL,
10635         },
10636 };
10637
10638 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10639         .f = cmd_flow_director_filter_parsed,
10640         .data = NULL,
10641         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10642                 "director entry on NIC",
10643         .tokens = {
10644                 (void *)&cmd_flow_director_filter,
10645                 (void *)&cmd_flow_director_port_id,
10646                 (void *)&cmd_flow_director_mode,
10647                 (void *)&cmd_flow_director_mode_ip,
10648                 (void *)&cmd_flow_director_ops,
10649                 (void *)&cmd_flow_director_flow,
10650                 (void *)&cmd_flow_director_flow_type,
10651                 (void *)&cmd_flow_director_src,
10652                 (void *)&cmd_flow_director_ip_src,
10653                 (void *)&cmd_flow_director_port_src,
10654                 (void *)&cmd_flow_director_dst,
10655                 (void *)&cmd_flow_director_ip_dst,
10656                 (void *)&cmd_flow_director_port_dst,
10657                 (void *)&cmd_flow_director_verify_tag,
10658                 (void *)&cmd_flow_director_verify_tag_value,
10659                 (void *)&cmd_flow_director_tos,
10660                 (void *)&cmd_flow_director_tos_value,
10661                 (void *)&cmd_flow_director_ttl,
10662                 (void *)&cmd_flow_director_ttl_value,
10663                 (void *)&cmd_flow_director_vlan,
10664                 (void *)&cmd_flow_director_vlan_value,
10665                 (void *)&cmd_flow_director_flexbytes,
10666                 (void *)&cmd_flow_director_flexbytes_value,
10667                 (void *)&cmd_flow_director_drop,
10668                 (void *)&cmd_flow_director_pf_vf,
10669                 (void *)&cmd_flow_director_queue,
10670                 (void *)&cmd_flow_director_queue_id,
10671                 (void *)&cmd_flow_director_fd_id,
10672                 (void *)&cmd_flow_director_fd_id_value,
10673                 NULL,
10674         },
10675 };
10676
10677 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10678         .f = cmd_flow_director_filter_parsed,
10679         .data = NULL,
10680         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10681                 "director entry on NIC",
10682         .tokens = {
10683                 (void *)&cmd_flow_director_filter,
10684                 (void *)&cmd_flow_director_port_id,
10685                 (void *)&cmd_flow_director_mode,
10686                 (void *)&cmd_flow_director_mode_ip,
10687                 (void *)&cmd_flow_director_ops,
10688                 (void *)&cmd_flow_director_flow,
10689                 (void *)&cmd_flow_director_flow_type,
10690                 (void *)&cmd_flow_director_ether,
10691                 (void *)&cmd_flow_director_ether_type,
10692                 (void *)&cmd_flow_director_flexbytes,
10693                 (void *)&cmd_flow_director_flexbytes_value,
10694                 (void *)&cmd_flow_director_drop,
10695                 (void *)&cmd_flow_director_pf_vf,
10696                 (void *)&cmd_flow_director_queue,
10697                 (void *)&cmd_flow_director_queue_id,
10698                 (void *)&cmd_flow_director_fd_id,
10699                 (void *)&cmd_flow_director_fd_id_value,
10700                 NULL,
10701         },
10702 };
10703
10704 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10705         .f = cmd_flow_director_filter_parsed,
10706         .data = NULL,
10707         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10708                 "director entry on NIC",
10709         .tokens = {
10710                 (void *)&cmd_flow_director_filter,
10711                 (void *)&cmd_flow_director_port_id,
10712                 (void *)&cmd_flow_director_mode,
10713                 (void *)&cmd_flow_director_mode_mac_vlan,
10714                 (void *)&cmd_flow_director_ops,
10715                 (void *)&cmd_flow_director_mac,
10716                 (void *)&cmd_flow_director_mac_addr,
10717                 (void *)&cmd_flow_director_vlan,
10718                 (void *)&cmd_flow_director_vlan_value,
10719                 (void *)&cmd_flow_director_flexbytes,
10720                 (void *)&cmd_flow_director_flexbytes_value,
10721                 (void *)&cmd_flow_director_drop,
10722                 (void *)&cmd_flow_director_queue,
10723                 (void *)&cmd_flow_director_queue_id,
10724                 (void *)&cmd_flow_director_fd_id,
10725                 (void *)&cmd_flow_director_fd_id_value,
10726                 NULL,
10727         },
10728 };
10729
10730 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10731         .f = cmd_flow_director_filter_parsed,
10732         .data = NULL,
10733         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10734                 "director entry on NIC",
10735         .tokens = {
10736                 (void *)&cmd_flow_director_filter,
10737                 (void *)&cmd_flow_director_port_id,
10738                 (void *)&cmd_flow_director_mode,
10739                 (void *)&cmd_flow_director_mode_tunnel,
10740                 (void *)&cmd_flow_director_ops,
10741                 (void *)&cmd_flow_director_mac,
10742                 (void *)&cmd_flow_director_mac_addr,
10743                 (void *)&cmd_flow_director_vlan,
10744                 (void *)&cmd_flow_director_vlan_value,
10745                 (void *)&cmd_flow_director_tunnel,
10746                 (void *)&cmd_flow_director_tunnel_type,
10747                 (void *)&cmd_flow_director_tunnel_id,
10748                 (void *)&cmd_flow_director_tunnel_id_value,
10749                 (void *)&cmd_flow_director_flexbytes,
10750                 (void *)&cmd_flow_director_flexbytes_value,
10751                 (void *)&cmd_flow_director_drop,
10752                 (void *)&cmd_flow_director_queue,
10753                 (void *)&cmd_flow_director_queue_id,
10754                 (void *)&cmd_flow_director_fd_id,
10755                 (void *)&cmd_flow_director_fd_id_value,
10756                 NULL,
10757         },
10758 };
10759
10760 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10761         .f = cmd_flow_director_filter_parsed,
10762         .data = NULL,
10763         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10764                 "director entry on NIC",
10765         .tokens = {
10766                 (void *)&cmd_flow_director_filter,
10767                 (void *)&cmd_flow_director_port_id,
10768                 (void *)&cmd_flow_director_mode,
10769                 (void *)&cmd_flow_director_mode_raw,
10770                 (void *)&cmd_flow_director_ops,
10771                 (void *)&cmd_flow_director_flow,
10772                 (void *)&cmd_flow_director_flow_type,
10773                 (void *)&cmd_flow_director_drop,
10774                 (void *)&cmd_flow_director_queue,
10775                 (void *)&cmd_flow_director_queue_id,
10776                 (void *)&cmd_flow_director_fd_id,
10777                 (void *)&cmd_flow_director_fd_id_value,
10778                 (void *)&cmd_flow_director_packet,
10779                 (void *)&cmd_flow_director_filepath,
10780                 NULL,
10781         },
10782 };
10783
10784 struct cmd_flush_flow_director_result {
10785         cmdline_fixed_string_t flush_flow_director;
10786         portid_t port_id;
10787 };
10788
10789 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10790         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10791                                  flush_flow_director, "flush_flow_director");
10792 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10793         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10794                               port_id, UINT16);
10795
10796 static void
10797 cmd_flush_flow_director_parsed(void *parsed_result,
10798                           __attribute__((unused)) struct cmdline *cl,
10799                           __attribute__((unused)) void *data)
10800 {
10801         struct cmd_flow_director_result *res = parsed_result;
10802         int ret = 0;
10803
10804         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10805         if (ret < 0) {
10806                 printf("flow director is not supported on port %u.\n",
10807                         res->port_id);
10808                 return;
10809         }
10810
10811         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10812                         RTE_ETH_FILTER_FLUSH, NULL);
10813         if (ret < 0)
10814                 printf("flow director table flushing error: (%s)\n",
10815                         strerror(-ret));
10816 }
10817
10818 cmdline_parse_inst_t cmd_flush_flow_director = {
10819         .f = cmd_flush_flow_director_parsed,
10820         .data = NULL,
10821         .help_str = "flush_flow_director <port_id>: "
10822                 "Flush all flow director entries of a device on NIC",
10823         .tokens = {
10824                 (void *)&cmd_flush_flow_director_flush,
10825                 (void *)&cmd_flush_flow_director_port_id,
10826                 NULL,
10827         },
10828 };
10829
10830 /* *** deal with flow director mask *** */
10831 struct cmd_flow_director_mask_result {
10832         cmdline_fixed_string_t flow_director_mask;
10833         portid_t port_id;
10834         cmdline_fixed_string_t mode;
10835         cmdline_fixed_string_t mode_value;
10836         cmdline_fixed_string_t vlan;
10837         uint16_t vlan_mask;
10838         cmdline_fixed_string_t src_mask;
10839         cmdline_ipaddr_t ipv4_src;
10840         cmdline_ipaddr_t ipv6_src;
10841         uint16_t port_src;
10842         cmdline_fixed_string_t dst_mask;
10843         cmdline_ipaddr_t ipv4_dst;
10844         cmdline_ipaddr_t ipv6_dst;
10845         uint16_t port_dst;
10846         cmdline_fixed_string_t mac;
10847         uint8_t mac_addr_byte_mask;
10848         cmdline_fixed_string_t tunnel_id;
10849         uint32_t tunnel_id_mask;
10850         cmdline_fixed_string_t tunnel_type;
10851         uint8_t tunnel_type_mask;
10852 };
10853
10854 static void
10855 cmd_flow_director_mask_parsed(void *parsed_result,
10856                           __attribute__((unused)) struct cmdline *cl,
10857                           __attribute__((unused)) void *data)
10858 {
10859         struct cmd_flow_director_mask_result *res = parsed_result;
10860         struct rte_eth_fdir_masks *mask;
10861         struct rte_port *port;
10862
10863         port = &ports[res->port_id];
10864         /** Check if the port is not started **/
10865         if (port->port_status != RTE_PORT_STOPPED) {
10866                 printf("Please stop port %d first\n", res->port_id);
10867                 return;
10868         }
10869
10870         mask = &port->dev_conf.fdir_conf.mask;
10871
10872         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10873                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10874                         printf("Please set mode to MAC-VLAN.\n");
10875                         return;
10876                 }
10877
10878                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10879         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10880                 if (strcmp(res->mode_value, "Tunnel")) {
10881                         printf("Please set mode to Tunnel.\n");
10882                         return;
10883                 }
10884
10885                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10886                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10887                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10888                 mask->tunnel_type_mask = res->tunnel_type_mask;
10889         } else {
10890                 if (strcmp(res->mode_value, "IP")) {
10891                         printf("Please set mode to IP.\n");
10892                         return;
10893                 }
10894
10895                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10896                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10897                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10898                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10899                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10900                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10901                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10902         }
10903
10904         cmd_reconfig_device_queue(res->port_id, 1, 1);
10905 }
10906
10907 cmdline_parse_token_string_t cmd_flow_director_mask =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10909                                  flow_director_mask, "flow_director_mask");
10910 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10911         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10912                               port_id, UINT16);
10913 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10914         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10915                                  vlan, "vlan");
10916 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10917         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10918                               vlan_mask, UINT16);
10919 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10920         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10921                                  src_mask, "src_mask");
10922 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10923         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10924                                  ipv4_src);
10925 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10926         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10927                                  ipv6_src);
10928 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10929         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10930                               port_src, UINT16);
10931 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10932         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10933                                  dst_mask, "dst_mask");
10934 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10935         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10936                                  ipv4_dst);
10937 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10938         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10939                                  ipv6_dst);
10940 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10941         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10942                               port_dst, UINT16);
10943
10944 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10945         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10946                                  mode, "mode");
10947 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10948         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10949                                  mode_value, "IP");
10950 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10951         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10952                                  mode_value, "MAC-VLAN");
10953 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10954         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10955                                  mode_value, "Tunnel");
10956 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10957         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10958                                  mac, "mac");
10959 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10960         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10961                               mac_addr_byte_mask, UINT8);
10962 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10963         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10964                                  tunnel_type, "tunnel-type");
10965 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10966         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10967                               tunnel_type_mask, UINT8);
10968 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10969         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10970                                  tunnel_id, "tunnel-id");
10971 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10972         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10973                               tunnel_id_mask, UINT32);
10974
10975 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10976         .f = cmd_flow_director_mask_parsed,
10977         .data = NULL,
10978         .help_str = "flow_director_mask ... : "
10979                 "Set IP mode flow director's mask on NIC",
10980         .tokens = {
10981                 (void *)&cmd_flow_director_mask,
10982                 (void *)&cmd_flow_director_mask_port_id,
10983                 (void *)&cmd_flow_director_mask_mode,
10984                 (void *)&cmd_flow_director_mask_mode_ip,
10985                 (void *)&cmd_flow_director_mask_vlan,
10986                 (void *)&cmd_flow_director_mask_vlan_value,
10987                 (void *)&cmd_flow_director_mask_src,
10988                 (void *)&cmd_flow_director_mask_ipv4_src,
10989                 (void *)&cmd_flow_director_mask_ipv6_src,
10990                 (void *)&cmd_flow_director_mask_port_src,
10991                 (void *)&cmd_flow_director_mask_dst,
10992                 (void *)&cmd_flow_director_mask_ipv4_dst,
10993                 (void *)&cmd_flow_director_mask_ipv6_dst,
10994                 (void *)&cmd_flow_director_mask_port_dst,
10995                 NULL,
10996         },
10997 };
10998
10999 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11000         .f = cmd_flow_director_mask_parsed,
11001         .data = NULL,
11002         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11003                 "flow director's mask on NIC",
11004         .tokens = {
11005                 (void *)&cmd_flow_director_mask,
11006                 (void *)&cmd_flow_director_mask_port_id,
11007                 (void *)&cmd_flow_director_mask_mode,
11008                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11009                 (void *)&cmd_flow_director_mask_vlan,
11010                 (void *)&cmd_flow_director_mask_vlan_value,
11011                 NULL,
11012         },
11013 };
11014
11015 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11016         .f = cmd_flow_director_mask_parsed,
11017         .data = NULL,
11018         .help_str = "flow_director_mask ... : Set tunnel mode "
11019                 "flow director's mask on NIC",
11020         .tokens = {
11021                 (void *)&cmd_flow_director_mask,
11022                 (void *)&cmd_flow_director_mask_port_id,
11023                 (void *)&cmd_flow_director_mask_mode,
11024                 (void *)&cmd_flow_director_mask_mode_tunnel,
11025                 (void *)&cmd_flow_director_mask_vlan,
11026                 (void *)&cmd_flow_director_mask_vlan_value,
11027                 (void *)&cmd_flow_director_mask_mac,
11028                 (void *)&cmd_flow_director_mask_mac_value,
11029                 (void *)&cmd_flow_director_mask_tunnel_type,
11030                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11031                 (void *)&cmd_flow_director_mask_tunnel_id,
11032                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11033                 NULL,
11034         },
11035 };
11036
11037 /* *** deal with flow director mask on flexible payload *** */
11038 struct cmd_flow_director_flex_mask_result {
11039         cmdline_fixed_string_t flow_director_flexmask;
11040         portid_t port_id;
11041         cmdline_fixed_string_t flow;
11042         cmdline_fixed_string_t flow_type;
11043         cmdline_fixed_string_t mask;
11044 };
11045
11046 static void
11047 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11048                           __attribute__((unused)) struct cmdline *cl,
11049                           __attribute__((unused)) void *data)
11050 {
11051         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11052         struct rte_eth_fdir_info fdir_info;
11053         struct rte_eth_fdir_flex_mask flex_mask;
11054         struct rte_port *port;
11055         uint64_t flow_type_mask;
11056         uint16_t i;
11057         int ret;
11058
11059         port = &ports[res->port_id];
11060         /** Check if the port is not started **/
11061         if (port->port_status != RTE_PORT_STOPPED) {
11062                 printf("Please stop port %d first\n", res->port_id);
11063                 return;
11064         }
11065
11066         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11067         ret = parse_flexbytes(res->mask,
11068                         flex_mask.mask,
11069                         RTE_ETH_FDIR_MAX_FLEXLEN);
11070         if (ret < 0) {
11071                 printf("error: Cannot parse mask input.\n");
11072                 return;
11073         }
11074
11075         memset(&fdir_info, 0, sizeof(fdir_info));
11076         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11077                                 RTE_ETH_FILTER_INFO, &fdir_info);
11078         if (ret < 0) {
11079                 printf("Cannot get FDir filter info\n");
11080                 return;
11081         }
11082
11083         if (!strcmp(res->flow_type, "none")) {
11084                 /* means don't specify the flow type */
11085                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11086                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11087                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11088                                0, sizeof(struct rte_eth_fdir_flex_mask));
11089                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11090                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11091                                  &flex_mask,
11092                                  sizeof(struct rte_eth_fdir_flex_mask));
11093                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11094                 return;
11095         }
11096         flow_type_mask = fdir_info.flow_types_mask[0];
11097         if (!strcmp(res->flow_type, "all")) {
11098                 if (!flow_type_mask) {
11099                         printf("No flow type supported\n");
11100                         return;
11101                 }
11102                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11103                         if (flow_type_mask & (1ULL << i)) {
11104                                 flex_mask.flow_type = i;
11105                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11106                         }
11107                 }
11108                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11109                 return;
11110         }
11111         flex_mask.flow_type = str2flowtype(res->flow_type);
11112         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11113                 printf("Flow type %s not supported on port %d\n",
11114                                 res->flow_type, res->port_id);
11115                 return;
11116         }
11117         fdir_set_flex_mask(res->port_id, &flex_mask);
11118         cmd_reconfig_device_queue(res->port_id, 1, 1);
11119 }
11120
11121 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11122         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11123                                  flow_director_flexmask,
11124                                  "flow_director_flex_mask");
11125 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11126         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11127                               port_id, UINT16);
11128 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11129         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11130                                  flow, "flow");
11131 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11132         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11133                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11134                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11135 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11136         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11137                                  mask, NULL);
11138
11139 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11140         .f = cmd_flow_director_flex_mask_parsed,
11141         .data = NULL,
11142         .help_str = "flow_director_flex_mask ... : "
11143                 "Set flow director's flex mask on NIC",
11144         .tokens = {
11145                 (void *)&cmd_flow_director_flexmask,
11146                 (void *)&cmd_flow_director_flexmask_port_id,
11147                 (void *)&cmd_flow_director_flexmask_flow,
11148                 (void *)&cmd_flow_director_flexmask_flow_type,
11149                 (void *)&cmd_flow_director_flexmask_mask,
11150                 NULL,
11151         },
11152 };
11153
11154 /* *** deal with flow director flexible payload configuration *** */
11155 struct cmd_flow_director_flexpayload_result {
11156         cmdline_fixed_string_t flow_director_flexpayload;
11157         portid_t port_id;
11158         cmdline_fixed_string_t payload_layer;
11159         cmdline_fixed_string_t payload_cfg;
11160 };
11161
11162 static inline int
11163 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11164 {
11165         char s[256];
11166         const char *p, *p0 = q_arg;
11167         char *end;
11168         unsigned long int_fld;
11169         char *str_fld[max_num];
11170         int i;
11171         unsigned size;
11172         int ret = -1;
11173
11174         p = strchr(p0, '(');
11175         if (p == NULL)
11176                 return -1;
11177         ++p;
11178         p0 = strchr(p, ')');
11179         if (p0 == NULL)
11180                 return -1;
11181
11182         size = p0 - p;
11183         if (size >= sizeof(s))
11184                 return -1;
11185
11186         snprintf(s, sizeof(s), "%.*s", size, p);
11187         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11188         if (ret < 0 || ret > max_num)
11189                 return -1;
11190         for (i = 0; i < ret; i++) {
11191                 errno = 0;
11192                 int_fld = strtoul(str_fld[i], &end, 0);
11193                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11194                         return -1;
11195                 offsets[i] = (uint16_t)int_fld;
11196         }
11197         return ret;
11198 }
11199
11200 static void
11201 cmd_flow_director_flxpld_parsed(void *parsed_result,
11202                           __attribute__((unused)) struct cmdline *cl,
11203                           __attribute__((unused)) void *data)
11204 {
11205         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11206         struct rte_eth_flex_payload_cfg flex_cfg;
11207         struct rte_port *port;
11208         int ret = 0;
11209
11210         port = &ports[res->port_id];
11211         /** Check if the port is not started **/
11212         if (port->port_status != RTE_PORT_STOPPED) {
11213                 printf("Please stop port %d first\n", res->port_id);
11214                 return;
11215         }
11216
11217         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11218
11219         if (!strcmp(res->payload_layer, "raw"))
11220                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11221         else if (!strcmp(res->payload_layer, "l2"))
11222                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11223         else if (!strcmp(res->payload_layer, "l3"))
11224                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11225         else if (!strcmp(res->payload_layer, "l4"))
11226                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11227
11228         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11229                             RTE_ETH_FDIR_MAX_FLEXLEN);
11230         if (ret < 0) {
11231                 printf("error: Cannot parse flex payload input.\n");
11232                 return;
11233         }
11234
11235         fdir_set_flex_payload(res->port_id, &flex_cfg);
11236         cmd_reconfig_device_queue(res->port_id, 1, 1);
11237 }
11238
11239 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11241                                  flow_director_flexpayload,
11242                                  "flow_director_flex_payload");
11243 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11244         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11245                               port_id, UINT16);
11246 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11248                                  payload_layer, "raw#l2#l3#l4");
11249 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11251                                  payload_cfg, NULL);
11252
11253 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11254         .f = cmd_flow_director_flxpld_parsed,
11255         .data = NULL,
11256         .help_str = "flow_director_flexpayload ... : "
11257                 "Set flow director's flex payload on NIC",
11258         .tokens = {
11259                 (void *)&cmd_flow_director_flexpayload,
11260                 (void *)&cmd_flow_director_flexpayload_port_id,
11261                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11262                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11263                 NULL,
11264         },
11265 };
11266
11267 /* Generic flow interface command. */
11268 extern cmdline_parse_inst_t cmd_flow;
11269
11270 /* *** Classification Filters Control *** */
11271 /* *** Get symmetric hash enable per port *** */
11272 struct cmd_get_sym_hash_ena_per_port_result {
11273         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11274         portid_t port_id;
11275 };
11276
11277 static void
11278 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11279                                  __rte_unused struct cmdline *cl,
11280                                  __rte_unused void *data)
11281 {
11282         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11283         struct rte_eth_hash_filter_info info;
11284         int ret;
11285
11286         if (rte_eth_dev_filter_supported(res->port_id,
11287                                 RTE_ETH_FILTER_HASH) < 0) {
11288                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11289                                                         res->port_id);
11290                 return;
11291         }
11292
11293         memset(&info, 0, sizeof(info));
11294         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11295         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11296                                                 RTE_ETH_FILTER_GET, &info);
11297
11298         if (ret < 0) {
11299                 printf("Cannot get symmetric hash enable per port "
11300                                         "on port %u\n", res->port_id);
11301                 return;
11302         }
11303
11304         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11305                                 "enabled" : "disabled", res->port_id);
11306 }
11307
11308 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11309         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11310                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11311 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11312         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11313                 port_id, UINT16);
11314
11315 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11316         .f = cmd_get_sym_hash_per_port_parsed,
11317         .data = NULL,
11318         .help_str = "get_sym_hash_ena_per_port <port_id>",
11319         .tokens = {
11320                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11321                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11322                 NULL,
11323         },
11324 };
11325
11326 /* *** Set symmetric hash enable per port *** */
11327 struct cmd_set_sym_hash_ena_per_port_result {
11328         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11329         cmdline_fixed_string_t enable;
11330         portid_t port_id;
11331 };
11332
11333 static void
11334 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11335                                  __rte_unused struct cmdline *cl,
11336                                  __rte_unused void *data)
11337 {
11338         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11339         struct rte_eth_hash_filter_info info;
11340         int ret;
11341
11342         if (rte_eth_dev_filter_supported(res->port_id,
11343                                 RTE_ETH_FILTER_HASH) < 0) {
11344                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11345                                                         res->port_id);
11346                 return;
11347         }
11348
11349         memset(&info, 0, sizeof(info));
11350         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11351         if (!strcmp(res->enable, "enable"))
11352                 info.info.enable = 1;
11353         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11354                                         RTE_ETH_FILTER_SET, &info);
11355         if (ret < 0) {
11356                 printf("Cannot set symmetric hash enable per port on "
11357                                         "port %u\n", res->port_id);
11358                 return;
11359         }
11360         printf("Symmetric hash has been set to %s on port %u\n",
11361                                         res->enable, res->port_id);
11362 }
11363
11364 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11365         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11366                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11367 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11368         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11369                 port_id, UINT16);
11370 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11371         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11372                 enable, "enable#disable");
11373
11374 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11375         .f = cmd_set_sym_hash_per_port_parsed,
11376         .data = NULL,
11377         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11378         .tokens = {
11379                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11380                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11381                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11382                 NULL,
11383         },
11384 };
11385
11386 /* Get global config of hash function */
11387 struct cmd_get_hash_global_config_result {
11388         cmdline_fixed_string_t get_hash_global_config;
11389         portid_t port_id;
11390 };
11391
11392 static char *
11393 flowtype_to_str(uint16_t ftype)
11394 {
11395         uint16_t i;
11396         static struct {
11397                 char str[16];
11398                 uint16_t ftype;
11399         } ftype_table[] = {
11400                 {"ipv4", RTE_ETH_FLOW_IPV4},
11401                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11402                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11403                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11404                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11405                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11406                 {"ipv6", RTE_ETH_FLOW_IPV6},
11407                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11408                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11409                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11410                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11411                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11412                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11413                 {"port", RTE_ETH_FLOW_PORT},
11414                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11415                 {"geneve", RTE_ETH_FLOW_GENEVE},
11416                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11417         };
11418
11419         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11420                 if (ftype_table[i].ftype == ftype)
11421                         return ftype_table[i].str;
11422         }
11423
11424         return NULL;
11425 }
11426
11427 static void
11428 cmd_get_hash_global_config_parsed(void *parsed_result,
11429                                   __rte_unused struct cmdline *cl,
11430                                   __rte_unused void *data)
11431 {
11432         struct cmd_get_hash_global_config_result *res = parsed_result;
11433         struct rte_eth_hash_filter_info info;
11434         uint32_t idx, offset;
11435         uint16_t i;
11436         char *str;
11437         int ret;
11438
11439         if (rte_eth_dev_filter_supported(res->port_id,
11440                         RTE_ETH_FILTER_HASH) < 0) {
11441                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11442                                                         res->port_id);
11443                 return;
11444         }
11445
11446         memset(&info, 0, sizeof(info));
11447         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11448         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11449                                         RTE_ETH_FILTER_GET, &info);
11450         if (ret < 0) {
11451                 printf("Cannot get hash global configurations by port %d\n",
11452                                                         res->port_id);
11453                 return;
11454         }
11455
11456         switch (info.info.global_conf.hash_func) {
11457         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11458                 printf("Hash function is Toeplitz\n");
11459                 break;
11460         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11461                 printf("Hash function is Simple XOR\n");
11462                 break;
11463         default:
11464                 printf("Unknown hash function\n");
11465                 break;
11466         }
11467
11468         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11469                 idx = i / UINT64_BIT;
11470                 offset = i % UINT64_BIT;
11471                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11472                                                 (1ULL << offset)))
11473                         continue;
11474                 str = flowtype_to_str(i);
11475                 if (!str)
11476                         continue;
11477                 printf("Symmetric hash is %s globally for flow type %s "
11478                                                         "by port %d\n",
11479                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11480                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11481                                                         res->port_id);
11482         }
11483 }
11484
11485 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11486         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11487                 get_hash_global_config, "get_hash_global_config");
11488 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11489         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11490                 port_id, UINT16);
11491
11492 cmdline_parse_inst_t cmd_get_hash_global_config = {
11493         .f = cmd_get_hash_global_config_parsed,
11494         .data = NULL,
11495         .help_str = "get_hash_global_config <port_id>",
11496         .tokens = {
11497                 (void *)&cmd_get_hash_global_config_all,
11498                 (void *)&cmd_get_hash_global_config_port_id,
11499                 NULL,
11500         },
11501 };
11502
11503 /* Set global config of hash function */
11504 struct cmd_set_hash_global_config_result {
11505         cmdline_fixed_string_t set_hash_global_config;
11506         portid_t port_id;
11507         cmdline_fixed_string_t hash_func;
11508         cmdline_fixed_string_t flow_type;
11509         cmdline_fixed_string_t enable;
11510 };
11511
11512 static void
11513 cmd_set_hash_global_config_parsed(void *parsed_result,
11514                                   __rte_unused struct cmdline *cl,
11515                                   __rte_unused void *data)
11516 {
11517         struct cmd_set_hash_global_config_result *res = parsed_result;
11518         struct rte_eth_hash_filter_info info;
11519         uint32_t ftype, idx, offset;
11520         int ret;
11521
11522         if (rte_eth_dev_filter_supported(res->port_id,
11523                                 RTE_ETH_FILTER_HASH) < 0) {
11524                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11525                                                         res->port_id);
11526                 return;
11527         }
11528         memset(&info, 0, sizeof(info));
11529         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11530         if (!strcmp(res->hash_func, "toeplitz"))
11531                 info.info.global_conf.hash_func =
11532                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11533         else if (!strcmp(res->hash_func, "simple_xor"))
11534                 info.info.global_conf.hash_func =
11535                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11536         else if (!strcmp(res->hash_func, "default"))
11537                 info.info.global_conf.hash_func =
11538                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11539
11540         ftype = str2flowtype(res->flow_type);
11541         idx = ftype / UINT64_BIT;
11542         offset = ftype % UINT64_BIT;
11543         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11544         if (!strcmp(res->enable, "enable"))
11545                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11546                                                 (1ULL << offset);
11547         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11548                                         RTE_ETH_FILTER_SET, &info);
11549         if (ret < 0)
11550                 printf("Cannot set global hash configurations by port %d\n",
11551                                                         res->port_id);
11552         else
11553                 printf("Global hash configurations have been set "
11554                         "succcessfully by port %d\n", res->port_id);
11555 }
11556
11557 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11558         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11559                 set_hash_global_config, "set_hash_global_config");
11560 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11561         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11562                 port_id, UINT16);
11563 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11564         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11565                 hash_func, "toeplitz#simple_xor#default");
11566 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11567         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11568                 flow_type,
11569                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11570                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11571 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11572         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11573                 enable, "enable#disable");
11574
11575 cmdline_parse_inst_t cmd_set_hash_global_config = {
11576         .f = cmd_set_hash_global_config_parsed,
11577         .data = NULL,
11578         .help_str = "set_hash_global_config <port_id> "
11579                 "toeplitz|simple_xor|default "
11580                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11581                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11582                 "l2_payload enable|disable",
11583         .tokens = {
11584                 (void *)&cmd_set_hash_global_config_all,
11585                 (void *)&cmd_set_hash_global_config_port_id,
11586                 (void *)&cmd_set_hash_global_config_hash_func,
11587                 (void *)&cmd_set_hash_global_config_flow_type,
11588                 (void *)&cmd_set_hash_global_config_enable,
11589                 NULL,
11590         },
11591 };
11592
11593 /* Set hash input set */
11594 struct cmd_set_hash_input_set_result {
11595         cmdline_fixed_string_t set_hash_input_set;
11596         portid_t port_id;
11597         cmdline_fixed_string_t flow_type;
11598         cmdline_fixed_string_t inset_field;
11599         cmdline_fixed_string_t select;
11600 };
11601
11602 static enum rte_eth_input_set_field
11603 str2inset(char *string)
11604 {
11605         uint16_t i;
11606
11607         static const struct {
11608                 char str[32];
11609                 enum rte_eth_input_set_field inset;
11610         } inset_table[] = {
11611                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11612                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11613                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11614                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11615                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11616                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11617                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11618                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11619                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11620                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11621                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11622                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11623                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11624                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11625                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11626                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11627                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11628                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11629                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11630                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11631                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11632                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11633                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11634                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11635                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11636                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11637                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11638                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11639                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11640                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11641                 {"none", RTE_ETH_INPUT_SET_NONE},
11642         };
11643
11644         for (i = 0; i < RTE_DIM(inset_table); i++) {
11645                 if (!strcmp(string, inset_table[i].str))
11646                         return inset_table[i].inset;
11647         }
11648
11649         return RTE_ETH_INPUT_SET_UNKNOWN;
11650 }
11651
11652 static void
11653 cmd_set_hash_input_set_parsed(void *parsed_result,
11654                               __rte_unused struct cmdline *cl,
11655                               __rte_unused void *data)
11656 {
11657         struct cmd_set_hash_input_set_result *res = parsed_result;
11658         struct rte_eth_hash_filter_info info;
11659
11660         memset(&info, 0, sizeof(info));
11661         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11662         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11663         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11664         info.info.input_set_conf.inset_size = 1;
11665         if (!strcmp(res->select, "select"))
11666                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11667         else if (!strcmp(res->select, "add"))
11668                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11669         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11670                                 RTE_ETH_FILTER_SET, &info);
11671 }
11672
11673 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11674         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11675                 set_hash_input_set, "set_hash_input_set");
11676 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11677         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11678                 port_id, UINT16);
11679 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11680         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11681                 flow_type, NULL);
11682 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11683         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11684                 inset_field,
11685                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11686                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11687                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11688                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11689                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11690                 "fld-8th#none");
11691 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11692         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11693                 select, "select#add");
11694
11695 cmdline_parse_inst_t cmd_set_hash_input_set = {
11696         .f = cmd_set_hash_input_set_parsed,
11697         .data = NULL,
11698         .help_str = "set_hash_input_set <port_id> "
11699         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11700         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11701         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11702         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11703         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11704         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11705         "fld-7th|fld-8th|none select|add",
11706         .tokens = {
11707                 (void *)&cmd_set_hash_input_set_cmd,
11708                 (void *)&cmd_set_hash_input_set_port_id,
11709                 (void *)&cmd_set_hash_input_set_flow_type,
11710                 (void *)&cmd_set_hash_input_set_field,
11711                 (void *)&cmd_set_hash_input_set_select,
11712                 NULL,
11713         },
11714 };
11715
11716 /* Set flow director input set */
11717 struct cmd_set_fdir_input_set_result {
11718         cmdline_fixed_string_t set_fdir_input_set;
11719         portid_t port_id;
11720         cmdline_fixed_string_t flow_type;
11721         cmdline_fixed_string_t inset_field;
11722         cmdline_fixed_string_t select;
11723 };
11724
11725 static void
11726 cmd_set_fdir_input_set_parsed(void *parsed_result,
11727         __rte_unused struct cmdline *cl,
11728         __rte_unused void *data)
11729 {
11730         struct cmd_set_fdir_input_set_result *res = parsed_result;
11731         struct rte_eth_fdir_filter_info info;
11732
11733         memset(&info, 0, sizeof(info));
11734         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11735         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11736         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11737         info.info.input_set_conf.inset_size = 1;
11738         if (!strcmp(res->select, "select"))
11739                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11740         else if (!strcmp(res->select, "add"))
11741                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11742         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11743                 RTE_ETH_FILTER_SET, &info);
11744 }
11745
11746 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11747         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11748         set_fdir_input_set, "set_fdir_input_set");
11749 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11750         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11751         port_id, UINT16);
11752 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11753         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11754         flow_type,
11755         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11756         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11757 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11758         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11759         inset_field,
11760         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11761         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11762         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11763         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11764         "sctp-veri-tag#none");
11765 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11766         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11767         select, "select#add");
11768
11769 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11770         .f = cmd_set_fdir_input_set_parsed,
11771         .data = NULL,
11772         .help_str = "set_fdir_input_set <port_id> "
11773         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11774         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11775         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11776         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11777         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11778         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11779         "sctp-veri-tag|none select|add",
11780         .tokens = {
11781                 (void *)&cmd_set_fdir_input_set_cmd,
11782                 (void *)&cmd_set_fdir_input_set_port_id,
11783                 (void *)&cmd_set_fdir_input_set_flow_type,
11784                 (void *)&cmd_set_fdir_input_set_field,
11785                 (void *)&cmd_set_fdir_input_set_select,
11786                 NULL,
11787         },
11788 };
11789
11790 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11791 struct cmd_mcast_addr_result {
11792         cmdline_fixed_string_t mcast_addr_cmd;
11793         cmdline_fixed_string_t what;
11794         uint16_t port_num;
11795         struct ether_addr mc_addr;
11796 };
11797
11798 static void cmd_mcast_addr_parsed(void *parsed_result,
11799                 __attribute__((unused)) struct cmdline *cl,
11800                 __attribute__((unused)) void *data)
11801 {
11802         struct cmd_mcast_addr_result *res = parsed_result;
11803
11804         if (!is_multicast_ether_addr(&res->mc_addr)) {
11805                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11806                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11807                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11808                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11809                 return;
11810         }
11811         if (strcmp(res->what, "add") == 0)
11812                 mcast_addr_add(res->port_num, &res->mc_addr);
11813         else
11814                 mcast_addr_remove(res->port_num, &res->mc_addr);
11815 }
11816
11817 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11818         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11819                                  mcast_addr_cmd, "mcast_addr");
11820 cmdline_parse_token_string_t cmd_mcast_addr_what =
11821         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11822                                  "add#remove");
11823 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11824         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11825 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11826         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11827
11828 cmdline_parse_inst_t cmd_mcast_addr = {
11829         .f = cmd_mcast_addr_parsed,
11830         .data = (void *)0,
11831         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11832                 "Add/Remove multicast MAC address on port_id",
11833         .tokens = {
11834                 (void *)&cmd_mcast_addr_cmd,
11835                 (void *)&cmd_mcast_addr_what,
11836                 (void *)&cmd_mcast_addr_portnum,
11837                 (void *)&cmd_mcast_addr_addr,
11838                 NULL,
11839         },
11840 };
11841
11842 /* l2 tunnel config
11843  * only support E-tag now.
11844  */
11845
11846 /* Ether type config */
11847 struct cmd_config_l2_tunnel_eth_type_result {
11848         cmdline_fixed_string_t port;
11849         cmdline_fixed_string_t config;
11850         cmdline_fixed_string_t all;
11851         uint8_t id;
11852         cmdline_fixed_string_t l2_tunnel;
11853         cmdline_fixed_string_t l2_tunnel_type;
11854         cmdline_fixed_string_t eth_type;
11855         uint16_t eth_type_val;
11856 };
11857
11858 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11859         TOKEN_STRING_INITIALIZER
11860                 (struct cmd_config_l2_tunnel_eth_type_result,
11861                  port, "port");
11862 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11863         TOKEN_STRING_INITIALIZER
11864                 (struct cmd_config_l2_tunnel_eth_type_result,
11865                  config, "config");
11866 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11867         TOKEN_STRING_INITIALIZER
11868                 (struct cmd_config_l2_tunnel_eth_type_result,
11869                  all, "all");
11870 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11871         TOKEN_NUM_INITIALIZER
11872                 (struct cmd_config_l2_tunnel_eth_type_result,
11873                  id, UINT8);
11874 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11875         TOKEN_STRING_INITIALIZER
11876                 (struct cmd_config_l2_tunnel_eth_type_result,
11877                  l2_tunnel, "l2-tunnel");
11878 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11879         TOKEN_STRING_INITIALIZER
11880                 (struct cmd_config_l2_tunnel_eth_type_result,
11881                  l2_tunnel_type, "E-tag");
11882 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11883         TOKEN_STRING_INITIALIZER
11884                 (struct cmd_config_l2_tunnel_eth_type_result,
11885                  eth_type, "ether-type");
11886 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11887         TOKEN_NUM_INITIALIZER
11888                 (struct cmd_config_l2_tunnel_eth_type_result,
11889                  eth_type_val, UINT16);
11890
11891 static enum rte_eth_tunnel_type
11892 str2fdir_l2_tunnel_type(char *string)
11893 {
11894         uint32_t i = 0;
11895
11896         static const struct {
11897                 char str[32];
11898                 enum rte_eth_tunnel_type type;
11899         } l2_tunnel_type_str[] = {
11900                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11901         };
11902
11903         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11904                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11905                         return l2_tunnel_type_str[i].type;
11906         }
11907         return RTE_TUNNEL_TYPE_NONE;
11908 }
11909
11910 /* ether type config for all ports */
11911 static void
11912 cmd_config_l2_tunnel_eth_type_all_parsed
11913         (void *parsed_result,
11914          __attribute__((unused)) struct cmdline *cl,
11915          __attribute__((unused)) void *data)
11916 {
11917         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11918         struct rte_eth_l2_tunnel_conf entry;
11919         portid_t pid;
11920
11921         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11922         entry.ether_type = res->eth_type_val;
11923
11924         RTE_ETH_FOREACH_DEV(pid) {
11925                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11926         }
11927 }
11928
11929 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11930         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11931         .data = NULL,
11932         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11933         .tokens = {
11934                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11935                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11936                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11937                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11938                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11939                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11940                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11941                 NULL,
11942         },
11943 };
11944
11945 /* ether type config for a specific port */
11946 static void
11947 cmd_config_l2_tunnel_eth_type_specific_parsed(
11948         void *parsed_result,
11949         __attribute__((unused)) struct cmdline *cl,
11950         __attribute__((unused)) void *data)
11951 {
11952         struct cmd_config_l2_tunnel_eth_type_result *res =
11953                  parsed_result;
11954         struct rte_eth_l2_tunnel_conf entry;
11955
11956         if (port_id_is_invalid(res->id, ENABLED_WARN))
11957                 return;
11958
11959         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11960         entry.ether_type = res->eth_type_val;
11961
11962         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11963 }
11964
11965 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11966         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11967         .data = NULL,
11968         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11969         .tokens = {
11970                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11971                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11972                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11973                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11974                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11975                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11976                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11977                 NULL,
11978         },
11979 };
11980
11981 /* Enable/disable l2 tunnel */
11982 struct cmd_config_l2_tunnel_en_dis_result {
11983         cmdline_fixed_string_t port;
11984         cmdline_fixed_string_t config;
11985         cmdline_fixed_string_t all;
11986         uint8_t id;
11987         cmdline_fixed_string_t l2_tunnel;
11988         cmdline_fixed_string_t l2_tunnel_type;
11989         cmdline_fixed_string_t en_dis;
11990 };
11991
11992 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11993         TOKEN_STRING_INITIALIZER
11994                 (struct cmd_config_l2_tunnel_en_dis_result,
11995                  port, "port");
11996 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11997         TOKEN_STRING_INITIALIZER
11998                 (struct cmd_config_l2_tunnel_en_dis_result,
11999                  config, "config");
12000 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12001         TOKEN_STRING_INITIALIZER
12002                 (struct cmd_config_l2_tunnel_en_dis_result,
12003                  all, "all");
12004 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12005         TOKEN_NUM_INITIALIZER
12006                 (struct cmd_config_l2_tunnel_en_dis_result,
12007                  id, UINT8);
12008 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12009         TOKEN_STRING_INITIALIZER
12010                 (struct cmd_config_l2_tunnel_en_dis_result,
12011                  l2_tunnel, "l2-tunnel");
12012 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12013         TOKEN_STRING_INITIALIZER
12014                 (struct cmd_config_l2_tunnel_en_dis_result,
12015                  l2_tunnel_type, "E-tag");
12016 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12017         TOKEN_STRING_INITIALIZER
12018                 (struct cmd_config_l2_tunnel_en_dis_result,
12019                  en_dis, "enable#disable");
12020
12021 /* enable/disable l2 tunnel for all ports */
12022 static void
12023 cmd_config_l2_tunnel_en_dis_all_parsed(
12024         void *parsed_result,
12025         __attribute__((unused)) struct cmdline *cl,
12026         __attribute__((unused)) void *data)
12027 {
12028         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12029         struct rte_eth_l2_tunnel_conf entry;
12030         portid_t pid;
12031         uint8_t en;
12032
12033         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12034
12035         if (!strcmp("enable", res->en_dis))
12036                 en = 1;
12037         else
12038                 en = 0;
12039
12040         RTE_ETH_FOREACH_DEV(pid) {
12041                 rte_eth_dev_l2_tunnel_offload_set(pid,
12042                                                   &entry,
12043                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12044                                                   en);
12045         }
12046 }
12047
12048 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12049         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12050         .data = NULL,
12051         .help_str = "port config all l2-tunnel E-tag enable|disable",
12052         .tokens = {
12053                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12054                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12055                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12056                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12057                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12058                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12059                 NULL,
12060         },
12061 };
12062
12063 /* enable/disable l2 tunnel for a port */
12064 static void
12065 cmd_config_l2_tunnel_en_dis_specific_parsed(
12066         void *parsed_result,
12067         __attribute__((unused)) struct cmdline *cl,
12068         __attribute__((unused)) void *data)
12069 {
12070         struct cmd_config_l2_tunnel_en_dis_result *res =
12071                 parsed_result;
12072         struct rte_eth_l2_tunnel_conf entry;
12073
12074         if (port_id_is_invalid(res->id, ENABLED_WARN))
12075                 return;
12076
12077         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12078
12079         if (!strcmp("enable", res->en_dis))
12080                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12081                                                   &entry,
12082                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12083                                                   1);
12084         else
12085                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12086                                                   &entry,
12087                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12088                                                   0);
12089 }
12090
12091 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12092         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12093         .data = NULL,
12094         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12095         .tokens = {
12096                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12097                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12098                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12099                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12100                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12101                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12102                 NULL,
12103         },
12104 };
12105
12106 /* E-tag configuration */
12107
12108 /* Common result structure for all E-tag configuration */
12109 struct cmd_config_e_tag_result {
12110         cmdline_fixed_string_t e_tag;
12111         cmdline_fixed_string_t set;
12112         cmdline_fixed_string_t insertion;
12113         cmdline_fixed_string_t stripping;
12114         cmdline_fixed_string_t forwarding;
12115         cmdline_fixed_string_t filter;
12116         cmdline_fixed_string_t add;
12117         cmdline_fixed_string_t del;
12118         cmdline_fixed_string_t on;
12119         cmdline_fixed_string_t off;
12120         cmdline_fixed_string_t on_off;
12121         cmdline_fixed_string_t port_tag_id;
12122         uint32_t port_tag_id_val;
12123         cmdline_fixed_string_t e_tag_id;
12124         uint16_t e_tag_id_val;
12125         cmdline_fixed_string_t dst_pool;
12126         uint8_t dst_pool_val;
12127         cmdline_fixed_string_t port;
12128         portid_t port_id;
12129         cmdline_fixed_string_t vf;
12130         uint8_t vf_id;
12131 };
12132
12133 /* Common CLI fields for all E-tag configuration */
12134 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12135         TOKEN_STRING_INITIALIZER
12136                 (struct cmd_config_e_tag_result,
12137                  e_tag, "E-tag");
12138 cmdline_parse_token_string_t cmd_config_e_tag_set =
12139         TOKEN_STRING_INITIALIZER
12140                 (struct cmd_config_e_tag_result,
12141                  set, "set");
12142 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12143         TOKEN_STRING_INITIALIZER
12144                 (struct cmd_config_e_tag_result,
12145                  insertion, "insertion");
12146 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12147         TOKEN_STRING_INITIALIZER
12148                 (struct cmd_config_e_tag_result,
12149                  stripping, "stripping");
12150 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12151         TOKEN_STRING_INITIALIZER
12152                 (struct cmd_config_e_tag_result,
12153                  forwarding, "forwarding");
12154 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12155         TOKEN_STRING_INITIALIZER
12156                 (struct cmd_config_e_tag_result,
12157                  filter, "filter");
12158 cmdline_parse_token_string_t cmd_config_e_tag_add =
12159         TOKEN_STRING_INITIALIZER
12160                 (struct cmd_config_e_tag_result,
12161                  add, "add");
12162 cmdline_parse_token_string_t cmd_config_e_tag_del =
12163         TOKEN_STRING_INITIALIZER
12164                 (struct cmd_config_e_tag_result,
12165                  del, "del");
12166 cmdline_parse_token_string_t cmd_config_e_tag_on =
12167         TOKEN_STRING_INITIALIZER
12168                 (struct cmd_config_e_tag_result,
12169                  on, "on");
12170 cmdline_parse_token_string_t cmd_config_e_tag_off =
12171         TOKEN_STRING_INITIALIZER
12172                 (struct cmd_config_e_tag_result,
12173                  off, "off");
12174 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12175         TOKEN_STRING_INITIALIZER
12176                 (struct cmd_config_e_tag_result,
12177                  on_off, "on#off");
12178 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12179         TOKEN_STRING_INITIALIZER
12180                 (struct cmd_config_e_tag_result,
12181                  port_tag_id, "port-tag-id");
12182 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12183         TOKEN_NUM_INITIALIZER
12184                 (struct cmd_config_e_tag_result,
12185                  port_tag_id_val, UINT32);
12186 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12187         TOKEN_STRING_INITIALIZER
12188                 (struct cmd_config_e_tag_result,
12189                  e_tag_id, "e-tag-id");
12190 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12191         TOKEN_NUM_INITIALIZER
12192                 (struct cmd_config_e_tag_result,
12193                  e_tag_id_val, UINT16);
12194 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12195         TOKEN_STRING_INITIALIZER
12196                 (struct cmd_config_e_tag_result,
12197                  dst_pool, "dst-pool");
12198 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12199         TOKEN_NUM_INITIALIZER
12200                 (struct cmd_config_e_tag_result,
12201                  dst_pool_val, UINT8);
12202 cmdline_parse_token_string_t cmd_config_e_tag_port =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_config_e_tag_result,
12205                  port, "port");
12206 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12207         TOKEN_NUM_INITIALIZER
12208                 (struct cmd_config_e_tag_result,
12209                  port_id, UINT16);
12210 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12211         TOKEN_STRING_INITIALIZER
12212                 (struct cmd_config_e_tag_result,
12213                  vf, "vf");
12214 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12215         TOKEN_NUM_INITIALIZER
12216                 (struct cmd_config_e_tag_result,
12217                  vf_id, UINT8);
12218
12219 /* E-tag insertion configuration */
12220 static void
12221 cmd_config_e_tag_insertion_en_parsed(
12222         void *parsed_result,
12223         __attribute__((unused)) struct cmdline *cl,
12224         __attribute__((unused)) void *data)
12225 {
12226         struct cmd_config_e_tag_result *res =
12227                 parsed_result;
12228         struct rte_eth_l2_tunnel_conf entry;
12229
12230         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12231                 return;
12232
12233         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12234         entry.tunnel_id = res->port_tag_id_val;
12235         entry.vf_id = res->vf_id;
12236         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12237                                           &entry,
12238                                           ETH_L2_TUNNEL_INSERTION_MASK,
12239                                           1);
12240 }
12241
12242 static void
12243 cmd_config_e_tag_insertion_dis_parsed(
12244         void *parsed_result,
12245         __attribute__((unused)) struct cmdline *cl,
12246         __attribute__((unused)) void *data)
12247 {
12248         struct cmd_config_e_tag_result *res =
12249                 parsed_result;
12250         struct rte_eth_l2_tunnel_conf entry;
12251
12252         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12253                 return;
12254
12255         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12256         entry.vf_id = res->vf_id;
12257
12258         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12259                                           &entry,
12260                                           ETH_L2_TUNNEL_INSERTION_MASK,
12261                                           0);
12262 }
12263
12264 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12265         .f = cmd_config_e_tag_insertion_en_parsed,
12266         .data = NULL,
12267         .help_str = "E-tag ... : E-tag insertion enable",
12268         .tokens = {
12269                 (void *)&cmd_config_e_tag_e_tag,
12270                 (void *)&cmd_config_e_tag_set,
12271                 (void *)&cmd_config_e_tag_insertion,
12272                 (void *)&cmd_config_e_tag_on,
12273                 (void *)&cmd_config_e_tag_port_tag_id,
12274                 (void *)&cmd_config_e_tag_port_tag_id_val,
12275                 (void *)&cmd_config_e_tag_port,
12276                 (void *)&cmd_config_e_tag_port_id,
12277                 (void *)&cmd_config_e_tag_vf,
12278                 (void *)&cmd_config_e_tag_vf_id,
12279                 NULL,
12280         },
12281 };
12282
12283 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12284         .f = cmd_config_e_tag_insertion_dis_parsed,
12285         .data = NULL,
12286         .help_str = "E-tag ... : E-tag insertion disable",
12287         .tokens = {
12288                 (void *)&cmd_config_e_tag_e_tag,
12289                 (void *)&cmd_config_e_tag_set,
12290                 (void *)&cmd_config_e_tag_insertion,
12291                 (void *)&cmd_config_e_tag_off,
12292                 (void *)&cmd_config_e_tag_port,
12293                 (void *)&cmd_config_e_tag_port_id,
12294                 (void *)&cmd_config_e_tag_vf,
12295                 (void *)&cmd_config_e_tag_vf_id,
12296                 NULL,
12297         },
12298 };
12299
12300 /* E-tag stripping configuration */
12301 static void
12302 cmd_config_e_tag_stripping_parsed(
12303         void *parsed_result,
12304         __attribute__((unused)) struct cmdline *cl,
12305         __attribute__((unused)) void *data)
12306 {
12307         struct cmd_config_e_tag_result *res =
12308                 parsed_result;
12309         struct rte_eth_l2_tunnel_conf entry;
12310
12311         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12312                 return;
12313
12314         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12315
12316         if (!strcmp(res->on_off, "on"))
12317                 rte_eth_dev_l2_tunnel_offload_set
12318                         (res->port_id,
12319                          &entry,
12320                          ETH_L2_TUNNEL_STRIPPING_MASK,
12321                          1);
12322         else
12323                 rte_eth_dev_l2_tunnel_offload_set
12324                         (res->port_id,
12325                          &entry,
12326                          ETH_L2_TUNNEL_STRIPPING_MASK,
12327                          0);
12328 }
12329
12330 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12331         .f = cmd_config_e_tag_stripping_parsed,
12332         .data = NULL,
12333         .help_str = "E-tag ... : E-tag stripping enable/disable",
12334         .tokens = {
12335                 (void *)&cmd_config_e_tag_e_tag,
12336                 (void *)&cmd_config_e_tag_set,
12337                 (void *)&cmd_config_e_tag_stripping,
12338                 (void *)&cmd_config_e_tag_on_off,
12339                 (void *)&cmd_config_e_tag_port,
12340                 (void *)&cmd_config_e_tag_port_id,
12341                 NULL,
12342         },
12343 };
12344
12345 /* E-tag forwarding configuration */
12346 static void
12347 cmd_config_e_tag_forwarding_parsed(
12348         void *parsed_result,
12349         __attribute__((unused)) struct cmdline *cl,
12350         __attribute__((unused)) void *data)
12351 {
12352         struct cmd_config_e_tag_result *res = parsed_result;
12353         struct rte_eth_l2_tunnel_conf entry;
12354
12355         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12356                 return;
12357
12358         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12359
12360         if (!strcmp(res->on_off, "on"))
12361                 rte_eth_dev_l2_tunnel_offload_set
12362                         (res->port_id,
12363                          &entry,
12364                          ETH_L2_TUNNEL_FORWARDING_MASK,
12365                          1);
12366         else
12367                 rte_eth_dev_l2_tunnel_offload_set
12368                         (res->port_id,
12369                          &entry,
12370                          ETH_L2_TUNNEL_FORWARDING_MASK,
12371                          0);
12372 }
12373
12374 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12375         .f = cmd_config_e_tag_forwarding_parsed,
12376         .data = NULL,
12377         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12378         .tokens = {
12379                 (void *)&cmd_config_e_tag_e_tag,
12380                 (void *)&cmd_config_e_tag_set,
12381                 (void *)&cmd_config_e_tag_forwarding,
12382                 (void *)&cmd_config_e_tag_on_off,
12383                 (void *)&cmd_config_e_tag_port,
12384                 (void *)&cmd_config_e_tag_port_id,
12385                 NULL,
12386         },
12387 };
12388
12389 /* E-tag filter configuration */
12390 static void
12391 cmd_config_e_tag_filter_add_parsed(
12392         void *parsed_result,
12393         __attribute__((unused)) struct cmdline *cl,
12394         __attribute__((unused)) void *data)
12395 {
12396         struct cmd_config_e_tag_result *res = parsed_result;
12397         struct rte_eth_l2_tunnel_conf entry;
12398         int ret = 0;
12399
12400         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12401                 return;
12402
12403         if (res->e_tag_id_val > 0x3fff) {
12404                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12405                 return;
12406         }
12407
12408         ret = rte_eth_dev_filter_supported(res->port_id,
12409                                            RTE_ETH_FILTER_L2_TUNNEL);
12410         if (ret < 0) {
12411                 printf("E-tag filter is not supported on port %u.\n",
12412                        res->port_id);
12413                 return;
12414         }
12415
12416         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12417         entry.tunnel_id = res->e_tag_id_val;
12418         entry.pool = res->dst_pool_val;
12419
12420         ret = rte_eth_dev_filter_ctrl(res->port_id,
12421                                       RTE_ETH_FILTER_L2_TUNNEL,
12422                                       RTE_ETH_FILTER_ADD,
12423                                       &entry);
12424         if (ret < 0)
12425                 printf("E-tag filter programming error: (%s)\n",
12426                        strerror(-ret));
12427 }
12428
12429 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12430         .f = cmd_config_e_tag_filter_add_parsed,
12431         .data = NULL,
12432         .help_str = "E-tag ... : E-tag filter add",
12433         .tokens = {
12434                 (void *)&cmd_config_e_tag_e_tag,
12435                 (void *)&cmd_config_e_tag_set,
12436                 (void *)&cmd_config_e_tag_filter,
12437                 (void *)&cmd_config_e_tag_add,
12438                 (void *)&cmd_config_e_tag_e_tag_id,
12439                 (void *)&cmd_config_e_tag_e_tag_id_val,
12440                 (void *)&cmd_config_e_tag_dst_pool,
12441                 (void *)&cmd_config_e_tag_dst_pool_val,
12442                 (void *)&cmd_config_e_tag_port,
12443                 (void *)&cmd_config_e_tag_port_id,
12444                 NULL,
12445         },
12446 };
12447
12448 static void
12449 cmd_config_e_tag_filter_del_parsed(
12450         void *parsed_result,
12451         __attribute__((unused)) struct cmdline *cl,
12452         __attribute__((unused)) void *data)
12453 {
12454         struct cmd_config_e_tag_result *res = parsed_result;
12455         struct rte_eth_l2_tunnel_conf entry;
12456         int ret = 0;
12457
12458         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12459                 return;
12460
12461         if (res->e_tag_id_val > 0x3fff) {
12462                 printf("e-tag-id must be less than 0x3fff.\n");
12463                 return;
12464         }
12465
12466         ret = rte_eth_dev_filter_supported(res->port_id,
12467                                            RTE_ETH_FILTER_L2_TUNNEL);
12468         if (ret < 0) {
12469                 printf("E-tag filter is not supported on port %u.\n",
12470                        res->port_id);
12471                 return;
12472         }
12473
12474         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12475         entry.tunnel_id = res->e_tag_id_val;
12476
12477         ret = rte_eth_dev_filter_ctrl(res->port_id,
12478                                       RTE_ETH_FILTER_L2_TUNNEL,
12479                                       RTE_ETH_FILTER_DELETE,
12480                                       &entry);
12481         if (ret < 0)
12482                 printf("E-tag filter programming error: (%s)\n",
12483                        strerror(-ret));
12484 }
12485
12486 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12487         .f = cmd_config_e_tag_filter_del_parsed,
12488         .data = NULL,
12489         .help_str = "E-tag ... : E-tag filter delete",
12490         .tokens = {
12491                 (void *)&cmd_config_e_tag_e_tag,
12492                 (void *)&cmd_config_e_tag_set,
12493                 (void *)&cmd_config_e_tag_filter,
12494                 (void *)&cmd_config_e_tag_del,
12495                 (void *)&cmd_config_e_tag_e_tag_id,
12496                 (void *)&cmd_config_e_tag_e_tag_id_val,
12497                 (void *)&cmd_config_e_tag_port,
12498                 (void *)&cmd_config_e_tag_port_id,
12499                 NULL,
12500         },
12501 };
12502
12503 /* vf vlan anti spoof configuration */
12504
12505 /* Common result structure for vf vlan anti spoof */
12506 struct cmd_vf_vlan_anti_spoof_result {
12507         cmdline_fixed_string_t set;
12508         cmdline_fixed_string_t vf;
12509         cmdline_fixed_string_t vlan;
12510         cmdline_fixed_string_t antispoof;
12511         portid_t port_id;
12512         uint32_t vf_id;
12513         cmdline_fixed_string_t on_off;
12514 };
12515
12516 /* Common CLI fields for vf vlan anti spoof enable disable */
12517 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12518         TOKEN_STRING_INITIALIZER
12519                 (struct cmd_vf_vlan_anti_spoof_result,
12520                  set, "set");
12521 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12522         TOKEN_STRING_INITIALIZER
12523                 (struct cmd_vf_vlan_anti_spoof_result,
12524                  vf, "vf");
12525 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12526         TOKEN_STRING_INITIALIZER
12527                 (struct cmd_vf_vlan_anti_spoof_result,
12528                  vlan, "vlan");
12529 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12530         TOKEN_STRING_INITIALIZER
12531                 (struct cmd_vf_vlan_anti_spoof_result,
12532                  antispoof, "antispoof");
12533 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12534         TOKEN_NUM_INITIALIZER
12535                 (struct cmd_vf_vlan_anti_spoof_result,
12536                  port_id, UINT16);
12537 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12538         TOKEN_NUM_INITIALIZER
12539                 (struct cmd_vf_vlan_anti_spoof_result,
12540                  vf_id, UINT32);
12541 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12542         TOKEN_STRING_INITIALIZER
12543                 (struct cmd_vf_vlan_anti_spoof_result,
12544                  on_off, "on#off");
12545
12546 static void
12547 cmd_set_vf_vlan_anti_spoof_parsed(
12548         void *parsed_result,
12549         __attribute__((unused)) struct cmdline *cl,
12550         __attribute__((unused)) void *data)
12551 {
12552         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12553         int ret = -ENOTSUP;
12554
12555         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12556
12557         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12558                 return;
12559
12560 #ifdef RTE_LIBRTE_IXGBE_PMD
12561         if (ret == -ENOTSUP)
12562                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12563                                 res->vf_id, is_on);
12564 #endif
12565 #ifdef RTE_LIBRTE_I40E_PMD
12566         if (ret == -ENOTSUP)
12567                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12568                                 res->vf_id, is_on);
12569 #endif
12570 #ifdef RTE_LIBRTE_BNXT_PMD
12571         if (ret == -ENOTSUP)
12572                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12573                                 res->vf_id, is_on);
12574 #endif
12575
12576         switch (ret) {
12577         case 0:
12578                 break;
12579         case -EINVAL:
12580                 printf("invalid vf_id %d\n", res->vf_id);
12581                 break;
12582         case -ENODEV:
12583                 printf("invalid port_id %d\n", res->port_id);
12584                 break;
12585         case -ENOTSUP:
12586                 printf("function not implemented\n");
12587                 break;
12588         default:
12589                 printf("programming error: (%s)\n", strerror(-ret));
12590         }
12591 }
12592
12593 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12594         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12595         .data = NULL,
12596         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12597         .tokens = {
12598                 (void *)&cmd_vf_vlan_anti_spoof_set,
12599                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12600                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12601                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12602                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12603                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12604                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12605                 NULL,
12606         },
12607 };
12608
12609 /* vf mac anti spoof configuration */
12610
12611 /* Common result structure for vf mac anti spoof */
12612 struct cmd_vf_mac_anti_spoof_result {
12613         cmdline_fixed_string_t set;
12614         cmdline_fixed_string_t vf;
12615         cmdline_fixed_string_t mac;
12616         cmdline_fixed_string_t antispoof;
12617         portid_t port_id;
12618         uint32_t vf_id;
12619         cmdline_fixed_string_t on_off;
12620 };
12621
12622 /* Common CLI fields for vf mac anti spoof enable disable */
12623 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12624         TOKEN_STRING_INITIALIZER
12625                 (struct cmd_vf_mac_anti_spoof_result,
12626                  set, "set");
12627 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12628         TOKEN_STRING_INITIALIZER
12629                 (struct cmd_vf_mac_anti_spoof_result,
12630                  vf, "vf");
12631 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12632         TOKEN_STRING_INITIALIZER
12633                 (struct cmd_vf_mac_anti_spoof_result,
12634                  mac, "mac");
12635 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12636         TOKEN_STRING_INITIALIZER
12637                 (struct cmd_vf_mac_anti_spoof_result,
12638                  antispoof, "antispoof");
12639 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12640         TOKEN_NUM_INITIALIZER
12641                 (struct cmd_vf_mac_anti_spoof_result,
12642                  port_id, UINT16);
12643 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12644         TOKEN_NUM_INITIALIZER
12645                 (struct cmd_vf_mac_anti_spoof_result,
12646                  vf_id, UINT32);
12647 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12648         TOKEN_STRING_INITIALIZER
12649                 (struct cmd_vf_mac_anti_spoof_result,
12650                  on_off, "on#off");
12651
12652 static void
12653 cmd_set_vf_mac_anti_spoof_parsed(
12654         void *parsed_result,
12655         __attribute__((unused)) struct cmdline *cl,
12656         __attribute__((unused)) void *data)
12657 {
12658         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12659         int ret = -ENOTSUP;
12660
12661         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12662
12663         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12664                 return;
12665
12666 #ifdef RTE_LIBRTE_IXGBE_PMD
12667         if (ret == -ENOTSUP)
12668                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12669                         res->vf_id, is_on);
12670 #endif
12671 #ifdef RTE_LIBRTE_I40E_PMD
12672         if (ret == -ENOTSUP)
12673                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12674                         res->vf_id, is_on);
12675 #endif
12676 #ifdef RTE_LIBRTE_BNXT_PMD
12677         if (ret == -ENOTSUP)
12678                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12679                         res->vf_id, is_on);
12680 #endif
12681
12682         switch (ret) {
12683         case 0:
12684                 break;
12685         case -EINVAL:
12686                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12687                 break;
12688         case -ENODEV:
12689                 printf("invalid port_id %d\n", res->port_id);
12690                 break;
12691         case -ENOTSUP:
12692                 printf("function not implemented\n");
12693                 break;
12694         default:
12695                 printf("programming error: (%s)\n", strerror(-ret));
12696         }
12697 }
12698
12699 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12700         .f = cmd_set_vf_mac_anti_spoof_parsed,
12701         .data = NULL,
12702         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12703         .tokens = {
12704                 (void *)&cmd_vf_mac_anti_spoof_set,
12705                 (void *)&cmd_vf_mac_anti_spoof_vf,
12706                 (void *)&cmd_vf_mac_anti_spoof_mac,
12707                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12708                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12709                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12710                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12711                 NULL,
12712         },
12713 };
12714
12715 /* vf vlan strip queue configuration */
12716
12717 /* Common result structure for vf mac anti spoof */
12718 struct cmd_vf_vlan_stripq_result {
12719         cmdline_fixed_string_t set;
12720         cmdline_fixed_string_t vf;
12721         cmdline_fixed_string_t vlan;
12722         cmdline_fixed_string_t stripq;
12723         portid_t port_id;
12724         uint16_t vf_id;
12725         cmdline_fixed_string_t on_off;
12726 };
12727
12728 /* Common CLI fields for vf vlan strip enable disable */
12729 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12730         TOKEN_STRING_INITIALIZER
12731                 (struct cmd_vf_vlan_stripq_result,
12732                  set, "set");
12733 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12734         TOKEN_STRING_INITIALIZER
12735                 (struct cmd_vf_vlan_stripq_result,
12736                  vf, "vf");
12737 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12738         TOKEN_STRING_INITIALIZER
12739                 (struct cmd_vf_vlan_stripq_result,
12740                  vlan, "vlan");
12741 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12742         TOKEN_STRING_INITIALIZER
12743                 (struct cmd_vf_vlan_stripq_result,
12744                  stripq, "stripq");
12745 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12746         TOKEN_NUM_INITIALIZER
12747                 (struct cmd_vf_vlan_stripq_result,
12748                  port_id, UINT16);
12749 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12750         TOKEN_NUM_INITIALIZER
12751                 (struct cmd_vf_vlan_stripq_result,
12752                  vf_id, UINT16);
12753 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12754         TOKEN_STRING_INITIALIZER
12755                 (struct cmd_vf_vlan_stripq_result,
12756                  on_off, "on#off");
12757
12758 static void
12759 cmd_set_vf_vlan_stripq_parsed(
12760         void *parsed_result,
12761         __attribute__((unused)) struct cmdline *cl,
12762         __attribute__((unused)) void *data)
12763 {
12764         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12765         int ret = -ENOTSUP;
12766
12767         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12768
12769         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12770                 return;
12771
12772 #ifdef RTE_LIBRTE_IXGBE_PMD
12773         if (ret == -ENOTSUP)
12774                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12775                         res->vf_id, is_on);
12776 #endif
12777 #ifdef RTE_LIBRTE_I40E_PMD
12778         if (ret == -ENOTSUP)
12779                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12780                         res->vf_id, is_on);
12781 #endif
12782 #ifdef RTE_LIBRTE_BNXT_PMD
12783         if (ret == -ENOTSUP)
12784                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12785                         res->vf_id, is_on);
12786 #endif
12787
12788         switch (ret) {
12789         case 0:
12790                 break;
12791         case -EINVAL:
12792                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12793                 break;
12794         case -ENODEV:
12795                 printf("invalid port_id %d\n", res->port_id);
12796                 break;
12797         case -ENOTSUP:
12798                 printf("function not implemented\n");
12799                 break;
12800         default:
12801                 printf("programming error: (%s)\n", strerror(-ret));
12802         }
12803 }
12804
12805 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12806         .f = cmd_set_vf_vlan_stripq_parsed,
12807         .data = NULL,
12808         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12809         .tokens = {
12810                 (void *)&cmd_vf_vlan_stripq_set,
12811                 (void *)&cmd_vf_vlan_stripq_vf,
12812                 (void *)&cmd_vf_vlan_stripq_vlan,
12813                 (void *)&cmd_vf_vlan_stripq_stripq,
12814                 (void *)&cmd_vf_vlan_stripq_port_id,
12815                 (void *)&cmd_vf_vlan_stripq_vf_id,
12816                 (void *)&cmd_vf_vlan_stripq_on_off,
12817                 NULL,
12818         },
12819 };
12820
12821 /* vf vlan insert configuration */
12822
12823 /* Common result structure for vf vlan insert */
12824 struct cmd_vf_vlan_insert_result {
12825         cmdline_fixed_string_t set;
12826         cmdline_fixed_string_t vf;
12827         cmdline_fixed_string_t vlan;
12828         cmdline_fixed_string_t insert;
12829         portid_t port_id;
12830         uint16_t vf_id;
12831         uint16_t vlan_id;
12832 };
12833
12834 /* Common CLI fields for vf vlan insert enable disable */
12835 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12836         TOKEN_STRING_INITIALIZER
12837                 (struct cmd_vf_vlan_insert_result,
12838                  set, "set");
12839 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12840         TOKEN_STRING_INITIALIZER
12841                 (struct cmd_vf_vlan_insert_result,
12842                  vf, "vf");
12843 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12844         TOKEN_STRING_INITIALIZER
12845                 (struct cmd_vf_vlan_insert_result,
12846                  vlan, "vlan");
12847 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12848         TOKEN_STRING_INITIALIZER
12849                 (struct cmd_vf_vlan_insert_result,
12850                  insert, "insert");
12851 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12852         TOKEN_NUM_INITIALIZER
12853                 (struct cmd_vf_vlan_insert_result,
12854                  port_id, UINT16);
12855 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12856         TOKEN_NUM_INITIALIZER
12857                 (struct cmd_vf_vlan_insert_result,
12858                  vf_id, UINT16);
12859 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12860         TOKEN_NUM_INITIALIZER
12861                 (struct cmd_vf_vlan_insert_result,
12862                  vlan_id, UINT16);
12863
12864 static void
12865 cmd_set_vf_vlan_insert_parsed(
12866         void *parsed_result,
12867         __attribute__((unused)) struct cmdline *cl,
12868         __attribute__((unused)) void *data)
12869 {
12870         struct cmd_vf_vlan_insert_result *res = parsed_result;
12871         int ret = -ENOTSUP;
12872
12873         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12874                 return;
12875
12876 #ifdef RTE_LIBRTE_IXGBE_PMD
12877         if (ret == -ENOTSUP)
12878                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12879                         res->vlan_id);
12880 #endif
12881 #ifdef RTE_LIBRTE_I40E_PMD
12882         if (ret == -ENOTSUP)
12883                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12884                         res->vlan_id);
12885 #endif
12886 #ifdef RTE_LIBRTE_BNXT_PMD
12887         if (ret == -ENOTSUP)
12888                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12889                         res->vlan_id);
12890 #endif
12891
12892         switch (ret) {
12893         case 0:
12894                 break;
12895         case -EINVAL:
12896                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12897                 break;
12898         case -ENODEV:
12899                 printf("invalid port_id %d\n", res->port_id);
12900                 break;
12901         case -ENOTSUP:
12902                 printf("function not implemented\n");
12903                 break;
12904         default:
12905                 printf("programming error: (%s)\n", strerror(-ret));
12906         }
12907 }
12908
12909 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12910         .f = cmd_set_vf_vlan_insert_parsed,
12911         .data = NULL,
12912         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12913         .tokens = {
12914                 (void *)&cmd_vf_vlan_insert_set,
12915                 (void *)&cmd_vf_vlan_insert_vf,
12916                 (void *)&cmd_vf_vlan_insert_vlan,
12917                 (void *)&cmd_vf_vlan_insert_insert,
12918                 (void *)&cmd_vf_vlan_insert_port_id,
12919                 (void *)&cmd_vf_vlan_insert_vf_id,
12920                 (void *)&cmd_vf_vlan_insert_vlan_id,
12921                 NULL,
12922         },
12923 };
12924
12925 /* tx loopback configuration */
12926
12927 /* Common result structure for tx loopback */
12928 struct cmd_tx_loopback_result {
12929         cmdline_fixed_string_t set;
12930         cmdline_fixed_string_t tx;
12931         cmdline_fixed_string_t loopback;
12932         portid_t port_id;
12933         cmdline_fixed_string_t on_off;
12934 };
12935
12936 /* Common CLI fields for tx loopback enable disable */
12937 cmdline_parse_token_string_t cmd_tx_loopback_set =
12938         TOKEN_STRING_INITIALIZER
12939                 (struct cmd_tx_loopback_result,
12940                  set, "set");
12941 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12942         TOKEN_STRING_INITIALIZER
12943                 (struct cmd_tx_loopback_result,
12944                  tx, "tx");
12945 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12946         TOKEN_STRING_INITIALIZER
12947                 (struct cmd_tx_loopback_result,
12948                  loopback, "loopback");
12949 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12950         TOKEN_NUM_INITIALIZER
12951                 (struct cmd_tx_loopback_result,
12952                  port_id, UINT16);
12953 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12954         TOKEN_STRING_INITIALIZER
12955                 (struct cmd_tx_loopback_result,
12956                  on_off, "on#off");
12957
12958 static void
12959 cmd_set_tx_loopback_parsed(
12960         void *parsed_result,
12961         __attribute__((unused)) struct cmdline *cl,
12962         __attribute__((unused)) void *data)
12963 {
12964         struct cmd_tx_loopback_result *res = parsed_result;
12965         int ret = -ENOTSUP;
12966
12967         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12968
12969         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12970                 return;
12971
12972 #ifdef RTE_LIBRTE_IXGBE_PMD
12973         if (ret == -ENOTSUP)
12974                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12975 #endif
12976 #ifdef RTE_LIBRTE_I40E_PMD
12977         if (ret == -ENOTSUP)
12978                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12979 #endif
12980 #ifdef RTE_LIBRTE_BNXT_PMD
12981         if (ret == -ENOTSUP)
12982                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12983 #endif
12984 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
12985         if (ret == -ENOTSUP)
12986                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12987 #endif
12988
12989         switch (ret) {
12990         case 0:
12991                 break;
12992         case -EINVAL:
12993                 printf("invalid is_on %d\n", is_on);
12994                 break;
12995         case -ENODEV:
12996                 printf("invalid port_id %d\n", res->port_id);
12997                 break;
12998         case -ENOTSUP:
12999                 printf("function not implemented\n");
13000                 break;
13001         default:
13002                 printf("programming error: (%s)\n", strerror(-ret));
13003         }
13004 }
13005
13006 cmdline_parse_inst_t cmd_set_tx_loopback = {
13007         .f = cmd_set_tx_loopback_parsed,
13008         .data = NULL,
13009         .help_str = "set tx loopback <port_id> on|off",
13010         .tokens = {
13011                 (void *)&cmd_tx_loopback_set,
13012                 (void *)&cmd_tx_loopback_tx,
13013                 (void *)&cmd_tx_loopback_loopback,
13014                 (void *)&cmd_tx_loopback_port_id,
13015                 (void *)&cmd_tx_loopback_on_off,
13016                 NULL,
13017         },
13018 };
13019
13020 /* all queues drop enable configuration */
13021
13022 /* Common result structure for all queues drop enable */
13023 struct cmd_all_queues_drop_en_result {
13024         cmdline_fixed_string_t set;
13025         cmdline_fixed_string_t all;
13026         cmdline_fixed_string_t queues;
13027         cmdline_fixed_string_t drop;
13028         portid_t port_id;
13029         cmdline_fixed_string_t on_off;
13030 };
13031
13032 /* Common CLI fields for tx loopback enable disable */
13033 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13034         TOKEN_STRING_INITIALIZER
13035                 (struct cmd_all_queues_drop_en_result,
13036                  set, "set");
13037 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13038         TOKEN_STRING_INITIALIZER
13039                 (struct cmd_all_queues_drop_en_result,
13040                  all, "all");
13041 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13042         TOKEN_STRING_INITIALIZER
13043                 (struct cmd_all_queues_drop_en_result,
13044                  queues, "queues");
13045 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13046         TOKEN_STRING_INITIALIZER
13047                 (struct cmd_all_queues_drop_en_result,
13048                  drop, "drop");
13049 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13050         TOKEN_NUM_INITIALIZER
13051                 (struct cmd_all_queues_drop_en_result,
13052                  port_id, UINT16);
13053 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13054         TOKEN_STRING_INITIALIZER
13055                 (struct cmd_all_queues_drop_en_result,
13056                  on_off, "on#off");
13057
13058 static void
13059 cmd_set_all_queues_drop_en_parsed(
13060         void *parsed_result,
13061         __attribute__((unused)) struct cmdline *cl,
13062         __attribute__((unused)) void *data)
13063 {
13064         struct cmd_all_queues_drop_en_result *res = parsed_result;
13065         int ret = -ENOTSUP;
13066         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13067
13068         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13069                 return;
13070
13071 #ifdef RTE_LIBRTE_IXGBE_PMD
13072         if (ret == -ENOTSUP)
13073                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13074 #endif
13075 #ifdef RTE_LIBRTE_BNXT_PMD
13076         if (ret == -ENOTSUP)
13077                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13078 #endif
13079         switch (ret) {
13080         case 0:
13081                 break;
13082         case -EINVAL:
13083                 printf("invalid is_on %d\n", is_on);
13084                 break;
13085         case -ENODEV:
13086                 printf("invalid port_id %d\n", res->port_id);
13087                 break;
13088         case -ENOTSUP:
13089                 printf("function not implemented\n");
13090                 break;
13091         default:
13092                 printf("programming error: (%s)\n", strerror(-ret));
13093         }
13094 }
13095
13096 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13097         .f = cmd_set_all_queues_drop_en_parsed,
13098         .data = NULL,
13099         .help_str = "set all queues drop <port_id> on|off",
13100         .tokens = {
13101                 (void *)&cmd_all_queues_drop_en_set,
13102                 (void *)&cmd_all_queues_drop_en_all,
13103                 (void *)&cmd_all_queues_drop_en_queues,
13104                 (void *)&cmd_all_queues_drop_en_drop,
13105                 (void *)&cmd_all_queues_drop_en_port_id,
13106                 (void *)&cmd_all_queues_drop_en_on_off,
13107                 NULL,
13108         },
13109 };
13110
13111 /* vf split drop enable configuration */
13112
13113 /* Common result structure for vf split drop enable */
13114 struct cmd_vf_split_drop_en_result {
13115         cmdline_fixed_string_t set;
13116         cmdline_fixed_string_t vf;
13117         cmdline_fixed_string_t split;
13118         cmdline_fixed_string_t drop;
13119         portid_t port_id;
13120         uint16_t vf_id;
13121         cmdline_fixed_string_t on_off;
13122 };
13123
13124 /* Common CLI fields for vf split drop enable disable */
13125 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13126         TOKEN_STRING_INITIALIZER
13127                 (struct cmd_vf_split_drop_en_result,
13128                  set, "set");
13129 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13130         TOKEN_STRING_INITIALIZER
13131                 (struct cmd_vf_split_drop_en_result,
13132                  vf, "vf");
13133 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13134         TOKEN_STRING_INITIALIZER
13135                 (struct cmd_vf_split_drop_en_result,
13136                  split, "split");
13137 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13138         TOKEN_STRING_INITIALIZER
13139                 (struct cmd_vf_split_drop_en_result,
13140                  drop, "drop");
13141 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13142         TOKEN_NUM_INITIALIZER
13143                 (struct cmd_vf_split_drop_en_result,
13144                  port_id, UINT16);
13145 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13146         TOKEN_NUM_INITIALIZER
13147                 (struct cmd_vf_split_drop_en_result,
13148                  vf_id, UINT16);
13149 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13150         TOKEN_STRING_INITIALIZER
13151                 (struct cmd_vf_split_drop_en_result,
13152                  on_off, "on#off");
13153
13154 static void
13155 cmd_set_vf_split_drop_en_parsed(
13156         void *parsed_result,
13157         __attribute__((unused)) struct cmdline *cl,
13158         __attribute__((unused)) void *data)
13159 {
13160         struct cmd_vf_split_drop_en_result *res = parsed_result;
13161         int ret = -ENOTSUP;
13162         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13163
13164         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13165                 return;
13166
13167 #ifdef RTE_LIBRTE_IXGBE_PMD
13168         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13169                         is_on);
13170 #endif
13171         switch (ret) {
13172         case 0:
13173                 break;
13174         case -EINVAL:
13175                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13176                 break;
13177         case -ENODEV:
13178                 printf("invalid port_id %d\n", res->port_id);
13179                 break;
13180         case -ENOTSUP:
13181                 printf("not supported on port %d\n", res->port_id);
13182                 break;
13183         default:
13184                 printf("programming error: (%s)\n", strerror(-ret));
13185         }
13186 }
13187
13188 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13189         .f = cmd_set_vf_split_drop_en_parsed,
13190         .data = NULL,
13191         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13192         .tokens = {
13193                 (void *)&cmd_vf_split_drop_en_set,
13194                 (void *)&cmd_vf_split_drop_en_vf,
13195                 (void *)&cmd_vf_split_drop_en_split,
13196                 (void *)&cmd_vf_split_drop_en_drop,
13197                 (void *)&cmd_vf_split_drop_en_port_id,
13198                 (void *)&cmd_vf_split_drop_en_vf_id,
13199                 (void *)&cmd_vf_split_drop_en_on_off,
13200                 NULL,
13201         },
13202 };
13203
13204 /* vf mac address configuration */
13205
13206 /* Common result structure for vf mac address */
13207 struct cmd_set_vf_mac_addr_result {
13208         cmdline_fixed_string_t set;
13209         cmdline_fixed_string_t vf;
13210         cmdline_fixed_string_t mac;
13211         cmdline_fixed_string_t addr;
13212         portid_t port_id;
13213         uint16_t vf_id;
13214         struct ether_addr mac_addr;
13215
13216 };
13217
13218 /* Common CLI fields for vf split drop enable disable */
13219 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13220         TOKEN_STRING_INITIALIZER
13221                 (struct cmd_set_vf_mac_addr_result,
13222                  set, "set");
13223 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13224         TOKEN_STRING_INITIALIZER
13225                 (struct cmd_set_vf_mac_addr_result,
13226                  vf, "vf");
13227 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13228         TOKEN_STRING_INITIALIZER
13229                 (struct cmd_set_vf_mac_addr_result,
13230                  mac, "mac");
13231 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13232         TOKEN_STRING_INITIALIZER
13233                 (struct cmd_set_vf_mac_addr_result,
13234                  addr, "addr");
13235 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13236         TOKEN_NUM_INITIALIZER
13237                 (struct cmd_set_vf_mac_addr_result,
13238                  port_id, UINT16);
13239 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13240         TOKEN_NUM_INITIALIZER
13241                 (struct cmd_set_vf_mac_addr_result,
13242                  vf_id, UINT16);
13243 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13244         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13245                  mac_addr);
13246
13247 static void
13248 cmd_set_vf_mac_addr_parsed(
13249         void *parsed_result,
13250         __attribute__((unused)) struct cmdline *cl,
13251         __attribute__((unused)) void *data)
13252 {
13253         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13254         int ret = -ENOTSUP;
13255
13256         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13257                 return;
13258
13259 #ifdef RTE_LIBRTE_IXGBE_PMD
13260         if (ret == -ENOTSUP)
13261                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13262                                 &res->mac_addr);
13263 #endif
13264 #ifdef RTE_LIBRTE_I40E_PMD
13265         if (ret == -ENOTSUP)
13266                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13267                                 &res->mac_addr);
13268 #endif
13269 #ifdef RTE_LIBRTE_BNXT_PMD
13270         if (ret == -ENOTSUP)
13271                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13272                                 &res->mac_addr);
13273 #endif
13274
13275         switch (ret) {
13276         case 0:
13277                 break;
13278         case -EINVAL:
13279                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13280                 break;
13281         case -ENODEV:
13282                 printf("invalid port_id %d\n", res->port_id);
13283                 break;
13284         case -ENOTSUP:
13285                 printf("function not implemented\n");
13286                 break;
13287         default:
13288                 printf("programming error: (%s)\n", strerror(-ret));
13289         }
13290 }
13291
13292 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13293         .f = cmd_set_vf_mac_addr_parsed,
13294         .data = NULL,
13295         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13296         .tokens = {
13297                 (void *)&cmd_set_vf_mac_addr_set,
13298                 (void *)&cmd_set_vf_mac_addr_vf,
13299                 (void *)&cmd_set_vf_mac_addr_mac,
13300                 (void *)&cmd_set_vf_mac_addr_addr,
13301                 (void *)&cmd_set_vf_mac_addr_port_id,
13302                 (void *)&cmd_set_vf_mac_addr_vf_id,
13303                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13304                 NULL,
13305         },
13306 };
13307
13308 /* MACsec configuration */
13309
13310 /* Common result structure for MACsec offload enable */
13311 struct cmd_macsec_offload_on_result {
13312         cmdline_fixed_string_t set;
13313         cmdline_fixed_string_t macsec;
13314         cmdline_fixed_string_t offload;
13315         portid_t port_id;
13316         cmdline_fixed_string_t on;
13317         cmdline_fixed_string_t encrypt;
13318         cmdline_fixed_string_t en_on_off;
13319         cmdline_fixed_string_t replay_protect;
13320         cmdline_fixed_string_t rp_on_off;
13321 };
13322
13323 /* Common CLI fields for MACsec offload disable */
13324 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13325         TOKEN_STRING_INITIALIZER
13326                 (struct cmd_macsec_offload_on_result,
13327                  set, "set");
13328 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13329         TOKEN_STRING_INITIALIZER
13330                 (struct cmd_macsec_offload_on_result,
13331                  macsec, "macsec");
13332 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13333         TOKEN_STRING_INITIALIZER
13334                 (struct cmd_macsec_offload_on_result,
13335                  offload, "offload");
13336 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13337         TOKEN_NUM_INITIALIZER
13338                 (struct cmd_macsec_offload_on_result,
13339                  port_id, UINT16);
13340 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13341         TOKEN_STRING_INITIALIZER
13342                 (struct cmd_macsec_offload_on_result,
13343                  on, "on");
13344 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13345         TOKEN_STRING_INITIALIZER
13346                 (struct cmd_macsec_offload_on_result,
13347                  encrypt, "encrypt");
13348 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13349         TOKEN_STRING_INITIALIZER
13350                 (struct cmd_macsec_offload_on_result,
13351                  en_on_off, "on#off");
13352 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13353         TOKEN_STRING_INITIALIZER
13354                 (struct cmd_macsec_offload_on_result,
13355                  replay_protect, "replay-protect");
13356 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13357         TOKEN_STRING_INITIALIZER
13358                 (struct cmd_macsec_offload_on_result,
13359                  rp_on_off, "on#off");
13360
13361 static void
13362 cmd_set_macsec_offload_on_parsed(
13363         void *parsed_result,
13364         __attribute__((unused)) struct cmdline *cl,
13365         __attribute__((unused)) void *data)
13366 {
13367         struct cmd_macsec_offload_on_result *res = parsed_result;
13368         int ret = -ENOTSUP;
13369         portid_t port_id = res->port_id;
13370         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13371         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13372         struct rte_eth_dev_info dev_info;
13373
13374         if (port_id_is_invalid(port_id, ENABLED_WARN))
13375                 return;
13376         if (!port_is_stopped(port_id)) {
13377                 printf("Please stop port %d first\n", port_id);
13378                 return;
13379         }
13380
13381         rte_eth_dev_info_get(port_id, &dev_info);
13382         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13383 #ifdef RTE_LIBRTE_IXGBE_PMD
13384                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13385 #endif
13386         }
13387         RTE_SET_USED(en);
13388         RTE_SET_USED(rp);
13389
13390         switch (ret) {
13391         case 0:
13392                 ports[port_id].dev_conf.txmode.offloads |=
13393                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13394                 cmd_reconfig_device_queue(port_id, 1, 1);
13395                 break;
13396         case -ENODEV:
13397                 printf("invalid port_id %d\n", port_id);
13398                 break;
13399         case -ENOTSUP:
13400                 printf("not supported on port %d\n", port_id);
13401                 break;
13402         default:
13403                 printf("programming error: (%s)\n", strerror(-ret));
13404         }
13405 }
13406
13407 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13408         .f = cmd_set_macsec_offload_on_parsed,
13409         .data = NULL,
13410         .help_str = "set macsec offload <port_id> on "
13411                 "encrypt on|off replay-protect on|off",
13412         .tokens = {
13413                 (void *)&cmd_macsec_offload_on_set,
13414                 (void *)&cmd_macsec_offload_on_macsec,
13415                 (void *)&cmd_macsec_offload_on_offload,
13416                 (void *)&cmd_macsec_offload_on_port_id,
13417                 (void *)&cmd_macsec_offload_on_on,
13418                 (void *)&cmd_macsec_offload_on_encrypt,
13419                 (void *)&cmd_macsec_offload_on_en_on_off,
13420                 (void *)&cmd_macsec_offload_on_replay_protect,
13421                 (void *)&cmd_macsec_offload_on_rp_on_off,
13422                 NULL,
13423         },
13424 };
13425
13426 /* Common result structure for MACsec offload disable */
13427 struct cmd_macsec_offload_off_result {
13428         cmdline_fixed_string_t set;
13429         cmdline_fixed_string_t macsec;
13430         cmdline_fixed_string_t offload;
13431         portid_t port_id;
13432         cmdline_fixed_string_t off;
13433 };
13434
13435 /* Common CLI fields for MACsec offload disable */
13436 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13437         TOKEN_STRING_INITIALIZER
13438                 (struct cmd_macsec_offload_off_result,
13439                  set, "set");
13440 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13441         TOKEN_STRING_INITIALIZER
13442                 (struct cmd_macsec_offload_off_result,
13443                  macsec, "macsec");
13444 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13445         TOKEN_STRING_INITIALIZER
13446                 (struct cmd_macsec_offload_off_result,
13447                  offload, "offload");
13448 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13449         TOKEN_NUM_INITIALIZER
13450                 (struct cmd_macsec_offload_off_result,
13451                  port_id, UINT16);
13452 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13453         TOKEN_STRING_INITIALIZER
13454                 (struct cmd_macsec_offload_off_result,
13455                  off, "off");
13456
13457 static void
13458 cmd_set_macsec_offload_off_parsed(
13459         void *parsed_result,
13460         __attribute__((unused)) struct cmdline *cl,
13461         __attribute__((unused)) void *data)
13462 {
13463         struct cmd_macsec_offload_off_result *res = parsed_result;
13464         int ret = -ENOTSUP;
13465         struct rte_eth_dev_info dev_info;
13466         portid_t port_id = res->port_id;
13467
13468         if (port_id_is_invalid(port_id, ENABLED_WARN))
13469                 return;
13470         if (!port_is_stopped(port_id)) {
13471                 printf("Please stop port %d first\n", port_id);
13472                 return;
13473         }
13474
13475         rte_eth_dev_info_get(port_id, &dev_info);
13476         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13477 #ifdef RTE_LIBRTE_IXGBE_PMD
13478                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13479 #endif
13480         }
13481         switch (ret) {
13482         case 0:
13483                 ports[port_id].dev_conf.txmode.offloads &=
13484                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13485                 cmd_reconfig_device_queue(port_id, 1, 1);
13486                 break;
13487         case -ENODEV:
13488                 printf("invalid port_id %d\n", port_id);
13489                 break;
13490         case -ENOTSUP:
13491                 printf("not supported on port %d\n", port_id);
13492                 break;
13493         default:
13494                 printf("programming error: (%s)\n", strerror(-ret));
13495         }
13496 }
13497
13498 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13499         .f = cmd_set_macsec_offload_off_parsed,
13500         .data = NULL,
13501         .help_str = "set macsec offload <port_id> off",
13502         .tokens = {
13503                 (void *)&cmd_macsec_offload_off_set,
13504                 (void *)&cmd_macsec_offload_off_macsec,
13505                 (void *)&cmd_macsec_offload_off_offload,
13506                 (void *)&cmd_macsec_offload_off_port_id,
13507                 (void *)&cmd_macsec_offload_off_off,
13508                 NULL,
13509         },
13510 };
13511
13512 /* Common result structure for MACsec secure connection configure */
13513 struct cmd_macsec_sc_result {
13514         cmdline_fixed_string_t set;
13515         cmdline_fixed_string_t macsec;
13516         cmdline_fixed_string_t sc;
13517         cmdline_fixed_string_t tx_rx;
13518         portid_t port_id;
13519         struct ether_addr mac;
13520         uint16_t pi;
13521 };
13522
13523 /* Common CLI fields for MACsec secure connection configure */
13524 cmdline_parse_token_string_t cmd_macsec_sc_set =
13525         TOKEN_STRING_INITIALIZER
13526                 (struct cmd_macsec_sc_result,
13527                  set, "set");
13528 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13529         TOKEN_STRING_INITIALIZER
13530                 (struct cmd_macsec_sc_result,
13531                  macsec, "macsec");
13532 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13533         TOKEN_STRING_INITIALIZER
13534                 (struct cmd_macsec_sc_result,
13535                  sc, "sc");
13536 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13537         TOKEN_STRING_INITIALIZER
13538                 (struct cmd_macsec_sc_result,
13539                  tx_rx, "tx#rx");
13540 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13541         TOKEN_NUM_INITIALIZER
13542                 (struct cmd_macsec_sc_result,
13543                  port_id, UINT16);
13544 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13545         TOKEN_ETHERADDR_INITIALIZER
13546                 (struct cmd_macsec_sc_result,
13547                  mac);
13548 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13549         TOKEN_NUM_INITIALIZER
13550                 (struct cmd_macsec_sc_result,
13551                  pi, UINT16);
13552
13553 static void
13554 cmd_set_macsec_sc_parsed(
13555         void *parsed_result,
13556         __attribute__((unused)) struct cmdline *cl,
13557         __attribute__((unused)) void *data)
13558 {
13559         struct cmd_macsec_sc_result *res = parsed_result;
13560         int ret = -ENOTSUP;
13561         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13562
13563 #ifdef RTE_LIBRTE_IXGBE_PMD
13564         ret = is_tx ?
13565                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13566                                 res->mac.addr_bytes) :
13567                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13568                                 res->mac.addr_bytes, res->pi);
13569 #endif
13570         RTE_SET_USED(is_tx);
13571
13572         switch (ret) {
13573         case 0:
13574                 break;
13575         case -ENODEV:
13576                 printf("invalid port_id %d\n", res->port_id);
13577                 break;
13578         case -ENOTSUP:
13579                 printf("not supported on port %d\n", res->port_id);
13580                 break;
13581         default:
13582                 printf("programming error: (%s)\n", strerror(-ret));
13583         }
13584 }
13585
13586 cmdline_parse_inst_t cmd_set_macsec_sc = {
13587         .f = cmd_set_macsec_sc_parsed,
13588         .data = NULL,
13589         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13590         .tokens = {
13591                 (void *)&cmd_macsec_sc_set,
13592                 (void *)&cmd_macsec_sc_macsec,
13593                 (void *)&cmd_macsec_sc_sc,
13594                 (void *)&cmd_macsec_sc_tx_rx,
13595                 (void *)&cmd_macsec_sc_port_id,
13596                 (void *)&cmd_macsec_sc_mac,
13597                 (void *)&cmd_macsec_sc_pi,
13598                 NULL,
13599         },
13600 };
13601
13602 /* Common result structure for MACsec secure connection configure */
13603 struct cmd_macsec_sa_result {
13604         cmdline_fixed_string_t set;
13605         cmdline_fixed_string_t macsec;
13606         cmdline_fixed_string_t sa;
13607         cmdline_fixed_string_t tx_rx;
13608         portid_t port_id;
13609         uint8_t idx;
13610         uint8_t an;
13611         uint32_t pn;
13612         cmdline_fixed_string_t key;
13613 };
13614
13615 /* Common CLI fields for MACsec secure connection configure */
13616 cmdline_parse_token_string_t cmd_macsec_sa_set =
13617         TOKEN_STRING_INITIALIZER
13618                 (struct cmd_macsec_sa_result,
13619                  set, "set");
13620 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13621         TOKEN_STRING_INITIALIZER
13622                 (struct cmd_macsec_sa_result,
13623                  macsec, "macsec");
13624 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13625         TOKEN_STRING_INITIALIZER
13626                 (struct cmd_macsec_sa_result,
13627                  sa, "sa");
13628 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13629         TOKEN_STRING_INITIALIZER
13630                 (struct cmd_macsec_sa_result,
13631                  tx_rx, "tx#rx");
13632 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13633         TOKEN_NUM_INITIALIZER
13634                 (struct cmd_macsec_sa_result,
13635                  port_id, UINT16);
13636 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13637         TOKEN_NUM_INITIALIZER
13638                 (struct cmd_macsec_sa_result,
13639                  idx, UINT8);
13640 cmdline_parse_token_num_t cmd_macsec_sa_an =
13641         TOKEN_NUM_INITIALIZER
13642                 (struct cmd_macsec_sa_result,
13643                  an, UINT8);
13644 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13645         TOKEN_NUM_INITIALIZER
13646                 (struct cmd_macsec_sa_result,
13647                  pn, UINT32);
13648 cmdline_parse_token_string_t cmd_macsec_sa_key =
13649         TOKEN_STRING_INITIALIZER
13650                 (struct cmd_macsec_sa_result,
13651                  key, NULL);
13652
13653 static void
13654 cmd_set_macsec_sa_parsed(
13655         void *parsed_result,
13656         __attribute__((unused)) struct cmdline *cl,
13657         __attribute__((unused)) void *data)
13658 {
13659         struct cmd_macsec_sa_result *res = parsed_result;
13660         int ret = -ENOTSUP;
13661         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13662         uint8_t key[16] = { 0 };
13663         uint8_t xdgt0;
13664         uint8_t xdgt1;
13665         int key_len;
13666         int i;
13667
13668         key_len = strlen(res->key) / 2;
13669         if (key_len > 16)
13670                 key_len = 16;
13671
13672         for (i = 0; i < key_len; i++) {
13673                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13674                 if (xdgt0 == 0xFF)
13675                         return;
13676                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13677                 if (xdgt1 == 0xFF)
13678                         return;
13679                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13680         }
13681
13682 #ifdef RTE_LIBRTE_IXGBE_PMD
13683         ret = is_tx ?
13684                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13685                         res->idx, res->an, res->pn, key) :
13686                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13687                         res->idx, res->an, res->pn, key);
13688 #endif
13689         RTE_SET_USED(is_tx);
13690         RTE_SET_USED(key);
13691
13692         switch (ret) {
13693         case 0:
13694                 break;
13695         case -EINVAL:
13696                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13697                 break;
13698         case -ENODEV:
13699                 printf("invalid port_id %d\n", res->port_id);
13700                 break;
13701         case -ENOTSUP:
13702                 printf("not supported on port %d\n", res->port_id);
13703                 break;
13704         default:
13705                 printf("programming error: (%s)\n", strerror(-ret));
13706         }
13707 }
13708
13709 cmdline_parse_inst_t cmd_set_macsec_sa = {
13710         .f = cmd_set_macsec_sa_parsed,
13711         .data = NULL,
13712         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13713         .tokens = {
13714                 (void *)&cmd_macsec_sa_set,
13715                 (void *)&cmd_macsec_sa_macsec,
13716                 (void *)&cmd_macsec_sa_sa,
13717                 (void *)&cmd_macsec_sa_tx_rx,
13718                 (void *)&cmd_macsec_sa_port_id,
13719                 (void *)&cmd_macsec_sa_idx,
13720                 (void *)&cmd_macsec_sa_an,
13721                 (void *)&cmd_macsec_sa_pn,
13722                 (void *)&cmd_macsec_sa_key,
13723                 NULL,
13724         },
13725 };
13726
13727 /* VF unicast promiscuous mode configuration */
13728
13729 /* Common result structure for VF unicast promiscuous mode */
13730 struct cmd_vf_promisc_result {
13731         cmdline_fixed_string_t set;
13732         cmdline_fixed_string_t vf;
13733         cmdline_fixed_string_t promisc;
13734         portid_t port_id;
13735         uint32_t vf_id;
13736         cmdline_fixed_string_t on_off;
13737 };
13738
13739 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13740 cmdline_parse_token_string_t cmd_vf_promisc_set =
13741         TOKEN_STRING_INITIALIZER
13742                 (struct cmd_vf_promisc_result,
13743                  set, "set");
13744 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13745         TOKEN_STRING_INITIALIZER
13746                 (struct cmd_vf_promisc_result,
13747                  vf, "vf");
13748 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13749         TOKEN_STRING_INITIALIZER
13750                 (struct cmd_vf_promisc_result,
13751                  promisc, "promisc");
13752 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13753         TOKEN_NUM_INITIALIZER
13754                 (struct cmd_vf_promisc_result,
13755                  port_id, UINT16);
13756 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13757         TOKEN_NUM_INITIALIZER
13758                 (struct cmd_vf_promisc_result,
13759                  vf_id, UINT32);
13760 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13761         TOKEN_STRING_INITIALIZER
13762                 (struct cmd_vf_promisc_result,
13763                  on_off, "on#off");
13764
13765 static void
13766 cmd_set_vf_promisc_parsed(
13767         void *parsed_result,
13768         __attribute__((unused)) struct cmdline *cl,
13769         __attribute__((unused)) void *data)
13770 {
13771         struct cmd_vf_promisc_result *res = parsed_result;
13772         int ret = -ENOTSUP;
13773
13774         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13775
13776         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13777                 return;
13778
13779 #ifdef RTE_LIBRTE_I40E_PMD
13780         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13781                                                   res->vf_id, is_on);
13782 #endif
13783
13784         switch (ret) {
13785         case 0:
13786                 break;
13787         case -EINVAL:
13788                 printf("invalid vf_id %d\n", res->vf_id);
13789                 break;
13790         case -ENODEV:
13791                 printf("invalid port_id %d\n", res->port_id);
13792                 break;
13793         case -ENOTSUP:
13794                 printf("function not implemented\n");
13795                 break;
13796         default:
13797                 printf("programming error: (%s)\n", strerror(-ret));
13798         }
13799 }
13800
13801 cmdline_parse_inst_t cmd_set_vf_promisc = {
13802         .f = cmd_set_vf_promisc_parsed,
13803         .data = NULL,
13804         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13805                 "Set unicast promiscuous mode for a VF from the PF",
13806         .tokens = {
13807                 (void *)&cmd_vf_promisc_set,
13808                 (void *)&cmd_vf_promisc_vf,
13809                 (void *)&cmd_vf_promisc_promisc,
13810                 (void *)&cmd_vf_promisc_port_id,
13811                 (void *)&cmd_vf_promisc_vf_id,
13812                 (void *)&cmd_vf_promisc_on_off,
13813                 NULL,
13814         },
13815 };
13816
13817 /* VF multicast promiscuous mode configuration */
13818
13819 /* Common result structure for VF multicast promiscuous mode */
13820 struct cmd_vf_allmulti_result {
13821         cmdline_fixed_string_t set;
13822         cmdline_fixed_string_t vf;
13823         cmdline_fixed_string_t allmulti;
13824         portid_t port_id;
13825         uint32_t vf_id;
13826         cmdline_fixed_string_t on_off;
13827 };
13828
13829 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13830 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13831         TOKEN_STRING_INITIALIZER
13832                 (struct cmd_vf_allmulti_result,
13833                  set, "set");
13834 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13835         TOKEN_STRING_INITIALIZER
13836                 (struct cmd_vf_allmulti_result,
13837                  vf, "vf");
13838 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13839         TOKEN_STRING_INITIALIZER
13840                 (struct cmd_vf_allmulti_result,
13841                  allmulti, "allmulti");
13842 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13843         TOKEN_NUM_INITIALIZER
13844                 (struct cmd_vf_allmulti_result,
13845                  port_id, UINT16);
13846 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13847         TOKEN_NUM_INITIALIZER
13848                 (struct cmd_vf_allmulti_result,
13849                  vf_id, UINT32);
13850 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13851         TOKEN_STRING_INITIALIZER
13852                 (struct cmd_vf_allmulti_result,
13853                  on_off, "on#off");
13854
13855 static void
13856 cmd_set_vf_allmulti_parsed(
13857         void *parsed_result,
13858         __attribute__((unused)) struct cmdline *cl,
13859         __attribute__((unused)) void *data)
13860 {
13861         struct cmd_vf_allmulti_result *res = parsed_result;
13862         int ret = -ENOTSUP;
13863
13864         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13865
13866         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13867                 return;
13868
13869 #ifdef RTE_LIBRTE_I40E_PMD
13870         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13871                                                     res->vf_id, is_on);
13872 #endif
13873
13874         switch (ret) {
13875         case 0:
13876                 break;
13877         case -EINVAL:
13878                 printf("invalid vf_id %d\n", res->vf_id);
13879                 break;
13880         case -ENODEV:
13881                 printf("invalid port_id %d\n", res->port_id);
13882                 break;
13883         case -ENOTSUP:
13884                 printf("function not implemented\n");
13885                 break;
13886         default:
13887                 printf("programming error: (%s)\n", strerror(-ret));
13888         }
13889 }
13890
13891 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13892         .f = cmd_set_vf_allmulti_parsed,
13893         .data = NULL,
13894         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13895                 "Set multicast promiscuous mode for a VF from the PF",
13896         .tokens = {
13897                 (void *)&cmd_vf_allmulti_set,
13898                 (void *)&cmd_vf_allmulti_vf,
13899                 (void *)&cmd_vf_allmulti_allmulti,
13900                 (void *)&cmd_vf_allmulti_port_id,
13901                 (void *)&cmd_vf_allmulti_vf_id,
13902                 (void *)&cmd_vf_allmulti_on_off,
13903                 NULL,
13904         },
13905 };
13906
13907 /* vf broadcast mode configuration */
13908
13909 /* Common result structure for vf broadcast */
13910 struct cmd_set_vf_broadcast_result {
13911         cmdline_fixed_string_t set;
13912         cmdline_fixed_string_t vf;
13913         cmdline_fixed_string_t broadcast;
13914         portid_t port_id;
13915         uint16_t vf_id;
13916         cmdline_fixed_string_t on_off;
13917 };
13918
13919 /* Common CLI fields for vf broadcast enable disable */
13920 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13921         TOKEN_STRING_INITIALIZER
13922                 (struct cmd_set_vf_broadcast_result,
13923                  set, "set");
13924 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13925         TOKEN_STRING_INITIALIZER
13926                 (struct cmd_set_vf_broadcast_result,
13927                  vf, "vf");
13928 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13929         TOKEN_STRING_INITIALIZER
13930                 (struct cmd_set_vf_broadcast_result,
13931                  broadcast, "broadcast");
13932 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13933         TOKEN_NUM_INITIALIZER
13934                 (struct cmd_set_vf_broadcast_result,
13935                  port_id, UINT16);
13936 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13937         TOKEN_NUM_INITIALIZER
13938                 (struct cmd_set_vf_broadcast_result,
13939                  vf_id, UINT16);
13940 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13941         TOKEN_STRING_INITIALIZER
13942                 (struct cmd_set_vf_broadcast_result,
13943                  on_off, "on#off");
13944
13945 static void
13946 cmd_set_vf_broadcast_parsed(
13947         void *parsed_result,
13948         __attribute__((unused)) struct cmdline *cl,
13949         __attribute__((unused)) void *data)
13950 {
13951         struct cmd_set_vf_broadcast_result *res = parsed_result;
13952         int ret = -ENOTSUP;
13953
13954         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13955
13956         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13957                 return;
13958
13959 #ifdef RTE_LIBRTE_I40E_PMD
13960         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13961                                             res->vf_id, is_on);
13962 #endif
13963
13964         switch (ret) {
13965         case 0:
13966                 break;
13967         case -EINVAL:
13968                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13969                 break;
13970         case -ENODEV:
13971                 printf("invalid port_id %d\n", res->port_id);
13972                 break;
13973         case -ENOTSUP:
13974                 printf("function not implemented\n");
13975                 break;
13976         default:
13977                 printf("programming error: (%s)\n", strerror(-ret));
13978         }
13979 }
13980
13981 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13982         .f = cmd_set_vf_broadcast_parsed,
13983         .data = NULL,
13984         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13985         .tokens = {
13986                 (void *)&cmd_set_vf_broadcast_set,
13987                 (void *)&cmd_set_vf_broadcast_vf,
13988                 (void *)&cmd_set_vf_broadcast_broadcast,
13989                 (void *)&cmd_set_vf_broadcast_port_id,
13990                 (void *)&cmd_set_vf_broadcast_vf_id,
13991                 (void *)&cmd_set_vf_broadcast_on_off,
13992                 NULL,
13993         },
13994 };
13995
13996 /* vf vlan tag configuration */
13997
13998 /* Common result structure for vf vlan tag */
13999 struct cmd_set_vf_vlan_tag_result {
14000         cmdline_fixed_string_t set;
14001         cmdline_fixed_string_t vf;
14002         cmdline_fixed_string_t vlan;
14003         cmdline_fixed_string_t tag;
14004         portid_t port_id;
14005         uint16_t vf_id;
14006         cmdline_fixed_string_t on_off;
14007 };
14008
14009 /* Common CLI fields for vf vlan tag enable disable */
14010 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14011         TOKEN_STRING_INITIALIZER
14012                 (struct cmd_set_vf_vlan_tag_result,
14013                  set, "set");
14014 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14015         TOKEN_STRING_INITIALIZER
14016                 (struct cmd_set_vf_vlan_tag_result,
14017                  vf, "vf");
14018 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14019         TOKEN_STRING_INITIALIZER
14020                 (struct cmd_set_vf_vlan_tag_result,
14021                  vlan, "vlan");
14022 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14023         TOKEN_STRING_INITIALIZER
14024                 (struct cmd_set_vf_vlan_tag_result,
14025                  tag, "tag");
14026 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14027         TOKEN_NUM_INITIALIZER
14028                 (struct cmd_set_vf_vlan_tag_result,
14029                  port_id, UINT16);
14030 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14031         TOKEN_NUM_INITIALIZER
14032                 (struct cmd_set_vf_vlan_tag_result,
14033                  vf_id, UINT16);
14034 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14035         TOKEN_STRING_INITIALIZER
14036                 (struct cmd_set_vf_vlan_tag_result,
14037                  on_off, "on#off");
14038
14039 static void
14040 cmd_set_vf_vlan_tag_parsed(
14041         void *parsed_result,
14042         __attribute__((unused)) struct cmdline *cl,
14043         __attribute__((unused)) void *data)
14044 {
14045         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14046         int ret = -ENOTSUP;
14047
14048         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14049
14050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14051                 return;
14052
14053 #ifdef RTE_LIBRTE_I40E_PMD
14054         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14055                                            res->vf_id, is_on);
14056 #endif
14057
14058         switch (ret) {
14059         case 0:
14060                 break;
14061         case -EINVAL:
14062                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14063                 break;
14064         case -ENODEV:
14065                 printf("invalid port_id %d\n", res->port_id);
14066                 break;
14067         case -ENOTSUP:
14068                 printf("function not implemented\n");
14069                 break;
14070         default:
14071                 printf("programming error: (%s)\n", strerror(-ret));
14072         }
14073 }
14074
14075 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14076         .f = cmd_set_vf_vlan_tag_parsed,
14077         .data = NULL,
14078         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14079         .tokens = {
14080                 (void *)&cmd_set_vf_vlan_tag_set,
14081                 (void *)&cmd_set_vf_vlan_tag_vf,
14082                 (void *)&cmd_set_vf_vlan_tag_vlan,
14083                 (void *)&cmd_set_vf_vlan_tag_tag,
14084                 (void *)&cmd_set_vf_vlan_tag_port_id,
14085                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14086                 (void *)&cmd_set_vf_vlan_tag_on_off,
14087                 NULL,
14088         },
14089 };
14090
14091 /* Common definition of VF and TC TX bandwidth configuration */
14092 struct cmd_vf_tc_bw_result {
14093         cmdline_fixed_string_t set;
14094         cmdline_fixed_string_t vf;
14095         cmdline_fixed_string_t tc;
14096         cmdline_fixed_string_t tx;
14097         cmdline_fixed_string_t min_bw;
14098         cmdline_fixed_string_t max_bw;
14099         cmdline_fixed_string_t strict_link_prio;
14100         portid_t port_id;
14101         uint16_t vf_id;
14102         uint8_t tc_no;
14103         uint32_t bw;
14104         cmdline_fixed_string_t bw_list;
14105         uint8_t tc_map;
14106 };
14107
14108 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14109         TOKEN_STRING_INITIALIZER
14110                 (struct cmd_vf_tc_bw_result,
14111                  set, "set");
14112 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14113         TOKEN_STRING_INITIALIZER
14114                 (struct cmd_vf_tc_bw_result,
14115                  vf, "vf");
14116 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14117         TOKEN_STRING_INITIALIZER
14118                 (struct cmd_vf_tc_bw_result,
14119                  tc, "tc");
14120 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14121         TOKEN_STRING_INITIALIZER
14122                 (struct cmd_vf_tc_bw_result,
14123                  tx, "tx");
14124 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14125         TOKEN_STRING_INITIALIZER
14126                 (struct cmd_vf_tc_bw_result,
14127                  strict_link_prio, "strict-link-priority");
14128 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14129         TOKEN_STRING_INITIALIZER
14130                 (struct cmd_vf_tc_bw_result,
14131                  min_bw, "min-bandwidth");
14132 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14133         TOKEN_STRING_INITIALIZER
14134                 (struct cmd_vf_tc_bw_result,
14135                  max_bw, "max-bandwidth");
14136 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14137         TOKEN_NUM_INITIALIZER
14138                 (struct cmd_vf_tc_bw_result,
14139                  port_id, UINT16);
14140 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14141         TOKEN_NUM_INITIALIZER
14142                 (struct cmd_vf_tc_bw_result,
14143                  vf_id, UINT16);
14144 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14145         TOKEN_NUM_INITIALIZER
14146                 (struct cmd_vf_tc_bw_result,
14147                  tc_no, UINT8);
14148 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14149         TOKEN_NUM_INITIALIZER
14150                 (struct cmd_vf_tc_bw_result,
14151                  bw, UINT32);
14152 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14153         TOKEN_STRING_INITIALIZER
14154                 (struct cmd_vf_tc_bw_result,
14155                  bw_list, NULL);
14156 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14157         TOKEN_NUM_INITIALIZER
14158                 (struct cmd_vf_tc_bw_result,
14159                  tc_map, UINT8);
14160
14161 /* VF max bandwidth setting */
14162 static void
14163 cmd_vf_max_bw_parsed(
14164         void *parsed_result,
14165         __attribute__((unused)) struct cmdline *cl,
14166         __attribute__((unused)) void *data)
14167 {
14168         struct cmd_vf_tc_bw_result *res = parsed_result;
14169         int ret = -ENOTSUP;
14170
14171         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14172                 return;
14173
14174 #ifdef RTE_LIBRTE_I40E_PMD
14175         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14176                                          res->vf_id, res->bw);
14177 #endif
14178
14179         switch (ret) {
14180         case 0:
14181                 break;
14182         case -EINVAL:
14183                 printf("invalid vf_id %d or bandwidth %d\n",
14184                        res->vf_id, res->bw);
14185                 break;
14186         case -ENODEV:
14187                 printf("invalid port_id %d\n", res->port_id);
14188                 break;
14189         case -ENOTSUP:
14190                 printf("function not implemented\n");
14191                 break;
14192         default:
14193                 printf("programming error: (%s)\n", strerror(-ret));
14194         }
14195 }
14196
14197 cmdline_parse_inst_t cmd_vf_max_bw = {
14198         .f = cmd_vf_max_bw_parsed,
14199         .data = NULL,
14200         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14201         .tokens = {
14202                 (void *)&cmd_vf_tc_bw_set,
14203                 (void *)&cmd_vf_tc_bw_vf,
14204                 (void *)&cmd_vf_tc_bw_tx,
14205                 (void *)&cmd_vf_tc_bw_max_bw,
14206                 (void *)&cmd_vf_tc_bw_port_id,
14207                 (void *)&cmd_vf_tc_bw_vf_id,
14208                 (void *)&cmd_vf_tc_bw_bw,
14209                 NULL,
14210         },
14211 };
14212
14213 static int
14214 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14215                            uint8_t *tc_num,
14216                            char *str)
14217 {
14218         uint32_t size;
14219         const char *p, *p0 = str;
14220         char s[256];
14221         char *end;
14222         char *str_fld[16];
14223         uint16_t i;
14224         int ret;
14225
14226         p = strchr(p0, '(');
14227         if (p == NULL) {
14228                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14229                 return -1;
14230         }
14231         p++;
14232         p0 = strchr(p, ')');
14233         if (p0 == NULL) {
14234                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14235                 return -1;
14236         }
14237         size = p0 - p;
14238         if (size >= sizeof(s)) {
14239                 printf("The string size exceeds the internal buffer size\n");
14240                 return -1;
14241         }
14242         snprintf(s, sizeof(s), "%.*s", size, p);
14243         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14244         if (ret <= 0) {
14245                 printf("Failed to get the bandwidth list. ");
14246                 return -1;
14247         }
14248         *tc_num = ret;
14249         for (i = 0; i < ret; i++)
14250                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14251
14252         return 0;
14253 }
14254
14255 /* TC min bandwidth setting */
14256 static void
14257 cmd_vf_tc_min_bw_parsed(
14258         void *parsed_result,
14259         __attribute__((unused)) struct cmdline *cl,
14260         __attribute__((unused)) void *data)
14261 {
14262         struct cmd_vf_tc_bw_result *res = parsed_result;
14263         uint8_t tc_num;
14264         uint8_t bw[16];
14265         int ret = -ENOTSUP;
14266
14267         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14268                 return;
14269
14270         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14271         if (ret)
14272                 return;
14273
14274 #ifdef RTE_LIBRTE_I40E_PMD
14275         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14276                                               tc_num, bw);
14277 #endif
14278
14279         switch (ret) {
14280         case 0:
14281                 break;
14282         case -EINVAL:
14283                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14284                 break;
14285         case -ENODEV:
14286                 printf("invalid port_id %d\n", res->port_id);
14287                 break;
14288         case -ENOTSUP:
14289                 printf("function not implemented\n");
14290                 break;
14291         default:
14292                 printf("programming error: (%s)\n", strerror(-ret));
14293         }
14294 }
14295
14296 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14297         .f = cmd_vf_tc_min_bw_parsed,
14298         .data = NULL,
14299         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14300                     " <bw1, bw2, ...>",
14301         .tokens = {
14302                 (void *)&cmd_vf_tc_bw_set,
14303                 (void *)&cmd_vf_tc_bw_vf,
14304                 (void *)&cmd_vf_tc_bw_tc,
14305                 (void *)&cmd_vf_tc_bw_tx,
14306                 (void *)&cmd_vf_tc_bw_min_bw,
14307                 (void *)&cmd_vf_tc_bw_port_id,
14308                 (void *)&cmd_vf_tc_bw_vf_id,
14309                 (void *)&cmd_vf_tc_bw_bw_list,
14310                 NULL,
14311         },
14312 };
14313
14314 static void
14315 cmd_tc_min_bw_parsed(
14316         void *parsed_result,
14317         __attribute__((unused)) struct cmdline *cl,
14318         __attribute__((unused)) void *data)
14319 {
14320         struct cmd_vf_tc_bw_result *res = parsed_result;
14321         struct rte_port *port;
14322         uint8_t tc_num;
14323         uint8_t bw[16];
14324         int ret = -ENOTSUP;
14325
14326         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14327                 return;
14328
14329         port = &ports[res->port_id];
14330         /** Check if the port is not started **/
14331         if (port->port_status != RTE_PORT_STOPPED) {
14332                 printf("Please stop port %d first\n", res->port_id);
14333                 return;
14334         }
14335
14336         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14337         if (ret)
14338                 return;
14339
14340 #ifdef RTE_LIBRTE_IXGBE_PMD
14341         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14342 #endif
14343
14344         switch (ret) {
14345         case 0:
14346                 break;
14347         case -EINVAL:
14348                 printf("invalid bandwidth\n");
14349                 break;
14350         case -ENODEV:
14351                 printf("invalid port_id %d\n", res->port_id);
14352                 break;
14353         case -ENOTSUP:
14354                 printf("function not implemented\n");
14355                 break;
14356         default:
14357                 printf("programming error: (%s)\n", strerror(-ret));
14358         }
14359 }
14360
14361 cmdline_parse_inst_t cmd_tc_min_bw = {
14362         .f = cmd_tc_min_bw_parsed,
14363         .data = NULL,
14364         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14365         .tokens = {
14366                 (void *)&cmd_vf_tc_bw_set,
14367                 (void *)&cmd_vf_tc_bw_tc,
14368                 (void *)&cmd_vf_tc_bw_tx,
14369                 (void *)&cmd_vf_tc_bw_min_bw,
14370                 (void *)&cmd_vf_tc_bw_port_id,
14371                 (void *)&cmd_vf_tc_bw_bw_list,
14372                 NULL,
14373         },
14374 };
14375
14376 /* TC max bandwidth setting */
14377 static void
14378 cmd_vf_tc_max_bw_parsed(
14379         void *parsed_result,
14380         __attribute__((unused)) struct cmdline *cl,
14381         __attribute__((unused)) void *data)
14382 {
14383         struct cmd_vf_tc_bw_result *res = parsed_result;
14384         int ret = -ENOTSUP;
14385
14386         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14387                 return;
14388
14389 #ifdef RTE_LIBRTE_I40E_PMD
14390         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14391                                             res->tc_no, res->bw);
14392 #endif
14393
14394         switch (ret) {
14395         case 0:
14396                 break;
14397         case -EINVAL:
14398                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14399                        res->vf_id, res->tc_no, res->bw);
14400                 break;
14401         case -ENODEV:
14402                 printf("invalid port_id %d\n", res->port_id);
14403                 break;
14404         case -ENOTSUP:
14405                 printf("function not implemented\n");
14406                 break;
14407         default:
14408                 printf("programming error: (%s)\n", strerror(-ret));
14409         }
14410 }
14411
14412 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14413         .f = cmd_vf_tc_max_bw_parsed,
14414         .data = NULL,
14415         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14416                     " <bandwidth>",
14417         .tokens = {
14418                 (void *)&cmd_vf_tc_bw_set,
14419                 (void *)&cmd_vf_tc_bw_vf,
14420                 (void *)&cmd_vf_tc_bw_tc,
14421                 (void *)&cmd_vf_tc_bw_tx,
14422                 (void *)&cmd_vf_tc_bw_max_bw,
14423                 (void *)&cmd_vf_tc_bw_port_id,
14424                 (void *)&cmd_vf_tc_bw_vf_id,
14425                 (void *)&cmd_vf_tc_bw_tc_no,
14426                 (void *)&cmd_vf_tc_bw_bw,
14427                 NULL,
14428         },
14429 };
14430
14431
14432 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14433
14434 /* *** Set Port default Traffic Management Hierarchy *** */
14435 struct cmd_set_port_tm_hierarchy_default_result {
14436         cmdline_fixed_string_t set;
14437         cmdline_fixed_string_t port;
14438         cmdline_fixed_string_t tm;
14439         cmdline_fixed_string_t hierarchy;
14440         cmdline_fixed_string_t def;
14441         portid_t port_id;
14442 };
14443
14444 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14445         TOKEN_STRING_INITIALIZER(
14446                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14447 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14448         TOKEN_STRING_INITIALIZER(
14449                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14450 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14451         TOKEN_STRING_INITIALIZER(
14452                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14453 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14454         TOKEN_STRING_INITIALIZER(
14455                 struct cmd_set_port_tm_hierarchy_default_result,
14456                         hierarchy, "hierarchy");
14457 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14458         TOKEN_STRING_INITIALIZER(
14459                 struct cmd_set_port_tm_hierarchy_default_result,
14460                         def, "default");
14461 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14462         TOKEN_NUM_INITIALIZER(
14463                 struct cmd_set_port_tm_hierarchy_default_result,
14464                         port_id, UINT16);
14465
14466 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14467         __attribute__((unused)) struct cmdline *cl,
14468         __attribute__((unused)) void *data)
14469 {
14470         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14471         struct rte_port *p;
14472         portid_t port_id = res->port_id;
14473
14474         if (port_id_is_invalid(port_id, ENABLED_WARN))
14475                 return;
14476
14477         p = &ports[port_id];
14478
14479         /* Port tm flag */
14480         if (p->softport.tm_flag == 0) {
14481                 printf("  tm not enabled on port %u (error)\n", port_id);
14482                 return;
14483         }
14484
14485         /* Forward mode: tm */
14486         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14487                 printf("  tm mode not enabled(error)\n");
14488                 return;
14489         }
14490
14491         /* Set the default tm hierarchy */
14492         p->softport.tm.default_hierarchy_enable = 1;
14493 }
14494
14495 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14496         .f = cmd_set_port_tm_hierarchy_default_parsed,
14497         .data = NULL,
14498         .help_str = "set port tm hierarchy default <port_id>",
14499         .tokens = {
14500                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14501                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14502                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14503                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14504                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14505                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14506                 NULL,
14507         },
14508 };
14509 #endif
14510
14511 /* Strict link priority scheduling mode setting */
14512 static void
14513 cmd_strict_link_prio_parsed(
14514         void *parsed_result,
14515         __attribute__((unused)) struct cmdline *cl,
14516         __attribute__((unused)) void *data)
14517 {
14518         struct cmd_vf_tc_bw_result *res = parsed_result;
14519         int ret = -ENOTSUP;
14520
14521         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14522                 return;
14523
14524 #ifdef RTE_LIBRTE_I40E_PMD
14525         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14526 #endif
14527
14528         switch (ret) {
14529         case 0:
14530                 break;
14531         case -EINVAL:
14532                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14533                 break;
14534         case -ENODEV:
14535                 printf("invalid port_id %d\n", res->port_id);
14536                 break;
14537         case -ENOTSUP:
14538                 printf("function not implemented\n");
14539                 break;
14540         default:
14541                 printf("programming error: (%s)\n", strerror(-ret));
14542         }
14543 }
14544
14545 cmdline_parse_inst_t cmd_strict_link_prio = {
14546         .f = cmd_strict_link_prio_parsed,
14547         .data = NULL,
14548         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14549         .tokens = {
14550                 (void *)&cmd_vf_tc_bw_set,
14551                 (void *)&cmd_vf_tc_bw_tx,
14552                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14553                 (void *)&cmd_vf_tc_bw_port_id,
14554                 (void *)&cmd_vf_tc_bw_tc_map,
14555                 NULL,
14556         },
14557 };
14558
14559 /* Load dynamic device personalization*/
14560 struct cmd_ddp_add_result {
14561         cmdline_fixed_string_t ddp;
14562         cmdline_fixed_string_t add;
14563         portid_t port_id;
14564         char filepath[];
14565 };
14566
14567 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14568         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14569 cmdline_parse_token_string_t cmd_ddp_add_add =
14570         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14571 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14572         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14573 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14574         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14575
14576 static void
14577 cmd_ddp_add_parsed(
14578         void *parsed_result,
14579         __attribute__((unused)) struct cmdline *cl,
14580         __attribute__((unused)) void *data)
14581 {
14582         struct cmd_ddp_add_result *res = parsed_result;
14583         uint8_t *buff;
14584         uint32_t size;
14585         char *filepath;
14586         char *file_fld[2];
14587         int file_num;
14588         int ret = -ENOTSUP;
14589
14590         if (!all_ports_stopped()) {
14591                 printf("Please stop all ports first\n");
14592                 return;
14593         }
14594
14595         filepath = strdup(res->filepath);
14596         if (filepath == NULL) {
14597                 printf("Failed to allocate memory\n");
14598                 return;
14599         }
14600         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14601
14602         buff = open_file(file_fld[0], &size);
14603         if (!buff) {
14604                 free((void *)filepath);
14605                 return;
14606         }
14607
14608 #ifdef RTE_LIBRTE_I40E_PMD
14609         if (ret == -ENOTSUP)
14610                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14611                                                buff, size,
14612                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14613 #endif
14614
14615         if (ret == -EEXIST)
14616                 printf("Profile has already existed.\n");
14617         else if (ret < 0)
14618                 printf("Failed to load profile.\n");
14619         else if (file_num == 2)
14620                 save_file(file_fld[1], buff, size);
14621
14622         close_file(buff);
14623         free((void *)filepath);
14624 }
14625
14626 cmdline_parse_inst_t cmd_ddp_add = {
14627         .f = cmd_ddp_add_parsed,
14628         .data = NULL,
14629         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14630         .tokens = {
14631                 (void *)&cmd_ddp_add_ddp,
14632                 (void *)&cmd_ddp_add_add,
14633                 (void *)&cmd_ddp_add_port_id,
14634                 (void *)&cmd_ddp_add_filepath,
14635                 NULL,
14636         },
14637 };
14638
14639 /* Delete dynamic device personalization*/
14640 struct cmd_ddp_del_result {
14641         cmdline_fixed_string_t ddp;
14642         cmdline_fixed_string_t del;
14643         portid_t port_id;
14644         char filepath[];
14645 };
14646
14647 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14648         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14649 cmdline_parse_token_string_t cmd_ddp_del_del =
14650         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14651 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14652         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14653 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14654         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14655
14656 static void
14657 cmd_ddp_del_parsed(
14658         void *parsed_result,
14659         __attribute__((unused)) struct cmdline *cl,
14660         __attribute__((unused)) void *data)
14661 {
14662         struct cmd_ddp_del_result *res = parsed_result;
14663         uint8_t *buff;
14664         uint32_t size;
14665         int ret = -ENOTSUP;
14666
14667         if (!all_ports_stopped()) {
14668                 printf("Please stop all ports first\n");
14669                 return;
14670         }
14671
14672         buff = open_file(res->filepath, &size);
14673         if (!buff)
14674                 return;
14675
14676 #ifdef RTE_LIBRTE_I40E_PMD
14677         if (ret == -ENOTSUP)
14678                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14679                                                buff, size,
14680                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14681 #endif
14682
14683         if (ret == -EACCES)
14684                 printf("Profile does not exist.\n");
14685         else if (ret < 0)
14686                 printf("Failed to delete profile.\n");
14687
14688         close_file(buff);
14689 }
14690
14691 cmdline_parse_inst_t cmd_ddp_del = {
14692         .f = cmd_ddp_del_parsed,
14693         .data = NULL,
14694         .help_str = "ddp del <port_id> <backup_profile_path>",
14695         .tokens = {
14696                 (void *)&cmd_ddp_del_ddp,
14697                 (void *)&cmd_ddp_del_del,
14698                 (void *)&cmd_ddp_del_port_id,
14699                 (void *)&cmd_ddp_del_filepath,
14700                 NULL,
14701         },
14702 };
14703
14704 /* Get dynamic device personalization profile info */
14705 struct cmd_ddp_info_result {
14706         cmdline_fixed_string_t ddp;
14707         cmdline_fixed_string_t get;
14708         cmdline_fixed_string_t info;
14709         char filepath[];
14710 };
14711
14712 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14713         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14714 cmdline_parse_token_string_t cmd_ddp_info_get =
14715         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14716 cmdline_parse_token_string_t cmd_ddp_info_info =
14717         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14718 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14719         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14720
14721 static void
14722 cmd_ddp_info_parsed(
14723         void *parsed_result,
14724         __attribute__((unused)) struct cmdline *cl,
14725         __attribute__((unused)) void *data)
14726 {
14727         struct cmd_ddp_info_result *res = parsed_result;
14728         uint8_t *pkg;
14729         uint32_t pkg_size;
14730         int ret = -ENOTSUP;
14731 #ifdef RTE_LIBRTE_I40E_PMD
14732         uint32_t i, j, n;
14733         uint8_t *buff;
14734         uint32_t buff_size = 0;
14735         struct rte_pmd_i40e_profile_info info;
14736         uint32_t dev_num = 0;
14737         struct rte_pmd_i40e_ddp_device_id *devs;
14738         uint32_t proto_num = 0;
14739         struct rte_pmd_i40e_proto_info *proto = NULL;
14740         uint32_t pctype_num = 0;
14741         struct rte_pmd_i40e_ptype_info *pctype;
14742         uint32_t ptype_num = 0;
14743         struct rte_pmd_i40e_ptype_info *ptype;
14744         uint8_t proto_id;
14745
14746 #endif
14747
14748         pkg = open_file(res->filepath, &pkg_size);
14749         if (!pkg)
14750                 return;
14751
14752 #ifdef RTE_LIBRTE_I40E_PMD
14753         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14754                                 (uint8_t *)&info, sizeof(info),
14755                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14756         if (!ret) {
14757                 printf("Global Track id:       0x%x\n", info.track_id);
14758                 printf("Global Version:        %d.%d.%d.%d\n",
14759                         info.version.major,
14760                         info.version.minor,
14761                         info.version.update,
14762                         info.version.draft);
14763                 printf("Global Package name:   %s\n\n", info.name);
14764         }
14765
14766         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14767                                 (uint8_t *)&info, sizeof(info),
14768                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14769         if (!ret) {
14770                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14771                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14772                         info.version.major,
14773                         info.version.minor,
14774                         info.version.update,
14775                         info.version.draft);
14776                 printf("i40e Profile name:     %s\n\n", info.name);
14777         }
14778
14779         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14780                                 (uint8_t *)&buff_size, sizeof(buff_size),
14781                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14782         if (!ret && buff_size) {
14783                 buff = (uint8_t *)malloc(buff_size);
14784                 if (buff) {
14785                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14786                                                 buff, buff_size,
14787                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14788                         if (!ret)
14789                                 printf("Package Notes:\n%s\n\n", buff);
14790                         free(buff);
14791                 }
14792         }
14793
14794         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14795                                 (uint8_t *)&dev_num, sizeof(dev_num),
14796                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14797         if (!ret && dev_num) {
14798                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14799                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14800                 if (devs) {
14801                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14802                                                 (uint8_t *)devs, buff_size,
14803                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14804                         if (!ret) {
14805                                 printf("List of supported devices:\n");
14806                                 for (i = 0; i < dev_num; i++) {
14807                                         printf("  %04X:%04X %04X:%04X\n",
14808                                                 devs[i].vendor_dev_id >> 16,
14809                                                 devs[i].vendor_dev_id & 0xFFFF,
14810                                                 devs[i].sub_vendor_dev_id >> 16,
14811                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14812                                 }
14813                                 printf("\n");
14814                         }
14815                         free(devs);
14816                 }
14817         }
14818
14819         /* get information about protocols and packet types */
14820         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14821                 (uint8_t *)&proto_num, sizeof(proto_num),
14822                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14823         if (ret || !proto_num)
14824                 goto no_print_return;
14825
14826         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14827         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14828         if (!proto)
14829                 goto no_print_return;
14830
14831         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14832                                         buff_size,
14833                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14834         if (!ret) {
14835                 printf("List of used protocols:\n");
14836                 for (i = 0; i < proto_num; i++)
14837                         printf("  %2u: %s\n", proto[i].proto_id,
14838                                proto[i].name);
14839                 printf("\n");
14840         }
14841         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14842                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14843                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14844         if (ret || !pctype_num)
14845                 goto no_print_pctypes;
14846
14847         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14848         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14849         if (!pctype)
14850                 goto no_print_pctypes;
14851
14852         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14853                                         buff_size,
14854                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14855         if (ret) {
14856                 free(pctype);
14857                 goto no_print_pctypes;
14858         }
14859
14860         printf("List of defined packet classification types:\n");
14861         for (i = 0; i < pctype_num; i++) {
14862                 printf("  %2u:", pctype[i].ptype_id);
14863                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14864                         proto_id = pctype[i].protocols[j];
14865                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14866                                 for (n = 0; n < proto_num; n++) {
14867                                         if (proto[n].proto_id == proto_id) {
14868                                                 printf(" %s", proto[n].name);
14869                                                 break;
14870                                         }
14871                                 }
14872                         }
14873                 }
14874                 printf("\n");
14875         }
14876         printf("\n");
14877         free(pctype);
14878
14879 no_print_pctypes:
14880
14881         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14882                                         sizeof(ptype_num),
14883                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14884         if (ret || !ptype_num)
14885                 goto no_print_return;
14886
14887         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14888         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14889         if (!ptype)
14890                 goto no_print_return;
14891
14892         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14893                                         buff_size,
14894                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14895         if (ret) {
14896                 free(ptype);
14897                 goto no_print_return;
14898         }
14899         printf("List of defined packet types:\n");
14900         for (i = 0; i < ptype_num; i++) {
14901                 printf("  %2u:", ptype[i].ptype_id);
14902                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14903                         proto_id = ptype[i].protocols[j];
14904                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14905                                 for (n = 0; n < proto_num; n++) {
14906                                         if (proto[n].proto_id == proto_id) {
14907                                                 printf(" %s", proto[n].name);
14908                                                 break;
14909                                         }
14910                                 }
14911                         }
14912                 }
14913                 printf("\n");
14914         }
14915         free(ptype);
14916         printf("\n");
14917
14918         ret = 0;
14919 no_print_return:
14920         if (proto)
14921                 free(proto);
14922 #endif
14923         if (ret == -ENOTSUP)
14924                 printf("Function not supported in PMD driver\n");
14925         close_file(pkg);
14926 }
14927
14928 cmdline_parse_inst_t cmd_ddp_get_info = {
14929         .f = cmd_ddp_info_parsed,
14930         .data = NULL,
14931         .help_str = "ddp get info <profile_path>",
14932         .tokens = {
14933                 (void *)&cmd_ddp_info_ddp,
14934                 (void *)&cmd_ddp_info_get,
14935                 (void *)&cmd_ddp_info_info,
14936                 (void *)&cmd_ddp_info_filepath,
14937                 NULL,
14938         },
14939 };
14940
14941 /* Get dynamic device personalization profile info list*/
14942 #define PROFILE_INFO_SIZE 48
14943 #define MAX_PROFILE_NUM 16
14944
14945 struct cmd_ddp_get_list_result {
14946         cmdline_fixed_string_t ddp;
14947         cmdline_fixed_string_t get;
14948         cmdline_fixed_string_t list;
14949         portid_t port_id;
14950 };
14951
14952 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14953         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14954 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14955         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14956 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14957         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14958 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14959         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14960
14961 static void
14962 cmd_ddp_get_list_parsed(
14963         __attribute__((unused)) void *parsed_result,
14964         __attribute__((unused)) struct cmdline *cl,
14965         __attribute__((unused)) void *data)
14966 {
14967 #ifdef RTE_LIBRTE_I40E_PMD
14968         struct cmd_ddp_get_list_result *res = parsed_result;
14969         struct rte_pmd_i40e_profile_list *p_list;
14970         struct rte_pmd_i40e_profile_info *p_info;
14971         uint32_t p_num;
14972         uint32_t size;
14973         uint32_t i;
14974 #endif
14975         int ret = -ENOTSUP;
14976
14977 #ifdef RTE_LIBRTE_I40E_PMD
14978         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14979         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14980         if (!p_list)
14981                 printf("%s: Failed to malloc buffer\n", __func__);
14982
14983         if (ret == -ENOTSUP)
14984                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14985                                                 (uint8_t *)p_list, size);
14986
14987         if (!ret) {
14988                 p_num = p_list->p_count;
14989                 printf("Profile number is: %d\n\n", p_num);
14990
14991                 for (i = 0; i < p_num; i++) {
14992                         p_info = &p_list->p_info[i];
14993                         printf("Profile %d:\n", i);
14994                         printf("Track id:     0x%x\n", p_info->track_id);
14995                         printf("Version:      %d.%d.%d.%d\n",
14996                                p_info->version.major,
14997                                p_info->version.minor,
14998                                p_info->version.update,
14999                                p_info->version.draft);
15000                         printf("Profile name: %s\n\n", p_info->name);
15001                 }
15002         }
15003
15004         free(p_list);
15005 #endif
15006
15007         if (ret < 0)
15008                 printf("Failed to get ddp list\n");
15009 }
15010
15011 cmdline_parse_inst_t cmd_ddp_get_list = {
15012         .f = cmd_ddp_get_list_parsed,
15013         .data = NULL,
15014         .help_str = "ddp get list <port_id>",
15015         .tokens = {
15016                 (void *)&cmd_ddp_get_list_ddp,
15017                 (void *)&cmd_ddp_get_list_get,
15018                 (void *)&cmd_ddp_get_list_list,
15019                 (void *)&cmd_ddp_get_list_port_id,
15020                 NULL,
15021         },
15022 };
15023
15024 /* Configure input set */
15025 struct cmd_cfg_input_set_result {
15026         cmdline_fixed_string_t port;
15027         cmdline_fixed_string_t cfg;
15028         portid_t port_id;
15029         cmdline_fixed_string_t pctype;
15030         uint8_t pctype_id;
15031         cmdline_fixed_string_t inset_type;
15032         cmdline_fixed_string_t opt;
15033         cmdline_fixed_string_t field;
15034         uint8_t field_idx;
15035 };
15036
15037 static void
15038 cmd_cfg_input_set_parsed(
15039         __attribute__((unused)) void *parsed_result,
15040         __attribute__((unused)) struct cmdline *cl,
15041         __attribute__((unused)) void *data)
15042 {
15043 #ifdef RTE_LIBRTE_I40E_PMD
15044         struct cmd_cfg_input_set_result *res = parsed_result;
15045         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15046         struct rte_pmd_i40e_inset inset;
15047 #endif
15048         int ret = -ENOTSUP;
15049
15050         if (!all_ports_stopped()) {
15051                 printf("Please stop all ports first\n");
15052                 return;
15053         }
15054
15055 #ifdef RTE_LIBRTE_I40E_PMD
15056         if (!strcmp(res->inset_type, "hash_inset"))
15057                 inset_type = INSET_HASH;
15058         else if (!strcmp(res->inset_type, "fdir_inset"))
15059                 inset_type = INSET_FDIR;
15060         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15061                 inset_type = INSET_FDIR_FLX;
15062         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15063                                      &inset, inset_type);
15064         if (ret) {
15065                 printf("Failed to get input set.\n");
15066                 return;
15067         }
15068
15069         if (!strcmp(res->opt, "get")) {
15070                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15071                                                    res->field_idx);
15072                 if (ret)
15073                         printf("Field index %d is enabled.\n", res->field_idx);
15074                 else
15075                         printf("Field index %d is disabled.\n", res->field_idx);
15076                 return;
15077         } else if (!strcmp(res->opt, "set"))
15078                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15079                                                    res->field_idx);
15080         else if (!strcmp(res->opt, "clear"))
15081                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15082                                                      res->field_idx);
15083         if (ret) {
15084                 printf("Failed to configure input set field.\n");
15085                 return;
15086         }
15087
15088         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15089                                      &inset, inset_type);
15090         if (ret) {
15091                 printf("Failed to set input set.\n");
15092                 return;
15093         }
15094 #endif
15095
15096         if (ret == -ENOTSUP)
15097                 printf("Function not supported\n");
15098 }
15099
15100 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15101         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15102                                  port, "port");
15103 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15104         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15105                                  cfg, "config");
15106 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15107         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15108                               port_id, UINT16);
15109 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15110         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15111                                  pctype, "pctype");
15112 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15113         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15114                               pctype_id, UINT8);
15115 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15116         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15117                                  inset_type,
15118                                  "hash_inset#fdir_inset#fdir_flx_inset");
15119 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15120         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15121                                  opt, "get#set#clear");
15122 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15123         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15124                                  field, "field");
15125 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15126         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15127                               field_idx, UINT8);
15128
15129 cmdline_parse_inst_t cmd_cfg_input_set = {
15130         .f = cmd_cfg_input_set_parsed,
15131         .data = NULL,
15132         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15133                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15134         .tokens = {
15135                 (void *)&cmd_cfg_input_set_port,
15136                 (void *)&cmd_cfg_input_set_cfg,
15137                 (void *)&cmd_cfg_input_set_port_id,
15138                 (void *)&cmd_cfg_input_set_pctype,
15139                 (void *)&cmd_cfg_input_set_pctype_id,
15140                 (void *)&cmd_cfg_input_set_inset_type,
15141                 (void *)&cmd_cfg_input_set_opt,
15142                 (void *)&cmd_cfg_input_set_field,
15143                 (void *)&cmd_cfg_input_set_field_idx,
15144                 NULL,
15145         },
15146 };
15147
15148 /* Clear input set */
15149 struct cmd_clear_input_set_result {
15150         cmdline_fixed_string_t port;
15151         cmdline_fixed_string_t cfg;
15152         portid_t port_id;
15153         cmdline_fixed_string_t pctype;
15154         uint8_t pctype_id;
15155         cmdline_fixed_string_t inset_type;
15156         cmdline_fixed_string_t clear;
15157         cmdline_fixed_string_t all;
15158 };
15159
15160 static void
15161 cmd_clear_input_set_parsed(
15162         __attribute__((unused)) void *parsed_result,
15163         __attribute__((unused)) struct cmdline *cl,
15164         __attribute__((unused)) void *data)
15165 {
15166 #ifdef RTE_LIBRTE_I40E_PMD
15167         struct cmd_clear_input_set_result *res = parsed_result;
15168         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15169         struct rte_pmd_i40e_inset inset;
15170 #endif
15171         int ret = -ENOTSUP;
15172
15173         if (!all_ports_stopped()) {
15174                 printf("Please stop all ports first\n");
15175                 return;
15176         }
15177
15178 #ifdef RTE_LIBRTE_I40E_PMD
15179         if (!strcmp(res->inset_type, "hash_inset"))
15180                 inset_type = INSET_HASH;
15181         else if (!strcmp(res->inset_type, "fdir_inset"))
15182                 inset_type = INSET_FDIR;
15183         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15184                 inset_type = INSET_FDIR_FLX;
15185
15186         memset(&inset, 0, sizeof(inset));
15187
15188         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15189                                      &inset, inset_type);
15190         if (ret) {
15191                 printf("Failed to clear input set.\n");
15192                 return;
15193         }
15194
15195 #endif
15196
15197         if (ret == -ENOTSUP)
15198                 printf("Function not supported\n");
15199 }
15200
15201 cmdline_parse_token_string_t cmd_clear_input_set_port =
15202         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15203                                  port, "port");
15204 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15205         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15206                                  cfg, "config");
15207 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15208         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15209                               port_id, UINT16);
15210 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15211         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15212                                  pctype, "pctype");
15213 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15214         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15215                               pctype_id, UINT8);
15216 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15217         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15218                                  inset_type,
15219                                  "hash_inset#fdir_inset#fdir_flx_inset");
15220 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15221         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15222                                  clear, "clear");
15223 cmdline_parse_token_string_t cmd_clear_input_set_all =
15224         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15225                                  all, "all");
15226
15227 cmdline_parse_inst_t cmd_clear_input_set = {
15228         .f = cmd_clear_input_set_parsed,
15229         .data = NULL,
15230         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15231                     "fdir_inset|fdir_flx_inset clear all",
15232         .tokens = {
15233                 (void *)&cmd_clear_input_set_port,
15234                 (void *)&cmd_clear_input_set_cfg,
15235                 (void *)&cmd_clear_input_set_port_id,
15236                 (void *)&cmd_clear_input_set_pctype,
15237                 (void *)&cmd_clear_input_set_pctype_id,
15238                 (void *)&cmd_clear_input_set_inset_type,
15239                 (void *)&cmd_clear_input_set_clear,
15240                 (void *)&cmd_clear_input_set_all,
15241                 NULL,
15242         },
15243 };
15244
15245 /* show vf stats */
15246
15247 /* Common result structure for show vf stats */
15248 struct cmd_show_vf_stats_result {
15249         cmdline_fixed_string_t show;
15250         cmdline_fixed_string_t vf;
15251         cmdline_fixed_string_t stats;
15252         portid_t port_id;
15253         uint16_t vf_id;
15254 };
15255
15256 /* Common CLI fields show vf stats*/
15257 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15258         TOKEN_STRING_INITIALIZER
15259                 (struct cmd_show_vf_stats_result,
15260                  show, "show");
15261 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15262         TOKEN_STRING_INITIALIZER
15263                 (struct cmd_show_vf_stats_result,
15264                  vf, "vf");
15265 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15266         TOKEN_STRING_INITIALIZER
15267                 (struct cmd_show_vf_stats_result,
15268                  stats, "stats");
15269 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15270         TOKEN_NUM_INITIALIZER
15271                 (struct cmd_show_vf_stats_result,
15272                  port_id, UINT16);
15273 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15274         TOKEN_NUM_INITIALIZER
15275                 (struct cmd_show_vf_stats_result,
15276                  vf_id, UINT16);
15277
15278 static void
15279 cmd_show_vf_stats_parsed(
15280         void *parsed_result,
15281         __attribute__((unused)) struct cmdline *cl,
15282         __attribute__((unused)) void *data)
15283 {
15284         struct cmd_show_vf_stats_result *res = parsed_result;
15285         struct rte_eth_stats stats;
15286         int ret = -ENOTSUP;
15287         static const char *nic_stats_border = "########################";
15288
15289         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15290                 return;
15291
15292         memset(&stats, 0, sizeof(stats));
15293
15294 #ifdef RTE_LIBRTE_I40E_PMD
15295         if (ret == -ENOTSUP)
15296                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15297                                                 res->vf_id,
15298                                                 &stats);
15299 #endif
15300 #ifdef RTE_LIBRTE_BNXT_PMD
15301         if (ret == -ENOTSUP)
15302                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15303                                                 res->vf_id,
15304                                                 &stats);
15305 #endif
15306
15307         switch (ret) {
15308         case 0:
15309                 break;
15310         case -EINVAL:
15311                 printf("invalid vf_id %d\n", res->vf_id);
15312                 break;
15313         case -ENODEV:
15314                 printf("invalid port_id %d\n", res->port_id);
15315                 break;
15316         case -ENOTSUP:
15317                 printf("function not implemented\n");
15318                 break;
15319         default:
15320                 printf("programming error: (%s)\n", strerror(-ret));
15321         }
15322
15323         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15324                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15325
15326         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15327                "%-"PRIu64"\n",
15328                stats.ipackets, stats.imissed, stats.ibytes);
15329         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15330         printf("  RX-nombuf:  %-10"PRIu64"\n",
15331                stats.rx_nombuf);
15332         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15333                "%-"PRIu64"\n",
15334                stats.opackets, stats.oerrors, stats.obytes);
15335
15336         printf("  %s############################%s\n",
15337                                nic_stats_border, nic_stats_border);
15338 }
15339
15340 cmdline_parse_inst_t cmd_show_vf_stats = {
15341         .f = cmd_show_vf_stats_parsed,
15342         .data = NULL,
15343         .help_str = "show vf stats <port_id> <vf_id>",
15344         .tokens = {
15345                 (void *)&cmd_show_vf_stats_show,
15346                 (void *)&cmd_show_vf_stats_vf,
15347                 (void *)&cmd_show_vf_stats_stats,
15348                 (void *)&cmd_show_vf_stats_port_id,
15349                 (void *)&cmd_show_vf_stats_vf_id,
15350                 NULL,
15351         },
15352 };
15353
15354 /* clear vf stats */
15355
15356 /* Common result structure for clear vf stats */
15357 struct cmd_clear_vf_stats_result {
15358         cmdline_fixed_string_t clear;
15359         cmdline_fixed_string_t vf;
15360         cmdline_fixed_string_t stats;
15361         portid_t port_id;
15362         uint16_t vf_id;
15363 };
15364
15365 /* Common CLI fields clear vf stats*/
15366 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15367         TOKEN_STRING_INITIALIZER
15368                 (struct cmd_clear_vf_stats_result,
15369                  clear, "clear");
15370 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15371         TOKEN_STRING_INITIALIZER
15372                 (struct cmd_clear_vf_stats_result,
15373                  vf, "vf");
15374 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15375         TOKEN_STRING_INITIALIZER
15376                 (struct cmd_clear_vf_stats_result,
15377                  stats, "stats");
15378 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15379         TOKEN_NUM_INITIALIZER
15380                 (struct cmd_clear_vf_stats_result,
15381                  port_id, UINT16);
15382 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15383         TOKEN_NUM_INITIALIZER
15384                 (struct cmd_clear_vf_stats_result,
15385                  vf_id, UINT16);
15386
15387 static void
15388 cmd_clear_vf_stats_parsed(
15389         void *parsed_result,
15390         __attribute__((unused)) struct cmdline *cl,
15391         __attribute__((unused)) void *data)
15392 {
15393         struct cmd_clear_vf_stats_result *res = parsed_result;
15394         int ret = -ENOTSUP;
15395
15396         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15397                 return;
15398
15399 #ifdef RTE_LIBRTE_I40E_PMD
15400         if (ret == -ENOTSUP)
15401                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15402                                                   res->vf_id);
15403 #endif
15404 #ifdef RTE_LIBRTE_BNXT_PMD
15405         if (ret == -ENOTSUP)
15406                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15407                                                   res->vf_id);
15408 #endif
15409
15410         switch (ret) {
15411         case 0:
15412                 break;
15413         case -EINVAL:
15414                 printf("invalid vf_id %d\n", res->vf_id);
15415                 break;
15416         case -ENODEV:
15417                 printf("invalid port_id %d\n", res->port_id);
15418                 break;
15419         case -ENOTSUP:
15420                 printf("function not implemented\n");
15421                 break;
15422         default:
15423                 printf("programming error: (%s)\n", strerror(-ret));
15424         }
15425 }
15426
15427 cmdline_parse_inst_t cmd_clear_vf_stats = {
15428         .f = cmd_clear_vf_stats_parsed,
15429         .data = NULL,
15430         .help_str = "clear vf stats <port_id> <vf_id>",
15431         .tokens = {
15432                 (void *)&cmd_clear_vf_stats_clear,
15433                 (void *)&cmd_clear_vf_stats_vf,
15434                 (void *)&cmd_clear_vf_stats_stats,
15435                 (void *)&cmd_clear_vf_stats_port_id,
15436                 (void *)&cmd_clear_vf_stats_vf_id,
15437                 NULL,
15438         },
15439 };
15440
15441 /* port config pctype mapping reset */
15442
15443 /* Common result structure for port config pctype mapping reset */
15444 struct cmd_pctype_mapping_reset_result {
15445         cmdline_fixed_string_t port;
15446         cmdline_fixed_string_t config;
15447         portid_t port_id;
15448         cmdline_fixed_string_t pctype;
15449         cmdline_fixed_string_t mapping;
15450         cmdline_fixed_string_t reset;
15451 };
15452
15453 /* Common CLI fields for port config pctype mapping reset*/
15454 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15455         TOKEN_STRING_INITIALIZER
15456                 (struct cmd_pctype_mapping_reset_result,
15457                  port, "port");
15458 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15459         TOKEN_STRING_INITIALIZER
15460                 (struct cmd_pctype_mapping_reset_result,
15461                  config, "config");
15462 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15463         TOKEN_NUM_INITIALIZER
15464                 (struct cmd_pctype_mapping_reset_result,
15465                  port_id, UINT16);
15466 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15467         TOKEN_STRING_INITIALIZER
15468                 (struct cmd_pctype_mapping_reset_result,
15469                  pctype, "pctype");
15470 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15471         TOKEN_STRING_INITIALIZER
15472                 (struct cmd_pctype_mapping_reset_result,
15473                  mapping, "mapping");
15474 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15475         TOKEN_STRING_INITIALIZER
15476                 (struct cmd_pctype_mapping_reset_result,
15477                  reset, "reset");
15478
15479 static void
15480 cmd_pctype_mapping_reset_parsed(
15481         void *parsed_result,
15482         __attribute__((unused)) struct cmdline *cl,
15483         __attribute__((unused)) void *data)
15484 {
15485         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15486         int ret = -ENOTSUP;
15487
15488         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15489                 return;
15490
15491 #ifdef RTE_LIBRTE_I40E_PMD
15492         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15493 #endif
15494
15495         switch (ret) {
15496         case 0:
15497                 break;
15498         case -ENODEV:
15499                 printf("invalid port_id %d\n", res->port_id);
15500                 break;
15501         case -ENOTSUP:
15502                 printf("function not implemented\n");
15503                 break;
15504         default:
15505                 printf("programming error: (%s)\n", strerror(-ret));
15506         }
15507 }
15508
15509 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15510         .f = cmd_pctype_mapping_reset_parsed,
15511         .data = NULL,
15512         .help_str = "port config <port_id> pctype mapping reset",
15513         .tokens = {
15514                 (void *)&cmd_pctype_mapping_reset_port,
15515                 (void *)&cmd_pctype_mapping_reset_config,
15516                 (void *)&cmd_pctype_mapping_reset_port_id,
15517                 (void *)&cmd_pctype_mapping_reset_pctype,
15518                 (void *)&cmd_pctype_mapping_reset_mapping,
15519                 (void *)&cmd_pctype_mapping_reset_reset,
15520                 NULL,
15521         },
15522 };
15523
15524 /* show port pctype mapping */
15525
15526 /* Common result structure for show port pctype mapping */
15527 struct cmd_pctype_mapping_get_result {
15528         cmdline_fixed_string_t show;
15529         cmdline_fixed_string_t port;
15530         portid_t port_id;
15531         cmdline_fixed_string_t pctype;
15532         cmdline_fixed_string_t mapping;
15533 };
15534
15535 /* Common CLI fields for pctype mapping get */
15536 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15537         TOKEN_STRING_INITIALIZER
15538                 (struct cmd_pctype_mapping_get_result,
15539                  show, "show");
15540 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15541         TOKEN_STRING_INITIALIZER
15542                 (struct cmd_pctype_mapping_get_result,
15543                  port, "port");
15544 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15545         TOKEN_NUM_INITIALIZER
15546                 (struct cmd_pctype_mapping_get_result,
15547                  port_id, UINT16);
15548 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15549         TOKEN_STRING_INITIALIZER
15550                 (struct cmd_pctype_mapping_get_result,
15551                  pctype, "pctype");
15552 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15553         TOKEN_STRING_INITIALIZER
15554                 (struct cmd_pctype_mapping_get_result,
15555                  mapping, "mapping");
15556
15557 static void
15558 cmd_pctype_mapping_get_parsed(
15559         void *parsed_result,
15560         __attribute__((unused)) struct cmdline *cl,
15561         __attribute__((unused)) void *data)
15562 {
15563         struct cmd_pctype_mapping_get_result *res = parsed_result;
15564         int ret = -ENOTSUP;
15565 #ifdef RTE_LIBRTE_I40E_PMD
15566         struct rte_pmd_i40e_flow_type_mapping
15567                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15568         int i, j, first_pctype;
15569 #endif
15570
15571         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15572                 return;
15573
15574 #ifdef RTE_LIBRTE_I40E_PMD
15575         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15576 #endif
15577
15578         switch (ret) {
15579         case 0:
15580                 break;
15581         case -ENODEV:
15582                 printf("invalid port_id %d\n", res->port_id);
15583                 return;
15584         case -ENOTSUP:
15585                 printf("function not implemented\n");
15586                 return;
15587         default:
15588                 printf("programming error: (%s)\n", strerror(-ret));
15589                 return;
15590         }
15591
15592 #ifdef RTE_LIBRTE_I40E_PMD
15593         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15594                 if (mapping[i].pctype != 0ULL) {
15595                         first_pctype = 1;
15596
15597                         printf("pctype: ");
15598                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15599                                 if (mapping[i].pctype & (1ULL << j)) {
15600                                         printf(first_pctype ?
15601                                                "%02d" : ",%02d", j);
15602                                         first_pctype = 0;
15603                                 }
15604                         }
15605                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15606                 }
15607         }
15608 #endif
15609 }
15610
15611 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15612         .f = cmd_pctype_mapping_get_parsed,
15613         .data = NULL,
15614         .help_str = "show port <port_id> pctype mapping",
15615         .tokens = {
15616                 (void *)&cmd_pctype_mapping_get_show,
15617                 (void *)&cmd_pctype_mapping_get_port,
15618                 (void *)&cmd_pctype_mapping_get_port_id,
15619                 (void *)&cmd_pctype_mapping_get_pctype,
15620                 (void *)&cmd_pctype_mapping_get_mapping,
15621                 NULL,
15622         },
15623 };
15624
15625 /* port config pctype mapping update */
15626
15627 /* Common result structure for port config pctype mapping update */
15628 struct cmd_pctype_mapping_update_result {
15629         cmdline_fixed_string_t port;
15630         cmdline_fixed_string_t config;
15631         portid_t port_id;
15632         cmdline_fixed_string_t pctype;
15633         cmdline_fixed_string_t mapping;
15634         cmdline_fixed_string_t update;
15635         cmdline_fixed_string_t pctype_list;
15636         uint16_t flow_type;
15637 };
15638
15639 /* Common CLI fields for pctype mapping update*/
15640 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15641         TOKEN_STRING_INITIALIZER
15642                 (struct cmd_pctype_mapping_update_result,
15643                  port, "port");
15644 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15645         TOKEN_STRING_INITIALIZER
15646                 (struct cmd_pctype_mapping_update_result,
15647                  config, "config");
15648 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15649         TOKEN_NUM_INITIALIZER
15650                 (struct cmd_pctype_mapping_update_result,
15651                  port_id, UINT16);
15652 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15653         TOKEN_STRING_INITIALIZER
15654                 (struct cmd_pctype_mapping_update_result,
15655                  pctype, "pctype");
15656 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15657         TOKEN_STRING_INITIALIZER
15658                 (struct cmd_pctype_mapping_update_result,
15659                  mapping, "mapping");
15660 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15661         TOKEN_STRING_INITIALIZER
15662                 (struct cmd_pctype_mapping_update_result,
15663                  update, "update");
15664 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15665         TOKEN_STRING_INITIALIZER
15666                 (struct cmd_pctype_mapping_update_result,
15667                  pctype_list, NULL);
15668 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15669         TOKEN_NUM_INITIALIZER
15670                 (struct cmd_pctype_mapping_update_result,
15671                  flow_type, UINT16);
15672
15673 static void
15674 cmd_pctype_mapping_update_parsed(
15675         void *parsed_result,
15676         __attribute__((unused)) struct cmdline *cl,
15677         __attribute__((unused)) void *data)
15678 {
15679         struct cmd_pctype_mapping_update_result *res = parsed_result;
15680         int ret = -ENOTSUP;
15681 #ifdef RTE_LIBRTE_I40E_PMD
15682         struct rte_pmd_i40e_flow_type_mapping mapping;
15683         unsigned int i;
15684         unsigned int nb_item;
15685         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15686 #endif
15687
15688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15689                 return;
15690
15691 #ifdef RTE_LIBRTE_I40E_PMD
15692         nb_item = parse_item_list(res->pctype_list, "pctypes",
15693                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15694         mapping.flow_type = res->flow_type;
15695         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15696                 mapping.pctype |= (1ULL << pctype_list[i]);
15697         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15698                                                 &mapping,
15699                                                 1,
15700                                                 0);
15701 #endif
15702
15703         switch (ret) {
15704         case 0:
15705                 break;
15706         case -EINVAL:
15707                 printf("invalid pctype or flow type\n");
15708                 break;
15709         case -ENODEV:
15710                 printf("invalid port_id %d\n", res->port_id);
15711                 break;
15712         case -ENOTSUP:
15713                 printf("function not implemented\n");
15714                 break;
15715         default:
15716                 printf("programming error: (%s)\n", strerror(-ret));
15717         }
15718 }
15719
15720 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15721         .f = cmd_pctype_mapping_update_parsed,
15722         .data = NULL,
15723         .help_str = "port config <port_id> pctype mapping update"
15724         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15725         .tokens = {
15726                 (void *)&cmd_pctype_mapping_update_port,
15727                 (void *)&cmd_pctype_mapping_update_config,
15728                 (void *)&cmd_pctype_mapping_update_port_id,
15729                 (void *)&cmd_pctype_mapping_update_pctype,
15730                 (void *)&cmd_pctype_mapping_update_mapping,
15731                 (void *)&cmd_pctype_mapping_update_update,
15732                 (void *)&cmd_pctype_mapping_update_pc_type,
15733                 (void *)&cmd_pctype_mapping_update_flow_type,
15734                 NULL,
15735         },
15736 };
15737
15738 /* ptype mapping get */
15739
15740 /* Common result structure for ptype mapping get */
15741 struct cmd_ptype_mapping_get_result {
15742         cmdline_fixed_string_t ptype;
15743         cmdline_fixed_string_t mapping;
15744         cmdline_fixed_string_t get;
15745         portid_t port_id;
15746         uint8_t valid_only;
15747 };
15748
15749 /* Common CLI fields for ptype mapping get */
15750 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15751         TOKEN_STRING_INITIALIZER
15752                 (struct cmd_ptype_mapping_get_result,
15753                  ptype, "ptype");
15754 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15755         TOKEN_STRING_INITIALIZER
15756                 (struct cmd_ptype_mapping_get_result,
15757                  mapping, "mapping");
15758 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15759         TOKEN_STRING_INITIALIZER
15760                 (struct cmd_ptype_mapping_get_result,
15761                  get, "get");
15762 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15763         TOKEN_NUM_INITIALIZER
15764                 (struct cmd_ptype_mapping_get_result,
15765                  port_id, UINT16);
15766 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15767         TOKEN_NUM_INITIALIZER
15768                 (struct cmd_ptype_mapping_get_result,
15769                  valid_only, UINT8);
15770
15771 static void
15772 cmd_ptype_mapping_get_parsed(
15773         void *parsed_result,
15774         __attribute__((unused)) struct cmdline *cl,
15775         __attribute__((unused)) void *data)
15776 {
15777         struct cmd_ptype_mapping_get_result *res = parsed_result;
15778         int ret = -ENOTSUP;
15779 #ifdef RTE_LIBRTE_I40E_PMD
15780         int max_ptype_num = 256;
15781         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15782         uint16_t count;
15783         int i;
15784 #endif
15785
15786         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15787                 return;
15788
15789 #ifdef RTE_LIBRTE_I40E_PMD
15790         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15791                                         mapping,
15792                                         max_ptype_num,
15793                                         &count,
15794                                         res->valid_only);
15795 #endif
15796
15797         switch (ret) {
15798         case 0:
15799                 break;
15800         case -ENODEV:
15801                 printf("invalid port_id %d\n", res->port_id);
15802                 break;
15803         case -ENOTSUP:
15804                 printf("function not implemented\n");
15805                 break;
15806         default:
15807                 printf("programming error: (%s)\n", strerror(-ret));
15808         }
15809
15810 #ifdef RTE_LIBRTE_I40E_PMD
15811         if (!ret) {
15812                 for (i = 0; i < count; i++)
15813                         printf("%3d\t0x%08x\n",
15814                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15815         }
15816 #endif
15817 }
15818
15819 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15820         .f = cmd_ptype_mapping_get_parsed,
15821         .data = NULL,
15822         .help_str = "ptype mapping get <port_id> <valid_only>",
15823         .tokens = {
15824                 (void *)&cmd_ptype_mapping_get_ptype,
15825                 (void *)&cmd_ptype_mapping_get_mapping,
15826                 (void *)&cmd_ptype_mapping_get_get,
15827                 (void *)&cmd_ptype_mapping_get_port_id,
15828                 (void *)&cmd_ptype_mapping_get_valid_only,
15829                 NULL,
15830         },
15831 };
15832
15833 /* ptype mapping replace */
15834
15835 /* Common result structure for ptype mapping replace */
15836 struct cmd_ptype_mapping_replace_result {
15837         cmdline_fixed_string_t ptype;
15838         cmdline_fixed_string_t mapping;
15839         cmdline_fixed_string_t replace;
15840         portid_t port_id;
15841         uint32_t target;
15842         uint8_t mask;
15843         uint32_t pkt_type;
15844 };
15845
15846 /* Common CLI fields for ptype mapping replace */
15847 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15848         TOKEN_STRING_INITIALIZER
15849                 (struct cmd_ptype_mapping_replace_result,
15850                  ptype, "ptype");
15851 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15852         TOKEN_STRING_INITIALIZER
15853                 (struct cmd_ptype_mapping_replace_result,
15854                  mapping, "mapping");
15855 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15856         TOKEN_STRING_INITIALIZER
15857                 (struct cmd_ptype_mapping_replace_result,
15858                  replace, "replace");
15859 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15860         TOKEN_NUM_INITIALIZER
15861                 (struct cmd_ptype_mapping_replace_result,
15862                  port_id, UINT16);
15863 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15864         TOKEN_NUM_INITIALIZER
15865                 (struct cmd_ptype_mapping_replace_result,
15866                  target, UINT32);
15867 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15868         TOKEN_NUM_INITIALIZER
15869                 (struct cmd_ptype_mapping_replace_result,
15870                  mask, UINT8);
15871 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15872         TOKEN_NUM_INITIALIZER
15873                 (struct cmd_ptype_mapping_replace_result,
15874                  pkt_type, UINT32);
15875
15876 static void
15877 cmd_ptype_mapping_replace_parsed(
15878         void *parsed_result,
15879         __attribute__((unused)) struct cmdline *cl,
15880         __attribute__((unused)) void *data)
15881 {
15882         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15883         int ret = -ENOTSUP;
15884
15885         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15886                 return;
15887
15888 #ifdef RTE_LIBRTE_I40E_PMD
15889         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15890                                         res->target,
15891                                         res->mask,
15892                                         res->pkt_type);
15893 #endif
15894
15895         switch (ret) {
15896         case 0:
15897                 break;
15898         case -EINVAL:
15899                 printf("invalid ptype 0x%8x or 0x%8x\n",
15900                                 res->target, res->pkt_type);
15901                 break;
15902         case -ENODEV:
15903                 printf("invalid port_id %d\n", res->port_id);
15904                 break;
15905         case -ENOTSUP:
15906                 printf("function not implemented\n");
15907                 break;
15908         default:
15909                 printf("programming error: (%s)\n", strerror(-ret));
15910         }
15911 }
15912
15913 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15914         .f = cmd_ptype_mapping_replace_parsed,
15915         .data = NULL,
15916         .help_str =
15917                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15918         .tokens = {
15919                 (void *)&cmd_ptype_mapping_replace_ptype,
15920                 (void *)&cmd_ptype_mapping_replace_mapping,
15921                 (void *)&cmd_ptype_mapping_replace_replace,
15922                 (void *)&cmd_ptype_mapping_replace_port_id,
15923                 (void *)&cmd_ptype_mapping_replace_target,
15924                 (void *)&cmd_ptype_mapping_replace_mask,
15925                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15926                 NULL,
15927         },
15928 };
15929
15930 /* ptype mapping reset */
15931
15932 /* Common result structure for ptype mapping reset */
15933 struct cmd_ptype_mapping_reset_result {
15934         cmdline_fixed_string_t ptype;
15935         cmdline_fixed_string_t mapping;
15936         cmdline_fixed_string_t reset;
15937         portid_t port_id;
15938 };
15939
15940 /* Common CLI fields for ptype mapping reset*/
15941 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15942         TOKEN_STRING_INITIALIZER
15943                 (struct cmd_ptype_mapping_reset_result,
15944                  ptype, "ptype");
15945 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15946         TOKEN_STRING_INITIALIZER
15947                 (struct cmd_ptype_mapping_reset_result,
15948                  mapping, "mapping");
15949 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15950         TOKEN_STRING_INITIALIZER
15951                 (struct cmd_ptype_mapping_reset_result,
15952                  reset, "reset");
15953 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15954         TOKEN_NUM_INITIALIZER
15955                 (struct cmd_ptype_mapping_reset_result,
15956                  port_id, UINT16);
15957
15958 static void
15959 cmd_ptype_mapping_reset_parsed(
15960         void *parsed_result,
15961         __attribute__((unused)) struct cmdline *cl,
15962         __attribute__((unused)) void *data)
15963 {
15964         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15965         int ret = -ENOTSUP;
15966
15967         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15968                 return;
15969
15970 #ifdef RTE_LIBRTE_I40E_PMD
15971         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15972 #endif
15973
15974         switch (ret) {
15975         case 0:
15976                 break;
15977         case -ENODEV:
15978                 printf("invalid port_id %d\n", res->port_id);
15979                 break;
15980         case -ENOTSUP:
15981                 printf("function not implemented\n");
15982                 break;
15983         default:
15984                 printf("programming error: (%s)\n", strerror(-ret));
15985         }
15986 }
15987
15988 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15989         .f = cmd_ptype_mapping_reset_parsed,
15990         .data = NULL,
15991         .help_str = "ptype mapping reset <port_id>",
15992         .tokens = {
15993                 (void *)&cmd_ptype_mapping_reset_ptype,
15994                 (void *)&cmd_ptype_mapping_reset_mapping,
15995                 (void *)&cmd_ptype_mapping_reset_reset,
15996                 (void *)&cmd_ptype_mapping_reset_port_id,
15997                 NULL,
15998         },
15999 };
16000
16001 /* ptype mapping update */
16002
16003 /* Common result structure for ptype mapping update */
16004 struct cmd_ptype_mapping_update_result {
16005         cmdline_fixed_string_t ptype;
16006         cmdline_fixed_string_t mapping;
16007         cmdline_fixed_string_t reset;
16008         portid_t port_id;
16009         uint8_t hw_ptype;
16010         uint32_t sw_ptype;
16011 };
16012
16013 /* Common CLI fields for ptype mapping update*/
16014 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16015         TOKEN_STRING_INITIALIZER
16016                 (struct cmd_ptype_mapping_update_result,
16017                  ptype, "ptype");
16018 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16019         TOKEN_STRING_INITIALIZER
16020                 (struct cmd_ptype_mapping_update_result,
16021                  mapping, "mapping");
16022 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16023         TOKEN_STRING_INITIALIZER
16024                 (struct cmd_ptype_mapping_update_result,
16025                  reset, "update");
16026 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16027         TOKEN_NUM_INITIALIZER
16028                 (struct cmd_ptype_mapping_update_result,
16029                  port_id, UINT16);
16030 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16031         TOKEN_NUM_INITIALIZER
16032                 (struct cmd_ptype_mapping_update_result,
16033                  hw_ptype, UINT8);
16034 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16035         TOKEN_NUM_INITIALIZER
16036                 (struct cmd_ptype_mapping_update_result,
16037                  sw_ptype, UINT32);
16038
16039 static void
16040 cmd_ptype_mapping_update_parsed(
16041         void *parsed_result,
16042         __attribute__((unused)) struct cmdline *cl,
16043         __attribute__((unused)) void *data)
16044 {
16045         struct cmd_ptype_mapping_update_result *res = parsed_result;
16046         int ret = -ENOTSUP;
16047 #ifdef RTE_LIBRTE_I40E_PMD
16048         struct rte_pmd_i40e_ptype_mapping mapping;
16049 #endif
16050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16051                 return;
16052
16053 #ifdef RTE_LIBRTE_I40E_PMD
16054         mapping.hw_ptype = res->hw_ptype;
16055         mapping.sw_ptype = res->sw_ptype;
16056         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16057                                                 &mapping,
16058                                                 1,
16059                                                 0);
16060 #endif
16061
16062         switch (ret) {
16063         case 0:
16064                 break;
16065         case -EINVAL:
16066                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16067                 break;
16068         case -ENODEV:
16069                 printf("invalid port_id %d\n", res->port_id);
16070                 break;
16071         case -ENOTSUP:
16072                 printf("function not implemented\n");
16073                 break;
16074         default:
16075                 printf("programming error: (%s)\n", strerror(-ret));
16076         }
16077 }
16078
16079 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16080         .f = cmd_ptype_mapping_update_parsed,
16081         .data = NULL,
16082         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16083         .tokens = {
16084                 (void *)&cmd_ptype_mapping_update_ptype,
16085                 (void *)&cmd_ptype_mapping_update_mapping,
16086                 (void *)&cmd_ptype_mapping_update_update,
16087                 (void *)&cmd_ptype_mapping_update_port_id,
16088                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16089                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16090                 NULL,
16091         },
16092 };
16093
16094 /* Common result structure for file commands */
16095 struct cmd_cmdfile_result {
16096         cmdline_fixed_string_t load;
16097         cmdline_fixed_string_t filename;
16098 };
16099
16100 /* Common CLI fields for file commands */
16101 cmdline_parse_token_string_t cmd_load_cmdfile =
16102         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16103 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16104         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16105
16106 static void
16107 cmd_load_from_file_parsed(
16108         void *parsed_result,
16109         __attribute__((unused)) struct cmdline *cl,
16110         __attribute__((unused)) void *data)
16111 {
16112         struct cmd_cmdfile_result *res = parsed_result;
16113
16114         cmdline_read_from_file(res->filename);
16115 }
16116
16117 cmdline_parse_inst_t cmd_load_from_file = {
16118         .f = cmd_load_from_file_parsed,
16119         .data = NULL,
16120         .help_str = "load <filename>",
16121         .tokens = {
16122                 (void *)&cmd_load_cmdfile,
16123                 (void *)&cmd_load_cmdfile_filename,
16124                 NULL,
16125         },
16126 };
16127
16128 /* ******************************************************************************** */
16129
16130 /* list of instructions */
16131 cmdline_parse_ctx_t main_ctx[] = {
16132         (cmdline_parse_inst_t *)&cmd_help_brief,
16133         (cmdline_parse_inst_t *)&cmd_help_long,
16134         (cmdline_parse_inst_t *)&cmd_quit,
16135         (cmdline_parse_inst_t *)&cmd_load_from_file,
16136         (cmdline_parse_inst_t *)&cmd_showport,
16137         (cmdline_parse_inst_t *)&cmd_showqueue,
16138         (cmdline_parse_inst_t *)&cmd_showportall,
16139         (cmdline_parse_inst_t *)&cmd_showcfg,
16140         (cmdline_parse_inst_t *)&cmd_start,
16141         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16142         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16143         (cmdline_parse_inst_t *)&cmd_set_link_up,
16144         (cmdline_parse_inst_t *)&cmd_set_link_down,
16145         (cmdline_parse_inst_t *)&cmd_reset,
16146         (cmdline_parse_inst_t *)&cmd_set_numbers,
16147         (cmdline_parse_inst_t *)&cmd_set_log,
16148         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16149         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16150         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16151         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16152         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16153         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16154         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16155         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16156         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16157         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16158         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16159         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16160         (cmdline_parse_inst_t *)&cmd_set_link_check,
16161         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16162         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16163         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16164         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16165 #ifdef RTE_LIBRTE_PMD_BOND
16166         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16167         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16168         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16169         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16170         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16171         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16172         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16173         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16174         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16175         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16176         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16177 #endif
16178         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16179         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16180         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16181         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16182         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16183         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16184         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16185         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16186         (cmdline_parse_inst_t *)&cmd_csum_set,
16187         (cmdline_parse_inst_t *)&cmd_csum_show,
16188         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16189         (cmdline_parse_inst_t *)&cmd_tso_set,
16190         (cmdline_parse_inst_t *)&cmd_tso_show,
16191         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16192         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16193         (cmdline_parse_inst_t *)&cmd_gro_enable,
16194         (cmdline_parse_inst_t *)&cmd_gro_flush,
16195         (cmdline_parse_inst_t *)&cmd_gro_show,
16196         (cmdline_parse_inst_t *)&cmd_gso_enable,
16197         (cmdline_parse_inst_t *)&cmd_gso_size,
16198         (cmdline_parse_inst_t *)&cmd_gso_show,
16199         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16200         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16201         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16202         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16203         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16204         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16205         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16206         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16207         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16208         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16209         (cmdline_parse_inst_t *)&cmd_config_dcb,
16210         (cmdline_parse_inst_t *)&cmd_read_reg,
16211         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16212         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16213         (cmdline_parse_inst_t *)&cmd_write_reg,
16214         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16215         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16216         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16217         (cmdline_parse_inst_t *)&cmd_stop,
16218         (cmdline_parse_inst_t *)&cmd_mac_addr,
16219         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16220         (cmdline_parse_inst_t *)&cmd_set_qmap,
16221         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16222         (cmdline_parse_inst_t *)&cmd_operate_port,
16223         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16224         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16225         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16226         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16227         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16228         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16229         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16230         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16231         (cmdline_parse_inst_t *)&cmd_config_mtu,
16232         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16233         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16234         (cmdline_parse_inst_t *)&cmd_config_rss,
16235         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16236         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16237         (cmdline_parse_inst_t *)&cmd_showport_reta,
16238         (cmdline_parse_inst_t *)&cmd_config_burst,
16239         (cmdline_parse_inst_t *)&cmd_config_thresh,
16240         (cmdline_parse_inst_t *)&cmd_config_threshold,
16241         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16242         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16243         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16244         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16245         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16246         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16247         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16248         (cmdline_parse_inst_t *)&cmd_global_config,
16249         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16250         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16251         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16252         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16253         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16254         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16255         (cmdline_parse_inst_t *)&cmd_dump,
16256         (cmdline_parse_inst_t *)&cmd_dump_one,
16257         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16258         (cmdline_parse_inst_t *)&cmd_syn_filter,
16259         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16260         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16261         (cmdline_parse_inst_t *)&cmd_flex_filter,
16262         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16263         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16264         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16265         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16266         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16267         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16268         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16269         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16270         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16271         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16272         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16273         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16274         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16275         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16276         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16277         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16278         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16279         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16280         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16281         (cmdline_parse_inst_t *)&cmd_flow,
16282         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16283         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16284         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16285         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16286         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16287         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16288         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16289         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16290         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16291         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16292         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16293         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16294         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16295         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16296         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16297         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16298         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16299         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16300         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16301         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16302         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16303         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16304         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16305         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16306         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16307         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16308         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16309         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16310         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16311         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16312         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16313         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16314         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16315         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16316         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16317         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16318         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16319         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16320         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16321         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16322         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16323         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16324         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16325         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16326         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16327         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16328         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16329         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16330         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16331 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16332         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16333 #endif
16334         (cmdline_parse_inst_t *)&cmd_ddp_add,
16335         (cmdline_parse_inst_t *)&cmd_ddp_del,
16336         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16337         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16338         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16339         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16340         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16341         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16342         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16343         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16344         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16345         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16346
16347         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16348         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16349         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16350         (cmdline_parse_inst_t *)&cmd_queue_region,
16351         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16352         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16353         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16354         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16355         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16356         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16357         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16358         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16359         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16360         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16361         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16362         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16363         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16364         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16365         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16366         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16367         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16368         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16369         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16370         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16371         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16372         NULL,
16373 };
16374
16375 /* read cmdline commands from file */
16376 void
16377 cmdline_read_from_file(const char *filename)
16378 {
16379         struct cmdline *cl;
16380
16381         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16382         if (cl == NULL) {
16383                 printf("Failed to create file based cmdline context: %s\n",
16384                        filename);
16385                 return;
16386         }
16387
16388         cmdline_interact(cl);
16389         cmdline_quit(cl);
16390
16391         cmdline_free(cl);
16392
16393         printf("Read CLI commands from %s\n", filename);
16394 }
16395
16396 /* prompt function, called from main on MASTER lcore */
16397 void
16398 prompt(void)
16399 {
16400         /* initialize non-constant commands */
16401         cmd_set_fwd_mode_init();
16402         cmd_set_fwd_retry_mode_init();
16403
16404         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16405         if (testpmd_cl == NULL)
16406                 return;
16407         cmdline_interact(testpmd_cl);
16408         cmdline_stdin_exit(testpmd_cl);
16409 }
16410
16411 void
16412 prompt_exit(void)
16413 {
16414         if (testpmd_cl != NULL)
16415                 cmdline_quit(testpmd_cl);
16416 }
16417
16418 static void
16419 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16420 {
16421         if (id == (portid_t)RTE_PORT_ALL) {
16422                 portid_t pid;
16423
16424                 RTE_ETH_FOREACH_DEV(pid) {
16425                         /* check if need_reconfig has been set to 1 */
16426                         if (ports[pid].need_reconfig == 0)
16427                                 ports[pid].need_reconfig = dev;
16428                         /* check if need_reconfig_queues has been set to 1 */
16429                         if (ports[pid].need_reconfig_queues == 0)
16430                                 ports[pid].need_reconfig_queues = queue;
16431                 }
16432         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16433                 /* check if need_reconfig has been set to 1 */
16434                 if (ports[id].need_reconfig == 0)
16435                         ports[id].need_reconfig = dev;
16436                 /* check if need_reconfig_queues has been set to 1 */
16437                 if (ports[id].need_reconfig_queues == 0)
16438                         ports[id].need_reconfig_queues = queue;
16439         }
16440 }