app/testpmd: enable queue ring size configure
[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|default|ip|tcp|udp|sctp|"
825                         "ether|port|vxlan|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 config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
850                         "    Set a rx/tx queue's ring size configuration, the new"
851                         " value will take effect after command that (re-)start the port"
852                         " or command that setup the specific queue\n\n"
853
854                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
855                         "    Start/stop a rx/tx queue of port X. Only take effect"
856                         " when port X is started\n\n"
857
858                         "port (port_id) (rxq|txq) (queue_id) setup\n"
859                         "    Setup a rx/tx queue of port X.\n\n"
860
861                         "port config (port_id|all) l2-tunnel E-tag ether-type"
862                         " (value)\n"
863                         "    Set the value of E-tag ether-type.\n\n"
864
865                         "port config (port_id|all) l2-tunnel E-tag"
866                         " (enable|disable)\n"
867                         "    Enable/disable the E-tag support.\n\n"
868
869                         "port config (port_id) pctype mapping reset\n"
870                         "    Reset flow type to pctype mapping on a port\n\n"
871
872                         "port config (port_id) pctype mapping update"
873                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
874                         "    Update a flow type to pctype mapping item on a port\n\n"
875
876                         "port config (port_id) pctype (pctype_id) hash_inset|"
877                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
878                         " (field_idx)\n"
879                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
880
881                         "port config (port_id) pctype (pctype_id) hash_inset|"
882                         "fdir_inset|fdir_flx_inset clear all"
883                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
884                 );
885         }
886
887         if (show_all || !strcmp(res->section, "registers")) {
888
889                 cmdline_printf(
890                         cl,
891                         "\n"
892                         "Registers:\n"
893                         "----------\n\n"
894
895                         "read reg (port_id) (address)\n"
896                         "    Display value of a port register.\n\n"
897
898                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
899                         "    Display a port register bit field.\n\n"
900
901                         "read regbit (port_id) (address) (bit_x)\n"
902                         "    Display a single port register bit.\n\n"
903
904                         "write reg (port_id) (address) (value)\n"
905                         "    Set value of a port register.\n\n"
906
907                         "write regfield (port_id) (address) (bit_x) (bit_y)"
908                         " (value)\n"
909                         "    Set bit field of a port register.\n\n"
910
911                         "write regbit (port_id) (address) (bit_x) (value)\n"
912                         "    Set single bit value of a port register.\n\n"
913                 );
914         }
915         if (show_all || !strcmp(res->section, "filters")) {
916
917                 cmdline_printf(
918                         cl,
919                         "\n"
920                         "filters:\n"
921                         "--------\n\n"
922
923                         "ethertype_filter (port_id) (add|del)"
924                         " (mac_addr|mac_ignr) (mac_address) ethertype"
925                         " (ether_type) (drop|fwd) queue (queue_id)\n"
926                         "    Add/Del an ethertype filter.\n\n"
927
928                         "2tuple_filter (port_id) (add|del)"
929                         " dst_port (dst_port_value) protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 2tuple filter.\n\n"
933
934                         "5tuple_filter (port_id) (add|del)"
935                         " dst_ip (dst_address) src_ip (src_address)"
936                         " dst_port (dst_port_value) src_port (src_port_value)"
937                         " protocol (protocol_value)"
938                         " mask (mask_value) tcp_flags (tcp_flags_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a 5tuple filter.\n\n"
941
942                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
943                         "    Add/Del syn filter.\n\n"
944
945                         "flex_filter (port_id) (add|del) len (len_value)"
946                         " bytes (bytes_value) mask (mask_value)"
947                         " priority (prio_value) queue (queue_id)\n"
948                         "    Add/Del a flex filter.\n\n"
949
950                         "flow_director_filter (port_id) mode IP (add|del|update)"
951                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
952                         " src (src_ip_address) dst (dst_ip_address)"
953                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
954                         " vlan (vlan_value) flexbytes (flexbytes_value)"
955                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
956                         " fd_id (fd_id_value)\n"
957                         "    Add/Del an IP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
961                         " src (src_ip_address) (src_port)"
962                         " dst (dst_ip_address) (dst_port)"
963                         " tos (tos_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-sctp|ipv6-sctp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tag (verification_tag) "
974                         " tos (tos_value) ttl (ttl_value)"
975                         " vlan (vlan_value)"
976                         " flexbytes (flexbytes_value) (drop|fwd)"
977                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
978                         "    Add/Del a SCTP type flow director filter.\n\n"
979
980                         "flow_director_filter (port_id) mode IP (add|del|update)"
981                         " flow l2_payload ether (ethertype)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a l2 payload type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
987                         " mac (mac_address) vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a Tunnel flow director filter.\n\n"
998
999                         "flow_director_filter (port_id) mode raw (add|del|update)"
1000                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1001                         " fd_id (fd_id_value) packet (packet file name)\n"
1002                         "    Add/Del a raw type flow director filter.\n\n"
1003
1004                         "flush_flow_director (port_id)\n"
1005                         "    Flush all flow director entries of a device.\n\n"
1006
1007                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1008                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1009                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1010                         "    Set flow director IP mask.\n\n"
1011
1012                         "flow_director_mask (port_id) mode MAC-VLAN"
1013                         " vlan (vlan_value)\n"
1014                         "    Set flow director MAC-VLAN mask.\n\n"
1015
1016                         "flow_director_mask (port_id) mode Tunnel"
1017                         " vlan (vlan_value) mac (mac_value)"
1018                         " tunnel-type (tunnel_type_value)"
1019                         " tunnel-id (tunnel_id_value)\n"
1020                         "    Set flow director Tunnel mask.\n\n"
1021
1022                         "flow_director_flex_mask (port_id)"
1023                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1024                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1025                         " (mask)\n"
1026                         "    Configure mask of flex payload.\n\n"
1027
1028                         "flow_director_flex_payload (port_id)"
1029                         " (raw|l2|l3|l4) (config)\n"
1030                         "    Configure flex payload selection.\n\n"
1031
1032                         "get_sym_hash_ena_per_port (port_id)\n"
1033                         "    get symmetric hash enable configuration per port.\n\n"
1034
1035                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1036                         "    set symmetric hash enable configuration per port"
1037                         " to enable or disable.\n\n"
1038
1039                         "get_hash_global_config (port_id)\n"
1040                         "    Get the global configurations of hash filters.\n\n"
1041
1042                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1043                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1044                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1045                         " (enable|disable)\n"
1046                         "    Set the global configurations of hash filters.\n\n"
1047
1048                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1049                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1050                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1051                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1052                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1053                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1054                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1055                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1056                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1057                         "fld-8th|none) (select|add)\n"
1058                         "    Set the input set for hash.\n\n"
1059
1060                         "set_fdir_input_set (port_id) "
1061                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1062                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1063                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1064                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1065                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1066                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1067                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1068                         " (select|add)\n"
1069                         "    Set the input set for FDir.\n\n"
1070
1071                         "flow validate {port_id}"
1072                         " [group {group_id}] [priority {level}]"
1073                         " [ingress] [egress]"
1074                         " pattern {item} [/ {item} [...]] / end"
1075                         " actions {action} [/ {action} [...]] / end\n"
1076                         "    Check whether a flow rule can be created.\n\n"
1077
1078                         "flow create {port_id}"
1079                         " [group {group_id}] [priority {level}]"
1080                         " [ingress] [egress]"
1081                         " pattern {item} [/ {item} [...]] / end"
1082                         " actions {action} [/ {action} [...]] / end\n"
1083                         "    Create a flow rule.\n\n"
1084
1085                         "flow destroy {port_id} rule {rule_id} [...]\n"
1086                         "    Destroy specific flow rules.\n\n"
1087
1088                         "flow flush {port_id}\n"
1089                         "    Destroy all flow rules.\n\n"
1090
1091                         "flow query {port_id} {rule_id} {action}\n"
1092                         "    Query an existing flow rule.\n\n"
1093
1094                         "flow list {port_id} [group {group_id}] [...]\n"
1095                         "    List existing flow rules sorted by priority,"
1096                         " filtered by group identifiers.\n\n"
1097
1098                         "flow isolate {port_id} {boolean}\n"
1099                         "    Restrict ingress traffic to the defined"
1100                         " flow rules\n\n"
1101                 );
1102         }
1103 }
1104
1105 cmdline_parse_token_string_t cmd_help_long_help =
1106         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1107
1108 cmdline_parse_token_string_t cmd_help_long_section =
1109         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1110                         "all#control#display#config#"
1111                         "ports#registers#filters");
1112
1113 cmdline_parse_inst_t cmd_help_long = {
1114         .f = cmd_help_long_parsed,
1115         .data = NULL,
1116         .help_str = "help all|control|display|config|ports|register|filters: "
1117                 "Show help",
1118         .tokens = {
1119                 (void *)&cmd_help_long_help,
1120                 (void *)&cmd_help_long_section,
1121                 NULL,
1122         },
1123 };
1124
1125
1126 /* *** start/stop/close all ports *** */
1127 struct cmd_operate_port_result {
1128         cmdline_fixed_string_t keyword;
1129         cmdline_fixed_string_t name;
1130         cmdline_fixed_string_t value;
1131 };
1132
1133 static void cmd_operate_port_parsed(void *parsed_result,
1134                                 __attribute__((unused)) struct cmdline *cl,
1135                                 __attribute__((unused)) void *data)
1136 {
1137         struct cmd_operate_port_result *res = parsed_result;
1138
1139         if (!strcmp(res->name, "start"))
1140                 start_port(RTE_PORT_ALL);
1141         else if (!strcmp(res->name, "stop"))
1142                 stop_port(RTE_PORT_ALL);
1143         else if (!strcmp(res->name, "close"))
1144                 close_port(RTE_PORT_ALL);
1145         else if (!strcmp(res->name, "reset"))
1146                 reset_port(RTE_PORT_ALL);
1147         else
1148                 printf("Unknown parameter\n");
1149 }
1150
1151 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1152         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1153                                                                 "port");
1154 cmdline_parse_token_string_t cmd_operate_port_all_port =
1155         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1156                                                 "start#stop#close#reset");
1157 cmdline_parse_token_string_t cmd_operate_port_all_all =
1158         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1159
1160 cmdline_parse_inst_t cmd_operate_port = {
1161         .f = cmd_operate_port_parsed,
1162         .data = NULL,
1163         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1164         .tokens = {
1165                 (void *)&cmd_operate_port_all_cmd,
1166                 (void *)&cmd_operate_port_all_port,
1167                 (void *)&cmd_operate_port_all_all,
1168                 NULL,
1169         },
1170 };
1171
1172 /* *** start/stop/close specific port *** */
1173 struct cmd_operate_specific_port_result {
1174         cmdline_fixed_string_t keyword;
1175         cmdline_fixed_string_t name;
1176         uint8_t value;
1177 };
1178
1179 static void cmd_operate_specific_port_parsed(void *parsed_result,
1180                         __attribute__((unused)) struct cmdline *cl,
1181                                 __attribute__((unused)) void *data)
1182 {
1183         struct cmd_operate_specific_port_result *res = parsed_result;
1184
1185         if (!strcmp(res->name, "start"))
1186                 start_port(res->value);
1187         else if (!strcmp(res->name, "stop"))
1188                 stop_port(res->value);
1189         else if (!strcmp(res->name, "close"))
1190                 close_port(res->value);
1191         else if (!strcmp(res->name, "reset"))
1192                 reset_port(res->value);
1193         else
1194                 printf("Unknown parameter\n");
1195 }
1196
1197 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1198         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1199                                                         keyword, "port");
1200 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1201         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1202                                                 name, "start#stop#close#reset");
1203 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1204         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1205                                                         value, UINT8);
1206
1207 cmdline_parse_inst_t cmd_operate_specific_port = {
1208         .f = cmd_operate_specific_port_parsed,
1209         .data = NULL,
1210         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1211         .tokens = {
1212                 (void *)&cmd_operate_specific_port_cmd,
1213                 (void *)&cmd_operate_specific_port_port,
1214                 (void *)&cmd_operate_specific_port_id,
1215                 NULL,
1216         },
1217 };
1218
1219 /* *** attach a specified port *** */
1220 struct cmd_operate_attach_port_result {
1221         cmdline_fixed_string_t port;
1222         cmdline_fixed_string_t keyword;
1223         cmdline_fixed_string_t identifier;
1224 };
1225
1226 static void cmd_operate_attach_port_parsed(void *parsed_result,
1227                                 __attribute__((unused)) struct cmdline *cl,
1228                                 __attribute__((unused)) void *data)
1229 {
1230         struct cmd_operate_attach_port_result *res = parsed_result;
1231
1232         if (!strcmp(res->keyword, "attach"))
1233                 attach_port(res->identifier);
1234         else
1235                 printf("Unknown parameter\n");
1236 }
1237
1238 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1239         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1240                         port, "port");
1241 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1242         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1243                         keyword, "attach");
1244 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1245         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1246                         identifier, NULL);
1247
1248 cmdline_parse_inst_t cmd_operate_attach_port = {
1249         .f = cmd_operate_attach_port_parsed,
1250         .data = NULL,
1251         .help_str = "port attach <identifier>: "
1252                 "(identifier: pci address or virtual dev name)",
1253         .tokens = {
1254                 (void *)&cmd_operate_attach_port_port,
1255                 (void *)&cmd_operate_attach_port_keyword,
1256                 (void *)&cmd_operate_attach_port_identifier,
1257                 NULL,
1258         },
1259 };
1260
1261 /* *** detach a specified port *** */
1262 struct cmd_operate_detach_port_result {
1263         cmdline_fixed_string_t port;
1264         cmdline_fixed_string_t keyword;
1265         portid_t port_id;
1266 };
1267
1268 static void cmd_operate_detach_port_parsed(void *parsed_result,
1269                                 __attribute__((unused)) struct cmdline *cl,
1270                                 __attribute__((unused)) void *data)
1271 {
1272         struct cmd_operate_detach_port_result *res = parsed_result;
1273
1274         if (!strcmp(res->keyword, "detach"))
1275                 detach_port(res->port_id);
1276         else
1277                 printf("Unknown parameter\n");
1278 }
1279
1280 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1281         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1282                         port, "port");
1283 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1284         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1285                         keyword, "detach");
1286 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1287         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1288                         port_id, UINT16);
1289
1290 cmdline_parse_inst_t cmd_operate_detach_port = {
1291         .f = cmd_operate_detach_port_parsed,
1292         .data = NULL,
1293         .help_str = "port detach <port_id>",
1294         .tokens = {
1295                 (void *)&cmd_operate_detach_port_port,
1296                 (void *)&cmd_operate_detach_port_keyword,
1297                 (void *)&cmd_operate_detach_port_port_id,
1298                 NULL,
1299         },
1300 };
1301
1302 /* *** configure speed for all ports *** */
1303 struct cmd_config_speed_all {
1304         cmdline_fixed_string_t port;
1305         cmdline_fixed_string_t keyword;
1306         cmdline_fixed_string_t all;
1307         cmdline_fixed_string_t item1;
1308         cmdline_fixed_string_t item2;
1309         cmdline_fixed_string_t value1;
1310         cmdline_fixed_string_t value2;
1311 };
1312
1313 static int
1314 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1315 {
1316
1317         int duplex;
1318
1319         if (!strcmp(duplexstr, "half")) {
1320                 duplex = ETH_LINK_HALF_DUPLEX;
1321         } else if (!strcmp(duplexstr, "full")) {
1322                 duplex = ETH_LINK_FULL_DUPLEX;
1323         } else if (!strcmp(duplexstr, "auto")) {
1324                 duplex = ETH_LINK_FULL_DUPLEX;
1325         } else {
1326                 printf("Unknown duplex parameter\n");
1327                 return -1;
1328         }
1329
1330         if (!strcmp(speedstr, "10")) {
1331                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1332                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1333         } else if (!strcmp(speedstr, "100")) {
1334                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1335                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1336         } else {
1337                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1338                         printf("Invalid speed/duplex parameters\n");
1339                         return -1;
1340                 }
1341                 if (!strcmp(speedstr, "1000")) {
1342                         *speed = ETH_LINK_SPEED_1G;
1343                 } else if (!strcmp(speedstr, "10000")) {
1344                         *speed = ETH_LINK_SPEED_10G;
1345                 } else if (!strcmp(speedstr, "25000")) {
1346                         *speed = ETH_LINK_SPEED_25G;
1347                 } else if (!strcmp(speedstr, "40000")) {
1348                         *speed = ETH_LINK_SPEED_40G;
1349                 } else if (!strcmp(speedstr, "50000")) {
1350                         *speed = ETH_LINK_SPEED_50G;
1351                 } else if (!strcmp(speedstr, "100000")) {
1352                         *speed = ETH_LINK_SPEED_100G;
1353                 } else if (!strcmp(speedstr, "auto")) {
1354                         *speed = ETH_LINK_SPEED_AUTONEG;
1355                 } else {
1356                         printf("Unknown speed parameter\n");
1357                         return -1;
1358                 }
1359         }
1360
1361         return 0;
1362 }
1363
1364 static void
1365 cmd_config_speed_all_parsed(void *parsed_result,
1366                         __attribute__((unused)) struct cmdline *cl,
1367                         __attribute__((unused)) void *data)
1368 {
1369         struct cmd_config_speed_all *res = parsed_result;
1370         uint32_t link_speed;
1371         portid_t pid;
1372
1373         if (!all_ports_stopped()) {
1374                 printf("Please stop all ports first\n");
1375                 return;
1376         }
1377
1378         if (parse_and_check_speed_duplex(res->value1, res->value2,
1379                         &link_speed) < 0)
1380                 return;
1381
1382         RTE_ETH_FOREACH_DEV(pid) {
1383                 ports[pid].dev_conf.link_speeds = link_speed;
1384         }
1385
1386         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1387 }
1388
1389 cmdline_parse_token_string_t cmd_config_speed_all_port =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1391 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1393                                                         "config");
1394 cmdline_parse_token_string_t cmd_config_speed_all_all =
1395         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1396 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1398 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1400                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1401 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1402         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1403 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1404         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1405                                                 "half#full#auto");
1406
1407 cmdline_parse_inst_t cmd_config_speed_all = {
1408         .f = cmd_config_speed_all_parsed,
1409         .data = NULL,
1410         .help_str = "port config all speed "
1411                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1412                                                         "half|full|auto",
1413         .tokens = {
1414                 (void *)&cmd_config_speed_all_port,
1415                 (void *)&cmd_config_speed_all_keyword,
1416                 (void *)&cmd_config_speed_all_all,
1417                 (void *)&cmd_config_speed_all_item1,
1418                 (void *)&cmd_config_speed_all_value1,
1419                 (void *)&cmd_config_speed_all_item2,
1420                 (void *)&cmd_config_speed_all_value2,
1421                 NULL,
1422         },
1423 };
1424
1425 /* *** configure speed for specific port *** */
1426 struct cmd_config_speed_specific {
1427         cmdline_fixed_string_t port;
1428         cmdline_fixed_string_t keyword;
1429         portid_t id;
1430         cmdline_fixed_string_t item1;
1431         cmdline_fixed_string_t item2;
1432         cmdline_fixed_string_t value1;
1433         cmdline_fixed_string_t value2;
1434 };
1435
1436 static void
1437 cmd_config_speed_specific_parsed(void *parsed_result,
1438                                 __attribute__((unused)) struct cmdline *cl,
1439                                 __attribute__((unused)) void *data)
1440 {
1441         struct cmd_config_speed_specific *res = parsed_result;
1442         uint32_t link_speed;
1443
1444         if (!all_ports_stopped()) {
1445                 printf("Please stop all ports first\n");
1446                 return;
1447         }
1448
1449         if (port_id_is_invalid(res->id, ENABLED_WARN))
1450                 return;
1451
1452         if (parse_and_check_speed_duplex(res->value1, res->value2,
1453                         &link_speed) < 0)
1454                 return;
1455
1456         ports[res->id].dev_conf.link_speeds = link_speed;
1457
1458         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1459 }
1460
1461
1462 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1463         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1464                                                                 "port");
1465 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1467                                                                 "config");
1468 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1469         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1470 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1471         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1472                                                                 "speed");
1473 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1474         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1475                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1476 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1477         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1478                                                                 "duplex");
1479 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1480         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1481                                                         "half#full#auto");
1482
1483 cmdline_parse_inst_t cmd_config_speed_specific = {
1484         .f = cmd_config_speed_specific_parsed,
1485         .data = NULL,
1486         .help_str = "port config <port_id> speed "
1487                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1488                                                         "half|full|auto",
1489         .tokens = {
1490                 (void *)&cmd_config_speed_specific_port,
1491                 (void *)&cmd_config_speed_specific_keyword,
1492                 (void *)&cmd_config_speed_specific_id,
1493                 (void *)&cmd_config_speed_specific_item1,
1494                 (void *)&cmd_config_speed_specific_value1,
1495                 (void *)&cmd_config_speed_specific_item2,
1496                 (void *)&cmd_config_speed_specific_value2,
1497                 NULL,
1498         },
1499 };
1500
1501 /* *** configure loopback for all ports *** */
1502 struct cmd_config_loopback_all {
1503         cmdline_fixed_string_t port;
1504         cmdline_fixed_string_t keyword;
1505         cmdline_fixed_string_t all;
1506         cmdline_fixed_string_t item;
1507         uint32_t mode;
1508 };
1509
1510 static void
1511 cmd_config_loopback_all_parsed(void *parsed_result,
1512                         __attribute__((unused)) struct cmdline *cl,
1513                         __attribute__((unused)) void *data)
1514 {
1515         struct cmd_config_loopback_all *res = parsed_result;
1516         portid_t pid;
1517
1518         if (!all_ports_stopped()) {
1519                 printf("Please stop all ports first\n");
1520                 return;
1521         }
1522
1523         RTE_ETH_FOREACH_DEV(pid) {
1524                 ports[pid].dev_conf.lpbk_mode = res->mode;
1525         }
1526
1527         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1528 }
1529
1530 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1531         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1532 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1533         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1534                                                         "config");
1535 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1536         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1537 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1538         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1539                                                         "loopback");
1540 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1541         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1542
1543 cmdline_parse_inst_t cmd_config_loopback_all = {
1544         .f = cmd_config_loopback_all_parsed,
1545         .data = NULL,
1546         .help_str = "port config all loopback <mode>",
1547         .tokens = {
1548                 (void *)&cmd_config_loopback_all_port,
1549                 (void *)&cmd_config_loopback_all_keyword,
1550                 (void *)&cmd_config_loopback_all_all,
1551                 (void *)&cmd_config_loopback_all_item,
1552                 (void *)&cmd_config_loopback_all_mode,
1553                 NULL,
1554         },
1555 };
1556
1557 /* *** configure loopback for specific port *** */
1558 struct cmd_config_loopback_specific {
1559         cmdline_fixed_string_t port;
1560         cmdline_fixed_string_t keyword;
1561         uint16_t port_id;
1562         cmdline_fixed_string_t item;
1563         uint32_t mode;
1564 };
1565
1566 static void
1567 cmd_config_loopback_specific_parsed(void *parsed_result,
1568                                 __attribute__((unused)) struct cmdline *cl,
1569                                 __attribute__((unused)) void *data)
1570 {
1571         struct cmd_config_loopback_specific *res = parsed_result;
1572
1573         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1574                 return;
1575
1576         if (!port_is_stopped(res->port_id)) {
1577                 printf("Please stop port %u first\n", res->port_id);
1578                 return;
1579         }
1580
1581         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1582
1583         cmd_reconfig_device_queue(res->port_id, 1, 1);
1584 }
1585
1586
1587 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1588         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1589                                                                 "port");
1590 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1592                                                                 "config");
1593 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1594         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1595                                                                 UINT16);
1596 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1597         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1598                                                                 "loopback");
1599 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1600         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1601                               UINT32);
1602
1603 cmdline_parse_inst_t cmd_config_loopback_specific = {
1604         .f = cmd_config_loopback_specific_parsed,
1605         .data = NULL,
1606         .help_str = "port config <port_id> loopback <mode>",
1607         .tokens = {
1608                 (void *)&cmd_config_loopback_specific_port,
1609                 (void *)&cmd_config_loopback_specific_keyword,
1610                 (void *)&cmd_config_loopback_specific_id,
1611                 (void *)&cmd_config_loopback_specific_item,
1612                 (void *)&cmd_config_loopback_specific_mode,
1613                 NULL,
1614         },
1615 };
1616
1617 /* *** configure txq/rxq, txd/rxd *** */
1618 struct cmd_config_rx_tx {
1619         cmdline_fixed_string_t port;
1620         cmdline_fixed_string_t keyword;
1621         cmdline_fixed_string_t all;
1622         cmdline_fixed_string_t name;
1623         uint16_t value;
1624 };
1625
1626 static void
1627 cmd_config_rx_tx_parsed(void *parsed_result,
1628                         __attribute__((unused)) struct cmdline *cl,
1629                         __attribute__((unused)) void *data)
1630 {
1631         struct cmd_config_rx_tx *res = parsed_result;
1632
1633         if (!all_ports_stopped()) {
1634                 printf("Please stop all ports first\n");
1635                 return;
1636         }
1637         if (!strcmp(res->name, "rxq")) {
1638                 if (!res->value && !nb_txq) {
1639                         printf("Warning: Either rx or tx queues should be non zero\n");
1640                         return;
1641                 }
1642                 if (check_nb_rxq(res->value) != 0)
1643                         return;
1644                 nb_rxq = res->value;
1645         }
1646         else if (!strcmp(res->name, "txq")) {
1647                 if (!res->value && !nb_rxq) {
1648                         printf("Warning: Either rx or tx queues should be non zero\n");
1649                         return;
1650                 }
1651                 if (check_nb_txq(res->value) != 0)
1652                         return;
1653                 nb_txq = res->value;
1654         }
1655         else if (!strcmp(res->name, "rxd")) {
1656                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1657                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1658                                         res->value, RTE_TEST_RX_DESC_MAX);
1659                         return;
1660                 }
1661                 nb_rxd = res->value;
1662         } else if (!strcmp(res->name, "txd")) {
1663                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1664                         printf("txd %d invalid - must be > 0 && <= %d\n",
1665                                         res->value, RTE_TEST_TX_DESC_MAX);
1666                         return;
1667                 }
1668                 nb_txd = res->value;
1669         } else {
1670                 printf("Unknown parameter\n");
1671                 return;
1672         }
1673
1674         fwd_config_setup();
1675
1676         init_port_config();
1677
1678         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1679 }
1680
1681 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1682         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1683 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1685 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1686         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1687 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1688         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1689                                                 "rxq#txq#rxd#txd");
1690 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1691         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1692
1693 cmdline_parse_inst_t cmd_config_rx_tx = {
1694         .f = cmd_config_rx_tx_parsed,
1695         .data = NULL,
1696         .help_str = "port config all rxq|txq|rxd|txd <value>",
1697         .tokens = {
1698                 (void *)&cmd_config_rx_tx_port,
1699                 (void *)&cmd_config_rx_tx_keyword,
1700                 (void *)&cmd_config_rx_tx_all,
1701                 (void *)&cmd_config_rx_tx_name,
1702                 (void *)&cmd_config_rx_tx_value,
1703                 NULL,
1704         },
1705 };
1706
1707 /* *** config max packet length *** */
1708 struct cmd_config_max_pkt_len_result {
1709         cmdline_fixed_string_t port;
1710         cmdline_fixed_string_t keyword;
1711         cmdline_fixed_string_t all;
1712         cmdline_fixed_string_t name;
1713         uint32_t value;
1714 };
1715
1716 static void
1717 cmd_config_max_pkt_len_parsed(void *parsed_result,
1718                                 __attribute__((unused)) struct cmdline *cl,
1719                                 __attribute__((unused)) void *data)
1720 {
1721         struct cmd_config_max_pkt_len_result *res = parsed_result;
1722         portid_t pid;
1723
1724         if (!all_ports_stopped()) {
1725                 printf("Please stop all ports first\n");
1726                 return;
1727         }
1728
1729         RTE_ETH_FOREACH_DEV(pid) {
1730                 struct rte_port *port = &ports[pid];
1731                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1732
1733                 if (!strcmp(res->name, "max-pkt-len")) {
1734                         if (res->value < ETHER_MIN_LEN) {
1735                                 printf("max-pkt-len can not be less than %d\n",
1736                                                 ETHER_MIN_LEN);
1737                                 return;
1738                         }
1739                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1740                                 return;
1741
1742                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1743                         if (res->value > ETHER_MAX_LEN)
1744                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1745                         else
1746                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1747                         port->dev_conf.rxmode.offloads = rx_offloads;
1748                 } else {
1749                         printf("Unknown parameter\n");
1750                         return;
1751                 }
1752         }
1753
1754         init_port_config();
1755
1756         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1757 }
1758
1759 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1761                                                                 "port");
1762 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1763         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1764                                                                 "config");
1765 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1766         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1767                                                                 "all");
1768 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1769         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1770                                                                 "max-pkt-len");
1771 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1772         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1773                                                                 UINT32);
1774
1775 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1776         .f = cmd_config_max_pkt_len_parsed,
1777         .data = NULL,
1778         .help_str = "port config all max-pkt-len <value>",
1779         .tokens = {
1780                 (void *)&cmd_config_max_pkt_len_port,
1781                 (void *)&cmd_config_max_pkt_len_keyword,
1782                 (void *)&cmd_config_max_pkt_len_all,
1783                 (void *)&cmd_config_max_pkt_len_name,
1784                 (void *)&cmd_config_max_pkt_len_value,
1785                 NULL,
1786         },
1787 };
1788
1789 /* *** configure port MTU *** */
1790 struct cmd_config_mtu_result {
1791         cmdline_fixed_string_t port;
1792         cmdline_fixed_string_t keyword;
1793         cmdline_fixed_string_t mtu;
1794         portid_t port_id;
1795         uint16_t value;
1796 };
1797
1798 static void
1799 cmd_config_mtu_parsed(void *parsed_result,
1800                       __attribute__((unused)) struct cmdline *cl,
1801                       __attribute__((unused)) void *data)
1802 {
1803         struct cmd_config_mtu_result *res = parsed_result;
1804
1805         if (res->value < ETHER_MIN_LEN) {
1806                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1807                 return;
1808         }
1809         port_mtu_set(res->port_id, res->value);
1810 }
1811
1812 cmdline_parse_token_string_t cmd_config_mtu_port =
1813         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1814                                  "port");
1815 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1816         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1817                                  "config");
1818 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1819         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1820                                  "mtu");
1821 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1822         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1823 cmdline_parse_token_num_t cmd_config_mtu_value =
1824         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1825
1826 cmdline_parse_inst_t cmd_config_mtu = {
1827         .f = cmd_config_mtu_parsed,
1828         .data = NULL,
1829         .help_str = "port config mtu <port_id> <value>",
1830         .tokens = {
1831                 (void *)&cmd_config_mtu_port,
1832                 (void *)&cmd_config_mtu_keyword,
1833                 (void *)&cmd_config_mtu_mtu,
1834                 (void *)&cmd_config_mtu_port_id,
1835                 (void *)&cmd_config_mtu_value,
1836                 NULL,
1837         },
1838 };
1839
1840 /* *** configure rx mode *** */
1841 struct cmd_config_rx_mode_flag {
1842         cmdline_fixed_string_t port;
1843         cmdline_fixed_string_t keyword;
1844         cmdline_fixed_string_t all;
1845         cmdline_fixed_string_t name;
1846         cmdline_fixed_string_t value;
1847 };
1848
1849 static void
1850 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1851                                 __attribute__((unused)) struct cmdline *cl,
1852                                 __attribute__((unused)) void *data)
1853 {
1854         struct cmd_config_rx_mode_flag *res = parsed_result;
1855         portid_t pid;
1856
1857         if (!all_ports_stopped()) {
1858                 printf("Please stop all ports first\n");
1859                 return;
1860         }
1861
1862         RTE_ETH_FOREACH_DEV(pid) {
1863                 struct rte_port *port;
1864                 uint64_t rx_offloads;
1865
1866                 port = &ports[pid];
1867                 rx_offloads = port->dev_conf.rxmode.offloads;
1868                 if (!strcmp(res->name, "crc-strip")) {
1869                         if (!strcmp(res->value, "on"))
1870                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1871                         else if (!strcmp(res->value, "off"))
1872                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1873                         else {
1874                                 printf("Unknown parameter\n");
1875                                 return;
1876                         }
1877                 } else if (!strcmp(res->name, "scatter")) {
1878                         if (!strcmp(res->value, "on")) {
1879                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1880                         } else if (!strcmp(res->value, "off")) {
1881                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1882                         } else {
1883                                 printf("Unknown parameter\n");
1884                                 return;
1885                         }
1886                 } else if (!strcmp(res->name, "rx-cksum")) {
1887                         if (!strcmp(res->value, "on"))
1888                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1889                         else if (!strcmp(res->value, "off"))
1890                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1891                         else {
1892                                 printf("Unknown parameter\n");
1893                                 return;
1894                         }
1895                 } else if (!strcmp(res->name, "rx-timestamp")) {
1896                         if (!strcmp(res->value, "on"))
1897                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1898                         else if (!strcmp(res->value, "off"))
1899                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1900                         else {
1901                                 printf("Unknown parameter\n");
1902                                 return;
1903                         }
1904                 } else if (!strcmp(res->name, "hw-vlan")) {
1905                         if (!strcmp(res->value, "on")) {
1906                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1907                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1908                         } else if (!strcmp(res->value, "off")) {
1909                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1910                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1911                         } else {
1912                                 printf("Unknown parameter\n");
1913                                 return;
1914                         }
1915                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1916                         if (!strcmp(res->value, "on"))
1917                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1918                         else if (!strcmp(res->value, "off"))
1919                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1920                         else {
1921                                 printf("Unknown parameter\n");
1922                                 return;
1923                         }
1924                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1925                         if (!strcmp(res->value, "on"))
1926                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1927                         else if (!strcmp(res->value, "off"))
1928                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1929                         else {
1930                                 printf("Unknown parameter\n");
1931                                 return;
1932                         }
1933                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1934                         if (!strcmp(res->value, "on"))
1935                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1936                         else if (!strcmp(res->value, "off"))
1937                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1938                         else {
1939                                 printf("Unknown parameter\n");
1940                                 return;
1941                         }
1942                 } else if (!strcmp(res->name, "drop-en")) {
1943                         if (!strcmp(res->value, "on"))
1944                                 rx_drop_en = 1;
1945                         else if (!strcmp(res->value, "off"))
1946                                 rx_drop_en = 0;
1947                         else {
1948                                 printf("Unknown parameter\n");
1949                                 return;
1950                         }
1951                 } else {
1952                         printf("Unknown parameter\n");
1953                         return;
1954                 }
1955                 port->dev_conf.rxmode.offloads = rx_offloads;
1956         }
1957
1958         init_port_config();
1959
1960         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1961 }
1962
1963 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1965 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1966         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1967                                                                 "config");
1968 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1969         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1970 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1971         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1972                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1973                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1974 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1975         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1976                                                         "on#off");
1977
1978 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1979         .f = cmd_config_rx_mode_flag_parsed,
1980         .data = NULL,
1981         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1982                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1983         .tokens = {
1984                 (void *)&cmd_config_rx_mode_flag_port,
1985                 (void *)&cmd_config_rx_mode_flag_keyword,
1986                 (void *)&cmd_config_rx_mode_flag_all,
1987                 (void *)&cmd_config_rx_mode_flag_name,
1988                 (void *)&cmd_config_rx_mode_flag_value,
1989                 NULL,
1990         },
1991 };
1992
1993 /* *** configure rss *** */
1994 struct cmd_config_rss {
1995         cmdline_fixed_string_t port;
1996         cmdline_fixed_string_t keyword;
1997         cmdline_fixed_string_t all;
1998         cmdline_fixed_string_t name;
1999         cmdline_fixed_string_t value;
2000 };
2001
2002 static void
2003 cmd_config_rss_parsed(void *parsed_result,
2004                         __attribute__((unused)) struct cmdline *cl,
2005                         __attribute__((unused)) void *data)
2006 {
2007         struct cmd_config_rss *res = parsed_result;
2008         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2009         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2010         int diag;
2011         uint16_t i;
2012
2013         if (!strcmp(res->value, "all"))
2014                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2015                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2016                                         ETH_RSS_L2_PAYLOAD;
2017         else if (!strcmp(res->value, "ip"))
2018                 rss_conf.rss_hf = ETH_RSS_IP;
2019         else if (!strcmp(res->value, "udp"))
2020                 rss_conf.rss_hf = ETH_RSS_UDP;
2021         else if (!strcmp(res->value, "tcp"))
2022                 rss_conf.rss_hf = ETH_RSS_TCP;
2023         else if (!strcmp(res->value, "sctp"))
2024                 rss_conf.rss_hf = ETH_RSS_SCTP;
2025         else if (!strcmp(res->value, "ether"))
2026                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2027         else if (!strcmp(res->value, "port"))
2028                 rss_conf.rss_hf = ETH_RSS_PORT;
2029         else if (!strcmp(res->value, "vxlan"))
2030                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2031         else if (!strcmp(res->value, "geneve"))
2032                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2033         else if (!strcmp(res->value, "nvgre"))
2034                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2035         else if (!strcmp(res->value, "none") || !strcmp(res->value, "default"))
2036                 rss_conf.rss_hf = 0;
2037         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2038                                                 atoi(res->value) < 64)
2039                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2040         else {
2041                 printf("Unknown parameter\n");
2042                 return;
2043         }
2044         rss_conf.rss_key = NULL;
2045         /* Update global configuration for RSS types. */
2046         rss_hf = rss_conf.rss_hf;
2047         RTE_ETH_FOREACH_DEV(i) {
2048                 if (!strcmp(res->value, "default")) {
2049                         rte_eth_dev_info_get(i, &dev_info);
2050                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2051                 }
2052                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2053                 if (diag < 0)
2054                         printf("Configuration of RSS hash at ethernet port %d "
2055                                 "failed with error (%d): %s.\n",
2056                                 i, -diag, strerror(-diag));
2057         }
2058 }
2059
2060 cmdline_parse_token_string_t cmd_config_rss_port =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2062 cmdline_parse_token_string_t cmd_config_rss_keyword =
2063         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2064 cmdline_parse_token_string_t cmd_config_rss_all =
2065         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2066 cmdline_parse_token_string_t cmd_config_rss_name =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2068 cmdline_parse_token_string_t cmd_config_rss_value =
2069         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2070
2071 cmdline_parse_inst_t cmd_config_rss = {
2072         .f = cmd_config_rss_parsed,
2073         .data = NULL,
2074         .help_str = "port config all rss "
2075                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2076         .tokens = {
2077                 (void *)&cmd_config_rss_port,
2078                 (void *)&cmd_config_rss_keyword,
2079                 (void *)&cmd_config_rss_all,
2080                 (void *)&cmd_config_rss_name,
2081                 (void *)&cmd_config_rss_value,
2082                 NULL,
2083         },
2084 };
2085
2086 /* *** configure rss hash key *** */
2087 struct cmd_config_rss_hash_key {
2088         cmdline_fixed_string_t port;
2089         cmdline_fixed_string_t config;
2090         portid_t port_id;
2091         cmdline_fixed_string_t rss_hash_key;
2092         cmdline_fixed_string_t rss_type;
2093         cmdline_fixed_string_t key;
2094 };
2095
2096 static uint8_t
2097 hexa_digit_to_value(char hexa_digit)
2098 {
2099         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2100                 return (uint8_t) (hexa_digit - '0');
2101         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2102                 return (uint8_t) ((hexa_digit - 'a') + 10);
2103         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2104                 return (uint8_t) ((hexa_digit - 'A') + 10);
2105         /* Invalid hexa digit */
2106         return 0xFF;
2107 }
2108
2109 static uint8_t
2110 parse_and_check_key_hexa_digit(char *key, int idx)
2111 {
2112         uint8_t hexa_v;
2113
2114         hexa_v = hexa_digit_to_value(key[idx]);
2115         if (hexa_v == 0xFF)
2116                 printf("invalid key: character %c at position %d is not a "
2117                        "valid hexa digit\n", key[idx], idx);
2118         return hexa_v;
2119 }
2120
2121 static void
2122 cmd_config_rss_hash_key_parsed(void *parsed_result,
2123                                __attribute__((unused)) struct cmdline *cl,
2124                                __attribute__((unused)) void *data)
2125 {
2126         struct cmd_config_rss_hash_key *res = parsed_result;
2127         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2128         uint8_t xdgt0;
2129         uint8_t xdgt1;
2130         int i;
2131         struct rte_eth_dev_info dev_info;
2132         uint8_t hash_key_size;
2133         uint32_t key_len;
2134
2135         memset(&dev_info, 0, sizeof(dev_info));
2136         rte_eth_dev_info_get(res->port_id, &dev_info);
2137         if (dev_info.hash_key_size > 0 &&
2138                         dev_info.hash_key_size <= sizeof(hash_key))
2139                 hash_key_size = dev_info.hash_key_size;
2140         else {
2141                 printf("dev_info did not provide a valid hash key size\n");
2142                 return;
2143         }
2144         /* Check the length of the RSS hash key */
2145         key_len = strlen(res->key);
2146         if (key_len != (hash_key_size * 2)) {
2147                 printf("key length: %d invalid - key must be a string of %d"
2148                            " hexa-decimal numbers\n",
2149                            (int) key_len, hash_key_size * 2);
2150                 return;
2151         }
2152         /* Translate RSS hash key into binary representation */
2153         for (i = 0; i < hash_key_size; i++) {
2154                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2155                 if (xdgt0 == 0xFF)
2156                         return;
2157                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2158                 if (xdgt1 == 0xFF)
2159                         return;
2160                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2161         }
2162         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2163                         hash_key_size);
2164 }
2165
2166 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2167         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2168 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2170                                  "config");
2171 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2172         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2173 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2174         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2175                                  rss_hash_key, "rss-hash-key");
2176 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2177         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2178                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2179                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2180                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2181                                  "ipv6-tcp-ex#ipv6-udp-ex");
2182 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2183         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2184
2185 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2186         .f = cmd_config_rss_hash_key_parsed,
2187         .data = NULL,
2188         .help_str = "port config <port_id> rss-hash-key "
2189                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2190                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2191                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2192                 "<string of hex digits (variable length, NIC dependent)>",
2193         .tokens = {
2194                 (void *)&cmd_config_rss_hash_key_port,
2195                 (void *)&cmd_config_rss_hash_key_config,
2196                 (void *)&cmd_config_rss_hash_key_port_id,
2197                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2198                 (void *)&cmd_config_rss_hash_key_rss_type,
2199                 (void *)&cmd_config_rss_hash_key_value,
2200                 NULL,
2201         },
2202 };
2203
2204 /* *** configure port rxq/txq ring size *** */
2205 struct cmd_config_rxtx_ring_size {
2206         cmdline_fixed_string_t port;
2207         cmdline_fixed_string_t config;
2208         portid_t portid;
2209         cmdline_fixed_string_t rxtxq;
2210         uint16_t qid;
2211         cmdline_fixed_string_t rsize;
2212         uint16_t size;
2213 };
2214
2215 static void
2216 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2217                                  __attribute__((unused)) struct cmdline *cl,
2218                                  __attribute__((unused)) void *data)
2219 {
2220         struct cmd_config_rxtx_ring_size *res = parsed_result;
2221         struct rte_port *port;
2222         uint8_t isrx;
2223
2224         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2225                 return;
2226
2227         if (res->portid == (portid_t)RTE_PORT_ALL) {
2228                 printf("Invalid port id\n");
2229                 return;
2230         }
2231
2232         port = &ports[res->portid];
2233
2234         if (!strcmp(res->rxtxq, "rxq"))
2235                 isrx = 1;
2236         else if (!strcmp(res->rxtxq, "txq"))
2237                 isrx = 0;
2238         else {
2239                 printf("Unknown parameter\n");
2240                 return;
2241         }
2242
2243         if (isrx && rx_queue_id_is_invalid(res->qid))
2244                 return;
2245         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2246                 return;
2247
2248         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2249                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2250                        rx_free_thresh);
2251                 return;
2252         }
2253
2254         if (isrx)
2255                 port->nb_rx_desc[res->qid] = res->size;
2256         else
2257                 port->nb_tx_desc[res->qid] = res->size;
2258
2259         cmd_reconfig_device_queue(res->portid, 0, 1);
2260 }
2261
2262 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2263         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2264                                  port, "port");
2265 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2267                                  config, "config");
2268 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2269         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2270                                  portid, UINT16);
2271 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2273                                  rxtxq, "rxq#txq");
2274 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2275         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2276                               qid, UINT16);
2277 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2278         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2279                                  rsize, "ring_size");
2280 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2281         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2282                               size, UINT16);
2283
2284 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2285         .f = cmd_config_rxtx_ring_size_parsed,
2286         .data = NULL,
2287         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2288         .tokens = {
2289                 (void *)&cmd_config_rxtx_ring_size_port,
2290                 (void *)&cmd_config_rxtx_ring_size_config,
2291                 (void *)&cmd_config_rxtx_ring_size_portid,
2292                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2293                 (void *)&cmd_config_rxtx_ring_size_qid,
2294                 (void *)&cmd_config_rxtx_ring_size_rsize,
2295                 (void *)&cmd_config_rxtx_ring_size_size,
2296                 NULL,
2297         },
2298 };
2299
2300 /* *** configure port rxq/txq start/stop *** */
2301 struct cmd_config_rxtx_queue {
2302         cmdline_fixed_string_t port;
2303         portid_t portid;
2304         cmdline_fixed_string_t rxtxq;
2305         uint16_t qid;
2306         cmdline_fixed_string_t opname;
2307 };
2308
2309 static void
2310 cmd_config_rxtx_queue_parsed(void *parsed_result,
2311                         __attribute__((unused)) struct cmdline *cl,
2312                         __attribute__((unused)) void *data)
2313 {
2314         struct cmd_config_rxtx_queue *res = parsed_result;
2315         uint8_t isrx;
2316         uint8_t isstart;
2317         int ret = 0;
2318
2319         if (test_done == 0) {
2320                 printf("Please stop forwarding first\n");
2321                 return;
2322         }
2323
2324         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2325                 return;
2326
2327         if (port_is_started(res->portid) != 1) {
2328                 printf("Please start port %u first\n", res->portid);
2329                 return;
2330         }
2331
2332         if (!strcmp(res->rxtxq, "rxq"))
2333                 isrx = 1;
2334         else if (!strcmp(res->rxtxq, "txq"))
2335                 isrx = 0;
2336         else {
2337                 printf("Unknown parameter\n");
2338                 return;
2339         }
2340
2341         if (isrx && rx_queue_id_is_invalid(res->qid))
2342                 return;
2343         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2344                 return;
2345
2346         if (!strcmp(res->opname, "start"))
2347                 isstart = 1;
2348         else if (!strcmp(res->opname, "stop"))
2349                 isstart = 0;
2350         else {
2351                 printf("Unknown parameter\n");
2352                 return;
2353         }
2354
2355         if (isstart && isrx)
2356                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2357         else if (!isstart && isrx)
2358                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2359         else if (isstart && !isrx)
2360                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2361         else
2362                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2363
2364         if (ret == -ENOTSUP)
2365                 printf("Function not supported in PMD driver\n");
2366 }
2367
2368 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2370 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2371         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2372 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2373         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2374 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2375         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2376 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2378                                                 "start#stop");
2379
2380 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2381         .f = cmd_config_rxtx_queue_parsed,
2382         .data = NULL,
2383         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2384         .tokens = {
2385                 (void *)&cmd_config_rxtx_queue_port,
2386                 (void *)&cmd_config_rxtx_queue_portid,
2387                 (void *)&cmd_config_rxtx_queue_rxtxq,
2388                 (void *)&cmd_config_rxtx_queue_qid,
2389                 (void *)&cmd_config_rxtx_queue_opname,
2390                 NULL,
2391         },
2392 };
2393
2394 /* *** configure port rxq/txq setup *** */
2395 struct cmd_setup_rxtx_queue {
2396         cmdline_fixed_string_t port;
2397         portid_t portid;
2398         cmdline_fixed_string_t rxtxq;
2399         uint16_t qid;
2400         cmdline_fixed_string_t setup;
2401 };
2402
2403 /* Common CLI fields for queue setup */
2404 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2405         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2406 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2407         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2408 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2409         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2410 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2411         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2412 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2413         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2414
2415 static void
2416 cmd_setup_rxtx_queue_parsed(
2417         void *parsed_result,
2418         __attribute__((unused)) struct cmdline *cl,
2419         __attribute__((unused)) void *data)
2420 {
2421         struct cmd_setup_rxtx_queue *res = parsed_result;
2422         struct rte_port *port;
2423         struct rte_mempool *mp;
2424         unsigned int socket_id;
2425         uint8_t isrx = 0;
2426         int ret;
2427
2428         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2429                 return;
2430
2431         if (res->portid == (portid_t)RTE_PORT_ALL) {
2432                 printf("Invalid port id\n");
2433                 return;
2434         }
2435
2436         if (!strcmp(res->rxtxq, "rxq"))
2437                 isrx = 1;
2438         else if (!strcmp(res->rxtxq, "txq"))
2439                 isrx = 0;
2440         else {
2441                 printf("Unknown parameter\n");
2442                 return;
2443         }
2444
2445         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2446                 printf("Invalid rx queue\n");
2447                 return;
2448         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2449                 printf("Invalid tx queue\n");
2450                 return;
2451         }
2452
2453         port = &ports[res->portid];
2454         if (isrx) {
2455                 socket_id = rxring_numa[res->portid];
2456                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2457                         socket_id = port->socket_id;
2458
2459                 mp = mbuf_pool_find(socket_id);
2460                 if (mp == NULL) {
2461                         printf("Failed to setup RX queue: "
2462                                 "No mempool allocation"
2463                                 " on the socket %d\n",
2464                                 rxring_numa[res->portid]);
2465                         return;
2466                 }
2467                 ret = rte_eth_rx_queue_setup(res->portid,
2468                                              res->qid,
2469                                              port->nb_rx_desc[res->qid],
2470                                              socket_id,
2471                                              &port->rx_conf[res->qid],
2472                                              mp);
2473                 if (ret)
2474                         printf("Failed to setup RX queue\n");
2475         } else {
2476                 socket_id = txring_numa[res->portid];
2477                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2478                         socket_id = port->socket_id;
2479
2480                 ret = rte_eth_tx_queue_setup(res->portid,
2481                                              res->qid,
2482                                              port->nb_tx_desc[res->qid],
2483                                              socket_id,
2484                                              &port->tx_conf[res->qid]);
2485                 if (ret)
2486                         printf("Failed to setup TX queue\n");
2487         }
2488 }
2489
2490 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2491         .f = cmd_setup_rxtx_queue_parsed,
2492         .data = NULL,
2493         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2494         .tokens = {
2495                 (void *)&cmd_setup_rxtx_queue_port,
2496                 (void *)&cmd_setup_rxtx_queue_portid,
2497                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2498                 (void *)&cmd_setup_rxtx_queue_qid,
2499                 (void *)&cmd_setup_rxtx_queue_setup,
2500                 NULL,
2501         },
2502 };
2503
2504
2505 /* *** Configure RSS RETA *** */
2506 struct cmd_config_rss_reta {
2507         cmdline_fixed_string_t port;
2508         cmdline_fixed_string_t keyword;
2509         portid_t port_id;
2510         cmdline_fixed_string_t name;
2511         cmdline_fixed_string_t list_name;
2512         cmdline_fixed_string_t list_of_items;
2513 };
2514
2515 static int
2516 parse_reta_config(const char *str,
2517                   struct rte_eth_rss_reta_entry64 *reta_conf,
2518                   uint16_t nb_entries)
2519 {
2520         int i;
2521         unsigned size;
2522         uint16_t hash_index, idx, shift;
2523         uint16_t nb_queue;
2524         char s[256];
2525         const char *p, *p0 = str;
2526         char *end;
2527         enum fieldnames {
2528                 FLD_HASH_INDEX = 0,
2529                 FLD_QUEUE,
2530                 _NUM_FLD
2531         };
2532         unsigned long int_fld[_NUM_FLD];
2533         char *str_fld[_NUM_FLD];
2534
2535         while ((p = strchr(p0,'(')) != NULL) {
2536                 ++p;
2537                 if((p0 = strchr(p,')')) == NULL)
2538                         return -1;
2539
2540                 size = p0 - p;
2541                 if(size >= sizeof(s))
2542                         return -1;
2543
2544                 snprintf(s, sizeof(s), "%.*s", size, p);
2545                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2546                         return -1;
2547                 for (i = 0; i < _NUM_FLD; i++) {
2548                         errno = 0;
2549                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2550                         if (errno != 0 || end == str_fld[i] ||
2551                                         int_fld[i] > 65535)
2552                                 return -1;
2553                 }
2554
2555                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2556                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2557
2558                 if (hash_index >= nb_entries) {
2559                         printf("Invalid RETA hash index=%d\n", hash_index);
2560                         return -1;
2561                 }
2562
2563                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2564                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2565                 reta_conf[idx].mask |= (1ULL << shift);
2566                 reta_conf[idx].reta[shift] = nb_queue;
2567         }
2568
2569         return 0;
2570 }
2571
2572 static void
2573 cmd_set_rss_reta_parsed(void *parsed_result,
2574                         __attribute__((unused)) struct cmdline *cl,
2575                         __attribute__((unused)) void *data)
2576 {
2577         int ret;
2578         struct rte_eth_dev_info dev_info;
2579         struct rte_eth_rss_reta_entry64 reta_conf[8];
2580         struct cmd_config_rss_reta *res = parsed_result;
2581
2582         memset(&dev_info, 0, sizeof(dev_info));
2583         rte_eth_dev_info_get(res->port_id, &dev_info);
2584         if (dev_info.reta_size == 0) {
2585                 printf("Redirection table size is 0 which is "
2586                                         "invalid for RSS\n");
2587                 return;
2588         } else
2589                 printf("The reta size of port %d is %u\n",
2590                         res->port_id, dev_info.reta_size);
2591         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2592                 printf("Currently do not support more than %u entries of "
2593                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2594                 return;
2595         }
2596
2597         memset(reta_conf, 0, sizeof(reta_conf));
2598         if (!strcmp(res->list_name, "reta")) {
2599                 if (parse_reta_config(res->list_of_items, reta_conf,
2600                                                 dev_info.reta_size)) {
2601                         printf("Invalid RSS Redirection Table "
2602                                         "config entered\n");
2603                         return;
2604                 }
2605                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2606                                 reta_conf, dev_info.reta_size);
2607                 if (ret != 0)
2608                         printf("Bad redirection table parameter, "
2609                                         "return code = %d \n", ret);
2610         }
2611 }
2612
2613 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2614         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2615 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2616         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2617 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2618         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2619 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2621 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2622         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2623 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2625                                  NULL);
2626 cmdline_parse_inst_t cmd_config_rss_reta = {
2627         .f = cmd_set_rss_reta_parsed,
2628         .data = NULL,
2629         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2630         .tokens = {
2631                 (void *)&cmd_config_rss_reta_port,
2632                 (void *)&cmd_config_rss_reta_keyword,
2633                 (void *)&cmd_config_rss_reta_port_id,
2634                 (void *)&cmd_config_rss_reta_name,
2635                 (void *)&cmd_config_rss_reta_list_name,
2636                 (void *)&cmd_config_rss_reta_list_of_items,
2637                 NULL,
2638         },
2639 };
2640
2641 /* *** SHOW PORT RETA INFO *** */
2642 struct cmd_showport_reta {
2643         cmdline_fixed_string_t show;
2644         cmdline_fixed_string_t port;
2645         portid_t port_id;
2646         cmdline_fixed_string_t rss;
2647         cmdline_fixed_string_t reta;
2648         uint16_t size;
2649         cmdline_fixed_string_t list_of_items;
2650 };
2651
2652 static int
2653 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2654                            uint16_t nb_entries,
2655                            char *str)
2656 {
2657         uint32_t size;
2658         const char *p, *p0 = str;
2659         char s[256];
2660         char *end;
2661         char *str_fld[8];
2662         uint16_t i;
2663         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2664                         RTE_RETA_GROUP_SIZE;
2665         int ret;
2666
2667         p = strchr(p0, '(');
2668         if (p == NULL)
2669                 return -1;
2670         p++;
2671         p0 = strchr(p, ')');
2672         if (p0 == NULL)
2673                 return -1;
2674         size = p0 - p;
2675         if (size >= sizeof(s)) {
2676                 printf("The string size exceeds the internal buffer size\n");
2677                 return -1;
2678         }
2679         snprintf(s, sizeof(s), "%.*s", size, p);
2680         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2681         if (ret <= 0 || ret != num) {
2682                 printf("The bits of masks do not match the number of "
2683                                         "reta entries: %u\n", num);
2684                 return -1;
2685         }
2686         for (i = 0; i < ret; i++)
2687                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2688
2689         return 0;
2690 }
2691
2692 static void
2693 cmd_showport_reta_parsed(void *parsed_result,
2694                          __attribute__((unused)) struct cmdline *cl,
2695                          __attribute__((unused)) void *data)
2696 {
2697         struct cmd_showport_reta *res = parsed_result;
2698         struct rte_eth_rss_reta_entry64 reta_conf[8];
2699         struct rte_eth_dev_info dev_info;
2700         uint16_t max_reta_size;
2701
2702         memset(&dev_info, 0, sizeof(dev_info));
2703         rte_eth_dev_info_get(res->port_id, &dev_info);
2704         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2705         if (res->size == 0 || res->size > max_reta_size) {
2706                 printf("Invalid redirection table size: %u (1-%u)\n",
2707                         res->size, max_reta_size);
2708                 return;
2709         }
2710
2711         memset(reta_conf, 0, sizeof(reta_conf));
2712         if (showport_parse_reta_config(reta_conf, res->size,
2713                                 res->list_of_items) < 0) {
2714                 printf("Invalid string: %s for reta masks\n",
2715                                         res->list_of_items);
2716                 return;
2717         }
2718         port_rss_reta_info(res->port_id, reta_conf, res->size);
2719 }
2720
2721 cmdline_parse_token_string_t cmd_showport_reta_show =
2722         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2723 cmdline_parse_token_string_t cmd_showport_reta_port =
2724         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2725 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2726         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2727 cmdline_parse_token_string_t cmd_showport_reta_rss =
2728         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2729 cmdline_parse_token_string_t cmd_showport_reta_reta =
2730         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2731 cmdline_parse_token_num_t cmd_showport_reta_size =
2732         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2733 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2734         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2735                                         list_of_items, NULL);
2736
2737 cmdline_parse_inst_t cmd_showport_reta = {
2738         .f = cmd_showport_reta_parsed,
2739         .data = NULL,
2740         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2741         .tokens = {
2742                 (void *)&cmd_showport_reta_show,
2743                 (void *)&cmd_showport_reta_port,
2744                 (void *)&cmd_showport_reta_port_id,
2745                 (void *)&cmd_showport_reta_rss,
2746                 (void *)&cmd_showport_reta_reta,
2747                 (void *)&cmd_showport_reta_size,
2748                 (void *)&cmd_showport_reta_list_of_items,
2749                 NULL,
2750         },
2751 };
2752
2753 /* *** Show RSS hash configuration *** */
2754 struct cmd_showport_rss_hash {
2755         cmdline_fixed_string_t show;
2756         cmdline_fixed_string_t port;
2757         portid_t port_id;
2758         cmdline_fixed_string_t rss_hash;
2759         cmdline_fixed_string_t rss_type;
2760         cmdline_fixed_string_t key; /* optional argument */
2761 };
2762
2763 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2764                                 __attribute__((unused)) struct cmdline *cl,
2765                                 void *show_rss_key)
2766 {
2767         struct cmd_showport_rss_hash *res = parsed_result;
2768
2769         port_rss_hash_conf_show(res->port_id, res->rss_type,
2770                                 show_rss_key != NULL);
2771 }
2772
2773 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2774         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2775 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2776         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2777 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2778         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2779 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2780         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2781                                  "rss-hash");
2782 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2783         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2784                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2785                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2786                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2787                                  "ipv6-tcp-ex#ipv6-udp-ex");
2788 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2789         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2790
2791 cmdline_parse_inst_t cmd_showport_rss_hash = {
2792         .f = cmd_showport_rss_hash_parsed,
2793         .data = NULL,
2794         .help_str = "show port <port_id> rss-hash "
2795                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2796                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2797                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2798         .tokens = {
2799                 (void *)&cmd_showport_rss_hash_show,
2800                 (void *)&cmd_showport_rss_hash_port,
2801                 (void *)&cmd_showport_rss_hash_port_id,
2802                 (void *)&cmd_showport_rss_hash_rss_hash,
2803                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2804                 NULL,
2805         },
2806 };
2807
2808 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2809         .f = cmd_showport_rss_hash_parsed,
2810         .data = (void *)1,
2811         .help_str = "show port <port_id> rss-hash "
2812                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2813                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2814                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2815         .tokens = {
2816                 (void *)&cmd_showport_rss_hash_show,
2817                 (void *)&cmd_showport_rss_hash_port,
2818                 (void *)&cmd_showport_rss_hash_port_id,
2819                 (void *)&cmd_showport_rss_hash_rss_hash,
2820                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2821                 (void *)&cmd_showport_rss_hash_rss_key,
2822                 NULL,
2823         },
2824 };
2825
2826 /* *** Configure DCB *** */
2827 struct cmd_config_dcb {
2828         cmdline_fixed_string_t port;
2829         cmdline_fixed_string_t config;
2830         portid_t port_id;
2831         cmdline_fixed_string_t dcb;
2832         cmdline_fixed_string_t vt;
2833         cmdline_fixed_string_t vt_en;
2834         uint8_t num_tcs;
2835         cmdline_fixed_string_t pfc;
2836         cmdline_fixed_string_t pfc_en;
2837 };
2838
2839 static void
2840 cmd_config_dcb_parsed(void *parsed_result,
2841                         __attribute__((unused)) struct cmdline *cl,
2842                         __attribute__((unused)) void *data)
2843 {
2844         struct cmd_config_dcb *res = parsed_result;
2845         portid_t port_id = res->port_id;
2846         struct rte_port *port;
2847         uint8_t pfc_en;
2848         int ret;
2849
2850         port = &ports[port_id];
2851         /** Check if the port is not started **/
2852         if (port->port_status != RTE_PORT_STOPPED) {
2853                 printf("Please stop port %d first\n", port_id);
2854                 return;
2855         }
2856
2857         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2858                 printf("The invalid number of traffic class,"
2859                         " only 4 or 8 allowed.\n");
2860                 return;
2861         }
2862
2863         if (nb_fwd_lcores < res->num_tcs) {
2864                 printf("nb_cores shouldn't be less than number of TCs.\n");
2865                 return;
2866         }
2867         if (!strncmp(res->pfc_en, "on", 2))
2868                 pfc_en = 1;
2869         else
2870                 pfc_en = 0;
2871
2872         /* DCB in VT mode */
2873         if (!strncmp(res->vt_en, "on", 2))
2874                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2875                                 (enum rte_eth_nb_tcs)res->num_tcs,
2876                                 pfc_en);
2877         else
2878                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2879                                 (enum rte_eth_nb_tcs)res->num_tcs,
2880                                 pfc_en);
2881
2882
2883         if (ret != 0) {
2884                 printf("Cannot initialize network ports.\n");
2885                 return;
2886         }
2887
2888         cmd_reconfig_device_queue(port_id, 1, 1);
2889 }
2890
2891 cmdline_parse_token_string_t cmd_config_dcb_port =
2892         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2893 cmdline_parse_token_string_t cmd_config_dcb_config =
2894         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2895 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2896         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2897 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2898         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2899 cmdline_parse_token_string_t cmd_config_dcb_vt =
2900         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2901 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2902         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2903 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2904         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2905 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2906         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2907 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2908         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2909
2910 cmdline_parse_inst_t cmd_config_dcb = {
2911         .f = cmd_config_dcb_parsed,
2912         .data = NULL,
2913         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2914         .tokens = {
2915                 (void *)&cmd_config_dcb_port,
2916                 (void *)&cmd_config_dcb_config,
2917                 (void *)&cmd_config_dcb_port_id,
2918                 (void *)&cmd_config_dcb_dcb,
2919                 (void *)&cmd_config_dcb_vt,
2920                 (void *)&cmd_config_dcb_vt_en,
2921                 (void *)&cmd_config_dcb_num_tcs,
2922                 (void *)&cmd_config_dcb_pfc,
2923                 (void *)&cmd_config_dcb_pfc_en,
2924                 NULL,
2925         },
2926 };
2927
2928 /* *** configure number of packets per burst *** */
2929 struct cmd_config_burst {
2930         cmdline_fixed_string_t port;
2931         cmdline_fixed_string_t keyword;
2932         cmdline_fixed_string_t all;
2933         cmdline_fixed_string_t name;
2934         uint16_t value;
2935 };
2936
2937 static void
2938 cmd_config_burst_parsed(void *parsed_result,
2939                         __attribute__((unused)) struct cmdline *cl,
2940                         __attribute__((unused)) void *data)
2941 {
2942         struct cmd_config_burst *res = parsed_result;
2943         struct rte_eth_dev_info dev_info;
2944         uint16_t rec_nb_pkts;
2945
2946         if (!all_ports_stopped()) {
2947                 printf("Please stop all ports first\n");
2948                 return;
2949         }
2950
2951         if (!strcmp(res->name, "burst")) {
2952                 if (res->value == 0) {
2953                         /* If user gives a value of zero, query the PMD for
2954                          * its recommended Rx burst size. Testpmd uses a single
2955                          * size for all ports, so assume all ports are the same
2956                          * NIC model and use the values from Port 0.
2957                          */
2958                         rte_eth_dev_info_get(0, &dev_info);
2959                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2960
2961                         if (rec_nb_pkts == 0) {
2962                                 printf("PMD does not recommend a burst size.\n"
2963                                         "User provided value must be between"
2964                                         " 1 and %d\n", MAX_PKT_BURST);
2965                                 return;
2966                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2967                                 printf("PMD recommended burst size of %d"
2968                                         " exceeds maximum value of %d\n",
2969                                         rec_nb_pkts, MAX_PKT_BURST);
2970                                 return;
2971                         }
2972                         printf("Using PMD-provided burst value of %d\n",
2973                                 rec_nb_pkts);
2974                         nb_pkt_per_burst = rec_nb_pkts;
2975                 } else if (res->value > MAX_PKT_BURST) {
2976                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2977                         return;
2978                 } else
2979                         nb_pkt_per_burst = res->value;
2980         } else {
2981                 printf("Unknown parameter\n");
2982                 return;
2983         }
2984
2985         init_port_config();
2986
2987         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2988 }
2989
2990 cmdline_parse_token_string_t cmd_config_burst_port =
2991         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2992 cmdline_parse_token_string_t cmd_config_burst_keyword =
2993         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2994 cmdline_parse_token_string_t cmd_config_burst_all =
2995         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2996 cmdline_parse_token_string_t cmd_config_burst_name =
2997         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2998 cmdline_parse_token_num_t cmd_config_burst_value =
2999         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3000
3001 cmdline_parse_inst_t cmd_config_burst = {
3002         .f = cmd_config_burst_parsed,
3003         .data = NULL,
3004         .help_str = "port config all burst <value>",
3005         .tokens = {
3006                 (void *)&cmd_config_burst_port,
3007                 (void *)&cmd_config_burst_keyword,
3008                 (void *)&cmd_config_burst_all,
3009                 (void *)&cmd_config_burst_name,
3010                 (void *)&cmd_config_burst_value,
3011                 NULL,
3012         },
3013 };
3014
3015 /* *** configure rx/tx queues *** */
3016 struct cmd_config_thresh {
3017         cmdline_fixed_string_t port;
3018         cmdline_fixed_string_t keyword;
3019         cmdline_fixed_string_t all;
3020         cmdline_fixed_string_t name;
3021         uint8_t value;
3022 };
3023
3024 static void
3025 cmd_config_thresh_parsed(void *parsed_result,
3026                         __attribute__((unused)) struct cmdline *cl,
3027                         __attribute__((unused)) void *data)
3028 {
3029         struct cmd_config_thresh *res = parsed_result;
3030
3031         if (!all_ports_stopped()) {
3032                 printf("Please stop all ports first\n");
3033                 return;
3034         }
3035
3036         if (!strcmp(res->name, "txpt"))
3037                 tx_pthresh = res->value;
3038         else if(!strcmp(res->name, "txht"))
3039                 tx_hthresh = res->value;
3040         else if(!strcmp(res->name, "txwt"))
3041                 tx_wthresh = res->value;
3042         else if(!strcmp(res->name, "rxpt"))
3043                 rx_pthresh = res->value;
3044         else if(!strcmp(res->name, "rxht"))
3045                 rx_hthresh = res->value;
3046         else if(!strcmp(res->name, "rxwt"))
3047                 rx_wthresh = res->value;
3048         else {
3049                 printf("Unknown parameter\n");
3050                 return;
3051         }
3052
3053         init_port_config();
3054
3055         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3056 }
3057
3058 cmdline_parse_token_string_t cmd_config_thresh_port =
3059         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3060 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3061         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3062 cmdline_parse_token_string_t cmd_config_thresh_all =
3063         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3064 cmdline_parse_token_string_t cmd_config_thresh_name =
3065         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3066                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3067 cmdline_parse_token_num_t cmd_config_thresh_value =
3068         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3069
3070 cmdline_parse_inst_t cmd_config_thresh = {
3071         .f = cmd_config_thresh_parsed,
3072         .data = NULL,
3073         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3074         .tokens = {
3075                 (void *)&cmd_config_thresh_port,
3076                 (void *)&cmd_config_thresh_keyword,
3077                 (void *)&cmd_config_thresh_all,
3078                 (void *)&cmd_config_thresh_name,
3079                 (void *)&cmd_config_thresh_value,
3080                 NULL,
3081         },
3082 };
3083
3084 /* *** configure free/rs threshold *** */
3085 struct cmd_config_threshold {
3086         cmdline_fixed_string_t port;
3087         cmdline_fixed_string_t keyword;
3088         cmdline_fixed_string_t all;
3089         cmdline_fixed_string_t name;
3090         uint16_t value;
3091 };
3092
3093 static void
3094 cmd_config_threshold_parsed(void *parsed_result,
3095                         __attribute__((unused)) struct cmdline *cl,
3096                         __attribute__((unused)) void *data)
3097 {
3098         struct cmd_config_threshold *res = parsed_result;
3099
3100         if (!all_ports_stopped()) {
3101                 printf("Please stop all ports first\n");
3102                 return;
3103         }
3104
3105         if (!strcmp(res->name, "txfreet"))
3106                 tx_free_thresh = res->value;
3107         else if (!strcmp(res->name, "txrst"))
3108                 tx_rs_thresh = res->value;
3109         else if (!strcmp(res->name, "rxfreet"))
3110                 rx_free_thresh = res->value;
3111         else {
3112                 printf("Unknown parameter\n");
3113                 return;
3114         }
3115
3116         init_port_config();
3117
3118         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3119 }
3120
3121 cmdline_parse_token_string_t cmd_config_threshold_port =
3122         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3123 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3124         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3125                                                                 "config");
3126 cmdline_parse_token_string_t cmd_config_threshold_all =
3127         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3128 cmdline_parse_token_string_t cmd_config_threshold_name =
3129         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3130                                                 "txfreet#txrst#rxfreet");
3131 cmdline_parse_token_num_t cmd_config_threshold_value =
3132         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3133
3134 cmdline_parse_inst_t cmd_config_threshold = {
3135         .f = cmd_config_threshold_parsed,
3136         .data = NULL,
3137         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3138         .tokens = {
3139                 (void *)&cmd_config_threshold_port,
3140                 (void *)&cmd_config_threshold_keyword,
3141                 (void *)&cmd_config_threshold_all,
3142                 (void *)&cmd_config_threshold_name,
3143                 (void *)&cmd_config_threshold_value,
3144                 NULL,
3145         },
3146 };
3147
3148 /* *** stop *** */
3149 struct cmd_stop_result {
3150         cmdline_fixed_string_t stop;
3151 };
3152
3153 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3154                             __attribute__((unused)) struct cmdline *cl,
3155                             __attribute__((unused)) void *data)
3156 {
3157         stop_packet_forwarding();
3158 }
3159
3160 cmdline_parse_token_string_t cmd_stop_stop =
3161         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3162
3163 cmdline_parse_inst_t cmd_stop = {
3164         .f = cmd_stop_parsed,
3165         .data = NULL,
3166         .help_str = "stop: Stop packet forwarding",
3167         .tokens = {
3168                 (void *)&cmd_stop_stop,
3169                 NULL,
3170         },
3171 };
3172
3173 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3174
3175 unsigned int
3176 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3177                 unsigned int *parsed_items, int check_unique_values)
3178 {
3179         unsigned int nb_item;
3180         unsigned int value;
3181         unsigned int i;
3182         unsigned int j;
3183         int value_ok;
3184         char c;
3185
3186         /*
3187          * First parse all items in the list and store their value.
3188          */
3189         value = 0;
3190         nb_item = 0;
3191         value_ok = 0;
3192         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3193                 c = str[i];
3194                 if ((c >= '0') && (c <= '9')) {
3195                         value = (unsigned int) (value * 10 + (c - '0'));
3196                         value_ok = 1;
3197                         continue;
3198                 }
3199                 if (c != ',') {
3200                         printf("character %c is not a decimal digit\n", c);
3201                         return 0;
3202                 }
3203                 if (! value_ok) {
3204                         printf("No valid value before comma\n");
3205                         return 0;
3206                 }
3207                 if (nb_item < max_items) {
3208                         parsed_items[nb_item] = value;
3209                         value_ok = 0;
3210                         value = 0;
3211                 }
3212                 nb_item++;
3213         }
3214         if (nb_item >= max_items) {
3215                 printf("Number of %s = %u > %u (maximum items)\n",
3216                        item_name, nb_item + 1, max_items);
3217                 return 0;
3218         }
3219         parsed_items[nb_item++] = value;
3220         if (! check_unique_values)
3221                 return nb_item;
3222
3223         /*
3224          * Then, check that all values in the list are differents.
3225          * No optimization here...
3226          */
3227         for (i = 0; i < nb_item; i++) {
3228                 for (j = i + 1; j < nb_item; j++) {
3229                         if (parsed_items[j] == parsed_items[i]) {
3230                                 printf("duplicated %s %u at index %u and %u\n",
3231                                        item_name, parsed_items[i], i, j);
3232                                 return 0;
3233                         }
3234                 }
3235         }
3236         return nb_item;
3237 }
3238
3239 struct cmd_set_list_result {
3240         cmdline_fixed_string_t cmd_keyword;
3241         cmdline_fixed_string_t list_name;
3242         cmdline_fixed_string_t list_of_items;
3243 };
3244
3245 static void cmd_set_list_parsed(void *parsed_result,
3246                                 __attribute__((unused)) struct cmdline *cl,
3247                                 __attribute__((unused)) void *data)
3248 {
3249         struct cmd_set_list_result *res;
3250         union {
3251                 unsigned int lcorelist[RTE_MAX_LCORE];
3252                 unsigned int portlist[RTE_MAX_ETHPORTS];
3253         } parsed_items;
3254         unsigned int nb_item;
3255
3256         if (test_done == 0) {
3257                 printf("Please stop forwarding first\n");
3258                 return;
3259         }
3260
3261         res = parsed_result;
3262         if (!strcmp(res->list_name, "corelist")) {
3263                 nb_item = parse_item_list(res->list_of_items, "core",
3264                                           RTE_MAX_LCORE,
3265                                           parsed_items.lcorelist, 1);
3266                 if (nb_item > 0) {
3267                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3268                         fwd_config_setup();
3269                 }
3270                 return;
3271         }
3272         if (!strcmp(res->list_name, "portlist")) {
3273                 nb_item = parse_item_list(res->list_of_items, "port",
3274                                           RTE_MAX_ETHPORTS,
3275                                           parsed_items.portlist, 1);
3276                 if (nb_item > 0) {
3277                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3278                         fwd_config_setup();
3279                 }
3280         }
3281 }
3282
3283 cmdline_parse_token_string_t cmd_set_list_keyword =
3284         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3285                                  "set");
3286 cmdline_parse_token_string_t cmd_set_list_name =
3287         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3288                                  "corelist#portlist");
3289 cmdline_parse_token_string_t cmd_set_list_of_items =
3290         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3291                                  NULL);
3292
3293 cmdline_parse_inst_t cmd_set_fwd_list = {
3294         .f = cmd_set_list_parsed,
3295         .data = NULL,
3296         .help_str = "set corelist|portlist <list0[,list1]*>",
3297         .tokens = {
3298                 (void *)&cmd_set_list_keyword,
3299                 (void *)&cmd_set_list_name,
3300                 (void *)&cmd_set_list_of_items,
3301                 NULL,
3302         },
3303 };
3304
3305 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3306
3307 struct cmd_setmask_result {
3308         cmdline_fixed_string_t set;
3309         cmdline_fixed_string_t mask;
3310         uint64_t hexavalue;
3311 };
3312
3313 static void cmd_set_mask_parsed(void *parsed_result,
3314                                 __attribute__((unused)) struct cmdline *cl,
3315                                 __attribute__((unused)) void *data)
3316 {
3317         struct cmd_setmask_result *res = parsed_result;
3318
3319         if (test_done == 0) {
3320                 printf("Please stop forwarding first\n");
3321                 return;
3322         }
3323         if (!strcmp(res->mask, "coremask")) {
3324                 set_fwd_lcores_mask(res->hexavalue);
3325                 fwd_config_setup();
3326         } else if (!strcmp(res->mask, "portmask")) {
3327                 set_fwd_ports_mask(res->hexavalue);
3328                 fwd_config_setup();
3329         }
3330 }
3331
3332 cmdline_parse_token_string_t cmd_setmask_set =
3333         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3334 cmdline_parse_token_string_t cmd_setmask_mask =
3335         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3336                                  "coremask#portmask");
3337 cmdline_parse_token_num_t cmd_setmask_value =
3338         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3339
3340 cmdline_parse_inst_t cmd_set_fwd_mask = {
3341         .f = cmd_set_mask_parsed,
3342         .data = NULL,
3343         .help_str = "set coremask|portmask <hexadecimal value>",
3344         .tokens = {
3345                 (void *)&cmd_setmask_set,
3346                 (void *)&cmd_setmask_mask,
3347                 (void *)&cmd_setmask_value,
3348                 NULL,
3349         },
3350 };
3351
3352 /*
3353  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3354  */
3355 struct cmd_set_result {
3356         cmdline_fixed_string_t set;
3357         cmdline_fixed_string_t what;
3358         uint16_t value;
3359 };
3360
3361 static void cmd_set_parsed(void *parsed_result,
3362                            __attribute__((unused)) struct cmdline *cl,
3363                            __attribute__((unused)) void *data)
3364 {
3365         struct cmd_set_result *res = parsed_result;
3366         if (!strcmp(res->what, "nbport")) {
3367                 set_fwd_ports_number(res->value);
3368                 fwd_config_setup();
3369         } else if (!strcmp(res->what, "nbcore")) {
3370                 set_fwd_lcores_number(res->value);
3371                 fwd_config_setup();
3372         } else if (!strcmp(res->what, "burst"))
3373                 set_nb_pkt_per_burst(res->value);
3374         else if (!strcmp(res->what, "verbose"))
3375                 set_verbose_level(res->value);
3376 }
3377
3378 cmdline_parse_token_string_t cmd_set_set =
3379         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3380 cmdline_parse_token_string_t cmd_set_what =
3381         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3382                                  "nbport#nbcore#burst#verbose");
3383 cmdline_parse_token_num_t cmd_set_value =
3384         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3385
3386 cmdline_parse_inst_t cmd_set_numbers = {
3387         .f = cmd_set_parsed,
3388         .data = NULL,
3389         .help_str = "set nbport|nbcore|burst|verbose <value>",
3390         .tokens = {
3391                 (void *)&cmd_set_set,
3392                 (void *)&cmd_set_what,
3393                 (void *)&cmd_set_value,
3394                 NULL,
3395         },
3396 };
3397
3398 /* *** SET LOG LEVEL CONFIGURATION *** */
3399
3400 struct cmd_set_log_result {
3401         cmdline_fixed_string_t set;
3402         cmdline_fixed_string_t log;
3403         cmdline_fixed_string_t type;
3404         uint32_t level;
3405 };
3406
3407 static void
3408 cmd_set_log_parsed(void *parsed_result,
3409                    __attribute__((unused)) struct cmdline *cl,
3410                    __attribute__((unused)) void *data)
3411 {
3412         struct cmd_set_log_result *res;
3413         int ret;
3414
3415         res = parsed_result;
3416         if (!strcmp(res->type, "global"))
3417                 rte_log_set_global_level(res->level);
3418         else {
3419                 ret = rte_log_set_level_regexp(res->type, res->level);
3420                 if (ret < 0)
3421                         printf("Unable to set log level\n");
3422         }
3423 }
3424
3425 cmdline_parse_token_string_t cmd_set_log_set =
3426         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3427 cmdline_parse_token_string_t cmd_set_log_log =
3428         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3429 cmdline_parse_token_string_t cmd_set_log_type =
3430         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3431 cmdline_parse_token_num_t cmd_set_log_level =
3432         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3433
3434 cmdline_parse_inst_t cmd_set_log = {
3435         .f = cmd_set_log_parsed,
3436         .data = NULL,
3437         .help_str = "set log global|<type> <level>",
3438         .tokens = {
3439                 (void *)&cmd_set_log_set,
3440                 (void *)&cmd_set_log_log,
3441                 (void *)&cmd_set_log_type,
3442                 (void *)&cmd_set_log_level,
3443                 NULL,
3444         },
3445 };
3446
3447 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3448
3449 struct cmd_set_txpkts_result {
3450         cmdline_fixed_string_t cmd_keyword;
3451         cmdline_fixed_string_t txpkts;
3452         cmdline_fixed_string_t seg_lengths;
3453 };
3454
3455 static void
3456 cmd_set_txpkts_parsed(void *parsed_result,
3457                       __attribute__((unused)) struct cmdline *cl,
3458                       __attribute__((unused)) void *data)
3459 {
3460         struct cmd_set_txpkts_result *res;
3461         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3462         unsigned int nb_segs;
3463
3464         res = parsed_result;
3465         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3466                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3467         if (nb_segs > 0)
3468                 set_tx_pkt_segments(seg_lengths, nb_segs);
3469 }
3470
3471 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3472         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3473                                  cmd_keyword, "set");
3474 cmdline_parse_token_string_t cmd_set_txpkts_name =
3475         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3476                                  txpkts, "txpkts");
3477 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3478         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3479                                  seg_lengths, NULL);
3480
3481 cmdline_parse_inst_t cmd_set_txpkts = {
3482         .f = cmd_set_txpkts_parsed,
3483         .data = NULL,
3484         .help_str = "set txpkts <len0[,len1]*>",
3485         .tokens = {
3486                 (void *)&cmd_set_txpkts_keyword,
3487                 (void *)&cmd_set_txpkts_name,
3488                 (void *)&cmd_set_txpkts_lengths,
3489                 NULL,
3490         },
3491 };
3492
3493 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3494
3495 struct cmd_set_txsplit_result {
3496         cmdline_fixed_string_t cmd_keyword;
3497         cmdline_fixed_string_t txsplit;
3498         cmdline_fixed_string_t mode;
3499 };
3500
3501 static void
3502 cmd_set_txsplit_parsed(void *parsed_result,
3503                       __attribute__((unused)) struct cmdline *cl,
3504                       __attribute__((unused)) void *data)
3505 {
3506         struct cmd_set_txsplit_result *res;
3507
3508         res = parsed_result;
3509         set_tx_pkt_split(res->mode);
3510 }
3511
3512 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3513         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3514                                  cmd_keyword, "set");
3515 cmdline_parse_token_string_t cmd_set_txsplit_name =
3516         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3517                                  txsplit, "txsplit");
3518 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3519         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3520                                  mode, NULL);
3521
3522 cmdline_parse_inst_t cmd_set_txsplit = {
3523         .f = cmd_set_txsplit_parsed,
3524         .data = NULL,
3525         .help_str = "set txsplit on|off|rand",
3526         .tokens = {
3527                 (void *)&cmd_set_txsplit_keyword,
3528                 (void *)&cmd_set_txsplit_name,
3529                 (void *)&cmd_set_txsplit_mode,
3530                 NULL,
3531         },
3532 };
3533
3534 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3535 struct cmd_rx_vlan_filter_all_result {
3536         cmdline_fixed_string_t rx_vlan;
3537         cmdline_fixed_string_t what;
3538         cmdline_fixed_string_t all;
3539         portid_t port_id;
3540 };
3541
3542 static void
3543 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3544                               __attribute__((unused)) struct cmdline *cl,
3545                               __attribute__((unused)) void *data)
3546 {
3547         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3548
3549         if (!strcmp(res->what, "add"))
3550                 rx_vlan_all_filter_set(res->port_id, 1);
3551         else
3552                 rx_vlan_all_filter_set(res->port_id, 0);
3553 }
3554
3555 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3556         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3557                                  rx_vlan, "rx_vlan");
3558 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3559         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3560                                  what, "add#rm");
3561 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3562         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3563                                  all, "all");
3564 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3565         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3566                               port_id, UINT16);
3567
3568 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3569         .f = cmd_rx_vlan_filter_all_parsed,
3570         .data = NULL,
3571         .help_str = "rx_vlan add|rm all <port_id>: "
3572                 "Add/Remove all identifiers to/from the set of VLAN "
3573                 "identifiers filtered by a port",
3574         .tokens = {
3575                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3576                 (void *)&cmd_rx_vlan_filter_all_what,
3577                 (void *)&cmd_rx_vlan_filter_all_all,
3578                 (void *)&cmd_rx_vlan_filter_all_portid,
3579                 NULL,
3580         },
3581 };
3582
3583 /* *** VLAN OFFLOAD SET ON A PORT *** */
3584 struct cmd_vlan_offload_result {
3585         cmdline_fixed_string_t vlan;
3586         cmdline_fixed_string_t set;
3587         cmdline_fixed_string_t vlan_type;
3588         cmdline_fixed_string_t what;
3589         cmdline_fixed_string_t on;
3590         cmdline_fixed_string_t port_id;
3591 };
3592
3593 static void
3594 cmd_vlan_offload_parsed(void *parsed_result,
3595                           __attribute__((unused)) struct cmdline *cl,
3596                           __attribute__((unused)) void *data)
3597 {
3598         int on;
3599         struct cmd_vlan_offload_result *res = parsed_result;
3600         char *str;
3601         int i, len = 0;
3602         portid_t port_id = 0;
3603         unsigned int tmp;
3604
3605         str = res->port_id;
3606         len = strnlen(str, STR_TOKEN_SIZE);
3607         i = 0;
3608         /* Get port_id first */
3609         while(i < len){
3610                 if(str[i] == ',')
3611                         break;
3612
3613                 i++;
3614         }
3615         str[i]='\0';
3616         tmp = strtoul(str, NULL, 0);
3617         /* If port_id greater that what portid_t can represent, return */
3618         if(tmp >= RTE_MAX_ETHPORTS)
3619                 return;
3620         port_id = (portid_t)tmp;
3621
3622         if (!strcmp(res->on, "on"))
3623                 on = 1;
3624         else
3625                 on = 0;
3626
3627         if (!strcmp(res->what, "strip"))
3628                 rx_vlan_strip_set(port_id,  on);
3629         else if(!strcmp(res->what, "stripq")){
3630                 uint16_t queue_id = 0;
3631
3632                 /* No queue_id, return */
3633                 if(i + 1 >= len) {
3634                         printf("must specify (port,queue_id)\n");
3635                         return;
3636                 }
3637                 tmp = strtoul(str + i + 1, NULL, 0);
3638                 /* If queue_id greater that what 16-bits can represent, return */
3639                 if(tmp > 0xffff)
3640                         return;
3641
3642                 queue_id = (uint16_t)tmp;
3643                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3644         }
3645         else if (!strcmp(res->what, "filter"))
3646                 rx_vlan_filter_set(port_id, on);
3647         else
3648                 vlan_extend_set(port_id, on);
3649
3650         return;
3651 }
3652
3653 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3654         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3655                                  vlan, "vlan");
3656 cmdline_parse_token_string_t cmd_vlan_offload_set =
3657         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3658                                  set, "set");
3659 cmdline_parse_token_string_t cmd_vlan_offload_what =
3660         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3661                                  what, "strip#filter#qinq#stripq");
3662 cmdline_parse_token_string_t cmd_vlan_offload_on =
3663         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3664                               on, "on#off");
3665 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3666         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3667                               port_id, NULL);
3668
3669 cmdline_parse_inst_t cmd_vlan_offload = {
3670         .f = cmd_vlan_offload_parsed,
3671         .data = NULL,
3672         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3673                 "<port_id[,queue_id]>: "
3674                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3675         .tokens = {
3676                 (void *)&cmd_vlan_offload_vlan,
3677                 (void *)&cmd_vlan_offload_set,
3678                 (void *)&cmd_vlan_offload_what,
3679                 (void *)&cmd_vlan_offload_on,
3680                 (void *)&cmd_vlan_offload_portid,
3681                 NULL,
3682         },
3683 };
3684
3685 /* *** VLAN TPID SET ON A PORT *** */
3686 struct cmd_vlan_tpid_result {
3687         cmdline_fixed_string_t vlan;
3688         cmdline_fixed_string_t set;
3689         cmdline_fixed_string_t vlan_type;
3690         cmdline_fixed_string_t what;
3691         uint16_t tp_id;
3692         portid_t port_id;
3693 };
3694
3695 static void
3696 cmd_vlan_tpid_parsed(void *parsed_result,
3697                           __attribute__((unused)) struct cmdline *cl,
3698                           __attribute__((unused)) void *data)
3699 {
3700         struct cmd_vlan_tpid_result *res = parsed_result;
3701         enum rte_vlan_type vlan_type;
3702
3703         if (!strcmp(res->vlan_type, "inner"))
3704                 vlan_type = ETH_VLAN_TYPE_INNER;
3705         else if (!strcmp(res->vlan_type, "outer"))
3706                 vlan_type = ETH_VLAN_TYPE_OUTER;
3707         else {
3708                 printf("Unknown vlan type\n");
3709                 return;
3710         }
3711         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3712 }
3713
3714 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3715         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3716                                  vlan, "vlan");
3717 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3718         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3719                                  set, "set");
3720 cmdline_parse_token_string_t cmd_vlan_type =
3721         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3722                                  vlan_type, "inner#outer");
3723 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3724         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3725                                  what, "tpid");
3726 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3727         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3728                               tp_id, UINT16);
3729 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3730         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3731                               port_id, UINT16);
3732
3733 cmdline_parse_inst_t cmd_vlan_tpid = {
3734         .f = cmd_vlan_tpid_parsed,
3735         .data = NULL,
3736         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3737                 "Set the VLAN Ether type",
3738         .tokens = {
3739                 (void *)&cmd_vlan_tpid_vlan,
3740                 (void *)&cmd_vlan_tpid_set,
3741                 (void *)&cmd_vlan_type,
3742                 (void *)&cmd_vlan_tpid_what,
3743                 (void *)&cmd_vlan_tpid_tpid,
3744                 (void *)&cmd_vlan_tpid_portid,
3745                 NULL,
3746         },
3747 };
3748
3749 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3750 struct cmd_rx_vlan_filter_result {
3751         cmdline_fixed_string_t rx_vlan;
3752         cmdline_fixed_string_t what;
3753         uint16_t vlan_id;
3754         portid_t port_id;
3755 };
3756
3757 static void
3758 cmd_rx_vlan_filter_parsed(void *parsed_result,
3759                           __attribute__((unused)) struct cmdline *cl,
3760                           __attribute__((unused)) void *data)
3761 {
3762         struct cmd_rx_vlan_filter_result *res = parsed_result;
3763
3764         if (!strcmp(res->what, "add"))
3765                 rx_vft_set(res->port_id, res->vlan_id, 1);
3766         else
3767                 rx_vft_set(res->port_id, res->vlan_id, 0);
3768 }
3769
3770 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3771         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3772                                  rx_vlan, "rx_vlan");
3773 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3774         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3775                                  what, "add#rm");
3776 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3777         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3778                               vlan_id, UINT16);
3779 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3780         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3781                               port_id, UINT16);
3782
3783 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3784         .f = cmd_rx_vlan_filter_parsed,
3785         .data = NULL,
3786         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3787                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3788                 "identifiers filtered by a port",
3789         .tokens = {
3790                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3791                 (void *)&cmd_rx_vlan_filter_what,
3792                 (void *)&cmd_rx_vlan_filter_vlanid,
3793                 (void *)&cmd_rx_vlan_filter_portid,
3794                 NULL,
3795         },
3796 };
3797
3798 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3799 struct cmd_tx_vlan_set_result {
3800         cmdline_fixed_string_t tx_vlan;
3801         cmdline_fixed_string_t set;
3802         portid_t port_id;
3803         uint16_t vlan_id;
3804 };
3805
3806 static void
3807 cmd_tx_vlan_set_parsed(void *parsed_result,
3808                        __attribute__((unused)) struct cmdline *cl,
3809                        __attribute__((unused)) void *data)
3810 {
3811         struct cmd_tx_vlan_set_result *res = parsed_result;
3812
3813         if (!port_is_stopped(res->port_id)) {
3814                 printf("Please stop port %d first\n", res->port_id);
3815                 return;
3816         }
3817
3818         tx_vlan_set(res->port_id, res->vlan_id);
3819
3820         cmd_reconfig_device_queue(res->port_id, 1, 1);
3821 }
3822
3823 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3824         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3825                                  tx_vlan, "tx_vlan");
3826 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3827         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3828                                  set, "set");
3829 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3830         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3831                               port_id, UINT16);
3832 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3833         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3834                               vlan_id, UINT16);
3835
3836 cmdline_parse_inst_t cmd_tx_vlan_set = {
3837         .f = cmd_tx_vlan_set_parsed,
3838         .data = NULL,
3839         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3840                 "Enable hardware insertion of a single VLAN header "
3841                 "with a given TAG Identifier in packets sent on a port",
3842         .tokens = {
3843                 (void *)&cmd_tx_vlan_set_tx_vlan,
3844                 (void *)&cmd_tx_vlan_set_set,
3845                 (void *)&cmd_tx_vlan_set_portid,
3846                 (void *)&cmd_tx_vlan_set_vlanid,
3847                 NULL,
3848         },
3849 };
3850
3851 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3852 struct cmd_tx_vlan_set_qinq_result {
3853         cmdline_fixed_string_t tx_vlan;
3854         cmdline_fixed_string_t set;
3855         portid_t port_id;
3856         uint16_t vlan_id;
3857         uint16_t vlan_id_outer;
3858 };
3859
3860 static void
3861 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3862                             __attribute__((unused)) struct cmdline *cl,
3863                             __attribute__((unused)) void *data)
3864 {
3865         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3866
3867         if (!port_is_stopped(res->port_id)) {
3868                 printf("Please stop port %d first\n", res->port_id);
3869                 return;
3870         }
3871
3872         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3873
3874         cmd_reconfig_device_queue(res->port_id, 1, 1);
3875 }
3876
3877 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3878         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3879                 tx_vlan, "tx_vlan");
3880 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3881         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3882                 set, "set");
3883 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3884         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3885                 port_id, UINT16);
3886 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3887         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3888                 vlan_id, UINT16);
3889 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3890         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3891                 vlan_id_outer, UINT16);
3892
3893 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3894         .f = cmd_tx_vlan_set_qinq_parsed,
3895         .data = NULL,
3896         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3897                 "Enable hardware insertion of double VLAN header "
3898                 "with given TAG Identifiers in packets sent on a port",
3899         .tokens = {
3900                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3901                 (void *)&cmd_tx_vlan_set_qinq_set,
3902                 (void *)&cmd_tx_vlan_set_qinq_portid,
3903                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3904                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3905                 NULL,
3906         },
3907 };
3908
3909 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3910 struct cmd_tx_vlan_set_pvid_result {
3911         cmdline_fixed_string_t tx_vlan;
3912         cmdline_fixed_string_t set;
3913         cmdline_fixed_string_t pvid;
3914         portid_t port_id;
3915         uint16_t vlan_id;
3916         cmdline_fixed_string_t mode;
3917 };
3918
3919 static void
3920 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3921                             __attribute__((unused)) struct cmdline *cl,
3922                             __attribute__((unused)) void *data)
3923 {
3924         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3925
3926         if (strcmp(res->mode, "on") == 0)
3927                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3928         else
3929                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3930 }
3931
3932 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3933         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3934                                  tx_vlan, "tx_vlan");
3935 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3936         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3937                                  set, "set");
3938 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3939         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3940                                  pvid, "pvid");
3941 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3942         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3943                              port_id, UINT16);
3944 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3945         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3946                               vlan_id, UINT16);
3947 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3948         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3949                                  mode, "on#off");
3950
3951 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3952         .f = cmd_tx_vlan_set_pvid_parsed,
3953         .data = NULL,
3954         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3955         .tokens = {
3956                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3957                 (void *)&cmd_tx_vlan_set_pvid_set,
3958                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3959                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3960                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3961                 (void *)&cmd_tx_vlan_set_pvid_mode,
3962                 NULL,
3963         },
3964 };
3965
3966 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3967 struct cmd_tx_vlan_reset_result {
3968         cmdline_fixed_string_t tx_vlan;
3969         cmdline_fixed_string_t reset;
3970         portid_t port_id;
3971 };
3972
3973 static void
3974 cmd_tx_vlan_reset_parsed(void *parsed_result,
3975                          __attribute__((unused)) struct cmdline *cl,
3976                          __attribute__((unused)) void *data)
3977 {
3978         struct cmd_tx_vlan_reset_result *res = parsed_result;
3979
3980         if (!port_is_stopped(res->port_id)) {
3981                 printf("Please stop port %d first\n", res->port_id);
3982                 return;
3983         }
3984
3985         tx_vlan_reset(res->port_id);
3986
3987         cmd_reconfig_device_queue(res->port_id, 1, 1);
3988 }
3989
3990 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3991         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3992                                  tx_vlan, "tx_vlan");
3993 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3994         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3995                                  reset, "reset");
3996 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3997         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3998                               port_id, UINT16);
3999
4000 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4001         .f = cmd_tx_vlan_reset_parsed,
4002         .data = NULL,
4003         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4004                 "VLAN header in packets sent on a port",
4005         .tokens = {
4006                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4007                 (void *)&cmd_tx_vlan_reset_reset,
4008                 (void *)&cmd_tx_vlan_reset_portid,
4009                 NULL,
4010         },
4011 };
4012
4013
4014 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4015 struct cmd_csum_result {
4016         cmdline_fixed_string_t csum;
4017         cmdline_fixed_string_t mode;
4018         cmdline_fixed_string_t proto;
4019         cmdline_fixed_string_t hwsw;
4020         portid_t port_id;
4021 };
4022
4023 static void
4024 csum_show(int port_id)
4025 {
4026         struct rte_eth_dev_info dev_info;
4027         uint64_t tx_offloads;
4028
4029         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4030         printf("Parse tunnel is %s\n",
4031                 (ports[port_id].parse_tunnel) ? "on" : "off");
4032         printf("IP checksum offload is %s\n",
4033                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4034         printf("UDP checksum offload is %s\n",
4035                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4036         printf("TCP checksum offload is %s\n",
4037                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4038         printf("SCTP checksum offload is %s\n",
4039                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4040         printf("Outer-Ip checksum offload is %s\n",
4041                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4042
4043         /* display warnings if configuration is not supported by the NIC */
4044         rte_eth_dev_info_get(port_id, &dev_info);
4045         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4046                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4047                 printf("Warning: hardware IP checksum enabled but not "
4048                         "supported by port %d\n", port_id);
4049         }
4050         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4051                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4052                 printf("Warning: hardware UDP checksum enabled but not "
4053                         "supported by port %d\n", port_id);
4054         }
4055         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4056                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4057                 printf("Warning: hardware TCP checksum enabled but not "
4058                         "supported by port %d\n", port_id);
4059         }
4060         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4061                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4062                 printf("Warning: hardware SCTP checksum enabled but not "
4063                         "supported by port %d\n", port_id);
4064         }
4065         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4066                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4067                 printf("Warning: hardware outer IP checksum enabled but not "
4068                         "supported by port %d\n", port_id);
4069         }
4070 }
4071
4072 static void
4073 cmd_csum_parsed(void *parsed_result,
4074                        __attribute__((unused)) struct cmdline *cl,
4075                        __attribute__((unused)) void *data)
4076 {
4077         struct cmd_csum_result *res = parsed_result;
4078         int hw = 0;
4079         uint64_t csum_offloads = 0;
4080         struct rte_eth_dev_info dev_info;
4081
4082         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4083                 printf("invalid port %d\n", res->port_id);
4084                 return;
4085         }
4086         if (!port_is_stopped(res->port_id)) {
4087                 printf("Please stop port %d first\n", res->port_id);
4088                 return;
4089         }
4090
4091         rte_eth_dev_info_get(res->port_id, &dev_info);
4092         if (!strcmp(res->mode, "set")) {
4093
4094                 if (!strcmp(res->hwsw, "hw"))
4095                         hw = 1;
4096
4097                 if (!strcmp(res->proto, "ip")) {
4098                         if (hw == 0 || (dev_info.tx_offload_capa &
4099                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4100                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4101                         } else {
4102                                 printf("IP checksum offload is not supported "
4103                                        "by port %u\n", res->port_id);
4104                         }
4105                 } else if (!strcmp(res->proto, "udp")) {
4106                         if (hw == 0 || (dev_info.tx_offload_capa &
4107                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4108                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4109                         } else {
4110                                 printf("UDP checksum offload is not supported "
4111                                        "by port %u\n", res->port_id);
4112                         }
4113                 } else if (!strcmp(res->proto, "tcp")) {
4114                         if (hw == 0 || (dev_info.tx_offload_capa &
4115                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4116                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4117                         } else {
4118                                 printf("TCP checksum offload is not supported "
4119                                        "by port %u\n", res->port_id);
4120                         }
4121                 } else if (!strcmp(res->proto, "sctp")) {
4122                         if (hw == 0 || (dev_info.tx_offload_capa &
4123                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4124                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4125                         } else {
4126                                 printf("SCTP checksum offload is not supported "
4127                                        "by port %u\n", res->port_id);
4128                         }
4129                 } else if (!strcmp(res->proto, "outer-ip")) {
4130                         if (hw == 0 || (dev_info.tx_offload_capa &
4131                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4132                                 csum_offloads |=
4133                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4134                         } else {
4135                                 printf("Outer IP checksum offload is not "
4136                                        "supported by port %u\n", res->port_id);
4137                         }
4138                 }
4139
4140                 if (hw) {
4141                         ports[res->port_id].dev_conf.txmode.offloads |=
4142                                                         csum_offloads;
4143                 } else {
4144                         ports[res->port_id].dev_conf.txmode.offloads &=
4145                                                         (~csum_offloads);
4146                 }
4147         }
4148         csum_show(res->port_id);
4149
4150         cmd_reconfig_device_queue(res->port_id, 1, 1);
4151 }
4152
4153 cmdline_parse_token_string_t cmd_csum_csum =
4154         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4155                                 csum, "csum");
4156 cmdline_parse_token_string_t cmd_csum_mode =
4157         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4158                                 mode, "set");
4159 cmdline_parse_token_string_t cmd_csum_proto =
4160         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4161                                 proto, "ip#tcp#udp#sctp#outer-ip");
4162 cmdline_parse_token_string_t cmd_csum_hwsw =
4163         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4164                                 hwsw, "hw#sw");
4165 cmdline_parse_token_num_t cmd_csum_portid =
4166         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4167                                 port_id, UINT16);
4168
4169 cmdline_parse_inst_t cmd_csum_set = {
4170         .f = cmd_csum_parsed,
4171         .data = NULL,
4172         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4173                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4174                 "using csum forward engine",
4175         .tokens = {
4176                 (void *)&cmd_csum_csum,
4177                 (void *)&cmd_csum_mode,
4178                 (void *)&cmd_csum_proto,
4179                 (void *)&cmd_csum_hwsw,
4180                 (void *)&cmd_csum_portid,
4181                 NULL,
4182         },
4183 };
4184
4185 cmdline_parse_token_string_t cmd_csum_mode_show =
4186         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4187                                 mode, "show");
4188
4189 cmdline_parse_inst_t cmd_csum_show = {
4190         .f = cmd_csum_parsed,
4191         .data = NULL,
4192         .help_str = "csum show <port_id>: Show checksum offload configuration",
4193         .tokens = {
4194                 (void *)&cmd_csum_csum,
4195                 (void *)&cmd_csum_mode_show,
4196                 (void *)&cmd_csum_portid,
4197                 NULL,
4198         },
4199 };
4200
4201 /* Enable/disable tunnel parsing */
4202 struct cmd_csum_tunnel_result {
4203         cmdline_fixed_string_t csum;
4204         cmdline_fixed_string_t parse;
4205         cmdline_fixed_string_t onoff;
4206         portid_t port_id;
4207 };
4208
4209 static void
4210 cmd_csum_tunnel_parsed(void *parsed_result,
4211                        __attribute__((unused)) struct cmdline *cl,
4212                        __attribute__((unused)) void *data)
4213 {
4214         struct cmd_csum_tunnel_result *res = parsed_result;
4215
4216         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4217                 return;
4218
4219         if (!strcmp(res->onoff, "on"))
4220                 ports[res->port_id].parse_tunnel = 1;
4221         else
4222                 ports[res->port_id].parse_tunnel = 0;
4223
4224         csum_show(res->port_id);
4225 }
4226
4227 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4228         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4229                                 csum, "csum");
4230 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4231         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4232                                 parse, "parse_tunnel");
4233 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4234         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4235                                 onoff, "on#off");
4236 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4237         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4238                                 port_id, UINT16);
4239
4240 cmdline_parse_inst_t cmd_csum_tunnel = {
4241         .f = cmd_csum_tunnel_parsed,
4242         .data = NULL,
4243         .help_str = "csum parse_tunnel on|off <port_id>: "
4244                 "Enable/Disable parsing of tunnels for csum engine",
4245         .tokens = {
4246                 (void *)&cmd_csum_tunnel_csum,
4247                 (void *)&cmd_csum_tunnel_parse,
4248                 (void *)&cmd_csum_tunnel_onoff,
4249                 (void *)&cmd_csum_tunnel_portid,
4250                 NULL,
4251         },
4252 };
4253
4254 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4255 struct cmd_tso_set_result {
4256         cmdline_fixed_string_t tso;
4257         cmdline_fixed_string_t mode;
4258         uint16_t tso_segsz;
4259         portid_t port_id;
4260 };
4261
4262 static void
4263 cmd_tso_set_parsed(void *parsed_result,
4264                        __attribute__((unused)) struct cmdline *cl,
4265                        __attribute__((unused)) void *data)
4266 {
4267         struct cmd_tso_set_result *res = parsed_result;
4268         struct rte_eth_dev_info dev_info;
4269
4270         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4271                 return;
4272         if (!port_is_stopped(res->port_id)) {
4273                 printf("Please stop port %d first\n", res->port_id);
4274                 return;
4275         }
4276
4277         if (!strcmp(res->mode, "set"))
4278                 ports[res->port_id].tso_segsz = res->tso_segsz;
4279
4280         rte_eth_dev_info_get(res->port_id, &dev_info);
4281         if ((ports[res->port_id].tso_segsz != 0) &&
4282                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4283                 printf("Error: TSO is not supported by port %d\n",
4284                        res->port_id);
4285                 return;
4286         }
4287
4288         if (ports[res->port_id].tso_segsz == 0) {
4289                 ports[res->port_id].dev_conf.txmode.offloads &=
4290                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4291                 printf("TSO for non-tunneled packets is disabled\n");
4292         } else {
4293                 ports[res->port_id].dev_conf.txmode.offloads |=
4294                                                 DEV_TX_OFFLOAD_TCP_TSO;
4295                 printf("TSO segment size for non-tunneled packets is %d\n",
4296                         ports[res->port_id].tso_segsz);
4297         }
4298
4299         /* display warnings if configuration is not supported by the NIC */
4300         rte_eth_dev_info_get(res->port_id, &dev_info);
4301         if ((ports[res->port_id].tso_segsz != 0) &&
4302                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4303                 printf("Warning: TSO enabled but not "
4304                         "supported by port %d\n", res->port_id);
4305         }
4306
4307         cmd_reconfig_device_queue(res->port_id, 1, 1);
4308 }
4309
4310 cmdline_parse_token_string_t cmd_tso_set_tso =
4311         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4312                                 tso, "tso");
4313 cmdline_parse_token_string_t cmd_tso_set_mode =
4314         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4315                                 mode, "set");
4316 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4317         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4318                                 tso_segsz, UINT16);
4319 cmdline_parse_token_num_t cmd_tso_set_portid =
4320         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4321                                 port_id, UINT16);
4322
4323 cmdline_parse_inst_t cmd_tso_set = {
4324         .f = cmd_tso_set_parsed,
4325         .data = NULL,
4326         .help_str = "tso set <tso_segsz> <port_id>: "
4327                 "Set TSO segment size of non-tunneled packets for csum engine "
4328                 "(0 to disable)",
4329         .tokens = {
4330                 (void *)&cmd_tso_set_tso,
4331                 (void *)&cmd_tso_set_mode,
4332                 (void *)&cmd_tso_set_tso_segsz,
4333                 (void *)&cmd_tso_set_portid,
4334                 NULL,
4335         },
4336 };
4337
4338 cmdline_parse_token_string_t cmd_tso_show_mode =
4339         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4340                                 mode, "show");
4341
4342
4343 cmdline_parse_inst_t cmd_tso_show = {
4344         .f = cmd_tso_set_parsed,
4345         .data = NULL,
4346         .help_str = "tso show <port_id>: "
4347                 "Show TSO segment size of non-tunneled packets for csum engine",
4348         .tokens = {
4349                 (void *)&cmd_tso_set_tso,
4350                 (void *)&cmd_tso_show_mode,
4351                 (void *)&cmd_tso_set_portid,
4352                 NULL,
4353         },
4354 };
4355
4356 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4357 struct cmd_tunnel_tso_set_result {
4358         cmdline_fixed_string_t tso;
4359         cmdline_fixed_string_t mode;
4360         uint16_t tso_segsz;
4361         portid_t port_id;
4362 };
4363
4364 static struct rte_eth_dev_info
4365 check_tunnel_tso_nic_support(portid_t port_id)
4366 {
4367         struct rte_eth_dev_info dev_info;
4368
4369         rte_eth_dev_info_get(port_id, &dev_info);
4370         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4371                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4372                        "not enabled for port %d\n", port_id);
4373         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4374                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4375                        "not enabled for port %d\n", port_id);
4376         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4377                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4378                        "not enabled for port %d\n", port_id);
4379         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4380                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4381                        "not enabled for port %d\n", port_id);
4382         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4383                 printf("Warning: IP TUNNEL TSO not supported therefore "
4384                        "not enabled for port %d\n", port_id);
4385         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4386                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4387                        "not enabled for port %d\n", port_id);
4388         return dev_info;
4389 }
4390
4391 static void
4392 cmd_tunnel_tso_set_parsed(void *parsed_result,
4393                           __attribute__((unused)) struct cmdline *cl,
4394                           __attribute__((unused)) void *data)
4395 {
4396         struct cmd_tunnel_tso_set_result *res = parsed_result;
4397         struct rte_eth_dev_info dev_info;
4398
4399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4400                 return;
4401         if (!port_is_stopped(res->port_id)) {
4402                 printf("Please stop port %d first\n", res->port_id);
4403                 return;
4404         }
4405
4406         if (!strcmp(res->mode, "set"))
4407                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4408
4409         dev_info = check_tunnel_tso_nic_support(res->port_id);
4410         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4411                 ports[res->port_id].dev_conf.txmode.offloads &=
4412                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4413                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4414                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4415                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4416                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4417                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4418                 printf("TSO for tunneled packets is disabled\n");
4419         } else {
4420                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4421                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4422                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4423                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4424                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4425                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4426
4427                 ports[res->port_id].dev_conf.txmode.offloads |=
4428                         (tso_offloads & dev_info.tx_offload_capa);
4429                 printf("TSO segment size for tunneled packets is %d\n",
4430                         ports[res->port_id].tunnel_tso_segsz);
4431
4432                 /* Below conditions are needed to make it work:
4433                  * (1) tunnel TSO is supported by the NIC;
4434                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4435                  * are recognized;
4436                  * (3) for tunneled pkts with outer L3 of IPv4,
4437                  * "csum set outer-ip" must be set to hw, because after tso,
4438                  * total_len of outer IP header is changed, and the checksum
4439                  * of outer IP header calculated by sw should be wrong; that
4440                  * is not necessary for IPv6 tunneled pkts because there's no
4441                  * checksum in IP header anymore.
4442                  */
4443
4444                 if (!ports[res->port_id].parse_tunnel)
4445                         printf("Warning: csum parse_tunnel must be set "
4446                                 "so that tunneled packets are recognized\n");
4447                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4448                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4449                         printf("Warning: csum set outer-ip must be set to hw "
4450                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4451         }
4452
4453         cmd_reconfig_device_queue(res->port_id, 1, 1);
4454 }
4455
4456 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4457         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4458                                 tso, "tunnel_tso");
4459 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4460         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4461                                 mode, "set");
4462 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4463         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4464                                 tso_segsz, UINT16);
4465 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4466         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4467                                 port_id, UINT16);
4468
4469 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4470         .f = cmd_tunnel_tso_set_parsed,
4471         .data = NULL,
4472         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4473                 "Set TSO segment size of tunneled packets for csum engine "
4474                 "(0 to disable)",
4475         .tokens = {
4476                 (void *)&cmd_tunnel_tso_set_tso,
4477                 (void *)&cmd_tunnel_tso_set_mode,
4478                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4479                 (void *)&cmd_tunnel_tso_set_portid,
4480                 NULL,
4481         },
4482 };
4483
4484 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4485         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4486                                 mode, "show");
4487
4488
4489 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4490         .f = cmd_tunnel_tso_set_parsed,
4491         .data = NULL,
4492         .help_str = "tunnel_tso show <port_id> "
4493                 "Show TSO segment size of tunneled packets for csum engine",
4494         .tokens = {
4495                 (void *)&cmd_tunnel_tso_set_tso,
4496                 (void *)&cmd_tunnel_tso_show_mode,
4497                 (void *)&cmd_tunnel_tso_set_portid,
4498                 NULL,
4499         },
4500 };
4501
4502 /* *** SET GRO FOR A PORT *** */
4503 struct cmd_gro_enable_result {
4504         cmdline_fixed_string_t cmd_set;
4505         cmdline_fixed_string_t cmd_port;
4506         cmdline_fixed_string_t cmd_keyword;
4507         cmdline_fixed_string_t cmd_onoff;
4508         portid_t cmd_pid;
4509 };
4510
4511 static void
4512 cmd_gro_enable_parsed(void *parsed_result,
4513                 __attribute__((unused)) struct cmdline *cl,
4514                 __attribute__((unused)) void *data)
4515 {
4516         struct cmd_gro_enable_result *res;
4517
4518         res = parsed_result;
4519         if (!strcmp(res->cmd_keyword, "gro"))
4520                 setup_gro(res->cmd_onoff, res->cmd_pid);
4521 }
4522
4523 cmdline_parse_token_string_t cmd_gro_enable_set =
4524         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4525                         cmd_set, "set");
4526 cmdline_parse_token_string_t cmd_gro_enable_port =
4527         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4528                         cmd_keyword, "port");
4529 cmdline_parse_token_num_t cmd_gro_enable_pid =
4530         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4531                         cmd_pid, UINT16);
4532 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4533         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4534                         cmd_keyword, "gro");
4535 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4536         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4537                         cmd_onoff, "on#off");
4538
4539 cmdline_parse_inst_t cmd_gro_enable = {
4540         .f = cmd_gro_enable_parsed,
4541         .data = NULL,
4542         .help_str = "set port <port_id> gro on|off",
4543         .tokens = {
4544                 (void *)&cmd_gro_enable_set,
4545                 (void *)&cmd_gro_enable_port,
4546                 (void *)&cmd_gro_enable_pid,
4547                 (void *)&cmd_gro_enable_keyword,
4548                 (void *)&cmd_gro_enable_onoff,
4549                 NULL,
4550         },
4551 };
4552
4553 /* *** DISPLAY GRO CONFIGURATION *** */
4554 struct cmd_gro_show_result {
4555         cmdline_fixed_string_t cmd_show;
4556         cmdline_fixed_string_t cmd_port;
4557         cmdline_fixed_string_t cmd_keyword;
4558         portid_t cmd_pid;
4559 };
4560
4561 static void
4562 cmd_gro_show_parsed(void *parsed_result,
4563                 __attribute__((unused)) struct cmdline *cl,
4564                 __attribute__((unused)) void *data)
4565 {
4566         struct cmd_gro_show_result *res;
4567
4568         res = parsed_result;
4569         if (!strcmp(res->cmd_keyword, "gro"))
4570                 show_gro(res->cmd_pid);
4571 }
4572
4573 cmdline_parse_token_string_t cmd_gro_show_show =
4574         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4575                         cmd_show, "show");
4576 cmdline_parse_token_string_t cmd_gro_show_port =
4577         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4578                         cmd_port, "port");
4579 cmdline_parse_token_num_t cmd_gro_show_pid =
4580         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4581                         cmd_pid, UINT16);
4582 cmdline_parse_token_string_t cmd_gro_show_keyword =
4583         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4584                         cmd_keyword, "gro");
4585
4586 cmdline_parse_inst_t cmd_gro_show = {
4587         .f = cmd_gro_show_parsed,
4588         .data = NULL,
4589         .help_str = "show port <port_id> gro",
4590         .tokens = {
4591                 (void *)&cmd_gro_show_show,
4592                 (void *)&cmd_gro_show_port,
4593                 (void *)&cmd_gro_show_pid,
4594                 (void *)&cmd_gro_show_keyword,
4595                 NULL,
4596         },
4597 };
4598
4599 /* *** SET FLUSH CYCLES FOR GRO *** */
4600 struct cmd_gro_flush_result {
4601         cmdline_fixed_string_t cmd_set;
4602         cmdline_fixed_string_t cmd_keyword;
4603         cmdline_fixed_string_t cmd_flush;
4604         uint8_t cmd_cycles;
4605 };
4606
4607 static void
4608 cmd_gro_flush_parsed(void *parsed_result,
4609                 __attribute__((unused)) struct cmdline *cl,
4610                 __attribute__((unused)) void *data)
4611 {
4612         struct cmd_gro_flush_result *res;
4613
4614         res = parsed_result;
4615         if ((!strcmp(res->cmd_keyword, "gro")) &&
4616                         (!strcmp(res->cmd_flush, "flush")))
4617                 setup_gro_flush_cycles(res->cmd_cycles);
4618 }
4619
4620 cmdline_parse_token_string_t cmd_gro_flush_set =
4621         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4622                         cmd_set, "set");
4623 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4624         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4625                         cmd_keyword, "gro");
4626 cmdline_parse_token_string_t cmd_gro_flush_flush =
4627         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4628                         cmd_flush, "flush");
4629 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4630         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4631                         cmd_cycles, UINT8);
4632
4633 cmdline_parse_inst_t cmd_gro_flush = {
4634         .f = cmd_gro_flush_parsed,
4635         .data = NULL,
4636         .help_str = "set gro flush <cycles>",
4637         .tokens = {
4638                 (void *)&cmd_gro_flush_set,
4639                 (void *)&cmd_gro_flush_keyword,
4640                 (void *)&cmd_gro_flush_flush,
4641                 (void *)&cmd_gro_flush_cycles,
4642                 NULL,
4643         },
4644 };
4645
4646 /* *** ENABLE/DISABLE GSO *** */
4647 struct cmd_gso_enable_result {
4648         cmdline_fixed_string_t cmd_set;
4649         cmdline_fixed_string_t cmd_port;
4650         cmdline_fixed_string_t cmd_keyword;
4651         cmdline_fixed_string_t cmd_mode;
4652         portid_t cmd_pid;
4653 };
4654
4655 static void
4656 cmd_gso_enable_parsed(void *parsed_result,
4657                 __attribute__((unused)) struct cmdline *cl,
4658                 __attribute__((unused)) void *data)
4659 {
4660         struct cmd_gso_enable_result *res;
4661
4662         res = parsed_result;
4663         if (!strcmp(res->cmd_keyword, "gso"))
4664                 setup_gso(res->cmd_mode, res->cmd_pid);
4665 }
4666
4667 cmdline_parse_token_string_t cmd_gso_enable_set =
4668         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4669                         cmd_set, "set");
4670 cmdline_parse_token_string_t cmd_gso_enable_port =
4671         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4672                         cmd_port, "port");
4673 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4674         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4675                         cmd_keyword, "gso");
4676 cmdline_parse_token_string_t cmd_gso_enable_mode =
4677         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4678                         cmd_mode, "on#off");
4679 cmdline_parse_token_num_t cmd_gso_enable_pid =
4680         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4681                         cmd_pid, UINT16);
4682
4683 cmdline_parse_inst_t cmd_gso_enable = {
4684         .f = cmd_gso_enable_parsed,
4685         .data = NULL,
4686         .help_str = "set port <port_id> gso on|off",
4687         .tokens = {
4688                 (void *)&cmd_gso_enable_set,
4689                 (void *)&cmd_gso_enable_port,
4690                 (void *)&cmd_gso_enable_pid,
4691                 (void *)&cmd_gso_enable_keyword,
4692                 (void *)&cmd_gso_enable_mode,
4693                 NULL,
4694         },
4695 };
4696
4697 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4698 struct cmd_gso_size_result {
4699         cmdline_fixed_string_t cmd_set;
4700         cmdline_fixed_string_t cmd_keyword;
4701         cmdline_fixed_string_t cmd_segsz;
4702         uint16_t cmd_size;
4703 };
4704
4705 static void
4706 cmd_gso_size_parsed(void *parsed_result,
4707                        __attribute__((unused)) struct cmdline *cl,
4708                        __attribute__((unused)) void *data)
4709 {
4710         struct cmd_gso_size_result *res = parsed_result;
4711
4712         if (test_done == 0) {
4713                 printf("Before setting GSO segsz, please first"
4714                                 " stop fowarding\n");
4715                 return;
4716         }
4717
4718         if (!strcmp(res->cmd_keyword, "gso") &&
4719                         !strcmp(res->cmd_segsz, "segsz")) {
4720                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4721                         printf("gso_size should be larger than %zu."
4722                                         " Please input a legal value\n",
4723                                         RTE_GSO_SEG_SIZE_MIN);
4724                 else
4725                         gso_max_segment_size = res->cmd_size;
4726         }
4727 }
4728
4729 cmdline_parse_token_string_t cmd_gso_size_set =
4730         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4731                                 cmd_set, "set");
4732 cmdline_parse_token_string_t cmd_gso_size_keyword =
4733         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4734                                 cmd_keyword, "gso");
4735 cmdline_parse_token_string_t cmd_gso_size_segsz =
4736         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4737                                 cmd_segsz, "segsz");
4738 cmdline_parse_token_num_t cmd_gso_size_size =
4739         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4740                                 cmd_size, UINT16);
4741
4742 cmdline_parse_inst_t cmd_gso_size = {
4743         .f = cmd_gso_size_parsed,
4744         .data = NULL,
4745         .help_str = "set gso segsz <length>",
4746         .tokens = {
4747                 (void *)&cmd_gso_size_set,
4748                 (void *)&cmd_gso_size_keyword,
4749                 (void *)&cmd_gso_size_segsz,
4750                 (void *)&cmd_gso_size_size,
4751                 NULL,
4752         },
4753 };
4754
4755 /* *** SHOW GSO CONFIGURATION *** */
4756 struct cmd_gso_show_result {
4757         cmdline_fixed_string_t cmd_show;
4758         cmdline_fixed_string_t cmd_port;
4759         cmdline_fixed_string_t cmd_keyword;
4760         portid_t cmd_pid;
4761 };
4762
4763 static void
4764 cmd_gso_show_parsed(void *parsed_result,
4765                        __attribute__((unused)) struct cmdline *cl,
4766                        __attribute__((unused)) void *data)
4767 {
4768         struct cmd_gso_show_result *res = parsed_result;
4769
4770         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4771                 printf("invalid port id %u\n", res->cmd_pid);
4772                 return;
4773         }
4774         if (!strcmp(res->cmd_keyword, "gso")) {
4775                 if (gso_ports[res->cmd_pid].enable) {
4776                         printf("Max GSO'd packet size: %uB\n"
4777                                         "Supported GSO types: TCP/IPv4, "
4778                                         "VxLAN with inner TCP/IPv4 packet, "
4779                                         "GRE with inner TCP/IPv4  packet\n",
4780                                         gso_max_segment_size);
4781                 } else
4782                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4783         }
4784 }
4785
4786 cmdline_parse_token_string_t cmd_gso_show_show =
4787 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4788                 cmd_show, "show");
4789 cmdline_parse_token_string_t cmd_gso_show_port =
4790 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4791                 cmd_port, "port");
4792 cmdline_parse_token_string_t cmd_gso_show_keyword =
4793         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4794                                 cmd_keyword, "gso");
4795 cmdline_parse_token_num_t cmd_gso_show_pid =
4796         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4797                                 cmd_pid, UINT16);
4798
4799 cmdline_parse_inst_t cmd_gso_show = {
4800         .f = cmd_gso_show_parsed,
4801         .data = NULL,
4802         .help_str = "show port <port_id> gso",
4803         .tokens = {
4804                 (void *)&cmd_gso_show_show,
4805                 (void *)&cmd_gso_show_port,
4806                 (void *)&cmd_gso_show_pid,
4807                 (void *)&cmd_gso_show_keyword,
4808                 NULL,
4809         },
4810 };
4811
4812 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4813 struct cmd_set_flush_rx {
4814         cmdline_fixed_string_t set;
4815         cmdline_fixed_string_t flush_rx;
4816         cmdline_fixed_string_t mode;
4817 };
4818
4819 static void
4820 cmd_set_flush_rx_parsed(void *parsed_result,
4821                 __attribute__((unused)) struct cmdline *cl,
4822                 __attribute__((unused)) void *data)
4823 {
4824         struct cmd_set_flush_rx *res = parsed_result;
4825         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4826 }
4827
4828 cmdline_parse_token_string_t cmd_setflushrx_set =
4829         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4830                         set, "set");
4831 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4832         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4833                         flush_rx, "flush_rx");
4834 cmdline_parse_token_string_t cmd_setflushrx_mode =
4835         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4836                         mode, "on#off");
4837
4838
4839 cmdline_parse_inst_t cmd_set_flush_rx = {
4840         .f = cmd_set_flush_rx_parsed,
4841         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4842         .data = NULL,
4843         .tokens = {
4844                 (void *)&cmd_setflushrx_set,
4845                 (void *)&cmd_setflushrx_flush_rx,
4846                 (void *)&cmd_setflushrx_mode,
4847                 NULL,
4848         },
4849 };
4850
4851 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4852 struct cmd_set_link_check {
4853         cmdline_fixed_string_t set;
4854         cmdline_fixed_string_t link_check;
4855         cmdline_fixed_string_t mode;
4856 };
4857
4858 static void
4859 cmd_set_link_check_parsed(void *parsed_result,
4860                 __attribute__((unused)) struct cmdline *cl,
4861                 __attribute__((unused)) void *data)
4862 {
4863         struct cmd_set_link_check *res = parsed_result;
4864         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4865 }
4866
4867 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4868         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4869                         set, "set");
4870 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4871         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4872                         link_check, "link_check");
4873 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4874         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4875                         mode, "on#off");
4876
4877
4878 cmdline_parse_inst_t cmd_set_link_check = {
4879         .f = cmd_set_link_check_parsed,
4880         .help_str = "set link_check on|off: Enable/Disable link status check "
4881                     "when starting/stopping a port",
4882         .data = NULL,
4883         .tokens = {
4884                 (void *)&cmd_setlinkcheck_set,
4885                 (void *)&cmd_setlinkcheck_link_check,
4886                 (void *)&cmd_setlinkcheck_mode,
4887                 NULL,
4888         },
4889 };
4890
4891 /* *** SET NIC BYPASS MODE *** */
4892 struct cmd_set_bypass_mode_result {
4893         cmdline_fixed_string_t set;
4894         cmdline_fixed_string_t bypass;
4895         cmdline_fixed_string_t mode;
4896         cmdline_fixed_string_t value;
4897         portid_t port_id;
4898 };
4899
4900 static void
4901 cmd_set_bypass_mode_parsed(void *parsed_result,
4902                 __attribute__((unused)) struct cmdline *cl,
4903                 __attribute__((unused)) void *data)
4904 {
4905         struct cmd_set_bypass_mode_result *res = parsed_result;
4906         portid_t port_id = res->port_id;
4907         int32_t rc = -EINVAL;
4908
4909 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4910         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4911
4912         if (!strcmp(res->value, "bypass"))
4913                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4914         else if (!strcmp(res->value, "isolate"))
4915                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4916         else
4917                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4918
4919         /* Set the bypass mode for the relevant port. */
4920         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4921 #endif
4922         if (rc != 0)
4923                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4924 }
4925
4926 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4927         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4928                         set, "set");
4929 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4930         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4931                         bypass, "bypass");
4932 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4933         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4934                         mode, "mode");
4935 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4936         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4937                         value, "normal#bypass#isolate");
4938 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4939         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4940                                 port_id, UINT16);
4941
4942 cmdline_parse_inst_t cmd_set_bypass_mode = {
4943         .f = cmd_set_bypass_mode_parsed,
4944         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4945                     "Set the NIC bypass mode for port_id",
4946         .data = NULL,
4947         .tokens = {
4948                 (void *)&cmd_setbypass_mode_set,
4949                 (void *)&cmd_setbypass_mode_bypass,
4950                 (void *)&cmd_setbypass_mode_mode,
4951                 (void *)&cmd_setbypass_mode_value,
4952                 (void *)&cmd_setbypass_mode_port,
4953                 NULL,
4954         },
4955 };
4956
4957 /* *** SET NIC BYPASS EVENT *** */
4958 struct cmd_set_bypass_event_result {
4959         cmdline_fixed_string_t set;
4960         cmdline_fixed_string_t bypass;
4961         cmdline_fixed_string_t event;
4962         cmdline_fixed_string_t event_value;
4963         cmdline_fixed_string_t mode;
4964         cmdline_fixed_string_t mode_value;
4965         portid_t port_id;
4966 };
4967
4968 static void
4969 cmd_set_bypass_event_parsed(void *parsed_result,
4970                 __attribute__((unused)) struct cmdline *cl,
4971                 __attribute__((unused)) void *data)
4972 {
4973         int32_t rc = -EINVAL;
4974         struct cmd_set_bypass_event_result *res = parsed_result;
4975         portid_t port_id = res->port_id;
4976
4977 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4978         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4979         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4980
4981         if (!strcmp(res->event_value, "timeout"))
4982                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4983         else if (!strcmp(res->event_value, "os_on"))
4984                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4985         else if (!strcmp(res->event_value, "os_off"))
4986                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4987         else if (!strcmp(res->event_value, "power_on"))
4988                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4989         else if (!strcmp(res->event_value, "power_off"))
4990                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4991         else
4992                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4993
4994         if (!strcmp(res->mode_value, "bypass"))
4995                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4996         else if (!strcmp(res->mode_value, "isolate"))
4997                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4998         else
4999                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5000
5001         /* Set the watchdog timeout. */
5002         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5003
5004                 rc = -EINVAL;
5005                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5006                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5007                                                            bypass_timeout);
5008                 }
5009                 if (rc != 0) {
5010                         printf("Failed to set timeout value %u "
5011                         "for port %d, errto code: %d.\n",
5012                         bypass_timeout, port_id, rc);
5013                 }
5014         }
5015
5016         /* Set the bypass event to transition to bypass mode. */
5017         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5018                                               bypass_mode);
5019 #endif
5020
5021         if (rc != 0)
5022                 printf("\t Failed to set bypass event for port = %d.\n",
5023                        port_id);
5024 }
5025
5026 cmdline_parse_token_string_t cmd_setbypass_event_set =
5027         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5028                         set, "set");
5029 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5030         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5031                         bypass, "bypass");
5032 cmdline_parse_token_string_t cmd_setbypass_event_event =
5033         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5034                         event, "event");
5035 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5036         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5037                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5038 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5039         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5040                         mode, "mode");
5041 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5042         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5043                         mode_value, "normal#bypass#isolate");
5044 cmdline_parse_token_num_t cmd_setbypass_event_port =
5045         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5046                                 port_id, UINT16);
5047
5048 cmdline_parse_inst_t cmd_set_bypass_event = {
5049         .f = cmd_set_bypass_event_parsed,
5050         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5051                 "power_off mode normal|bypass|isolate <port_id>: "
5052                 "Set the NIC bypass event mode for port_id",
5053         .data = NULL,
5054         .tokens = {
5055                 (void *)&cmd_setbypass_event_set,
5056                 (void *)&cmd_setbypass_event_bypass,
5057                 (void *)&cmd_setbypass_event_event,
5058                 (void *)&cmd_setbypass_event_event_value,
5059                 (void *)&cmd_setbypass_event_mode,
5060                 (void *)&cmd_setbypass_event_mode_value,
5061                 (void *)&cmd_setbypass_event_port,
5062                 NULL,
5063         },
5064 };
5065
5066
5067 /* *** SET NIC BYPASS TIMEOUT *** */
5068 struct cmd_set_bypass_timeout_result {
5069         cmdline_fixed_string_t set;
5070         cmdline_fixed_string_t bypass;
5071         cmdline_fixed_string_t timeout;
5072         cmdline_fixed_string_t value;
5073 };
5074
5075 static void
5076 cmd_set_bypass_timeout_parsed(void *parsed_result,
5077                 __attribute__((unused)) struct cmdline *cl,
5078                 __attribute__((unused)) void *data)
5079 {
5080         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5081
5082 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5083         if (!strcmp(res->value, "1.5"))
5084                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5085         else if (!strcmp(res->value, "2"))
5086                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5087         else if (!strcmp(res->value, "3"))
5088                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5089         else if (!strcmp(res->value, "4"))
5090                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5091         else if (!strcmp(res->value, "8"))
5092                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5093         else if (!strcmp(res->value, "16"))
5094                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5095         else if (!strcmp(res->value, "32"))
5096                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5097         else
5098                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5099 #endif
5100 }
5101
5102 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5103         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5104                         set, "set");
5105 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5106         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5107                         bypass, "bypass");
5108 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5109         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5110                         timeout, "timeout");
5111 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5112         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5113                         value, "0#1.5#2#3#4#8#16#32");
5114
5115 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5116         .f = cmd_set_bypass_timeout_parsed,
5117         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5118                 "Set the NIC bypass watchdog timeout in seconds",
5119         .data = NULL,
5120         .tokens = {
5121                 (void *)&cmd_setbypass_timeout_set,
5122                 (void *)&cmd_setbypass_timeout_bypass,
5123                 (void *)&cmd_setbypass_timeout_timeout,
5124                 (void *)&cmd_setbypass_timeout_value,
5125                 NULL,
5126         },
5127 };
5128
5129 /* *** SHOW NIC BYPASS MODE *** */
5130 struct cmd_show_bypass_config_result {
5131         cmdline_fixed_string_t show;
5132         cmdline_fixed_string_t bypass;
5133         cmdline_fixed_string_t config;
5134         portid_t port_id;
5135 };
5136
5137 static void
5138 cmd_show_bypass_config_parsed(void *parsed_result,
5139                 __attribute__((unused)) struct cmdline *cl,
5140                 __attribute__((unused)) void *data)
5141 {
5142         struct cmd_show_bypass_config_result *res = parsed_result;
5143         portid_t port_id = res->port_id;
5144         int rc = -EINVAL;
5145 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5146         uint32_t event_mode;
5147         uint32_t bypass_mode;
5148         uint32_t timeout = bypass_timeout;
5149         int i;
5150
5151         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5152                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5153         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5154                 {"UNKNOWN", "normal", "bypass", "isolate"};
5155         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5156                 "NONE",
5157                 "OS/board on",
5158                 "power supply on",
5159                 "OS/board off",
5160                 "power supply off",
5161                 "timeout"};
5162         int num_events = (sizeof events) / (sizeof events[0]);
5163
5164         /* Display the bypass mode.*/
5165         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5166                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5167                 return;
5168         }
5169         else {
5170                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5171                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5172
5173                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5174         }
5175
5176         /* Display the bypass timeout.*/
5177         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5178                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5179
5180         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5181
5182         /* Display the bypass events and associated modes. */
5183         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5184
5185                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5186                         printf("\tFailed to get bypass mode for event = %s\n",
5187                                 events[i]);
5188                 } else {
5189                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5190                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5191
5192                         printf("\tbypass event: %-16s = %s\n", events[i],
5193                                 modes[event_mode]);
5194                 }
5195         }
5196 #endif
5197         if (rc != 0)
5198                 printf("\tFailed to get bypass configuration for port = %d\n",
5199                        port_id);
5200 }
5201
5202 cmdline_parse_token_string_t cmd_showbypass_config_show =
5203         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5204                         show, "show");
5205 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5206         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5207                         bypass, "bypass");
5208 cmdline_parse_token_string_t cmd_showbypass_config_config =
5209         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5210                         config, "config");
5211 cmdline_parse_token_num_t cmd_showbypass_config_port =
5212         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5213                                 port_id, UINT16);
5214
5215 cmdline_parse_inst_t cmd_show_bypass_config = {
5216         .f = cmd_show_bypass_config_parsed,
5217         .help_str = "show bypass config <port_id>: "
5218                     "Show the NIC bypass config for port_id",
5219         .data = NULL,
5220         .tokens = {
5221                 (void *)&cmd_showbypass_config_show,
5222                 (void *)&cmd_showbypass_config_bypass,
5223                 (void *)&cmd_showbypass_config_config,
5224                 (void *)&cmd_showbypass_config_port,
5225                 NULL,
5226         },
5227 };
5228
5229 #ifdef RTE_LIBRTE_PMD_BOND
5230 /* *** SET BONDING MODE *** */
5231 struct cmd_set_bonding_mode_result {
5232         cmdline_fixed_string_t set;
5233         cmdline_fixed_string_t bonding;
5234         cmdline_fixed_string_t mode;
5235         uint8_t value;
5236         portid_t port_id;
5237 };
5238
5239 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5240                 __attribute__((unused))  struct cmdline *cl,
5241                 __attribute__((unused)) void *data)
5242 {
5243         struct cmd_set_bonding_mode_result *res = parsed_result;
5244         portid_t port_id = res->port_id;
5245
5246         /* Set the bonding mode for the relevant port. */
5247         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5248                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5249 }
5250
5251 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5252 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5253                 set, "set");
5254 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5255 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5256                 bonding, "bonding");
5257 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5258 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5259                 mode, "mode");
5260 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5261 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5262                 value, UINT8);
5263 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5264 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5265                 port_id, UINT16);
5266
5267 cmdline_parse_inst_t cmd_set_bonding_mode = {
5268                 .f = cmd_set_bonding_mode_parsed,
5269                 .help_str = "set bonding mode <mode_value> <port_id>: "
5270                         "Set the bonding mode for port_id",
5271                 .data = NULL,
5272                 .tokens = {
5273                                 (void *) &cmd_setbonding_mode_set,
5274                                 (void *) &cmd_setbonding_mode_bonding,
5275                                 (void *) &cmd_setbonding_mode_mode,
5276                                 (void *) &cmd_setbonding_mode_value,
5277                                 (void *) &cmd_setbonding_mode_port,
5278                                 NULL
5279                 }
5280 };
5281
5282 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5283 struct cmd_set_bonding_lacp_dedicated_queues_result {
5284         cmdline_fixed_string_t set;
5285         cmdline_fixed_string_t bonding;
5286         cmdline_fixed_string_t lacp;
5287         cmdline_fixed_string_t dedicated_queues;
5288         portid_t port_id;
5289         cmdline_fixed_string_t mode;
5290 };
5291
5292 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5293                 __attribute__((unused))  struct cmdline *cl,
5294                 __attribute__((unused)) void *data)
5295 {
5296         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5297         portid_t port_id = res->port_id;
5298         struct rte_port *port;
5299
5300         port = &ports[port_id];
5301
5302         /** Check if the port is not started **/
5303         if (port->port_status != RTE_PORT_STOPPED) {
5304                 printf("Please stop port %d first\n", port_id);
5305                 return;
5306         }
5307
5308         if (!strcmp(res->mode, "enable")) {
5309                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5310                         printf("Dedicate queues for LACP control packets"
5311                                         " enabled\n");
5312                 else
5313                         printf("Enabling dedicate queues for LACP control "
5314                                         "packets on port %d failed\n", port_id);
5315         } else if (!strcmp(res->mode, "disable")) {
5316                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5317                         printf("Dedicated queues for LACP control packets "
5318                                         "disabled\n");
5319                 else
5320                         printf("Disabling dedicated queues for LACP control "
5321                                         "traffic on port %d failed\n", port_id);
5322         }
5323 }
5324
5325 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5326 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5327                 set, "set");
5328 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5329 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5330                 bonding, "bonding");
5331 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5332 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5333                 lacp, "lacp");
5334 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5335 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5336                 dedicated_queues, "dedicated_queues");
5337 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5338 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5339                 port_id, UINT16);
5340 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5341 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5342                 mode, "enable#disable");
5343
5344 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5345                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5346                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5347                         "enable|disable: "
5348                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5349                 .data = NULL,
5350                 .tokens = {
5351                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5352                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5353                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5354                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5355                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5356                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5357                         NULL
5358                 }
5359 };
5360
5361 /* *** SET BALANCE XMIT POLICY *** */
5362 struct cmd_set_bonding_balance_xmit_policy_result {
5363         cmdline_fixed_string_t set;
5364         cmdline_fixed_string_t bonding;
5365         cmdline_fixed_string_t balance_xmit_policy;
5366         portid_t port_id;
5367         cmdline_fixed_string_t policy;
5368 };
5369
5370 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5371                 __attribute__((unused))  struct cmdline *cl,
5372                 __attribute__((unused)) void *data)
5373 {
5374         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5375         portid_t port_id = res->port_id;
5376         uint8_t policy;
5377
5378         if (!strcmp(res->policy, "l2")) {
5379                 policy = BALANCE_XMIT_POLICY_LAYER2;
5380         } else if (!strcmp(res->policy, "l23")) {
5381                 policy = BALANCE_XMIT_POLICY_LAYER23;
5382         } else if (!strcmp(res->policy, "l34")) {
5383                 policy = BALANCE_XMIT_POLICY_LAYER34;
5384         } else {
5385                 printf("\t Invalid xmit policy selection");
5386                 return;
5387         }
5388
5389         /* Set the bonding mode for the relevant port. */
5390         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5391                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5392                                 port_id);
5393         }
5394 }
5395
5396 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5397 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5398                 set, "set");
5399 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5400 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5401                 bonding, "bonding");
5402 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5403 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5404                 balance_xmit_policy, "balance_xmit_policy");
5405 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5406 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5407                 port_id, UINT16);
5408 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5409 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5410                 policy, "l2#l23#l34");
5411
5412 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5413                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5414                 .help_str = "set bonding balance_xmit_policy <port_id> "
5415                         "l2|l23|l34: "
5416                         "Set the bonding balance_xmit_policy for port_id",
5417                 .data = NULL,
5418                 .tokens = {
5419                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5420                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5421                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5422                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5423                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5424                                 NULL
5425                 }
5426 };
5427
5428 /* *** SHOW NIC BONDING CONFIGURATION *** */
5429 struct cmd_show_bonding_config_result {
5430         cmdline_fixed_string_t show;
5431         cmdline_fixed_string_t bonding;
5432         cmdline_fixed_string_t config;
5433         portid_t port_id;
5434 };
5435
5436 static void cmd_show_bonding_config_parsed(void *parsed_result,
5437                 __attribute__((unused))  struct cmdline *cl,
5438                 __attribute__((unused)) void *data)
5439 {
5440         struct cmd_show_bonding_config_result *res = parsed_result;
5441         int bonding_mode, agg_mode;
5442         portid_t slaves[RTE_MAX_ETHPORTS];
5443         int num_slaves, num_active_slaves;
5444         int primary_id;
5445         int i;
5446         portid_t port_id = res->port_id;
5447
5448         /* Display the bonding mode.*/
5449         bonding_mode = rte_eth_bond_mode_get(port_id);
5450         if (bonding_mode < 0) {
5451                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5452                 return;
5453         } else
5454                 printf("\tBonding mode: %d\n", bonding_mode);
5455
5456         if (bonding_mode == BONDING_MODE_BALANCE) {
5457                 int balance_xmit_policy;
5458
5459                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5460                 if (balance_xmit_policy < 0) {
5461                         printf("\tFailed to get balance xmit policy for port = %d\n",
5462                                         port_id);
5463                         return;
5464                 } else {
5465                         printf("\tBalance Xmit Policy: ");
5466
5467                         switch (balance_xmit_policy) {
5468                         case BALANCE_XMIT_POLICY_LAYER2:
5469                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5470                                 break;
5471                         case BALANCE_XMIT_POLICY_LAYER23:
5472                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5473                                 break;
5474                         case BALANCE_XMIT_POLICY_LAYER34:
5475                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5476                                 break;
5477                         }
5478                         printf("\n");
5479                 }
5480         }
5481
5482         if (bonding_mode == BONDING_MODE_8023AD) {
5483                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5484                 printf("\tIEEE802.3AD Aggregator Mode: ");
5485                 switch (agg_mode) {
5486                 case AGG_BANDWIDTH:
5487                         printf("bandwidth");
5488                         break;
5489                 case AGG_STABLE:
5490                         printf("stable");
5491                         break;
5492                 case AGG_COUNT:
5493                         printf("count");
5494                         break;
5495                 }
5496                 printf("\n");
5497         }
5498
5499         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5500
5501         if (num_slaves < 0) {
5502                 printf("\tFailed to get slave list for port = %d\n", port_id);
5503                 return;
5504         }
5505         if (num_slaves > 0) {
5506                 printf("\tSlaves (%d): [", num_slaves);
5507                 for (i = 0; i < num_slaves - 1; i++)
5508                         printf("%d ", slaves[i]);
5509
5510                 printf("%d]\n", slaves[num_slaves - 1]);
5511         } else {
5512                 printf("\tSlaves: []\n");
5513
5514         }
5515
5516         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5517                         RTE_MAX_ETHPORTS);
5518
5519         if (num_active_slaves < 0) {
5520                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5521                 return;
5522         }
5523         if (num_active_slaves > 0) {
5524                 printf("\tActive Slaves (%d): [", num_active_slaves);
5525                 for (i = 0; i < num_active_slaves - 1; i++)
5526                         printf("%d ", slaves[i]);
5527
5528                 printf("%d]\n", slaves[num_active_slaves - 1]);
5529
5530         } else {
5531                 printf("\tActive Slaves: []\n");
5532
5533         }
5534
5535         primary_id = rte_eth_bond_primary_get(port_id);
5536         if (primary_id < 0) {
5537                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5538                 return;
5539         } else
5540                 printf("\tPrimary: [%d]\n", primary_id);
5541
5542 }
5543
5544 cmdline_parse_token_string_t cmd_showbonding_config_show =
5545 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5546                 show, "show");
5547 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5548 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5549                 bonding, "bonding");
5550 cmdline_parse_token_string_t cmd_showbonding_config_config =
5551 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5552                 config, "config");
5553 cmdline_parse_token_num_t cmd_showbonding_config_port =
5554 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5555                 port_id, UINT16);
5556
5557 cmdline_parse_inst_t cmd_show_bonding_config = {
5558                 .f = cmd_show_bonding_config_parsed,
5559                 .help_str = "show bonding config <port_id>: "
5560                         "Show the bonding config for port_id",
5561                 .data = NULL,
5562                 .tokens = {
5563                                 (void *)&cmd_showbonding_config_show,
5564                                 (void *)&cmd_showbonding_config_bonding,
5565                                 (void *)&cmd_showbonding_config_config,
5566                                 (void *)&cmd_showbonding_config_port,
5567                                 NULL
5568                 }
5569 };
5570
5571 /* *** SET BONDING PRIMARY *** */
5572 struct cmd_set_bonding_primary_result {
5573         cmdline_fixed_string_t set;
5574         cmdline_fixed_string_t bonding;
5575         cmdline_fixed_string_t primary;
5576         portid_t slave_id;
5577         portid_t port_id;
5578 };
5579
5580 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5581                 __attribute__((unused))  struct cmdline *cl,
5582                 __attribute__((unused)) void *data)
5583 {
5584         struct cmd_set_bonding_primary_result *res = parsed_result;
5585         portid_t master_port_id = res->port_id;
5586         portid_t slave_port_id = res->slave_id;
5587
5588         /* Set the primary slave for a bonded device. */
5589         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5590                 printf("\t Failed to set primary slave for port = %d.\n",
5591                                 master_port_id);
5592                 return;
5593         }
5594         init_port_config();
5595 }
5596
5597 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5598 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5599                 set, "set");
5600 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5601 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5602                 bonding, "bonding");
5603 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5604 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5605                 primary, "primary");
5606 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5607 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5608                 slave_id, UINT16);
5609 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5610 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5611                 port_id, UINT16);
5612
5613 cmdline_parse_inst_t cmd_set_bonding_primary = {
5614                 .f = cmd_set_bonding_primary_parsed,
5615                 .help_str = "set bonding primary <slave_id> <port_id>: "
5616                         "Set the primary slave for port_id",
5617                 .data = NULL,
5618                 .tokens = {
5619                                 (void *)&cmd_setbonding_primary_set,
5620                                 (void *)&cmd_setbonding_primary_bonding,
5621                                 (void *)&cmd_setbonding_primary_primary,
5622                                 (void *)&cmd_setbonding_primary_slave,
5623                                 (void *)&cmd_setbonding_primary_port,
5624                                 NULL
5625                 }
5626 };
5627
5628 /* *** ADD SLAVE *** */
5629 struct cmd_add_bonding_slave_result {
5630         cmdline_fixed_string_t add;
5631         cmdline_fixed_string_t bonding;
5632         cmdline_fixed_string_t slave;
5633         portid_t slave_id;
5634         portid_t port_id;
5635 };
5636
5637 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5638                 __attribute__((unused))  struct cmdline *cl,
5639                 __attribute__((unused)) void *data)
5640 {
5641         struct cmd_add_bonding_slave_result *res = parsed_result;
5642         portid_t master_port_id = res->port_id;
5643         portid_t slave_port_id = res->slave_id;
5644
5645         /* add the slave for a bonded device. */
5646         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5647                 printf("\t Failed to add slave %d to master port = %d.\n",
5648                                 slave_port_id, master_port_id);
5649                 return;
5650         }
5651         init_port_config();
5652         set_port_slave_flag(slave_port_id);
5653 }
5654
5655 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5656 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5657                 add, "add");
5658 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5659 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5660                 bonding, "bonding");
5661 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5662 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5663                 slave, "slave");
5664 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5665 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5666                 slave_id, UINT16);
5667 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5668 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5669                 port_id, UINT16);
5670
5671 cmdline_parse_inst_t cmd_add_bonding_slave = {
5672                 .f = cmd_add_bonding_slave_parsed,
5673                 .help_str = "add bonding slave <slave_id> <port_id>: "
5674                         "Add a slave device to a bonded device",
5675                 .data = NULL,
5676                 .tokens = {
5677                                 (void *)&cmd_addbonding_slave_add,
5678                                 (void *)&cmd_addbonding_slave_bonding,
5679                                 (void *)&cmd_addbonding_slave_slave,
5680                                 (void *)&cmd_addbonding_slave_slaveid,
5681                                 (void *)&cmd_addbonding_slave_port,
5682                                 NULL
5683                 }
5684 };
5685
5686 /* *** REMOVE SLAVE *** */
5687 struct cmd_remove_bonding_slave_result {
5688         cmdline_fixed_string_t remove;
5689         cmdline_fixed_string_t bonding;
5690         cmdline_fixed_string_t slave;
5691         portid_t slave_id;
5692         portid_t port_id;
5693 };
5694
5695 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5696                 __attribute__((unused))  struct cmdline *cl,
5697                 __attribute__((unused)) void *data)
5698 {
5699         struct cmd_remove_bonding_slave_result *res = parsed_result;
5700         portid_t master_port_id = res->port_id;
5701         portid_t slave_port_id = res->slave_id;
5702
5703         /* remove the slave from a bonded device. */
5704         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5705                 printf("\t Failed to remove slave %d from master port = %d.\n",
5706                                 slave_port_id, master_port_id);
5707                 return;
5708         }
5709         init_port_config();
5710         clear_port_slave_flag(slave_port_id);
5711 }
5712
5713 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5714                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5715                                 remove, "remove");
5716 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5717                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5718                                 bonding, "bonding");
5719 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5720                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5721                                 slave, "slave");
5722 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5723                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5724                                 slave_id, UINT16);
5725 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5726                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5727                                 port_id, UINT16);
5728
5729 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5730                 .f = cmd_remove_bonding_slave_parsed,
5731                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5732                         "Remove a slave device from a bonded device",
5733                 .data = NULL,
5734                 .tokens = {
5735                                 (void *)&cmd_removebonding_slave_remove,
5736                                 (void *)&cmd_removebonding_slave_bonding,
5737                                 (void *)&cmd_removebonding_slave_slave,
5738                                 (void *)&cmd_removebonding_slave_slaveid,
5739                                 (void *)&cmd_removebonding_slave_port,
5740                                 NULL
5741                 }
5742 };
5743
5744 /* *** CREATE BONDED DEVICE *** */
5745 struct cmd_create_bonded_device_result {
5746         cmdline_fixed_string_t create;
5747         cmdline_fixed_string_t bonded;
5748         cmdline_fixed_string_t device;
5749         uint8_t mode;
5750         uint8_t socket;
5751 };
5752
5753 static int bond_dev_num = 0;
5754
5755 static void cmd_create_bonded_device_parsed(void *parsed_result,
5756                 __attribute__((unused))  struct cmdline *cl,
5757                 __attribute__((unused)) void *data)
5758 {
5759         struct cmd_create_bonded_device_result *res = parsed_result;
5760         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5761         int port_id;
5762
5763         if (test_done == 0) {
5764                 printf("Please stop forwarding first\n");
5765                 return;
5766         }
5767
5768         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5769                         bond_dev_num++);
5770
5771         /* Create a new bonded device. */
5772         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5773         if (port_id < 0) {
5774                 printf("\t Failed to create bonded device.\n");
5775                 return;
5776         } else {
5777                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5778                                 port_id);
5779
5780                 /* Update number of ports */
5781                 nb_ports = rte_eth_dev_count_avail();
5782                 reconfig(port_id, res->socket);
5783                 rte_eth_promiscuous_enable(port_id);
5784         }
5785
5786 }
5787
5788 cmdline_parse_token_string_t cmd_createbonded_device_create =
5789                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5790                                 create, "create");
5791 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5792                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5793                                 bonded, "bonded");
5794 cmdline_parse_token_string_t cmd_createbonded_device_device =
5795                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5796                                 device, "device");
5797 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5798                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5799                                 mode, UINT8);
5800 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5801                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5802                                 socket, UINT8);
5803
5804 cmdline_parse_inst_t cmd_create_bonded_device = {
5805                 .f = cmd_create_bonded_device_parsed,
5806                 .help_str = "create bonded device <mode> <socket>: "
5807                         "Create a new bonded device with specific bonding mode and socket",
5808                 .data = NULL,
5809                 .tokens = {
5810                                 (void *)&cmd_createbonded_device_create,
5811                                 (void *)&cmd_createbonded_device_bonded,
5812                                 (void *)&cmd_createbonded_device_device,
5813                                 (void *)&cmd_createbonded_device_mode,
5814                                 (void *)&cmd_createbonded_device_socket,
5815                                 NULL
5816                 }
5817 };
5818
5819 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5820 struct cmd_set_bond_mac_addr_result {
5821         cmdline_fixed_string_t set;
5822         cmdline_fixed_string_t bonding;
5823         cmdline_fixed_string_t mac_addr;
5824         uint16_t port_num;
5825         struct ether_addr address;
5826 };
5827
5828 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5829                 __attribute__((unused))  struct cmdline *cl,
5830                 __attribute__((unused)) void *data)
5831 {
5832         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5833         int ret;
5834
5835         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5836                 return;
5837
5838         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5839
5840         /* check the return value and print it if is < 0 */
5841         if (ret < 0)
5842                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5843 }
5844
5845 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5846                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5847 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5848                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5849                                 "bonding");
5850 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5851                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5852                                 "mac_addr");
5853 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5854                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5855                                 port_num, UINT16);
5856 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5857                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5858
5859 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5860                 .f = cmd_set_bond_mac_addr_parsed,
5861                 .data = (void *) 0,
5862                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5863                 .tokens = {
5864                                 (void *)&cmd_set_bond_mac_addr_set,
5865                                 (void *)&cmd_set_bond_mac_addr_bonding,
5866                                 (void *)&cmd_set_bond_mac_addr_mac,
5867                                 (void *)&cmd_set_bond_mac_addr_portnum,
5868                                 (void *)&cmd_set_bond_mac_addr_addr,
5869                                 NULL
5870                 }
5871 };
5872
5873
5874 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5875 struct cmd_set_bond_mon_period_result {
5876         cmdline_fixed_string_t set;
5877         cmdline_fixed_string_t bonding;
5878         cmdline_fixed_string_t mon_period;
5879         uint16_t port_num;
5880         uint32_t period_ms;
5881 };
5882
5883 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5884                 __attribute__((unused))  struct cmdline *cl,
5885                 __attribute__((unused)) void *data)
5886 {
5887         struct cmd_set_bond_mon_period_result *res = parsed_result;
5888         int ret;
5889
5890         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5891
5892         /* check the return value and print it if is < 0 */
5893         if (ret < 0)
5894                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5895 }
5896
5897 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5898                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5899                                 set, "set");
5900 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5901                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5902                                 bonding, "bonding");
5903 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5904                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5905                                 mon_period,     "mon_period");
5906 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5907                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5908                                 port_num, UINT16);
5909 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5910                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5911                                 period_ms, UINT32);
5912
5913 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5914                 .f = cmd_set_bond_mon_period_parsed,
5915                 .data = (void *) 0,
5916                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5917                 .tokens = {
5918                                 (void *)&cmd_set_bond_mon_period_set,
5919                                 (void *)&cmd_set_bond_mon_period_bonding,
5920                                 (void *)&cmd_set_bond_mon_period_mon_period,
5921                                 (void *)&cmd_set_bond_mon_period_portnum,
5922                                 (void *)&cmd_set_bond_mon_period_period_ms,
5923                                 NULL
5924                 }
5925 };
5926
5927
5928
5929 struct cmd_set_bonding_agg_mode_policy_result {
5930         cmdline_fixed_string_t set;
5931         cmdline_fixed_string_t bonding;
5932         cmdline_fixed_string_t agg_mode;
5933         uint16_t port_num;
5934         cmdline_fixed_string_t policy;
5935 };
5936
5937
5938 static void
5939 cmd_set_bonding_agg_mode(void *parsed_result,
5940                 __attribute__((unused)) struct cmdline *cl,
5941                 __attribute__((unused)) void *data)
5942 {
5943         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5944         uint8_t policy = AGG_BANDWIDTH;
5945
5946         if (!strcmp(res->policy, "bandwidth"))
5947                 policy = AGG_BANDWIDTH;
5948         else if (!strcmp(res->policy, "stable"))
5949                 policy = AGG_STABLE;
5950         else if (!strcmp(res->policy, "count"))
5951                 policy = AGG_COUNT;
5952
5953         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5954 }
5955
5956
5957 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5958         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5959                                 set, "set");
5960 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5961         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5962                                 bonding, "bonding");
5963
5964 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5965         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5966                                 agg_mode, "agg_mode");
5967
5968 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5969         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5970                                 port_num, UINT16);
5971
5972 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5973         TOKEN_STRING_INITIALIZER(
5974                         struct cmd_set_bonding_balance_xmit_policy_result,
5975                 policy, "stable#bandwidth#count");
5976
5977 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5978         .f = cmd_set_bonding_agg_mode,
5979         .data = (void *) 0,
5980         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5981         .tokens = {
5982                         (void *)&cmd_set_bonding_agg_mode_set,
5983                         (void *)&cmd_set_bonding_agg_mode_bonding,
5984                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5985                         (void *)&cmd_set_bonding_agg_mode_portnum,
5986                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5987                         NULL
5988                 }
5989 };
5990
5991
5992 #endif /* RTE_LIBRTE_PMD_BOND */
5993
5994 /* *** SET FORWARDING MODE *** */
5995 struct cmd_set_fwd_mode_result {
5996         cmdline_fixed_string_t set;
5997         cmdline_fixed_string_t fwd;
5998         cmdline_fixed_string_t mode;
5999 };
6000
6001 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6002                                     __attribute__((unused)) struct cmdline *cl,
6003                                     __attribute__((unused)) void *data)
6004 {
6005         struct cmd_set_fwd_mode_result *res = parsed_result;
6006
6007         retry_enabled = 0;
6008         set_pkt_forwarding_mode(res->mode);
6009 }
6010
6011 cmdline_parse_token_string_t cmd_setfwd_set =
6012         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6013 cmdline_parse_token_string_t cmd_setfwd_fwd =
6014         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6015 cmdline_parse_token_string_t cmd_setfwd_mode =
6016         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6017                 "" /* defined at init */);
6018
6019 cmdline_parse_inst_t cmd_set_fwd_mode = {
6020         .f = cmd_set_fwd_mode_parsed,
6021         .data = NULL,
6022         .help_str = NULL, /* defined at init */
6023         .tokens = {
6024                 (void *)&cmd_setfwd_set,
6025                 (void *)&cmd_setfwd_fwd,
6026                 (void *)&cmd_setfwd_mode,
6027                 NULL,
6028         },
6029 };
6030
6031 static void cmd_set_fwd_mode_init(void)
6032 {
6033         char *modes, *c;
6034         static char token[128];
6035         static char help[256];
6036         cmdline_parse_token_string_t *token_struct;
6037
6038         modes = list_pkt_forwarding_modes();
6039         snprintf(help, sizeof(help), "set fwd %s: "
6040                 "Set packet forwarding mode", modes);
6041         cmd_set_fwd_mode.help_str = help;
6042
6043         /* string token separator is # */
6044         for (c = token; *modes != '\0'; modes++)
6045                 if (*modes == '|')
6046                         *c++ = '#';
6047                 else
6048                         *c++ = *modes;
6049         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6050         token_struct->string_data.str = token;
6051 }
6052
6053 /* *** SET RETRY FORWARDING MODE *** */
6054 struct cmd_set_fwd_retry_mode_result {
6055         cmdline_fixed_string_t set;
6056         cmdline_fixed_string_t fwd;
6057         cmdline_fixed_string_t mode;
6058         cmdline_fixed_string_t retry;
6059 };
6060
6061 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6062                             __attribute__((unused)) struct cmdline *cl,
6063                             __attribute__((unused)) void *data)
6064 {
6065         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6066
6067         retry_enabled = 1;
6068         set_pkt_forwarding_mode(res->mode);
6069 }
6070
6071 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6072         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6073                         set, "set");
6074 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6075         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6076                         fwd, "fwd");
6077 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6078         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6079                         mode,
6080                 "" /* defined at init */);
6081 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6082         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6083                         retry, "retry");
6084
6085 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6086         .f = cmd_set_fwd_retry_mode_parsed,
6087         .data = NULL,
6088         .help_str = NULL, /* defined at init */
6089         .tokens = {
6090                 (void *)&cmd_setfwd_retry_set,
6091                 (void *)&cmd_setfwd_retry_fwd,
6092                 (void *)&cmd_setfwd_retry_mode,
6093                 (void *)&cmd_setfwd_retry_retry,
6094                 NULL,
6095         },
6096 };
6097
6098 static void cmd_set_fwd_retry_mode_init(void)
6099 {
6100         char *modes, *c;
6101         static char token[128];
6102         static char help[256];
6103         cmdline_parse_token_string_t *token_struct;
6104
6105         modes = list_pkt_forwarding_retry_modes();
6106         snprintf(help, sizeof(help), "set fwd %s retry: "
6107                 "Set packet forwarding mode with retry", modes);
6108         cmd_set_fwd_retry_mode.help_str = help;
6109
6110         /* string token separator is # */
6111         for (c = token; *modes != '\0'; modes++)
6112                 if (*modes == '|')
6113                         *c++ = '#';
6114                 else
6115                         *c++ = *modes;
6116         token_struct = (cmdline_parse_token_string_t *)
6117                 cmd_set_fwd_retry_mode.tokens[2];
6118         token_struct->string_data.str = token;
6119 }
6120
6121 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6122 struct cmd_set_burst_tx_retry_result {
6123         cmdline_fixed_string_t set;
6124         cmdline_fixed_string_t burst;
6125         cmdline_fixed_string_t tx;
6126         cmdline_fixed_string_t delay;
6127         uint32_t time;
6128         cmdline_fixed_string_t retry;
6129         uint32_t retry_num;
6130 };
6131
6132 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6133                                         __attribute__((unused)) struct cmdline *cl,
6134                                         __attribute__((unused)) void *data)
6135 {
6136         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6137
6138         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6139                 && !strcmp(res->tx, "tx")) {
6140                 if (!strcmp(res->delay, "delay"))
6141                         burst_tx_delay_time = res->time;
6142                 if (!strcmp(res->retry, "retry"))
6143                         burst_tx_retry_num = res->retry_num;
6144         }
6145
6146 }
6147
6148 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6149         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6150 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6151         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6152                                  "burst");
6153 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6154         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6155 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6156         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6157 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6158         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6159 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6160         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6161 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6162         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6163
6164 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6165         .f = cmd_set_burst_tx_retry_parsed,
6166         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6167         .tokens = {
6168                 (void *)&cmd_set_burst_tx_retry_set,
6169                 (void *)&cmd_set_burst_tx_retry_burst,
6170                 (void *)&cmd_set_burst_tx_retry_tx,
6171                 (void *)&cmd_set_burst_tx_retry_delay,
6172                 (void *)&cmd_set_burst_tx_retry_time,
6173                 (void *)&cmd_set_burst_tx_retry_retry,
6174                 (void *)&cmd_set_burst_tx_retry_retry_num,
6175                 NULL,
6176         },
6177 };
6178
6179 /* *** SET PROMISC MODE *** */
6180 struct cmd_set_promisc_mode_result {
6181         cmdline_fixed_string_t set;
6182         cmdline_fixed_string_t promisc;
6183         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6184         uint16_t port_num;               /* valid if "allports" argument == 0 */
6185         cmdline_fixed_string_t mode;
6186 };
6187
6188 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6189                                         __attribute__((unused)) struct cmdline *cl,
6190                                         void *allports)
6191 {
6192         struct cmd_set_promisc_mode_result *res = parsed_result;
6193         int enable;
6194         portid_t i;
6195
6196         if (!strcmp(res->mode, "on"))
6197                 enable = 1;
6198         else
6199                 enable = 0;
6200
6201         /* all ports */
6202         if (allports) {
6203                 RTE_ETH_FOREACH_DEV(i) {
6204                         if (enable)
6205                                 rte_eth_promiscuous_enable(i);
6206                         else
6207                                 rte_eth_promiscuous_disable(i);
6208                 }
6209         }
6210         else {
6211                 if (enable)
6212                         rte_eth_promiscuous_enable(res->port_num);
6213                 else
6214                         rte_eth_promiscuous_disable(res->port_num);
6215         }
6216 }
6217
6218 cmdline_parse_token_string_t cmd_setpromisc_set =
6219         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6220 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6221         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6222                                  "promisc");
6223 cmdline_parse_token_string_t cmd_setpromisc_portall =
6224         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6225                                  "all");
6226 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6227         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6228                               UINT16);
6229 cmdline_parse_token_string_t cmd_setpromisc_mode =
6230         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6231                                  "on#off");
6232
6233 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6234         .f = cmd_set_promisc_mode_parsed,
6235         .data = (void *)1,
6236         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6237         .tokens = {
6238                 (void *)&cmd_setpromisc_set,
6239                 (void *)&cmd_setpromisc_promisc,
6240                 (void *)&cmd_setpromisc_portall,
6241                 (void *)&cmd_setpromisc_mode,
6242                 NULL,
6243         },
6244 };
6245
6246 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6247         .f = cmd_set_promisc_mode_parsed,
6248         .data = (void *)0,
6249         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6250         .tokens = {
6251                 (void *)&cmd_setpromisc_set,
6252                 (void *)&cmd_setpromisc_promisc,
6253                 (void *)&cmd_setpromisc_portnum,
6254                 (void *)&cmd_setpromisc_mode,
6255                 NULL,
6256         },
6257 };
6258
6259 /* *** SET ALLMULTI MODE *** */
6260 struct cmd_set_allmulti_mode_result {
6261         cmdline_fixed_string_t set;
6262         cmdline_fixed_string_t allmulti;
6263         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6264         uint16_t port_num;               /* valid if "allports" argument == 0 */
6265         cmdline_fixed_string_t mode;
6266 };
6267
6268 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6269                                         __attribute__((unused)) struct cmdline *cl,
6270                                         void *allports)
6271 {
6272         struct cmd_set_allmulti_mode_result *res = parsed_result;
6273         int enable;
6274         portid_t i;
6275
6276         if (!strcmp(res->mode, "on"))
6277                 enable = 1;
6278         else
6279                 enable = 0;
6280
6281         /* all ports */
6282         if (allports) {
6283                 RTE_ETH_FOREACH_DEV(i) {
6284                         if (enable)
6285                                 rte_eth_allmulticast_enable(i);
6286                         else
6287                                 rte_eth_allmulticast_disable(i);
6288                 }
6289         }
6290         else {
6291                 if (enable)
6292                         rte_eth_allmulticast_enable(res->port_num);
6293                 else
6294                         rte_eth_allmulticast_disable(res->port_num);
6295         }
6296 }
6297
6298 cmdline_parse_token_string_t cmd_setallmulti_set =
6299         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6300 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6301         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6302                                  "allmulti");
6303 cmdline_parse_token_string_t cmd_setallmulti_portall =
6304         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6305                                  "all");
6306 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6307         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6308                               UINT16);
6309 cmdline_parse_token_string_t cmd_setallmulti_mode =
6310         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6311                                  "on#off");
6312
6313 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6314         .f = cmd_set_allmulti_mode_parsed,
6315         .data = (void *)1,
6316         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6317         .tokens = {
6318                 (void *)&cmd_setallmulti_set,
6319                 (void *)&cmd_setallmulti_allmulti,
6320                 (void *)&cmd_setallmulti_portall,
6321                 (void *)&cmd_setallmulti_mode,
6322                 NULL,
6323         },
6324 };
6325
6326 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6327         .f = cmd_set_allmulti_mode_parsed,
6328         .data = (void *)0,
6329         .help_str = "set allmulti <port_id> on|off: "
6330                 "Set allmulti mode on port_id",
6331         .tokens = {
6332                 (void *)&cmd_setallmulti_set,
6333                 (void *)&cmd_setallmulti_allmulti,
6334                 (void *)&cmd_setallmulti_portnum,
6335                 (void *)&cmd_setallmulti_mode,
6336                 NULL,
6337         },
6338 };
6339
6340 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6341 struct cmd_link_flow_ctrl_set_result {
6342         cmdline_fixed_string_t set;
6343         cmdline_fixed_string_t flow_ctrl;
6344         cmdline_fixed_string_t rx;
6345         cmdline_fixed_string_t rx_lfc_mode;
6346         cmdline_fixed_string_t tx;
6347         cmdline_fixed_string_t tx_lfc_mode;
6348         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6349         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6350         cmdline_fixed_string_t autoneg_str;
6351         cmdline_fixed_string_t autoneg;
6352         cmdline_fixed_string_t hw_str;
6353         uint32_t high_water;
6354         cmdline_fixed_string_t lw_str;
6355         uint32_t low_water;
6356         cmdline_fixed_string_t pt_str;
6357         uint16_t pause_time;
6358         cmdline_fixed_string_t xon_str;
6359         uint16_t send_xon;
6360         portid_t port_id;
6361 };
6362
6363 cmdline_parse_token_string_t cmd_lfc_set_set =
6364         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6365                                 set, "set");
6366 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6367         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6368                                 flow_ctrl, "flow_ctrl");
6369 cmdline_parse_token_string_t cmd_lfc_set_rx =
6370         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6371                                 rx, "rx");
6372 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6373         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6374                                 rx_lfc_mode, "on#off");
6375 cmdline_parse_token_string_t cmd_lfc_set_tx =
6376         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6377                                 tx, "tx");
6378 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6379         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6380                                 tx_lfc_mode, "on#off");
6381 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6382         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6383                                 hw_str, "high_water");
6384 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6385         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6386                                 high_water, UINT32);
6387 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6388         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6389                                 lw_str, "low_water");
6390 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6391         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6392                                 low_water, UINT32);
6393 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6394         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6395                                 pt_str, "pause_time");
6396 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6397         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6398                                 pause_time, UINT16);
6399 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6400         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6401                                 xon_str, "send_xon");
6402 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6403         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6404                                 send_xon, UINT16);
6405 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6406         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6407                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6408 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6409         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6410                                 mac_ctrl_frame_fwd_mode, "on#off");
6411 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6412         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6413                                 autoneg_str, "autoneg");
6414 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6415         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6416                                 autoneg, "on#off");
6417 cmdline_parse_token_num_t cmd_lfc_set_portid =
6418         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6419                                 port_id, UINT16);
6420
6421 /* forward declaration */
6422 static void
6423 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6424                               void *data);
6425
6426 cmdline_parse_inst_t cmd_link_flow_control_set = {
6427         .f = cmd_link_flow_ctrl_set_parsed,
6428         .data = NULL,
6429         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6430                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6431                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6432         .tokens = {
6433                 (void *)&cmd_lfc_set_set,
6434                 (void *)&cmd_lfc_set_flow_ctrl,
6435                 (void *)&cmd_lfc_set_rx,
6436                 (void *)&cmd_lfc_set_rx_mode,
6437                 (void *)&cmd_lfc_set_tx,
6438                 (void *)&cmd_lfc_set_tx_mode,
6439                 (void *)&cmd_lfc_set_high_water,
6440                 (void *)&cmd_lfc_set_low_water,
6441                 (void *)&cmd_lfc_set_pause_time,
6442                 (void *)&cmd_lfc_set_send_xon,
6443                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6444                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6445                 (void *)&cmd_lfc_set_autoneg_str,
6446                 (void *)&cmd_lfc_set_autoneg,
6447                 (void *)&cmd_lfc_set_portid,
6448                 NULL,
6449         },
6450 };
6451
6452 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6453         .f = cmd_link_flow_ctrl_set_parsed,
6454         .data = (void *)&cmd_link_flow_control_set_rx,
6455         .help_str = "set flow_ctrl rx on|off <port_id>: "
6456                 "Change rx flow control parameter",
6457         .tokens = {
6458                 (void *)&cmd_lfc_set_set,
6459                 (void *)&cmd_lfc_set_flow_ctrl,
6460                 (void *)&cmd_lfc_set_rx,
6461                 (void *)&cmd_lfc_set_rx_mode,
6462                 (void *)&cmd_lfc_set_portid,
6463                 NULL,
6464         },
6465 };
6466
6467 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6468         .f = cmd_link_flow_ctrl_set_parsed,
6469         .data = (void *)&cmd_link_flow_control_set_tx,
6470         .help_str = "set flow_ctrl tx on|off <port_id>: "
6471                 "Change tx flow control parameter",
6472         .tokens = {
6473                 (void *)&cmd_lfc_set_set,
6474                 (void *)&cmd_lfc_set_flow_ctrl,
6475                 (void *)&cmd_lfc_set_tx,
6476                 (void *)&cmd_lfc_set_tx_mode,
6477                 (void *)&cmd_lfc_set_portid,
6478                 NULL,
6479         },
6480 };
6481
6482 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6483         .f = cmd_link_flow_ctrl_set_parsed,
6484         .data = (void *)&cmd_link_flow_control_set_hw,
6485         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6486                 "Change high water flow control parameter",
6487         .tokens = {
6488                 (void *)&cmd_lfc_set_set,
6489                 (void *)&cmd_lfc_set_flow_ctrl,
6490                 (void *)&cmd_lfc_set_high_water_str,
6491                 (void *)&cmd_lfc_set_high_water,
6492                 (void *)&cmd_lfc_set_portid,
6493                 NULL,
6494         },
6495 };
6496
6497 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6498         .f = cmd_link_flow_ctrl_set_parsed,
6499         .data = (void *)&cmd_link_flow_control_set_lw,
6500         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6501                 "Change low water flow control parameter",
6502         .tokens = {
6503                 (void *)&cmd_lfc_set_set,
6504                 (void *)&cmd_lfc_set_flow_ctrl,
6505                 (void *)&cmd_lfc_set_low_water_str,
6506                 (void *)&cmd_lfc_set_low_water,
6507                 (void *)&cmd_lfc_set_portid,
6508                 NULL,
6509         },
6510 };
6511
6512 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6513         .f = cmd_link_flow_ctrl_set_parsed,
6514         .data = (void *)&cmd_link_flow_control_set_pt,
6515         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6516                 "Change pause time flow control parameter",
6517         .tokens = {
6518                 (void *)&cmd_lfc_set_set,
6519                 (void *)&cmd_lfc_set_flow_ctrl,
6520                 (void *)&cmd_lfc_set_pause_time_str,
6521                 (void *)&cmd_lfc_set_pause_time,
6522                 (void *)&cmd_lfc_set_portid,
6523                 NULL,
6524         },
6525 };
6526
6527 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6528         .f = cmd_link_flow_ctrl_set_parsed,
6529         .data = (void *)&cmd_link_flow_control_set_xon,
6530         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6531                 "Change send_xon flow control parameter",
6532         .tokens = {
6533                 (void *)&cmd_lfc_set_set,
6534                 (void *)&cmd_lfc_set_flow_ctrl,
6535                 (void *)&cmd_lfc_set_send_xon_str,
6536                 (void *)&cmd_lfc_set_send_xon,
6537                 (void *)&cmd_lfc_set_portid,
6538                 NULL,
6539         },
6540 };
6541
6542 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6543         .f = cmd_link_flow_ctrl_set_parsed,
6544         .data = (void *)&cmd_link_flow_control_set_macfwd,
6545         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6546                 "Change mac ctrl fwd flow control parameter",
6547         .tokens = {
6548                 (void *)&cmd_lfc_set_set,
6549                 (void *)&cmd_lfc_set_flow_ctrl,
6550                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6551                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6552                 (void *)&cmd_lfc_set_portid,
6553                 NULL,
6554         },
6555 };
6556
6557 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6558         .f = cmd_link_flow_ctrl_set_parsed,
6559         .data = (void *)&cmd_link_flow_control_set_autoneg,
6560         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6561                 "Change autoneg flow control parameter",
6562         .tokens = {
6563                 (void *)&cmd_lfc_set_set,
6564                 (void *)&cmd_lfc_set_flow_ctrl,
6565                 (void *)&cmd_lfc_set_autoneg_str,
6566                 (void *)&cmd_lfc_set_autoneg,
6567                 (void *)&cmd_lfc_set_portid,
6568                 NULL,
6569         },
6570 };
6571
6572 static void
6573 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6574                               __attribute__((unused)) struct cmdline *cl,
6575                               void *data)
6576 {
6577         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6578         cmdline_parse_inst_t *cmd = data;
6579         struct rte_eth_fc_conf fc_conf;
6580         int rx_fc_en = 0;
6581         int tx_fc_en = 0;
6582         int ret;
6583
6584         /*
6585          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6586          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6587          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6588          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6589          */
6590         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6591                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6592         };
6593
6594         /* Partial command line, retrieve current configuration */
6595         if (cmd) {
6596                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6597                 if (ret != 0) {
6598                         printf("cannot get current flow ctrl parameters, return"
6599                                "code = %d\n", ret);
6600                         return;
6601                 }
6602
6603                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6604                     (fc_conf.mode == RTE_FC_FULL))
6605                         rx_fc_en = 1;
6606                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6607                     (fc_conf.mode == RTE_FC_FULL))
6608                         tx_fc_en = 1;
6609         }
6610
6611         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6612                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6613
6614         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6615                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6616
6617         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6618
6619         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6620                 fc_conf.high_water = res->high_water;
6621
6622         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6623                 fc_conf.low_water = res->low_water;
6624
6625         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6626                 fc_conf.pause_time = res->pause_time;
6627
6628         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6629                 fc_conf.send_xon = res->send_xon;
6630
6631         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6632                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6633                         fc_conf.mac_ctrl_frame_fwd = 1;
6634                 else
6635                         fc_conf.mac_ctrl_frame_fwd = 0;
6636         }
6637
6638         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6639                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6640
6641         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6642         if (ret != 0)
6643                 printf("bad flow contrl parameter, return code = %d \n", ret);
6644 }
6645
6646 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6647 struct cmd_priority_flow_ctrl_set_result {
6648         cmdline_fixed_string_t set;
6649         cmdline_fixed_string_t pfc_ctrl;
6650         cmdline_fixed_string_t rx;
6651         cmdline_fixed_string_t rx_pfc_mode;
6652         cmdline_fixed_string_t tx;
6653         cmdline_fixed_string_t tx_pfc_mode;
6654         uint32_t high_water;
6655         uint32_t low_water;
6656         uint16_t pause_time;
6657         uint8_t  priority;
6658         portid_t port_id;
6659 };
6660
6661 static void
6662 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6663                        __attribute__((unused)) struct cmdline *cl,
6664                        __attribute__((unused)) void *data)
6665 {
6666         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6667         struct rte_eth_pfc_conf pfc_conf;
6668         int rx_fc_enable, tx_fc_enable;
6669         int ret;
6670
6671         /*
6672          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6673          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6674          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6675          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6676          */
6677         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6678                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6679         };
6680
6681         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6682         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6683         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6684         pfc_conf.fc.high_water = res->high_water;
6685         pfc_conf.fc.low_water  = res->low_water;
6686         pfc_conf.fc.pause_time = res->pause_time;
6687         pfc_conf.priority      = res->priority;
6688
6689         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6690         if (ret != 0)
6691                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6692 }
6693
6694 cmdline_parse_token_string_t cmd_pfc_set_set =
6695         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6696                                 set, "set");
6697 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6698         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6699                                 pfc_ctrl, "pfc_ctrl");
6700 cmdline_parse_token_string_t cmd_pfc_set_rx =
6701         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6702                                 rx, "rx");
6703 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6704         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6705                                 rx_pfc_mode, "on#off");
6706 cmdline_parse_token_string_t cmd_pfc_set_tx =
6707         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6708                                 tx, "tx");
6709 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6710         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6711                                 tx_pfc_mode, "on#off");
6712 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6713         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6714                                 high_water, UINT32);
6715 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6716         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6717                                 low_water, UINT32);
6718 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6719         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6720                                 pause_time, UINT16);
6721 cmdline_parse_token_num_t cmd_pfc_set_priority =
6722         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6723                                 priority, UINT8);
6724 cmdline_parse_token_num_t cmd_pfc_set_portid =
6725         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6726                                 port_id, UINT16);
6727
6728 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6729         .f = cmd_priority_flow_ctrl_set_parsed,
6730         .data = NULL,
6731         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6732                 "<pause_time> <priority> <port_id>: "
6733                 "Configure the Ethernet priority flow control",
6734         .tokens = {
6735                 (void *)&cmd_pfc_set_set,
6736                 (void *)&cmd_pfc_set_flow_ctrl,
6737                 (void *)&cmd_pfc_set_rx,
6738                 (void *)&cmd_pfc_set_rx_mode,
6739                 (void *)&cmd_pfc_set_tx,
6740                 (void *)&cmd_pfc_set_tx_mode,
6741                 (void *)&cmd_pfc_set_high_water,
6742                 (void *)&cmd_pfc_set_low_water,
6743                 (void *)&cmd_pfc_set_pause_time,
6744                 (void *)&cmd_pfc_set_priority,
6745                 (void *)&cmd_pfc_set_portid,
6746                 NULL,
6747         },
6748 };
6749
6750 /* *** RESET CONFIGURATION *** */
6751 struct cmd_reset_result {
6752         cmdline_fixed_string_t reset;
6753         cmdline_fixed_string_t def;
6754 };
6755
6756 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6757                              struct cmdline *cl,
6758                              __attribute__((unused)) void *data)
6759 {
6760         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6761         set_def_fwd_config();
6762 }
6763
6764 cmdline_parse_token_string_t cmd_reset_set =
6765         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6766 cmdline_parse_token_string_t cmd_reset_def =
6767         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6768                                  "default");
6769
6770 cmdline_parse_inst_t cmd_reset = {
6771         .f = cmd_reset_parsed,
6772         .data = NULL,
6773         .help_str = "set default: Reset default forwarding configuration",
6774         .tokens = {
6775                 (void *)&cmd_reset_set,
6776                 (void *)&cmd_reset_def,
6777                 NULL,
6778         },
6779 };
6780
6781 /* *** START FORWARDING *** */
6782 struct cmd_start_result {
6783         cmdline_fixed_string_t start;
6784 };
6785
6786 cmdline_parse_token_string_t cmd_start_start =
6787         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6788
6789 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6790                              __attribute__((unused)) struct cmdline *cl,
6791                              __attribute__((unused)) void *data)
6792 {
6793         start_packet_forwarding(0);
6794 }
6795
6796 cmdline_parse_inst_t cmd_start = {
6797         .f = cmd_start_parsed,
6798         .data = NULL,
6799         .help_str = "start: Start packet forwarding",
6800         .tokens = {
6801                 (void *)&cmd_start_start,
6802                 NULL,
6803         },
6804 };
6805
6806 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6807 struct cmd_start_tx_first_result {
6808         cmdline_fixed_string_t start;
6809         cmdline_fixed_string_t tx_first;
6810 };
6811
6812 static void
6813 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6814                           __attribute__((unused)) struct cmdline *cl,
6815                           __attribute__((unused)) void *data)
6816 {
6817         start_packet_forwarding(1);
6818 }
6819
6820 cmdline_parse_token_string_t cmd_start_tx_first_start =
6821         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6822                                  "start");
6823 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6824         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6825                                  tx_first, "tx_first");
6826
6827 cmdline_parse_inst_t cmd_start_tx_first = {
6828         .f = cmd_start_tx_first_parsed,
6829         .data = NULL,
6830         .help_str = "start tx_first: Start packet forwarding, "
6831                 "after sending 1 burst of packets",
6832         .tokens = {
6833                 (void *)&cmd_start_tx_first_start,
6834                 (void *)&cmd_start_tx_first_tx_first,
6835                 NULL,
6836         },
6837 };
6838
6839 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6840 struct cmd_start_tx_first_n_result {
6841         cmdline_fixed_string_t start;
6842         cmdline_fixed_string_t tx_first;
6843         uint32_t tx_num;
6844 };
6845
6846 static void
6847 cmd_start_tx_first_n_parsed(void *parsed_result,
6848                           __attribute__((unused)) struct cmdline *cl,
6849                           __attribute__((unused)) void *data)
6850 {
6851         struct cmd_start_tx_first_n_result *res = parsed_result;
6852
6853         start_packet_forwarding(res->tx_num);
6854 }
6855
6856 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6857         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6858                         start, "start");
6859 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6860         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6861                         tx_first, "tx_first");
6862 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6863         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6864                         tx_num, UINT32);
6865
6866 cmdline_parse_inst_t cmd_start_tx_first_n = {
6867         .f = cmd_start_tx_first_n_parsed,
6868         .data = NULL,
6869         .help_str = "start tx_first <num>: "
6870                 "packet forwarding, after sending <num> bursts of packets",
6871         .tokens = {
6872                 (void *)&cmd_start_tx_first_n_start,
6873                 (void *)&cmd_start_tx_first_n_tx_first,
6874                 (void *)&cmd_start_tx_first_n_tx_num,
6875                 NULL,
6876         },
6877 };
6878
6879 /* *** SET LINK UP *** */
6880 struct cmd_set_link_up_result {
6881         cmdline_fixed_string_t set;
6882         cmdline_fixed_string_t link_up;
6883         cmdline_fixed_string_t port;
6884         portid_t port_id;
6885 };
6886
6887 cmdline_parse_token_string_t cmd_set_link_up_set =
6888         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6889 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6890         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6891                                 "link-up");
6892 cmdline_parse_token_string_t cmd_set_link_up_port =
6893         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6894 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6895         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6896
6897 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6898                              __attribute__((unused)) struct cmdline *cl,
6899                              __attribute__((unused)) void *data)
6900 {
6901         struct cmd_set_link_up_result *res = parsed_result;
6902         dev_set_link_up(res->port_id);
6903 }
6904
6905 cmdline_parse_inst_t cmd_set_link_up = {
6906         .f = cmd_set_link_up_parsed,
6907         .data = NULL,
6908         .help_str = "set link-up port <port id>",
6909         .tokens = {
6910                 (void *)&cmd_set_link_up_set,
6911                 (void *)&cmd_set_link_up_link_up,
6912                 (void *)&cmd_set_link_up_port,
6913                 (void *)&cmd_set_link_up_port_id,
6914                 NULL,
6915         },
6916 };
6917
6918 /* *** SET LINK DOWN *** */
6919 struct cmd_set_link_down_result {
6920         cmdline_fixed_string_t set;
6921         cmdline_fixed_string_t link_down;
6922         cmdline_fixed_string_t port;
6923         portid_t port_id;
6924 };
6925
6926 cmdline_parse_token_string_t cmd_set_link_down_set =
6927         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6928 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6929         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6930                                 "link-down");
6931 cmdline_parse_token_string_t cmd_set_link_down_port =
6932         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6933 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6934         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6935
6936 static void cmd_set_link_down_parsed(
6937                                 __attribute__((unused)) void *parsed_result,
6938                                 __attribute__((unused)) struct cmdline *cl,
6939                                 __attribute__((unused)) void *data)
6940 {
6941         struct cmd_set_link_down_result *res = parsed_result;
6942         dev_set_link_down(res->port_id);
6943 }
6944
6945 cmdline_parse_inst_t cmd_set_link_down = {
6946         .f = cmd_set_link_down_parsed,
6947         .data = NULL,
6948         .help_str = "set link-down port <port id>",
6949         .tokens = {
6950                 (void *)&cmd_set_link_down_set,
6951                 (void *)&cmd_set_link_down_link_down,
6952                 (void *)&cmd_set_link_down_port,
6953                 (void *)&cmd_set_link_down_port_id,
6954                 NULL,
6955         },
6956 };
6957
6958 /* *** SHOW CFG *** */
6959 struct cmd_showcfg_result {
6960         cmdline_fixed_string_t show;
6961         cmdline_fixed_string_t cfg;
6962         cmdline_fixed_string_t what;
6963 };
6964
6965 static void cmd_showcfg_parsed(void *parsed_result,
6966                                __attribute__((unused)) struct cmdline *cl,
6967                                __attribute__((unused)) void *data)
6968 {
6969         struct cmd_showcfg_result *res = parsed_result;
6970         if (!strcmp(res->what, "rxtx"))
6971                 rxtx_config_display();
6972         else if (!strcmp(res->what, "cores"))
6973                 fwd_lcores_config_display();
6974         else if (!strcmp(res->what, "fwd"))
6975                 pkt_fwd_config_display(&cur_fwd_config);
6976         else if (!strcmp(res->what, "txpkts"))
6977                 show_tx_pkt_segments();
6978 }
6979
6980 cmdline_parse_token_string_t cmd_showcfg_show =
6981         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6982 cmdline_parse_token_string_t cmd_showcfg_port =
6983         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6984 cmdline_parse_token_string_t cmd_showcfg_what =
6985         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6986                                  "rxtx#cores#fwd#txpkts");
6987
6988 cmdline_parse_inst_t cmd_showcfg = {
6989         .f = cmd_showcfg_parsed,
6990         .data = NULL,
6991         .help_str = "show config rxtx|cores|fwd|txpkts",
6992         .tokens = {
6993                 (void *)&cmd_showcfg_show,
6994                 (void *)&cmd_showcfg_port,
6995                 (void *)&cmd_showcfg_what,
6996                 NULL,
6997         },
6998 };
6999
7000 /* *** SHOW ALL PORT INFO *** */
7001 struct cmd_showportall_result {
7002         cmdline_fixed_string_t show;
7003         cmdline_fixed_string_t port;
7004         cmdline_fixed_string_t what;
7005         cmdline_fixed_string_t all;
7006 };
7007
7008 static void cmd_showportall_parsed(void *parsed_result,
7009                                 __attribute__((unused)) struct cmdline *cl,
7010                                 __attribute__((unused)) void *data)
7011 {
7012         portid_t i;
7013
7014         struct cmd_showportall_result *res = parsed_result;
7015         if (!strcmp(res->show, "clear")) {
7016                 if (!strcmp(res->what, "stats"))
7017                         RTE_ETH_FOREACH_DEV(i)
7018                                 nic_stats_clear(i);
7019                 else if (!strcmp(res->what, "xstats"))
7020                         RTE_ETH_FOREACH_DEV(i)
7021                                 nic_xstats_clear(i);
7022         } else if (!strcmp(res->what, "info"))
7023                 RTE_ETH_FOREACH_DEV(i)
7024                         port_infos_display(i);
7025         else if (!strcmp(res->what, "stats"))
7026                 RTE_ETH_FOREACH_DEV(i)
7027                         nic_stats_display(i);
7028         else if (!strcmp(res->what, "xstats"))
7029                 RTE_ETH_FOREACH_DEV(i)
7030                         nic_xstats_display(i);
7031         else if (!strcmp(res->what, "fdir"))
7032                 RTE_ETH_FOREACH_DEV(i)
7033                         fdir_get_infos(i);
7034         else if (!strcmp(res->what, "stat_qmap"))
7035                 RTE_ETH_FOREACH_DEV(i)
7036                         nic_stats_mapping_display(i);
7037         else if (!strcmp(res->what, "dcb_tc"))
7038                 RTE_ETH_FOREACH_DEV(i)
7039                         port_dcb_info_display(i);
7040         else if (!strcmp(res->what, "cap"))
7041                 RTE_ETH_FOREACH_DEV(i)
7042                         port_offload_cap_display(i);
7043 }
7044
7045 cmdline_parse_token_string_t cmd_showportall_show =
7046         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7047                                  "show#clear");
7048 cmdline_parse_token_string_t cmd_showportall_port =
7049         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7050 cmdline_parse_token_string_t cmd_showportall_what =
7051         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7052                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7053 cmdline_parse_token_string_t cmd_showportall_all =
7054         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7055 cmdline_parse_inst_t cmd_showportall = {
7056         .f = cmd_showportall_parsed,
7057         .data = NULL,
7058         .help_str = "show|clear port "
7059                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7060         .tokens = {
7061                 (void *)&cmd_showportall_show,
7062                 (void *)&cmd_showportall_port,
7063                 (void *)&cmd_showportall_what,
7064                 (void *)&cmd_showportall_all,
7065                 NULL,
7066         },
7067 };
7068
7069 /* *** SHOW PORT INFO *** */
7070 struct cmd_showport_result {
7071         cmdline_fixed_string_t show;
7072         cmdline_fixed_string_t port;
7073         cmdline_fixed_string_t what;
7074         uint16_t portnum;
7075 };
7076
7077 static void cmd_showport_parsed(void *parsed_result,
7078                                 __attribute__((unused)) struct cmdline *cl,
7079                                 __attribute__((unused)) void *data)
7080 {
7081         struct cmd_showport_result *res = parsed_result;
7082         if (!strcmp(res->show, "clear")) {
7083                 if (!strcmp(res->what, "stats"))
7084                         nic_stats_clear(res->portnum);
7085                 else if (!strcmp(res->what, "xstats"))
7086                         nic_xstats_clear(res->portnum);
7087         } else if (!strcmp(res->what, "info"))
7088                 port_infos_display(res->portnum);
7089         else if (!strcmp(res->what, "stats"))
7090                 nic_stats_display(res->portnum);
7091         else if (!strcmp(res->what, "xstats"))
7092                 nic_xstats_display(res->portnum);
7093         else if (!strcmp(res->what, "fdir"))
7094                  fdir_get_infos(res->portnum);
7095         else if (!strcmp(res->what, "stat_qmap"))
7096                 nic_stats_mapping_display(res->portnum);
7097         else if (!strcmp(res->what, "dcb_tc"))
7098                 port_dcb_info_display(res->portnum);
7099         else if (!strcmp(res->what, "cap"))
7100                 port_offload_cap_display(res->portnum);
7101 }
7102
7103 cmdline_parse_token_string_t cmd_showport_show =
7104         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7105                                  "show#clear");
7106 cmdline_parse_token_string_t cmd_showport_port =
7107         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7108 cmdline_parse_token_string_t cmd_showport_what =
7109         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7110                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7111 cmdline_parse_token_num_t cmd_showport_portnum =
7112         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7113
7114 cmdline_parse_inst_t cmd_showport = {
7115         .f = cmd_showport_parsed,
7116         .data = NULL,
7117         .help_str = "show|clear port "
7118                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7119                 "<port_id>",
7120         .tokens = {
7121                 (void *)&cmd_showport_show,
7122                 (void *)&cmd_showport_port,
7123                 (void *)&cmd_showport_what,
7124                 (void *)&cmd_showport_portnum,
7125                 NULL,
7126         },
7127 };
7128
7129 /* *** SHOW QUEUE INFO *** */
7130 struct cmd_showqueue_result {
7131         cmdline_fixed_string_t show;
7132         cmdline_fixed_string_t type;
7133         cmdline_fixed_string_t what;
7134         uint16_t portnum;
7135         uint16_t queuenum;
7136 };
7137
7138 static void
7139 cmd_showqueue_parsed(void *parsed_result,
7140         __attribute__((unused)) struct cmdline *cl,
7141         __attribute__((unused)) void *data)
7142 {
7143         struct cmd_showqueue_result *res = parsed_result;
7144
7145         if (!strcmp(res->type, "rxq"))
7146                 rx_queue_infos_display(res->portnum, res->queuenum);
7147         else if (!strcmp(res->type, "txq"))
7148                 tx_queue_infos_display(res->portnum, res->queuenum);
7149 }
7150
7151 cmdline_parse_token_string_t cmd_showqueue_show =
7152         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7153 cmdline_parse_token_string_t cmd_showqueue_type =
7154         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7155 cmdline_parse_token_string_t cmd_showqueue_what =
7156         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7157 cmdline_parse_token_num_t cmd_showqueue_portnum =
7158         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7159 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7160         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7161
7162 cmdline_parse_inst_t cmd_showqueue = {
7163         .f = cmd_showqueue_parsed,
7164         .data = NULL,
7165         .help_str = "show rxq|txq info <port_id> <queue_id>",
7166         .tokens = {
7167                 (void *)&cmd_showqueue_show,
7168                 (void *)&cmd_showqueue_type,
7169                 (void *)&cmd_showqueue_what,
7170                 (void *)&cmd_showqueue_portnum,
7171                 (void *)&cmd_showqueue_queuenum,
7172                 NULL,
7173         },
7174 };
7175
7176 /* *** READ PORT REGISTER *** */
7177 struct cmd_read_reg_result {
7178         cmdline_fixed_string_t read;
7179         cmdline_fixed_string_t reg;
7180         portid_t port_id;
7181         uint32_t reg_off;
7182 };
7183
7184 static void
7185 cmd_read_reg_parsed(void *parsed_result,
7186                     __attribute__((unused)) struct cmdline *cl,
7187                     __attribute__((unused)) void *data)
7188 {
7189         struct cmd_read_reg_result *res = parsed_result;
7190         port_reg_display(res->port_id, res->reg_off);
7191 }
7192
7193 cmdline_parse_token_string_t cmd_read_reg_read =
7194         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7195 cmdline_parse_token_string_t cmd_read_reg_reg =
7196         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7197 cmdline_parse_token_num_t cmd_read_reg_port_id =
7198         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7199 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7200         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7201
7202 cmdline_parse_inst_t cmd_read_reg = {
7203         .f = cmd_read_reg_parsed,
7204         .data = NULL,
7205         .help_str = "read reg <port_id> <reg_off>",
7206         .tokens = {
7207                 (void *)&cmd_read_reg_read,
7208                 (void *)&cmd_read_reg_reg,
7209                 (void *)&cmd_read_reg_port_id,
7210                 (void *)&cmd_read_reg_reg_off,
7211                 NULL,
7212         },
7213 };
7214
7215 /* *** READ PORT REGISTER BIT FIELD *** */
7216 struct cmd_read_reg_bit_field_result {
7217         cmdline_fixed_string_t read;
7218         cmdline_fixed_string_t regfield;
7219         portid_t port_id;
7220         uint32_t reg_off;
7221         uint8_t bit1_pos;
7222         uint8_t bit2_pos;
7223 };
7224
7225 static void
7226 cmd_read_reg_bit_field_parsed(void *parsed_result,
7227                               __attribute__((unused)) struct cmdline *cl,
7228                               __attribute__((unused)) void *data)
7229 {
7230         struct cmd_read_reg_bit_field_result *res = parsed_result;
7231         port_reg_bit_field_display(res->port_id, res->reg_off,
7232                                    res->bit1_pos, res->bit2_pos);
7233 }
7234
7235 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7236         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7237                                  "read");
7238 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7239         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7240                                  regfield, "regfield");
7241 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7242         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7243                               UINT16);
7244 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7245         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7246                               UINT32);
7247 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7248         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7249                               UINT8);
7250 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7251         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7252                               UINT8);
7253
7254 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7255         .f = cmd_read_reg_bit_field_parsed,
7256         .data = NULL,
7257         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7258         "Read register bit field between bit_x and bit_y included",
7259         .tokens = {
7260                 (void *)&cmd_read_reg_bit_field_read,
7261                 (void *)&cmd_read_reg_bit_field_regfield,
7262                 (void *)&cmd_read_reg_bit_field_port_id,
7263                 (void *)&cmd_read_reg_bit_field_reg_off,
7264                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7265                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7266                 NULL,
7267         },
7268 };
7269
7270 /* *** READ PORT REGISTER BIT *** */
7271 struct cmd_read_reg_bit_result {
7272         cmdline_fixed_string_t read;
7273         cmdline_fixed_string_t regbit;
7274         portid_t port_id;
7275         uint32_t reg_off;
7276         uint8_t bit_pos;
7277 };
7278
7279 static void
7280 cmd_read_reg_bit_parsed(void *parsed_result,
7281                         __attribute__((unused)) struct cmdline *cl,
7282                         __attribute__((unused)) void *data)
7283 {
7284         struct cmd_read_reg_bit_result *res = parsed_result;
7285         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7286 }
7287
7288 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7289         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7290 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7291         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7292                                  regbit, "regbit");
7293 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7294         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7295 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7296         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7297 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7298         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7299
7300 cmdline_parse_inst_t cmd_read_reg_bit = {
7301         .f = cmd_read_reg_bit_parsed,
7302         .data = NULL,
7303         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7304         .tokens = {
7305                 (void *)&cmd_read_reg_bit_read,
7306                 (void *)&cmd_read_reg_bit_regbit,
7307                 (void *)&cmd_read_reg_bit_port_id,
7308                 (void *)&cmd_read_reg_bit_reg_off,
7309                 (void *)&cmd_read_reg_bit_bit_pos,
7310                 NULL,
7311         },
7312 };
7313
7314 /* *** WRITE PORT REGISTER *** */
7315 struct cmd_write_reg_result {
7316         cmdline_fixed_string_t write;
7317         cmdline_fixed_string_t reg;
7318         portid_t port_id;
7319         uint32_t reg_off;
7320         uint32_t value;
7321 };
7322
7323 static void
7324 cmd_write_reg_parsed(void *parsed_result,
7325                      __attribute__((unused)) struct cmdline *cl,
7326                      __attribute__((unused)) void *data)
7327 {
7328         struct cmd_write_reg_result *res = parsed_result;
7329         port_reg_set(res->port_id, res->reg_off, res->value);
7330 }
7331
7332 cmdline_parse_token_string_t cmd_write_reg_write =
7333         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7334 cmdline_parse_token_string_t cmd_write_reg_reg =
7335         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7336 cmdline_parse_token_num_t cmd_write_reg_port_id =
7337         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7338 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7339         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7340 cmdline_parse_token_num_t cmd_write_reg_value =
7341         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7342
7343 cmdline_parse_inst_t cmd_write_reg = {
7344         .f = cmd_write_reg_parsed,
7345         .data = NULL,
7346         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7347         .tokens = {
7348                 (void *)&cmd_write_reg_write,
7349                 (void *)&cmd_write_reg_reg,
7350                 (void *)&cmd_write_reg_port_id,
7351                 (void *)&cmd_write_reg_reg_off,
7352                 (void *)&cmd_write_reg_value,
7353                 NULL,
7354         },
7355 };
7356
7357 /* *** WRITE PORT REGISTER BIT FIELD *** */
7358 struct cmd_write_reg_bit_field_result {
7359         cmdline_fixed_string_t write;
7360         cmdline_fixed_string_t regfield;
7361         portid_t port_id;
7362         uint32_t reg_off;
7363         uint8_t bit1_pos;
7364         uint8_t bit2_pos;
7365         uint32_t value;
7366 };
7367
7368 static void
7369 cmd_write_reg_bit_field_parsed(void *parsed_result,
7370                                __attribute__((unused)) struct cmdline *cl,
7371                                __attribute__((unused)) void *data)
7372 {
7373         struct cmd_write_reg_bit_field_result *res = parsed_result;
7374         port_reg_bit_field_set(res->port_id, res->reg_off,
7375                           res->bit1_pos, res->bit2_pos, res->value);
7376 }
7377
7378 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7379         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7380                                  "write");
7381 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7382         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7383                                  regfield, "regfield");
7384 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7385         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7386                               UINT16);
7387 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7388         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7389                               UINT32);
7390 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7391         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7392                               UINT8);
7393 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7394         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7395                               UINT8);
7396 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7397         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7398                               UINT32);
7399
7400 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7401         .f = cmd_write_reg_bit_field_parsed,
7402         .data = NULL,
7403         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7404                 "<reg_value>: "
7405                 "Set register bit field between bit_x and bit_y included",
7406         .tokens = {
7407                 (void *)&cmd_write_reg_bit_field_write,
7408                 (void *)&cmd_write_reg_bit_field_regfield,
7409                 (void *)&cmd_write_reg_bit_field_port_id,
7410                 (void *)&cmd_write_reg_bit_field_reg_off,
7411                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7412                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7413                 (void *)&cmd_write_reg_bit_field_value,
7414                 NULL,
7415         },
7416 };
7417
7418 /* *** WRITE PORT REGISTER BIT *** */
7419 struct cmd_write_reg_bit_result {
7420         cmdline_fixed_string_t write;
7421         cmdline_fixed_string_t regbit;
7422         portid_t port_id;
7423         uint32_t reg_off;
7424         uint8_t bit_pos;
7425         uint8_t value;
7426 };
7427
7428 static void
7429 cmd_write_reg_bit_parsed(void *parsed_result,
7430                          __attribute__((unused)) struct cmdline *cl,
7431                          __attribute__((unused)) void *data)
7432 {
7433         struct cmd_write_reg_bit_result *res = parsed_result;
7434         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7435 }
7436
7437 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7438         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7439                                  "write");
7440 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7441         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7442                                  regbit, "regbit");
7443 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7444         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7445 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7446         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7447 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7448         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7449 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7450         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7451
7452 cmdline_parse_inst_t cmd_write_reg_bit = {
7453         .f = cmd_write_reg_bit_parsed,
7454         .data = NULL,
7455         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7456                 "0 <= bit_x <= 31",
7457         .tokens = {
7458                 (void *)&cmd_write_reg_bit_write,
7459                 (void *)&cmd_write_reg_bit_regbit,
7460                 (void *)&cmd_write_reg_bit_port_id,
7461                 (void *)&cmd_write_reg_bit_reg_off,
7462                 (void *)&cmd_write_reg_bit_bit_pos,
7463                 (void *)&cmd_write_reg_bit_value,
7464                 NULL,
7465         },
7466 };
7467
7468 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7469 struct cmd_read_rxd_txd_result {
7470         cmdline_fixed_string_t read;
7471         cmdline_fixed_string_t rxd_txd;
7472         portid_t port_id;
7473         uint16_t queue_id;
7474         uint16_t desc_id;
7475 };
7476
7477 static void
7478 cmd_read_rxd_txd_parsed(void *parsed_result,
7479                         __attribute__((unused)) struct cmdline *cl,
7480                         __attribute__((unused)) void *data)
7481 {
7482         struct cmd_read_rxd_txd_result *res = parsed_result;
7483
7484         if (!strcmp(res->rxd_txd, "rxd"))
7485                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7486         else if (!strcmp(res->rxd_txd, "txd"))
7487                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7488 }
7489
7490 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7491         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7492 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7493         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7494                                  "rxd#txd");
7495 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7496         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7497 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7498         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7499 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7500         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7501
7502 cmdline_parse_inst_t cmd_read_rxd_txd = {
7503         .f = cmd_read_rxd_txd_parsed,
7504         .data = NULL,
7505         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7506         .tokens = {
7507                 (void *)&cmd_read_rxd_txd_read,
7508                 (void *)&cmd_read_rxd_txd_rxd_txd,
7509                 (void *)&cmd_read_rxd_txd_port_id,
7510                 (void *)&cmd_read_rxd_txd_queue_id,
7511                 (void *)&cmd_read_rxd_txd_desc_id,
7512                 NULL,
7513         },
7514 };
7515
7516 /* *** QUIT *** */
7517 struct cmd_quit_result {
7518         cmdline_fixed_string_t quit;
7519 };
7520
7521 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7522                             struct cmdline *cl,
7523                             __attribute__((unused)) void *data)
7524 {
7525         pmd_test_exit();
7526         cmdline_quit(cl);
7527 }
7528
7529 cmdline_parse_token_string_t cmd_quit_quit =
7530         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7531
7532 cmdline_parse_inst_t cmd_quit = {
7533         .f = cmd_quit_parsed,
7534         .data = NULL,
7535         .help_str = "quit: Exit application",
7536         .tokens = {
7537                 (void *)&cmd_quit_quit,
7538                 NULL,
7539         },
7540 };
7541
7542 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7543 struct cmd_mac_addr_result {
7544         cmdline_fixed_string_t mac_addr_cmd;
7545         cmdline_fixed_string_t what;
7546         uint16_t port_num;
7547         struct ether_addr address;
7548 };
7549
7550 static void cmd_mac_addr_parsed(void *parsed_result,
7551                 __attribute__((unused)) struct cmdline *cl,
7552                 __attribute__((unused)) void *data)
7553 {
7554         struct cmd_mac_addr_result *res = parsed_result;
7555         int ret;
7556
7557         if (strcmp(res->what, "add") == 0)
7558                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7559         else if (strcmp(res->what, "set") == 0)
7560                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7561                                                        &res->address);
7562         else
7563                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7564
7565         /* check the return value and print it if is < 0 */
7566         if(ret < 0)
7567                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7568
7569 }
7570
7571 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7572         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7573                                 "mac_addr");
7574 cmdline_parse_token_string_t cmd_mac_addr_what =
7575         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7576                                 "add#remove#set");
7577 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7578                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7579                                         UINT16);
7580 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7581                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7582
7583 cmdline_parse_inst_t cmd_mac_addr = {
7584         .f = cmd_mac_addr_parsed,
7585         .data = (void *)0,
7586         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7587                         "Add/Remove/Set MAC address on port_id",
7588         .tokens = {
7589                 (void *)&cmd_mac_addr_cmd,
7590                 (void *)&cmd_mac_addr_what,
7591                 (void *)&cmd_mac_addr_portnum,
7592                 (void *)&cmd_mac_addr_addr,
7593                 NULL,
7594         },
7595 };
7596
7597 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7598 struct cmd_eth_peer_result {
7599         cmdline_fixed_string_t set;
7600         cmdline_fixed_string_t eth_peer;
7601         portid_t port_id;
7602         cmdline_fixed_string_t peer_addr;
7603 };
7604
7605 static void cmd_set_eth_peer_parsed(void *parsed_result,
7606                         __attribute__((unused)) struct cmdline *cl,
7607                         __attribute__((unused)) void *data)
7608 {
7609                 struct cmd_eth_peer_result *res = parsed_result;
7610
7611                 if (test_done == 0) {
7612                         printf("Please stop forwarding first\n");
7613                         return;
7614                 }
7615                 if (!strcmp(res->eth_peer, "eth-peer")) {
7616                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7617                         fwd_config_setup();
7618                 }
7619 }
7620 cmdline_parse_token_string_t cmd_eth_peer_set =
7621         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7622 cmdline_parse_token_string_t cmd_eth_peer =
7623         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7624 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7625         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7626 cmdline_parse_token_string_t cmd_eth_peer_addr =
7627         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7628
7629 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7630         .f = cmd_set_eth_peer_parsed,
7631         .data = NULL,
7632         .help_str = "set eth-peer <port_id> <peer_mac>",
7633         .tokens = {
7634                 (void *)&cmd_eth_peer_set,
7635                 (void *)&cmd_eth_peer,
7636                 (void *)&cmd_eth_peer_port_id,
7637                 (void *)&cmd_eth_peer_addr,
7638                 NULL,
7639         },
7640 };
7641
7642 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7643 struct cmd_set_qmap_result {
7644         cmdline_fixed_string_t set;
7645         cmdline_fixed_string_t qmap;
7646         cmdline_fixed_string_t what;
7647         portid_t port_id;
7648         uint16_t queue_id;
7649         uint8_t map_value;
7650 };
7651
7652 static void
7653 cmd_set_qmap_parsed(void *parsed_result,
7654                        __attribute__((unused)) struct cmdline *cl,
7655                        __attribute__((unused)) void *data)
7656 {
7657         struct cmd_set_qmap_result *res = parsed_result;
7658         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7659
7660         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7661 }
7662
7663 cmdline_parse_token_string_t cmd_setqmap_set =
7664         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7665                                  set, "set");
7666 cmdline_parse_token_string_t cmd_setqmap_qmap =
7667         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7668                                  qmap, "stat_qmap");
7669 cmdline_parse_token_string_t cmd_setqmap_what =
7670         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7671                                  what, "tx#rx");
7672 cmdline_parse_token_num_t cmd_setqmap_portid =
7673         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7674                               port_id, UINT16);
7675 cmdline_parse_token_num_t cmd_setqmap_queueid =
7676         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7677                               queue_id, UINT16);
7678 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7679         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7680                               map_value, UINT8);
7681
7682 cmdline_parse_inst_t cmd_set_qmap = {
7683         .f = cmd_set_qmap_parsed,
7684         .data = NULL,
7685         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7686                 "Set statistics mapping value on tx|rx queue_id of port_id",
7687         .tokens = {
7688                 (void *)&cmd_setqmap_set,
7689                 (void *)&cmd_setqmap_qmap,
7690                 (void *)&cmd_setqmap_what,
7691                 (void *)&cmd_setqmap_portid,
7692                 (void *)&cmd_setqmap_queueid,
7693                 (void *)&cmd_setqmap_mapvalue,
7694                 NULL,
7695         },
7696 };
7697
7698 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7699 struct cmd_set_xstats_hide_zero_result {
7700         cmdline_fixed_string_t keyword;
7701         cmdline_fixed_string_t name;
7702         cmdline_fixed_string_t on_off;
7703 };
7704
7705 static void
7706 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7707                         __attribute__((unused)) struct cmdline *cl,
7708                         __attribute__((unused)) void *data)
7709 {
7710         struct cmd_set_xstats_hide_zero_result *res;
7711         uint16_t on_off = 0;
7712
7713         res = parsed_result;
7714         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7715         set_xstats_hide_zero(on_off);
7716 }
7717
7718 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7719         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7720                                  keyword, "set");
7721 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7722         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7723                                  name, "xstats-hide-zero");
7724 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7725         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7726                                  on_off, "on#off");
7727
7728 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7729         .f = cmd_set_xstats_hide_zero_parsed,
7730         .data = NULL,
7731         .help_str = "set xstats-hide-zero on|off",
7732         .tokens = {
7733                 (void *)&cmd_set_xstats_hide_zero_keyword,
7734                 (void *)&cmd_set_xstats_hide_zero_name,
7735                 (void *)&cmd_set_xstats_hide_zero_on_off,
7736                 NULL,
7737         },
7738 };
7739
7740 /* *** CONFIGURE UNICAST HASH TABLE *** */
7741 struct cmd_set_uc_hash_table {
7742         cmdline_fixed_string_t set;
7743         cmdline_fixed_string_t port;
7744         portid_t port_id;
7745         cmdline_fixed_string_t what;
7746         struct ether_addr address;
7747         cmdline_fixed_string_t mode;
7748 };
7749
7750 static void
7751 cmd_set_uc_hash_parsed(void *parsed_result,
7752                        __attribute__((unused)) struct cmdline *cl,
7753                        __attribute__((unused)) void *data)
7754 {
7755         int ret=0;
7756         struct cmd_set_uc_hash_table *res = parsed_result;
7757
7758         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7759
7760         if (strcmp(res->what, "uta") == 0)
7761                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7762                                                 &res->address,(uint8_t)is_on);
7763         if (ret < 0)
7764                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7765
7766 }
7767
7768 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7769         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7770                                  set, "set");
7771 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7772         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7773                                  port, "port");
7774 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7775         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7776                               port_id, UINT16);
7777 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7778         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7779                                  what, "uta");
7780 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7781         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7782                                 address);
7783 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7784         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7785                                  mode, "on#off");
7786
7787 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7788         .f = cmd_set_uc_hash_parsed,
7789         .data = NULL,
7790         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7791         .tokens = {
7792                 (void *)&cmd_set_uc_hash_set,
7793                 (void *)&cmd_set_uc_hash_port,
7794                 (void *)&cmd_set_uc_hash_portid,
7795                 (void *)&cmd_set_uc_hash_what,
7796                 (void *)&cmd_set_uc_hash_mac,
7797                 (void *)&cmd_set_uc_hash_mode,
7798                 NULL,
7799         },
7800 };
7801
7802 struct cmd_set_uc_all_hash_table {
7803         cmdline_fixed_string_t set;
7804         cmdline_fixed_string_t port;
7805         portid_t port_id;
7806         cmdline_fixed_string_t what;
7807         cmdline_fixed_string_t value;
7808         cmdline_fixed_string_t mode;
7809 };
7810
7811 static void
7812 cmd_set_uc_all_hash_parsed(void *parsed_result,
7813                        __attribute__((unused)) struct cmdline *cl,
7814                        __attribute__((unused)) void *data)
7815 {
7816         int ret=0;
7817         struct cmd_set_uc_all_hash_table *res = parsed_result;
7818
7819         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7820
7821         if ((strcmp(res->what, "uta") == 0) &&
7822                 (strcmp(res->value, "all") == 0))
7823                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7824         if (ret < 0)
7825                 printf("bad unicast hash table parameter,"
7826                         "return code = %d \n", ret);
7827 }
7828
7829 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7830         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7831                                  set, "set");
7832 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7833         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7834                                  port, "port");
7835 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7836         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7837                               port_id, UINT16);
7838 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7839         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7840                                  what, "uta");
7841 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7842         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7843                                 value,"all");
7844 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7845         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7846                                  mode, "on#off");
7847
7848 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7849         .f = cmd_set_uc_all_hash_parsed,
7850         .data = NULL,
7851         .help_str = "set port <port_id> uta all on|off",
7852         .tokens = {
7853                 (void *)&cmd_set_uc_all_hash_set,
7854                 (void *)&cmd_set_uc_all_hash_port,
7855                 (void *)&cmd_set_uc_all_hash_portid,
7856                 (void *)&cmd_set_uc_all_hash_what,
7857                 (void *)&cmd_set_uc_all_hash_value,
7858                 (void *)&cmd_set_uc_all_hash_mode,
7859                 NULL,
7860         },
7861 };
7862
7863 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7864 struct cmd_set_vf_macvlan_filter {
7865         cmdline_fixed_string_t set;
7866         cmdline_fixed_string_t port;
7867         portid_t port_id;
7868         cmdline_fixed_string_t vf;
7869         uint8_t vf_id;
7870         struct ether_addr address;
7871         cmdline_fixed_string_t filter_type;
7872         cmdline_fixed_string_t mode;
7873 };
7874
7875 static void
7876 cmd_set_vf_macvlan_parsed(void *parsed_result,
7877                        __attribute__((unused)) struct cmdline *cl,
7878                        __attribute__((unused)) void *data)
7879 {
7880         int is_on, ret = 0;
7881         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7882         struct rte_eth_mac_filter filter;
7883
7884         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7885
7886         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7887
7888         /* set VF MAC filter */
7889         filter.is_vf = 1;
7890
7891         /* set VF ID */
7892         filter.dst_id = res->vf_id;
7893
7894         if (!strcmp(res->filter_type, "exact-mac"))
7895                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7896         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7897                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7898         else if (!strcmp(res->filter_type, "hashmac"))
7899                 filter.filter_type = RTE_MAC_HASH_MATCH;
7900         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7901                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7902
7903         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7904
7905         if (is_on)
7906                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7907                                         RTE_ETH_FILTER_MACVLAN,
7908                                         RTE_ETH_FILTER_ADD,
7909                                          &filter);
7910         else
7911                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7912                                         RTE_ETH_FILTER_MACVLAN,
7913                                         RTE_ETH_FILTER_DELETE,
7914                                         &filter);
7915
7916         if (ret < 0)
7917                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7918
7919 }
7920
7921 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7922         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7923                                  set, "set");
7924 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7925         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7926                                  port, "port");
7927 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7928         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7929                               port_id, UINT16);
7930 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7931         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7932                                  vf, "vf");
7933 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7934         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7935                                 vf_id, UINT8);
7936 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7937         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7938                                 address);
7939 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7940         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7941                                 filter_type, "exact-mac#exact-mac-vlan"
7942                                 "#hashmac#hashmac-vlan");
7943 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7944         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7945                                  mode, "on#off");
7946
7947 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7948         .f = cmd_set_vf_macvlan_parsed,
7949         .data = NULL,
7950         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7951                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7952                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7953                 "hash match rule: hash match of MAC and exact match of VLAN",
7954         .tokens = {
7955                 (void *)&cmd_set_vf_macvlan_set,
7956                 (void *)&cmd_set_vf_macvlan_port,
7957                 (void *)&cmd_set_vf_macvlan_portid,
7958                 (void *)&cmd_set_vf_macvlan_vf,
7959                 (void *)&cmd_set_vf_macvlan_vf_id,
7960                 (void *)&cmd_set_vf_macvlan_mac,
7961                 (void *)&cmd_set_vf_macvlan_filter_type,
7962                 (void *)&cmd_set_vf_macvlan_mode,
7963                 NULL,
7964         },
7965 };
7966
7967 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7968 struct cmd_set_vf_traffic {
7969         cmdline_fixed_string_t set;
7970         cmdline_fixed_string_t port;
7971         portid_t port_id;
7972         cmdline_fixed_string_t vf;
7973         uint8_t vf_id;
7974         cmdline_fixed_string_t what;
7975         cmdline_fixed_string_t mode;
7976 };
7977
7978 static void
7979 cmd_set_vf_traffic_parsed(void *parsed_result,
7980                        __attribute__((unused)) struct cmdline *cl,
7981                        __attribute__((unused)) void *data)
7982 {
7983         struct cmd_set_vf_traffic *res = parsed_result;
7984         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7985         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7986
7987         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7988 }
7989
7990 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7991         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7992                                  set, "set");
7993 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7994         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7995                                  port, "port");
7996 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7997         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7998                               port_id, UINT16);
7999 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8000         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8001                                  vf, "vf");
8002 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8003         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8004                               vf_id, UINT8);
8005 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8006         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8007                                  what, "tx#rx");
8008 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8009         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8010                                  mode, "on#off");
8011
8012 cmdline_parse_inst_t cmd_set_vf_traffic = {
8013         .f = cmd_set_vf_traffic_parsed,
8014         .data = NULL,
8015         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8016         .tokens = {
8017                 (void *)&cmd_setvf_traffic_set,
8018                 (void *)&cmd_setvf_traffic_port,
8019                 (void *)&cmd_setvf_traffic_portid,
8020                 (void *)&cmd_setvf_traffic_vf,
8021                 (void *)&cmd_setvf_traffic_vfid,
8022                 (void *)&cmd_setvf_traffic_what,
8023                 (void *)&cmd_setvf_traffic_mode,
8024                 NULL,
8025         },
8026 };
8027
8028 /* *** CONFIGURE VF RECEIVE MODE *** */
8029 struct cmd_set_vf_rxmode {
8030         cmdline_fixed_string_t set;
8031         cmdline_fixed_string_t port;
8032         portid_t port_id;
8033         cmdline_fixed_string_t vf;
8034         uint8_t vf_id;
8035         cmdline_fixed_string_t what;
8036         cmdline_fixed_string_t mode;
8037         cmdline_fixed_string_t on;
8038 };
8039
8040 static void
8041 cmd_set_vf_rxmode_parsed(void *parsed_result,
8042                        __attribute__((unused)) struct cmdline *cl,
8043                        __attribute__((unused)) void *data)
8044 {
8045         int ret = -ENOTSUP;
8046         uint16_t rx_mode = 0;
8047         struct cmd_set_vf_rxmode *res = parsed_result;
8048
8049         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8050         if (!strcmp(res->what,"rxmode")) {
8051                 if (!strcmp(res->mode, "AUPE"))
8052                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8053                 else if (!strcmp(res->mode, "ROPE"))
8054                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8055                 else if (!strcmp(res->mode, "BAM"))
8056                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8057                 else if (!strncmp(res->mode, "MPE",3))
8058                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8059         }
8060
8061         RTE_SET_USED(is_on);
8062
8063 #ifdef RTE_LIBRTE_IXGBE_PMD
8064         if (ret == -ENOTSUP)
8065                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8066                                                   rx_mode, (uint8_t)is_on);
8067 #endif
8068 #ifdef RTE_LIBRTE_BNXT_PMD
8069         if (ret == -ENOTSUP)
8070                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8071                                                  rx_mode, (uint8_t)is_on);
8072 #endif
8073         if (ret < 0)
8074                 printf("bad VF receive mode parameter, return code = %d \n",
8075                 ret);
8076 }
8077
8078 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8079         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8080                                  set, "set");
8081 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8082         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8083                                  port, "port");
8084 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8085         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8086                               port_id, UINT16);
8087 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8088         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8089                                  vf, "vf");
8090 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8091         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8092                               vf_id, UINT8);
8093 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8094         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8095                                  what, "rxmode");
8096 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8097         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8098                                  mode, "AUPE#ROPE#BAM#MPE");
8099 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8100         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8101                                  on, "on#off");
8102
8103 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8104         .f = cmd_set_vf_rxmode_parsed,
8105         .data = NULL,
8106         .help_str = "set port <port_id> vf <vf_id> rxmode "
8107                 "AUPE|ROPE|BAM|MPE on|off",
8108         .tokens = {
8109                 (void *)&cmd_set_vf_rxmode_set,
8110                 (void *)&cmd_set_vf_rxmode_port,
8111                 (void *)&cmd_set_vf_rxmode_portid,
8112                 (void *)&cmd_set_vf_rxmode_vf,
8113                 (void *)&cmd_set_vf_rxmode_vfid,
8114                 (void *)&cmd_set_vf_rxmode_what,
8115                 (void *)&cmd_set_vf_rxmode_mode,
8116                 (void *)&cmd_set_vf_rxmode_on,
8117                 NULL,
8118         },
8119 };
8120
8121 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8122 struct cmd_vf_mac_addr_result {
8123         cmdline_fixed_string_t mac_addr_cmd;
8124         cmdline_fixed_string_t what;
8125         cmdline_fixed_string_t port;
8126         uint16_t port_num;
8127         cmdline_fixed_string_t vf;
8128         uint8_t vf_num;
8129         struct ether_addr address;
8130 };
8131
8132 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8133                 __attribute__((unused)) struct cmdline *cl,
8134                 __attribute__((unused)) void *data)
8135 {
8136         struct cmd_vf_mac_addr_result *res = parsed_result;
8137         int ret = -ENOTSUP;
8138
8139         if (strcmp(res->what, "add") != 0)
8140                 return;
8141
8142 #ifdef RTE_LIBRTE_I40E_PMD
8143         if (ret == -ENOTSUP)
8144                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8145                                                    &res->address);
8146 #endif
8147 #ifdef RTE_LIBRTE_BNXT_PMD
8148         if (ret == -ENOTSUP)
8149                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8150                                                 res->vf_num);
8151 #endif
8152
8153         if(ret < 0)
8154                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8155
8156 }
8157
8158 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8159         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8160                                 mac_addr_cmd,"mac_addr");
8161 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8162         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8163                                 what,"add");
8164 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8165         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8166                                 port,"port");
8167 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8168         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8169                                 port_num, UINT16);
8170 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8171         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8172                                 vf,"vf");
8173 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8174         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8175                                 vf_num, UINT8);
8176 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8177         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8178                                 address);
8179
8180 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8181         .f = cmd_vf_mac_addr_parsed,
8182         .data = (void *)0,
8183         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8184                 "Add MAC address filtering for a VF on port_id",
8185         .tokens = {
8186                 (void *)&cmd_vf_mac_addr_cmd,
8187                 (void *)&cmd_vf_mac_addr_what,
8188                 (void *)&cmd_vf_mac_addr_port,
8189                 (void *)&cmd_vf_mac_addr_portnum,
8190                 (void *)&cmd_vf_mac_addr_vf,
8191                 (void *)&cmd_vf_mac_addr_vfnum,
8192                 (void *)&cmd_vf_mac_addr_addr,
8193                 NULL,
8194         },
8195 };
8196
8197 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8198 struct cmd_vf_rx_vlan_filter {
8199         cmdline_fixed_string_t rx_vlan;
8200         cmdline_fixed_string_t what;
8201         uint16_t vlan_id;
8202         cmdline_fixed_string_t port;
8203         portid_t port_id;
8204         cmdline_fixed_string_t vf;
8205         uint64_t vf_mask;
8206 };
8207
8208 static void
8209 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8210                           __attribute__((unused)) struct cmdline *cl,
8211                           __attribute__((unused)) void *data)
8212 {
8213         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8214         int ret = -ENOTSUP;
8215
8216         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8217
8218 #ifdef RTE_LIBRTE_IXGBE_PMD
8219         if (ret == -ENOTSUP)
8220                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8221                                 res->vlan_id, res->vf_mask, is_add);
8222 #endif
8223 #ifdef RTE_LIBRTE_I40E_PMD
8224         if (ret == -ENOTSUP)
8225                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8226                                 res->vlan_id, res->vf_mask, is_add);
8227 #endif
8228 #ifdef RTE_LIBRTE_BNXT_PMD
8229         if (ret == -ENOTSUP)
8230                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8231                                 res->vlan_id, res->vf_mask, is_add);
8232 #endif
8233
8234         switch (ret) {
8235         case 0:
8236                 break;
8237         case -EINVAL:
8238                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8239                                 res->vlan_id, res->vf_mask);
8240                 break;
8241         case -ENODEV:
8242                 printf("invalid port_id %d\n", res->port_id);
8243                 break;
8244         case -ENOTSUP:
8245                 printf("function not implemented or supported\n");
8246                 break;
8247         default:
8248                 printf("programming error: (%s)\n", strerror(-ret));
8249         }
8250 }
8251
8252 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8253         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8254                                  rx_vlan, "rx_vlan");
8255 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8256         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8257                                  what, "add#rm");
8258 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8259         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8260                               vlan_id, UINT16);
8261 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8262         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8263                                  port, "port");
8264 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8265         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8266                               port_id, UINT16);
8267 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8268         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8269                                  vf, "vf");
8270 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8271         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8272                               vf_mask, UINT64);
8273
8274 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8275         .f = cmd_vf_rx_vlan_filter_parsed,
8276         .data = NULL,
8277         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8278                 "(vf_mask = hexadecimal VF mask)",
8279         .tokens = {
8280                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8281                 (void *)&cmd_vf_rx_vlan_filter_what,
8282                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8283                 (void *)&cmd_vf_rx_vlan_filter_port,
8284                 (void *)&cmd_vf_rx_vlan_filter_portid,
8285                 (void *)&cmd_vf_rx_vlan_filter_vf,
8286                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8287                 NULL,
8288         },
8289 };
8290
8291 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8292 struct cmd_queue_rate_limit_result {
8293         cmdline_fixed_string_t set;
8294         cmdline_fixed_string_t port;
8295         uint16_t port_num;
8296         cmdline_fixed_string_t queue;
8297         uint8_t queue_num;
8298         cmdline_fixed_string_t rate;
8299         uint16_t rate_num;
8300 };
8301
8302 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8303                 __attribute__((unused)) struct cmdline *cl,
8304                 __attribute__((unused)) void *data)
8305 {
8306         struct cmd_queue_rate_limit_result *res = parsed_result;
8307         int ret = 0;
8308
8309         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8310                 && (strcmp(res->queue, "queue") == 0)
8311                 && (strcmp(res->rate, "rate") == 0))
8312                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8313                                         res->rate_num);
8314         if (ret < 0)
8315                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8316
8317 }
8318
8319 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8320         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8321                                 set, "set");
8322 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8323         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8324                                 port, "port");
8325 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8326         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8327                                 port_num, UINT16);
8328 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8329         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8330                                 queue, "queue");
8331 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8332         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8333                                 queue_num, UINT8);
8334 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8335         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8336                                 rate, "rate");
8337 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8338         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8339                                 rate_num, UINT16);
8340
8341 cmdline_parse_inst_t cmd_queue_rate_limit = {
8342         .f = cmd_queue_rate_limit_parsed,
8343         .data = (void *)0,
8344         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8345                 "Set rate limit for a queue on port_id",
8346         .tokens = {
8347                 (void *)&cmd_queue_rate_limit_set,
8348                 (void *)&cmd_queue_rate_limit_port,
8349                 (void *)&cmd_queue_rate_limit_portnum,
8350                 (void *)&cmd_queue_rate_limit_queue,
8351                 (void *)&cmd_queue_rate_limit_queuenum,
8352                 (void *)&cmd_queue_rate_limit_rate,
8353                 (void *)&cmd_queue_rate_limit_ratenum,
8354                 NULL,
8355         },
8356 };
8357
8358 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8359 struct cmd_vf_rate_limit_result {
8360         cmdline_fixed_string_t set;
8361         cmdline_fixed_string_t port;
8362         uint16_t port_num;
8363         cmdline_fixed_string_t vf;
8364         uint8_t vf_num;
8365         cmdline_fixed_string_t rate;
8366         uint16_t rate_num;
8367         cmdline_fixed_string_t q_msk;
8368         uint64_t q_msk_val;
8369 };
8370
8371 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8372                 __attribute__((unused)) struct cmdline *cl,
8373                 __attribute__((unused)) void *data)
8374 {
8375         struct cmd_vf_rate_limit_result *res = parsed_result;
8376         int ret = 0;
8377
8378         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8379                 && (strcmp(res->vf, "vf") == 0)
8380                 && (strcmp(res->rate, "rate") == 0)
8381                 && (strcmp(res->q_msk, "queue_mask") == 0))
8382                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8383                                         res->rate_num, res->q_msk_val);
8384         if (ret < 0)
8385                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8386
8387 }
8388
8389 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8390         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8391                                 set, "set");
8392 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8393         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8394                                 port, "port");
8395 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8396         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8397                                 port_num, UINT16);
8398 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8399         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8400                                 vf, "vf");
8401 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8402         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8403                                 vf_num, UINT8);
8404 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8405         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8406                                 rate, "rate");
8407 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8408         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8409                                 rate_num, UINT16);
8410 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8411         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8412                                 q_msk, "queue_mask");
8413 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8414         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8415                                 q_msk_val, UINT64);
8416
8417 cmdline_parse_inst_t cmd_vf_rate_limit = {
8418         .f = cmd_vf_rate_limit_parsed,
8419         .data = (void *)0,
8420         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8421                 "queue_mask <queue_mask_value>: "
8422                 "Set rate limit for queues of VF on port_id",
8423         .tokens = {
8424                 (void *)&cmd_vf_rate_limit_set,
8425                 (void *)&cmd_vf_rate_limit_port,
8426                 (void *)&cmd_vf_rate_limit_portnum,
8427                 (void *)&cmd_vf_rate_limit_vf,
8428                 (void *)&cmd_vf_rate_limit_vfnum,
8429                 (void *)&cmd_vf_rate_limit_rate,
8430                 (void *)&cmd_vf_rate_limit_ratenum,
8431                 (void *)&cmd_vf_rate_limit_q_msk,
8432                 (void *)&cmd_vf_rate_limit_q_msk_val,
8433                 NULL,
8434         },
8435 };
8436
8437 /* *** ADD TUNNEL FILTER OF A PORT *** */
8438 struct cmd_tunnel_filter_result {
8439         cmdline_fixed_string_t cmd;
8440         cmdline_fixed_string_t what;
8441         portid_t port_id;
8442         struct ether_addr outer_mac;
8443         struct ether_addr inner_mac;
8444         cmdline_ipaddr_t ip_value;
8445         uint16_t inner_vlan;
8446         cmdline_fixed_string_t tunnel_type;
8447         cmdline_fixed_string_t filter_type;
8448         uint32_t tenant_id;
8449         uint16_t queue_num;
8450 };
8451
8452 static void
8453 cmd_tunnel_filter_parsed(void *parsed_result,
8454                           __attribute__((unused)) struct cmdline *cl,
8455                           __attribute__((unused)) void *data)
8456 {
8457         struct cmd_tunnel_filter_result *res = parsed_result;
8458         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8459         int ret = 0;
8460
8461         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8462
8463         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8464         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8465         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8466
8467         if (res->ip_value.family == AF_INET) {
8468                 tunnel_filter_conf.ip_addr.ipv4_addr =
8469                         res->ip_value.addr.ipv4.s_addr;
8470                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8471         } else {
8472                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8473                         &(res->ip_value.addr.ipv6),
8474                         sizeof(struct in6_addr));
8475                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8476         }
8477
8478         if (!strcmp(res->filter_type, "imac-ivlan"))
8479                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8480         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8481                 tunnel_filter_conf.filter_type =
8482                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8483         else if (!strcmp(res->filter_type, "imac-tenid"))
8484                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8485         else if (!strcmp(res->filter_type, "imac"))
8486                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8487         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8488                 tunnel_filter_conf.filter_type =
8489                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8490         else if (!strcmp(res->filter_type, "oip"))
8491                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8492         else if (!strcmp(res->filter_type, "iip"))
8493                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8494         else {
8495                 printf("The filter type is not supported");
8496                 return;
8497         }
8498
8499         if (!strcmp(res->tunnel_type, "vxlan"))
8500                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8501         else if (!strcmp(res->tunnel_type, "nvgre"))
8502                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8503         else if (!strcmp(res->tunnel_type, "ipingre"))
8504                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8505         else {
8506                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8507                 return;
8508         }
8509
8510         tunnel_filter_conf.tenant_id = res->tenant_id;
8511         tunnel_filter_conf.queue_id = res->queue_num;
8512         if (!strcmp(res->what, "add"))
8513                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8514                                         RTE_ETH_FILTER_TUNNEL,
8515                                         RTE_ETH_FILTER_ADD,
8516                                         &tunnel_filter_conf);
8517         else
8518                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8519                                         RTE_ETH_FILTER_TUNNEL,
8520                                         RTE_ETH_FILTER_DELETE,
8521                                         &tunnel_filter_conf);
8522         if (ret < 0)
8523                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8524                                 strerror(-ret));
8525
8526 }
8527 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8528         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8529         cmd, "tunnel_filter");
8530 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8531         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8532         what, "add#rm");
8533 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8534         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8535         port_id, UINT16);
8536 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8537         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8538         outer_mac);
8539 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8540         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8541         inner_mac);
8542 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8543         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8544         inner_vlan, UINT16);
8545 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8546         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8547         ip_value);
8548 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8549         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8550         tunnel_type, "vxlan#nvgre#ipingre");
8551
8552 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8553         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8554         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8555                 "imac#omac-imac-tenid");
8556 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8557         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8558         tenant_id, UINT32);
8559 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8560         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8561         queue_num, UINT16);
8562
8563 cmdline_parse_inst_t cmd_tunnel_filter = {
8564         .f = cmd_tunnel_filter_parsed,
8565         .data = (void *)0,
8566         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8567                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8568                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8569                 "<queue_id>: Add/Rm tunnel filter of a port",
8570         .tokens = {
8571                 (void *)&cmd_tunnel_filter_cmd,
8572                 (void *)&cmd_tunnel_filter_what,
8573                 (void *)&cmd_tunnel_filter_port_id,
8574                 (void *)&cmd_tunnel_filter_outer_mac,
8575                 (void *)&cmd_tunnel_filter_inner_mac,
8576                 (void *)&cmd_tunnel_filter_ip_value,
8577                 (void *)&cmd_tunnel_filter_innner_vlan,
8578                 (void *)&cmd_tunnel_filter_tunnel_type,
8579                 (void *)&cmd_tunnel_filter_filter_type,
8580                 (void *)&cmd_tunnel_filter_tenant_id,
8581                 (void *)&cmd_tunnel_filter_queue_num,
8582                 NULL,
8583         },
8584 };
8585
8586 /* *** CONFIGURE TUNNEL UDP PORT *** */
8587 struct cmd_tunnel_udp_config {
8588         cmdline_fixed_string_t cmd;
8589         cmdline_fixed_string_t what;
8590         uint16_t udp_port;
8591         portid_t port_id;
8592 };
8593
8594 static void
8595 cmd_tunnel_udp_config_parsed(void *parsed_result,
8596                           __attribute__((unused)) struct cmdline *cl,
8597                           __attribute__((unused)) void *data)
8598 {
8599         struct cmd_tunnel_udp_config *res = parsed_result;
8600         struct rte_eth_udp_tunnel tunnel_udp;
8601         int ret;
8602
8603         tunnel_udp.udp_port = res->udp_port;
8604
8605         if (!strcmp(res->cmd, "rx_vxlan_port"))
8606                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8607
8608         if (!strcmp(res->what, "add"))
8609                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8610                                                       &tunnel_udp);
8611         else
8612                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8613                                                          &tunnel_udp);
8614
8615         if (ret < 0)
8616                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8617 }
8618
8619 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8620         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8621                                 cmd, "rx_vxlan_port");
8622 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8623         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8624                                 what, "add#rm");
8625 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8626         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8627                                 udp_port, UINT16);
8628 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8629         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8630                                 port_id, UINT16);
8631
8632 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8633         .f = cmd_tunnel_udp_config_parsed,
8634         .data = (void *)0,
8635         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8636                 "Add/Remove a tunneling UDP port filter",
8637         .tokens = {
8638                 (void *)&cmd_tunnel_udp_config_cmd,
8639                 (void *)&cmd_tunnel_udp_config_what,
8640                 (void *)&cmd_tunnel_udp_config_udp_port,
8641                 (void *)&cmd_tunnel_udp_config_port_id,
8642                 NULL,
8643         },
8644 };
8645
8646 /* *** GLOBAL CONFIG *** */
8647 struct cmd_global_config_result {
8648         cmdline_fixed_string_t cmd;
8649         portid_t port_id;
8650         cmdline_fixed_string_t cfg_type;
8651         uint8_t len;
8652 };
8653
8654 static void
8655 cmd_global_config_parsed(void *parsed_result,
8656                          __attribute__((unused)) struct cmdline *cl,
8657                          __attribute__((unused)) void *data)
8658 {
8659         struct cmd_global_config_result *res = parsed_result;
8660         struct rte_eth_global_cfg conf;
8661         int ret;
8662
8663         memset(&conf, 0, sizeof(conf));
8664         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8665         conf.cfg.gre_key_len = res->len;
8666         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8667                                       RTE_ETH_FILTER_SET, &conf);
8668         if (ret != 0)
8669                 printf("Global config error\n");
8670 }
8671
8672 cmdline_parse_token_string_t cmd_global_config_cmd =
8673         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8674                 "global_config");
8675 cmdline_parse_token_num_t cmd_global_config_port_id =
8676         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8677                                UINT16);
8678 cmdline_parse_token_string_t cmd_global_config_type =
8679         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8680                 cfg_type, "gre-key-len");
8681 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8682         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8683                 len, UINT8);
8684
8685 cmdline_parse_inst_t cmd_global_config = {
8686         .f = cmd_global_config_parsed,
8687         .data = (void *)NULL,
8688         .help_str = "global_config <port_id> gre-key-len <key_len>",
8689         .tokens = {
8690                 (void *)&cmd_global_config_cmd,
8691                 (void *)&cmd_global_config_port_id,
8692                 (void *)&cmd_global_config_type,
8693                 (void *)&cmd_global_config_gre_key_len,
8694                 NULL,
8695         },
8696 };
8697
8698 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8699 struct cmd_set_mirror_mask_result {
8700         cmdline_fixed_string_t set;
8701         cmdline_fixed_string_t port;
8702         portid_t port_id;
8703         cmdline_fixed_string_t mirror;
8704         uint8_t rule_id;
8705         cmdline_fixed_string_t what;
8706         cmdline_fixed_string_t value;
8707         cmdline_fixed_string_t dstpool;
8708         uint8_t dstpool_id;
8709         cmdline_fixed_string_t on;
8710 };
8711
8712 cmdline_parse_token_string_t cmd_mirror_mask_set =
8713         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8714                                 set, "set");
8715 cmdline_parse_token_string_t cmd_mirror_mask_port =
8716         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8717                                 port, "port");
8718 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8719         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8720                                 port_id, UINT16);
8721 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8722         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8723                                 mirror, "mirror-rule");
8724 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8725         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8726                                 rule_id, UINT8);
8727 cmdline_parse_token_string_t cmd_mirror_mask_what =
8728         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8729                                 what, "pool-mirror-up#pool-mirror-down"
8730                                       "#vlan-mirror");
8731 cmdline_parse_token_string_t cmd_mirror_mask_value =
8732         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8733                                 value, NULL);
8734 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8735         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8736                                 dstpool, "dst-pool");
8737 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8738         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8739                                 dstpool_id, UINT8);
8740 cmdline_parse_token_string_t cmd_mirror_mask_on =
8741         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8742                                 on, "on#off");
8743
8744 static void
8745 cmd_set_mirror_mask_parsed(void *parsed_result,
8746                        __attribute__((unused)) struct cmdline *cl,
8747                        __attribute__((unused)) void *data)
8748 {
8749         int ret,nb_item,i;
8750         struct cmd_set_mirror_mask_result *res = parsed_result;
8751         struct rte_eth_mirror_conf mr_conf;
8752
8753         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8754
8755         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8756
8757         mr_conf.dst_pool = res->dstpool_id;
8758
8759         if (!strcmp(res->what, "pool-mirror-up")) {
8760                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8761                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8762         } else if (!strcmp(res->what, "pool-mirror-down")) {
8763                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8764                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8765         } else if (!strcmp(res->what, "vlan-mirror")) {
8766                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8767                 nb_item = parse_item_list(res->value, "vlan",
8768                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8769                 if (nb_item <= 0)
8770                         return;
8771
8772                 for (i = 0; i < nb_item; i++) {
8773                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8774                                 printf("Invalid vlan_id: must be < 4096\n");
8775                                 return;
8776                         }
8777
8778                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8779                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8780                 }
8781         }
8782
8783         if (!strcmp(res->on, "on"))
8784                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8785                                                 res->rule_id, 1);
8786         else
8787                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8788                                                 res->rule_id, 0);
8789         if (ret < 0)
8790                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8791 }
8792
8793 cmdline_parse_inst_t cmd_set_mirror_mask = {
8794                 .f = cmd_set_mirror_mask_parsed,
8795                 .data = NULL,
8796                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8797                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8798                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8799                 .tokens = {
8800                         (void *)&cmd_mirror_mask_set,
8801                         (void *)&cmd_mirror_mask_port,
8802                         (void *)&cmd_mirror_mask_portid,
8803                         (void *)&cmd_mirror_mask_mirror,
8804                         (void *)&cmd_mirror_mask_ruleid,
8805                         (void *)&cmd_mirror_mask_what,
8806                         (void *)&cmd_mirror_mask_value,
8807                         (void *)&cmd_mirror_mask_dstpool,
8808                         (void *)&cmd_mirror_mask_poolid,
8809                         (void *)&cmd_mirror_mask_on,
8810                         NULL,
8811                 },
8812 };
8813
8814 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8815 struct cmd_set_mirror_link_result {
8816         cmdline_fixed_string_t set;
8817         cmdline_fixed_string_t port;
8818         portid_t port_id;
8819         cmdline_fixed_string_t mirror;
8820         uint8_t rule_id;
8821         cmdline_fixed_string_t what;
8822         cmdline_fixed_string_t dstpool;
8823         uint8_t dstpool_id;
8824         cmdline_fixed_string_t on;
8825 };
8826
8827 cmdline_parse_token_string_t cmd_mirror_link_set =
8828         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8829                                  set, "set");
8830 cmdline_parse_token_string_t cmd_mirror_link_port =
8831         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8832                                 port, "port");
8833 cmdline_parse_token_num_t cmd_mirror_link_portid =
8834         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8835                                 port_id, UINT16);
8836 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8837         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8838                                 mirror, "mirror-rule");
8839 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8840         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8841                             rule_id, UINT8);
8842 cmdline_parse_token_string_t cmd_mirror_link_what =
8843         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8844                                 what, "uplink-mirror#downlink-mirror");
8845 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8846         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8847                                 dstpool, "dst-pool");
8848 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8849         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8850                                 dstpool_id, UINT8);
8851 cmdline_parse_token_string_t cmd_mirror_link_on =
8852         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8853                                 on, "on#off");
8854
8855 static void
8856 cmd_set_mirror_link_parsed(void *parsed_result,
8857                        __attribute__((unused)) struct cmdline *cl,
8858                        __attribute__((unused)) void *data)
8859 {
8860         int ret;
8861         struct cmd_set_mirror_link_result *res = parsed_result;
8862         struct rte_eth_mirror_conf mr_conf;
8863
8864         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8865         if (!strcmp(res->what, "uplink-mirror"))
8866                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8867         else
8868                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8869
8870         mr_conf.dst_pool = res->dstpool_id;
8871
8872         if (!strcmp(res->on, "on"))
8873                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8874                                                 res->rule_id, 1);
8875         else
8876                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8877                                                 res->rule_id, 0);
8878
8879         /* check the return value and print it if is < 0 */
8880         if (ret < 0)
8881                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8882
8883 }
8884
8885 cmdline_parse_inst_t cmd_set_mirror_link = {
8886                 .f = cmd_set_mirror_link_parsed,
8887                 .data = NULL,
8888                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8889                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8890                 .tokens = {
8891                         (void *)&cmd_mirror_link_set,
8892                         (void *)&cmd_mirror_link_port,
8893                         (void *)&cmd_mirror_link_portid,
8894                         (void *)&cmd_mirror_link_mirror,
8895                         (void *)&cmd_mirror_link_ruleid,
8896                         (void *)&cmd_mirror_link_what,
8897                         (void *)&cmd_mirror_link_dstpool,
8898                         (void *)&cmd_mirror_link_poolid,
8899                         (void *)&cmd_mirror_link_on,
8900                         NULL,
8901                 },
8902 };
8903
8904 /* *** RESET VM MIRROR RULE *** */
8905 struct cmd_rm_mirror_rule_result {
8906         cmdline_fixed_string_t reset;
8907         cmdline_fixed_string_t port;
8908         portid_t port_id;
8909         cmdline_fixed_string_t mirror;
8910         uint8_t rule_id;
8911 };
8912
8913 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8914         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8915                                  reset, "reset");
8916 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8917         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8918                                 port, "port");
8919 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8920         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8921                                 port_id, UINT16);
8922 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8923         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8924                                 mirror, "mirror-rule");
8925 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8926         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8927                                 rule_id, UINT8);
8928
8929 static void
8930 cmd_reset_mirror_rule_parsed(void *parsed_result,
8931                        __attribute__((unused)) struct cmdline *cl,
8932                        __attribute__((unused)) void *data)
8933 {
8934         int ret;
8935         struct cmd_set_mirror_link_result *res = parsed_result;
8936         /* check rule_id */
8937         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8938         if(ret < 0)
8939                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8940 }
8941
8942 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8943                 .f = cmd_reset_mirror_rule_parsed,
8944                 .data = NULL,
8945                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8946                 .tokens = {
8947                         (void *)&cmd_rm_mirror_rule_reset,
8948                         (void *)&cmd_rm_mirror_rule_port,
8949                         (void *)&cmd_rm_mirror_rule_portid,
8950                         (void *)&cmd_rm_mirror_rule_mirror,
8951                         (void *)&cmd_rm_mirror_rule_ruleid,
8952                         NULL,
8953                 },
8954 };
8955
8956 /* ******************************************************************************** */
8957
8958 struct cmd_dump_result {
8959         cmdline_fixed_string_t dump;
8960 };
8961
8962 static void
8963 dump_struct_sizes(void)
8964 {
8965 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8966         DUMP_SIZE(struct rte_mbuf);
8967         DUMP_SIZE(struct rte_mempool);
8968         DUMP_SIZE(struct rte_ring);
8969 #undef DUMP_SIZE
8970 }
8971
8972 static void cmd_dump_parsed(void *parsed_result,
8973                             __attribute__((unused)) struct cmdline *cl,
8974                             __attribute__((unused)) void *data)
8975 {
8976         struct cmd_dump_result *res = parsed_result;
8977
8978         if (!strcmp(res->dump, "dump_physmem"))
8979                 rte_dump_physmem_layout(stdout);
8980         else if (!strcmp(res->dump, "dump_memzone"))
8981                 rte_memzone_dump(stdout);
8982         else if (!strcmp(res->dump, "dump_struct_sizes"))
8983                 dump_struct_sizes();
8984         else if (!strcmp(res->dump, "dump_ring"))
8985                 rte_ring_list_dump(stdout);
8986         else if (!strcmp(res->dump, "dump_mempool"))
8987                 rte_mempool_list_dump(stdout);
8988         else if (!strcmp(res->dump, "dump_devargs"))
8989                 rte_devargs_dump(stdout);
8990         else if (!strcmp(res->dump, "dump_log_types"))
8991                 rte_log_dump(stdout);
8992 }
8993
8994 cmdline_parse_token_string_t cmd_dump_dump =
8995         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8996                 "dump_physmem#"
8997                 "dump_memzone#"
8998                 "dump_struct_sizes#"
8999                 "dump_ring#"
9000                 "dump_mempool#"
9001                 "dump_devargs#"
9002                 "dump_log_types");
9003
9004 cmdline_parse_inst_t cmd_dump = {
9005         .f = cmd_dump_parsed,  /* function to call */
9006         .data = NULL,      /* 2nd arg of func */
9007         .help_str = "Dump status",
9008         .tokens = {        /* token list, NULL terminated */
9009                 (void *)&cmd_dump_dump,
9010                 NULL,
9011         },
9012 };
9013
9014 /* ******************************************************************************** */
9015
9016 struct cmd_dump_one_result {
9017         cmdline_fixed_string_t dump;
9018         cmdline_fixed_string_t name;
9019 };
9020
9021 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9022                                 __attribute__((unused)) void *data)
9023 {
9024         struct cmd_dump_one_result *res = parsed_result;
9025
9026         if (!strcmp(res->dump, "dump_ring")) {
9027                 struct rte_ring *r;
9028                 r = rte_ring_lookup(res->name);
9029                 if (r == NULL) {
9030                         cmdline_printf(cl, "Cannot find ring\n");
9031                         return;
9032                 }
9033                 rte_ring_dump(stdout, r);
9034         } else if (!strcmp(res->dump, "dump_mempool")) {
9035                 struct rte_mempool *mp;
9036                 mp = rte_mempool_lookup(res->name);
9037                 if (mp == NULL) {
9038                         cmdline_printf(cl, "Cannot find mempool\n");
9039                         return;
9040                 }
9041                 rte_mempool_dump(stdout, mp);
9042         }
9043 }
9044
9045 cmdline_parse_token_string_t cmd_dump_one_dump =
9046         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9047                                  "dump_ring#dump_mempool");
9048
9049 cmdline_parse_token_string_t cmd_dump_one_name =
9050         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9051
9052 cmdline_parse_inst_t cmd_dump_one = {
9053         .f = cmd_dump_one_parsed,  /* function to call */
9054         .data = NULL,      /* 2nd arg of func */
9055         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9056         .tokens = {        /* token list, NULL terminated */
9057                 (void *)&cmd_dump_one_dump,
9058                 (void *)&cmd_dump_one_name,
9059                 NULL,
9060         },
9061 };
9062
9063 /* *** Add/Del syn filter *** */
9064 struct cmd_syn_filter_result {
9065         cmdline_fixed_string_t filter;
9066         portid_t port_id;
9067         cmdline_fixed_string_t ops;
9068         cmdline_fixed_string_t priority;
9069         cmdline_fixed_string_t high;
9070         cmdline_fixed_string_t queue;
9071         uint16_t queue_id;
9072 };
9073
9074 static void
9075 cmd_syn_filter_parsed(void *parsed_result,
9076                         __attribute__((unused)) struct cmdline *cl,
9077                         __attribute__((unused)) void *data)
9078 {
9079         struct cmd_syn_filter_result *res = parsed_result;
9080         struct rte_eth_syn_filter syn_filter;
9081         int ret = 0;
9082
9083         ret = rte_eth_dev_filter_supported(res->port_id,
9084                                         RTE_ETH_FILTER_SYN);
9085         if (ret < 0) {
9086                 printf("syn filter is not supported on port %u.\n",
9087                                 res->port_id);
9088                 return;
9089         }
9090
9091         memset(&syn_filter, 0, sizeof(syn_filter));
9092
9093         if (!strcmp(res->ops, "add")) {
9094                 if (!strcmp(res->high, "high"))
9095                         syn_filter.hig_pri = 1;
9096                 else
9097                         syn_filter.hig_pri = 0;
9098
9099                 syn_filter.queue = res->queue_id;
9100                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9101                                                 RTE_ETH_FILTER_SYN,
9102                                                 RTE_ETH_FILTER_ADD,
9103                                                 &syn_filter);
9104         } else
9105                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9106                                                 RTE_ETH_FILTER_SYN,
9107                                                 RTE_ETH_FILTER_DELETE,
9108                                                 &syn_filter);
9109
9110         if (ret < 0)
9111                 printf("syn filter programming error: (%s)\n",
9112                                 strerror(-ret));
9113 }
9114
9115 cmdline_parse_token_string_t cmd_syn_filter_filter =
9116         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9117         filter, "syn_filter");
9118 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9119         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9120         port_id, UINT16);
9121 cmdline_parse_token_string_t cmd_syn_filter_ops =
9122         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9123         ops, "add#del");
9124 cmdline_parse_token_string_t cmd_syn_filter_priority =
9125         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9126                                 priority, "priority");
9127 cmdline_parse_token_string_t cmd_syn_filter_high =
9128         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9129                                 high, "high#low");
9130 cmdline_parse_token_string_t cmd_syn_filter_queue =
9131         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9132                                 queue, "queue");
9133 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9134         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9135                                 queue_id, UINT16);
9136
9137 cmdline_parse_inst_t cmd_syn_filter = {
9138         .f = cmd_syn_filter_parsed,
9139         .data = NULL,
9140         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9141                 "<queue_id>: Add/Delete syn filter",
9142         .tokens = {
9143                 (void *)&cmd_syn_filter_filter,
9144                 (void *)&cmd_syn_filter_port_id,
9145                 (void *)&cmd_syn_filter_ops,
9146                 (void *)&cmd_syn_filter_priority,
9147                 (void *)&cmd_syn_filter_high,
9148                 (void *)&cmd_syn_filter_queue,
9149                 (void *)&cmd_syn_filter_queue_id,
9150                 NULL,
9151         },
9152 };
9153
9154 /* *** queue region set *** */
9155 struct cmd_queue_region_result {
9156         cmdline_fixed_string_t set;
9157         cmdline_fixed_string_t port;
9158         portid_t port_id;
9159         cmdline_fixed_string_t cmd;
9160         cmdline_fixed_string_t region;
9161         uint8_t  region_id;
9162         cmdline_fixed_string_t queue_start_index;
9163         uint8_t  queue_id;
9164         cmdline_fixed_string_t queue_num;
9165         uint8_t  queue_num_value;
9166 };
9167
9168 static void
9169 cmd_queue_region_parsed(void *parsed_result,
9170                         __attribute__((unused)) struct cmdline *cl,
9171                         __attribute__((unused)) void *data)
9172 {
9173         struct cmd_queue_region_result *res = parsed_result;
9174         int ret = -ENOTSUP;
9175 #ifdef RTE_LIBRTE_I40E_PMD
9176         struct rte_pmd_i40e_queue_region_conf region_conf;
9177         enum rte_pmd_i40e_queue_region_op op_type;
9178 #endif
9179
9180         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9181                 return;
9182
9183 #ifdef RTE_LIBRTE_I40E_PMD
9184         memset(&region_conf, 0, sizeof(region_conf));
9185         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9186         region_conf.region_id = res->region_id;
9187         region_conf.queue_num = res->queue_num_value;
9188         region_conf.queue_start_index = res->queue_id;
9189
9190         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9191                                 op_type, &region_conf);
9192 #endif
9193
9194         switch (ret) {
9195         case 0:
9196                 break;
9197         case -ENOTSUP:
9198                 printf("function not implemented or supported\n");
9199                 break;
9200         default:
9201                 printf("queue region config error: (%s)\n", strerror(-ret));
9202         }
9203 }
9204
9205 cmdline_parse_token_string_t cmd_queue_region_set =
9206 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9207                 set, "set");
9208 cmdline_parse_token_string_t cmd_queue_region_port =
9209         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9210 cmdline_parse_token_num_t cmd_queue_region_port_id =
9211         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9212                                 port_id, UINT16);
9213 cmdline_parse_token_string_t cmd_queue_region_cmd =
9214         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9215                                  cmd, "queue-region");
9216 cmdline_parse_token_string_t cmd_queue_region_id =
9217         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9218                                 region, "region_id");
9219 cmdline_parse_token_num_t cmd_queue_region_index =
9220         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9221                                 region_id, UINT8);
9222 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9223         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9224                                 queue_start_index, "queue_start_index");
9225 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9226         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9227                                 queue_id, UINT8);
9228 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9229         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9230                                 queue_num, "queue_num");
9231 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9232         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9233                                 queue_num_value, UINT8);
9234
9235 cmdline_parse_inst_t cmd_queue_region = {
9236         .f = cmd_queue_region_parsed,
9237         .data = NULL,
9238         .help_str = "set port <port_id> queue-region region_id <value> "
9239                 "queue_start_index <value> queue_num <value>: Set a queue region",
9240         .tokens = {
9241                 (void *)&cmd_queue_region_set,
9242                 (void *)&cmd_queue_region_port,
9243                 (void *)&cmd_queue_region_port_id,
9244                 (void *)&cmd_queue_region_cmd,
9245                 (void *)&cmd_queue_region_id,
9246                 (void *)&cmd_queue_region_index,
9247                 (void *)&cmd_queue_region_queue_start_index,
9248                 (void *)&cmd_queue_region_queue_id,
9249                 (void *)&cmd_queue_region_queue_num,
9250                 (void *)&cmd_queue_region_queue_num_value,
9251                 NULL,
9252         },
9253 };
9254
9255 /* *** queue region and flowtype set *** */
9256 struct cmd_region_flowtype_result {
9257         cmdline_fixed_string_t set;
9258         cmdline_fixed_string_t port;
9259         portid_t port_id;
9260         cmdline_fixed_string_t cmd;
9261         cmdline_fixed_string_t region;
9262         uint8_t  region_id;
9263         cmdline_fixed_string_t flowtype;
9264         uint8_t  flowtype_id;
9265 };
9266
9267 static void
9268 cmd_region_flowtype_parsed(void *parsed_result,
9269                         __attribute__((unused)) struct cmdline *cl,
9270                         __attribute__((unused)) void *data)
9271 {
9272         struct cmd_region_flowtype_result *res = parsed_result;
9273         int ret = -ENOTSUP;
9274 #ifdef RTE_LIBRTE_I40E_PMD
9275         struct rte_pmd_i40e_queue_region_conf region_conf;
9276         enum rte_pmd_i40e_queue_region_op op_type;
9277 #endif
9278
9279         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9280                 return;
9281
9282 #ifdef RTE_LIBRTE_I40E_PMD
9283         memset(&region_conf, 0, sizeof(region_conf));
9284
9285         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9286         region_conf.region_id = res->region_id;
9287         region_conf.hw_flowtype = res->flowtype_id;
9288
9289         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9290                         op_type, &region_conf);
9291 #endif
9292
9293         switch (ret) {
9294         case 0:
9295                 break;
9296         case -ENOTSUP:
9297                 printf("function not implemented or supported\n");
9298                 break;
9299         default:
9300                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9301         }
9302 }
9303
9304 cmdline_parse_token_string_t cmd_region_flowtype_set =
9305 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9306                                 set, "set");
9307 cmdline_parse_token_string_t cmd_region_flowtype_port =
9308         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9309                                 port, "port");
9310 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9311         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9312                                 port_id, UINT16);
9313 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9314         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9315                                 cmd, "queue-region");
9316 cmdline_parse_token_string_t cmd_region_flowtype_index =
9317         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9318                                 region, "region_id");
9319 cmdline_parse_token_num_t cmd_region_flowtype_id =
9320         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9321                                 region_id, UINT8);
9322 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9323         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9324                                 flowtype, "flowtype");
9325 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9326         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9327                                 flowtype_id, UINT8);
9328 cmdline_parse_inst_t cmd_region_flowtype = {
9329         .f = cmd_region_flowtype_parsed,
9330         .data = NULL,
9331         .help_str = "set port <port_id> queue-region region_id <value> "
9332                 "flowtype <value>: Set a flowtype region index",
9333         .tokens = {
9334                 (void *)&cmd_region_flowtype_set,
9335                 (void *)&cmd_region_flowtype_port,
9336                 (void *)&cmd_region_flowtype_port_index,
9337                 (void *)&cmd_region_flowtype_cmd,
9338                 (void *)&cmd_region_flowtype_index,
9339                 (void *)&cmd_region_flowtype_id,
9340                 (void *)&cmd_region_flowtype_flow_index,
9341                 (void *)&cmd_region_flowtype_flow_id,
9342                 NULL,
9343         },
9344 };
9345
9346 /* *** User Priority (UP) to queue region (region_id) set *** */
9347 struct cmd_user_priority_region_result {
9348         cmdline_fixed_string_t set;
9349         cmdline_fixed_string_t port;
9350         portid_t port_id;
9351         cmdline_fixed_string_t cmd;
9352         cmdline_fixed_string_t user_priority;
9353         uint8_t  user_priority_id;
9354         cmdline_fixed_string_t region;
9355         uint8_t  region_id;
9356 };
9357
9358 static void
9359 cmd_user_priority_region_parsed(void *parsed_result,
9360                         __attribute__((unused)) struct cmdline *cl,
9361                         __attribute__((unused)) void *data)
9362 {
9363         struct cmd_user_priority_region_result *res = parsed_result;
9364         int ret = -ENOTSUP;
9365 #ifdef RTE_LIBRTE_I40E_PMD
9366         struct rte_pmd_i40e_queue_region_conf region_conf;
9367         enum rte_pmd_i40e_queue_region_op op_type;
9368 #endif
9369
9370         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9371                 return;
9372
9373 #ifdef RTE_LIBRTE_I40E_PMD
9374         memset(&region_conf, 0, sizeof(region_conf));
9375         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9376         region_conf.user_priority = res->user_priority_id;
9377         region_conf.region_id = res->region_id;
9378
9379         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9380                                 op_type, &region_conf);
9381 #endif
9382
9383         switch (ret) {
9384         case 0:
9385                 break;
9386         case -ENOTSUP:
9387                 printf("function not implemented or supported\n");
9388                 break;
9389         default:
9390                 printf("user_priority region config error: (%s)\n",
9391                                 strerror(-ret));
9392         }
9393 }
9394
9395 cmdline_parse_token_string_t cmd_user_priority_region_set =
9396         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9397                                 set, "set");
9398 cmdline_parse_token_string_t cmd_user_priority_region_port =
9399         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9400                                 port, "port");
9401 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9402         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9403                                 port_id, UINT16);
9404 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9405         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9406                                 cmd, "queue-region");
9407 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9408         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9409                                 user_priority, "UP");
9410 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9411         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9412                                 user_priority_id, UINT8);
9413 cmdline_parse_token_string_t cmd_user_priority_region_region =
9414         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9415                                 region, "region_id");
9416 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9417         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9418                                 region_id, UINT8);
9419
9420 cmdline_parse_inst_t cmd_user_priority_region = {
9421         .f = cmd_user_priority_region_parsed,
9422         .data = NULL,
9423         .help_str = "set port <port_id> queue-region UP <value> "
9424                 "region_id <value>: Set the mapping of User Priority (UP) "
9425                 "to queue region (region_id) ",
9426         .tokens = {
9427                 (void *)&cmd_user_priority_region_set,
9428                 (void *)&cmd_user_priority_region_port,
9429                 (void *)&cmd_user_priority_region_port_index,
9430                 (void *)&cmd_user_priority_region_cmd,
9431                 (void *)&cmd_user_priority_region_UP,
9432                 (void *)&cmd_user_priority_region_UP_id,
9433                 (void *)&cmd_user_priority_region_region,
9434                 (void *)&cmd_user_priority_region_region_id,
9435                 NULL,
9436         },
9437 };
9438
9439 /* *** flush all queue region related configuration *** */
9440 struct cmd_flush_queue_region_result {
9441         cmdline_fixed_string_t set;
9442         cmdline_fixed_string_t port;
9443         portid_t port_id;
9444         cmdline_fixed_string_t cmd;
9445         cmdline_fixed_string_t flush;
9446         cmdline_fixed_string_t what;
9447 };
9448
9449 static void
9450 cmd_flush_queue_region_parsed(void *parsed_result,
9451                         __attribute__((unused)) struct cmdline *cl,
9452                         __attribute__((unused)) void *data)
9453 {
9454         struct cmd_flush_queue_region_result *res = parsed_result;
9455         int ret = -ENOTSUP;
9456 #ifdef RTE_LIBRTE_I40E_PMD
9457         struct rte_pmd_i40e_queue_region_conf region_conf;
9458         enum rte_pmd_i40e_queue_region_op op_type;
9459 #endif
9460
9461         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9462                 return;
9463
9464 #ifdef RTE_LIBRTE_I40E_PMD
9465         memset(&region_conf, 0, sizeof(region_conf));
9466
9467         if (strcmp(res->what, "on") == 0)
9468                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9469         else
9470                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9471
9472         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9473                                 op_type, &region_conf);
9474 #endif
9475
9476         switch (ret) {
9477         case 0:
9478                 break;
9479         case -ENOTSUP:
9480                 printf("function not implemented or supported\n");
9481                 break;
9482         default:
9483                 printf("queue region config flush error: (%s)\n",
9484                                 strerror(-ret));
9485         }
9486 }
9487
9488 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9489         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9490                                 set, "set");
9491 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9492         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9493                                 port, "port");
9494 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9495         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9496                                 port_id, UINT16);
9497 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9498         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9499                                 cmd, "queue-region");
9500 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9501         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9502                                 flush, "flush");
9503 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9504         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9505                                 what, "on#off");
9506
9507 cmdline_parse_inst_t cmd_flush_queue_region = {
9508         .f = cmd_flush_queue_region_parsed,
9509         .data = NULL,
9510         .help_str = "set port <port_id> queue-region flush on|off"
9511                 ": flush all queue region related configuration",
9512         .tokens = {
9513                 (void *)&cmd_flush_queue_region_set,
9514                 (void *)&cmd_flush_queue_region_port,
9515                 (void *)&cmd_flush_queue_region_port_index,
9516                 (void *)&cmd_flush_queue_region_cmd,
9517                 (void *)&cmd_flush_queue_region_flush,
9518                 (void *)&cmd_flush_queue_region_what,
9519                 NULL,
9520         },
9521 };
9522
9523 /* *** get all queue region related configuration info *** */
9524 struct cmd_show_queue_region_info {
9525         cmdline_fixed_string_t show;
9526         cmdline_fixed_string_t port;
9527         portid_t port_id;
9528         cmdline_fixed_string_t cmd;
9529 };
9530
9531 static void
9532 cmd_show_queue_region_info_parsed(void *parsed_result,
9533                         __attribute__((unused)) struct cmdline *cl,
9534                         __attribute__((unused)) void *data)
9535 {
9536         struct cmd_show_queue_region_info *res = parsed_result;
9537         int ret = -ENOTSUP;
9538 #ifdef RTE_LIBRTE_I40E_PMD
9539         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9540         enum rte_pmd_i40e_queue_region_op op_type;
9541 #endif
9542
9543         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9544                 return;
9545
9546 #ifdef RTE_LIBRTE_I40E_PMD
9547         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9548
9549         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9550
9551         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9552                                         op_type, &rte_pmd_regions);
9553
9554         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9555 #endif
9556
9557         switch (ret) {
9558         case 0:
9559                 break;
9560         case -ENOTSUP:
9561                 printf("function not implemented or supported\n");
9562                 break;
9563         default:
9564                 printf("queue region config info show error: (%s)\n",
9565                                 strerror(-ret));
9566         }
9567 }
9568
9569 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9570 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9571                                 show, "show");
9572 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9573         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9574                                 port, "port");
9575 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9576         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9577                                 port_id, UINT16);
9578 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9579         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9580                                 cmd, "queue-region");
9581
9582 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9583         .f = cmd_show_queue_region_info_parsed,
9584         .data = NULL,
9585         .help_str = "show port <port_id> queue-region"
9586                 ": show all queue region related configuration info",
9587         .tokens = {
9588                 (void *)&cmd_show_queue_region_info_get,
9589                 (void *)&cmd_show_queue_region_info_port,
9590                 (void *)&cmd_show_queue_region_info_port_index,
9591                 (void *)&cmd_show_queue_region_info_cmd,
9592                 NULL,
9593         },
9594 };
9595
9596 /* *** ADD/REMOVE A 2tuple FILTER *** */
9597 struct cmd_2tuple_filter_result {
9598         cmdline_fixed_string_t filter;
9599         portid_t port_id;
9600         cmdline_fixed_string_t ops;
9601         cmdline_fixed_string_t dst_port;
9602         uint16_t dst_port_value;
9603         cmdline_fixed_string_t protocol;
9604         uint8_t protocol_value;
9605         cmdline_fixed_string_t mask;
9606         uint8_t  mask_value;
9607         cmdline_fixed_string_t tcp_flags;
9608         uint8_t tcp_flags_value;
9609         cmdline_fixed_string_t priority;
9610         uint8_t  priority_value;
9611         cmdline_fixed_string_t queue;
9612         uint16_t  queue_id;
9613 };
9614
9615 static void
9616 cmd_2tuple_filter_parsed(void *parsed_result,
9617                         __attribute__((unused)) struct cmdline *cl,
9618                         __attribute__((unused)) void *data)
9619 {
9620         struct rte_eth_ntuple_filter filter;
9621         struct cmd_2tuple_filter_result *res = parsed_result;
9622         int ret = 0;
9623
9624         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9625         if (ret < 0) {
9626                 printf("ntuple filter is not supported on port %u.\n",
9627                         res->port_id);
9628                 return;
9629         }
9630
9631         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9632
9633         filter.flags = RTE_2TUPLE_FLAGS;
9634         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9635         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9636         filter.proto = res->protocol_value;
9637         filter.priority = res->priority_value;
9638         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9639                 printf("nonzero tcp_flags is only meaningful"
9640                         " when protocol is TCP.\n");
9641                 return;
9642         }
9643         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9644                 printf("invalid TCP flags.\n");
9645                 return;
9646         }
9647
9648         if (res->tcp_flags_value != 0) {
9649                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9650                 filter.tcp_flags = res->tcp_flags_value;
9651         }
9652
9653         /* need convert to big endian. */
9654         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9655         filter.queue = res->queue_id;
9656
9657         if (!strcmp(res->ops, "add"))
9658                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9659                                 RTE_ETH_FILTER_NTUPLE,
9660                                 RTE_ETH_FILTER_ADD,
9661                                 &filter);
9662         else
9663                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9664                                 RTE_ETH_FILTER_NTUPLE,
9665                                 RTE_ETH_FILTER_DELETE,
9666                                 &filter);
9667         if (ret < 0)
9668                 printf("2tuple filter programming error: (%s)\n",
9669                         strerror(-ret));
9670
9671 }
9672
9673 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9674         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9675                                  filter, "2tuple_filter");
9676 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9677         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9678                                 port_id, UINT16);
9679 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9680         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9681                                  ops, "add#del");
9682 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9683         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9684                                 dst_port, "dst_port");
9685 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9686         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9687                                 dst_port_value, UINT16);
9688 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9689         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9690                                 protocol, "protocol");
9691 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9692         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9693                                 protocol_value, UINT8);
9694 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9695         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9696                                 mask, "mask");
9697 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9698         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9699                                 mask_value, INT8);
9700 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9701         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9702                                 tcp_flags, "tcp_flags");
9703 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9704         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9705                                 tcp_flags_value, UINT8);
9706 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9707         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9708                                 priority, "priority");
9709 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9710         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9711                                 priority_value, UINT8);
9712 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9713         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9714                                 queue, "queue");
9715 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9716         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9717                                 queue_id, UINT16);
9718
9719 cmdline_parse_inst_t cmd_2tuple_filter = {
9720         .f = cmd_2tuple_filter_parsed,
9721         .data = NULL,
9722         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9723                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9724                 "<queue_id>: Add a 2tuple filter",
9725         .tokens = {
9726                 (void *)&cmd_2tuple_filter_filter,
9727                 (void *)&cmd_2tuple_filter_port_id,
9728                 (void *)&cmd_2tuple_filter_ops,
9729                 (void *)&cmd_2tuple_filter_dst_port,
9730                 (void *)&cmd_2tuple_filter_dst_port_value,
9731                 (void *)&cmd_2tuple_filter_protocol,
9732                 (void *)&cmd_2tuple_filter_protocol_value,
9733                 (void *)&cmd_2tuple_filter_mask,
9734                 (void *)&cmd_2tuple_filter_mask_value,
9735                 (void *)&cmd_2tuple_filter_tcp_flags,
9736                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9737                 (void *)&cmd_2tuple_filter_priority,
9738                 (void *)&cmd_2tuple_filter_priority_value,
9739                 (void *)&cmd_2tuple_filter_queue,
9740                 (void *)&cmd_2tuple_filter_queue_id,
9741                 NULL,
9742         },
9743 };
9744
9745 /* *** ADD/REMOVE A 5tuple FILTER *** */
9746 struct cmd_5tuple_filter_result {
9747         cmdline_fixed_string_t filter;
9748         portid_t port_id;
9749         cmdline_fixed_string_t ops;
9750         cmdline_fixed_string_t dst_ip;
9751         cmdline_ipaddr_t dst_ip_value;
9752         cmdline_fixed_string_t src_ip;
9753         cmdline_ipaddr_t src_ip_value;
9754         cmdline_fixed_string_t dst_port;
9755         uint16_t dst_port_value;
9756         cmdline_fixed_string_t src_port;
9757         uint16_t src_port_value;
9758         cmdline_fixed_string_t protocol;
9759         uint8_t protocol_value;
9760         cmdline_fixed_string_t mask;
9761         uint8_t  mask_value;
9762         cmdline_fixed_string_t tcp_flags;
9763         uint8_t tcp_flags_value;
9764         cmdline_fixed_string_t priority;
9765         uint8_t  priority_value;
9766         cmdline_fixed_string_t queue;
9767         uint16_t  queue_id;
9768 };
9769
9770 static void
9771 cmd_5tuple_filter_parsed(void *parsed_result,
9772                         __attribute__((unused)) struct cmdline *cl,
9773                         __attribute__((unused)) void *data)
9774 {
9775         struct rte_eth_ntuple_filter filter;
9776         struct cmd_5tuple_filter_result *res = parsed_result;
9777         int ret = 0;
9778
9779         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9780         if (ret < 0) {
9781                 printf("ntuple filter is not supported on port %u.\n",
9782                         res->port_id);
9783                 return;
9784         }
9785
9786         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9787
9788         filter.flags = RTE_5TUPLE_FLAGS;
9789         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9790         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9791         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9792         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9793         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9794         filter.proto = res->protocol_value;
9795         filter.priority = res->priority_value;
9796         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9797                 printf("nonzero tcp_flags is only meaningful"
9798                         " when protocol is TCP.\n");
9799                 return;
9800         }
9801         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9802                 printf("invalid TCP flags.\n");
9803                 return;
9804         }
9805
9806         if (res->tcp_flags_value != 0) {
9807                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9808                 filter.tcp_flags = res->tcp_flags_value;
9809         }
9810
9811         if (res->dst_ip_value.family == AF_INET)
9812                 /* no need to convert, already big endian. */
9813                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9814         else {
9815                 if (filter.dst_ip_mask == 0) {
9816                         printf("can not support ipv6 involved compare.\n");
9817                         return;
9818                 }
9819                 filter.dst_ip = 0;
9820         }
9821
9822         if (res->src_ip_value.family == AF_INET)
9823                 /* no need to convert, already big endian. */
9824                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9825         else {
9826                 if (filter.src_ip_mask == 0) {
9827                         printf("can not support ipv6 involved compare.\n");
9828                         return;
9829                 }
9830                 filter.src_ip = 0;
9831         }
9832         /* need convert to big endian. */
9833         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9834         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9835         filter.queue = res->queue_id;
9836
9837         if (!strcmp(res->ops, "add"))
9838                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9839                                 RTE_ETH_FILTER_NTUPLE,
9840                                 RTE_ETH_FILTER_ADD,
9841                                 &filter);
9842         else
9843                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9844                                 RTE_ETH_FILTER_NTUPLE,
9845                                 RTE_ETH_FILTER_DELETE,
9846                                 &filter);
9847         if (ret < 0)
9848                 printf("5tuple filter programming error: (%s)\n",
9849                         strerror(-ret));
9850 }
9851
9852 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9853         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9854                                  filter, "5tuple_filter");
9855 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9856         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9857                                 port_id, UINT16);
9858 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9859         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9860                                  ops, "add#del");
9861 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9862         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9863                                 dst_ip, "dst_ip");
9864 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9865         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9866                                 dst_ip_value);
9867 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9868         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9869                                 src_ip, "src_ip");
9870 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9871         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9872                                 src_ip_value);
9873 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9874         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9875                                 dst_port, "dst_port");
9876 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9877         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9878                                 dst_port_value, UINT16);
9879 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9880         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9881                                 src_port, "src_port");
9882 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9883         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9884                                 src_port_value, UINT16);
9885 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9886         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9887                                 protocol, "protocol");
9888 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9889         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9890                                 protocol_value, UINT8);
9891 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9892         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9893                                 mask, "mask");
9894 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9895         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9896                                 mask_value, INT8);
9897 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9898         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9899                                 tcp_flags, "tcp_flags");
9900 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9901         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9902                                 tcp_flags_value, UINT8);
9903 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9904         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9905                                 priority, "priority");
9906 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9907         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9908                                 priority_value, UINT8);
9909 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9910         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9911                                 queue, "queue");
9912 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9913         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9914                                 queue_id, UINT16);
9915
9916 cmdline_parse_inst_t cmd_5tuple_filter = {
9917         .f = cmd_5tuple_filter_parsed,
9918         .data = NULL,
9919         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9920                 "src_ip <value> dst_port <value> src_port <value> "
9921                 "protocol <value>  mask <value> tcp_flags <value> "
9922                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9923         .tokens = {
9924                 (void *)&cmd_5tuple_filter_filter,
9925                 (void *)&cmd_5tuple_filter_port_id,
9926                 (void *)&cmd_5tuple_filter_ops,
9927                 (void *)&cmd_5tuple_filter_dst_ip,
9928                 (void *)&cmd_5tuple_filter_dst_ip_value,
9929                 (void *)&cmd_5tuple_filter_src_ip,
9930                 (void *)&cmd_5tuple_filter_src_ip_value,
9931                 (void *)&cmd_5tuple_filter_dst_port,
9932                 (void *)&cmd_5tuple_filter_dst_port_value,
9933                 (void *)&cmd_5tuple_filter_src_port,
9934                 (void *)&cmd_5tuple_filter_src_port_value,
9935                 (void *)&cmd_5tuple_filter_protocol,
9936                 (void *)&cmd_5tuple_filter_protocol_value,
9937                 (void *)&cmd_5tuple_filter_mask,
9938                 (void *)&cmd_5tuple_filter_mask_value,
9939                 (void *)&cmd_5tuple_filter_tcp_flags,
9940                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9941                 (void *)&cmd_5tuple_filter_priority,
9942                 (void *)&cmd_5tuple_filter_priority_value,
9943                 (void *)&cmd_5tuple_filter_queue,
9944                 (void *)&cmd_5tuple_filter_queue_id,
9945                 NULL,
9946         },
9947 };
9948
9949 /* *** ADD/REMOVE A flex FILTER *** */
9950 struct cmd_flex_filter_result {
9951         cmdline_fixed_string_t filter;
9952         cmdline_fixed_string_t ops;
9953         portid_t port_id;
9954         cmdline_fixed_string_t len;
9955         uint8_t len_value;
9956         cmdline_fixed_string_t bytes;
9957         cmdline_fixed_string_t bytes_value;
9958         cmdline_fixed_string_t mask;
9959         cmdline_fixed_string_t mask_value;
9960         cmdline_fixed_string_t priority;
9961         uint8_t priority_value;
9962         cmdline_fixed_string_t queue;
9963         uint16_t queue_id;
9964 };
9965
9966 static int xdigit2val(unsigned char c)
9967 {
9968         int val;
9969         if (isdigit(c))
9970                 val = c - '0';
9971         else if (isupper(c))
9972                 val = c - 'A' + 10;
9973         else
9974                 val = c - 'a' + 10;
9975         return val;
9976 }
9977
9978 static void
9979 cmd_flex_filter_parsed(void *parsed_result,
9980                           __attribute__((unused)) struct cmdline *cl,
9981                           __attribute__((unused)) void *data)
9982 {
9983         int ret = 0;
9984         struct rte_eth_flex_filter filter;
9985         struct cmd_flex_filter_result *res = parsed_result;
9986         char *bytes_ptr, *mask_ptr;
9987         uint16_t len, i, j = 0;
9988         char c;
9989         int val;
9990         uint8_t byte = 0;
9991
9992         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9993                 printf("the len exceed the max length 128\n");
9994                 return;
9995         }
9996         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9997         filter.len = res->len_value;
9998         filter.priority = res->priority_value;
9999         filter.queue = res->queue_id;
10000         bytes_ptr = res->bytes_value;
10001         mask_ptr = res->mask_value;
10002
10003          /* translate bytes string to array. */
10004         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10005                 (bytes_ptr[1] == 'X')))
10006                 bytes_ptr += 2;
10007         len = strnlen(bytes_ptr, res->len_value * 2);
10008         if (len == 0 || (len % 8 != 0)) {
10009                 printf("please check len and bytes input\n");
10010                 return;
10011         }
10012         for (i = 0; i < len; i++) {
10013                 c = bytes_ptr[i];
10014                 if (isxdigit(c) == 0) {
10015                         /* invalid characters. */
10016                         printf("invalid input\n");
10017                         return;
10018                 }
10019                 val = xdigit2val(c);
10020                 if (i % 2) {
10021                         byte |= val;
10022                         filter.bytes[j] = byte;
10023                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10024                         j++;
10025                         byte = 0;
10026                 } else
10027                         byte |= val << 4;
10028         }
10029         printf("\n");
10030          /* translate mask string to uint8_t array. */
10031         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10032                 (mask_ptr[1] == 'X')))
10033                 mask_ptr += 2;
10034         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10035         if (len == 0) {
10036                 printf("invalid input\n");
10037                 return;
10038         }
10039         j = 0;
10040         byte = 0;
10041         for (i = 0; i < len; i++) {
10042                 c = mask_ptr[i];
10043                 if (isxdigit(c) == 0) {
10044                         /* invalid characters. */
10045                         printf("invalid input\n");
10046                         return;
10047                 }
10048                 val = xdigit2val(c);
10049                 if (i % 2) {
10050                         byte |= val;
10051                         filter.mask[j] = byte;
10052                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10053                         j++;
10054                         byte = 0;
10055                 } else
10056                         byte |= val << 4;
10057         }
10058         printf("\n");
10059
10060         if (!strcmp(res->ops, "add"))
10061                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10062                                 RTE_ETH_FILTER_FLEXIBLE,
10063                                 RTE_ETH_FILTER_ADD,
10064                                 &filter);
10065         else
10066                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10067                                 RTE_ETH_FILTER_FLEXIBLE,
10068                                 RTE_ETH_FILTER_DELETE,
10069                                 &filter);
10070
10071         if (ret < 0)
10072                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10073 }
10074
10075 cmdline_parse_token_string_t cmd_flex_filter_filter =
10076         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10077                                 filter, "flex_filter");
10078 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10079         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10080                                 port_id, UINT16);
10081 cmdline_parse_token_string_t cmd_flex_filter_ops =
10082         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10083                                 ops, "add#del");
10084 cmdline_parse_token_string_t cmd_flex_filter_len =
10085         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10086                                 len, "len");
10087 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10088         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10089                                 len_value, UINT8);
10090 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10091         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10092                                 bytes, "bytes");
10093 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10094         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10095                                 bytes_value, NULL);
10096 cmdline_parse_token_string_t cmd_flex_filter_mask =
10097         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10098                                 mask, "mask");
10099 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10100         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10101                                 mask_value, NULL);
10102 cmdline_parse_token_string_t cmd_flex_filter_priority =
10103         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10104                                 priority, "priority");
10105 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10106         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10107                                 priority_value, UINT8);
10108 cmdline_parse_token_string_t cmd_flex_filter_queue =
10109         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10110                                 queue, "queue");
10111 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10112         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10113                                 queue_id, UINT16);
10114 cmdline_parse_inst_t cmd_flex_filter = {
10115         .f = cmd_flex_filter_parsed,
10116         .data = NULL,
10117         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10118                 "<value> mask <value> priority <value> queue <queue_id>: "
10119                 "Add/Del a flex filter",
10120         .tokens = {
10121                 (void *)&cmd_flex_filter_filter,
10122                 (void *)&cmd_flex_filter_port_id,
10123                 (void *)&cmd_flex_filter_ops,
10124                 (void *)&cmd_flex_filter_len,
10125                 (void *)&cmd_flex_filter_len_value,
10126                 (void *)&cmd_flex_filter_bytes,
10127                 (void *)&cmd_flex_filter_bytes_value,
10128                 (void *)&cmd_flex_filter_mask,
10129                 (void *)&cmd_flex_filter_mask_value,
10130                 (void *)&cmd_flex_filter_priority,
10131                 (void *)&cmd_flex_filter_priority_value,
10132                 (void *)&cmd_flex_filter_queue,
10133                 (void *)&cmd_flex_filter_queue_id,
10134                 NULL,
10135         },
10136 };
10137
10138 /* *** Filters Control *** */
10139
10140 /* *** deal with ethertype filter *** */
10141 struct cmd_ethertype_filter_result {
10142         cmdline_fixed_string_t filter;
10143         portid_t port_id;
10144         cmdline_fixed_string_t ops;
10145         cmdline_fixed_string_t mac;
10146         struct ether_addr mac_addr;
10147         cmdline_fixed_string_t ethertype;
10148         uint16_t ethertype_value;
10149         cmdline_fixed_string_t drop;
10150         cmdline_fixed_string_t queue;
10151         uint16_t  queue_id;
10152 };
10153
10154 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10155         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10156                                  filter, "ethertype_filter");
10157 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10158         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10159                               port_id, UINT16);
10160 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10161         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10162                                  ops, "add#del");
10163 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10164         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10165                                  mac, "mac_addr#mac_ignr");
10166 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10167         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10168                                      mac_addr);
10169 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10170         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10171                                  ethertype, "ethertype");
10172 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10173         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10174                               ethertype_value, UINT16);
10175 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10176         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10177                                  drop, "drop#fwd");
10178 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10179         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10180                                  queue, "queue");
10181 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10182         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10183                               queue_id, UINT16);
10184
10185 static void
10186 cmd_ethertype_filter_parsed(void *parsed_result,
10187                           __attribute__((unused)) struct cmdline *cl,
10188                           __attribute__((unused)) void *data)
10189 {
10190         struct cmd_ethertype_filter_result *res = parsed_result;
10191         struct rte_eth_ethertype_filter filter;
10192         int ret = 0;
10193
10194         ret = rte_eth_dev_filter_supported(res->port_id,
10195                         RTE_ETH_FILTER_ETHERTYPE);
10196         if (ret < 0) {
10197                 printf("ethertype filter is not supported on port %u.\n",
10198                         res->port_id);
10199                 return;
10200         }
10201
10202         memset(&filter, 0, sizeof(filter));
10203         if (!strcmp(res->mac, "mac_addr")) {
10204                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10205                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10206                         sizeof(struct ether_addr));
10207         }
10208         if (!strcmp(res->drop, "drop"))
10209                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10210         filter.ether_type = res->ethertype_value;
10211         filter.queue = res->queue_id;
10212
10213         if (!strcmp(res->ops, "add"))
10214                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10215                                 RTE_ETH_FILTER_ETHERTYPE,
10216                                 RTE_ETH_FILTER_ADD,
10217                                 &filter);
10218         else
10219                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10220                                 RTE_ETH_FILTER_ETHERTYPE,
10221                                 RTE_ETH_FILTER_DELETE,
10222                                 &filter);
10223         if (ret < 0)
10224                 printf("ethertype filter programming error: (%s)\n",
10225                         strerror(-ret));
10226 }
10227
10228 cmdline_parse_inst_t cmd_ethertype_filter = {
10229         .f = cmd_ethertype_filter_parsed,
10230         .data = NULL,
10231         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10232                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10233                 "Add or delete an ethertype filter entry",
10234         .tokens = {
10235                 (void *)&cmd_ethertype_filter_filter,
10236                 (void *)&cmd_ethertype_filter_port_id,
10237                 (void *)&cmd_ethertype_filter_ops,
10238                 (void *)&cmd_ethertype_filter_mac,
10239                 (void *)&cmd_ethertype_filter_mac_addr,
10240                 (void *)&cmd_ethertype_filter_ethertype,
10241                 (void *)&cmd_ethertype_filter_ethertype_value,
10242                 (void *)&cmd_ethertype_filter_drop,
10243                 (void *)&cmd_ethertype_filter_queue,
10244                 (void *)&cmd_ethertype_filter_queue_id,
10245                 NULL,
10246         },
10247 };
10248
10249 /* *** deal with flow director filter *** */
10250 struct cmd_flow_director_result {
10251         cmdline_fixed_string_t flow_director_filter;
10252         portid_t port_id;
10253         cmdline_fixed_string_t mode;
10254         cmdline_fixed_string_t mode_value;
10255         cmdline_fixed_string_t ops;
10256         cmdline_fixed_string_t flow;
10257         cmdline_fixed_string_t flow_type;
10258         cmdline_fixed_string_t ether;
10259         uint16_t ether_type;
10260         cmdline_fixed_string_t src;
10261         cmdline_ipaddr_t ip_src;
10262         uint16_t port_src;
10263         cmdline_fixed_string_t dst;
10264         cmdline_ipaddr_t ip_dst;
10265         uint16_t port_dst;
10266         cmdline_fixed_string_t verify_tag;
10267         uint32_t verify_tag_value;
10268         cmdline_fixed_string_t tos;
10269         uint8_t tos_value;
10270         cmdline_fixed_string_t proto;
10271         uint8_t proto_value;
10272         cmdline_fixed_string_t ttl;
10273         uint8_t ttl_value;
10274         cmdline_fixed_string_t vlan;
10275         uint16_t vlan_value;
10276         cmdline_fixed_string_t flexbytes;
10277         cmdline_fixed_string_t flexbytes_value;
10278         cmdline_fixed_string_t pf_vf;
10279         cmdline_fixed_string_t drop;
10280         cmdline_fixed_string_t queue;
10281         uint16_t  queue_id;
10282         cmdline_fixed_string_t fd_id;
10283         uint32_t  fd_id_value;
10284         cmdline_fixed_string_t mac;
10285         struct ether_addr mac_addr;
10286         cmdline_fixed_string_t tunnel;
10287         cmdline_fixed_string_t tunnel_type;
10288         cmdline_fixed_string_t tunnel_id;
10289         uint32_t tunnel_id_value;
10290         cmdline_fixed_string_t packet;
10291         char filepath[];
10292 };
10293
10294 static inline int
10295 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10296 {
10297         char s[256];
10298         const char *p, *p0 = q_arg;
10299         char *end;
10300         unsigned long int_fld;
10301         char *str_fld[max_num];
10302         int i;
10303         unsigned size;
10304         int ret = -1;
10305
10306         p = strchr(p0, '(');
10307         if (p == NULL)
10308                 return -1;
10309         ++p;
10310         p0 = strchr(p, ')');
10311         if (p0 == NULL)
10312                 return -1;
10313
10314         size = p0 - p;
10315         if (size >= sizeof(s))
10316                 return -1;
10317
10318         snprintf(s, sizeof(s), "%.*s", size, p);
10319         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10320         if (ret < 0 || ret > max_num)
10321                 return -1;
10322         for (i = 0; i < ret; i++) {
10323                 errno = 0;
10324                 int_fld = strtoul(str_fld[i], &end, 0);
10325                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10326                         return -1;
10327                 flexbytes[i] = (uint8_t)int_fld;
10328         }
10329         return ret;
10330 }
10331
10332 static uint16_t
10333 str2flowtype(char *string)
10334 {
10335         uint8_t i = 0;
10336         static const struct {
10337                 char str[32];
10338                 uint16_t type;
10339         } flowtype_str[] = {
10340                 {"raw", RTE_ETH_FLOW_RAW},
10341                 {"ipv4", RTE_ETH_FLOW_IPV4},
10342                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10343                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10344                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10345                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10346                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10347                 {"ipv6", RTE_ETH_FLOW_IPV6},
10348                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10349                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10350                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10351                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10352                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10353                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10354         };
10355
10356         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10357                 if (!strcmp(flowtype_str[i].str, string))
10358                         return flowtype_str[i].type;
10359         }
10360
10361         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10362                 return (uint16_t)atoi(string);
10363
10364         return RTE_ETH_FLOW_UNKNOWN;
10365 }
10366
10367 static enum rte_eth_fdir_tunnel_type
10368 str2fdir_tunneltype(char *string)
10369 {
10370         uint8_t i = 0;
10371
10372         static const struct {
10373                 char str[32];
10374                 enum rte_eth_fdir_tunnel_type type;
10375         } tunneltype_str[] = {
10376                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10377                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10378         };
10379
10380         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10381                 if (!strcmp(tunneltype_str[i].str, string))
10382                         return tunneltype_str[i].type;
10383         }
10384         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10385 }
10386
10387 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10388 do { \
10389         if ((ip_addr).family == AF_INET) \
10390                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10391         else { \
10392                 printf("invalid parameter.\n"); \
10393                 return; \
10394         } \
10395 } while (0)
10396
10397 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10398 do { \
10399         if ((ip_addr).family == AF_INET6) \
10400                 rte_memcpy(&(ip), \
10401                                  &((ip_addr).addr.ipv6), \
10402                                  sizeof(struct in6_addr)); \
10403         else { \
10404                 printf("invalid parameter.\n"); \
10405                 return; \
10406         } \
10407 } while (0)
10408
10409 static void
10410 cmd_flow_director_filter_parsed(void *parsed_result,
10411                           __attribute__((unused)) struct cmdline *cl,
10412                           __attribute__((unused)) void *data)
10413 {
10414         struct cmd_flow_director_result *res = parsed_result;
10415         struct rte_eth_fdir_filter entry;
10416         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10417         char *end;
10418         unsigned long vf_id;
10419         int ret = 0;
10420
10421         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10422         if (ret < 0) {
10423                 printf("flow director is not supported on port %u.\n",
10424                         res->port_id);
10425                 return;
10426         }
10427         memset(flexbytes, 0, sizeof(flexbytes));
10428         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10429
10430         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10431                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10432                         printf("Please set mode to MAC-VLAN.\n");
10433                         return;
10434                 }
10435         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10436                 if (strcmp(res->mode_value, "Tunnel")) {
10437                         printf("Please set mode to Tunnel.\n");
10438                         return;
10439                 }
10440         } else {
10441                 if (!strcmp(res->mode_value, "raw")) {
10442 #ifdef RTE_LIBRTE_I40E_PMD
10443                         struct rte_pmd_i40e_flow_type_mapping
10444                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10445                         struct rte_pmd_i40e_pkt_template_conf conf;
10446                         uint16_t flow_type = str2flowtype(res->flow_type);
10447                         uint16_t i, port = res->port_id;
10448                         uint8_t add;
10449
10450                         memset(&conf, 0, sizeof(conf));
10451
10452                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10453                                 printf("Invalid flow type specified.\n");
10454                                 return;
10455                         }
10456                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10457                                                                  mapping);
10458                         if (ret)
10459                                 return;
10460                         if (mapping[flow_type].pctype == 0ULL) {
10461                                 printf("Invalid flow type specified.\n");
10462                                 return;
10463                         }
10464                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10465                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10466                                         conf.input.pctype = i;
10467                                         break;
10468                                 }
10469                         }
10470
10471                         conf.input.packet = open_file(res->filepath,
10472                                                 &conf.input.length);
10473                         if (!conf.input.packet)
10474                                 return;
10475                         if (!strcmp(res->drop, "drop"))
10476                                 conf.action.behavior =
10477                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10478                         else
10479                                 conf.action.behavior =
10480                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10481                         conf.action.report_status =
10482                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10483                         conf.action.rx_queue = res->queue_id;
10484                         conf.soft_id = res->fd_id_value;
10485                         add  = strcmp(res->ops, "del") ? 1 : 0;
10486                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10487                                                                         &conf,
10488                                                                         add);
10489                         if (ret < 0)
10490                                 printf("flow director config error: (%s)\n",
10491                                        strerror(-ret));
10492                         close_file(conf.input.packet);
10493 #endif
10494                         return;
10495                 } else if (strcmp(res->mode_value, "IP")) {
10496                         printf("Please set mode to IP or raw.\n");
10497                         return;
10498                 }
10499                 entry.input.flow_type = str2flowtype(res->flow_type);
10500         }
10501
10502         ret = parse_flexbytes(res->flexbytes_value,
10503                                         flexbytes,
10504                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10505         if (ret < 0) {
10506                 printf("error: Cannot parse flexbytes input.\n");
10507                 return;
10508         }
10509
10510         switch (entry.input.flow_type) {
10511         case RTE_ETH_FLOW_FRAG_IPV4:
10512         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10513                 entry.input.flow.ip4_flow.proto = res->proto_value;
10514                 /* fall-through */
10515         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10516         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10517                 IPV4_ADDR_TO_UINT(res->ip_dst,
10518                         entry.input.flow.ip4_flow.dst_ip);
10519                 IPV4_ADDR_TO_UINT(res->ip_src,
10520                         entry.input.flow.ip4_flow.src_ip);
10521                 entry.input.flow.ip4_flow.tos = res->tos_value;
10522                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10523                 /* need convert to big endian. */
10524                 entry.input.flow.udp4_flow.dst_port =
10525                                 rte_cpu_to_be_16(res->port_dst);
10526                 entry.input.flow.udp4_flow.src_port =
10527                                 rte_cpu_to_be_16(res->port_src);
10528                 break;
10529         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10530                 IPV4_ADDR_TO_UINT(res->ip_dst,
10531                         entry.input.flow.sctp4_flow.ip.dst_ip);
10532                 IPV4_ADDR_TO_UINT(res->ip_src,
10533                         entry.input.flow.sctp4_flow.ip.src_ip);
10534                 entry.input.flow.ip4_flow.tos = res->tos_value;
10535                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10536                 /* need convert to big endian. */
10537                 entry.input.flow.sctp4_flow.dst_port =
10538                                 rte_cpu_to_be_16(res->port_dst);
10539                 entry.input.flow.sctp4_flow.src_port =
10540                                 rte_cpu_to_be_16(res->port_src);
10541                 entry.input.flow.sctp4_flow.verify_tag =
10542                                 rte_cpu_to_be_32(res->verify_tag_value);
10543                 break;
10544         case RTE_ETH_FLOW_FRAG_IPV6:
10545         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10546                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10547                 /* fall-through */
10548         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10549         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10550                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10551                         entry.input.flow.ipv6_flow.dst_ip);
10552                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10553                         entry.input.flow.ipv6_flow.src_ip);
10554                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10555                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10556                 /* need convert to big endian. */
10557                 entry.input.flow.udp6_flow.dst_port =
10558                                 rte_cpu_to_be_16(res->port_dst);
10559                 entry.input.flow.udp6_flow.src_port =
10560                                 rte_cpu_to_be_16(res->port_src);
10561                 break;
10562         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10563                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10564                         entry.input.flow.sctp6_flow.ip.dst_ip);
10565                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10566                         entry.input.flow.sctp6_flow.ip.src_ip);
10567                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10568                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10569                 /* need convert to big endian. */
10570                 entry.input.flow.sctp6_flow.dst_port =
10571                                 rte_cpu_to_be_16(res->port_dst);
10572                 entry.input.flow.sctp6_flow.src_port =
10573                                 rte_cpu_to_be_16(res->port_src);
10574                 entry.input.flow.sctp6_flow.verify_tag =
10575                                 rte_cpu_to_be_32(res->verify_tag_value);
10576                 break;
10577         case RTE_ETH_FLOW_L2_PAYLOAD:
10578                 entry.input.flow.l2_flow.ether_type =
10579                         rte_cpu_to_be_16(res->ether_type);
10580                 break;
10581         default:
10582                 break;
10583         }
10584
10585         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10586                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10587                                  &res->mac_addr,
10588                                  sizeof(struct ether_addr));
10589
10590         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10591                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10592                                  &res->mac_addr,
10593                                  sizeof(struct ether_addr));
10594                 entry.input.flow.tunnel_flow.tunnel_type =
10595                         str2fdir_tunneltype(res->tunnel_type);
10596                 entry.input.flow.tunnel_flow.tunnel_id =
10597                         rte_cpu_to_be_32(res->tunnel_id_value);
10598         }
10599
10600         rte_memcpy(entry.input.flow_ext.flexbytes,
10601                    flexbytes,
10602                    RTE_ETH_FDIR_MAX_FLEXLEN);
10603
10604         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10605
10606         entry.action.flex_off = 0;  /*use 0 by default */
10607         if (!strcmp(res->drop, "drop"))
10608                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10609         else
10610                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10611
10612         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10613             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10614                 if (!strcmp(res->pf_vf, "pf"))
10615                         entry.input.flow_ext.is_vf = 0;
10616                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10617                         struct rte_eth_dev_info dev_info;
10618
10619                         memset(&dev_info, 0, sizeof(dev_info));
10620                         rte_eth_dev_info_get(res->port_id, &dev_info);
10621                         errno = 0;
10622                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10623                         if (errno != 0 || *end != '\0' ||
10624                             vf_id >= dev_info.max_vfs) {
10625                                 printf("invalid parameter %s.\n", res->pf_vf);
10626                                 return;
10627                         }
10628                         entry.input.flow_ext.is_vf = 1;
10629                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10630                 } else {
10631                         printf("invalid parameter %s.\n", res->pf_vf);
10632                         return;
10633                 }
10634         }
10635
10636         /* set to report FD ID by default */
10637         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10638         entry.action.rx_queue = res->queue_id;
10639         entry.soft_id = res->fd_id_value;
10640         if (!strcmp(res->ops, "add"))
10641                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10642                                              RTE_ETH_FILTER_ADD, &entry);
10643         else if (!strcmp(res->ops, "del"))
10644                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10645                                              RTE_ETH_FILTER_DELETE, &entry);
10646         else
10647                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10648                                              RTE_ETH_FILTER_UPDATE, &entry);
10649         if (ret < 0)
10650                 printf("flow director programming error: (%s)\n",
10651                         strerror(-ret));
10652 }
10653
10654 cmdline_parse_token_string_t cmd_flow_director_filter =
10655         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10656                                  flow_director_filter, "flow_director_filter");
10657 cmdline_parse_token_num_t cmd_flow_director_port_id =
10658         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10659                               port_id, UINT16);
10660 cmdline_parse_token_string_t cmd_flow_director_ops =
10661         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10662                                  ops, "add#del#update");
10663 cmdline_parse_token_string_t cmd_flow_director_flow =
10664         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10665                                  flow, "flow");
10666 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10667         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10668                 flow_type, NULL);
10669 cmdline_parse_token_string_t cmd_flow_director_ether =
10670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10671                                  ether, "ether");
10672 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10673         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10674                               ether_type, UINT16);
10675 cmdline_parse_token_string_t cmd_flow_director_src =
10676         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10677                                  src, "src");
10678 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10679         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10680                                  ip_src);
10681 cmdline_parse_token_num_t cmd_flow_director_port_src =
10682         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10683                               port_src, UINT16);
10684 cmdline_parse_token_string_t cmd_flow_director_dst =
10685         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10686                                  dst, "dst");
10687 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10688         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10689                                  ip_dst);
10690 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10691         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10692                               port_dst, UINT16);
10693 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10694         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10695                                   verify_tag, "verify_tag");
10696 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10697         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10698                               verify_tag_value, UINT32);
10699 cmdline_parse_token_string_t cmd_flow_director_tos =
10700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10701                                  tos, "tos");
10702 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10703         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10704                               tos_value, UINT8);
10705 cmdline_parse_token_string_t cmd_flow_director_proto =
10706         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10707                                  proto, "proto");
10708 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10709         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10710                               proto_value, UINT8);
10711 cmdline_parse_token_string_t cmd_flow_director_ttl =
10712         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10713                                  ttl, "ttl");
10714 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10715         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10716                               ttl_value, UINT8);
10717 cmdline_parse_token_string_t cmd_flow_director_vlan =
10718         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10719                                  vlan, "vlan");
10720 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10721         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10722                               vlan_value, UINT16);
10723 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10724         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10725                                  flexbytes, "flexbytes");
10726 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10727         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10728                               flexbytes_value, NULL);
10729 cmdline_parse_token_string_t cmd_flow_director_drop =
10730         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10731                                  drop, "drop#fwd");
10732 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10733         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10734                               pf_vf, NULL);
10735 cmdline_parse_token_string_t cmd_flow_director_queue =
10736         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10737                                  queue, "queue");
10738 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10739         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10740                               queue_id, UINT16);
10741 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10743                                  fd_id, "fd_id");
10744 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10745         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10746                               fd_id_value, UINT32);
10747
10748 cmdline_parse_token_string_t cmd_flow_director_mode =
10749         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10750                                  mode, "mode");
10751 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10752         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10753                                  mode_value, "IP");
10754 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10755         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10756                                  mode_value, "MAC-VLAN");
10757 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10758         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10759                                  mode_value, "Tunnel");
10760 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10761         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10762                                  mode_value, "raw");
10763 cmdline_parse_token_string_t cmd_flow_director_mac =
10764         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10765                                  mac, "mac");
10766 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10767         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10768                                     mac_addr);
10769 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10770         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10771                                  tunnel, "tunnel");
10772 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10773         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10774                                  tunnel_type, "NVGRE#VxLAN");
10775 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10776         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10777                                  tunnel_id, "tunnel-id");
10778 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10779         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10780                               tunnel_id_value, UINT32);
10781 cmdline_parse_token_string_t cmd_flow_director_packet =
10782         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10783                                  packet, "packet");
10784 cmdline_parse_token_string_t cmd_flow_director_filepath =
10785         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10786                                  filepath, NULL);
10787
10788 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10789         .f = cmd_flow_director_filter_parsed,
10790         .data = NULL,
10791         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10792                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10793                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10794                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10795                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10796                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10797                 "fd_id <fd_id_value>: "
10798                 "Add or delete an ip flow director entry on NIC",
10799         .tokens = {
10800                 (void *)&cmd_flow_director_filter,
10801                 (void *)&cmd_flow_director_port_id,
10802                 (void *)&cmd_flow_director_mode,
10803                 (void *)&cmd_flow_director_mode_ip,
10804                 (void *)&cmd_flow_director_ops,
10805                 (void *)&cmd_flow_director_flow,
10806                 (void *)&cmd_flow_director_flow_type,
10807                 (void *)&cmd_flow_director_src,
10808                 (void *)&cmd_flow_director_ip_src,
10809                 (void *)&cmd_flow_director_dst,
10810                 (void *)&cmd_flow_director_ip_dst,
10811                 (void *)&cmd_flow_director_tos,
10812                 (void *)&cmd_flow_director_tos_value,
10813                 (void *)&cmd_flow_director_proto,
10814                 (void *)&cmd_flow_director_proto_value,
10815                 (void *)&cmd_flow_director_ttl,
10816                 (void *)&cmd_flow_director_ttl_value,
10817                 (void *)&cmd_flow_director_vlan,
10818                 (void *)&cmd_flow_director_vlan_value,
10819                 (void *)&cmd_flow_director_flexbytes,
10820                 (void *)&cmd_flow_director_flexbytes_value,
10821                 (void *)&cmd_flow_director_drop,
10822                 (void *)&cmd_flow_director_pf_vf,
10823                 (void *)&cmd_flow_director_queue,
10824                 (void *)&cmd_flow_director_queue_id,
10825                 (void *)&cmd_flow_director_fd_id,
10826                 (void *)&cmd_flow_director_fd_id_value,
10827                 NULL,
10828         },
10829 };
10830
10831 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10832         .f = cmd_flow_director_filter_parsed,
10833         .data = NULL,
10834         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10835                 "director entry on NIC",
10836         .tokens = {
10837                 (void *)&cmd_flow_director_filter,
10838                 (void *)&cmd_flow_director_port_id,
10839                 (void *)&cmd_flow_director_mode,
10840                 (void *)&cmd_flow_director_mode_ip,
10841                 (void *)&cmd_flow_director_ops,
10842                 (void *)&cmd_flow_director_flow,
10843                 (void *)&cmd_flow_director_flow_type,
10844                 (void *)&cmd_flow_director_src,
10845                 (void *)&cmd_flow_director_ip_src,
10846                 (void *)&cmd_flow_director_port_src,
10847                 (void *)&cmd_flow_director_dst,
10848                 (void *)&cmd_flow_director_ip_dst,
10849                 (void *)&cmd_flow_director_port_dst,
10850                 (void *)&cmd_flow_director_tos,
10851                 (void *)&cmd_flow_director_tos_value,
10852                 (void *)&cmd_flow_director_ttl,
10853                 (void *)&cmd_flow_director_ttl_value,
10854                 (void *)&cmd_flow_director_vlan,
10855                 (void *)&cmd_flow_director_vlan_value,
10856                 (void *)&cmd_flow_director_flexbytes,
10857                 (void *)&cmd_flow_director_flexbytes_value,
10858                 (void *)&cmd_flow_director_drop,
10859                 (void *)&cmd_flow_director_pf_vf,
10860                 (void *)&cmd_flow_director_queue,
10861                 (void *)&cmd_flow_director_queue_id,
10862                 (void *)&cmd_flow_director_fd_id,
10863                 (void *)&cmd_flow_director_fd_id_value,
10864                 NULL,
10865         },
10866 };
10867
10868 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10869         .f = cmd_flow_director_filter_parsed,
10870         .data = NULL,
10871         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10872                 "director entry on NIC",
10873         .tokens = {
10874                 (void *)&cmd_flow_director_filter,
10875                 (void *)&cmd_flow_director_port_id,
10876                 (void *)&cmd_flow_director_mode,
10877                 (void *)&cmd_flow_director_mode_ip,
10878                 (void *)&cmd_flow_director_ops,
10879                 (void *)&cmd_flow_director_flow,
10880                 (void *)&cmd_flow_director_flow_type,
10881                 (void *)&cmd_flow_director_src,
10882                 (void *)&cmd_flow_director_ip_src,
10883                 (void *)&cmd_flow_director_port_src,
10884                 (void *)&cmd_flow_director_dst,
10885                 (void *)&cmd_flow_director_ip_dst,
10886                 (void *)&cmd_flow_director_port_dst,
10887                 (void *)&cmd_flow_director_verify_tag,
10888                 (void *)&cmd_flow_director_verify_tag_value,
10889                 (void *)&cmd_flow_director_tos,
10890                 (void *)&cmd_flow_director_tos_value,
10891                 (void *)&cmd_flow_director_ttl,
10892                 (void *)&cmd_flow_director_ttl_value,
10893                 (void *)&cmd_flow_director_vlan,
10894                 (void *)&cmd_flow_director_vlan_value,
10895                 (void *)&cmd_flow_director_flexbytes,
10896                 (void *)&cmd_flow_director_flexbytes_value,
10897                 (void *)&cmd_flow_director_drop,
10898                 (void *)&cmd_flow_director_pf_vf,
10899                 (void *)&cmd_flow_director_queue,
10900                 (void *)&cmd_flow_director_queue_id,
10901                 (void *)&cmd_flow_director_fd_id,
10902                 (void *)&cmd_flow_director_fd_id_value,
10903                 NULL,
10904         },
10905 };
10906
10907 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10908         .f = cmd_flow_director_filter_parsed,
10909         .data = NULL,
10910         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10911                 "director entry on NIC",
10912         .tokens = {
10913                 (void *)&cmd_flow_director_filter,
10914                 (void *)&cmd_flow_director_port_id,
10915                 (void *)&cmd_flow_director_mode,
10916                 (void *)&cmd_flow_director_mode_ip,
10917                 (void *)&cmd_flow_director_ops,
10918                 (void *)&cmd_flow_director_flow,
10919                 (void *)&cmd_flow_director_flow_type,
10920                 (void *)&cmd_flow_director_ether,
10921                 (void *)&cmd_flow_director_ether_type,
10922                 (void *)&cmd_flow_director_flexbytes,
10923                 (void *)&cmd_flow_director_flexbytes_value,
10924                 (void *)&cmd_flow_director_drop,
10925                 (void *)&cmd_flow_director_pf_vf,
10926                 (void *)&cmd_flow_director_queue,
10927                 (void *)&cmd_flow_director_queue_id,
10928                 (void *)&cmd_flow_director_fd_id,
10929                 (void *)&cmd_flow_director_fd_id_value,
10930                 NULL,
10931         },
10932 };
10933
10934 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10935         .f = cmd_flow_director_filter_parsed,
10936         .data = NULL,
10937         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10938                 "director entry on NIC",
10939         .tokens = {
10940                 (void *)&cmd_flow_director_filter,
10941                 (void *)&cmd_flow_director_port_id,
10942                 (void *)&cmd_flow_director_mode,
10943                 (void *)&cmd_flow_director_mode_mac_vlan,
10944                 (void *)&cmd_flow_director_ops,
10945                 (void *)&cmd_flow_director_mac,
10946                 (void *)&cmd_flow_director_mac_addr,
10947                 (void *)&cmd_flow_director_vlan,
10948                 (void *)&cmd_flow_director_vlan_value,
10949                 (void *)&cmd_flow_director_flexbytes,
10950                 (void *)&cmd_flow_director_flexbytes_value,
10951                 (void *)&cmd_flow_director_drop,
10952                 (void *)&cmd_flow_director_queue,
10953                 (void *)&cmd_flow_director_queue_id,
10954                 (void *)&cmd_flow_director_fd_id,
10955                 (void *)&cmd_flow_director_fd_id_value,
10956                 NULL,
10957         },
10958 };
10959
10960 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10961         .f = cmd_flow_director_filter_parsed,
10962         .data = NULL,
10963         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10964                 "director entry on NIC",
10965         .tokens = {
10966                 (void *)&cmd_flow_director_filter,
10967                 (void *)&cmd_flow_director_port_id,
10968                 (void *)&cmd_flow_director_mode,
10969                 (void *)&cmd_flow_director_mode_tunnel,
10970                 (void *)&cmd_flow_director_ops,
10971                 (void *)&cmd_flow_director_mac,
10972                 (void *)&cmd_flow_director_mac_addr,
10973                 (void *)&cmd_flow_director_vlan,
10974                 (void *)&cmd_flow_director_vlan_value,
10975                 (void *)&cmd_flow_director_tunnel,
10976                 (void *)&cmd_flow_director_tunnel_type,
10977                 (void *)&cmd_flow_director_tunnel_id,
10978                 (void *)&cmd_flow_director_tunnel_id_value,
10979                 (void *)&cmd_flow_director_flexbytes,
10980                 (void *)&cmd_flow_director_flexbytes_value,
10981                 (void *)&cmd_flow_director_drop,
10982                 (void *)&cmd_flow_director_queue,
10983                 (void *)&cmd_flow_director_queue_id,
10984                 (void *)&cmd_flow_director_fd_id,
10985                 (void *)&cmd_flow_director_fd_id_value,
10986                 NULL,
10987         },
10988 };
10989
10990 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10991         .f = cmd_flow_director_filter_parsed,
10992         .data = NULL,
10993         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10994                 "director entry on NIC",
10995         .tokens = {
10996                 (void *)&cmd_flow_director_filter,
10997                 (void *)&cmd_flow_director_port_id,
10998                 (void *)&cmd_flow_director_mode,
10999                 (void *)&cmd_flow_director_mode_raw,
11000                 (void *)&cmd_flow_director_ops,
11001                 (void *)&cmd_flow_director_flow,
11002                 (void *)&cmd_flow_director_flow_type,
11003                 (void *)&cmd_flow_director_drop,
11004                 (void *)&cmd_flow_director_queue,
11005                 (void *)&cmd_flow_director_queue_id,
11006                 (void *)&cmd_flow_director_fd_id,
11007                 (void *)&cmd_flow_director_fd_id_value,
11008                 (void *)&cmd_flow_director_packet,
11009                 (void *)&cmd_flow_director_filepath,
11010                 NULL,
11011         },
11012 };
11013
11014 struct cmd_flush_flow_director_result {
11015         cmdline_fixed_string_t flush_flow_director;
11016         portid_t port_id;
11017 };
11018
11019 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11020         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11021                                  flush_flow_director, "flush_flow_director");
11022 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11023         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11024                               port_id, UINT16);
11025
11026 static void
11027 cmd_flush_flow_director_parsed(void *parsed_result,
11028                           __attribute__((unused)) struct cmdline *cl,
11029                           __attribute__((unused)) void *data)
11030 {
11031         struct cmd_flow_director_result *res = parsed_result;
11032         int ret = 0;
11033
11034         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11035         if (ret < 0) {
11036                 printf("flow director is not supported on port %u.\n",
11037                         res->port_id);
11038                 return;
11039         }
11040
11041         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11042                         RTE_ETH_FILTER_FLUSH, NULL);
11043         if (ret < 0)
11044                 printf("flow director table flushing error: (%s)\n",
11045                         strerror(-ret));
11046 }
11047
11048 cmdline_parse_inst_t cmd_flush_flow_director = {
11049         .f = cmd_flush_flow_director_parsed,
11050         .data = NULL,
11051         .help_str = "flush_flow_director <port_id>: "
11052                 "Flush all flow director entries of a device on NIC",
11053         .tokens = {
11054                 (void *)&cmd_flush_flow_director_flush,
11055                 (void *)&cmd_flush_flow_director_port_id,
11056                 NULL,
11057         },
11058 };
11059
11060 /* *** deal with flow director mask *** */
11061 struct cmd_flow_director_mask_result {
11062         cmdline_fixed_string_t flow_director_mask;
11063         portid_t port_id;
11064         cmdline_fixed_string_t mode;
11065         cmdline_fixed_string_t mode_value;
11066         cmdline_fixed_string_t vlan;
11067         uint16_t vlan_mask;
11068         cmdline_fixed_string_t src_mask;
11069         cmdline_ipaddr_t ipv4_src;
11070         cmdline_ipaddr_t ipv6_src;
11071         uint16_t port_src;
11072         cmdline_fixed_string_t dst_mask;
11073         cmdline_ipaddr_t ipv4_dst;
11074         cmdline_ipaddr_t ipv6_dst;
11075         uint16_t port_dst;
11076         cmdline_fixed_string_t mac;
11077         uint8_t mac_addr_byte_mask;
11078         cmdline_fixed_string_t tunnel_id;
11079         uint32_t tunnel_id_mask;
11080         cmdline_fixed_string_t tunnel_type;
11081         uint8_t tunnel_type_mask;
11082 };
11083
11084 static void
11085 cmd_flow_director_mask_parsed(void *parsed_result,
11086                           __attribute__((unused)) struct cmdline *cl,
11087                           __attribute__((unused)) void *data)
11088 {
11089         struct cmd_flow_director_mask_result *res = parsed_result;
11090         struct rte_eth_fdir_masks *mask;
11091         struct rte_port *port;
11092
11093         port = &ports[res->port_id];
11094         /** Check if the port is not started **/
11095         if (port->port_status != RTE_PORT_STOPPED) {
11096                 printf("Please stop port %d first\n", res->port_id);
11097                 return;
11098         }
11099
11100         mask = &port->dev_conf.fdir_conf.mask;
11101
11102         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11103                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11104                         printf("Please set mode to MAC-VLAN.\n");
11105                         return;
11106                 }
11107
11108                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11109         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11110                 if (strcmp(res->mode_value, "Tunnel")) {
11111                         printf("Please set mode to Tunnel.\n");
11112                         return;
11113                 }
11114
11115                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11116                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11117                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11118                 mask->tunnel_type_mask = res->tunnel_type_mask;
11119         } else {
11120                 if (strcmp(res->mode_value, "IP")) {
11121                         printf("Please set mode to IP.\n");
11122                         return;
11123                 }
11124
11125                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11126                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11127                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11128                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11129                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11130                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11131                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11132         }
11133
11134         cmd_reconfig_device_queue(res->port_id, 1, 1);
11135 }
11136
11137 cmdline_parse_token_string_t cmd_flow_director_mask =
11138         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11139                                  flow_director_mask, "flow_director_mask");
11140 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11141         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11142                               port_id, UINT16);
11143 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11144         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11145                                  vlan, "vlan");
11146 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11147         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11148                               vlan_mask, UINT16);
11149 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11150         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11151                                  src_mask, "src_mask");
11152 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11153         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11154                                  ipv4_src);
11155 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11156         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11157                                  ipv6_src);
11158 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11159         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11160                               port_src, UINT16);
11161 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11162         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11163                                  dst_mask, "dst_mask");
11164 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11165         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11166                                  ipv4_dst);
11167 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11168         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11169                                  ipv6_dst);
11170 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11171         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11172                               port_dst, UINT16);
11173
11174 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11175         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11176                                  mode, "mode");
11177 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11178         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11179                                  mode_value, "IP");
11180 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11181         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11182                                  mode_value, "MAC-VLAN");
11183 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11184         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11185                                  mode_value, "Tunnel");
11186 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11187         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11188                                  mac, "mac");
11189 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11190         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11191                               mac_addr_byte_mask, UINT8);
11192 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11193         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11194                                  tunnel_type, "tunnel-type");
11195 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11196         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11197                               tunnel_type_mask, UINT8);
11198 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11199         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11200                                  tunnel_id, "tunnel-id");
11201 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11202         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11203                               tunnel_id_mask, UINT32);
11204
11205 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11206         .f = cmd_flow_director_mask_parsed,
11207         .data = NULL,
11208         .help_str = "flow_director_mask ... : "
11209                 "Set IP mode flow director's mask on NIC",
11210         .tokens = {
11211                 (void *)&cmd_flow_director_mask,
11212                 (void *)&cmd_flow_director_mask_port_id,
11213                 (void *)&cmd_flow_director_mask_mode,
11214                 (void *)&cmd_flow_director_mask_mode_ip,
11215                 (void *)&cmd_flow_director_mask_vlan,
11216                 (void *)&cmd_flow_director_mask_vlan_value,
11217                 (void *)&cmd_flow_director_mask_src,
11218                 (void *)&cmd_flow_director_mask_ipv4_src,
11219                 (void *)&cmd_flow_director_mask_ipv6_src,
11220                 (void *)&cmd_flow_director_mask_port_src,
11221                 (void *)&cmd_flow_director_mask_dst,
11222                 (void *)&cmd_flow_director_mask_ipv4_dst,
11223                 (void *)&cmd_flow_director_mask_ipv6_dst,
11224                 (void *)&cmd_flow_director_mask_port_dst,
11225                 NULL,
11226         },
11227 };
11228
11229 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11230         .f = cmd_flow_director_mask_parsed,
11231         .data = NULL,
11232         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11233                 "flow director's mask on NIC",
11234         .tokens = {
11235                 (void *)&cmd_flow_director_mask,
11236                 (void *)&cmd_flow_director_mask_port_id,
11237                 (void *)&cmd_flow_director_mask_mode,
11238                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11239                 (void *)&cmd_flow_director_mask_vlan,
11240                 (void *)&cmd_flow_director_mask_vlan_value,
11241                 NULL,
11242         },
11243 };
11244
11245 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11246         .f = cmd_flow_director_mask_parsed,
11247         .data = NULL,
11248         .help_str = "flow_director_mask ... : Set tunnel mode "
11249                 "flow director's mask on NIC",
11250         .tokens = {
11251                 (void *)&cmd_flow_director_mask,
11252                 (void *)&cmd_flow_director_mask_port_id,
11253                 (void *)&cmd_flow_director_mask_mode,
11254                 (void *)&cmd_flow_director_mask_mode_tunnel,
11255                 (void *)&cmd_flow_director_mask_vlan,
11256                 (void *)&cmd_flow_director_mask_vlan_value,
11257                 (void *)&cmd_flow_director_mask_mac,
11258                 (void *)&cmd_flow_director_mask_mac_value,
11259                 (void *)&cmd_flow_director_mask_tunnel_type,
11260                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11261                 (void *)&cmd_flow_director_mask_tunnel_id,
11262                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11263                 NULL,
11264         },
11265 };
11266
11267 /* *** deal with flow director mask on flexible payload *** */
11268 struct cmd_flow_director_flex_mask_result {
11269         cmdline_fixed_string_t flow_director_flexmask;
11270         portid_t port_id;
11271         cmdline_fixed_string_t flow;
11272         cmdline_fixed_string_t flow_type;
11273         cmdline_fixed_string_t mask;
11274 };
11275
11276 static void
11277 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11278                           __attribute__((unused)) struct cmdline *cl,
11279                           __attribute__((unused)) void *data)
11280 {
11281         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11282         struct rte_eth_fdir_info fdir_info;
11283         struct rte_eth_fdir_flex_mask flex_mask;
11284         struct rte_port *port;
11285         uint64_t flow_type_mask;
11286         uint16_t i;
11287         int ret;
11288
11289         port = &ports[res->port_id];
11290         /** Check if the port is not started **/
11291         if (port->port_status != RTE_PORT_STOPPED) {
11292                 printf("Please stop port %d first\n", res->port_id);
11293                 return;
11294         }
11295
11296         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11297         ret = parse_flexbytes(res->mask,
11298                         flex_mask.mask,
11299                         RTE_ETH_FDIR_MAX_FLEXLEN);
11300         if (ret < 0) {
11301                 printf("error: Cannot parse mask input.\n");
11302                 return;
11303         }
11304
11305         memset(&fdir_info, 0, sizeof(fdir_info));
11306         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11307                                 RTE_ETH_FILTER_INFO, &fdir_info);
11308         if (ret < 0) {
11309                 printf("Cannot get FDir filter info\n");
11310                 return;
11311         }
11312
11313         if (!strcmp(res->flow_type, "none")) {
11314                 /* means don't specify the flow type */
11315                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11316                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11317                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11318                                0, sizeof(struct rte_eth_fdir_flex_mask));
11319                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11320                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11321                                  &flex_mask,
11322                                  sizeof(struct rte_eth_fdir_flex_mask));
11323                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11324                 return;
11325         }
11326         flow_type_mask = fdir_info.flow_types_mask[0];
11327         if (!strcmp(res->flow_type, "all")) {
11328                 if (!flow_type_mask) {
11329                         printf("No flow type supported\n");
11330                         return;
11331                 }
11332                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11333                         if (flow_type_mask & (1ULL << i)) {
11334                                 flex_mask.flow_type = i;
11335                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11336                         }
11337                 }
11338                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11339                 return;
11340         }
11341         flex_mask.flow_type = str2flowtype(res->flow_type);
11342         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11343                 printf("Flow type %s not supported on port %d\n",
11344                                 res->flow_type, res->port_id);
11345                 return;
11346         }
11347         fdir_set_flex_mask(res->port_id, &flex_mask);
11348         cmd_reconfig_device_queue(res->port_id, 1, 1);
11349 }
11350
11351 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11352         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11353                                  flow_director_flexmask,
11354                                  "flow_director_flex_mask");
11355 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11356         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11357                               port_id, UINT16);
11358 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11359         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11360                                  flow, "flow");
11361 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11362         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11363                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11364                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11365 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11366         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11367                                  mask, NULL);
11368
11369 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11370         .f = cmd_flow_director_flex_mask_parsed,
11371         .data = NULL,
11372         .help_str = "flow_director_flex_mask ... : "
11373                 "Set flow director's flex mask on NIC",
11374         .tokens = {
11375                 (void *)&cmd_flow_director_flexmask,
11376                 (void *)&cmd_flow_director_flexmask_port_id,
11377                 (void *)&cmd_flow_director_flexmask_flow,
11378                 (void *)&cmd_flow_director_flexmask_flow_type,
11379                 (void *)&cmd_flow_director_flexmask_mask,
11380                 NULL,
11381         },
11382 };
11383
11384 /* *** deal with flow director flexible payload configuration *** */
11385 struct cmd_flow_director_flexpayload_result {
11386         cmdline_fixed_string_t flow_director_flexpayload;
11387         portid_t port_id;
11388         cmdline_fixed_string_t payload_layer;
11389         cmdline_fixed_string_t payload_cfg;
11390 };
11391
11392 static inline int
11393 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11394 {
11395         char s[256];
11396         const char *p, *p0 = q_arg;
11397         char *end;
11398         unsigned long int_fld;
11399         char *str_fld[max_num];
11400         int i;
11401         unsigned size;
11402         int ret = -1;
11403
11404         p = strchr(p0, '(');
11405         if (p == NULL)
11406                 return -1;
11407         ++p;
11408         p0 = strchr(p, ')');
11409         if (p0 == NULL)
11410                 return -1;
11411
11412         size = p0 - p;
11413         if (size >= sizeof(s))
11414                 return -1;
11415
11416         snprintf(s, sizeof(s), "%.*s", size, p);
11417         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11418         if (ret < 0 || ret > max_num)
11419                 return -1;
11420         for (i = 0; i < ret; i++) {
11421                 errno = 0;
11422                 int_fld = strtoul(str_fld[i], &end, 0);
11423                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11424                         return -1;
11425                 offsets[i] = (uint16_t)int_fld;
11426         }
11427         return ret;
11428 }
11429
11430 static void
11431 cmd_flow_director_flxpld_parsed(void *parsed_result,
11432                           __attribute__((unused)) struct cmdline *cl,
11433                           __attribute__((unused)) void *data)
11434 {
11435         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11436         struct rte_eth_flex_payload_cfg flex_cfg;
11437         struct rte_port *port;
11438         int ret = 0;
11439
11440         port = &ports[res->port_id];
11441         /** Check if the port is not started **/
11442         if (port->port_status != RTE_PORT_STOPPED) {
11443                 printf("Please stop port %d first\n", res->port_id);
11444                 return;
11445         }
11446
11447         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11448
11449         if (!strcmp(res->payload_layer, "raw"))
11450                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11451         else if (!strcmp(res->payload_layer, "l2"))
11452                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11453         else if (!strcmp(res->payload_layer, "l3"))
11454                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11455         else if (!strcmp(res->payload_layer, "l4"))
11456                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11457
11458         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11459                             RTE_ETH_FDIR_MAX_FLEXLEN);
11460         if (ret < 0) {
11461                 printf("error: Cannot parse flex payload input.\n");
11462                 return;
11463         }
11464
11465         fdir_set_flex_payload(res->port_id, &flex_cfg);
11466         cmd_reconfig_device_queue(res->port_id, 1, 1);
11467 }
11468
11469 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11471                                  flow_director_flexpayload,
11472                                  "flow_director_flex_payload");
11473 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11474         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11475                               port_id, UINT16);
11476 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11477         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11478                                  payload_layer, "raw#l2#l3#l4");
11479 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11480         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11481                                  payload_cfg, NULL);
11482
11483 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11484         .f = cmd_flow_director_flxpld_parsed,
11485         .data = NULL,
11486         .help_str = "flow_director_flexpayload ... : "
11487                 "Set flow director's flex payload on NIC",
11488         .tokens = {
11489                 (void *)&cmd_flow_director_flexpayload,
11490                 (void *)&cmd_flow_director_flexpayload_port_id,
11491                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11492                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11493                 NULL,
11494         },
11495 };
11496
11497 /* Generic flow interface command. */
11498 extern cmdline_parse_inst_t cmd_flow;
11499
11500 /* *** Classification Filters Control *** */
11501 /* *** Get symmetric hash enable per port *** */
11502 struct cmd_get_sym_hash_ena_per_port_result {
11503         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11504         portid_t port_id;
11505 };
11506
11507 static void
11508 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11509                                  __rte_unused struct cmdline *cl,
11510                                  __rte_unused void *data)
11511 {
11512         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11513         struct rte_eth_hash_filter_info info;
11514         int ret;
11515
11516         if (rte_eth_dev_filter_supported(res->port_id,
11517                                 RTE_ETH_FILTER_HASH) < 0) {
11518                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11519                                                         res->port_id);
11520                 return;
11521         }
11522
11523         memset(&info, 0, sizeof(info));
11524         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11525         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11526                                                 RTE_ETH_FILTER_GET, &info);
11527
11528         if (ret < 0) {
11529                 printf("Cannot get symmetric hash enable per port "
11530                                         "on port %u\n", res->port_id);
11531                 return;
11532         }
11533
11534         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11535                                 "enabled" : "disabled", res->port_id);
11536 }
11537
11538 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11539         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11540                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11541 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11542         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11543                 port_id, UINT16);
11544
11545 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11546         .f = cmd_get_sym_hash_per_port_parsed,
11547         .data = NULL,
11548         .help_str = "get_sym_hash_ena_per_port <port_id>",
11549         .tokens = {
11550                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11551                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11552                 NULL,
11553         },
11554 };
11555
11556 /* *** Set symmetric hash enable per port *** */
11557 struct cmd_set_sym_hash_ena_per_port_result {
11558         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11559         cmdline_fixed_string_t enable;
11560         portid_t port_id;
11561 };
11562
11563 static void
11564 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11565                                  __rte_unused struct cmdline *cl,
11566                                  __rte_unused void *data)
11567 {
11568         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11569         struct rte_eth_hash_filter_info info;
11570         int ret;
11571
11572         if (rte_eth_dev_filter_supported(res->port_id,
11573                                 RTE_ETH_FILTER_HASH) < 0) {
11574                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11575                                                         res->port_id);
11576                 return;
11577         }
11578
11579         memset(&info, 0, sizeof(info));
11580         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11581         if (!strcmp(res->enable, "enable"))
11582                 info.info.enable = 1;
11583         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11584                                         RTE_ETH_FILTER_SET, &info);
11585         if (ret < 0) {
11586                 printf("Cannot set symmetric hash enable per port on "
11587                                         "port %u\n", res->port_id);
11588                 return;
11589         }
11590         printf("Symmetric hash has been set to %s on port %u\n",
11591                                         res->enable, res->port_id);
11592 }
11593
11594 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11595         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11596                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11597 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11598         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11599                 port_id, UINT16);
11600 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11601         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11602                 enable, "enable#disable");
11603
11604 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11605         .f = cmd_set_sym_hash_per_port_parsed,
11606         .data = NULL,
11607         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11608         .tokens = {
11609                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11610                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11611                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11612                 NULL,
11613         },
11614 };
11615
11616 /* Get global config of hash function */
11617 struct cmd_get_hash_global_config_result {
11618         cmdline_fixed_string_t get_hash_global_config;
11619         portid_t port_id;
11620 };
11621
11622 static char *
11623 flowtype_to_str(uint16_t ftype)
11624 {
11625         uint16_t i;
11626         static struct {
11627                 char str[16];
11628                 uint16_t ftype;
11629         } ftype_table[] = {
11630                 {"ipv4", RTE_ETH_FLOW_IPV4},
11631                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11632                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11633                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11634                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11635                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11636                 {"ipv6", RTE_ETH_FLOW_IPV6},
11637                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11638                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11639                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11640                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11641                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11642                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11643                 {"port", RTE_ETH_FLOW_PORT},
11644                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11645                 {"geneve", RTE_ETH_FLOW_GENEVE},
11646                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11647         };
11648
11649         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11650                 if (ftype_table[i].ftype == ftype)
11651                         return ftype_table[i].str;
11652         }
11653
11654         return NULL;
11655 }
11656
11657 static void
11658 cmd_get_hash_global_config_parsed(void *parsed_result,
11659                                   __rte_unused struct cmdline *cl,
11660                                   __rte_unused void *data)
11661 {
11662         struct cmd_get_hash_global_config_result *res = parsed_result;
11663         struct rte_eth_hash_filter_info info;
11664         uint32_t idx, offset;
11665         uint16_t i;
11666         char *str;
11667         int ret;
11668
11669         if (rte_eth_dev_filter_supported(res->port_id,
11670                         RTE_ETH_FILTER_HASH) < 0) {
11671                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11672                                                         res->port_id);
11673                 return;
11674         }
11675
11676         memset(&info, 0, sizeof(info));
11677         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11678         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11679                                         RTE_ETH_FILTER_GET, &info);
11680         if (ret < 0) {
11681                 printf("Cannot get hash global configurations by port %d\n",
11682                                                         res->port_id);
11683                 return;
11684         }
11685
11686         switch (info.info.global_conf.hash_func) {
11687         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11688                 printf("Hash function is Toeplitz\n");
11689                 break;
11690         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11691                 printf("Hash function is Simple XOR\n");
11692                 break;
11693         default:
11694                 printf("Unknown hash function\n");
11695                 break;
11696         }
11697
11698         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11699                 idx = i / UINT64_BIT;
11700                 offset = i % UINT64_BIT;
11701                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11702                                                 (1ULL << offset)))
11703                         continue;
11704                 str = flowtype_to_str(i);
11705                 if (!str)
11706                         continue;
11707                 printf("Symmetric hash is %s globally for flow type %s "
11708                                                         "by port %d\n",
11709                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11710                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11711                                                         res->port_id);
11712         }
11713 }
11714
11715 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11716         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11717                 get_hash_global_config, "get_hash_global_config");
11718 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11719         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11720                 port_id, UINT16);
11721
11722 cmdline_parse_inst_t cmd_get_hash_global_config = {
11723         .f = cmd_get_hash_global_config_parsed,
11724         .data = NULL,
11725         .help_str = "get_hash_global_config <port_id>",
11726         .tokens = {
11727                 (void *)&cmd_get_hash_global_config_all,
11728                 (void *)&cmd_get_hash_global_config_port_id,
11729                 NULL,
11730         },
11731 };
11732
11733 /* Set global config of hash function */
11734 struct cmd_set_hash_global_config_result {
11735         cmdline_fixed_string_t set_hash_global_config;
11736         portid_t port_id;
11737         cmdline_fixed_string_t hash_func;
11738         cmdline_fixed_string_t flow_type;
11739         cmdline_fixed_string_t enable;
11740 };
11741
11742 static void
11743 cmd_set_hash_global_config_parsed(void *parsed_result,
11744                                   __rte_unused struct cmdline *cl,
11745                                   __rte_unused void *data)
11746 {
11747         struct cmd_set_hash_global_config_result *res = parsed_result;
11748         struct rte_eth_hash_filter_info info;
11749         uint32_t ftype, idx, offset;
11750         int ret;
11751
11752         if (rte_eth_dev_filter_supported(res->port_id,
11753                                 RTE_ETH_FILTER_HASH) < 0) {
11754                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11755                                                         res->port_id);
11756                 return;
11757         }
11758         memset(&info, 0, sizeof(info));
11759         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11760         if (!strcmp(res->hash_func, "toeplitz"))
11761                 info.info.global_conf.hash_func =
11762                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11763         else if (!strcmp(res->hash_func, "simple_xor"))
11764                 info.info.global_conf.hash_func =
11765                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11766         else if (!strcmp(res->hash_func, "default"))
11767                 info.info.global_conf.hash_func =
11768                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11769
11770         ftype = str2flowtype(res->flow_type);
11771         idx = ftype / UINT64_BIT;
11772         offset = ftype % UINT64_BIT;
11773         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11774         if (!strcmp(res->enable, "enable"))
11775                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11776                                                 (1ULL << offset);
11777         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11778                                         RTE_ETH_FILTER_SET, &info);
11779         if (ret < 0)
11780                 printf("Cannot set global hash configurations by port %d\n",
11781                                                         res->port_id);
11782         else
11783                 printf("Global hash configurations have been set "
11784                         "succcessfully by port %d\n", res->port_id);
11785 }
11786
11787 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11788         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11789                 set_hash_global_config, "set_hash_global_config");
11790 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11791         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11792                 port_id, UINT16);
11793 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11794         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11795                 hash_func, "toeplitz#simple_xor#default");
11796 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11797         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11798                 flow_type,
11799                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11800                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11801 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11802         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11803                 enable, "enable#disable");
11804
11805 cmdline_parse_inst_t cmd_set_hash_global_config = {
11806         .f = cmd_set_hash_global_config_parsed,
11807         .data = NULL,
11808         .help_str = "set_hash_global_config <port_id> "
11809                 "toeplitz|simple_xor|default "
11810                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11811                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11812                 "l2_payload enable|disable",
11813         .tokens = {
11814                 (void *)&cmd_set_hash_global_config_all,
11815                 (void *)&cmd_set_hash_global_config_port_id,
11816                 (void *)&cmd_set_hash_global_config_hash_func,
11817                 (void *)&cmd_set_hash_global_config_flow_type,
11818                 (void *)&cmd_set_hash_global_config_enable,
11819                 NULL,
11820         },
11821 };
11822
11823 /* Set hash input set */
11824 struct cmd_set_hash_input_set_result {
11825         cmdline_fixed_string_t set_hash_input_set;
11826         portid_t port_id;
11827         cmdline_fixed_string_t flow_type;
11828         cmdline_fixed_string_t inset_field;
11829         cmdline_fixed_string_t select;
11830 };
11831
11832 static enum rte_eth_input_set_field
11833 str2inset(char *string)
11834 {
11835         uint16_t i;
11836
11837         static const struct {
11838                 char str[32];
11839                 enum rte_eth_input_set_field inset;
11840         } inset_table[] = {
11841                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11842                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11843                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11844                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11845                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11846                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11847                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11848                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11849                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11850                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11851                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11852                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11853                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11854                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11855                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11856                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11857                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11858                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11859                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11860                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11861                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11862                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11863                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11864                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11865                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11866                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11867                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11868                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11869                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11870                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11871                 {"none", RTE_ETH_INPUT_SET_NONE},
11872         };
11873
11874         for (i = 0; i < RTE_DIM(inset_table); i++) {
11875                 if (!strcmp(string, inset_table[i].str))
11876                         return inset_table[i].inset;
11877         }
11878
11879         return RTE_ETH_INPUT_SET_UNKNOWN;
11880 }
11881
11882 static void
11883 cmd_set_hash_input_set_parsed(void *parsed_result,
11884                               __rte_unused struct cmdline *cl,
11885                               __rte_unused void *data)
11886 {
11887         struct cmd_set_hash_input_set_result *res = parsed_result;
11888         struct rte_eth_hash_filter_info info;
11889
11890         memset(&info, 0, sizeof(info));
11891         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11892         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11893         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11894         info.info.input_set_conf.inset_size = 1;
11895         if (!strcmp(res->select, "select"))
11896                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11897         else if (!strcmp(res->select, "add"))
11898                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11899         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11900                                 RTE_ETH_FILTER_SET, &info);
11901 }
11902
11903 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11904         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11905                 set_hash_input_set, "set_hash_input_set");
11906 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11907         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11908                 port_id, UINT16);
11909 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11910         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11911                 flow_type, NULL);
11912 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11913         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11914                 inset_field,
11915                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11916                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11917                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11918                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11919                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11920                 "fld-8th#none");
11921 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11922         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11923                 select, "select#add");
11924
11925 cmdline_parse_inst_t cmd_set_hash_input_set = {
11926         .f = cmd_set_hash_input_set_parsed,
11927         .data = NULL,
11928         .help_str = "set_hash_input_set <port_id> "
11929         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11930         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11931         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11932         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11933         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11934         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11935         "fld-7th|fld-8th|none select|add",
11936         .tokens = {
11937                 (void *)&cmd_set_hash_input_set_cmd,
11938                 (void *)&cmd_set_hash_input_set_port_id,
11939                 (void *)&cmd_set_hash_input_set_flow_type,
11940                 (void *)&cmd_set_hash_input_set_field,
11941                 (void *)&cmd_set_hash_input_set_select,
11942                 NULL,
11943         },
11944 };
11945
11946 /* Set flow director input set */
11947 struct cmd_set_fdir_input_set_result {
11948         cmdline_fixed_string_t set_fdir_input_set;
11949         portid_t port_id;
11950         cmdline_fixed_string_t flow_type;
11951         cmdline_fixed_string_t inset_field;
11952         cmdline_fixed_string_t select;
11953 };
11954
11955 static void
11956 cmd_set_fdir_input_set_parsed(void *parsed_result,
11957         __rte_unused struct cmdline *cl,
11958         __rte_unused void *data)
11959 {
11960         struct cmd_set_fdir_input_set_result *res = parsed_result;
11961         struct rte_eth_fdir_filter_info info;
11962
11963         memset(&info, 0, sizeof(info));
11964         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11965         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11966         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11967         info.info.input_set_conf.inset_size = 1;
11968         if (!strcmp(res->select, "select"))
11969                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11970         else if (!strcmp(res->select, "add"))
11971                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11972         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11973                 RTE_ETH_FILTER_SET, &info);
11974 }
11975
11976 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11977         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11978         set_fdir_input_set, "set_fdir_input_set");
11979 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11980         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11981         port_id, UINT16);
11982 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11983         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11984         flow_type,
11985         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11986         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11987 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11988         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11989         inset_field,
11990         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11991         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11992         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11993         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11994         "sctp-veri-tag#none");
11995 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11996         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11997         select, "select#add");
11998
11999 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12000         .f = cmd_set_fdir_input_set_parsed,
12001         .data = NULL,
12002         .help_str = "set_fdir_input_set <port_id> "
12003         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12004         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12005         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12006         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12007         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12008         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12009         "sctp-veri-tag|none select|add",
12010         .tokens = {
12011                 (void *)&cmd_set_fdir_input_set_cmd,
12012                 (void *)&cmd_set_fdir_input_set_port_id,
12013                 (void *)&cmd_set_fdir_input_set_flow_type,
12014                 (void *)&cmd_set_fdir_input_set_field,
12015                 (void *)&cmd_set_fdir_input_set_select,
12016                 NULL,
12017         },
12018 };
12019
12020 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12021 struct cmd_mcast_addr_result {
12022         cmdline_fixed_string_t mcast_addr_cmd;
12023         cmdline_fixed_string_t what;
12024         uint16_t port_num;
12025         struct ether_addr mc_addr;
12026 };
12027
12028 static void cmd_mcast_addr_parsed(void *parsed_result,
12029                 __attribute__((unused)) struct cmdline *cl,
12030                 __attribute__((unused)) void *data)
12031 {
12032         struct cmd_mcast_addr_result *res = parsed_result;
12033
12034         if (!is_multicast_ether_addr(&res->mc_addr)) {
12035                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12036                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12037                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12038                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12039                 return;
12040         }
12041         if (strcmp(res->what, "add") == 0)
12042                 mcast_addr_add(res->port_num, &res->mc_addr);
12043         else
12044                 mcast_addr_remove(res->port_num, &res->mc_addr);
12045 }
12046
12047 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12048         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12049                                  mcast_addr_cmd, "mcast_addr");
12050 cmdline_parse_token_string_t cmd_mcast_addr_what =
12051         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12052                                  "add#remove");
12053 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12054         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12055 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12056         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12057
12058 cmdline_parse_inst_t cmd_mcast_addr = {
12059         .f = cmd_mcast_addr_parsed,
12060         .data = (void *)0,
12061         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12062                 "Add/Remove multicast MAC address on port_id",
12063         .tokens = {
12064                 (void *)&cmd_mcast_addr_cmd,
12065                 (void *)&cmd_mcast_addr_what,
12066                 (void *)&cmd_mcast_addr_portnum,
12067                 (void *)&cmd_mcast_addr_addr,
12068                 NULL,
12069         },
12070 };
12071
12072 /* l2 tunnel config
12073  * only support E-tag now.
12074  */
12075
12076 /* Ether type config */
12077 struct cmd_config_l2_tunnel_eth_type_result {
12078         cmdline_fixed_string_t port;
12079         cmdline_fixed_string_t config;
12080         cmdline_fixed_string_t all;
12081         portid_t id;
12082         cmdline_fixed_string_t l2_tunnel;
12083         cmdline_fixed_string_t l2_tunnel_type;
12084         cmdline_fixed_string_t eth_type;
12085         uint16_t eth_type_val;
12086 };
12087
12088 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12089         TOKEN_STRING_INITIALIZER
12090                 (struct cmd_config_l2_tunnel_eth_type_result,
12091                  port, "port");
12092 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12093         TOKEN_STRING_INITIALIZER
12094                 (struct cmd_config_l2_tunnel_eth_type_result,
12095                  config, "config");
12096 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12097         TOKEN_STRING_INITIALIZER
12098                 (struct cmd_config_l2_tunnel_eth_type_result,
12099                  all, "all");
12100 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12101         TOKEN_NUM_INITIALIZER
12102                 (struct cmd_config_l2_tunnel_eth_type_result,
12103                  id, UINT16);
12104 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12105         TOKEN_STRING_INITIALIZER
12106                 (struct cmd_config_l2_tunnel_eth_type_result,
12107                  l2_tunnel, "l2-tunnel");
12108 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12109         TOKEN_STRING_INITIALIZER
12110                 (struct cmd_config_l2_tunnel_eth_type_result,
12111                  l2_tunnel_type, "E-tag");
12112 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12113         TOKEN_STRING_INITIALIZER
12114                 (struct cmd_config_l2_tunnel_eth_type_result,
12115                  eth_type, "ether-type");
12116 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12117         TOKEN_NUM_INITIALIZER
12118                 (struct cmd_config_l2_tunnel_eth_type_result,
12119                  eth_type_val, UINT16);
12120
12121 static enum rte_eth_tunnel_type
12122 str2fdir_l2_tunnel_type(char *string)
12123 {
12124         uint32_t i = 0;
12125
12126         static const struct {
12127                 char str[32];
12128                 enum rte_eth_tunnel_type type;
12129         } l2_tunnel_type_str[] = {
12130                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12131         };
12132
12133         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12134                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12135                         return l2_tunnel_type_str[i].type;
12136         }
12137         return RTE_TUNNEL_TYPE_NONE;
12138 }
12139
12140 /* ether type config for all ports */
12141 static void
12142 cmd_config_l2_tunnel_eth_type_all_parsed
12143         (void *parsed_result,
12144          __attribute__((unused)) struct cmdline *cl,
12145          __attribute__((unused)) void *data)
12146 {
12147         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12148         struct rte_eth_l2_tunnel_conf entry;
12149         portid_t pid;
12150
12151         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12152         entry.ether_type = res->eth_type_val;
12153
12154         RTE_ETH_FOREACH_DEV(pid) {
12155                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12156         }
12157 }
12158
12159 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12160         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12161         .data = NULL,
12162         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12163         .tokens = {
12164                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12165                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12166                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12167                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12168                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12169                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12170                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12171                 NULL,
12172         },
12173 };
12174
12175 /* ether type config for a specific port */
12176 static void
12177 cmd_config_l2_tunnel_eth_type_specific_parsed(
12178         void *parsed_result,
12179         __attribute__((unused)) struct cmdline *cl,
12180         __attribute__((unused)) void *data)
12181 {
12182         struct cmd_config_l2_tunnel_eth_type_result *res =
12183                  parsed_result;
12184         struct rte_eth_l2_tunnel_conf entry;
12185
12186         if (port_id_is_invalid(res->id, ENABLED_WARN))
12187                 return;
12188
12189         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12190         entry.ether_type = res->eth_type_val;
12191
12192         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12193 }
12194
12195 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12196         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12197         .data = NULL,
12198         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12199         .tokens = {
12200                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12201                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12202                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12203                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12204                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12205                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12206                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12207                 NULL,
12208         },
12209 };
12210
12211 /* Enable/disable l2 tunnel */
12212 struct cmd_config_l2_tunnel_en_dis_result {
12213         cmdline_fixed_string_t port;
12214         cmdline_fixed_string_t config;
12215         cmdline_fixed_string_t all;
12216         portid_t id;
12217         cmdline_fixed_string_t l2_tunnel;
12218         cmdline_fixed_string_t l2_tunnel_type;
12219         cmdline_fixed_string_t en_dis;
12220 };
12221
12222 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12223         TOKEN_STRING_INITIALIZER
12224                 (struct cmd_config_l2_tunnel_en_dis_result,
12225                  port, "port");
12226 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12227         TOKEN_STRING_INITIALIZER
12228                 (struct cmd_config_l2_tunnel_en_dis_result,
12229                  config, "config");
12230 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12231         TOKEN_STRING_INITIALIZER
12232                 (struct cmd_config_l2_tunnel_en_dis_result,
12233                  all, "all");
12234 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12235         TOKEN_NUM_INITIALIZER
12236                 (struct cmd_config_l2_tunnel_en_dis_result,
12237                  id, UINT16);
12238 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12239         TOKEN_STRING_INITIALIZER
12240                 (struct cmd_config_l2_tunnel_en_dis_result,
12241                  l2_tunnel, "l2-tunnel");
12242 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12243         TOKEN_STRING_INITIALIZER
12244                 (struct cmd_config_l2_tunnel_en_dis_result,
12245                  l2_tunnel_type, "E-tag");
12246 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12247         TOKEN_STRING_INITIALIZER
12248                 (struct cmd_config_l2_tunnel_en_dis_result,
12249                  en_dis, "enable#disable");
12250
12251 /* enable/disable l2 tunnel for all ports */
12252 static void
12253 cmd_config_l2_tunnel_en_dis_all_parsed(
12254         void *parsed_result,
12255         __attribute__((unused)) struct cmdline *cl,
12256         __attribute__((unused)) void *data)
12257 {
12258         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12259         struct rte_eth_l2_tunnel_conf entry;
12260         portid_t pid;
12261         uint8_t en;
12262
12263         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12264
12265         if (!strcmp("enable", res->en_dis))
12266                 en = 1;
12267         else
12268                 en = 0;
12269
12270         RTE_ETH_FOREACH_DEV(pid) {
12271                 rte_eth_dev_l2_tunnel_offload_set(pid,
12272                                                   &entry,
12273                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12274                                                   en);
12275         }
12276 }
12277
12278 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12279         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12280         .data = NULL,
12281         .help_str = "port config all l2-tunnel E-tag enable|disable",
12282         .tokens = {
12283                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12284                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12285                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12286                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12287                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12288                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12289                 NULL,
12290         },
12291 };
12292
12293 /* enable/disable l2 tunnel for a port */
12294 static void
12295 cmd_config_l2_tunnel_en_dis_specific_parsed(
12296         void *parsed_result,
12297         __attribute__((unused)) struct cmdline *cl,
12298         __attribute__((unused)) void *data)
12299 {
12300         struct cmd_config_l2_tunnel_en_dis_result *res =
12301                 parsed_result;
12302         struct rte_eth_l2_tunnel_conf entry;
12303
12304         if (port_id_is_invalid(res->id, ENABLED_WARN))
12305                 return;
12306
12307         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12308
12309         if (!strcmp("enable", res->en_dis))
12310                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12311                                                   &entry,
12312                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12313                                                   1);
12314         else
12315                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12316                                                   &entry,
12317                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12318                                                   0);
12319 }
12320
12321 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12322         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12323         .data = NULL,
12324         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12325         .tokens = {
12326                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12327                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12328                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12329                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12330                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12331                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12332                 NULL,
12333         },
12334 };
12335
12336 /* E-tag configuration */
12337
12338 /* Common result structure for all E-tag configuration */
12339 struct cmd_config_e_tag_result {
12340         cmdline_fixed_string_t e_tag;
12341         cmdline_fixed_string_t set;
12342         cmdline_fixed_string_t insertion;
12343         cmdline_fixed_string_t stripping;
12344         cmdline_fixed_string_t forwarding;
12345         cmdline_fixed_string_t filter;
12346         cmdline_fixed_string_t add;
12347         cmdline_fixed_string_t del;
12348         cmdline_fixed_string_t on;
12349         cmdline_fixed_string_t off;
12350         cmdline_fixed_string_t on_off;
12351         cmdline_fixed_string_t port_tag_id;
12352         uint32_t port_tag_id_val;
12353         cmdline_fixed_string_t e_tag_id;
12354         uint16_t e_tag_id_val;
12355         cmdline_fixed_string_t dst_pool;
12356         uint8_t dst_pool_val;
12357         cmdline_fixed_string_t port;
12358         portid_t port_id;
12359         cmdline_fixed_string_t vf;
12360         uint8_t vf_id;
12361 };
12362
12363 /* Common CLI fields for all E-tag configuration */
12364 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12365         TOKEN_STRING_INITIALIZER
12366                 (struct cmd_config_e_tag_result,
12367                  e_tag, "E-tag");
12368 cmdline_parse_token_string_t cmd_config_e_tag_set =
12369         TOKEN_STRING_INITIALIZER
12370                 (struct cmd_config_e_tag_result,
12371                  set, "set");
12372 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12373         TOKEN_STRING_INITIALIZER
12374                 (struct cmd_config_e_tag_result,
12375                  insertion, "insertion");
12376 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12377         TOKEN_STRING_INITIALIZER
12378                 (struct cmd_config_e_tag_result,
12379                  stripping, "stripping");
12380 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12381         TOKEN_STRING_INITIALIZER
12382                 (struct cmd_config_e_tag_result,
12383                  forwarding, "forwarding");
12384 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12385         TOKEN_STRING_INITIALIZER
12386                 (struct cmd_config_e_tag_result,
12387                  filter, "filter");
12388 cmdline_parse_token_string_t cmd_config_e_tag_add =
12389         TOKEN_STRING_INITIALIZER
12390                 (struct cmd_config_e_tag_result,
12391                  add, "add");
12392 cmdline_parse_token_string_t cmd_config_e_tag_del =
12393         TOKEN_STRING_INITIALIZER
12394                 (struct cmd_config_e_tag_result,
12395                  del, "del");
12396 cmdline_parse_token_string_t cmd_config_e_tag_on =
12397         TOKEN_STRING_INITIALIZER
12398                 (struct cmd_config_e_tag_result,
12399                  on, "on");
12400 cmdline_parse_token_string_t cmd_config_e_tag_off =
12401         TOKEN_STRING_INITIALIZER
12402                 (struct cmd_config_e_tag_result,
12403                  off, "off");
12404 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12405         TOKEN_STRING_INITIALIZER
12406                 (struct cmd_config_e_tag_result,
12407                  on_off, "on#off");
12408 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12409         TOKEN_STRING_INITIALIZER
12410                 (struct cmd_config_e_tag_result,
12411                  port_tag_id, "port-tag-id");
12412 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12413         TOKEN_NUM_INITIALIZER
12414                 (struct cmd_config_e_tag_result,
12415                  port_tag_id_val, UINT32);
12416 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12417         TOKEN_STRING_INITIALIZER
12418                 (struct cmd_config_e_tag_result,
12419                  e_tag_id, "e-tag-id");
12420 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12421         TOKEN_NUM_INITIALIZER
12422                 (struct cmd_config_e_tag_result,
12423                  e_tag_id_val, UINT16);
12424 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12425         TOKEN_STRING_INITIALIZER
12426                 (struct cmd_config_e_tag_result,
12427                  dst_pool, "dst-pool");
12428 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12429         TOKEN_NUM_INITIALIZER
12430                 (struct cmd_config_e_tag_result,
12431                  dst_pool_val, UINT8);
12432 cmdline_parse_token_string_t cmd_config_e_tag_port =
12433         TOKEN_STRING_INITIALIZER
12434                 (struct cmd_config_e_tag_result,
12435                  port, "port");
12436 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12437         TOKEN_NUM_INITIALIZER
12438                 (struct cmd_config_e_tag_result,
12439                  port_id, UINT16);
12440 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12441         TOKEN_STRING_INITIALIZER
12442                 (struct cmd_config_e_tag_result,
12443                  vf, "vf");
12444 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12445         TOKEN_NUM_INITIALIZER
12446                 (struct cmd_config_e_tag_result,
12447                  vf_id, UINT8);
12448
12449 /* E-tag insertion configuration */
12450 static void
12451 cmd_config_e_tag_insertion_en_parsed(
12452         void *parsed_result,
12453         __attribute__((unused)) struct cmdline *cl,
12454         __attribute__((unused)) void *data)
12455 {
12456         struct cmd_config_e_tag_result *res =
12457                 parsed_result;
12458         struct rte_eth_l2_tunnel_conf entry;
12459
12460         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12461                 return;
12462
12463         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12464         entry.tunnel_id = res->port_tag_id_val;
12465         entry.vf_id = res->vf_id;
12466         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12467                                           &entry,
12468                                           ETH_L2_TUNNEL_INSERTION_MASK,
12469                                           1);
12470 }
12471
12472 static void
12473 cmd_config_e_tag_insertion_dis_parsed(
12474         void *parsed_result,
12475         __attribute__((unused)) struct cmdline *cl,
12476         __attribute__((unused)) void *data)
12477 {
12478         struct cmd_config_e_tag_result *res =
12479                 parsed_result;
12480         struct rte_eth_l2_tunnel_conf entry;
12481
12482         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12483                 return;
12484
12485         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12486         entry.vf_id = res->vf_id;
12487
12488         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12489                                           &entry,
12490                                           ETH_L2_TUNNEL_INSERTION_MASK,
12491                                           0);
12492 }
12493
12494 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12495         .f = cmd_config_e_tag_insertion_en_parsed,
12496         .data = NULL,
12497         .help_str = "E-tag ... : E-tag insertion enable",
12498         .tokens = {
12499                 (void *)&cmd_config_e_tag_e_tag,
12500                 (void *)&cmd_config_e_tag_set,
12501                 (void *)&cmd_config_e_tag_insertion,
12502                 (void *)&cmd_config_e_tag_on,
12503                 (void *)&cmd_config_e_tag_port_tag_id,
12504                 (void *)&cmd_config_e_tag_port_tag_id_val,
12505                 (void *)&cmd_config_e_tag_port,
12506                 (void *)&cmd_config_e_tag_port_id,
12507                 (void *)&cmd_config_e_tag_vf,
12508                 (void *)&cmd_config_e_tag_vf_id,
12509                 NULL,
12510         },
12511 };
12512
12513 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12514         .f = cmd_config_e_tag_insertion_dis_parsed,
12515         .data = NULL,
12516         .help_str = "E-tag ... : E-tag insertion disable",
12517         .tokens = {
12518                 (void *)&cmd_config_e_tag_e_tag,
12519                 (void *)&cmd_config_e_tag_set,
12520                 (void *)&cmd_config_e_tag_insertion,
12521                 (void *)&cmd_config_e_tag_off,
12522                 (void *)&cmd_config_e_tag_port,
12523                 (void *)&cmd_config_e_tag_port_id,
12524                 (void *)&cmd_config_e_tag_vf,
12525                 (void *)&cmd_config_e_tag_vf_id,
12526                 NULL,
12527         },
12528 };
12529
12530 /* E-tag stripping configuration */
12531 static void
12532 cmd_config_e_tag_stripping_parsed(
12533         void *parsed_result,
12534         __attribute__((unused)) struct cmdline *cl,
12535         __attribute__((unused)) void *data)
12536 {
12537         struct cmd_config_e_tag_result *res =
12538                 parsed_result;
12539         struct rte_eth_l2_tunnel_conf entry;
12540
12541         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12542                 return;
12543
12544         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12545
12546         if (!strcmp(res->on_off, "on"))
12547                 rte_eth_dev_l2_tunnel_offload_set
12548                         (res->port_id,
12549                          &entry,
12550                          ETH_L2_TUNNEL_STRIPPING_MASK,
12551                          1);
12552         else
12553                 rte_eth_dev_l2_tunnel_offload_set
12554                         (res->port_id,
12555                          &entry,
12556                          ETH_L2_TUNNEL_STRIPPING_MASK,
12557                          0);
12558 }
12559
12560 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12561         .f = cmd_config_e_tag_stripping_parsed,
12562         .data = NULL,
12563         .help_str = "E-tag ... : E-tag stripping enable/disable",
12564         .tokens = {
12565                 (void *)&cmd_config_e_tag_e_tag,
12566                 (void *)&cmd_config_e_tag_set,
12567                 (void *)&cmd_config_e_tag_stripping,
12568                 (void *)&cmd_config_e_tag_on_off,
12569                 (void *)&cmd_config_e_tag_port,
12570                 (void *)&cmd_config_e_tag_port_id,
12571                 NULL,
12572         },
12573 };
12574
12575 /* E-tag forwarding configuration */
12576 static void
12577 cmd_config_e_tag_forwarding_parsed(
12578         void *parsed_result,
12579         __attribute__((unused)) struct cmdline *cl,
12580         __attribute__((unused)) void *data)
12581 {
12582         struct cmd_config_e_tag_result *res = parsed_result;
12583         struct rte_eth_l2_tunnel_conf entry;
12584
12585         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12586                 return;
12587
12588         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12589
12590         if (!strcmp(res->on_off, "on"))
12591                 rte_eth_dev_l2_tunnel_offload_set
12592                         (res->port_id,
12593                          &entry,
12594                          ETH_L2_TUNNEL_FORWARDING_MASK,
12595                          1);
12596         else
12597                 rte_eth_dev_l2_tunnel_offload_set
12598                         (res->port_id,
12599                          &entry,
12600                          ETH_L2_TUNNEL_FORWARDING_MASK,
12601                          0);
12602 }
12603
12604 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12605         .f = cmd_config_e_tag_forwarding_parsed,
12606         .data = NULL,
12607         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12608         .tokens = {
12609                 (void *)&cmd_config_e_tag_e_tag,
12610                 (void *)&cmd_config_e_tag_set,
12611                 (void *)&cmd_config_e_tag_forwarding,
12612                 (void *)&cmd_config_e_tag_on_off,
12613                 (void *)&cmd_config_e_tag_port,
12614                 (void *)&cmd_config_e_tag_port_id,
12615                 NULL,
12616         },
12617 };
12618
12619 /* E-tag filter configuration */
12620 static void
12621 cmd_config_e_tag_filter_add_parsed(
12622         void *parsed_result,
12623         __attribute__((unused)) struct cmdline *cl,
12624         __attribute__((unused)) void *data)
12625 {
12626         struct cmd_config_e_tag_result *res = parsed_result;
12627         struct rte_eth_l2_tunnel_conf entry;
12628         int ret = 0;
12629
12630         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12631                 return;
12632
12633         if (res->e_tag_id_val > 0x3fff) {
12634                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12635                 return;
12636         }
12637
12638         ret = rte_eth_dev_filter_supported(res->port_id,
12639                                            RTE_ETH_FILTER_L2_TUNNEL);
12640         if (ret < 0) {
12641                 printf("E-tag filter is not supported on port %u.\n",
12642                        res->port_id);
12643                 return;
12644         }
12645
12646         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12647         entry.tunnel_id = res->e_tag_id_val;
12648         entry.pool = res->dst_pool_val;
12649
12650         ret = rte_eth_dev_filter_ctrl(res->port_id,
12651                                       RTE_ETH_FILTER_L2_TUNNEL,
12652                                       RTE_ETH_FILTER_ADD,
12653                                       &entry);
12654         if (ret < 0)
12655                 printf("E-tag filter programming error: (%s)\n",
12656                        strerror(-ret));
12657 }
12658
12659 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12660         .f = cmd_config_e_tag_filter_add_parsed,
12661         .data = NULL,
12662         .help_str = "E-tag ... : E-tag filter add",
12663         .tokens = {
12664                 (void *)&cmd_config_e_tag_e_tag,
12665                 (void *)&cmd_config_e_tag_set,
12666                 (void *)&cmd_config_e_tag_filter,
12667                 (void *)&cmd_config_e_tag_add,
12668                 (void *)&cmd_config_e_tag_e_tag_id,
12669                 (void *)&cmd_config_e_tag_e_tag_id_val,
12670                 (void *)&cmd_config_e_tag_dst_pool,
12671                 (void *)&cmd_config_e_tag_dst_pool_val,
12672                 (void *)&cmd_config_e_tag_port,
12673                 (void *)&cmd_config_e_tag_port_id,
12674                 NULL,
12675         },
12676 };
12677
12678 static void
12679 cmd_config_e_tag_filter_del_parsed(
12680         void *parsed_result,
12681         __attribute__((unused)) struct cmdline *cl,
12682         __attribute__((unused)) void *data)
12683 {
12684         struct cmd_config_e_tag_result *res = parsed_result;
12685         struct rte_eth_l2_tunnel_conf entry;
12686         int ret = 0;
12687
12688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12689                 return;
12690
12691         if (res->e_tag_id_val > 0x3fff) {
12692                 printf("e-tag-id must be less than 0x3fff.\n");
12693                 return;
12694         }
12695
12696         ret = rte_eth_dev_filter_supported(res->port_id,
12697                                            RTE_ETH_FILTER_L2_TUNNEL);
12698         if (ret < 0) {
12699                 printf("E-tag filter is not supported on port %u.\n",
12700                        res->port_id);
12701                 return;
12702         }
12703
12704         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12705         entry.tunnel_id = res->e_tag_id_val;
12706
12707         ret = rte_eth_dev_filter_ctrl(res->port_id,
12708                                       RTE_ETH_FILTER_L2_TUNNEL,
12709                                       RTE_ETH_FILTER_DELETE,
12710                                       &entry);
12711         if (ret < 0)
12712                 printf("E-tag filter programming error: (%s)\n",
12713                        strerror(-ret));
12714 }
12715
12716 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12717         .f = cmd_config_e_tag_filter_del_parsed,
12718         .data = NULL,
12719         .help_str = "E-tag ... : E-tag filter delete",
12720         .tokens = {
12721                 (void *)&cmd_config_e_tag_e_tag,
12722                 (void *)&cmd_config_e_tag_set,
12723                 (void *)&cmd_config_e_tag_filter,
12724                 (void *)&cmd_config_e_tag_del,
12725                 (void *)&cmd_config_e_tag_e_tag_id,
12726                 (void *)&cmd_config_e_tag_e_tag_id_val,
12727                 (void *)&cmd_config_e_tag_port,
12728                 (void *)&cmd_config_e_tag_port_id,
12729                 NULL,
12730         },
12731 };
12732
12733 /* vf vlan anti spoof configuration */
12734
12735 /* Common result structure for vf vlan anti spoof */
12736 struct cmd_vf_vlan_anti_spoof_result {
12737         cmdline_fixed_string_t set;
12738         cmdline_fixed_string_t vf;
12739         cmdline_fixed_string_t vlan;
12740         cmdline_fixed_string_t antispoof;
12741         portid_t port_id;
12742         uint32_t vf_id;
12743         cmdline_fixed_string_t on_off;
12744 };
12745
12746 /* Common CLI fields for vf vlan anti spoof enable disable */
12747 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12748         TOKEN_STRING_INITIALIZER
12749                 (struct cmd_vf_vlan_anti_spoof_result,
12750                  set, "set");
12751 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12752         TOKEN_STRING_INITIALIZER
12753                 (struct cmd_vf_vlan_anti_spoof_result,
12754                  vf, "vf");
12755 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12756         TOKEN_STRING_INITIALIZER
12757                 (struct cmd_vf_vlan_anti_spoof_result,
12758                  vlan, "vlan");
12759 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12760         TOKEN_STRING_INITIALIZER
12761                 (struct cmd_vf_vlan_anti_spoof_result,
12762                  antispoof, "antispoof");
12763 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12764         TOKEN_NUM_INITIALIZER
12765                 (struct cmd_vf_vlan_anti_spoof_result,
12766                  port_id, UINT16);
12767 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12768         TOKEN_NUM_INITIALIZER
12769                 (struct cmd_vf_vlan_anti_spoof_result,
12770                  vf_id, UINT32);
12771 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12772         TOKEN_STRING_INITIALIZER
12773                 (struct cmd_vf_vlan_anti_spoof_result,
12774                  on_off, "on#off");
12775
12776 static void
12777 cmd_set_vf_vlan_anti_spoof_parsed(
12778         void *parsed_result,
12779         __attribute__((unused)) struct cmdline *cl,
12780         __attribute__((unused)) void *data)
12781 {
12782         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12783         int ret = -ENOTSUP;
12784
12785         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12786
12787         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12788                 return;
12789
12790 #ifdef RTE_LIBRTE_IXGBE_PMD
12791         if (ret == -ENOTSUP)
12792                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12793                                 res->vf_id, is_on);
12794 #endif
12795 #ifdef RTE_LIBRTE_I40E_PMD
12796         if (ret == -ENOTSUP)
12797                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12798                                 res->vf_id, is_on);
12799 #endif
12800 #ifdef RTE_LIBRTE_BNXT_PMD
12801         if (ret == -ENOTSUP)
12802                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12803                                 res->vf_id, is_on);
12804 #endif
12805
12806         switch (ret) {
12807         case 0:
12808                 break;
12809         case -EINVAL:
12810                 printf("invalid vf_id %d\n", res->vf_id);
12811                 break;
12812         case -ENODEV:
12813                 printf("invalid port_id %d\n", res->port_id);
12814                 break;
12815         case -ENOTSUP:
12816                 printf("function not implemented\n");
12817                 break;
12818         default:
12819                 printf("programming error: (%s)\n", strerror(-ret));
12820         }
12821 }
12822
12823 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12824         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12825         .data = NULL,
12826         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12827         .tokens = {
12828                 (void *)&cmd_vf_vlan_anti_spoof_set,
12829                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12830                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12831                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12832                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12833                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12834                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12835                 NULL,
12836         },
12837 };
12838
12839 /* vf mac anti spoof configuration */
12840
12841 /* Common result structure for vf mac anti spoof */
12842 struct cmd_vf_mac_anti_spoof_result {
12843         cmdline_fixed_string_t set;
12844         cmdline_fixed_string_t vf;
12845         cmdline_fixed_string_t mac;
12846         cmdline_fixed_string_t antispoof;
12847         portid_t port_id;
12848         uint32_t vf_id;
12849         cmdline_fixed_string_t on_off;
12850 };
12851
12852 /* Common CLI fields for vf mac anti spoof enable disable */
12853 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12854         TOKEN_STRING_INITIALIZER
12855                 (struct cmd_vf_mac_anti_spoof_result,
12856                  set, "set");
12857 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12858         TOKEN_STRING_INITIALIZER
12859                 (struct cmd_vf_mac_anti_spoof_result,
12860                  vf, "vf");
12861 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12862         TOKEN_STRING_INITIALIZER
12863                 (struct cmd_vf_mac_anti_spoof_result,
12864                  mac, "mac");
12865 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12866         TOKEN_STRING_INITIALIZER
12867                 (struct cmd_vf_mac_anti_spoof_result,
12868                  antispoof, "antispoof");
12869 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12870         TOKEN_NUM_INITIALIZER
12871                 (struct cmd_vf_mac_anti_spoof_result,
12872                  port_id, UINT16);
12873 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12874         TOKEN_NUM_INITIALIZER
12875                 (struct cmd_vf_mac_anti_spoof_result,
12876                  vf_id, UINT32);
12877 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12878         TOKEN_STRING_INITIALIZER
12879                 (struct cmd_vf_mac_anti_spoof_result,
12880                  on_off, "on#off");
12881
12882 static void
12883 cmd_set_vf_mac_anti_spoof_parsed(
12884         void *parsed_result,
12885         __attribute__((unused)) struct cmdline *cl,
12886         __attribute__((unused)) void *data)
12887 {
12888         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12889         int ret = -ENOTSUP;
12890
12891         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12892
12893         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12894                 return;
12895
12896 #ifdef RTE_LIBRTE_IXGBE_PMD
12897         if (ret == -ENOTSUP)
12898                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12899                         res->vf_id, is_on);
12900 #endif
12901 #ifdef RTE_LIBRTE_I40E_PMD
12902         if (ret == -ENOTSUP)
12903                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12904                         res->vf_id, is_on);
12905 #endif
12906 #ifdef RTE_LIBRTE_BNXT_PMD
12907         if (ret == -ENOTSUP)
12908                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12909                         res->vf_id, is_on);
12910 #endif
12911
12912         switch (ret) {
12913         case 0:
12914                 break;
12915         case -EINVAL:
12916                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12917                 break;
12918         case -ENODEV:
12919                 printf("invalid port_id %d\n", res->port_id);
12920                 break;
12921         case -ENOTSUP:
12922                 printf("function not implemented\n");
12923                 break;
12924         default:
12925                 printf("programming error: (%s)\n", strerror(-ret));
12926         }
12927 }
12928
12929 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12930         .f = cmd_set_vf_mac_anti_spoof_parsed,
12931         .data = NULL,
12932         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12933         .tokens = {
12934                 (void *)&cmd_vf_mac_anti_spoof_set,
12935                 (void *)&cmd_vf_mac_anti_spoof_vf,
12936                 (void *)&cmd_vf_mac_anti_spoof_mac,
12937                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12938                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12939                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12940                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12941                 NULL,
12942         },
12943 };
12944
12945 /* vf vlan strip queue configuration */
12946
12947 /* Common result structure for vf mac anti spoof */
12948 struct cmd_vf_vlan_stripq_result {
12949         cmdline_fixed_string_t set;
12950         cmdline_fixed_string_t vf;
12951         cmdline_fixed_string_t vlan;
12952         cmdline_fixed_string_t stripq;
12953         portid_t port_id;
12954         uint16_t vf_id;
12955         cmdline_fixed_string_t on_off;
12956 };
12957
12958 /* Common CLI fields for vf vlan strip enable disable */
12959 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12960         TOKEN_STRING_INITIALIZER
12961                 (struct cmd_vf_vlan_stripq_result,
12962                  set, "set");
12963 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_vf_vlan_stripq_result,
12966                  vf, "vf");
12967 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_vf_vlan_stripq_result,
12970                  vlan, "vlan");
12971 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_vf_vlan_stripq_result,
12974                  stripq, "stripq");
12975 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12976         TOKEN_NUM_INITIALIZER
12977                 (struct cmd_vf_vlan_stripq_result,
12978                  port_id, UINT16);
12979 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12980         TOKEN_NUM_INITIALIZER
12981                 (struct cmd_vf_vlan_stripq_result,
12982                  vf_id, UINT16);
12983 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12984         TOKEN_STRING_INITIALIZER
12985                 (struct cmd_vf_vlan_stripq_result,
12986                  on_off, "on#off");
12987
12988 static void
12989 cmd_set_vf_vlan_stripq_parsed(
12990         void *parsed_result,
12991         __attribute__((unused)) struct cmdline *cl,
12992         __attribute__((unused)) void *data)
12993 {
12994         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12995         int ret = -ENOTSUP;
12996
12997         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12998
12999         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13000                 return;
13001
13002 #ifdef RTE_LIBRTE_IXGBE_PMD
13003         if (ret == -ENOTSUP)
13004                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13005                         res->vf_id, is_on);
13006 #endif
13007 #ifdef RTE_LIBRTE_I40E_PMD
13008         if (ret == -ENOTSUP)
13009                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13010                         res->vf_id, is_on);
13011 #endif
13012 #ifdef RTE_LIBRTE_BNXT_PMD
13013         if (ret == -ENOTSUP)
13014                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13015                         res->vf_id, is_on);
13016 #endif
13017
13018         switch (ret) {
13019         case 0:
13020                 break;
13021         case -EINVAL:
13022                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13023                 break;
13024         case -ENODEV:
13025                 printf("invalid port_id %d\n", res->port_id);
13026                 break;
13027         case -ENOTSUP:
13028                 printf("function not implemented\n");
13029                 break;
13030         default:
13031                 printf("programming error: (%s)\n", strerror(-ret));
13032         }
13033 }
13034
13035 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13036         .f = cmd_set_vf_vlan_stripq_parsed,
13037         .data = NULL,
13038         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13039         .tokens = {
13040                 (void *)&cmd_vf_vlan_stripq_set,
13041                 (void *)&cmd_vf_vlan_stripq_vf,
13042                 (void *)&cmd_vf_vlan_stripq_vlan,
13043                 (void *)&cmd_vf_vlan_stripq_stripq,
13044                 (void *)&cmd_vf_vlan_stripq_port_id,
13045                 (void *)&cmd_vf_vlan_stripq_vf_id,
13046                 (void *)&cmd_vf_vlan_stripq_on_off,
13047                 NULL,
13048         },
13049 };
13050
13051 /* vf vlan insert configuration */
13052
13053 /* Common result structure for vf vlan insert */
13054 struct cmd_vf_vlan_insert_result {
13055         cmdline_fixed_string_t set;
13056         cmdline_fixed_string_t vf;
13057         cmdline_fixed_string_t vlan;
13058         cmdline_fixed_string_t insert;
13059         portid_t port_id;
13060         uint16_t vf_id;
13061         uint16_t vlan_id;
13062 };
13063
13064 /* Common CLI fields for vf vlan insert enable disable */
13065 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13066         TOKEN_STRING_INITIALIZER
13067                 (struct cmd_vf_vlan_insert_result,
13068                  set, "set");
13069 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_vf_vlan_insert_result,
13072                  vf, "vf");
13073 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13074         TOKEN_STRING_INITIALIZER
13075                 (struct cmd_vf_vlan_insert_result,
13076                  vlan, "vlan");
13077 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13078         TOKEN_STRING_INITIALIZER
13079                 (struct cmd_vf_vlan_insert_result,
13080                  insert, "insert");
13081 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13082         TOKEN_NUM_INITIALIZER
13083                 (struct cmd_vf_vlan_insert_result,
13084                  port_id, UINT16);
13085 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13086         TOKEN_NUM_INITIALIZER
13087                 (struct cmd_vf_vlan_insert_result,
13088                  vf_id, UINT16);
13089 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13090         TOKEN_NUM_INITIALIZER
13091                 (struct cmd_vf_vlan_insert_result,
13092                  vlan_id, UINT16);
13093
13094 static void
13095 cmd_set_vf_vlan_insert_parsed(
13096         void *parsed_result,
13097         __attribute__((unused)) struct cmdline *cl,
13098         __attribute__((unused)) void *data)
13099 {
13100         struct cmd_vf_vlan_insert_result *res = parsed_result;
13101         int ret = -ENOTSUP;
13102
13103         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13104                 return;
13105
13106 #ifdef RTE_LIBRTE_IXGBE_PMD
13107         if (ret == -ENOTSUP)
13108                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13109                         res->vlan_id);
13110 #endif
13111 #ifdef RTE_LIBRTE_I40E_PMD
13112         if (ret == -ENOTSUP)
13113                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13114                         res->vlan_id);
13115 #endif
13116 #ifdef RTE_LIBRTE_BNXT_PMD
13117         if (ret == -ENOTSUP)
13118                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13119                         res->vlan_id);
13120 #endif
13121
13122         switch (ret) {
13123         case 0:
13124                 break;
13125         case -EINVAL:
13126                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13127                 break;
13128         case -ENODEV:
13129                 printf("invalid port_id %d\n", res->port_id);
13130                 break;
13131         case -ENOTSUP:
13132                 printf("function not implemented\n");
13133                 break;
13134         default:
13135                 printf("programming error: (%s)\n", strerror(-ret));
13136         }
13137 }
13138
13139 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13140         .f = cmd_set_vf_vlan_insert_parsed,
13141         .data = NULL,
13142         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13143         .tokens = {
13144                 (void *)&cmd_vf_vlan_insert_set,
13145                 (void *)&cmd_vf_vlan_insert_vf,
13146                 (void *)&cmd_vf_vlan_insert_vlan,
13147                 (void *)&cmd_vf_vlan_insert_insert,
13148                 (void *)&cmd_vf_vlan_insert_port_id,
13149                 (void *)&cmd_vf_vlan_insert_vf_id,
13150                 (void *)&cmd_vf_vlan_insert_vlan_id,
13151                 NULL,
13152         },
13153 };
13154
13155 /* tx loopback configuration */
13156
13157 /* Common result structure for tx loopback */
13158 struct cmd_tx_loopback_result {
13159         cmdline_fixed_string_t set;
13160         cmdline_fixed_string_t tx;
13161         cmdline_fixed_string_t loopback;
13162         portid_t port_id;
13163         cmdline_fixed_string_t on_off;
13164 };
13165
13166 /* Common CLI fields for tx loopback enable disable */
13167 cmdline_parse_token_string_t cmd_tx_loopback_set =
13168         TOKEN_STRING_INITIALIZER
13169                 (struct cmd_tx_loopback_result,
13170                  set, "set");
13171 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13172         TOKEN_STRING_INITIALIZER
13173                 (struct cmd_tx_loopback_result,
13174                  tx, "tx");
13175 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13176         TOKEN_STRING_INITIALIZER
13177                 (struct cmd_tx_loopback_result,
13178                  loopback, "loopback");
13179 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13180         TOKEN_NUM_INITIALIZER
13181                 (struct cmd_tx_loopback_result,
13182                  port_id, UINT16);
13183 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13184         TOKEN_STRING_INITIALIZER
13185                 (struct cmd_tx_loopback_result,
13186                  on_off, "on#off");
13187
13188 static void
13189 cmd_set_tx_loopback_parsed(
13190         void *parsed_result,
13191         __attribute__((unused)) struct cmdline *cl,
13192         __attribute__((unused)) void *data)
13193 {
13194         struct cmd_tx_loopback_result *res = parsed_result;
13195         int ret = -ENOTSUP;
13196
13197         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13198
13199         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13200                 return;
13201
13202 #ifdef RTE_LIBRTE_IXGBE_PMD
13203         if (ret == -ENOTSUP)
13204                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13205 #endif
13206 #ifdef RTE_LIBRTE_I40E_PMD
13207         if (ret == -ENOTSUP)
13208                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13209 #endif
13210 #ifdef RTE_LIBRTE_BNXT_PMD
13211         if (ret == -ENOTSUP)
13212                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13213 #endif
13214 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13215         if (ret == -ENOTSUP)
13216                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13217 #endif
13218
13219         switch (ret) {
13220         case 0:
13221                 break;
13222         case -EINVAL:
13223                 printf("invalid is_on %d\n", is_on);
13224                 break;
13225         case -ENODEV:
13226                 printf("invalid port_id %d\n", res->port_id);
13227                 break;
13228         case -ENOTSUP:
13229                 printf("function not implemented\n");
13230                 break;
13231         default:
13232                 printf("programming error: (%s)\n", strerror(-ret));
13233         }
13234 }
13235
13236 cmdline_parse_inst_t cmd_set_tx_loopback = {
13237         .f = cmd_set_tx_loopback_parsed,
13238         .data = NULL,
13239         .help_str = "set tx loopback <port_id> on|off",
13240         .tokens = {
13241                 (void *)&cmd_tx_loopback_set,
13242                 (void *)&cmd_tx_loopback_tx,
13243                 (void *)&cmd_tx_loopback_loopback,
13244                 (void *)&cmd_tx_loopback_port_id,
13245                 (void *)&cmd_tx_loopback_on_off,
13246                 NULL,
13247         },
13248 };
13249
13250 /* all queues drop enable configuration */
13251
13252 /* Common result structure for all queues drop enable */
13253 struct cmd_all_queues_drop_en_result {
13254         cmdline_fixed_string_t set;
13255         cmdline_fixed_string_t all;
13256         cmdline_fixed_string_t queues;
13257         cmdline_fixed_string_t drop;
13258         portid_t port_id;
13259         cmdline_fixed_string_t on_off;
13260 };
13261
13262 /* Common CLI fields for tx loopback enable disable */
13263 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13264         TOKEN_STRING_INITIALIZER
13265                 (struct cmd_all_queues_drop_en_result,
13266                  set, "set");
13267 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13268         TOKEN_STRING_INITIALIZER
13269                 (struct cmd_all_queues_drop_en_result,
13270                  all, "all");
13271 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13272         TOKEN_STRING_INITIALIZER
13273                 (struct cmd_all_queues_drop_en_result,
13274                  queues, "queues");
13275 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13276         TOKEN_STRING_INITIALIZER
13277                 (struct cmd_all_queues_drop_en_result,
13278                  drop, "drop");
13279 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13280         TOKEN_NUM_INITIALIZER
13281                 (struct cmd_all_queues_drop_en_result,
13282                  port_id, UINT16);
13283 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13284         TOKEN_STRING_INITIALIZER
13285                 (struct cmd_all_queues_drop_en_result,
13286                  on_off, "on#off");
13287
13288 static void
13289 cmd_set_all_queues_drop_en_parsed(
13290         void *parsed_result,
13291         __attribute__((unused)) struct cmdline *cl,
13292         __attribute__((unused)) void *data)
13293 {
13294         struct cmd_all_queues_drop_en_result *res = parsed_result;
13295         int ret = -ENOTSUP;
13296         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13297
13298         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13299                 return;
13300
13301 #ifdef RTE_LIBRTE_IXGBE_PMD
13302         if (ret == -ENOTSUP)
13303                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13304 #endif
13305 #ifdef RTE_LIBRTE_BNXT_PMD
13306         if (ret == -ENOTSUP)
13307                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13308 #endif
13309         switch (ret) {
13310         case 0:
13311                 break;
13312         case -EINVAL:
13313                 printf("invalid is_on %d\n", is_on);
13314                 break;
13315         case -ENODEV:
13316                 printf("invalid port_id %d\n", res->port_id);
13317                 break;
13318         case -ENOTSUP:
13319                 printf("function not implemented\n");
13320                 break;
13321         default:
13322                 printf("programming error: (%s)\n", strerror(-ret));
13323         }
13324 }
13325
13326 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13327         .f = cmd_set_all_queues_drop_en_parsed,
13328         .data = NULL,
13329         .help_str = "set all queues drop <port_id> on|off",
13330         .tokens = {
13331                 (void *)&cmd_all_queues_drop_en_set,
13332                 (void *)&cmd_all_queues_drop_en_all,
13333                 (void *)&cmd_all_queues_drop_en_queues,
13334                 (void *)&cmd_all_queues_drop_en_drop,
13335                 (void *)&cmd_all_queues_drop_en_port_id,
13336                 (void *)&cmd_all_queues_drop_en_on_off,
13337                 NULL,
13338         },
13339 };
13340
13341 /* vf split drop enable configuration */
13342
13343 /* Common result structure for vf split drop enable */
13344 struct cmd_vf_split_drop_en_result {
13345         cmdline_fixed_string_t set;
13346         cmdline_fixed_string_t vf;
13347         cmdline_fixed_string_t split;
13348         cmdline_fixed_string_t drop;
13349         portid_t port_id;
13350         uint16_t vf_id;
13351         cmdline_fixed_string_t on_off;
13352 };
13353
13354 /* Common CLI fields for vf split drop enable disable */
13355 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13356         TOKEN_STRING_INITIALIZER
13357                 (struct cmd_vf_split_drop_en_result,
13358                  set, "set");
13359 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13360         TOKEN_STRING_INITIALIZER
13361                 (struct cmd_vf_split_drop_en_result,
13362                  vf, "vf");
13363 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13364         TOKEN_STRING_INITIALIZER
13365                 (struct cmd_vf_split_drop_en_result,
13366                  split, "split");
13367 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13368         TOKEN_STRING_INITIALIZER
13369                 (struct cmd_vf_split_drop_en_result,
13370                  drop, "drop");
13371 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13372         TOKEN_NUM_INITIALIZER
13373                 (struct cmd_vf_split_drop_en_result,
13374                  port_id, UINT16);
13375 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13376         TOKEN_NUM_INITIALIZER
13377                 (struct cmd_vf_split_drop_en_result,
13378                  vf_id, UINT16);
13379 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13380         TOKEN_STRING_INITIALIZER
13381                 (struct cmd_vf_split_drop_en_result,
13382                  on_off, "on#off");
13383
13384 static void
13385 cmd_set_vf_split_drop_en_parsed(
13386         void *parsed_result,
13387         __attribute__((unused)) struct cmdline *cl,
13388         __attribute__((unused)) void *data)
13389 {
13390         struct cmd_vf_split_drop_en_result *res = parsed_result;
13391         int ret = -ENOTSUP;
13392         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13393
13394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13395                 return;
13396
13397 #ifdef RTE_LIBRTE_IXGBE_PMD
13398         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13399                         is_on);
13400 #endif
13401         switch (ret) {
13402         case 0:
13403                 break;
13404         case -EINVAL:
13405                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13406                 break;
13407         case -ENODEV:
13408                 printf("invalid port_id %d\n", res->port_id);
13409                 break;
13410         case -ENOTSUP:
13411                 printf("not supported on port %d\n", res->port_id);
13412                 break;
13413         default:
13414                 printf("programming error: (%s)\n", strerror(-ret));
13415         }
13416 }
13417
13418 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13419         .f = cmd_set_vf_split_drop_en_parsed,
13420         .data = NULL,
13421         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13422         .tokens = {
13423                 (void *)&cmd_vf_split_drop_en_set,
13424                 (void *)&cmd_vf_split_drop_en_vf,
13425                 (void *)&cmd_vf_split_drop_en_split,
13426                 (void *)&cmd_vf_split_drop_en_drop,
13427                 (void *)&cmd_vf_split_drop_en_port_id,
13428                 (void *)&cmd_vf_split_drop_en_vf_id,
13429                 (void *)&cmd_vf_split_drop_en_on_off,
13430                 NULL,
13431         },
13432 };
13433
13434 /* vf mac address configuration */
13435
13436 /* Common result structure for vf mac address */
13437 struct cmd_set_vf_mac_addr_result {
13438         cmdline_fixed_string_t set;
13439         cmdline_fixed_string_t vf;
13440         cmdline_fixed_string_t mac;
13441         cmdline_fixed_string_t addr;
13442         portid_t port_id;
13443         uint16_t vf_id;
13444         struct ether_addr mac_addr;
13445
13446 };
13447
13448 /* Common CLI fields for vf split drop enable disable */
13449 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13450         TOKEN_STRING_INITIALIZER
13451                 (struct cmd_set_vf_mac_addr_result,
13452                  set, "set");
13453 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13454         TOKEN_STRING_INITIALIZER
13455                 (struct cmd_set_vf_mac_addr_result,
13456                  vf, "vf");
13457 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13458         TOKEN_STRING_INITIALIZER
13459                 (struct cmd_set_vf_mac_addr_result,
13460                  mac, "mac");
13461 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13462         TOKEN_STRING_INITIALIZER
13463                 (struct cmd_set_vf_mac_addr_result,
13464                  addr, "addr");
13465 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13466         TOKEN_NUM_INITIALIZER
13467                 (struct cmd_set_vf_mac_addr_result,
13468                  port_id, UINT16);
13469 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13470         TOKEN_NUM_INITIALIZER
13471                 (struct cmd_set_vf_mac_addr_result,
13472                  vf_id, UINT16);
13473 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13474         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13475                  mac_addr);
13476
13477 static void
13478 cmd_set_vf_mac_addr_parsed(
13479         void *parsed_result,
13480         __attribute__((unused)) struct cmdline *cl,
13481         __attribute__((unused)) void *data)
13482 {
13483         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13484         int ret = -ENOTSUP;
13485
13486         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13487                 return;
13488
13489 #ifdef RTE_LIBRTE_IXGBE_PMD
13490         if (ret == -ENOTSUP)
13491                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13492                                 &res->mac_addr);
13493 #endif
13494 #ifdef RTE_LIBRTE_I40E_PMD
13495         if (ret == -ENOTSUP)
13496                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13497                                 &res->mac_addr);
13498 #endif
13499 #ifdef RTE_LIBRTE_BNXT_PMD
13500         if (ret == -ENOTSUP)
13501                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13502                                 &res->mac_addr);
13503 #endif
13504
13505         switch (ret) {
13506         case 0:
13507                 break;
13508         case -EINVAL:
13509                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13510                 break;
13511         case -ENODEV:
13512                 printf("invalid port_id %d\n", res->port_id);
13513                 break;
13514         case -ENOTSUP:
13515                 printf("function not implemented\n");
13516                 break;
13517         default:
13518                 printf("programming error: (%s)\n", strerror(-ret));
13519         }
13520 }
13521
13522 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13523         .f = cmd_set_vf_mac_addr_parsed,
13524         .data = NULL,
13525         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13526         .tokens = {
13527                 (void *)&cmd_set_vf_mac_addr_set,
13528                 (void *)&cmd_set_vf_mac_addr_vf,
13529                 (void *)&cmd_set_vf_mac_addr_mac,
13530                 (void *)&cmd_set_vf_mac_addr_addr,
13531                 (void *)&cmd_set_vf_mac_addr_port_id,
13532                 (void *)&cmd_set_vf_mac_addr_vf_id,
13533                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13534                 NULL,
13535         },
13536 };
13537
13538 /* MACsec configuration */
13539
13540 /* Common result structure for MACsec offload enable */
13541 struct cmd_macsec_offload_on_result {
13542         cmdline_fixed_string_t set;
13543         cmdline_fixed_string_t macsec;
13544         cmdline_fixed_string_t offload;
13545         portid_t port_id;
13546         cmdline_fixed_string_t on;
13547         cmdline_fixed_string_t encrypt;
13548         cmdline_fixed_string_t en_on_off;
13549         cmdline_fixed_string_t replay_protect;
13550         cmdline_fixed_string_t rp_on_off;
13551 };
13552
13553 /* Common CLI fields for MACsec offload disable */
13554 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13555         TOKEN_STRING_INITIALIZER
13556                 (struct cmd_macsec_offload_on_result,
13557                  set, "set");
13558 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13559         TOKEN_STRING_INITIALIZER
13560                 (struct cmd_macsec_offload_on_result,
13561                  macsec, "macsec");
13562 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13563         TOKEN_STRING_INITIALIZER
13564                 (struct cmd_macsec_offload_on_result,
13565                  offload, "offload");
13566 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13567         TOKEN_NUM_INITIALIZER
13568                 (struct cmd_macsec_offload_on_result,
13569                  port_id, UINT16);
13570 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13571         TOKEN_STRING_INITIALIZER
13572                 (struct cmd_macsec_offload_on_result,
13573                  on, "on");
13574 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13575         TOKEN_STRING_INITIALIZER
13576                 (struct cmd_macsec_offload_on_result,
13577                  encrypt, "encrypt");
13578 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13579         TOKEN_STRING_INITIALIZER
13580                 (struct cmd_macsec_offload_on_result,
13581                  en_on_off, "on#off");
13582 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_macsec_offload_on_result,
13585                  replay_protect, "replay-protect");
13586 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13587         TOKEN_STRING_INITIALIZER
13588                 (struct cmd_macsec_offload_on_result,
13589                  rp_on_off, "on#off");
13590
13591 static void
13592 cmd_set_macsec_offload_on_parsed(
13593         void *parsed_result,
13594         __attribute__((unused)) struct cmdline *cl,
13595         __attribute__((unused)) void *data)
13596 {
13597         struct cmd_macsec_offload_on_result *res = parsed_result;
13598         int ret = -ENOTSUP;
13599         portid_t port_id = res->port_id;
13600         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13601         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13602         struct rte_eth_dev_info dev_info;
13603
13604         if (port_id_is_invalid(port_id, ENABLED_WARN))
13605                 return;
13606         if (!port_is_stopped(port_id)) {
13607                 printf("Please stop port %d first\n", port_id);
13608                 return;
13609         }
13610
13611         rte_eth_dev_info_get(port_id, &dev_info);
13612         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13613 #ifdef RTE_LIBRTE_IXGBE_PMD
13614                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13615 #endif
13616         }
13617         RTE_SET_USED(en);
13618         RTE_SET_USED(rp);
13619
13620         switch (ret) {
13621         case 0:
13622                 ports[port_id].dev_conf.txmode.offloads |=
13623                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13624                 cmd_reconfig_device_queue(port_id, 1, 1);
13625                 break;
13626         case -ENODEV:
13627                 printf("invalid port_id %d\n", port_id);
13628                 break;
13629         case -ENOTSUP:
13630                 printf("not supported on port %d\n", port_id);
13631                 break;
13632         default:
13633                 printf("programming error: (%s)\n", strerror(-ret));
13634         }
13635 }
13636
13637 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13638         .f = cmd_set_macsec_offload_on_parsed,
13639         .data = NULL,
13640         .help_str = "set macsec offload <port_id> on "
13641                 "encrypt on|off replay-protect on|off",
13642         .tokens = {
13643                 (void *)&cmd_macsec_offload_on_set,
13644                 (void *)&cmd_macsec_offload_on_macsec,
13645                 (void *)&cmd_macsec_offload_on_offload,
13646                 (void *)&cmd_macsec_offload_on_port_id,
13647                 (void *)&cmd_macsec_offload_on_on,
13648                 (void *)&cmd_macsec_offload_on_encrypt,
13649                 (void *)&cmd_macsec_offload_on_en_on_off,
13650                 (void *)&cmd_macsec_offload_on_replay_protect,
13651                 (void *)&cmd_macsec_offload_on_rp_on_off,
13652                 NULL,
13653         },
13654 };
13655
13656 /* Common result structure for MACsec offload disable */
13657 struct cmd_macsec_offload_off_result {
13658         cmdline_fixed_string_t set;
13659         cmdline_fixed_string_t macsec;
13660         cmdline_fixed_string_t offload;
13661         portid_t port_id;
13662         cmdline_fixed_string_t off;
13663 };
13664
13665 /* Common CLI fields for MACsec offload disable */
13666 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13667         TOKEN_STRING_INITIALIZER
13668                 (struct cmd_macsec_offload_off_result,
13669                  set, "set");
13670 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13671         TOKEN_STRING_INITIALIZER
13672                 (struct cmd_macsec_offload_off_result,
13673                  macsec, "macsec");
13674 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13675         TOKEN_STRING_INITIALIZER
13676                 (struct cmd_macsec_offload_off_result,
13677                  offload, "offload");
13678 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13679         TOKEN_NUM_INITIALIZER
13680                 (struct cmd_macsec_offload_off_result,
13681                  port_id, UINT16);
13682 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13683         TOKEN_STRING_INITIALIZER
13684                 (struct cmd_macsec_offload_off_result,
13685                  off, "off");
13686
13687 static void
13688 cmd_set_macsec_offload_off_parsed(
13689         void *parsed_result,
13690         __attribute__((unused)) struct cmdline *cl,
13691         __attribute__((unused)) void *data)
13692 {
13693         struct cmd_macsec_offload_off_result *res = parsed_result;
13694         int ret = -ENOTSUP;
13695         struct rte_eth_dev_info dev_info;
13696         portid_t port_id = res->port_id;
13697
13698         if (port_id_is_invalid(port_id, ENABLED_WARN))
13699                 return;
13700         if (!port_is_stopped(port_id)) {
13701                 printf("Please stop port %d first\n", port_id);
13702                 return;
13703         }
13704
13705         rte_eth_dev_info_get(port_id, &dev_info);
13706         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13707 #ifdef RTE_LIBRTE_IXGBE_PMD
13708                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13709 #endif
13710         }
13711         switch (ret) {
13712         case 0:
13713                 ports[port_id].dev_conf.txmode.offloads &=
13714                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13715                 cmd_reconfig_device_queue(port_id, 1, 1);
13716                 break;
13717         case -ENODEV:
13718                 printf("invalid port_id %d\n", port_id);
13719                 break;
13720         case -ENOTSUP:
13721                 printf("not supported on port %d\n", port_id);
13722                 break;
13723         default:
13724                 printf("programming error: (%s)\n", strerror(-ret));
13725         }
13726 }
13727
13728 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13729         .f = cmd_set_macsec_offload_off_parsed,
13730         .data = NULL,
13731         .help_str = "set macsec offload <port_id> off",
13732         .tokens = {
13733                 (void *)&cmd_macsec_offload_off_set,
13734                 (void *)&cmd_macsec_offload_off_macsec,
13735                 (void *)&cmd_macsec_offload_off_offload,
13736                 (void *)&cmd_macsec_offload_off_port_id,
13737                 (void *)&cmd_macsec_offload_off_off,
13738                 NULL,
13739         },
13740 };
13741
13742 /* Common result structure for MACsec secure connection configure */
13743 struct cmd_macsec_sc_result {
13744         cmdline_fixed_string_t set;
13745         cmdline_fixed_string_t macsec;
13746         cmdline_fixed_string_t sc;
13747         cmdline_fixed_string_t tx_rx;
13748         portid_t port_id;
13749         struct ether_addr mac;
13750         uint16_t pi;
13751 };
13752
13753 /* Common CLI fields for MACsec secure connection configure */
13754 cmdline_parse_token_string_t cmd_macsec_sc_set =
13755         TOKEN_STRING_INITIALIZER
13756                 (struct cmd_macsec_sc_result,
13757                  set, "set");
13758 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13759         TOKEN_STRING_INITIALIZER
13760                 (struct cmd_macsec_sc_result,
13761                  macsec, "macsec");
13762 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13763         TOKEN_STRING_INITIALIZER
13764                 (struct cmd_macsec_sc_result,
13765                  sc, "sc");
13766 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_macsec_sc_result,
13769                  tx_rx, "tx#rx");
13770 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13771         TOKEN_NUM_INITIALIZER
13772                 (struct cmd_macsec_sc_result,
13773                  port_id, UINT16);
13774 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13775         TOKEN_ETHERADDR_INITIALIZER
13776                 (struct cmd_macsec_sc_result,
13777                  mac);
13778 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13779         TOKEN_NUM_INITIALIZER
13780                 (struct cmd_macsec_sc_result,
13781                  pi, UINT16);
13782
13783 static void
13784 cmd_set_macsec_sc_parsed(
13785         void *parsed_result,
13786         __attribute__((unused)) struct cmdline *cl,
13787         __attribute__((unused)) void *data)
13788 {
13789         struct cmd_macsec_sc_result *res = parsed_result;
13790         int ret = -ENOTSUP;
13791         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13792
13793 #ifdef RTE_LIBRTE_IXGBE_PMD
13794         ret = is_tx ?
13795                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13796                                 res->mac.addr_bytes) :
13797                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13798                                 res->mac.addr_bytes, res->pi);
13799 #endif
13800         RTE_SET_USED(is_tx);
13801
13802         switch (ret) {
13803         case 0:
13804                 break;
13805         case -ENODEV:
13806                 printf("invalid port_id %d\n", res->port_id);
13807                 break;
13808         case -ENOTSUP:
13809                 printf("not supported on port %d\n", res->port_id);
13810                 break;
13811         default:
13812                 printf("programming error: (%s)\n", strerror(-ret));
13813         }
13814 }
13815
13816 cmdline_parse_inst_t cmd_set_macsec_sc = {
13817         .f = cmd_set_macsec_sc_parsed,
13818         .data = NULL,
13819         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13820         .tokens = {
13821                 (void *)&cmd_macsec_sc_set,
13822                 (void *)&cmd_macsec_sc_macsec,
13823                 (void *)&cmd_macsec_sc_sc,
13824                 (void *)&cmd_macsec_sc_tx_rx,
13825                 (void *)&cmd_macsec_sc_port_id,
13826                 (void *)&cmd_macsec_sc_mac,
13827                 (void *)&cmd_macsec_sc_pi,
13828                 NULL,
13829         },
13830 };
13831
13832 /* Common result structure for MACsec secure connection configure */
13833 struct cmd_macsec_sa_result {
13834         cmdline_fixed_string_t set;
13835         cmdline_fixed_string_t macsec;
13836         cmdline_fixed_string_t sa;
13837         cmdline_fixed_string_t tx_rx;
13838         portid_t port_id;
13839         uint8_t idx;
13840         uint8_t an;
13841         uint32_t pn;
13842         cmdline_fixed_string_t key;
13843 };
13844
13845 /* Common CLI fields for MACsec secure connection configure */
13846 cmdline_parse_token_string_t cmd_macsec_sa_set =
13847         TOKEN_STRING_INITIALIZER
13848                 (struct cmd_macsec_sa_result,
13849                  set, "set");
13850 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13851         TOKEN_STRING_INITIALIZER
13852                 (struct cmd_macsec_sa_result,
13853                  macsec, "macsec");
13854 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13855         TOKEN_STRING_INITIALIZER
13856                 (struct cmd_macsec_sa_result,
13857                  sa, "sa");
13858 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13859         TOKEN_STRING_INITIALIZER
13860                 (struct cmd_macsec_sa_result,
13861                  tx_rx, "tx#rx");
13862 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13863         TOKEN_NUM_INITIALIZER
13864                 (struct cmd_macsec_sa_result,
13865                  port_id, UINT16);
13866 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13867         TOKEN_NUM_INITIALIZER
13868                 (struct cmd_macsec_sa_result,
13869                  idx, UINT8);
13870 cmdline_parse_token_num_t cmd_macsec_sa_an =
13871         TOKEN_NUM_INITIALIZER
13872                 (struct cmd_macsec_sa_result,
13873                  an, UINT8);
13874 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13875         TOKEN_NUM_INITIALIZER
13876                 (struct cmd_macsec_sa_result,
13877                  pn, UINT32);
13878 cmdline_parse_token_string_t cmd_macsec_sa_key =
13879         TOKEN_STRING_INITIALIZER
13880                 (struct cmd_macsec_sa_result,
13881                  key, NULL);
13882
13883 static void
13884 cmd_set_macsec_sa_parsed(
13885         void *parsed_result,
13886         __attribute__((unused)) struct cmdline *cl,
13887         __attribute__((unused)) void *data)
13888 {
13889         struct cmd_macsec_sa_result *res = parsed_result;
13890         int ret = -ENOTSUP;
13891         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13892         uint8_t key[16] = { 0 };
13893         uint8_t xdgt0;
13894         uint8_t xdgt1;
13895         int key_len;
13896         int i;
13897
13898         key_len = strlen(res->key) / 2;
13899         if (key_len > 16)
13900                 key_len = 16;
13901
13902         for (i = 0; i < key_len; i++) {
13903                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13904                 if (xdgt0 == 0xFF)
13905                         return;
13906                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13907                 if (xdgt1 == 0xFF)
13908                         return;
13909                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13910         }
13911
13912 #ifdef RTE_LIBRTE_IXGBE_PMD
13913         ret = is_tx ?
13914                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13915                         res->idx, res->an, res->pn, key) :
13916                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13917                         res->idx, res->an, res->pn, key);
13918 #endif
13919         RTE_SET_USED(is_tx);
13920         RTE_SET_USED(key);
13921
13922         switch (ret) {
13923         case 0:
13924                 break;
13925         case -EINVAL:
13926                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13927                 break;
13928         case -ENODEV:
13929                 printf("invalid port_id %d\n", res->port_id);
13930                 break;
13931         case -ENOTSUP:
13932                 printf("not supported on port %d\n", res->port_id);
13933                 break;
13934         default:
13935                 printf("programming error: (%s)\n", strerror(-ret));
13936         }
13937 }
13938
13939 cmdline_parse_inst_t cmd_set_macsec_sa = {
13940         .f = cmd_set_macsec_sa_parsed,
13941         .data = NULL,
13942         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13943         .tokens = {
13944                 (void *)&cmd_macsec_sa_set,
13945                 (void *)&cmd_macsec_sa_macsec,
13946                 (void *)&cmd_macsec_sa_sa,
13947                 (void *)&cmd_macsec_sa_tx_rx,
13948                 (void *)&cmd_macsec_sa_port_id,
13949                 (void *)&cmd_macsec_sa_idx,
13950                 (void *)&cmd_macsec_sa_an,
13951                 (void *)&cmd_macsec_sa_pn,
13952                 (void *)&cmd_macsec_sa_key,
13953                 NULL,
13954         },
13955 };
13956
13957 /* VF unicast promiscuous mode configuration */
13958
13959 /* Common result structure for VF unicast promiscuous mode */
13960 struct cmd_vf_promisc_result {
13961         cmdline_fixed_string_t set;
13962         cmdline_fixed_string_t vf;
13963         cmdline_fixed_string_t promisc;
13964         portid_t port_id;
13965         uint32_t vf_id;
13966         cmdline_fixed_string_t on_off;
13967 };
13968
13969 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13970 cmdline_parse_token_string_t cmd_vf_promisc_set =
13971         TOKEN_STRING_INITIALIZER
13972                 (struct cmd_vf_promisc_result,
13973                  set, "set");
13974 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13975         TOKEN_STRING_INITIALIZER
13976                 (struct cmd_vf_promisc_result,
13977                  vf, "vf");
13978 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13979         TOKEN_STRING_INITIALIZER
13980                 (struct cmd_vf_promisc_result,
13981                  promisc, "promisc");
13982 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13983         TOKEN_NUM_INITIALIZER
13984                 (struct cmd_vf_promisc_result,
13985                  port_id, UINT16);
13986 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13987         TOKEN_NUM_INITIALIZER
13988                 (struct cmd_vf_promisc_result,
13989                  vf_id, UINT32);
13990 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13991         TOKEN_STRING_INITIALIZER
13992                 (struct cmd_vf_promisc_result,
13993                  on_off, "on#off");
13994
13995 static void
13996 cmd_set_vf_promisc_parsed(
13997         void *parsed_result,
13998         __attribute__((unused)) struct cmdline *cl,
13999         __attribute__((unused)) void *data)
14000 {
14001         struct cmd_vf_promisc_result *res = parsed_result;
14002         int ret = -ENOTSUP;
14003
14004         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14005
14006         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14007                 return;
14008
14009 #ifdef RTE_LIBRTE_I40E_PMD
14010         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14011                                                   res->vf_id, is_on);
14012 #endif
14013
14014         switch (ret) {
14015         case 0:
14016                 break;
14017         case -EINVAL:
14018                 printf("invalid vf_id %d\n", res->vf_id);
14019                 break;
14020         case -ENODEV:
14021                 printf("invalid port_id %d\n", res->port_id);
14022                 break;
14023         case -ENOTSUP:
14024                 printf("function not implemented\n");
14025                 break;
14026         default:
14027                 printf("programming error: (%s)\n", strerror(-ret));
14028         }
14029 }
14030
14031 cmdline_parse_inst_t cmd_set_vf_promisc = {
14032         .f = cmd_set_vf_promisc_parsed,
14033         .data = NULL,
14034         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14035                 "Set unicast promiscuous mode for a VF from the PF",
14036         .tokens = {
14037                 (void *)&cmd_vf_promisc_set,
14038                 (void *)&cmd_vf_promisc_vf,
14039                 (void *)&cmd_vf_promisc_promisc,
14040                 (void *)&cmd_vf_promisc_port_id,
14041                 (void *)&cmd_vf_promisc_vf_id,
14042                 (void *)&cmd_vf_promisc_on_off,
14043                 NULL,
14044         },
14045 };
14046
14047 /* VF multicast promiscuous mode configuration */
14048
14049 /* Common result structure for VF multicast promiscuous mode */
14050 struct cmd_vf_allmulti_result {
14051         cmdline_fixed_string_t set;
14052         cmdline_fixed_string_t vf;
14053         cmdline_fixed_string_t allmulti;
14054         portid_t port_id;
14055         uint32_t vf_id;
14056         cmdline_fixed_string_t on_off;
14057 };
14058
14059 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14060 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14061         TOKEN_STRING_INITIALIZER
14062                 (struct cmd_vf_allmulti_result,
14063                  set, "set");
14064 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14065         TOKEN_STRING_INITIALIZER
14066                 (struct cmd_vf_allmulti_result,
14067                  vf, "vf");
14068 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14069         TOKEN_STRING_INITIALIZER
14070                 (struct cmd_vf_allmulti_result,
14071                  allmulti, "allmulti");
14072 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14073         TOKEN_NUM_INITIALIZER
14074                 (struct cmd_vf_allmulti_result,
14075                  port_id, UINT16);
14076 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14077         TOKEN_NUM_INITIALIZER
14078                 (struct cmd_vf_allmulti_result,
14079                  vf_id, UINT32);
14080 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14081         TOKEN_STRING_INITIALIZER
14082                 (struct cmd_vf_allmulti_result,
14083                  on_off, "on#off");
14084
14085 static void
14086 cmd_set_vf_allmulti_parsed(
14087         void *parsed_result,
14088         __attribute__((unused)) struct cmdline *cl,
14089         __attribute__((unused)) void *data)
14090 {
14091         struct cmd_vf_allmulti_result *res = parsed_result;
14092         int ret = -ENOTSUP;
14093
14094         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14095
14096         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14097                 return;
14098
14099 #ifdef RTE_LIBRTE_I40E_PMD
14100         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14101                                                     res->vf_id, is_on);
14102 #endif
14103
14104         switch (ret) {
14105         case 0:
14106                 break;
14107         case -EINVAL:
14108                 printf("invalid vf_id %d\n", res->vf_id);
14109                 break;
14110         case -ENODEV:
14111                 printf("invalid port_id %d\n", res->port_id);
14112                 break;
14113         case -ENOTSUP:
14114                 printf("function not implemented\n");
14115                 break;
14116         default:
14117                 printf("programming error: (%s)\n", strerror(-ret));
14118         }
14119 }
14120
14121 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14122         .f = cmd_set_vf_allmulti_parsed,
14123         .data = NULL,
14124         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14125                 "Set multicast promiscuous mode for a VF from the PF",
14126         .tokens = {
14127                 (void *)&cmd_vf_allmulti_set,
14128                 (void *)&cmd_vf_allmulti_vf,
14129                 (void *)&cmd_vf_allmulti_allmulti,
14130                 (void *)&cmd_vf_allmulti_port_id,
14131                 (void *)&cmd_vf_allmulti_vf_id,
14132                 (void *)&cmd_vf_allmulti_on_off,
14133                 NULL,
14134         },
14135 };
14136
14137 /* vf broadcast mode configuration */
14138
14139 /* Common result structure for vf broadcast */
14140 struct cmd_set_vf_broadcast_result {
14141         cmdline_fixed_string_t set;
14142         cmdline_fixed_string_t vf;
14143         cmdline_fixed_string_t broadcast;
14144         portid_t port_id;
14145         uint16_t vf_id;
14146         cmdline_fixed_string_t on_off;
14147 };
14148
14149 /* Common CLI fields for vf broadcast enable disable */
14150 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14151         TOKEN_STRING_INITIALIZER
14152                 (struct cmd_set_vf_broadcast_result,
14153                  set, "set");
14154 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14155         TOKEN_STRING_INITIALIZER
14156                 (struct cmd_set_vf_broadcast_result,
14157                  vf, "vf");
14158 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14159         TOKEN_STRING_INITIALIZER
14160                 (struct cmd_set_vf_broadcast_result,
14161                  broadcast, "broadcast");
14162 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14163         TOKEN_NUM_INITIALIZER
14164                 (struct cmd_set_vf_broadcast_result,
14165                  port_id, UINT16);
14166 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14167         TOKEN_NUM_INITIALIZER
14168                 (struct cmd_set_vf_broadcast_result,
14169                  vf_id, UINT16);
14170 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14171         TOKEN_STRING_INITIALIZER
14172                 (struct cmd_set_vf_broadcast_result,
14173                  on_off, "on#off");
14174
14175 static void
14176 cmd_set_vf_broadcast_parsed(
14177         void *parsed_result,
14178         __attribute__((unused)) struct cmdline *cl,
14179         __attribute__((unused)) void *data)
14180 {
14181         struct cmd_set_vf_broadcast_result *res = parsed_result;
14182         int ret = -ENOTSUP;
14183
14184         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14185
14186         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14187                 return;
14188
14189 #ifdef RTE_LIBRTE_I40E_PMD
14190         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14191                                             res->vf_id, is_on);
14192 #endif
14193
14194         switch (ret) {
14195         case 0:
14196                 break;
14197         case -EINVAL:
14198                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14199                 break;
14200         case -ENODEV:
14201                 printf("invalid port_id %d\n", res->port_id);
14202                 break;
14203         case -ENOTSUP:
14204                 printf("function not implemented\n");
14205                 break;
14206         default:
14207                 printf("programming error: (%s)\n", strerror(-ret));
14208         }
14209 }
14210
14211 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14212         .f = cmd_set_vf_broadcast_parsed,
14213         .data = NULL,
14214         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14215         .tokens = {
14216                 (void *)&cmd_set_vf_broadcast_set,
14217                 (void *)&cmd_set_vf_broadcast_vf,
14218                 (void *)&cmd_set_vf_broadcast_broadcast,
14219                 (void *)&cmd_set_vf_broadcast_port_id,
14220                 (void *)&cmd_set_vf_broadcast_vf_id,
14221                 (void *)&cmd_set_vf_broadcast_on_off,
14222                 NULL,
14223         },
14224 };
14225
14226 /* vf vlan tag configuration */
14227
14228 /* Common result structure for vf vlan tag */
14229 struct cmd_set_vf_vlan_tag_result {
14230         cmdline_fixed_string_t set;
14231         cmdline_fixed_string_t vf;
14232         cmdline_fixed_string_t vlan;
14233         cmdline_fixed_string_t tag;
14234         portid_t port_id;
14235         uint16_t vf_id;
14236         cmdline_fixed_string_t on_off;
14237 };
14238
14239 /* Common CLI fields for vf vlan tag enable disable */
14240 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14241         TOKEN_STRING_INITIALIZER
14242                 (struct cmd_set_vf_vlan_tag_result,
14243                  set, "set");
14244 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14245         TOKEN_STRING_INITIALIZER
14246                 (struct cmd_set_vf_vlan_tag_result,
14247                  vf, "vf");
14248 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14249         TOKEN_STRING_INITIALIZER
14250                 (struct cmd_set_vf_vlan_tag_result,
14251                  vlan, "vlan");
14252 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14253         TOKEN_STRING_INITIALIZER
14254                 (struct cmd_set_vf_vlan_tag_result,
14255                  tag, "tag");
14256 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14257         TOKEN_NUM_INITIALIZER
14258                 (struct cmd_set_vf_vlan_tag_result,
14259                  port_id, UINT16);
14260 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14261         TOKEN_NUM_INITIALIZER
14262                 (struct cmd_set_vf_vlan_tag_result,
14263                  vf_id, UINT16);
14264 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14265         TOKEN_STRING_INITIALIZER
14266                 (struct cmd_set_vf_vlan_tag_result,
14267                  on_off, "on#off");
14268
14269 static void
14270 cmd_set_vf_vlan_tag_parsed(
14271         void *parsed_result,
14272         __attribute__((unused)) struct cmdline *cl,
14273         __attribute__((unused)) void *data)
14274 {
14275         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14276         int ret = -ENOTSUP;
14277
14278         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14279
14280         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14281                 return;
14282
14283 #ifdef RTE_LIBRTE_I40E_PMD
14284         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14285                                            res->vf_id, is_on);
14286 #endif
14287
14288         switch (ret) {
14289         case 0:
14290                 break;
14291         case -EINVAL:
14292                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14293                 break;
14294         case -ENODEV:
14295                 printf("invalid port_id %d\n", res->port_id);
14296                 break;
14297         case -ENOTSUP:
14298                 printf("function not implemented\n");
14299                 break;
14300         default:
14301                 printf("programming error: (%s)\n", strerror(-ret));
14302         }
14303 }
14304
14305 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14306         .f = cmd_set_vf_vlan_tag_parsed,
14307         .data = NULL,
14308         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14309         .tokens = {
14310                 (void *)&cmd_set_vf_vlan_tag_set,
14311                 (void *)&cmd_set_vf_vlan_tag_vf,
14312                 (void *)&cmd_set_vf_vlan_tag_vlan,
14313                 (void *)&cmd_set_vf_vlan_tag_tag,
14314                 (void *)&cmd_set_vf_vlan_tag_port_id,
14315                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14316                 (void *)&cmd_set_vf_vlan_tag_on_off,
14317                 NULL,
14318         },
14319 };
14320
14321 /* Common definition of VF and TC TX bandwidth configuration */
14322 struct cmd_vf_tc_bw_result {
14323         cmdline_fixed_string_t set;
14324         cmdline_fixed_string_t vf;
14325         cmdline_fixed_string_t tc;
14326         cmdline_fixed_string_t tx;
14327         cmdline_fixed_string_t min_bw;
14328         cmdline_fixed_string_t max_bw;
14329         cmdline_fixed_string_t strict_link_prio;
14330         portid_t port_id;
14331         uint16_t vf_id;
14332         uint8_t tc_no;
14333         uint32_t bw;
14334         cmdline_fixed_string_t bw_list;
14335         uint8_t tc_map;
14336 };
14337
14338 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14339         TOKEN_STRING_INITIALIZER
14340                 (struct cmd_vf_tc_bw_result,
14341                  set, "set");
14342 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14343         TOKEN_STRING_INITIALIZER
14344                 (struct cmd_vf_tc_bw_result,
14345                  vf, "vf");
14346 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14347         TOKEN_STRING_INITIALIZER
14348                 (struct cmd_vf_tc_bw_result,
14349                  tc, "tc");
14350 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14351         TOKEN_STRING_INITIALIZER
14352                 (struct cmd_vf_tc_bw_result,
14353                  tx, "tx");
14354 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14355         TOKEN_STRING_INITIALIZER
14356                 (struct cmd_vf_tc_bw_result,
14357                  strict_link_prio, "strict-link-priority");
14358 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14359         TOKEN_STRING_INITIALIZER
14360                 (struct cmd_vf_tc_bw_result,
14361                  min_bw, "min-bandwidth");
14362 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14363         TOKEN_STRING_INITIALIZER
14364                 (struct cmd_vf_tc_bw_result,
14365                  max_bw, "max-bandwidth");
14366 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14367         TOKEN_NUM_INITIALIZER
14368                 (struct cmd_vf_tc_bw_result,
14369                  port_id, UINT16);
14370 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14371         TOKEN_NUM_INITIALIZER
14372                 (struct cmd_vf_tc_bw_result,
14373                  vf_id, UINT16);
14374 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14375         TOKEN_NUM_INITIALIZER
14376                 (struct cmd_vf_tc_bw_result,
14377                  tc_no, UINT8);
14378 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14379         TOKEN_NUM_INITIALIZER
14380                 (struct cmd_vf_tc_bw_result,
14381                  bw, UINT32);
14382 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14383         TOKEN_STRING_INITIALIZER
14384                 (struct cmd_vf_tc_bw_result,
14385                  bw_list, NULL);
14386 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14387         TOKEN_NUM_INITIALIZER
14388                 (struct cmd_vf_tc_bw_result,
14389                  tc_map, UINT8);
14390
14391 /* VF max bandwidth setting */
14392 static void
14393 cmd_vf_max_bw_parsed(
14394         void *parsed_result,
14395         __attribute__((unused)) struct cmdline *cl,
14396         __attribute__((unused)) void *data)
14397 {
14398         struct cmd_vf_tc_bw_result *res = parsed_result;
14399         int ret = -ENOTSUP;
14400
14401         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14402                 return;
14403
14404 #ifdef RTE_LIBRTE_I40E_PMD
14405         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14406                                          res->vf_id, res->bw);
14407 #endif
14408
14409         switch (ret) {
14410         case 0:
14411                 break;
14412         case -EINVAL:
14413                 printf("invalid vf_id %d or bandwidth %d\n",
14414                        res->vf_id, res->bw);
14415                 break;
14416         case -ENODEV:
14417                 printf("invalid port_id %d\n", res->port_id);
14418                 break;
14419         case -ENOTSUP:
14420                 printf("function not implemented\n");
14421                 break;
14422         default:
14423                 printf("programming error: (%s)\n", strerror(-ret));
14424         }
14425 }
14426
14427 cmdline_parse_inst_t cmd_vf_max_bw = {
14428         .f = cmd_vf_max_bw_parsed,
14429         .data = NULL,
14430         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14431         .tokens = {
14432                 (void *)&cmd_vf_tc_bw_set,
14433                 (void *)&cmd_vf_tc_bw_vf,
14434                 (void *)&cmd_vf_tc_bw_tx,
14435                 (void *)&cmd_vf_tc_bw_max_bw,
14436                 (void *)&cmd_vf_tc_bw_port_id,
14437                 (void *)&cmd_vf_tc_bw_vf_id,
14438                 (void *)&cmd_vf_tc_bw_bw,
14439                 NULL,
14440         },
14441 };
14442
14443 static int
14444 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14445                            uint8_t *tc_num,
14446                            char *str)
14447 {
14448         uint32_t size;
14449         const char *p, *p0 = str;
14450         char s[256];
14451         char *end;
14452         char *str_fld[16];
14453         uint16_t i;
14454         int ret;
14455
14456         p = strchr(p0, '(');
14457         if (p == NULL) {
14458                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14459                 return -1;
14460         }
14461         p++;
14462         p0 = strchr(p, ')');
14463         if (p0 == NULL) {
14464                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14465                 return -1;
14466         }
14467         size = p0 - p;
14468         if (size >= sizeof(s)) {
14469                 printf("The string size exceeds the internal buffer size\n");
14470                 return -1;
14471         }
14472         snprintf(s, sizeof(s), "%.*s", size, p);
14473         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14474         if (ret <= 0) {
14475                 printf("Failed to get the bandwidth list. ");
14476                 return -1;
14477         }
14478         *tc_num = ret;
14479         for (i = 0; i < ret; i++)
14480                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14481
14482         return 0;
14483 }
14484
14485 /* TC min bandwidth setting */
14486 static void
14487 cmd_vf_tc_min_bw_parsed(
14488         void *parsed_result,
14489         __attribute__((unused)) struct cmdline *cl,
14490         __attribute__((unused)) void *data)
14491 {
14492         struct cmd_vf_tc_bw_result *res = parsed_result;
14493         uint8_t tc_num;
14494         uint8_t bw[16];
14495         int ret = -ENOTSUP;
14496
14497         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14498                 return;
14499
14500         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14501         if (ret)
14502                 return;
14503
14504 #ifdef RTE_LIBRTE_I40E_PMD
14505         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14506                                               tc_num, bw);
14507 #endif
14508
14509         switch (ret) {
14510         case 0:
14511                 break;
14512         case -EINVAL:
14513                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14514                 break;
14515         case -ENODEV:
14516                 printf("invalid port_id %d\n", res->port_id);
14517                 break;
14518         case -ENOTSUP:
14519                 printf("function not implemented\n");
14520                 break;
14521         default:
14522                 printf("programming error: (%s)\n", strerror(-ret));
14523         }
14524 }
14525
14526 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14527         .f = cmd_vf_tc_min_bw_parsed,
14528         .data = NULL,
14529         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14530                     " <bw1, bw2, ...>",
14531         .tokens = {
14532                 (void *)&cmd_vf_tc_bw_set,
14533                 (void *)&cmd_vf_tc_bw_vf,
14534                 (void *)&cmd_vf_tc_bw_tc,
14535                 (void *)&cmd_vf_tc_bw_tx,
14536                 (void *)&cmd_vf_tc_bw_min_bw,
14537                 (void *)&cmd_vf_tc_bw_port_id,
14538                 (void *)&cmd_vf_tc_bw_vf_id,
14539                 (void *)&cmd_vf_tc_bw_bw_list,
14540                 NULL,
14541         },
14542 };
14543
14544 static void
14545 cmd_tc_min_bw_parsed(
14546         void *parsed_result,
14547         __attribute__((unused)) struct cmdline *cl,
14548         __attribute__((unused)) void *data)
14549 {
14550         struct cmd_vf_tc_bw_result *res = parsed_result;
14551         struct rte_port *port;
14552         uint8_t tc_num;
14553         uint8_t bw[16];
14554         int ret = -ENOTSUP;
14555
14556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14557                 return;
14558
14559         port = &ports[res->port_id];
14560         /** Check if the port is not started **/
14561         if (port->port_status != RTE_PORT_STOPPED) {
14562                 printf("Please stop port %d first\n", res->port_id);
14563                 return;
14564         }
14565
14566         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14567         if (ret)
14568                 return;
14569
14570 #ifdef RTE_LIBRTE_IXGBE_PMD
14571         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14572 #endif
14573
14574         switch (ret) {
14575         case 0:
14576                 break;
14577         case -EINVAL:
14578                 printf("invalid bandwidth\n");
14579                 break;
14580         case -ENODEV:
14581                 printf("invalid port_id %d\n", res->port_id);
14582                 break;
14583         case -ENOTSUP:
14584                 printf("function not implemented\n");
14585                 break;
14586         default:
14587                 printf("programming error: (%s)\n", strerror(-ret));
14588         }
14589 }
14590
14591 cmdline_parse_inst_t cmd_tc_min_bw = {
14592         .f = cmd_tc_min_bw_parsed,
14593         .data = NULL,
14594         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14595         .tokens = {
14596                 (void *)&cmd_vf_tc_bw_set,
14597                 (void *)&cmd_vf_tc_bw_tc,
14598                 (void *)&cmd_vf_tc_bw_tx,
14599                 (void *)&cmd_vf_tc_bw_min_bw,
14600                 (void *)&cmd_vf_tc_bw_port_id,
14601                 (void *)&cmd_vf_tc_bw_bw_list,
14602                 NULL,
14603         },
14604 };
14605
14606 /* TC max bandwidth setting */
14607 static void
14608 cmd_vf_tc_max_bw_parsed(
14609         void *parsed_result,
14610         __attribute__((unused)) struct cmdline *cl,
14611         __attribute__((unused)) void *data)
14612 {
14613         struct cmd_vf_tc_bw_result *res = parsed_result;
14614         int ret = -ENOTSUP;
14615
14616         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14617                 return;
14618
14619 #ifdef RTE_LIBRTE_I40E_PMD
14620         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14621                                             res->tc_no, res->bw);
14622 #endif
14623
14624         switch (ret) {
14625         case 0:
14626                 break;
14627         case -EINVAL:
14628                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14629                        res->vf_id, res->tc_no, res->bw);
14630                 break;
14631         case -ENODEV:
14632                 printf("invalid port_id %d\n", res->port_id);
14633                 break;
14634         case -ENOTSUP:
14635                 printf("function not implemented\n");
14636                 break;
14637         default:
14638                 printf("programming error: (%s)\n", strerror(-ret));
14639         }
14640 }
14641
14642 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14643         .f = cmd_vf_tc_max_bw_parsed,
14644         .data = NULL,
14645         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14646                     " <bandwidth>",
14647         .tokens = {
14648                 (void *)&cmd_vf_tc_bw_set,
14649                 (void *)&cmd_vf_tc_bw_vf,
14650                 (void *)&cmd_vf_tc_bw_tc,
14651                 (void *)&cmd_vf_tc_bw_tx,
14652                 (void *)&cmd_vf_tc_bw_max_bw,
14653                 (void *)&cmd_vf_tc_bw_port_id,
14654                 (void *)&cmd_vf_tc_bw_vf_id,
14655                 (void *)&cmd_vf_tc_bw_tc_no,
14656                 (void *)&cmd_vf_tc_bw_bw,
14657                 NULL,
14658         },
14659 };
14660
14661
14662 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14663
14664 /* *** Set Port default Traffic Management Hierarchy *** */
14665 struct cmd_set_port_tm_hierarchy_default_result {
14666         cmdline_fixed_string_t set;
14667         cmdline_fixed_string_t port;
14668         cmdline_fixed_string_t tm;
14669         cmdline_fixed_string_t hierarchy;
14670         cmdline_fixed_string_t def;
14671         portid_t port_id;
14672 };
14673
14674 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14675         TOKEN_STRING_INITIALIZER(
14676                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14677 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14678         TOKEN_STRING_INITIALIZER(
14679                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14680 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14681         TOKEN_STRING_INITIALIZER(
14682                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14683 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14684         TOKEN_STRING_INITIALIZER(
14685                 struct cmd_set_port_tm_hierarchy_default_result,
14686                         hierarchy, "hierarchy");
14687 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14688         TOKEN_STRING_INITIALIZER(
14689                 struct cmd_set_port_tm_hierarchy_default_result,
14690                         def, "default");
14691 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14692         TOKEN_NUM_INITIALIZER(
14693                 struct cmd_set_port_tm_hierarchy_default_result,
14694                         port_id, UINT16);
14695
14696 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14697         __attribute__((unused)) struct cmdline *cl,
14698         __attribute__((unused)) void *data)
14699 {
14700         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14701         struct rte_port *p;
14702         portid_t port_id = res->port_id;
14703
14704         if (port_id_is_invalid(port_id, ENABLED_WARN))
14705                 return;
14706
14707         p = &ports[port_id];
14708
14709         /* Port tm flag */
14710         if (p->softport.tm_flag == 0) {
14711                 printf("  tm not enabled on port %u (error)\n", port_id);
14712                 return;
14713         }
14714
14715         /* Forward mode: tm */
14716         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14717                 printf("  tm mode not enabled(error)\n");
14718                 return;
14719         }
14720
14721         /* Set the default tm hierarchy */
14722         p->softport.tm.default_hierarchy_enable = 1;
14723 }
14724
14725 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14726         .f = cmd_set_port_tm_hierarchy_default_parsed,
14727         .data = NULL,
14728         .help_str = "set port tm hierarchy default <port_id>",
14729         .tokens = {
14730                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14731                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14732                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14733                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14734                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14735                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14736                 NULL,
14737         },
14738 };
14739 #endif
14740
14741 /* Strict link priority scheduling mode setting */
14742 static void
14743 cmd_strict_link_prio_parsed(
14744         void *parsed_result,
14745         __attribute__((unused)) struct cmdline *cl,
14746         __attribute__((unused)) void *data)
14747 {
14748         struct cmd_vf_tc_bw_result *res = parsed_result;
14749         int ret = -ENOTSUP;
14750
14751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14752                 return;
14753
14754 #ifdef RTE_LIBRTE_I40E_PMD
14755         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14756 #endif
14757
14758         switch (ret) {
14759         case 0:
14760                 break;
14761         case -EINVAL:
14762                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14763                 break;
14764         case -ENODEV:
14765                 printf("invalid port_id %d\n", res->port_id);
14766                 break;
14767         case -ENOTSUP:
14768                 printf("function not implemented\n");
14769                 break;
14770         default:
14771                 printf("programming error: (%s)\n", strerror(-ret));
14772         }
14773 }
14774
14775 cmdline_parse_inst_t cmd_strict_link_prio = {
14776         .f = cmd_strict_link_prio_parsed,
14777         .data = NULL,
14778         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14779         .tokens = {
14780                 (void *)&cmd_vf_tc_bw_set,
14781                 (void *)&cmd_vf_tc_bw_tx,
14782                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14783                 (void *)&cmd_vf_tc_bw_port_id,
14784                 (void *)&cmd_vf_tc_bw_tc_map,
14785                 NULL,
14786         },
14787 };
14788
14789 /* Load dynamic device personalization*/
14790 struct cmd_ddp_add_result {
14791         cmdline_fixed_string_t ddp;
14792         cmdline_fixed_string_t add;
14793         portid_t port_id;
14794         char filepath[];
14795 };
14796
14797 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14798         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14799 cmdline_parse_token_string_t cmd_ddp_add_add =
14800         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14801 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14802         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14803 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14804         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14805
14806 static void
14807 cmd_ddp_add_parsed(
14808         void *parsed_result,
14809         __attribute__((unused)) struct cmdline *cl,
14810         __attribute__((unused)) void *data)
14811 {
14812         struct cmd_ddp_add_result *res = parsed_result;
14813         uint8_t *buff;
14814         uint32_t size;
14815         char *filepath;
14816         char *file_fld[2];
14817         int file_num;
14818         int ret = -ENOTSUP;
14819
14820         if (!all_ports_stopped()) {
14821                 printf("Please stop all ports first\n");
14822                 return;
14823         }
14824
14825         filepath = strdup(res->filepath);
14826         if (filepath == NULL) {
14827                 printf("Failed to allocate memory\n");
14828                 return;
14829         }
14830         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14831
14832         buff = open_file(file_fld[0], &size);
14833         if (!buff) {
14834                 free((void *)filepath);
14835                 return;
14836         }
14837
14838 #ifdef RTE_LIBRTE_I40E_PMD
14839         if (ret == -ENOTSUP)
14840                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14841                                                buff, size,
14842                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14843 #endif
14844
14845         if (ret == -EEXIST)
14846                 printf("Profile has already existed.\n");
14847         else if (ret < 0)
14848                 printf("Failed to load profile.\n");
14849         else if (file_num == 2)
14850                 save_file(file_fld[1], buff, size);
14851
14852         close_file(buff);
14853         free((void *)filepath);
14854 }
14855
14856 cmdline_parse_inst_t cmd_ddp_add = {
14857         .f = cmd_ddp_add_parsed,
14858         .data = NULL,
14859         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14860         .tokens = {
14861                 (void *)&cmd_ddp_add_ddp,
14862                 (void *)&cmd_ddp_add_add,
14863                 (void *)&cmd_ddp_add_port_id,
14864                 (void *)&cmd_ddp_add_filepath,
14865                 NULL,
14866         },
14867 };
14868
14869 /* Delete dynamic device personalization*/
14870 struct cmd_ddp_del_result {
14871         cmdline_fixed_string_t ddp;
14872         cmdline_fixed_string_t del;
14873         portid_t port_id;
14874         char filepath[];
14875 };
14876
14877 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14878         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14879 cmdline_parse_token_string_t cmd_ddp_del_del =
14880         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14881 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14882         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14883 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14884         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14885
14886 static void
14887 cmd_ddp_del_parsed(
14888         void *parsed_result,
14889         __attribute__((unused)) struct cmdline *cl,
14890         __attribute__((unused)) void *data)
14891 {
14892         struct cmd_ddp_del_result *res = parsed_result;
14893         uint8_t *buff;
14894         uint32_t size;
14895         int ret = -ENOTSUP;
14896
14897         if (!all_ports_stopped()) {
14898                 printf("Please stop all ports first\n");
14899                 return;
14900         }
14901
14902         buff = open_file(res->filepath, &size);
14903         if (!buff)
14904                 return;
14905
14906 #ifdef RTE_LIBRTE_I40E_PMD
14907         if (ret == -ENOTSUP)
14908                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14909                                                buff, size,
14910                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14911 #endif
14912
14913         if (ret == -EACCES)
14914                 printf("Profile does not exist.\n");
14915         else if (ret < 0)
14916                 printf("Failed to delete profile.\n");
14917
14918         close_file(buff);
14919 }
14920
14921 cmdline_parse_inst_t cmd_ddp_del = {
14922         .f = cmd_ddp_del_parsed,
14923         .data = NULL,
14924         .help_str = "ddp del <port_id> <backup_profile_path>",
14925         .tokens = {
14926                 (void *)&cmd_ddp_del_ddp,
14927                 (void *)&cmd_ddp_del_del,
14928                 (void *)&cmd_ddp_del_port_id,
14929                 (void *)&cmd_ddp_del_filepath,
14930                 NULL,
14931         },
14932 };
14933
14934 /* Get dynamic device personalization profile info */
14935 struct cmd_ddp_info_result {
14936         cmdline_fixed_string_t ddp;
14937         cmdline_fixed_string_t get;
14938         cmdline_fixed_string_t info;
14939         char filepath[];
14940 };
14941
14942 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14943         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14944 cmdline_parse_token_string_t cmd_ddp_info_get =
14945         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14946 cmdline_parse_token_string_t cmd_ddp_info_info =
14947         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14948 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14949         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14950
14951 static void
14952 cmd_ddp_info_parsed(
14953         void *parsed_result,
14954         __attribute__((unused)) struct cmdline *cl,
14955         __attribute__((unused)) void *data)
14956 {
14957         struct cmd_ddp_info_result *res = parsed_result;
14958         uint8_t *pkg;
14959         uint32_t pkg_size;
14960         int ret = -ENOTSUP;
14961 #ifdef RTE_LIBRTE_I40E_PMD
14962         uint32_t i, j, n;
14963         uint8_t *buff;
14964         uint32_t buff_size = 0;
14965         struct rte_pmd_i40e_profile_info info;
14966         uint32_t dev_num = 0;
14967         struct rte_pmd_i40e_ddp_device_id *devs;
14968         uint32_t proto_num = 0;
14969         struct rte_pmd_i40e_proto_info *proto = NULL;
14970         uint32_t pctype_num = 0;
14971         struct rte_pmd_i40e_ptype_info *pctype;
14972         uint32_t ptype_num = 0;
14973         struct rte_pmd_i40e_ptype_info *ptype;
14974         uint8_t proto_id;
14975
14976 #endif
14977
14978         pkg = open_file(res->filepath, &pkg_size);
14979         if (!pkg)
14980                 return;
14981
14982 #ifdef RTE_LIBRTE_I40E_PMD
14983         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14984                                 (uint8_t *)&info, sizeof(info),
14985                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14986         if (!ret) {
14987                 printf("Global Track id:       0x%x\n", info.track_id);
14988                 printf("Global Version:        %d.%d.%d.%d\n",
14989                         info.version.major,
14990                         info.version.minor,
14991                         info.version.update,
14992                         info.version.draft);
14993                 printf("Global Package name:   %s\n\n", info.name);
14994         }
14995
14996         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14997                                 (uint8_t *)&info, sizeof(info),
14998                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14999         if (!ret) {
15000                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15001                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15002                         info.version.major,
15003                         info.version.minor,
15004                         info.version.update,
15005                         info.version.draft);
15006                 printf("i40e Profile name:     %s\n\n", info.name);
15007         }
15008
15009         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15010                                 (uint8_t *)&buff_size, sizeof(buff_size),
15011                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15012         if (!ret && buff_size) {
15013                 buff = (uint8_t *)malloc(buff_size);
15014                 if (buff) {
15015                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15016                                                 buff, buff_size,
15017                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15018                         if (!ret)
15019                                 printf("Package Notes:\n%s\n\n", buff);
15020                         free(buff);
15021                 }
15022         }
15023
15024         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15025                                 (uint8_t *)&dev_num, sizeof(dev_num),
15026                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15027         if (!ret && dev_num) {
15028                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15029                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15030                 if (devs) {
15031                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15032                                                 (uint8_t *)devs, buff_size,
15033                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15034                         if (!ret) {
15035                                 printf("List of supported devices:\n");
15036                                 for (i = 0; i < dev_num; i++) {
15037                                         printf("  %04X:%04X %04X:%04X\n",
15038                                                 devs[i].vendor_dev_id >> 16,
15039                                                 devs[i].vendor_dev_id & 0xFFFF,
15040                                                 devs[i].sub_vendor_dev_id >> 16,
15041                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15042                                 }
15043                                 printf("\n");
15044                         }
15045                         free(devs);
15046                 }
15047         }
15048
15049         /* get information about protocols and packet types */
15050         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15051                 (uint8_t *)&proto_num, sizeof(proto_num),
15052                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15053         if (ret || !proto_num)
15054                 goto no_print_return;
15055
15056         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15057         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15058         if (!proto)
15059                 goto no_print_return;
15060
15061         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15062                                         buff_size,
15063                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15064         if (!ret) {
15065                 printf("List of used protocols:\n");
15066                 for (i = 0; i < proto_num; i++)
15067                         printf("  %2u: %s\n", proto[i].proto_id,
15068                                proto[i].name);
15069                 printf("\n");
15070         }
15071         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15072                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15073                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15074         if (ret || !pctype_num)
15075                 goto no_print_pctypes;
15076
15077         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15078         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15079         if (!pctype)
15080                 goto no_print_pctypes;
15081
15082         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15083                                         buff_size,
15084                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15085         if (ret) {
15086                 free(pctype);
15087                 goto no_print_pctypes;
15088         }
15089
15090         printf("List of defined packet classification types:\n");
15091         for (i = 0; i < pctype_num; i++) {
15092                 printf("  %2u:", pctype[i].ptype_id);
15093                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15094                         proto_id = pctype[i].protocols[j];
15095                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15096                                 for (n = 0; n < proto_num; n++) {
15097                                         if (proto[n].proto_id == proto_id) {
15098                                                 printf(" %s", proto[n].name);
15099                                                 break;
15100                                         }
15101                                 }
15102                         }
15103                 }
15104                 printf("\n");
15105         }
15106         printf("\n");
15107         free(pctype);
15108
15109 no_print_pctypes:
15110
15111         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15112                                         sizeof(ptype_num),
15113                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15114         if (ret || !ptype_num)
15115                 goto no_print_return;
15116
15117         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15118         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15119         if (!ptype)
15120                 goto no_print_return;
15121
15122         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15123                                         buff_size,
15124                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15125         if (ret) {
15126                 free(ptype);
15127                 goto no_print_return;
15128         }
15129         printf("List of defined packet types:\n");
15130         for (i = 0; i < ptype_num; i++) {
15131                 printf("  %2u:", ptype[i].ptype_id);
15132                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15133                         proto_id = ptype[i].protocols[j];
15134                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15135                                 for (n = 0; n < proto_num; n++) {
15136                                         if (proto[n].proto_id == proto_id) {
15137                                                 printf(" %s", proto[n].name);
15138                                                 break;
15139                                         }
15140                                 }
15141                         }
15142                 }
15143                 printf("\n");
15144         }
15145         free(ptype);
15146         printf("\n");
15147
15148         ret = 0;
15149 no_print_return:
15150         if (proto)
15151                 free(proto);
15152 #endif
15153         if (ret == -ENOTSUP)
15154                 printf("Function not supported in PMD driver\n");
15155         close_file(pkg);
15156 }
15157
15158 cmdline_parse_inst_t cmd_ddp_get_info = {
15159         .f = cmd_ddp_info_parsed,
15160         .data = NULL,
15161         .help_str = "ddp get info <profile_path>",
15162         .tokens = {
15163                 (void *)&cmd_ddp_info_ddp,
15164                 (void *)&cmd_ddp_info_get,
15165                 (void *)&cmd_ddp_info_info,
15166                 (void *)&cmd_ddp_info_filepath,
15167                 NULL,
15168         },
15169 };
15170
15171 /* Get dynamic device personalization profile info list*/
15172 #define PROFILE_INFO_SIZE 48
15173 #define MAX_PROFILE_NUM 16
15174
15175 struct cmd_ddp_get_list_result {
15176         cmdline_fixed_string_t ddp;
15177         cmdline_fixed_string_t get;
15178         cmdline_fixed_string_t list;
15179         portid_t port_id;
15180 };
15181
15182 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15183         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15184 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15185         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15186 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15187         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15188 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15189         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15190
15191 static void
15192 cmd_ddp_get_list_parsed(
15193         __attribute__((unused)) void *parsed_result,
15194         __attribute__((unused)) struct cmdline *cl,
15195         __attribute__((unused)) void *data)
15196 {
15197 #ifdef RTE_LIBRTE_I40E_PMD
15198         struct cmd_ddp_get_list_result *res = parsed_result;
15199         struct rte_pmd_i40e_profile_list *p_list;
15200         struct rte_pmd_i40e_profile_info *p_info;
15201         uint32_t p_num;
15202         uint32_t size;
15203         uint32_t i;
15204 #endif
15205         int ret = -ENOTSUP;
15206
15207 #ifdef RTE_LIBRTE_I40E_PMD
15208         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15209         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15210         if (!p_list)
15211                 printf("%s: Failed to malloc buffer\n", __func__);
15212
15213         if (ret == -ENOTSUP)
15214                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15215                                                 (uint8_t *)p_list, size);
15216
15217         if (!ret) {
15218                 p_num = p_list->p_count;
15219                 printf("Profile number is: %d\n\n", p_num);
15220
15221                 for (i = 0; i < p_num; i++) {
15222                         p_info = &p_list->p_info[i];
15223                         printf("Profile %d:\n", i);
15224                         printf("Track id:     0x%x\n", p_info->track_id);
15225                         printf("Version:      %d.%d.%d.%d\n",
15226                                p_info->version.major,
15227                                p_info->version.minor,
15228                                p_info->version.update,
15229                                p_info->version.draft);
15230                         printf("Profile name: %s\n\n", p_info->name);
15231                 }
15232         }
15233
15234         free(p_list);
15235 #endif
15236
15237         if (ret < 0)
15238                 printf("Failed to get ddp list\n");
15239 }
15240
15241 cmdline_parse_inst_t cmd_ddp_get_list = {
15242         .f = cmd_ddp_get_list_parsed,
15243         .data = NULL,
15244         .help_str = "ddp get list <port_id>",
15245         .tokens = {
15246                 (void *)&cmd_ddp_get_list_ddp,
15247                 (void *)&cmd_ddp_get_list_get,
15248                 (void *)&cmd_ddp_get_list_list,
15249                 (void *)&cmd_ddp_get_list_port_id,
15250                 NULL,
15251         },
15252 };
15253
15254 /* Configure input set */
15255 struct cmd_cfg_input_set_result {
15256         cmdline_fixed_string_t port;
15257         cmdline_fixed_string_t cfg;
15258         portid_t port_id;
15259         cmdline_fixed_string_t pctype;
15260         uint8_t pctype_id;
15261         cmdline_fixed_string_t inset_type;
15262         cmdline_fixed_string_t opt;
15263         cmdline_fixed_string_t field;
15264         uint8_t field_idx;
15265 };
15266
15267 static void
15268 cmd_cfg_input_set_parsed(
15269         __attribute__((unused)) void *parsed_result,
15270         __attribute__((unused)) struct cmdline *cl,
15271         __attribute__((unused)) void *data)
15272 {
15273 #ifdef RTE_LIBRTE_I40E_PMD
15274         struct cmd_cfg_input_set_result *res = parsed_result;
15275         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15276         struct rte_pmd_i40e_inset inset;
15277 #endif
15278         int ret = -ENOTSUP;
15279
15280         if (!all_ports_stopped()) {
15281                 printf("Please stop all ports first\n");
15282                 return;
15283         }
15284
15285 #ifdef RTE_LIBRTE_I40E_PMD
15286         if (!strcmp(res->inset_type, "hash_inset"))
15287                 inset_type = INSET_HASH;
15288         else if (!strcmp(res->inset_type, "fdir_inset"))
15289                 inset_type = INSET_FDIR;
15290         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15291                 inset_type = INSET_FDIR_FLX;
15292         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15293                                      &inset, inset_type);
15294         if (ret) {
15295                 printf("Failed to get input set.\n");
15296                 return;
15297         }
15298
15299         if (!strcmp(res->opt, "get")) {
15300                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15301                                                    res->field_idx);
15302                 if (ret)
15303                         printf("Field index %d is enabled.\n", res->field_idx);
15304                 else
15305                         printf("Field index %d is disabled.\n", res->field_idx);
15306                 return;
15307         } else if (!strcmp(res->opt, "set"))
15308                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15309                                                    res->field_idx);
15310         else if (!strcmp(res->opt, "clear"))
15311                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15312                                                      res->field_idx);
15313         if (ret) {
15314                 printf("Failed to configure input set field.\n");
15315                 return;
15316         }
15317
15318         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15319                                      &inset, inset_type);
15320         if (ret) {
15321                 printf("Failed to set input set.\n");
15322                 return;
15323         }
15324 #endif
15325
15326         if (ret == -ENOTSUP)
15327                 printf("Function not supported\n");
15328 }
15329
15330 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15331         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15332                                  port, "port");
15333 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15334         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15335                                  cfg, "config");
15336 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15337         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15338                               port_id, UINT16);
15339 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15340         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15341                                  pctype, "pctype");
15342 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15343         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15344                               pctype_id, UINT8);
15345 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15346         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15347                                  inset_type,
15348                                  "hash_inset#fdir_inset#fdir_flx_inset");
15349 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15350         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15351                                  opt, "get#set#clear");
15352 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15353         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15354                                  field, "field");
15355 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15356         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15357                               field_idx, UINT8);
15358
15359 cmdline_parse_inst_t cmd_cfg_input_set = {
15360         .f = cmd_cfg_input_set_parsed,
15361         .data = NULL,
15362         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15363                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15364         .tokens = {
15365                 (void *)&cmd_cfg_input_set_port,
15366                 (void *)&cmd_cfg_input_set_cfg,
15367                 (void *)&cmd_cfg_input_set_port_id,
15368                 (void *)&cmd_cfg_input_set_pctype,
15369                 (void *)&cmd_cfg_input_set_pctype_id,
15370                 (void *)&cmd_cfg_input_set_inset_type,
15371                 (void *)&cmd_cfg_input_set_opt,
15372                 (void *)&cmd_cfg_input_set_field,
15373                 (void *)&cmd_cfg_input_set_field_idx,
15374                 NULL,
15375         },
15376 };
15377
15378 /* Clear input set */
15379 struct cmd_clear_input_set_result {
15380         cmdline_fixed_string_t port;
15381         cmdline_fixed_string_t cfg;
15382         portid_t port_id;
15383         cmdline_fixed_string_t pctype;
15384         uint8_t pctype_id;
15385         cmdline_fixed_string_t inset_type;
15386         cmdline_fixed_string_t clear;
15387         cmdline_fixed_string_t all;
15388 };
15389
15390 static void
15391 cmd_clear_input_set_parsed(
15392         __attribute__((unused)) void *parsed_result,
15393         __attribute__((unused)) struct cmdline *cl,
15394         __attribute__((unused)) void *data)
15395 {
15396 #ifdef RTE_LIBRTE_I40E_PMD
15397         struct cmd_clear_input_set_result *res = parsed_result;
15398         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15399         struct rte_pmd_i40e_inset inset;
15400 #endif
15401         int ret = -ENOTSUP;
15402
15403         if (!all_ports_stopped()) {
15404                 printf("Please stop all ports first\n");
15405                 return;
15406         }
15407
15408 #ifdef RTE_LIBRTE_I40E_PMD
15409         if (!strcmp(res->inset_type, "hash_inset"))
15410                 inset_type = INSET_HASH;
15411         else if (!strcmp(res->inset_type, "fdir_inset"))
15412                 inset_type = INSET_FDIR;
15413         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15414                 inset_type = INSET_FDIR_FLX;
15415
15416         memset(&inset, 0, sizeof(inset));
15417
15418         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15419                                      &inset, inset_type);
15420         if (ret) {
15421                 printf("Failed to clear input set.\n");
15422                 return;
15423         }
15424
15425 #endif
15426
15427         if (ret == -ENOTSUP)
15428                 printf("Function not supported\n");
15429 }
15430
15431 cmdline_parse_token_string_t cmd_clear_input_set_port =
15432         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15433                                  port, "port");
15434 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15435         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15436                                  cfg, "config");
15437 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15438         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15439                               port_id, UINT16);
15440 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15441         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15442                                  pctype, "pctype");
15443 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15444         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15445                               pctype_id, UINT8);
15446 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15447         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15448                                  inset_type,
15449                                  "hash_inset#fdir_inset#fdir_flx_inset");
15450 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15451         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15452                                  clear, "clear");
15453 cmdline_parse_token_string_t cmd_clear_input_set_all =
15454         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15455                                  all, "all");
15456
15457 cmdline_parse_inst_t cmd_clear_input_set = {
15458         .f = cmd_clear_input_set_parsed,
15459         .data = NULL,
15460         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15461                     "fdir_inset|fdir_flx_inset clear all",
15462         .tokens = {
15463                 (void *)&cmd_clear_input_set_port,
15464                 (void *)&cmd_clear_input_set_cfg,
15465                 (void *)&cmd_clear_input_set_port_id,
15466                 (void *)&cmd_clear_input_set_pctype,
15467                 (void *)&cmd_clear_input_set_pctype_id,
15468                 (void *)&cmd_clear_input_set_inset_type,
15469                 (void *)&cmd_clear_input_set_clear,
15470                 (void *)&cmd_clear_input_set_all,
15471                 NULL,
15472         },
15473 };
15474
15475 /* show vf stats */
15476
15477 /* Common result structure for show vf stats */
15478 struct cmd_show_vf_stats_result {
15479         cmdline_fixed_string_t show;
15480         cmdline_fixed_string_t vf;
15481         cmdline_fixed_string_t stats;
15482         portid_t port_id;
15483         uint16_t vf_id;
15484 };
15485
15486 /* Common CLI fields show vf stats*/
15487 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15488         TOKEN_STRING_INITIALIZER
15489                 (struct cmd_show_vf_stats_result,
15490                  show, "show");
15491 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15492         TOKEN_STRING_INITIALIZER
15493                 (struct cmd_show_vf_stats_result,
15494                  vf, "vf");
15495 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15496         TOKEN_STRING_INITIALIZER
15497                 (struct cmd_show_vf_stats_result,
15498                  stats, "stats");
15499 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15500         TOKEN_NUM_INITIALIZER
15501                 (struct cmd_show_vf_stats_result,
15502                  port_id, UINT16);
15503 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15504         TOKEN_NUM_INITIALIZER
15505                 (struct cmd_show_vf_stats_result,
15506                  vf_id, UINT16);
15507
15508 static void
15509 cmd_show_vf_stats_parsed(
15510         void *parsed_result,
15511         __attribute__((unused)) struct cmdline *cl,
15512         __attribute__((unused)) void *data)
15513 {
15514         struct cmd_show_vf_stats_result *res = parsed_result;
15515         struct rte_eth_stats stats;
15516         int ret = -ENOTSUP;
15517         static const char *nic_stats_border = "########################";
15518
15519         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15520                 return;
15521
15522         memset(&stats, 0, sizeof(stats));
15523
15524 #ifdef RTE_LIBRTE_I40E_PMD
15525         if (ret == -ENOTSUP)
15526                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15527                                                 res->vf_id,
15528                                                 &stats);
15529 #endif
15530 #ifdef RTE_LIBRTE_BNXT_PMD
15531         if (ret == -ENOTSUP)
15532                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15533                                                 res->vf_id,
15534                                                 &stats);
15535 #endif
15536
15537         switch (ret) {
15538         case 0:
15539                 break;
15540         case -EINVAL:
15541                 printf("invalid vf_id %d\n", res->vf_id);
15542                 break;
15543         case -ENODEV:
15544                 printf("invalid port_id %d\n", res->port_id);
15545                 break;
15546         case -ENOTSUP:
15547                 printf("function not implemented\n");
15548                 break;
15549         default:
15550                 printf("programming error: (%s)\n", strerror(-ret));
15551         }
15552
15553         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15554                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15555
15556         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15557                "%-"PRIu64"\n",
15558                stats.ipackets, stats.imissed, stats.ibytes);
15559         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15560         printf("  RX-nombuf:  %-10"PRIu64"\n",
15561                stats.rx_nombuf);
15562         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15563                "%-"PRIu64"\n",
15564                stats.opackets, stats.oerrors, stats.obytes);
15565
15566         printf("  %s############################%s\n",
15567                                nic_stats_border, nic_stats_border);
15568 }
15569
15570 cmdline_parse_inst_t cmd_show_vf_stats = {
15571         .f = cmd_show_vf_stats_parsed,
15572         .data = NULL,
15573         .help_str = "show vf stats <port_id> <vf_id>",
15574         .tokens = {
15575                 (void *)&cmd_show_vf_stats_show,
15576                 (void *)&cmd_show_vf_stats_vf,
15577                 (void *)&cmd_show_vf_stats_stats,
15578                 (void *)&cmd_show_vf_stats_port_id,
15579                 (void *)&cmd_show_vf_stats_vf_id,
15580                 NULL,
15581         },
15582 };
15583
15584 /* clear vf stats */
15585
15586 /* Common result structure for clear vf stats */
15587 struct cmd_clear_vf_stats_result {
15588         cmdline_fixed_string_t clear;
15589         cmdline_fixed_string_t vf;
15590         cmdline_fixed_string_t stats;
15591         portid_t port_id;
15592         uint16_t vf_id;
15593 };
15594
15595 /* Common CLI fields clear vf stats*/
15596 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15597         TOKEN_STRING_INITIALIZER
15598                 (struct cmd_clear_vf_stats_result,
15599                  clear, "clear");
15600 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15601         TOKEN_STRING_INITIALIZER
15602                 (struct cmd_clear_vf_stats_result,
15603                  vf, "vf");
15604 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15605         TOKEN_STRING_INITIALIZER
15606                 (struct cmd_clear_vf_stats_result,
15607                  stats, "stats");
15608 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15609         TOKEN_NUM_INITIALIZER
15610                 (struct cmd_clear_vf_stats_result,
15611                  port_id, UINT16);
15612 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15613         TOKEN_NUM_INITIALIZER
15614                 (struct cmd_clear_vf_stats_result,
15615                  vf_id, UINT16);
15616
15617 static void
15618 cmd_clear_vf_stats_parsed(
15619         void *parsed_result,
15620         __attribute__((unused)) struct cmdline *cl,
15621         __attribute__((unused)) void *data)
15622 {
15623         struct cmd_clear_vf_stats_result *res = parsed_result;
15624         int ret = -ENOTSUP;
15625
15626         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15627                 return;
15628
15629 #ifdef RTE_LIBRTE_I40E_PMD
15630         if (ret == -ENOTSUP)
15631                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15632                                                   res->vf_id);
15633 #endif
15634 #ifdef RTE_LIBRTE_BNXT_PMD
15635         if (ret == -ENOTSUP)
15636                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15637                                                   res->vf_id);
15638 #endif
15639
15640         switch (ret) {
15641         case 0:
15642                 break;
15643         case -EINVAL:
15644                 printf("invalid vf_id %d\n", res->vf_id);
15645                 break;
15646         case -ENODEV:
15647                 printf("invalid port_id %d\n", res->port_id);
15648                 break;
15649         case -ENOTSUP:
15650                 printf("function not implemented\n");
15651                 break;
15652         default:
15653                 printf("programming error: (%s)\n", strerror(-ret));
15654         }
15655 }
15656
15657 cmdline_parse_inst_t cmd_clear_vf_stats = {
15658         .f = cmd_clear_vf_stats_parsed,
15659         .data = NULL,
15660         .help_str = "clear vf stats <port_id> <vf_id>",
15661         .tokens = {
15662                 (void *)&cmd_clear_vf_stats_clear,
15663                 (void *)&cmd_clear_vf_stats_vf,
15664                 (void *)&cmd_clear_vf_stats_stats,
15665                 (void *)&cmd_clear_vf_stats_port_id,
15666                 (void *)&cmd_clear_vf_stats_vf_id,
15667                 NULL,
15668         },
15669 };
15670
15671 /* port config pctype mapping reset */
15672
15673 /* Common result structure for port config pctype mapping reset */
15674 struct cmd_pctype_mapping_reset_result {
15675         cmdline_fixed_string_t port;
15676         cmdline_fixed_string_t config;
15677         portid_t port_id;
15678         cmdline_fixed_string_t pctype;
15679         cmdline_fixed_string_t mapping;
15680         cmdline_fixed_string_t reset;
15681 };
15682
15683 /* Common CLI fields for port config pctype mapping reset*/
15684 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15685         TOKEN_STRING_INITIALIZER
15686                 (struct cmd_pctype_mapping_reset_result,
15687                  port, "port");
15688 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15689         TOKEN_STRING_INITIALIZER
15690                 (struct cmd_pctype_mapping_reset_result,
15691                  config, "config");
15692 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15693         TOKEN_NUM_INITIALIZER
15694                 (struct cmd_pctype_mapping_reset_result,
15695                  port_id, UINT16);
15696 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15697         TOKEN_STRING_INITIALIZER
15698                 (struct cmd_pctype_mapping_reset_result,
15699                  pctype, "pctype");
15700 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15701         TOKEN_STRING_INITIALIZER
15702                 (struct cmd_pctype_mapping_reset_result,
15703                  mapping, "mapping");
15704 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15705         TOKEN_STRING_INITIALIZER
15706                 (struct cmd_pctype_mapping_reset_result,
15707                  reset, "reset");
15708
15709 static void
15710 cmd_pctype_mapping_reset_parsed(
15711         void *parsed_result,
15712         __attribute__((unused)) struct cmdline *cl,
15713         __attribute__((unused)) void *data)
15714 {
15715         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15716         int ret = -ENOTSUP;
15717
15718         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15719                 return;
15720
15721 #ifdef RTE_LIBRTE_I40E_PMD
15722         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15723 #endif
15724
15725         switch (ret) {
15726         case 0:
15727                 break;
15728         case -ENODEV:
15729                 printf("invalid port_id %d\n", res->port_id);
15730                 break;
15731         case -ENOTSUP:
15732                 printf("function not implemented\n");
15733                 break;
15734         default:
15735                 printf("programming error: (%s)\n", strerror(-ret));
15736         }
15737 }
15738
15739 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15740         .f = cmd_pctype_mapping_reset_parsed,
15741         .data = NULL,
15742         .help_str = "port config <port_id> pctype mapping reset",
15743         .tokens = {
15744                 (void *)&cmd_pctype_mapping_reset_port,
15745                 (void *)&cmd_pctype_mapping_reset_config,
15746                 (void *)&cmd_pctype_mapping_reset_port_id,
15747                 (void *)&cmd_pctype_mapping_reset_pctype,
15748                 (void *)&cmd_pctype_mapping_reset_mapping,
15749                 (void *)&cmd_pctype_mapping_reset_reset,
15750                 NULL,
15751         },
15752 };
15753
15754 /* show port pctype mapping */
15755
15756 /* Common result structure for show port pctype mapping */
15757 struct cmd_pctype_mapping_get_result {
15758         cmdline_fixed_string_t show;
15759         cmdline_fixed_string_t port;
15760         portid_t port_id;
15761         cmdline_fixed_string_t pctype;
15762         cmdline_fixed_string_t mapping;
15763 };
15764
15765 /* Common CLI fields for pctype mapping get */
15766 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15767         TOKEN_STRING_INITIALIZER
15768                 (struct cmd_pctype_mapping_get_result,
15769                  show, "show");
15770 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15771         TOKEN_STRING_INITIALIZER
15772                 (struct cmd_pctype_mapping_get_result,
15773                  port, "port");
15774 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15775         TOKEN_NUM_INITIALIZER
15776                 (struct cmd_pctype_mapping_get_result,
15777                  port_id, UINT16);
15778 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15779         TOKEN_STRING_INITIALIZER
15780                 (struct cmd_pctype_mapping_get_result,
15781                  pctype, "pctype");
15782 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15783         TOKEN_STRING_INITIALIZER
15784                 (struct cmd_pctype_mapping_get_result,
15785                  mapping, "mapping");
15786
15787 static void
15788 cmd_pctype_mapping_get_parsed(
15789         void *parsed_result,
15790         __attribute__((unused)) struct cmdline *cl,
15791         __attribute__((unused)) void *data)
15792 {
15793         struct cmd_pctype_mapping_get_result *res = parsed_result;
15794         int ret = -ENOTSUP;
15795 #ifdef RTE_LIBRTE_I40E_PMD
15796         struct rte_pmd_i40e_flow_type_mapping
15797                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15798         int i, j, first_pctype;
15799 #endif
15800
15801         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15802                 return;
15803
15804 #ifdef RTE_LIBRTE_I40E_PMD
15805         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15806 #endif
15807
15808         switch (ret) {
15809         case 0:
15810                 break;
15811         case -ENODEV:
15812                 printf("invalid port_id %d\n", res->port_id);
15813                 return;
15814         case -ENOTSUP:
15815                 printf("function not implemented\n");
15816                 return;
15817         default:
15818                 printf("programming error: (%s)\n", strerror(-ret));
15819                 return;
15820         }
15821
15822 #ifdef RTE_LIBRTE_I40E_PMD
15823         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15824                 if (mapping[i].pctype != 0ULL) {
15825                         first_pctype = 1;
15826
15827                         printf("pctype: ");
15828                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15829                                 if (mapping[i].pctype & (1ULL << j)) {
15830                                         printf(first_pctype ?
15831                                                "%02d" : ",%02d", j);
15832                                         first_pctype = 0;
15833                                 }
15834                         }
15835                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15836                 }
15837         }
15838 #endif
15839 }
15840
15841 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15842         .f = cmd_pctype_mapping_get_parsed,
15843         .data = NULL,
15844         .help_str = "show port <port_id> pctype mapping",
15845         .tokens = {
15846                 (void *)&cmd_pctype_mapping_get_show,
15847                 (void *)&cmd_pctype_mapping_get_port,
15848                 (void *)&cmd_pctype_mapping_get_port_id,
15849                 (void *)&cmd_pctype_mapping_get_pctype,
15850                 (void *)&cmd_pctype_mapping_get_mapping,
15851                 NULL,
15852         },
15853 };
15854
15855 /* port config pctype mapping update */
15856
15857 /* Common result structure for port config pctype mapping update */
15858 struct cmd_pctype_mapping_update_result {
15859         cmdline_fixed_string_t port;
15860         cmdline_fixed_string_t config;
15861         portid_t port_id;
15862         cmdline_fixed_string_t pctype;
15863         cmdline_fixed_string_t mapping;
15864         cmdline_fixed_string_t update;
15865         cmdline_fixed_string_t pctype_list;
15866         uint16_t flow_type;
15867 };
15868
15869 /* Common CLI fields for pctype mapping update*/
15870 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15871         TOKEN_STRING_INITIALIZER
15872                 (struct cmd_pctype_mapping_update_result,
15873                  port, "port");
15874 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15875         TOKEN_STRING_INITIALIZER
15876                 (struct cmd_pctype_mapping_update_result,
15877                  config, "config");
15878 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15879         TOKEN_NUM_INITIALIZER
15880                 (struct cmd_pctype_mapping_update_result,
15881                  port_id, UINT16);
15882 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15883         TOKEN_STRING_INITIALIZER
15884                 (struct cmd_pctype_mapping_update_result,
15885                  pctype, "pctype");
15886 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15887         TOKEN_STRING_INITIALIZER
15888                 (struct cmd_pctype_mapping_update_result,
15889                  mapping, "mapping");
15890 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15891         TOKEN_STRING_INITIALIZER
15892                 (struct cmd_pctype_mapping_update_result,
15893                  update, "update");
15894 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15895         TOKEN_STRING_INITIALIZER
15896                 (struct cmd_pctype_mapping_update_result,
15897                  pctype_list, NULL);
15898 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15899         TOKEN_NUM_INITIALIZER
15900                 (struct cmd_pctype_mapping_update_result,
15901                  flow_type, UINT16);
15902
15903 static void
15904 cmd_pctype_mapping_update_parsed(
15905         void *parsed_result,
15906         __attribute__((unused)) struct cmdline *cl,
15907         __attribute__((unused)) void *data)
15908 {
15909         struct cmd_pctype_mapping_update_result *res = parsed_result;
15910         int ret = -ENOTSUP;
15911 #ifdef RTE_LIBRTE_I40E_PMD
15912         struct rte_pmd_i40e_flow_type_mapping mapping;
15913         unsigned int i;
15914         unsigned int nb_item;
15915         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15916 #endif
15917
15918         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15919                 return;
15920
15921 #ifdef RTE_LIBRTE_I40E_PMD
15922         nb_item = parse_item_list(res->pctype_list, "pctypes",
15923                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15924         mapping.flow_type = res->flow_type;
15925         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15926                 mapping.pctype |= (1ULL << pctype_list[i]);
15927         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15928                                                 &mapping,
15929                                                 1,
15930                                                 0);
15931 #endif
15932
15933         switch (ret) {
15934         case 0:
15935                 break;
15936         case -EINVAL:
15937                 printf("invalid pctype or flow type\n");
15938                 break;
15939         case -ENODEV:
15940                 printf("invalid port_id %d\n", res->port_id);
15941                 break;
15942         case -ENOTSUP:
15943                 printf("function not implemented\n");
15944                 break;
15945         default:
15946                 printf("programming error: (%s)\n", strerror(-ret));
15947         }
15948 }
15949
15950 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15951         .f = cmd_pctype_mapping_update_parsed,
15952         .data = NULL,
15953         .help_str = "port config <port_id> pctype mapping update"
15954         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15955         .tokens = {
15956                 (void *)&cmd_pctype_mapping_update_port,
15957                 (void *)&cmd_pctype_mapping_update_config,
15958                 (void *)&cmd_pctype_mapping_update_port_id,
15959                 (void *)&cmd_pctype_mapping_update_pctype,
15960                 (void *)&cmd_pctype_mapping_update_mapping,
15961                 (void *)&cmd_pctype_mapping_update_update,
15962                 (void *)&cmd_pctype_mapping_update_pc_type,
15963                 (void *)&cmd_pctype_mapping_update_flow_type,
15964                 NULL,
15965         },
15966 };
15967
15968 /* ptype mapping get */
15969
15970 /* Common result structure for ptype mapping get */
15971 struct cmd_ptype_mapping_get_result {
15972         cmdline_fixed_string_t ptype;
15973         cmdline_fixed_string_t mapping;
15974         cmdline_fixed_string_t get;
15975         portid_t port_id;
15976         uint8_t valid_only;
15977 };
15978
15979 /* Common CLI fields for ptype mapping get */
15980 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15981         TOKEN_STRING_INITIALIZER
15982                 (struct cmd_ptype_mapping_get_result,
15983                  ptype, "ptype");
15984 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15985         TOKEN_STRING_INITIALIZER
15986                 (struct cmd_ptype_mapping_get_result,
15987                  mapping, "mapping");
15988 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15989         TOKEN_STRING_INITIALIZER
15990                 (struct cmd_ptype_mapping_get_result,
15991                  get, "get");
15992 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15993         TOKEN_NUM_INITIALIZER
15994                 (struct cmd_ptype_mapping_get_result,
15995                  port_id, UINT16);
15996 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15997         TOKEN_NUM_INITIALIZER
15998                 (struct cmd_ptype_mapping_get_result,
15999                  valid_only, UINT8);
16000
16001 static void
16002 cmd_ptype_mapping_get_parsed(
16003         void *parsed_result,
16004         __attribute__((unused)) struct cmdline *cl,
16005         __attribute__((unused)) void *data)
16006 {
16007         struct cmd_ptype_mapping_get_result *res = parsed_result;
16008         int ret = -ENOTSUP;
16009 #ifdef RTE_LIBRTE_I40E_PMD
16010         int max_ptype_num = 256;
16011         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16012         uint16_t count;
16013         int i;
16014 #endif
16015
16016         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16017                 return;
16018
16019 #ifdef RTE_LIBRTE_I40E_PMD
16020         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16021                                         mapping,
16022                                         max_ptype_num,
16023                                         &count,
16024                                         res->valid_only);
16025 #endif
16026
16027         switch (ret) {
16028         case 0:
16029                 break;
16030         case -ENODEV:
16031                 printf("invalid port_id %d\n", res->port_id);
16032                 break;
16033         case -ENOTSUP:
16034                 printf("function not implemented\n");
16035                 break;
16036         default:
16037                 printf("programming error: (%s)\n", strerror(-ret));
16038         }
16039
16040 #ifdef RTE_LIBRTE_I40E_PMD
16041         if (!ret) {
16042                 for (i = 0; i < count; i++)
16043                         printf("%3d\t0x%08x\n",
16044                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16045         }
16046 #endif
16047 }
16048
16049 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16050         .f = cmd_ptype_mapping_get_parsed,
16051         .data = NULL,
16052         .help_str = "ptype mapping get <port_id> <valid_only>",
16053         .tokens = {
16054                 (void *)&cmd_ptype_mapping_get_ptype,
16055                 (void *)&cmd_ptype_mapping_get_mapping,
16056                 (void *)&cmd_ptype_mapping_get_get,
16057                 (void *)&cmd_ptype_mapping_get_port_id,
16058                 (void *)&cmd_ptype_mapping_get_valid_only,
16059                 NULL,
16060         },
16061 };
16062
16063 /* ptype mapping replace */
16064
16065 /* Common result structure for ptype mapping replace */
16066 struct cmd_ptype_mapping_replace_result {
16067         cmdline_fixed_string_t ptype;
16068         cmdline_fixed_string_t mapping;
16069         cmdline_fixed_string_t replace;
16070         portid_t port_id;
16071         uint32_t target;
16072         uint8_t mask;
16073         uint32_t pkt_type;
16074 };
16075
16076 /* Common CLI fields for ptype mapping replace */
16077 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16078         TOKEN_STRING_INITIALIZER
16079                 (struct cmd_ptype_mapping_replace_result,
16080                  ptype, "ptype");
16081 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16082         TOKEN_STRING_INITIALIZER
16083                 (struct cmd_ptype_mapping_replace_result,
16084                  mapping, "mapping");
16085 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16086         TOKEN_STRING_INITIALIZER
16087                 (struct cmd_ptype_mapping_replace_result,
16088                  replace, "replace");
16089 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16090         TOKEN_NUM_INITIALIZER
16091                 (struct cmd_ptype_mapping_replace_result,
16092                  port_id, UINT16);
16093 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16094         TOKEN_NUM_INITIALIZER
16095                 (struct cmd_ptype_mapping_replace_result,
16096                  target, UINT32);
16097 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16098         TOKEN_NUM_INITIALIZER
16099                 (struct cmd_ptype_mapping_replace_result,
16100                  mask, UINT8);
16101 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16102         TOKEN_NUM_INITIALIZER
16103                 (struct cmd_ptype_mapping_replace_result,
16104                  pkt_type, UINT32);
16105
16106 static void
16107 cmd_ptype_mapping_replace_parsed(
16108         void *parsed_result,
16109         __attribute__((unused)) struct cmdline *cl,
16110         __attribute__((unused)) void *data)
16111 {
16112         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16113         int ret = -ENOTSUP;
16114
16115         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16116                 return;
16117
16118 #ifdef RTE_LIBRTE_I40E_PMD
16119         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16120                                         res->target,
16121                                         res->mask,
16122                                         res->pkt_type);
16123 #endif
16124
16125         switch (ret) {
16126         case 0:
16127                 break;
16128         case -EINVAL:
16129                 printf("invalid ptype 0x%8x or 0x%8x\n",
16130                                 res->target, res->pkt_type);
16131                 break;
16132         case -ENODEV:
16133                 printf("invalid port_id %d\n", res->port_id);
16134                 break;
16135         case -ENOTSUP:
16136                 printf("function not implemented\n");
16137                 break;
16138         default:
16139                 printf("programming error: (%s)\n", strerror(-ret));
16140         }
16141 }
16142
16143 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16144         .f = cmd_ptype_mapping_replace_parsed,
16145         .data = NULL,
16146         .help_str =
16147                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16148         .tokens = {
16149                 (void *)&cmd_ptype_mapping_replace_ptype,
16150                 (void *)&cmd_ptype_mapping_replace_mapping,
16151                 (void *)&cmd_ptype_mapping_replace_replace,
16152                 (void *)&cmd_ptype_mapping_replace_port_id,
16153                 (void *)&cmd_ptype_mapping_replace_target,
16154                 (void *)&cmd_ptype_mapping_replace_mask,
16155                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16156                 NULL,
16157         },
16158 };
16159
16160 /* ptype mapping reset */
16161
16162 /* Common result structure for ptype mapping reset */
16163 struct cmd_ptype_mapping_reset_result {
16164         cmdline_fixed_string_t ptype;
16165         cmdline_fixed_string_t mapping;
16166         cmdline_fixed_string_t reset;
16167         portid_t port_id;
16168 };
16169
16170 /* Common CLI fields for ptype mapping reset*/
16171 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16172         TOKEN_STRING_INITIALIZER
16173                 (struct cmd_ptype_mapping_reset_result,
16174                  ptype, "ptype");
16175 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16176         TOKEN_STRING_INITIALIZER
16177                 (struct cmd_ptype_mapping_reset_result,
16178                  mapping, "mapping");
16179 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16180         TOKEN_STRING_INITIALIZER
16181                 (struct cmd_ptype_mapping_reset_result,
16182                  reset, "reset");
16183 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16184         TOKEN_NUM_INITIALIZER
16185                 (struct cmd_ptype_mapping_reset_result,
16186                  port_id, UINT16);
16187
16188 static void
16189 cmd_ptype_mapping_reset_parsed(
16190         void *parsed_result,
16191         __attribute__((unused)) struct cmdline *cl,
16192         __attribute__((unused)) void *data)
16193 {
16194         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16195         int ret = -ENOTSUP;
16196
16197         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16198                 return;
16199
16200 #ifdef RTE_LIBRTE_I40E_PMD
16201         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16202 #endif
16203
16204         switch (ret) {
16205         case 0:
16206                 break;
16207         case -ENODEV:
16208                 printf("invalid port_id %d\n", res->port_id);
16209                 break;
16210         case -ENOTSUP:
16211                 printf("function not implemented\n");
16212                 break;
16213         default:
16214                 printf("programming error: (%s)\n", strerror(-ret));
16215         }
16216 }
16217
16218 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16219         .f = cmd_ptype_mapping_reset_parsed,
16220         .data = NULL,
16221         .help_str = "ptype mapping reset <port_id>",
16222         .tokens = {
16223                 (void *)&cmd_ptype_mapping_reset_ptype,
16224                 (void *)&cmd_ptype_mapping_reset_mapping,
16225                 (void *)&cmd_ptype_mapping_reset_reset,
16226                 (void *)&cmd_ptype_mapping_reset_port_id,
16227                 NULL,
16228         },
16229 };
16230
16231 /* ptype mapping update */
16232
16233 /* Common result structure for ptype mapping update */
16234 struct cmd_ptype_mapping_update_result {
16235         cmdline_fixed_string_t ptype;
16236         cmdline_fixed_string_t mapping;
16237         cmdline_fixed_string_t reset;
16238         portid_t port_id;
16239         uint8_t hw_ptype;
16240         uint32_t sw_ptype;
16241 };
16242
16243 /* Common CLI fields for ptype mapping update*/
16244 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16245         TOKEN_STRING_INITIALIZER
16246                 (struct cmd_ptype_mapping_update_result,
16247                  ptype, "ptype");
16248 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16249         TOKEN_STRING_INITIALIZER
16250                 (struct cmd_ptype_mapping_update_result,
16251                  mapping, "mapping");
16252 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16253         TOKEN_STRING_INITIALIZER
16254                 (struct cmd_ptype_mapping_update_result,
16255                  reset, "update");
16256 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16257         TOKEN_NUM_INITIALIZER
16258                 (struct cmd_ptype_mapping_update_result,
16259                  port_id, UINT16);
16260 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16261         TOKEN_NUM_INITIALIZER
16262                 (struct cmd_ptype_mapping_update_result,
16263                  hw_ptype, UINT8);
16264 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16265         TOKEN_NUM_INITIALIZER
16266                 (struct cmd_ptype_mapping_update_result,
16267                  sw_ptype, UINT32);
16268
16269 static void
16270 cmd_ptype_mapping_update_parsed(
16271         void *parsed_result,
16272         __attribute__((unused)) struct cmdline *cl,
16273         __attribute__((unused)) void *data)
16274 {
16275         struct cmd_ptype_mapping_update_result *res = parsed_result;
16276         int ret = -ENOTSUP;
16277 #ifdef RTE_LIBRTE_I40E_PMD
16278         struct rte_pmd_i40e_ptype_mapping mapping;
16279 #endif
16280         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16281                 return;
16282
16283 #ifdef RTE_LIBRTE_I40E_PMD
16284         mapping.hw_ptype = res->hw_ptype;
16285         mapping.sw_ptype = res->sw_ptype;
16286         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16287                                                 &mapping,
16288                                                 1,
16289                                                 0);
16290 #endif
16291
16292         switch (ret) {
16293         case 0:
16294                 break;
16295         case -EINVAL:
16296                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16297                 break;
16298         case -ENODEV:
16299                 printf("invalid port_id %d\n", res->port_id);
16300                 break;
16301         case -ENOTSUP:
16302                 printf("function not implemented\n");
16303                 break;
16304         default:
16305                 printf("programming error: (%s)\n", strerror(-ret));
16306         }
16307 }
16308
16309 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16310         .f = cmd_ptype_mapping_update_parsed,
16311         .data = NULL,
16312         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16313         .tokens = {
16314                 (void *)&cmd_ptype_mapping_update_ptype,
16315                 (void *)&cmd_ptype_mapping_update_mapping,
16316                 (void *)&cmd_ptype_mapping_update_update,
16317                 (void *)&cmd_ptype_mapping_update_port_id,
16318                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16319                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16320                 NULL,
16321         },
16322 };
16323
16324 /* Common result structure for file commands */
16325 struct cmd_cmdfile_result {
16326         cmdline_fixed_string_t load;
16327         cmdline_fixed_string_t filename;
16328 };
16329
16330 /* Common CLI fields for file commands */
16331 cmdline_parse_token_string_t cmd_load_cmdfile =
16332         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16333 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16334         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16335
16336 static void
16337 cmd_load_from_file_parsed(
16338         void *parsed_result,
16339         __attribute__((unused)) struct cmdline *cl,
16340         __attribute__((unused)) void *data)
16341 {
16342         struct cmd_cmdfile_result *res = parsed_result;
16343
16344         cmdline_read_from_file(res->filename);
16345 }
16346
16347 cmdline_parse_inst_t cmd_load_from_file = {
16348         .f = cmd_load_from_file_parsed,
16349         .data = NULL,
16350         .help_str = "load <filename>",
16351         .tokens = {
16352                 (void *)&cmd_load_cmdfile,
16353                 (void *)&cmd_load_cmdfile_filename,
16354                 NULL,
16355         },
16356 };
16357
16358 /* ******************************************************************************** */
16359
16360 /* list of instructions */
16361 cmdline_parse_ctx_t main_ctx[] = {
16362         (cmdline_parse_inst_t *)&cmd_help_brief,
16363         (cmdline_parse_inst_t *)&cmd_help_long,
16364         (cmdline_parse_inst_t *)&cmd_quit,
16365         (cmdline_parse_inst_t *)&cmd_load_from_file,
16366         (cmdline_parse_inst_t *)&cmd_showport,
16367         (cmdline_parse_inst_t *)&cmd_showqueue,
16368         (cmdline_parse_inst_t *)&cmd_showportall,
16369         (cmdline_parse_inst_t *)&cmd_showcfg,
16370         (cmdline_parse_inst_t *)&cmd_start,
16371         (cmdline_parse_inst_t *)&cmd_start_tx_first,
16372         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
16373         (cmdline_parse_inst_t *)&cmd_set_link_up,
16374         (cmdline_parse_inst_t *)&cmd_set_link_down,
16375         (cmdline_parse_inst_t *)&cmd_reset,
16376         (cmdline_parse_inst_t *)&cmd_set_numbers,
16377         (cmdline_parse_inst_t *)&cmd_set_log,
16378         (cmdline_parse_inst_t *)&cmd_set_txpkts,
16379         (cmdline_parse_inst_t *)&cmd_set_txsplit,
16380         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
16381         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
16382         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
16383         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
16384         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
16385         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
16386         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
16387         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
16388         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
16389         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
16390         (cmdline_parse_inst_t *)&cmd_set_link_check,
16391         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
16392         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
16393         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
16394         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
16395 #ifdef RTE_LIBRTE_PMD_BOND
16396         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
16397         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
16398         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
16399         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
16400         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
16401         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
16402         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
16403         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
16404         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
16405         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
16406         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
16407 #endif
16408         (cmdline_parse_inst_t *)&cmd_vlan_offload,
16409         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
16410         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
16411         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
16412         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
16413         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
16414         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
16415         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
16416         (cmdline_parse_inst_t *)&cmd_csum_set,
16417         (cmdline_parse_inst_t *)&cmd_csum_show,
16418         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
16419         (cmdline_parse_inst_t *)&cmd_tso_set,
16420         (cmdline_parse_inst_t *)&cmd_tso_show,
16421         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
16422         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
16423         (cmdline_parse_inst_t *)&cmd_gro_enable,
16424         (cmdline_parse_inst_t *)&cmd_gro_flush,
16425         (cmdline_parse_inst_t *)&cmd_gro_show,
16426         (cmdline_parse_inst_t *)&cmd_gso_enable,
16427         (cmdline_parse_inst_t *)&cmd_gso_size,
16428         (cmdline_parse_inst_t *)&cmd_gso_show,
16429         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
16430         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
16431         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
16432         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
16433         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
16434         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
16435         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
16436         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
16437         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
16438         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
16439         (cmdline_parse_inst_t *)&cmd_config_dcb,
16440         (cmdline_parse_inst_t *)&cmd_read_reg,
16441         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
16442         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
16443         (cmdline_parse_inst_t *)&cmd_write_reg,
16444         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
16445         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
16446         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
16447         (cmdline_parse_inst_t *)&cmd_stop,
16448         (cmdline_parse_inst_t *)&cmd_mac_addr,
16449         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
16450         (cmdline_parse_inst_t *)&cmd_set_qmap,
16451         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
16452         (cmdline_parse_inst_t *)&cmd_operate_port,
16453         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
16454         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
16455         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
16456         (cmdline_parse_inst_t *)&cmd_config_speed_all,
16457         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
16458         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
16459         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
16460         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
16461         (cmdline_parse_inst_t *)&cmd_config_mtu,
16462         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
16463         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
16464         (cmdline_parse_inst_t *)&cmd_config_rss,
16465         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
16466         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
16467         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
16468         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
16469         (cmdline_parse_inst_t *)&cmd_showport_reta,
16470         (cmdline_parse_inst_t *)&cmd_config_burst,
16471         (cmdline_parse_inst_t *)&cmd_config_thresh,
16472         (cmdline_parse_inst_t *)&cmd_config_threshold,
16473         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
16474         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
16475         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
16476         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
16477         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
16478         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
16479         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
16480         (cmdline_parse_inst_t *)&cmd_global_config,
16481         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
16482         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
16483         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
16484         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
16485         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
16486         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
16487         (cmdline_parse_inst_t *)&cmd_dump,
16488         (cmdline_parse_inst_t *)&cmd_dump_one,
16489         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
16490         (cmdline_parse_inst_t *)&cmd_syn_filter,
16491         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
16492         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
16493         (cmdline_parse_inst_t *)&cmd_flex_filter,
16494         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
16495         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
16496         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
16497         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
16498         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
16499         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
16500         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
16501         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
16502         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
16503         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
16504         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
16505         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
16506         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
16507         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
16508         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
16509         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
16510         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
16511         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
16512         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
16513         (cmdline_parse_inst_t *)&cmd_flow,
16514         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
16515         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
16516         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
16517         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
16518         (cmdline_parse_inst_t *)&cmd_create_port_meter,
16519         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
16520         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
16521         (cmdline_parse_inst_t *)&cmd_del_port_meter,
16522         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
16523         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
16524         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
16525         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
16526         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
16527         (cmdline_parse_inst_t *)&cmd_mcast_addr,
16528         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
16529         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
16530         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
16531         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
16532         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
16533         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
16534         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
16535         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
16536         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
16537         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
16538         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
16539         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
16540         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
16541         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
16542         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
16543         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
16544         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
16545         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
16546         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
16547         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
16548         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
16549         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
16550         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
16551         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
16552         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
16553         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
16554         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
16555         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
16556         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
16557         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
16558         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
16559         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
16560         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
16561         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
16562         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
16563 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
16564         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
16565 #endif
16566         (cmdline_parse_inst_t *)&cmd_ddp_add,
16567         (cmdline_parse_inst_t *)&cmd_ddp_del,
16568         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
16569         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
16570         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
16571         (cmdline_parse_inst_t *)&cmd_clear_input_set,
16572         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
16573         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
16574         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
16575         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
16576         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
16577         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
16578
16579         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
16580         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
16581         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
16582         (cmdline_parse_inst_t *)&cmd_queue_region,
16583         (cmdline_parse_inst_t *)&cmd_region_flowtype,
16584         (cmdline_parse_inst_t *)&cmd_user_priority_region,
16585         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
16586         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
16587         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
16588         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
16589         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
16590         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
16591         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
16592         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
16593         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
16594         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
16595         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
16596         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
16597         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
16598         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
16599         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
16600         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
16601         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
16602         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
16603         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
16604         NULL,
16605 };
16606
16607 /* read cmdline commands from file */
16608 void
16609 cmdline_read_from_file(const char *filename)
16610 {
16611         struct cmdline *cl;
16612
16613         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
16614         if (cl == NULL) {
16615                 printf("Failed to create file based cmdline context: %s\n",
16616                        filename);
16617                 return;
16618         }
16619
16620         cmdline_interact(cl);
16621         cmdline_quit(cl);
16622
16623         cmdline_free(cl);
16624
16625         printf("Read CLI commands from %s\n", filename);
16626 }
16627
16628 /* prompt function, called from main on MASTER lcore */
16629 void
16630 prompt(void)
16631 {
16632         /* initialize non-constant commands */
16633         cmd_set_fwd_mode_init();
16634         cmd_set_fwd_retry_mode_init();
16635
16636         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
16637         if (testpmd_cl == NULL)
16638                 return;
16639         cmdline_interact(testpmd_cl);
16640         cmdline_stdin_exit(testpmd_cl);
16641 }
16642
16643 void
16644 prompt_exit(void)
16645 {
16646         if (testpmd_cl != NULL)
16647                 cmdline_quit(testpmd_cl);
16648 }
16649
16650 static void
16651 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
16652 {
16653         if (id == (portid_t)RTE_PORT_ALL) {
16654                 portid_t pid;
16655
16656                 RTE_ETH_FOREACH_DEV(pid) {
16657                         /* check if need_reconfig has been set to 1 */
16658                         if (ports[pid].need_reconfig == 0)
16659                                 ports[pid].need_reconfig = dev;
16660                         /* check if need_reconfig_queues has been set to 1 */
16661                         if (ports[pid].need_reconfig_queues == 0)
16662                                 ports[pid].need_reconfig_queues = queue;
16663                 }
16664         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
16665                 /* check if need_reconfig has been set to 1 */
16666                 if (ports[id].need_reconfig == 0)
16667                         ports[id].need_reconfig = dev;
16668                 /* check if need_reconfig_queues has been set to 1 */
16669                 if (ports[id].need_reconfig_queues == 0)
16670                         ports[id].need_reconfig_queues = queue;
16671         }
16672 }