examples: fix RSS hash function configuration
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.h"
78 #include "bpf_cmd.h"
79
80 static struct cmdline *testpmd_cl;
81
82 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
83
84 /* *** Help command with introduction. *** */
85 struct cmd_help_brief_result {
86         cmdline_fixed_string_t help;
87 };
88
89 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
90                                   struct cmdline *cl,
91                                   __attribute__((unused)) void *data)
92 {
93         cmdline_printf(
94                 cl,
95                 "\n"
96                 "Help is available for the following sections:\n\n"
97                 "    help control    : Start and stop forwarding.\n"
98                 "    help display    : Displaying port, stats and config "
99                 "information.\n"
100                 "    help config     : Configuration information.\n"
101                 "    help ports      : Configuring ports.\n"
102                 "    help registers  : Reading and setting port registers.\n"
103                 "    help filters    : Filters configuration help.\n"
104                 "    help all        : All of the above sections.\n\n"
105         );
106
107 }
108
109 cmdline_parse_token_string_t cmd_help_brief_help =
110         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
111
112 cmdline_parse_inst_t cmd_help_brief = {
113         .f = cmd_help_brief_parsed,
114         .data = NULL,
115         .help_str = "help: Show help",
116         .tokens = {
117                 (void *)&cmd_help_brief_help,
118                 NULL,
119         },
120 };
121
122 /* *** Help command with help sections. *** */
123 struct cmd_help_long_result {
124         cmdline_fixed_string_t help;
125         cmdline_fixed_string_t section;
126 };
127
128 static void cmd_help_long_parsed(void *parsed_result,
129                                  struct cmdline *cl,
130                                  __attribute__((unused)) void *data)
131 {
132         int show_all = 0;
133         struct cmd_help_long_result *res = parsed_result;
134
135         if (!strcmp(res->section, "all"))
136                 show_all = 1;
137
138         if (show_all || !strcmp(res->section, "control")) {
139
140                 cmdline_printf(
141                         cl,
142                         "\n"
143                         "Control forwarding:\n"
144                         "-------------------\n\n"
145
146                         "start\n"
147                         "    Start packet forwarding with current configuration.\n\n"
148
149                         "start tx_first\n"
150                         "    Start packet forwarding with current config"
151                         " after sending one burst of packets.\n\n"
152
153                         "stop\n"
154                         "    Stop packet forwarding, and display accumulated"
155                         " statistics.\n\n"
156
157                         "quit\n"
158                         "    Quit to prompt.\n\n"
159                 );
160         }
161
162         if (show_all || !strcmp(res->section, "display")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Display:\n"
168                         "--------\n\n"
169
170                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
171                         "    Display information for port_id, or all.\n\n"
172
173                         "show port X rss reta (size) (mask0,mask1,...)\n"
174                         "    Display the rss redirection table entry indicated"
175                         " by masks on port X. size is used to indicate the"
176                         " hardware supported reta size\n\n"
177
178                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
179                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
180                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
181                         "    Display the RSS hash functions and RSS hash key"
182                         " of port X\n\n"
183
184                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
185                         "    Clear information for port_id, or all.\n\n"
186
187                         "show (rxq|txq) info (port_id) (queue_id)\n"
188                         "    Display information for configured RX/TX queue.\n\n"
189
190                         "show config (rxtx|cores|fwd|txpkts)\n"
191                         "    Display the given configuration.\n\n"
192
193                         "read rxd (port_id) (queue_id) (rxd_id)\n"
194                         "    Display an RX descriptor of a port RX queue.\n\n"
195
196                         "read txd (port_id) (queue_id) (txd_id)\n"
197                         "    Display a TX descriptor of a port TX queue.\n\n"
198
199                         "ddp get list (port_id)\n"
200                         "    Get ddp profile info list\n\n"
201
202                         "ddp get info (profile_path)\n"
203                         "    Get ddp profile information.\n\n"
204
205                         "show vf stats (port_id) (vf_id)\n"
206                         "    Display a VF's statistics.\n\n"
207
208                         "clear vf stats (port_id) (vf_id)\n"
209                         "    Reset a VF's statistics.\n\n"
210
211                         "show port (port_id) pctype mapping\n"
212                         "    Get flow ptype to pctype mapping on a port\n\n"
213
214                         "show port meter stats (port_id) (meter_id) (clear)\n"
215                         "    Get meter stats on a port\n\n"
216                         "show port tm cap (port_id)\n"
217                         "       Display the port TM capability.\n\n"
218
219                         "show port tm level cap (port_id) (level_id)\n"
220                         "       Display the port TM hierarchical level capability.\n\n"
221
222                         "show port tm node cap (port_id) (node_id)\n"
223                         "       Display the port TM node capability.\n\n"
224
225                         "show port tm node type (port_id) (node_id)\n"
226                         "       Display the port TM node type.\n\n"
227
228                         "show port tm node stats (port_id) (node_id) (clear)\n"
229                         "       Display the port TM node stats.\n\n"
230
231                 );
232         }
233
234         if (show_all || !strcmp(res->section, "config")) {
235                 cmdline_printf(
236                         cl,
237                         "\n"
238                         "Configuration:\n"
239                         "--------------\n"
240                         "Configuration changes only become active when"
241                         " forwarding is started/restarted.\n\n"
242
243                         "set default\n"
244                         "    Reset forwarding to the default configuration.\n\n"
245
246                         "set verbose (level)\n"
247                         "    Set the debug verbosity level X.\n\n"
248
249                         "set log global|(type) (level)\n"
250                         "    Set the log level.\n\n"
251
252                         "set nbport (num)\n"
253                         "    Set number of ports.\n\n"
254
255                         "set nbcore (num)\n"
256                         "    Set number of cores.\n\n"
257
258                         "set coremask (mask)\n"
259                         "    Set the forwarding cores hexadecimal mask.\n\n"
260
261                         "set portmask (mask)\n"
262                         "    Set the forwarding ports hexadecimal mask.\n\n"
263
264                         "set burst (num)\n"
265                         "    Set number of packets per burst.\n\n"
266
267                         "set burst tx delay (microseconds) retry (num)\n"
268                         "    Set the transmit delay time and number of retries,"
269                         " effective when retry is enabled.\n\n"
270
271                         "set txpkts (x[,y]*)\n"
272                         "    Set the length of each segment of TXONLY"
273                         " and optionally CSUM packets.\n\n"
274
275                         "set txsplit (off|on|rand)\n"
276                         "    Set the split policy for the TX packets."
277                         " Right now only applicable for CSUM and TXONLY"
278                         " modes\n\n"
279
280                         "set corelist (x[,y]*)\n"
281                         "    Set the list of forwarding cores.\n\n"
282
283                         "set portlist (x[,y]*)\n"
284                         "    Set the list of forwarding ports.\n\n"
285
286                         "set tx loopback (port_id) (on|off)\n"
287                         "    Enable or disable tx loopback.\n\n"
288
289                         "set all queues drop (port_id) (on|off)\n"
290                         "    Set drop enable bit for all queues.\n\n"
291
292                         "set vf split drop (port_id) (vf_id) (on|off)\n"
293                         "    Set split drop enable bit for a VF from the PF.\n\n"
294
295                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
296                         "    Set MAC antispoof for a VF from the PF.\n\n"
297
298                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
299                         "    Enable MACsec offload.\n\n"
300
301                         "set macsec offload (port_id) off\n"
302                         "    Disable MACsec offload.\n\n"
303
304                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
305                         "    Configure MACsec secure connection (SC).\n\n"
306
307                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
308                         "    Configure MACsec secure association (SA).\n\n"
309
310                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
311                         "    Set VF broadcast for a VF from the PF.\n\n"
312
313                         "vlan set strip (on|off) (port_id)\n"
314                         "    Set the VLAN strip on a port.\n\n"
315
316                         "vlan set stripq (on|off) (port_id,queue_id)\n"
317                         "    Set the VLAN strip for a queue on a port.\n\n"
318
319                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
320                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
321
322                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
323                         "    Set VLAN insert for a VF from the PF.\n\n"
324
325                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
326                         "    Set VLAN antispoof for a VF from the PF.\n\n"
327
328                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN tag for a VF from the PF.\n\n"
330
331                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
332                         "    Set a VF's max bandwidth(Mbps).\n\n"
333
334                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
335                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
336
337                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
338                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
339
340                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
341                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
342
343                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
344                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
345
346                         "vlan set filter (on|off) (port_id)\n"
347                         "    Set the VLAN filter on a port.\n\n"
348
349                         "vlan set qinq (on|off) (port_id)\n"
350                         "    Set the VLAN QinQ (extended queue in queue)"
351                         " on a port.\n\n"
352
353                         "vlan set (inner|outer) tpid (value) (port_id)\n"
354                         "    Set the VLAN TPID for Packet Filtering on"
355                         " a port\n\n"
356
357                         "rx_vlan add (vlan_id|all) (port_id)\n"
358                         "    Add a vlan_id, or all identifiers, to the set"
359                         " of VLAN identifiers filtered by port_id.\n\n"
360
361                         "rx_vlan rm (vlan_id|all) (port_id)\n"
362                         "    Remove a vlan_id, or all identifiers, from the set"
363                         " of VLAN identifiers filtered by port_id.\n\n"
364
365                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
366                         "    Add a vlan_id, to the set of VLAN identifiers"
367                         "filtered for VF(s) from port_id.\n\n"
368
369                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
370                         "    Remove a vlan_id, to the set of VLAN identifiers"
371                         "filtered for VF(s) from port_id.\n\n"
372
373                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
374                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
375                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
376                         "   add a tunnel filter of a port.\n\n"
377
378                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
379                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
380                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
381                         "   remove a tunnel filter of a port.\n\n"
382
383                         "rx_vxlan_port add (udp_port) (port_id)\n"
384                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
385
386                         "rx_vxlan_port rm (udp_port) (port_id)\n"
387                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
390                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
391                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
392
393                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
394                         "    Set port based TX VLAN insertion.\n\n"
395
396                         "tx_vlan reset (port_id)\n"
397                         "    Disable hardware insertion of a VLAN header in"
398                         " packets sent on a port.\n\n"
399
400                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
401                         "    Select hardware or software calculation of the"
402                         " checksum when transmitting a packet using the"
403                         " csum forward engine.\n"
404                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
405                         "    outer-ip concerns the outer IP layer in"
406                         " case the packet is recognized as a tunnel packet by"
407                         " the forward engine (vxlan, gre and ipip are supported)\n"
408                         "    Please check the NIC datasheet for HW limits.\n\n"
409
410                         "csum parse-tunnel (on|off) (tx_port_id)\n"
411                         "    If disabled, treat tunnel packets as non-tunneled"
412                         " packets (treat inner headers as payload). The port\n"
413                         "    argument is the port used for TX in csum forward"
414                         " engine.\n\n"
415
416                         "csum show (port_id)\n"
417                         "    Display tx checksum offload configuration\n\n"
418
419                         "tso set (segsize) (portid)\n"
420                         "    Enable TCP Segmentation Offload in csum forward"
421                         " engine.\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "tso show (portid)"
425                         "    Display the status of TCP Segmentation Offload.\n\n"
426
427                         "set port (port_id) gro on|off\n"
428                         "    Enable or disable Generic Receive Offload in"
429                         " csum forwarding engine.\n\n"
430
431                         "show port (port_id) gro\n"
432                         "    Display GRO configuration.\n\n"
433
434                         "set gro flush (cycles)\n"
435                         "    Set the cycle to flush GROed packets from"
436                         " reassembly tables.\n\n"
437
438                         "set port (port_id) gso (on|off)"
439                         "    Enable or disable Generic Segmentation Offload in"
440                         " csum forwarding engine.\n\n"
441
442                         "set gso segsz (length)\n"
443                         "    Set max packet length for output GSO segments,"
444                         " including packet header and payload.\n\n"
445
446                         "show port (port_id) gso\n"
447                         "    Show GSO configuration.\n\n"
448
449                         "set fwd (%s)\n"
450                         "    Set packet forwarding mode.\n\n"
451
452                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
453                         "    Add a MAC address on port_id.\n\n"
454
455                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
456                         "    Remove a MAC address from port_id.\n\n"
457
458                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Set the default MAC address for port_id.\n\n"
460
461                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
462                         "    Add a MAC address for a VF on the port.\n\n"
463
464                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Set the MAC address for a VF from the PF.\n\n"
466
467                         "set eth-peer (port_id) (peer_addr)\n"
468                         "    set the peer address for certain port.\n\n"
469
470                         "set port (port_id) uta (mac_address|all) (on|off)\n"
471                         "    Add/Remove a or all unicast hash filter(s)"
472                         "from port X.\n\n"
473
474                         "set promisc (port_id|all) (on|off)\n"
475                         "    Set the promiscuous mode on port_id, or all.\n\n"
476
477                         "set allmulti (port_id|all) (on|off)\n"
478                         "    Set the allmulti mode on port_id, or all.\n\n"
479
480                         "set vf promisc (port_id) (vf_id) (on|off)\n"
481                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
482
483                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
484                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
487                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
488                         " (on|off) autoneg (on|off) (port_id)\n"
489                         "set flow_ctrl rx (on|off) (portid)\n"
490                         "set flow_ctrl tx (on|off) (portid)\n"
491                         "set flow_ctrl high_water (high_water) (portid)\n"
492                         "set flow_ctrl low_water (low_water) (portid)\n"
493                         "set flow_ctrl pause_time (pause_time) (portid)\n"
494                         "set flow_ctrl send_xon (send_xon) (portid)\n"
495                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
496                         "set flow_ctrl autoneg (on|off) (port_id)\n"
497                         "    Set the link flow control parameter on a port.\n\n"
498
499                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
500                         " (low_water) (pause_time) (priority) (port_id)\n"
501                         "    Set the priority flow control parameter on a"
502                         " port.\n\n"
503
504                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
505                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
506                         " queue on port.\n"
507                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
508                         " on port 0 to mapping 5.\n\n"
509
510                         "set xstats-hide-zero on|off\n"
511                         "    Set the option to hide the zero values"
512                         " for xstats display.\n"
513
514                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
515                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
516
517                         "set port (port_id) vf (vf_id) (mac_addr)"
518                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
519                         "   Add/Remove unicast or multicast MAC addr filter"
520                         " for a VF.\n\n"
521
522                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
523                         "|MPE) (on|off)\n"
524                         "    AUPE:accepts untagged VLAN;"
525                         "ROPE:accept unicast hash\n\n"
526                         "    BAM:accepts broadcast packets;"
527                         "MPE:accepts all multicast packets\n\n"
528                         "    Enable/Disable a VF receive mode of a port\n\n"
529
530                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
531                         "    Set rate limit for a queue of a port\n\n"
532
533                         "set port (port_id) vf (vf_id) rate (rate_num) "
534                         "queue_mask (queue_mask_value)\n"
535                         "    Set rate limit for queues in VF of a port\n\n"
536
537                         "set port (port_id) mirror-rule (rule_id)"
538                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
539                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
540                         "   Set pool or vlan type mirror rule on a port.\n"
541                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
542                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
543                         " to pool 0.\n\n"
544
545                         "set port (port_id) mirror-rule (rule_id)"
546                         " (uplink-mirror|downlink-mirror) dst-pool"
547                         " (pool_id) (on|off)\n"
548                         "   Set uplink or downlink type mirror rule on a port.\n"
549                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
550                         " 0 on' enable mirror income traffic to pool 0.\n\n"
551
552                         "reset port (port_id) mirror-rule (rule_id)\n"
553                         "   Reset a mirror rule.\n\n"
554
555                         "set flush_rx (on|off)\n"
556                         "   Flush (default) or don't flush RX streams before"
557                         " forwarding. Mainly used with PCAP drivers.\n\n"
558
559                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
560                         "   Set the bypass mode for the lowest port on bypass enabled"
561                         " NIC.\n\n"
562
563                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
564                         "mode (normal|bypass|isolate) (port_id)\n"
565                         "   Set the event required to initiate specified bypass mode for"
566                         " the lowest port on a bypass enabled NIC where:\n"
567                         "       timeout   = enable bypass after watchdog timeout.\n"
568                         "       os_on     = enable bypass when OS/board is powered on.\n"
569                         "       os_off    = enable bypass when OS/board is powered off.\n"
570                         "       power_on  = enable bypass when power supply is turned on.\n"
571                         "       power_off = enable bypass when power supply is turned off."
572                         "\n\n"
573
574                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
575                         "   Set the bypass watchdog timeout to 'n' seconds"
576                         " where 0 = instant.\n\n"
577
578                         "show bypass config (port_id)\n"
579                         "   Show the bypass configuration for a bypass enabled NIC"
580                         " using the lowest port on the NIC.\n\n"
581
582 #ifdef RTE_LIBRTE_PMD_BOND
583                         "create bonded device (mode) (socket)\n"
584                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
585
586                         "add bonding slave (slave_id) (port_id)\n"
587                         "       Add a slave device to a bonded device.\n\n"
588
589                         "remove bonding slave (slave_id) (port_id)\n"
590                         "       Remove a slave device from a bonded device.\n\n"
591
592                         "set bonding mode (value) (port_id)\n"
593                         "       Set the bonding mode on a bonded device.\n\n"
594
595                         "set bonding primary (slave_id) (port_id)\n"
596                         "       Set the primary slave for a bonded device.\n\n"
597
598                         "show bonding config (port_id)\n"
599                         "       Show the bonding config for port_id.\n\n"
600
601                         "set bonding mac_addr (port_id) (address)\n"
602                         "       Set the MAC address of a bonded device.\n\n"
603
604                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
605                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
606
607                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
608                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
609
610                         "set bonding mon_period (port_id) (value)\n"
611                         "       Set the bonding link status monitoring polling period in ms.\n\n"
612
613                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
614                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
615
616 #endif
617                         "set link-up port (port_id)\n"
618                         "       Set link up for a port.\n\n"
619
620                         "set link-down port (port_id)\n"
621                         "       Set link down for a port.\n\n"
622
623                         "E-tag set insertion on port-tag-id (value)"
624                         " port (port_id) vf (vf_id)\n"
625                         "    Enable E-tag insertion for a VF on a port\n\n"
626
627                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
628                         "    Disable E-tag insertion for a VF on a port\n\n"
629
630                         "E-tag set stripping (on|off) port (port_id)\n"
631                         "    Enable/disable E-tag stripping on a port\n\n"
632
633                         "E-tag set forwarding (on|off) port (port_id)\n"
634                         "    Enable/disable E-tag based forwarding"
635                         " on a port\n\n"
636
637                         "E-tag set filter add e-tag-id (value) dst-pool"
638                         " (pool_id) port (port_id)\n"
639                         "    Add an E-tag forwarding filter on a port\n\n"
640
641                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
642                         "    Delete an E-tag forwarding filter on a port\n\n"
643
644 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
645                         "set port tm hierarchy default (port_id)\n"
646                         "       Set default traffic Management hierarchy on a port\n\n"
647
648 #endif
649                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
650                         "    Load a profile package on a port\n\n"
651
652                         "ddp del (port_id) (backup_profile_path)\n"
653                         "    Delete a profile package from a port\n\n"
654
655                         "ptype mapping get (port_id) (valid_only)\n"
656                         "    Get ptype mapping on a port\n\n"
657
658                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
659                         "    Replace target with the pkt_type in ptype mapping\n\n"
660
661                         "ptype mapping reset (port_id)\n"
662                         "    Reset ptype mapping on a port\n\n"
663
664                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
665                         "    Update a ptype mapping item on a port\n\n"
666
667                         "set port (port_id) queue-region region_id (value) "
668                         "queue_start_index (value) queue_num (value)\n"
669                         "    Set a queue region on a port\n\n"
670
671                         "set port (port_id) queue-region region_id (value) "
672                         "flowtype (value)\n"
673                         "    Set a flowtype region index on a port\n\n"
674
675                         "set port (port_id) queue-region UP (value) region_id (value)\n"
676                         "    Set the mapping of User Priority to "
677                         "queue region on a port\n\n"
678
679                         "set port (port_id) queue-region flush (on|off)\n"
680                         "    flush all queue region related configuration\n\n"
681
682                         "show port meter cap (port_id)\n"
683                         "    Show port meter capability information\n\n"
684
685                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
686                         "    meter profile add - srtcm rfc 2697\n\n"
687
688                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
689                         "    meter profile add - trtcm rfc 2698\n\n"
690
691                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
692                         "    meter profile add - trtcm rfc 4115\n\n"
693
694                         "del port meter profile (port_id) (profile_id)\n"
695                         "    meter profile delete\n\n"
696
697                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
698                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
699                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
700                         "(dscp_tbl_entry63)]\n"
701                         "    meter create\n\n"
702
703                         "enable port meter (port_id) (mtr_id)\n"
704                         "    meter enable\n\n"
705
706                         "disable port meter (port_id) (mtr_id)\n"
707                         "    meter disable\n\n"
708
709                         "del port meter (port_id) (mtr_id)\n"
710                         "    meter delete\n\n"
711
712                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
713                         "    meter update meter profile\n\n"
714
715                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
716                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
717                         "    update meter dscp table entries\n\n"
718
719                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
720                         "(action0) [(action1) (action2)]\n"
721                         "    meter update policer action\n\n"
722
723                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
724                         "    meter update stats\n\n"
725
726                         "show port (port_id) queue-region\n"
727                         "    show all queue region related configuration info\n\n"
728
729                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
730                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
731                         "       Add port tm node private shaper profile.\n\n"
732
733                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
734                         "       Delete port tm node private shaper profile.\n\n"
735
736                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
737                         " (shaper_profile_id)\n"
738                         "       Add/update port tm node shared shaper.\n\n"
739
740                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
741                         "       Delete port tm node shared shaper.\n\n"
742
743                         "set port tm node shaper profile (port_id) (node_id)"
744                         " (shaper_profile_id)\n"
745                         "       Set port tm node shaper profile.\n\n"
746
747                         "add port tm node wred profile (port_id) (wred_profile_id)"
748                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
749                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
750                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
751                         "       Add port tm node wred profile.\n\n"
752
753                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
754                         "       Delete port tm node wred profile.\n\n"
755
756                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
757                         " (priority) (weight) (level_id) (shaper_profile_id)"
758                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
759                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
760                         "       Add port tm nonleaf node.\n\n"
761
762                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
763                         " (priority) (weight) (level_id) (shaper_profile_id)"
764                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
765                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
766                         "       Add port tm leaf node.\n\n"
767
768                         "del port tm node (port_id) (node_id)\n"
769                         "       Delete port tm node.\n\n"
770
771                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
772                         " (priority) (weight)\n"
773                         "       Set port tm node parent.\n\n"
774
775                         "suspend port tm node (port_id) (node_id)"
776                         "       Suspend tm node.\n\n"
777
778                         "resume port tm node (port_id) (node_id)"
779                         "       Resume tm node.\n\n"
780
781                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
782                         "       Commit tm hierarchy.\n\n"
783
784                         , list_pkt_forwarding_modes()
785                 );
786         }
787
788         if (show_all || !strcmp(res->section, "ports")) {
789
790                 cmdline_printf(
791                         cl,
792                         "\n"
793                         "Port Operations:\n"
794                         "----------------\n\n"
795
796                         "port start (port_id|all)\n"
797                         "    Start all ports or port_id.\n\n"
798
799                         "port stop (port_id|all)\n"
800                         "    Stop all ports or port_id.\n\n"
801
802                         "port close (port_id|all)\n"
803                         "    Close all ports or port_id.\n\n"
804
805                         "port attach (ident)\n"
806                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
807
808                         "port detach (port_id)\n"
809                         "    Detach physical or virtual dev by port_id\n\n"
810
811                         "port config (port_id|all)"
812                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
813                         " duplex (half|full|auto)\n"
814                         "    Set speed and duplex for all ports or port_id\n\n"
815
816                         "port config (port_id|all) loopback (mode)\n"
817                         "    Set loopback mode for all ports or port_id\n\n"
818
819                         "port config all (rxq|txq|rxd|txd) (value)\n"
820                         "    Set number for rxq/txq/rxd/txd.\n\n"
821
822                         "port config all max-pkt-len (value)\n"
823                         "    Set the max packet length.\n\n"
824
825                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
826                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
827                         " (on|off)\n"
828                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
829                         " for ports.\n\n"
830
831                         "port config all rss (all|default|ip|tcp|udp|sctp|"
832                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
833                         "    Set the RSS mode.\n\n"
834
835                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
836                         "    Set the RSS redirection table.\n\n"
837
838                         "port config (port_id) dcb vt (on|off) (traffic_class)"
839                         " pfc (on|off)\n"
840                         "    Set the DCB mode.\n\n"
841
842                         "port config all burst (value)\n"
843                         "    Set the number of packets per burst.\n\n"
844
845                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
846                         " (value)\n"
847                         "    Set the ring prefetch/host/writeback threshold"
848                         " for tx/rx queue.\n\n"
849
850                         "port config all (txfreet|txrst|rxfreet) (value)\n"
851                         "    Set free threshold for rx/tx, or set"
852                         " tx rs bit threshold.\n\n"
853                         "port config mtu X value\n"
854                         "    Set the MTU of port X to a given value\n\n"
855
856                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
857                         "    Set a rx/tx queue's ring size configuration, the new"
858                         " value will take effect after command that (re-)start the port"
859                         " or command that setup the specific queue\n\n"
860
861                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
862                         "    Start/stop a rx/tx queue of port X. Only take effect"
863                         " when port X is started\n\n"
864
865                         "port (port_id) (rxq|txq) (queue_id) setup\n"
866                         "    Setup a rx/tx queue of port X.\n\n"
867
868                         "port config (port_id|all) l2-tunnel E-tag ether-type"
869                         " (value)\n"
870                         "    Set the value of E-tag ether-type.\n\n"
871
872                         "port config (port_id|all) l2-tunnel E-tag"
873                         " (enable|disable)\n"
874                         "    Enable/disable the E-tag support.\n\n"
875
876                         "port config (port_id) pctype mapping reset\n"
877                         "    Reset flow type to pctype mapping on a port\n\n"
878
879                         "port config (port_id) pctype mapping update"
880                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
881                         "    Update a flow type to pctype mapping item on a port\n\n"
882
883                         "port config (port_id) pctype (pctype_id) hash_inset|"
884                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
885                         " (field_idx)\n"
886                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
887
888                         "port config (port_id) pctype (pctype_id) hash_inset|"
889                         "fdir_inset|fdir_flx_inset clear all"
890                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
891
892                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
893                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
894                 );
895         }
896
897         if (show_all || !strcmp(res->section, "registers")) {
898
899                 cmdline_printf(
900                         cl,
901                         "\n"
902                         "Registers:\n"
903                         "----------\n\n"
904
905                         "read reg (port_id) (address)\n"
906                         "    Display value of a port register.\n\n"
907
908                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
909                         "    Display a port register bit field.\n\n"
910
911                         "read regbit (port_id) (address) (bit_x)\n"
912                         "    Display a single port register bit.\n\n"
913
914                         "write reg (port_id) (address) (value)\n"
915                         "    Set value of a port register.\n\n"
916
917                         "write regfield (port_id) (address) (bit_x) (bit_y)"
918                         " (value)\n"
919                         "    Set bit field of a port register.\n\n"
920
921                         "write regbit (port_id) (address) (bit_x) (value)\n"
922                         "    Set single bit value of a port register.\n\n"
923                 );
924         }
925         if (show_all || !strcmp(res->section, "filters")) {
926
927                 cmdline_printf(
928                         cl,
929                         "\n"
930                         "filters:\n"
931                         "--------\n\n"
932
933                         "ethertype_filter (port_id) (add|del)"
934                         " (mac_addr|mac_ignr) (mac_address) ethertype"
935                         " (ether_type) (drop|fwd) queue (queue_id)\n"
936                         "    Add/Del an ethertype filter.\n\n"
937
938                         "2tuple_filter (port_id) (add|del)"
939                         " dst_port (dst_port_value) protocol (protocol_value)"
940                         " mask (mask_value) tcp_flags (tcp_flags_value)"
941                         " priority (prio_value) queue (queue_id)\n"
942                         "    Add/Del a 2tuple filter.\n\n"
943
944                         "5tuple_filter (port_id) (add|del)"
945                         " dst_ip (dst_address) src_ip (src_address)"
946                         " dst_port (dst_port_value) src_port (src_port_value)"
947                         " protocol (protocol_value)"
948                         " mask (mask_value) tcp_flags (tcp_flags_value)"
949                         " priority (prio_value) queue (queue_id)\n"
950                         "    Add/Del a 5tuple filter.\n\n"
951
952                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
953                         "    Add/Del syn filter.\n\n"
954
955                         "flex_filter (port_id) (add|del) len (len_value)"
956                         " bytes (bytes_value) mask (mask_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a flex filter.\n\n"
959
960                         "flow_director_filter (port_id) mode IP (add|del|update)"
961                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
962                         " src (src_ip_address) dst (dst_ip_address)"
963                         " tos (tos_value) proto (proto_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 IP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tos (tos_value) ttl (ttl_value)"
974                         " vlan (vlan_value) flexbytes (flexbytes_value)"
975                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
976                         " fd_id (fd_id_value)\n"
977                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
978
979                         "flow_director_filter (port_id) mode IP (add|del|update)"
980                         " flow (ipv4-sctp|ipv6-sctp)"
981                         " src (src_ip_address) (src_port)"
982                         " dst (dst_ip_address) (dst_port)"
983                         " tag (verification_tag) "
984                         " tos (tos_value) ttl (ttl_value)"
985                         " vlan (vlan_value)"
986                         " flexbytes (flexbytes_value) (drop|fwd)"
987                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
988                         "    Add/Del a SCTP type flow director filter.\n\n"
989
990                         "flow_director_filter (port_id) mode IP (add|del|update)"
991                         " flow l2_payload ether (ethertype)"
992                         " flexbytes (flexbytes_value) (drop|fwd)"
993                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
994                         "    Add/Del a l2 payload type flow director filter.\n\n"
995
996                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
997                         " mac (mac_address) vlan (vlan_value)"
998                         " flexbytes (flexbytes_value) (drop|fwd)"
999                         " queue (queue_id) fd_id (fd_id_value)\n"
1000                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1003                         " mac (mac_address) vlan (vlan_value)"
1004                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1005                         " flexbytes (flexbytes_value) (drop|fwd)"
1006                         " queue (queue_id) fd_id (fd_id_value)\n"
1007                         "    Add/Del a Tunnel flow director filter.\n\n"
1008
1009                         "flow_director_filter (port_id) mode raw (add|del|update)"
1010                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1011                         " fd_id (fd_id_value) packet (packet file name)\n"
1012                         "    Add/Del a raw type flow director filter.\n\n"
1013
1014                         "flush_flow_director (port_id)\n"
1015                         "    Flush all flow director entries of a device.\n\n"
1016
1017                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1018                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1019                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1020                         "    Set flow director IP mask.\n\n"
1021
1022                         "flow_director_mask (port_id) mode MAC-VLAN"
1023                         " vlan (vlan_value)\n"
1024                         "    Set flow director MAC-VLAN mask.\n\n"
1025
1026                         "flow_director_mask (port_id) mode Tunnel"
1027                         " vlan (vlan_value) mac (mac_value)"
1028                         " tunnel-type (tunnel_type_value)"
1029                         " tunnel-id (tunnel_id_value)\n"
1030                         "    Set flow director Tunnel mask.\n\n"
1031
1032                         "flow_director_flex_mask (port_id)"
1033                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1034                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1035                         " (mask)\n"
1036                         "    Configure mask of flex payload.\n\n"
1037
1038                         "flow_director_flex_payload (port_id)"
1039                         " (raw|l2|l3|l4) (config)\n"
1040                         "    Configure flex payload selection.\n\n"
1041
1042                         "get_sym_hash_ena_per_port (port_id)\n"
1043                         "    get symmetric hash enable configuration per port.\n\n"
1044
1045                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1046                         "    set symmetric hash enable configuration per port"
1047                         " to enable or disable.\n\n"
1048
1049                         "get_hash_global_config (port_id)\n"
1050                         "    Get the global configurations of hash filters.\n\n"
1051
1052                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1053                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1054                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1055                         " (enable|disable)\n"
1056                         "    Set the global configurations of hash filters.\n\n"
1057
1058                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1059                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1060                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1061                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1062                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1063                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1064                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1065                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1066                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1067                         "fld-8th|none) (select|add)\n"
1068                         "    Set the input set for hash.\n\n"
1069
1070                         "set_fdir_input_set (port_id) "
1071                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1072                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1073                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1074                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1075                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1076                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1077                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1078                         " (select|add)\n"
1079                         "    Set the input set for FDir.\n\n"
1080
1081                         "flow validate {port_id}"
1082                         " [group {group_id}] [priority {level}]"
1083                         " [ingress] [egress]"
1084                         " pattern {item} [/ {item} [...]] / end"
1085                         " actions {action} [/ {action} [...]] / end\n"
1086                         "    Check whether a flow rule can be created.\n\n"
1087
1088                         "flow create {port_id}"
1089                         " [group {group_id}] [priority {level}]"
1090                         " [ingress] [egress]"
1091                         " pattern {item} [/ {item} [...]] / end"
1092                         " actions {action} [/ {action} [...]] / end\n"
1093                         "    Create a flow rule.\n\n"
1094
1095                         "flow destroy {port_id} rule {rule_id} [...]\n"
1096                         "    Destroy specific flow rules.\n\n"
1097
1098                         "flow flush {port_id}\n"
1099                         "    Destroy all flow rules.\n\n"
1100
1101                         "flow query {port_id} {rule_id} {action}\n"
1102                         "    Query an existing flow rule.\n\n"
1103
1104                         "flow list {port_id} [group {group_id}] [...]\n"
1105                         "    List existing flow rules sorted by priority,"
1106                         " filtered by group identifiers.\n\n"
1107
1108                         "flow isolate {port_id} {boolean}\n"
1109                         "    Restrict ingress traffic to the defined"
1110                         " flow rules\n\n"
1111                 );
1112         }
1113 }
1114
1115 cmdline_parse_token_string_t cmd_help_long_help =
1116         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1117
1118 cmdline_parse_token_string_t cmd_help_long_section =
1119         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1120                         "all#control#display#config#"
1121                         "ports#registers#filters");
1122
1123 cmdline_parse_inst_t cmd_help_long = {
1124         .f = cmd_help_long_parsed,
1125         .data = NULL,
1126         .help_str = "help all|control|display|config|ports|register|filters: "
1127                 "Show help",
1128         .tokens = {
1129                 (void *)&cmd_help_long_help,
1130                 (void *)&cmd_help_long_section,
1131                 NULL,
1132         },
1133 };
1134
1135
1136 /* *** start/stop/close all ports *** */
1137 struct cmd_operate_port_result {
1138         cmdline_fixed_string_t keyword;
1139         cmdline_fixed_string_t name;
1140         cmdline_fixed_string_t value;
1141 };
1142
1143 static void cmd_operate_port_parsed(void *parsed_result,
1144                                 __attribute__((unused)) struct cmdline *cl,
1145                                 __attribute__((unused)) void *data)
1146 {
1147         struct cmd_operate_port_result *res = parsed_result;
1148
1149         if (!strcmp(res->name, "start"))
1150                 start_port(RTE_PORT_ALL);
1151         else if (!strcmp(res->name, "stop"))
1152                 stop_port(RTE_PORT_ALL);
1153         else if (!strcmp(res->name, "close"))
1154                 close_port(RTE_PORT_ALL);
1155         else if (!strcmp(res->name, "reset"))
1156                 reset_port(RTE_PORT_ALL);
1157         else
1158                 printf("Unknown parameter\n");
1159 }
1160
1161 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1162         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1163                                                                 "port");
1164 cmdline_parse_token_string_t cmd_operate_port_all_port =
1165         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1166                                                 "start#stop#close#reset");
1167 cmdline_parse_token_string_t cmd_operate_port_all_all =
1168         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1169
1170 cmdline_parse_inst_t cmd_operate_port = {
1171         .f = cmd_operate_port_parsed,
1172         .data = NULL,
1173         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1174         .tokens = {
1175                 (void *)&cmd_operate_port_all_cmd,
1176                 (void *)&cmd_operate_port_all_port,
1177                 (void *)&cmd_operate_port_all_all,
1178                 NULL,
1179         },
1180 };
1181
1182 /* *** start/stop/close specific port *** */
1183 struct cmd_operate_specific_port_result {
1184         cmdline_fixed_string_t keyword;
1185         cmdline_fixed_string_t name;
1186         uint8_t value;
1187 };
1188
1189 static void cmd_operate_specific_port_parsed(void *parsed_result,
1190                         __attribute__((unused)) struct cmdline *cl,
1191                                 __attribute__((unused)) void *data)
1192 {
1193         struct cmd_operate_specific_port_result *res = parsed_result;
1194
1195         if (!strcmp(res->name, "start"))
1196                 start_port(res->value);
1197         else if (!strcmp(res->name, "stop"))
1198                 stop_port(res->value);
1199         else if (!strcmp(res->name, "close"))
1200                 close_port(res->value);
1201         else if (!strcmp(res->name, "reset"))
1202                 reset_port(res->value);
1203         else
1204                 printf("Unknown parameter\n");
1205 }
1206
1207 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1208         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1209                                                         keyword, "port");
1210 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1211         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1212                                                 name, "start#stop#close#reset");
1213 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1214         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1215                                                         value, UINT8);
1216
1217 cmdline_parse_inst_t cmd_operate_specific_port = {
1218         .f = cmd_operate_specific_port_parsed,
1219         .data = NULL,
1220         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1221         .tokens = {
1222                 (void *)&cmd_operate_specific_port_cmd,
1223                 (void *)&cmd_operate_specific_port_port,
1224                 (void *)&cmd_operate_specific_port_id,
1225                 NULL,
1226         },
1227 };
1228
1229 /* *** attach a specified port *** */
1230 struct cmd_operate_attach_port_result {
1231         cmdline_fixed_string_t port;
1232         cmdline_fixed_string_t keyword;
1233         cmdline_fixed_string_t identifier;
1234 };
1235
1236 static void cmd_operate_attach_port_parsed(void *parsed_result,
1237                                 __attribute__((unused)) struct cmdline *cl,
1238                                 __attribute__((unused)) void *data)
1239 {
1240         struct cmd_operate_attach_port_result *res = parsed_result;
1241
1242         if (!strcmp(res->keyword, "attach"))
1243                 attach_port(res->identifier);
1244         else
1245                 printf("Unknown parameter\n");
1246 }
1247
1248 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1249         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1250                         port, "port");
1251 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1252         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1253                         keyword, "attach");
1254 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1256                         identifier, NULL);
1257
1258 cmdline_parse_inst_t cmd_operate_attach_port = {
1259         .f = cmd_operate_attach_port_parsed,
1260         .data = NULL,
1261         .help_str = "port attach <identifier>: "
1262                 "(identifier: pci address or virtual dev name)",
1263         .tokens = {
1264                 (void *)&cmd_operate_attach_port_port,
1265                 (void *)&cmd_operate_attach_port_keyword,
1266                 (void *)&cmd_operate_attach_port_identifier,
1267                 NULL,
1268         },
1269 };
1270
1271 /* *** detach a specified port *** */
1272 struct cmd_operate_detach_port_result {
1273         cmdline_fixed_string_t port;
1274         cmdline_fixed_string_t keyword;
1275         portid_t port_id;
1276 };
1277
1278 static void cmd_operate_detach_port_parsed(void *parsed_result,
1279                                 __attribute__((unused)) struct cmdline *cl,
1280                                 __attribute__((unused)) void *data)
1281 {
1282         struct cmd_operate_detach_port_result *res = parsed_result;
1283
1284         if (!strcmp(res->keyword, "detach"))
1285                 detach_port(res->port_id);
1286         else
1287                 printf("Unknown parameter\n");
1288 }
1289
1290 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1291         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1292                         port, "port");
1293 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1294         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1295                         keyword, "detach");
1296 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1297         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1298                         port_id, UINT16);
1299
1300 cmdline_parse_inst_t cmd_operate_detach_port = {
1301         .f = cmd_operate_detach_port_parsed,
1302         .data = NULL,
1303         .help_str = "port detach <port_id>",
1304         .tokens = {
1305                 (void *)&cmd_operate_detach_port_port,
1306                 (void *)&cmd_operate_detach_port_keyword,
1307                 (void *)&cmd_operate_detach_port_port_id,
1308                 NULL,
1309         },
1310 };
1311
1312 /* *** configure speed for all ports *** */
1313 struct cmd_config_speed_all {
1314         cmdline_fixed_string_t port;
1315         cmdline_fixed_string_t keyword;
1316         cmdline_fixed_string_t all;
1317         cmdline_fixed_string_t item1;
1318         cmdline_fixed_string_t item2;
1319         cmdline_fixed_string_t value1;
1320         cmdline_fixed_string_t value2;
1321 };
1322
1323 static int
1324 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1325 {
1326
1327         int duplex;
1328
1329         if (!strcmp(duplexstr, "half")) {
1330                 duplex = ETH_LINK_HALF_DUPLEX;
1331         } else if (!strcmp(duplexstr, "full")) {
1332                 duplex = ETH_LINK_FULL_DUPLEX;
1333         } else if (!strcmp(duplexstr, "auto")) {
1334                 duplex = ETH_LINK_FULL_DUPLEX;
1335         } else {
1336                 printf("Unknown duplex parameter\n");
1337                 return -1;
1338         }
1339
1340         if (!strcmp(speedstr, "10")) {
1341                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1342                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1343         } else if (!strcmp(speedstr, "100")) {
1344                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1345                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1346         } else {
1347                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1348                         printf("Invalid speed/duplex parameters\n");
1349                         return -1;
1350                 }
1351                 if (!strcmp(speedstr, "1000")) {
1352                         *speed = ETH_LINK_SPEED_1G;
1353                 } else if (!strcmp(speedstr, "10000")) {
1354                         *speed = ETH_LINK_SPEED_10G;
1355                 } else if (!strcmp(speedstr, "25000")) {
1356                         *speed = ETH_LINK_SPEED_25G;
1357                 } else if (!strcmp(speedstr, "40000")) {
1358                         *speed = ETH_LINK_SPEED_40G;
1359                 } else if (!strcmp(speedstr, "50000")) {
1360                         *speed = ETH_LINK_SPEED_50G;
1361                 } else if (!strcmp(speedstr, "100000")) {
1362                         *speed = ETH_LINK_SPEED_100G;
1363                 } else if (!strcmp(speedstr, "auto")) {
1364                         *speed = ETH_LINK_SPEED_AUTONEG;
1365                 } else {
1366                         printf("Unknown speed parameter\n");
1367                         return -1;
1368                 }
1369         }
1370
1371         return 0;
1372 }
1373
1374 static void
1375 cmd_config_speed_all_parsed(void *parsed_result,
1376                         __attribute__((unused)) struct cmdline *cl,
1377                         __attribute__((unused)) void *data)
1378 {
1379         struct cmd_config_speed_all *res = parsed_result;
1380         uint32_t link_speed;
1381         portid_t pid;
1382
1383         if (!all_ports_stopped()) {
1384                 printf("Please stop all ports first\n");
1385                 return;
1386         }
1387
1388         if (parse_and_check_speed_duplex(res->value1, res->value2,
1389                         &link_speed) < 0)
1390                 return;
1391
1392         RTE_ETH_FOREACH_DEV(pid) {
1393                 ports[pid].dev_conf.link_speeds = link_speed;
1394         }
1395
1396         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1397 }
1398
1399 cmdline_parse_token_string_t cmd_config_speed_all_port =
1400         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1401 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1402         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1403                                                         "config");
1404 cmdline_parse_token_string_t cmd_config_speed_all_all =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1406 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1408 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1409         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1410                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1411 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1412         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1413 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1414         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1415                                                 "half#full#auto");
1416
1417 cmdline_parse_inst_t cmd_config_speed_all = {
1418         .f = cmd_config_speed_all_parsed,
1419         .data = NULL,
1420         .help_str = "port config all speed "
1421                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1422                                                         "half|full|auto",
1423         .tokens = {
1424                 (void *)&cmd_config_speed_all_port,
1425                 (void *)&cmd_config_speed_all_keyword,
1426                 (void *)&cmd_config_speed_all_all,
1427                 (void *)&cmd_config_speed_all_item1,
1428                 (void *)&cmd_config_speed_all_value1,
1429                 (void *)&cmd_config_speed_all_item2,
1430                 (void *)&cmd_config_speed_all_value2,
1431                 NULL,
1432         },
1433 };
1434
1435 /* *** configure speed for specific port *** */
1436 struct cmd_config_speed_specific {
1437         cmdline_fixed_string_t port;
1438         cmdline_fixed_string_t keyword;
1439         portid_t id;
1440         cmdline_fixed_string_t item1;
1441         cmdline_fixed_string_t item2;
1442         cmdline_fixed_string_t value1;
1443         cmdline_fixed_string_t value2;
1444 };
1445
1446 static void
1447 cmd_config_speed_specific_parsed(void *parsed_result,
1448                                 __attribute__((unused)) struct cmdline *cl,
1449                                 __attribute__((unused)) void *data)
1450 {
1451         struct cmd_config_speed_specific *res = parsed_result;
1452         uint32_t link_speed;
1453
1454         if (!all_ports_stopped()) {
1455                 printf("Please stop all ports first\n");
1456                 return;
1457         }
1458
1459         if (port_id_is_invalid(res->id, ENABLED_WARN))
1460                 return;
1461
1462         if (parse_and_check_speed_duplex(res->value1, res->value2,
1463                         &link_speed) < 0)
1464                 return;
1465
1466         ports[res->id].dev_conf.link_speeds = link_speed;
1467
1468         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1469 }
1470
1471
1472 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1473         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1474                                                                 "port");
1475 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1476         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1477                                                                 "config");
1478 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1479         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1480 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1482                                                                 "speed");
1483 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1484         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1485                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1486 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1488                                                                 "duplex");
1489 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1490         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1491                                                         "half#full#auto");
1492
1493 cmdline_parse_inst_t cmd_config_speed_specific = {
1494         .f = cmd_config_speed_specific_parsed,
1495         .data = NULL,
1496         .help_str = "port config <port_id> speed "
1497                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1498                                                         "half|full|auto",
1499         .tokens = {
1500                 (void *)&cmd_config_speed_specific_port,
1501                 (void *)&cmd_config_speed_specific_keyword,
1502                 (void *)&cmd_config_speed_specific_id,
1503                 (void *)&cmd_config_speed_specific_item1,
1504                 (void *)&cmd_config_speed_specific_value1,
1505                 (void *)&cmd_config_speed_specific_item2,
1506                 (void *)&cmd_config_speed_specific_value2,
1507                 NULL,
1508         },
1509 };
1510
1511 /* *** configure loopback for all ports *** */
1512 struct cmd_config_loopback_all {
1513         cmdline_fixed_string_t port;
1514         cmdline_fixed_string_t keyword;
1515         cmdline_fixed_string_t all;
1516         cmdline_fixed_string_t item;
1517         uint32_t mode;
1518 };
1519
1520 static void
1521 cmd_config_loopback_all_parsed(void *parsed_result,
1522                         __attribute__((unused)) struct cmdline *cl,
1523                         __attribute__((unused)) void *data)
1524 {
1525         struct cmd_config_loopback_all *res = parsed_result;
1526         portid_t pid;
1527
1528         if (!all_ports_stopped()) {
1529                 printf("Please stop all ports first\n");
1530                 return;
1531         }
1532
1533         RTE_ETH_FOREACH_DEV(pid) {
1534                 ports[pid].dev_conf.lpbk_mode = res->mode;
1535         }
1536
1537         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1538 }
1539
1540 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1541         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1542 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1543         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1544                                                         "config");
1545 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1546         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1547 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1548         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1549                                                         "loopback");
1550 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1551         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1552
1553 cmdline_parse_inst_t cmd_config_loopback_all = {
1554         .f = cmd_config_loopback_all_parsed,
1555         .data = NULL,
1556         .help_str = "port config all loopback <mode>",
1557         .tokens = {
1558                 (void *)&cmd_config_loopback_all_port,
1559                 (void *)&cmd_config_loopback_all_keyword,
1560                 (void *)&cmd_config_loopback_all_all,
1561                 (void *)&cmd_config_loopback_all_item,
1562                 (void *)&cmd_config_loopback_all_mode,
1563                 NULL,
1564         },
1565 };
1566
1567 /* *** configure loopback for specific port *** */
1568 struct cmd_config_loopback_specific {
1569         cmdline_fixed_string_t port;
1570         cmdline_fixed_string_t keyword;
1571         uint16_t port_id;
1572         cmdline_fixed_string_t item;
1573         uint32_t mode;
1574 };
1575
1576 static void
1577 cmd_config_loopback_specific_parsed(void *parsed_result,
1578                                 __attribute__((unused)) struct cmdline *cl,
1579                                 __attribute__((unused)) void *data)
1580 {
1581         struct cmd_config_loopback_specific *res = parsed_result;
1582
1583         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1584                 return;
1585
1586         if (!port_is_stopped(res->port_id)) {
1587                 printf("Please stop port %u first\n", res->port_id);
1588                 return;
1589         }
1590
1591         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1592
1593         cmd_reconfig_device_queue(res->port_id, 1, 1);
1594 }
1595
1596
1597 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1599                                                                 "port");
1600 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1601         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1602                                                                 "config");
1603 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1604         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1605                                                                 UINT16);
1606 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1607         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1608                                                                 "loopback");
1609 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1610         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1611                               UINT32);
1612
1613 cmdline_parse_inst_t cmd_config_loopback_specific = {
1614         .f = cmd_config_loopback_specific_parsed,
1615         .data = NULL,
1616         .help_str = "port config <port_id> loopback <mode>",
1617         .tokens = {
1618                 (void *)&cmd_config_loopback_specific_port,
1619                 (void *)&cmd_config_loopback_specific_keyword,
1620                 (void *)&cmd_config_loopback_specific_id,
1621                 (void *)&cmd_config_loopback_specific_item,
1622                 (void *)&cmd_config_loopback_specific_mode,
1623                 NULL,
1624         },
1625 };
1626
1627 /* *** configure txq/rxq, txd/rxd *** */
1628 struct cmd_config_rx_tx {
1629         cmdline_fixed_string_t port;
1630         cmdline_fixed_string_t keyword;
1631         cmdline_fixed_string_t all;
1632         cmdline_fixed_string_t name;
1633         uint16_t value;
1634 };
1635
1636 static void
1637 cmd_config_rx_tx_parsed(void *parsed_result,
1638                         __attribute__((unused)) struct cmdline *cl,
1639                         __attribute__((unused)) void *data)
1640 {
1641         struct cmd_config_rx_tx *res = parsed_result;
1642
1643         if (!all_ports_stopped()) {
1644                 printf("Please stop all ports first\n");
1645                 return;
1646         }
1647         if (!strcmp(res->name, "rxq")) {
1648                 if (!res->value && !nb_txq) {
1649                         printf("Warning: Either rx or tx queues should be non zero\n");
1650                         return;
1651                 }
1652                 if (check_nb_rxq(res->value) != 0)
1653                         return;
1654                 nb_rxq = res->value;
1655         }
1656         else if (!strcmp(res->name, "txq")) {
1657                 if (!res->value && !nb_rxq) {
1658                         printf("Warning: Either rx or tx queues should be non zero\n");
1659                         return;
1660                 }
1661                 if (check_nb_txq(res->value) != 0)
1662                         return;
1663                 nb_txq = res->value;
1664         }
1665         else if (!strcmp(res->name, "rxd")) {
1666                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1667                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1668                                         res->value, RTE_TEST_RX_DESC_MAX);
1669                         return;
1670                 }
1671                 nb_rxd = res->value;
1672         } else if (!strcmp(res->name, "txd")) {
1673                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1674                         printf("txd %d invalid - must be > 0 && <= %d\n",
1675                                         res->value, RTE_TEST_TX_DESC_MAX);
1676                         return;
1677                 }
1678                 nb_txd = res->value;
1679         } else {
1680                 printf("Unknown parameter\n");
1681                 return;
1682         }
1683
1684         fwd_config_setup();
1685
1686         init_port_config();
1687
1688         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1689 }
1690
1691 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1692         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1693 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1695 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1696         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1697 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1698         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1699                                                 "rxq#txq#rxd#txd");
1700 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1701         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1702
1703 cmdline_parse_inst_t cmd_config_rx_tx = {
1704         .f = cmd_config_rx_tx_parsed,
1705         .data = NULL,
1706         .help_str = "port config all rxq|txq|rxd|txd <value>",
1707         .tokens = {
1708                 (void *)&cmd_config_rx_tx_port,
1709                 (void *)&cmd_config_rx_tx_keyword,
1710                 (void *)&cmd_config_rx_tx_all,
1711                 (void *)&cmd_config_rx_tx_name,
1712                 (void *)&cmd_config_rx_tx_value,
1713                 NULL,
1714         },
1715 };
1716
1717 /* *** config max packet length *** */
1718 struct cmd_config_max_pkt_len_result {
1719         cmdline_fixed_string_t port;
1720         cmdline_fixed_string_t keyword;
1721         cmdline_fixed_string_t all;
1722         cmdline_fixed_string_t name;
1723         uint32_t value;
1724 };
1725
1726 static void
1727 cmd_config_max_pkt_len_parsed(void *parsed_result,
1728                                 __attribute__((unused)) struct cmdline *cl,
1729                                 __attribute__((unused)) void *data)
1730 {
1731         struct cmd_config_max_pkt_len_result *res = parsed_result;
1732         portid_t pid;
1733
1734         if (!all_ports_stopped()) {
1735                 printf("Please stop all ports first\n");
1736                 return;
1737         }
1738
1739         RTE_ETH_FOREACH_DEV(pid) {
1740                 struct rte_port *port = &ports[pid];
1741                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1742
1743                 if (!strcmp(res->name, "max-pkt-len")) {
1744                         if (res->value < ETHER_MIN_LEN) {
1745                                 printf("max-pkt-len can not be less than %d\n",
1746                                                 ETHER_MIN_LEN);
1747                                 return;
1748                         }
1749                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1750                                 return;
1751
1752                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1753                         if (res->value > ETHER_MAX_LEN)
1754                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1755                         else
1756                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1757                         port->dev_conf.rxmode.offloads = rx_offloads;
1758                 } else {
1759                         printf("Unknown parameter\n");
1760                         return;
1761                 }
1762         }
1763
1764         init_port_config();
1765
1766         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1767 }
1768
1769 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1770         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1771                                                                 "port");
1772 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1774                                                                 "config");
1775 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1777                                                                 "all");
1778 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1779         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1780                                                                 "max-pkt-len");
1781 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1782         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1783                                                                 UINT32);
1784
1785 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1786         .f = cmd_config_max_pkt_len_parsed,
1787         .data = NULL,
1788         .help_str = "port config all max-pkt-len <value>",
1789         .tokens = {
1790                 (void *)&cmd_config_max_pkt_len_port,
1791                 (void *)&cmd_config_max_pkt_len_keyword,
1792                 (void *)&cmd_config_max_pkt_len_all,
1793                 (void *)&cmd_config_max_pkt_len_name,
1794                 (void *)&cmd_config_max_pkt_len_value,
1795                 NULL,
1796         },
1797 };
1798
1799 /* *** configure port MTU *** */
1800 struct cmd_config_mtu_result {
1801         cmdline_fixed_string_t port;
1802         cmdline_fixed_string_t keyword;
1803         cmdline_fixed_string_t mtu;
1804         portid_t port_id;
1805         uint16_t value;
1806 };
1807
1808 static void
1809 cmd_config_mtu_parsed(void *parsed_result,
1810                       __attribute__((unused)) struct cmdline *cl,
1811                       __attribute__((unused)) void *data)
1812 {
1813         struct cmd_config_mtu_result *res = parsed_result;
1814
1815         if (res->value < ETHER_MIN_LEN) {
1816                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1817                 return;
1818         }
1819         port_mtu_set(res->port_id, res->value);
1820 }
1821
1822 cmdline_parse_token_string_t cmd_config_mtu_port =
1823         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1824                                  "port");
1825 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1826         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1827                                  "config");
1828 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1829         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1830                                  "mtu");
1831 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1832         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1833 cmdline_parse_token_num_t cmd_config_mtu_value =
1834         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1835
1836 cmdline_parse_inst_t cmd_config_mtu = {
1837         .f = cmd_config_mtu_parsed,
1838         .data = NULL,
1839         .help_str = "port config mtu <port_id> <value>",
1840         .tokens = {
1841                 (void *)&cmd_config_mtu_port,
1842                 (void *)&cmd_config_mtu_keyword,
1843                 (void *)&cmd_config_mtu_mtu,
1844                 (void *)&cmd_config_mtu_port_id,
1845                 (void *)&cmd_config_mtu_value,
1846                 NULL,
1847         },
1848 };
1849
1850 /* *** configure rx mode *** */
1851 struct cmd_config_rx_mode_flag {
1852         cmdline_fixed_string_t port;
1853         cmdline_fixed_string_t keyword;
1854         cmdline_fixed_string_t all;
1855         cmdline_fixed_string_t name;
1856         cmdline_fixed_string_t value;
1857 };
1858
1859 static void
1860 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1861                                 __attribute__((unused)) struct cmdline *cl,
1862                                 __attribute__((unused)) void *data)
1863 {
1864         struct cmd_config_rx_mode_flag *res = parsed_result;
1865         portid_t pid;
1866
1867         if (!all_ports_stopped()) {
1868                 printf("Please stop all ports first\n");
1869                 return;
1870         }
1871
1872         RTE_ETH_FOREACH_DEV(pid) {
1873                 struct rte_port *port;
1874                 uint64_t rx_offloads;
1875
1876                 port = &ports[pid];
1877                 rx_offloads = port->dev_conf.rxmode.offloads;
1878                 if (!strcmp(res->name, "crc-strip")) {
1879                         if (!strcmp(res->value, "on"))
1880                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1881                         else if (!strcmp(res->value, "off"))
1882                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1883                         else {
1884                                 printf("Unknown parameter\n");
1885                                 return;
1886                         }
1887                 } else if (!strcmp(res->name, "scatter")) {
1888                         if (!strcmp(res->value, "on")) {
1889                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1890                         } else if (!strcmp(res->value, "off")) {
1891                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1892                         } else {
1893                                 printf("Unknown parameter\n");
1894                                 return;
1895                         }
1896                 } else if (!strcmp(res->name, "rx-cksum")) {
1897                         if (!strcmp(res->value, "on"))
1898                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1899                         else if (!strcmp(res->value, "off"))
1900                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1901                         else {
1902                                 printf("Unknown parameter\n");
1903                                 return;
1904                         }
1905                 } else if (!strcmp(res->name, "rx-timestamp")) {
1906                         if (!strcmp(res->value, "on"))
1907                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1908                         else if (!strcmp(res->value, "off"))
1909                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1910                         else {
1911                                 printf("Unknown parameter\n");
1912                                 return;
1913                         }
1914                 } else if (!strcmp(res->name, "hw-vlan")) {
1915                         if (!strcmp(res->value, "on")) {
1916                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1917                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1918                         } else if (!strcmp(res->value, "off")) {
1919                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1920                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1921                         } else {
1922                                 printf("Unknown parameter\n");
1923                                 return;
1924                         }
1925                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1926                         if (!strcmp(res->value, "on"))
1927                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1928                         else if (!strcmp(res->value, "off"))
1929                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1930                         else {
1931                                 printf("Unknown parameter\n");
1932                                 return;
1933                         }
1934                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1935                         if (!strcmp(res->value, "on"))
1936                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1937                         else if (!strcmp(res->value, "off"))
1938                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1939                         else {
1940                                 printf("Unknown parameter\n");
1941                                 return;
1942                         }
1943                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1944                         if (!strcmp(res->value, "on"))
1945                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1946                         else if (!strcmp(res->value, "off"))
1947                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1948                         else {
1949                                 printf("Unknown parameter\n");
1950                                 return;
1951                         }
1952                 } else if (!strcmp(res->name, "drop-en")) {
1953                         if (!strcmp(res->value, "on"))
1954                                 rx_drop_en = 1;
1955                         else if (!strcmp(res->value, "off"))
1956                                 rx_drop_en = 0;
1957                         else {
1958                                 printf("Unknown parameter\n");
1959                                 return;
1960                         }
1961                 } else {
1962                         printf("Unknown parameter\n");
1963                         return;
1964                 }
1965                 port->dev_conf.rxmode.offloads = rx_offloads;
1966         }
1967
1968         init_port_config();
1969
1970         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1971 }
1972
1973 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1974         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1975 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1976         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1977                                                                 "config");
1978 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1979         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1980 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1981         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1982                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1983                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1984 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1985         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1986                                                         "on#off");
1987
1988 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1989         .f = cmd_config_rx_mode_flag_parsed,
1990         .data = NULL,
1991         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1992                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1993         .tokens = {
1994                 (void *)&cmd_config_rx_mode_flag_port,
1995                 (void *)&cmd_config_rx_mode_flag_keyword,
1996                 (void *)&cmd_config_rx_mode_flag_all,
1997                 (void *)&cmd_config_rx_mode_flag_name,
1998                 (void *)&cmd_config_rx_mode_flag_value,
1999                 NULL,
2000         },
2001 };
2002
2003 /* *** configure rss *** */
2004 struct cmd_config_rss {
2005         cmdline_fixed_string_t port;
2006         cmdline_fixed_string_t keyword;
2007         cmdline_fixed_string_t all;
2008         cmdline_fixed_string_t name;
2009         cmdline_fixed_string_t value;
2010 };
2011
2012 static void
2013 cmd_config_rss_parsed(void *parsed_result,
2014                         __attribute__((unused)) struct cmdline *cl,
2015                         __attribute__((unused)) void *data)
2016 {
2017         struct cmd_config_rss *res = parsed_result;
2018         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2019         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2020         int use_default = 0;
2021         int all_updated = 1;
2022         int diag;
2023         uint16_t i;
2024
2025         if (!strcmp(res->value, "all"))
2026                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2027                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2028                                         ETH_RSS_L2_PAYLOAD;
2029         else if (!strcmp(res->value, "ip"))
2030                 rss_conf.rss_hf = ETH_RSS_IP;
2031         else if (!strcmp(res->value, "udp"))
2032                 rss_conf.rss_hf = ETH_RSS_UDP;
2033         else if (!strcmp(res->value, "tcp"))
2034                 rss_conf.rss_hf = ETH_RSS_TCP;
2035         else if (!strcmp(res->value, "sctp"))
2036                 rss_conf.rss_hf = ETH_RSS_SCTP;
2037         else if (!strcmp(res->value, "ether"))
2038                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2039         else if (!strcmp(res->value, "port"))
2040                 rss_conf.rss_hf = ETH_RSS_PORT;
2041         else if (!strcmp(res->value, "vxlan"))
2042                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2043         else if (!strcmp(res->value, "geneve"))
2044                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2045         else if (!strcmp(res->value, "nvgre"))
2046                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2047         else if (!strcmp(res->value, "none"))
2048                 rss_conf.rss_hf = 0;
2049         else if (!strcmp(res->value, "default"))
2050                 use_default = 1;
2051         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2052                                                 atoi(res->value) < 64)
2053                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2054         else {
2055                 printf("Unknown parameter\n");
2056                 return;
2057         }
2058         rss_conf.rss_key = NULL;
2059         /* Update global configuration for RSS types. */
2060         RTE_ETH_FOREACH_DEV(i) {
2061                 struct rte_eth_rss_conf local_rss_conf;
2062
2063                 rte_eth_dev_info_get(i, &dev_info);
2064                 if (use_default)
2065                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2066
2067                 local_rss_conf = rss_conf;
2068                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2069                         dev_info.flow_type_rss_offloads;
2070                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2071                         printf("Port %u modified RSS hash function based on hardware support,"
2072                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2073                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2074                 }
2075                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2076                 if (diag < 0) {
2077                         all_updated = 0;
2078                         printf("Configuration of RSS hash at ethernet port %d "
2079                                 "failed with error (%d): %s.\n",
2080                                 i, -diag, strerror(-diag));
2081                 }
2082         }
2083         if (all_updated && !use_default)
2084                 rss_hf = rss_conf.rss_hf;
2085 }
2086
2087 cmdline_parse_token_string_t cmd_config_rss_port =
2088         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2089 cmdline_parse_token_string_t cmd_config_rss_keyword =
2090         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2091 cmdline_parse_token_string_t cmd_config_rss_all =
2092         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2093 cmdline_parse_token_string_t cmd_config_rss_name =
2094         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2095 cmdline_parse_token_string_t cmd_config_rss_value =
2096         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2097
2098 cmdline_parse_inst_t cmd_config_rss = {
2099         .f = cmd_config_rss_parsed,
2100         .data = NULL,
2101         .help_str = "port config all rss "
2102                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2103         .tokens = {
2104                 (void *)&cmd_config_rss_port,
2105                 (void *)&cmd_config_rss_keyword,
2106                 (void *)&cmd_config_rss_all,
2107                 (void *)&cmd_config_rss_name,
2108                 (void *)&cmd_config_rss_value,
2109                 NULL,
2110         },
2111 };
2112
2113 /* *** configure rss hash key *** */
2114 struct cmd_config_rss_hash_key {
2115         cmdline_fixed_string_t port;
2116         cmdline_fixed_string_t config;
2117         portid_t port_id;
2118         cmdline_fixed_string_t rss_hash_key;
2119         cmdline_fixed_string_t rss_type;
2120         cmdline_fixed_string_t key;
2121 };
2122
2123 static uint8_t
2124 hexa_digit_to_value(char hexa_digit)
2125 {
2126         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2127                 return (uint8_t) (hexa_digit - '0');
2128         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2129                 return (uint8_t) ((hexa_digit - 'a') + 10);
2130         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2131                 return (uint8_t) ((hexa_digit - 'A') + 10);
2132         /* Invalid hexa digit */
2133         return 0xFF;
2134 }
2135
2136 static uint8_t
2137 parse_and_check_key_hexa_digit(char *key, int idx)
2138 {
2139         uint8_t hexa_v;
2140
2141         hexa_v = hexa_digit_to_value(key[idx]);
2142         if (hexa_v == 0xFF)
2143                 printf("invalid key: character %c at position %d is not a "
2144                        "valid hexa digit\n", key[idx], idx);
2145         return hexa_v;
2146 }
2147
2148 static void
2149 cmd_config_rss_hash_key_parsed(void *parsed_result,
2150                                __attribute__((unused)) struct cmdline *cl,
2151                                __attribute__((unused)) void *data)
2152 {
2153         struct cmd_config_rss_hash_key *res = parsed_result;
2154         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2155         uint8_t xdgt0;
2156         uint8_t xdgt1;
2157         int i;
2158         struct rte_eth_dev_info dev_info;
2159         uint8_t hash_key_size;
2160         uint32_t key_len;
2161
2162         memset(&dev_info, 0, sizeof(dev_info));
2163         rte_eth_dev_info_get(res->port_id, &dev_info);
2164         if (dev_info.hash_key_size > 0 &&
2165                         dev_info.hash_key_size <= sizeof(hash_key))
2166                 hash_key_size = dev_info.hash_key_size;
2167         else {
2168                 printf("dev_info did not provide a valid hash key size\n");
2169                 return;
2170         }
2171         /* Check the length of the RSS hash key */
2172         key_len = strlen(res->key);
2173         if (key_len != (hash_key_size * 2)) {
2174                 printf("key length: %d invalid - key must be a string of %d"
2175                            " hexa-decimal numbers\n",
2176                            (int) key_len, hash_key_size * 2);
2177                 return;
2178         }
2179         /* Translate RSS hash key into binary representation */
2180         for (i = 0; i < hash_key_size; i++) {
2181                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2182                 if (xdgt0 == 0xFF)
2183                         return;
2184                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2185                 if (xdgt1 == 0xFF)
2186                         return;
2187                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2188         }
2189         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2190                         hash_key_size);
2191 }
2192
2193 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2194         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2195 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2196         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2197                                  "config");
2198 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2199         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2200 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2201         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2202                                  rss_hash_key, "rss-hash-key");
2203 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2204         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2205                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2206                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2207                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2208                                  "ipv6-tcp-ex#ipv6-udp-ex");
2209 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2210         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2211
2212 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2213         .f = cmd_config_rss_hash_key_parsed,
2214         .data = NULL,
2215         .help_str = "port config <port_id> rss-hash-key "
2216                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2217                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2218                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2219                 "<string of hex digits (variable length, NIC dependent)>",
2220         .tokens = {
2221                 (void *)&cmd_config_rss_hash_key_port,
2222                 (void *)&cmd_config_rss_hash_key_config,
2223                 (void *)&cmd_config_rss_hash_key_port_id,
2224                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2225                 (void *)&cmd_config_rss_hash_key_rss_type,
2226                 (void *)&cmd_config_rss_hash_key_value,
2227                 NULL,
2228         },
2229 };
2230
2231 /* *** configure port rxq/txq ring size *** */
2232 struct cmd_config_rxtx_ring_size {
2233         cmdline_fixed_string_t port;
2234         cmdline_fixed_string_t config;
2235         portid_t portid;
2236         cmdline_fixed_string_t rxtxq;
2237         uint16_t qid;
2238         cmdline_fixed_string_t rsize;
2239         uint16_t size;
2240 };
2241
2242 static void
2243 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2244                                  __attribute__((unused)) struct cmdline *cl,
2245                                  __attribute__((unused)) void *data)
2246 {
2247         struct cmd_config_rxtx_ring_size *res = parsed_result;
2248         struct rte_port *port;
2249         uint8_t isrx;
2250
2251         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2252                 return;
2253
2254         if (res->portid == (portid_t)RTE_PORT_ALL) {
2255                 printf("Invalid port id\n");
2256                 return;
2257         }
2258
2259         port = &ports[res->portid];
2260
2261         if (!strcmp(res->rxtxq, "rxq"))
2262                 isrx = 1;
2263         else if (!strcmp(res->rxtxq, "txq"))
2264                 isrx = 0;
2265         else {
2266                 printf("Unknown parameter\n");
2267                 return;
2268         }
2269
2270         if (isrx && rx_queue_id_is_invalid(res->qid))
2271                 return;
2272         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2273                 return;
2274
2275         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2276                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2277                        rx_free_thresh);
2278                 return;
2279         }
2280
2281         if (isrx)
2282                 port->nb_rx_desc[res->qid] = res->size;
2283         else
2284                 port->nb_tx_desc[res->qid] = res->size;
2285
2286         cmd_reconfig_device_queue(res->portid, 0, 1);
2287 }
2288
2289 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2290         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2291                                  port, "port");
2292 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2293         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2294                                  config, "config");
2295 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2296         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2297                                  portid, UINT16);
2298 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2300                                  rxtxq, "rxq#txq");
2301 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2302         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2303                               qid, UINT16);
2304 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2306                                  rsize, "ring_size");
2307 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2308         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2309                               size, UINT16);
2310
2311 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2312         .f = cmd_config_rxtx_ring_size_parsed,
2313         .data = NULL,
2314         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2315         .tokens = {
2316                 (void *)&cmd_config_rxtx_ring_size_port,
2317                 (void *)&cmd_config_rxtx_ring_size_config,
2318                 (void *)&cmd_config_rxtx_ring_size_portid,
2319                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2320                 (void *)&cmd_config_rxtx_ring_size_qid,
2321                 (void *)&cmd_config_rxtx_ring_size_rsize,
2322                 (void *)&cmd_config_rxtx_ring_size_size,
2323                 NULL,
2324         },
2325 };
2326
2327 /* *** configure port rxq/txq start/stop *** */
2328 struct cmd_config_rxtx_queue {
2329         cmdline_fixed_string_t port;
2330         portid_t portid;
2331         cmdline_fixed_string_t rxtxq;
2332         uint16_t qid;
2333         cmdline_fixed_string_t opname;
2334 };
2335
2336 static void
2337 cmd_config_rxtx_queue_parsed(void *parsed_result,
2338                         __attribute__((unused)) struct cmdline *cl,
2339                         __attribute__((unused)) void *data)
2340 {
2341         struct cmd_config_rxtx_queue *res = parsed_result;
2342         uint8_t isrx;
2343         uint8_t isstart;
2344         int ret = 0;
2345
2346         if (test_done == 0) {
2347                 printf("Please stop forwarding first\n");
2348                 return;
2349         }
2350
2351         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2352                 return;
2353
2354         if (port_is_started(res->portid) != 1) {
2355                 printf("Please start port %u first\n", res->portid);
2356                 return;
2357         }
2358
2359         if (!strcmp(res->rxtxq, "rxq"))
2360                 isrx = 1;
2361         else if (!strcmp(res->rxtxq, "txq"))
2362                 isrx = 0;
2363         else {
2364                 printf("Unknown parameter\n");
2365                 return;
2366         }
2367
2368         if (isrx && rx_queue_id_is_invalid(res->qid))
2369                 return;
2370         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2371                 return;
2372
2373         if (!strcmp(res->opname, "start"))
2374                 isstart = 1;
2375         else if (!strcmp(res->opname, "stop"))
2376                 isstart = 0;
2377         else {
2378                 printf("Unknown parameter\n");
2379                 return;
2380         }
2381
2382         if (isstart && isrx)
2383                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2384         else if (!isstart && isrx)
2385                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2386         else if (isstart && !isrx)
2387                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2388         else
2389                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2390
2391         if (ret == -ENOTSUP)
2392                 printf("Function not supported in PMD driver\n");
2393 }
2394
2395 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2396         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2397 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2398         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2399 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2401 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2402         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2403 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2404         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2405                                                 "start#stop");
2406
2407 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2408         .f = cmd_config_rxtx_queue_parsed,
2409         .data = NULL,
2410         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2411         .tokens = {
2412                 (void *)&cmd_config_rxtx_queue_port,
2413                 (void *)&cmd_config_rxtx_queue_portid,
2414                 (void *)&cmd_config_rxtx_queue_rxtxq,
2415                 (void *)&cmd_config_rxtx_queue_qid,
2416                 (void *)&cmd_config_rxtx_queue_opname,
2417                 NULL,
2418         },
2419 };
2420
2421 /* *** configure port rxq/txq setup *** */
2422 struct cmd_setup_rxtx_queue {
2423         cmdline_fixed_string_t port;
2424         portid_t portid;
2425         cmdline_fixed_string_t rxtxq;
2426         uint16_t qid;
2427         cmdline_fixed_string_t setup;
2428 };
2429
2430 /* Common CLI fields for queue setup */
2431 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2432         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2433 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2434         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2435 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2436         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2437 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2438         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2439 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2440         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2441
2442 static void
2443 cmd_setup_rxtx_queue_parsed(
2444         void *parsed_result,
2445         __attribute__((unused)) struct cmdline *cl,
2446         __attribute__((unused)) void *data)
2447 {
2448         struct cmd_setup_rxtx_queue *res = parsed_result;
2449         struct rte_port *port;
2450         struct rte_mempool *mp;
2451         unsigned int socket_id;
2452         uint8_t isrx = 0;
2453         int ret;
2454
2455         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2456                 return;
2457
2458         if (res->portid == (portid_t)RTE_PORT_ALL) {
2459                 printf("Invalid port id\n");
2460                 return;
2461         }
2462
2463         if (!strcmp(res->rxtxq, "rxq"))
2464                 isrx = 1;
2465         else if (!strcmp(res->rxtxq, "txq"))
2466                 isrx = 0;
2467         else {
2468                 printf("Unknown parameter\n");
2469                 return;
2470         }
2471
2472         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2473                 printf("Invalid rx queue\n");
2474                 return;
2475         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2476                 printf("Invalid tx queue\n");
2477                 return;
2478         }
2479
2480         port = &ports[res->portid];
2481         if (isrx) {
2482                 socket_id = rxring_numa[res->portid];
2483                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2484                         socket_id = port->socket_id;
2485
2486                 mp = mbuf_pool_find(socket_id);
2487                 if (mp == NULL) {
2488                         printf("Failed to setup RX queue: "
2489                                 "No mempool allocation"
2490                                 " on the socket %d\n",
2491                                 rxring_numa[res->portid]);
2492                         return;
2493                 }
2494                 ret = rte_eth_rx_queue_setup(res->portid,
2495                                              res->qid,
2496                                              port->nb_rx_desc[res->qid],
2497                                              socket_id,
2498                                              &port->rx_conf[res->qid],
2499                                              mp);
2500                 if (ret)
2501                         printf("Failed to setup RX queue\n");
2502         } else {
2503                 socket_id = txring_numa[res->portid];
2504                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2505                         socket_id = port->socket_id;
2506
2507                 ret = rte_eth_tx_queue_setup(res->portid,
2508                                              res->qid,
2509                                              port->nb_tx_desc[res->qid],
2510                                              socket_id,
2511                                              &port->tx_conf[res->qid]);
2512                 if (ret)
2513                         printf("Failed to setup TX queue\n");
2514         }
2515 }
2516
2517 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2518         .f = cmd_setup_rxtx_queue_parsed,
2519         .data = NULL,
2520         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2521         .tokens = {
2522                 (void *)&cmd_setup_rxtx_queue_port,
2523                 (void *)&cmd_setup_rxtx_queue_portid,
2524                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2525                 (void *)&cmd_setup_rxtx_queue_qid,
2526                 (void *)&cmd_setup_rxtx_queue_setup,
2527                 NULL,
2528         },
2529 };
2530
2531
2532 /* *** Configure RSS RETA *** */
2533 struct cmd_config_rss_reta {
2534         cmdline_fixed_string_t port;
2535         cmdline_fixed_string_t keyword;
2536         portid_t port_id;
2537         cmdline_fixed_string_t name;
2538         cmdline_fixed_string_t list_name;
2539         cmdline_fixed_string_t list_of_items;
2540 };
2541
2542 static int
2543 parse_reta_config(const char *str,
2544                   struct rte_eth_rss_reta_entry64 *reta_conf,
2545                   uint16_t nb_entries)
2546 {
2547         int i;
2548         unsigned size;
2549         uint16_t hash_index, idx, shift;
2550         uint16_t nb_queue;
2551         char s[256];
2552         const char *p, *p0 = str;
2553         char *end;
2554         enum fieldnames {
2555                 FLD_HASH_INDEX = 0,
2556                 FLD_QUEUE,
2557                 _NUM_FLD
2558         };
2559         unsigned long int_fld[_NUM_FLD];
2560         char *str_fld[_NUM_FLD];
2561
2562         while ((p = strchr(p0,'(')) != NULL) {
2563                 ++p;
2564                 if((p0 = strchr(p,')')) == NULL)
2565                         return -1;
2566
2567                 size = p0 - p;
2568                 if(size >= sizeof(s))
2569                         return -1;
2570
2571                 snprintf(s, sizeof(s), "%.*s", size, p);
2572                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2573                         return -1;
2574                 for (i = 0; i < _NUM_FLD; i++) {
2575                         errno = 0;
2576                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2577                         if (errno != 0 || end == str_fld[i] ||
2578                                         int_fld[i] > 65535)
2579                                 return -1;
2580                 }
2581
2582                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2583                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2584
2585                 if (hash_index >= nb_entries) {
2586                         printf("Invalid RETA hash index=%d\n", hash_index);
2587                         return -1;
2588                 }
2589
2590                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2591                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2592                 reta_conf[idx].mask |= (1ULL << shift);
2593                 reta_conf[idx].reta[shift] = nb_queue;
2594         }
2595
2596         return 0;
2597 }
2598
2599 static void
2600 cmd_set_rss_reta_parsed(void *parsed_result,
2601                         __attribute__((unused)) struct cmdline *cl,
2602                         __attribute__((unused)) void *data)
2603 {
2604         int ret;
2605         struct rte_eth_dev_info dev_info;
2606         struct rte_eth_rss_reta_entry64 reta_conf[8];
2607         struct cmd_config_rss_reta *res = parsed_result;
2608
2609         memset(&dev_info, 0, sizeof(dev_info));
2610         rte_eth_dev_info_get(res->port_id, &dev_info);
2611         if (dev_info.reta_size == 0) {
2612                 printf("Redirection table size is 0 which is "
2613                                         "invalid for RSS\n");
2614                 return;
2615         } else
2616                 printf("The reta size of port %d is %u\n",
2617                         res->port_id, dev_info.reta_size);
2618         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2619                 printf("Currently do not support more than %u entries of "
2620                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2621                 return;
2622         }
2623
2624         memset(reta_conf, 0, sizeof(reta_conf));
2625         if (!strcmp(res->list_name, "reta")) {
2626                 if (parse_reta_config(res->list_of_items, reta_conf,
2627                                                 dev_info.reta_size)) {
2628                         printf("Invalid RSS Redirection Table "
2629                                         "config entered\n");
2630                         return;
2631                 }
2632                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2633                                 reta_conf, dev_info.reta_size);
2634                 if (ret != 0)
2635                         printf("Bad redirection table parameter, "
2636                                         "return code = %d \n", ret);
2637         }
2638 }
2639
2640 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2641         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2642 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2643         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2644 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2645         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2646 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2647         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2648 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2649         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2650 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2651         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2652                                  NULL);
2653 cmdline_parse_inst_t cmd_config_rss_reta = {
2654         .f = cmd_set_rss_reta_parsed,
2655         .data = NULL,
2656         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2657         .tokens = {
2658                 (void *)&cmd_config_rss_reta_port,
2659                 (void *)&cmd_config_rss_reta_keyword,
2660                 (void *)&cmd_config_rss_reta_port_id,
2661                 (void *)&cmd_config_rss_reta_name,
2662                 (void *)&cmd_config_rss_reta_list_name,
2663                 (void *)&cmd_config_rss_reta_list_of_items,
2664                 NULL,
2665         },
2666 };
2667
2668 /* *** SHOW PORT RETA INFO *** */
2669 struct cmd_showport_reta {
2670         cmdline_fixed_string_t show;
2671         cmdline_fixed_string_t port;
2672         portid_t port_id;
2673         cmdline_fixed_string_t rss;
2674         cmdline_fixed_string_t reta;
2675         uint16_t size;
2676         cmdline_fixed_string_t list_of_items;
2677 };
2678
2679 static int
2680 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2681                            uint16_t nb_entries,
2682                            char *str)
2683 {
2684         uint32_t size;
2685         const char *p, *p0 = str;
2686         char s[256];
2687         char *end;
2688         char *str_fld[8];
2689         uint16_t i;
2690         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2691                         RTE_RETA_GROUP_SIZE;
2692         int ret;
2693
2694         p = strchr(p0, '(');
2695         if (p == NULL)
2696                 return -1;
2697         p++;
2698         p0 = strchr(p, ')');
2699         if (p0 == NULL)
2700                 return -1;
2701         size = p0 - p;
2702         if (size >= sizeof(s)) {
2703                 printf("The string size exceeds the internal buffer size\n");
2704                 return -1;
2705         }
2706         snprintf(s, sizeof(s), "%.*s", size, p);
2707         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2708         if (ret <= 0 || ret != num) {
2709                 printf("The bits of masks do not match the number of "
2710                                         "reta entries: %u\n", num);
2711                 return -1;
2712         }
2713         for (i = 0; i < ret; i++)
2714                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2715
2716         return 0;
2717 }
2718
2719 static void
2720 cmd_showport_reta_parsed(void *parsed_result,
2721                          __attribute__((unused)) struct cmdline *cl,
2722                          __attribute__((unused)) void *data)
2723 {
2724         struct cmd_showport_reta *res = parsed_result;
2725         struct rte_eth_rss_reta_entry64 reta_conf[8];
2726         struct rte_eth_dev_info dev_info;
2727         uint16_t max_reta_size;
2728
2729         memset(&dev_info, 0, sizeof(dev_info));
2730         rte_eth_dev_info_get(res->port_id, &dev_info);
2731         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2732         if (res->size == 0 || res->size > max_reta_size) {
2733                 printf("Invalid redirection table size: %u (1-%u)\n",
2734                         res->size, max_reta_size);
2735                 return;
2736         }
2737
2738         memset(reta_conf, 0, sizeof(reta_conf));
2739         if (showport_parse_reta_config(reta_conf, res->size,
2740                                 res->list_of_items) < 0) {
2741                 printf("Invalid string: %s for reta masks\n",
2742                                         res->list_of_items);
2743                 return;
2744         }
2745         port_rss_reta_info(res->port_id, reta_conf, res->size);
2746 }
2747
2748 cmdline_parse_token_string_t cmd_showport_reta_show =
2749         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2750 cmdline_parse_token_string_t cmd_showport_reta_port =
2751         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2752 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2753         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2754 cmdline_parse_token_string_t cmd_showport_reta_rss =
2755         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2756 cmdline_parse_token_string_t cmd_showport_reta_reta =
2757         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2758 cmdline_parse_token_num_t cmd_showport_reta_size =
2759         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2760 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2761         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2762                                         list_of_items, NULL);
2763
2764 cmdline_parse_inst_t cmd_showport_reta = {
2765         .f = cmd_showport_reta_parsed,
2766         .data = NULL,
2767         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2768         .tokens = {
2769                 (void *)&cmd_showport_reta_show,
2770                 (void *)&cmd_showport_reta_port,
2771                 (void *)&cmd_showport_reta_port_id,
2772                 (void *)&cmd_showport_reta_rss,
2773                 (void *)&cmd_showport_reta_reta,
2774                 (void *)&cmd_showport_reta_size,
2775                 (void *)&cmd_showport_reta_list_of_items,
2776                 NULL,
2777         },
2778 };
2779
2780 /* *** Show RSS hash configuration *** */
2781 struct cmd_showport_rss_hash {
2782         cmdline_fixed_string_t show;
2783         cmdline_fixed_string_t port;
2784         portid_t port_id;
2785         cmdline_fixed_string_t rss_hash;
2786         cmdline_fixed_string_t rss_type;
2787         cmdline_fixed_string_t key; /* optional argument */
2788 };
2789
2790 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2791                                 __attribute__((unused)) struct cmdline *cl,
2792                                 void *show_rss_key)
2793 {
2794         struct cmd_showport_rss_hash *res = parsed_result;
2795
2796         port_rss_hash_conf_show(res->port_id, res->rss_type,
2797                                 show_rss_key != NULL);
2798 }
2799
2800 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2801         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2802 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2803         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2804 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2805         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2806 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2807         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2808                                  "rss-hash");
2809 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2810         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2811                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2812                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2813                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2814                                  "ipv6-tcp-ex#ipv6-udp-ex");
2815 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2816         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2817
2818 cmdline_parse_inst_t cmd_showport_rss_hash = {
2819         .f = cmd_showport_rss_hash_parsed,
2820         .data = NULL,
2821         .help_str = "show port <port_id> rss-hash "
2822                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2823                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2824                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2825         .tokens = {
2826                 (void *)&cmd_showport_rss_hash_show,
2827                 (void *)&cmd_showport_rss_hash_port,
2828                 (void *)&cmd_showport_rss_hash_port_id,
2829                 (void *)&cmd_showport_rss_hash_rss_hash,
2830                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2831                 NULL,
2832         },
2833 };
2834
2835 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2836         .f = cmd_showport_rss_hash_parsed,
2837         .data = (void *)1,
2838         .help_str = "show port <port_id> rss-hash "
2839                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2840                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2841                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2842         .tokens = {
2843                 (void *)&cmd_showport_rss_hash_show,
2844                 (void *)&cmd_showport_rss_hash_port,
2845                 (void *)&cmd_showport_rss_hash_port_id,
2846                 (void *)&cmd_showport_rss_hash_rss_hash,
2847                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2848                 (void *)&cmd_showport_rss_hash_rss_key,
2849                 NULL,
2850         },
2851 };
2852
2853 /* *** Configure DCB *** */
2854 struct cmd_config_dcb {
2855         cmdline_fixed_string_t port;
2856         cmdline_fixed_string_t config;
2857         portid_t port_id;
2858         cmdline_fixed_string_t dcb;
2859         cmdline_fixed_string_t vt;
2860         cmdline_fixed_string_t vt_en;
2861         uint8_t num_tcs;
2862         cmdline_fixed_string_t pfc;
2863         cmdline_fixed_string_t pfc_en;
2864 };
2865
2866 static void
2867 cmd_config_dcb_parsed(void *parsed_result,
2868                         __attribute__((unused)) struct cmdline *cl,
2869                         __attribute__((unused)) void *data)
2870 {
2871         struct cmd_config_dcb *res = parsed_result;
2872         portid_t port_id = res->port_id;
2873         struct rte_port *port;
2874         uint8_t pfc_en;
2875         int ret;
2876
2877         port = &ports[port_id];
2878         /** Check if the port is not started **/
2879         if (port->port_status != RTE_PORT_STOPPED) {
2880                 printf("Please stop port %d first\n", port_id);
2881                 return;
2882         }
2883
2884         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2885                 printf("The invalid number of traffic class,"
2886                         " only 4 or 8 allowed.\n");
2887                 return;
2888         }
2889
2890         if (nb_fwd_lcores < res->num_tcs) {
2891                 printf("nb_cores shouldn't be less than number of TCs.\n");
2892                 return;
2893         }
2894         if (!strncmp(res->pfc_en, "on", 2))
2895                 pfc_en = 1;
2896         else
2897                 pfc_en = 0;
2898
2899         /* DCB in VT mode */
2900         if (!strncmp(res->vt_en, "on", 2))
2901                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2902                                 (enum rte_eth_nb_tcs)res->num_tcs,
2903                                 pfc_en);
2904         else
2905                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2906                                 (enum rte_eth_nb_tcs)res->num_tcs,
2907                                 pfc_en);
2908
2909
2910         if (ret != 0) {
2911                 printf("Cannot initialize network ports.\n");
2912                 return;
2913         }
2914
2915         cmd_reconfig_device_queue(port_id, 1, 1);
2916 }
2917
2918 cmdline_parse_token_string_t cmd_config_dcb_port =
2919         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2920 cmdline_parse_token_string_t cmd_config_dcb_config =
2921         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2922 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2923         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2924 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2925         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2926 cmdline_parse_token_string_t cmd_config_dcb_vt =
2927         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2928 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2929         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2930 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2931         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2932 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2933         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2934 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2935         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2936
2937 cmdline_parse_inst_t cmd_config_dcb = {
2938         .f = cmd_config_dcb_parsed,
2939         .data = NULL,
2940         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2941         .tokens = {
2942                 (void *)&cmd_config_dcb_port,
2943                 (void *)&cmd_config_dcb_config,
2944                 (void *)&cmd_config_dcb_port_id,
2945                 (void *)&cmd_config_dcb_dcb,
2946                 (void *)&cmd_config_dcb_vt,
2947                 (void *)&cmd_config_dcb_vt_en,
2948                 (void *)&cmd_config_dcb_num_tcs,
2949                 (void *)&cmd_config_dcb_pfc,
2950                 (void *)&cmd_config_dcb_pfc_en,
2951                 NULL,
2952         },
2953 };
2954
2955 /* *** configure number of packets per burst *** */
2956 struct cmd_config_burst {
2957         cmdline_fixed_string_t port;
2958         cmdline_fixed_string_t keyword;
2959         cmdline_fixed_string_t all;
2960         cmdline_fixed_string_t name;
2961         uint16_t value;
2962 };
2963
2964 static void
2965 cmd_config_burst_parsed(void *parsed_result,
2966                         __attribute__((unused)) struct cmdline *cl,
2967                         __attribute__((unused)) void *data)
2968 {
2969         struct cmd_config_burst *res = parsed_result;
2970         struct rte_eth_dev_info dev_info;
2971         uint16_t rec_nb_pkts;
2972
2973         if (!all_ports_stopped()) {
2974                 printf("Please stop all ports first\n");
2975                 return;
2976         }
2977
2978         if (!strcmp(res->name, "burst")) {
2979                 if (res->value == 0) {
2980                         /* If user gives a value of zero, query the PMD for
2981                          * its recommended Rx burst size. Testpmd uses a single
2982                          * size for all ports, so assume all ports are the same
2983                          * NIC model and use the values from Port 0.
2984                          */
2985                         rte_eth_dev_info_get(0, &dev_info);
2986                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2987
2988                         if (rec_nb_pkts == 0) {
2989                                 printf("PMD does not recommend a burst size.\n"
2990                                         "User provided value must be between"
2991                                         " 1 and %d\n", MAX_PKT_BURST);
2992                                 return;
2993                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2994                                 printf("PMD recommended burst size of %d"
2995                                         " exceeds maximum value of %d\n",
2996                                         rec_nb_pkts, MAX_PKT_BURST);
2997                                 return;
2998                         }
2999                         printf("Using PMD-provided burst value of %d\n",
3000                                 rec_nb_pkts);
3001                         nb_pkt_per_burst = rec_nb_pkts;
3002                 } else if (res->value > MAX_PKT_BURST) {
3003                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3004                         return;
3005                 } else
3006                         nb_pkt_per_burst = res->value;
3007         } else {
3008                 printf("Unknown parameter\n");
3009                 return;
3010         }
3011
3012         init_port_config();
3013
3014         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3015 }
3016
3017 cmdline_parse_token_string_t cmd_config_burst_port =
3018         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3019 cmdline_parse_token_string_t cmd_config_burst_keyword =
3020         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3021 cmdline_parse_token_string_t cmd_config_burst_all =
3022         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3023 cmdline_parse_token_string_t cmd_config_burst_name =
3024         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3025 cmdline_parse_token_num_t cmd_config_burst_value =
3026         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3027
3028 cmdline_parse_inst_t cmd_config_burst = {
3029         .f = cmd_config_burst_parsed,
3030         .data = NULL,
3031         .help_str = "port config all burst <value>",
3032         .tokens = {
3033                 (void *)&cmd_config_burst_port,
3034                 (void *)&cmd_config_burst_keyword,
3035                 (void *)&cmd_config_burst_all,
3036                 (void *)&cmd_config_burst_name,
3037                 (void *)&cmd_config_burst_value,
3038                 NULL,
3039         },
3040 };
3041
3042 /* *** configure rx/tx queues *** */
3043 struct cmd_config_thresh {
3044         cmdline_fixed_string_t port;
3045         cmdline_fixed_string_t keyword;
3046         cmdline_fixed_string_t all;
3047         cmdline_fixed_string_t name;
3048         uint8_t value;
3049 };
3050
3051 static void
3052 cmd_config_thresh_parsed(void *parsed_result,
3053                         __attribute__((unused)) struct cmdline *cl,
3054                         __attribute__((unused)) void *data)
3055 {
3056         struct cmd_config_thresh *res = parsed_result;
3057
3058         if (!all_ports_stopped()) {
3059                 printf("Please stop all ports first\n");
3060                 return;
3061         }
3062
3063         if (!strcmp(res->name, "txpt"))
3064                 tx_pthresh = res->value;
3065         else if(!strcmp(res->name, "txht"))
3066                 tx_hthresh = res->value;
3067         else if(!strcmp(res->name, "txwt"))
3068                 tx_wthresh = res->value;
3069         else if(!strcmp(res->name, "rxpt"))
3070                 rx_pthresh = res->value;
3071         else if(!strcmp(res->name, "rxht"))
3072                 rx_hthresh = res->value;
3073         else if(!strcmp(res->name, "rxwt"))
3074                 rx_wthresh = res->value;
3075         else {
3076                 printf("Unknown parameter\n");
3077                 return;
3078         }
3079
3080         init_port_config();
3081
3082         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3083 }
3084
3085 cmdline_parse_token_string_t cmd_config_thresh_port =
3086         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3087 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3088         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3089 cmdline_parse_token_string_t cmd_config_thresh_all =
3090         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3091 cmdline_parse_token_string_t cmd_config_thresh_name =
3092         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3093                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3094 cmdline_parse_token_num_t cmd_config_thresh_value =
3095         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3096
3097 cmdline_parse_inst_t cmd_config_thresh = {
3098         .f = cmd_config_thresh_parsed,
3099         .data = NULL,
3100         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3101         .tokens = {
3102                 (void *)&cmd_config_thresh_port,
3103                 (void *)&cmd_config_thresh_keyword,
3104                 (void *)&cmd_config_thresh_all,
3105                 (void *)&cmd_config_thresh_name,
3106                 (void *)&cmd_config_thresh_value,
3107                 NULL,
3108         },
3109 };
3110
3111 /* *** configure free/rs threshold *** */
3112 struct cmd_config_threshold {
3113         cmdline_fixed_string_t port;
3114         cmdline_fixed_string_t keyword;
3115         cmdline_fixed_string_t all;
3116         cmdline_fixed_string_t name;
3117         uint16_t value;
3118 };
3119
3120 static void
3121 cmd_config_threshold_parsed(void *parsed_result,
3122                         __attribute__((unused)) struct cmdline *cl,
3123                         __attribute__((unused)) void *data)
3124 {
3125         struct cmd_config_threshold *res = parsed_result;
3126
3127         if (!all_ports_stopped()) {
3128                 printf("Please stop all ports first\n");
3129                 return;
3130         }
3131
3132         if (!strcmp(res->name, "txfreet"))
3133                 tx_free_thresh = res->value;
3134         else if (!strcmp(res->name, "txrst"))
3135                 tx_rs_thresh = res->value;
3136         else if (!strcmp(res->name, "rxfreet"))
3137                 rx_free_thresh = res->value;
3138         else {
3139                 printf("Unknown parameter\n");
3140                 return;
3141         }
3142
3143         init_port_config();
3144
3145         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3146 }
3147
3148 cmdline_parse_token_string_t cmd_config_threshold_port =
3149         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3150 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3151         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3152                                                                 "config");
3153 cmdline_parse_token_string_t cmd_config_threshold_all =
3154         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3155 cmdline_parse_token_string_t cmd_config_threshold_name =
3156         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3157                                                 "txfreet#txrst#rxfreet");
3158 cmdline_parse_token_num_t cmd_config_threshold_value =
3159         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3160
3161 cmdline_parse_inst_t cmd_config_threshold = {
3162         .f = cmd_config_threshold_parsed,
3163         .data = NULL,
3164         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3165         .tokens = {
3166                 (void *)&cmd_config_threshold_port,
3167                 (void *)&cmd_config_threshold_keyword,
3168                 (void *)&cmd_config_threshold_all,
3169                 (void *)&cmd_config_threshold_name,
3170                 (void *)&cmd_config_threshold_value,
3171                 NULL,
3172         },
3173 };
3174
3175 /* *** stop *** */
3176 struct cmd_stop_result {
3177         cmdline_fixed_string_t stop;
3178 };
3179
3180 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3181                             __attribute__((unused)) struct cmdline *cl,
3182                             __attribute__((unused)) void *data)
3183 {
3184         stop_packet_forwarding();
3185 }
3186
3187 cmdline_parse_token_string_t cmd_stop_stop =
3188         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3189
3190 cmdline_parse_inst_t cmd_stop = {
3191         .f = cmd_stop_parsed,
3192         .data = NULL,
3193         .help_str = "stop: Stop packet forwarding",
3194         .tokens = {
3195                 (void *)&cmd_stop_stop,
3196                 NULL,
3197         },
3198 };
3199
3200 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3201
3202 unsigned int
3203 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3204                 unsigned int *parsed_items, int check_unique_values)
3205 {
3206         unsigned int nb_item;
3207         unsigned int value;
3208         unsigned int i;
3209         unsigned int j;
3210         int value_ok;
3211         char c;
3212
3213         /*
3214          * First parse all items in the list and store their value.
3215          */
3216         value = 0;
3217         nb_item = 0;
3218         value_ok = 0;
3219         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3220                 c = str[i];
3221                 if ((c >= '0') && (c <= '9')) {
3222                         value = (unsigned int) (value * 10 + (c - '0'));
3223                         value_ok = 1;
3224                         continue;
3225                 }
3226                 if (c != ',') {
3227                         printf("character %c is not a decimal digit\n", c);
3228                         return 0;
3229                 }
3230                 if (! value_ok) {
3231                         printf("No valid value before comma\n");
3232                         return 0;
3233                 }
3234                 if (nb_item < max_items) {
3235                         parsed_items[nb_item] = value;
3236                         value_ok = 0;
3237                         value = 0;
3238                 }
3239                 nb_item++;
3240         }
3241         if (nb_item >= max_items) {
3242                 printf("Number of %s = %u > %u (maximum items)\n",
3243                        item_name, nb_item + 1, max_items);
3244                 return 0;
3245         }
3246         parsed_items[nb_item++] = value;
3247         if (! check_unique_values)
3248                 return nb_item;
3249
3250         /*
3251          * Then, check that all values in the list are differents.
3252          * No optimization here...
3253          */
3254         for (i = 0; i < nb_item; i++) {
3255                 for (j = i + 1; j < nb_item; j++) {
3256                         if (parsed_items[j] == parsed_items[i]) {
3257                                 printf("duplicated %s %u at index %u and %u\n",
3258                                        item_name, parsed_items[i], i, j);
3259                                 return 0;
3260                         }
3261                 }
3262         }
3263         return nb_item;
3264 }
3265
3266 struct cmd_set_list_result {
3267         cmdline_fixed_string_t cmd_keyword;
3268         cmdline_fixed_string_t list_name;
3269         cmdline_fixed_string_t list_of_items;
3270 };
3271
3272 static void cmd_set_list_parsed(void *parsed_result,
3273                                 __attribute__((unused)) struct cmdline *cl,
3274                                 __attribute__((unused)) void *data)
3275 {
3276         struct cmd_set_list_result *res;
3277         union {
3278                 unsigned int lcorelist[RTE_MAX_LCORE];
3279                 unsigned int portlist[RTE_MAX_ETHPORTS];
3280         } parsed_items;
3281         unsigned int nb_item;
3282
3283         if (test_done == 0) {
3284                 printf("Please stop forwarding first\n");
3285                 return;
3286         }
3287
3288         res = parsed_result;
3289         if (!strcmp(res->list_name, "corelist")) {
3290                 nb_item = parse_item_list(res->list_of_items, "core",
3291                                           RTE_MAX_LCORE,
3292                                           parsed_items.lcorelist, 1);
3293                 if (nb_item > 0) {
3294                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3295                         fwd_config_setup();
3296                 }
3297                 return;
3298         }
3299         if (!strcmp(res->list_name, "portlist")) {
3300                 nb_item = parse_item_list(res->list_of_items, "port",
3301                                           RTE_MAX_ETHPORTS,
3302                                           parsed_items.portlist, 1);
3303                 if (nb_item > 0) {
3304                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3305                         fwd_config_setup();
3306                 }
3307         }
3308 }
3309
3310 cmdline_parse_token_string_t cmd_set_list_keyword =
3311         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3312                                  "set");
3313 cmdline_parse_token_string_t cmd_set_list_name =
3314         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3315                                  "corelist#portlist");
3316 cmdline_parse_token_string_t cmd_set_list_of_items =
3317         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3318                                  NULL);
3319
3320 cmdline_parse_inst_t cmd_set_fwd_list = {
3321         .f = cmd_set_list_parsed,
3322         .data = NULL,
3323         .help_str = "set corelist|portlist <list0[,list1]*>",
3324         .tokens = {
3325                 (void *)&cmd_set_list_keyword,
3326                 (void *)&cmd_set_list_name,
3327                 (void *)&cmd_set_list_of_items,
3328                 NULL,
3329         },
3330 };
3331
3332 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3333
3334 struct cmd_setmask_result {
3335         cmdline_fixed_string_t set;
3336         cmdline_fixed_string_t mask;
3337         uint64_t hexavalue;
3338 };
3339
3340 static void cmd_set_mask_parsed(void *parsed_result,
3341                                 __attribute__((unused)) struct cmdline *cl,
3342                                 __attribute__((unused)) void *data)
3343 {
3344         struct cmd_setmask_result *res = parsed_result;
3345
3346         if (test_done == 0) {
3347                 printf("Please stop forwarding first\n");
3348                 return;
3349         }
3350         if (!strcmp(res->mask, "coremask")) {
3351                 set_fwd_lcores_mask(res->hexavalue);
3352                 fwd_config_setup();
3353         } else if (!strcmp(res->mask, "portmask")) {
3354                 set_fwd_ports_mask(res->hexavalue);
3355                 fwd_config_setup();
3356         }
3357 }
3358
3359 cmdline_parse_token_string_t cmd_setmask_set =
3360         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3361 cmdline_parse_token_string_t cmd_setmask_mask =
3362         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3363                                  "coremask#portmask");
3364 cmdline_parse_token_num_t cmd_setmask_value =
3365         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3366
3367 cmdline_parse_inst_t cmd_set_fwd_mask = {
3368         .f = cmd_set_mask_parsed,
3369         .data = NULL,
3370         .help_str = "set coremask|portmask <hexadecimal value>",
3371         .tokens = {
3372                 (void *)&cmd_setmask_set,
3373                 (void *)&cmd_setmask_mask,
3374                 (void *)&cmd_setmask_value,
3375                 NULL,
3376         },
3377 };
3378
3379 /*
3380  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3381  */
3382 struct cmd_set_result {
3383         cmdline_fixed_string_t set;
3384         cmdline_fixed_string_t what;
3385         uint16_t value;
3386 };
3387
3388 static void cmd_set_parsed(void *parsed_result,
3389                            __attribute__((unused)) struct cmdline *cl,
3390                            __attribute__((unused)) void *data)
3391 {
3392         struct cmd_set_result *res = parsed_result;
3393         if (!strcmp(res->what, "nbport")) {
3394                 set_fwd_ports_number(res->value);
3395                 fwd_config_setup();
3396         } else if (!strcmp(res->what, "nbcore")) {
3397                 set_fwd_lcores_number(res->value);
3398                 fwd_config_setup();
3399         } else if (!strcmp(res->what, "burst"))
3400                 set_nb_pkt_per_burst(res->value);
3401         else if (!strcmp(res->what, "verbose"))
3402                 set_verbose_level(res->value);
3403 }
3404
3405 cmdline_parse_token_string_t cmd_set_set =
3406         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3407 cmdline_parse_token_string_t cmd_set_what =
3408         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3409                                  "nbport#nbcore#burst#verbose");
3410 cmdline_parse_token_num_t cmd_set_value =
3411         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3412
3413 cmdline_parse_inst_t cmd_set_numbers = {
3414         .f = cmd_set_parsed,
3415         .data = NULL,
3416         .help_str = "set nbport|nbcore|burst|verbose <value>",
3417         .tokens = {
3418                 (void *)&cmd_set_set,
3419                 (void *)&cmd_set_what,
3420                 (void *)&cmd_set_value,
3421                 NULL,
3422         },
3423 };
3424
3425 /* *** SET LOG LEVEL CONFIGURATION *** */
3426
3427 struct cmd_set_log_result {
3428         cmdline_fixed_string_t set;
3429         cmdline_fixed_string_t log;
3430         cmdline_fixed_string_t type;
3431         uint32_t level;
3432 };
3433
3434 static void
3435 cmd_set_log_parsed(void *parsed_result,
3436                    __attribute__((unused)) struct cmdline *cl,
3437                    __attribute__((unused)) void *data)
3438 {
3439         struct cmd_set_log_result *res;
3440         int ret;
3441
3442         res = parsed_result;
3443         if (!strcmp(res->type, "global"))
3444                 rte_log_set_global_level(res->level);
3445         else {
3446                 ret = rte_log_set_level_regexp(res->type, res->level);
3447                 if (ret < 0)
3448                         printf("Unable to set log level\n");
3449         }
3450 }
3451
3452 cmdline_parse_token_string_t cmd_set_log_set =
3453         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3454 cmdline_parse_token_string_t cmd_set_log_log =
3455         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3456 cmdline_parse_token_string_t cmd_set_log_type =
3457         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3458 cmdline_parse_token_num_t cmd_set_log_level =
3459         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3460
3461 cmdline_parse_inst_t cmd_set_log = {
3462         .f = cmd_set_log_parsed,
3463         .data = NULL,
3464         .help_str = "set log global|<type> <level>",
3465         .tokens = {
3466                 (void *)&cmd_set_log_set,
3467                 (void *)&cmd_set_log_log,
3468                 (void *)&cmd_set_log_type,
3469                 (void *)&cmd_set_log_level,
3470                 NULL,
3471         },
3472 };
3473
3474 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3475
3476 struct cmd_set_txpkts_result {
3477         cmdline_fixed_string_t cmd_keyword;
3478         cmdline_fixed_string_t txpkts;
3479         cmdline_fixed_string_t seg_lengths;
3480 };
3481
3482 static void
3483 cmd_set_txpkts_parsed(void *parsed_result,
3484                       __attribute__((unused)) struct cmdline *cl,
3485                       __attribute__((unused)) void *data)
3486 {
3487         struct cmd_set_txpkts_result *res;
3488         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3489         unsigned int nb_segs;
3490
3491         res = parsed_result;
3492         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3493                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3494         if (nb_segs > 0)
3495                 set_tx_pkt_segments(seg_lengths, nb_segs);
3496 }
3497
3498 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3499         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3500                                  cmd_keyword, "set");
3501 cmdline_parse_token_string_t cmd_set_txpkts_name =
3502         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3503                                  txpkts, "txpkts");
3504 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3505         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3506                                  seg_lengths, NULL);
3507
3508 cmdline_parse_inst_t cmd_set_txpkts = {
3509         .f = cmd_set_txpkts_parsed,
3510         .data = NULL,
3511         .help_str = "set txpkts <len0[,len1]*>",
3512         .tokens = {
3513                 (void *)&cmd_set_txpkts_keyword,
3514                 (void *)&cmd_set_txpkts_name,
3515                 (void *)&cmd_set_txpkts_lengths,
3516                 NULL,
3517         },
3518 };
3519
3520 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3521
3522 struct cmd_set_txsplit_result {
3523         cmdline_fixed_string_t cmd_keyword;
3524         cmdline_fixed_string_t txsplit;
3525         cmdline_fixed_string_t mode;
3526 };
3527
3528 static void
3529 cmd_set_txsplit_parsed(void *parsed_result,
3530                       __attribute__((unused)) struct cmdline *cl,
3531                       __attribute__((unused)) void *data)
3532 {
3533         struct cmd_set_txsplit_result *res;
3534
3535         res = parsed_result;
3536         set_tx_pkt_split(res->mode);
3537 }
3538
3539 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3540         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3541                                  cmd_keyword, "set");
3542 cmdline_parse_token_string_t cmd_set_txsplit_name =
3543         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3544                                  txsplit, "txsplit");
3545 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3546         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3547                                  mode, NULL);
3548
3549 cmdline_parse_inst_t cmd_set_txsplit = {
3550         .f = cmd_set_txsplit_parsed,
3551         .data = NULL,
3552         .help_str = "set txsplit on|off|rand",
3553         .tokens = {
3554                 (void *)&cmd_set_txsplit_keyword,
3555                 (void *)&cmd_set_txsplit_name,
3556                 (void *)&cmd_set_txsplit_mode,
3557                 NULL,
3558         },
3559 };
3560
3561 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3562 struct cmd_rx_vlan_filter_all_result {
3563         cmdline_fixed_string_t rx_vlan;
3564         cmdline_fixed_string_t what;
3565         cmdline_fixed_string_t all;
3566         portid_t port_id;
3567 };
3568
3569 static void
3570 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3571                               __attribute__((unused)) struct cmdline *cl,
3572                               __attribute__((unused)) void *data)
3573 {
3574         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3575
3576         if (!strcmp(res->what, "add"))
3577                 rx_vlan_all_filter_set(res->port_id, 1);
3578         else
3579                 rx_vlan_all_filter_set(res->port_id, 0);
3580 }
3581
3582 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3583         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3584                                  rx_vlan, "rx_vlan");
3585 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3586         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3587                                  what, "add#rm");
3588 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3589         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3590                                  all, "all");
3591 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3592         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3593                               port_id, UINT16);
3594
3595 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3596         .f = cmd_rx_vlan_filter_all_parsed,
3597         .data = NULL,
3598         .help_str = "rx_vlan add|rm all <port_id>: "
3599                 "Add/Remove all identifiers to/from the set of VLAN "
3600                 "identifiers filtered by a port",
3601         .tokens = {
3602                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3603                 (void *)&cmd_rx_vlan_filter_all_what,
3604                 (void *)&cmd_rx_vlan_filter_all_all,
3605                 (void *)&cmd_rx_vlan_filter_all_portid,
3606                 NULL,
3607         },
3608 };
3609
3610 /* *** VLAN OFFLOAD SET ON A PORT *** */
3611 struct cmd_vlan_offload_result {
3612         cmdline_fixed_string_t vlan;
3613         cmdline_fixed_string_t set;
3614         cmdline_fixed_string_t vlan_type;
3615         cmdline_fixed_string_t what;
3616         cmdline_fixed_string_t on;
3617         cmdline_fixed_string_t port_id;
3618 };
3619
3620 static void
3621 cmd_vlan_offload_parsed(void *parsed_result,
3622                           __attribute__((unused)) struct cmdline *cl,
3623                           __attribute__((unused)) void *data)
3624 {
3625         int on;
3626         struct cmd_vlan_offload_result *res = parsed_result;
3627         char *str;
3628         int i, len = 0;
3629         portid_t port_id = 0;
3630         unsigned int tmp;
3631
3632         str = res->port_id;
3633         len = strnlen(str, STR_TOKEN_SIZE);
3634         i = 0;
3635         /* Get port_id first */
3636         while(i < len){
3637                 if(str[i] == ',')
3638                         break;
3639
3640                 i++;
3641         }
3642         str[i]='\0';
3643         tmp = strtoul(str, NULL, 0);
3644         /* If port_id greater that what portid_t can represent, return */
3645         if(tmp >= RTE_MAX_ETHPORTS)
3646                 return;
3647         port_id = (portid_t)tmp;
3648
3649         if (!strcmp(res->on, "on"))
3650                 on = 1;
3651         else
3652                 on = 0;
3653
3654         if (!strcmp(res->what, "strip"))
3655                 rx_vlan_strip_set(port_id,  on);
3656         else if(!strcmp(res->what, "stripq")){
3657                 uint16_t queue_id = 0;
3658
3659                 /* No queue_id, return */
3660                 if(i + 1 >= len) {
3661                         printf("must specify (port,queue_id)\n");
3662                         return;
3663                 }
3664                 tmp = strtoul(str + i + 1, NULL, 0);
3665                 /* If queue_id greater that what 16-bits can represent, return */
3666                 if(tmp > 0xffff)
3667                         return;
3668
3669                 queue_id = (uint16_t)tmp;
3670                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3671         }
3672         else if (!strcmp(res->what, "filter"))
3673                 rx_vlan_filter_set(port_id, on);
3674         else
3675                 vlan_extend_set(port_id, on);
3676
3677         return;
3678 }
3679
3680 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3681         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3682                                  vlan, "vlan");
3683 cmdline_parse_token_string_t cmd_vlan_offload_set =
3684         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3685                                  set, "set");
3686 cmdline_parse_token_string_t cmd_vlan_offload_what =
3687         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3688                                  what, "strip#filter#qinq#stripq");
3689 cmdline_parse_token_string_t cmd_vlan_offload_on =
3690         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3691                               on, "on#off");
3692 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3693         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3694                               port_id, NULL);
3695
3696 cmdline_parse_inst_t cmd_vlan_offload = {
3697         .f = cmd_vlan_offload_parsed,
3698         .data = NULL,
3699         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3700                 "<port_id[,queue_id]>: "
3701                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3702         .tokens = {
3703                 (void *)&cmd_vlan_offload_vlan,
3704                 (void *)&cmd_vlan_offload_set,
3705                 (void *)&cmd_vlan_offload_what,
3706                 (void *)&cmd_vlan_offload_on,
3707                 (void *)&cmd_vlan_offload_portid,
3708                 NULL,
3709         },
3710 };
3711
3712 /* *** VLAN TPID SET ON A PORT *** */
3713 struct cmd_vlan_tpid_result {
3714         cmdline_fixed_string_t vlan;
3715         cmdline_fixed_string_t set;
3716         cmdline_fixed_string_t vlan_type;
3717         cmdline_fixed_string_t what;
3718         uint16_t tp_id;
3719         portid_t port_id;
3720 };
3721
3722 static void
3723 cmd_vlan_tpid_parsed(void *parsed_result,
3724                           __attribute__((unused)) struct cmdline *cl,
3725                           __attribute__((unused)) void *data)
3726 {
3727         struct cmd_vlan_tpid_result *res = parsed_result;
3728         enum rte_vlan_type vlan_type;
3729
3730         if (!strcmp(res->vlan_type, "inner"))
3731                 vlan_type = ETH_VLAN_TYPE_INNER;
3732         else if (!strcmp(res->vlan_type, "outer"))
3733                 vlan_type = ETH_VLAN_TYPE_OUTER;
3734         else {
3735                 printf("Unknown vlan type\n");
3736                 return;
3737         }
3738         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3739 }
3740
3741 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3742         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3743                                  vlan, "vlan");
3744 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3745         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3746                                  set, "set");
3747 cmdline_parse_token_string_t cmd_vlan_type =
3748         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3749                                  vlan_type, "inner#outer");
3750 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3751         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3752                                  what, "tpid");
3753 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3754         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3755                               tp_id, UINT16);
3756 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3757         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3758                               port_id, UINT16);
3759
3760 cmdline_parse_inst_t cmd_vlan_tpid = {
3761         .f = cmd_vlan_tpid_parsed,
3762         .data = NULL,
3763         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3764                 "Set the VLAN Ether type",
3765         .tokens = {
3766                 (void *)&cmd_vlan_tpid_vlan,
3767                 (void *)&cmd_vlan_tpid_set,
3768                 (void *)&cmd_vlan_type,
3769                 (void *)&cmd_vlan_tpid_what,
3770                 (void *)&cmd_vlan_tpid_tpid,
3771                 (void *)&cmd_vlan_tpid_portid,
3772                 NULL,
3773         },
3774 };
3775
3776 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3777 struct cmd_rx_vlan_filter_result {
3778         cmdline_fixed_string_t rx_vlan;
3779         cmdline_fixed_string_t what;
3780         uint16_t vlan_id;
3781         portid_t port_id;
3782 };
3783
3784 static void
3785 cmd_rx_vlan_filter_parsed(void *parsed_result,
3786                           __attribute__((unused)) struct cmdline *cl,
3787                           __attribute__((unused)) void *data)
3788 {
3789         struct cmd_rx_vlan_filter_result *res = parsed_result;
3790
3791         if (!strcmp(res->what, "add"))
3792                 rx_vft_set(res->port_id, res->vlan_id, 1);
3793         else
3794                 rx_vft_set(res->port_id, res->vlan_id, 0);
3795 }
3796
3797 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3798         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3799                                  rx_vlan, "rx_vlan");
3800 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3801         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3802                                  what, "add#rm");
3803 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3804         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3805                               vlan_id, UINT16);
3806 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3807         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3808                               port_id, UINT16);
3809
3810 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3811         .f = cmd_rx_vlan_filter_parsed,
3812         .data = NULL,
3813         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3814                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3815                 "identifiers filtered by a port",
3816         .tokens = {
3817                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3818                 (void *)&cmd_rx_vlan_filter_what,
3819                 (void *)&cmd_rx_vlan_filter_vlanid,
3820                 (void *)&cmd_rx_vlan_filter_portid,
3821                 NULL,
3822         },
3823 };
3824
3825 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3826 struct cmd_tx_vlan_set_result {
3827         cmdline_fixed_string_t tx_vlan;
3828         cmdline_fixed_string_t set;
3829         portid_t port_id;
3830         uint16_t vlan_id;
3831 };
3832
3833 static void
3834 cmd_tx_vlan_set_parsed(void *parsed_result,
3835                        __attribute__((unused)) struct cmdline *cl,
3836                        __attribute__((unused)) void *data)
3837 {
3838         struct cmd_tx_vlan_set_result *res = parsed_result;
3839
3840         if (!port_is_stopped(res->port_id)) {
3841                 printf("Please stop port %d first\n", res->port_id);
3842                 return;
3843         }
3844
3845         tx_vlan_set(res->port_id, res->vlan_id);
3846
3847         cmd_reconfig_device_queue(res->port_id, 1, 1);
3848 }
3849
3850 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3851         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3852                                  tx_vlan, "tx_vlan");
3853 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3854         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3855                                  set, "set");
3856 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3857         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3858                               port_id, UINT16);
3859 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3860         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3861                               vlan_id, UINT16);
3862
3863 cmdline_parse_inst_t cmd_tx_vlan_set = {
3864         .f = cmd_tx_vlan_set_parsed,
3865         .data = NULL,
3866         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3867                 "Enable hardware insertion of a single VLAN header "
3868                 "with a given TAG Identifier in packets sent on a port",
3869         .tokens = {
3870                 (void *)&cmd_tx_vlan_set_tx_vlan,
3871                 (void *)&cmd_tx_vlan_set_set,
3872                 (void *)&cmd_tx_vlan_set_portid,
3873                 (void *)&cmd_tx_vlan_set_vlanid,
3874                 NULL,
3875         },
3876 };
3877
3878 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3879 struct cmd_tx_vlan_set_qinq_result {
3880         cmdline_fixed_string_t tx_vlan;
3881         cmdline_fixed_string_t set;
3882         portid_t port_id;
3883         uint16_t vlan_id;
3884         uint16_t vlan_id_outer;
3885 };
3886
3887 static void
3888 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3889                             __attribute__((unused)) struct cmdline *cl,
3890                             __attribute__((unused)) void *data)
3891 {
3892         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3893
3894         if (!port_is_stopped(res->port_id)) {
3895                 printf("Please stop port %d first\n", res->port_id);
3896                 return;
3897         }
3898
3899         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3900
3901         cmd_reconfig_device_queue(res->port_id, 1, 1);
3902 }
3903
3904 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3905         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3906                 tx_vlan, "tx_vlan");
3907 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3908         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3909                 set, "set");
3910 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3911         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3912                 port_id, UINT16);
3913 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3914         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3915                 vlan_id, UINT16);
3916 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3917         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3918                 vlan_id_outer, UINT16);
3919
3920 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3921         .f = cmd_tx_vlan_set_qinq_parsed,
3922         .data = NULL,
3923         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3924                 "Enable hardware insertion of double VLAN header "
3925                 "with given TAG Identifiers in packets sent on a port",
3926         .tokens = {
3927                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3928                 (void *)&cmd_tx_vlan_set_qinq_set,
3929                 (void *)&cmd_tx_vlan_set_qinq_portid,
3930                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3931                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3932                 NULL,
3933         },
3934 };
3935
3936 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3937 struct cmd_tx_vlan_set_pvid_result {
3938         cmdline_fixed_string_t tx_vlan;
3939         cmdline_fixed_string_t set;
3940         cmdline_fixed_string_t pvid;
3941         portid_t port_id;
3942         uint16_t vlan_id;
3943         cmdline_fixed_string_t mode;
3944 };
3945
3946 static void
3947 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3948                             __attribute__((unused)) struct cmdline *cl,
3949                             __attribute__((unused)) void *data)
3950 {
3951         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3952
3953         if (strcmp(res->mode, "on") == 0)
3954                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3955         else
3956                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3957 }
3958
3959 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3960         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3961                                  tx_vlan, "tx_vlan");
3962 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3963         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3964                                  set, "set");
3965 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3966         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3967                                  pvid, "pvid");
3968 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3969         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3970                              port_id, UINT16);
3971 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3972         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3973                               vlan_id, UINT16);
3974 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3975         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3976                                  mode, "on#off");
3977
3978 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3979         .f = cmd_tx_vlan_set_pvid_parsed,
3980         .data = NULL,
3981         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3982         .tokens = {
3983                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3984                 (void *)&cmd_tx_vlan_set_pvid_set,
3985                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3986                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3987                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3988                 (void *)&cmd_tx_vlan_set_pvid_mode,
3989                 NULL,
3990         },
3991 };
3992
3993 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3994 struct cmd_tx_vlan_reset_result {
3995         cmdline_fixed_string_t tx_vlan;
3996         cmdline_fixed_string_t reset;
3997         portid_t port_id;
3998 };
3999
4000 static void
4001 cmd_tx_vlan_reset_parsed(void *parsed_result,
4002                          __attribute__((unused)) struct cmdline *cl,
4003                          __attribute__((unused)) void *data)
4004 {
4005         struct cmd_tx_vlan_reset_result *res = parsed_result;
4006
4007         if (!port_is_stopped(res->port_id)) {
4008                 printf("Please stop port %d first\n", res->port_id);
4009                 return;
4010         }
4011
4012         tx_vlan_reset(res->port_id);
4013
4014         cmd_reconfig_device_queue(res->port_id, 1, 1);
4015 }
4016
4017 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4018         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4019                                  tx_vlan, "tx_vlan");
4020 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4021         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4022                                  reset, "reset");
4023 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4024         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4025                               port_id, UINT16);
4026
4027 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4028         .f = cmd_tx_vlan_reset_parsed,
4029         .data = NULL,
4030         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4031                 "VLAN header in packets sent on a port",
4032         .tokens = {
4033                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4034                 (void *)&cmd_tx_vlan_reset_reset,
4035                 (void *)&cmd_tx_vlan_reset_portid,
4036                 NULL,
4037         },
4038 };
4039
4040
4041 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4042 struct cmd_csum_result {
4043         cmdline_fixed_string_t csum;
4044         cmdline_fixed_string_t mode;
4045         cmdline_fixed_string_t proto;
4046         cmdline_fixed_string_t hwsw;
4047         portid_t port_id;
4048 };
4049
4050 static void
4051 csum_show(int port_id)
4052 {
4053         struct rte_eth_dev_info dev_info;
4054         uint64_t tx_offloads;
4055
4056         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4057         printf("Parse tunnel is %s\n",
4058                 (ports[port_id].parse_tunnel) ? "on" : "off");
4059         printf("IP checksum offload is %s\n",
4060                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4061         printf("UDP checksum offload is %s\n",
4062                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4063         printf("TCP checksum offload is %s\n",
4064                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4065         printf("SCTP checksum offload is %s\n",
4066                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4067         printf("Outer-Ip checksum offload is %s\n",
4068                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4069
4070         /* display warnings if configuration is not supported by the NIC */
4071         rte_eth_dev_info_get(port_id, &dev_info);
4072         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4073                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4074                 printf("Warning: hardware IP checksum enabled but not "
4075                         "supported by port %d\n", port_id);
4076         }
4077         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4078                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4079                 printf("Warning: hardware UDP checksum enabled but not "
4080                         "supported by port %d\n", port_id);
4081         }
4082         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4083                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4084                 printf("Warning: hardware TCP checksum enabled but not "
4085                         "supported by port %d\n", port_id);
4086         }
4087         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4088                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4089                 printf("Warning: hardware SCTP checksum enabled but not "
4090                         "supported by port %d\n", port_id);
4091         }
4092         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4093                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4094                 printf("Warning: hardware outer IP checksum enabled but not "
4095                         "supported by port %d\n", port_id);
4096         }
4097 }
4098
4099 static void
4100 cmd_csum_parsed(void *parsed_result,
4101                        __attribute__((unused)) struct cmdline *cl,
4102                        __attribute__((unused)) void *data)
4103 {
4104         struct cmd_csum_result *res = parsed_result;
4105         int hw = 0;
4106         uint64_t csum_offloads = 0;
4107         struct rte_eth_dev_info dev_info;
4108
4109         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4110                 printf("invalid port %d\n", res->port_id);
4111                 return;
4112         }
4113         if (!port_is_stopped(res->port_id)) {
4114                 printf("Please stop port %d first\n", res->port_id);
4115                 return;
4116         }
4117
4118         rte_eth_dev_info_get(res->port_id, &dev_info);
4119         if (!strcmp(res->mode, "set")) {
4120
4121                 if (!strcmp(res->hwsw, "hw"))
4122                         hw = 1;
4123
4124                 if (!strcmp(res->proto, "ip")) {
4125                         if (hw == 0 || (dev_info.tx_offload_capa &
4126                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4127                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4128                         } else {
4129                                 printf("IP checksum offload is not supported "
4130                                        "by port %u\n", res->port_id);
4131                         }
4132                 } else if (!strcmp(res->proto, "udp")) {
4133                         if (hw == 0 || (dev_info.tx_offload_capa &
4134                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4135                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4136                         } else {
4137                                 printf("UDP checksum offload is not supported "
4138                                        "by port %u\n", res->port_id);
4139                         }
4140                 } else if (!strcmp(res->proto, "tcp")) {
4141                         if (hw == 0 || (dev_info.tx_offload_capa &
4142                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4143                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4144                         } else {
4145                                 printf("TCP checksum offload is not supported "
4146                                        "by port %u\n", res->port_id);
4147                         }
4148                 } else if (!strcmp(res->proto, "sctp")) {
4149                         if (hw == 0 || (dev_info.tx_offload_capa &
4150                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4151                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4152                         } else {
4153                                 printf("SCTP checksum offload is not supported "
4154                                        "by port %u\n", res->port_id);
4155                         }
4156                 } else if (!strcmp(res->proto, "outer-ip")) {
4157                         if (hw == 0 || (dev_info.tx_offload_capa &
4158                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4159                                 csum_offloads |=
4160                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4161                         } else {
4162                                 printf("Outer IP checksum offload is not "
4163                                        "supported by port %u\n", res->port_id);
4164                         }
4165                 }
4166
4167                 if (hw) {
4168                         ports[res->port_id].dev_conf.txmode.offloads |=
4169                                                         csum_offloads;
4170                 } else {
4171                         ports[res->port_id].dev_conf.txmode.offloads &=
4172                                                         (~csum_offloads);
4173                 }
4174         }
4175         csum_show(res->port_id);
4176
4177         cmd_reconfig_device_queue(res->port_id, 1, 1);
4178 }
4179
4180 cmdline_parse_token_string_t cmd_csum_csum =
4181         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4182                                 csum, "csum");
4183 cmdline_parse_token_string_t cmd_csum_mode =
4184         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4185                                 mode, "set");
4186 cmdline_parse_token_string_t cmd_csum_proto =
4187         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4188                                 proto, "ip#tcp#udp#sctp#outer-ip");
4189 cmdline_parse_token_string_t cmd_csum_hwsw =
4190         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4191                                 hwsw, "hw#sw");
4192 cmdline_parse_token_num_t cmd_csum_portid =
4193         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4194                                 port_id, UINT16);
4195
4196 cmdline_parse_inst_t cmd_csum_set = {
4197         .f = cmd_csum_parsed,
4198         .data = NULL,
4199         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4200                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4201                 "using csum forward engine",
4202         .tokens = {
4203                 (void *)&cmd_csum_csum,
4204                 (void *)&cmd_csum_mode,
4205                 (void *)&cmd_csum_proto,
4206                 (void *)&cmd_csum_hwsw,
4207                 (void *)&cmd_csum_portid,
4208                 NULL,
4209         },
4210 };
4211
4212 cmdline_parse_token_string_t cmd_csum_mode_show =
4213         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4214                                 mode, "show");
4215
4216 cmdline_parse_inst_t cmd_csum_show = {
4217         .f = cmd_csum_parsed,
4218         .data = NULL,
4219         .help_str = "csum show <port_id>: Show checksum offload configuration",
4220         .tokens = {
4221                 (void *)&cmd_csum_csum,
4222                 (void *)&cmd_csum_mode_show,
4223                 (void *)&cmd_csum_portid,
4224                 NULL,
4225         },
4226 };
4227
4228 /* Enable/disable tunnel parsing */
4229 struct cmd_csum_tunnel_result {
4230         cmdline_fixed_string_t csum;
4231         cmdline_fixed_string_t parse;
4232         cmdline_fixed_string_t onoff;
4233         portid_t port_id;
4234 };
4235
4236 static void
4237 cmd_csum_tunnel_parsed(void *parsed_result,
4238                        __attribute__((unused)) struct cmdline *cl,
4239                        __attribute__((unused)) void *data)
4240 {
4241         struct cmd_csum_tunnel_result *res = parsed_result;
4242
4243         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4244                 return;
4245
4246         if (!strcmp(res->onoff, "on"))
4247                 ports[res->port_id].parse_tunnel = 1;
4248         else
4249                 ports[res->port_id].parse_tunnel = 0;
4250
4251         csum_show(res->port_id);
4252 }
4253
4254 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4255         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4256                                 csum, "csum");
4257 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4258         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4259                                 parse, "parse_tunnel");
4260 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4261         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4262                                 onoff, "on#off");
4263 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4264         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4265                                 port_id, UINT16);
4266
4267 cmdline_parse_inst_t cmd_csum_tunnel = {
4268         .f = cmd_csum_tunnel_parsed,
4269         .data = NULL,
4270         .help_str = "csum parse_tunnel on|off <port_id>: "
4271                 "Enable/Disable parsing of tunnels for csum engine",
4272         .tokens = {
4273                 (void *)&cmd_csum_tunnel_csum,
4274                 (void *)&cmd_csum_tunnel_parse,
4275                 (void *)&cmd_csum_tunnel_onoff,
4276                 (void *)&cmd_csum_tunnel_portid,
4277                 NULL,
4278         },
4279 };
4280
4281 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4282 struct cmd_tso_set_result {
4283         cmdline_fixed_string_t tso;
4284         cmdline_fixed_string_t mode;
4285         uint16_t tso_segsz;
4286         portid_t port_id;
4287 };
4288
4289 static void
4290 cmd_tso_set_parsed(void *parsed_result,
4291                        __attribute__((unused)) struct cmdline *cl,
4292                        __attribute__((unused)) void *data)
4293 {
4294         struct cmd_tso_set_result *res = parsed_result;
4295         struct rte_eth_dev_info dev_info;
4296
4297         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4298                 return;
4299         if (!port_is_stopped(res->port_id)) {
4300                 printf("Please stop port %d first\n", res->port_id);
4301                 return;
4302         }
4303
4304         if (!strcmp(res->mode, "set"))
4305                 ports[res->port_id].tso_segsz = res->tso_segsz;
4306
4307         rte_eth_dev_info_get(res->port_id, &dev_info);
4308         if ((ports[res->port_id].tso_segsz != 0) &&
4309                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4310                 printf("Error: TSO is not supported by port %d\n",
4311                        res->port_id);
4312                 return;
4313         }
4314
4315         if (ports[res->port_id].tso_segsz == 0) {
4316                 ports[res->port_id].dev_conf.txmode.offloads &=
4317                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4318                 printf("TSO for non-tunneled packets is disabled\n");
4319         } else {
4320                 ports[res->port_id].dev_conf.txmode.offloads |=
4321                                                 DEV_TX_OFFLOAD_TCP_TSO;
4322                 printf("TSO segment size for non-tunneled packets is %d\n",
4323                         ports[res->port_id].tso_segsz);
4324         }
4325
4326         /* display warnings if configuration is not supported by the NIC */
4327         rte_eth_dev_info_get(res->port_id, &dev_info);
4328         if ((ports[res->port_id].tso_segsz != 0) &&
4329                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4330                 printf("Warning: TSO enabled but not "
4331                         "supported by port %d\n", res->port_id);
4332         }
4333
4334         cmd_reconfig_device_queue(res->port_id, 1, 1);
4335 }
4336
4337 cmdline_parse_token_string_t cmd_tso_set_tso =
4338         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4339                                 tso, "tso");
4340 cmdline_parse_token_string_t cmd_tso_set_mode =
4341         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4342                                 mode, "set");
4343 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4344         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4345                                 tso_segsz, UINT16);
4346 cmdline_parse_token_num_t cmd_tso_set_portid =
4347         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4348                                 port_id, UINT16);
4349
4350 cmdline_parse_inst_t cmd_tso_set = {
4351         .f = cmd_tso_set_parsed,
4352         .data = NULL,
4353         .help_str = "tso set <tso_segsz> <port_id>: "
4354                 "Set TSO segment size of non-tunneled packets for csum engine "
4355                 "(0 to disable)",
4356         .tokens = {
4357                 (void *)&cmd_tso_set_tso,
4358                 (void *)&cmd_tso_set_mode,
4359                 (void *)&cmd_tso_set_tso_segsz,
4360                 (void *)&cmd_tso_set_portid,
4361                 NULL,
4362         },
4363 };
4364
4365 cmdline_parse_token_string_t cmd_tso_show_mode =
4366         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4367                                 mode, "show");
4368
4369
4370 cmdline_parse_inst_t cmd_tso_show = {
4371         .f = cmd_tso_set_parsed,
4372         .data = NULL,
4373         .help_str = "tso show <port_id>: "
4374                 "Show TSO segment size of non-tunneled packets for csum engine",
4375         .tokens = {
4376                 (void *)&cmd_tso_set_tso,
4377                 (void *)&cmd_tso_show_mode,
4378                 (void *)&cmd_tso_set_portid,
4379                 NULL,
4380         },
4381 };
4382
4383 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4384 struct cmd_tunnel_tso_set_result {
4385         cmdline_fixed_string_t tso;
4386         cmdline_fixed_string_t mode;
4387         uint16_t tso_segsz;
4388         portid_t port_id;
4389 };
4390
4391 static struct rte_eth_dev_info
4392 check_tunnel_tso_nic_support(portid_t port_id)
4393 {
4394         struct rte_eth_dev_info dev_info;
4395
4396         rte_eth_dev_info_get(port_id, &dev_info);
4397         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4398                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4399                        "not enabled for port %d\n", port_id);
4400         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4401                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4402                        "not enabled for port %d\n", port_id);
4403         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4404                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4405                        "not enabled for port %d\n", port_id);
4406         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4407                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4408                        "not enabled for port %d\n", port_id);
4409         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4410                 printf("Warning: IP TUNNEL TSO not supported therefore "
4411                        "not enabled for port %d\n", port_id);
4412         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4413                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4414                        "not enabled for port %d\n", port_id);
4415         return dev_info;
4416 }
4417
4418 static void
4419 cmd_tunnel_tso_set_parsed(void *parsed_result,
4420                           __attribute__((unused)) struct cmdline *cl,
4421                           __attribute__((unused)) void *data)
4422 {
4423         struct cmd_tunnel_tso_set_result *res = parsed_result;
4424         struct rte_eth_dev_info dev_info;
4425
4426         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4427                 return;
4428         if (!port_is_stopped(res->port_id)) {
4429                 printf("Please stop port %d first\n", res->port_id);
4430                 return;
4431         }
4432
4433         if (!strcmp(res->mode, "set"))
4434                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4435
4436         dev_info = check_tunnel_tso_nic_support(res->port_id);
4437         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4438                 ports[res->port_id].dev_conf.txmode.offloads &=
4439                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4440                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4441                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4442                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4443                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4444                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4445                 printf("TSO for tunneled packets is disabled\n");
4446         } else {
4447                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4448                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4449                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4450                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4451                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4452                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4453
4454                 ports[res->port_id].dev_conf.txmode.offloads |=
4455                         (tso_offloads & dev_info.tx_offload_capa);
4456                 printf("TSO segment size for tunneled packets is %d\n",
4457                         ports[res->port_id].tunnel_tso_segsz);
4458
4459                 /* Below conditions are needed to make it work:
4460                  * (1) tunnel TSO is supported by the NIC;
4461                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4462                  * are recognized;
4463                  * (3) for tunneled pkts with outer L3 of IPv4,
4464                  * "csum set outer-ip" must be set to hw, because after tso,
4465                  * total_len of outer IP header is changed, and the checksum
4466                  * of outer IP header calculated by sw should be wrong; that
4467                  * is not necessary for IPv6 tunneled pkts because there's no
4468                  * checksum in IP header anymore.
4469                  */
4470
4471                 if (!ports[res->port_id].parse_tunnel)
4472                         printf("Warning: csum parse_tunnel must be set "
4473                                 "so that tunneled packets are recognized\n");
4474                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4475                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4476                         printf("Warning: csum set outer-ip must be set to hw "
4477                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4478         }
4479
4480         cmd_reconfig_device_queue(res->port_id, 1, 1);
4481 }
4482
4483 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4484         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4485                                 tso, "tunnel_tso");
4486 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4487         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4488                                 mode, "set");
4489 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4490         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4491                                 tso_segsz, UINT16);
4492 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4493         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4494                                 port_id, UINT16);
4495
4496 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4497         .f = cmd_tunnel_tso_set_parsed,
4498         .data = NULL,
4499         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4500                 "Set TSO segment size of tunneled packets for csum engine "
4501                 "(0 to disable)",
4502         .tokens = {
4503                 (void *)&cmd_tunnel_tso_set_tso,
4504                 (void *)&cmd_tunnel_tso_set_mode,
4505                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4506                 (void *)&cmd_tunnel_tso_set_portid,
4507                 NULL,
4508         },
4509 };
4510
4511 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4512         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4513                                 mode, "show");
4514
4515
4516 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4517         .f = cmd_tunnel_tso_set_parsed,
4518         .data = NULL,
4519         .help_str = "tunnel_tso show <port_id> "
4520                 "Show TSO segment size of tunneled packets for csum engine",
4521         .tokens = {
4522                 (void *)&cmd_tunnel_tso_set_tso,
4523                 (void *)&cmd_tunnel_tso_show_mode,
4524                 (void *)&cmd_tunnel_tso_set_portid,
4525                 NULL,
4526         },
4527 };
4528
4529 /* *** SET GRO FOR A PORT *** */
4530 struct cmd_gro_enable_result {
4531         cmdline_fixed_string_t cmd_set;
4532         cmdline_fixed_string_t cmd_port;
4533         cmdline_fixed_string_t cmd_keyword;
4534         cmdline_fixed_string_t cmd_onoff;
4535         portid_t cmd_pid;
4536 };
4537
4538 static void
4539 cmd_gro_enable_parsed(void *parsed_result,
4540                 __attribute__((unused)) struct cmdline *cl,
4541                 __attribute__((unused)) void *data)
4542 {
4543         struct cmd_gro_enable_result *res;
4544
4545         res = parsed_result;
4546         if (!strcmp(res->cmd_keyword, "gro"))
4547                 setup_gro(res->cmd_onoff, res->cmd_pid);
4548 }
4549
4550 cmdline_parse_token_string_t cmd_gro_enable_set =
4551         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4552                         cmd_set, "set");
4553 cmdline_parse_token_string_t cmd_gro_enable_port =
4554         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4555                         cmd_keyword, "port");
4556 cmdline_parse_token_num_t cmd_gro_enable_pid =
4557         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4558                         cmd_pid, UINT16);
4559 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4560         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4561                         cmd_keyword, "gro");
4562 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4563         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4564                         cmd_onoff, "on#off");
4565
4566 cmdline_parse_inst_t cmd_gro_enable = {
4567         .f = cmd_gro_enable_parsed,
4568         .data = NULL,
4569         .help_str = "set port <port_id> gro on|off",
4570         .tokens = {
4571                 (void *)&cmd_gro_enable_set,
4572                 (void *)&cmd_gro_enable_port,
4573                 (void *)&cmd_gro_enable_pid,
4574                 (void *)&cmd_gro_enable_keyword,
4575                 (void *)&cmd_gro_enable_onoff,
4576                 NULL,
4577         },
4578 };
4579
4580 /* *** DISPLAY GRO CONFIGURATION *** */
4581 struct cmd_gro_show_result {
4582         cmdline_fixed_string_t cmd_show;
4583         cmdline_fixed_string_t cmd_port;
4584         cmdline_fixed_string_t cmd_keyword;
4585         portid_t cmd_pid;
4586 };
4587
4588 static void
4589 cmd_gro_show_parsed(void *parsed_result,
4590                 __attribute__((unused)) struct cmdline *cl,
4591                 __attribute__((unused)) void *data)
4592 {
4593         struct cmd_gro_show_result *res;
4594
4595         res = parsed_result;
4596         if (!strcmp(res->cmd_keyword, "gro"))
4597                 show_gro(res->cmd_pid);
4598 }
4599
4600 cmdline_parse_token_string_t cmd_gro_show_show =
4601         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4602                         cmd_show, "show");
4603 cmdline_parse_token_string_t cmd_gro_show_port =
4604         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4605                         cmd_port, "port");
4606 cmdline_parse_token_num_t cmd_gro_show_pid =
4607         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4608                         cmd_pid, UINT16);
4609 cmdline_parse_token_string_t cmd_gro_show_keyword =
4610         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4611                         cmd_keyword, "gro");
4612
4613 cmdline_parse_inst_t cmd_gro_show = {
4614         .f = cmd_gro_show_parsed,
4615         .data = NULL,
4616         .help_str = "show port <port_id> gro",
4617         .tokens = {
4618                 (void *)&cmd_gro_show_show,
4619                 (void *)&cmd_gro_show_port,
4620                 (void *)&cmd_gro_show_pid,
4621                 (void *)&cmd_gro_show_keyword,
4622                 NULL,
4623         },
4624 };
4625
4626 /* *** SET FLUSH CYCLES FOR GRO *** */
4627 struct cmd_gro_flush_result {
4628         cmdline_fixed_string_t cmd_set;
4629         cmdline_fixed_string_t cmd_keyword;
4630         cmdline_fixed_string_t cmd_flush;
4631         uint8_t cmd_cycles;
4632 };
4633
4634 static void
4635 cmd_gro_flush_parsed(void *parsed_result,
4636                 __attribute__((unused)) struct cmdline *cl,
4637                 __attribute__((unused)) void *data)
4638 {
4639         struct cmd_gro_flush_result *res;
4640
4641         res = parsed_result;
4642         if ((!strcmp(res->cmd_keyword, "gro")) &&
4643                         (!strcmp(res->cmd_flush, "flush")))
4644                 setup_gro_flush_cycles(res->cmd_cycles);
4645 }
4646
4647 cmdline_parse_token_string_t cmd_gro_flush_set =
4648         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4649                         cmd_set, "set");
4650 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4651         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4652                         cmd_keyword, "gro");
4653 cmdline_parse_token_string_t cmd_gro_flush_flush =
4654         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4655                         cmd_flush, "flush");
4656 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4657         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4658                         cmd_cycles, UINT8);
4659
4660 cmdline_parse_inst_t cmd_gro_flush = {
4661         .f = cmd_gro_flush_parsed,
4662         .data = NULL,
4663         .help_str = "set gro flush <cycles>",
4664         .tokens = {
4665                 (void *)&cmd_gro_flush_set,
4666                 (void *)&cmd_gro_flush_keyword,
4667                 (void *)&cmd_gro_flush_flush,
4668                 (void *)&cmd_gro_flush_cycles,
4669                 NULL,
4670         },
4671 };
4672
4673 /* *** ENABLE/DISABLE GSO *** */
4674 struct cmd_gso_enable_result {
4675         cmdline_fixed_string_t cmd_set;
4676         cmdline_fixed_string_t cmd_port;
4677         cmdline_fixed_string_t cmd_keyword;
4678         cmdline_fixed_string_t cmd_mode;
4679         portid_t cmd_pid;
4680 };
4681
4682 static void
4683 cmd_gso_enable_parsed(void *parsed_result,
4684                 __attribute__((unused)) struct cmdline *cl,
4685                 __attribute__((unused)) void *data)
4686 {
4687         struct cmd_gso_enable_result *res;
4688
4689         res = parsed_result;
4690         if (!strcmp(res->cmd_keyword, "gso"))
4691                 setup_gso(res->cmd_mode, res->cmd_pid);
4692 }
4693
4694 cmdline_parse_token_string_t cmd_gso_enable_set =
4695         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4696                         cmd_set, "set");
4697 cmdline_parse_token_string_t cmd_gso_enable_port =
4698         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4699                         cmd_port, "port");
4700 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4701         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4702                         cmd_keyword, "gso");
4703 cmdline_parse_token_string_t cmd_gso_enable_mode =
4704         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4705                         cmd_mode, "on#off");
4706 cmdline_parse_token_num_t cmd_gso_enable_pid =
4707         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4708                         cmd_pid, UINT16);
4709
4710 cmdline_parse_inst_t cmd_gso_enable = {
4711         .f = cmd_gso_enable_parsed,
4712         .data = NULL,
4713         .help_str = "set port <port_id> gso on|off",
4714         .tokens = {
4715                 (void *)&cmd_gso_enable_set,
4716                 (void *)&cmd_gso_enable_port,
4717                 (void *)&cmd_gso_enable_pid,
4718                 (void *)&cmd_gso_enable_keyword,
4719                 (void *)&cmd_gso_enable_mode,
4720                 NULL,
4721         },
4722 };
4723
4724 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4725 struct cmd_gso_size_result {
4726         cmdline_fixed_string_t cmd_set;
4727         cmdline_fixed_string_t cmd_keyword;
4728         cmdline_fixed_string_t cmd_segsz;
4729         uint16_t cmd_size;
4730 };
4731
4732 static void
4733 cmd_gso_size_parsed(void *parsed_result,
4734                        __attribute__((unused)) struct cmdline *cl,
4735                        __attribute__((unused)) void *data)
4736 {
4737         struct cmd_gso_size_result *res = parsed_result;
4738
4739         if (test_done == 0) {
4740                 printf("Before setting GSO segsz, please first"
4741                                 " stop fowarding\n");
4742                 return;
4743         }
4744
4745         if (!strcmp(res->cmd_keyword, "gso") &&
4746                         !strcmp(res->cmd_segsz, "segsz")) {
4747                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4748                         printf("gso_size should be larger than %zu."
4749                                         " Please input a legal value\n",
4750                                         RTE_GSO_SEG_SIZE_MIN);
4751                 else
4752                         gso_max_segment_size = res->cmd_size;
4753         }
4754 }
4755
4756 cmdline_parse_token_string_t cmd_gso_size_set =
4757         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4758                                 cmd_set, "set");
4759 cmdline_parse_token_string_t cmd_gso_size_keyword =
4760         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4761                                 cmd_keyword, "gso");
4762 cmdline_parse_token_string_t cmd_gso_size_segsz =
4763         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4764                                 cmd_segsz, "segsz");
4765 cmdline_parse_token_num_t cmd_gso_size_size =
4766         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4767                                 cmd_size, UINT16);
4768
4769 cmdline_parse_inst_t cmd_gso_size = {
4770         .f = cmd_gso_size_parsed,
4771         .data = NULL,
4772         .help_str = "set gso segsz <length>",
4773         .tokens = {
4774                 (void *)&cmd_gso_size_set,
4775                 (void *)&cmd_gso_size_keyword,
4776                 (void *)&cmd_gso_size_segsz,
4777                 (void *)&cmd_gso_size_size,
4778                 NULL,
4779         },
4780 };
4781
4782 /* *** SHOW GSO CONFIGURATION *** */
4783 struct cmd_gso_show_result {
4784         cmdline_fixed_string_t cmd_show;
4785         cmdline_fixed_string_t cmd_port;
4786         cmdline_fixed_string_t cmd_keyword;
4787         portid_t cmd_pid;
4788 };
4789
4790 static void
4791 cmd_gso_show_parsed(void *parsed_result,
4792                        __attribute__((unused)) struct cmdline *cl,
4793                        __attribute__((unused)) void *data)
4794 {
4795         struct cmd_gso_show_result *res = parsed_result;
4796
4797         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4798                 printf("invalid port id %u\n", res->cmd_pid);
4799                 return;
4800         }
4801         if (!strcmp(res->cmd_keyword, "gso")) {
4802                 if (gso_ports[res->cmd_pid].enable) {
4803                         printf("Max GSO'd packet size: %uB\n"
4804                                         "Supported GSO types: TCP/IPv4, "
4805                                         "VxLAN with inner TCP/IPv4 packet, "
4806                                         "GRE with inner TCP/IPv4  packet\n",
4807                                         gso_max_segment_size);
4808                 } else
4809                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4810         }
4811 }
4812
4813 cmdline_parse_token_string_t cmd_gso_show_show =
4814 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4815                 cmd_show, "show");
4816 cmdline_parse_token_string_t cmd_gso_show_port =
4817 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4818                 cmd_port, "port");
4819 cmdline_parse_token_string_t cmd_gso_show_keyword =
4820         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4821                                 cmd_keyword, "gso");
4822 cmdline_parse_token_num_t cmd_gso_show_pid =
4823         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4824                                 cmd_pid, UINT16);
4825
4826 cmdline_parse_inst_t cmd_gso_show = {
4827         .f = cmd_gso_show_parsed,
4828         .data = NULL,
4829         .help_str = "show port <port_id> gso",
4830         .tokens = {
4831                 (void *)&cmd_gso_show_show,
4832                 (void *)&cmd_gso_show_port,
4833                 (void *)&cmd_gso_show_pid,
4834                 (void *)&cmd_gso_show_keyword,
4835                 NULL,
4836         },
4837 };
4838
4839 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4840 struct cmd_set_flush_rx {
4841         cmdline_fixed_string_t set;
4842         cmdline_fixed_string_t flush_rx;
4843         cmdline_fixed_string_t mode;
4844 };
4845
4846 static void
4847 cmd_set_flush_rx_parsed(void *parsed_result,
4848                 __attribute__((unused)) struct cmdline *cl,
4849                 __attribute__((unused)) void *data)
4850 {
4851         struct cmd_set_flush_rx *res = parsed_result;
4852         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4853 }
4854
4855 cmdline_parse_token_string_t cmd_setflushrx_set =
4856         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4857                         set, "set");
4858 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4859         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4860                         flush_rx, "flush_rx");
4861 cmdline_parse_token_string_t cmd_setflushrx_mode =
4862         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4863                         mode, "on#off");
4864
4865
4866 cmdline_parse_inst_t cmd_set_flush_rx = {
4867         .f = cmd_set_flush_rx_parsed,
4868         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4869         .data = NULL,
4870         .tokens = {
4871                 (void *)&cmd_setflushrx_set,
4872                 (void *)&cmd_setflushrx_flush_rx,
4873                 (void *)&cmd_setflushrx_mode,
4874                 NULL,
4875         },
4876 };
4877
4878 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4879 struct cmd_set_link_check {
4880         cmdline_fixed_string_t set;
4881         cmdline_fixed_string_t link_check;
4882         cmdline_fixed_string_t mode;
4883 };
4884
4885 static void
4886 cmd_set_link_check_parsed(void *parsed_result,
4887                 __attribute__((unused)) struct cmdline *cl,
4888                 __attribute__((unused)) void *data)
4889 {
4890         struct cmd_set_link_check *res = parsed_result;
4891         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4892 }
4893
4894 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4895         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4896                         set, "set");
4897 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4898         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4899                         link_check, "link_check");
4900 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4901         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4902                         mode, "on#off");
4903
4904
4905 cmdline_parse_inst_t cmd_set_link_check = {
4906         .f = cmd_set_link_check_parsed,
4907         .help_str = "set link_check on|off: Enable/Disable link status check "
4908                     "when starting/stopping a port",
4909         .data = NULL,
4910         .tokens = {
4911                 (void *)&cmd_setlinkcheck_set,
4912                 (void *)&cmd_setlinkcheck_link_check,
4913                 (void *)&cmd_setlinkcheck_mode,
4914                 NULL,
4915         },
4916 };
4917
4918 /* *** SET NIC BYPASS MODE *** */
4919 struct cmd_set_bypass_mode_result {
4920         cmdline_fixed_string_t set;
4921         cmdline_fixed_string_t bypass;
4922         cmdline_fixed_string_t mode;
4923         cmdline_fixed_string_t value;
4924         portid_t port_id;
4925 };
4926
4927 static void
4928 cmd_set_bypass_mode_parsed(void *parsed_result,
4929                 __attribute__((unused)) struct cmdline *cl,
4930                 __attribute__((unused)) void *data)
4931 {
4932         struct cmd_set_bypass_mode_result *res = parsed_result;
4933         portid_t port_id = res->port_id;
4934         int32_t rc = -EINVAL;
4935
4936 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4937         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4938
4939         if (!strcmp(res->value, "bypass"))
4940                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4941         else if (!strcmp(res->value, "isolate"))
4942                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4943         else
4944                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4945
4946         /* Set the bypass mode for the relevant port. */
4947         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4948 #endif
4949         if (rc != 0)
4950                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4951 }
4952
4953 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4954         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4955                         set, "set");
4956 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4957         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4958                         bypass, "bypass");
4959 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4960         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4961                         mode, "mode");
4962 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4963         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4964                         value, "normal#bypass#isolate");
4965 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4966         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4967                                 port_id, UINT16);
4968
4969 cmdline_parse_inst_t cmd_set_bypass_mode = {
4970         .f = cmd_set_bypass_mode_parsed,
4971         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4972                     "Set the NIC bypass mode for port_id",
4973         .data = NULL,
4974         .tokens = {
4975                 (void *)&cmd_setbypass_mode_set,
4976                 (void *)&cmd_setbypass_mode_bypass,
4977                 (void *)&cmd_setbypass_mode_mode,
4978                 (void *)&cmd_setbypass_mode_value,
4979                 (void *)&cmd_setbypass_mode_port,
4980                 NULL,
4981         },
4982 };
4983
4984 /* *** SET NIC BYPASS EVENT *** */
4985 struct cmd_set_bypass_event_result {
4986         cmdline_fixed_string_t set;
4987         cmdline_fixed_string_t bypass;
4988         cmdline_fixed_string_t event;
4989         cmdline_fixed_string_t event_value;
4990         cmdline_fixed_string_t mode;
4991         cmdline_fixed_string_t mode_value;
4992         portid_t port_id;
4993 };
4994
4995 static void
4996 cmd_set_bypass_event_parsed(void *parsed_result,
4997                 __attribute__((unused)) struct cmdline *cl,
4998                 __attribute__((unused)) void *data)
4999 {
5000         int32_t rc = -EINVAL;
5001         struct cmd_set_bypass_event_result *res = parsed_result;
5002         portid_t port_id = res->port_id;
5003
5004 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5005         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5006         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5007
5008         if (!strcmp(res->event_value, "timeout"))
5009                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5010         else if (!strcmp(res->event_value, "os_on"))
5011                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5012         else if (!strcmp(res->event_value, "os_off"))
5013                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5014         else if (!strcmp(res->event_value, "power_on"))
5015                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5016         else if (!strcmp(res->event_value, "power_off"))
5017                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5018         else
5019                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5020
5021         if (!strcmp(res->mode_value, "bypass"))
5022                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5023         else if (!strcmp(res->mode_value, "isolate"))
5024                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5025         else
5026                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5027
5028         /* Set the watchdog timeout. */
5029         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5030
5031                 rc = -EINVAL;
5032                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5033                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5034                                                            bypass_timeout);
5035                 }
5036                 if (rc != 0) {
5037                         printf("Failed to set timeout value %u "
5038                         "for port %d, errto code: %d.\n",
5039                         bypass_timeout, port_id, rc);
5040                 }
5041         }
5042
5043         /* Set the bypass event to transition to bypass mode. */
5044         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5045                                               bypass_mode);
5046 #endif
5047
5048         if (rc != 0)
5049                 printf("\t Failed to set bypass event for port = %d.\n",
5050                        port_id);
5051 }
5052
5053 cmdline_parse_token_string_t cmd_setbypass_event_set =
5054         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5055                         set, "set");
5056 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5057         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5058                         bypass, "bypass");
5059 cmdline_parse_token_string_t cmd_setbypass_event_event =
5060         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5061                         event, "event");
5062 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5063         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5064                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5065 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5066         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5067                         mode, "mode");
5068 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5069         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5070                         mode_value, "normal#bypass#isolate");
5071 cmdline_parse_token_num_t cmd_setbypass_event_port =
5072         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5073                                 port_id, UINT16);
5074
5075 cmdline_parse_inst_t cmd_set_bypass_event = {
5076         .f = cmd_set_bypass_event_parsed,
5077         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5078                 "power_off mode normal|bypass|isolate <port_id>: "
5079                 "Set the NIC bypass event mode for port_id",
5080         .data = NULL,
5081         .tokens = {
5082                 (void *)&cmd_setbypass_event_set,
5083                 (void *)&cmd_setbypass_event_bypass,
5084                 (void *)&cmd_setbypass_event_event,
5085                 (void *)&cmd_setbypass_event_event_value,
5086                 (void *)&cmd_setbypass_event_mode,
5087                 (void *)&cmd_setbypass_event_mode_value,
5088                 (void *)&cmd_setbypass_event_port,
5089                 NULL,
5090         },
5091 };
5092
5093
5094 /* *** SET NIC BYPASS TIMEOUT *** */
5095 struct cmd_set_bypass_timeout_result {
5096         cmdline_fixed_string_t set;
5097         cmdline_fixed_string_t bypass;
5098         cmdline_fixed_string_t timeout;
5099         cmdline_fixed_string_t value;
5100 };
5101
5102 static void
5103 cmd_set_bypass_timeout_parsed(void *parsed_result,
5104                 __attribute__((unused)) struct cmdline *cl,
5105                 __attribute__((unused)) void *data)
5106 {
5107         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5108
5109 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5110         if (!strcmp(res->value, "1.5"))
5111                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5112         else if (!strcmp(res->value, "2"))
5113                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5114         else if (!strcmp(res->value, "3"))
5115                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5116         else if (!strcmp(res->value, "4"))
5117                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5118         else if (!strcmp(res->value, "8"))
5119                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5120         else if (!strcmp(res->value, "16"))
5121                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5122         else if (!strcmp(res->value, "32"))
5123                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5124         else
5125                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5126 #endif
5127 }
5128
5129 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5130         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5131                         set, "set");
5132 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5133         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5134                         bypass, "bypass");
5135 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5136         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5137                         timeout, "timeout");
5138 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5139         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5140                         value, "0#1.5#2#3#4#8#16#32");
5141
5142 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5143         .f = cmd_set_bypass_timeout_parsed,
5144         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5145                 "Set the NIC bypass watchdog timeout in seconds",
5146         .data = NULL,
5147         .tokens = {
5148                 (void *)&cmd_setbypass_timeout_set,
5149                 (void *)&cmd_setbypass_timeout_bypass,
5150                 (void *)&cmd_setbypass_timeout_timeout,
5151                 (void *)&cmd_setbypass_timeout_value,
5152                 NULL,
5153         },
5154 };
5155
5156 /* *** SHOW NIC BYPASS MODE *** */
5157 struct cmd_show_bypass_config_result {
5158         cmdline_fixed_string_t show;
5159         cmdline_fixed_string_t bypass;
5160         cmdline_fixed_string_t config;
5161         portid_t port_id;
5162 };
5163
5164 static void
5165 cmd_show_bypass_config_parsed(void *parsed_result,
5166                 __attribute__((unused)) struct cmdline *cl,
5167                 __attribute__((unused)) void *data)
5168 {
5169         struct cmd_show_bypass_config_result *res = parsed_result;
5170         portid_t port_id = res->port_id;
5171         int rc = -EINVAL;
5172 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5173         uint32_t event_mode;
5174         uint32_t bypass_mode;
5175         uint32_t timeout = bypass_timeout;
5176         int i;
5177
5178         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5179                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5180         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5181                 {"UNKNOWN", "normal", "bypass", "isolate"};
5182         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5183                 "NONE",
5184                 "OS/board on",
5185                 "power supply on",
5186                 "OS/board off",
5187                 "power supply off",
5188                 "timeout"};
5189         int num_events = (sizeof events) / (sizeof events[0]);
5190
5191         /* Display the bypass mode.*/
5192         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5193                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5194                 return;
5195         }
5196         else {
5197                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5198                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5199
5200                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5201         }
5202
5203         /* Display the bypass timeout.*/
5204         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5205                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5206
5207         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5208
5209         /* Display the bypass events and associated modes. */
5210         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5211
5212                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5213                         printf("\tFailed to get bypass mode for event = %s\n",
5214                                 events[i]);
5215                 } else {
5216                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5217                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5218
5219                         printf("\tbypass event: %-16s = %s\n", events[i],
5220                                 modes[event_mode]);
5221                 }
5222         }
5223 #endif
5224         if (rc != 0)
5225                 printf("\tFailed to get bypass configuration for port = %d\n",
5226                        port_id);
5227 }
5228
5229 cmdline_parse_token_string_t cmd_showbypass_config_show =
5230         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5231                         show, "show");
5232 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5233         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5234                         bypass, "bypass");
5235 cmdline_parse_token_string_t cmd_showbypass_config_config =
5236         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5237                         config, "config");
5238 cmdline_parse_token_num_t cmd_showbypass_config_port =
5239         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5240                                 port_id, UINT16);
5241
5242 cmdline_parse_inst_t cmd_show_bypass_config = {
5243         .f = cmd_show_bypass_config_parsed,
5244         .help_str = "show bypass config <port_id>: "
5245                     "Show the NIC bypass config for port_id",
5246         .data = NULL,
5247         .tokens = {
5248                 (void *)&cmd_showbypass_config_show,
5249                 (void *)&cmd_showbypass_config_bypass,
5250                 (void *)&cmd_showbypass_config_config,
5251                 (void *)&cmd_showbypass_config_port,
5252                 NULL,
5253         },
5254 };
5255
5256 #ifdef RTE_LIBRTE_PMD_BOND
5257 /* *** SET BONDING MODE *** */
5258 struct cmd_set_bonding_mode_result {
5259         cmdline_fixed_string_t set;
5260         cmdline_fixed_string_t bonding;
5261         cmdline_fixed_string_t mode;
5262         uint8_t value;
5263         portid_t port_id;
5264 };
5265
5266 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5267                 __attribute__((unused))  struct cmdline *cl,
5268                 __attribute__((unused)) void *data)
5269 {
5270         struct cmd_set_bonding_mode_result *res = parsed_result;
5271         portid_t port_id = res->port_id;
5272
5273         /* Set the bonding mode for the relevant port. */
5274         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5275                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5276 }
5277
5278 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5279 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5280                 set, "set");
5281 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5282 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5283                 bonding, "bonding");
5284 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5285 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5286                 mode, "mode");
5287 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5288 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5289                 value, UINT8);
5290 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5291 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5292                 port_id, UINT16);
5293
5294 cmdline_parse_inst_t cmd_set_bonding_mode = {
5295                 .f = cmd_set_bonding_mode_parsed,
5296                 .help_str = "set bonding mode <mode_value> <port_id>: "
5297                         "Set the bonding mode for port_id",
5298                 .data = NULL,
5299                 .tokens = {
5300                                 (void *) &cmd_setbonding_mode_set,
5301                                 (void *) &cmd_setbonding_mode_bonding,
5302                                 (void *) &cmd_setbonding_mode_mode,
5303                                 (void *) &cmd_setbonding_mode_value,
5304                                 (void *) &cmd_setbonding_mode_port,
5305                                 NULL
5306                 }
5307 };
5308
5309 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5310 struct cmd_set_bonding_lacp_dedicated_queues_result {
5311         cmdline_fixed_string_t set;
5312         cmdline_fixed_string_t bonding;
5313         cmdline_fixed_string_t lacp;
5314         cmdline_fixed_string_t dedicated_queues;
5315         portid_t port_id;
5316         cmdline_fixed_string_t mode;
5317 };
5318
5319 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5320                 __attribute__((unused))  struct cmdline *cl,
5321                 __attribute__((unused)) void *data)
5322 {
5323         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5324         portid_t port_id = res->port_id;
5325         struct rte_port *port;
5326
5327         port = &ports[port_id];
5328
5329         /** Check if the port is not started **/
5330         if (port->port_status != RTE_PORT_STOPPED) {
5331                 printf("Please stop port %d first\n", port_id);
5332                 return;
5333         }
5334
5335         if (!strcmp(res->mode, "enable")) {
5336                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5337                         printf("Dedicate queues for LACP control packets"
5338                                         " enabled\n");
5339                 else
5340                         printf("Enabling dedicate queues for LACP control "
5341                                         "packets on port %d failed\n", port_id);
5342         } else if (!strcmp(res->mode, "disable")) {
5343                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5344                         printf("Dedicated queues for LACP control packets "
5345                                         "disabled\n");
5346                 else
5347                         printf("Disabling dedicated queues for LACP control "
5348                                         "traffic on port %d failed\n", port_id);
5349         }
5350 }
5351
5352 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5353 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5354                 set, "set");
5355 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5356 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5357                 bonding, "bonding");
5358 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5359 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5360                 lacp, "lacp");
5361 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5362 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5363                 dedicated_queues, "dedicated_queues");
5364 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5365 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5366                 port_id, UINT16);
5367 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5368 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5369                 mode, "enable#disable");
5370
5371 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5372                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5373                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5374                         "enable|disable: "
5375                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5376                 .data = NULL,
5377                 .tokens = {
5378                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5379                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5380                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5381                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5382                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5383                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5384                         NULL
5385                 }
5386 };
5387
5388 /* *** SET BALANCE XMIT POLICY *** */
5389 struct cmd_set_bonding_balance_xmit_policy_result {
5390         cmdline_fixed_string_t set;
5391         cmdline_fixed_string_t bonding;
5392         cmdline_fixed_string_t balance_xmit_policy;
5393         portid_t port_id;
5394         cmdline_fixed_string_t policy;
5395 };
5396
5397 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5398                 __attribute__((unused))  struct cmdline *cl,
5399                 __attribute__((unused)) void *data)
5400 {
5401         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5402         portid_t port_id = res->port_id;
5403         uint8_t policy;
5404
5405         if (!strcmp(res->policy, "l2")) {
5406                 policy = BALANCE_XMIT_POLICY_LAYER2;
5407         } else if (!strcmp(res->policy, "l23")) {
5408                 policy = BALANCE_XMIT_POLICY_LAYER23;
5409         } else if (!strcmp(res->policy, "l34")) {
5410                 policy = BALANCE_XMIT_POLICY_LAYER34;
5411         } else {
5412                 printf("\t Invalid xmit policy selection");
5413                 return;
5414         }
5415
5416         /* Set the bonding mode for the relevant port. */
5417         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5418                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5419                                 port_id);
5420         }
5421 }
5422
5423 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5424 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5425                 set, "set");
5426 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5427 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5428                 bonding, "bonding");
5429 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5430 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5431                 balance_xmit_policy, "balance_xmit_policy");
5432 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5433 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5434                 port_id, UINT16);
5435 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5436 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5437                 policy, "l2#l23#l34");
5438
5439 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5440                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5441                 .help_str = "set bonding balance_xmit_policy <port_id> "
5442                         "l2|l23|l34: "
5443                         "Set the bonding balance_xmit_policy for port_id",
5444                 .data = NULL,
5445                 .tokens = {
5446                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5447                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5448                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5449                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5450                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5451                                 NULL
5452                 }
5453 };
5454
5455 /* *** SHOW NIC BONDING CONFIGURATION *** */
5456 struct cmd_show_bonding_config_result {
5457         cmdline_fixed_string_t show;
5458         cmdline_fixed_string_t bonding;
5459         cmdline_fixed_string_t config;
5460         portid_t port_id;
5461 };
5462
5463 static void cmd_show_bonding_config_parsed(void *parsed_result,
5464                 __attribute__((unused))  struct cmdline *cl,
5465                 __attribute__((unused)) void *data)
5466 {
5467         struct cmd_show_bonding_config_result *res = parsed_result;
5468         int bonding_mode, agg_mode;
5469         portid_t slaves[RTE_MAX_ETHPORTS];
5470         int num_slaves, num_active_slaves;
5471         int primary_id;
5472         int i;
5473         portid_t port_id = res->port_id;
5474
5475         /* Display the bonding mode.*/
5476         bonding_mode = rte_eth_bond_mode_get(port_id);
5477         if (bonding_mode < 0) {
5478                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5479                 return;
5480         } else
5481                 printf("\tBonding mode: %d\n", bonding_mode);
5482
5483         if (bonding_mode == BONDING_MODE_BALANCE) {
5484                 int balance_xmit_policy;
5485
5486                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5487                 if (balance_xmit_policy < 0) {
5488                         printf("\tFailed to get balance xmit policy for port = %d\n",
5489                                         port_id);
5490                         return;
5491                 } else {
5492                         printf("\tBalance Xmit Policy: ");
5493
5494                         switch (balance_xmit_policy) {
5495                         case BALANCE_XMIT_POLICY_LAYER2:
5496                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5497                                 break;
5498                         case BALANCE_XMIT_POLICY_LAYER23:
5499                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5500                                 break;
5501                         case BALANCE_XMIT_POLICY_LAYER34:
5502                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5503                                 break;
5504                         }
5505                         printf("\n");
5506                 }
5507         }
5508
5509         if (bonding_mode == BONDING_MODE_8023AD) {
5510                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5511                 printf("\tIEEE802.3AD Aggregator Mode: ");
5512                 switch (agg_mode) {
5513                 case AGG_BANDWIDTH:
5514                         printf("bandwidth");
5515                         break;
5516                 case AGG_STABLE:
5517                         printf("stable");
5518                         break;
5519                 case AGG_COUNT:
5520                         printf("count");
5521                         break;
5522                 }
5523                 printf("\n");
5524         }
5525
5526         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5527
5528         if (num_slaves < 0) {
5529                 printf("\tFailed to get slave list for port = %d\n", port_id);
5530                 return;
5531         }
5532         if (num_slaves > 0) {
5533                 printf("\tSlaves (%d): [", num_slaves);
5534                 for (i = 0; i < num_slaves - 1; i++)
5535                         printf("%d ", slaves[i]);
5536
5537                 printf("%d]\n", slaves[num_slaves - 1]);
5538         } else {
5539                 printf("\tSlaves: []\n");
5540
5541         }
5542
5543         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5544                         RTE_MAX_ETHPORTS);
5545
5546         if (num_active_slaves < 0) {
5547                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5548                 return;
5549         }
5550         if (num_active_slaves > 0) {
5551                 printf("\tActive Slaves (%d): [", num_active_slaves);
5552                 for (i = 0; i < num_active_slaves - 1; i++)
5553                         printf("%d ", slaves[i]);
5554
5555                 printf("%d]\n", slaves[num_active_slaves - 1]);
5556
5557         } else {
5558                 printf("\tActive Slaves: []\n");
5559
5560         }
5561
5562         primary_id = rte_eth_bond_primary_get(port_id);
5563         if (primary_id < 0) {
5564                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5565                 return;
5566         } else
5567                 printf("\tPrimary: [%d]\n", primary_id);
5568
5569 }
5570
5571 cmdline_parse_token_string_t cmd_showbonding_config_show =
5572 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5573                 show, "show");
5574 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5575 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5576                 bonding, "bonding");
5577 cmdline_parse_token_string_t cmd_showbonding_config_config =
5578 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5579                 config, "config");
5580 cmdline_parse_token_num_t cmd_showbonding_config_port =
5581 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5582                 port_id, UINT16);
5583
5584 cmdline_parse_inst_t cmd_show_bonding_config = {
5585                 .f = cmd_show_bonding_config_parsed,
5586                 .help_str = "show bonding config <port_id>: "
5587                         "Show the bonding config for port_id",
5588                 .data = NULL,
5589                 .tokens = {
5590                                 (void *)&cmd_showbonding_config_show,
5591                                 (void *)&cmd_showbonding_config_bonding,
5592                                 (void *)&cmd_showbonding_config_config,
5593                                 (void *)&cmd_showbonding_config_port,
5594                                 NULL
5595                 }
5596 };
5597
5598 /* *** SET BONDING PRIMARY *** */
5599 struct cmd_set_bonding_primary_result {
5600         cmdline_fixed_string_t set;
5601         cmdline_fixed_string_t bonding;
5602         cmdline_fixed_string_t primary;
5603         portid_t slave_id;
5604         portid_t port_id;
5605 };
5606
5607 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5608                 __attribute__((unused))  struct cmdline *cl,
5609                 __attribute__((unused)) void *data)
5610 {
5611         struct cmd_set_bonding_primary_result *res = parsed_result;
5612         portid_t master_port_id = res->port_id;
5613         portid_t slave_port_id = res->slave_id;
5614
5615         /* Set the primary slave for a bonded device. */
5616         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5617                 printf("\t Failed to set primary slave for port = %d.\n",
5618                                 master_port_id);
5619                 return;
5620         }
5621         init_port_config();
5622 }
5623
5624 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5625 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5626                 set, "set");
5627 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5628 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5629                 bonding, "bonding");
5630 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5631 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5632                 primary, "primary");
5633 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5634 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5635                 slave_id, UINT16);
5636 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5637 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5638                 port_id, UINT16);
5639
5640 cmdline_parse_inst_t cmd_set_bonding_primary = {
5641                 .f = cmd_set_bonding_primary_parsed,
5642                 .help_str = "set bonding primary <slave_id> <port_id>: "
5643                         "Set the primary slave for port_id",
5644                 .data = NULL,
5645                 .tokens = {
5646                                 (void *)&cmd_setbonding_primary_set,
5647                                 (void *)&cmd_setbonding_primary_bonding,
5648                                 (void *)&cmd_setbonding_primary_primary,
5649                                 (void *)&cmd_setbonding_primary_slave,
5650                                 (void *)&cmd_setbonding_primary_port,
5651                                 NULL
5652                 }
5653 };
5654
5655 /* *** ADD SLAVE *** */
5656 struct cmd_add_bonding_slave_result {
5657         cmdline_fixed_string_t add;
5658         cmdline_fixed_string_t bonding;
5659         cmdline_fixed_string_t slave;
5660         portid_t slave_id;
5661         portid_t port_id;
5662 };
5663
5664 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5665                 __attribute__((unused))  struct cmdline *cl,
5666                 __attribute__((unused)) void *data)
5667 {
5668         struct cmd_add_bonding_slave_result *res = parsed_result;
5669         portid_t master_port_id = res->port_id;
5670         portid_t slave_port_id = res->slave_id;
5671
5672         /* add the slave for a bonded device. */
5673         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5674                 printf("\t Failed to add slave %d to master port = %d.\n",
5675                                 slave_port_id, master_port_id);
5676                 return;
5677         }
5678         init_port_config();
5679         set_port_slave_flag(slave_port_id);
5680 }
5681
5682 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5683 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5684                 add, "add");
5685 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5686 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5687                 bonding, "bonding");
5688 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5689 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5690                 slave, "slave");
5691 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5692 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5693                 slave_id, UINT16);
5694 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5695 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5696                 port_id, UINT16);
5697
5698 cmdline_parse_inst_t cmd_add_bonding_slave = {
5699                 .f = cmd_add_bonding_slave_parsed,
5700                 .help_str = "add bonding slave <slave_id> <port_id>: "
5701                         "Add a slave device to a bonded device",
5702                 .data = NULL,
5703                 .tokens = {
5704                                 (void *)&cmd_addbonding_slave_add,
5705                                 (void *)&cmd_addbonding_slave_bonding,
5706                                 (void *)&cmd_addbonding_slave_slave,
5707                                 (void *)&cmd_addbonding_slave_slaveid,
5708                                 (void *)&cmd_addbonding_slave_port,
5709                                 NULL
5710                 }
5711 };
5712
5713 /* *** REMOVE SLAVE *** */
5714 struct cmd_remove_bonding_slave_result {
5715         cmdline_fixed_string_t remove;
5716         cmdline_fixed_string_t bonding;
5717         cmdline_fixed_string_t slave;
5718         portid_t slave_id;
5719         portid_t port_id;
5720 };
5721
5722 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5723                 __attribute__((unused))  struct cmdline *cl,
5724                 __attribute__((unused)) void *data)
5725 {
5726         struct cmd_remove_bonding_slave_result *res = parsed_result;
5727         portid_t master_port_id = res->port_id;
5728         portid_t slave_port_id = res->slave_id;
5729
5730         /* remove the slave from a bonded device. */
5731         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5732                 printf("\t Failed to remove slave %d from master port = %d.\n",
5733                                 slave_port_id, master_port_id);
5734                 return;
5735         }
5736         init_port_config();
5737         clear_port_slave_flag(slave_port_id);
5738 }
5739
5740 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5741                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5742                                 remove, "remove");
5743 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5744                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5745                                 bonding, "bonding");
5746 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5747                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5748                                 slave, "slave");
5749 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5750                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5751                                 slave_id, UINT16);
5752 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5753                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5754                                 port_id, UINT16);
5755
5756 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5757                 .f = cmd_remove_bonding_slave_parsed,
5758                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5759                         "Remove a slave device from a bonded device",
5760                 .data = NULL,
5761                 .tokens = {
5762                                 (void *)&cmd_removebonding_slave_remove,
5763                                 (void *)&cmd_removebonding_slave_bonding,
5764                                 (void *)&cmd_removebonding_slave_slave,
5765                                 (void *)&cmd_removebonding_slave_slaveid,
5766                                 (void *)&cmd_removebonding_slave_port,
5767                                 NULL
5768                 }
5769 };
5770
5771 /* *** CREATE BONDED DEVICE *** */
5772 struct cmd_create_bonded_device_result {
5773         cmdline_fixed_string_t create;
5774         cmdline_fixed_string_t bonded;
5775         cmdline_fixed_string_t device;
5776         uint8_t mode;
5777         uint8_t socket;
5778 };
5779
5780 static int bond_dev_num = 0;
5781
5782 static void cmd_create_bonded_device_parsed(void *parsed_result,
5783                 __attribute__((unused))  struct cmdline *cl,
5784                 __attribute__((unused)) void *data)
5785 {
5786         struct cmd_create_bonded_device_result *res = parsed_result;
5787         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5788         int port_id;
5789
5790         if (test_done == 0) {
5791                 printf("Please stop forwarding first\n");
5792                 return;
5793         }
5794
5795         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5796                         bond_dev_num++);
5797
5798         /* Create a new bonded device. */
5799         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5800         if (port_id < 0) {
5801                 printf("\t Failed to create bonded device.\n");
5802                 return;
5803         } else {
5804                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5805                                 port_id);
5806
5807                 /* Update number of ports */
5808                 nb_ports = rte_eth_dev_count_avail();
5809                 reconfig(port_id, res->socket);
5810                 rte_eth_promiscuous_enable(port_id);
5811         }
5812
5813 }
5814
5815 cmdline_parse_token_string_t cmd_createbonded_device_create =
5816                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5817                                 create, "create");
5818 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5819                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5820                                 bonded, "bonded");
5821 cmdline_parse_token_string_t cmd_createbonded_device_device =
5822                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5823                                 device, "device");
5824 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5825                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5826                                 mode, UINT8);
5827 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5828                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5829                                 socket, UINT8);
5830
5831 cmdline_parse_inst_t cmd_create_bonded_device = {
5832                 .f = cmd_create_bonded_device_parsed,
5833                 .help_str = "create bonded device <mode> <socket>: "
5834                         "Create a new bonded device with specific bonding mode and socket",
5835                 .data = NULL,
5836                 .tokens = {
5837                                 (void *)&cmd_createbonded_device_create,
5838                                 (void *)&cmd_createbonded_device_bonded,
5839                                 (void *)&cmd_createbonded_device_device,
5840                                 (void *)&cmd_createbonded_device_mode,
5841                                 (void *)&cmd_createbonded_device_socket,
5842                                 NULL
5843                 }
5844 };
5845
5846 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5847 struct cmd_set_bond_mac_addr_result {
5848         cmdline_fixed_string_t set;
5849         cmdline_fixed_string_t bonding;
5850         cmdline_fixed_string_t mac_addr;
5851         uint16_t port_num;
5852         struct ether_addr address;
5853 };
5854
5855 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5856                 __attribute__((unused))  struct cmdline *cl,
5857                 __attribute__((unused)) void *data)
5858 {
5859         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5860         int ret;
5861
5862         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5863                 return;
5864
5865         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5866
5867         /* check the return value and print it if is < 0 */
5868         if (ret < 0)
5869                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5870 }
5871
5872 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5873                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5874 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5875                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5876                                 "bonding");
5877 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5878                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5879                                 "mac_addr");
5880 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5881                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5882                                 port_num, UINT16);
5883 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5884                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5885
5886 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5887                 .f = cmd_set_bond_mac_addr_parsed,
5888                 .data = (void *) 0,
5889                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5890                 .tokens = {
5891                                 (void *)&cmd_set_bond_mac_addr_set,
5892                                 (void *)&cmd_set_bond_mac_addr_bonding,
5893                                 (void *)&cmd_set_bond_mac_addr_mac,
5894                                 (void *)&cmd_set_bond_mac_addr_portnum,
5895                                 (void *)&cmd_set_bond_mac_addr_addr,
5896                                 NULL
5897                 }
5898 };
5899
5900
5901 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5902 struct cmd_set_bond_mon_period_result {
5903         cmdline_fixed_string_t set;
5904         cmdline_fixed_string_t bonding;
5905         cmdline_fixed_string_t mon_period;
5906         uint16_t port_num;
5907         uint32_t period_ms;
5908 };
5909
5910 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5911                 __attribute__((unused))  struct cmdline *cl,
5912                 __attribute__((unused)) void *data)
5913 {
5914         struct cmd_set_bond_mon_period_result *res = parsed_result;
5915         int ret;
5916
5917         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5918
5919         /* check the return value and print it if is < 0 */
5920         if (ret < 0)
5921                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5922 }
5923
5924 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5925                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5926                                 set, "set");
5927 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5928                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5929                                 bonding, "bonding");
5930 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5931                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5932                                 mon_period,     "mon_period");
5933 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5934                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5935                                 port_num, UINT16);
5936 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5937                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5938                                 period_ms, UINT32);
5939
5940 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5941                 .f = cmd_set_bond_mon_period_parsed,
5942                 .data = (void *) 0,
5943                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5944                 .tokens = {
5945                                 (void *)&cmd_set_bond_mon_period_set,
5946                                 (void *)&cmd_set_bond_mon_period_bonding,
5947                                 (void *)&cmd_set_bond_mon_period_mon_period,
5948                                 (void *)&cmd_set_bond_mon_period_portnum,
5949                                 (void *)&cmd_set_bond_mon_period_period_ms,
5950                                 NULL
5951                 }
5952 };
5953
5954
5955
5956 struct cmd_set_bonding_agg_mode_policy_result {
5957         cmdline_fixed_string_t set;
5958         cmdline_fixed_string_t bonding;
5959         cmdline_fixed_string_t agg_mode;
5960         uint16_t port_num;
5961         cmdline_fixed_string_t policy;
5962 };
5963
5964
5965 static void
5966 cmd_set_bonding_agg_mode(void *parsed_result,
5967                 __attribute__((unused)) struct cmdline *cl,
5968                 __attribute__((unused)) void *data)
5969 {
5970         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5971         uint8_t policy = AGG_BANDWIDTH;
5972
5973         if (!strcmp(res->policy, "bandwidth"))
5974                 policy = AGG_BANDWIDTH;
5975         else if (!strcmp(res->policy, "stable"))
5976                 policy = AGG_STABLE;
5977         else if (!strcmp(res->policy, "count"))
5978                 policy = AGG_COUNT;
5979
5980         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5981 }
5982
5983
5984 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5985         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5986                                 set, "set");
5987 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5988         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5989                                 bonding, "bonding");
5990
5991 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5992         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5993                                 agg_mode, "agg_mode");
5994
5995 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5996         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5997                                 port_num, UINT16);
5998
5999 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6000         TOKEN_STRING_INITIALIZER(
6001                         struct cmd_set_bonding_balance_xmit_policy_result,
6002                 policy, "stable#bandwidth#count");
6003
6004 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6005         .f = cmd_set_bonding_agg_mode,
6006         .data = (void *) 0,
6007         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6008         .tokens = {
6009                         (void *)&cmd_set_bonding_agg_mode_set,
6010                         (void *)&cmd_set_bonding_agg_mode_bonding,
6011                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6012                         (void *)&cmd_set_bonding_agg_mode_portnum,
6013                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6014                         NULL
6015                 }
6016 };
6017
6018
6019 #endif /* RTE_LIBRTE_PMD_BOND */
6020
6021 /* *** SET FORWARDING MODE *** */
6022 struct cmd_set_fwd_mode_result {
6023         cmdline_fixed_string_t set;
6024         cmdline_fixed_string_t fwd;
6025         cmdline_fixed_string_t mode;
6026 };
6027
6028 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6029                                     __attribute__((unused)) struct cmdline *cl,
6030                                     __attribute__((unused)) void *data)
6031 {
6032         struct cmd_set_fwd_mode_result *res = parsed_result;
6033
6034         retry_enabled = 0;
6035         set_pkt_forwarding_mode(res->mode);
6036 }
6037
6038 cmdline_parse_token_string_t cmd_setfwd_set =
6039         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6040 cmdline_parse_token_string_t cmd_setfwd_fwd =
6041         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6042 cmdline_parse_token_string_t cmd_setfwd_mode =
6043         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6044                 "" /* defined at init */);
6045
6046 cmdline_parse_inst_t cmd_set_fwd_mode = {
6047         .f = cmd_set_fwd_mode_parsed,
6048         .data = NULL,
6049         .help_str = NULL, /* defined at init */
6050         .tokens = {
6051                 (void *)&cmd_setfwd_set,
6052                 (void *)&cmd_setfwd_fwd,
6053                 (void *)&cmd_setfwd_mode,
6054                 NULL,
6055         },
6056 };
6057
6058 static void cmd_set_fwd_mode_init(void)
6059 {
6060         char *modes, *c;
6061         static char token[128];
6062         static char help[256];
6063         cmdline_parse_token_string_t *token_struct;
6064
6065         modes = list_pkt_forwarding_modes();
6066         snprintf(help, sizeof(help), "set fwd %s: "
6067                 "Set packet forwarding mode", modes);
6068         cmd_set_fwd_mode.help_str = help;
6069
6070         /* string token separator is # */
6071         for (c = token; *modes != '\0'; modes++)
6072                 if (*modes == '|')
6073                         *c++ = '#';
6074                 else
6075                         *c++ = *modes;
6076         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6077         token_struct->string_data.str = token;
6078 }
6079
6080 /* *** SET RETRY FORWARDING MODE *** */
6081 struct cmd_set_fwd_retry_mode_result {
6082         cmdline_fixed_string_t set;
6083         cmdline_fixed_string_t fwd;
6084         cmdline_fixed_string_t mode;
6085         cmdline_fixed_string_t retry;
6086 };
6087
6088 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6089                             __attribute__((unused)) struct cmdline *cl,
6090                             __attribute__((unused)) void *data)
6091 {
6092         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6093
6094         retry_enabled = 1;
6095         set_pkt_forwarding_mode(res->mode);
6096 }
6097
6098 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6099         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6100                         set, "set");
6101 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6102         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6103                         fwd, "fwd");
6104 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6105         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6106                         mode,
6107                 "" /* defined at init */);
6108 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6109         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6110                         retry, "retry");
6111
6112 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6113         .f = cmd_set_fwd_retry_mode_parsed,
6114         .data = NULL,
6115         .help_str = NULL, /* defined at init */
6116         .tokens = {
6117                 (void *)&cmd_setfwd_retry_set,
6118                 (void *)&cmd_setfwd_retry_fwd,
6119                 (void *)&cmd_setfwd_retry_mode,
6120                 (void *)&cmd_setfwd_retry_retry,
6121                 NULL,
6122         },
6123 };
6124
6125 static void cmd_set_fwd_retry_mode_init(void)
6126 {
6127         char *modes, *c;
6128         static char token[128];
6129         static char help[256];
6130         cmdline_parse_token_string_t *token_struct;
6131
6132         modes = list_pkt_forwarding_retry_modes();
6133         snprintf(help, sizeof(help), "set fwd %s retry: "
6134                 "Set packet forwarding mode with retry", modes);
6135         cmd_set_fwd_retry_mode.help_str = help;
6136
6137         /* string token separator is # */
6138         for (c = token; *modes != '\0'; modes++)
6139                 if (*modes == '|')
6140                         *c++ = '#';
6141                 else
6142                         *c++ = *modes;
6143         token_struct = (cmdline_parse_token_string_t *)
6144                 cmd_set_fwd_retry_mode.tokens[2];
6145         token_struct->string_data.str = token;
6146 }
6147
6148 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6149 struct cmd_set_burst_tx_retry_result {
6150         cmdline_fixed_string_t set;
6151         cmdline_fixed_string_t burst;
6152         cmdline_fixed_string_t tx;
6153         cmdline_fixed_string_t delay;
6154         uint32_t time;
6155         cmdline_fixed_string_t retry;
6156         uint32_t retry_num;
6157 };
6158
6159 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6160                                         __attribute__((unused)) struct cmdline *cl,
6161                                         __attribute__((unused)) void *data)
6162 {
6163         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6164
6165         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6166                 && !strcmp(res->tx, "tx")) {
6167                 if (!strcmp(res->delay, "delay"))
6168                         burst_tx_delay_time = res->time;
6169                 if (!strcmp(res->retry, "retry"))
6170                         burst_tx_retry_num = res->retry_num;
6171         }
6172
6173 }
6174
6175 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6176         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6177 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6178         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6179                                  "burst");
6180 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6181         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6182 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6183         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6184 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6185         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6186 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6187         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6188 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6189         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6190
6191 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6192         .f = cmd_set_burst_tx_retry_parsed,
6193         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6194         .tokens = {
6195                 (void *)&cmd_set_burst_tx_retry_set,
6196                 (void *)&cmd_set_burst_tx_retry_burst,
6197                 (void *)&cmd_set_burst_tx_retry_tx,
6198                 (void *)&cmd_set_burst_tx_retry_delay,
6199                 (void *)&cmd_set_burst_tx_retry_time,
6200                 (void *)&cmd_set_burst_tx_retry_retry,
6201                 (void *)&cmd_set_burst_tx_retry_retry_num,
6202                 NULL,
6203         },
6204 };
6205
6206 /* *** SET PROMISC MODE *** */
6207 struct cmd_set_promisc_mode_result {
6208         cmdline_fixed_string_t set;
6209         cmdline_fixed_string_t promisc;
6210         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6211         uint16_t port_num;               /* valid if "allports" argument == 0 */
6212         cmdline_fixed_string_t mode;
6213 };
6214
6215 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6216                                         __attribute__((unused)) struct cmdline *cl,
6217                                         void *allports)
6218 {
6219         struct cmd_set_promisc_mode_result *res = parsed_result;
6220         int enable;
6221         portid_t i;
6222
6223         if (!strcmp(res->mode, "on"))
6224                 enable = 1;
6225         else
6226                 enable = 0;
6227
6228         /* all ports */
6229         if (allports) {
6230                 RTE_ETH_FOREACH_DEV(i) {
6231                         if (enable)
6232                                 rte_eth_promiscuous_enable(i);
6233                         else
6234                                 rte_eth_promiscuous_disable(i);
6235                 }
6236         }
6237         else {
6238                 if (enable)
6239                         rte_eth_promiscuous_enable(res->port_num);
6240                 else
6241                         rte_eth_promiscuous_disable(res->port_num);
6242         }
6243 }
6244
6245 cmdline_parse_token_string_t cmd_setpromisc_set =
6246         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6247 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6248         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6249                                  "promisc");
6250 cmdline_parse_token_string_t cmd_setpromisc_portall =
6251         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6252                                  "all");
6253 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6254         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6255                               UINT16);
6256 cmdline_parse_token_string_t cmd_setpromisc_mode =
6257         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6258                                  "on#off");
6259
6260 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6261         .f = cmd_set_promisc_mode_parsed,
6262         .data = (void *)1,
6263         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6264         .tokens = {
6265                 (void *)&cmd_setpromisc_set,
6266                 (void *)&cmd_setpromisc_promisc,
6267                 (void *)&cmd_setpromisc_portall,
6268                 (void *)&cmd_setpromisc_mode,
6269                 NULL,
6270         },
6271 };
6272
6273 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6274         .f = cmd_set_promisc_mode_parsed,
6275         .data = (void *)0,
6276         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6277         .tokens = {
6278                 (void *)&cmd_setpromisc_set,
6279                 (void *)&cmd_setpromisc_promisc,
6280                 (void *)&cmd_setpromisc_portnum,
6281                 (void *)&cmd_setpromisc_mode,
6282                 NULL,
6283         },
6284 };
6285
6286 /* *** SET ALLMULTI MODE *** */
6287 struct cmd_set_allmulti_mode_result {
6288         cmdline_fixed_string_t set;
6289         cmdline_fixed_string_t allmulti;
6290         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6291         uint16_t port_num;               /* valid if "allports" argument == 0 */
6292         cmdline_fixed_string_t mode;
6293 };
6294
6295 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6296                                         __attribute__((unused)) struct cmdline *cl,
6297                                         void *allports)
6298 {
6299         struct cmd_set_allmulti_mode_result *res = parsed_result;
6300         int enable;
6301         portid_t i;
6302
6303         if (!strcmp(res->mode, "on"))
6304                 enable = 1;
6305         else
6306                 enable = 0;
6307
6308         /* all ports */
6309         if (allports) {
6310                 RTE_ETH_FOREACH_DEV(i) {
6311                         if (enable)
6312                                 rte_eth_allmulticast_enable(i);
6313                         else
6314                                 rte_eth_allmulticast_disable(i);
6315                 }
6316         }
6317         else {
6318                 if (enable)
6319                         rte_eth_allmulticast_enable(res->port_num);
6320                 else
6321                         rte_eth_allmulticast_disable(res->port_num);
6322         }
6323 }
6324
6325 cmdline_parse_token_string_t cmd_setallmulti_set =
6326         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6327 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6328         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6329                                  "allmulti");
6330 cmdline_parse_token_string_t cmd_setallmulti_portall =
6331         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6332                                  "all");
6333 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6334         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6335                               UINT16);
6336 cmdline_parse_token_string_t cmd_setallmulti_mode =
6337         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6338                                  "on#off");
6339
6340 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6341         .f = cmd_set_allmulti_mode_parsed,
6342         .data = (void *)1,
6343         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6344         .tokens = {
6345                 (void *)&cmd_setallmulti_set,
6346                 (void *)&cmd_setallmulti_allmulti,
6347                 (void *)&cmd_setallmulti_portall,
6348                 (void *)&cmd_setallmulti_mode,
6349                 NULL,
6350         },
6351 };
6352
6353 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6354         .f = cmd_set_allmulti_mode_parsed,
6355         .data = (void *)0,
6356         .help_str = "set allmulti <port_id> on|off: "
6357                 "Set allmulti mode on port_id",
6358         .tokens = {
6359                 (void *)&cmd_setallmulti_set,
6360                 (void *)&cmd_setallmulti_allmulti,
6361                 (void *)&cmd_setallmulti_portnum,
6362                 (void *)&cmd_setallmulti_mode,
6363                 NULL,
6364         },
6365 };
6366
6367 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6368 struct cmd_link_flow_ctrl_set_result {
6369         cmdline_fixed_string_t set;
6370         cmdline_fixed_string_t flow_ctrl;
6371         cmdline_fixed_string_t rx;
6372         cmdline_fixed_string_t rx_lfc_mode;
6373         cmdline_fixed_string_t tx;
6374         cmdline_fixed_string_t tx_lfc_mode;
6375         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6376         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6377         cmdline_fixed_string_t autoneg_str;
6378         cmdline_fixed_string_t autoneg;
6379         cmdline_fixed_string_t hw_str;
6380         uint32_t high_water;
6381         cmdline_fixed_string_t lw_str;
6382         uint32_t low_water;
6383         cmdline_fixed_string_t pt_str;
6384         uint16_t pause_time;
6385         cmdline_fixed_string_t xon_str;
6386         uint16_t send_xon;
6387         portid_t port_id;
6388 };
6389
6390 cmdline_parse_token_string_t cmd_lfc_set_set =
6391         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6392                                 set, "set");
6393 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6394         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6395                                 flow_ctrl, "flow_ctrl");
6396 cmdline_parse_token_string_t cmd_lfc_set_rx =
6397         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6398                                 rx, "rx");
6399 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6400         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6401                                 rx_lfc_mode, "on#off");
6402 cmdline_parse_token_string_t cmd_lfc_set_tx =
6403         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6404                                 tx, "tx");
6405 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6406         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6407                                 tx_lfc_mode, "on#off");
6408 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6409         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6410                                 hw_str, "high_water");
6411 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6412         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6413                                 high_water, UINT32);
6414 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6415         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6416                                 lw_str, "low_water");
6417 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6418         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6419                                 low_water, UINT32);
6420 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6421         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6422                                 pt_str, "pause_time");
6423 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6424         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6425                                 pause_time, UINT16);
6426 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6427         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6428                                 xon_str, "send_xon");
6429 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6430         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6431                                 send_xon, UINT16);
6432 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6433         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6434                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6435 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6436         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6437                                 mac_ctrl_frame_fwd_mode, "on#off");
6438 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6439         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6440                                 autoneg_str, "autoneg");
6441 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6442         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6443                                 autoneg, "on#off");
6444 cmdline_parse_token_num_t cmd_lfc_set_portid =
6445         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6446                                 port_id, UINT16);
6447
6448 /* forward declaration */
6449 static void
6450 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6451                               void *data);
6452
6453 cmdline_parse_inst_t cmd_link_flow_control_set = {
6454         .f = cmd_link_flow_ctrl_set_parsed,
6455         .data = NULL,
6456         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6457                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6458                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6459         .tokens = {
6460                 (void *)&cmd_lfc_set_set,
6461                 (void *)&cmd_lfc_set_flow_ctrl,
6462                 (void *)&cmd_lfc_set_rx,
6463                 (void *)&cmd_lfc_set_rx_mode,
6464                 (void *)&cmd_lfc_set_tx,
6465                 (void *)&cmd_lfc_set_tx_mode,
6466                 (void *)&cmd_lfc_set_high_water,
6467                 (void *)&cmd_lfc_set_low_water,
6468                 (void *)&cmd_lfc_set_pause_time,
6469                 (void *)&cmd_lfc_set_send_xon,
6470                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6471                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6472                 (void *)&cmd_lfc_set_autoneg_str,
6473                 (void *)&cmd_lfc_set_autoneg,
6474                 (void *)&cmd_lfc_set_portid,
6475                 NULL,
6476         },
6477 };
6478
6479 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6480         .f = cmd_link_flow_ctrl_set_parsed,
6481         .data = (void *)&cmd_link_flow_control_set_rx,
6482         .help_str = "set flow_ctrl rx on|off <port_id>: "
6483                 "Change rx flow control parameter",
6484         .tokens = {
6485                 (void *)&cmd_lfc_set_set,
6486                 (void *)&cmd_lfc_set_flow_ctrl,
6487                 (void *)&cmd_lfc_set_rx,
6488                 (void *)&cmd_lfc_set_rx_mode,
6489                 (void *)&cmd_lfc_set_portid,
6490                 NULL,
6491         },
6492 };
6493
6494 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6495         .f = cmd_link_flow_ctrl_set_parsed,
6496         .data = (void *)&cmd_link_flow_control_set_tx,
6497         .help_str = "set flow_ctrl tx on|off <port_id>: "
6498                 "Change tx flow control parameter",
6499         .tokens = {
6500                 (void *)&cmd_lfc_set_set,
6501                 (void *)&cmd_lfc_set_flow_ctrl,
6502                 (void *)&cmd_lfc_set_tx,
6503                 (void *)&cmd_lfc_set_tx_mode,
6504                 (void *)&cmd_lfc_set_portid,
6505                 NULL,
6506         },
6507 };
6508
6509 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6510         .f = cmd_link_flow_ctrl_set_parsed,
6511         .data = (void *)&cmd_link_flow_control_set_hw,
6512         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6513                 "Change high water flow control parameter",
6514         .tokens = {
6515                 (void *)&cmd_lfc_set_set,
6516                 (void *)&cmd_lfc_set_flow_ctrl,
6517                 (void *)&cmd_lfc_set_high_water_str,
6518                 (void *)&cmd_lfc_set_high_water,
6519                 (void *)&cmd_lfc_set_portid,
6520                 NULL,
6521         },
6522 };
6523
6524 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6525         .f = cmd_link_flow_ctrl_set_parsed,
6526         .data = (void *)&cmd_link_flow_control_set_lw,
6527         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6528                 "Change low water flow control parameter",
6529         .tokens = {
6530                 (void *)&cmd_lfc_set_set,
6531                 (void *)&cmd_lfc_set_flow_ctrl,
6532                 (void *)&cmd_lfc_set_low_water_str,
6533                 (void *)&cmd_lfc_set_low_water,
6534                 (void *)&cmd_lfc_set_portid,
6535                 NULL,
6536         },
6537 };
6538
6539 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6540         .f = cmd_link_flow_ctrl_set_parsed,
6541         .data = (void *)&cmd_link_flow_control_set_pt,
6542         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6543                 "Change pause time flow control parameter",
6544         .tokens = {
6545                 (void *)&cmd_lfc_set_set,
6546                 (void *)&cmd_lfc_set_flow_ctrl,
6547                 (void *)&cmd_lfc_set_pause_time_str,
6548                 (void *)&cmd_lfc_set_pause_time,
6549                 (void *)&cmd_lfc_set_portid,
6550                 NULL,
6551         },
6552 };
6553
6554 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6555         .f = cmd_link_flow_ctrl_set_parsed,
6556         .data = (void *)&cmd_link_flow_control_set_xon,
6557         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6558                 "Change send_xon flow control parameter",
6559         .tokens = {
6560                 (void *)&cmd_lfc_set_set,
6561                 (void *)&cmd_lfc_set_flow_ctrl,
6562                 (void *)&cmd_lfc_set_send_xon_str,
6563                 (void *)&cmd_lfc_set_send_xon,
6564                 (void *)&cmd_lfc_set_portid,
6565                 NULL,
6566         },
6567 };
6568
6569 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6570         .f = cmd_link_flow_ctrl_set_parsed,
6571         .data = (void *)&cmd_link_flow_control_set_macfwd,
6572         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6573                 "Change mac ctrl fwd flow control parameter",
6574         .tokens = {
6575                 (void *)&cmd_lfc_set_set,
6576                 (void *)&cmd_lfc_set_flow_ctrl,
6577                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6578                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6579                 (void *)&cmd_lfc_set_portid,
6580                 NULL,
6581         },
6582 };
6583
6584 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6585         .f = cmd_link_flow_ctrl_set_parsed,
6586         .data = (void *)&cmd_link_flow_control_set_autoneg,
6587         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6588                 "Change autoneg flow control parameter",
6589         .tokens = {
6590                 (void *)&cmd_lfc_set_set,
6591                 (void *)&cmd_lfc_set_flow_ctrl,
6592                 (void *)&cmd_lfc_set_autoneg_str,
6593                 (void *)&cmd_lfc_set_autoneg,
6594                 (void *)&cmd_lfc_set_portid,
6595                 NULL,
6596         },
6597 };
6598
6599 static void
6600 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6601                               __attribute__((unused)) struct cmdline *cl,
6602                               void *data)
6603 {
6604         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6605         cmdline_parse_inst_t *cmd = data;
6606         struct rte_eth_fc_conf fc_conf;
6607         int rx_fc_en = 0;
6608         int tx_fc_en = 0;
6609         int ret;
6610
6611         /*
6612          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6613          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6614          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6615          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6616          */
6617         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6618                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6619         };
6620
6621         /* Partial command line, retrieve current configuration */
6622         if (cmd) {
6623                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6624                 if (ret != 0) {
6625                         printf("cannot get current flow ctrl parameters, return"
6626                                "code = %d\n", ret);
6627                         return;
6628                 }
6629
6630                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6631                     (fc_conf.mode == RTE_FC_FULL))
6632                         rx_fc_en = 1;
6633                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6634                     (fc_conf.mode == RTE_FC_FULL))
6635                         tx_fc_en = 1;
6636         }
6637
6638         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6639                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6640
6641         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6642                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6643
6644         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6645
6646         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6647                 fc_conf.high_water = res->high_water;
6648
6649         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6650                 fc_conf.low_water = res->low_water;
6651
6652         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6653                 fc_conf.pause_time = res->pause_time;
6654
6655         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6656                 fc_conf.send_xon = res->send_xon;
6657
6658         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6659                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6660                         fc_conf.mac_ctrl_frame_fwd = 1;
6661                 else
6662                         fc_conf.mac_ctrl_frame_fwd = 0;
6663         }
6664
6665         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6666                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6667
6668         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6669         if (ret != 0)
6670                 printf("bad flow contrl parameter, return code = %d \n", ret);
6671 }
6672
6673 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6674 struct cmd_priority_flow_ctrl_set_result {
6675         cmdline_fixed_string_t set;
6676         cmdline_fixed_string_t pfc_ctrl;
6677         cmdline_fixed_string_t rx;
6678         cmdline_fixed_string_t rx_pfc_mode;
6679         cmdline_fixed_string_t tx;
6680         cmdline_fixed_string_t tx_pfc_mode;
6681         uint32_t high_water;
6682         uint32_t low_water;
6683         uint16_t pause_time;
6684         uint8_t  priority;
6685         portid_t port_id;
6686 };
6687
6688 static void
6689 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6690                        __attribute__((unused)) struct cmdline *cl,
6691                        __attribute__((unused)) void *data)
6692 {
6693         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6694         struct rte_eth_pfc_conf pfc_conf;
6695         int rx_fc_enable, tx_fc_enable;
6696         int ret;
6697
6698         /*
6699          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6700          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6701          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6702          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6703          */
6704         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6705                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6706         };
6707
6708         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6709         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6710         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6711         pfc_conf.fc.high_water = res->high_water;
6712         pfc_conf.fc.low_water  = res->low_water;
6713         pfc_conf.fc.pause_time = res->pause_time;
6714         pfc_conf.priority      = res->priority;
6715
6716         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6717         if (ret != 0)
6718                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6719 }
6720
6721 cmdline_parse_token_string_t cmd_pfc_set_set =
6722         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6723                                 set, "set");
6724 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6725         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6726                                 pfc_ctrl, "pfc_ctrl");
6727 cmdline_parse_token_string_t cmd_pfc_set_rx =
6728         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6729                                 rx, "rx");
6730 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6731         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6732                                 rx_pfc_mode, "on#off");
6733 cmdline_parse_token_string_t cmd_pfc_set_tx =
6734         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6735                                 tx, "tx");
6736 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6737         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6738                                 tx_pfc_mode, "on#off");
6739 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6740         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6741                                 high_water, UINT32);
6742 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6743         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6744                                 low_water, UINT32);
6745 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6746         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6747                                 pause_time, UINT16);
6748 cmdline_parse_token_num_t cmd_pfc_set_priority =
6749         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6750                                 priority, UINT8);
6751 cmdline_parse_token_num_t cmd_pfc_set_portid =
6752         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6753                                 port_id, UINT16);
6754
6755 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6756         .f = cmd_priority_flow_ctrl_set_parsed,
6757         .data = NULL,
6758         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6759                 "<pause_time> <priority> <port_id>: "
6760                 "Configure the Ethernet priority flow control",
6761         .tokens = {
6762                 (void *)&cmd_pfc_set_set,
6763                 (void *)&cmd_pfc_set_flow_ctrl,
6764                 (void *)&cmd_pfc_set_rx,
6765                 (void *)&cmd_pfc_set_rx_mode,
6766                 (void *)&cmd_pfc_set_tx,
6767                 (void *)&cmd_pfc_set_tx_mode,
6768                 (void *)&cmd_pfc_set_high_water,
6769                 (void *)&cmd_pfc_set_low_water,
6770                 (void *)&cmd_pfc_set_pause_time,
6771                 (void *)&cmd_pfc_set_priority,
6772                 (void *)&cmd_pfc_set_portid,
6773                 NULL,
6774         },
6775 };
6776
6777 /* *** RESET CONFIGURATION *** */
6778 struct cmd_reset_result {
6779         cmdline_fixed_string_t reset;
6780         cmdline_fixed_string_t def;
6781 };
6782
6783 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6784                              struct cmdline *cl,
6785                              __attribute__((unused)) void *data)
6786 {
6787         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6788         set_def_fwd_config();
6789 }
6790
6791 cmdline_parse_token_string_t cmd_reset_set =
6792         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6793 cmdline_parse_token_string_t cmd_reset_def =
6794         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6795                                  "default");
6796
6797 cmdline_parse_inst_t cmd_reset = {
6798         .f = cmd_reset_parsed,
6799         .data = NULL,
6800         .help_str = "set default: Reset default forwarding configuration",
6801         .tokens = {
6802                 (void *)&cmd_reset_set,
6803                 (void *)&cmd_reset_def,
6804                 NULL,
6805         },
6806 };
6807
6808 /* *** START FORWARDING *** */
6809 struct cmd_start_result {
6810         cmdline_fixed_string_t start;
6811 };
6812
6813 cmdline_parse_token_string_t cmd_start_start =
6814         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6815
6816 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6817                              __attribute__((unused)) struct cmdline *cl,
6818                              __attribute__((unused)) void *data)
6819 {
6820         start_packet_forwarding(0);
6821 }
6822
6823 cmdline_parse_inst_t cmd_start = {
6824         .f = cmd_start_parsed,
6825         .data = NULL,
6826         .help_str = "start: Start packet forwarding",
6827         .tokens = {
6828                 (void *)&cmd_start_start,
6829                 NULL,
6830         },
6831 };
6832
6833 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6834 struct cmd_start_tx_first_result {
6835         cmdline_fixed_string_t start;
6836         cmdline_fixed_string_t tx_first;
6837 };
6838
6839 static void
6840 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6841                           __attribute__((unused)) struct cmdline *cl,
6842                           __attribute__((unused)) void *data)
6843 {
6844         start_packet_forwarding(1);
6845 }
6846
6847 cmdline_parse_token_string_t cmd_start_tx_first_start =
6848         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6849                                  "start");
6850 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6851         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6852                                  tx_first, "tx_first");
6853
6854 cmdline_parse_inst_t cmd_start_tx_first = {
6855         .f = cmd_start_tx_first_parsed,
6856         .data = NULL,
6857         .help_str = "start tx_first: Start packet forwarding, "
6858                 "after sending 1 burst of packets",
6859         .tokens = {
6860                 (void *)&cmd_start_tx_first_start,
6861                 (void *)&cmd_start_tx_first_tx_first,
6862                 NULL,
6863         },
6864 };
6865
6866 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6867 struct cmd_start_tx_first_n_result {
6868         cmdline_fixed_string_t start;
6869         cmdline_fixed_string_t tx_first;
6870         uint32_t tx_num;
6871 };
6872
6873 static void
6874 cmd_start_tx_first_n_parsed(void *parsed_result,
6875                           __attribute__((unused)) struct cmdline *cl,
6876                           __attribute__((unused)) void *data)
6877 {
6878         struct cmd_start_tx_first_n_result *res = parsed_result;
6879
6880         start_packet_forwarding(res->tx_num);
6881 }
6882
6883 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6884         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6885                         start, "start");
6886 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6887         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6888                         tx_first, "tx_first");
6889 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6890         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6891                         tx_num, UINT32);
6892
6893 cmdline_parse_inst_t cmd_start_tx_first_n = {
6894         .f = cmd_start_tx_first_n_parsed,
6895         .data = NULL,
6896         .help_str = "start tx_first <num>: "
6897                 "packet forwarding, after sending <num> bursts of packets",
6898         .tokens = {
6899                 (void *)&cmd_start_tx_first_n_start,
6900                 (void *)&cmd_start_tx_first_n_tx_first,
6901                 (void *)&cmd_start_tx_first_n_tx_num,
6902                 NULL,
6903         },
6904 };
6905
6906 /* *** SET LINK UP *** */
6907 struct cmd_set_link_up_result {
6908         cmdline_fixed_string_t set;
6909         cmdline_fixed_string_t link_up;
6910         cmdline_fixed_string_t port;
6911         portid_t port_id;
6912 };
6913
6914 cmdline_parse_token_string_t cmd_set_link_up_set =
6915         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6916 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6917         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6918                                 "link-up");
6919 cmdline_parse_token_string_t cmd_set_link_up_port =
6920         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6921 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6922         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6923
6924 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6925                              __attribute__((unused)) struct cmdline *cl,
6926                              __attribute__((unused)) void *data)
6927 {
6928         struct cmd_set_link_up_result *res = parsed_result;
6929         dev_set_link_up(res->port_id);
6930 }
6931
6932 cmdline_parse_inst_t cmd_set_link_up = {
6933         .f = cmd_set_link_up_parsed,
6934         .data = NULL,
6935         .help_str = "set link-up port <port id>",
6936         .tokens = {
6937                 (void *)&cmd_set_link_up_set,
6938                 (void *)&cmd_set_link_up_link_up,
6939                 (void *)&cmd_set_link_up_port,
6940                 (void *)&cmd_set_link_up_port_id,
6941                 NULL,
6942         },
6943 };
6944
6945 /* *** SET LINK DOWN *** */
6946 struct cmd_set_link_down_result {
6947         cmdline_fixed_string_t set;
6948         cmdline_fixed_string_t link_down;
6949         cmdline_fixed_string_t port;
6950         portid_t port_id;
6951 };
6952
6953 cmdline_parse_token_string_t cmd_set_link_down_set =
6954         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6955 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6956         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6957                                 "link-down");
6958 cmdline_parse_token_string_t cmd_set_link_down_port =
6959         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6960 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6961         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6962
6963 static void cmd_set_link_down_parsed(
6964                                 __attribute__((unused)) void *parsed_result,
6965                                 __attribute__((unused)) struct cmdline *cl,
6966                                 __attribute__((unused)) void *data)
6967 {
6968         struct cmd_set_link_down_result *res = parsed_result;
6969         dev_set_link_down(res->port_id);
6970 }
6971
6972 cmdline_parse_inst_t cmd_set_link_down = {
6973         .f = cmd_set_link_down_parsed,
6974         .data = NULL,
6975         .help_str = "set link-down port <port id>",
6976         .tokens = {
6977                 (void *)&cmd_set_link_down_set,
6978                 (void *)&cmd_set_link_down_link_down,
6979                 (void *)&cmd_set_link_down_port,
6980                 (void *)&cmd_set_link_down_port_id,
6981                 NULL,
6982         },
6983 };
6984
6985 /* *** SHOW CFG *** */
6986 struct cmd_showcfg_result {
6987         cmdline_fixed_string_t show;
6988         cmdline_fixed_string_t cfg;
6989         cmdline_fixed_string_t what;
6990 };
6991
6992 static void cmd_showcfg_parsed(void *parsed_result,
6993                                __attribute__((unused)) struct cmdline *cl,
6994                                __attribute__((unused)) void *data)
6995 {
6996         struct cmd_showcfg_result *res = parsed_result;
6997         if (!strcmp(res->what, "rxtx"))
6998                 rxtx_config_display();
6999         else if (!strcmp(res->what, "cores"))
7000                 fwd_lcores_config_display();
7001         else if (!strcmp(res->what, "fwd"))
7002                 pkt_fwd_config_display(&cur_fwd_config);
7003         else if (!strcmp(res->what, "txpkts"))
7004                 show_tx_pkt_segments();
7005 }
7006
7007 cmdline_parse_token_string_t cmd_showcfg_show =
7008         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7009 cmdline_parse_token_string_t cmd_showcfg_port =
7010         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7011 cmdline_parse_token_string_t cmd_showcfg_what =
7012         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7013                                  "rxtx#cores#fwd#txpkts");
7014
7015 cmdline_parse_inst_t cmd_showcfg = {
7016         .f = cmd_showcfg_parsed,
7017         .data = NULL,
7018         .help_str = "show config rxtx|cores|fwd|txpkts",
7019         .tokens = {
7020                 (void *)&cmd_showcfg_show,
7021                 (void *)&cmd_showcfg_port,
7022                 (void *)&cmd_showcfg_what,
7023                 NULL,
7024         },
7025 };
7026
7027 /* *** SHOW ALL PORT INFO *** */
7028 struct cmd_showportall_result {
7029         cmdline_fixed_string_t show;
7030         cmdline_fixed_string_t port;
7031         cmdline_fixed_string_t what;
7032         cmdline_fixed_string_t all;
7033 };
7034
7035 static void cmd_showportall_parsed(void *parsed_result,
7036                                 __attribute__((unused)) struct cmdline *cl,
7037                                 __attribute__((unused)) void *data)
7038 {
7039         portid_t i;
7040
7041         struct cmd_showportall_result *res = parsed_result;
7042         if (!strcmp(res->show, "clear")) {
7043                 if (!strcmp(res->what, "stats"))
7044                         RTE_ETH_FOREACH_DEV(i)
7045                                 nic_stats_clear(i);
7046                 else if (!strcmp(res->what, "xstats"))
7047                         RTE_ETH_FOREACH_DEV(i)
7048                                 nic_xstats_clear(i);
7049         } else if (!strcmp(res->what, "info"))
7050                 RTE_ETH_FOREACH_DEV(i)
7051                         port_infos_display(i);
7052         else if (!strcmp(res->what, "stats"))
7053                 RTE_ETH_FOREACH_DEV(i)
7054                         nic_stats_display(i);
7055         else if (!strcmp(res->what, "xstats"))
7056                 RTE_ETH_FOREACH_DEV(i)
7057                         nic_xstats_display(i);
7058         else if (!strcmp(res->what, "fdir"))
7059                 RTE_ETH_FOREACH_DEV(i)
7060                         fdir_get_infos(i);
7061         else if (!strcmp(res->what, "stat_qmap"))
7062                 RTE_ETH_FOREACH_DEV(i)
7063                         nic_stats_mapping_display(i);
7064         else if (!strcmp(res->what, "dcb_tc"))
7065                 RTE_ETH_FOREACH_DEV(i)
7066                         port_dcb_info_display(i);
7067         else if (!strcmp(res->what, "cap"))
7068                 RTE_ETH_FOREACH_DEV(i)
7069                         port_offload_cap_display(i);
7070 }
7071
7072 cmdline_parse_token_string_t cmd_showportall_show =
7073         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7074                                  "show#clear");
7075 cmdline_parse_token_string_t cmd_showportall_port =
7076         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7077 cmdline_parse_token_string_t cmd_showportall_what =
7078         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7079                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7080 cmdline_parse_token_string_t cmd_showportall_all =
7081         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7082 cmdline_parse_inst_t cmd_showportall = {
7083         .f = cmd_showportall_parsed,
7084         .data = NULL,
7085         .help_str = "show|clear port "
7086                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7087         .tokens = {
7088                 (void *)&cmd_showportall_show,
7089                 (void *)&cmd_showportall_port,
7090                 (void *)&cmd_showportall_what,
7091                 (void *)&cmd_showportall_all,
7092                 NULL,
7093         },
7094 };
7095
7096 /* *** SHOW PORT INFO *** */
7097 struct cmd_showport_result {
7098         cmdline_fixed_string_t show;
7099         cmdline_fixed_string_t port;
7100         cmdline_fixed_string_t what;
7101         uint16_t portnum;
7102 };
7103
7104 static void cmd_showport_parsed(void *parsed_result,
7105                                 __attribute__((unused)) struct cmdline *cl,
7106                                 __attribute__((unused)) void *data)
7107 {
7108         struct cmd_showport_result *res = parsed_result;
7109         if (!strcmp(res->show, "clear")) {
7110                 if (!strcmp(res->what, "stats"))
7111                         nic_stats_clear(res->portnum);
7112                 else if (!strcmp(res->what, "xstats"))
7113                         nic_xstats_clear(res->portnum);
7114         } else if (!strcmp(res->what, "info"))
7115                 port_infos_display(res->portnum);
7116         else if (!strcmp(res->what, "stats"))
7117                 nic_stats_display(res->portnum);
7118         else if (!strcmp(res->what, "xstats"))
7119                 nic_xstats_display(res->portnum);
7120         else if (!strcmp(res->what, "fdir"))
7121                  fdir_get_infos(res->portnum);
7122         else if (!strcmp(res->what, "stat_qmap"))
7123                 nic_stats_mapping_display(res->portnum);
7124         else if (!strcmp(res->what, "dcb_tc"))
7125                 port_dcb_info_display(res->portnum);
7126         else if (!strcmp(res->what, "cap"))
7127                 port_offload_cap_display(res->portnum);
7128 }
7129
7130 cmdline_parse_token_string_t cmd_showport_show =
7131         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7132                                  "show#clear");
7133 cmdline_parse_token_string_t cmd_showport_port =
7134         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7135 cmdline_parse_token_string_t cmd_showport_what =
7136         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7137                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7138 cmdline_parse_token_num_t cmd_showport_portnum =
7139         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7140
7141 cmdline_parse_inst_t cmd_showport = {
7142         .f = cmd_showport_parsed,
7143         .data = NULL,
7144         .help_str = "show|clear port "
7145                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7146                 "<port_id>",
7147         .tokens = {
7148                 (void *)&cmd_showport_show,
7149                 (void *)&cmd_showport_port,
7150                 (void *)&cmd_showport_what,
7151                 (void *)&cmd_showport_portnum,
7152                 NULL,
7153         },
7154 };
7155
7156 /* *** SHOW QUEUE INFO *** */
7157 struct cmd_showqueue_result {
7158         cmdline_fixed_string_t show;
7159         cmdline_fixed_string_t type;
7160         cmdline_fixed_string_t what;
7161         uint16_t portnum;
7162         uint16_t queuenum;
7163 };
7164
7165 static void
7166 cmd_showqueue_parsed(void *parsed_result,
7167         __attribute__((unused)) struct cmdline *cl,
7168         __attribute__((unused)) void *data)
7169 {
7170         struct cmd_showqueue_result *res = parsed_result;
7171
7172         if (!strcmp(res->type, "rxq"))
7173                 rx_queue_infos_display(res->portnum, res->queuenum);
7174         else if (!strcmp(res->type, "txq"))
7175                 tx_queue_infos_display(res->portnum, res->queuenum);
7176 }
7177
7178 cmdline_parse_token_string_t cmd_showqueue_show =
7179         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7180 cmdline_parse_token_string_t cmd_showqueue_type =
7181         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7182 cmdline_parse_token_string_t cmd_showqueue_what =
7183         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7184 cmdline_parse_token_num_t cmd_showqueue_portnum =
7185         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7186 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7187         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7188
7189 cmdline_parse_inst_t cmd_showqueue = {
7190         .f = cmd_showqueue_parsed,
7191         .data = NULL,
7192         .help_str = "show rxq|txq info <port_id> <queue_id>",
7193         .tokens = {
7194                 (void *)&cmd_showqueue_show,
7195                 (void *)&cmd_showqueue_type,
7196                 (void *)&cmd_showqueue_what,
7197                 (void *)&cmd_showqueue_portnum,
7198                 (void *)&cmd_showqueue_queuenum,
7199                 NULL,
7200         },
7201 };
7202
7203 /* *** READ PORT REGISTER *** */
7204 struct cmd_read_reg_result {
7205         cmdline_fixed_string_t read;
7206         cmdline_fixed_string_t reg;
7207         portid_t port_id;
7208         uint32_t reg_off;
7209 };
7210
7211 static void
7212 cmd_read_reg_parsed(void *parsed_result,
7213                     __attribute__((unused)) struct cmdline *cl,
7214                     __attribute__((unused)) void *data)
7215 {
7216         struct cmd_read_reg_result *res = parsed_result;
7217         port_reg_display(res->port_id, res->reg_off);
7218 }
7219
7220 cmdline_parse_token_string_t cmd_read_reg_read =
7221         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7222 cmdline_parse_token_string_t cmd_read_reg_reg =
7223         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7224 cmdline_parse_token_num_t cmd_read_reg_port_id =
7225         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7226 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7227         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7228
7229 cmdline_parse_inst_t cmd_read_reg = {
7230         .f = cmd_read_reg_parsed,
7231         .data = NULL,
7232         .help_str = "read reg <port_id> <reg_off>",
7233         .tokens = {
7234                 (void *)&cmd_read_reg_read,
7235                 (void *)&cmd_read_reg_reg,
7236                 (void *)&cmd_read_reg_port_id,
7237                 (void *)&cmd_read_reg_reg_off,
7238                 NULL,
7239         },
7240 };
7241
7242 /* *** READ PORT REGISTER BIT FIELD *** */
7243 struct cmd_read_reg_bit_field_result {
7244         cmdline_fixed_string_t read;
7245         cmdline_fixed_string_t regfield;
7246         portid_t port_id;
7247         uint32_t reg_off;
7248         uint8_t bit1_pos;
7249         uint8_t bit2_pos;
7250 };
7251
7252 static void
7253 cmd_read_reg_bit_field_parsed(void *parsed_result,
7254                               __attribute__((unused)) struct cmdline *cl,
7255                               __attribute__((unused)) void *data)
7256 {
7257         struct cmd_read_reg_bit_field_result *res = parsed_result;
7258         port_reg_bit_field_display(res->port_id, res->reg_off,
7259                                    res->bit1_pos, res->bit2_pos);
7260 }
7261
7262 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7263         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7264                                  "read");
7265 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7266         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7267                                  regfield, "regfield");
7268 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7269         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7270                               UINT16);
7271 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7272         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7273                               UINT32);
7274 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7275         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7276                               UINT8);
7277 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7278         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7279                               UINT8);
7280
7281 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7282         .f = cmd_read_reg_bit_field_parsed,
7283         .data = NULL,
7284         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7285         "Read register bit field between bit_x and bit_y included",
7286         .tokens = {
7287                 (void *)&cmd_read_reg_bit_field_read,
7288                 (void *)&cmd_read_reg_bit_field_regfield,
7289                 (void *)&cmd_read_reg_bit_field_port_id,
7290                 (void *)&cmd_read_reg_bit_field_reg_off,
7291                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7292                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7293                 NULL,
7294         },
7295 };
7296
7297 /* *** READ PORT REGISTER BIT *** */
7298 struct cmd_read_reg_bit_result {
7299         cmdline_fixed_string_t read;
7300         cmdline_fixed_string_t regbit;
7301         portid_t port_id;
7302         uint32_t reg_off;
7303         uint8_t bit_pos;
7304 };
7305
7306 static void
7307 cmd_read_reg_bit_parsed(void *parsed_result,
7308                         __attribute__((unused)) struct cmdline *cl,
7309                         __attribute__((unused)) void *data)
7310 {
7311         struct cmd_read_reg_bit_result *res = parsed_result;
7312         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7313 }
7314
7315 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7316         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7317 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7318         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7319                                  regbit, "regbit");
7320 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7321         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7322 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7323         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7324 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7325         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7326
7327 cmdline_parse_inst_t cmd_read_reg_bit = {
7328         .f = cmd_read_reg_bit_parsed,
7329         .data = NULL,
7330         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7331         .tokens = {
7332                 (void *)&cmd_read_reg_bit_read,
7333                 (void *)&cmd_read_reg_bit_regbit,
7334                 (void *)&cmd_read_reg_bit_port_id,
7335                 (void *)&cmd_read_reg_bit_reg_off,
7336                 (void *)&cmd_read_reg_bit_bit_pos,
7337                 NULL,
7338         },
7339 };
7340
7341 /* *** WRITE PORT REGISTER *** */
7342 struct cmd_write_reg_result {
7343         cmdline_fixed_string_t write;
7344         cmdline_fixed_string_t reg;
7345         portid_t port_id;
7346         uint32_t reg_off;
7347         uint32_t value;
7348 };
7349
7350 static void
7351 cmd_write_reg_parsed(void *parsed_result,
7352                      __attribute__((unused)) struct cmdline *cl,
7353                      __attribute__((unused)) void *data)
7354 {
7355         struct cmd_write_reg_result *res = parsed_result;
7356         port_reg_set(res->port_id, res->reg_off, res->value);
7357 }
7358
7359 cmdline_parse_token_string_t cmd_write_reg_write =
7360         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7361 cmdline_parse_token_string_t cmd_write_reg_reg =
7362         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7363 cmdline_parse_token_num_t cmd_write_reg_port_id =
7364         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7365 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7366         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7367 cmdline_parse_token_num_t cmd_write_reg_value =
7368         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7369
7370 cmdline_parse_inst_t cmd_write_reg = {
7371         .f = cmd_write_reg_parsed,
7372         .data = NULL,
7373         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7374         .tokens = {
7375                 (void *)&cmd_write_reg_write,
7376                 (void *)&cmd_write_reg_reg,
7377                 (void *)&cmd_write_reg_port_id,
7378                 (void *)&cmd_write_reg_reg_off,
7379                 (void *)&cmd_write_reg_value,
7380                 NULL,
7381         },
7382 };
7383
7384 /* *** WRITE PORT REGISTER BIT FIELD *** */
7385 struct cmd_write_reg_bit_field_result {
7386         cmdline_fixed_string_t write;
7387         cmdline_fixed_string_t regfield;
7388         portid_t port_id;
7389         uint32_t reg_off;
7390         uint8_t bit1_pos;
7391         uint8_t bit2_pos;
7392         uint32_t value;
7393 };
7394
7395 static void
7396 cmd_write_reg_bit_field_parsed(void *parsed_result,
7397                                __attribute__((unused)) struct cmdline *cl,
7398                                __attribute__((unused)) void *data)
7399 {
7400         struct cmd_write_reg_bit_field_result *res = parsed_result;
7401         port_reg_bit_field_set(res->port_id, res->reg_off,
7402                           res->bit1_pos, res->bit2_pos, res->value);
7403 }
7404
7405 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7406         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7407                                  "write");
7408 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7409         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7410                                  regfield, "regfield");
7411 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7412         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7413                               UINT16);
7414 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7415         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7416                               UINT32);
7417 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7418         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7419                               UINT8);
7420 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7421         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7422                               UINT8);
7423 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7424         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7425                               UINT32);
7426
7427 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7428         .f = cmd_write_reg_bit_field_parsed,
7429         .data = NULL,
7430         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7431                 "<reg_value>: "
7432                 "Set register bit field between bit_x and bit_y included",
7433         .tokens = {
7434                 (void *)&cmd_write_reg_bit_field_write,
7435                 (void *)&cmd_write_reg_bit_field_regfield,
7436                 (void *)&cmd_write_reg_bit_field_port_id,
7437                 (void *)&cmd_write_reg_bit_field_reg_off,
7438                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7439                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7440                 (void *)&cmd_write_reg_bit_field_value,
7441                 NULL,
7442         },
7443 };
7444
7445 /* *** WRITE PORT REGISTER BIT *** */
7446 struct cmd_write_reg_bit_result {
7447         cmdline_fixed_string_t write;
7448         cmdline_fixed_string_t regbit;
7449         portid_t port_id;
7450         uint32_t reg_off;
7451         uint8_t bit_pos;
7452         uint8_t value;
7453 };
7454
7455 static void
7456 cmd_write_reg_bit_parsed(void *parsed_result,
7457                          __attribute__((unused)) struct cmdline *cl,
7458                          __attribute__((unused)) void *data)
7459 {
7460         struct cmd_write_reg_bit_result *res = parsed_result;
7461         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7462 }
7463
7464 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7465         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7466                                  "write");
7467 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7468         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7469                                  regbit, "regbit");
7470 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7471         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7472 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7473         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7474 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7475         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7476 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7477         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7478
7479 cmdline_parse_inst_t cmd_write_reg_bit = {
7480         .f = cmd_write_reg_bit_parsed,
7481         .data = NULL,
7482         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7483                 "0 <= bit_x <= 31",
7484         .tokens = {
7485                 (void *)&cmd_write_reg_bit_write,
7486                 (void *)&cmd_write_reg_bit_regbit,
7487                 (void *)&cmd_write_reg_bit_port_id,
7488                 (void *)&cmd_write_reg_bit_reg_off,
7489                 (void *)&cmd_write_reg_bit_bit_pos,
7490                 (void *)&cmd_write_reg_bit_value,
7491                 NULL,
7492         },
7493 };
7494
7495 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7496 struct cmd_read_rxd_txd_result {
7497         cmdline_fixed_string_t read;
7498         cmdline_fixed_string_t rxd_txd;
7499         portid_t port_id;
7500         uint16_t queue_id;
7501         uint16_t desc_id;
7502 };
7503
7504 static void
7505 cmd_read_rxd_txd_parsed(void *parsed_result,
7506                         __attribute__((unused)) struct cmdline *cl,
7507                         __attribute__((unused)) void *data)
7508 {
7509         struct cmd_read_rxd_txd_result *res = parsed_result;
7510
7511         if (!strcmp(res->rxd_txd, "rxd"))
7512                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7513         else if (!strcmp(res->rxd_txd, "txd"))
7514                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7515 }
7516
7517 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7518         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7519 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7520         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7521                                  "rxd#txd");
7522 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7523         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7524 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7525         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7526 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7527         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7528
7529 cmdline_parse_inst_t cmd_read_rxd_txd = {
7530         .f = cmd_read_rxd_txd_parsed,
7531         .data = NULL,
7532         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7533         .tokens = {
7534                 (void *)&cmd_read_rxd_txd_read,
7535                 (void *)&cmd_read_rxd_txd_rxd_txd,
7536                 (void *)&cmd_read_rxd_txd_port_id,
7537                 (void *)&cmd_read_rxd_txd_queue_id,
7538                 (void *)&cmd_read_rxd_txd_desc_id,
7539                 NULL,
7540         },
7541 };
7542
7543 /* *** QUIT *** */
7544 struct cmd_quit_result {
7545         cmdline_fixed_string_t quit;
7546 };
7547
7548 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7549                             struct cmdline *cl,
7550                             __attribute__((unused)) void *data)
7551 {
7552         pmd_test_exit();
7553         cmdline_quit(cl);
7554 }
7555
7556 cmdline_parse_token_string_t cmd_quit_quit =
7557         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7558
7559 cmdline_parse_inst_t cmd_quit = {
7560         .f = cmd_quit_parsed,
7561         .data = NULL,
7562         .help_str = "quit: Exit application",
7563         .tokens = {
7564                 (void *)&cmd_quit_quit,
7565                 NULL,
7566         },
7567 };
7568
7569 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7570 struct cmd_mac_addr_result {
7571         cmdline_fixed_string_t mac_addr_cmd;
7572         cmdline_fixed_string_t what;
7573         uint16_t port_num;
7574         struct ether_addr address;
7575 };
7576
7577 static void cmd_mac_addr_parsed(void *parsed_result,
7578                 __attribute__((unused)) struct cmdline *cl,
7579                 __attribute__((unused)) void *data)
7580 {
7581         struct cmd_mac_addr_result *res = parsed_result;
7582         int ret;
7583
7584         if (strcmp(res->what, "add") == 0)
7585                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7586         else if (strcmp(res->what, "set") == 0)
7587                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7588                                                        &res->address);
7589         else
7590                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7591
7592         /* check the return value and print it if is < 0 */
7593         if(ret < 0)
7594                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7595
7596 }
7597
7598 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7599         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7600                                 "mac_addr");
7601 cmdline_parse_token_string_t cmd_mac_addr_what =
7602         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7603                                 "add#remove#set");
7604 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7605                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7606                                         UINT16);
7607 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7608                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7609
7610 cmdline_parse_inst_t cmd_mac_addr = {
7611         .f = cmd_mac_addr_parsed,
7612         .data = (void *)0,
7613         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7614                         "Add/Remove/Set MAC address on port_id",
7615         .tokens = {
7616                 (void *)&cmd_mac_addr_cmd,
7617                 (void *)&cmd_mac_addr_what,
7618                 (void *)&cmd_mac_addr_portnum,
7619                 (void *)&cmd_mac_addr_addr,
7620                 NULL,
7621         },
7622 };
7623
7624 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7625 struct cmd_eth_peer_result {
7626         cmdline_fixed_string_t set;
7627         cmdline_fixed_string_t eth_peer;
7628         portid_t port_id;
7629         cmdline_fixed_string_t peer_addr;
7630 };
7631
7632 static void cmd_set_eth_peer_parsed(void *parsed_result,
7633                         __attribute__((unused)) struct cmdline *cl,
7634                         __attribute__((unused)) void *data)
7635 {
7636                 struct cmd_eth_peer_result *res = parsed_result;
7637
7638                 if (test_done == 0) {
7639                         printf("Please stop forwarding first\n");
7640                         return;
7641                 }
7642                 if (!strcmp(res->eth_peer, "eth-peer")) {
7643                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7644                         fwd_config_setup();
7645                 }
7646 }
7647 cmdline_parse_token_string_t cmd_eth_peer_set =
7648         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7649 cmdline_parse_token_string_t cmd_eth_peer =
7650         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7651 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7652         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7653 cmdline_parse_token_string_t cmd_eth_peer_addr =
7654         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7655
7656 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7657         .f = cmd_set_eth_peer_parsed,
7658         .data = NULL,
7659         .help_str = "set eth-peer <port_id> <peer_mac>",
7660         .tokens = {
7661                 (void *)&cmd_eth_peer_set,
7662                 (void *)&cmd_eth_peer,
7663                 (void *)&cmd_eth_peer_port_id,
7664                 (void *)&cmd_eth_peer_addr,
7665                 NULL,
7666         },
7667 };
7668
7669 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7670 struct cmd_set_qmap_result {
7671         cmdline_fixed_string_t set;
7672         cmdline_fixed_string_t qmap;
7673         cmdline_fixed_string_t what;
7674         portid_t port_id;
7675         uint16_t queue_id;
7676         uint8_t map_value;
7677 };
7678
7679 static void
7680 cmd_set_qmap_parsed(void *parsed_result,
7681                        __attribute__((unused)) struct cmdline *cl,
7682                        __attribute__((unused)) void *data)
7683 {
7684         struct cmd_set_qmap_result *res = parsed_result;
7685         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7686
7687         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7688 }
7689
7690 cmdline_parse_token_string_t cmd_setqmap_set =
7691         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7692                                  set, "set");
7693 cmdline_parse_token_string_t cmd_setqmap_qmap =
7694         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7695                                  qmap, "stat_qmap");
7696 cmdline_parse_token_string_t cmd_setqmap_what =
7697         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7698                                  what, "tx#rx");
7699 cmdline_parse_token_num_t cmd_setqmap_portid =
7700         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7701                               port_id, UINT16);
7702 cmdline_parse_token_num_t cmd_setqmap_queueid =
7703         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7704                               queue_id, UINT16);
7705 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7706         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7707                               map_value, UINT8);
7708
7709 cmdline_parse_inst_t cmd_set_qmap = {
7710         .f = cmd_set_qmap_parsed,
7711         .data = NULL,
7712         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7713                 "Set statistics mapping value on tx|rx queue_id of port_id",
7714         .tokens = {
7715                 (void *)&cmd_setqmap_set,
7716                 (void *)&cmd_setqmap_qmap,
7717                 (void *)&cmd_setqmap_what,
7718                 (void *)&cmd_setqmap_portid,
7719                 (void *)&cmd_setqmap_queueid,
7720                 (void *)&cmd_setqmap_mapvalue,
7721                 NULL,
7722         },
7723 };
7724
7725 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7726 struct cmd_set_xstats_hide_zero_result {
7727         cmdline_fixed_string_t keyword;
7728         cmdline_fixed_string_t name;
7729         cmdline_fixed_string_t on_off;
7730 };
7731
7732 static void
7733 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7734                         __attribute__((unused)) struct cmdline *cl,
7735                         __attribute__((unused)) void *data)
7736 {
7737         struct cmd_set_xstats_hide_zero_result *res;
7738         uint16_t on_off = 0;
7739
7740         res = parsed_result;
7741         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7742         set_xstats_hide_zero(on_off);
7743 }
7744
7745 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7746         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7747                                  keyword, "set");
7748 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7749         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7750                                  name, "xstats-hide-zero");
7751 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7752         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7753                                  on_off, "on#off");
7754
7755 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7756         .f = cmd_set_xstats_hide_zero_parsed,
7757         .data = NULL,
7758         .help_str = "set xstats-hide-zero on|off",
7759         .tokens = {
7760                 (void *)&cmd_set_xstats_hide_zero_keyword,
7761                 (void *)&cmd_set_xstats_hide_zero_name,
7762                 (void *)&cmd_set_xstats_hide_zero_on_off,
7763                 NULL,
7764         },
7765 };
7766
7767 /* *** CONFIGURE UNICAST HASH TABLE *** */
7768 struct cmd_set_uc_hash_table {
7769         cmdline_fixed_string_t set;
7770         cmdline_fixed_string_t port;
7771         portid_t port_id;
7772         cmdline_fixed_string_t what;
7773         struct ether_addr address;
7774         cmdline_fixed_string_t mode;
7775 };
7776
7777 static void
7778 cmd_set_uc_hash_parsed(void *parsed_result,
7779                        __attribute__((unused)) struct cmdline *cl,
7780                        __attribute__((unused)) void *data)
7781 {
7782         int ret=0;
7783         struct cmd_set_uc_hash_table *res = parsed_result;
7784
7785         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7786
7787         if (strcmp(res->what, "uta") == 0)
7788                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7789                                                 &res->address,(uint8_t)is_on);
7790         if (ret < 0)
7791                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7792
7793 }
7794
7795 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7796         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7797                                  set, "set");
7798 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7799         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7800                                  port, "port");
7801 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7802         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7803                               port_id, UINT16);
7804 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7805         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7806                                  what, "uta");
7807 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7808         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7809                                 address);
7810 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7811         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7812                                  mode, "on#off");
7813
7814 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7815         .f = cmd_set_uc_hash_parsed,
7816         .data = NULL,
7817         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7818         .tokens = {
7819                 (void *)&cmd_set_uc_hash_set,
7820                 (void *)&cmd_set_uc_hash_port,
7821                 (void *)&cmd_set_uc_hash_portid,
7822                 (void *)&cmd_set_uc_hash_what,
7823                 (void *)&cmd_set_uc_hash_mac,
7824                 (void *)&cmd_set_uc_hash_mode,
7825                 NULL,
7826         },
7827 };
7828
7829 struct cmd_set_uc_all_hash_table {
7830         cmdline_fixed_string_t set;
7831         cmdline_fixed_string_t port;
7832         portid_t port_id;
7833         cmdline_fixed_string_t what;
7834         cmdline_fixed_string_t value;
7835         cmdline_fixed_string_t mode;
7836 };
7837
7838 static void
7839 cmd_set_uc_all_hash_parsed(void *parsed_result,
7840                        __attribute__((unused)) struct cmdline *cl,
7841                        __attribute__((unused)) void *data)
7842 {
7843         int ret=0;
7844         struct cmd_set_uc_all_hash_table *res = parsed_result;
7845
7846         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7847
7848         if ((strcmp(res->what, "uta") == 0) &&
7849                 (strcmp(res->value, "all") == 0))
7850                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7851         if (ret < 0)
7852                 printf("bad unicast hash table parameter,"
7853                         "return code = %d \n", ret);
7854 }
7855
7856 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7857         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7858                                  set, "set");
7859 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7860         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7861                                  port, "port");
7862 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7863         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7864                               port_id, UINT16);
7865 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7866         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7867                                  what, "uta");
7868 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7869         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7870                                 value,"all");
7871 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7872         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7873                                  mode, "on#off");
7874
7875 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7876         .f = cmd_set_uc_all_hash_parsed,
7877         .data = NULL,
7878         .help_str = "set port <port_id> uta all on|off",
7879         .tokens = {
7880                 (void *)&cmd_set_uc_all_hash_set,
7881                 (void *)&cmd_set_uc_all_hash_port,
7882                 (void *)&cmd_set_uc_all_hash_portid,
7883                 (void *)&cmd_set_uc_all_hash_what,
7884                 (void *)&cmd_set_uc_all_hash_value,
7885                 (void *)&cmd_set_uc_all_hash_mode,
7886                 NULL,
7887         },
7888 };
7889
7890 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7891 struct cmd_set_vf_macvlan_filter {
7892         cmdline_fixed_string_t set;
7893         cmdline_fixed_string_t port;
7894         portid_t port_id;
7895         cmdline_fixed_string_t vf;
7896         uint8_t vf_id;
7897         struct ether_addr address;
7898         cmdline_fixed_string_t filter_type;
7899         cmdline_fixed_string_t mode;
7900 };
7901
7902 static void
7903 cmd_set_vf_macvlan_parsed(void *parsed_result,
7904                        __attribute__((unused)) struct cmdline *cl,
7905                        __attribute__((unused)) void *data)
7906 {
7907         int is_on, ret = 0;
7908         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7909         struct rte_eth_mac_filter filter;
7910
7911         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7912
7913         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7914
7915         /* set VF MAC filter */
7916         filter.is_vf = 1;
7917
7918         /* set VF ID */
7919         filter.dst_id = res->vf_id;
7920
7921         if (!strcmp(res->filter_type, "exact-mac"))
7922                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7923         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7924                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7925         else if (!strcmp(res->filter_type, "hashmac"))
7926                 filter.filter_type = RTE_MAC_HASH_MATCH;
7927         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7928                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7929
7930         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7931
7932         if (is_on)
7933                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7934                                         RTE_ETH_FILTER_MACVLAN,
7935                                         RTE_ETH_FILTER_ADD,
7936                                          &filter);
7937         else
7938                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7939                                         RTE_ETH_FILTER_MACVLAN,
7940                                         RTE_ETH_FILTER_DELETE,
7941                                         &filter);
7942
7943         if (ret < 0)
7944                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7945
7946 }
7947
7948 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7949         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7950                                  set, "set");
7951 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7952         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7953                                  port, "port");
7954 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7955         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7956                               port_id, UINT16);
7957 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7958         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7959                                  vf, "vf");
7960 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7961         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7962                                 vf_id, UINT8);
7963 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7964         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7965                                 address);
7966 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7967         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7968                                 filter_type, "exact-mac#exact-mac-vlan"
7969                                 "#hashmac#hashmac-vlan");
7970 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7971         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7972                                  mode, "on#off");
7973
7974 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7975         .f = cmd_set_vf_macvlan_parsed,
7976         .data = NULL,
7977         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7978                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7979                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7980                 "hash match rule: hash match of MAC and exact match of VLAN",
7981         .tokens = {
7982                 (void *)&cmd_set_vf_macvlan_set,
7983                 (void *)&cmd_set_vf_macvlan_port,
7984                 (void *)&cmd_set_vf_macvlan_portid,
7985                 (void *)&cmd_set_vf_macvlan_vf,
7986                 (void *)&cmd_set_vf_macvlan_vf_id,
7987                 (void *)&cmd_set_vf_macvlan_mac,
7988                 (void *)&cmd_set_vf_macvlan_filter_type,
7989                 (void *)&cmd_set_vf_macvlan_mode,
7990                 NULL,
7991         },
7992 };
7993
7994 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7995 struct cmd_set_vf_traffic {
7996         cmdline_fixed_string_t set;
7997         cmdline_fixed_string_t port;
7998         portid_t port_id;
7999         cmdline_fixed_string_t vf;
8000         uint8_t vf_id;
8001         cmdline_fixed_string_t what;
8002         cmdline_fixed_string_t mode;
8003 };
8004
8005 static void
8006 cmd_set_vf_traffic_parsed(void *parsed_result,
8007                        __attribute__((unused)) struct cmdline *cl,
8008                        __attribute__((unused)) void *data)
8009 {
8010         struct cmd_set_vf_traffic *res = parsed_result;
8011         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8012         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8013
8014         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8015 }
8016
8017 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8018         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8019                                  set, "set");
8020 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8021         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8022                                  port, "port");
8023 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8024         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8025                               port_id, UINT16);
8026 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8027         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8028                                  vf, "vf");
8029 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8030         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8031                               vf_id, UINT8);
8032 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8033         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8034                                  what, "tx#rx");
8035 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8036         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8037                                  mode, "on#off");
8038
8039 cmdline_parse_inst_t cmd_set_vf_traffic = {
8040         .f = cmd_set_vf_traffic_parsed,
8041         .data = NULL,
8042         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8043         .tokens = {
8044                 (void *)&cmd_setvf_traffic_set,
8045                 (void *)&cmd_setvf_traffic_port,
8046                 (void *)&cmd_setvf_traffic_portid,
8047                 (void *)&cmd_setvf_traffic_vf,
8048                 (void *)&cmd_setvf_traffic_vfid,
8049                 (void *)&cmd_setvf_traffic_what,
8050                 (void *)&cmd_setvf_traffic_mode,
8051                 NULL,
8052         },
8053 };
8054
8055 /* *** CONFIGURE VF RECEIVE MODE *** */
8056 struct cmd_set_vf_rxmode {
8057         cmdline_fixed_string_t set;
8058         cmdline_fixed_string_t port;
8059         portid_t port_id;
8060         cmdline_fixed_string_t vf;
8061         uint8_t vf_id;
8062         cmdline_fixed_string_t what;
8063         cmdline_fixed_string_t mode;
8064         cmdline_fixed_string_t on;
8065 };
8066
8067 static void
8068 cmd_set_vf_rxmode_parsed(void *parsed_result,
8069                        __attribute__((unused)) struct cmdline *cl,
8070                        __attribute__((unused)) void *data)
8071 {
8072         int ret = -ENOTSUP;
8073         uint16_t rx_mode = 0;
8074         struct cmd_set_vf_rxmode *res = parsed_result;
8075
8076         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8077         if (!strcmp(res->what,"rxmode")) {
8078                 if (!strcmp(res->mode, "AUPE"))
8079                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8080                 else if (!strcmp(res->mode, "ROPE"))
8081                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8082                 else if (!strcmp(res->mode, "BAM"))
8083                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8084                 else if (!strncmp(res->mode, "MPE",3))
8085                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8086         }
8087
8088         RTE_SET_USED(is_on);
8089
8090 #ifdef RTE_LIBRTE_IXGBE_PMD
8091         if (ret == -ENOTSUP)
8092                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8093                                                   rx_mode, (uint8_t)is_on);
8094 #endif
8095 #ifdef RTE_LIBRTE_BNXT_PMD
8096         if (ret == -ENOTSUP)
8097                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8098                                                  rx_mode, (uint8_t)is_on);
8099 #endif
8100         if (ret < 0)
8101                 printf("bad VF receive mode parameter, return code = %d \n",
8102                 ret);
8103 }
8104
8105 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8106         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8107                                  set, "set");
8108 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8109         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8110                                  port, "port");
8111 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8112         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8113                               port_id, UINT16);
8114 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8115         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8116                                  vf, "vf");
8117 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8118         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8119                               vf_id, UINT8);
8120 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8121         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8122                                  what, "rxmode");
8123 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8124         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8125                                  mode, "AUPE#ROPE#BAM#MPE");
8126 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8127         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8128                                  on, "on#off");
8129
8130 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8131         .f = cmd_set_vf_rxmode_parsed,
8132         .data = NULL,
8133         .help_str = "set port <port_id> vf <vf_id> rxmode "
8134                 "AUPE|ROPE|BAM|MPE on|off",
8135         .tokens = {
8136                 (void *)&cmd_set_vf_rxmode_set,
8137                 (void *)&cmd_set_vf_rxmode_port,
8138                 (void *)&cmd_set_vf_rxmode_portid,
8139                 (void *)&cmd_set_vf_rxmode_vf,
8140                 (void *)&cmd_set_vf_rxmode_vfid,
8141                 (void *)&cmd_set_vf_rxmode_what,
8142                 (void *)&cmd_set_vf_rxmode_mode,
8143                 (void *)&cmd_set_vf_rxmode_on,
8144                 NULL,
8145         },
8146 };
8147
8148 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8149 struct cmd_vf_mac_addr_result {
8150         cmdline_fixed_string_t mac_addr_cmd;
8151         cmdline_fixed_string_t what;
8152         cmdline_fixed_string_t port;
8153         uint16_t port_num;
8154         cmdline_fixed_string_t vf;
8155         uint8_t vf_num;
8156         struct ether_addr address;
8157 };
8158
8159 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8160                 __attribute__((unused)) struct cmdline *cl,
8161                 __attribute__((unused)) void *data)
8162 {
8163         struct cmd_vf_mac_addr_result *res = parsed_result;
8164         int ret = -ENOTSUP;
8165
8166         if (strcmp(res->what, "add") != 0)
8167                 return;
8168
8169 #ifdef RTE_LIBRTE_I40E_PMD
8170         if (ret == -ENOTSUP)
8171                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8172                                                    &res->address);
8173 #endif
8174 #ifdef RTE_LIBRTE_BNXT_PMD
8175         if (ret == -ENOTSUP)
8176                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8177                                                 res->vf_num);
8178 #endif
8179
8180         if(ret < 0)
8181                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8182
8183 }
8184
8185 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8186         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8187                                 mac_addr_cmd,"mac_addr");
8188 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8189         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8190                                 what,"add");
8191 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8192         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8193                                 port,"port");
8194 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8195         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8196                                 port_num, UINT16);
8197 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8198         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8199                                 vf,"vf");
8200 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8201         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8202                                 vf_num, UINT8);
8203 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8204         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8205                                 address);
8206
8207 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8208         .f = cmd_vf_mac_addr_parsed,
8209         .data = (void *)0,
8210         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8211                 "Add MAC address filtering for a VF on port_id",
8212         .tokens = {
8213                 (void *)&cmd_vf_mac_addr_cmd,
8214                 (void *)&cmd_vf_mac_addr_what,
8215                 (void *)&cmd_vf_mac_addr_port,
8216                 (void *)&cmd_vf_mac_addr_portnum,
8217                 (void *)&cmd_vf_mac_addr_vf,
8218                 (void *)&cmd_vf_mac_addr_vfnum,
8219                 (void *)&cmd_vf_mac_addr_addr,
8220                 NULL,
8221         },
8222 };
8223
8224 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8225 struct cmd_vf_rx_vlan_filter {
8226         cmdline_fixed_string_t rx_vlan;
8227         cmdline_fixed_string_t what;
8228         uint16_t vlan_id;
8229         cmdline_fixed_string_t port;
8230         portid_t port_id;
8231         cmdline_fixed_string_t vf;
8232         uint64_t vf_mask;
8233 };
8234
8235 static void
8236 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8237                           __attribute__((unused)) struct cmdline *cl,
8238                           __attribute__((unused)) void *data)
8239 {
8240         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8241         int ret = -ENOTSUP;
8242
8243         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8244
8245 #ifdef RTE_LIBRTE_IXGBE_PMD
8246         if (ret == -ENOTSUP)
8247                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8248                                 res->vlan_id, res->vf_mask, is_add);
8249 #endif
8250 #ifdef RTE_LIBRTE_I40E_PMD
8251         if (ret == -ENOTSUP)
8252                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8253                                 res->vlan_id, res->vf_mask, is_add);
8254 #endif
8255 #ifdef RTE_LIBRTE_BNXT_PMD
8256         if (ret == -ENOTSUP)
8257                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8258                                 res->vlan_id, res->vf_mask, is_add);
8259 #endif
8260
8261         switch (ret) {
8262         case 0:
8263                 break;
8264         case -EINVAL:
8265                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8266                                 res->vlan_id, res->vf_mask);
8267                 break;
8268         case -ENODEV:
8269                 printf("invalid port_id %d\n", res->port_id);
8270                 break;
8271         case -ENOTSUP:
8272                 printf("function not implemented or supported\n");
8273                 break;
8274         default:
8275                 printf("programming error: (%s)\n", strerror(-ret));
8276         }
8277 }
8278
8279 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8280         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8281                                  rx_vlan, "rx_vlan");
8282 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8283         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8284                                  what, "add#rm");
8285 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8286         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8287                               vlan_id, UINT16);
8288 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8289         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8290                                  port, "port");
8291 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8292         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8293                               port_id, UINT16);
8294 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8295         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8296                                  vf, "vf");
8297 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8298         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8299                               vf_mask, UINT64);
8300
8301 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8302         .f = cmd_vf_rx_vlan_filter_parsed,
8303         .data = NULL,
8304         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8305                 "(vf_mask = hexadecimal VF mask)",
8306         .tokens = {
8307                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8308                 (void *)&cmd_vf_rx_vlan_filter_what,
8309                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8310                 (void *)&cmd_vf_rx_vlan_filter_port,
8311                 (void *)&cmd_vf_rx_vlan_filter_portid,
8312                 (void *)&cmd_vf_rx_vlan_filter_vf,
8313                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8314                 NULL,
8315         },
8316 };
8317
8318 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8319 struct cmd_queue_rate_limit_result {
8320         cmdline_fixed_string_t set;
8321         cmdline_fixed_string_t port;
8322         uint16_t port_num;
8323         cmdline_fixed_string_t queue;
8324         uint8_t queue_num;
8325         cmdline_fixed_string_t rate;
8326         uint16_t rate_num;
8327 };
8328
8329 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8330                 __attribute__((unused)) struct cmdline *cl,
8331                 __attribute__((unused)) void *data)
8332 {
8333         struct cmd_queue_rate_limit_result *res = parsed_result;
8334         int ret = 0;
8335
8336         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8337                 && (strcmp(res->queue, "queue") == 0)
8338                 && (strcmp(res->rate, "rate") == 0))
8339                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8340                                         res->rate_num);
8341         if (ret < 0)
8342                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8343
8344 }
8345
8346 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8347         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8348                                 set, "set");
8349 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8350         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8351                                 port, "port");
8352 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8353         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8354                                 port_num, UINT16);
8355 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8356         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8357                                 queue, "queue");
8358 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8359         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8360                                 queue_num, UINT8);
8361 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8362         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8363                                 rate, "rate");
8364 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8365         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8366                                 rate_num, UINT16);
8367
8368 cmdline_parse_inst_t cmd_queue_rate_limit = {
8369         .f = cmd_queue_rate_limit_parsed,
8370         .data = (void *)0,
8371         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8372                 "Set rate limit for a queue on port_id",
8373         .tokens = {
8374                 (void *)&cmd_queue_rate_limit_set,
8375                 (void *)&cmd_queue_rate_limit_port,
8376                 (void *)&cmd_queue_rate_limit_portnum,
8377                 (void *)&cmd_queue_rate_limit_queue,
8378                 (void *)&cmd_queue_rate_limit_queuenum,
8379                 (void *)&cmd_queue_rate_limit_rate,
8380                 (void *)&cmd_queue_rate_limit_ratenum,
8381                 NULL,
8382         },
8383 };
8384
8385 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8386 struct cmd_vf_rate_limit_result {
8387         cmdline_fixed_string_t set;
8388         cmdline_fixed_string_t port;
8389         uint16_t port_num;
8390         cmdline_fixed_string_t vf;
8391         uint8_t vf_num;
8392         cmdline_fixed_string_t rate;
8393         uint16_t rate_num;
8394         cmdline_fixed_string_t q_msk;
8395         uint64_t q_msk_val;
8396 };
8397
8398 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8399                 __attribute__((unused)) struct cmdline *cl,
8400                 __attribute__((unused)) void *data)
8401 {
8402         struct cmd_vf_rate_limit_result *res = parsed_result;
8403         int ret = 0;
8404
8405         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8406                 && (strcmp(res->vf, "vf") == 0)
8407                 && (strcmp(res->rate, "rate") == 0)
8408                 && (strcmp(res->q_msk, "queue_mask") == 0))
8409                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8410                                         res->rate_num, res->q_msk_val);
8411         if (ret < 0)
8412                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8413
8414 }
8415
8416 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8417         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8418                                 set, "set");
8419 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8420         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8421                                 port, "port");
8422 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8423         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8424                                 port_num, UINT16);
8425 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8426         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8427                                 vf, "vf");
8428 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8429         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8430                                 vf_num, UINT8);
8431 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8432         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8433                                 rate, "rate");
8434 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8435         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8436                                 rate_num, UINT16);
8437 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8438         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8439                                 q_msk, "queue_mask");
8440 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8441         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8442                                 q_msk_val, UINT64);
8443
8444 cmdline_parse_inst_t cmd_vf_rate_limit = {
8445         .f = cmd_vf_rate_limit_parsed,
8446         .data = (void *)0,
8447         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8448                 "queue_mask <queue_mask_value>: "
8449                 "Set rate limit for queues of VF on port_id",
8450         .tokens = {
8451                 (void *)&cmd_vf_rate_limit_set,
8452                 (void *)&cmd_vf_rate_limit_port,
8453                 (void *)&cmd_vf_rate_limit_portnum,
8454                 (void *)&cmd_vf_rate_limit_vf,
8455                 (void *)&cmd_vf_rate_limit_vfnum,
8456                 (void *)&cmd_vf_rate_limit_rate,
8457                 (void *)&cmd_vf_rate_limit_ratenum,
8458                 (void *)&cmd_vf_rate_limit_q_msk,
8459                 (void *)&cmd_vf_rate_limit_q_msk_val,
8460                 NULL,
8461         },
8462 };
8463
8464 /* *** ADD TUNNEL FILTER OF A PORT *** */
8465 struct cmd_tunnel_filter_result {
8466         cmdline_fixed_string_t cmd;
8467         cmdline_fixed_string_t what;
8468         portid_t port_id;
8469         struct ether_addr outer_mac;
8470         struct ether_addr inner_mac;
8471         cmdline_ipaddr_t ip_value;
8472         uint16_t inner_vlan;
8473         cmdline_fixed_string_t tunnel_type;
8474         cmdline_fixed_string_t filter_type;
8475         uint32_t tenant_id;
8476         uint16_t queue_num;
8477 };
8478
8479 static void
8480 cmd_tunnel_filter_parsed(void *parsed_result,
8481                           __attribute__((unused)) struct cmdline *cl,
8482                           __attribute__((unused)) void *data)
8483 {
8484         struct cmd_tunnel_filter_result *res = parsed_result;
8485         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8486         int ret = 0;
8487
8488         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8489
8490         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8491         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8492         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8493
8494         if (res->ip_value.family == AF_INET) {
8495                 tunnel_filter_conf.ip_addr.ipv4_addr =
8496                         res->ip_value.addr.ipv4.s_addr;
8497                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8498         } else {
8499                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8500                         &(res->ip_value.addr.ipv6),
8501                         sizeof(struct in6_addr));
8502                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8503         }
8504
8505         if (!strcmp(res->filter_type, "imac-ivlan"))
8506                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8507         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8508                 tunnel_filter_conf.filter_type =
8509                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8510         else if (!strcmp(res->filter_type, "imac-tenid"))
8511                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8512         else if (!strcmp(res->filter_type, "imac"))
8513                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8514         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8515                 tunnel_filter_conf.filter_type =
8516                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8517         else if (!strcmp(res->filter_type, "oip"))
8518                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8519         else if (!strcmp(res->filter_type, "iip"))
8520                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8521         else {
8522                 printf("The filter type is not supported");
8523                 return;
8524         }
8525
8526         if (!strcmp(res->tunnel_type, "vxlan"))
8527                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8528         else if (!strcmp(res->tunnel_type, "nvgre"))
8529                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8530         else if (!strcmp(res->tunnel_type, "ipingre"))
8531                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8532         else {
8533                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8534                 return;
8535         }
8536
8537         tunnel_filter_conf.tenant_id = res->tenant_id;
8538         tunnel_filter_conf.queue_id = res->queue_num;
8539         if (!strcmp(res->what, "add"))
8540                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8541                                         RTE_ETH_FILTER_TUNNEL,
8542                                         RTE_ETH_FILTER_ADD,
8543                                         &tunnel_filter_conf);
8544         else
8545                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8546                                         RTE_ETH_FILTER_TUNNEL,
8547                                         RTE_ETH_FILTER_DELETE,
8548                                         &tunnel_filter_conf);
8549         if (ret < 0)
8550                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8551                                 strerror(-ret));
8552
8553 }
8554 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8555         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8556         cmd, "tunnel_filter");
8557 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8558         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8559         what, "add#rm");
8560 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8561         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8562         port_id, UINT16);
8563 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8564         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8565         outer_mac);
8566 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8567         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8568         inner_mac);
8569 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8570         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8571         inner_vlan, UINT16);
8572 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8573         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8574         ip_value);
8575 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8576         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8577         tunnel_type, "vxlan#nvgre#ipingre");
8578
8579 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8580         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8581         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8582                 "imac#omac-imac-tenid");
8583 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8584         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8585         tenant_id, UINT32);
8586 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8587         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8588         queue_num, UINT16);
8589
8590 cmdline_parse_inst_t cmd_tunnel_filter = {
8591         .f = cmd_tunnel_filter_parsed,
8592         .data = (void *)0,
8593         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8594                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8595                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8596                 "<queue_id>: Add/Rm tunnel filter of a port",
8597         .tokens = {
8598                 (void *)&cmd_tunnel_filter_cmd,
8599                 (void *)&cmd_tunnel_filter_what,
8600                 (void *)&cmd_tunnel_filter_port_id,
8601                 (void *)&cmd_tunnel_filter_outer_mac,
8602                 (void *)&cmd_tunnel_filter_inner_mac,
8603                 (void *)&cmd_tunnel_filter_ip_value,
8604                 (void *)&cmd_tunnel_filter_innner_vlan,
8605                 (void *)&cmd_tunnel_filter_tunnel_type,
8606                 (void *)&cmd_tunnel_filter_filter_type,
8607                 (void *)&cmd_tunnel_filter_tenant_id,
8608                 (void *)&cmd_tunnel_filter_queue_num,
8609                 NULL,
8610         },
8611 };
8612
8613 /* *** CONFIGURE TUNNEL UDP PORT *** */
8614 struct cmd_tunnel_udp_config {
8615         cmdline_fixed_string_t cmd;
8616         cmdline_fixed_string_t what;
8617         uint16_t udp_port;
8618         portid_t port_id;
8619 };
8620
8621 static void
8622 cmd_tunnel_udp_config_parsed(void *parsed_result,
8623                           __attribute__((unused)) struct cmdline *cl,
8624                           __attribute__((unused)) void *data)
8625 {
8626         struct cmd_tunnel_udp_config *res = parsed_result;
8627         struct rte_eth_udp_tunnel tunnel_udp;
8628         int ret;
8629
8630         tunnel_udp.udp_port = res->udp_port;
8631
8632         if (!strcmp(res->cmd, "rx_vxlan_port"))
8633                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8634
8635         if (!strcmp(res->what, "add"))
8636                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8637                                                       &tunnel_udp);
8638         else
8639                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8640                                                          &tunnel_udp);
8641
8642         if (ret < 0)
8643                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8644 }
8645
8646 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8647         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8648                                 cmd, "rx_vxlan_port");
8649 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8650         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8651                                 what, "add#rm");
8652 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8653         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8654                                 udp_port, UINT16);
8655 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8656         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8657                                 port_id, UINT16);
8658
8659 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8660         .f = cmd_tunnel_udp_config_parsed,
8661         .data = (void *)0,
8662         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8663                 "Add/Remove a tunneling UDP port filter",
8664         .tokens = {
8665                 (void *)&cmd_tunnel_udp_config_cmd,
8666                 (void *)&cmd_tunnel_udp_config_what,
8667                 (void *)&cmd_tunnel_udp_config_udp_port,
8668                 (void *)&cmd_tunnel_udp_config_port_id,
8669                 NULL,
8670         },
8671 };
8672
8673 struct cmd_config_tunnel_udp_port {
8674         cmdline_fixed_string_t port;
8675         cmdline_fixed_string_t config;
8676         portid_t port_id;
8677         cmdline_fixed_string_t udp_tunnel_port;
8678         cmdline_fixed_string_t action;
8679         cmdline_fixed_string_t tunnel_type;
8680         uint16_t udp_port;
8681 };
8682
8683 static void
8684 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8685                                __attribute__((unused)) struct cmdline *cl,
8686                                __attribute__((unused)) void *data)
8687 {
8688         struct cmd_config_tunnel_udp_port *res = parsed_result;
8689         struct rte_eth_udp_tunnel tunnel_udp;
8690         int ret = 0;
8691
8692         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8693                 return;
8694
8695         tunnel_udp.udp_port = res->udp_port;
8696
8697         if (!strcmp(res->tunnel_type, "vxlan")) {
8698                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8699         } else if (!strcmp(res->tunnel_type, "geneve")) {
8700                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8701         } else {
8702                 printf("Invalid tunnel type\n");
8703                 return;
8704         }
8705
8706         if (!strcmp(res->action, "add"))
8707                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8708                                                       &tunnel_udp);
8709         else
8710                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8711                                                          &tunnel_udp);
8712
8713         if (ret < 0)
8714                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8715 }
8716
8717 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8718         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8719                                  "port");
8720 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8721         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8722                                  "config");
8723 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8724         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8725                               UINT16);
8726 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8727         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8728                                  udp_tunnel_port,
8729                                  "udp_tunnel_port");
8730 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8731         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8732                                  "add#rm");
8733 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8734         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8735                                  "vxlan#geneve");
8736 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8737         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8738                               UINT16);
8739
8740 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8741         .f = cmd_cfg_tunnel_udp_port_parsed,
8742         .data = NULL,
8743         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8744         .tokens = {
8745                 (void *)&cmd_config_tunnel_udp_port_port,
8746                 (void *)&cmd_config_tunnel_udp_port_config,
8747                 (void *)&cmd_config_tunnel_udp_port_port_id,
8748                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8749                 (void *)&cmd_config_tunnel_udp_port_action,
8750                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8751                 (void *)&cmd_config_tunnel_udp_port_value,
8752                 NULL,
8753         },
8754 };
8755
8756 /* *** GLOBAL CONFIG *** */
8757 struct cmd_global_config_result {
8758         cmdline_fixed_string_t cmd;
8759         portid_t port_id;
8760         cmdline_fixed_string_t cfg_type;
8761         uint8_t len;
8762 };
8763
8764 static void
8765 cmd_global_config_parsed(void *parsed_result,
8766                          __attribute__((unused)) struct cmdline *cl,
8767                          __attribute__((unused)) void *data)
8768 {
8769         struct cmd_global_config_result *res = parsed_result;
8770         struct rte_eth_global_cfg conf;
8771         int ret;
8772
8773         memset(&conf, 0, sizeof(conf));
8774         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8775         conf.cfg.gre_key_len = res->len;
8776         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8777                                       RTE_ETH_FILTER_SET, &conf);
8778         if (ret != 0)
8779                 printf("Global config error\n");
8780 }
8781
8782 cmdline_parse_token_string_t cmd_global_config_cmd =
8783         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8784                 "global_config");
8785 cmdline_parse_token_num_t cmd_global_config_port_id =
8786         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8787                                UINT16);
8788 cmdline_parse_token_string_t cmd_global_config_type =
8789         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8790                 cfg_type, "gre-key-len");
8791 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8792         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8793                 len, UINT8);
8794
8795 cmdline_parse_inst_t cmd_global_config = {
8796         .f = cmd_global_config_parsed,
8797         .data = (void *)NULL,
8798         .help_str = "global_config <port_id> gre-key-len <key_len>",
8799         .tokens = {
8800                 (void *)&cmd_global_config_cmd,
8801                 (void *)&cmd_global_config_port_id,
8802                 (void *)&cmd_global_config_type,
8803                 (void *)&cmd_global_config_gre_key_len,
8804                 NULL,
8805         },
8806 };
8807
8808 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8809 struct cmd_set_mirror_mask_result {
8810         cmdline_fixed_string_t set;
8811         cmdline_fixed_string_t port;
8812         portid_t port_id;
8813         cmdline_fixed_string_t mirror;
8814         uint8_t rule_id;
8815         cmdline_fixed_string_t what;
8816         cmdline_fixed_string_t value;
8817         cmdline_fixed_string_t dstpool;
8818         uint8_t dstpool_id;
8819         cmdline_fixed_string_t on;
8820 };
8821
8822 cmdline_parse_token_string_t cmd_mirror_mask_set =
8823         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8824                                 set, "set");
8825 cmdline_parse_token_string_t cmd_mirror_mask_port =
8826         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8827                                 port, "port");
8828 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8829         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8830                                 port_id, UINT16);
8831 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8832         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8833                                 mirror, "mirror-rule");
8834 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8835         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8836                                 rule_id, UINT8);
8837 cmdline_parse_token_string_t cmd_mirror_mask_what =
8838         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8839                                 what, "pool-mirror-up#pool-mirror-down"
8840                                       "#vlan-mirror");
8841 cmdline_parse_token_string_t cmd_mirror_mask_value =
8842         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8843                                 value, NULL);
8844 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8845         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8846                                 dstpool, "dst-pool");
8847 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8848         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8849                                 dstpool_id, UINT8);
8850 cmdline_parse_token_string_t cmd_mirror_mask_on =
8851         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8852                                 on, "on#off");
8853
8854 static void
8855 cmd_set_mirror_mask_parsed(void *parsed_result,
8856                        __attribute__((unused)) struct cmdline *cl,
8857                        __attribute__((unused)) void *data)
8858 {
8859         int ret,nb_item,i;
8860         struct cmd_set_mirror_mask_result *res = parsed_result;
8861         struct rte_eth_mirror_conf mr_conf;
8862
8863         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8864
8865         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8866
8867         mr_conf.dst_pool = res->dstpool_id;
8868
8869         if (!strcmp(res->what, "pool-mirror-up")) {
8870                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8871                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8872         } else if (!strcmp(res->what, "pool-mirror-down")) {
8873                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8874                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8875         } else if (!strcmp(res->what, "vlan-mirror")) {
8876                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8877                 nb_item = parse_item_list(res->value, "vlan",
8878                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8879                 if (nb_item <= 0)
8880                         return;
8881
8882                 for (i = 0; i < nb_item; i++) {
8883                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8884                                 printf("Invalid vlan_id: must be < 4096\n");
8885                                 return;
8886                         }
8887
8888                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8889                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8890                 }
8891         }
8892
8893         if (!strcmp(res->on, "on"))
8894                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8895                                                 res->rule_id, 1);
8896         else
8897                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8898                                                 res->rule_id, 0);
8899         if (ret < 0)
8900                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8901 }
8902
8903 cmdline_parse_inst_t cmd_set_mirror_mask = {
8904                 .f = cmd_set_mirror_mask_parsed,
8905                 .data = NULL,
8906                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8907                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8908                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8909                 .tokens = {
8910                         (void *)&cmd_mirror_mask_set,
8911                         (void *)&cmd_mirror_mask_port,
8912                         (void *)&cmd_mirror_mask_portid,
8913                         (void *)&cmd_mirror_mask_mirror,
8914                         (void *)&cmd_mirror_mask_ruleid,
8915                         (void *)&cmd_mirror_mask_what,
8916                         (void *)&cmd_mirror_mask_value,
8917                         (void *)&cmd_mirror_mask_dstpool,
8918                         (void *)&cmd_mirror_mask_poolid,
8919                         (void *)&cmd_mirror_mask_on,
8920                         NULL,
8921                 },
8922 };
8923
8924 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8925 struct cmd_set_mirror_link_result {
8926         cmdline_fixed_string_t set;
8927         cmdline_fixed_string_t port;
8928         portid_t port_id;
8929         cmdline_fixed_string_t mirror;
8930         uint8_t rule_id;
8931         cmdline_fixed_string_t what;
8932         cmdline_fixed_string_t dstpool;
8933         uint8_t dstpool_id;
8934         cmdline_fixed_string_t on;
8935 };
8936
8937 cmdline_parse_token_string_t cmd_mirror_link_set =
8938         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8939                                  set, "set");
8940 cmdline_parse_token_string_t cmd_mirror_link_port =
8941         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8942                                 port, "port");
8943 cmdline_parse_token_num_t cmd_mirror_link_portid =
8944         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8945                                 port_id, UINT16);
8946 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8947         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8948                                 mirror, "mirror-rule");
8949 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8950         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8951                             rule_id, UINT8);
8952 cmdline_parse_token_string_t cmd_mirror_link_what =
8953         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8954                                 what, "uplink-mirror#downlink-mirror");
8955 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8956         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8957                                 dstpool, "dst-pool");
8958 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8959         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8960                                 dstpool_id, UINT8);
8961 cmdline_parse_token_string_t cmd_mirror_link_on =
8962         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8963                                 on, "on#off");
8964
8965 static void
8966 cmd_set_mirror_link_parsed(void *parsed_result,
8967                        __attribute__((unused)) struct cmdline *cl,
8968                        __attribute__((unused)) void *data)
8969 {
8970         int ret;
8971         struct cmd_set_mirror_link_result *res = parsed_result;
8972         struct rte_eth_mirror_conf mr_conf;
8973
8974         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8975         if (!strcmp(res->what, "uplink-mirror"))
8976                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8977         else
8978                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8979
8980         mr_conf.dst_pool = res->dstpool_id;
8981
8982         if (!strcmp(res->on, "on"))
8983                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8984                                                 res->rule_id, 1);
8985         else
8986                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8987                                                 res->rule_id, 0);
8988
8989         /* check the return value and print it if is < 0 */
8990         if (ret < 0)
8991                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8992
8993 }
8994
8995 cmdline_parse_inst_t cmd_set_mirror_link = {
8996                 .f = cmd_set_mirror_link_parsed,
8997                 .data = NULL,
8998                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8999                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9000                 .tokens = {
9001                         (void *)&cmd_mirror_link_set,
9002                         (void *)&cmd_mirror_link_port,
9003                         (void *)&cmd_mirror_link_portid,
9004                         (void *)&cmd_mirror_link_mirror,
9005                         (void *)&cmd_mirror_link_ruleid,
9006                         (void *)&cmd_mirror_link_what,
9007                         (void *)&cmd_mirror_link_dstpool,
9008                         (void *)&cmd_mirror_link_poolid,
9009                         (void *)&cmd_mirror_link_on,
9010                         NULL,
9011                 },
9012 };
9013
9014 /* *** RESET VM MIRROR RULE *** */
9015 struct cmd_rm_mirror_rule_result {
9016         cmdline_fixed_string_t reset;
9017         cmdline_fixed_string_t port;
9018         portid_t port_id;
9019         cmdline_fixed_string_t mirror;
9020         uint8_t rule_id;
9021 };
9022
9023 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9024         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9025                                  reset, "reset");
9026 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9027         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9028                                 port, "port");
9029 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9030         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9031                                 port_id, UINT16);
9032 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9033         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9034                                 mirror, "mirror-rule");
9035 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9036         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9037                                 rule_id, UINT8);
9038
9039 static void
9040 cmd_reset_mirror_rule_parsed(void *parsed_result,
9041                        __attribute__((unused)) struct cmdline *cl,
9042                        __attribute__((unused)) void *data)
9043 {
9044         int ret;
9045         struct cmd_set_mirror_link_result *res = parsed_result;
9046         /* check rule_id */
9047         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9048         if(ret < 0)
9049                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9050 }
9051
9052 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9053                 .f = cmd_reset_mirror_rule_parsed,
9054                 .data = NULL,
9055                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9056                 .tokens = {
9057                         (void *)&cmd_rm_mirror_rule_reset,
9058                         (void *)&cmd_rm_mirror_rule_port,
9059                         (void *)&cmd_rm_mirror_rule_portid,
9060                         (void *)&cmd_rm_mirror_rule_mirror,
9061                         (void *)&cmd_rm_mirror_rule_ruleid,
9062                         NULL,
9063                 },
9064 };
9065
9066 /* ******************************************************************************** */
9067
9068 struct cmd_dump_result {
9069         cmdline_fixed_string_t dump;
9070 };
9071
9072 static void
9073 dump_struct_sizes(void)
9074 {
9075 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9076         DUMP_SIZE(struct rte_mbuf);
9077         DUMP_SIZE(struct rte_mempool);
9078         DUMP_SIZE(struct rte_ring);
9079 #undef DUMP_SIZE
9080 }
9081
9082 static void cmd_dump_parsed(void *parsed_result,
9083                             __attribute__((unused)) struct cmdline *cl,
9084                             __attribute__((unused)) void *data)
9085 {
9086         struct cmd_dump_result *res = parsed_result;
9087
9088         if (!strcmp(res->dump, "dump_physmem"))
9089                 rte_dump_physmem_layout(stdout);
9090         else if (!strcmp(res->dump, "dump_memzone"))
9091                 rte_memzone_dump(stdout);
9092         else if (!strcmp(res->dump, "dump_struct_sizes"))
9093                 dump_struct_sizes();
9094         else if (!strcmp(res->dump, "dump_ring"))
9095                 rte_ring_list_dump(stdout);
9096         else if (!strcmp(res->dump, "dump_mempool"))
9097                 rte_mempool_list_dump(stdout);
9098         else if (!strcmp(res->dump, "dump_devargs"))
9099                 rte_devargs_dump(stdout);
9100         else if (!strcmp(res->dump, "dump_log_types"))
9101                 rte_log_dump(stdout);
9102 }
9103
9104 cmdline_parse_token_string_t cmd_dump_dump =
9105         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9106                 "dump_physmem#"
9107                 "dump_memzone#"
9108                 "dump_struct_sizes#"
9109                 "dump_ring#"
9110                 "dump_mempool#"
9111                 "dump_devargs#"
9112                 "dump_log_types");
9113
9114 cmdline_parse_inst_t cmd_dump = {
9115         .f = cmd_dump_parsed,  /* function to call */
9116         .data = NULL,      /* 2nd arg of func */
9117         .help_str = "Dump status",
9118         .tokens = {        /* token list, NULL terminated */
9119                 (void *)&cmd_dump_dump,
9120                 NULL,
9121         },
9122 };
9123
9124 /* ******************************************************************************** */
9125
9126 struct cmd_dump_one_result {
9127         cmdline_fixed_string_t dump;
9128         cmdline_fixed_string_t name;
9129 };
9130
9131 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9132                                 __attribute__((unused)) void *data)
9133 {
9134         struct cmd_dump_one_result *res = parsed_result;
9135
9136         if (!strcmp(res->dump, "dump_ring")) {
9137                 struct rte_ring *r;
9138                 r = rte_ring_lookup(res->name);
9139                 if (r == NULL) {
9140                         cmdline_printf(cl, "Cannot find ring\n");
9141                         return;
9142                 }
9143                 rte_ring_dump(stdout, r);
9144         } else if (!strcmp(res->dump, "dump_mempool")) {
9145                 struct rte_mempool *mp;
9146                 mp = rte_mempool_lookup(res->name);
9147                 if (mp == NULL) {
9148                         cmdline_printf(cl, "Cannot find mempool\n");
9149                         return;
9150                 }
9151                 rte_mempool_dump(stdout, mp);
9152         }
9153 }
9154
9155 cmdline_parse_token_string_t cmd_dump_one_dump =
9156         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9157                                  "dump_ring#dump_mempool");
9158
9159 cmdline_parse_token_string_t cmd_dump_one_name =
9160         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9161
9162 cmdline_parse_inst_t cmd_dump_one = {
9163         .f = cmd_dump_one_parsed,  /* function to call */
9164         .data = NULL,      /* 2nd arg of func */
9165         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9166         .tokens = {        /* token list, NULL terminated */
9167                 (void *)&cmd_dump_one_dump,
9168                 (void *)&cmd_dump_one_name,
9169                 NULL,
9170         },
9171 };
9172
9173 /* *** Add/Del syn filter *** */
9174 struct cmd_syn_filter_result {
9175         cmdline_fixed_string_t filter;
9176         portid_t port_id;
9177         cmdline_fixed_string_t ops;
9178         cmdline_fixed_string_t priority;
9179         cmdline_fixed_string_t high;
9180         cmdline_fixed_string_t queue;
9181         uint16_t queue_id;
9182 };
9183
9184 static void
9185 cmd_syn_filter_parsed(void *parsed_result,
9186                         __attribute__((unused)) struct cmdline *cl,
9187                         __attribute__((unused)) void *data)
9188 {
9189         struct cmd_syn_filter_result *res = parsed_result;
9190         struct rte_eth_syn_filter syn_filter;
9191         int ret = 0;
9192
9193         ret = rte_eth_dev_filter_supported(res->port_id,
9194                                         RTE_ETH_FILTER_SYN);
9195         if (ret < 0) {
9196                 printf("syn filter is not supported on port %u.\n",
9197                                 res->port_id);
9198                 return;
9199         }
9200
9201         memset(&syn_filter, 0, sizeof(syn_filter));
9202
9203         if (!strcmp(res->ops, "add")) {
9204                 if (!strcmp(res->high, "high"))
9205                         syn_filter.hig_pri = 1;
9206                 else
9207                         syn_filter.hig_pri = 0;
9208
9209                 syn_filter.queue = res->queue_id;
9210                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9211                                                 RTE_ETH_FILTER_SYN,
9212                                                 RTE_ETH_FILTER_ADD,
9213                                                 &syn_filter);
9214         } else
9215                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9216                                                 RTE_ETH_FILTER_SYN,
9217                                                 RTE_ETH_FILTER_DELETE,
9218                                                 &syn_filter);
9219
9220         if (ret < 0)
9221                 printf("syn filter programming error: (%s)\n",
9222                                 strerror(-ret));
9223 }
9224
9225 cmdline_parse_token_string_t cmd_syn_filter_filter =
9226         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9227         filter, "syn_filter");
9228 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9229         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9230         port_id, UINT16);
9231 cmdline_parse_token_string_t cmd_syn_filter_ops =
9232         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9233         ops, "add#del");
9234 cmdline_parse_token_string_t cmd_syn_filter_priority =
9235         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9236                                 priority, "priority");
9237 cmdline_parse_token_string_t cmd_syn_filter_high =
9238         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9239                                 high, "high#low");
9240 cmdline_parse_token_string_t cmd_syn_filter_queue =
9241         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9242                                 queue, "queue");
9243 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9244         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9245                                 queue_id, UINT16);
9246
9247 cmdline_parse_inst_t cmd_syn_filter = {
9248         .f = cmd_syn_filter_parsed,
9249         .data = NULL,
9250         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9251                 "<queue_id>: Add/Delete syn filter",
9252         .tokens = {
9253                 (void *)&cmd_syn_filter_filter,
9254                 (void *)&cmd_syn_filter_port_id,
9255                 (void *)&cmd_syn_filter_ops,
9256                 (void *)&cmd_syn_filter_priority,
9257                 (void *)&cmd_syn_filter_high,
9258                 (void *)&cmd_syn_filter_queue,
9259                 (void *)&cmd_syn_filter_queue_id,
9260                 NULL,
9261         },
9262 };
9263
9264 /* *** queue region set *** */
9265 struct cmd_queue_region_result {
9266         cmdline_fixed_string_t set;
9267         cmdline_fixed_string_t port;
9268         portid_t port_id;
9269         cmdline_fixed_string_t cmd;
9270         cmdline_fixed_string_t region;
9271         uint8_t  region_id;
9272         cmdline_fixed_string_t queue_start_index;
9273         uint8_t  queue_id;
9274         cmdline_fixed_string_t queue_num;
9275         uint8_t  queue_num_value;
9276 };
9277
9278 static void
9279 cmd_queue_region_parsed(void *parsed_result,
9280                         __attribute__((unused)) struct cmdline *cl,
9281                         __attribute__((unused)) void *data)
9282 {
9283         struct cmd_queue_region_result *res = parsed_result;
9284         int ret = -ENOTSUP;
9285 #ifdef RTE_LIBRTE_I40E_PMD
9286         struct rte_pmd_i40e_queue_region_conf region_conf;
9287         enum rte_pmd_i40e_queue_region_op op_type;
9288 #endif
9289
9290         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9291                 return;
9292
9293 #ifdef RTE_LIBRTE_I40E_PMD
9294         memset(&region_conf, 0, sizeof(region_conf));
9295         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9296         region_conf.region_id = res->region_id;
9297         region_conf.queue_num = res->queue_num_value;
9298         region_conf.queue_start_index = res->queue_id;
9299
9300         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9301                                 op_type, &region_conf);
9302 #endif
9303
9304         switch (ret) {
9305         case 0:
9306                 break;
9307         case -ENOTSUP:
9308                 printf("function not implemented or supported\n");
9309                 break;
9310         default:
9311                 printf("queue region config error: (%s)\n", strerror(-ret));
9312         }
9313 }
9314
9315 cmdline_parse_token_string_t cmd_queue_region_set =
9316 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9317                 set, "set");
9318 cmdline_parse_token_string_t cmd_queue_region_port =
9319         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9320 cmdline_parse_token_num_t cmd_queue_region_port_id =
9321         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9322                                 port_id, UINT16);
9323 cmdline_parse_token_string_t cmd_queue_region_cmd =
9324         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9325                                  cmd, "queue-region");
9326 cmdline_parse_token_string_t cmd_queue_region_id =
9327         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9328                                 region, "region_id");
9329 cmdline_parse_token_num_t cmd_queue_region_index =
9330         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9331                                 region_id, UINT8);
9332 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9333         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9334                                 queue_start_index, "queue_start_index");
9335 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9336         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9337                                 queue_id, UINT8);
9338 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9339         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9340                                 queue_num, "queue_num");
9341 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9342         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9343                                 queue_num_value, UINT8);
9344
9345 cmdline_parse_inst_t cmd_queue_region = {
9346         .f = cmd_queue_region_parsed,
9347         .data = NULL,
9348         .help_str = "set port <port_id> queue-region region_id <value> "
9349                 "queue_start_index <value> queue_num <value>: Set a queue region",
9350         .tokens = {
9351                 (void *)&cmd_queue_region_set,
9352                 (void *)&cmd_queue_region_port,
9353                 (void *)&cmd_queue_region_port_id,
9354                 (void *)&cmd_queue_region_cmd,
9355                 (void *)&cmd_queue_region_id,
9356                 (void *)&cmd_queue_region_index,
9357                 (void *)&cmd_queue_region_queue_start_index,
9358                 (void *)&cmd_queue_region_queue_id,
9359                 (void *)&cmd_queue_region_queue_num,
9360                 (void *)&cmd_queue_region_queue_num_value,
9361                 NULL,
9362         },
9363 };
9364
9365 /* *** queue region and flowtype set *** */
9366 struct cmd_region_flowtype_result {
9367         cmdline_fixed_string_t set;
9368         cmdline_fixed_string_t port;
9369         portid_t port_id;
9370         cmdline_fixed_string_t cmd;
9371         cmdline_fixed_string_t region;
9372         uint8_t  region_id;
9373         cmdline_fixed_string_t flowtype;
9374         uint8_t  flowtype_id;
9375 };
9376
9377 static void
9378 cmd_region_flowtype_parsed(void *parsed_result,
9379                         __attribute__((unused)) struct cmdline *cl,
9380                         __attribute__((unused)) void *data)
9381 {
9382         struct cmd_region_flowtype_result *res = parsed_result;
9383         int ret = -ENOTSUP;
9384 #ifdef RTE_LIBRTE_I40E_PMD
9385         struct rte_pmd_i40e_queue_region_conf region_conf;
9386         enum rte_pmd_i40e_queue_region_op op_type;
9387 #endif
9388
9389         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9390                 return;
9391
9392 #ifdef RTE_LIBRTE_I40E_PMD
9393         memset(&region_conf, 0, sizeof(region_conf));
9394
9395         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9396         region_conf.region_id = res->region_id;
9397         region_conf.hw_flowtype = res->flowtype_id;
9398
9399         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9400                         op_type, &region_conf);
9401 #endif
9402
9403         switch (ret) {
9404         case 0:
9405                 break;
9406         case -ENOTSUP:
9407                 printf("function not implemented or supported\n");
9408                 break;
9409         default:
9410                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9411         }
9412 }
9413
9414 cmdline_parse_token_string_t cmd_region_flowtype_set =
9415 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9416                                 set, "set");
9417 cmdline_parse_token_string_t cmd_region_flowtype_port =
9418         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9419                                 port, "port");
9420 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9421         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9422                                 port_id, UINT16);
9423 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9424         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9425                                 cmd, "queue-region");
9426 cmdline_parse_token_string_t cmd_region_flowtype_index =
9427         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9428                                 region, "region_id");
9429 cmdline_parse_token_num_t cmd_region_flowtype_id =
9430         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9431                                 region_id, UINT8);
9432 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9433         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9434                                 flowtype, "flowtype");
9435 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9436         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9437                                 flowtype_id, UINT8);
9438 cmdline_parse_inst_t cmd_region_flowtype = {
9439         .f = cmd_region_flowtype_parsed,
9440         .data = NULL,
9441         .help_str = "set port <port_id> queue-region region_id <value> "
9442                 "flowtype <value>: Set a flowtype region index",
9443         .tokens = {
9444                 (void *)&cmd_region_flowtype_set,
9445                 (void *)&cmd_region_flowtype_port,
9446                 (void *)&cmd_region_flowtype_port_index,
9447                 (void *)&cmd_region_flowtype_cmd,
9448                 (void *)&cmd_region_flowtype_index,
9449                 (void *)&cmd_region_flowtype_id,
9450                 (void *)&cmd_region_flowtype_flow_index,
9451                 (void *)&cmd_region_flowtype_flow_id,
9452                 NULL,
9453         },
9454 };
9455
9456 /* *** User Priority (UP) to queue region (region_id) set *** */
9457 struct cmd_user_priority_region_result {
9458         cmdline_fixed_string_t set;
9459         cmdline_fixed_string_t port;
9460         portid_t port_id;
9461         cmdline_fixed_string_t cmd;
9462         cmdline_fixed_string_t user_priority;
9463         uint8_t  user_priority_id;
9464         cmdline_fixed_string_t region;
9465         uint8_t  region_id;
9466 };
9467
9468 static void
9469 cmd_user_priority_region_parsed(void *parsed_result,
9470                         __attribute__((unused)) struct cmdline *cl,
9471                         __attribute__((unused)) void *data)
9472 {
9473         struct cmd_user_priority_region_result *res = parsed_result;
9474         int ret = -ENOTSUP;
9475 #ifdef RTE_LIBRTE_I40E_PMD
9476         struct rte_pmd_i40e_queue_region_conf region_conf;
9477         enum rte_pmd_i40e_queue_region_op op_type;
9478 #endif
9479
9480         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9481                 return;
9482
9483 #ifdef RTE_LIBRTE_I40E_PMD
9484         memset(&region_conf, 0, sizeof(region_conf));
9485         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9486         region_conf.user_priority = res->user_priority_id;
9487         region_conf.region_id = res->region_id;
9488
9489         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9490                                 op_type, &region_conf);
9491 #endif
9492
9493         switch (ret) {
9494         case 0:
9495                 break;
9496         case -ENOTSUP:
9497                 printf("function not implemented or supported\n");
9498                 break;
9499         default:
9500                 printf("user_priority region config error: (%s)\n",
9501                                 strerror(-ret));
9502         }
9503 }
9504
9505 cmdline_parse_token_string_t cmd_user_priority_region_set =
9506         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9507                                 set, "set");
9508 cmdline_parse_token_string_t cmd_user_priority_region_port =
9509         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9510                                 port, "port");
9511 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9512         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9513                                 port_id, UINT16);
9514 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9515         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9516                                 cmd, "queue-region");
9517 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9518         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9519                                 user_priority, "UP");
9520 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9521         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9522                                 user_priority_id, UINT8);
9523 cmdline_parse_token_string_t cmd_user_priority_region_region =
9524         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9525                                 region, "region_id");
9526 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9527         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9528                                 region_id, UINT8);
9529
9530 cmdline_parse_inst_t cmd_user_priority_region = {
9531         .f = cmd_user_priority_region_parsed,
9532         .data = NULL,
9533         .help_str = "set port <port_id> queue-region UP <value> "
9534                 "region_id <value>: Set the mapping of User Priority (UP) "
9535                 "to queue region (region_id) ",
9536         .tokens = {
9537                 (void *)&cmd_user_priority_region_set,
9538                 (void *)&cmd_user_priority_region_port,
9539                 (void *)&cmd_user_priority_region_port_index,
9540                 (void *)&cmd_user_priority_region_cmd,
9541                 (void *)&cmd_user_priority_region_UP,
9542                 (void *)&cmd_user_priority_region_UP_id,
9543                 (void *)&cmd_user_priority_region_region,
9544                 (void *)&cmd_user_priority_region_region_id,
9545                 NULL,
9546         },
9547 };
9548
9549 /* *** flush all queue region related configuration *** */
9550 struct cmd_flush_queue_region_result {
9551         cmdline_fixed_string_t set;
9552         cmdline_fixed_string_t port;
9553         portid_t port_id;
9554         cmdline_fixed_string_t cmd;
9555         cmdline_fixed_string_t flush;
9556         cmdline_fixed_string_t what;
9557 };
9558
9559 static void
9560 cmd_flush_queue_region_parsed(void *parsed_result,
9561                         __attribute__((unused)) struct cmdline *cl,
9562                         __attribute__((unused)) void *data)
9563 {
9564         struct cmd_flush_queue_region_result *res = parsed_result;
9565         int ret = -ENOTSUP;
9566 #ifdef RTE_LIBRTE_I40E_PMD
9567         struct rte_pmd_i40e_queue_region_conf region_conf;
9568         enum rte_pmd_i40e_queue_region_op op_type;
9569 #endif
9570
9571         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9572                 return;
9573
9574 #ifdef RTE_LIBRTE_I40E_PMD
9575         memset(&region_conf, 0, sizeof(region_conf));
9576
9577         if (strcmp(res->what, "on") == 0)
9578                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9579         else
9580                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9581
9582         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9583                                 op_type, &region_conf);
9584 #endif
9585
9586         switch (ret) {
9587         case 0:
9588                 break;
9589         case -ENOTSUP:
9590                 printf("function not implemented or supported\n");
9591                 break;
9592         default:
9593                 printf("queue region config flush error: (%s)\n",
9594                                 strerror(-ret));
9595         }
9596 }
9597
9598 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9599         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9600                                 set, "set");
9601 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9602         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9603                                 port, "port");
9604 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9605         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9606                                 port_id, UINT16);
9607 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9608         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9609                                 cmd, "queue-region");
9610 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9611         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9612                                 flush, "flush");
9613 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9614         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9615                                 what, "on#off");
9616
9617 cmdline_parse_inst_t cmd_flush_queue_region = {
9618         .f = cmd_flush_queue_region_parsed,
9619         .data = NULL,
9620         .help_str = "set port <port_id> queue-region flush on|off"
9621                 ": flush all queue region related configuration",
9622         .tokens = {
9623                 (void *)&cmd_flush_queue_region_set,
9624                 (void *)&cmd_flush_queue_region_port,
9625                 (void *)&cmd_flush_queue_region_port_index,
9626                 (void *)&cmd_flush_queue_region_cmd,
9627                 (void *)&cmd_flush_queue_region_flush,
9628                 (void *)&cmd_flush_queue_region_what,
9629                 NULL,
9630         },
9631 };
9632
9633 /* *** get all queue region related configuration info *** */
9634 struct cmd_show_queue_region_info {
9635         cmdline_fixed_string_t show;
9636         cmdline_fixed_string_t port;
9637         portid_t port_id;
9638         cmdline_fixed_string_t cmd;
9639 };
9640
9641 static void
9642 cmd_show_queue_region_info_parsed(void *parsed_result,
9643                         __attribute__((unused)) struct cmdline *cl,
9644                         __attribute__((unused)) void *data)
9645 {
9646         struct cmd_show_queue_region_info *res = parsed_result;
9647         int ret = -ENOTSUP;
9648 #ifdef RTE_LIBRTE_I40E_PMD
9649         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9650         enum rte_pmd_i40e_queue_region_op op_type;
9651 #endif
9652
9653         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9654                 return;
9655
9656 #ifdef RTE_LIBRTE_I40E_PMD
9657         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9658
9659         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9660
9661         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9662                                         op_type, &rte_pmd_regions);
9663
9664         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9665 #endif
9666
9667         switch (ret) {
9668         case 0:
9669                 break;
9670         case -ENOTSUP:
9671                 printf("function not implemented or supported\n");
9672                 break;
9673         default:
9674                 printf("queue region config info show error: (%s)\n",
9675                                 strerror(-ret));
9676         }
9677 }
9678
9679 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9680 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9681                                 show, "show");
9682 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9683         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9684                                 port, "port");
9685 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9686         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9687                                 port_id, UINT16);
9688 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9689         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9690                                 cmd, "queue-region");
9691
9692 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9693         .f = cmd_show_queue_region_info_parsed,
9694         .data = NULL,
9695         .help_str = "show port <port_id> queue-region"
9696                 ": show all queue region related configuration info",
9697         .tokens = {
9698                 (void *)&cmd_show_queue_region_info_get,
9699                 (void *)&cmd_show_queue_region_info_port,
9700                 (void *)&cmd_show_queue_region_info_port_index,
9701                 (void *)&cmd_show_queue_region_info_cmd,
9702                 NULL,
9703         },
9704 };
9705
9706 /* *** ADD/REMOVE A 2tuple FILTER *** */
9707 struct cmd_2tuple_filter_result {
9708         cmdline_fixed_string_t filter;
9709         portid_t port_id;
9710         cmdline_fixed_string_t ops;
9711         cmdline_fixed_string_t dst_port;
9712         uint16_t dst_port_value;
9713         cmdline_fixed_string_t protocol;
9714         uint8_t protocol_value;
9715         cmdline_fixed_string_t mask;
9716         uint8_t  mask_value;
9717         cmdline_fixed_string_t tcp_flags;
9718         uint8_t tcp_flags_value;
9719         cmdline_fixed_string_t priority;
9720         uint8_t  priority_value;
9721         cmdline_fixed_string_t queue;
9722         uint16_t  queue_id;
9723 };
9724
9725 static void
9726 cmd_2tuple_filter_parsed(void *parsed_result,
9727                         __attribute__((unused)) struct cmdline *cl,
9728                         __attribute__((unused)) void *data)
9729 {
9730         struct rte_eth_ntuple_filter filter;
9731         struct cmd_2tuple_filter_result *res = parsed_result;
9732         int ret = 0;
9733
9734         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9735         if (ret < 0) {
9736                 printf("ntuple filter is not supported on port %u.\n",
9737                         res->port_id);
9738                 return;
9739         }
9740
9741         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9742
9743         filter.flags = RTE_2TUPLE_FLAGS;
9744         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9745         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9746         filter.proto = res->protocol_value;
9747         filter.priority = res->priority_value;
9748         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9749                 printf("nonzero tcp_flags is only meaningful"
9750                         " when protocol is TCP.\n");
9751                 return;
9752         }
9753         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9754                 printf("invalid TCP flags.\n");
9755                 return;
9756         }
9757
9758         if (res->tcp_flags_value != 0) {
9759                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9760                 filter.tcp_flags = res->tcp_flags_value;
9761         }
9762
9763         /* need convert to big endian. */
9764         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9765         filter.queue = res->queue_id;
9766
9767         if (!strcmp(res->ops, "add"))
9768                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9769                                 RTE_ETH_FILTER_NTUPLE,
9770                                 RTE_ETH_FILTER_ADD,
9771                                 &filter);
9772         else
9773                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9774                                 RTE_ETH_FILTER_NTUPLE,
9775                                 RTE_ETH_FILTER_DELETE,
9776                                 &filter);
9777         if (ret < 0)
9778                 printf("2tuple filter programming error: (%s)\n",
9779                         strerror(-ret));
9780
9781 }
9782
9783 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9784         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9785                                  filter, "2tuple_filter");
9786 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9787         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9788                                 port_id, UINT16);
9789 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9790         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9791                                  ops, "add#del");
9792 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9793         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9794                                 dst_port, "dst_port");
9795 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9796         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9797                                 dst_port_value, UINT16);
9798 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9799         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9800                                 protocol, "protocol");
9801 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9802         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9803                                 protocol_value, UINT8);
9804 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9805         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9806                                 mask, "mask");
9807 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9808         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9809                                 mask_value, INT8);
9810 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9811         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9812                                 tcp_flags, "tcp_flags");
9813 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9814         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9815                                 tcp_flags_value, UINT8);
9816 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9817         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9818                                 priority, "priority");
9819 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9820         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9821                                 priority_value, UINT8);
9822 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9823         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9824                                 queue, "queue");
9825 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9826         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9827                                 queue_id, UINT16);
9828
9829 cmdline_parse_inst_t cmd_2tuple_filter = {
9830         .f = cmd_2tuple_filter_parsed,
9831         .data = NULL,
9832         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9833                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9834                 "<queue_id>: Add a 2tuple filter",
9835         .tokens = {
9836                 (void *)&cmd_2tuple_filter_filter,
9837                 (void *)&cmd_2tuple_filter_port_id,
9838                 (void *)&cmd_2tuple_filter_ops,
9839                 (void *)&cmd_2tuple_filter_dst_port,
9840                 (void *)&cmd_2tuple_filter_dst_port_value,
9841                 (void *)&cmd_2tuple_filter_protocol,
9842                 (void *)&cmd_2tuple_filter_protocol_value,
9843                 (void *)&cmd_2tuple_filter_mask,
9844                 (void *)&cmd_2tuple_filter_mask_value,
9845                 (void *)&cmd_2tuple_filter_tcp_flags,
9846                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9847                 (void *)&cmd_2tuple_filter_priority,
9848                 (void *)&cmd_2tuple_filter_priority_value,
9849                 (void *)&cmd_2tuple_filter_queue,
9850                 (void *)&cmd_2tuple_filter_queue_id,
9851                 NULL,
9852         },
9853 };
9854
9855 /* *** ADD/REMOVE A 5tuple FILTER *** */
9856 struct cmd_5tuple_filter_result {
9857         cmdline_fixed_string_t filter;
9858         portid_t port_id;
9859         cmdline_fixed_string_t ops;
9860         cmdline_fixed_string_t dst_ip;
9861         cmdline_ipaddr_t dst_ip_value;
9862         cmdline_fixed_string_t src_ip;
9863         cmdline_ipaddr_t src_ip_value;
9864         cmdline_fixed_string_t dst_port;
9865         uint16_t dst_port_value;
9866         cmdline_fixed_string_t src_port;
9867         uint16_t src_port_value;
9868         cmdline_fixed_string_t protocol;
9869         uint8_t protocol_value;
9870         cmdline_fixed_string_t mask;
9871         uint8_t  mask_value;
9872         cmdline_fixed_string_t tcp_flags;
9873         uint8_t tcp_flags_value;
9874         cmdline_fixed_string_t priority;
9875         uint8_t  priority_value;
9876         cmdline_fixed_string_t queue;
9877         uint16_t  queue_id;
9878 };
9879
9880 static void
9881 cmd_5tuple_filter_parsed(void *parsed_result,
9882                         __attribute__((unused)) struct cmdline *cl,
9883                         __attribute__((unused)) void *data)
9884 {
9885         struct rte_eth_ntuple_filter filter;
9886         struct cmd_5tuple_filter_result *res = parsed_result;
9887         int ret = 0;
9888
9889         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9890         if (ret < 0) {
9891                 printf("ntuple filter is not supported on port %u.\n",
9892                         res->port_id);
9893                 return;
9894         }
9895
9896         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9897
9898         filter.flags = RTE_5TUPLE_FLAGS;
9899         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9900         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9901         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9902         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9903         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9904         filter.proto = res->protocol_value;
9905         filter.priority = res->priority_value;
9906         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9907                 printf("nonzero tcp_flags is only meaningful"
9908                         " when protocol is TCP.\n");
9909                 return;
9910         }
9911         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9912                 printf("invalid TCP flags.\n");
9913                 return;
9914         }
9915
9916         if (res->tcp_flags_value != 0) {
9917                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9918                 filter.tcp_flags = res->tcp_flags_value;
9919         }
9920
9921         if (res->dst_ip_value.family == AF_INET)
9922                 /* no need to convert, already big endian. */
9923                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9924         else {
9925                 if (filter.dst_ip_mask == 0) {
9926                         printf("can not support ipv6 involved compare.\n");
9927                         return;
9928                 }
9929                 filter.dst_ip = 0;
9930         }
9931
9932         if (res->src_ip_value.family == AF_INET)
9933                 /* no need to convert, already big endian. */
9934                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9935         else {
9936                 if (filter.src_ip_mask == 0) {
9937                         printf("can not support ipv6 involved compare.\n");
9938                         return;
9939                 }
9940                 filter.src_ip = 0;
9941         }
9942         /* need convert to big endian. */
9943         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9944         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9945         filter.queue = res->queue_id;
9946
9947         if (!strcmp(res->ops, "add"))
9948                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9949                                 RTE_ETH_FILTER_NTUPLE,
9950                                 RTE_ETH_FILTER_ADD,
9951                                 &filter);
9952         else
9953                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9954                                 RTE_ETH_FILTER_NTUPLE,
9955                                 RTE_ETH_FILTER_DELETE,
9956                                 &filter);
9957         if (ret < 0)
9958                 printf("5tuple filter programming error: (%s)\n",
9959                         strerror(-ret));
9960 }
9961
9962 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9963         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9964                                  filter, "5tuple_filter");
9965 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9966         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9967                                 port_id, UINT16);
9968 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9969         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9970                                  ops, "add#del");
9971 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9972         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9973                                 dst_ip, "dst_ip");
9974 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9975         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9976                                 dst_ip_value);
9977 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9978         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9979                                 src_ip, "src_ip");
9980 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9981         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9982                                 src_ip_value);
9983 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9984         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9985                                 dst_port, "dst_port");
9986 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9987         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9988                                 dst_port_value, UINT16);
9989 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9990         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9991                                 src_port, "src_port");
9992 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9993         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9994                                 src_port_value, UINT16);
9995 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9996         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9997                                 protocol, "protocol");
9998 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9999         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10000                                 protocol_value, UINT8);
10001 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10002         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10003                                 mask, "mask");
10004 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10005         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10006                                 mask_value, INT8);
10007 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10008         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10009                                 tcp_flags, "tcp_flags");
10010 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10011         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10012                                 tcp_flags_value, UINT8);
10013 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10014         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10015                                 priority, "priority");
10016 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10017         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10018                                 priority_value, UINT8);
10019 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10020         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10021                                 queue, "queue");
10022 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10023         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10024                                 queue_id, UINT16);
10025
10026 cmdline_parse_inst_t cmd_5tuple_filter = {
10027         .f = cmd_5tuple_filter_parsed,
10028         .data = NULL,
10029         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10030                 "src_ip <value> dst_port <value> src_port <value> "
10031                 "protocol <value>  mask <value> tcp_flags <value> "
10032                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10033         .tokens = {
10034                 (void *)&cmd_5tuple_filter_filter,
10035                 (void *)&cmd_5tuple_filter_port_id,
10036                 (void *)&cmd_5tuple_filter_ops,
10037                 (void *)&cmd_5tuple_filter_dst_ip,
10038                 (void *)&cmd_5tuple_filter_dst_ip_value,
10039                 (void *)&cmd_5tuple_filter_src_ip,
10040                 (void *)&cmd_5tuple_filter_src_ip_value,
10041                 (void *)&cmd_5tuple_filter_dst_port,
10042                 (void *)&cmd_5tuple_filter_dst_port_value,
10043                 (void *)&cmd_5tuple_filter_src_port,
10044                 (void *)&cmd_5tuple_filter_src_port_value,
10045                 (void *)&cmd_5tuple_filter_protocol,
10046                 (void *)&cmd_5tuple_filter_protocol_value,
10047                 (void *)&cmd_5tuple_filter_mask,
10048                 (void *)&cmd_5tuple_filter_mask_value,
10049                 (void *)&cmd_5tuple_filter_tcp_flags,
10050                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10051                 (void *)&cmd_5tuple_filter_priority,
10052                 (void *)&cmd_5tuple_filter_priority_value,
10053                 (void *)&cmd_5tuple_filter_queue,
10054                 (void *)&cmd_5tuple_filter_queue_id,
10055                 NULL,
10056         },
10057 };
10058
10059 /* *** ADD/REMOVE A flex FILTER *** */
10060 struct cmd_flex_filter_result {
10061         cmdline_fixed_string_t filter;
10062         cmdline_fixed_string_t ops;
10063         portid_t port_id;
10064         cmdline_fixed_string_t len;
10065         uint8_t len_value;
10066         cmdline_fixed_string_t bytes;
10067         cmdline_fixed_string_t bytes_value;
10068         cmdline_fixed_string_t mask;
10069         cmdline_fixed_string_t mask_value;
10070         cmdline_fixed_string_t priority;
10071         uint8_t priority_value;
10072         cmdline_fixed_string_t queue;
10073         uint16_t queue_id;
10074 };
10075
10076 static int xdigit2val(unsigned char c)
10077 {
10078         int val;
10079         if (isdigit(c))
10080                 val = c - '0';
10081         else if (isupper(c))
10082                 val = c - 'A' + 10;
10083         else
10084                 val = c - 'a' + 10;
10085         return val;
10086 }
10087
10088 static void
10089 cmd_flex_filter_parsed(void *parsed_result,
10090                           __attribute__((unused)) struct cmdline *cl,
10091                           __attribute__((unused)) void *data)
10092 {
10093         int ret = 0;
10094         struct rte_eth_flex_filter filter;
10095         struct cmd_flex_filter_result *res = parsed_result;
10096         char *bytes_ptr, *mask_ptr;
10097         uint16_t len, i, j = 0;
10098         char c;
10099         int val;
10100         uint8_t byte = 0;
10101
10102         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10103                 printf("the len exceed the max length 128\n");
10104                 return;
10105         }
10106         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10107         filter.len = res->len_value;
10108         filter.priority = res->priority_value;
10109         filter.queue = res->queue_id;
10110         bytes_ptr = res->bytes_value;
10111         mask_ptr = res->mask_value;
10112
10113          /* translate bytes string to array. */
10114         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10115                 (bytes_ptr[1] == 'X')))
10116                 bytes_ptr += 2;
10117         len = strnlen(bytes_ptr, res->len_value * 2);
10118         if (len == 0 || (len % 8 != 0)) {
10119                 printf("please check len and bytes input\n");
10120                 return;
10121         }
10122         for (i = 0; i < len; i++) {
10123                 c = bytes_ptr[i];
10124                 if (isxdigit(c) == 0) {
10125                         /* invalid characters. */
10126                         printf("invalid input\n");
10127                         return;
10128                 }
10129                 val = xdigit2val(c);
10130                 if (i % 2) {
10131                         byte |= val;
10132                         filter.bytes[j] = byte;
10133                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10134                         j++;
10135                         byte = 0;
10136                 } else
10137                         byte |= val << 4;
10138         }
10139         printf("\n");
10140          /* translate mask string to uint8_t array. */
10141         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10142                 (mask_ptr[1] == 'X')))
10143                 mask_ptr += 2;
10144         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10145         if (len == 0) {
10146                 printf("invalid input\n");
10147                 return;
10148         }
10149         j = 0;
10150         byte = 0;
10151         for (i = 0; i < len; i++) {
10152                 c = mask_ptr[i];
10153                 if (isxdigit(c) == 0) {
10154                         /* invalid characters. */
10155                         printf("invalid input\n");
10156                         return;
10157                 }
10158                 val = xdigit2val(c);
10159                 if (i % 2) {
10160                         byte |= val;
10161                         filter.mask[j] = byte;
10162                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10163                         j++;
10164                         byte = 0;
10165                 } else
10166                         byte |= val << 4;
10167         }
10168         printf("\n");
10169
10170         if (!strcmp(res->ops, "add"))
10171                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10172                                 RTE_ETH_FILTER_FLEXIBLE,
10173                                 RTE_ETH_FILTER_ADD,
10174                                 &filter);
10175         else
10176                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10177                                 RTE_ETH_FILTER_FLEXIBLE,
10178                                 RTE_ETH_FILTER_DELETE,
10179                                 &filter);
10180
10181         if (ret < 0)
10182                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10183 }
10184
10185 cmdline_parse_token_string_t cmd_flex_filter_filter =
10186         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10187                                 filter, "flex_filter");
10188 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10189         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10190                                 port_id, UINT16);
10191 cmdline_parse_token_string_t cmd_flex_filter_ops =
10192         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10193                                 ops, "add#del");
10194 cmdline_parse_token_string_t cmd_flex_filter_len =
10195         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10196                                 len, "len");
10197 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10198         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10199                                 len_value, UINT8);
10200 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10201         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10202                                 bytes, "bytes");
10203 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10204         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10205                                 bytes_value, NULL);
10206 cmdline_parse_token_string_t cmd_flex_filter_mask =
10207         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10208                                 mask, "mask");
10209 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10210         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10211                                 mask_value, NULL);
10212 cmdline_parse_token_string_t cmd_flex_filter_priority =
10213         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10214                                 priority, "priority");
10215 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10216         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10217                                 priority_value, UINT8);
10218 cmdline_parse_token_string_t cmd_flex_filter_queue =
10219         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10220                                 queue, "queue");
10221 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10222         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10223                                 queue_id, UINT16);
10224 cmdline_parse_inst_t cmd_flex_filter = {
10225         .f = cmd_flex_filter_parsed,
10226         .data = NULL,
10227         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10228                 "<value> mask <value> priority <value> queue <queue_id>: "
10229                 "Add/Del a flex filter",
10230         .tokens = {
10231                 (void *)&cmd_flex_filter_filter,
10232                 (void *)&cmd_flex_filter_port_id,
10233                 (void *)&cmd_flex_filter_ops,
10234                 (void *)&cmd_flex_filter_len,
10235                 (void *)&cmd_flex_filter_len_value,
10236                 (void *)&cmd_flex_filter_bytes,
10237                 (void *)&cmd_flex_filter_bytes_value,
10238                 (void *)&cmd_flex_filter_mask,
10239                 (void *)&cmd_flex_filter_mask_value,
10240                 (void *)&cmd_flex_filter_priority,
10241                 (void *)&cmd_flex_filter_priority_value,
10242                 (void *)&cmd_flex_filter_queue,
10243                 (void *)&cmd_flex_filter_queue_id,
10244                 NULL,
10245         },
10246 };
10247
10248 /* *** Filters Control *** */
10249
10250 /* *** deal with ethertype filter *** */
10251 struct cmd_ethertype_filter_result {
10252         cmdline_fixed_string_t filter;
10253         portid_t port_id;
10254         cmdline_fixed_string_t ops;
10255         cmdline_fixed_string_t mac;
10256         struct ether_addr mac_addr;
10257         cmdline_fixed_string_t ethertype;
10258         uint16_t ethertype_value;
10259         cmdline_fixed_string_t drop;
10260         cmdline_fixed_string_t queue;
10261         uint16_t  queue_id;
10262 };
10263
10264 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10265         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10266                                  filter, "ethertype_filter");
10267 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10268         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10269                               port_id, UINT16);
10270 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10271         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10272                                  ops, "add#del");
10273 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10274         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10275                                  mac, "mac_addr#mac_ignr");
10276 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10277         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10278                                      mac_addr);
10279 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10280         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10281                                  ethertype, "ethertype");
10282 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10283         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10284                               ethertype_value, UINT16);
10285 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10286         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10287                                  drop, "drop#fwd");
10288 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10289         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10290                                  queue, "queue");
10291 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10292         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10293                               queue_id, UINT16);
10294
10295 static void
10296 cmd_ethertype_filter_parsed(void *parsed_result,
10297                           __attribute__((unused)) struct cmdline *cl,
10298                           __attribute__((unused)) void *data)
10299 {
10300         struct cmd_ethertype_filter_result *res = parsed_result;
10301         struct rte_eth_ethertype_filter filter;
10302         int ret = 0;
10303
10304         ret = rte_eth_dev_filter_supported(res->port_id,
10305                         RTE_ETH_FILTER_ETHERTYPE);
10306         if (ret < 0) {
10307                 printf("ethertype filter is not supported on port %u.\n",
10308                         res->port_id);
10309                 return;
10310         }
10311
10312         memset(&filter, 0, sizeof(filter));
10313         if (!strcmp(res->mac, "mac_addr")) {
10314                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10315                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10316                         sizeof(struct ether_addr));
10317         }
10318         if (!strcmp(res->drop, "drop"))
10319                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10320         filter.ether_type = res->ethertype_value;
10321         filter.queue = res->queue_id;
10322
10323         if (!strcmp(res->ops, "add"))
10324                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10325                                 RTE_ETH_FILTER_ETHERTYPE,
10326                                 RTE_ETH_FILTER_ADD,
10327                                 &filter);
10328         else
10329                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10330                                 RTE_ETH_FILTER_ETHERTYPE,
10331                                 RTE_ETH_FILTER_DELETE,
10332                                 &filter);
10333         if (ret < 0)
10334                 printf("ethertype filter programming error: (%s)\n",
10335                         strerror(-ret));
10336 }
10337
10338 cmdline_parse_inst_t cmd_ethertype_filter = {
10339         .f = cmd_ethertype_filter_parsed,
10340         .data = NULL,
10341         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10342                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10343                 "Add or delete an ethertype filter entry",
10344         .tokens = {
10345                 (void *)&cmd_ethertype_filter_filter,
10346                 (void *)&cmd_ethertype_filter_port_id,
10347                 (void *)&cmd_ethertype_filter_ops,
10348                 (void *)&cmd_ethertype_filter_mac,
10349                 (void *)&cmd_ethertype_filter_mac_addr,
10350                 (void *)&cmd_ethertype_filter_ethertype,
10351                 (void *)&cmd_ethertype_filter_ethertype_value,
10352                 (void *)&cmd_ethertype_filter_drop,
10353                 (void *)&cmd_ethertype_filter_queue,
10354                 (void *)&cmd_ethertype_filter_queue_id,
10355                 NULL,
10356         },
10357 };
10358
10359 /* *** deal with flow director filter *** */
10360 struct cmd_flow_director_result {
10361         cmdline_fixed_string_t flow_director_filter;
10362         portid_t port_id;
10363         cmdline_fixed_string_t mode;
10364         cmdline_fixed_string_t mode_value;
10365         cmdline_fixed_string_t ops;
10366         cmdline_fixed_string_t flow;
10367         cmdline_fixed_string_t flow_type;
10368         cmdline_fixed_string_t ether;
10369         uint16_t ether_type;
10370         cmdline_fixed_string_t src;
10371         cmdline_ipaddr_t ip_src;
10372         uint16_t port_src;
10373         cmdline_fixed_string_t dst;
10374         cmdline_ipaddr_t ip_dst;
10375         uint16_t port_dst;
10376         cmdline_fixed_string_t verify_tag;
10377         uint32_t verify_tag_value;
10378         cmdline_fixed_string_t tos;
10379         uint8_t tos_value;
10380         cmdline_fixed_string_t proto;
10381         uint8_t proto_value;
10382         cmdline_fixed_string_t ttl;
10383         uint8_t ttl_value;
10384         cmdline_fixed_string_t vlan;
10385         uint16_t vlan_value;
10386         cmdline_fixed_string_t flexbytes;
10387         cmdline_fixed_string_t flexbytes_value;
10388         cmdline_fixed_string_t pf_vf;
10389         cmdline_fixed_string_t drop;
10390         cmdline_fixed_string_t queue;
10391         uint16_t  queue_id;
10392         cmdline_fixed_string_t fd_id;
10393         uint32_t  fd_id_value;
10394         cmdline_fixed_string_t mac;
10395         struct ether_addr mac_addr;
10396         cmdline_fixed_string_t tunnel;
10397         cmdline_fixed_string_t tunnel_type;
10398         cmdline_fixed_string_t tunnel_id;
10399         uint32_t tunnel_id_value;
10400         cmdline_fixed_string_t packet;
10401         char filepath[];
10402 };
10403
10404 static inline int
10405 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10406 {
10407         char s[256];
10408         const char *p, *p0 = q_arg;
10409         char *end;
10410         unsigned long int_fld;
10411         char *str_fld[max_num];
10412         int i;
10413         unsigned size;
10414         int ret = -1;
10415
10416         p = strchr(p0, '(');
10417         if (p == NULL)
10418                 return -1;
10419         ++p;
10420         p0 = strchr(p, ')');
10421         if (p0 == NULL)
10422                 return -1;
10423
10424         size = p0 - p;
10425         if (size >= sizeof(s))
10426                 return -1;
10427
10428         snprintf(s, sizeof(s), "%.*s", size, p);
10429         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10430         if (ret < 0 || ret > max_num)
10431                 return -1;
10432         for (i = 0; i < ret; i++) {
10433                 errno = 0;
10434                 int_fld = strtoul(str_fld[i], &end, 0);
10435                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10436                         return -1;
10437                 flexbytes[i] = (uint8_t)int_fld;
10438         }
10439         return ret;
10440 }
10441
10442 static uint16_t
10443 str2flowtype(char *string)
10444 {
10445         uint8_t i = 0;
10446         static const struct {
10447                 char str[32];
10448                 uint16_t type;
10449         } flowtype_str[] = {
10450                 {"raw", RTE_ETH_FLOW_RAW},
10451                 {"ipv4", RTE_ETH_FLOW_IPV4},
10452                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10453                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10454                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10455                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10456                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10457                 {"ipv6", RTE_ETH_FLOW_IPV6},
10458                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10459                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10460                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10461                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10462                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10463                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10464         };
10465
10466         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10467                 if (!strcmp(flowtype_str[i].str, string))
10468                         return flowtype_str[i].type;
10469         }
10470
10471         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10472                 return (uint16_t)atoi(string);
10473
10474         return RTE_ETH_FLOW_UNKNOWN;
10475 }
10476
10477 static enum rte_eth_fdir_tunnel_type
10478 str2fdir_tunneltype(char *string)
10479 {
10480         uint8_t i = 0;
10481
10482         static const struct {
10483                 char str[32];
10484                 enum rte_eth_fdir_tunnel_type type;
10485         } tunneltype_str[] = {
10486                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10487                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10488         };
10489
10490         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10491                 if (!strcmp(tunneltype_str[i].str, string))
10492                         return tunneltype_str[i].type;
10493         }
10494         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10495 }
10496
10497 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10498 do { \
10499         if ((ip_addr).family == AF_INET) \
10500                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10501         else { \
10502                 printf("invalid parameter.\n"); \
10503                 return; \
10504         } \
10505 } while (0)
10506
10507 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10508 do { \
10509         if ((ip_addr).family == AF_INET6) \
10510                 rte_memcpy(&(ip), \
10511                                  &((ip_addr).addr.ipv6), \
10512                                  sizeof(struct in6_addr)); \
10513         else { \
10514                 printf("invalid parameter.\n"); \
10515                 return; \
10516         } \
10517 } while (0)
10518
10519 static void
10520 cmd_flow_director_filter_parsed(void *parsed_result,
10521                           __attribute__((unused)) struct cmdline *cl,
10522                           __attribute__((unused)) void *data)
10523 {
10524         struct cmd_flow_director_result *res = parsed_result;
10525         struct rte_eth_fdir_filter entry;
10526         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10527         char *end;
10528         unsigned long vf_id;
10529         int ret = 0;
10530
10531         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10532         if (ret < 0) {
10533                 printf("flow director is not supported on port %u.\n",
10534                         res->port_id);
10535                 return;
10536         }
10537         memset(flexbytes, 0, sizeof(flexbytes));
10538         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10539
10540         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10541                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10542                         printf("Please set mode to MAC-VLAN.\n");
10543                         return;
10544                 }
10545         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10546                 if (strcmp(res->mode_value, "Tunnel")) {
10547                         printf("Please set mode to Tunnel.\n");
10548                         return;
10549                 }
10550         } else {
10551                 if (!strcmp(res->mode_value, "raw")) {
10552 #ifdef RTE_LIBRTE_I40E_PMD
10553                         struct rte_pmd_i40e_flow_type_mapping
10554                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10555                         struct rte_pmd_i40e_pkt_template_conf conf;
10556                         uint16_t flow_type = str2flowtype(res->flow_type);
10557                         uint16_t i, port = res->port_id;
10558                         uint8_t add;
10559
10560                         memset(&conf, 0, sizeof(conf));
10561
10562                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10563                                 printf("Invalid flow type specified.\n");
10564                                 return;
10565                         }
10566                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10567                                                                  mapping);
10568                         if (ret)
10569                                 return;
10570                         if (mapping[flow_type].pctype == 0ULL) {
10571                                 printf("Invalid flow type specified.\n");
10572                                 return;
10573                         }
10574                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10575                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10576                                         conf.input.pctype = i;
10577                                         break;
10578                                 }
10579                         }
10580
10581                         conf.input.packet = open_file(res->filepath,
10582                                                 &conf.input.length);
10583                         if (!conf.input.packet)
10584                                 return;
10585                         if (!strcmp(res->drop, "drop"))
10586                                 conf.action.behavior =
10587                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10588                         else
10589                                 conf.action.behavior =
10590                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10591                         conf.action.report_status =
10592                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10593                         conf.action.rx_queue = res->queue_id;
10594                         conf.soft_id = res->fd_id_value;
10595                         add  = strcmp(res->ops, "del") ? 1 : 0;
10596                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10597                                                                         &conf,
10598                                                                         add);
10599                         if (ret < 0)
10600                                 printf("flow director config error: (%s)\n",
10601                                        strerror(-ret));
10602                         close_file(conf.input.packet);
10603 #endif
10604                         return;
10605                 } else if (strcmp(res->mode_value, "IP")) {
10606                         printf("Please set mode to IP or raw.\n");
10607                         return;
10608                 }
10609                 entry.input.flow_type = str2flowtype(res->flow_type);
10610         }
10611
10612         ret = parse_flexbytes(res->flexbytes_value,
10613                                         flexbytes,
10614                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10615         if (ret < 0) {
10616                 printf("error: Cannot parse flexbytes input.\n");
10617                 return;
10618         }
10619
10620         switch (entry.input.flow_type) {
10621         case RTE_ETH_FLOW_FRAG_IPV4:
10622         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10623                 entry.input.flow.ip4_flow.proto = res->proto_value;
10624                 /* fall-through */
10625         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10626         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10627                 IPV4_ADDR_TO_UINT(res->ip_dst,
10628                         entry.input.flow.ip4_flow.dst_ip);
10629                 IPV4_ADDR_TO_UINT(res->ip_src,
10630                         entry.input.flow.ip4_flow.src_ip);
10631                 entry.input.flow.ip4_flow.tos = res->tos_value;
10632                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10633                 /* need convert to big endian. */
10634                 entry.input.flow.udp4_flow.dst_port =
10635                                 rte_cpu_to_be_16(res->port_dst);
10636                 entry.input.flow.udp4_flow.src_port =
10637                                 rte_cpu_to_be_16(res->port_src);
10638                 break;
10639         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10640                 IPV4_ADDR_TO_UINT(res->ip_dst,
10641                         entry.input.flow.sctp4_flow.ip.dst_ip);
10642                 IPV4_ADDR_TO_UINT(res->ip_src,
10643                         entry.input.flow.sctp4_flow.ip.src_ip);
10644                 entry.input.flow.ip4_flow.tos = res->tos_value;
10645                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10646                 /* need convert to big endian. */
10647                 entry.input.flow.sctp4_flow.dst_port =
10648                                 rte_cpu_to_be_16(res->port_dst);
10649                 entry.input.flow.sctp4_flow.src_port =
10650                                 rte_cpu_to_be_16(res->port_src);
10651                 entry.input.flow.sctp4_flow.verify_tag =
10652                                 rte_cpu_to_be_32(res->verify_tag_value);
10653                 break;
10654         case RTE_ETH_FLOW_FRAG_IPV6:
10655         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10656                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10657                 /* fall-through */
10658         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10659         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10660                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10661                         entry.input.flow.ipv6_flow.dst_ip);
10662                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10663                         entry.input.flow.ipv6_flow.src_ip);
10664                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10665                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10666                 /* need convert to big endian. */
10667                 entry.input.flow.udp6_flow.dst_port =
10668                                 rte_cpu_to_be_16(res->port_dst);
10669                 entry.input.flow.udp6_flow.src_port =
10670                                 rte_cpu_to_be_16(res->port_src);
10671                 break;
10672         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10673                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10674                         entry.input.flow.sctp6_flow.ip.dst_ip);
10675                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10676                         entry.input.flow.sctp6_flow.ip.src_ip);
10677                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10678                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10679                 /* need convert to big endian. */
10680                 entry.input.flow.sctp6_flow.dst_port =
10681                                 rte_cpu_to_be_16(res->port_dst);
10682                 entry.input.flow.sctp6_flow.src_port =
10683                                 rte_cpu_to_be_16(res->port_src);
10684                 entry.input.flow.sctp6_flow.verify_tag =
10685                                 rte_cpu_to_be_32(res->verify_tag_value);
10686                 break;
10687         case RTE_ETH_FLOW_L2_PAYLOAD:
10688                 entry.input.flow.l2_flow.ether_type =
10689                         rte_cpu_to_be_16(res->ether_type);
10690                 break;
10691         default:
10692                 break;
10693         }
10694
10695         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10696                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10697                                  &res->mac_addr,
10698                                  sizeof(struct ether_addr));
10699
10700         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10701                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10702                                  &res->mac_addr,
10703                                  sizeof(struct ether_addr));
10704                 entry.input.flow.tunnel_flow.tunnel_type =
10705                         str2fdir_tunneltype(res->tunnel_type);
10706                 entry.input.flow.tunnel_flow.tunnel_id =
10707                         rte_cpu_to_be_32(res->tunnel_id_value);
10708         }
10709
10710         rte_memcpy(entry.input.flow_ext.flexbytes,
10711                    flexbytes,
10712                    RTE_ETH_FDIR_MAX_FLEXLEN);
10713
10714         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10715
10716         entry.action.flex_off = 0;  /*use 0 by default */
10717         if (!strcmp(res->drop, "drop"))
10718                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10719         else
10720                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10721
10722         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10723             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10724                 if (!strcmp(res->pf_vf, "pf"))
10725                         entry.input.flow_ext.is_vf = 0;
10726                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10727                         struct rte_eth_dev_info dev_info;
10728
10729                         memset(&dev_info, 0, sizeof(dev_info));
10730                         rte_eth_dev_info_get(res->port_id, &dev_info);
10731                         errno = 0;
10732                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10733                         if (errno != 0 || *end != '\0' ||
10734                             vf_id >= dev_info.max_vfs) {
10735                                 printf("invalid parameter %s.\n", res->pf_vf);
10736                                 return;
10737                         }
10738                         entry.input.flow_ext.is_vf = 1;
10739                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10740                 } else {
10741                         printf("invalid parameter %s.\n", res->pf_vf);
10742                         return;
10743                 }
10744         }
10745
10746         /* set to report FD ID by default */
10747         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10748         entry.action.rx_queue = res->queue_id;
10749         entry.soft_id = res->fd_id_value;
10750         if (!strcmp(res->ops, "add"))
10751                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10752                                              RTE_ETH_FILTER_ADD, &entry);
10753         else if (!strcmp(res->ops, "del"))
10754                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10755                                              RTE_ETH_FILTER_DELETE, &entry);
10756         else
10757                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10758                                              RTE_ETH_FILTER_UPDATE, &entry);
10759         if (ret < 0)
10760                 printf("flow director programming error: (%s)\n",
10761                         strerror(-ret));
10762 }
10763
10764 cmdline_parse_token_string_t cmd_flow_director_filter =
10765         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10766                                  flow_director_filter, "flow_director_filter");
10767 cmdline_parse_token_num_t cmd_flow_director_port_id =
10768         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10769                               port_id, UINT16);
10770 cmdline_parse_token_string_t cmd_flow_director_ops =
10771         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10772                                  ops, "add#del#update");
10773 cmdline_parse_token_string_t cmd_flow_director_flow =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10775                                  flow, "flow");
10776 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10777         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10778                 flow_type, NULL);
10779 cmdline_parse_token_string_t cmd_flow_director_ether =
10780         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10781                                  ether, "ether");
10782 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10783         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10784                               ether_type, UINT16);
10785 cmdline_parse_token_string_t cmd_flow_director_src =
10786         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10787                                  src, "src");
10788 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10789         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10790                                  ip_src);
10791 cmdline_parse_token_num_t cmd_flow_director_port_src =
10792         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10793                               port_src, UINT16);
10794 cmdline_parse_token_string_t cmd_flow_director_dst =
10795         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10796                                  dst, "dst");
10797 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10798         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10799                                  ip_dst);
10800 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10801         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10802                               port_dst, UINT16);
10803 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10804         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10805                                   verify_tag, "verify_tag");
10806 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10807         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10808                               verify_tag_value, UINT32);
10809 cmdline_parse_token_string_t cmd_flow_director_tos =
10810         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10811                                  tos, "tos");
10812 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10813         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10814                               tos_value, UINT8);
10815 cmdline_parse_token_string_t cmd_flow_director_proto =
10816         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10817                                  proto, "proto");
10818 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10819         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10820                               proto_value, UINT8);
10821 cmdline_parse_token_string_t cmd_flow_director_ttl =
10822         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10823                                  ttl, "ttl");
10824 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10825         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10826                               ttl_value, UINT8);
10827 cmdline_parse_token_string_t cmd_flow_director_vlan =
10828         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10829                                  vlan, "vlan");
10830 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10831         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10832                               vlan_value, UINT16);
10833 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10834         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10835                                  flexbytes, "flexbytes");
10836 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10837         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10838                               flexbytes_value, NULL);
10839 cmdline_parse_token_string_t cmd_flow_director_drop =
10840         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10841                                  drop, "drop#fwd");
10842 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10843         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10844                               pf_vf, NULL);
10845 cmdline_parse_token_string_t cmd_flow_director_queue =
10846         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10847                                  queue, "queue");
10848 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10849         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10850                               queue_id, UINT16);
10851 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10852         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10853                                  fd_id, "fd_id");
10854 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10855         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10856                               fd_id_value, UINT32);
10857
10858 cmdline_parse_token_string_t cmd_flow_director_mode =
10859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10860                                  mode, "mode");
10861 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10863                                  mode_value, "IP");
10864 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10866                                  mode_value, "MAC-VLAN");
10867 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10869                                  mode_value, "Tunnel");
10870 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10872                                  mode_value, "raw");
10873 cmdline_parse_token_string_t cmd_flow_director_mac =
10874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10875                                  mac, "mac");
10876 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10877         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10878                                     mac_addr);
10879 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10880         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10881                                  tunnel, "tunnel");
10882 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10883         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10884                                  tunnel_type, "NVGRE#VxLAN");
10885 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10886         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10887                                  tunnel_id, "tunnel-id");
10888 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10889         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10890                               tunnel_id_value, UINT32);
10891 cmdline_parse_token_string_t cmd_flow_director_packet =
10892         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10893                                  packet, "packet");
10894 cmdline_parse_token_string_t cmd_flow_director_filepath =
10895         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10896                                  filepath, NULL);
10897
10898 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10899         .f = cmd_flow_director_filter_parsed,
10900         .data = NULL,
10901         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10902                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10903                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10904                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10905                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10906                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10907                 "fd_id <fd_id_value>: "
10908                 "Add or delete an ip flow director entry on NIC",
10909         .tokens = {
10910                 (void *)&cmd_flow_director_filter,
10911                 (void *)&cmd_flow_director_port_id,
10912                 (void *)&cmd_flow_director_mode,
10913                 (void *)&cmd_flow_director_mode_ip,
10914                 (void *)&cmd_flow_director_ops,
10915                 (void *)&cmd_flow_director_flow,
10916                 (void *)&cmd_flow_director_flow_type,
10917                 (void *)&cmd_flow_director_src,
10918                 (void *)&cmd_flow_director_ip_src,
10919                 (void *)&cmd_flow_director_dst,
10920                 (void *)&cmd_flow_director_ip_dst,
10921                 (void *)&cmd_flow_director_tos,
10922                 (void *)&cmd_flow_director_tos_value,
10923                 (void *)&cmd_flow_director_proto,
10924                 (void *)&cmd_flow_director_proto_value,
10925                 (void *)&cmd_flow_director_ttl,
10926                 (void *)&cmd_flow_director_ttl_value,
10927                 (void *)&cmd_flow_director_vlan,
10928                 (void *)&cmd_flow_director_vlan_value,
10929                 (void *)&cmd_flow_director_flexbytes,
10930                 (void *)&cmd_flow_director_flexbytes_value,
10931                 (void *)&cmd_flow_director_drop,
10932                 (void *)&cmd_flow_director_pf_vf,
10933                 (void *)&cmd_flow_director_queue,
10934                 (void *)&cmd_flow_director_queue_id,
10935                 (void *)&cmd_flow_director_fd_id,
10936                 (void *)&cmd_flow_director_fd_id_value,
10937                 NULL,
10938         },
10939 };
10940
10941 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10942         .f = cmd_flow_director_filter_parsed,
10943         .data = NULL,
10944         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10945                 "director entry on NIC",
10946         .tokens = {
10947                 (void *)&cmd_flow_director_filter,
10948                 (void *)&cmd_flow_director_port_id,
10949                 (void *)&cmd_flow_director_mode,
10950                 (void *)&cmd_flow_director_mode_ip,
10951                 (void *)&cmd_flow_director_ops,
10952                 (void *)&cmd_flow_director_flow,
10953                 (void *)&cmd_flow_director_flow_type,
10954                 (void *)&cmd_flow_director_src,
10955                 (void *)&cmd_flow_director_ip_src,
10956                 (void *)&cmd_flow_director_port_src,
10957                 (void *)&cmd_flow_director_dst,
10958                 (void *)&cmd_flow_director_ip_dst,
10959                 (void *)&cmd_flow_director_port_dst,
10960                 (void *)&cmd_flow_director_tos,
10961                 (void *)&cmd_flow_director_tos_value,
10962                 (void *)&cmd_flow_director_ttl,
10963                 (void *)&cmd_flow_director_ttl_value,
10964                 (void *)&cmd_flow_director_vlan,
10965                 (void *)&cmd_flow_director_vlan_value,
10966                 (void *)&cmd_flow_director_flexbytes,
10967                 (void *)&cmd_flow_director_flexbytes_value,
10968                 (void *)&cmd_flow_director_drop,
10969                 (void *)&cmd_flow_director_pf_vf,
10970                 (void *)&cmd_flow_director_queue,
10971                 (void *)&cmd_flow_director_queue_id,
10972                 (void *)&cmd_flow_director_fd_id,
10973                 (void *)&cmd_flow_director_fd_id_value,
10974                 NULL,
10975         },
10976 };
10977
10978 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10979         .f = cmd_flow_director_filter_parsed,
10980         .data = NULL,
10981         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10982                 "director entry on NIC",
10983         .tokens = {
10984                 (void *)&cmd_flow_director_filter,
10985                 (void *)&cmd_flow_director_port_id,
10986                 (void *)&cmd_flow_director_mode,
10987                 (void *)&cmd_flow_director_mode_ip,
10988                 (void *)&cmd_flow_director_ops,
10989                 (void *)&cmd_flow_director_flow,
10990                 (void *)&cmd_flow_director_flow_type,
10991                 (void *)&cmd_flow_director_src,
10992                 (void *)&cmd_flow_director_ip_src,
10993                 (void *)&cmd_flow_director_port_src,
10994                 (void *)&cmd_flow_director_dst,
10995                 (void *)&cmd_flow_director_ip_dst,
10996                 (void *)&cmd_flow_director_port_dst,
10997                 (void *)&cmd_flow_director_verify_tag,
10998                 (void *)&cmd_flow_director_verify_tag_value,
10999                 (void *)&cmd_flow_director_tos,
11000                 (void *)&cmd_flow_director_tos_value,
11001                 (void *)&cmd_flow_director_ttl,
11002                 (void *)&cmd_flow_director_ttl_value,
11003                 (void *)&cmd_flow_director_vlan,
11004                 (void *)&cmd_flow_director_vlan_value,
11005                 (void *)&cmd_flow_director_flexbytes,
11006                 (void *)&cmd_flow_director_flexbytes_value,
11007                 (void *)&cmd_flow_director_drop,
11008                 (void *)&cmd_flow_director_pf_vf,
11009                 (void *)&cmd_flow_director_queue,
11010                 (void *)&cmd_flow_director_queue_id,
11011                 (void *)&cmd_flow_director_fd_id,
11012                 (void *)&cmd_flow_director_fd_id_value,
11013                 NULL,
11014         },
11015 };
11016
11017 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11018         .f = cmd_flow_director_filter_parsed,
11019         .data = NULL,
11020         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11021                 "director entry on NIC",
11022         .tokens = {
11023                 (void *)&cmd_flow_director_filter,
11024                 (void *)&cmd_flow_director_port_id,
11025                 (void *)&cmd_flow_director_mode,
11026                 (void *)&cmd_flow_director_mode_ip,
11027                 (void *)&cmd_flow_director_ops,
11028                 (void *)&cmd_flow_director_flow,
11029                 (void *)&cmd_flow_director_flow_type,
11030                 (void *)&cmd_flow_director_ether,
11031                 (void *)&cmd_flow_director_ether_type,
11032                 (void *)&cmd_flow_director_flexbytes,
11033                 (void *)&cmd_flow_director_flexbytes_value,
11034                 (void *)&cmd_flow_director_drop,
11035                 (void *)&cmd_flow_director_pf_vf,
11036                 (void *)&cmd_flow_director_queue,
11037                 (void *)&cmd_flow_director_queue_id,
11038                 (void *)&cmd_flow_director_fd_id,
11039                 (void *)&cmd_flow_director_fd_id_value,
11040                 NULL,
11041         },
11042 };
11043
11044 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11045         .f = cmd_flow_director_filter_parsed,
11046         .data = NULL,
11047         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11048                 "director entry on NIC",
11049         .tokens = {
11050                 (void *)&cmd_flow_director_filter,
11051                 (void *)&cmd_flow_director_port_id,
11052                 (void *)&cmd_flow_director_mode,
11053                 (void *)&cmd_flow_director_mode_mac_vlan,
11054                 (void *)&cmd_flow_director_ops,
11055                 (void *)&cmd_flow_director_mac,
11056                 (void *)&cmd_flow_director_mac_addr,
11057                 (void *)&cmd_flow_director_vlan,
11058                 (void *)&cmd_flow_director_vlan_value,
11059                 (void *)&cmd_flow_director_flexbytes,
11060                 (void *)&cmd_flow_director_flexbytes_value,
11061                 (void *)&cmd_flow_director_drop,
11062                 (void *)&cmd_flow_director_queue,
11063                 (void *)&cmd_flow_director_queue_id,
11064                 (void *)&cmd_flow_director_fd_id,
11065                 (void *)&cmd_flow_director_fd_id_value,
11066                 NULL,
11067         },
11068 };
11069
11070 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11071         .f = cmd_flow_director_filter_parsed,
11072         .data = NULL,
11073         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11074                 "director entry on NIC",
11075         .tokens = {
11076                 (void *)&cmd_flow_director_filter,
11077                 (void *)&cmd_flow_director_port_id,
11078                 (void *)&cmd_flow_director_mode,
11079                 (void *)&cmd_flow_director_mode_tunnel,
11080                 (void *)&cmd_flow_director_ops,
11081                 (void *)&cmd_flow_director_mac,
11082                 (void *)&cmd_flow_director_mac_addr,
11083                 (void *)&cmd_flow_director_vlan,
11084                 (void *)&cmd_flow_director_vlan_value,
11085                 (void *)&cmd_flow_director_tunnel,
11086                 (void *)&cmd_flow_director_tunnel_type,
11087                 (void *)&cmd_flow_director_tunnel_id,
11088                 (void *)&cmd_flow_director_tunnel_id_value,
11089                 (void *)&cmd_flow_director_flexbytes,
11090                 (void *)&cmd_flow_director_flexbytes_value,
11091                 (void *)&cmd_flow_director_drop,
11092                 (void *)&cmd_flow_director_queue,
11093                 (void *)&cmd_flow_director_queue_id,
11094                 (void *)&cmd_flow_director_fd_id,
11095                 (void *)&cmd_flow_director_fd_id_value,
11096                 NULL,
11097         },
11098 };
11099
11100 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11101         .f = cmd_flow_director_filter_parsed,
11102         .data = NULL,
11103         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11104                 "director entry on NIC",
11105         .tokens = {
11106                 (void *)&cmd_flow_director_filter,
11107                 (void *)&cmd_flow_director_port_id,
11108                 (void *)&cmd_flow_director_mode,
11109                 (void *)&cmd_flow_director_mode_raw,
11110                 (void *)&cmd_flow_director_ops,
11111                 (void *)&cmd_flow_director_flow,
11112                 (void *)&cmd_flow_director_flow_type,
11113                 (void *)&cmd_flow_director_drop,
11114                 (void *)&cmd_flow_director_queue,
11115                 (void *)&cmd_flow_director_queue_id,
11116                 (void *)&cmd_flow_director_fd_id,
11117                 (void *)&cmd_flow_director_fd_id_value,
11118                 (void *)&cmd_flow_director_packet,
11119                 (void *)&cmd_flow_director_filepath,
11120                 NULL,
11121         },
11122 };
11123
11124 struct cmd_flush_flow_director_result {
11125         cmdline_fixed_string_t flush_flow_director;
11126         portid_t port_id;
11127 };
11128
11129 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11130         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11131                                  flush_flow_director, "flush_flow_director");
11132 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11133         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11134                               port_id, UINT16);
11135
11136 static void
11137 cmd_flush_flow_director_parsed(void *parsed_result,
11138                           __attribute__((unused)) struct cmdline *cl,
11139                           __attribute__((unused)) void *data)
11140 {
11141         struct cmd_flow_director_result *res = parsed_result;
11142         int ret = 0;
11143
11144         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11145         if (ret < 0) {
11146                 printf("flow director is not supported on port %u.\n",
11147                         res->port_id);
11148                 return;
11149         }
11150
11151         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11152                         RTE_ETH_FILTER_FLUSH, NULL);
11153         if (ret < 0)
11154                 printf("flow director table flushing error: (%s)\n",
11155                         strerror(-ret));
11156 }
11157
11158 cmdline_parse_inst_t cmd_flush_flow_director = {
11159         .f = cmd_flush_flow_director_parsed,
11160         .data = NULL,
11161         .help_str = "flush_flow_director <port_id>: "
11162                 "Flush all flow director entries of a device on NIC",
11163         .tokens = {
11164                 (void *)&cmd_flush_flow_director_flush,
11165                 (void *)&cmd_flush_flow_director_port_id,
11166                 NULL,
11167         },
11168 };
11169
11170 /* *** deal with flow director mask *** */
11171 struct cmd_flow_director_mask_result {
11172         cmdline_fixed_string_t flow_director_mask;
11173         portid_t port_id;
11174         cmdline_fixed_string_t mode;
11175         cmdline_fixed_string_t mode_value;
11176         cmdline_fixed_string_t vlan;
11177         uint16_t vlan_mask;
11178         cmdline_fixed_string_t src_mask;
11179         cmdline_ipaddr_t ipv4_src;
11180         cmdline_ipaddr_t ipv6_src;
11181         uint16_t port_src;
11182         cmdline_fixed_string_t dst_mask;
11183         cmdline_ipaddr_t ipv4_dst;
11184         cmdline_ipaddr_t ipv6_dst;
11185         uint16_t port_dst;
11186         cmdline_fixed_string_t mac;
11187         uint8_t mac_addr_byte_mask;
11188         cmdline_fixed_string_t tunnel_id;
11189         uint32_t tunnel_id_mask;
11190         cmdline_fixed_string_t tunnel_type;
11191         uint8_t tunnel_type_mask;
11192 };
11193
11194 static void
11195 cmd_flow_director_mask_parsed(void *parsed_result,
11196                           __attribute__((unused)) struct cmdline *cl,
11197                           __attribute__((unused)) void *data)
11198 {
11199         struct cmd_flow_director_mask_result *res = parsed_result;
11200         struct rte_eth_fdir_masks *mask;
11201         struct rte_port *port;
11202
11203         port = &ports[res->port_id];
11204         /** Check if the port is not started **/
11205         if (port->port_status != RTE_PORT_STOPPED) {
11206                 printf("Please stop port %d first\n", res->port_id);
11207                 return;
11208         }
11209
11210         mask = &port->dev_conf.fdir_conf.mask;
11211
11212         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11213                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11214                         printf("Please set mode to MAC-VLAN.\n");
11215                         return;
11216                 }
11217
11218                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11219         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11220                 if (strcmp(res->mode_value, "Tunnel")) {
11221                         printf("Please set mode to Tunnel.\n");
11222                         return;
11223                 }
11224
11225                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11226                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11227                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11228                 mask->tunnel_type_mask = res->tunnel_type_mask;
11229         } else {
11230                 if (strcmp(res->mode_value, "IP")) {
11231                         printf("Please set mode to IP.\n");
11232                         return;
11233                 }
11234
11235                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11236                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11237                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11238                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11239                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11240                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11241                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11242         }
11243
11244         cmd_reconfig_device_queue(res->port_id, 1, 1);
11245 }
11246
11247 cmdline_parse_token_string_t cmd_flow_director_mask =
11248         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11249                                  flow_director_mask, "flow_director_mask");
11250 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11251         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11252                               port_id, UINT16);
11253 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11254         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11255                                  vlan, "vlan");
11256 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11257         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11258                               vlan_mask, UINT16);
11259 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11261                                  src_mask, "src_mask");
11262 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11263         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11264                                  ipv4_src);
11265 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11266         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11267                                  ipv6_src);
11268 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11269         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11270                               port_src, UINT16);
11271 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11273                                  dst_mask, "dst_mask");
11274 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11275         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11276                                  ipv4_dst);
11277 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11278         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11279                                  ipv6_dst);
11280 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11281         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11282                               port_dst, UINT16);
11283
11284 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11286                                  mode, "mode");
11287 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11289                                  mode_value, "IP");
11290 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11291         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11292                                  mode_value, "MAC-VLAN");
11293 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11295                                  mode_value, "Tunnel");
11296 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11298                                  mac, "mac");
11299 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11300         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11301                               mac_addr_byte_mask, UINT8);
11302 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11303         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11304                                  tunnel_type, "tunnel-type");
11305 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11306         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11307                               tunnel_type_mask, UINT8);
11308 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11309         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11310                                  tunnel_id, "tunnel-id");
11311 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11312         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11313                               tunnel_id_mask, UINT32);
11314
11315 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11316         .f = cmd_flow_director_mask_parsed,
11317         .data = NULL,
11318         .help_str = "flow_director_mask ... : "
11319                 "Set IP mode flow director's mask on NIC",
11320         .tokens = {
11321                 (void *)&cmd_flow_director_mask,
11322                 (void *)&cmd_flow_director_mask_port_id,
11323                 (void *)&cmd_flow_director_mask_mode,
11324                 (void *)&cmd_flow_director_mask_mode_ip,
11325                 (void *)&cmd_flow_director_mask_vlan,
11326                 (void *)&cmd_flow_director_mask_vlan_value,
11327                 (void *)&cmd_flow_director_mask_src,
11328                 (void *)&cmd_flow_director_mask_ipv4_src,
11329                 (void *)&cmd_flow_director_mask_ipv6_src,
11330                 (void *)&cmd_flow_director_mask_port_src,
11331                 (void *)&cmd_flow_director_mask_dst,
11332                 (void *)&cmd_flow_director_mask_ipv4_dst,
11333                 (void *)&cmd_flow_director_mask_ipv6_dst,
11334                 (void *)&cmd_flow_director_mask_port_dst,
11335                 NULL,
11336         },
11337 };
11338
11339 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11340         .f = cmd_flow_director_mask_parsed,
11341         .data = NULL,
11342         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11343                 "flow director's mask on NIC",
11344         .tokens = {
11345                 (void *)&cmd_flow_director_mask,
11346                 (void *)&cmd_flow_director_mask_port_id,
11347                 (void *)&cmd_flow_director_mask_mode,
11348                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11349                 (void *)&cmd_flow_director_mask_vlan,
11350                 (void *)&cmd_flow_director_mask_vlan_value,
11351                 NULL,
11352         },
11353 };
11354
11355 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11356         .f = cmd_flow_director_mask_parsed,
11357         .data = NULL,
11358         .help_str = "flow_director_mask ... : Set tunnel mode "
11359                 "flow director's mask on NIC",
11360         .tokens = {
11361                 (void *)&cmd_flow_director_mask,
11362                 (void *)&cmd_flow_director_mask_port_id,
11363                 (void *)&cmd_flow_director_mask_mode,
11364                 (void *)&cmd_flow_director_mask_mode_tunnel,
11365                 (void *)&cmd_flow_director_mask_vlan,
11366                 (void *)&cmd_flow_director_mask_vlan_value,
11367                 (void *)&cmd_flow_director_mask_mac,
11368                 (void *)&cmd_flow_director_mask_mac_value,
11369                 (void *)&cmd_flow_director_mask_tunnel_type,
11370                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11371                 (void *)&cmd_flow_director_mask_tunnel_id,
11372                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11373                 NULL,
11374         },
11375 };
11376
11377 /* *** deal with flow director mask on flexible payload *** */
11378 struct cmd_flow_director_flex_mask_result {
11379         cmdline_fixed_string_t flow_director_flexmask;
11380         portid_t port_id;
11381         cmdline_fixed_string_t flow;
11382         cmdline_fixed_string_t flow_type;
11383         cmdline_fixed_string_t mask;
11384 };
11385
11386 static void
11387 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11388                           __attribute__((unused)) struct cmdline *cl,
11389                           __attribute__((unused)) void *data)
11390 {
11391         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11392         struct rte_eth_fdir_info fdir_info;
11393         struct rte_eth_fdir_flex_mask flex_mask;
11394         struct rte_port *port;
11395         uint64_t flow_type_mask;
11396         uint16_t i;
11397         int ret;
11398
11399         port = &ports[res->port_id];
11400         /** Check if the port is not started **/
11401         if (port->port_status != RTE_PORT_STOPPED) {
11402                 printf("Please stop port %d first\n", res->port_id);
11403                 return;
11404         }
11405
11406         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11407         ret = parse_flexbytes(res->mask,
11408                         flex_mask.mask,
11409                         RTE_ETH_FDIR_MAX_FLEXLEN);
11410         if (ret < 0) {
11411                 printf("error: Cannot parse mask input.\n");
11412                 return;
11413         }
11414
11415         memset(&fdir_info, 0, sizeof(fdir_info));
11416         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11417                                 RTE_ETH_FILTER_INFO, &fdir_info);
11418         if (ret < 0) {
11419                 printf("Cannot get FDir filter info\n");
11420                 return;
11421         }
11422
11423         if (!strcmp(res->flow_type, "none")) {
11424                 /* means don't specify the flow type */
11425                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11426                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11427                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11428                                0, sizeof(struct rte_eth_fdir_flex_mask));
11429                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11430                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11431                                  &flex_mask,
11432                                  sizeof(struct rte_eth_fdir_flex_mask));
11433                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11434                 return;
11435         }
11436         flow_type_mask = fdir_info.flow_types_mask[0];
11437         if (!strcmp(res->flow_type, "all")) {
11438                 if (!flow_type_mask) {
11439                         printf("No flow type supported\n");
11440                         return;
11441                 }
11442                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11443                         if (flow_type_mask & (1ULL << i)) {
11444                                 flex_mask.flow_type = i;
11445                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11446                         }
11447                 }
11448                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11449                 return;
11450         }
11451         flex_mask.flow_type = str2flowtype(res->flow_type);
11452         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11453                 printf("Flow type %s not supported on port %d\n",
11454                                 res->flow_type, res->port_id);
11455                 return;
11456         }
11457         fdir_set_flex_mask(res->port_id, &flex_mask);
11458         cmd_reconfig_device_queue(res->port_id, 1, 1);
11459 }
11460
11461 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11463                                  flow_director_flexmask,
11464                                  "flow_director_flex_mask");
11465 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11466         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11467                               port_id, UINT16);
11468 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11469         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11470                                  flow, "flow");
11471 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11472         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11473                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11474                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11475 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11476         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11477                                  mask, NULL);
11478
11479 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11480         .f = cmd_flow_director_flex_mask_parsed,
11481         .data = NULL,
11482         .help_str = "flow_director_flex_mask ... : "
11483                 "Set flow director's flex mask on NIC",
11484         .tokens = {
11485                 (void *)&cmd_flow_director_flexmask,
11486                 (void *)&cmd_flow_director_flexmask_port_id,
11487                 (void *)&cmd_flow_director_flexmask_flow,
11488                 (void *)&cmd_flow_director_flexmask_flow_type,
11489                 (void *)&cmd_flow_director_flexmask_mask,
11490                 NULL,
11491         },
11492 };
11493
11494 /* *** deal with flow director flexible payload configuration *** */
11495 struct cmd_flow_director_flexpayload_result {
11496         cmdline_fixed_string_t flow_director_flexpayload;
11497         portid_t port_id;
11498         cmdline_fixed_string_t payload_layer;
11499         cmdline_fixed_string_t payload_cfg;
11500 };
11501
11502 static inline int
11503 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11504 {
11505         char s[256];
11506         const char *p, *p0 = q_arg;
11507         char *end;
11508         unsigned long int_fld;
11509         char *str_fld[max_num];
11510         int i;
11511         unsigned size;
11512         int ret = -1;
11513
11514         p = strchr(p0, '(');
11515         if (p == NULL)
11516                 return -1;
11517         ++p;
11518         p0 = strchr(p, ')');
11519         if (p0 == NULL)
11520                 return -1;
11521
11522         size = p0 - p;
11523         if (size >= sizeof(s))
11524                 return -1;
11525
11526         snprintf(s, sizeof(s), "%.*s", size, p);
11527         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11528         if (ret < 0 || ret > max_num)
11529                 return -1;
11530         for (i = 0; i < ret; i++) {
11531                 errno = 0;
11532                 int_fld = strtoul(str_fld[i], &end, 0);
11533                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11534                         return -1;
11535                 offsets[i] = (uint16_t)int_fld;
11536         }
11537         return ret;
11538 }
11539
11540 static void
11541 cmd_flow_director_flxpld_parsed(void *parsed_result,
11542                           __attribute__((unused)) struct cmdline *cl,
11543                           __attribute__((unused)) void *data)
11544 {
11545         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11546         struct rte_eth_flex_payload_cfg flex_cfg;
11547         struct rte_port *port;
11548         int ret = 0;
11549
11550         port = &ports[res->port_id];
11551         /** Check if the port is not started **/
11552         if (port->port_status != RTE_PORT_STOPPED) {
11553                 printf("Please stop port %d first\n", res->port_id);
11554                 return;
11555         }
11556
11557         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11558
11559         if (!strcmp(res->payload_layer, "raw"))
11560                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11561         else if (!strcmp(res->payload_layer, "l2"))
11562                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11563         else if (!strcmp(res->payload_layer, "l3"))
11564                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11565         else if (!strcmp(res->payload_layer, "l4"))
11566                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11567
11568         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11569                             RTE_ETH_FDIR_MAX_FLEXLEN);
11570         if (ret < 0) {
11571                 printf("error: Cannot parse flex payload input.\n");
11572                 return;
11573         }
11574
11575         fdir_set_flex_payload(res->port_id, &flex_cfg);
11576         cmd_reconfig_device_queue(res->port_id, 1, 1);
11577 }
11578
11579 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11580         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11581                                  flow_director_flexpayload,
11582                                  "flow_director_flex_payload");
11583 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11584         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11585                               port_id, UINT16);
11586 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11587         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11588                                  payload_layer, "raw#l2#l3#l4");
11589 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11591                                  payload_cfg, NULL);
11592
11593 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11594         .f = cmd_flow_director_flxpld_parsed,
11595         .data = NULL,
11596         .help_str = "flow_director_flexpayload ... : "
11597                 "Set flow director's flex payload on NIC",
11598         .tokens = {
11599                 (void *)&cmd_flow_director_flexpayload,
11600                 (void *)&cmd_flow_director_flexpayload_port_id,
11601                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11602                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11603                 NULL,
11604         },
11605 };
11606
11607 /* Generic flow interface command. */
11608 extern cmdline_parse_inst_t cmd_flow;
11609
11610 /* *** Classification Filters Control *** */
11611 /* *** Get symmetric hash enable per port *** */
11612 struct cmd_get_sym_hash_ena_per_port_result {
11613         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11614         portid_t port_id;
11615 };
11616
11617 static void
11618 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11619                                  __rte_unused struct cmdline *cl,
11620                                  __rte_unused void *data)
11621 {
11622         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11623         struct rte_eth_hash_filter_info info;
11624         int ret;
11625
11626         if (rte_eth_dev_filter_supported(res->port_id,
11627                                 RTE_ETH_FILTER_HASH) < 0) {
11628                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11629                                                         res->port_id);
11630                 return;
11631         }
11632
11633         memset(&info, 0, sizeof(info));
11634         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11635         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11636                                                 RTE_ETH_FILTER_GET, &info);
11637
11638         if (ret < 0) {
11639                 printf("Cannot get symmetric hash enable per port "
11640                                         "on port %u\n", res->port_id);
11641                 return;
11642         }
11643
11644         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11645                                 "enabled" : "disabled", res->port_id);
11646 }
11647
11648 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11649         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11650                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11651 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11652         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11653                 port_id, UINT16);
11654
11655 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11656         .f = cmd_get_sym_hash_per_port_parsed,
11657         .data = NULL,
11658         .help_str = "get_sym_hash_ena_per_port <port_id>",
11659         .tokens = {
11660                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11661                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11662                 NULL,
11663         },
11664 };
11665
11666 /* *** Set symmetric hash enable per port *** */
11667 struct cmd_set_sym_hash_ena_per_port_result {
11668         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11669         cmdline_fixed_string_t enable;
11670         portid_t port_id;
11671 };
11672
11673 static void
11674 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11675                                  __rte_unused struct cmdline *cl,
11676                                  __rte_unused void *data)
11677 {
11678         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11679         struct rte_eth_hash_filter_info info;
11680         int ret;
11681
11682         if (rte_eth_dev_filter_supported(res->port_id,
11683                                 RTE_ETH_FILTER_HASH) < 0) {
11684                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11685                                                         res->port_id);
11686                 return;
11687         }
11688
11689         memset(&info, 0, sizeof(info));
11690         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11691         if (!strcmp(res->enable, "enable"))
11692                 info.info.enable = 1;
11693         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11694                                         RTE_ETH_FILTER_SET, &info);
11695         if (ret < 0) {
11696                 printf("Cannot set symmetric hash enable per port on "
11697                                         "port %u\n", res->port_id);
11698                 return;
11699         }
11700         printf("Symmetric hash has been set to %s on port %u\n",
11701                                         res->enable, res->port_id);
11702 }
11703
11704 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11705         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11706                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11707 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11708         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11709                 port_id, UINT16);
11710 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11711         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11712                 enable, "enable#disable");
11713
11714 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11715         .f = cmd_set_sym_hash_per_port_parsed,
11716         .data = NULL,
11717         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11718         .tokens = {
11719                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11720                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11721                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11722                 NULL,
11723         },
11724 };
11725
11726 /* Get global config of hash function */
11727 struct cmd_get_hash_global_config_result {
11728         cmdline_fixed_string_t get_hash_global_config;
11729         portid_t port_id;
11730 };
11731
11732 static char *
11733 flowtype_to_str(uint16_t ftype)
11734 {
11735         uint16_t i;
11736         static struct {
11737                 char str[16];
11738                 uint16_t ftype;
11739         } ftype_table[] = {
11740                 {"ipv4", RTE_ETH_FLOW_IPV4},
11741                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11742                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11743                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11744                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11745                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11746                 {"ipv6", RTE_ETH_FLOW_IPV6},
11747                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11748                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11749                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11750                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11751                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11752                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11753                 {"port", RTE_ETH_FLOW_PORT},
11754                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11755                 {"geneve", RTE_ETH_FLOW_GENEVE},
11756                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11757         };
11758
11759         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11760                 if (ftype_table[i].ftype == ftype)
11761                         return ftype_table[i].str;
11762         }
11763
11764         return NULL;
11765 }
11766
11767 static void
11768 cmd_get_hash_global_config_parsed(void *parsed_result,
11769                                   __rte_unused struct cmdline *cl,
11770                                   __rte_unused void *data)
11771 {
11772         struct cmd_get_hash_global_config_result *res = parsed_result;
11773         struct rte_eth_hash_filter_info info;
11774         uint32_t idx, offset;
11775         uint16_t i;
11776         char *str;
11777         int ret;
11778
11779         if (rte_eth_dev_filter_supported(res->port_id,
11780                         RTE_ETH_FILTER_HASH) < 0) {
11781                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11782                                                         res->port_id);
11783                 return;
11784         }
11785
11786         memset(&info, 0, sizeof(info));
11787         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11788         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11789                                         RTE_ETH_FILTER_GET, &info);
11790         if (ret < 0) {
11791                 printf("Cannot get hash global configurations by port %d\n",
11792                                                         res->port_id);
11793                 return;
11794         }
11795
11796         switch (info.info.global_conf.hash_func) {
11797         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11798                 printf("Hash function is Toeplitz\n");
11799                 break;
11800         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11801                 printf("Hash function is Simple XOR\n");
11802                 break;
11803         default:
11804                 printf("Unknown hash function\n");
11805                 break;
11806         }
11807
11808         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11809                 idx = i / UINT64_BIT;
11810                 offset = i % UINT64_BIT;
11811                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11812                                                 (1ULL << offset)))
11813                         continue;
11814                 str = flowtype_to_str(i);
11815                 if (!str)
11816                         continue;
11817                 printf("Symmetric hash is %s globally for flow type %s "
11818                                                         "by port %d\n",
11819                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11820                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11821                                                         res->port_id);
11822         }
11823 }
11824
11825 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11826         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11827                 get_hash_global_config, "get_hash_global_config");
11828 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11829         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11830                 port_id, UINT16);
11831
11832 cmdline_parse_inst_t cmd_get_hash_global_config = {
11833         .f = cmd_get_hash_global_config_parsed,
11834         .data = NULL,
11835         .help_str = "get_hash_global_config <port_id>",
11836         .tokens = {
11837                 (void *)&cmd_get_hash_global_config_all,
11838                 (void *)&cmd_get_hash_global_config_port_id,
11839                 NULL,
11840         },
11841 };
11842
11843 /* Set global config of hash function */
11844 struct cmd_set_hash_global_config_result {
11845         cmdline_fixed_string_t set_hash_global_config;
11846         portid_t port_id;
11847         cmdline_fixed_string_t hash_func;
11848         cmdline_fixed_string_t flow_type;
11849         cmdline_fixed_string_t enable;
11850 };
11851
11852 static void
11853 cmd_set_hash_global_config_parsed(void *parsed_result,
11854                                   __rte_unused struct cmdline *cl,
11855                                   __rte_unused void *data)
11856 {
11857         struct cmd_set_hash_global_config_result *res = parsed_result;
11858         struct rte_eth_hash_filter_info info;
11859         uint32_t ftype, idx, offset;
11860         int ret;
11861
11862         if (rte_eth_dev_filter_supported(res->port_id,
11863                                 RTE_ETH_FILTER_HASH) < 0) {
11864                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11865                                                         res->port_id);
11866                 return;
11867         }
11868         memset(&info, 0, sizeof(info));
11869         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11870         if (!strcmp(res->hash_func, "toeplitz"))
11871                 info.info.global_conf.hash_func =
11872                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11873         else if (!strcmp(res->hash_func, "simple_xor"))
11874                 info.info.global_conf.hash_func =
11875                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11876         else if (!strcmp(res->hash_func, "default"))
11877                 info.info.global_conf.hash_func =
11878                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11879
11880         ftype = str2flowtype(res->flow_type);
11881         idx = ftype / UINT64_BIT;
11882         offset = ftype % UINT64_BIT;
11883         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11884         if (!strcmp(res->enable, "enable"))
11885                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11886                                                 (1ULL << offset);
11887         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11888                                         RTE_ETH_FILTER_SET, &info);
11889         if (ret < 0)
11890                 printf("Cannot set global hash configurations by port %d\n",
11891                                                         res->port_id);
11892         else
11893                 printf("Global hash configurations have been set "
11894                         "succcessfully by port %d\n", res->port_id);
11895 }
11896
11897 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11898         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11899                 set_hash_global_config, "set_hash_global_config");
11900 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11901         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11902                 port_id, UINT16);
11903 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11904         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11905                 hash_func, "toeplitz#simple_xor#default");
11906 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11907         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11908                 flow_type,
11909                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11910                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11911 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11912         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11913                 enable, "enable#disable");
11914
11915 cmdline_parse_inst_t cmd_set_hash_global_config = {
11916         .f = cmd_set_hash_global_config_parsed,
11917         .data = NULL,
11918         .help_str = "set_hash_global_config <port_id> "
11919                 "toeplitz|simple_xor|default "
11920                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11921                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11922                 "l2_payload enable|disable",
11923         .tokens = {
11924                 (void *)&cmd_set_hash_global_config_all,
11925                 (void *)&cmd_set_hash_global_config_port_id,
11926                 (void *)&cmd_set_hash_global_config_hash_func,
11927                 (void *)&cmd_set_hash_global_config_flow_type,
11928                 (void *)&cmd_set_hash_global_config_enable,
11929                 NULL,
11930         },
11931 };
11932
11933 /* Set hash input set */
11934 struct cmd_set_hash_input_set_result {
11935         cmdline_fixed_string_t set_hash_input_set;
11936         portid_t port_id;
11937         cmdline_fixed_string_t flow_type;
11938         cmdline_fixed_string_t inset_field;
11939         cmdline_fixed_string_t select;
11940 };
11941
11942 static enum rte_eth_input_set_field
11943 str2inset(char *string)
11944 {
11945         uint16_t i;
11946
11947         static const struct {
11948                 char str[32];
11949                 enum rte_eth_input_set_field inset;
11950         } inset_table[] = {
11951                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11952                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11953                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11954                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11955                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11956                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11957                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11958                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11959                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11960                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11961                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11962                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11963                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11964                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11965                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11966                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11967                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11968                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11969                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11970                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11971                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11972                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11973                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11974                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11975                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11976                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11977                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11978                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11979                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11980                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11981                 {"none", RTE_ETH_INPUT_SET_NONE},
11982         };
11983
11984         for (i = 0; i < RTE_DIM(inset_table); i++) {
11985                 if (!strcmp(string, inset_table[i].str))
11986                         return inset_table[i].inset;
11987         }
11988
11989         return RTE_ETH_INPUT_SET_UNKNOWN;
11990 }
11991
11992 static void
11993 cmd_set_hash_input_set_parsed(void *parsed_result,
11994                               __rte_unused struct cmdline *cl,
11995                               __rte_unused void *data)
11996 {
11997         struct cmd_set_hash_input_set_result *res = parsed_result;
11998         struct rte_eth_hash_filter_info info;
11999
12000         memset(&info, 0, sizeof(info));
12001         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12002         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12003         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12004         info.info.input_set_conf.inset_size = 1;
12005         if (!strcmp(res->select, "select"))
12006                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12007         else if (!strcmp(res->select, "add"))
12008                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12009         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12010                                 RTE_ETH_FILTER_SET, &info);
12011 }
12012
12013 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12014         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12015                 set_hash_input_set, "set_hash_input_set");
12016 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12017         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12018                 port_id, UINT16);
12019 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12020         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12021                 flow_type, NULL);
12022 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12023         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12024                 inset_field,
12025                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12026                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12027                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12028                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12029                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12030                 "fld-8th#none");
12031 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12032         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12033                 select, "select#add");
12034
12035 cmdline_parse_inst_t cmd_set_hash_input_set = {
12036         .f = cmd_set_hash_input_set_parsed,
12037         .data = NULL,
12038         .help_str = "set_hash_input_set <port_id> "
12039         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12040         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12041         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12042         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12043         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12044         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12045         "fld-7th|fld-8th|none select|add",
12046         .tokens = {
12047                 (void *)&cmd_set_hash_input_set_cmd,
12048                 (void *)&cmd_set_hash_input_set_port_id,
12049                 (void *)&cmd_set_hash_input_set_flow_type,
12050                 (void *)&cmd_set_hash_input_set_field,
12051                 (void *)&cmd_set_hash_input_set_select,
12052                 NULL,
12053         },
12054 };
12055
12056 /* Set flow director input set */
12057 struct cmd_set_fdir_input_set_result {
12058         cmdline_fixed_string_t set_fdir_input_set;
12059         portid_t port_id;
12060         cmdline_fixed_string_t flow_type;
12061         cmdline_fixed_string_t inset_field;
12062         cmdline_fixed_string_t select;
12063 };
12064
12065 static void
12066 cmd_set_fdir_input_set_parsed(void *parsed_result,
12067         __rte_unused struct cmdline *cl,
12068         __rte_unused void *data)
12069 {
12070         struct cmd_set_fdir_input_set_result *res = parsed_result;
12071         struct rte_eth_fdir_filter_info info;
12072
12073         memset(&info, 0, sizeof(info));
12074         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12075         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12076         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12077         info.info.input_set_conf.inset_size = 1;
12078         if (!strcmp(res->select, "select"))
12079                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12080         else if (!strcmp(res->select, "add"))
12081                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12082         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12083                 RTE_ETH_FILTER_SET, &info);
12084 }
12085
12086 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12087         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12088         set_fdir_input_set, "set_fdir_input_set");
12089 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12090         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12091         port_id, UINT16);
12092 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12093         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12094         flow_type,
12095         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12096         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12097 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12098         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12099         inset_field,
12100         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12101         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12102         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12103         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12104         "sctp-veri-tag#none");
12105 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12106         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12107         select, "select#add");
12108
12109 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12110         .f = cmd_set_fdir_input_set_parsed,
12111         .data = NULL,
12112         .help_str = "set_fdir_input_set <port_id> "
12113         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12114         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12115         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12116         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12117         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12118         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12119         "sctp-veri-tag|none select|add",
12120         .tokens = {
12121                 (void *)&cmd_set_fdir_input_set_cmd,
12122                 (void *)&cmd_set_fdir_input_set_port_id,
12123                 (void *)&cmd_set_fdir_input_set_flow_type,
12124                 (void *)&cmd_set_fdir_input_set_field,
12125                 (void *)&cmd_set_fdir_input_set_select,
12126                 NULL,
12127         },
12128 };
12129
12130 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12131 struct cmd_mcast_addr_result {
12132         cmdline_fixed_string_t mcast_addr_cmd;
12133         cmdline_fixed_string_t what;
12134         uint16_t port_num;
12135         struct ether_addr mc_addr;
12136 };
12137
12138 static void cmd_mcast_addr_parsed(void *parsed_result,
12139                 __attribute__((unused)) struct cmdline *cl,
12140                 __attribute__((unused)) void *data)
12141 {
12142         struct cmd_mcast_addr_result *res = parsed_result;
12143
12144         if (!is_multicast_ether_addr(&res->mc_addr)) {
12145                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12146                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12147                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12148                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12149                 return;
12150         }
12151         if (strcmp(res->what, "add") == 0)
12152                 mcast_addr_add(res->port_num, &res->mc_addr);
12153         else
12154                 mcast_addr_remove(res->port_num, &res->mc_addr);
12155 }
12156
12157 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12158         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12159                                  mcast_addr_cmd, "mcast_addr");
12160 cmdline_parse_token_string_t cmd_mcast_addr_what =
12161         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12162                                  "add#remove");
12163 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12164         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12165 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12166         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12167
12168 cmdline_parse_inst_t cmd_mcast_addr = {
12169         .f = cmd_mcast_addr_parsed,
12170         .data = (void *)0,
12171         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12172                 "Add/Remove multicast MAC address on port_id",
12173         .tokens = {
12174                 (void *)&cmd_mcast_addr_cmd,
12175                 (void *)&cmd_mcast_addr_what,
12176                 (void *)&cmd_mcast_addr_portnum,
12177                 (void *)&cmd_mcast_addr_addr,
12178                 NULL,
12179         },
12180 };
12181
12182 /* l2 tunnel config
12183  * only support E-tag now.
12184  */
12185
12186 /* Ether type config */
12187 struct cmd_config_l2_tunnel_eth_type_result {
12188         cmdline_fixed_string_t port;
12189         cmdline_fixed_string_t config;
12190         cmdline_fixed_string_t all;
12191         portid_t id;
12192         cmdline_fixed_string_t l2_tunnel;
12193         cmdline_fixed_string_t l2_tunnel_type;
12194         cmdline_fixed_string_t eth_type;
12195         uint16_t eth_type_val;
12196 };
12197
12198 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12199         TOKEN_STRING_INITIALIZER
12200                 (struct cmd_config_l2_tunnel_eth_type_result,
12201                  port, "port");
12202 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_config_l2_tunnel_eth_type_result,
12205                  config, "config");
12206 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12207         TOKEN_STRING_INITIALIZER
12208                 (struct cmd_config_l2_tunnel_eth_type_result,
12209                  all, "all");
12210 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12211         TOKEN_NUM_INITIALIZER
12212                 (struct cmd_config_l2_tunnel_eth_type_result,
12213                  id, UINT16);
12214 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12215         TOKEN_STRING_INITIALIZER
12216                 (struct cmd_config_l2_tunnel_eth_type_result,
12217                  l2_tunnel, "l2-tunnel");
12218 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12219         TOKEN_STRING_INITIALIZER
12220                 (struct cmd_config_l2_tunnel_eth_type_result,
12221                  l2_tunnel_type, "E-tag");
12222 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12223         TOKEN_STRING_INITIALIZER
12224                 (struct cmd_config_l2_tunnel_eth_type_result,
12225                  eth_type, "ether-type");
12226 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12227         TOKEN_NUM_INITIALIZER
12228                 (struct cmd_config_l2_tunnel_eth_type_result,
12229                  eth_type_val, UINT16);
12230
12231 static enum rte_eth_tunnel_type
12232 str2fdir_l2_tunnel_type(char *string)
12233 {
12234         uint32_t i = 0;
12235
12236         static const struct {
12237                 char str[32];
12238                 enum rte_eth_tunnel_type type;
12239         } l2_tunnel_type_str[] = {
12240                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12241         };
12242
12243         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12244                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12245                         return l2_tunnel_type_str[i].type;
12246         }
12247         return RTE_TUNNEL_TYPE_NONE;
12248 }
12249
12250 /* ether type config for all ports */
12251 static void
12252 cmd_config_l2_tunnel_eth_type_all_parsed
12253         (void *parsed_result,
12254          __attribute__((unused)) struct cmdline *cl,
12255          __attribute__((unused)) void *data)
12256 {
12257         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12258         struct rte_eth_l2_tunnel_conf entry;
12259         portid_t pid;
12260
12261         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12262         entry.ether_type = res->eth_type_val;
12263
12264         RTE_ETH_FOREACH_DEV(pid) {
12265                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12266         }
12267 }
12268
12269 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12270         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12271         .data = NULL,
12272         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12273         .tokens = {
12274                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12275                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12276                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12277                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12278                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12279                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12280                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12281                 NULL,
12282         },
12283 };
12284
12285 /* ether type config for a specific port */
12286 static void
12287 cmd_config_l2_tunnel_eth_type_specific_parsed(
12288         void *parsed_result,
12289         __attribute__((unused)) struct cmdline *cl,
12290         __attribute__((unused)) void *data)
12291 {
12292         struct cmd_config_l2_tunnel_eth_type_result *res =
12293                  parsed_result;
12294         struct rte_eth_l2_tunnel_conf entry;
12295
12296         if (port_id_is_invalid(res->id, ENABLED_WARN))
12297                 return;
12298
12299         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12300         entry.ether_type = res->eth_type_val;
12301
12302         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12303 }
12304
12305 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12306         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12307         .data = NULL,
12308         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12309         .tokens = {
12310                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12311                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12312                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12313                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12314                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12315                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12316                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12317                 NULL,
12318         },
12319 };
12320
12321 /* Enable/disable l2 tunnel */
12322 struct cmd_config_l2_tunnel_en_dis_result {
12323         cmdline_fixed_string_t port;
12324         cmdline_fixed_string_t config;
12325         cmdline_fixed_string_t all;
12326         portid_t id;
12327         cmdline_fixed_string_t l2_tunnel;
12328         cmdline_fixed_string_t l2_tunnel_type;
12329         cmdline_fixed_string_t en_dis;
12330 };
12331
12332 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12333         TOKEN_STRING_INITIALIZER
12334                 (struct cmd_config_l2_tunnel_en_dis_result,
12335                  port, "port");
12336 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12337         TOKEN_STRING_INITIALIZER
12338                 (struct cmd_config_l2_tunnel_en_dis_result,
12339                  config, "config");
12340 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12341         TOKEN_STRING_INITIALIZER
12342                 (struct cmd_config_l2_tunnel_en_dis_result,
12343                  all, "all");
12344 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12345         TOKEN_NUM_INITIALIZER
12346                 (struct cmd_config_l2_tunnel_en_dis_result,
12347                  id, UINT16);
12348 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12349         TOKEN_STRING_INITIALIZER
12350                 (struct cmd_config_l2_tunnel_en_dis_result,
12351                  l2_tunnel, "l2-tunnel");
12352 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12353         TOKEN_STRING_INITIALIZER
12354                 (struct cmd_config_l2_tunnel_en_dis_result,
12355                  l2_tunnel_type, "E-tag");
12356 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12357         TOKEN_STRING_INITIALIZER
12358                 (struct cmd_config_l2_tunnel_en_dis_result,
12359                  en_dis, "enable#disable");
12360
12361 /* enable/disable l2 tunnel for all ports */
12362 static void
12363 cmd_config_l2_tunnel_en_dis_all_parsed(
12364         void *parsed_result,
12365         __attribute__((unused)) struct cmdline *cl,
12366         __attribute__((unused)) void *data)
12367 {
12368         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12369         struct rte_eth_l2_tunnel_conf entry;
12370         portid_t pid;
12371         uint8_t en;
12372
12373         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12374
12375         if (!strcmp("enable", res->en_dis))
12376                 en = 1;
12377         else
12378                 en = 0;
12379
12380         RTE_ETH_FOREACH_DEV(pid) {
12381                 rte_eth_dev_l2_tunnel_offload_set(pid,
12382                                                   &entry,
12383                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12384                                                   en);
12385         }
12386 }
12387
12388 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12389         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12390         .data = NULL,
12391         .help_str = "port config all l2-tunnel E-tag enable|disable",
12392         .tokens = {
12393                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12394                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12395                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12396                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12397                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12398                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12399                 NULL,
12400         },
12401 };
12402
12403 /* enable/disable l2 tunnel for a port */
12404 static void
12405 cmd_config_l2_tunnel_en_dis_specific_parsed(
12406         void *parsed_result,
12407         __attribute__((unused)) struct cmdline *cl,
12408         __attribute__((unused)) void *data)
12409 {
12410         struct cmd_config_l2_tunnel_en_dis_result *res =
12411                 parsed_result;
12412         struct rte_eth_l2_tunnel_conf entry;
12413
12414         if (port_id_is_invalid(res->id, ENABLED_WARN))
12415                 return;
12416
12417         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12418
12419         if (!strcmp("enable", res->en_dis))
12420                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12421                                                   &entry,
12422                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12423                                                   1);
12424         else
12425                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12426                                                   &entry,
12427                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12428                                                   0);
12429 }
12430
12431 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12432         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12433         .data = NULL,
12434         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12435         .tokens = {
12436                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12437                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12438                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12439                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12440                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12441                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12442                 NULL,
12443         },
12444 };
12445
12446 /* E-tag configuration */
12447
12448 /* Common result structure for all E-tag configuration */
12449 struct cmd_config_e_tag_result {
12450         cmdline_fixed_string_t e_tag;
12451         cmdline_fixed_string_t set;
12452         cmdline_fixed_string_t insertion;
12453         cmdline_fixed_string_t stripping;
12454         cmdline_fixed_string_t forwarding;
12455         cmdline_fixed_string_t filter;
12456         cmdline_fixed_string_t add;
12457         cmdline_fixed_string_t del;
12458         cmdline_fixed_string_t on;
12459         cmdline_fixed_string_t off;
12460         cmdline_fixed_string_t on_off;
12461         cmdline_fixed_string_t port_tag_id;
12462         uint32_t port_tag_id_val;
12463         cmdline_fixed_string_t e_tag_id;
12464         uint16_t e_tag_id_val;
12465         cmdline_fixed_string_t dst_pool;
12466         uint8_t dst_pool_val;
12467         cmdline_fixed_string_t port;
12468         portid_t port_id;
12469         cmdline_fixed_string_t vf;
12470         uint8_t vf_id;
12471 };
12472
12473 /* Common CLI fields for all E-tag configuration */
12474 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12475         TOKEN_STRING_INITIALIZER
12476                 (struct cmd_config_e_tag_result,
12477                  e_tag, "E-tag");
12478 cmdline_parse_token_string_t cmd_config_e_tag_set =
12479         TOKEN_STRING_INITIALIZER
12480                 (struct cmd_config_e_tag_result,
12481                  set, "set");
12482 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_config_e_tag_result,
12485                  insertion, "insertion");
12486 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_config_e_tag_result,
12489                  stripping, "stripping");
12490 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12491         TOKEN_STRING_INITIALIZER
12492                 (struct cmd_config_e_tag_result,
12493                  forwarding, "forwarding");
12494 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12495         TOKEN_STRING_INITIALIZER
12496                 (struct cmd_config_e_tag_result,
12497                  filter, "filter");
12498 cmdline_parse_token_string_t cmd_config_e_tag_add =
12499         TOKEN_STRING_INITIALIZER
12500                 (struct cmd_config_e_tag_result,
12501                  add, "add");
12502 cmdline_parse_token_string_t cmd_config_e_tag_del =
12503         TOKEN_STRING_INITIALIZER
12504                 (struct cmd_config_e_tag_result,
12505                  del, "del");
12506 cmdline_parse_token_string_t cmd_config_e_tag_on =
12507         TOKEN_STRING_INITIALIZER
12508                 (struct cmd_config_e_tag_result,
12509                  on, "on");
12510 cmdline_parse_token_string_t cmd_config_e_tag_off =
12511         TOKEN_STRING_INITIALIZER
12512                 (struct cmd_config_e_tag_result,
12513                  off, "off");
12514 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12515         TOKEN_STRING_INITIALIZER
12516                 (struct cmd_config_e_tag_result,
12517                  on_off, "on#off");
12518 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12519         TOKEN_STRING_INITIALIZER
12520                 (struct cmd_config_e_tag_result,
12521                  port_tag_id, "port-tag-id");
12522 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12523         TOKEN_NUM_INITIALIZER
12524                 (struct cmd_config_e_tag_result,
12525                  port_tag_id_val, UINT32);
12526 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12527         TOKEN_STRING_INITIALIZER
12528                 (struct cmd_config_e_tag_result,
12529                  e_tag_id, "e-tag-id");
12530 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12531         TOKEN_NUM_INITIALIZER
12532                 (struct cmd_config_e_tag_result,
12533                  e_tag_id_val, UINT16);
12534 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12535         TOKEN_STRING_INITIALIZER
12536                 (struct cmd_config_e_tag_result,
12537                  dst_pool, "dst-pool");
12538 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12539         TOKEN_NUM_INITIALIZER
12540                 (struct cmd_config_e_tag_result,
12541                  dst_pool_val, UINT8);
12542 cmdline_parse_token_string_t cmd_config_e_tag_port =
12543         TOKEN_STRING_INITIALIZER
12544                 (struct cmd_config_e_tag_result,
12545                  port, "port");
12546 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12547         TOKEN_NUM_INITIALIZER
12548                 (struct cmd_config_e_tag_result,
12549                  port_id, UINT16);
12550 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12551         TOKEN_STRING_INITIALIZER
12552                 (struct cmd_config_e_tag_result,
12553                  vf, "vf");
12554 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12555         TOKEN_NUM_INITIALIZER
12556                 (struct cmd_config_e_tag_result,
12557                  vf_id, UINT8);
12558
12559 /* E-tag insertion configuration */
12560 static void
12561 cmd_config_e_tag_insertion_en_parsed(
12562         void *parsed_result,
12563         __attribute__((unused)) struct cmdline *cl,
12564         __attribute__((unused)) void *data)
12565 {
12566         struct cmd_config_e_tag_result *res =
12567                 parsed_result;
12568         struct rte_eth_l2_tunnel_conf entry;
12569
12570         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12571                 return;
12572
12573         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12574         entry.tunnel_id = res->port_tag_id_val;
12575         entry.vf_id = res->vf_id;
12576         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12577                                           &entry,
12578                                           ETH_L2_TUNNEL_INSERTION_MASK,
12579                                           1);
12580 }
12581
12582 static void
12583 cmd_config_e_tag_insertion_dis_parsed(
12584         void *parsed_result,
12585         __attribute__((unused)) struct cmdline *cl,
12586         __attribute__((unused)) void *data)
12587 {
12588         struct cmd_config_e_tag_result *res =
12589                 parsed_result;
12590         struct rte_eth_l2_tunnel_conf entry;
12591
12592         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12593                 return;
12594
12595         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12596         entry.vf_id = res->vf_id;
12597
12598         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12599                                           &entry,
12600                                           ETH_L2_TUNNEL_INSERTION_MASK,
12601                                           0);
12602 }
12603
12604 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12605         .f = cmd_config_e_tag_insertion_en_parsed,
12606         .data = NULL,
12607         .help_str = "E-tag ... : E-tag insertion enable",
12608         .tokens = {
12609                 (void *)&cmd_config_e_tag_e_tag,
12610                 (void *)&cmd_config_e_tag_set,
12611                 (void *)&cmd_config_e_tag_insertion,
12612                 (void *)&cmd_config_e_tag_on,
12613                 (void *)&cmd_config_e_tag_port_tag_id,
12614                 (void *)&cmd_config_e_tag_port_tag_id_val,
12615                 (void *)&cmd_config_e_tag_port,
12616                 (void *)&cmd_config_e_tag_port_id,
12617                 (void *)&cmd_config_e_tag_vf,
12618                 (void *)&cmd_config_e_tag_vf_id,
12619                 NULL,
12620         },
12621 };
12622
12623 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12624         .f = cmd_config_e_tag_insertion_dis_parsed,
12625         .data = NULL,
12626         .help_str = "E-tag ... : E-tag insertion disable",
12627         .tokens = {
12628                 (void *)&cmd_config_e_tag_e_tag,
12629                 (void *)&cmd_config_e_tag_set,
12630                 (void *)&cmd_config_e_tag_insertion,
12631                 (void *)&cmd_config_e_tag_off,
12632                 (void *)&cmd_config_e_tag_port,
12633                 (void *)&cmd_config_e_tag_port_id,
12634                 (void *)&cmd_config_e_tag_vf,
12635                 (void *)&cmd_config_e_tag_vf_id,
12636                 NULL,
12637         },
12638 };
12639
12640 /* E-tag stripping configuration */
12641 static void
12642 cmd_config_e_tag_stripping_parsed(
12643         void *parsed_result,
12644         __attribute__((unused)) struct cmdline *cl,
12645         __attribute__((unused)) void *data)
12646 {
12647         struct cmd_config_e_tag_result *res =
12648                 parsed_result;
12649         struct rte_eth_l2_tunnel_conf entry;
12650
12651         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12652                 return;
12653
12654         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12655
12656         if (!strcmp(res->on_off, "on"))
12657                 rte_eth_dev_l2_tunnel_offload_set
12658                         (res->port_id,
12659                          &entry,
12660                          ETH_L2_TUNNEL_STRIPPING_MASK,
12661                          1);
12662         else
12663                 rte_eth_dev_l2_tunnel_offload_set
12664                         (res->port_id,
12665                          &entry,
12666                          ETH_L2_TUNNEL_STRIPPING_MASK,
12667                          0);
12668 }
12669
12670 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12671         .f = cmd_config_e_tag_stripping_parsed,
12672         .data = NULL,
12673         .help_str = "E-tag ... : E-tag stripping enable/disable",
12674         .tokens = {
12675                 (void *)&cmd_config_e_tag_e_tag,
12676                 (void *)&cmd_config_e_tag_set,
12677                 (void *)&cmd_config_e_tag_stripping,
12678                 (void *)&cmd_config_e_tag_on_off,
12679                 (void *)&cmd_config_e_tag_port,
12680                 (void *)&cmd_config_e_tag_port_id,
12681                 NULL,
12682         },
12683 };
12684
12685 /* E-tag forwarding configuration */
12686 static void
12687 cmd_config_e_tag_forwarding_parsed(
12688         void *parsed_result,
12689         __attribute__((unused)) struct cmdline *cl,
12690         __attribute__((unused)) void *data)
12691 {
12692         struct cmd_config_e_tag_result *res = parsed_result;
12693         struct rte_eth_l2_tunnel_conf entry;
12694
12695         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12696                 return;
12697
12698         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12699
12700         if (!strcmp(res->on_off, "on"))
12701                 rte_eth_dev_l2_tunnel_offload_set
12702                         (res->port_id,
12703                          &entry,
12704                          ETH_L2_TUNNEL_FORWARDING_MASK,
12705                          1);
12706         else
12707                 rte_eth_dev_l2_tunnel_offload_set
12708                         (res->port_id,
12709                          &entry,
12710                          ETH_L2_TUNNEL_FORWARDING_MASK,
12711                          0);
12712 }
12713
12714 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12715         .f = cmd_config_e_tag_forwarding_parsed,
12716         .data = NULL,
12717         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12718         .tokens = {
12719                 (void *)&cmd_config_e_tag_e_tag,
12720                 (void *)&cmd_config_e_tag_set,
12721                 (void *)&cmd_config_e_tag_forwarding,
12722                 (void *)&cmd_config_e_tag_on_off,
12723                 (void *)&cmd_config_e_tag_port,
12724                 (void *)&cmd_config_e_tag_port_id,
12725                 NULL,
12726         },
12727 };
12728
12729 /* E-tag filter configuration */
12730 static void
12731 cmd_config_e_tag_filter_add_parsed(
12732         void *parsed_result,
12733         __attribute__((unused)) struct cmdline *cl,
12734         __attribute__((unused)) void *data)
12735 {
12736         struct cmd_config_e_tag_result *res = parsed_result;
12737         struct rte_eth_l2_tunnel_conf entry;
12738         int ret = 0;
12739
12740         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12741                 return;
12742
12743         if (res->e_tag_id_val > 0x3fff) {
12744                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12745                 return;
12746         }
12747
12748         ret = rte_eth_dev_filter_supported(res->port_id,
12749                                            RTE_ETH_FILTER_L2_TUNNEL);
12750         if (ret < 0) {
12751                 printf("E-tag filter is not supported on port %u.\n",
12752                        res->port_id);
12753                 return;
12754         }
12755
12756         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12757         entry.tunnel_id = res->e_tag_id_val;
12758         entry.pool = res->dst_pool_val;
12759
12760         ret = rte_eth_dev_filter_ctrl(res->port_id,
12761                                       RTE_ETH_FILTER_L2_TUNNEL,
12762                                       RTE_ETH_FILTER_ADD,
12763                                       &entry);
12764         if (ret < 0)
12765                 printf("E-tag filter programming error: (%s)\n",
12766                        strerror(-ret));
12767 }
12768
12769 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12770         .f = cmd_config_e_tag_filter_add_parsed,
12771         .data = NULL,
12772         .help_str = "E-tag ... : E-tag filter add",
12773         .tokens = {
12774                 (void *)&cmd_config_e_tag_e_tag,
12775                 (void *)&cmd_config_e_tag_set,
12776                 (void *)&cmd_config_e_tag_filter,
12777                 (void *)&cmd_config_e_tag_add,
12778                 (void *)&cmd_config_e_tag_e_tag_id,
12779                 (void *)&cmd_config_e_tag_e_tag_id_val,
12780                 (void *)&cmd_config_e_tag_dst_pool,
12781                 (void *)&cmd_config_e_tag_dst_pool_val,
12782                 (void *)&cmd_config_e_tag_port,
12783                 (void *)&cmd_config_e_tag_port_id,
12784                 NULL,
12785         },
12786 };
12787
12788 static void
12789 cmd_config_e_tag_filter_del_parsed(
12790         void *parsed_result,
12791         __attribute__((unused)) struct cmdline *cl,
12792         __attribute__((unused)) void *data)
12793 {
12794         struct cmd_config_e_tag_result *res = parsed_result;
12795         struct rte_eth_l2_tunnel_conf entry;
12796         int ret = 0;
12797
12798         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12799                 return;
12800
12801         if (res->e_tag_id_val > 0x3fff) {
12802                 printf("e-tag-id must be less than 0x3fff.\n");
12803                 return;
12804         }
12805
12806         ret = rte_eth_dev_filter_supported(res->port_id,
12807                                            RTE_ETH_FILTER_L2_TUNNEL);
12808         if (ret < 0) {
12809                 printf("E-tag filter is not supported on port %u.\n",
12810                        res->port_id);
12811                 return;
12812         }
12813
12814         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12815         entry.tunnel_id = res->e_tag_id_val;
12816
12817         ret = rte_eth_dev_filter_ctrl(res->port_id,
12818                                       RTE_ETH_FILTER_L2_TUNNEL,
12819                                       RTE_ETH_FILTER_DELETE,
12820                                       &entry);
12821         if (ret < 0)
12822                 printf("E-tag filter programming error: (%s)\n",
12823                        strerror(-ret));
12824 }
12825
12826 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12827         .f = cmd_config_e_tag_filter_del_parsed,
12828         .data = NULL,
12829         .help_str = "E-tag ... : E-tag filter delete",
12830         .tokens = {
12831                 (void *)&cmd_config_e_tag_e_tag,
12832                 (void *)&cmd_config_e_tag_set,
12833                 (void *)&cmd_config_e_tag_filter,
12834                 (void *)&cmd_config_e_tag_del,
12835                 (void *)&cmd_config_e_tag_e_tag_id,
12836                 (void *)&cmd_config_e_tag_e_tag_id_val,
12837                 (void *)&cmd_config_e_tag_port,
12838                 (void *)&cmd_config_e_tag_port_id,
12839                 NULL,
12840         },
12841 };
12842
12843 /* vf vlan anti spoof configuration */
12844
12845 /* Common result structure for vf vlan anti spoof */
12846 struct cmd_vf_vlan_anti_spoof_result {
12847         cmdline_fixed_string_t set;
12848         cmdline_fixed_string_t vf;
12849         cmdline_fixed_string_t vlan;
12850         cmdline_fixed_string_t antispoof;
12851         portid_t port_id;
12852         uint32_t vf_id;
12853         cmdline_fixed_string_t on_off;
12854 };
12855
12856 /* Common CLI fields for vf vlan anti spoof enable disable */
12857 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12858         TOKEN_STRING_INITIALIZER
12859                 (struct cmd_vf_vlan_anti_spoof_result,
12860                  set, "set");
12861 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12862         TOKEN_STRING_INITIALIZER
12863                 (struct cmd_vf_vlan_anti_spoof_result,
12864                  vf, "vf");
12865 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12866         TOKEN_STRING_INITIALIZER
12867                 (struct cmd_vf_vlan_anti_spoof_result,
12868                  vlan, "vlan");
12869 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12870         TOKEN_STRING_INITIALIZER
12871                 (struct cmd_vf_vlan_anti_spoof_result,
12872                  antispoof, "antispoof");
12873 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12874         TOKEN_NUM_INITIALIZER
12875                 (struct cmd_vf_vlan_anti_spoof_result,
12876                  port_id, UINT16);
12877 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12878         TOKEN_NUM_INITIALIZER
12879                 (struct cmd_vf_vlan_anti_spoof_result,
12880                  vf_id, UINT32);
12881 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12882         TOKEN_STRING_INITIALIZER
12883                 (struct cmd_vf_vlan_anti_spoof_result,
12884                  on_off, "on#off");
12885
12886 static void
12887 cmd_set_vf_vlan_anti_spoof_parsed(
12888         void *parsed_result,
12889         __attribute__((unused)) struct cmdline *cl,
12890         __attribute__((unused)) void *data)
12891 {
12892         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12893         int ret = -ENOTSUP;
12894
12895         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12896
12897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12898                 return;
12899
12900 #ifdef RTE_LIBRTE_IXGBE_PMD
12901         if (ret == -ENOTSUP)
12902                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12903                                 res->vf_id, is_on);
12904 #endif
12905 #ifdef RTE_LIBRTE_I40E_PMD
12906         if (ret == -ENOTSUP)
12907                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12908                                 res->vf_id, is_on);
12909 #endif
12910 #ifdef RTE_LIBRTE_BNXT_PMD
12911         if (ret == -ENOTSUP)
12912                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12913                                 res->vf_id, is_on);
12914 #endif
12915
12916         switch (ret) {
12917         case 0:
12918                 break;
12919         case -EINVAL:
12920                 printf("invalid vf_id %d\n", res->vf_id);
12921                 break;
12922         case -ENODEV:
12923                 printf("invalid port_id %d\n", res->port_id);
12924                 break;
12925         case -ENOTSUP:
12926                 printf("function not implemented\n");
12927                 break;
12928         default:
12929                 printf("programming error: (%s)\n", strerror(-ret));
12930         }
12931 }
12932
12933 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12934         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12935         .data = NULL,
12936         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12937         .tokens = {
12938                 (void *)&cmd_vf_vlan_anti_spoof_set,
12939                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12940                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12941                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12942                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12943                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12944                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12945                 NULL,
12946         },
12947 };
12948
12949 /* vf mac anti spoof configuration */
12950
12951 /* Common result structure for vf mac anti spoof */
12952 struct cmd_vf_mac_anti_spoof_result {
12953         cmdline_fixed_string_t set;
12954         cmdline_fixed_string_t vf;
12955         cmdline_fixed_string_t mac;
12956         cmdline_fixed_string_t antispoof;
12957         portid_t port_id;
12958         uint32_t vf_id;
12959         cmdline_fixed_string_t on_off;
12960 };
12961
12962 /* Common CLI fields for vf mac anti spoof enable disable */
12963 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_vf_mac_anti_spoof_result,
12966                  set, "set");
12967 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_vf_mac_anti_spoof_result,
12970                  vf, "vf");
12971 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_vf_mac_anti_spoof_result,
12974                  mac, "mac");
12975 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12976         TOKEN_STRING_INITIALIZER
12977                 (struct cmd_vf_mac_anti_spoof_result,
12978                  antispoof, "antispoof");
12979 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12980         TOKEN_NUM_INITIALIZER
12981                 (struct cmd_vf_mac_anti_spoof_result,
12982                  port_id, UINT16);
12983 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12984         TOKEN_NUM_INITIALIZER
12985                 (struct cmd_vf_mac_anti_spoof_result,
12986                  vf_id, UINT32);
12987 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12988         TOKEN_STRING_INITIALIZER
12989                 (struct cmd_vf_mac_anti_spoof_result,
12990                  on_off, "on#off");
12991
12992 static void
12993 cmd_set_vf_mac_anti_spoof_parsed(
12994         void *parsed_result,
12995         __attribute__((unused)) struct cmdline *cl,
12996         __attribute__((unused)) void *data)
12997 {
12998         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12999         int ret = -ENOTSUP;
13000
13001         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13002
13003         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13004                 return;
13005
13006 #ifdef RTE_LIBRTE_IXGBE_PMD
13007         if (ret == -ENOTSUP)
13008                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13009                         res->vf_id, is_on);
13010 #endif
13011 #ifdef RTE_LIBRTE_I40E_PMD
13012         if (ret == -ENOTSUP)
13013                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13014                         res->vf_id, is_on);
13015 #endif
13016 #ifdef RTE_LIBRTE_BNXT_PMD
13017         if (ret == -ENOTSUP)
13018                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13019                         res->vf_id, is_on);
13020 #endif
13021
13022         switch (ret) {
13023         case 0:
13024                 break;
13025         case -EINVAL:
13026                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13027                 break;
13028         case -ENODEV:
13029                 printf("invalid port_id %d\n", res->port_id);
13030                 break;
13031         case -ENOTSUP:
13032                 printf("function not implemented\n");
13033                 break;
13034         default:
13035                 printf("programming error: (%s)\n", strerror(-ret));
13036         }
13037 }
13038
13039 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13040         .f = cmd_set_vf_mac_anti_spoof_parsed,
13041         .data = NULL,
13042         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13043         .tokens = {
13044                 (void *)&cmd_vf_mac_anti_spoof_set,
13045                 (void *)&cmd_vf_mac_anti_spoof_vf,
13046                 (void *)&cmd_vf_mac_anti_spoof_mac,
13047                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13048                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13049                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13050                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13051                 NULL,
13052         },
13053 };
13054
13055 /* vf vlan strip queue configuration */
13056
13057 /* Common result structure for vf mac anti spoof */
13058 struct cmd_vf_vlan_stripq_result {
13059         cmdline_fixed_string_t set;
13060         cmdline_fixed_string_t vf;
13061         cmdline_fixed_string_t vlan;
13062         cmdline_fixed_string_t stripq;
13063         portid_t port_id;
13064         uint16_t vf_id;
13065         cmdline_fixed_string_t on_off;
13066 };
13067
13068 /* Common CLI fields for vf vlan strip enable disable */
13069 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_vf_vlan_stripq_result,
13072                  set, "set");
13073 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13074         TOKEN_STRING_INITIALIZER
13075                 (struct cmd_vf_vlan_stripq_result,
13076                  vf, "vf");
13077 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13078         TOKEN_STRING_INITIALIZER
13079                 (struct cmd_vf_vlan_stripq_result,
13080                  vlan, "vlan");
13081 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13082         TOKEN_STRING_INITIALIZER
13083                 (struct cmd_vf_vlan_stripq_result,
13084                  stripq, "stripq");
13085 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13086         TOKEN_NUM_INITIALIZER
13087                 (struct cmd_vf_vlan_stripq_result,
13088                  port_id, UINT16);
13089 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13090         TOKEN_NUM_INITIALIZER
13091                 (struct cmd_vf_vlan_stripq_result,
13092                  vf_id, UINT16);
13093 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13094         TOKEN_STRING_INITIALIZER
13095                 (struct cmd_vf_vlan_stripq_result,
13096                  on_off, "on#off");
13097
13098 static void
13099 cmd_set_vf_vlan_stripq_parsed(
13100         void *parsed_result,
13101         __attribute__((unused)) struct cmdline *cl,
13102         __attribute__((unused)) void *data)
13103 {
13104         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13105         int ret = -ENOTSUP;
13106
13107         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13108
13109         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13110                 return;
13111
13112 #ifdef RTE_LIBRTE_IXGBE_PMD
13113         if (ret == -ENOTSUP)
13114                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13115                         res->vf_id, is_on);
13116 #endif
13117 #ifdef RTE_LIBRTE_I40E_PMD
13118         if (ret == -ENOTSUP)
13119                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13120                         res->vf_id, is_on);
13121 #endif
13122 #ifdef RTE_LIBRTE_BNXT_PMD
13123         if (ret == -ENOTSUP)
13124                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13125                         res->vf_id, is_on);
13126 #endif
13127
13128         switch (ret) {
13129         case 0:
13130                 break;
13131         case -EINVAL:
13132                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13133                 break;
13134         case -ENODEV:
13135                 printf("invalid port_id %d\n", res->port_id);
13136                 break;
13137         case -ENOTSUP:
13138                 printf("function not implemented\n");
13139                 break;
13140         default:
13141                 printf("programming error: (%s)\n", strerror(-ret));
13142         }
13143 }
13144
13145 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13146         .f = cmd_set_vf_vlan_stripq_parsed,
13147         .data = NULL,
13148         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13149         .tokens = {
13150                 (void *)&cmd_vf_vlan_stripq_set,
13151                 (void *)&cmd_vf_vlan_stripq_vf,
13152                 (void *)&cmd_vf_vlan_stripq_vlan,
13153                 (void *)&cmd_vf_vlan_stripq_stripq,
13154                 (void *)&cmd_vf_vlan_stripq_port_id,
13155                 (void *)&cmd_vf_vlan_stripq_vf_id,
13156                 (void *)&cmd_vf_vlan_stripq_on_off,
13157                 NULL,
13158         },
13159 };
13160
13161 /* vf vlan insert configuration */
13162
13163 /* Common result structure for vf vlan insert */
13164 struct cmd_vf_vlan_insert_result {
13165         cmdline_fixed_string_t set;
13166         cmdline_fixed_string_t vf;
13167         cmdline_fixed_string_t vlan;
13168         cmdline_fixed_string_t insert;
13169         portid_t port_id;
13170         uint16_t vf_id;
13171         uint16_t vlan_id;
13172 };
13173
13174 /* Common CLI fields for vf vlan insert enable disable */
13175 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13176         TOKEN_STRING_INITIALIZER
13177                 (struct cmd_vf_vlan_insert_result,
13178                  set, "set");
13179 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13180         TOKEN_STRING_INITIALIZER
13181                 (struct cmd_vf_vlan_insert_result,
13182                  vf, "vf");
13183 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13184         TOKEN_STRING_INITIALIZER
13185                 (struct cmd_vf_vlan_insert_result,
13186                  vlan, "vlan");
13187 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13188         TOKEN_STRING_INITIALIZER
13189                 (struct cmd_vf_vlan_insert_result,
13190                  insert, "insert");
13191 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13192         TOKEN_NUM_INITIALIZER
13193                 (struct cmd_vf_vlan_insert_result,
13194                  port_id, UINT16);
13195 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13196         TOKEN_NUM_INITIALIZER
13197                 (struct cmd_vf_vlan_insert_result,
13198                  vf_id, UINT16);
13199 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13200         TOKEN_NUM_INITIALIZER
13201                 (struct cmd_vf_vlan_insert_result,
13202                  vlan_id, UINT16);
13203
13204 static void
13205 cmd_set_vf_vlan_insert_parsed(
13206         void *parsed_result,
13207         __attribute__((unused)) struct cmdline *cl,
13208         __attribute__((unused)) void *data)
13209 {
13210         struct cmd_vf_vlan_insert_result *res = parsed_result;
13211         int ret = -ENOTSUP;
13212
13213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13214                 return;
13215
13216 #ifdef RTE_LIBRTE_IXGBE_PMD
13217         if (ret == -ENOTSUP)
13218                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13219                         res->vlan_id);
13220 #endif
13221 #ifdef RTE_LIBRTE_I40E_PMD
13222         if (ret == -ENOTSUP)
13223                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13224                         res->vlan_id);
13225 #endif
13226 #ifdef RTE_LIBRTE_BNXT_PMD
13227         if (ret == -ENOTSUP)
13228                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13229                         res->vlan_id);
13230 #endif
13231
13232         switch (ret) {
13233         case 0:
13234                 break;
13235         case -EINVAL:
13236                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13237                 break;
13238         case -ENODEV:
13239                 printf("invalid port_id %d\n", res->port_id);
13240                 break;
13241         case -ENOTSUP:
13242                 printf("function not implemented\n");
13243                 break;
13244         default:
13245                 printf("programming error: (%s)\n", strerror(-ret));
13246         }
13247 }
13248
13249 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13250         .f = cmd_set_vf_vlan_insert_parsed,
13251         .data = NULL,
13252         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13253         .tokens = {
13254                 (void *)&cmd_vf_vlan_insert_set,
13255                 (void *)&cmd_vf_vlan_insert_vf,
13256                 (void *)&cmd_vf_vlan_insert_vlan,
13257                 (void *)&cmd_vf_vlan_insert_insert,
13258                 (void *)&cmd_vf_vlan_insert_port_id,
13259                 (void *)&cmd_vf_vlan_insert_vf_id,
13260                 (void *)&cmd_vf_vlan_insert_vlan_id,
13261                 NULL,
13262         },
13263 };
13264
13265 /* tx loopback configuration */
13266
13267 /* Common result structure for tx loopback */
13268 struct cmd_tx_loopback_result {
13269         cmdline_fixed_string_t set;
13270         cmdline_fixed_string_t tx;
13271         cmdline_fixed_string_t loopback;
13272         portid_t port_id;
13273         cmdline_fixed_string_t on_off;
13274 };
13275
13276 /* Common CLI fields for tx loopback enable disable */
13277 cmdline_parse_token_string_t cmd_tx_loopback_set =
13278         TOKEN_STRING_INITIALIZER
13279                 (struct cmd_tx_loopback_result,
13280                  set, "set");
13281 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13282         TOKEN_STRING_INITIALIZER
13283                 (struct cmd_tx_loopback_result,
13284                  tx, "tx");
13285 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13286         TOKEN_STRING_INITIALIZER
13287                 (struct cmd_tx_loopback_result,
13288                  loopback, "loopback");
13289 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13290         TOKEN_NUM_INITIALIZER
13291                 (struct cmd_tx_loopback_result,
13292                  port_id, UINT16);
13293 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13294         TOKEN_STRING_INITIALIZER
13295                 (struct cmd_tx_loopback_result,
13296                  on_off, "on#off");
13297
13298 static void
13299 cmd_set_tx_loopback_parsed(
13300         void *parsed_result,
13301         __attribute__((unused)) struct cmdline *cl,
13302         __attribute__((unused)) void *data)
13303 {
13304         struct cmd_tx_loopback_result *res = parsed_result;
13305         int ret = -ENOTSUP;
13306
13307         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13308
13309         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13310                 return;
13311
13312 #ifdef RTE_LIBRTE_IXGBE_PMD
13313         if (ret == -ENOTSUP)
13314                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13315 #endif
13316 #ifdef RTE_LIBRTE_I40E_PMD
13317         if (ret == -ENOTSUP)
13318                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13319 #endif
13320 #ifdef RTE_LIBRTE_BNXT_PMD
13321         if (ret == -ENOTSUP)
13322                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13323 #endif
13324 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13325         if (ret == -ENOTSUP)
13326                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13327 #endif
13328
13329         switch (ret) {
13330         case 0:
13331                 break;
13332         case -EINVAL:
13333                 printf("invalid is_on %d\n", is_on);
13334                 break;
13335         case -ENODEV:
13336                 printf("invalid port_id %d\n", res->port_id);
13337                 break;
13338         case -ENOTSUP:
13339                 printf("function not implemented\n");
13340                 break;
13341         default:
13342                 printf("programming error: (%s)\n", strerror(-ret));
13343         }
13344 }
13345
13346 cmdline_parse_inst_t cmd_set_tx_loopback = {
13347         .f = cmd_set_tx_loopback_parsed,
13348         .data = NULL,
13349         .help_str = "set tx loopback <port_id> on|off",
13350         .tokens = {
13351                 (void *)&cmd_tx_loopback_set,
13352                 (void *)&cmd_tx_loopback_tx,
13353                 (void *)&cmd_tx_loopback_loopback,
13354                 (void *)&cmd_tx_loopback_port_id,
13355                 (void *)&cmd_tx_loopback_on_off,
13356                 NULL,
13357         },
13358 };
13359
13360 /* all queues drop enable configuration */
13361
13362 /* Common result structure for all queues drop enable */
13363 struct cmd_all_queues_drop_en_result {
13364         cmdline_fixed_string_t set;
13365         cmdline_fixed_string_t all;
13366         cmdline_fixed_string_t queues;
13367         cmdline_fixed_string_t drop;
13368         portid_t port_id;
13369         cmdline_fixed_string_t on_off;
13370 };
13371
13372 /* Common CLI fields for tx loopback enable disable */
13373 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13374         TOKEN_STRING_INITIALIZER
13375                 (struct cmd_all_queues_drop_en_result,
13376                  set, "set");
13377 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13378         TOKEN_STRING_INITIALIZER
13379                 (struct cmd_all_queues_drop_en_result,
13380                  all, "all");
13381 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_all_queues_drop_en_result,
13384                  queues, "queues");
13385 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13386         TOKEN_STRING_INITIALIZER
13387                 (struct cmd_all_queues_drop_en_result,
13388                  drop, "drop");
13389 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13390         TOKEN_NUM_INITIALIZER
13391                 (struct cmd_all_queues_drop_en_result,
13392                  port_id, UINT16);
13393 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13394         TOKEN_STRING_INITIALIZER
13395                 (struct cmd_all_queues_drop_en_result,
13396                  on_off, "on#off");
13397
13398 static void
13399 cmd_set_all_queues_drop_en_parsed(
13400         void *parsed_result,
13401         __attribute__((unused)) struct cmdline *cl,
13402         __attribute__((unused)) void *data)
13403 {
13404         struct cmd_all_queues_drop_en_result *res = parsed_result;
13405         int ret = -ENOTSUP;
13406         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13407
13408         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13409                 return;
13410
13411 #ifdef RTE_LIBRTE_IXGBE_PMD
13412         if (ret == -ENOTSUP)
13413                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13414 #endif
13415 #ifdef RTE_LIBRTE_BNXT_PMD
13416         if (ret == -ENOTSUP)
13417                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13418 #endif
13419         switch (ret) {
13420         case 0:
13421                 break;
13422         case -EINVAL:
13423                 printf("invalid is_on %d\n", is_on);
13424                 break;
13425         case -ENODEV:
13426                 printf("invalid port_id %d\n", res->port_id);
13427                 break;
13428         case -ENOTSUP:
13429                 printf("function not implemented\n");
13430                 break;
13431         default:
13432                 printf("programming error: (%s)\n", strerror(-ret));
13433         }
13434 }
13435
13436 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13437         .f = cmd_set_all_queues_drop_en_parsed,
13438         .data = NULL,
13439         .help_str = "set all queues drop <port_id> on|off",
13440         .tokens = {
13441                 (void *)&cmd_all_queues_drop_en_set,
13442                 (void *)&cmd_all_queues_drop_en_all,
13443                 (void *)&cmd_all_queues_drop_en_queues,
13444                 (void *)&cmd_all_queues_drop_en_drop,
13445                 (void *)&cmd_all_queues_drop_en_port_id,
13446                 (void *)&cmd_all_queues_drop_en_on_off,
13447                 NULL,
13448         },
13449 };
13450
13451 /* vf split drop enable configuration */
13452
13453 /* Common result structure for vf split drop enable */
13454 struct cmd_vf_split_drop_en_result {
13455         cmdline_fixed_string_t set;
13456         cmdline_fixed_string_t vf;
13457         cmdline_fixed_string_t split;
13458         cmdline_fixed_string_t drop;
13459         portid_t port_id;
13460         uint16_t vf_id;
13461         cmdline_fixed_string_t on_off;
13462 };
13463
13464 /* Common CLI fields for vf split drop enable disable */
13465 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13466         TOKEN_STRING_INITIALIZER
13467                 (struct cmd_vf_split_drop_en_result,
13468                  set, "set");
13469 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13470         TOKEN_STRING_INITIALIZER
13471                 (struct cmd_vf_split_drop_en_result,
13472                  vf, "vf");
13473 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13474         TOKEN_STRING_INITIALIZER
13475                 (struct cmd_vf_split_drop_en_result,
13476                  split, "split");
13477 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13478         TOKEN_STRING_INITIALIZER
13479                 (struct cmd_vf_split_drop_en_result,
13480                  drop, "drop");
13481 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13482         TOKEN_NUM_INITIALIZER
13483                 (struct cmd_vf_split_drop_en_result,
13484                  port_id, UINT16);
13485 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13486         TOKEN_NUM_INITIALIZER
13487                 (struct cmd_vf_split_drop_en_result,
13488                  vf_id, UINT16);
13489 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13490         TOKEN_STRING_INITIALIZER
13491                 (struct cmd_vf_split_drop_en_result,
13492                  on_off, "on#off");
13493
13494 static void
13495 cmd_set_vf_split_drop_en_parsed(
13496         void *parsed_result,
13497         __attribute__((unused)) struct cmdline *cl,
13498         __attribute__((unused)) void *data)
13499 {
13500         struct cmd_vf_split_drop_en_result *res = parsed_result;
13501         int ret = -ENOTSUP;
13502         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13503
13504         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13505                 return;
13506
13507 #ifdef RTE_LIBRTE_IXGBE_PMD
13508         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13509                         is_on);
13510 #endif
13511         switch (ret) {
13512         case 0:
13513                 break;
13514         case -EINVAL:
13515                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13516                 break;
13517         case -ENODEV:
13518                 printf("invalid port_id %d\n", res->port_id);
13519                 break;
13520         case -ENOTSUP:
13521                 printf("not supported on port %d\n", res->port_id);
13522                 break;
13523         default:
13524                 printf("programming error: (%s)\n", strerror(-ret));
13525         }
13526 }
13527
13528 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13529         .f = cmd_set_vf_split_drop_en_parsed,
13530         .data = NULL,
13531         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13532         .tokens = {
13533                 (void *)&cmd_vf_split_drop_en_set,
13534                 (void *)&cmd_vf_split_drop_en_vf,
13535                 (void *)&cmd_vf_split_drop_en_split,
13536                 (void *)&cmd_vf_split_drop_en_drop,
13537                 (void *)&cmd_vf_split_drop_en_port_id,
13538                 (void *)&cmd_vf_split_drop_en_vf_id,
13539                 (void *)&cmd_vf_split_drop_en_on_off,
13540                 NULL,
13541         },
13542 };
13543
13544 /* vf mac address configuration */
13545
13546 /* Common result structure for vf mac address */
13547 struct cmd_set_vf_mac_addr_result {
13548         cmdline_fixed_string_t set;
13549         cmdline_fixed_string_t vf;
13550         cmdline_fixed_string_t mac;
13551         cmdline_fixed_string_t addr;
13552         portid_t port_id;
13553         uint16_t vf_id;
13554         struct ether_addr mac_addr;
13555
13556 };
13557
13558 /* Common CLI fields for vf split drop enable disable */
13559 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13560         TOKEN_STRING_INITIALIZER
13561                 (struct cmd_set_vf_mac_addr_result,
13562                  set, "set");
13563 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13564         TOKEN_STRING_INITIALIZER
13565                 (struct cmd_set_vf_mac_addr_result,
13566                  vf, "vf");
13567 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13568         TOKEN_STRING_INITIALIZER
13569                 (struct cmd_set_vf_mac_addr_result,
13570                  mac, "mac");
13571 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13572         TOKEN_STRING_INITIALIZER
13573                 (struct cmd_set_vf_mac_addr_result,
13574                  addr, "addr");
13575 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13576         TOKEN_NUM_INITIALIZER
13577                 (struct cmd_set_vf_mac_addr_result,
13578                  port_id, UINT16);
13579 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13580         TOKEN_NUM_INITIALIZER
13581                 (struct cmd_set_vf_mac_addr_result,
13582                  vf_id, UINT16);
13583 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13584         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13585                  mac_addr);
13586
13587 static void
13588 cmd_set_vf_mac_addr_parsed(
13589         void *parsed_result,
13590         __attribute__((unused)) struct cmdline *cl,
13591         __attribute__((unused)) void *data)
13592 {
13593         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13594         int ret = -ENOTSUP;
13595
13596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13597                 return;
13598
13599 #ifdef RTE_LIBRTE_IXGBE_PMD
13600         if (ret == -ENOTSUP)
13601                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13602                                 &res->mac_addr);
13603 #endif
13604 #ifdef RTE_LIBRTE_I40E_PMD
13605         if (ret == -ENOTSUP)
13606                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13607                                 &res->mac_addr);
13608 #endif
13609 #ifdef RTE_LIBRTE_BNXT_PMD
13610         if (ret == -ENOTSUP)
13611                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13612                                 &res->mac_addr);
13613 #endif
13614
13615         switch (ret) {
13616         case 0:
13617                 break;
13618         case -EINVAL:
13619                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13620                 break;
13621         case -ENODEV:
13622                 printf("invalid port_id %d\n", res->port_id);
13623                 break;
13624         case -ENOTSUP:
13625                 printf("function not implemented\n");
13626                 break;
13627         default:
13628                 printf("programming error: (%s)\n", strerror(-ret));
13629         }
13630 }
13631
13632 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13633         .f = cmd_set_vf_mac_addr_parsed,
13634         .data = NULL,
13635         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13636         .tokens = {
13637                 (void *)&cmd_set_vf_mac_addr_set,
13638                 (void *)&cmd_set_vf_mac_addr_vf,
13639                 (void *)&cmd_set_vf_mac_addr_mac,
13640                 (void *)&cmd_set_vf_mac_addr_addr,
13641                 (void *)&cmd_set_vf_mac_addr_port_id,
13642                 (void *)&cmd_set_vf_mac_addr_vf_id,
13643                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13644                 NULL,
13645         },
13646 };
13647
13648 /* MACsec configuration */
13649
13650 /* Common result structure for MACsec offload enable */
13651 struct cmd_macsec_offload_on_result {
13652         cmdline_fixed_string_t set;
13653         cmdline_fixed_string_t macsec;
13654         cmdline_fixed_string_t offload;
13655         portid_t port_id;
13656         cmdline_fixed_string_t on;
13657         cmdline_fixed_string_t encrypt;
13658         cmdline_fixed_string_t en_on_off;
13659         cmdline_fixed_string_t replay_protect;
13660         cmdline_fixed_string_t rp_on_off;
13661 };
13662
13663 /* Common CLI fields for MACsec offload disable */
13664 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13665         TOKEN_STRING_INITIALIZER
13666                 (struct cmd_macsec_offload_on_result,
13667                  set, "set");
13668 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_macsec_offload_on_result,
13671                  macsec, "macsec");
13672 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_macsec_offload_on_result,
13675                  offload, "offload");
13676 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13677         TOKEN_NUM_INITIALIZER
13678                 (struct cmd_macsec_offload_on_result,
13679                  port_id, UINT16);
13680 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13681         TOKEN_STRING_INITIALIZER
13682                 (struct cmd_macsec_offload_on_result,
13683                  on, "on");
13684 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_macsec_offload_on_result,
13687                  encrypt, "encrypt");
13688 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13689         TOKEN_STRING_INITIALIZER
13690                 (struct cmd_macsec_offload_on_result,
13691                  en_on_off, "on#off");
13692 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13693         TOKEN_STRING_INITIALIZER
13694                 (struct cmd_macsec_offload_on_result,
13695                  replay_protect, "replay-protect");
13696 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13697         TOKEN_STRING_INITIALIZER
13698                 (struct cmd_macsec_offload_on_result,
13699                  rp_on_off, "on#off");
13700
13701 static void
13702 cmd_set_macsec_offload_on_parsed(
13703         void *parsed_result,
13704         __attribute__((unused)) struct cmdline *cl,
13705         __attribute__((unused)) void *data)
13706 {
13707         struct cmd_macsec_offload_on_result *res = parsed_result;
13708         int ret = -ENOTSUP;
13709         portid_t port_id = res->port_id;
13710         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13711         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13712         struct rte_eth_dev_info dev_info;
13713
13714         if (port_id_is_invalid(port_id, ENABLED_WARN))
13715                 return;
13716         if (!port_is_stopped(port_id)) {
13717                 printf("Please stop port %d first\n", port_id);
13718                 return;
13719         }
13720
13721         rte_eth_dev_info_get(port_id, &dev_info);
13722         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13723 #ifdef RTE_LIBRTE_IXGBE_PMD
13724                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13725 #endif
13726         }
13727         RTE_SET_USED(en);
13728         RTE_SET_USED(rp);
13729
13730         switch (ret) {
13731         case 0:
13732                 ports[port_id].dev_conf.txmode.offloads |=
13733                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13734                 cmd_reconfig_device_queue(port_id, 1, 1);
13735                 break;
13736         case -ENODEV:
13737                 printf("invalid port_id %d\n", port_id);
13738                 break;
13739         case -ENOTSUP:
13740                 printf("not supported on port %d\n", port_id);
13741                 break;
13742         default:
13743                 printf("programming error: (%s)\n", strerror(-ret));
13744         }
13745 }
13746
13747 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13748         .f = cmd_set_macsec_offload_on_parsed,
13749         .data = NULL,
13750         .help_str = "set macsec offload <port_id> on "
13751                 "encrypt on|off replay-protect on|off",
13752         .tokens = {
13753                 (void *)&cmd_macsec_offload_on_set,
13754                 (void *)&cmd_macsec_offload_on_macsec,
13755                 (void *)&cmd_macsec_offload_on_offload,
13756                 (void *)&cmd_macsec_offload_on_port_id,
13757                 (void *)&cmd_macsec_offload_on_on,
13758                 (void *)&cmd_macsec_offload_on_encrypt,
13759                 (void *)&cmd_macsec_offload_on_en_on_off,
13760                 (void *)&cmd_macsec_offload_on_replay_protect,
13761                 (void *)&cmd_macsec_offload_on_rp_on_off,
13762                 NULL,
13763         },
13764 };
13765
13766 /* Common result structure for MACsec offload disable */
13767 struct cmd_macsec_offload_off_result {
13768         cmdline_fixed_string_t set;
13769         cmdline_fixed_string_t macsec;
13770         cmdline_fixed_string_t offload;
13771         portid_t port_id;
13772         cmdline_fixed_string_t off;
13773 };
13774
13775 /* Common CLI fields for MACsec offload disable */
13776 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13777         TOKEN_STRING_INITIALIZER
13778                 (struct cmd_macsec_offload_off_result,
13779                  set, "set");
13780 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13781         TOKEN_STRING_INITIALIZER
13782                 (struct cmd_macsec_offload_off_result,
13783                  macsec, "macsec");
13784 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13785         TOKEN_STRING_INITIALIZER
13786                 (struct cmd_macsec_offload_off_result,
13787                  offload, "offload");
13788 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13789         TOKEN_NUM_INITIALIZER
13790                 (struct cmd_macsec_offload_off_result,
13791                  port_id, UINT16);
13792 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13793         TOKEN_STRING_INITIALIZER
13794                 (struct cmd_macsec_offload_off_result,
13795                  off, "off");
13796
13797 static void
13798 cmd_set_macsec_offload_off_parsed(
13799         void *parsed_result,
13800         __attribute__((unused)) struct cmdline *cl,
13801         __attribute__((unused)) void *data)
13802 {
13803         struct cmd_macsec_offload_off_result *res = parsed_result;
13804         int ret = -ENOTSUP;
13805         struct rte_eth_dev_info dev_info;
13806         portid_t port_id = res->port_id;
13807
13808         if (port_id_is_invalid(port_id, ENABLED_WARN))
13809                 return;
13810         if (!port_is_stopped(port_id)) {
13811                 printf("Please stop port %d first\n", port_id);
13812                 return;
13813         }
13814
13815         rte_eth_dev_info_get(port_id, &dev_info);
13816         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13817 #ifdef RTE_LIBRTE_IXGBE_PMD
13818                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13819 #endif
13820         }
13821         switch (ret) {
13822         case 0:
13823                 ports[port_id].dev_conf.txmode.offloads &=
13824                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13825                 cmd_reconfig_device_queue(port_id, 1, 1);
13826                 break;
13827         case -ENODEV:
13828                 printf("invalid port_id %d\n", port_id);
13829                 break;
13830         case -ENOTSUP:
13831                 printf("not supported on port %d\n", port_id);
13832                 break;
13833         default:
13834                 printf("programming error: (%s)\n", strerror(-ret));
13835         }
13836 }
13837
13838 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13839         .f = cmd_set_macsec_offload_off_parsed,
13840         .data = NULL,
13841         .help_str = "set macsec offload <port_id> off",
13842         .tokens = {
13843                 (void *)&cmd_macsec_offload_off_set,
13844                 (void *)&cmd_macsec_offload_off_macsec,
13845                 (void *)&cmd_macsec_offload_off_offload,
13846                 (void *)&cmd_macsec_offload_off_port_id,
13847                 (void *)&cmd_macsec_offload_off_off,
13848                 NULL,
13849         },
13850 };
13851
13852 /* Common result structure for MACsec secure connection configure */
13853 struct cmd_macsec_sc_result {
13854         cmdline_fixed_string_t set;
13855         cmdline_fixed_string_t macsec;
13856         cmdline_fixed_string_t sc;
13857         cmdline_fixed_string_t tx_rx;
13858         portid_t port_id;
13859         struct ether_addr mac;
13860         uint16_t pi;
13861 };
13862
13863 /* Common CLI fields for MACsec secure connection configure */
13864 cmdline_parse_token_string_t cmd_macsec_sc_set =
13865         TOKEN_STRING_INITIALIZER
13866                 (struct cmd_macsec_sc_result,
13867                  set, "set");
13868 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_macsec_sc_result,
13871                  macsec, "macsec");
13872 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13873         TOKEN_STRING_INITIALIZER
13874                 (struct cmd_macsec_sc_result,
13875                  sc, "sc");
13876 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13877         TOKEN_STRING_INITIALIZER
13878                 (struct cmd_macsec_sc_result,
13879                  tx_rx, "tx#rx");
13880 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13881         TOKEN_NUM_INITIALIZER
13882                 (struct cmd_macsec_sc_result,
13883                  port_id, UINT16);
13884 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13885         TOKEN_ETHERADDR_INITIALIZER
13886                 (struct cmd_macsec_sc_result,
13887                  mac);
13888 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13889         TOKEN_NUM_INITIALIZER
13890                 (struct cmd_macsec_sc_result,
13891                  pi, UINT16);
13892
13893 static void
13894 cmd_set_macsec_sc_parsed(
13895         void *parsed_result,
13896         __attribute__((unused)) struct cmdline *cl,
13897         __attribute__((unused)) void *data)
13898 {
13899         struct cmd_macsec_sc_result *res = parsed_result;
13900         int ret = -ENOTSUP;
13901         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13902
13903 #ifdef RTE_LIBRTE_IXGBE_PMD
13904         ret = is_tx ?
13905                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13906                                 res->mac.addr_bytes) :
13907                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13908                                 res->mac.addr_bytes, res->pi);
13909 #endif
13910         RTE_SET_USED(is_tx);
13911
13912         switch (ret) {
13913         case 0:
13914                 break;
13915         case -ENODEV:
13916                 printf("invalid port_id %d\n", res->port_id);
13917                 break;
13918         case -ENOTSUP:
13919                 printf("not supported on port %d\n", res->port_id);
13920                 break;
13921         default:
13922                 printf("programming error: (%s)\n", strerror(-ret));
13923         }
13924 }
13925
13926 cmdline_parse_inst_t cmd_set_macsec_sc = {
13927         .f = cmd_set_macsec_sc_parsed,
13928         .data = NULL,
13929         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13930         .tokens = {
13931                 (void *)&cmd_macsec_sc_set,
13932                 (void *)&cmd_macsec_sc_macsec,
13933                 (void *)&cmd_macsec_sc_sc,
13934                 (void *)&cmd_macsec_sc_tx_rx,
13935                 (void *)&cmd_macsec_sc_port_id,
13936                 (void *)&cmd_macsec_sc_mac,
13937                 (void *)&cmd_macsec_sc_pi,
13938                 NULL,
13939         },
13940 };
13941
13942 /* Common result structure for MACsec secure connection configure */
13943 struct cmd_macsec_sa_result {
13944         cmdline_fixed_string_t set;
13945         cmdline_fixed_string_t macsec;
13946         cmdline_fixed_string_t sa;
13947         cmdline_fixed_string_t tx_rx;
13948         portid_t port_id;
13949         uint8_t idx;
13950         uint8_t an;
13951         uint32_t pn;
13952         cmdline_fixed_string_t key;
13953 };
13954
13955 /* Common CLI fields for MACsec secure connection configure */
13956 cmdline_parse_token_string_t cmd_macsec_sa_set =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_macsec_sa_result,
13959                  set, "set");
13960 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_macsec_sa_result,
13963                  macsec, "macsec");
13964 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_macsec_sa_result,
13967                  sa, "sa");
13968 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_macsec_sa_result,
13971                  tx_rx, "tx#rx");
13972 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13973         TOKEN_NUM_INITIALIZER
13974                 (struct cmd_macsec_sa_result,
13975                  port_id, UINT16);
13976 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13977         TOKEN_NUM_INITIALIZER
13978                 (struct cmd_macsec_sa_result,
13979                  idx, UINT8);
13980 cmdline_parse_token_num_t cmd_macsec_sa_an =
13981         TOKEN_NUM_INITIALIZER
13982                 (struct cmd_macsec_sa_result,
13983                  an, UINT8);
13984 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13985         TOKEN_NUM_INITIALIZER
13986                 (struct cmd_macsec_sa_result,
13987                  pn, UINT32);
13988 cmdline_parse_token_string_t cmd_macsec_sa_key =
13989         TOKEN_STRING_INITIALIZER
13990                 (struct cmd_macsec_sa_result,
13991                  key, NULL);
13992
13993 static void
13994 cmd_set_macsec_sa_parsed(
13995         void *parsed_result,
13996         __attribute__((unused)) struct cmdline *cl,
13997         __attribute__((unused)) void *data)
13998 {
13999         struct cmd_macsec_sa_result *res = parsed_result;
14000         int ret = -ENOTSUP;
14001         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14002         uint8_t key[16] = { 0 };
14003         uint8_t xdgt0;
14004         uint8_t xdgt1;
14005         int key_len;
14006         int i;
14007
14008         key_len = strlen(res->key) / 2;
14009         if (key_len > 16)
14010                 key_len = 16;
14011
14012         for (i = 0; i < key_len; i++) {
14013                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14014                 if (xdgt0 == 0xFF)
14015                         return;
14016                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14017                 if (xdgt1 == 0xFF)
14018                         return;
14019                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14020         }
14021
14022 #ifdef RTE_LIBRTE_IXGBE_PMD
14023         ret = is_tx ?
14024                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14025                         res->idx, res->an, res->pn, key) :
14026                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14027                         res->idx, res->an, res->pn, key);
14028 #endif
14029         RTE_SET_USED(is_tx);
14030         RTE_SET_USED(key);
14031
14032         switch (ret) {
14033         case 0:
14034                 break;
14035         case -EINVAL:
14036                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14037                 break;
14038         case -ENODEV:
14039                 printf("invalid port_id %d\n", res->port_id);
14040                 break;
14041         case -ENOTSUP:
14042                 printf("not supported on port %d\n", res->port_id);
14043                 break;
14044         default:
14045                 printf("programming error: (%s)\n", strerror(-ret));
14046         }
14047 }
14048
14049 cmdline_parse_inst_t cmd_set_macsec_sa = {
14050         .f = cmd_set_macsec_sa_parsed,
14051         .data = NULL,
14052         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14053         .tokens = {
14054                 (void *)&cmd_macsec_sa_set,
14055                 (void *)&cmd_macsec_sa_macsec,
14056                 (void *)&cmd_macsec_sa_sa,
14057                 (void *)&cmd_macsec_sa_tx_rx,
14058                 (void *)&cmd_macsec_sa_port_id,
14059                 (void *)&cmd_macsec_sa_idx,
14060                 (void *)&cmd_macsec_sa_an,
14061                 (void *)&cmd_macsec_sa_pn,
14062                 (void *)&cmd_macsec_sa_key,
14063                 NULL,
14064         },
14065 };
14066
14067 /* VF unicast promiscuous mode configuration */
14068
14069 /* Common result structure for VF unicast promiscuous mode */
14070 struct cmd_vf_promisc_result {
14071         cmdline_fixed_string_t set;
14072         cmdline_fixed_string_t vf;
14073         cmdline_fixed_string_t promisc;
14074         portid_t port_id;
14075         uint32_t vf_id;
14076         cmdline_fixed_string_t on_off;
14077 };
14078
14079 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14080 cmdline_parse_token_string_t cmd_vf_promisc_set =
14081         TOKEN_STRING_INITIALIZER
14082                 (struct cmd_vf_promisc_result,
14083                  set, "set");
14084 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14085         TOKEN_STRING_INITIALIZER
14086                 (struct cmd_vf_promisc_result,
14087                  vf, "vf");
14088 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14089         TOKEN_STRING_INITIALIZER
14090                 (struct cmd_vf_promisc_result,
14091                  promisc, "promisc");
14092 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14093         TOKEN_NUM_INITIALIZER
14094                 (struct cmd_vf_promisc_result,
14095                  port_id, UINT16);
14096 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14097         TOKEN_NUM_INITIALIZER
14098                 (struct cmd_vf_promisc_result,
14099                  vf_id, UINT32);
14100 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14101         TOKEN_STRING_INITIALIZER
14102                 (struct cmd_vf_promisc_result,
14103                  on_off, "on#off");
14104
14105 static void
14106 cmd_set_vf_promisc_parsed(
14107         void *parsed_result,
14108         __attribute__((unused)) struct cmdline *cl,
14109         __attribute__((unused)) void *data)
14110 {
14111         struct cmd_vf_promisc_result *res = parsed_result;
14112         int ret = -ENOTSUP;
14113
14114         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14115
14116         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14117                 return;
14118
14119 #ifdef RTE_LIBRTE_I40E_PMD
14120         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14121                                                   res->vf_id, is_on);
14122 #endif
14123
14124         switch (ret) {
14125         case 0:
14126                 break;
14127         case -EINVAL:
14128                 printf("invalid vf_id %d\n", res->vf_id);
14129                 break;
14130         case -ENODEV:
14131                 printf("invalid port_id %d\n", res->port_id);
14132                 break;
14133         case -ENOTSUP:
14134                 printf("function not implemented\n");
14135                 break;
14136         default:
14137                 printf("programming error: (%s)\n", strerror(-ret));
14138         }
14139 }
14140
14141 cmdline_parse_inst_t cmd_set_vf_promisc = {
14142         .f = cmd_set_vf_promisc_parsed,
14143         .data = NULL,
14144         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14145                 "Set unicast promiscuous mode for a VF from the PF",
14146         .tokens = {
14147                 (void *)&cmd_vf_promisc_set,
14148                 (void *)&cmd_vf_promisc_vf,
14149                 (void *)&cmd_vf_promisc_promisc,
14150                 (void *)&cmd_vf_promisc_port_id,
14151                 (void *)&cmd_vf_promisc_vf_id,
14152                 (void *)&cmd_vf_promisc_on_off,
14153                 NULL,
14154         },
14155 };
14156
14157 /* VF multicast promiscuous mode configuration */
14158
14159 /* Common result structure for VF multicast promiscuous mode */
14160 struct cmd_vf_allmulti_result {
14161         cmdline_fixed_string_t set;
14162         cmdline_fixed_string_t vf;
14163         cmdline_fixed_string_t allmulti;
14164         portid_t port_id;
14165         uint32_t vf_id;
14166         cmdline_fixed_string_t on_off;
14167 };
14168
14169 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14170 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14171         TOKEN_STRING_INITIALIZER
14172                 (struct cmd_vf_allmulti_result,
14173                  set, "set");
14174 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14175         TOKEN_STRING_INITIALIZER
14176                 (struct cmd_vf_allmulti_result,
14177                  vf, "vf");
14178 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14179         TOKEN_STRING_INITIALIZER
14180                 (struct cmd_vf_allmulti_result,
14181                  allmulti, "allmulti");
14182 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14183         TOKEN_NUM_INITIALIZER
14184                 (struct cmd_vf_allmulti_result,
14185                  port_id, UINT16);
14186 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14187         TOKEN_NUM_INITIALIZER
14188                 (struct cmd_vf_allmulti_result,
14189                  vf_id, UINT32);
14190 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14191         TOKEN_STRING_INITIALIZER
14192                 (struct cmd_vf_allmulti_result,
14193                  on_off, "on#off");
14194
14195 static void
14196 cmd_set_vf_allmulti_parsed(
14197         void *parsed_result,
14198         __attribute__((unused)) struct cmdline *cl,
14199         __attribute__((unused)) void *data)
14200 {
14201         struct cmd_vf_allmulti_result *res = parsed_result;
14202         int ret = -ENOTSUP;
14203
14204         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14205
14206         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14207                 return;
14208
14209 #ifdef RTE_LIBRTE_I40E_PMD
14210         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14211                                                     res->vf_id, is_on);
14212 #endif
14213
14214         switch (ret) {
14215         case 0:
14216                 break;
14217         case -EINVAL:
14218                 printf("invalid vf_id %d\n", res->vf_id);
14219                 break;
14220         case -ENODEV:
14221                 printf("invalid port_id %d\n", res->port_id);
14222                 break;
14223         case -ENOTSUP:
14224                 printf("function not implemented\n");
14225                 break;
14226         default:
14227                 printf("programming error: (%s)\n", strerror(-ret));
14228         }
14229 }
14230
14231 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14232         .f = cmd_set_vf_allmulti_parsed,
14233         .data = NULL,
14234         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14235                 "Set multicast promiscuous mode for a VF from the PF",
14236         .tokens = {
14237                 (void *)&cmd_vf_allmulti_set,
14238                 (void *)&cmd_vf_allmulti_vf,
14239                 (void *)&cmd_vf_allmulti_allmulti,
14240                 (void *)&cmd_vf_allmulti_port_id,
14241                 (void *)&cmd_vf_allmulti_vf_id,
14242                 (void *)&cmd_vf_allmulti_on_off,
14243                 NULL,
14244         },
14245 };
14246
14247 /* vf broadcast mode configuration */
14248
14249 /* Common result structure for vf broadcast */
14250 struct cmd_set_vf_broadcast_result {
14251         cmdline_fixed_string_t set;
14252         cmdline_fixed_string_t vf;
14253         cmdline_fixed_string_t broadcast;
14254         portid_t port_id;
14255         uint16_t vf_id;
14256         cmdline_fixed_string_t on_off;
14257 };
14258
14259 /* Common CLI fields for vf broadcast enable disable */
14260 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14261         TOKEN_STRING_INITIALIZER
14262                 (struct cmd_set_vf_broadcast_result,
14263                  set, "set");
14264 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14265         TOKEN_STRING_INITIALIZER
14266                 (struct cmd_set_vf_broadcast_result,
14267                  vf, "vf");
14268 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14269         TOKEN_STRING_INITIALIZER
14270                 (struct cmd_set_vf_broadcast_result,
14271                  broadcast, "broadcast");
14272 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14273         TOKEN_NUM_INITIALIZER
14274                 (struct cmd_set_vf_broadcast_result,
14275                  port_id, UINT16);
14276 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14277         TOKEN_NUM_INITIALIZER
14278                 (struct cmd_set_vf_broadcast_result,
14279                  vf_id, UINT16);
14280 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14281         TOKEN_STRING_INITIALIZER
14282                 (struct cmd_set_vf_broadcast_result,
14283                  on_off, "on#off");
14284
14285 static void
14286 cmd_set_vf_broadcast_parsed(
14287         void *parsed_result,
14288         __attribute__((unused)) struct cmdline *cl,
14289         __attribute__((unused)) void *data)
14290 {
14291         struct cmd_set_vf_broadcast_result *res = parsed_result;
14292         int ret = -ENOTSUP;
14293
14294         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14295
14296         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14297                 return;
14298
14299 #ifdef RTE_LIBRTE_I40E_PMD
14300         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14301                                             res->vf_id, is_on);
14302 #endif
14303
14304         switch (ret) {
14305         case 0:
14306                 break;
14307         case -EINVAL:
14308                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14309                 break;
14310         case -ENODEV:
14311                 printf("invalid port_id %d\n", res->port_id);
14312                 break;
14313         case -ENOTSUP:
14314                 printf("function not implemented\n");
14315                 break;
14316         default:
14317                 printf("programming error: (%s)\n", strerror(-ret));
14318         }
14319 }
14320
14321 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14322         .f = cmd_set_vf_broadcast_parsed,
14323         .data = NULL,
14324         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14325         .tokens = {
14326                 (void *)&cmd_set_vf_broadcast_set,
14327                 (void *)&cmd_set_vf_broadcast_vf,
14328                 (void *)&cmd_set_vf_broadcast_broadcast,
14329                 (void *)&cmd_set_vf_broadcast_port_id,
14330                 (void *)&cmd_set_vf_broadcast_vf_id,
14331                 (void *)&cmd_set_vf_broadcast_on_off,
14332                 NULL,
14333         },
14334 };
14335
14336 /* vf vlan tag configuration */
14337
14338 /* Common result structure for vf vlan tag */
14339 struct cmd_set_vf_vlan_tag_result {
14340         cmdline_fixed_string_t set;
14341         cmdline_fixed_string_t vf;
14342         cmdline_fixed_string_t vlan;
14343         cmdline_fixed_string_t tag;
14344         portid_t port_id;
14345         uint16_t vf_id;
14346         cmdline_fixed_string_t on_off;
14347 };
14348
14349 /* Common CLI fields for vf vlan tag enable disable */
14350 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14351         TOKEN_STRING_INITIALIZER
14352                 (struct cmd_set_vf_vlan_tag_result,
14353                  set, "set");
14354 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14355         TOKEN_STRING_INITIALIZER
14356                 (struct cmd_set_vf_vlan_tag_result,
14357                  vf, "vf");
14358 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14359         TOKEN_STRING_INITIALIZER
14360                 (struct cmd_set_vf_vlan_tag_result,
14361                  vlan, "vlan");
14362 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14363         TOKEN_STRING_INITIALIZER
14364                 (struct cmd_set_vf_vlan_tag_result,
14365                  tag, "tag");
14366 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14367         TOKEN_NUM_INITIALIZER
14368                 (struct cmd_set_vf_vlan_tag_result,
14369                  port_id, UINT16);
14370 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14371         TOKEN_NUM_INITIALIZER
14372                 (struct cmd_set_vf_vlan_tag_result,
14373                  vf_id, UINT16);
14374 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14375         TOKEN_STRING_INITIALIZER
14376                 (struct cmd_set_vf_vlan_tag_result,
14377                  on_off, "on#off");
14378
14379 static void
14380 cmd_set_vf_vlan_tag_parsed(
14381         void *parsed_result,
14382         __attribute__((unused)) struct cmdline *cl,
14383         __attribute__((unused)) void *data)
14384 {
14385         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14386         int ret = -ENOTSUP;
14387
14388         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14389
14390         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14391                 return;
14392
14393 #ifdef RTE_LIBRTE_I40E_PMD
14394         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14395                                            res->vf_id, is_on);
14396 #endif
14397
14398         switch (ret) {
14399         case 0:
14400                 break;
14401         case -EINVAL:
14402                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14403                 break;
14404         case -ENODEV:
14405                 printf("invalid port_id %d\n", res->port_id);
14406                 break;
14407         case -ENOTSUP:
14408                 printf("function not implemented\n");
14409                 break;
14410         default:
14411                 printf("programming error: (%s)\n", strerror(-ret));
14412         }
14413 }
14414
14415 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14416         .f = cmd_set_vf_vlan_tag_parsed,
14417         .data = NULL,
14418         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14419         .tokens = {
14420                 (void *)&cmd_set_vf_vlan_tag_set,
14421                 (void *)&cmd_set_vf_vlan_tag_vf,
14422                 (void *)&cmd_set_vf_vlan_tag_vlan,
14423                 (void *)&cmd_set_vf_vlan_tag_tag,
14424                 (void *)&cmd_set_vf_vlan_tag_port_id,
14425                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14426                 (void *)&cmd_set_vf_vlan_tag_on_off,
14427                 NULL,
14428         },
14429 };
14430
14431 /* Common definition of VF and TC TX bandwidth configuration */
14432 struct cmd_vf_tc_bw_result {
14433         cmdline_fixed_string_t set;
14434         cmdline_fixed_string_t vf;
14435         cmdline_fixed_string_t tc;
14436         cmdline_fixed_string_t tx;
14437         cmdline_fixed_string_t min_bw;
14438         cmdline_fixed_string_t max_bw;
14439         cmdline_fixed_string_t strict_link_prio;
14440         portid_t port_id;
14441         uint16_t vf_id;
14442         uint8_t tc_no;
14443         uint32_t bw;
14444         cmdline_fixed_string_t bw_list;
14445         uint8_t tc_map;
14446 };
14447
14448 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14449         TOKEN_STRING_INITIALIZER
14450                 (struct cmd_vf_tc_bw_result,
14451                  set, "set");
14452 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14453         TOKEN_STRING_INITIALIZER
14454                 (struct cmd_vf_tc_bw_result,
14455                  vf, "vf");
14456 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14457         TOKEN_STRING_INITIALIZER
14458                 (struct cmd_vf_tc_bw_result,
14459                  tc, "tc");
14460 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14461         TOKEN_STRING_INITIALIZER
14462                 (struct cmd_vf_tc_bw_result,
14463                  tx, "tx");
14464 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14465         TOKEN_STRING_INITIALIZER
14466                 (struct cmd_vf_tc_bw_result,
14467                  strict_link_prio, "strict-link-priority");
14468 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14469         TOKEN_STRING_INITIALIZER
14470                 (struct cmd_vf_tc_bw_result,
14471                  min_bw, "min-bandwidth");
14472 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14473         TOKEN_STRING_INITIALIZER
14474                 (struct cmd_vf_tc_bw_result,
14475                  max_bw, "max-bandwidth");
14476 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14477         TOKEN_NUM_INITIALIZER
14478                 (struct cmd_vf_tc_bw_result,
14479                  port_id, UINT16);
14480 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14481         TOKEN_NUM_INITIALIZER
14482                 (struct cmd_vf_tc_bw_result,
14483                  vf_id, UINT16);
14484 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14485         TOKEN_NUM_INITIALIZER
14486                 (struct cmd_vf_tc_bw_result,
14487                  tc_no, UINT8);
14488 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14489         TOKEN_NUM_INITIALIZER
14490                 (struct cmd_vf_tc_bw_result,
14491                  bw, UINT32);
14492 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14493         TOKEN_STRING_INITIALIZER
14494                 (struct cmd_vf_tc_bw_result,
14495                  bw_list, NULL);
14496 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14497         TOKEN_NUM_INITIALIZER
14498                 (struct cmd_vf_tc_bw_result,
14499                  tc_map, UINT8);
14500
14501 /* VF max bandwidth setting */
14502 static void
14503 cmd_vf_max_bw_parsed(
14504         void *parsed_result,
14505         __attribute__((unused)) struct cmdline *cl,
14506         __attribute__((unused)) void *data)
14507 {
14508         struct cmd_vf_tc_bw_result *res = parsed_result;
14509         int ret = -ENOTSUP;
14510
14511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14512                 return;
14513
14514 #ifdef RTE_LIBRTE_I40E_PMD
14515         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14516                                          res->vf_id, res->bw);
14517 #endif
14518
14519         switch (ret) {
14520         case 0:
14521                 break;
14522         case -EINVAL:
14523                 printf("invalid vf_id %d or bandwidth %d\n",
14524                        res->vf_id, res->bw);
14525                 break;
14526         case -ENODEV:
14527                 printf("invalid port_id %d\n", res->port_id);
14528                 break;
14529         case -ENOTSUP:
14530                 printf("function not implemented\n");
14531                 break;
14532         default:
14533                 printf("programming error: (%s)\n", strerror(-ret));
14534         }
14535 }
14536
14537 cmdline_parse_inst_t cmd_vf_max_bw = {
14538         .f = cmd_vf_max_bw_parsed,
14539         .data = NULL,
14540         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14541         .tokens = {
14542                 (void *)&cmd_vf_tc_bw_set,
14543                 (void *)&cmd_vf_tc_bw_vf,
14544                 (void *)&cmd_vf_tc_bw_tx,
14545                 (void *)&cmd_vf_tc_bw_max_bw,
14546                 (void *)&cmd_vf_tc_bw_port_id,
14547                 (void *)&cmd_vf_tc_bw_vf_id,
14548                 (void *)&cmd_vf_tc_bw_bw,
14549                 NULL,
14550         },
14551 };
14552
14553 static int
14554 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14555                            uint8_t *tc_num,
14556                            char *str)
14557 {
14558         uint32_t size;
14559         const char *p, *p0 = str;
14560         char s[256];
14561         char *end;
14562         char *str_fld[16];
14563         uint16_t i;
14564         int ret;
14565
14566         p = strchr(p0, '(');
14567         if (p == NULL) {
14568                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14569                 return -1;
14570         }
14571         p++;
14572         p0 = strchr(p, ')');
14573         if (p0 == NULL) {
14574                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14575                 return -1;
14576         }
14577         size = p0 - p;
14578         if (size >= sizeof(s)) {
14579                 printf("The string size exceeds the internal buffer size\n");
14580                 return -1;
14581         }
14582         snprintf(s, sizeof(s), "%.*s", size, p);
14583         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14584         if (ret <= 0) {
14585                 printf("Failed to get the bandwidth list. ");
14586                 return -1;
14587         }
14588         *tc_num = ret;
14589         for (i = 0; i < ret; i++)
14590                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14591
14592         return 0;
14593 }
14594
14595 /* TC min bandwidth setting */
14596 static void
14597 cmd_vf_tc_min_bw_parsed(
14598         void *parsed_result,
14599         __attribute__((unused)) struct cmdline *cl,
14600         __attribute__((unused)) void *data)
14601 {
14602         struct cmd_vf_tc_bw_result *res = parsed_result;
14603         uint8_t tc_num;
14604         uint8_t bw[16];
14605         int ret = -ENOTSUP;
14606
14607         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14608                 return;
14609
14610         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14611         if (ret)
14612                 return;
14613
14614 #ifdef RTE_LIBRTE_I40E_PMD
14615         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14616                                               tc_num, bw);
14617 #endif
14618
14619         switch (ret) {
14620         case 0:
14621                 break;
14622         case -EINVAL:
14623                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14624                 break;
14625         case -ENODEV:
14626                 printf("invalid port_id %d\n", res->port_id);
14627                 break;
14628         case -ENOTSUP:
14629                 printf("function not implemented\n");
14630                 break;
14631         default:
14632                 printf("programming error: (%s)\n", strerror(-ret));
14633         }
14634 }
14635
14636 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14637         .f = cmd_vf_tc_min_bw_parsed,
14638         .data = NULL,
14639         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14640                     " <bw1, bw2, ...>",
14641         .tokens = {
14642                 (void *)&cmd_vf_tc_bw_set,
14643                 (void *)&cmd_vf_tc_bw_vf,
14644                 (void *)&cmd_vf_tc_bw_tc,
14645                 (void *)&cmd_vf_tc_bw_tx,
14646                 (void *)&cmd_vf_tc_bw_min_bw,
14647                 (void *)&cmd_vf_tc_bw_port_id,
14648                 (void *)&cmd_vf_tc_bw_vf_id,
14649                 (void *)&cmd_vf_tc_bw_bw_list,
14650                 NULL,
14651         },
14652 };
14653
14654 static void
14655 cmd_tc_min_bw_parsed(
14656         void *parsed_result,
14657         __attribute__((unused)) struct cmdline *cl,
14658         __attribute__((unused)) void *data)
14659 {
14660         struct cmd_vf_tc_bw_result *res = parsed_result;
14661         struct rte_port *port;
14662         uint8_t tc_num;
14663         uint8_t bw[16];
14664         int ret = -ENOTSUP;
14665
14666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14667                 return;
14668
14669         port = &ports[res->port_id];
14670         /** Check if the port is not started **/
14671         if (port->port_status != RTE_PORT_STOPPED) {
14672                 printf("Please stop port %d first\n", res->port_id);
14673                 return;
14674         }
14675
14676         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14677         if (ret)
14678                 return;
14679
14680 #ifdef RTE_LIBRTE_IXGBE_PMD
14681         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14682 #endif
14683
14684         switch (ret) {
14685         case 0:
14686                 break;
14687         case -EINVAL:
14688                 printf("invalid bandwidth\n");
14689                 break;
14690         case -ENODEV:
14691                 printf("invalid port_id %d\n", res->port_id);
14692                 break;
14693         case -ENOTSUP:
14694                 printf("function not implemented\n");
14695                 break;
14696         default:
14697                 printf("programming error: (%s)\n", strerror(-ret));
14698         }
14699 }
14700
14701 cmdline_parse_inst_t cmd_tc_min_bw = {
14702         .f = cmd_tc_min_bw_parsed,
14703         .data = NULL,
14704         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14705         .tokens = {
14706                 (void *)&cmd_vf_tc_bw_set,
14707                 (void *)&cmd_vf_tc_bw_tc,
14708                 (void *)&cmd_vf_tc_bw_tx,
14709                 (void *)&cmd_vf_tc_bw_min_bw,
14710                 (void *)&cmd_vf_tc_bw_port_id,
14711                 (void *)&cmd_vf_tc_bw_bw_list,
14712                 NULL,
14713         },
14714 };
14715
14716 /* TC max bandwidth setting */
14717 static void
14718 cmd_vf_tc_max_bw_parsed(
14719         void *parsed_result,
14720         __attribute__((unused)) struct cmdline *cl,
14721         __attribute__((unused)) void *data)
14722 {
14723         struct cmd_vf_tc_bw_result *res = parsed_result;
14724         int ret = -ENOTSUP;
14725
14726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14727                 return;
14728
14729 #ifdef RTE_LIBRTE_I40E_PMD
14730         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14731                                             res->tc_no, res->bw);
14732 #endif
14733
14734         switch (ret) {
14735         case 0:
14736                 break;
14737         case -EINVAL:
14738                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14739                        res->vf_id, res->tc_no, res->bw);
14740                 break;
14741         case -ENODEV:
14742                 printf("invalid port_id %d\n", res->port_id);
14743                 break;
14744         case -ENOTSUP:
14745                 printf("function not implemented\n");
14746                 break;
14747         default:
14748                 printf("programming error: (%s)\n", strerror(-ret));
14749         }
14750 }
14751
14752 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14753         .f = cmd_vf_tc_max_bw_parsed,
14754         .data = NULL,
14755         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14756                     " <bandwidth>",
14757         .tokens = {
14758                 (void *)&cmd_vf_tc_bw_set,
14759                 (void *)&cmd_vf_tc_bw_vf,
14760                 (void *)&cmd_vf_tc_bw_tc,
14761                 (void *)&cmd_vf_tc_bw_tx,
14762                 (void *)&cmd_vf_tc_bw_max_bw,
14763                 (void *)&cmd_vf_tc_bw_port_id,
14764                 (void *)&cmd_vf_tc_bw_vf_id,
14765                 (void *)&cmd_vf_tc_bw_tc_no,
14766                 (void *)&cmd_vf_tc_bw_bw,
14767                 NULL,
14768         },
14769 };
14770
14771
14772 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14773
14774 /* *** Set Port default Traffic Management Hierarchy *** */
14775 struct cmd_set_port_tm_hierarchy_default_result {
14776         cmdline_fixed_string_t set;
14777         cmdline_fixed_string_t port;
14778         cmdline_fixed_string_t tm;
14779         cmdline_fixed_string_t hierarchy;
14780         cmdline_fixed_string_t def;
14781         portid_t port_id;
14782 };
14783
14784 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14785         TOKEN_STRING_INITIALIZER(
14786                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14787 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14788         TOKEN_STRING_INITIALIZER(
14789                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14790 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14791         TOKEN_STRING_INITIALIZER(
14792                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14793 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14794         TOKEN_STRING_INITIALIZER(
14795                 struct cmd_set_port_tm_hierarchy_default_result,
14796                         hierarchy, "hierarchy");
14797 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14798         TOKEN_STRING_INITIALIZER(
14799                 struct cmd_set_port_tm_hierarchy_default_result,
14800                         def, "default");
14801 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14802         TOKEN_NUM_INITIALIZER(
14803                 struct cmd_set_port_tm_hierarchy_default_result,
14804                         port_id, UINT16);
14805
14806 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14807         __attribute__((unused)) struct cmdline *cl,
14808         __attribute__((unused)) void *data)
14809 {
14810         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14811         struct rte_port *p;
14812         portid_t port_id = res->port_id;
14813
14814         if (port_id_is_invalid(port_id, ENABLED_WARN))
14815                 return;
14816
14817         p = &ports[port_id];
14818
14819         /* Port tm flag */
14820         if (p->softport.tm_flag == 0) {
14821                 printf("  tm not enabled on port %u (error)\n", port_id);
14822                 return;
14823         }
14824
14825         /* Forward mode: tm */
14826         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14827                 printf("  tm mode not enabled(error)\n");
14828                 return;
14829         }
14830
14831         /* Set the default tm hierarchy */
14832         p->softport.tm.default_hierarchy_enable = 1;
14833 }
14834
14835 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14836         .f = cmd_set_port_tm_hierarchy_default_parsed,
14837         .data = NULL,
14838         .help_str = "set port tm hierarchy default <port_id>",
14839         .tokens = {
14840                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14841                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14842                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14843                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14844                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14845                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14846                 NULL,
14847         },
14848 };
14849 #endif
14850
14851 /* Strict link priority scheduling mode setting */
14852 static void
14853 cmd_strict_link_prio_parsed(
14854         void *parsed_result,
14855         __attribute__((unused)) struct cmdline *cl,
14856         __attribute__((unused)) void *data)
14857 {
14858         struct cmd_vf_tc_bw_result *res = parsed_result;
14859         int ret = -ENOTSUP;
14860
14861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14862                 return;
14863
14864 #ifdef RTE_LIBRTE_I40E_PMD
14865         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14866 #endif
14867
14868         switch (ret) {
14869         case 0:
14870                 break;
14871         case -EINVAL:
14872                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14873                 break;
14874         case -ENODEV:
14875                 printf("invalid port_id %d\n", res->port_id);
14876                 break;
14877         case -ENOTSUP:
14878                 printf("function not implemented\n");
14879                 break;
14880         default:
14881                 printf("programming error: (%s)\n", strerror(-ret));
14882         }
14883 }
14884
14885 cmdline_parse_inst_t cmd_strict_link_prio = {
14886         .f = cmd_strict_link_prio_parsed,
14887         .data = NULL,
14888         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14889         .tokens = {
14890                 (void *)&cmd_vf_tc_bw_set,
14891                 (void *)&cmd_vf_tc_bw_tx,
14892                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14893                 (void *)&cmd_vf_tc_bw_port_id,
14894                 (void *)&cmd_vf_tc_bw_tc_map,
14895                 NULL,
14896         },
14897 };
14898
14899 /* Load dynamic device personalization*/
14900 struct cmd_ddp_add_result {
14901         cmdline_fixed_string_t ddp;
14902         cmdline_fixed_string_t add;
14903         portid_t port_id;
14904         char filepath[];
14905 };
14906
14907 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14908         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14909 cmdline_parse_token_string_t cmd_ddp_add_add =
14910         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14911 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14912         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14913 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14914         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14915
14916 static void
14917 cmd_ddp_add_parsed(
14918         void *parsed_result,
14919         __attribute__((unused)) struct cmdline *cl,
14920         __attribute__((unused)) void *data)
14921 {
14922         struct cmd_ddp_add_result *res = parsed_result;
14923         uint8_t *buff;
14924         uint32_t size;
14925         char *filepath;
14926         char *file_fld[2];
14927         int file_num;
14928         int ret = -ENOTSUP;
14929
14930         if (!all_ports_stopped()) {
14931                 printf("Please stop all ports first\n");
14932                 return;
14933         }
14934
14935         filepath = strdup(res->filepath);
14936         if (filepath == NULL) {
14937                 printf("Failed to allocate memory\n");
14938                 return;
14939         }
14940         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14941
14942         buff = open_file(file_fld[0], &size);
14943         if (!buff) {
14944                 free((void *)filepath);
14945                 return;
14946         }
14947
14948 #ifdef RTE_LIBRTE_I40E_PMD
14949         if (ret == -ENOTSUP)
14950                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14951                                                buff, size,
14952                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14953 #endif
14954
14955         if (ret == -EEXIST)
14956                 printf("Profile has already existed.\n");
14957         else if (ret < 0)
14958                 printf("Failed to load profile.\n");
14959         else if (file_num == 2)
14960                 save_file(file_fld[1], buff, size);
14961
14962         close_file(buff);
14963         free((void *)filepath);
14964 }
14965
14966 cmdline_parse_inst_t cmd_ddp_add = {
14967         .f = cmd_ddp_add_parsed,
14968         .data = NULL,
14969         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14970         .tokens = {
14971                 (void *)&cmd_ddp_add_ddp,
14972                 (void *)&cmd_ddp_add_add,
14973                 (void *)&cmd_ddp_add_port_id,
14974                 (void *)&cmd_ddp_add_filepath,
14975                 NULL,
14976         },
14977 };
14978
14979 /* Delete dynamic device personalization*/
14980 struct cmd_ddp_del_result {
14981         cmdline_fixed_string_t ddp;
14982         cmdline_fixed_string_t del;
14983         portid_t port_id;
14984         char filepath[];
14985 };
14986
14987 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14988         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14989 cmdline_parse_token_string_t cmd_ddp_del_del =
14990         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14991 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14992         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14993 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14994         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14995
14996 static void
14997 cmd_ddp_del_parsed(
14998         void *parsed_result,
14999         __attribute__((unused)) struct cmdline *cl,
15000         __attribute__((unused)) void *data)
15001 {
15002         struct cmd_ddp_del_result *res = parsed_result;
15003         uint8_t *buff;
15004         uint32_t size;
15005         int ret = -ENOTSUP;
15006
15007         if (!all_ports_stopped()) {
15008                 printf("Please stop all ports first\n");
15009                 return;
15010         }
15011
15012         buff = open_file(res->filepath, &size);
15013         if (!buff)
15014                 return;
15015
15016 #ifdef RTE_LIBRTE_I40E_PMD
15017         if (ret == -ENOTSUP)
15018                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15019                                                buff, size,
15020                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15021 #endif
15022
15023         if (ret == -EACCES)
15024                 printf("Profile does not exist.\n");
15025         else if (ret < 0)
15026                 printf("Failed to delete profile.\n");
15027
15028         close_file(buff);
15029 }
15030
15031 cmdline_parse_inst_t cmd_ddp_del = {
15032         .f = cmd_ddp_del_parsed,
15033         .data = NULL,
15034         .help_str = "ddp del <port_id> <backup_profile_path>",
15035         .tokens = {
15036                 (void *)&cmd_ddp_del_ddp,
15037                 (void *)&cmd_ddp_del_del,
15038                 (void *)&cmd_ddp_del_port_id,
15039                 (void *)&cmd_ddp_del_filepath,
15040                 NULL,
15041         },
15042 };
15043
15044 /* Get dynamic device personalization profile info */
15045 struct cmd_ddp_info_result {
15046         cmdline_fixed_string_t ddp;
15047         cmdline_fixed_string_t get;
15048         cmdline_fixed_string_t info;
15049         char filepath[];
15050 };
15051
15052 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15053         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15054 cmdline_parse_token_string_t cmd_ddp_info_get =
15055         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15056 cmdline_parse_token_string_t cmd_ddp_info_info =
15057         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15058 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15059         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15060
15061 static void
15062 cmd_ddp_info_parsed(
15063         void *parsed_result,
15064         __attribute__((unused)) struct cmdline *cl,
15065         __attribute__((unused)) void *data)
15066 {
15067         struct cmd_ddp_info_result *res = parsed_result;
15068         uint8_t *pkg;
15069         uint32_t pkg_size;
15070         int ret = -ENOTSUP;
15071 #ifdef RTE_LIBRTE_I40E_PMD
15072         uint32_t i, j, n;
15073         uint8_t *buff;
15074         uint32_t buff_size = 0;
15075         struct rte_pmd_i40e_profile_info info;
15076         uint32_t dev_num = 0;
15077         struct rte_pmd_i40e_ddp_device_id *devs;
15078         uint32_t proto_num = 0;
15079         struct rte_pmd_i40e_proto_info *proto = NULL;
15080         uint32_t pctype_num = 0;
15081         struct rte_pmd_i40e_ptype_info *pctype;
15082         uint32_t ptype_num = 0;
15083         struct rte_pmd_i40e_ptype_info *ptype;
15084         uint8_t proto_id;
15085
15086 #endif
15087
15088         pkg = open_file(res->filepath, &pkg_size);
15089         if (!pkg)
15090                 return;
15091
15092 #ifdef RTE_LIBRTE_I40E_PMD
15093         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15094                                 (uint8_t *)&info, sizeof(info),
15095                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15096         if (!ret) {
15097                 printf("Global Track id:       0x%x\n", info.track_id);
15098                 printf("Global Version:        %d.%d.%d.%d\n",
15099                         info.version.major,
15100                         info.version.minor,
15101                         info.version.update,
15102                         info.version.draft);
15103                 printf("Global Package name:   %s\n\n", info.name);
15104         }
15105
15106         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15107                                 (uint8_t *)&info, sizeof(info),
15108                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15109         if (!ret) {
15110                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15111                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15112                         info.version.major,
15113                         info.version.minor,
15114                         info.version.update,
15115                         info.version.draft);
15116                 printf("i40e Profile name:     %s\n\n", info.name);
15117         }
15118
15119         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15120                                 (uint8_t *)&buff_size, sizeof(buff_size),
15121                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15122         if (!ret && buff_size) {
15123                 buff = (uint8_t *)malloc(buff_size);
15124                 if (buff) {
15125                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15126                                                 buff, buff_size,
15127                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15128                         if (!ret)
15129                                 printf("Package Notes:\n%s\n\n", buff);
15130                         free(buff);
15131                 }
15132         }
15133
15134         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15135                                 (uint8_t *)&dev_num, sizeof(dev_num),
15136                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15137         if (!ret && dev_num) {
15138                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15139                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15140                 if (devs) {
15141                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15142                                                 (uint8_t *)devs, buff_size,
15143                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15144                         if (!ret) {
15145                                 printf("List of supported devices:\n");
15146                                 for (i = 0; i < dev_num; i++) {
15147                                         printf("  %04X:%04X %04X:%04X\n",
15148                                                 devs[i].vendor_dev_id >> 16,
15149                                                 devs[i].vendor_dev_id & 0xFFFF,
15150                                                 devs[i].sub_vendor_dev_id >> 16,
15151                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15152                                 }
15153                                 printf("\n");
15154                         }
15155                         free(devs);
15156                 }
15157         }
15158
15159         /* get information about protocols and packet types */
15160         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15161                 (uint8_t *)&proto_num, sizeof(proto_num),
15162                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15163         if (ret || !proto_num)
15164                 goto no_print_return;
15165
15166         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15167         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15168         if (!proto)
15169                 goto no_print_return;
15170
15171         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15172                                         buff_size,
15173                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15174         if (!ret) {
15175                 printf("List of used protocols:\n");
15176                 for (i = 0; i < proto_num; i++)
15177                         printf("  %2u: %s\n", proto[i].proto_id,
15178                                proto[i].name);
15179                 printf("\n");
15180         }
15181         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15182                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15183                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15184         if (ret || !pctype_num)
15185                 goto no_print_pctypes;
15186
15187         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15188         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15189         if (!pctype)
15190                 goto no_print_pctypes;
15191
15192         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15193                                         buff_size,
15194                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15195         if (ret) {
15196                 free(pctype);
15197                 goto no_print_pctypes;
15198         }
15199
15200         printf("List of defined packet classification types:\n");
15201         for (i = 0; i < pctype_num; i++) {
15202                 printf("  %2u:", pctype[i].ptype_id);
15203                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15204                         proto_id = pctype[i].protocols[j];
15205                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15206                                 for (n = 0; n < proto_num; n++) {
15207                                         if (proto[n].proto_id == proto_id) {
15208                                                 printf(" %s", proto[n].name);
15209                                                 break;
15210                                         }
15211                                 }
15212                         }
15213                 }
15214                 printf("\n");
15215         }
15216         printf("\n");
15217         free(pctype);
15218
15219 no_print_pctypes:
15220
15221         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15222                                         sizeof(ptype_num),
15223                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15224         if (ret || !ptype_num)
15225                 goto no_print_return;
15226
15227         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15228         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15229         if (!ptype)
15230                 goto no_print_return;
15231
15232         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15233                                         buff_size,
15234                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15235         if (ret) {
15236                 free(ptype);
15237                 goto no_print_return;
15238         }
15239         printf("List of defined packet types:\n");
15240         for (i = 0; i < ptype_num; i++) {
15241                 printf("  %2u:", ptype[i].ptype_id);
15242                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15243                         proto_id = ptype[i].protocols[j];
15244                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15245                                 for (n = 0; n < proto_num; n++) {
15246                                         if (proto[n].proto_id == proto_id) {
15247                                                 printf(" %s", proto[n].name);
15248                                                 break;
15249                                         }
15250                                 }
15251                         }
15252                 }
15253                 printf("\n");
15254         }
15255         free(ptype);
15256         printf("\n");
15257
15258         ret = 0;
15259 no_print_return:
15260         if (proto)
15261                 free(proto);
15262 #endif
15263         if (ret == -ENOTSUP)
15264                 printf("Function not supported in PMD driver\n");
15265         close_file(pkg);
15266 }
15267
15268 cmdline_parse_inst_t cmd_ddp_get_info = {
15269         .f = cmd_ddp_info_parsed,
15270         .data = NULL,
15271         .help_str = "ddp get info <profile_path>",
15272         .tokens = {
15273                 (void *)&cmd_ddp_info_ddp,
15274                 (void *)&cmd_ddp_info_get,
15275                 (void *)&cmd_ddp_info_info,
15276                 (void *)&cmd_ddp_info_filepath,
15277                 NULL,
15278         },
15279 };
15280
15281 /* Get dynamic device personalization profile info list*/
15282 #define PROFILE_INFO_SIZE 48
15283 #define MAX_PROFILE_NUM 16
15284
15285 struct cmd_ddp_get_list_result {
15286         cmdline_fixed_string_t ddp;
15287         cmdline_fixed_string_t get;
15288         cmdline_fixed_string_t list;
15289         portid_t port_id;
15290 };
15291
15292 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15293         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15294 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15295         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15296 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15297         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15298 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15299         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15300
15301 static void
15302 cmd_ddp_get_list_parsed(
15303         __attribute__((unused)) void *parsed_result,
15304         __attribute__((unused)) struct cmdline *cl,
15305         __attribute__((unused)) void *data)
15306 {
15307 #ifdef RTE_LIBRTE_I40E_PMD
15308         struct cmd_ddp_get_list_result *res = parsed_result;
15309         struct rte_pmd_i40e_profile_list *p_list;
15310         struct rte_pmd_i40e_profile_info *p_info;
15311         uint32_t p_num;
15312         uint32_t size;
15313         uint32_t i;
15314 #endif
15315         int ret = -ENOTSUP;
15316
15317 #ifdef RTE_LIBRTE_I40E_PMD
15318         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15319         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15320         if (!p_list)
15321                 printf("%s: Failed to malloc buffer\n", __func__);
15322
15323         if (ret == -ENOTSUP)
15324                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15325                                                 (uint8_t *)p_list, size);
15326
15327         if (!ret) {
15328                 p_num = p_list->p_count;
15329                 printf("Profile number is: %d\n\n", p_num);
15330
15331                 for (i = 0; i < p_num; i++) {
15332                         p_info = &p_list->p_info[i];
15333                         printf("Profile %d:\n", i);
15334                         printf("Track id:     0x%x\n", p_info->track_id);
15335                         printf("Version:      %d.%d.%d.%d\n",
15336                                p_info->version.major,
15337                                p_info->version.minor,
15338                                p_info->version.update,
15339                                p_info->version.draft);
15340                         printf("Profile name: %s\n\n", p_info->name);
15341                 }
15342         }
15343
15344         free(p_list);
15345 #endif
15346
15347         if (ret < 0)
15348                 printf("Failed to get ddp list\n");
15349 }
15350
15351 cmdline_parse_inst_t cmd_ddp_get_list = {
15352         .f = cmd_ddp_get_list_parsed,
15353         .data = NULL,
15354         .help_str = "ddp get list <port_id>",
15355         .tokens = {
15356                 (void *)&cmd_ddp_get_list_ddp,
15357                 (void *)&cmd_ddp_get_list_get,
15358                 (void *)&cmd_ddp_get_list_list,
15359                 (void *)&cmd_ddp_get_list_port_id,
15360                 NULL,
15361         },
15362 };
15363
15364 /* Configure input set */
15365 struct cmd_cfg_input_set_result {
15366         cmdline_fixed_string_t port;
15367         cmdline_fixed_string_t cfg;
15368         portid_t port_id;
15369         cmdline_fixed_string_t pctype;
15370         uint8_t pctype_id;
15371         cmdline_fixed_string_t inset_type;
15372         cmdline_fixed_string_t opt;
15373         cmdline_fixed_string_t field;
15374         uint8_t field_idx;
15375 };
15376
15377 static void
15378 cmd_cfg_input_set_parsed(
15379         __attribute__((unused)) void *parsed_result,
15380         __attribute__((unused)) struct cmdline *cl,
15381         __attribute__((unused)) void *data)
15382 {
15383 #ifdef RTE_LIBRTE_I40E_PMD
15384         struct cmd_cfg_input_set_result *res = parsed_result;
15385         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15386         struct rte_pmd_i40e_inset inset;
15387 #endif
15388         int ret = -ENOTSUP;
15389
15390         if (!all_ports_stopped()) {
15391                 printf("Please stop all ports first\n");
15392                 return;
15393         }
15394
15395 #ifdef RTE_LIBRTE_I40E_PMD
15396         if (!strcmp(res->inset_type, "hash_inset"))
15397                 inset_type = INSET_HASH;
15398         else if (!strcmp(res->inset_type, "fdir_inset"))
15399                 inset_type = INSET_FDIR;
15400         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15401                 inset_type = INSET_FDIR_FLX;
15402         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15403                                      &inset, inset_type);
15404         if (ret) {
15405                 printf("Failed to get input set.\n");
15406                 return;
15407         }
15408
15409         if (!strcmp(res->opt, "get")) {
15410                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15411                                                    res->field_idx);
15412                 if (ret)
15413                         printf("Field index %d is enabled.\n", res->field_idx);
15414                 else
15415                         printf("Field index %d is disabled.\n", res->field_idx);
15416                 return;
15417         } else if (!strcmp(res->opt, "set"))
15418                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15419                                                    res->field_idx);
15420         else if (!strcmp(res->opt, "clear"))
15421                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15422                                                      res->field_idx);
15423         if (ret) {
15424                 printf("Failed to configure input set field.\n");
15425                 return;
15426         }
15427
15428         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15429                                      &inset, inset_type);
15430         if (ret) {
15431                 printf("Failed to set input set.\n");
15432                 return;
15433         }
15434 #endif
15435
15436         if (ret == -ENOTSUP)
15437                 printf("Function not supported\n");
15438 }
15439
15440 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15441         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15442                                  port, "port");
15443 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15444         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15445                                  cfg, "config");
15446 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15447         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15448                               port_id, UINT16);
15449 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15450         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15451                                  pctype, "pctype");
15452 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15453         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15454                               pctype_id, UINT8);
15455 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15456         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15457                                  inset_type,
15458                                  "hash_inset#fdir_inset#fdir_flx_inset");
15459 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15460         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15461                                  opt, "get#set#clear");
15462 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15463         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15464                                  field, "field");
15465 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15466         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15467                               field_idx, UINT8);
15468
15469 cmdline_parse_inst_t cmd_cfg_input_set = {
15470         .f = cmd_cfg_input_set_parsed,
15471         .data = NULL,
15472         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15473                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15474         .tokens = {
15475                 (void *)&cmd_cfg_input_set_port,
15476                 (void *)&cmd_cfg_input_set_cfg,
15477                 (void *)&cmd_cfg_input_set_port_id,
15478                 (void *)&cmd_cfg_input_set_pctype,
15479                 (void *)&cmd_cfg_input_set_pctype_id,
15480                 (void *)&cmd_cfg_input_set_inset_type,
15481                 (void *)&cmd_cfg_input_set_opt,
15482                 (void *)&cmd_cfg_input_set_field,
15483                 (void *)&cmd_cfg_input_set_field_idx,
15484                 NULL,
15485         },
15486 };
15487
15488 /* Clear input set */
15489 struct cmd_clear_input_set_result {
15490         cmdline_fixed_string_t port;
15491         cmdline_fixed_string_t cfg;
15492         portid_t port_id;
15493         cmdline_fixed_string_t pctype;
15494         uint8_t pctype_id;
15495         cmdline_fixed_string_t inset_type;
15496         cmdline_fixed_string_t clear;
15497         cmdline_fixed_string_t all;
15498 };
15499
15500 static void
15501 cmd_clear_input_set_parsed(
15502         __attribute__((unused)) void *parsed_result,
15503         __attribute__((unused)) struct cmdline *cl,
15504         __attribute__((unused)) void *data)
15505 {
15506 #ifdef RTE_LIBRTE_I40E_PMD
15507         struct cmd_clear_input_set_result *res = parsed_result;
15508         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15509         struct rte_pmd_i40e_inset inset;
15510 #endif
15511         int ret = -ENOTSUP;
15512
15513         if (!all_ports_stopped()) {
15514                 printf("Please stop all ports first\n");
15515                 return;
15516         }
15517
15518 #ifdef RTE_LIBRTE_I40E_PMD
15519         if (!strcmp(res->inset_type, "hash_inset"))
15520                 inset_type = INSET_HASH;
15521         else if (!strcmp(res->inset_type, "fdir_inset"))
15522                 inset_type = INSET_FDIR;
15523         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15524                 inset_type = INSET_FDIR_FLX;
15525
15526         memset(&inset, 0, sizeof(inset));
15527
15528         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15529                                      &inset, inset_type);
15530         if (ret) {
15531                 printf("Failed to clear input set.\n");
15532                 return;
15533         }
15534
15535 #endif
15536
15537         if (ret == -ENOTSUP)
15538                 printf("Function not supported\n");
15539 }
15540
15541 cmdline_parse_token_string_t cmd_clear_input_set_port =
15542         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15543                                  port, "port");
15544 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15545         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15546                                  cfg, "config");
15547 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15548         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15549                               port_id, UINT16);
15550 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15551         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15552                                  pctype, "pctype");
15553 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15554         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15555                               pctype_id, UINT8);
15556 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15557         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15558                                  inset_type,
15559                                  "hash_inset#fdir_inset#fdir_flx_inset");
15560 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15561         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15562                                  clear, "clear");
15563 cmdline_parse_token_string_t cmd_clear_input_set_all =
15564         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15565                                  all, "all");
15566
15567 cmdline_parse_inst_t cmd_clear_input_set = {
15568         .f = cmd_clear_input_set_parsed,
15569         .data = NULL,
15570         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15571                     "fdir_inset|fdir_flx_inset clear all",
15572         .tokens = {
15573                 (void *)&cmd_clear_input_set_port,
15574                 (void *)&cmd_clear_input_set_cfg,
15575                 (void *)&cmd_clear_input_set_port_id,
15576                 (void *)&cmd_clear_input_set_pctype,
15577                 (void *)&cmd_clear_input_set_pctype_id,
15578                 (void *)&cmd_clear_input_set_inset_type,
15579                 (void *)&cmd_clear_input_set_clear,
15580                 (void *)&cmd_clear_input_set_all,
15581                 NULL,
15582         },
15583 };
15584
15585 /* show vf stats */
15586
15587 /* Common result structure for show vf stats */
15588 struct cmd_show_vf_stats_result {
15589         cmdline_fixed_string_t show;
15590         cmdline_fixed_string_t vf;
15591         cmdline_fixed_string_t stats;
15592         portid_t port_id;
15593         uint16_t vf_id;
15594 };
15595
15596 /* Common CLI fields show vf stats*/
15597 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15598         TOKEN_STRING_INITIALIZER
15599                 (struct cmd_show_vf_stats_result,
15600                  show, "show");
15601 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15602         TOKEN_STRING_INITIALIZER
15603                 (struct cmd_show_vf_stats_result,
15604                  vf, "vf");
15605 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15606         TOKEN_STRING_INITIALIZER
15607                 (struct cmd_show_vf_stats_result,
15608                  stats, "stats");
15609 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15610         TOKEN_NUM_INITIALIZER
15611                 (struct cmd_show_vf_stats_result,
15612                  port_id, UINT16);
15613 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15614         TOKEN_NUM_INITIALIZER
15615                 (struct cmd_show_vf_stats_result,
15616                  vf_id, UINT16);
15617
15618 static void
15619 cmd_show_vf_stats_parsed(
15620         void *parsed_result,
15621         __attribute__((unused)) struct cmdline *cl,
15622         __attribute__((unused)) void *data)
15623 {
15624         struct cmd_show_vf_stats_result *res = parsed_result;
15625         struct rte_eth_stats stats;
15626         int ret = -ENOTSUP;
15627         static const char *nic_stats_border = "########################";
15628
15629         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15630                 return;
15631
15632         memset(&stats, 0, sizeof(stats));
15633
15634 #ifdef RTE_LIBRTE_I40E_PMD
15635         if (ret == -ENOTSUP)
15636                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15637                                                 res->vf_id,
15638                                                 &stats);
15639 #endif
15640 #ifdef RTE_LIBRTE_BNXT_PMD
15641         if (ret == -ENOTSUP)
15642                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15643                                                 res->vf_id,
15644                                                 &stats);
15645 #endif
15646
15647         switch (ret) {
15648         case 0:
15649                 break;
15650         case -EINVAL:
15651                 printf("invalid vf_id %d\n", res->vf_id);
15652                 break;
15653         case -ENODEV:
15654                 printf("invalid port_id %d\n", res->port_id);
15655                 break;
15656         case -ENOTSUP:
15657                 printf("function not implemented\n");
15658                 break;
15659         default:
15660                 printf("programming error: (%s)\n", strerror(-ret));
15661         }
15662
15663         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15664                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15665
15666         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15667                "%-"PRIu64"\n",
15668                stats.ipackets, stats.imissed, stats.ibytes);
15669         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15670         printf("  RX-nombuf:  %-10"PRIu64"\n",
15671                stats.rx_nombuf);
15672         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15673                "%-"PRIu64"\n",
15674                stats.opackets, stats.oerrors, stats.obytes);
15675
15676         printf("  %s############################%s\n",
15677                                nic_stats_border, nic_stats_border);
15678 }
15679
15680 cmdline_parse_inst_t cmd_show_vf_stats = {
15681         .f = cmd_show_vf_stats_parsed,
15682         .data = NULL,
15683         .help_str = "show vf stats <port_id> <vf_id>",
15684         .tokens = {
15685                 (void *)&cmd_show_vf_stats_show,
15686                 (void *)&cmd_show_vf_stats_vf,
15687                 (void *)&cmd_show_vf_stats_stats,
15688                 (void *)&cmd_show_vf_stats_port_id,
15689                 (void *)&cmd_show_vf_stats_vf_id,
15690                 NULL,
15691         },
15692 };
15693
15694 /* clear vf stats */
15695
15696 /* Common result structure for clear vf stats */
15697 struct cmd_clear_vf_stats_result {
15698         cmdline_fixed_string_t clear;
15699         cmdline_fixed_string_t vf;
15700         cmdline_fixed_string_t stats;
15701         portid_t port_id;
15702         uint16_t vf_id;
15703 };
15704
15705 /* Common CLI fields clear vf stats*/
15706 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15707         TOKEN_STRING_INITIALIZER
15708                 (struct cmd_clear_vf_stats_result,
15709                  clear, "clear");
15710 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15711         TOKEN_STRING_INITIALIZER
15712                 (struct cmd_clear_vf_stats_result,
15713                  vf, "vf");
15714 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15715         TOKEN_STRING_INITIALIZER
15716                 (struct cmd_clear_vf_stats_result,
15717                  stats, "stats");
15718 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15719         TOKEN_NUM_INITIALIZER
15720                 (struct cmd_clear_vf_stats_result,
15721                  port_id, UINT16);
15722 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15723         TOKEN_NUM_INITIALIZER
15724                 (struct cmd_clear_vf_stats_result,
15725                  vf_id, UINT16);
15726
15727 static void
15728 cmd_clear_vf_stats_parsed(
15729         void *parsed_result,
15730         __attribute__((unused)) struct cmdline *cl,
15731         __attribute__((unused)) void *data)
15732 {
15733         struct cmd_clear_vf_stats_result *res = parsed_result;
15734         int ret = -ENOTSUP;
15735
15736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15737                 return;
15738
15739 #ifdef RTE_LIBRTE_I40E_PMD
15740         if (ret == -ENOTSUP)
15741                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15742                                                   res->vf_id);
15743 #endif
15744 #ifdef RTE_LIBRTE_BNXT_PMD
15745         if (ret == -ENOTSUP)
15746                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15747                                                   res->vf_id);
15748 #endif
15749
15750         switch (ret) {
15751         case 0:
15752                 break;
15753         case -EINVAL:
15754                 printf("invalid vf_id %d\n", res->vf_id);
15755                 break;
15756         case -ENODEV:
15757                 printf("invalid port_id %d\n", res->port_id);
15758                 break;
15759         case -ENOTSUP:
15760                 printf("function not implemented\n");
15761                 break;
15762         default:
15763                 printf("programming error: (%s)\n", strerror(-ret));
15764         }
15765 }
15766
15767 cmdline_parse_inst_t cmd_clear_vf_stats = {
15768         .f = cmd_clear_vf_stats_parsed,
15769         .data = NULL,
15770         .help_str = "clear vf stats <port_id> <vf_id>",
15771         .tokens = {
15772                 (void *)&cmd_clear_vf_stats_clear,
15773                 (void *)&cmd_clear_vf_stats_vf,
15774                 (void *)&cmd_clear_vf_stats_stats,
15775                 (void *)&cmd_clear_vf_stats_port_id,
15776                 (void *)&cmd_clear_vf_stats_vf_id,
15777                 NULL,
15778         },
15779 };
15780
15781 /* port config pctype mapping reset */
15782
15783 /* Common result structure for port config pctype mapping reset */
15784 struct cmd_pctype_mapping_reset_result {
15785         cmdline_fixed_string_t port;
15786         cmdline_fixed_string_t config;
15787         portid_t port_id;
15788         cmdline_fixed_string_t pctype;
15789         cmdline_fixed_string_t mapping;
15790         cmdline_fixed_string_t reset;
15791 };
15792
15793 /* Common CLI fields for port config pctype mapping reset*/
15794 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15795         TOKEN_STRING_INITIALIZER
15796                 (struct cmd_pctype_mapping_reset_result,
15797                  port, "port");
15798 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15799         TOKEN_STRING_INITIALIZER
15800                 (struct cmd_pctype_mapping_reset_result,
15801                  config, "config");
15802 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15803         TOKEN_NUM_INITIALIZER
15804                 (struct cmd_pctype_mapping_reset_result,
15805                  port_id, UINT16);
15806 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15807         TOKEN_STRING_INITIALIZER
15808                 (struct cmd_pctype_mapping_reset_result,
15809                  pctype, "pctype");
15810 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15811         TOKEN_STRING_INITIALIZER
15812                 (struct cmd_pctype_mapping_reset_result,
15813                  mapping, "mapping");
15814 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15815         TOKEN_STRING_INITIALIZER
15816                 (struct cmd_pctype_mapping_reset_result,
15817                  reset, "reset");
15818
15819 static void
15820 cmd_pctype_mapping_reset_parsed(
15821         void *parsed_result,
15822         __attribute__((unused)) struct cmdline *cl,
15823         __attribute__((unused)) void *data)
15824 {
15825         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15826         int ret = -ENOTSUP;
15827
15828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15829                 return;
15830
15831 #ifdef RTE_LIBRTE_I40E_PMD
15832         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15833 #endif
15834
15835         switch (ret) {
15836         case 0:
15837                 break;
15838         case -ENODEV:
15839                 printf("invalid port_id %d\n", res->port_id);
15840                 break;
15841         case -ENOTSUP:
15842                 printf("function not implemented\n");
15843                 break;
15844         default:
15845                 printf("programming error: (%s)\n", strerror(-ret));
15846         }
15847 }
15848
15849 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15850         .f = cmd_pctype_mapping_reset_parsed,
15851         .data = NULL,
15852         .help_str = "port config <port_id> pctype mapping reset",
15853         .tokens = {
15854                 (void *)&cmd_pctype_mapping_reset_port,
15855                 (void *)&cmd_pctype_mapping_reset_config,
15856                 (void *)&cmd_pctype_mapping_reset_port_id,
15857                 (void *)&cmd_pctype_mapping_reset_pctype,
15858                 (void *)&cmd_pctype_mapping_reset_mapping,
15859                 (void *)&cmd_pctype_mapping_reset_reset,
15860                 NULL,
15861         },
15862 };
15863
15864 /* show port pctype mapping */
15865
15866 /* Common result structure for show port pctype mapping */
15867 struct cmd_pctype_mapping_get_result {
15868         cmdline_fixed_string_t show;
15869         cmdline_fixed_string_t port;
15870         portid_t port_id;
15871         cmdline_fixed_string_t pctype;
15872         cmdline_fixed_string_t mapping;
15873 };
15874
15875 /* Common CLI fields for pctype mapping get */
15876 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15877         TOKEN_STRING_INITIALIZER
15878                 (struct cmd_pctype_mapping_get_result,
15879                  show, "show");
15880 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15881         TOKEN_STRING_INITIALIZER
15882                 (struct cmd_pctype_mapping_get_result,
15883                  port, "port");
15884 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15885         TOKEN_NUM_INITIALIZER
15886                 (struct cmd_pctype_mapping_get_result,
15887                  port_id, UINT16);
15888 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15889         TOKEN_STRING_INITIALIZER
15890                 (struct cmd_pctype_mapping_get_result,
15891                  pctype, "pctype");
15892 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15893         TOKEN_STRING_INITIALIZER
15894                 (struct cmd_pctype_mapping_get_result,
15895                  mapping, "mapping");
15896
15897 static void
15898 cmd_pctype_mapping_get_parsed(
15899         void *parsed_result,
15900         __attribute__((unused)) struct cmdline *cl,
15901         __attribute__((unused)) void *data)
15902 {
15903         struct cmd_pctype_mapping_get_result *res = parsed_result;
15904         int ret = -ENOTSUP;
15905 #ifdef RTE_LIBRTE_I40E_PMD
15906         struct rte_pmd_i40e_flow_type_mapping
15907                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15908         int i, j, first_pctype;
15909 #endif
15910
15911         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15912                 return;
15913
15914 #ifdef RTE_LIBRTE_I40E_PMD
15915         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15916 #endif
15917
15918         switch (ret) {
15919         case 0:
15920                 break;
15921         case -ENODEV:
15922                 printf("invalid port_id %d\n", res->port_id);
15923                 return;
15924         case -ENOTSUP:
15925                 printf("function not implemented\n");
15926                 return;
15927         default:
15928                 printf("programming error: (%s)\n", strerror(-ret));
15929                 return;
15930         }
15931
15932 #ifdef RTE_LIBRTE_I40E_PMD
15933         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15934                 if (mapping[i].pctype != 0ULL) {
15935                         first_pctype = 1;
15936
15937                         printf("pctype: ");
15938                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15939                                 if (mapping[i].pctype & (1ULL << j)) {
15940                                         printf(first_pctype ?
15941                                                "%02d" : ",%02d", j);
15942                                         first_pctype = 0;
15943                                 }
15944                         }
15945                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15946                 }
15947         }
15948 #endif
15949 }
15950
15951 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15952         .f = cmd_pctype_mapping_get_parsed,
15953         .data = NULL,
15954         .help_str = "show port <port_id> pctype mapping",
15955         .tokens = {
15956                 (void *)&cmd_pctype_mapping_get_show,
15957                 (void *)&cmd_pctype_mapping_get_port,
15958                 (void *)&cmd_pctype_mapping_get_port_id,
15959                 (void *)&cmd_pctype_mapping_get_pctype,
15960                 (void *)&cmd_pctype_mapping_get_mapping,
15961                 NULL,
15962         },
15963 };
15964
15965 /* port config pctype mapping update */
15966
15967 /* Common result structure for port config pctype mapping update */
15968 struct cmd_pctype_mapping_update_result {
15969         cmdline_fixed_string_t port;
15970         cmdline_fixed_string_t config;
15971         portid_t port_id;
15972         cmdline_fixed_string_t pctype;
15973         cmdline_fixed_string_t mapping;
15974         cmdline_fixed_string_t update;
15975         cmdline_fixed_string_t pctype_list;
15976         uint16_t flow_type;
15977 };
15978
15979 /* Common CLI fields for pctype mapping update*/
15980 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15981         TOKEN_STRING_INITIALIZER
15982                 (struct cmd_pctype_mapping_update_result,
15983                  port, "port");
15984 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15985         TOKEN_STRING_INITIALIZER
15986                 (struct cmd_pctype_mapping_update_result,
15987                  config, "config");
15988 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15989         TOKEN_NUM_INITIALIZER
15990                 (struct cmd_pctype_mapping_update_result,
15991                  port_id, UINT16);
15992 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15993         TOKEN_STRING_INITIALIZER
15994                 (struct cmd_pctype_mapping_update_result,
15995                  pctype, "pctype");
15996 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15997         TOKEN_STRING_INITIALIZER
15998                 (struct cmd_pctype_mapping_update_result,
15999                  mapping, "mapping");
16000 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16001         TOKEN_STRING_INITIALIZER
16002                 (struct cmd_pctype_mapping_update_result,
16003                  update, "update");
16004 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16005         TOKEN_STRING_INITIALIZER
16006                 (struct cmd_pctype_mapping_update_result,
16007                  pctype_list, NULL);
16008 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16009         TOKEN_NUM_INITIALIZER
16010                 (struct cmd_pctype_mapping_update_result,
16011                  flow_type, UINT16);
16012
16013 static void
16014 cmd_pctype_mapping_update_parsed(
16015         void *parsed_result,
16016         __attribute__((unused)) struct cmdline *cl,
16017         __attribute__((unused)) void *data)
16018 {
16019         struct cmd_pctype_mapping_update_result *res = parsed_result;
16020         int ret = -ENOTSUP;
16021 #ifdef RTE_LIBRTE_I40E_PMD
16022         struct rte_pmd_i40e_flow_type_mapping mapping;
16023         unsigned int i;
16024         unsigned int nb_item;
16025         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16026 #endif
16027
16028         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16029                 return;
16030
16031 #ifdef RTE_LIBRTE_I40E_PMD
16032         nb_item = parse_item_list(res->pctype_list, "pctypes",
16033                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16034         mapping.flow_type = res->flow_type;
16035         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16036                 mapping.pctype |= (1ULL << pctype_list[i]);
16037         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16038                                                 &mapping,
16039                                                 1,
16040                                                 0);
16041 #endif
16042
16043         switch (ret) {
16044         case 0:
16045                 break;
16046         case -EINVAL:
16047                 printf("invalid pctype or flow type\n");
16048                 break;
16049         case -ENODEV:
16050                 printf("invalid port_id %d\n", res->port_id);
16051                 break;
16052         case -ENOTSUP:
16053                 printf("function not implemented\n");
16054                 break;
16055         default:
16056                 printf("programming error: (%s)\n", strerror(-ret));
16057         }
16058 }
16059
16060 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16061         .f = cmd_pctype_mapping_update_parsed,
16062         .data = NULL,
16063         .help_str = "port config <port_id> pctype mapping update"
16064         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16065         .tokens = {
16066                 (void *)&cmd_pctype_mapping_update_port,
16067                 (void *)&cmd_pctype_mapping_update_config,
16068                 (void *)&cmd_pctype_mapping_update_port_id,
16069                 (void *)&cmd_pctype_mapping_update_pctype,
16070                 (void *)&cmd_pctype_mapping_update_mapping,
16071                 (void *)&cmd_pctype_mapping_update_update,
16072                 (void *)&cmd_pctype_mapping_update_pc_type,
16073                 (void *)&cmd_pctype_mapping_update_flow_type,
16074                 NULL,
16075         },
16076 };
16077
16078 /* ptype mapping get */
16079
16080 /* Common result structure for ptype mapping get */
16081 struct cmd_ptype_mapping_get_result {
16082         cmdline_fixed_string_t ptype;
16083         cmdline_fixed_string_t mapping;
16084         cmdline_fixed_string_t get;
16085         portid_t port_id;
16086         uint8_t valid_only;
16087 };
16088
16089 /* Common CLI fields for ptype mapping get */
16090 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16091         TOKEN_STRING_INITIALIZER
16092                 (struct cmd_ptype_mapping_get_result,
16093                  ptype, "ptype");
16094 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16095         TOKEN_STRING_INITIALIZER
16096                 (struct cmd_ptype_mapping_get_result,
16097                  mapping, "mapping");
16098 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16099         TOKEN_STRING_INITIALIZER
16100                 (struct cmd_ptype_mapping_get_result,
16101                  get, "get");
16102 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16103         TOKEN_NUM_INITIALIZER
16104                 (struct cmd_ptype_mapping_get_result,
16105                  port_id, UINT16);
16106 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16107         TOKEN_NUM_INITIALIZER
16108                 (struct cmd_ptype_mapping_get_result,
16109                  valid_only, UINT8);
16110
16111 static void
16112 cmd_ptype_mapping_get_parsed(
16113         void *parsed_result,
16114         __attribute__((unused)) struct cmdline *cl,
16115         __attribute__((unused)) void *data)
16116 {
16117         struct cmd_ptype_mapping_get_result *res = parsed_result;
16118         int ret = -ENOTSUP;
16119 #ifdef RTE_LIBRTE_I40E_PMD
16120         int max_ptype_num = 256;
16121         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16122         uint16_t count;
16123         int i;
16124 #endif
16125
16126         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16127                 return;
16128
16129 #ifdef RTE_LIBRTE_I40E_PMD
16130         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16131                                         mapping,
16132                                         max_ptype_num,
16133                                         &count,
16134                                         res->valid_only);
16135 #endif
16136
16137         switch (ret) {
16138         case 0:
16139                 break;
16140         case -ENODEV:
16141                 printf("invalid port_id %d\n", res->port_id);
16142                 break;
16143         case -ENOTSUP:
16144                 printf("function not implemented\n");
16145                 break;
16146         default:
16147                 printf("programming error: (%s)\n", strerror(-ret));
16148         }
16149
16150 #ifdef RTE_LIBRTE_I40E_PMD
16151         if (!ret) {
16152                 for (i = 0; i < count; i++)
16153                         printf("%3d\t0x%08x\n",
16154                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16155         }
16156 #endif
16157 }
16158
16159 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16160         .f = cmd_ptype_mapping_get_parsed,
16161         .data = NULL,
16162         .help_str = "ptype mapping get <port_id> <valid_only>",
16163         .tokens = {
16164                 (void *)&cmd_ptype_mapping_get_ptype,
16165                 (void *)&cmd_ptype_mapping_get_mapping,
16166                 (void *)&cmd_ptype_mapping_get_get,
16167                 (void *)&cmd_ptype_mapping_get_port_id,
16168                 (void *)&cmd_ptype_mapping_get_valid_only,
16169                 NULL,
16170         },
16171 };
16172
16173 /* ptype mapping replace */
16174
16175 /* Common result structure for ptype mapping replace */
16176 struct cmd_ptype_mapping_replace_result {
16177         cmdline_fixed_string_t ptype;
16178         cmdline_fixed_string_t mapping;
16179         cmdline_fixed_string_t replace;
16180         portid_t port_id;
16181         uint32_t target;
16182         uint8_t mask;
16183         uint32_t pkt_type;
16184 };
16185
16186 /* Common CLI fields for ptype mapping replace */
16187 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16188         TOKEN_STRING_INITIALIZER
16189                 (struct cmd_ptype_mapping_replace_result,
16190                  ptype, "ptype");
16191 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16192         TOKEN_STRING_INITIALIZER
16193                 (struct cmd_ptype_mapping_replace_result,
16194                  mapping, "mapping");
16195 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16196         TOKEN_STRING_INITIALIZER
16197                 (struct cmd_ptype_mapping_replace_result,
16198                  replace, "replace");
16199 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16200         TOKEN_NUM_INITIALIZER
16201                 (struct cmd_ptype_mapping_replace_result,
16202                  port_id, UINT16);
16203 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16204         TOKEN_NUM_INITIALIZER
16205                 (struct cmd_ptype_mapping_replace_result,
16206                  target, UINT32);
16207 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16208         TOKEN_NUM_INITIALIZER
16209                 (struct cmd_ptype_mapping_replace_result,
16210                  mask, UINT8);
16211 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16212         TOKEN_NUM_INITIALIZER
16213                 (struct cmd_ptype_mapping_replace_result,
16214                  pkt_type, UINT32);
16215
16216 static void
16217 cmd_ptype_mapping_replace_parsed(
16218         void *parsed_result,
16219         __attribute__((unused)) struct cmdline *cl,
16220         __attribute__((unused)) void *data)
16221 {
16222         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16223         int ret = -ENOTSUP;
16224
16225         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16226                 return;
16227
16228 #ifdef RTE_LIBRTE_I40E_PMD
16229         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16230                                         res->target,
16231                                         res->mask,
16232                                         res->pkt_type);
16233 #endif
16234
16235         switch (ret) {
16236         case 0:
16237                 break;
16238         case -EINVAL:
16239                 printf("invalid ptype 0x%8x or 0x%8x\n",
16240                                 res->target, res->pkt_type);
16241                 break;
16242         case -ENODEV:
16243                 printf("invalid port_id %d\n", res->port_id);
16244                 break;
16245         case -ENOTSUP:
16246                 printf("function not implemented\n");
16247                 break;
16248         default:
16249                 printf("programming error: (%s)\n", strerror(-ret));
16250         }
16251 }
16252
16253 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16254         .f = cmd_ptype_mapping_replace_parsed,
16255         .data = NULL,
16256         .help_str =
16257                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16258         .tokens = {
16259                 (void *)&cmd_ptype_mapping_replace_ptype,
16260                 (void *)&cmd_ptype_mapping_replace_mapping,
16261                 (void *)&cmd_ptype_mapping_replace_replace,
16262                 (void *)&cmd_ptype_mapping_replace_port_id,
16263                 (void *)&cmd_ptype_mapping_replace_target,
16264                 (void *)&cmd_ptype_mapping_replace_mask,
16265                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16266                 NULL,
16267         },
16268 };
16269
16270 /* ptype mapping reset */
16271
16272 /* Common result structure for ptype mapping reset */
16273 struct cmd_ptype_mapping_reset_result {
16274         cmdline_fixed_string_t ptype;
16275         cmdline_fixed_string_t mapping;
16276         cmdline_fixed_string_t reset;
16277         portid_t port_id;
16278 };
16279
16280 /* Common CLI fields for ptype mapping reset*/
16281 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16282         TOKEN_STRING_INITIALIZER
16283                 (struct cmd_ptype_mapping_reset_result,
16284                  ptype, "ptype");
16285 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16286         TOKEN_STRING_INITIALIZER
16287                 (struct cmd_ptype_mapping_reset_result,
16288                  mapping, "mapping");
16289 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16290         TOKEN_STRING_INITIALIZER
16291                 (struct cmd_ptype_mapping_reset_result,
16292                  reset, "reset");
16293 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16294         TOKEN_NUM_INITIALIZER
16295                 (struct cmd_ptype_mapping_reset_result,
16296                  port_id, UINT16);
16297
16298 static void
16299 cmd_ptype_mapping_reset_parsed(
16300         void *parsed_result,
16301         __attribute__((unused)) struct cmdline *cl,
16302         __attribute__((unused)) void *data)
16303 {
16304         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16305         int ret = -ENOTSUP;
16306
16307         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16308                 return;
16309
16310 #ifdef RTE_LIBRTE_I40E_PMD
16311         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16312 #endif
16313
16314         switch (ret) {
16315         case 0:
16316                 break;
16317         case -ENODEV:
16318                 printf("invalid port_id %d\n", res->port_id);
16319                 break;
16320         case -ENOTSUP:
16321                 printf("function not implemented\n");
16322                 break;
16323         default:
16324                 printf("programming error: (%s)\n", strerror(-ret));
16325         }
16326 }
16327
16328 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16329         .f = cmd_ptype_mapping_reset_parsed,
16330         .data = NULL,
16331         .help_str = "ptype mapping reset <port_id>",
16332         .tokens = {
16333                 (void *)&cmd_ptype_mapping_reset_ptype,
16334                 (void *)&cmd_ptype_mapping_reset_mapping,
16335                 (void *)&cmd_ptype_mapping_reset_reset,
16336                 (void *)&cmd_ptype_mapping_reset_port_id,
16337                 NULL,
16338         },
16339 };
16340
16341 /* ptype mapping update */
16342
16343 /* Common result structure for ptype mapping update */
16344 struct cmd_ptype_mapping_update_result {
16345         cmdline_fixed_string_t ptype;
16346         cmdline_fixed_string_t mapping;
16347         cmdline_fixed_string_t reset;
16348         portid_t port_id;
16349         uint8_t hw_ptype;
16350         uint32_t sw_ptype;
16351 };
16352
16353 /* Common CLI fields for ptype mapping update*/
16354 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16355         TOKEN_STRING_INITIALIZER
16356                 (struct cmd_ptype_mapping_update_result,
16357                  ptype, "ptype");
16358 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16359         TOKEN_STRING_INITIALIZER
16360                 (struct cmd_ptype_mapping_update_result,
16361                  mapping, "mapping");
16362 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16363         TOKEN_STRING_INITIALIZER
16364                 (struct cmd_ptype_mapping_update_result,
16365                  reset, "update");
16366 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16367         TOKEN_NUM_INITIALIZER
16368                 (struct cmd_ptype_mapping_update_result,
16369                  port_id, UINT16);
16370 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16371         TOKEN_NUM_INITIALIZER
16372                 (struct cmd_ptype_mapping_update_result,
16373                  hw_ptype, UINT8);
16374 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16375         TOKEN_NUM_INITIALIZER
16376                 (struct cmd_ptype_mapping_update_result,
16377                  sw_ptype, UINT32);
16378
16379 static void
16380 cmd_ptype_mapping_update_parsed(
16381         void *parsed_result,
16382         __attribute__((unused)) struct cmdline *cl,
16383         __attribute__((unused)) void *data)
16384 {
16385         struct cmd_ptype_mapping_update_result *res = parsed_result;
16386         int ret = -ENOTSUP;
16387 #ifdef RTE_LIBRTE_I40E_PMD
16388         struct rte_pmd_i40e_ptype_mapping mapping;
16389 #endif
16390         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16391                 return;
16392
16393 #ifdef RTE_LIBRTE_I40E_PMD
16394         mapping.hw_ptype = res->hw_ptype;
16395         mapping.sw_ptype = res->sw_ptype;
16396         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16397                                                 &mapping,
16398                                                 1,
16399                                                 0);
16400 #endif
16401
16402         switch (ret) {
16403         case 0:
16404                 break;
16405         case -EINVAL:
16406                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16407                 break;
16408         case -ENODEV:
16409                 printf("invalid port_id %d\n", res->port_id);
16410                 break;
16411         case -ENOTSUP:
16412                 printf("function not implemented\n");
16413                 break;
16414         default:
16415                 printf("programming error: (%s)\n", strerror(-ret));
16416         }
16417 }
16418
16419 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16420         .f = cmd_ptype_mapping_update_parsed,
16421         .data = NULL,
16422         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16423         .tokens = {
16424                 (void *)&cmd_ptype_mapping_update_ptype,
16425                 (void *)&cmd_ptype_mapping_update_mapping,
16426                 (void *)&cmd_ptype_mapping_update_update,
16427                 (void *)&cmd_ptype_mapping_update_port_id,
16428                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16429                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16430                 NULL,
16431         },
16432 };
16433
16434 /* Common result structure for file commands */
16435 struct cmd_cmdfile_result {
16436         cmdline_fixed_string_t load;
16437         cmdline_fixed_string_t filename;
16438 };
16439
16440 /* Common CLI fields for file commands */
16441 cmdline_parse_token_string_t cmd_load_cmdfile =
16442         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16443 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16444         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16445
16446 static void
16447 cmd_load_from_file_parsed(
16448         void *parsed_result,
16449         __attribute__((unused)) struct cmdline *cl,
16450         __attribute__((unused)) void *data)
16451 {
16452         struct cmd_cmdfile_result *res = parsed_result;
16453
16454         cmdline_read_from_file(res->filename);
16455 }
16456
16457 cmdline_parse_inst_t cmd_load_from_file = {
16458         .f = cmd_load_from_file_parsed,
16459         .data = NULL,
16460         .help_str = "load <filename>",
16461         .tokens = {
16462                 (void *)&cmd_load_cmdfile,
16463                 (void *)&cmd_load_cmdfile_filename,
16464                 NULL,
16465         },
16466 };
16467
16468 /* Get Rx offloads capabilities */
16469 struct cmd_rx_offload_get_capa_result {
16470         cmdline_fixed_string_t show;
16471         cmdline_fixed_string_t port;
16472         portid_t port_id;
16473         cmdline_fixed_string_t rx_offload;
16474         cmdline_fixed_string_t capabilities;
16475 };
16476
16477 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16478         TOKEN_STRING_INITIALIZER
16479                 (struct cmd_rx_offload_get_capa_result,
16480                  show, "show");
16481 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16482         TOKEN_STRING_INITIALIZER
16483                 (struct cmd_rx_offload_get_capa_result,
16484                  port, "port");
16485 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16486         TOKEN_NUM_INITIALIZER
16487                 (struct cmd_rx_offload_get_capa_result,
16488                  port_id, UINT16);
16489 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16490         TOKEN_STRING_INITIALIZER
16491                 (struct cmd_rx_offload_get_capa_result,
16492                  rx_offload, "rx_offload");
16493 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16494         TOKEN_STRING_INITIALIZER
16495                 (struct cmd_rx_offload_get_capa_result,
16496                  capabilities, "capabilities");
16497
16498 static void
16499 print_rx_offloads(uint64_t offloads)
16500 {
16501         uint64_t single_offload;
16502         int begin;
16503         int end;
16504         int bit;
16505
16506         if (offloads == 0)
16507                 return;
16508
16509         begin = __builtin_ctzll(offloads);
16510         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16511
16512         single_offload = 1 << begin;
16513         for (bit = begin; bit < end; bit++) {
16514                 if (offloads & single_offload)
16515                         printf(" %s",
16516                                rte_eth_dev_rx_offload_name(single_offload));
16517                 single_offload <<= 1;
16518         }
16519 }
16520
16521 static void
16522 cmd_rx_offload_get_capa_parsed(
16523         void *parsed_result,
16524         __attribute__((unused)) struct cmdline *cl,
16525         __attribute__((unused)) void *data)
16526 {
16527         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16528         struct rte_eth_dev_info dev_info;
16529         portid_t port_id = res->port_id;
16530         uint64_t queue_offloads;
16531         uint64_t port_offloads;
16532
16533         rte_eth_dev_info_get(port_id, &dev_info);
16534         queue_offloads = dev_info.rx_queue_offload_capa;
16535         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16536
16537         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16538         printf("  Per Queue :");
16539         print_rx_offloads(queue_offloads);
16540
16541         printf("\n");
16542         printf("  Per Port  :");
16543         print_rx_offloads(port_offloads);
16544         printf("\n\n");
16545 }
16546
16547 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16548         .f = cmd_rx_offload_get_capa_parsed,
16549         .data = NULL,
16550         .help_str = "show port <port_id> rx_offload capabilities",
16551         .tokens = {
16552                 (void *)&cmd_rx_offload_get_capa_show,
16553                 (void *)&cmd_rx_offload_get_capa_port,
16554                 (void *)&cmd_rx_offload_get_capa_port_id,
16555                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16556                 (void *)&cmd_rx_offload_get_capa_capabilities,
16557                 NULL,
16558         }
16559 };
16560
16561 /* Get Rx offloads configuration */
16562 struct cmd_rx_offload_get_configuration_result {
16563         cmdline_fixed_string_t show;
16564         cmdline_fixed_string_t port;
16565         portid_t port_id;
16566         cmdline_fixed_string_t rx_offload;
16567         cmdline_fixed_string_t configuration;
16568 };
16569
16570 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16571         TOKEN_STRING_INITIALIZER
16572                 (struct cmd_rx_offload_get_configuration_result,
16573                  show, "show");
16574 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16575         TOKEN_STRING_INITIALIZER
16576                 (struct cmd_rx_offload_get_configuration_result,
16577                  port, "port");
16578 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16579         TOKEN_NUM_INITIALIZER
16580                 (struct cmd_rx_offload_get_configuration_result,
16581                  port_id, UINT16);
16582 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16583         TOKEN_STRING_INITIALIZER
16584                 (struct cmd_rx_offload_get_configuration_result,
16585                  rx_offload, "rx_offload");
16586 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16587         TOKEN_STRING_INITIALIZER
16588                 (struct cmd_rx_offload_get_configuration_result,
16589                  configuration, "configuration");
16590
16591 static void
16592 cmd_rx_offload_get_configuration_parsed(
16593         void *parsed_result,
16594         __attribute__((unused)) struct cmdline *cl,
16595         __attribute__((unused)) void *data)
16596 {
16597         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16598         struct rte_eth_dev_info dev_info;
16599         portid_t port_id = res->port_id;
16600         struct rte_port *port = &ports[port_id];
16601         uint64_t port_offloads;
16602         uint64_t queue_offloads;
16603         uint16_t nb_rx_queues;
16604         int q;
16605
16606         printf("Rx Offloading Configuration of port %d :\n", port_id);
16607
16608         port_offloads = port->dev_conf.rxmode.offloads;
16609         printf("  Port :");
16610         print_rx_offloads(port_offloads);
16611         printf("\n");
16612
16613         rte_eth_dev_info_get(port_id, &dev_info);
16614         nb_rx_queues = dev_info.nb_rx_queues;
16615         for (q = 0; q < nb_rx_queues; q++) {
16616                 queue_offloads = port->rx_conf[q].offloads;
16617                 printf("  Queue[%2d] :", q);
16618                 print_rx_offloads(queue_offloads);
16619                 printf("\n");
16620         }
16621         printf("\n");
16622 }
16623
16624 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16625         .f = cmd_rx_offload_get_configuration_parsed,
16626         .data = NULL,
16627         .help_str = "show port <port_id> rx_offload configuration",
16628         .tokens = {
16629                 (void *)&cmd_rx_offload_get_configuration_show,
16630                 (void *)&cmd_rx_offload_get_configuration_port,
16631                 (void *)&cmd_rx_offload_get_configuration_port_id,
16632                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16633                 (void *)&cmd_rx_offload_get_configuration_configuration,
16634                 NULL,
16635         }
16636 };
16637
16638 /* Enable/Disable a per port offloading */
16639 struct cmd_config_per_port_rx_offload_result {
16640         cmdline_fixed_string_t port;
16641         cmdline_fixed_string_t config;
16642         portid_t port_id;
16643         cmdline_fixed_string_t rx_offload;
16644         cmdline_fixed_string_t offload;
16645         cmdline_fixed_string_t on_off;
16646 };
16647
16648 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16649         TOKEN_STRING_INITIALIZER
16650                 (struct cmd_config_per_port_rx_offload_result,
16651                  port, "port");
16652 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16653         TOKEN_STRING_INITIALIZER
16654                 (struct cmd_config_per_port_rx_offload_result,
16655                  config, "config");
16656 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16657         TOKEN_NUM_INITIALIZER
16658                 (struct cmd_config_per_port_rx_offload_result,
16659                  port_id, UINT16);
16660 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16661         TOKEN_STRING_INITIALIZER
16662                 (struct cmd_config_per_port_rx_offload_result,
16663                  rx_offload, "rx_offload");
16664 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16665         TOKEN_STRING_INITIALIZER
16666                 (struct cmd_config_per_port_rx_offload_result,
16667                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16668                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16669                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16670                            "crc_strip#scatter#timestamp#security");
16671 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16672         TOKEN_STRING_INITIALIZER
16673                 (struct cmd_config_per_port_rx_offload_result,
16674                  on_off, "on#off");
16675
16676 static uint64_t
16677 search_rx_offload(const char *name)
16678 {
16679         uint64_t single_offload;
16680         const char *single_name;
16681         int found = 0;
16682         unsigned int bit;
16683
16684         single_offload = 1;
16685         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16686                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16687                 if (!strcasecmp(single_name, name)) {
16688                         found = 1;
16689                         break;
16690                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16691                         break;
16692                 else if (single_name == NULL)
16693                         break;
16694                 single_offload <<= 1;
16695         }
16696
16697         if (found)
16698                 return single_offload;
16699
16700         return 0;
16701 }
16702
16703 static void
16704 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16705                                 __attribute__((unused)) struct cmdline *cl,
16706                                 __attribute__((unused)) void *data)
16707 {
16708         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16709         portid_t port_id = res->port_id;
16710         struct rte_eth_dev_info dev_info;
16711         struct rte_port *port = &ports[port_id];
16712         uint64_t single_offload;
16713         uint16_t nb_rx_queues;
16714         int q;
16715
16716         if (port->port_status != RTE_PORT_STOPPED) {
16717                 printf("Error: Can't config offload when Port %d "
16718                        "is not stopped\n", port_id);
16719                 return;
16720         }
16721
16722         single_offload = search_rx_offload(res->offload);
16723         if (single_offload == 0) {
16724                 printf("Unknown offload name: %s\n", res->offload);
16725                 return;
16726         }
16727
16728         rte_eth_dev_info_get(port_id, &dev_info);
16729         nb_rx_queues = dev_info.nb_rx_queues;
16730         if (!strcmp(res->on_off, "on")) {
16731                 port->dev_conf.rxmode.offloads |= single_offload;
16732                 for (q = 0; q < nb_rx_queues; q++)
16733                         port->rx_conf[q].offloads |= single_offload;
16734         } else {
16735                 port->dev_conf.rxmode.offloads &= ~single_offload;
16736                 for (q = 0; q < nb_rx_queues; q++)
16737                         port->rx_conf[q].offloads &= ~single_offload;
16738         }
16739
16740         cmd_reconfig_device_queue(port_id, 1, 1);
16741 }
16742
16743 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16744         .f = cmd_config_per_port_rx_offload_parsed,
16745         .data = NULL,
16746         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16747                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16748                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16749                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16750                     "on|off",
16751         .tokens = {
16752                 (void *)&cmd_config_per_port_rx_offload_result_port,
16753                 (void *)&cmd_config_per_port_rx_offload_result_config,
16754                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16755                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16756                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16757                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16758                 NULL,
16759         }
16760 };
16761
16762 /* Enable/Disable a per queue offloading */
16763 struct cmd_config_per_queue_rx_offload_result {
16764         cmdline_fixed_string_t port;
16765         portid_t port_id;
16766         cmdline_fixed_string_t rxq;
16767         uint16_t queue_id;
16768         cmdline_fixed_string_t rx_offload;
16769         cmdline_fixed_string_t offload;
16770         cmdline_fixed_string_t on_off;
16771 };
16772
16773 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16774         TOKEN_STRING_INITIALIZER
16775                 (struct cmd_config_per_queue_rx_offload_result,
16776                  port, "port");
16777 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16778         TOKEN_NUM_INITIALIZER
16779                 (struct cmd_config_per_queue_rx_offload_result,
16780                  port_id, UINT16);
16781 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16782         TOKEN_STRING_INITIALIZER
16783                 (struct cmd_config_per_queue_rx_offload_result,
16784                  rxq, "rxq");
16785 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16786         TOKEN_NUM_INITIALIZER
16787                 (struct cmd_config_per_queue_rx_offload_result,
16788                  queue_id, UINT16);
16789 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16790         TOKEN_STRING_INITIALIZER
16791                 (struct cmd_config_per_queue_rx_offload_result,
16792                  rx_offload, "rx_offload");
16793 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16794         TOKEN_STRING_INITIALIZER
16795                 (struct cmd_config_per_queue_rx_offload_result,
16796                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16797                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16798                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16799                            "crc_strip#scatter#timestamp#security");
16800 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16801         TOKEN_STRING_INITIALIZER
16802                 (struct cmd_config_per_queue_rx_offload_result,
16803                  on_off, "on#off");
16804
16805 static void
16806 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16807                                 __attribute__((unused)) struct cmdline *cl,
16808                                 __attribute__((unused)) void *data)
16809 {
16810         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16811         struct rte_eth_dev_info dev_info;
16812         portid_t port_id = res->port_id;
16813         uint16_t queue_id = res->queue_id;
16814         struct rte_port *port = &ports[port_id];
16815         uint64_t single_offload;
16816
16817         if (port->port_status != RTE_PORT_STOPPED) {
16818                 printf("Error: Can't config offload when Port %d "
16819                        "is not stopped\n", port_id);
16820                 return;
16821         }
16822
16823         rte_eth_dev_info_get(port_id, &dev_info);
16824         if (queue_id >= dev_info.nb_rx_queues) {
16825                 printf("Error: input queue_id should be 0 ... "
16826                        "%d\n", dev_info.nb_rx_queues - 1);
16827                 return;
16828         }
16829
16830         single_offload = search_rx_offload(res->offload);
16831         if (single_offload == 0) {
16832                 printf("Unknown offload name: %s\n", res->offload);
16833                 return;
16834         }
16835
16836         if (!strcmp(res->on_off, "on"))
16837                 port->rx_conf[queue_id].offloads |= single_offload;
16838         else
16839                 port->rx_conf[queue_id].offloads &= ~single_offload;
16840
16841         cmd_reconfig_device_queue(port_id, 1, 1);
16842 }
16843
16844 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16845         .f = cmd_config_per_queue_rx_offload_parsed,
16846         .data = NULL,
16847         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16848                     "vlan_strip|ipv4_cksum|"
16849                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16850                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16851                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16852                     "on|off",
16853         .tokens = {
16854                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16855                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16856                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16857                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16858                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16859                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16860                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16861                 NULL,
16862         }
16863 };
16864
16865 /* Get Tx offloads capabilities */
16866 struct cmd_tx_offload_get_capa_result {
16867         cmdline_fixed_string_t show;
16868         cmdline_fixed_string_t port;
16869         portid_t port_id;
16870         cmdline_fixed_string_t tx_offload;
16871         cmdline_fixed_string_t capabilities;
16872 };
16873
16874 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16875         TOKEN_STRING_INITIALIZER
16876                 (struct cmd_tx_offload_get_capa_result,
16877                  show, "show");
16878 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16879         TOKEN_STRING_INITIALIZER
16880                 (struct cmd_tx_offload_get_capa_result,
16881                  port, "port");
16882 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16883         TOKEN_NUM_INITIALIZER
16884                 (struct cmd_tx_offload_get_capa_result,
16885                  port_id, UINT16);
16886 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16887         TOKEN_STRING_INITIALIZER
16888                 (struct cmd_tx_offload_get_capa_result,
16889                  tx_offload, "tx_offload");
16890 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16891         TOKEN_STRING_INITIALIZER
16892                 (struct cmd_tx_offload_get_capa_result,
16893                  capabilities, "capabilities");
16894
16895 static void
16896 print_tx_offloads(uint64_t offloads)
16897 {
16898         uint64_t single_offload;
16899         int begin;
16900         int end;
16901         int bit;
16902
16903         if (offloads == 0)
16904                 return;
16905
16906         begin = __builtin_ctzll(offloads);
16907         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16908
16909         single_offload = 1 << begin;
16910         for (bit = begin; bit < end; bit++) {
16911                 if (offloads & single_offload)
16912                         printf(" %s",
16913                                rte_eth_dev_tx_offload_name(single_offload));
16914                 single_offload <<= 1;
16915         }
16916 }
16917
16918 static void
16919 cmd_tx_offload_get_capa_parsed(
16920         void *parsed_result,
16921         __attribute__((unused)) struct cmdline *cl,
16922         __attribute__((unused)) void *data)
16923 {
16924         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16925         struct rte_eth_dev_info dev_info;
16926         portid_t port_id = res->port_id;
16927         uint64_t queue_offloads;
16928         uint64_t port_offloads;
16929
16930         rte_eth_dev_info_get(port_id, &dev_info);
16931         queue_offloads = dev_info.tx_queue_offload_capa;
16932         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16933
16934         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16935         printf("  Per Queue :");
16936         print_tx_offloads(queue_offloads);
16937
16938         printf("\n");
16939         printf("  Per Port  :");
16940         print_tx_offloads(port_offloads);
16941         printf("\n\n");
16942 }
16943
16944 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16945         .f = cmd_tx_offload_get_capa_parsed,
16946         .data = NULL,
16947         .help_str = "show port <port_id> tx_offload capabilities",
16948         .tokens = {
16949                 (void *)&cmd_tx_offload_get_capa_show,
16950                 (void *)&cmd_tx_offload_get_capa_port,
16951                 (void *)&cmd_tx_offload_get_capa_port_id,
16952                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16953                 (void *)&cmd_tx_offload_get_capa_capabilities,
16954                 NULL,
16955         }
16956 };
16957
16958 /* Get Tx offloads configuration */
16959 struct cmd_tx_offload_get_configuration_result {
16960         cmdline_fixed_string_t show;
16961         cmdline_fixed_string_t port;
16962         portid_t port_id;
16963         cmdline_fixed_string_t tx_offload;
16964         cmdline_fixed_string_t configuration;
16965 };
16966
16967 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16968         TOKEN_STRING_INITIALIZER
16969                 (struct cmd_tx_offload_get_configuration_result,
16970                  show, "show");
16971 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16972         TOKEN_STRING_INITIALIZER
16973                 (struct cmd_tx_offload_get_configuration_result,
16974                  port, "port");
16975 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16976         TOKEN_NUM_INITIALIZER
16977                 (struct cmd_tx_offload_get_configuration_result,
16978                  port_id, UINT16);
16979 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16980         TOKEN_STRING_INITIALIZER
16981                 (struct cmd_tx_offload_get_configuration_result,
16982                  tx_offload, "tx_offload");
16983 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16984         TOKEN_STRING_INITIALIZER
16985                 (struct cmd_tx_offload_get_configuration_result,
16986                  configuration, "configuration");
16987
16988 static void
16989 cmd_tx_offload_get_configuration_parsed(
16990         void *parsed_result,
16991         __attribute__((unused)) struct cmdline *cl,
16992         __attribute__((unused)) void *data)
16993 {
16994         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16995         struct rte_eth_dev_info dev_info;
16996         portid_t port_id = res->port_id;
16997         struct rte_port *port = &ports[port_id];
16998         uint64_t port_offloads;
16999         uint64_t queue_offloads;
17000         uint16_t nb_tx_queues;
17001         int q;
17002
17003         printf("Tx Offloading Configuration of port %d :\n", port_id);
17004
17005         port_offloads = port->dev_conf.txmode.offloads;
17006         printf("  Port :");
17007         print_tx_offloads(port_offloads);
17008         printf("\n");
17009
17010         rte_eth_dev_info_get(port_id, &dev_info);
17011         nb_tx_queues = dev_info.nb_tx_queues;
17012         for (q = 0; q < nb_tx_queues; q++) {
17013                 queue_offloads = port->tx_conf[q].offloads;
17014                 printf("  Queue[%2d] :", q);
17015                 print_tx_offloads(queue_offloads);
17016                 printf("\n");
17017         }
17018         printf("\n");
17019 }
17020
17021 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17022         .f = cmd_tx_offload_get_configuration_parsed,
17023         .data = NULL,
17024         .help_str = "show port <port_id> tx_offload configuration",
17025         .tokens = {
17026                 (void *)&cmd_tx_offload_get_configuration_show,
17027                 (void *)&cmd_tx_offload_get_configuration_port,
17028                 (void *)&cmd_tx_offload_get_configuration_port_id,
17029                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17030                 (void *)&cmd_tx_offload_get_configuration_configuration,
17031                 NULL,
17032         }
17033 };
17034
17035 /* Enable/Disable a per port offloading */
17036 struct cmd_config_per_port_tx_offload_result {
17037         cmdline_fixed_string_t port;
17038         cmdline_fixed_string_t config;
17039         portid_t port_id;
17040         cmdline_fixed_string_t tx_offload;
17041         cmdline_fixed_string_t offload;
17042         cmdline_fixed_string_t on_off;
17043 };
17044
17045 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17046         TOKEN_STRING_INITIALIZER
17047                 (struct cmd_config_per_port_tx_offload_result,
17048                  port, "port");
17049 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17050         TOKEN_STRING_INITIALIZER
17051                 (struct cmd_config_per_port_tx_offload_result,
17052                  config, "config");
17053 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17054         TOKEN_NUM_INITIALIZER
17055                 (struct cmd_config_per_port_tx_offload_result,
17056                  port_id, UINT16);
17057 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17058         TOKEN_STRING_INITIALIZER
17059                 (struct cmd_config_per_port_tx_offload_result,
17060                  tx_offload, "tx_offload");
17061 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17062         TOKEN_STRING_INITIALIZER
17063                 (struct cmd_config_per_port_tx_offload_result,
17064                  offload, "vlan_insert#ipv4_cksum#udp_cksum#udp_cksum#"
17065                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17066                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17067                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17068                           "mt_lockfree#multi_segs#fast_free#security");
17069 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17070         TOKEN_STRING_INITIALIZER
17071                 (struct cmd_config_per_port_tx_offload_result,
17072                  on_off, "on#off");
17073
17074 static uint64_t
17075 search_tx_offload(const char *name)
17076 {
17077         uint64_t single_offload;
17078         const char *single_name;
17079         int found = 0;
17080         unsigned int bit;
17081
17082         single_offload = 1;
17083         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17084                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17085                 if (!strcasecmp(single_name, name)) {
17086                         found = 1;
17087                         break;
17088                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17089                         break;
17090                 else if (single_name == NULL)
17091                         break;
17092                 single_offload <<= 1;
17093         }
17094
17095         if (found)
17096                 return single_offload;
17097
17098         return 0;
17099 }
17100
17101 static void
17102 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17103                                 __attribute__((unused)) struct cmdline *cl,
17104                                 __attribute__((unused)) void *data)
17105 {
17106         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17107         portid_t port_id = res->port_id;
17108         struct rte_eth_dev_info dev_info;
17109         struct rte_port *port = &ports[port_id];
17110         uint64_t single_offload;
17111         uint16_t nb_tx_queues;
17112         int q;
17113
17114         if (port->port_status != RTE_PORT_STOPPED) {
17115                 printf("Error: Can't config offload when Port %d "
17116                        "is not stopped\n", port_id);
17117                 return;
17118         }
17119
17120         single_offload = search_tx_offload(res->offload);
17121         if (single_offload == 0) {
17122                 printf("Unknown offload name: %s\n", res->offload);
17123                 return;
17124         }
17125
17126         rte_eth_dev_info_get(port_id, &dev_info);
17127         nb_tx_queues = dev_info.nb_tx_queues;
17128         if (!strcmp(res->on_off, "on")) {
17129                 port->dev_conf.txmode.offloads |= single_offload;
17130                 for (q = 0; q < nb_tx_queues; q++)
17131                         port->tx_conf[q].offloads |= single_offload;
17132         } else {
17133                 port->dev_conf.txmode.offloads &= ~single_offload;
17134                 for (q = 0; q < nb_tx_queues; q++)
17135                         port->tx_conf[q].offloads &= ~single_offload;
17136         }
17137
17138         cmd_reconfig_device_queue(port_id, 1, 1);
17139 }
17140
17141 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17142         .f = cmd_config_per_port_tx_offload_parsed,
17143         .data = NULL,
17144         .help_str = "port config <port_id> tx_offload "
17145                     "vlan_insert|ipv4_cksum|udp_cksum|udp_cksum|"
17146                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17147                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17148                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17149                     "mt_lockfree|multi_segs|fast_free|security "
17150                     "on|off",
17151         .tokens = {
17152                 (void *)&cmd_config_per_port_tx_offload_result_port,
17153                 (void *)&cmd_config_per_port_tx_offload_result_config,
17154                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17155                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17156                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17157                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17158                 NULL,
17159         }
17160 };
17161
17162 /* Enable/Disable a per queue offloading */
17163 struct cmd_config_per_queue_tx_offload_result {
17164         cmdline_fixed_string_t port;
17165         portid_t port_id;
17166         cmdline_fixed_string_t txq;
17167         uint16_t queue_id;
17168         cmdline_fixed_string_t tx_offload;
17169         cmdline_fixed_string_t offload;
17170         cmdline_fixed_string_t on_off;
17171 };
17172
17173 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17174         TOKEN_STRING_INITIALIZER
17175                 (struct cmd_config_per_queue_tx_offload_result,
17176                  port, "port");
17177 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17178         TOKEN_NUM_INITIALIZER
17179                 (struct cmd_config_per_queue_tx_offload_result,
17180                  port_id, UINT16);
17181 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17182         TOKEN_STRING_INITIALIZER
17183                 (struct cmd_config_per_queue_tx_offload_result,
17184                  txq, "txq");
17185 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17186         TOKEN_NUM_INITIALIZER
17187                 (struct cmd_config_per_queue_tx_offload_result,
17188                  queue_id, UINT16);
17189 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17190         TOKEN_STRING_INITIALIZER
17191                 (struct cmd_config_per_queue_tx_offload_result,
17192                  tx_offload, "tx_offload");
17193 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17194         TOKEN_STRING_INITIALIZER
17195                 (struct cmd_config_per_queue_tx_offload_result,
17196                  offload, "vlan_insert#ipv4_cksum#udp_cksum#udp_cksum#"
17197                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17198                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17199                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17200                           "mt_lockfree#multi_segs#fast_free#security");
17201 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17202         TOKEN_STRING_INITIALIZER
17203                 (struct cmd_config_per_queue_tx_offload_result,
17204                  on_off, "on#off");
17205
17206 static void
17207 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17208                                 __attribute__((unused)) struct cmdline *cl,
17209                                 __attribute__((unused)) void *data)
17210 {
17211         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17212         struct rte_eth_dev_info dev_info;
17213         portid_t port_id = res->port_id;
17214         uint16_t queue_id = res->queue_id;
17215         struct rte_port *port = &ports[port_id];
17216         uint64_t single_offload;
17217
17218         if (port->port_status != RTE_PORT_STOPPED) {
17219                 printf("Error: Can't config offload when Port %d "
17220                        "is not stopped\n", port_id);
17221                 return;
17222         }
17223
17224         rte_eth_dev_info_get(port_id, &dev_info);
17225         if (queue_id >= dev_info.nb_tx_queues) {
17226                 printf("Error: input queue_id should be 0 ... "
17227                        "%d\n", dev_info.nb_tx_queues - 1);
17228                 return;
17229         }
17230
17231         single_offload = search_tx_offload(res->offload);
17232         if (single_offload == 0) {
17233                 printf("Unknown offload name: %s\n", res->offload);
17234                 return;
17235         }
17236
17237         if (!strcmp(res->on_off, "on"))
17238                 port->tx_conf[queue_id].offloads |= single_offload;
17239         else
17240                 port->tx_conf[queue_id].offloads &= ~single_offload;
17241
17242         cmd_reconfig_device_queue(port_id, 1, 1);
17243 }
17244
17245 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17246         .f = cmd_config_per_queue_tx_offload_parsed,
17247         .data = NULL,
17248         .help_str = "port <port_id> txq <queue_id> tx_offload "
17249                     "vlan_insert|ipv4_cksum|udp_cksum|udp_cksum|"
17250                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17251                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17252                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17253                     "mt_lockfree|multi_segs|fast_free|security "
17254                     "on|off",
17255         .tokens = {
17256                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17257                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17258                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17259                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17260                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17261                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17262                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17263                 NULL,
17264         }
17265 };
17266
17267 /* ******************************************************************************** */
17268
17269 /* list of instructions */
17270 cmdline_parse_ctx_t main_ctx[] = {
17271         (cmdline_parse_inst_t *)&cmd_help_brief,
17272         (cmdline_parse_inst_t *)&cmd_help_long,
17273         (cmdline_parse_inst_t *)&cmd_quit,
17274         (cmdline_parse_inst_t *)&cmd_load_from_file,
17275         (cmdline_parse_inst_t *)&cmd_showport,
17276         (cmdline_parse_inst_t *)&cmd_showqueue,
17277         (cmdline_parse_inst_t *)&cmd_showportall,
17278         (cmdline_parse_inst_t *)&cmd_showcfg,
17279         (cmdline_parse_inst_t *)&cmd_start,
17280         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17281         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17282         (cmdline_parse_inst_t *)&cmd_set_link_up,
17283         (cmdline_parse_inst_t *)&cmd_set_link_down,
17284         (cmdline_parse_inst_t *)&cmd_reset,
17285         (cmdline_parse_inst_t *)&cmd_set_numbers,
17286         (cmdline_parse_inst_t *)&cmd_set_log,
17287         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17288         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17289         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17290         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17291         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17292         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17293         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17294         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17295         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17296         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17297         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17298         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17299         (cmdline_parse_inst_t *)&cmd_set_link_check,
17300         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17301         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17302         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17303         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17304 #ifdef RTE_LIBRTE_PMD_BOND
17305         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17306         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17307         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17308         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17309         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17310         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17311         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17312         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17313         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17314         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17315         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17316 #endif
17317         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17318         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17319         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17320         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17321         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17322         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17323         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17324         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17325         (cmdline_parse_inst_t *)&cmd_csum_set,
17326         (cmdline_parse_inst_t *)&cmd_csum_show,
17327         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17328         (cmdline_parse_inst_t *)&cmd_tso_set,
17329         (cmdline_parse_inst_t *)&cmd_tso_show,
17330         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17331         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17332         (cmdline_parse_inst_t *)&cmd_gro_enable,
17333         (cmdline_parse_inst_t *)&cmd_gro_flush,
17334         (cmdline_parse_inst_t *)&cmd_gro_show,
17335         (cmdline_parse_inst_t *)&cmd_gso_enable,
17336         (cmdline_parse_inst_t *)&cmd_gso_size,
17337         (cmdline_parse_inst_t *)&cmd_gso_show,
17338         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17339         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17340         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17341         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17342         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17343         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17344         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17345         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17346         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17347         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17348         (cmdline_parse_inst_t *)&cmd_config_dcb,
17349         (cmdline_parse_inst_t *)&cmd_read_reg,
17350         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17351         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17352         (cmdline_parse_inst_t *)&cmd_write_reg,
17353         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17354         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17355         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17356         (cmdline_parse_inst_t *)&cmd_stop,
17357         (cmdline_parse_inst_t *)&cmd_mac_addr,
17358         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17359         (cmdline_parse_inst_t *)&cmd_set_qmap,
17360         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17361         (cmdline_parse_inst_t *)&cmd_operate_port,
17362         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17363         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17364         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17365         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17366         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17367         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17368         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17369         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17370         (cmdline_parse_inst_t *)&cmd_config_mtu,
17371         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17372         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17373         (cmdline_parse_inst_t *)&cmd_config_rss,
17374         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17375         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17376         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17377         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17378         (cmdline_parse_inst_t *)&cmd_showport_reta,
17379         (cmdline_parse_inst_t *)&cmd_config_burst,
17380         (cmdline_parse_inst_t *)&cmd_config_thresh,
17381         (cmdline_parse_inst_t *)&cmd_config_threshold,
17382         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17383         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17384         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17385         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17386         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17387         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17388         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17389         (cmdline_parse_inst_t *)&cmd_global_config,
17390         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17391         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17392         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17393         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17394         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17395         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17396         (cmdline_parse_inst_t *)&cmd_dump,
17397         (cmdline_parse_inst_t *)&cmd_dump_one,
17398         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17399         (cmdline_parse_inst_t *)&cmd_syn_filter,
17400         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17401         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17402         (cmdline_parse_inst_t *)&cmd_flex_filter,
17403         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17404         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17405         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17406         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17407         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17408         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17409         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17410         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17411         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17412         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17413         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17414         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17415         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17416         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17417         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17418         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17419         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17420         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17421         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17422         (cmdline_parse_inst_t *)&cmd_flow,
17423         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17424         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17425         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17426         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17427         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17428         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17429         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17430         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17431         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17432         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17433         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17434         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17435         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17436         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17437         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17438         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17439         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17440         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17441         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17442         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17443         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17444         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17445         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17446         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17447         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17448         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17449         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17450         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17451         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17452         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17453         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17454         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17455         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17456         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17457         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17458         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17459         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17460         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17461         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17462         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17463         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17464         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17465         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17466         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17467         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17468         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17469         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17470         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17471         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17472 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17473         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17474 #endif
17475         (cmdline_parse_inst_t *)&cmd_ddp_add,
17476         (cmdline_parse_inst_t *)&cmd_ddp_del,
17477         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17478         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17479         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17480         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17481         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17482         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17483         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17484         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17485         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17486         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17487
17488         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17489         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17490         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17491         (cmdline_parse_inst_t *)&cmd_queue_region,
17492         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17493         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17494         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17495         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17496         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17497         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17498         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17499         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17500         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17501         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17502         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17503         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17504         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17505         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17506         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17507         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17508         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17509         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17510         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17511         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17512         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17513         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17514         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17515         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17516         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17517         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17518         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17519         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17520         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17521         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17522         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17523         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17524 #ifdef RTE_LIBRTE_BPF
17525         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17526         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17527 #endif
17528         NULL,
17529 };
17530
17531 /* read cmdline commands from file */
17532 void
17533 cmdline_read_from_file(const char *filename)
17534 {
17535         struct cmdline *cl;
17536
17537         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17538         if (cl == NULL) {
17539                 printf("Failed to create file based cmdline context: %s\n",
17540                        filename);
17541                 return;
17542         }
17543
17544         cmdline_interact(cl);
17545         cmdline_quit(cl);
17546
17547         cmdline_free(cl);
17548
17549         printf("Read CLI commands from %s\n", filename);
17550 }
17551
17552 /* prompt function, called from main on MASTER lcore */
17553 void
17554 prompt(void)
17555 {
17556         /* initialize non-constant commands */
17557         cmd_set_fwd_mode_init();
17558         cmd_set_fwd_retry_mode_init();
17559
17560         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17561         if (testpmd_cl == NULL)
17562                 return;
17563         cmdline_interact(testpmd_cl);
17564         cmdline_stdin_exit(testpmd_cl);
17565 }
17566
17567 void
17568 prompt_exit(void)
17569 {
17570         if (testpmd_cl != NULL)
17571                 cmdline_quit(testpmd_cl);
17572 }
17573
17574 static void
17575 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17576 {
17577         if (id == (portid_t)RTE_PORT_ALL) {
17578                 portid_t pid;
17579
17580                 RTE_ETH_FOREACH_DEV(pid) {
17581                         /* check if need_reconfig has been set to 1 */
17582                         if (ports[pid].need_reconfig == 0)
17583                                 ports[pid].need_reconfig = dev;
17584                         /* check if need_reconfig_queues has been set to 1 */
17585                         if (ports[pid].need_reconfig_queues == 0)
17586                                 ports[pid].need_reconfig_queues = queue;
17587                 }
17588         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17589                 /* check if need_reconfig has been set to 1 */
17590                 if (ports[id].need_reconfig == 0)
17591                         ports[id].need_reconfig = dev;
17592                 /* check if need_reconfig_queues has been set to 1 */
17593                 if (ports[id].need_reconfig_queues == 0)
17594                         ports[id].need_reconfig_queues = queue;
17595         }
17596 }