929d19af45ea959274e8d6b116dc172d49ec443b
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <termios.h>
42 #include <unistd.h>
43 #include <inttypes.h>
44 #ifndef __linux__
45 #ifndef __FreeBSD__
46 #include <net/socket.h>
47 #else
48 #include <sys/socket.h>
49 #endif
50 #endif
51 #include <netinet/in.h>
52
53 #include <sys/queue.h>
54
55 #include <rte_common.h>
56 #include <rte_byteorder.h>
57 #include <rte_log.h>
58 #include <rte_debug.h>
59 #include <rte_cycles.h>
60 #include <rte_memory.h>
61 #include <rte_memzone.h>
62 #include <rte_malloc.h>
63 #include <rte_launch.h>
64 #include <rte_eal.h>
65 #include <rte_per_lcore.h>
66 #include <rte_lcore.h>
67 #include <rte_atomic.h>
68 #include <rte_branch_prediction.h>
69 #include <rte_ring.h>
70 #include <rte_mempool.h>
71 #include <rte_interrupts.h>
72 #include <rte_pci.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
76 #include <rte_devargs.h>
77 #include <rte_eth_ctrl.h>
78
79 #include <cmdline_rdline.h>
80 #include <cmdline_parse.h>
81 #include <cmdline_parse_num.h>
82 #include <cmdline_parse_string.h>
83 #include <cmdline_parse_ipaddr.h>
84 #include <cmdline_parse_etheraddr.h>
85 #include <cmdline_socket.h>
86 #include <cmdline.h>
87 #ifdef RTE_LIBRTE_PMD_BOND
88 #include <rte_eth_bond.h>
89 #endif
90
91 #include "testpmd.h"
92
93 static struct cmdline *testpmd_cl;
94
95 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
96
97 #ifdef RTE_NIC_BYPASS
98 uint8_t bypass_is_supported(portid_t port_id);
99 #endif
100
101 /* *** Help command with introduction. *** */
102 struct cmd_help_brief_result {
103         cmdline_fixed_string_t help;
104 };
105
106 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
107                                   struct cmdline *cl,
108                                   __attribute__((unused)) void *data)
109 {
110         cmdline_printf(
111                 cl,
112                 "\n"
113                 "Help is available for the following sections:\n\n"
114                 "    help control    : Start and stop forwarding.\n"
115                 "    help display    : Displaying port, stats and config "
116                 "information.\n"
117                 "    help config     : Configuration information.\n"
118                 "    help ports      : Configuring ports.\n"
119                 "    help registers  : Reading and setting port registers.\n"
120                 "    help filters    : Filters configuration help.\n"
121                 "    help all        : All of the above sections.\n\n"
122         );
123
124 }
125
126 cmdline_parse_token_string_t cmd_help_brief_help =
127         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
128
129 cmdline_parse_inst_t cmd_help_brief = {
130         .f = cmd_help_brief_parsed,
131         .data = NULL,
132         .help_str = "show help",
133         .tokens = {
134                 (void *)&cmd_help_brief_help,
135                 NULL,
136         },
137 };
138
139 /* *** Help command with help sections. *** */
140 struct cmd_help_long_result {
141         cmdline_fixed_string_t help;
142         cmdline_fixed_string_t section;
143 };
144
145 static void cmd_help_long_parsed(void *parsed_result,
146                                  struct cmdline *cl,
147                                  __attribute__((unused)) void *data)
148 {
149         int show_all = 0;
150         struct cmd_help_long_result *res = parsed_result;
151
152         if (!strcmp(res->section, "all"))
153                 show_all = 1;
154
155         if (show_all || !strcmp(res->section, "control")) {
156
157                 cmdline_printf(
158                         cl,
159                         "\n"
160                         "Control forwarding:\n"
161                         "-------------------\n\n"
162
163                         "start\n"
164                         "    Start packet forwarding with current configuration.\n\n"
165
166                         "start tx_first\n"
167                         "    Start packet forwarding with current config"
168                         " after sending one burst of packets.\n\n"
169
170                         "stop\n"
171                         "    Stop packet forwarding, and display accumulated"
172                         " statistics.\n\n"
173
174                         "quit\n"
175                         "    Quit to prompt.\n\n"
176                 );
177         }
178
179         if (show_all || !strcmp(res->section, "display")) {
180
181                 cmdline_printf(
182                         cl,
183                         "\n"
184                         "Display:\n"
185                         "--------\n\n"
186
187                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc) (port_id|all)\n"
188                         "    Display information for port_id, or all.\n\n"
189
190                         "show port X rss reta (size) (mask0,mask1,...)\n"
191                         "    Display the rss redirection table entry indicated"
192                         " by masks on port X. size is used to indicate the"
193                         " hardware supported reta size\n\n"
194
195                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
196                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
197                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
198                         "    Display the RSS hash functions and RSS hash key"
199                         " of port X\n\n"
200
201                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
202                         "    Clear information for port_id, or all.\n\n"
203
204                         "show (rxq|txq) info (port_id) (queue_id)\n"
205                         "    Display information for configured RX/TX queue.\n\n"
206
207                         "show config (rxtx|cores|fwd|txpkts)\n"
208                         "    Display the given configuration.\n\n"
209
210                         "read rxd (port_id) (queue_id) (rxd_id)\n"
211                         "    Display an RX descriptor of a port RX queue.\n\n"
212
213                         "read txd (port_id) (queue_id) (txd_id)\n"
214                         "    Display a TX descriptor of a port TX queue.\n\n"
215                 );
216         }
217
218         if (show_all || !strcmp(res->section, "config")) {
219                 cmdline_printf(
220                         cl,
221                         "\n"
222                         "Configuration:\n"
223                         "--------------\n"
224                         "Configuration changes only become active when"
225                         " forwarding is started/restarted.\n\n"
226
227                         "set default\n"
228                         "    Reset forwarding to the default configuration.\n\n"
229
230                         "set verbose (level)\n"
231                         "    Set the debug verbosity level X.\n\n"
232
233                         "set nbport (num)\n"
234                         "    Set number of ports.\n\n"
235
236                         "set nbcore (num)\n"
237                         "    Set number of cores.\n\n"
238
239                         "set coremask (mask)\n"
240                         "    Set the forwarding cores hexadecimal mask.\n\n"
241
242                         "set portmask (mask)\n"
243                         "    Set the forwarding ports hexadecimal mask.\n\n"
244
245                         "set burst (num)\n"
246                         "    Set number of packets per burst.\n\n"
247
248                         "set burst tx delay (microseconds) retry (num)\n"
249                         "    Set the transmit delay time and number of retries"
250                         " in mac_retry forwarding mode.\n\n"
251
252                         "set txpkts (x[,y]*)\n"
253                         "    Set the length of each segment of TXONLY"
254                         " and optionally CSUM packets.\n\n"
255
256                         "set txsplit (off|on|rand)\n"
257                         "    Set the split policy for the TX packets."
258                         " Right now only applicable for CSUM and TXONLY"
259                         " modes\n\n"
260
261                         "set corelist (x[,y]*)\n"
262                         "    Set the list of forwarding cores.\n\n"
263
264                         "set portlist (x[,y]*)\n"
265                         "    Set the list of forwarding ports.\n\n"
266
267                         "vlan set strip (on|off) (port_id)\n"
268                         "    Set the VLAN strip on a port.\n\n"
269
270                         "vlan set stripq (on|off) (port_id,queue_id)\n"
271                         "    Set the VLAN strip for a queue on a port.\n\n"
272
273                         "vlan set filter (on|off) (port_id)\n"
274                         "    Set the VLAN filter on a port.\n\n"
275
276                         "vlan set qinq (on|off) (port_id)\n"
277                         "    Set the VLAN QinQ (extended queue in queue)"
278                         " on a port.\n\n"
279
280                         "vlan set (inner|outer) tpid (value) (port_id)\n"
281                         "    Set the VLAN TPID for Packet Filtering on"
282                         " a port\n\n"
283
284                         "rx_vlan add (vlan_id|all) (port_id)\n"
285                         "    Add a vlan_id, or all identifiers, to the set"
286                         " of VLAN identifiers filtered by port_id.\n\n"
287
288                         "rx_vlan rm (vlan_id|all) (port_id)\n"
289                         "    Remove a vlan_id, or all identifiers, from the set"
290                         " of VLAN identifiers filtered by port_id.\n\n"
291
292                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
293                         "    Add a vlan_id, to the set of VLAN identifiers"
294                         "filtered for VF(s) from port_id.\n\n"
295
296                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
297                         "    Remove a vlan_id, to the set of VLAN identifiers"
298                         "filtered for VF(s) from port_id.\n\n"
299
300                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
301                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
302                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
303                         "   add a tunnel filter of a port.\n\n"
304
305                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
306                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
307                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
308                         "   remove a tunnel filter of a port.\n\n"
309
310                         "rx_vxlan_port add (udp_port) (port_id)\n"
311                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
312
313                         "rx_vxlan_port rm (udp_port) (port_id)\n"
314                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
315
316                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
317                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
318                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
319
320                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
321                         "    Set port based TX VLAN insertion.\n\n"
322
323                         "tx_vlan reset (port_id)\n"
324                         "    Disable hardware insertion of a VLAN header in"
325                         " packets sent on a port.\n\n"
326
327                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
328                         "    Select hardware or software calculation of the"
329                         " checksum when transmitting a packet using the"
330                         " csum forward engine.\n"
331                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
332                         "    outer-ip concerns the outer IP layer in"
333                         " case the packet is recognized as a tunnel packet by"
334                         " the forward engine (vxlan, gre and ipip are supported)\n"
335                         "    Please check the NIC datasheet for HW limits.\n\n"
336
337                         "csum parse-tunnel (on|off) (tx_port_id)\n"
338                         "    If disabled, treat tunnel packets as non-tunneled"
339                         " packets (treat inner headers as payload). The port\n"
340                         "    argument is the port used for TX in csum forward"
341                         " engine.\n\n"
342
343                         "csum show (port_id)\n"
344                         "    Display tx checksum offload configuration\n\n"
345
346                         "tso set (segsize) (portid)\n"
347                         "    Enable TCP Segmentation Offload in csum forward"
348                         " engine.\n"
349                         "    Please check the NIC datasheet for HW limits.\n\n"
350
351                         "tso show (portid)"
352                         "    Display the status of TCP Segmentation Offload.\n\n"
353
354                         "set fwd (%s)\n"
355                         "    Set packet forwarding mode.\n\n"
356
357                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
358                         "    Add a MAC address on port_id.\n\n"
359
360                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
361                         "    Remove a MAC address from port_id.\n\n"
362
363                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
364                         "    Add a MAC address for a VF on the port.\n\n"
365
366                         "set port (port_id) uta (mac_address|all) (on|off)\n"
367                         "    Add/Remove a or all unicast hash filter(s)"
368                         "from port X.\n\n"
369
370                         "set promisc (port_id|all) (on|off)\n"
371                         "    Set the promiscuous mode on port_id, or all.\n\n"
372
373                         "set allmulti (port_id|all) (on|off)\n"
374                         "    Set the allmulti mode on port_id, or all.\n\n"
375
376                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
377                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
378                         " (on|off) autoneg (on|off) (port_id)\n"
379                         "set flow_ctrl rx (on|off) (portid)\n"
380                         "set flow_ctrl tx (on|off) (portid)\n"
381                         "set flow_ctrl high_water (high_water) (portid)\n"
382                         "set flow_ctrl low_water (low_water) (portid)\n"
383                         "set flow_ctrl pause_time (pause_time) (portid)\n"
384                         "set flow_ctrl send_xon (send_xon) (portid)\n"
385                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
386                         "set flow_ctrl autoneg (on|off) (port_id)\n"
387                         "    Set the link flow control parameter on a port.\n\n"
388
389                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
390                         " (low_water) (pause_time) (priority) (port_id)\n"
391                         "    Set the priority flow control parameter on a"
392                         " port.\n\n"
393
394                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
395                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
396                         " queue on port.\n"
397                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
398                         " on port 0 to mapping 5.\n\n"
399
400                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
401                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
402
403                         "set port (port_id) vf (vf_id) (mac_addr)"
404                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
405                         "   Add/Remove unicast or multicast MAC addr filter"
406                         " for a VF.\n\n"
407
408                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
409                         "|MPE) (on|off)\n"
410                         "    AUPE:accepts untagged VLAN;"
411                         "ROPE:accept unicast hash\n\n"
412                         "    BAM:accepts broadcast packets;"
413                         "MPE:accepts all multicast packets\n\n"
414                         "    Enable/Disable a VF receive mode of a port\n\n"
415
416                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
417                         "    Set rate limit for a queue of a port\n\n"
418
419                         "set port (port_id) vf (vf_id) rate (rate_num) "
420                         "queue_mask (queue_mask_value)\n"
421                         "    Set rate limit for queues in VF of a port\n\n"
422
423                         "set port (port_id) mirror-rule (rule_id)"
424                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
425                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
426                         "   Set pool or vlan type mirror rule on a port.\n"
427                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
428                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
429                         " to pool 0.\n\n"
430
431                         "set port (port_id) mirror-rule (rule_id)"
432                         " (uplink-mirror|downlink-mirror) dst-pool"
433                         " (pool_id) (on|off)\n"
434                         "   Set uplink or downlink type mirror rule on a port.\n"
435                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
436                         " 0 on' enable mirror income traffic to pool 0.\n\n"
437
438                         "reset port (port_id) mirror-rule (rule_id)\n"
439                         "   Reset a mirror rule.\n\n"
440
441                         "set flush_rx (on|off)\n"
442                         "   Flush (default) or don't flush RX streams before"
443                         " forwarding. Mainly used with PCAP drivers.\n\n"
444
445                         #ifdef RTE_NIC_BYPASS
446                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
447                         "   Set the bypass mode for the lowest port on bypass enabled"
448                         " NIC.\n\n"
449
450                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
451                         "mode (normal|bypass|isolate) (port_id)\n"
452                         "   Set the event required to initiate specified bypass mode for"
453                         " the lowest port on a bypass enabled NIC where:\n"
454                         "       timeout   = enable bypass after watchdog timeout.\n"
455                         "       os_on     = enable bypass when OS/board is powered on.\n"
456                         "       os_off    = enable bypass when OS/board is powered off.\n"
457                         "       power_on  = enable bypass when power supply is turned on.\n"
458                         "       power_off = enable bypass when power supply is turned off."
459                         "\n\n"
460
461                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
462                         "   Set the bypass watchdog timeout to 'n' seconds"
463                         " where 0 = instant.\n\n"
464
465                         "show bypass config (port_id)\n"
466                         "   Show the bypass configuration for a bypass enabled NIC"
467                         " using the lowest port on the NIC.\n\n"
468 #endif
469 #ifdef RTE_LIBRTE_PMD_BOND
470                         "create bonded device (mode) (socket)\n"
471                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
472
473                         "add bonding slave (slave_id) (port_id)\n"
474                         "       Add a slave device to a bonded device.\n\n"
475
476                         "remove bonding slave (slave_id) (port_id)\n"
477                         "       Remove a slave device from a bonded device.\n\n"
478
479                         "set bonding mode (value) (port_id)\n"
480                         "       Set the bonding mode on a bonded device.\n\n"
481
482                         "set bonding primary (slave_id) (port_id)\n"
483                         "       Set the primary slave for a bonded device.\n\n"
484
485                         "show bonding config (port_id)\n"
486                         "       Show the bonding config for port_id.\n\n"
487
488                         "set bonding mac_addr (port_id) (address)\n"
489                         "       Set the MAC address of a bonded device.\n\n"
490
491                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
492                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
493
494                         "set bonding mon_period (port_id) (value)\n"
495                         "       Set the bonding link status monitoring polling period in ms.\n\n"
496 #endif
497                         "set link-up port (port_id)\n"
498                         "       Set link up for a port.\n\n"
499
500                         "set link-down port (port_id)\n"
501                         "       Set link down for a port.\n\n"
502
503                         "E-tag set insertion on port-tag-id (value)"
504                         " port (port_id) vf (vf_id)\n"
505                         "    Enable E-tag insertion for a VF on a port\n\n"
506
507                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
508                         "    Disable E-tag insertion for a VF on a port\n\n"
509
510                         "E-tag set stripping (on|off) port (port_id)\n"
511                         "    Enable/disable E-tag stripping on a port\n\n"
512
513                         "E-tag set forwarding (on|off) port (port_id)\n"
514                         "    Enable/disable E-tag based forwarding"
515                         " on a port\n\n"
516
517                         "E-tag set filter add e-tag-id (value) dst-pool"
518                         " (pool_id) port (port_id)\n"
519                         "    Add an E-tag forwarding filter on a port\n\n"
520
521                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
522                         "    Delete an E-tag forwarding filter on a port\n\n"
523
524                         , list_pkt_forwarding_modes()
525                 );
526         }
527
528         if (show_all || !strcmp(res->section, "ports")) {
529
530                 cmdline_printf(
531                         cl,
532                         "\n"
533                         "Port Operations:\n"
534                         "----------------\n\n"
535
536                         "port start (port_id|all)\n"
537                         "    Start all ports or port_id.\n\n"
538
539                         "port stop (port_id|all)\n"
540                         "    Stop all ports or port_id.\n\n"
541
542                         "port close (port_id|all)\n"
543                         "    Close all ports or port_id.\n\n"
544
545                         "port attach (ident)\n"
546                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
547
548                         "port detach (port_id)\n"
549                         "    Detach physical or virtual dev by port_id\n\n"
550
551                         "port config (port_id|all)"
552                         " speed (10|100|1000|10000|40000|100000|auto)"
553                         " duplex (half|full|auto)\n"
554                         "    Set speed and duplex for all ports or port_id\n\n"
555
556                         "port config all (rxq|txq|rxd|txd) (value)\n"
557                         "    Set number for rxq/txq/rxd/txd.\n\n"
558
559                         "port config all max-pkt-len (value)\n"
560                         "    Set the max packet length.\n\n"
561
562                         "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
563                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
564                         " (on|off)\n"
565                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
566                         " for ports.\n\n"
567
568                         "port config all rss (all|ip|tcp|udp|sctp|ether|none)\n"
569                         "    Set the RSS mode.\n\n"
570
571                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
572                         "    Set the RSS redirection table.\n\n"
573
574                         "port config (port_id) dcb vt (on|off) (traffic_class)"
575                         " pfc (on|off)\n"
576                         "    Set the DCB mode.\n\n"
577
578                         "port config all burst (value)\n"
579                         "    Set the number of packets per burst.\n\n"
580
581                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
582                         " (value)\n"
583                         "    Set the ring prefetch/host/writeback threshold"
584                         " for tx/rx queue.\n\n"
585
586                         "port config all (txfreet|txrst|rxfreet) (value)\n"
587                         "    Set free threshold for rx/tx, or set"
588                         " tx rs bit threshold.\n\n"
589                         "port config mtu X value\n"
590                         "    Set the MTU of port X to a given value\n\n"
591
592                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
593                         "    Start/stop a rx/tx queue of port X. Only take effect"
594                         " when port X is started\n\n"
595
596                         "port config (port_id|all) l2-tunnel E-tag ether-type"
597                         " (value)\n"
598                         "    Set the value of E-tag ether-type.\n\n"
599
600                         "port config (port_id|all) l2-tunnel E-tag"
601                         " (enable|disable)\n"
602                         "    Enable/disable the E-tag support.\n\n"
603                 );
604         }
605
606         if (show_all || !strcmp(res->section, "registers")) {
607
608                 cmdline_printf(
609                         cl,
610                         "\n"
611                         "Registers:\n"
612                         "----------\n\n"
613
614                         "read reg (port_id) (address)\n"
615                         "    Display value of a port register.\n\n"
616
617                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
618                         "    Display a port register bit field.\n\n"
619
620                         "read regbit (port_id) (address) (bit_x)\n"
621                         "    Display a single port register bit.\n\n"
622
623                         "write reg (port_id) (address) (value)\n"
624                         "    Set value of a port register.\n\n"
625
626                         "write regfield (port_id) (address) (bit_x) (bit_y)"
627                         " (value)\n"
628                         "    Set bit field of a port register.\n\n"
629
630                         "write regbit (port_id) (address) (bit_x) (value)\n"
631                         "    Set single bit value of a port register.\n\n"
632                 );
633         }
634         if (show_all || !strcmp(res->section, "filters")) {
635
636                 cmdline_printf(
637                         cl,
638                         "\n"
639                         "filters:\n"
640                         "--------\n\n"
641
642                         "ethertype_filter (port_id) (add|del)"
643                         " (mac_addr|mac_ignr) (mac_address) ethertype"
644                         " (ether_type) (drop|fwd) queue (queue_id)\n"
645                         "    Add/Del an ethertype filter.\n\n"
646
647                         "2tuple_filter (port_id) (add|del)"
648                         " dst_port (dst_port_value) protocol (protocol_value)"
649                         " mask (mask_value) tcp_flags (tcp_flags_value)"
650                         " priority (prio_value) queue (queue_id)\n"
651                         "    Add/Del a 2tuple filter.\n\n"
652
653                         "5tuple_filter (port_id) (add|del)"
654                         " dst_ip (dst_address) src_ip (src_address)"
655                         " dst_port (dst_port_value) src_port (src_port_value)"
656                         " protocol (protocol_value)"
657                         " mask (mask_value) tcp_flags (tcp_flags_value)"
658                         " priority (prio_value) queue (queue_id)\n"
659                         "    Add/Del a 5tuple filter.\n\n"
660
661                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
662                         "    Add/Del syn filter.\n\n"
663
664                         "flex_filter (port_id) (add|del) len (len_value)"
665                         " bytes (bytes_value) mask (mask_value)"
666                         " priority (prio_value) queue (queue_id)\n"
667                         "    Add/Del a flex filter.\n\n"
668
669                         "flow_director_filter (port_id) mode IP (add|del|update)"
670                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
671                         " src (src_ip_address) dst (dst_ip_address)"
672                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
673                         " vlan (vlan_value) flexbytes (flexbytes_value)"
674                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
675                         " fd_id (fd_id_value)\n"
676                         "    Add/Del an IP type flow director filter.\n\n"
677
678                         "flow_director_filter (port_id) mode IP (add|del|update)"
679                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
680                         " src (src_ip_address) (src_port)"
681                         " dst (dst_ip_address) (dst_port)"
682                         " tos (tos_value) ttl (ttl_value)"
683                         " vlan (vlan_value) flexbytes (flexbytes_value)"
684                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
685                         " fd_id (fd_id_value)\n"
686                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
687
688                         "flow_director_filter (port_id) mode IP (add|del|update)"
689                         " flow (ipv4-sctp|ipv6-sctp)"
690                         " src (src_ip_address) (src_port)"
691                         " dst (dst_ip_address) (dst_port)"
692                         " tag (verification_tag) "
693                         " tos (tos_value) ttl (ttl_value)"
694                         " vlan (vlan_value)"
695                         " flexbytes (flexbytes_value) (drop|fwd)"
696                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
697                         "    Add/Del a SCTP type flow director filter.\n\n"
698
699                         "flow_director_filter (port_id) mode IP (add|del|update)"
700                         " flow l2_payload ether (ethertype)"
701                         " flexbytes (flexbytes_value) (drop|fwd)"
702                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
703                         "    Add/Del a l2 payload type flow director filter.\n\n"
704
705                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
706                         " mac (mac_address) vlan (vlan_value)"
707                         " flexbytes (flexbytes_value) (drop|fwd)"
708                         " queue (queue_id) fd_id (fd_id_value)\n"
709                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
710
711                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
712                         " mac (mac_address) vlan (vlan_value)"
713                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
714                         " flexbytes (flexbytes_value) (drop|fwd)"
715                         " queue (queue_id) fd_id (fd_id_value)\n"
716                         "    Add/Del a Tunnel flow director filter.\n\n"
717
718                         "flush_flow_director (port_id)\n"
719                         "    Flush all flow director entries of a device.\n\n"
720
721                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
722                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
723                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
724                         "    Set flow director IP mask.\n\n"
725
726                         "flow_director_mask (port_id) mode MAC-VLAN"
727                         " vlan (vlan_value) mac (mac_value)\n"
728                         "    Set flow director MAC-VLAN mask.\n\n"
729
730                         "flow_director_mask (port_id) mode Tunnel"
731                         " vlan (vlan_value) mac (mac_value)"
732                         " tunnel-type (tunnel_type_value)"
733                         " tunnel-id (tunnel_id_value)\n"
734                         "    Set flow director Tunnel mask.\n\n"
735
736                         "flow_director_flex_mask (port_id)"
737                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
738                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
739                         " (mask)\n"
740                         "    Configure mask of flex payload.\n\n"
741
742                         "flow_director_flex_payload (port_id)"
743                         " (raw|l2|l3|l4) (config)\n"
744                         "    Configure flex payload selection.\n\n"
745
746                         "get_sym_hash_ena_per_port (port_id)\n"
747                         "    get symmetric hash enable configuration per port.\n\n"
748
749                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
750                         "    set symmetric hash enable configuration per port"
751                         " to enable or disable.\n\n"
752
753                         "get_hash_global_config (port_id)\n"
754                         "    Get the global configurations of hash filters.\n\n"
755
756                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
757                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
758                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
759                         " (enable|disable)\n"
760                         "    Set the global configurations of hash filters.\n\n"
761
762                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
763                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
764                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
765                         "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
766                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
767                         "ipv6-next-header|udp-src-port|udp-dst-port|"
768                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
769                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
770                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
771                         "fld-8th|none) (select|add)\n"
772                         "    Set the input set for hash.\n\n"
773
774                         "set_fdir_input_set (port_id) "
775                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
776                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
777                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
778                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
779                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
780                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
781                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
782                         " (select|add)\n"
783                         "    Set the input set for FDir.\n\n"
784                 );
785         }
786 }
787
788 cmdline_parse_token_string_t cmd_help_long_help =
789         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
790
791 cmdline_parse_token_string_t cmd_help_long_section =
792         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
793                         "all#control#display#config#"
794                         "ports#registers#filters");
795
796 cmdline_parse_inst_t cmd_help_long = {
797         .f = cmd_help_long_parsed,
798         .data = NULL,
799         .help_str = "show help",
800         .tokens = {
801                 (void *)&cmd_help_long_help,
802                 (void *)&cmd_help_long_section,
803                 NULL,
804         },
805 };
806
807
808 /* *** start/stop/close all ports *** */
809 struct cmd_operate_port_result {
810         cmdline_fixed_string_t keyword;
811         cmdline_fixed_string_t name;
812         cmdline_fixed_string_t value;
813 };
814
815 static void cmd_operate_port_parsed(void *parsed_result,
816                                 __attribute__((unused)) struct cmdline *cl,
817                                 __attribute__((unused)) void *data)
818 {
819         struct cmd_operate_port_result *res = parsed_result;
820
821         if (!strcmp(res->name, "start"))
822                 start_port(RTE_PORT_ALL);
823         else if (!strcmp(res->name, "stop"))
824                 stop_port(RTE_PORT_ALL);
825         else if (!strcmp(res->name, "close"))
826                 close_port(RTE_PORT_ALL);
827         else
828                 printf("Unknown parameter\n");
829 }
830
831 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
832         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
833                                                                 "port");
834 cmdline_parse_token_string_t cmd_operate_port_all_port =
835         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
836                                                 "start#stop#close");
837 cmdline_parse_token_string_t cmd_operate_port_all_all =
838         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
839
840 cmdline_parse_inst_t cmd_operate_port = {
841         .f = cmd_operate_port_parsed,
842         .data = NULL,
843         .help_str = "port start|stop|close all: start/stop/close all ports",
844         .tokens = {
845                 (void *)&cmd_operate_port_all_cmd,
846                 (void *)&cmd_operate_port_all_port,
847                 (void *)&cmd_operate_port_all_all,
848                 NULL,
849         },
850 };
851
852 /* *** start/stop/close specific port *** */
853 struct cmd_operate_specific_port_result {
854         cmdline_fixed_string_t keyword;
855         cmdline_fixed_string_t name;
856         uint8_t value;
857 };
858
859 static void cmd_operate_specific_port_parsed(void *parsed_result,
860                         __attribute__((unused)) struct cmdline *cl,
861                                 __attribute__((unused)) void *data)
862 {
863         struct cmd_operate_specific_port_result *res = parsed_result;
864
865         if (!strcmp(res->name, "start"))
866                 start_port(res->value);
867         else if (!strcmp(res->name, "stop"))
868                 stop_port(res->value);
869         else if (!strcmp(res->name, "close"))
870                 close_port(res->value);
871         else
872                 printf("Unknown parameter\n");
873 }
874
875 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
876         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
877                                                         keyword, "port");
878 cmdline_parse_token_string_t cmd_operate_specific_port_port =
879         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
880                                                 name, "start#stop#close");
881 cmdline_parse_token_num_t cmd_operate_specific_port_id =
882         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
883                                                         value, UINT8);
884
885 cmdline_parse_inst_t cmd_operate_specific_port = {
886         .f = cmd_operate_specific_port_parsed,
887         .data = NULL,
888         .help_str = "port start|stop|close X: start/stop/close port X",
889         .tokens = {
890                 (void *)&cmd_operate_specific_port_cmd,
891                 (void *)&cmd_operate_specific_port_port,
892                 (void *)&cmd_operate_specific_port_id,
893                 NULL,
894         },
895 };
896
897 /* *** attach a specified port *** */
898 struct cmd_operate_attach_port_result {
899         cmdline_fixed_string_t port;
900         cmdline_fixed_string_t keyword;
901         cmdline_fixed_string_t identifier;
902 };
903
904 static void cmd_operate_attach_port_parsed(void *parsed_result,
905                                 __attribute__((unused)) struct cmdline *cl,
906                                 __attribute__((unused)) void *data)
907 {
908         struct cmd_operate_attach_port_result *res = parsed_result;
909
910         if (!strcmp(res->keyword, "attach"))
911                 attach_port(res->identifier);
912         else
913                 printf("Unknown parameter\n");
914 }
915
916 cmdline_parse_token_string_t cmd_operate_attach_port_port =
917         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
918                         port, "port");
919 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
920         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
921                         keyword, "attach");
922 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
923         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
924                         identifier, NULL);
925
926 cmdline_parse_inst_t cmd_operate_attach_port = {
927         .f = cmd_operate_attach_port_parsed,
928         .data = NULL,
929         .help_str = "port attach identifier, "
930                 "identifier: pci address or virtual dev name",
931         .tokens = {
932                 (void *)&cmd_operate_attach_port_port,
933                 (void *)&cmd_operate_attach_port_keyword,
934                 (void *)&cmd_operate_attach_port_identifier,
935                 NULL,
936         },
937 };
938
939 /* *** detach a specified port *** */
940 struct cmd_operate_detach_port_result {
941         cmdline_fixed_string_t port;
942         cmdline_fixed_string_t keyword;
943         uint8_t port_id;
944 };
945
946 static void cmd_operate_detach_port_parsed(void *parsed_result,
947                                 __attribute__((unused)) struct cmdline *cl,
948                                 __attribute__((unused)) void *data)
949 {
950         struct cmd_operate_detach_port_result *res = parsed_result;
951
952         if (!strcmp(res->keyword, "detach"))
953                 detach_port(res->port_id);
954         else
955                 printf("Unknown parameter\n");
956 }
957
958 cmdline_parse_token_string_t cmd_operate_detach_port_port =
959         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
960                         port, "port");
961 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
962         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
963                         keyword, "detach");
964 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
965         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
966                         port_id, UINT8);
967
968 cmdline_parse_inst_t cmd_operate_detach_port = {
969         .f = cmd_operate_detach_port_parsed,
970         .data = NULL,
971         .help_str = "port detach port_id",
972         .tokens = {
973                 (void *)&cmd_operate_detach_port_port,
974                 (void *)&cmd_operate_detach_port_keyword,
975                 (void *)&cmd_operate_detach_port_port_id,
976                 NULL,
977         },
978 };
979
980 /* *** configure speed for all ports *** */
981 struct cmd_config_speed_all {
982         cmdline_fixed_string_t port;
983         cmdline_fixed_string_t keyword;
984         cmdline_fixed_string_t all;
985         cmdline_fixed_string_t item1;
986         cmdline_fixed_string_t item2;
987         cmdline_fixed_string_t value1;
988         cmdline_fixed_string_t value2;
989 };
990
991 static int
992 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
993 {
994
995         int duplex;
996
997         if (!strcmp(duplexstr, "half")) {
998                 duplex = ETH_LINK_HALF_DUPLEX;
999         } else if (!strcmp(duplexstr, "full")) {
1000                 duplex = ETH_LINK_FULL_DUPLEX;
1001         } else if (!strcmp(duplexstr, "auto")) {
1002                 duplex = ETH_LINK_FULL_DUPLEX;
1003         } else {
1004                 printf("Unknown duplex parameter\n");
1005                 return -1;
1006         }
1007
1008         if (!strcmp(speedstr, "10")) {
1009                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1010                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1011         } else if (!strcmp(speedstr, "100")) {
1012                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1013                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1014         } else {
1015                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1016                         printf("Invalid speed/duplex parameters\n");
1017                         return -1;
1018                 }
1019                 if (!strcmp(speedstr, "1000")) {
1020                         *speed = ETH_LINK_SPEED_1G;
1021                 } else if (!strcmp(speedstr, "10000")) {
1022                         *speed = ETH_LINK_SPEED_10G;
1023                 } else if (!strcmp(speedstr, "40000")) {
1024                         *speed = ETH_LINK_SPEED_40G;
1025                 } else if (!strcmp(speedstr, "100000")) {
1026                         *speed = ETH_LINK_SPEED_100G;
1027                 } else if (!strcmp(speedstr, "auto")) {
1028                         *speed = ETH_LINK_SPEED_AUTONEG;
1029                 } else {
1030                         printf("Unknown speed parameter\n");
1031                         return -1;
1032                 }
1033         }
1034
1035         return 0;
1036 }
1037
1038 static void
1039 cmd_config_speed_all_parsed(void *parsed_result,
1040                         __attribute__((unused)) struct cmdline *cl,
1041                         __attribute__((unused)) void *data)
1042 {
1043         struct cmd_config_speed_all *res = parsed_result;
1044         uint32_t link_speed;
1045         portid_t pid;
1046
1047         if (!all_ports_stopped()) {
1048                 printf("Please stop all ports first\n");
1049                 return;
1050         }
1051
1052         if (parse_and_check_speed_duplex(res->value1, res->value2,
1053                         &link_speed) < 0)
1054                 return;
1055
1056         FOREACH_PORT(pid, ports) {
1057                 ports[pid].dev_conf.link_speeds = link_speed;
1058         }
1059
1060         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1061 }
1062
1063 cmdline_parse_token_string_t cmd_config_speed_all_port =
1064         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1065 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1066         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1067                                                         "config");
1068 cmdline_parse_token_string_t cmd_config_speed_all_all =
1069         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1070 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1071         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1072 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1073         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1074                                                 "10#100#1000#10000#40000#100000#auto");
1075 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1076         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1077 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1078         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1079                                                 "half#full#auto");
1080
1081 cmdline_parse_inst_t cmd_config_speed_all = {
1082         .f = cmd_config_speed_all_parsed,
1083         .data = NULL,
1084         .help_str = "port config all speed 10|100|1000|10000|40000|100000|auto duplex "
1085                                                         "half|full|auto",
1086         .tokens = {
1087                 (void *)&cmd_config_speed_all_port,
1088                 (void *)&cmd_config_speed_all_keyword,
1089                 (void *)&cmd_config_speed_all_all,
1090                 (void *)&cmd_config_speed_all_item1,
1091                 (void *)&cmd_config_speed_all_value1,
1092                 (void *)&cmd_config_speed_all_item2,
1093                 (void *)&cmd_config_speed_all_value2,
1094                 NULL,
1095         },
1096 };
1097
1098 /* *** configure speed for specific port *** */
1099 struct cmd_config_speed_specific {
1100         cmdline_fixed_string_t port;
1101         cmdline_fixed_string_t keyword;
1102         uint8_t id;
1103         cmdline_fixed_string_t item1;
1104         cmdline_fixed_string_t item2;
1105         cmdline_fixed_string_t value1;
1106         cmdline_fixed_string_t value2;
1107 };
1108
1109 static void
1110 cmd_config_speed_specific_parsed(void *parsed_result,
1111                                 __attribute__((unused)) struct cmdline *cl,
1112                                 __attribute__((unused)) void *data)
1113 {
1114         struct cmd_config_speed_specific *res = parsed_result;
1115         uint32_t link_speed;
1116
1117         if (!all_ports_stopped()) {
1118                 printf("Please stop all ports first\n");
1119                 return;
1120         }
1121
1122         if (port_id_is_invalid(res->id, ENABLED_WARN))
1123                 return;
1124
1125         if (parse_and_check_speed_duplex(res->value1, res->value2,
1126                         &link_speed) < 0)
1127                 return;
1128
1129         ports[res->id].dev_conf.link_speeds = link_speed;
1130
1131         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1132 }
1133
1134
1135 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1136         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1137                                                                 "port");
1138 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1139         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1140                                                                 "config");
1141 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1142         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1143 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1144         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1145                                                                 "speed");
1146 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1147         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1148                                                 "10#100#1000#10000#40000#100000#auto");
1149 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1150         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1151                                                                 "duplex");
1152 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1153         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1154                                                         "half#full#auto");
1155
1156 cmdline_parse_inst_t cmd_config_speed_specific = {
1157         .f = cmd_config_speed_specific_parsed,
1158         .data = NULL,
1159         .help_str = "port config X speed 10|100|1000|10000|40000|100000|auto duplex "
1160                                                         "half|full|auto",
1161         .tokens = {
1162                 (void *)&cmd_config_speed_specific_port,
1163                 (void *)&cmd_config_speed_specific_keyword,
1164                 (void *)&cmd_config_speed_specific_id,
1165                 (void *)&cmd_config_speed_specific_item1,
1166                 (void *)&cmd_config_speed_specific_value1,
1167                 (void *)&cmd_config_speed_specific_item2,
1168                 (void *)&cmd_config_speed_specific_value2,
1169                 NULL,
1170         },
1171 };
1172
1173 /* *** configure txq/rxq, txd/rxd *** */
1174 struct cmd_config_rx_tx {
1175         cmdline_fixed_string_t port;
1176         cmdline_fixed_string_t keyword;
1177         cmdline_fixed_string_t all;
1178         cmdline_fixed_string_t name;
1179         uint16_t value;
1180 };
1181
1182 static void
1183 cmd_config_rx_tx_parsed(void *parsed_result,
1184                         __attribute__((unused)) struct cmdline *cl,
1185                         __attribute__((unused)) void *data)
1186 {
1187         struct cmd_config_rx_tx *res = parsed_result;
1188
1189         if (!all_ports_stopped()) {
1190                 printf("Please stop all ports first\n");
1191                 return;
1192         }
1193         if (!strcmp(res->name, "rxq")) {
1194                 if (!res->value && !nb_txq) {
1195                         printf("Warning: Either rx or tx queues should be non zero\n");
1196                         return;
1197                 }
1198                 nb_rxq = res->value;
1199         }
1200         else if (!strcmp(res->name, "txq")) {
1201                 if (!res->value && !nb_rxq) {
1202                         printf("Warning: Either rx or tx queues should be non zero\n");
1203                         return;
1204                 }
1205                 nb_txq = res->value;
1206         }
1207         else if (!strcmp(res->name, "rxd")) {
1208                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1209                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1210                                         res->value, RTE_TEST_RX_DESC_MAX);
1211                         return;
1212                 }
1213                 nb_rxd = res->value;
1214         } else if (!strcmp(res->name, "txd")) {
1215                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1216                         printf("txd %d invalid - must be > 0 && <= %d\n",
1217                                         res->value, RTE_TEST_TX_DESC_MAX);
1218                         return;
1219                 }
1220                 nb_txd = res->value;
1221         } else {
1222                 printf("Unknown parameter\n");
1223                 return;
1224         }
1225
1226         init_port_config();
1227
1228         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1229 }
1230
1231 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1232         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1233 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1234         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1235 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1236         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1237 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1238         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1239                                                 "rxq#txq#rxd#txd");
1240 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1241         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1242
1243 cmdline_parse_inst_t cmd_config_rx_tx = {
1244         .f = cmd_config_rx_tx_parsed,
1245         .data = NULL,
1246         .help_str = "port config all rxq|txq|rxd|txd value",
1247         .tokens = {
1248                 (void *)&cmd_config_rx_tx_port,
1249                 (void *)&cmd_config_rx_tx_keyword,
1250                 (void *)&cmd_config_rx_tx_all,
1251                 (void *)&cmd_config_rx_tx_name,
1252                 (void *)&cmd_config_rx_tx_value,
1253                 NULL,
1254         },
1255 };
1256
1257 /* *** config max packet length *** */
1258 struct cmd_config_max_pkt_len_result {
1259         cmdline_fixed_string_t port;
1260         cmdline_fixed_string_t keyword;
1261         cmdline_fixed_string_t all;
1262         cmdline_fixed_string_t name;
1263         uint32_t value;
1264 };
1265
1266 static void
1267 cmd_config_max_pkt_len_parsed(void *parsed_result,
1268                                 __attribute__((unused)) struct cmdline *cl,
1269                                 __attribute__((unused)) void *data)
1270 {
1271         struct cmd_config_max_pkt_len_result *res = parsed_result;
1272
1273         if (!all_ports_stopped()) {
1274                 printf("Please stop all ports first\n");
1275                 return;
1276         }
1277
1278         if (!strcmp(res->name, "max-pkt-len")) {
1279                 if (res->value < ETHER_MIN_LEN) {
1280                         printf("max-pkt-len can not be less than %d\n",
1281                                                         ETHER_MIN_LEN);
1282                         return;
1283                 }
1284                 if (res->value == rx_mode.max_rx_pkt_len)
1285                         return;
1286
1287                 rx_mode.max_rx_pkt_len = res->value;
1288                 if (res->value > ETHER_MAX_LEN)
1289                         rx_mode.jumbo_frame = 1;
1290                 else
1291                         rx_mode.jumbo_frame = 0;
1292         } else {
1293                 printf("Unknown parameter\n");
1294                 return;
1295         }
1296
1297         init_port_config();
1298
1299         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1300 }
1301
1302 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1303         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1304                                                                 "port");
1305 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1306         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1307                                                                 "config");
1308 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1309         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1310                                                                 "all");
1311 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1312         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1313                                                                 "max-pkt-len");
1314 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1315         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1316                                                                 UINT32);
1317
1318 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1319         .f = cmd_config_max_pkt_len_parsed,
1320         .data = NULL,
1321         .help_str = "port config all max-pkt-len value",
1322         .tokens = {
1323                 (void *)&cmd_config_max_pkt_len_port,
1324                 (void *)&cmd_config_max_pkt_len_keyword,
1325                 (void *)&cmd_config_max_pkt_len_all,
1326                 (void *)&cmd_config_max_pkt_len_name,
1327                 (void *)&cmd_config_max_pkt_len_value,
1328                 NULL,
1329         },
1330 };
1331
1332 /* *** configure port MTU *** */
1333 struct cmd_config_mtu_result {
1334         cmdline_fixed_string_t port;
1335         cmdline_fixed_string_t keyword;
1336         cmdline_fixed_string_t mtu;
1337         uint8_t port_id;
1338         uint16_t value;
1339 };
1340
1341 static void
1342 cmd_config_mtu_parsed(void *parsed_result,
1343                       __attribute__((unused)) struct cmdline *cl,
1344                       __attribute__((unused)) void *data)
1345 {
1346         struct cmd_config_mtu_result *res = parsed_result;
1347
1348         if (res->value < ETHER_MIN_LEN) {
1349                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1350                 return;
1351         }
1352         port_mtu_set(res->port_id, res->value);
1353 }
1354
1355 cmdline_parse_token_string_t cmd_config_mtu_port =
1356         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1357                                  "port");
1358 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1359         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1360                                  "config");
1361 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1362         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1363                                  "mtu");
1364 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1365         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1366 cmdline_parse_token_num_t cmd_config_mtu_value =
1367         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1368
1369 cmdline_parse_inst_t cmd_config_mtu = {
1370         .f = cmd_config_mtu_parsed,
1371         .data = NULL,
1372         .help_str = "port config mtu value",
1373         .tokens = {
1374                 (void *)&cmd_config_mtu_port,
1375                 (void *)&cmd_config_mtu_keyword,
1376                 (void *)&cmd_config_mtu_mtu,
1377                 (void *)&cmd_config_mtu_port_id,
1378                 (void *)&cmd_config_mtu_value,
1379                 NULL,
1380         },
1381 };
1382
1383 /* *** configure rx mode *** */
1384 struct cmd_config_rx_mode_flag {
1385         cmdline_fixed_string_t port;
1386         cmdline_fixed_string_t keyword;
1387         cmdline_fixed_string_t all;
1388         cmdline_fixed_string_t name;
1389         cmdline_fixed_string_t value;
1390 };
1391
1392 static void
1393 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1394                                 __attribute__((unused)) struct cmdline *cl,
1395                                 __attribute__((unused)) void *data)
1396 {
1397         struct cmd_config_rx_mode_flag *res = parsed_result;
1398
1399         if (!all_ports_stopped()) {
1400                 printf("Please stop all ports first\n");
1401                 return;
1402         }
1403
1404         if (!strcmp(res->name, "crc-strip")) {
1405                 if (!strcmp(res->value, "on"))
1406                         rx_mode.hw_strip_crc = 1;
1407                 else if (!strcmp(res->value, "off"))
1408                         rx_mode.hw_strip_crc = 0;
1409                 else {
1410                         printf("Unknown parameter\n");
1411                         return;
1412                 }
1413         } else if (!strcmp(res->name, "scatter")) {
1414                 if (!strcmp(res->value, "on"))
1415                         rx_mode.enable_scatter = 1;
1416                 else if (!strcmp(res->value, "off"))
1417                         rx_mode.enable_scatter = 0;
1418                 else {
1419                         printf("Unknown parameter\n");
1420                         return;
1421                 }
1422         } else if (!strcmp(res->name, "rx-cksum")) {
1423                 if (!strcmp(res->value, "on"))
1424                         rx_mode.hw_ip_checksum = 1;
1425                 else if (!strcmp(res->value, "off"))
1426                         rx_mode.hw_ip_checksum = 0;
1427                 else {
1428                         printf("Unknown parameter\n");
1429                         return;
1430                 }
1431         } else if (!strcmp(res->name, "hw-vlan")) {
1432                 if (!strcmp(res->value, "on")) {
1433                         rx_mode.hw_vlan_filter = 1;
1434                         rx_mode.hw_vlan_strip  = 1;
1435                 }
1436                 else if (!strcmp(res->value, "off")) {
1437                         rx_mode.hw_vlan_filter = 0;
1438                         rx_mode.hw_vlan_strip  = 0;
1439                 }
1440                 else {
1441                         printf("Unknown parameter\n");
1442                         return;
1443                 }
1444         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1445                 if (!strcmp(res->value, "on"))
1446                         rx_mode.hw_vlan_filter = 1;
1447                 else if (!strcmp(res->value, "off"))
1448                         rx_mode.hw_vlan_filter = 0;
1449                 else {
1450                         printf("Unknown parameter\n");
1451                         return;
1452                 }
1453         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1454                 if (!strcmp(res->value, "on"))
1455                         rx_mode.hw_vlan_strip  = 1;
1456                 else if (!strcmp(res->value, "off"))
1457                         rx_mode.hw_vlan_strip  = 0;
1458                 else {
1459                         printf("Unknown parameter\n");
1460                         return;
1461                 }
1462         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1463                 if (!strcmp(res->value, "on"))
1464                         rx_mode.hw_vlan_extend = 1;
1465                 else if (!strcmp(res->value, "off"))
1466                         rx_mode.hw_vlan_extend = 0;
1467                 else {
1468                         printf("Unknown parameter\n");
1469                         return;
1470                 }
1471         } else if (!strcmp(res->name, "drop-en")) {
1472                 if (!strcmp(res->value, "on"))
1473                         rx_drop_en = 1;
1474                 else if (!strcmp(res->value, "off"))
1475                         rx_drop_en = 0;
1476                 else {
1477                         printf("Unknown parameter\n");
1478                         return;
1479                 }
1480         } else {
1481                 printf("Unknown parameter\n");
1482                 return;
1483         }
1484
1485         init_port_config();
1486
1487         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1488 }
1489
1490 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1491         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1492 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1493         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1494                                                                 "config");
1495 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1496         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1497 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1498         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1499                                         "crc-strip#scatter#rx-cksum#hw-vlan#"
1500                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1501 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1502         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1503                                                         "on#off");
1504
1505 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1506         .f = cmd_config_rx_mode_flag_parsed,
1507         .data = NULL,
1508         .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1509                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1510         .tokens = {
1511                 (void *)&cmd_config_rx_mode_flag_port,
1512                 (void *)&cmd_config_rx_mode_flag_keyword,
1513                 (void *)&cmd_config_rx_mode_flag_all,
1514                 (void *)&cmd_config_rx_mode_flag_name,
1515                 (void *)&cmd_config_rx_mode_flag_value,
1516                 NULL,
1517         },
1518 };
1519
1520 /* *** configure rss *** */
1521 struct cmd_config_rss {
1522         cmdline_fixed_string_t port;
1523         cmdline_fixed_string_t keyword;
1524         cmdline_fixed_string_t all;
1525         cmdline_fixed_string_t name;
1526         cmdline_fixed_string_t value;
1527 };
1528
1529 static void
1530 cmd_config_rss_parsed(void *parsed_result,
1531                         __attribute__((unused)) struct cmdline *cl,
1532                         __attribute__((unused)) void *data)
1533 {
1534         struct cmd_config_rss *res = parsed_result;
1535         struct rte_eth_rss_conf rss_conf;
1536         uint8_t i;
1537
1538         if (!strcmp(res->value, "all"))
1539                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1540                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1541                                         ETH_RSS_L2_PAYLOAD;
1542         else if (!strcmp(res->value, "ip"))
1543                 rss_conf.rss_hf = ETH_RSS_IP;
1544         else if (!strcmp(res->value, "udp"))
1545                 rss_conf.rss_hf = ETH_RSS_UDP;
1546         else if (!strcmp(res->value, "tcp"))
1547                 rss_conf.rss_hf = ETH_RSS_TCP;
1548         else if (!strcmp(res->value, "sctp"))
1549                 rss_conf.rss_hf = ETH_RSS_SCTP;
1550         else if (!strcmp(res->value, "ether"))
1551                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1552         else if (!strcmp(res->value, "none"))
1553                 rss_conf.rss_hf = 0;
1554         else {
1555                 printf("Unknown parameter\n");
1556                 return;
1557         }
1558         rss_conf.rss_key = NULL;
1559         for (i = 0; i < rte_eth_dev_count(); i++)
1560                 rte_eth_dev_rss_hash_update(i, &rss_conf);
1561 }
1562
1563 cmdline_parse_token_string_t cmd_config_rss_port =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1565 cmdline_parse_token_string_t cmd_config_rss_keyword =
1566         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1567 cmdline_parse_token_string_t cmd_config_rss_all =
1568         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1569 cmdline_parse_token_string_t cmd_config_rss_name =
1570         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1571 cmdline_parse_token_string_t cmd_config_rss_value =
1572         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1573                 "all#ip#tcp#udp#sctp#ether#none");
1574
1575 cmdline_parse_inst_t cmd_config_rss = {
1576         .f = cmd_config_rss_parsed,
1577         .data = NULL,
1578         .help_str = "port config all rss all|ip|tcp|udp|sctp|ether|none",
1579         .tokens = {
1580                 (void *)&cmd_config_rss_port,
1581                 (void *)&cmd_config_rss_keyword,
1582                 (void *)&cmd_config_rss_all,
1583                 (void *)&cmd_config_rss_name,
1584                 (void *)&cmd_config_rss_value,
1585                 NULL,
1586         },
1587 };
1588
1589 /* *** configure rss hash key *** */
1590 struct cmd_config_rss_hash_key {
1591         cmdline_fixed_string_t port;
1592         cmdline_fixed_string_t config;
1593         uint8_t port_id;
1594         cmdline_fixed_string_t rss_hash_key;
1595         cmdline_fixed_string_t rss_type;
1596         cmdline_fixed_string_t key;
1597 };
1598
1599 #define RSS_HASH_KEY_LENGTH 40
1600 static uint8_t
1601 hexa_digit_to_value(char hexa_digit)
1602 {
1603         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1604                 return (uint8_t) (hexa_digit - '0');
1605         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1606                 return (uint8_t) ((hexa_digit - 'a') + 10);
1607         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1608                 return (uint8_t) ((hexa_digit - 'A') + 10);
1609         /* Invalid hexa digit */
1610         return 0xFF;
1611 }
1612
1613 static uint8_t
1614 parse_and_check_key_hexa_digit(char *key, int idx)
1615 {
1616         uint8_t hexa_v;
1617
1618         hexa_v = hexa_digit_to_value(key[idx]);
1619         if (hexa_v == 0xFF)
1620                 printf("invalid key: character %c at position %d is not a "
1621                        "valid hexa digit\n", key[idx], idx);
1622         return hexa_v;
1623 }
1624
1625 static void
1626 cmd_config_rss_hash_key_parsed(void *parsed_result,
1627                                __attribute__((unused)) struct cmdline *cl,
1628                                __attribute__((unused)) void *data)
1629 {
1630         struct cmd_config_rss_hash_key *res = parsed_result;
1631         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1632         uint8_t xdgt0;
1633         uint8_t xdgt1;
1634         int i;
1635
1636         /* Check the length of the RSS hash key */
1637         if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) {
1638                 printf("key length: %d invalid - key must be a string of %d"
1639                        "hexa-decimal numbers\n", (int) strlen(res->key),
1640                        RSS_HASH_KEY_LENGTH * 2);
1641                 return;
1642         }
1643         /* Translate RSS hash key into binary representation */
1644         for (i = 0; i < RSS_HASH_KEY_LENGTH; i++) {
1645                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1646                 if (xdgt0 == 0xFF)
1647                         return;
1648                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1649                 if (xdgt1 == 0xFF)
1650                         return;
1651                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1652         }
1653         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1654                                  RSS_HASH_KEY_LENGTH);
1655 }
1656
1657 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1659 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1661                                  "config");
1662 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1663         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1664 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1666                                  rss_hash_key, "rss-hash-key");
1667 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1669                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1670                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1671                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1672                                  "ipv6-tcp-ex#ipv6-udp-ex");
1673 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1675
1676 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1677         .f = cmd_config_rss_hash_key_parsed,
1678         .data = NULL,
1679         .help_str =
1680                 "port config X rss-hash-key ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
1681                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
1682                 "ipv6-sctp|ipv6-other|l2-payload|"
1683                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex 80 hexa digits\n",
1684         .tokens = {
1685                 (void *)&cmd_config_rss_hash_key_port,
1686                 (void *)&cmd_config_rss_hash_key_config,
1687                 (void *)&cmd_config_rss_hash_key_port_id,
1688                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1689                 (void *)&cmd_config_rss_hash_key_rss_type,
1690                 (void *)&cmd_config_rss_hash_key_value,
1691                 NULL,
1692         },
1693 };
1694
1695 /* *** configure port rxq/txq start/stop *** */
1696 struct cmd_config_rxtx_queue {
1697         cmdline_fixed_string_t port;
1698         uint8_t portid;
1699         cmdline_fixed_string_t rxtxq;
1700         uint16_t qid;
1701         cmdline_fixed_string_t opname;
1702 };
1703
1704 static void
1705 cmd_config_rxtx_queue_parsed(void *parsed_result,
1706                         __attribute__((unused)) struct cmdline *cl,
1707                         __attribute__((unused)) void *data)
1708 {
1709         struct cmd_config_rxtx_queue *res = parsed_result;
1710         uint8_t isrx;
1711         uint8_t isstart;
1712         int ret = 0;
1713
1714         if (test_done == 0) {
1715                 printf("Please stop forwarding first\n");
1716                 return;
1717         }
1718
1719         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1720                 return;
1721
1722         if (port_is_started(res->portid) != 1) {
1723                 printf("Please start port %u first\n", res->portid);
1724                 return;
1725         }
1726
1727         if (!strcmp(res->rxtxq, "rxq"))
1728                 isrx = 1;
1729         else if (!strcmp(res->rxtxq, "txq"))
1730                 isrx = 0;
1731         else {
1732                 printf("Unknown parameter\n");
1733                 return;
1734         }
1735
1736         if (isrx && rx_queue_id_is_invalid(res->qid))
1737                 return;
1738         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1739                 return;
1740
1741         if (!strcmp(res->opname, "start"))
1742                 isstart = 1;
1743         else if (!strcmp(res->opname, "stop"))
1744                 isstart = 0;
1745         else {
1746                 printf("Unknown parameter\n");
1747                 return;
1748         }
1749
1750         if (isstart && isrx)
1751                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1752         else if (!isstart && isrx)
1753                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1754         else if (isstart && !isrx)
1755                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1756         else
1757                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1758
1759         if (ret == -ENOTSUP)
1760                 printf("Function not supported in PMD driver\n");
1761 }
1762
1763 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1765 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1766         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1767 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1768         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1769 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1770         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1771 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1772         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1773                                                 "start#stop");
1774
1775 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1776         .f = cmd_config_rxtx_queue_parsed,
1777         .data = NULL,
1778         .help_str = "port X rxq|txq ID start|stop",
1779         .tokens = {
1780                 (void *)&cmd_config_speed_all_port,
1781                 (void *)&cmd_config_rxtx_queue_portid,
1782                 (void *)&cmd_config_rxtx_queue_rxtxq,
1783                 (void *)&cmd_config_rxtx_queue_qid,
1784                 (void *)&cmd_config_rxtx_queue_opname,
1785                 NULL,
1786         },
1787 };
1788
1789 /* *** Configure RSS RETA *** */
1790 struct cmd_config_rss_reta {
1791         cmdline_fixed_string_t port;
1792         cmdline_fixed_string_t keyword;
1793         uint8_t port_id;
1794         cmdline_fixed_string_t name;
1795         cmdline_fixed_string_t list_name;
1796         cmdline_fixed_string_t list_of_items;
1797 };
1798
1799 static int
1800 parse_reta_config(const char *str,
1801                   struct rte_eth_rss_reta_entry64 *reta_conf,
1802                   uint16_t nb_entries)
1803 {
1804         int i;
1805         unsigned size;
1806         uint16_t hash_index, idx, shift;
1807         uint16_t nb_queue;
1808         char s[256];
1809         const char *p, *p0 = str;
1810         char *end;
1811         enum fieldnames {
1812                 FLD_HASH_INDEX = 0,
1813                 FLD_QUEUE,
1814                 _NUM_FLD
1815         };
1816         unsigned long int_fld[_NUM_FLD];
1817         char *str_fld[_NUM_FLD];
1818
1819         while ((p = strchr(p0,'(')) != NULL) {
1820                 ++p;
1821                 if((p0 = strchr(p,')')) == NULL)
1822                         return -1;
1823
1824                 size = p0 - p;
1825                 if(size >= sizeof(s))
1826                         return -1;
1827
1828                 snprintf(s, sizeof(s), "%.*s", size, p);
1829                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1830                         return -1;
1831                 for (i = 0; i < _NUM_FLD; i++) {
1832                         errno = 0;
1833                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1834                         if (errno != 0 || end == str_fld[i] ||
1835                                         int_fld[i] > 65535)
1836                                 return -1;
1837                 }
1838
1839                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
1840                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
1841
1842                 if (hash_index >= nb_entries) {
1843                         printf("Invalid RETA hash index=%d\n", hash_index);
1844                         return -1;
1845                 }
1846
1847                 idx = hash_index / RTE_RETA_GROUP_SIZE;
1848                 shift = hash_index % RTE_RETA_GROUP_SIZE;
1849                 reta_conf[idx].mask |= (1ULL << shift);
1850                 reta_conf[idx].reta[shift] = nb_queue;
1851         }
1852
1853         return 0;
1854 }
1855
1856 static void
1857 cmd_set_rss_reta_parsed(void *parsed_result,
1858                         __attribute__((unused)) struct cmdline *cl,
1859                         __attribute__((unused)) void *data)
1860 {
1861         int ret;
1862         struct rte_eth_dev_info dev_info;
1863         struct rte_eth_rss_reta_entry64 reta_conf[8];
1864         struct cmd_config_rss_reta *res = parsed_result;
1865
1866         memset(&dev_info, 0, sizeof(dev_info));
1867         rte_eth_dev_info_get(res->port_id, &dev_info);
1868         if (dev_info.reta_size == 0) {
1869                 printf("Redirection table size is 0 which is "
1870                                         "invalid for RSS\n");
1871                 return;
1872         } else
1873                 printf("The reta size of port %d is %u\n",
1874                         res->port_id, dev_info.reta_size);
1875         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
1876                 printf("Currently do not support more than %u entries of "
1877                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
1878                 return;
1879         }
1880
1881         memset(reta_conf, 0, sizeof(reta_conf));
1882         if (!strcmp(res->list_name, "reta")) {
1883                 if (parse_reta_config(res->list_of_items, reta_conf,
1884                                                 dev_info.reta_size)) {
1885                         printf("Invalid RSS Redirection Table "
1886                                         "config entered\n");
1887                         return;
1888                 }
1889                 ret = rte_eth_dev_rss_reta_update(res->port_id,
1890                                 reta_conf, dev_info.reta_size);
1891                 if (ret != 0)
1892                         printf("Bad redirection table parameter, "
1893                                         "return code = %d \n", ret);
1894         }
1895 }
1896
1897 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1898         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1899 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1900         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1901 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1902         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1903 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1904         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1905 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1906         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1907 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1908         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1909                                  NULL);
1910 cmdline_parse_inst_t cmd_config_rss_reta = {
1911         .f = cmd_set_rss_reta_parsed,
1912         .data = NULL,
1913         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1914         .tokens = {
1915                 (void *)&cmd_config_rss_reta_port,
1916                 (void *)&cmd_config_rss_reta_keyword,
1917                 (void *)&cmd_config_rss_reta_port_id,
1918                 (void *)&cmd_config_rss_reta_name,
1919                 (void *)&cmd_config_rss_reta_list_name,
1920                 (void *)&cmd_config_rss_reta_list_of_items,
1921                 NULL,
1922         },
1923 };
1924
1925 /* *** SHOW PORT RETA INFO *** */
1926 struct cmd_showport_reta {
1927         cmdline_fixed_string_t show;
1928         cmdline_fixed_string_t port;
1929         uint8_t port_id;
1930         cmdline_fixed_string_t rss;
1931         cmdline_fixed_string_t reta;
1932         uint16_t size;
1933         cmdline_fixed_string_t list_of_items;
1934 };
1935
1936 static int
1937 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
1938                            uint16_t nb_entries,
1939                            char *str)
1940 {
1941         uint32_t size;
1942         const char *p, *p0 = str;
1943         char s[256];
1944         char *end;
1945         char *str_fld[8];
1946         uint16_t i, num = nb_entries / RTE_RETA_GROUP_SIZE;
1947         int ret;
1948
1949         p = strchr(p0, '(');
1950         if (p == NULL)
1951                 return -1;
1952         p++;
1953         p0 = strchr(p, ')');
1954         if (p0 == NULL)
1955                 return -1;
1956         size = p0 - p;
1957         if (size >= sizeof(s)) {
1958                 printf("The string size exceeds the internal buffer size\n");
1959                 return -1;
1960         }
1961         snprintf(s, sizeof(s), "%.*s", size, p);
1962         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
1963         if (ret <= 0 || ret != num) {
1964                 printf("The bits of masks do not match the number of "
1965                                         "reta entries: %u\n", num);
1966                 return -1;
1967         }
1968         for (i = 0; i < ret; i++)
1969                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
1970
1971         return 0;
1972 }
1973
1974 static void
1975 cmd_showport_reta_parsed(void *parsed_result,
1976                          __attribute__((unused)) struct cmdline *cl,
1977                          __attribute__((unused)) void *data)
1978 {
1979         struct cmd_showport_reta *res = parsed_result;
1980         struct rte_eth_rss_reta_entry64 reta_conf[8];
1981         struct rte_eth_dev_info dev_info;
1982
1983         memset(&dev_info, 0, sizeof(dev_info));
1984         rte_eth_dev_info_get(res->port_id, &dev_info);
1985         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
1986                                 res->size > ETH_RSS_RETA_SIZE_512) {
1987                 printf("Invalid redirection table size: %u\n", res->size);
1988                 return;
1989         }
1990
1991         memset(reta_conf, 0, sizeof(reta_conf));
1992         if (showport_parse_reta_config(reta_conf, res->size,
1993                                 res->list_of_items) < 0) {
1994                 printf("Invalid string: %s for reta masks\n",
1995                                         res->list_of_items);
1996                 return;
1997         }
1998         port_rss_reta_info(res->port_id, reta_conf, res->size);
1999 }
2000
2001 cmdline_parse_token_string_t cmd_showport_reta_show =
2002         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2003 cmdline_parse_token_string_t cmd_showport_reta_port =
2004         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2005 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2006         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2007 cmdline_parse_token_string_t cmd_showport_reta_rss =
2008         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2009 cmdline_parse_token_string_t cmd_showport_reta_reta =
2010         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2011 cmdline_parse_token_num_t cmd_showport_reta_size =
2012         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2013 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2014         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2015                                         list_of_items, NULL);
2016
2017 cmdline_parse_inst_t cmd_showport_reta = {
2018         .f = cmd_showport_reta_parsed,
2019         .data = NULL,
2020         .help_str = "show port X rss reta (size) (mask0,mask1,...)",
2021         .tokens = {
2022                 (void *)&cmd_showport_reta_show,
2023                 (void *)&cmd_showport_reta_port,
2024                 (void *)&cmd_showport_reta_port_id,
2025                 (void *)&cmd_showport_reta_rss,
2026                 (void *)&cmd_showport_reta_reta,
2027                 (void *)&cmd_showport_reta_size,
2028                 (void *)&cmd_showport_reta_list_of_items,
2029                 NULL,
2030         },
2031 };
2032
2033 /* *** Show RSS hash configuration *** */
2034 struct cmd_showport_rss_hash {
2035         cmdline_fixed_string_t show;
2036         cmdline_fixed_string_t port;
2037         uint8_t port_id;
2038         cmdline_fixed_string_t rss_hash;
2039         cmdline_fixed_string_t rss_type;
2040         cmdline_fixed_string_t key; /* optional argument */
2041 };
2042
2043 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2044                                 __attribute__((unused)) struct cmdline *cl,
2045                                 void *show_rss_key)
2046 {
2047         struct cmd_showport_rss_hash *res = parsed_result;
2048
2049         port_rss_hash_conf_show(res->port_id, res->rss_type,
2050                                 show_rss_key != NULL);
2051 }
2052
2053 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2054         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2055 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2056         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2057 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2058         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2059 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2060         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2061                                  "rss-hash");
2062 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2063         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2064                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2065                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2066                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2067                                  "ipv6-tcp-ex#ipv6-udp-ex");
2068 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2069         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2070
2071 cmdline_parse_inst_t cmd_showport_rss_hash = {
2072         .f = cmd_showport_rss_hash_parsed,
2073         .data = NULL,
2074         .help_str =
2075                 "show port X rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
2076                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
2077                 "ipv6-sctp|ipv6-other|l2-payload|"
2078                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex (X = port number)\n",
2079         .tokens = {
2080                 (void *)&cmd_showport_rss_hash_show,
2081                 (void *)&cmd_showport_rss_hash_port,
2082                 (void *)&cmd_showport_rss_hash_port_id,
2083                 (void *)&cmd_showport_rss_hash_rss_hash,
2084                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2085                 NULL,
2086         },
2087 };
2088
2089 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2090         .f = cmd_showport_rss_hash_parsed,
2091         .data = (void *)1,
2092         .help_str =
2093                 "show port X rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
2094                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
2095                 "ipv6-sctp|ipv6-other|l2-payload|"
2096                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key (X = port number)\n",
2097         .tokens = {
2098                 (void *)&cmd_showport_rss_hash_show,
2099                 (void *)&cmd_showport_rss_hash_port,
2100                 (void *)&cmd_showport_rss_hash_port_id,
2101                 (void *)&cmd_showport_rss_hash_rss_hash,
2102                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2103                 (void *)&cmd_showport_rss_hash_rss_key,
2104                 NULL,
2105         },
2106 };
2107
2108 /* *** Configure DCB *** */
2109 struct cmd_config_dcb {
2110         cmdline_fixed_string_t port;
2111         cmdline_fixed_string_t config;
2112         uint8_t port_id;
2113         cmdline_fixed_string_t dcb;
2114         cmdline_fixed_string_t vt;
2115         cmdline_fixed_string_t vt_en;
2116         uint8_t num_tcs;
2117         cmdline_fixed_string_t pfc;
2118         cmdline_fixed_string_t pfc_en;
2119 };
2120
2121 static void
2122 cmd_config_dcb_parsed(void *parsed_result,
2123                         __attribute__((unused)) struct cmdline *cl,
2124                         __attribute__((unused)) void *data)
2125 {
2126         struct cmd_config_dcb *res = parsed_result;
2127         portid_t port_id = res->port_id;
2128         struct rte_port *port;
2129         uint8_t pfc_en;
2130         int ret;
2131
2132         port = &ports[port_id];
2133         /** Check if the port is not started **/
2134         if (port->port_status != RTE_PORT_STOPPED) {
2135                 printf("Please stop port %d first\n", port_id);
2136                 return;
2137         }
2138
2139         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2140                 printf("The invalid number of traffic class,"
2141                         " only 4 or 8 allowed.\n");
2142                 return;
2143         }
2144
2145         if (nb_fwd_lcores < res->num_tcs) {
2146                 printf("nb_cores shouldn't be less than number of TCs.\n");
2147                 return;
2148         }
2149         if (!strncmp(res->pfc_en, "on", 2))
2150                 pfc_en = 1;
2151         else
2152                 pfc_en = 0;
2153
2154         /* DCB in VT mode */
2155         if (!strncmp(res->vt_en, "on", 2))
2156                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2157                                 (enum rte_eth_nb_tcs)res->num_tcs,
2158                                 pfc_en);
2159         else
2160                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2161                                 (enum rte_eth_nb_tcs)res->num_tcs,
2162                                 pfc_en);
2163
2164
2165         if (ret != 0) {
2166                 printf("Cannot initialize network ports.\n");
2167                 return;
2168         }
2169
2170         cmd_reconfig_device_queue(port_id, 1, 1);
2171 }
2172
2173 cmdline_parse_token_string_t cmd_config_dcb_port =
2174         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2175 cmdline_parse_token_string_t cmd_config_dcb_config =
2176         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2177 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2178         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2179 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2180         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2181 cmdline_parse_token_string_t cmd_config_dcb_vt =
2182         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2183 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2184         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2185 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2186         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2187 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2188         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2189 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2190         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2191
2192 cmdline_parse_inst_t cmd_config_dcb = {
2193         .f = cmd_config_dcb_parsed,
2194         .data = NULL,
2195         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
2196         .tokens = {
2197                 (void *)&cmd_config_dcb_port,
2198                 (void *)&cmd_config_dcb_config,
2199                 (void *)&cmd_config_dcb_port_id,
2200                 (void *)&cmd_config_dcb_dcb,
2201                 (void *)&cmd_config_dcb_vt,
2202                 (void *)&cmd_config_dcb_vt_en,
2203                 (void *)&cmd_config_dcb_num_tcs,
2204                 (void *)&cmd_config_dcb_pfc,
2205                 (void *)&cmd_config_dcb_pfc_en,
2206                 NULL,
2207         },
2208 };
2209
2210 /* *** configure number of packets per burst *** */
2211 struct cmd_config_burst {
2212         cmdline_fixed_string_t port;
2213         cmdline_fixed_string_t keyword;
2214         cmdline_fixed_string_t all;
2215         cmdline_fixed_string_t name;
2216         uint16_t value;
2217 };
2218
2219 static void
2220 cmd_config_burst_parsed(void *parsed_result,
2221                         __attribute__((unused)) struct cmdline *cl,
2222                         __attribute__((unused)) void *data)
2223 {
2224         struct cmd_config_burst *res = parsed_result;
2225
2226         if (!all_ports_stopped()) {
2227                 printf("Please stop all ports first\n");
2228                 return;
2229         }
2230
2231         if (!strcmp(res->name, "burst")) {
2232                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2233                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2234                         return;
2235                 }
2236                 nb_pkt_per_burst = res->value;
2237         } else {
2238                 printf("Unknown parameter\n");
2239                 return;
2240         }
2241
2242         init_port_config();
2243
2244         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2245 }
2246
2247 cmdline_parse_token_string_t cmd_config_burst_port =
2248         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2249 cmdline_parse_token_string_t cmd_config_burst_keyword =
2250         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2251 cmdline_parse_token_string_t cmd_config_burst_all =
2252         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2253 cmdline_parse_token_string_t cmd_config_burst_name =
2254         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2255 cmdline_parse_token_num_t cmd_config_burst_value =
2256         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2257
2258 cmdline_parse_inst_t cmd_config_burst = {
2259         .f = cmd_config_burst_parsed,
2260         .data = NULL,
2261         .help_str = "port config all burst value",
2262         .tokens = {
2263                 (void *)&cmd_config_burst_port,
2264                 (void *)&cmd_config_burst_keyword,
2265                 (void *)&cmd_config_burst_all,
2266                 (void *)&cmd_config_burst_name,
2267                 (void *)&cmd_config_burst_value,
2268                 NULL,
2269         },
2270 };
2271
2272 /* *** configure rx/tx queues *** */
2273 struct cmd_config_thresh {
2274         cmdline_fixed_string_t port;
2275         cmdline_fixed_string_t keyword;
2276         cmdline_fixed_string_t all;
2277         cmdline_fixed_string_t name;
2278         uint8_t value;
2279 };
2280
2281 static void
2282 cmd_config_thresh_parsed(void *parsed_result,
2283                         __attribute__((unused)) struct cmdline *cl,
2284                         __attribute__((unused)) void *data)
2285 {
2286         struct cmd_config_thresh *res = parsed_result;
2287
2288         if (!all_ports_stopped()) {
2289                 printf("Please stop all ports first\n");
2290                 return;
2291         }
2292
2293         if (!strcmp(res->name, "txpt"))
2294                 tx_pthresh = res->value;
2295         else if(!strcmp(res->name, "txht"))
2296                 tx_hthresh = res->value;
2297         else if(!strcmp(res->name, "txwt"))
2298                 tx_wthresh = res->value;
2299         else if(!strcmp(res->name, "rxpt"))
2300                 rx_pthresh = res->value;
2301         else if(!strcmp(res->name, "rxht"))
2302                 rx_hthresh = res->value;
2303         else if(!strcmp(res->name, "rxwt"))
2304                 rx_wthresh = res->value;
2305         else {
2306                 printf("Unknown parameter\n");
2307                 return;
2308         }
2309
2310         init_port_config();
2311
2312         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2313 }
2314
2315 cmdline_parse_token_string_t cmd_config_thresh_port =
2316         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2317 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2318         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2319 cmdline_parse_token_string_t cmd_config_thresh_all =
2320         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2321 cmdline_parse_token_string_t cmd_config_thresh_name =
2322         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2323                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2324 cmdline_parse_token_num_t cmd_config_thresh_value =
2325         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2326
2327 cmdline_parse_inst_t cmd_config_thresh = {
2328         .f = cmd_config_thresh_parsed,
2329         .data = NULL,
2330         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
2331         .tokens = {
2332                 (void *)&cmd_config_thresh_port,
2333                 (void *)&cmd_config_thresh_keyword,
2334                 (void *)&cmd_config_thresh_all,
2335                 (void *)&cmd_config_thresh_name,
2336                 (void *)&cmd_config_thresh_value,
2337                 NULL,
2338         },
2339 };
2340
2341 /* *** configure free/rs threshold *** */
2342 struct cmd_config_threshold {
2343         cmdline_fixed_string_t port;
2344         cmdline_fixed_string_t keyword;
2345         cmdline_fixed_string_t all;
2346         cmdline_fixed_string_t name;
2347         uint16_t value;
2348 };
2349
2350 static void
2351 cmd_config_threshold_parsed(void *parsed_result,
2352                         __attribute__((unused)) struct cmdline *cl,
2353                         __attribute__((unused)) void *data)
2354 {
2355         struct cmd_config_threshold *res = parsed_result;
2356
2357         if (!all_ports_stopped()) {
2358                 printf("Please stop all ports first\n");
2359                 return;
2360         }
2361
2362         if (!strcmp(res->name, "txfreet"))
2363                 tx_free_thresh = res->value;
2364         else if (!strcmp(res->name, "txrst"))
2365                 tx_rs_thresh = res->value;
2366         else if (!strcmp(res->name, "rxfreet"))
2367                 rx_free_thresh = res->value;
2368         else {
2369                 printf("Unknown parameter\n");
2370                 return;
2371         }
2372
2373         init_port_config();
2374
2375         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2376 }
2377
2378 cmdline_parse_token_string_t cmd_config_threshold_port =
2379         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2380 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2381         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2382                                                                 "config");
2383 cmdline_parse_token_string_t cmd_config_threshold_all =
2384         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2385 cmdline_parse_token_string_t cmd_config_threshold_name =
2386         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2387                                                 "txfreet#txrst#rxfreet");
2388 cmdline_parse_token_num_t cmd_config_threshold_value =
2389         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2390
2391 cmdline_parse_inst_t cmd_config_threshold = {
2392         .f = cmd_config_threshold_parsed,
2393         .data = NULL,
2394         .help_str = "port config all txfreet|txrst|rxfreet value",
2395         .tokens = {
2396                 (void *)&cmd_config_threshold_port,
2397                 (void *)&cmd_config_threshold_keyword,
2398                 (void *)&cmd_config_threshold_all,
2399                 (void *)&cmd_config_threshold_name,
2400                 (void *)&cmd_config_threshold_value,
2401                 NULL,
2402         },
2403 };
2404
2405 /* *** stop *** */
2406 struct cmd_stop_result {
2407         cmdline_fixed_string_t stop;
2408 };
2409
2410 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2411                             __attribute__((unused)) struct cmdline *cl,
2412                             __attribute__((unused)) void *data)
2413 {
2414         stop_packet_forwarding();
2415 }
2416
2417 cmdline_parse_token_string_t cmd_stop_stop =
2418         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2419
2420 cmdline_parse_inst_t cmd_stop = {
2421         .f = cmd_stop_parsed,
2422         .data = NULL,
2423         .help_str = "stop - stop packet forwarding",
2424         .tokens = {
2425                 (void *)&cmd_stop_stop,
2426                 NULL,
2427         },
2428 };
2429
2430 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2431
2432 unsigned int
2433 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2434                 unsigned int *parsed_items, int check_unique_values)
2435 {
2436         unsigned int nb_item;
2437         unsigned int value;
2438         unsigned int i;
2439         unsigned int j;
2440         int value_ok;
2441         char c;
2442
2443         /*
2444          * First parse all items in the list and store their value.
2445          */
2446         value = 0;
2447         nb_item = 0;
2448         value_ok = 0;
2449         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2450                 c = str[i];
2451                 if ((c >= '0') && (c <= '9')) {
2452                         value = (unsigned int) (value * 10 + (c - '0'));
2453                         value_ok = 1;
2454                         continue;
2455                 }
2456                 if (c != ',') {
2457                         printf("character %c is not a decimal digit\n", c);
2458                         return 0;
2459                 }
2460                 if (! value_ok) {
2461                         printf("No valid value before comma\n");
2462                         return 0;
2463                 }
2464                 if (nb_item < max_items) {
2465                         parsed_items[nb_item] = value;
2466                         value_ok = 0;
2467                         value = 0;
2468                 }
2469                 nb_item++;
2470         }
2471         if (nb_item >= max_items) {
2472                 printf("Number of %s = %u > %u (maximum items)\n",
2473                        item_name, nb_item + 1, max_items);
2474                 return 0;
2475         }
2476         parsed_items[nb_item++] = value;
2477         if (! check_unique_values)
2478                 return nb_item;
2479
2480         /*
2481          * Then, check that all values in the list are differents.
2482          * No optimization here...
2483          */
2484         for (i = 0; i < nb_item; i++) {
2485                 for (j = i + 1; j < nb_item; j++) {
2486                         if (parsed_items[j] == parsed_items[i]) {
2487                                 printf("duplicated %s %u at index %u and %u\n",
2488                                        item_name, parsed_items[i], i, j);
2489                                 return 0;
2490                         }
2491                 }
2492         }
2493         return nb_item;
2494 }
2495
2496 struct cmd_set_list_result {
2497         cmdline_fixed_string_t cmd_keyword;
2498         cmdline_fixed_string_t list_name;
2499         cmdline_fixed_string_t list_of_items;
2500 };
2501
2502 static void cmd_set_list_parsed(void *parsed_result,
2503                                 __attribute__((unused)) struct cmdline *cl,
2504                                 __attribute__((unused)) void *data)
2505 {
2506         struct cmd_set_list_result *res;
2507         union {
2508                 unsigned int lcorelist[RTE_MAX_LCORE];
2509                 unsigned int portlist[RTE_MAX_ETHPORTS];
2510         } parsed_items;
2511         unsigned int nb_item;
2512
2513         if (test_done == 0) {
2514                 printf("Please stop forwarding first\n");
2515                 return;
2516         }
2517
2518         res = parsed_result;
2519         if (!strcmp(res->list_name, "corelist")) {
2520                 nb_item = parse_item_list(res->list_of_items, "core",
2521                                           RTE_MAX_LCORE,
2522                                           parsed_items.lcorelist, 1);
2523                 if (nb_item > 0)
2524                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2525                 return;
2526         }
2527         if (!strcmp(res->list_name, "portlist")) {
2528                 nb_item = parse_item_list(res->list_of_items, "port",
2529                                           RTE_MAX_ETHPORTS,
2530                                           parsed_items.portlist, 1);
2531                 if (nb_item > 0)
2532                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2533         }
2534 }
2535
2536 cmdline_parse_token_string_t cmd_set_list_keyword =
2537         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2538                                  "set");
2539 cmdline_parse_token_string_t cmd_set_list_name =
2540         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2541                                  "corelist#portlist");
2542 cmdline_parse_token_string_t cmd_set_list_of_items =
2543         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2544                                  NULL);
2545
2546 cmdline_parse_inst_t cmd_set_fwd_list = {
2547         .f = cmd_set_list_parsed,
2548         .data = NULL,
2549         .help_str = "set corelist|portlist x[,y]*",
2550         .tokens = {
2551                 (void *)&cmd_set_list_keyword,
2552                 (void *)&cmd_set_list_name,
2553                 (void *)&cmd_set_list_of_items,
2554                 NULL,
2555         },
2556 };
2557
2558 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2559
2560 struct cmd_setmask_result {
2561         cmdline_fixed_string_t set;
2562         cmdline_fixed_string_t mask;
2563         uint64_t hexavalue;
2564 };
2565
2566 static void cmd_set_mask_parsed(void *parsed_result,
2567                                 __attribute__((unused)) struct cmdline *cl,
2568                                 __attribute__((unused)) void *data)
2569 {
2570         struct cmd_setmask_result *res = parsed_result;
2571
2572         if (test_done == 0) {
2573                 printf("Please stop forwarding first\n");
2574                 return;
2575         }
2576         if (!strcmp(res->mask, "coremask"))
2577                 set_fwd_lcores_mask(res->hexavalue);
2578         else if (!strcmp(res->mask, "portmask"))
2579                 set_fwd_ports_mask(res->hexavalue);
2580 }
2581
2582 cmdline_parse_token_string_t cmd_setmask_set =
2583         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2584 cmdline_parse_token_string_t cmd_setmask_mask =
2585         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2586                                  "coremask#portmask");
2587 cmdline_parse_token_num_t cmd_setmask_value =
2588         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2589
2590 cmdline_parse_inst_t cmd_set_fwd_mask = {
2591         .f = cmd_set_mask_parsed,
2592         .data = NULL,
2593         .help_str = "set coremask|portmask hexadecimal value",
2594         .tokens = {
2595                 (void *)&cmd_setmask_set,
2596                 (void *)&cmd_setmask_mask,
2597                 (void *)&cmd_setmask_value,
2598                 NULL,
2599         },
2600 };
2601
2602 /*
2603  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2604  */
2605 struct cmd_set_result {
2606         cmdline_fixed_string_t set;
2607         cmdline_fixed_string_t what;
2608         uint16_t value;
2609 };
2610
2611 static void cmd_set_parsed(void *parsed_result,
2612                            __attribute__((unused)) struct cmdline *cl,
2613                            __attribute__((unused)) void *data)
2614 {
2615         struct cmd_set_result *res = parsed_result;
2616         if (!strcmp(res->what, "nbport"))
2617                 set_fwd_ports_number(res->value);
2618         else if (!strcmp(res->what, "nbcore"))
2619                 set_fwd_lcores_number(res->value);
2620         else if (!strcmp(res->what, "burst"))
2621                 set_nb_pkt_per_burst(res->value);
2622         else if (!strcmp(res->what, "verbose"))
2623                 set_verbose_level(res->value);
2624 }
2625
2626 cmdline_parse_token_string_t cmd_set_set =
2627         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2628 cmdline_parse_token_string_t cmd_set_what =
2629         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2630                                  "nbport#nbcore#burst#verbose");
2631 cmdline_parse_token_num_t cmd_set_value =
2632         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2633
2634 cmdline_parse_inst_t cmd_set_numbers = {
2635         .f = cmd_set_parsed,
2636         .data = NULL,
2637         .help_str = "set nbport|nbcore|burst|verbose value",
2638         .tokens = {
2639                 (void *)&cmd_set_set,
2640                 (void *)&cmd_set_what,
2641                 (void *)&cmd_set_value,
2642                 NULL,
2643         },
2644 };
2645
2646 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2647
2648 struct cmd_set_txpkts_result {
2649         cmdline_fixed_string_t cmd_keyword;
2650         cmdline_fixed_string_t txpkts;
2651         cmdline_fixed_string_t seg_lengths;
2652 };
2653
2654 static void
2655 cmd_set_txpkts_parsed(void *parsed_result,
2656                       __attribute__((unused)) struct cmdline *cl,
2657                       __attribute__((unused)) void *data)
2658 {
2659         struct cmd_set_txpkts_result *res;
2660         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2661         unsigned int nb_segs;
2662
2663         res = parsed_result;
2664         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2665                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2666         if (nb_segs > 0)
2667                 set_tx_pkt_segments(seg_lengths, nb_segs);
2668 }
2669
2670 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2671         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2672                                  cmd_keyword, "set");
2673 cmdline_parse_token_string_t cmd_set_txpkts_name =
2674         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2675                                  txpkts, "txpkts");
2676 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2677         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2678                                  seg_lengths, NULL);
2679
2680 cmdline_parse_inst_t cmd_set_txpkts = {
2681         .f = cmd_set_txpkts_parsed,
2682         .data = NULL,
2683         .help_str = "set txpkts x[,y]*",
2684         .tokens = {
2685                 (void *)&cmd_set_txpkts_keyword,
2686                 (void *)&cmd_set_txpkts_name,
2687                 (void *)&cmd_set_txpkts_lengths,
2688                 NULL,
2689         },
2690 };
2691
2692 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2693
2694 struct cmd_set_txsplit_result {
2695         cmdline_fixed_string_t cmd_keyword;
2696         cmdline_fixed_string_t txsplit;
2697         cmdline_fixed_string_t mode;
2698 };
2699
2700 static void
2701 cmd_set_txsplit_parsed(void *parsed_result,
2702                       __attribute__((unused)) struct cmdline *cl,
2703                       __attribute__((unused)) void *data)
2704 {
2705         struct cmd_set_txsplit_result *res;
2706
2707         res = parsed_result;
2708         set_tx_pkt_split(res->mode);
2709 }
2710
2711 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2712         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2713                                  cmd_keyword, "set");
2714 cmdline_parse_token_string_t cmd_set_txsplit_name =
2715         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2716                                  txsplit, "txsplit");
2717 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2718         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2719                                  mode, NULL);
2720
2721 cmdline_parse_inst_t cmd_set_txsplit = {
2722         .f = cmd_set_txsplit_parsed,
2723         .data = NULL,
2724         .help_str = "set txsplit on|off|rand",
2725         .tokens = {
2726                 (void *)&cmd_set_txsplit_keyword,
2727                 (void *)&cmd_set_txsplit_name,
2728                 (void *)&cmd_set_txsplit_mode,
2729                 NULL,
2730         },
2731 };
2732
2733 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2734 struct cmd_rx_vlan_filter_all_result {
2735         cmdline_fixed_string_t rx_vlan;
2736         cmdline_fixed_string_t what;
2737         cmdline_fixed_string_t all;
2738         uint8_t port_id;
2739 };
2740
2741 static void
2742 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2743                               __attribute__((unused)) struct cmdline *cl,
2744                               __attribute__((unused)) void *data)
2745 {
2746         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2747
2748         if (!strcmp(res->what, "add"))
2749                 rx_vlan_all_filter_set(res->port_id, 1);
2750         else
2751                 rx_vlan_all_filter_set(res->port_id, 0);
2752 }
2753
2754 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2755         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2756                                  rx_vlan, "rx_vlan");
2757 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2758         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2759                                  what, "add#rm");
2760 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2761         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2762                                  all, "all");
2763 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2764         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2765                               port_id, UINT8);
2766
2767 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2768         .f = cmd_rx_vlan_filter_all_parsed,
2769         .data = NULL,
2770         .help_str = "add/remove all identifiers to/from the set of VLAN "
2771         "Identifiers filtered by a port",
2772         .tokens = {
2773                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2774                 (void *)&cmd_rx_vlan_filter_all_what,
2775                 (void *)&cmd_rx_vlan_filter_all_all,
2776                 (void *)&cmd_rx_vlan_filter_all_portid,
2777                 NULL,
2778         },
2779 };
2780
2781 /* *** VLAN OFFLOAD SET ON A PORT *** */
2782 struct cmd_vlan_offload_result {
2783         cmdline_fixed_string_t vlan;
2784         cmdline_fixed_string_t set;
2785         cmdline_fixed_string_t vlan_type;
2786         cmdline_fixed_string_t what;
2787         cmdline_fixed_string_t on;
2788         cmdline_fixed_string_t port_id;
2789 };
2790
2791 static void
2792 cmd_vlan_offload_parsed(void *parsed_result,
2793                           __attribute__((unused)) struct cmdline *cl,
2794                           __attribute__((unused)) void *data)
2795 {
2796         int on;
2797         struct cmd_vlan_offload_result *res = parsed_result;
2798         char *str;
2799         int i, len = 0;
2800         portid_t port_id = 0;
2801         unsigned int tmp;
2802
2803         str = res->port_id;
2804         len = strnlen(str, STR_TOKEN_SIZE);
2805         i = 0;
2806         /* Get port_id first */
2807         while(i < len){
2808                 if(str[i] == ',')
2809                         break;
2810
2811                 i++;
2812         }
2813         str[i]='\0';
2814         tmp = strtoul(str, NULL, 0);
2815         /* If port_id greater that what portid_t can represent, return */
2816         if(tmp >= RTE_MAX_ETHPORTS)
2817                 return;
2818         port_id = (portid_t)tmp;
2819
2820         if (!strcmp(res->on, "on"))
2821                 on = 1;
2822         else
2823                 on = 0;
2824
2825         if (!strcmp(res->what, "strip"))
2826                 rx_vlan_strip_set(port_id,  on);
2827         else if(!strcmp(res->what, "stripq")){
2828                 uint16_t queue_id = 0;
2829
2830                 /* No queue_id, return */
2831                 if(i + 1 >= len) {
2832                         printf("must specify (port,queue_id)\n");
2833                         return;
2834                 }
2835                 tmp = strtoul(str + i + 1, NULL, 0);
2836                 /* If queue_id greater that what 16-bits can represent, return */
2837                 if(tmp > 0xffff)
2838                         return;
2839
2840                 queue_id = (uint16_t)tmp;
2841                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2842         }
2843         else if (!strcmp(res->what, "filter"))
2844                 rx_vlan_filter_set(port_id, on);
2845         else
2846                 vlan_extend_set(port_id, on);
2847
2848         return;
2849 }
2850
2851 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2852         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2853                                  vlan, "vlan");
2854 cmdline_parse_token_string_t cmd_vlan_offload_set =
2855         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2856                                  set, "set");
2857 cmdline_parse_token_string_t cmd_vlan_offload_what =
2858         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2859                                  what, "strip#filter#qinq#stripq");
2860 cmdline_parse_token_string_t cmd_vlan_offload_on =
2861         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2862                               on, "on#off");
2863 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2864         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2865                               port_id, NULL);
2866
2867 cmdline_parse_inst_t cmd_vlan_offload = {
2868         .f = cmd_vlan_offload_parsed,
2869         .data = NULL,
2870         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2871         " qinq(extended) for both rx/tx sides ",
2872         .tokens = {
2873                 (void *)&cmd_vlan_offload_vlan,
2874                 (void *)&cmd_vlan_offload_set,
2875                 (void *)&cmd_vlan_offload_what,
2876                 (void *)&cmd_vlan_offload_on,
2877                 (void *)&cmd_vlan_offload_portid,
2878                 NULL,
2879         },
2880 };
2881
2882 /* *** VLAN TPID SET ON A PORT *** */
2883 struct cmd_vlan_tpid_result {
2884         cmdline_fixed_string_t vlan;
2885         cmdline_fixed_string_t set;
2886         cmdline_fixed_string_t vlan_type;
2887         cmdline_fixed_string_t what;
2888         uint16_t tp_id;
2889         uint8_t port_id;
2890 };
2891
2892 static void
2893 cmd_vlan_tpid_parsed(void *parsed_result,
2894                           __attribute__((unused)) struct cmdline *cl,
2895                           __attribute__((unused)) void *data)
2896 {
2897         struct cmd_vlan_tpid_result *res = parsed_result;
2898         enum rte_vlan_type vlan_type;
2899
2900         if (!strcmp(res->vlan_type, "inner"))
2901                 vlan_type = ETH_VLAN_TYPE_INNER;
2902         else if (!strcmp(res->vlan_type, "outer"))
2903                 vlan_type = ETH_VLAN_TYPE_OUTER;
2904         else {
2905                 printf("Unknown vlan type\n");
2906                 return;
2907         }
2908         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
2909 }
2910
2911 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2912         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2913                                  vlan, "vlan");
2914 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2915         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2916                                  set, "set");
2917 cmdline_parse_token_string_t cmd_vlan_type =
2918         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2919                                  vlan_type, "inner#outer");
2920 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2921         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2922                                  what, "tpid");
2923 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2924         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2925                               tp_id, UINT16);
2926 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2927         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2928                               port_id, UINT8);
2929
2930 cmdline_parse_inst_t cmd_vlan_tpid = {
2931         .f = cmd_vlan_tpid_parsed,
2932         .data = NULL,
2933         .help_str = "set inner|outer tpid tp_id port_id, set the VLAN "
2934                     "Ether type",
2935         .tokens = {
2936                 (void *)&cmd_vlan_tpid_vlan,
2937                 (void *)&cmd_vlan_tpid_set,
2938                 (void *)&cmd_vlan_type,
2939                 (void *)&cmd_vlan_tpid_what,
2940                 (void *)&cmd_vlan_tpid_tpid,
2941                 (void *)&cmd_vlan_tpid_portid,
2942                 NULL,
2943         },
2944 };
2945
2946 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2947 struct cmd_rx_vlan_filter_result {
2948         cmdline_fixed_string_t rx_vlan;
2949         cmdline_fixed_string_t what;
2950         uint16_t vlan_id;
2951         uint8_t port_id;
2952 };
2953
2954 static void
2955 cmd_rx_vlan_filter_parsed(void *parsed_result,
2956                           __attribute__((unused)) struct cmdline *cl,
2957                           __attribute__((unused)) void *data)
2958 {
2959         struct cmd_rx_vlan_filter_result *res = parsed_result;
2960
2961         if (!strcmp(res->what, "add"))
2962                 rx_vft_set(res->port_id, res->vlan_id, 1);
2963         else
2964                 rx_vft_set(res->port_id, res->vlan_id, 0);
2965 }
2966
2967 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2968         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2969                                  rx_vlan, "rx_vlan");
2970 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2971         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2972                                  what, "add#rm");
2973 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2974         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2975                               vlan_id, UINT16);
2976 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2977         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2978                               port_id, UINT8);
2979
2980 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2981         .f = cmd_rx_vlan_filter_parsed,
2982         .data = NULL,
2983         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2984         "Identifiers filtered by a port",
2985         .tokens = {
2986                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2987                 (void *)&cmd_rx_vlan_filter_what,
2988                 (void *)&cmd_rx_vlan_filter_vlanid,
2989                 (void *)&cmd_rx_vlan_filter_portid,
2990                 NULL,
2991         },
2992 };
2993
2994 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2995 struct cmd_tx_vlan_set_result {
2996         cmdline_fixed_string_t tx_vlan;
2997         cmdline_fixed_string_t set;
2998         uint8_t port_id;
2999         uint16_t vlan_id;
3000 };
3001
3002 static void
3003 cmd_tx_vlan_set_parsed(void *parsed_result,
3004                        __attribute__((unused)) struct cmdline *cl,
3005                        __attribute__((unused)) void *data)
3006 {
3007         struct cmd_tx_vlan_set_result *res = parsed_result;
3008
3009         tx_vlan_set(res->port_id, res->vlan_id);
3010 }
3011
3012 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3013         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3014                                  tx_vlan, "tx_vlan");
3015 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3016         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3017                                  set, "set");
3018 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3019         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3020                               port_id, UINT8);
3021 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3022         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3023                               vlan_id, UINT16);
3024
3025 cmdline_parse_inst_t cmd_tx_vlan_set = {
3026         .f = cmd_tx_vlan_set_parsed,
3027         .data = NULL,
3028         .help_str = "enable hardware insertion of a single VLAN header "
3029                 "with a given TAG Identifier in packets sent on a port",
3030         .tokens = {
3031                 (void *)&cmd_tx_vlan_set_tx_vlan,
3032                 (void *)&cmd_tx_vlan_set_set,
3033                 (void *)&cmd_tx_vlan_set_portid,
3034                 (void *)&cmd_tx_vlan_set_vlanid,
3035                 NULL,
3036         },
3037 };
3038
3039 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3040 struct cmd_tx_vlan_set_qinq_result {
3041         cmdline_fixed_string_t tx_vlan;
3042         cmdline_fixed_string_t set;
3043         uint8_t port_id;
3044         uint16_t vlan_id;
3045         uint16_t vlan_id_outer;
3046 };
3047
3048 static void
3049 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3050                             __attribute__((unused)) struct cmdline *cl,
3051                             __attribute__((unused)) void *data)
3052 {
3053         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3054
3055         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3056 }
3057
3058 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3059         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3060                 tx_vlan, "tx_vlan");
3061 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3062         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3063                 set, "set");
3064 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3065         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3066                 port_id, UINT8);
3067 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3068         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3069                 vlan_id, UINT16);
3070 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3071         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3072                 vlan_id_outer, UINT16);
3073
3074 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3075         .f = cmd_tx_vlan_set_qinq_parsed,
3076         .data = NULL,
3077         .help_str = "enable hardware insertion of double VLAN header "
3078                 "with given TAG Identifiers in packets sent on a port",
3079         .tokens = {
3080                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3081                 (void *)&cmd_tx_vlan_set_qinq_set,
3082                 (void *)&cmd_tx_vlan_set_qinq_portid,
3083                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3084                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3085                 NULL,
3086         },
3087 };
3088
3089 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3090 struct cmd_tx_vlan_set_pvid_result {
3091         cmdline_fixed_string_t tx_vlan;
3092         cmdline_fixed_string_t set;
3093         cmdline_fixed_string_t pvid;
3094         uint8_t port_id;
3095         uint16_t vlan_id;
3096         cmdline_fixed_string_t mode;
3097 };
3098
3099 static void
3100 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3101                             __attribute__((unused)) struct cmdline *cl,
3102                             __attribute__((unused)) void *data)
3103 {
3104         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3105
3106         if (strcmp(res->mode, "on") == 0)
3107                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3108         else
3109                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3110 }
3111
3112 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3113         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3114                                  tx_vlan, "tx_vlan");
3115 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3116         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3117                                  set, "set");
3118 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3119         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3120                                  pvid, "pvid");
3121 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3122         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3123                              port_id, UINT8);
3124 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3125         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3126                               vlan_id, UINT16);
3127 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3128         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3129                                  mode, "on#off");
3130
3131 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3132         .f = cmd_tx_vlan_set_pvid_parsed,
3133         .data = NULL,
3134         .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
3135         .tokens = {
3136                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3137                 (void *)&cmd_tx_vlan_set_pvid_set,
3138                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3139                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3140                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3141                 (void *)&cmd_tx_vlan_set_pvid_mode,
3142                 NULL,
3143         },
3144 };
3145
3146 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3147 struct cmd_tx_vlan_reset_result {
3148         cmdline_fixed_string_t tx_vlan;
3149         cmdline_fixed_string_t reset;
3150         uint8_t port_id;
3151 };
3152
3153 static void
3154 cmd_tx_vlan_reset_parsed(void *parsed_result,
3155                          __attribute__((unused)) struct cmdline *cl,
3156                          __attribute__((unused)) void *data)
3157 {
3158         struct cmd_tx_vlan_reset_result *res = parsed_result;
3159
3160         tx_vlan_reset(res->port_id);
3161 }
3162
3163 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3164         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3165                                  tx_vlan, "tx_vlan");
3166 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3167         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3168                                  reset, "reset");
3169 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3170         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3171                               port_id, UINT8);
3172
3173 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3174         .f = cmd_tx_vlan_reset_parsed,
3175         .data = NULL,
3176         .help_str = "disable hardware insertion of a VLAN header in packets "
3177         "sent on a port",
3178         .tokens = {
3179                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3180                 (void *)&cmd_tx_vlan_reset_reset,
3181                 (void *)&cmd_tx_vlan_reset_portid,
3182                 NULL,
3183         },
3184 };
3185
3186
3187 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3188 struct cmd_csum_result {
3189         cmdline_fixed_string_t csum;
3190         cmdline_fixed_string_t mode;
3191         cmdline_fixed_string_t proto;
3192         cmdline_fixed_string_t hwsw;
3193         uint8_t port_id;
3194 };
3195
3196 static void
3197 csum_show(int port_id)
3198 {
3199         struct rte_eth_dev_info dev_info;
3200         uint16_t ol_flags;
3201
3202         ol_flags = ports[port_id].tx_ol_flags;
3203         printf("Parse tunnel is %s\n",
3204                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3205         printf("IP checksum offload is %s\n",
3206                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3207         printf("UDP checksum offload is %s\n",
3208                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3209         printf("TCP checksum offload is %s\n",
3210                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3211         printf("SCTP checksum offload is %s\n",
3212                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3213         printf("Outer-Ip checksum offload is %s\n",
3214                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3215
3216         /* display warnings if configuration is not supported by the NIC */
3217         rte_eth_dev_info_get(port_id, &dev_info);
3218         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3219                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3220                 printf("Warning: hardware IP checksum enabled but not "
3221                         "supported by port %d\n", port_id);
3222         }
3223         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3224                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3225                 printf("Warning: hardware UDP checksum enabled but not "
3226                         "supported by port %d\n", port_id);
3227         }
3228         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3229                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3230                 printf("Warning: hardware TCP checksum enabled but not "
3231                         "supported by port %d\n", port_id);
3232         }
3233         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3234                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3235                 printf("Warning: hardware SCTP checksum enabled but not "
3236                         "supported by port %d\n", port_id);
3237         }
3238         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3239                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3240                 printf("Warning: hardware outer IP checksum enabled but not "
3241                         "supported by port %d\n", port_id);
3242         }
3243 }
3244
3245 static void
3246 cmd_csum_parsed(void *parsed_result,
3247                        __attribute__((unused)) struct cmdline *cl,
3248                        __attribute__((unused)) void *data)
3249 {
3250         struct cmd_csum_result *res = parsed_result;
3251         int hw = 0;
3252         uint16_t mask = 0;
3253
3254         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3255                 printf("invalid port %d\n", res->port_id);
3256                 return;
3257         }
3258
3259         if (!strcmp(res->mode, "set")) {
3260
3261                 if (!strcmp(res->hwsw, "hw"))
3262                         hw = 1;
3263
3264                 if (!strcmp(res->proto, "ip")) {
3265                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3266                 } else if (!strcmp(res->proto, "udp")) {
3267                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3268                 } else if (!strcmp(res->proto, "tcp")) {
3269                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3270                 } else if (!strcmp(res->proto, "sctp")) {
3271                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3272                 } else if (!strcmp(res->proto, "outer-ip")) {
3273                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3274                 }
3275
3276                 if (hw)
3277                         ports[res->port_id].tx_ol_flags |= mask;
3278                 else
3279                         ports[res->port_id].tx_ol_flags &= (~mask);
3280         }
3281         csum_show(res->port_id);
3282 }
3283
3284 cmdline_parse_token_string_t cmd_csum_csum =
3285         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3286                                 csum, "csum");
3287 cmdline_parse_token_string_t cmd_csum_mode =
3288         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3289                                 mode, "set");
3290 cmdline_parse_token_string_t cmd_csum_proto =
3291         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3292                                 proto, "ip#tcp#udp#sctp#outer-ip");
3293 cmdline_parse_token_string_t cmd_csum_hwsw =
3294         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3295                                 hwsw, "hw#sw");
3296 cmdline_parse_token_num_t cmd_csum_portid =
3297         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3298                                 port_id, UINT8);
3299
3300 cmdline_parse_inst_t cmd_csum_set = {
3301         .f = cmd_csum_parsed,
3302         .data = NULL,
3303         .help_str = "enable/disable hardware calculation of L3/L4 checksum when "
3304                 "using csum forward engine: csum set ip|tcp|udp|sctp|outer-ip hw|sw <port>",
3305         .tokens = {
3306                 (void *)&cmd_csum_csum,
3307                 (void *)&cmd_csum_mode,
3308                 (void *)&cmd_csum_proto,
3309                 (void *)&cmd_csum_hwsw,
3310                 (void *)&cmd_csum_portid,
3311                 NULL,
3312         },
3313 };
3314
3315 cmdline_parse_token_string_t cmd_csum_mode_show =
3316         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3317                                 mode, "show");
3318
3319 cmdline_parse_inst_t cmd_csum_show = {
3320         .f = cmd_csum_parsed,
3321         .data = NULL,
3322         .help_str = "show checksum offload configuration: csum show <port>",
3323         .tokens = {
3324                 (void *)&cmd_csum_csum,
3325                 (void *)&cmd_csum_mode_show,
3326                 (void *)&cmd_csum_portid,
3327                 NULL,
3328         },
3329 };
3330
3331 /* Enable/disable tunnel parsing */
3332 struct cmd_csum_tunnel_result {
3333         cmdline_fixed_string_t csum;
3334         cmdline_fixed_string_t parse;
3335         cmdline_fixed_string_t onoff;
3336         uint8_t port_id;
3337 };
3338
3339 static void
3340 cmd_csum_tunnel_parsed(void *parsed_result,
3341                        __attribute__((unused)) struct cmdline *cl,
3342                        __attribute__((unused)) void *data)
3343 {
3344         struct cmd_csum_tunnel_result *res = parsed_result;
3345
3346         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3347                 return;
3348
3349         if (!strcmp(res->onoff, "on"))
3350                 ports[res->port_id].tx_ol_flags |=
3351                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3352         else
3353                 ports[res->port_id].tx_ol_flags &=
3354                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3355
3356         csum_show(res->port_id);
3357 }
3358
3359 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3360         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3361                                 csum, "csum");
3362 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3363         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3364                                 parse, "parse_tunnel");
3365 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3366         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3367                                 onoff, "on#off");
3368 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3369         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3370                                 port_id, UINT8);
3371
3372 cmdline_parse_inst_t cmd_csum_tunnel = {
3373         .f = cmd_csum_tunnel_parsed,
3374         .data = NULL,
3375         .help_str = "enable/disable parsing of tunnels for csum engine: "
3376         "csum parse_tunnel on|off <tx-port>",
3377         .tokens = {
3378                 (void *)&cmd_csum_tunnel_csum,
3379                 (void *)&cmd_csum_tunnel_parse,
3380                 (void *)&cmd_csum_tunnel_onoff,
3381                 (void *)&cmd_csum_tunnel_portid,
3382                 NULL,
3383         },
3384 };
3385
3386 /* *** ENABLE HARDWARE SEGMENTATION IN TX PACKETS *** */
3387 struct cmd_tso_set_result {
3388         cmdline_fixed_string_t tso;
3389         cmdline_fixed_string_t mode;
3390         uint16_t tso_segsz;
3391         uint8_t port_id;
3392 };
3393
3394 static void
3395 cmd_tso_set_parsed(void *parsed_result,
3396                        __attribute__((unused)) struct cmdline *cl,
3397                        __attribute__((unused)) void *data)
3398 {
3399         struct cmd_tso_set_result *res = parsed_result;
3400         struct rte_eth_dev_info dev_info;
3401
3402         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3403                 return;
3404
3405         if (!strcmp(res->mode, "set"))
3406                 ports[res->port_id].tso_segsz = res->tso_segsz;
3407
3408         if (ports[res->port_id].tso_segsz == 0)
3409                 printf("TSO is disabled\n");
3410         else
3411                 printf("TSO segment size is %d\n",
3412                         ports[res->port_id].tso_segsz);
3413
3414         /* display warnings if configuration is not supported by the NIC */
3415         rte_eth_dev_info_get(res->port_id, &dev_info);
3416         if ((ports[res->port_id].tso_segsz != 0) &&
3417                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3418                 printf("Warning: TSO enabled but not "
3419                         "supported by port %d\n", res->port_id);
3420         }
3421 }
3422
3423 cmdline_parse_token_string_t cmd_tso_set_tso =
3424         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3425                                 tso, "tso");
3426 cmdline_parse_token_string_t cmd_tso_set_mode =
3427         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3428                                 mode, "set");
3429 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3430         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3431                                 tso_segsz, UINT16);
3432 cmdline_parse_token_num_t cmd_tso_set_portid =
3433         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3434                                 port_id, UINT8);
3435
3436 cmdline_parse_inst_t cmd_tso_set = {
3437         .f = cmd_tso_set_parsed,
3438         .data = NULL,
3439         .help_str = "Set TSO segment size for csum engine (0 to disable): "
3440         "tso set <tso_segsz> <port>",
3441         .tokens = {
3442                 (void *)&cmd_tso_set_tso,
3443                 (void *)&cmd_tso_set_mode,
3444                 (void *)&cmd_tso_set_tso_segsz,
3445                 (void *)&cmd_tso_set_portid,
3446                 NULL,
3447         },
3448 };
3449
3450 cmdline_parse_token_string_t cmd_tso_show_mode =
3451         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3452                                 mode, "show");
3453
3454
3455 cmdline_parse_inst_t cmd_tso_show = {
3456         .f = cmd_tso_set_parsed,
3457         .data = NULL,
3458         .help_str = "Show TSO segment size for csum engine: "
3459         "tso show <port>",
3460         .tokens = {
3461                 (void *)&cmd_tso_set_tso,
3462                 (void *)&cmd_tso_show_mode,
3463                 (void *)&cmd_tso_set_portid,
3464                 NULL,
3465         },
3466 };
3467
3468 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3469 struct cmd_set_flush_rx {
3470         cmdline_fixed_string_t set;
3471         cmdline_fixed_string_t flush_rx;
3472         cmdline_fixed_string_t mode;
3473 };
3474
3475 static void
3476 cmd_set_flush_rx_parsed(void *parsed_result,
3477                 __attribute__((unused)) struct cmdline *cl,
3478                 __attribute__((unused)) void *data)
3479 {
3480         struct cmd_set_flush_rx *res = parsed_result;
3481         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3482 }
3483
3484 cmdline_parse_token_string_t cmd_setflushrx_set =
3485         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3486                         set, "set");
3487 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3488         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3489                         flush_rx, "flush_rx");
3490 cmdline_parse_token_string_t cmd_setflushrx_mode =
3491         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3492                         mode, "on#off");
3493
3494
3495 cmdline_parse_inst_t cmd_set_flush_rx = {
3496         .f = cmd_set_flush_rx_parsed,
3497         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
3498         .data = NULL,
3499         .tokens = {
3500                 (void *)&cmd_setflushrx_set,
3501                 (void *)&cmd_setflushrx_flush_rx,
3502                 (void *)&cmd_setflushrx_mode,
3503                 NULL,
3504         },
3505 };
3506
3507 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3508 struct cmd_set_link_check {
3509         cmdline_fixed_string_t set;
3510         cmdline_fixed_string_t link_check;
3511         cmdline_fixed_string_t mode;
3512 };
3513
3514 static void
3515 cmd_set_link_check_parsed(void *parsed_result,
3516                 __attribute__((unused)) struct cmdline *cl,
3517                 __attribute__((unused)) void *data)
3518 {
3519         struct cmd_set_link_check *res = parsed_result;
3520         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3521 }
3522
3523 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3524         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3525                         set, "set");
3526 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3527         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3528                         link_check, "link_check");
3529 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3530         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3531                         mode, "on#off");
3532
3533
3534 cmdline_parse_inst_t cmd_set_link_check = {
3535         .f = cmd_set_link_check_parsed,
3536         .help_str = "set link_check on|off: enable/disable link status check "
3537                     "when starting/stopping a port",
3538         .data = NULL,
3539         .tokens = {
3540                 (void *)&cmd_setlinkcheck_set,
3541                 (void *)&cmd_setlinkcheck_link_check,
3542                 (void *)&cmd_setlinkcheck_mode,
3543                 NULL,
3544         },
3545 };
3546
3547 #ifdef RTE_NIC_BYPASS
3548 /* *** SET NIC BYPASS MODE *** */
3549 struct cmd_set_bypass_mode_result {
3550         cmdline_fixed_string_t set;
3551         cmdline_fixed_string_t bypass;
3552         cmdline_fixed_string_t mode;
3553         cmdline_fixed_string_t value;
3554         uint8_t port_id;
3555 };
3556
3557 static void
3558 cmd_set_bypass_mode_parsed(void *parsed_result,
3559                 __attribute__((unused)) struct cmdline *cl,
3560                 __attribute__((unused)) void *data)
3561 {
3562         struct cmd_set_bypass_mode_result *res = parsed_result;
3563         portid_t port_id = res->port_id;
3564         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3565
3566         if (!bypass_is_supported(port_id))
3567                 return;
3568
3569         if (!strcmp(res->value, "bypass"))
3570                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3571         else if (!strcmp(res->value, "isolate"))
3572                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3573         else
3574                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3575
3576         /* Set the bypass mode for the relevant port. */
3577         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3578                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3579         }
3580 }
3581
3582 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3583         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3584                         set, "set");
3585 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3586         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3587                         bypass, "bypass");
3588 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3589         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3590                         mode, "mode");
3591 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3592         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3593                         value, "normal#bypass#isolate");
3594 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3595         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3596                                 port_id, UINT8);
3597
3598 cmdline_parse_inst_t cmd_set_bypass_mode = {
3599         .f = cmd_set_bypass_mode_parsed,
3600         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
3601                     "Set the NIC bypass mode for port_id",
3602         .data = NULL,
3603         .tokens = {
3604                 (void *)&cmd_setbypass_mode_set,
3605                 (void *)&cmd_setbypass_mode_bypass,
3606                 (void *)&cmd_setbypass_mode_mode,
3607                 (void *)&cmd_setbypass_mode_value,
3608                 (void *)&cmd_setbypass_mode_port,
3609                 NULL,
3610         },
3611 };
3612
3613 /* *** SET NIC BYPASS EVENT *** */
3614 struct cmd_set_bypass_event_result {
3615         cmdline_fixed_string_t set;
3616         cmdline_fixed_string_t bypass;
3617         cmdline_fixed_string_t event;
3618         cmdline_fixed_string_t event_value;
3619         cmdline_fixed_string_t mode;
3620         cmdline_fixed_string_t mode_value;
3621         uint8_t port_id;
3622 };
3623
3624 static void
3625 cmd_set_bypass_event_parsed(void *parsed_result,
3626                 __attribute__((unused)) struct cmdline *cl,
3627                 __attribute__((unused)) void *data)
3628 {
3629         int32_t rc;
3630         struct cmd_set_bypass_event_result *res = parsed_result;
3631         portid_t port_id = res->port_id;
3632         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3633         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3634
3635         if (!bypass_is_supported(port_id))
3636                 return;
3637
3638         if (!strcmp(res->event_value, "timeout"))
3639                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3640         else if (!strcmp(res->event_value, "os_on"))
3641                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3642         else if (!strcmp(res->event_value, "os_off"))
3643                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3644         else if (!strcmp(res->event_value, "power_on"))
3645                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3646         else if (!strcmp(res->event_value, "power_off"))
3647                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3648         else
3649                 bypass_event = RTE_BYPASS_EVENT_NONE;
3650
3651         if (!strcmp(res->mode_value, "bypass"))
3652                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3653         else if (!strcmp(res->mode_value, "isolate"))
3654                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3655         else
3656                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3657
3658         /* Set the watchdog timeout. */
3659         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3660
3661                 rc = -EINVAL;
3662                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3663                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3664                                 bypass_timeout)) != 0) {
3665                         printf("Failed to set timeout value %u "
3666                                 "for port %d, errto code: %d.\n",
3667                                 bypass_timeout, port_id, rc);
3668                 }
3669         }
3670
3671         /* Set the bypass event to transition to bypass mode. */
3672         if (0 != rte_eth_dev_bypass_event_store(port_id,
3673                         bypass_event, bypass_mode)) {
3674                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3675         }
3676
3677 }
3678
3679 cmdline_parse_token_string_t cmd_setbypass_event_set =
3680         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3681                         set, "set");
3682 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3683         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3684                         bypass, "bypass");
3685 cmdline_parse_token_string_t cmd_setbypass_event_event =
3686         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3687                         event, "event");
3688 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
3689         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3690                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
3691 cmdline_parse_token_string_t cmd_setbypass_event_mode =
3692         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3693                         mode, "mode");
3694 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
3695         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3696                         mode_value, "normal#bypass#isolate");
3697 cmdline_parse_token_num_t cmd_setbypass_event_port =
3698         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
3699                                 port_id, UINT8);
3700
3701 cmdline_parse_inst_t cmd_set_bypass_event = {
3702         .f = cmd_set_bypass_event_parsed,
3703         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
3704                     "mode (normal|bypass|isolate) (port_id): "
3705                     "Set the NIC bypass event mode for port_id",
3706         .data = NULL,
3707         .tokens = {
3708                 (void *)&cmd_setbypass_event_set,
3709                 (void *)&cmd_setbypass_event_bypass,
3710                 (void *)&cmd_setbypass_event_event,
3711                 (void *)&cmd_setbypass_event_event_value,
3712                 (void *)&cmd_setbypass_event_mode,
3713                 (void *)&cmd_setbypass_event_mode_value,
3714                 (void *)&cmd_setbypass_event_port,
3715                 NULL,
3716         },
3717 };
3718
3719
3720 /* *** SET NIC BYPASS TIMEOUT *** */
3721 struct cmd_set_bypass_timeout_result {
3722         cmdline_fixed_string_t set;
3723         cmdline_fixed_string_t bypass;
3724         cmdline_fixed_string_t timeout;
3725         cmdline_fixed_string_t value;
3726 };
3727
3728 static void
3729 cmd_set_bypass_timeout_parsed(void *parsed_result,
3730                 __attribute__((unused)) struct cmdline *cl,
3731                 __attribute__((unused)) void *data)
3732 {
3733         struct cmd_set_bypass_timeout_result *res = parsed_result;
3734
3735         if (!strcmp(res->value, "1.5"))
3736                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
3737         else if (!strcmp(res->value, "2"))
3738                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
3739         else if (!strcmp(res->value, "3"))
3740                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
3741         else if (!strcmp(res->value, "4"))
3742                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
3743         else if (!strcmp(res->value, "8"))
3744                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
3745         else if (!strcmp(res->value, "16"))
3746                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
3747         else if (!strcmp(res->value, "32"))
3748                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
3749         else
3750                 bypass_timeout = RTE_BYPASS_TMT_OFF;
3751 }
3752
3753 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
3754         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3755                         set, "set");
3756 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
3757         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3758                         bypass, "bypass");
3759 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
3760         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3761                         timeout, "timeout");
3762 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
3763         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3764                         value, "0#1.5#2#3#4#8#16#32");
3765
3766 cmdline_parse_inst_t cmd_set_bypass_timeout = {
3767         .f = cmd_set_bypass_timeout_parsed,
3768         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
3769                     "Set the NIC bypass watchdog timeout",
3770         .data = NULL,
3771         .tokens = {
3772                 (void *)&cmd_setbypass_timeout_set,
3773                 (void *)&cmd_setbypass_timeout_bypass,
3774                 (void *)&cmd_setbypass_timeout_timeout,
3775                 (void *)&cmd_setbypass_timeout_value,
3776                 NULL,
3777         },
3778 };
3779
3780 /* *** SHOW NIC BYPASS MODE *** */
3781 struct cmd_show_bypass_config_result {
3782         cmdline_fixed_string_t show;
3783         cmdline_fixed_string_t bypass;
3784         cmdline_fixed_string_t config;
3785         uint8_t port_id;
3786 };
3787
3788 static void
3789 cmd_show_bypass_config_parsed(void *parsed_result,
3790                 __attribute__((unused)) struct cmdline *cl,
3791                 __attribute__((unused)) void *data)
3792 {
3793         struct cmd_show_bypass_config_result *res = parsed_result;
3794         uint32_t event_mode;
3795         uint32_t bypass_mode;
3796         portid_t port_id = res->port_id;
3797         uint32_t timeout = bypass_timeout;
3798         int i;
3799
3800         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
3801                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
3802         static const char * const modes[RTE_BYPASS_MODE_NUM] =
3803                 {"UNKNOWN", "normal", "bypass", "isolate"};
3804         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
3805                 "NONE",
3806                 "OS/board on",
3807                 "power supply on",
3808                 "OS/board off",
3809                 "power supply off",
3810                 "timeout"};
3811         int num_events = (sizeof events) / (sizeof events[0]);
3812
3813         if (!bypass_is_supported(port_id))
3814                 return;
3815
3816         /* Display the bypass mode.*/
3817         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
3818                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
3819                 return;
3820         }
3821         else {
3822                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
3823                         bypass_mode = RTE_BYPASS_MODE_NONE;
3824
3825                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
3826         }
3827
3828         /* Display the bypass timeout.*/
3829         if (!RTE_BYPASS_TMT_VALID(timeout))
3830                 timeout = RTE_BYPASS_TMT_OFF;
3831
3832         printf("\tbypass timeout = %s\n", timeouts[timeout]);
3833
3834         /* Display the bypass events and associated modes. */
3835         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
3836
3837                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
3838                         printf("\tFailed to get bypass mode for event = %s\n",
3839                                 events[i]);
3840                 } else {
3841                         if (!RTE_BYPASS_MODE_VALID(event_mode))
3842                                 event_mode = RTE_BYPASS_MODE_NONE;
3843
3844                         printf("\tbypass event: %-16s = %s\n", events[i],
3845                                 modes[event_mode]);
3846                 }
3847         }
3848 }
3849
3850 cmdline_parse_token_string_t cmd_showbypass_config_show =
3851         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3852                         show, "show");
3853 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
3854         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3855                         bypass, "bypass");
3856 cmdline_parse_token_string_t cmd_showbypass_config_config =
3857         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3858                         config, "config");
3859 cmdline_parse_token_num_t cmd_showbypass_config_port =
3860         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
3861                                 port_id, UINT8);
3862
3863 cmdline_parse_inst_t cmd_show_bypass_config = {
3864         .f = cmd_show_bypass_config_parsed,
3865         .help_str = "show bypass config (port_id): "
3866                     "Show the NIC bypass config for port_id",
3867         .data = NULL,
3868         .tokens = {
3869                 (void *)&cmd_showbypass_config_show,
3870                 (void *)&cmd_showbypass_config_bypass,
3871                 (void *)&cmd_showbypass_config_config,
3872                 (void *)&cmd_showbypass_config_port,
3873                 NULL,
3874         },
3875 };
3876 #endif
3877
3878 #ifdef RTE_LIBRTE_PMD_BOND
3879 /* *** SET BONDING MODE *** */
3880 struct cmd_set_bonding_mode_result {
3881         cmdline_fixed_string_t set;
3882         cmdline_fixed_string_t bonding;
3883         cmdline_fixed_string_t mode;
3884         uint8_t value;
3885         uint8_t port_id;
3886 };
3887
3888 static void cmd_set_bonding_mode_parsed(void *parsed_result,
3889                 __attribute__((unused))  struct cmdline *cl,
3890                 __attribute__((unused)) void *data)
3891 {
3892         struct cmd_set_bonding_mode_result *res = parsed_result;
3893         portid_t port_id = res->port_id;
3894
3895         /* Set the bonding mode for the relevant port. */
3896         if (0 != rte_eth_bond_mode_set(port_id, res->value))
3897                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
3898 }
3899
3900 cmdline_parse_token_string_t cmd_setbonding_mode_set =
3901 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3902                 set, "set");
3903 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
3904 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3905                 bonding, "bonding");
3906 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
3907 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3908                 mode, "mode");
3909 cmdline_parse_token_num_t cmd_setbonding_mode_value =
3910 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3911                 value, UINT8);
3912 cmdline_parse_token_num_t cmd_setbonding_mode_port =
3913 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3914                 port_id, UINT8);
3915
3916 cmdline_parse_inst_t cmd_set_bonding_mode = {
3917                 .f = cmd_set_bonding_mode_parsed,
3918                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
3919                 .data = NULL,
3920                 .tokens = {
3921                                 (void *) &cmd_setbonding_mode_set,
3922                                 (void *) &cmd_setbonding_mode_bonding,
3923                                 (void *) &cmd_setbonding_mode_mode,
3924                                 (void *) &cmd_setbonding_mode_value,
3925                                 (void *) &cmd_setbonding_mode_port,
3926                                 NULL
3927                 }
3928 };
3929
3930 /* *** SET BALANCE XMIT POLICY *** */
3931 struct cmd_set_bonding_balance_xmit_policy_result {
3932         cmdline_fixed_string_t set;
3933         cmdline_fixed_string_t bonding;
3934         cmdline_fixed_string_t balance_xmit_policy;
3935         uint8_t port_id;
3936         cmdline_fixed_string_t policy;
3937 };
3938
3939 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
3940                 __attribute__((unused))  struct cmdline *cl,
3941                 __attribute__((unused)) void *data)
3942 {
3943         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
3944         portid_t port_id = res->port_id;
3945         uint8_t policy;
3946
3947         if (!strcmp(res->policy, "l2")) {
3948                 policy = BALANCE_XMIT_POLICY_LAYER2;
3949         } else if (!strcmp(res->policy, "l23")) {
3950                 policy = BALANCE_XMIT_POLICY_LAYER23;
3951         } else if (!strcmp(res->policy, "l34")) {
3952                 policy = BALANCE_XMIT_POLICY_LAYER34;
3953         } else {
3954                 printf("\t Invalid xmit policy selection");
3955                 return;
3956         }
3957
3958         /* Set the bonding mode for the relevant port. */
3959         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
3960                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
3961                                 port_id);
3962         }
3963 }
3964
3965 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
3966 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3967                 set, "set");
3968 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
3969 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3970                 bonding, "bonding");
3971 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
3972 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3973                 balance_xmit_policy, "balance_xmit_policy");
3974 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
3975 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3976                 port_id, UINT8);
3977 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
3978 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3979                 policy, "l2#l23#l34");
3980
3981 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
3982                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
3983                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
3984                 .data = NULL,
3985                 .tokens = {
3986                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
3987                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
3988                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
3989                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
3990                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
3991                                 NULL
3992                 }
3993 };
3994
3995 /* *** SHOW NIC BONDING CONFIGURATION *** */
3996 struct cmd_show_bonding_config_result {
3997         cmdline_fixed_string_t show;
3998         cmdline_fixed_string_t bonding;
3999         cmdline_fixed_string_t config;
4000         uint8_t port_id;
4001 };
4002
4003 static void cmd_show_bonding_config_parsed(void *parsed_result,
4004                 __attribute__((unused))  struct cmdline *cl,
4005                 __attribute__((unused)) void *data)
4006 {
4007         struct cmd_show_bonding_config_result *res = parsed_result;
4008         int bonding_mode;
4009         uint8_t slaves[RTE_MAX_ETHPORTS];
4010         int num_slaves, num_active_slaves;
4011         int primary_id;
4012         int i;
4013         portid_t port_id = res->port_id;
4014
4015         /* Display the bonding mode.*/
4016         bonding_mode = rte_eth_bond_mode_get(port_id);
4017         if (bonding_mode < 0) {
4018                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4019                 return;
4020         } else
4021                 printf("\tBonding mode: %d\n", bonding_mode);
4022
4023         if (bonding_mode == BONDING_MODE_BALANCE) {
4024                 int balance_xmit_policy;
4025
4026                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4027                 if (balance_xmit_policy < 0) {
4028                         printf("\tFailed to get balance xmit policy for port = %d\n",
4029                                         port_id);
4030                         return;
4031                 } else {
4032                         printf("\tBalance Xmit Policy: ");
4033
4034                         switch (balance_xmit_policy) {
4035                         case BALANCE_XMIT_POLICY_LAYER2:
4036                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4037                                 break;
4038                         case BALANCE_XMIT_POLICY_LAYER23:
4039                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4040                                 break;
4041                         case BALANCE_XMIT_POLICY_LAYER34:
4042                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4043                                 break;
4044                         }
4045                         printf("\n");
4046                 }
4047         }
4048
4049         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4050
4051         if (num_slaves < 0) {
4052                 printf("\tFailed to get slave list for port = %d\n", port_id);
4053                 return;
4054         }
4055         if (num_slaves > 0) {
4056                 printf("\tSlaves (%d): [", num_slaves);
4057                 for (i = 0; i < num_slaves - 1; i++)
4058                         printf("%d ", slaves[i]);
4059
4060                 printf("%d]\n", slaves[num_slaves - 1]);
4061         } else {
4062                 printf("\tSlaves: []\n");
4063
4064         }
4065
4066         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4067                         RTE_MAX_ETHPORTS);
4068
4069         if (num_active_slaves < 0) {
4070                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4071                 return;
4072         }
4073         if (num_active_slaves > 0) {
4074                 printf("\tActive Slaves (%d): [", num_active_slaves);
4075                 for (i = 0; i < num_active_slaves - 1; i++)
4076                         printf("%d ", slaves[i]);
4077
4078                 printf("%d]\n", slaves[num_active_slaves - 1]);
4079
4080         } else {
4081                 printf("\tActive Slaves: []\n");
4082
4083         }
4084
4085         primary_id = rte_eth_bond_primary_get(port_id);
4086         if (primary_id < 0) {
4087                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4088                 return;
4089         } else
4090                 printf("\tPrimary: [%d]\n", primary_id);
4091
4092 }
4093
4094 cmdline_parse_token_string_t cmd_showbonding_config_show =
4095 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4096                 show, "show");
4097 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4098 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4099                 bonding, "bonding");
4100 cmdline_parse_token_string_t cmd_showbonding_config_config =
4101 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4102                 config, "config");
4103 cmdline_parse_token_num_t cmd_showbonding_config_port =
4104 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4105                 port_id, UINT8);
4106
4107 cmdline_parse_inst_t cmd_show_bonding_config = {
4108                 .f = cmd_show_bonding_config_parsed,
4109                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
4110                 .data = NULL,
4111                 .tokens = {
4112                                 (void *)&cmd_showbonding_config_show,
4113                                 (void *)&cmd_showbonding_config_bonding,
4114                                 (void *)&cmd_showbonding_config_config,
4115                                 (void *)&cmd_showbonding_config_port,
4116                                 NULL
4117                 }
4118 };
4119
4120 /* *** SET BONDING PRIMARY *** */
4121 struct cmd_set_bonding_primary_result {
4122         cmdline_fixed_string_t set;
4123         cmdline_fixed_string_t bonding;
4124         cmdline_fixed_string_t primary;
4125         uint8_t slave_id;
4126         uint8_t port_id;
4127 };
4128
4129 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4130                 __attribute__((unused))  struct cmdline *cl,
4131                 __attribute__((unused)) void *data)
4132 {
4133         struct cmd_set_bonding_primary_result *res = parsed_result;
4134         portid_t master_port_id = res->port_id;
4135         portid_t slave_port_id = res->slave_id;
4136
4137         /* Set the primary slave for a bonded device. */
4138         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4139                 printf("\t Failed to set primary slave for port = %d.\n",
4140                                 master_port_id);
4141                 return;
4142         }
4143         init_port_config();
4144 }
4145
4146 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4147 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4148                 set, "set");
4149 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4150 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4151                 bonding, "bonding");
4152 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4153 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4154                 primary, "primary");
4155 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4156 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4157                 slave_id, UINT8);
4158 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4159 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4160                 port_id, UINT8);
4161
4162 cmdline_parse_inst_t cmd_set_bonding_primary = {
4163                 .f = cmd_set_bonding_primary_parsed,
4164                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
4165                 .data = NULL,
4166                 .tokens = {
4167                                 (void *)&cmd_setbonding_primary_set,
4168                                 (void *)&cmd_setbonding_primary_bonding,
4169                                 (void *)&cmd_setbonding_primary_primary,
4170                                 (void *)&cmd_setbonding_primary_slave,
4171                                 (void *)&cmd_setbonding_primary_port,
4172                                 NULL
4173                 }
4174 };
4175
4176 /* *** ADD SLAVE *** */
4177 struct cmd_add_bonding_slave_result {
4178         cmdline_fixed_string_t add;
4179         cmdline_fixed_string_t bonding;
4180         cmdline_fixed_string_t slave;
4181         uint8_t slave_id;
4182         uint8_t port_id;
4183 };
4184
4185 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4186                 __attribute__((unused))  struct cmdline *cl,
4187                 __attribute__((unused)) void *data)
4188 {
4189         struct cmd_add_bonding_slave_result *res = parsed_result;
4190         portid_t master_port_id = res->port_id;
4191         portid_t slave_port_id = res->slave_id;
4192
4193         /* Set the primary slave for a bonded device. */
4194         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4195                 printf("\t Failed to add slave %d to master port = %d.\n",
4196                                 slave_port_id, master_port_id);
4197                 return;
4198         }
4199         init_port_config();
4200         set_port_slave_flag(slave_port_id);
4201 }
4202
4203 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4204 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4205                 add, "add");
4206 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4207 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4208                 bonding, "bonding");
4209 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4210 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4211                 slave, "slave");
4212 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4213 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4214                 slave_id, UINT8);
4215 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4216 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4217                 port_id, UINT8);
4218
4219 cmdline_parse_inst_t cmd_add_bonding_slave = {
4220                 .f = cmd_add_bonding_slave_parsed,
4221                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
4222                 .data = NULL,
4223                 .tokens = {
4224                                 (void *)&cmd_addbonding_slave_add,
4225                                 (void *)&cmd_addbonding_slave_bonding,
4226                                 (void *)&cmd_addbonding_slave_slave,
4227                                 (void *)&cmd_addbonding_slave_slaveid,
4228                                 (void *)&cmd_addbonding_slave_port,
4229                                 NULL
4230                 }
4231 };
4232
4233 /* *** REMOVE SLAVE *** */
4234 struct cmd_remove_bonding_slave_result {
4235         cmdline_fixed_string_t remove;
4236         cmdline_fixed_string_t bonding;
4237         cmdline_fixed_string_t slave;
4238         uint8_t slave_id;
4239         uint8_t port_id;
4240 };
4241
4242 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4243                 __attribute__((unused))  struct cmdline *cl,
4244                 __attribute__((unused)) void *data)
4245 {
4246         struct cmd_remove_bonding_slave_result *res = parsed_result;
4247         portid_t master_port_id = res->port_id;
4248         portid_t slave_port_id = res->slave_id;
4249
4250         /* Set the primary slave for a bonded device. */
4251         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4252                 printf("\t Failed to remove slave %d from master port = %d.\n",
4253                                 slave_port_id, master_port_id);
4254                 return;
4255         }
4256         init_port_config();
4257         clear_port_slave_flag(slave_port_id);
4258 }
4259
4260 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4261                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4262                                 remove, "remove");
4263 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4264                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4265                                 bonding, "bonding");
4266 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4267                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4268                                 slave, "slave");
4269 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4270                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4271                                 slave_id, UINT8);
4272 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4273                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4274                                 port_id, UINT8);
4275
4276 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4277                 .f = cmd_remove_bonding_slave_parsed,
4278                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
4279                 .data = NULL,
4280                 .tokens = {
4281                                 (void *)&cmd_removebonding_slave_remove,
4282                                 (void *)&cmd_removebonding_slave_bonding,
4283                                 (void *)&cmd_removebonding_slave_slave,
4284                                 (void *)&cmd_removebonding_slave_slaveid,
4285                                 (void *)&cmd_removebonding_slave_port,
4286                                 NULL
4287                 }
4288 };
4289
4290 /* *** CREATE BONDED DEVICE *** */
4291 struct cmd_create_bonded_device_result {
4292         cmdline_fixed_string_t create;
4293         cmdline_fixed_string_t bonded;
4294         cmdline_fixed_string_t device;
4295         uint8_t mode;
4296         uint8_t socket;
4297 };
4298
4299 static int bond_dev_num = 0;
4300
4301 static void cmd_create_bonded_device_parsed(void *parsed_result,
4302                 __attribute__((unused))  struct cmdline *cl,
4303                 __attribute__((unused)) void *data)
4304 {
4305         struct cmd_create_bonded_device_result *res = parsed_result;
4306         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4307         int port_id;
4308
4309         if (test_done == 0) {
4310                 printf("Please stop forwarding first\n");
4311                 return;
4312         }
4313
4314         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
4315                         bond_dev_num++);
4316
4317         /* Create a new bonded device. */
4318         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4319         if (port_id < 0) {
4320                 printf("\t Failed to create bonded device.\n");
4321                 return;
4322         } else {
4323                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4324                                 port_id);
4325
4326                 /* Update number of ports */
4327                 nb_ports = rte_eth_dev_count();
4328                 reconfig(port_id, res->socket);
4329                 rte_eth_promiscuous_enable(port_id);
4330                 ports[port_id].enabled = 1;
4331         }
4332
4333 }
4334
4335 cmdline_parse_token_string_t cmd_createbonded_device_create =
4336                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4337                                 create, "create");
4338 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4339                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4340                                 bonded, "bonded");
4341 cmdline_parse_token_string_t cmd_createbonded_device_device =
4342                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4343                                 device, "device");
4344 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4345                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4346                                 mode, UINT8);
4347 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4348                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4349                                 socket, UINT8);
4350
4351 cmdline_parse_inst_t cmd_create_bonded_device = {
4352                 .f = cmd_create_bonded_device_parsed,
4353                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
4354                 .data = NULL,
4355                 .tokens = {
4356                                 (void *)&cmd_createbonded_device_create,
4357                                 (void *)&cmd_createbonded_device_bonded,
4358                                 (void *)&cmd_createbonded_device_device,
4359                                 (void *)&cmd_createbonded_device_mode,
4360                                 (void *)&cmd_createbonded_device_socket,
4361                                 NULL
4362                 }
4363 };
4364
4365 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4366 struct cmd_set_bond_mac_addr_result {
4367         cmdline_fixed_string_t set;
4368         cmdline_fixed_string_t bonding;
4369         cmdline_fixed_string_t mac_addr;
4370         uint8_t port_num;
4371         struct ether_addr address;
4372 };
4373
4374 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4375                 __attribute__((unused))  struct cmdline *cl,
4376                 __attribute__((unused)) void *data)
4377 {
4378         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4379         int ret;
4380
4381         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4382                 return;
4383
4384         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4385
4386         /* check the return value and print it if is < 0 */
4387         if (ret < 0)
4388                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4389 }
4390
4391 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4392                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4393 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4394                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4395                                 "bonding");
4396 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4397                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4398                                 "mac_addr");
4399 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4400                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4401 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4402                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4403
4404 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4405                 .f = cmd_set_bond_mac_addr_parsed,
4406                 .data = (void *) 0,
4407                 .help_str = "set bonding mac_addr (port_id) (address): ",
4408                 .tokens = {
4409                                 (void *)&cmd_set_bond_mac_addr_set,
4410                                 (void *)&cmd_set_bond_mac_addr_bonding,
4411                                 (void *)&cmd_set_bond_mac_addr_mac,
4412                                 (void *)&cmd_set_bond_mac_addr_portnum,
4413                                 (void *)&cmd_set_bond_mac_addr_addr,
4414                                 NULL
4415                 }
4416 };
4417
4418
4419 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4420 struct cmd_set_bond_mon_period_result {
4421         cmdline_fixed_string_t set;
4422         cmdline_fixed_string_t bonding;
4423         cmdline_fixed_string_t mon_period;
4424         uint8_t port_num;
4425         uint32_t period_ms;
4426 };
4427
4428 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4429                 __attribute__((unused))  struct cmdline *cl,
4430                 __attribute__((unused)) void *data)
4431 {
4432         struct cmd_set_bond_mon_period_result *res = parsed_result;
4433         int ret;
4434
4435         if (res->port_num >= nb_ports) {
4436                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4437                 return;
4438         }
4439
4440         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4441
4442         /* check the return value and print it if is < 0 */
4443         if (ret < 0)
4444                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4445 }
4446
4447 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4448                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4449                                 set, "set");
4450 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4451                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4452                                 bonding, "bonding");
4453 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4454                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4455                                 mon_period,     "mon_period");
4456 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4457                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4458                                 port_num, UINT8);
4459 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4460                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4461                                 period_ms, UINT32);
4462
4463 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4464                 .f = cmd_set_bond_mon_period_parsed,
4465                 .data = (void *) 0,
4466                 .help_str = "set bonding mon_period (port_id) (period_ms): ",
4467                 .tokens = {
4468                                 (void *)&cmd_set_bond_mon_period_set,
4469                                 (void *)&cmd_set_bond_mon_period_bonding,
4470                                 (void *)&cmd_set_bond_mon_period_mon_period,
4471                                 (void *)&cmd_set_bond_mon_period_portnum,
4472                                 (void *)&cmd_set_bond_mon_period_period_ms,
4473                                 NULL
4474                 }
4475 };
4476
4477 #endif /* RTE_LIBRTE_PMD_BOND */
4478
4479 /* *** SET FORWARDING MODE *** */
4480 struct cmd_set_fwd_mode_result {
4481         cmdline_fixed_string_t set;
4482         cmdline_fixed_string_t fwd;
4483         cmdline_fixed_string_t mode;
4484 };
4485
4486 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4487                                     __attribute__((unused)) struct cmdline *cl,
4488                                     __attribute__((unused)) void *data)
4489 {
4490         struct cmd_set_fwd_mode_result *res = parsed_result;
4491
4492         set_pkt_forwarding_mode(res->mode);
4493 }
4494
4495 cmdline_parse_token_string_t cmd_setfwd_set =
4496         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4497 cmdline_parse_token_string_t cmd_setfwd_fwd =
4498         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4499 cmdline_parse_token_string_t cmd_setfwd_mode =
4500         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4501                 "" /* defined at init */);
4502
4503 cmdline_parse_inst_t cmd_set_fwd_mode = {
4504         .f = cmd_set_fwd_mode_parsed,
4505         .data = NULL,
4506         .help_str = NULL, /* defined at init */
4507         .tokens = {
4508                 (void *)&cmd_setfwd_set,
4509                 (void *)&cmd_setfwd_fwd,
4510                 (void *)&cmd_setfwd_mode,
4511                 NULL,
4512         },
4513 };
4514
4515 static void cmd_set_fwd_mode_init(void)
4516 {
4517         char *modes, *c;
4518         static char token[128];
4519         static char help[256];
4520         cmdline_parse_token_string_t *token_struct;
4521
4522         modes = list_pkt_forwarding_modes();
4523         snprintf(help, sizeof help, "set fwd %s - "
4524                 "set packet forwarding mode", modes);
4525         cmd_set_fwd_mode.help_str = help;
4526
4527         /* string token separator is # */
4528         for (c = token; *modes != '\0'; modes++)
4529                 if (*modes == '|')
4530                         *c++ = '#';
4531                 else
4532                         *c++ = *modes;
4533         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4534         token_struct->string_data.str = token;
4535 }
4536
4537 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4538 struct cmd_set_burst_tx_retry_result {
4539         cmdline_fixed_string_t set;
4540         cmdline_fixed_string_t burst;
4541         cmdline_fixed_string_t tx;
4542         cmdline_fixed_string_t delay;
4543         uint32_t time;
4544         cmdline_fixed_string_t retry;
4545         uint32_t retry_num;
4546 };
4547
4548 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4549                                         __attribute__((unused)) struct cmdline *cl,
4550                                         __attribute__((unused)) void *data)
4551 {
4552         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4553
4554         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4555                 && !strcmp(res->tx, "tx")) {
4556                 if (!strcmp(res->delay, "delay"))
4557                         burst_tx_delay_time = res->time;
4558                 if (!strcmp(res->retry, "retry"))
4559                         burst_tx_retry_num = res->retry_num;
4560         }
4561
4562 }
4563
4564 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4565         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4566 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4567         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4568                                  "burst");
4569 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4570         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4571 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4572         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4573 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4574         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4575 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4576         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4577 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4578         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4579
4580 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4581         .f = cmd_set_burst_tx_retry_parsed,
4582         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
4583         .tokens = {
4584                 (void *)&cmd_set_burst_tx_retry_set,
4585                 (void *)&cmd_set_burst_tx_retry_burst,
4586                 (void *)&cmd_set_burst_tx_retry_tx,
4587                 (void *)&cmd_set_burst_tx_retry_delay,
4588                 (void *)&cmd_set_burst_tx_retry_time,
4589                 (void *)&cmd_set_burst_tx_retry_retry,
4590                 (void *)&cmd_set_burst_tx_retry_retry_num,
4591                 NULL,
4592         },
4593 };
4594
4595 /* *** SET PROMISC MODE *** */
4596 struct cmd_set_promisc_mode_result {
4597         cmdline_fixed_string_t set;
4598         cmdline_fixed_string_t promisc;
4599         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4600         uint8_t port_num;                /* valid if "allports" argument == 0 */
4601         cmdline_fixed_string_t mode;
4602 };
4603
4604 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4605                                         __attribute__((unused)) struct cmdline *cl,
4606                                         void *allports)
4607 {
4608         struct cmd_set_promisc_mode_result *res = parsed_result;
4609         int enable;
4610         portid_t i;
4611
4612         if (!strcmp(res->mode, "on"))
4613                 enable = 1;
4614         else
4615                 enable = 0;
4616
4617         /* all ports */
4618         if (allports) {
4619                 FOREACH_PORT(i, ports) {
4620                         if (enable)
4621                                 rte_eth_promiscuous_enable(i);
4622                         else
4623                                 rte_eth_promiscuous_disable(i);
4624                 }
4625         }
4626         else {
4627                 if (enable)
4628                         rte_eth_promiscuous_enable(res->port_num);
4629                 else
4630                         rte_eth_promiscuous_disable(res->port_num);
4631         }
4632 }
4633
4634 cmdline_parse_token_string_t cmd_setpromisc_set =
4635         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
4636 cmdline_parse_token_string_t cmd_setpromisc_promisc =
4637         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
4638                                  "promisc");
4639 cmdline_parse_token_string_t cmd_setpromisc_portall =
4640         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
4641                                  "all");
4642 cmdline_parse_token_num_t cmd_setpromisc_portnum =
4643         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
4644                               UINT8);
4645 cmdline_parse_token_string_t cmd_setpromisc_mode =
4646         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
4647                                  "on#off");
4648
4649 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
4650         .f = cmd_set_promisc_mode_parsed,
4651         .data = (void *)1,
4652         .help_str = "set promisc all on|off: set promisc mode for all ports",
4653         .tokens = {
4654                 (void *)&cmd_setpromisc_set,
4655                 (void *)&cmd_setpromisc_promisc,
4656                 (void *)&cmd_setpromisc_portall,
4657                 (void *)&cmd_setpromisc_mode,
4658                 NULL,
4659         },
4660 };
4661
4662 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
4663         .f = cmd_set_promisc_mode_parsed,
4664         .data = (void *)0,
4665         .help_str = "set promisc X on|off: set promisc mode on port X",
4666         .tokens = {
4667                 (void *)&cmd_setpromisc_set,
4668                 (void *)&cmd_setpromisc_promisc,
4669                 (void *)&cmd_setpromisc_portnum,
4670                 (void *)&cmd_setpromisc_mode,
4671                 NULL,
4672         },
4673 };
4674
4675 /* *** SET ALLMULTI MODE *** */
4676 struct cmd_set_allmulti_mode_result {
4677         cmdline_fixed_string_t set;
4678         cmdline_fixed_string_t allmulti;
4679         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4680         uint8_t port_num;                /* valid if "allports" argument == 0 */
4681         cmdline_fixed_string_t mode;
4682 };
4683
4684 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
4685                                         __attribute__((unused)) struct cmdline *cl,
4686                                         void *allports)
4687 {
4688         struct cmd_set_allmulti_mode_result *res = parsed_result;
4689         int enable;
4690         portid_t i;
4691
4692         if (!strcmp(res->mode, "on"))
4693                 enable = 1;
4694         else
4695                 enable = 0;
4696
4697         /* all ports */
4698         if (allports) {
4699                 FOREACH_PORT(i, ports) {
4700                         if (enable)
4701                                 rte_eth_allmulticast_enable(i);
4702                         else
4703                                 rte_eth_allmulticast_disable(i);
4704                 }
4705         }
4706         else {
4707                 if (enable)
4708                         rte_eth_allmulticast_enable(res->port_num);
4709                 else
4710                         rte_eth_allmulticast_disable(res->port_num);
4711         }
4712 }
4713
4714 cmdline_parse_token_string_t cmd_setallmulti_set =
4715         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
4716 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
4717         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
4718                                  "allmulti");
4719 cmdline_parse_token_string_t cmd_setallmulti_portall =
4720         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
4721                                  "all");
4722 cmdline_parse_token_num_t cmd_setallmulti_portnum =
4723         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
4724                               UINT8);
4725 cmdline_parse_token_string_t cmd_setallmulti_mode =
4726         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
4727                                  "on#off");
4728
4729 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
4730         .f = cmd_set_allmulti_mode_parsed,
4731         .data = (void *)1,
4732         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
4733         .tokens = {
4734                 (void *)&cmd_setallmulti_set,
4735                 (void *)&cmd_setallmulti_allmulti,
4736                 (void *)&cmd_setallmulti_portall,
4737                 (void *)&cmd_setallmulti_mode,
4738                 NULL,
4739         },
4740 };
4741
4742 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
4743         .f = cmd_set_allmulti_mode_parsed,
4744         .data = (void *)0,
4745         .help_str = "set allmulti X on|off: set allmulti mode on port X",
4746         .tokens = {
4747                 (void *)&cmd_setallmulti_set,
4748                 (void *)&cmd_setallmulti_allmulti,
4749                 (void *)&cmd_setallmulti_portnum,
4750                 (void *)&cmd_setallmulti_mode,
4751                 NULL,
4752         },
4753 };
4754
4755 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
4756 struct cmd_link_flow_ctrl_set_result {
4757         cmdline_fixed_string_t set;
4758         cmdline_fixed_string_t flow_ctrl;
4759         cmdline_fixed_string_t rx;
4760         cmdline_fixed_string_t rx_lfc_mode;
4761         cmdline_fixed_string_t tx;
4762         cmdline_fixed_string_t tx_lfc_mode;
4763         cmdline_fixed_string_t mac_ctrl_frame_fwd;
4764         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
4765         cmdline_fixed_string_t autoneg_str;
4766         cmdline_fixed_string_t autoneg;
4767         cmdline_fixed_string_t hw_str;
4768         uint32_t high_water;
4769         cmdline_fixed_string_t lw_str;
4770         uint32_t low_water;
4771         cmdline_fixed_string_t pt_str;
4772         uint16_t pause_time;
4773         cmdline_fixed_string_t xon_str;
4774         uint16_t send_xon;
4775         uint8_t  port_id;
4776 };
4777
4778 cmdline_parse_token_string_t cmd_lfc_set_set =
4779         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4780                                 set, "set");
4781 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
4782         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4783                                 flow_ctrl, "flow_ctrl");
4784 cmdline_parse_token_string_t cmd_lfc_set_rx =
4785         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4786                                 rx, "rx");
4787 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
4788         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4789                                 rx_lfc_mode, "on#off");
4790 cmdline_parse_token_string_t cmd_lfc_set_tx =
4791         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4792                                 tx, "tx");
4793 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
4794         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4795                                 tx_lfc_mode, "on#off");
4796 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
4797         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4798                                 hw_str, "high_water");
4799 cmdline_parse_token_num_t cmd_lfc_set_high_water =
4800         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4801                                 high_water, UINT32);
4802 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
4803         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4804                                 lw_str, "low_water");
4805 cmdline_parse_token_num_t cmd_lfc_set_low_water =
4806         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4807                                 low_water, UINT32);
4808 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
4809         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4810                                 pt_str, "pause_time");
4811 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
4812         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4813                                 pause_time, UINT16);
4814 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
4815         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4816                                 xon_str, "send_xon");
4817 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
4818         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4819                                 send_xon, UINT16);
4820 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
4821         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4822                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
4823 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
4824         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4825                                 mac_ctrl_frame_fwd_mode, "on#off");
4826 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
4827         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4828                                 autoneg_str, "autoneg");
4829 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
4830         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4831                                 autoneg, "on#off");
4832 cmdline_parse_token_num_t cmd_lfc_set_portid =
4833         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4834                                 port_id, UINT8);
4835
4836 /* forward declaration */
4837 static void
4838 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
4839                               void *data);
4840
4841 cmdline_parse_inst_t cmd_link_flow_control_set = {
4842         .f = cmd_link_flow_ctrl_set_parsed,
4843         .data = NULL,
4844         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
4845 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
4846 autoneg on|off port_id",
4847         .tokens = {
4848                 (void *)&cmd_lfc_set_set,
4849                 (void *)&cmd_lfc_set_flow_ctrl,
4850                 (void *)&cmd_lfc_set_rx,
4851                 (void *)&cmd_lfc_set_rx_mode,
4852                 (void *)&cmd_lfc_set_tx,
4853                 (void *)&cmd_lfc_set_tx_mode,
4854                 (void *)&cmd_lfc_set_high_water,
4855                 (void *)&cmd_lfc_set_low_water,
4856                 (void *)&cmd_lfc_set_pause_time,
4857                 (void *)&cmd_lfc_set_send_xon,
4858                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4859                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4860                 (void *)&cmd_lfc_set_autoneg_str,
4861                 (void *)&cmd_lfc_set_autoneg,
4862                 (void *)&cmd_lfc_set_portid,
4863                 NULL,
4864         },
4865 };
4866
4867 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
4868         .f = cmd_link_flow_ctrl_set_parsed,
4869         .data = (void *)&cmd_link_flow_control_set_rx,
4870         .help_str = "Change rx flow control parameter: set flow_ctrl "
4871                     "rx on|off port_id",
4872         .tokens = {
4873                 (void *)&cmd_lfc_set_set,
4874                 (void *)&cmd_lfc_set_flow_ctrl,
4875                 (void *)&cmd_lfc_set_rx,
4876                 (void *)&cmd_lfc_set_rx_mode,
4877                 (void *)&cmd_lfc_set_portid,
4878                 NULL,
4879         },
4880 };
4881
4882 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
4883         .f = cmd_link_flow_ctrl_set_parsed,
4884         .data = (void *)&cmd_link_flow_control_set_tx,
4885         .help_str = "Change tx flow control parameter: set flow_ctrl "
4886                     "tx on|off port_id",
4887         .tokens = {
4888                 (void *)&cmd_lfc_set_set,
4889                 (void *)&cmd_lfc_set_flow_ctrl,
4890                 (void *)&cmd_lfc_set_tx,
4891                 (void *)&cmd_lfc_set_tx_mode,
4892                 (void *)&cmd_lfc_set_portid,
4893                 NULL,
4894         },
4895 };
4896
4897 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
4898         .f = cmd_link_flow_ctrl_set_parsed,
4899         .data = (void *)&cmd_link_flow_control_set_hw,
4900         .help_str = "Change high water flow control parameter: set flow_ctrl "
4901                     "high_water value port_id",
4902         .tokens = {
4903                 (void *)&cmd_lfc_set_set,
4904                 (void *)&cmd_lfc_set_flow_ctrl,
4905                 (void *)&cmd_lfc_set_high_water_str,
4906                 (void *)&cmd_lfc_set_high_water,
4907                 (void *)&cmd_lfc_set_portid,
4908                 NULL,
4909         },
4910 };
4911
4912 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
4913         .f = cmd_link_flow_ctrl_set_parsed,
4914         .data = (void *)&cmd_link_flow_control_set_lw,
4915         .help_str = "Change low water flow control parameter: set flow_ctrl "
4916                     "low_water value port_id",
4917         .tokens = {
4918                 (void *)&cmd_lfc_set_set,
4919                 (void *)&cmd_lfc_set_flow_ctrl,
4920                 (void *)&cmd_lfc_set_low_water_str,
4921                 (void *)&cmd_lfc_set_low_water,
4922                 (void *)&cmd_lfc_set_portid,
4923                 NULL,
4924         },
4925 };
4926
4927 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
4928         .f = cmd_link_flow_ctrl_set_parsed,
4929         .data = (void *)&cmd_link_flow_control_set_pt,
4930         .help_str = "Change pause time flow control parameter: set flow_ctrl "
4931                     "pause_time value port_id",
4932         .tokens = {
4933                 (void *)&cmd_lfc_set_set,
4934                 (void *)&cmd_lfc_set_flow_ctrl,
4935                 (void *)&cmd_lfc_set_pause_time_str,
4936                 (void *)&cmd_lfc_set_pause_time,
4937                 (void *)&cmd_lfc_set_portid,
4938                 NULL,
4939         },
4940 };
4941
4942 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
4943         .f = cmd_link_flow_ctrl_set_parsed,
4944         .data = (void *)&cmd_link_flow_control_set_xon,
4945         .help_str = "Change send_xon flow control parameter: set flow_ctrl "
4946                     "send_xon value port_id",
4947         .tokens = {
4948                 (void *)&cmd_lfc_set_set,
4949                 (void *)&cmd_lfc_set_flow_ctrl,
4950                 (void *)&cmd_lfc_set_send_xon_str,
4951                 (void *)&cmd_lfc_set_send_xon,
4952                 (void *)&cmd_lfc_set_portid,
4953                 NULL,
4954         },
4955 };
4956
4957 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
4958         .f = cmd_link_flow_ctrl_set_parsed,
4959         .data = (void *)&cmd_link_flow_control_set_macfwd,
4960         .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl "
4961                     "mac_ctrl_frame_fwd on|off port_id",
4962         .tokens = {
4963                 (void *)&cmd_lfc_set_set,
4964                 (void *)&cmd_lfc_set_flow_ctrl,
4965                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4966                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4967                 (void *)&cmd_lfc_set_portid,
4968                 NULL,
4969         },
4970 };
4971
4972 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
4973         .f = cmd_link_flow_ctrl_set_parsed,
4974         .data = (void *)&cmd_link_flow_control_set_autoneg,
4975         .help_str = "Change autoneg flow control parameter: set flow_ctrl "
4976                     "autoneg on|off port_id",
4977         .tokens = {
4978                 (void *)&cmd_lfc_set_set,
4979                 (void *)&cmd_lfc_set_flow_ctrl,
4980                 (void *)&cmd_lfc_set_autoneg_str,
4981                 (void *)&cmd_lfc_set_autoneg,
4982                 (void *)&cmd_lfc_set_portid,
4983                 NULL,
4984         },
4985 };
4986
4987 static void
4988 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
4989                               __attribute__((unused)) struct cmdline *cl,
4990                               void *data)
4991 {
4992         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
4993         cmdline_parse_inst_t *cmd = data;
4994         struct rte_eth_fc_conf fc_conf;
4995         int rx_fc_en = 0;
4996         int tx_fc_en = 0;
4997         int ret;
4998
4999         /*
5000          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5001          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5002          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5003          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5004          */
5005         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5006                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5007         };
5008
5009         /* Partial command line, retrieve current configuration */
5010         if (cmd) {
5011                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5012                 if (ret != 0) {
5013                         printf("cannot get current flow ctrl parameters, return"
5014                                "code = %d\n", ret);
5015                         return;
5016                 }
5017
5018                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5019                     (fc_conf.mode == RTE_FC_FULL))
5020                         rx_fc_en = 1;
5021                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5022                     (fc_conf.mode == RTE_FC_FULL))
5023                         tx_fc_en = 1;
5024         }
5025
5026         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
5027                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
5028
5029         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
5030                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5031
5032         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5033
5034         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5035                 fc_conf.high_water = res->high_water;
5036
5037         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5038                 fc_conf.low_water = res->low_water;
5039
5040         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5041                 fc_conf.pause_time = res->pause_time;
5042
5043         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5044                 fc_conf.send_xon = res->send_xon;
5045
5046         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5047                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5048                         fc_conf.mac_ctrl_frame_fwd = 1;
5049                 else
5050                         fc_conf.mac_ctrl_frame_fwd = 0;
5051         }
5052
5053         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5054                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5055
5056         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5057         if (ret != 0)
5058                 printf("bad flow contrl parameter, return code = %d \n", ret);
5059 }
5060
5061 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
5062 struct cmd_priority_flow_ctrl_set_result {
5063         cmdline_fixed_string_t set;
5064         cmdline_fixed_string_t pfc_ctrl;
5065         cmdline_fixed_string_t rx;
5066         cmdline_fixed_string_t rx_pfc_mode;
5067         cmdline_fixed_string_t tx;
5068         cmdline_fixed_string_t tx_pfc_mode;
5069         uint32_t high_water;
5070         uint32_t low_water;
5071         uint16_t pause_time;
5072         uint8_t  priority;
5073         uint8_t  port_id;
5074 };
5075
5076 static void
5077 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5078                        __attribute__((unused)) struct cmdline *cl,
5079                        __attribute__((unused)) void *data)
5080 {
5081         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5082         struct rte_eth_pfc_conf pfc_conf;
5083         int rx_fc_enable, tx_fc_enable;
5084         int ret;
5085
5086         /*
5087          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5088          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5089          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5090          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5091          */
5092         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5093                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5094         };
5095
5096         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5097         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5098         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5099         pfc_conf.fc.high_water = res->high_water;
5100         pfc_conf.fc.low_water  = res->low_water;
5101         pfc_conf.fc.pause_time = res->pause_time;
5102         pfc_conf.priority      = res->priority;
5103
5104         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5105         if (ret != 0)
5106                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5107 }
5108
5109 cmdline_parse_token_string_t cmd_pfc_set_set =
5110         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5111                                 set, "set");
5112 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5113         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5114                                 pfc_ctrl, "pfc_ctrl");
5115 cmdline_parse_token_string_t cmd_pfc_set_rx =
5116         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5117                                 rx, "rx");
5118 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5119         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5120                                 rx_pfc_mode, "on#off");
5121 cmdline_parse_token_string_t cmd_pfc_set_tx =
5122         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5123                                 tx, "tx");
5124 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5125         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5126                                 tx_pfc_mode, "on#off");
5127 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5128         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5129                                 high_water, UINT32);
5130 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5131         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5132                                 low_water, UINT32);
5133 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5134         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5135                                 pause_time, UINT16);
5136 cmdline_parse_token_num_t cmd_pfc_set_priority =
5137         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5138                                 priority, UINT8);
5139 cmdline_parse_token_num_t cmd_pfc_set_portid =
5140         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5141                                 port_id, UINT8);
5142
5143 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5144         .f = cmd_priority_flow_ctrl_set_parsed,
5145         .data = NULL,
5146         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
5147                         tx on|off high_water low_water pause_time priority port_id",
5148         .tokens = {
5149                 (void *)&cmd_pfc_set_set,
5150                 (void *)&cmd_pfc_set_flow_ctrl,
5151                 (void *)&cmd_pfc_set_rx,
5152                 (void *)&cmd_pfc_set_rx_mode,
5153                 (void *)&cmd_pfc_set_tx,
5154                 (void *)&cmd_pfc_set_tx_mode,
5155                 (void *)&cmd_pfc_set_high_water,
5156                 (void *)&cmd_pfc_set_low_water,
5157                 (void *)&cmd_pfc_set_pause_time,
5158                 (void *)&cmd_pfc_set_priority,
5159                 (void *)&cmd_pfc_set_portid,
5160                 NULL,
5161         },
5162 };
5163
5164 /* *** RESET CONFIGURATION *** */
5165 struct cmd_reset_result {
5166         cmdline_fixed_string_t reset;
5167         cmdline_fixed_string_t def;
5168 };
5169
5170 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5171                              struct cmdline *cl,
5172                              __attribute__((unused)) void *data)
5173 {
5174         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5175         set_def_fwd_config();
5176 }
5177
5178 cmdline_parse_token_string_t cmd_reset_set =
5179         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5180 cmdline_parse_token_string_t cmd_reset_def =
5181         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5182                                  "default");
5183
5184 cmdline_parse_inst_t cmd_reset = {
5185         .f = cmd_reset_parsed,
5186         .data = NULL,
5187         .help_str = "set default: reset default forwarding configuration",
5188         .tokens = {
5189                 (void *)&cmd_reset_set,
5190                 (void *)&cmd_reset_def,
5191                 NULL,
5192         },
5193 };
5194
5195 /* *** START FORWARDING *** */
5196 struct cmd_start_result {
5197         cmdline_fixed_string_t start;
5198 };
5199
5200 cmdline_parse_token_string_t cmd_start_start =
5201         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5202
5203 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5204                              __attribute__((unused)) struct cmdline *cl,
5205                              __attribute__((unused)) void *data)
5206 {
5207         start_packet_forwarding(0);
5208 }
5209
5210 cmdline_parse_inst_t cmd_start = {
5211         .f = cmd_start_parsed,
5212         .data = NULL,
5213         .help_str = "start packet forwarding",
5214         .tokens = {
5215                 (void *)&cmd_start_start,
5216                 NULL,
5217         },
5218 };
5219
5220 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5221 struct cmd_start_tx_first_result {
5222         cmdline_fixed_string_t start;
5223         cmdline_fixed_string_t tx_first;
5224 };
5225
5226 static void
5227 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5228                           __attribute__((unused)) struct cmdline *cl,
5229                           __attribute__((unused)) void *data)
5230 {
5231         start_packet_forwarding(1);
5232 }
5233
5234 cmdline_parse_token_string_t cmd_start_tx_first_start =
5235         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5236                                  "start");
5237 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5238         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5239                                  tx_first, "tx_first");
5240
5241 cmdline_parse_inst_t cmd_start_tx_first = {
5242         .f = cmd_start_tx_first_parsed,
5243         .data = NULL,
5244         .help_str = "start packet forwarding, after sending 1 burst of packets",
5245         .tokens = {
5246                 (void *)&cmd_start_tx_first_start,
5247                 (void *)&cmd_start_tx_first_tx_first,
5248                 NULL,
5249         },
5250 };
5251
5252 /* *** SET LINK UP *** */
5253 struct cmd_set_link_up_result {
5254         cmdline_fixed_string_t set;
5255         cmdline_fixed_string_t link_up;
5256         cmdline_fixed_string_t port;
5257         uint8_t port_id;
5258 };
5259
5260 cmdline_parse_token_string_t cmd_set_link_up_set =
5261         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5262 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5263         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5264                                 "link-up");
5265 cmdline_parse_token_string_t cmd_set_link_up_port =
5266         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5267 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5268         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5269
5270 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5271                              __attribute__((unused)) struct cmdline *cl,
5272                              __attribute__((unused)) void *data)
5273 {
5274         struct cmd_set_link_up_result *res = parsed_result;
5275         dev_set_link_up(res->port_id);
5276 }
5277
5278 cmdline_parse_inst_t cmd_set_link_up = {
5279         .f = cmd_set_link_up_parsed,
5280         .data = NULL,
5281         .help_str = "set link-up port (port id)",
5282         .tokens = {
5283                 (void *)&cmd_set_link_up_set,
5284                 (void *)&cmd_set_link_up_link_up,
5285                 (void *)&cmd_set_link_up_port,
5286                 (void *)&cmd_set_link_up_port_id,
5287                 NULL,
5288         },
5289 };
5290
5291 /* *** SET LINK DOWN *** */
5292 struct cmd_set_link_down_result {
5293         cmdline_fixed_string_t set;
5294         cmdline_fixed_string_t link_down;
5295         cmdline_fixed_string_t port;
5296         uint8_t port_id;
5297 };
5298
5299 cmdline_parse_token_string_t cmd_set_link_down_set =
5300         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5301 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5302         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5303                                 "link-down");
5304 cmdline_parse_token_string_t cmd_set_link_down_port =
5305         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5306 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5307         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5308
5309 static void cmd_set_link_down_parsed(
5310                                 __attribute__((unused)) void *parsed_result,
5311                                 __attribute__((unused)) struct cmdline *cl,
5312                                 __attribute__((unused)) void *data)
5313 {
5314         struct cmd_set_link_down_result *res = parsed_result;
5315         dev_set_link_down(res->port_id);
5316 }
5317
5318 cmdline_parse_inst_t cmd_set_link_down = {
5319         .f = cmd_set_link_down_parsed,
5320         .data = NULL,
5321         .help_str = "set link-down port (port id)",
5322         .tokens = {
5323                 (void *)&cmd_set_link_down_set,
5324                 (void *)&cmd_set_link_down_link_down,
5325                 (void *)&cmd_set_link_down_port,
5326                 (void *)&cmd_set_link_down_port_id,
5327                 NULL,
5328         },
5329 };
5330
5331 /* *** SHOW CFG *** */
5332 struct cmd_showcfg_result {
5333         cmdline_fixed_string_t show;
5334         cmdline_fixed_string_t cfg;
5335         cmdline_fixed_string_t what;
5336 };
5337
5338 static void cmd_showcfg_parsed(void *parsed_result,
5339                                __attribute__((unused)) struct cmdline *cl,
5340                                __attribute__((unused)) void *data)
5341 {
5342         struct cmd_showcfg_result *res = parsed_result;
5343         if (!strcmp(res->what, "rxtx"))
5344                 rxtx_config_display();
5345         else if (!strcmp(res->what, "cores"))
5346                 fwd_lcores_config_display();
5347         else if (!strcmp(res->what, "fwd"))
5348                 fwd_config_display();
5349         else if (!strcmp(res->what, "txpkts"))
5350                 show_tx_pkt_segments();
5351 }
5352
5353 cmdline_parse_token_string_t cmd_showcfg_show =
5354         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5355 cmdline_parse_token_string_t cmd_showcfg_port =
5356         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5357 cmdline_parse_token_string_t cmd_showcfg_what =
5358         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5359                                  "rxtx#cores#fwd#txpkts");
5360
5361 cmdline_parse_inst_t cmd_showcfg = {
5362         .f = cmd_showcfg_parsed,
5363         .data = NULL,
5364         .help_str = "show config rxtx|cores|fwd|txpkts",
5365         .tokens = {
5366                 (void *)&cmd_showcfg_show,
5367                 (void *)&cmd_showcfg_port,
5368                 (void *)&cmd_showcfg_what,
5369                 NULL,
5370         },
5371 };
5372
5373 /* *** SHOW ALL PORT INFO *** */
5374 struct cmd_showportall_result {
5375         cmdline_fixed_string_t show;
5376         cmdline_fixed_string_t port;
5377         cmdline_fixed_string_t what;
5378         cmdline_fixed_string_t all;
5379 };
5380
5381 static void cmd_showportall_parsed(void *parsed_result,
5382                                 __attribute__((unused)) struct cmdline *cl,
5383                                 __attribute__((unused)) void *data)
5384 {
5385         portid_t i;
5386
5387         struct cmd_showportall_result *res = parsed_result;
5388         if (!strcmp(res->show, "clear")) {
5389                 if (!strcmp(res->what, "stats"))
5390                         FOREACH_PORT(i, ports)
5391                                 nic_stats_clear(i);
5392                 else if (!strcmp(res->what, "xstats"))
5393                         FOREACH_PORT(i, ports)
5394                                 nic_xstats_clear(i);
5395         } else if (!strcmp(res->what, "info"))
5396                 FOREACH_PORT(i, ports)
5397                         port_infos_display(i);
5398         else if (!strcmp(res->what, "stats"))
5399                 FOREACH_PORT(i, ports)
5400                         nic_stats_display(i);
5401         else if (!strcmp(res->what, "xstats"))
5402                 FOREACH_PORT(i, ports)
5403                         nic_xstats_display(i);
5404         else if (!strcmp(res->what, "fdir"))
5405                 FOREACH_PORT(i, ports)
5406                         fdir_get_infos(i);
5407         else if (!strcmp(res->what, "stat_qmap"))
5408                 FOREACH_PORT(i, ports)
5409                         nic_stats_mapping_display(i);
5410         else if (!strcmp(res->what, "dcb_tc"))
5411                 FOREACH_PORT(i, ports)
5412                         port_dcb_info_display(i);
5413 }
5414
5415 cmdline_parse_token_string_t cmd_showportall_show =
5416         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5417                                  "show#clear");
5418 cmdline_parse_token_string_t cmd_showportall_port =
5419         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5420 cmdline_parse_token_string_t cmd_showportall_what =
5421         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5422                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5423 cmdline_parse_token_string_t cmd_showportall_all =
5424         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5425 cmdline_parse_inst_t cmd_showportall = {
5426         .f = cmd_showportall_parsed,
5427         .data = NULL,
5428         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc all",
5429         .tokens = {
5430                 (void *)&cmd_showportall_show,
5431                 (void *)&cmd_showportall_port,
5432                 (void *)&cmd_showportall_what,
5433                 (void *)&cmd_showportall_all,
5434                 NULL,
5435         },
5436 };
5437
5438 /* *** SHOW PORT INFO *** */
5439 struct cmd_showport_result {
5440         cmdline_fixed_string_t show;
5441         cmdline_fixed_string_t port;
5442         cmdline_fixed_string_t what;
5443         uint8_t portnum;
5444 };
5445
5446 static void cmd_showport_parsed(void *parsed_result,
5447                                 __attribute__((unused)) struct cmdline *cl,
5448                                 __attribute__((unused)) void *data)
5449 {
5450         struct cmd_showport_result *res = parsed_result;
5451         if (!strcmp(res->show, "clear")) {
5452                 if (!strcmp(res->what, "stats"))
5453                         nic_stats_clear(res->portnum);
5454                 else if (!strcmp(res->what, "xstats"))
5455                         nic_xstats_clear(res->portnum);
5456         } else if (!strcmp(res->what, "info"))
5457                 port_infos_display(res->portnum);
5458         else if (!strcmp(res->what, "stats"))
5459                 nic_stats_display(res->portnum);
5460         else if (!strcmp(res->what, "xstats"))
5461                 nic_xstats_display(res->portnum);
5462         else if (!strcmp(res->what, "fdir"))
5463                  fdir_get_infos(res->portnum);
5464         else if (!strcmp(res->what, "stat_qmap"))
5465                 nic_stats_mapping_display(res->portnum);
5466         else if (!strcmp(res->what, "dcb_tc"))
5467                 port_dcb_info_display(res->portnum);
5468 }
5469
5470 cmdline_parse_token_string_t cmd_showport_show =
5471         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5472                                  "show#clear");
5473 cmdline_parse_token_string_t cmd_showport_port =
5474         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5475 cmdline_parse_token_string_t cmd_showport_what =
5476         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5477                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5478 cmdline_parse_token_num_t cmd_showport_portnum =
5479         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5480
5481 cmdline_parse_inst_t cmd_showport = {
5482         .f = cmd_showport_parsed,
5483         .data = NULL,
5484         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc X (X = port number)",
5485         .tokens = {
5486                 (void *)&cmd_showport_show,
5487                 (void *)&cmd_showport_port,
5488                 (void *)&cmd_showport_what,
5489                 (void *)&cmd_showport_portnum,
5490                 NULL,
5491         },
5492 };
5493
5494 /* *** SHOW QUEUE INFO *** */
5495 struct cmd_showqueue_result {
5496         cmdline_fixed_string_t show;
5497         cmdline_fixed_string_t type;
5498         cmdline_fixed_string_t what;
5499         uint8_t portnum;
5500         uint16_t queuenum;
5501 };
5502
5503 static void
5504 cmd_showqueue_parsed(void *parsed_result,
5505         __attribute__((unused)) struct cmdline *cl,
5506         __attribute__((unused)) void *data)
5507 {
5508         struct cmd_showqueue_result *res = parsed_result;
5509
5510         if (!strcmp(res->type, "rxq"))
5511                 rx_queue_infos_display(res->portnum, res->queuenum);
5512         else if (!strcmp(res->type, "txq"))
5513                 tx_queue_infos_display(res->portnum, res->queuenum);
5514 }
5515
5516 cmdline_parse_token_string_t cmd_showqueue_show =
5517         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5518 cmdline_parse_token_string_t cmd_showqueue_type =
5519         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5520 cmdline_parse_token_string_t cmd_showqueue_what =
5521         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
5522 cmdline_parse_token_num_t cmd_showqueue_portnum =
5523         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
5524 cmdline_parse_token_num_t cmd_showqueue_queuenum =
5525         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
5526
5527 cmdline_parse_inst_t cmd_showqueue = {
5528         .f = cmd_showqueue_parsed,
5529         .data = NULL,
5530         .help_str = "show rxq|txq info <port number> <queue_number>",
5531         .tokens = {
5532                 (void *)&cmd_showqueue_show,
5533                 (void *)&cmd_showqueue_type,
5534                 (void *)&cmd_showqueue_what,
5535                 (void *)&cmd_showqueue_portnum,
5536                 (void *)&cmd_showqueue_queuenum,
5537                 NULL,
5538         },
5539 };
5540
5541 /* *** READ PORT REGISTER *** */
5542 struct cmd_read_reg_result {
5543         cmdline_fixed_string_t read;
5544         cmdline_fixed_string_t reg;
5545         uint8_t port_id;
5546         uint32_t reg_off;
5547 };
5548
5549 static void
5550 cmd_read_reg_parsed(void *parsed_result,
5551                     __attribute__((unused)) struct cmdline *cl,
5552                     __attribute__((unused)) void *data)
5553 {
5554         struct cmd_read_reg_result *res = parsed_result;
5555         port_reg_display(res->port_id, res->reg_off);
5556 }
5557
5558 cmdline_parse_token_string_t cmd_read_reg_read =
5559         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5560 cmdline_parse_token_string_t cmd_read_reg_reg =
5561         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5562 cmdline_parse_token_num_t cmd_read_reg_port_id =
5563         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5564 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5565         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5566
5567 cmdline_parse_inst_t cmd_read_reg = {
5568         .f = cmd_read_reg_parsed,
5569         .data = NULL,
5570         .help_str = "read reg port_id reg_off",
5571         .tokens = {
5572                 (void *)&cmd_read_reg_read,
5573                 (void *)&cmd_read_reg_reg,
5574                 (void *)&cmd_read_reg_port_id,
5575                 (void *)&cmd_read_reg_reg_off,
5576                 NULL,
5577         },
5578 };
5579
5580 /* *** READ PORT REGISTER BIT FIELD *** */
5581 struct cmd_read_reg_bit_field_result {
5582         cmdline_fixed_string_t read;
5583         cmdline_fixed_string_t regfield;
5584         uint8_t port_id;
5585         uint32_t reg_off;
5586         uint8_t bit1_pos;
5587         uint8_t bit2_pos;
5588 };
5589
5590 static void
5591 cmd_read_reg_bit_field_parsed(void *parsed_result,
5592                               __attribute__((unused)) struct cmdline *cl,
5593                               __attribute__((unused)) void *data)
5594 {
5595         struct cmd_read_reg_bit_field_result *res = parsed_result;
5596         port_reg_bit_field_display(res->port_id, res->reg_off,
5597                                    res->bit1_pos, res->bit2_pos);
5598 }
5599
5600 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5601         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5602                                  "read");
5603 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5604         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5605                                  regfield, "regfield");
5606 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5607         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5608                               UINT8);
5609 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5610         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5611                               UINT32);
5612 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5613         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5614                               UINT8);
5615 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5616         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5617                               UINT8);
5618
5619 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5620         .f = cmd_read_reg_bit_field_parsed,
5621         .data = NULL,
5622         .help_str = "read regfield port_id reg_off bit_x bit_y "
5623         "(read register bit field between bit_x and bit_y included)",
5624         .tokens = {
5625                 (void *)&cmd_read_reg_bit_field_read,
5626                 (void *)&cmd_read_reg_bit_field_regfield,
5627                 (void *)&cmd_read_reg_bit_field_port_id,
5628                 (void *)&cmd_read_reg_bit_field_reg_off,
5629                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5630                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5631                 NULL,
5632         },
5633 };
5634
5635 /* *** READ PORT REGISTER BIT *** */
5636 struct cmd_read_reg_bit_result {
5637         cmdline_fixed_string_t read;
5638         cmdline_fixed_string_t regbit;
5639         uint8_t port_id;
5640         uint32_t reg_off;
5641         uint8_t bit_pos;
5642 };
5643
5644 static void
5645 cmd_read_reg_bit_parsed(void *parsed_result,
5646                         __attribute__((unused)) struct cmdline *cl,
5647                         __attribute__((unused)) void *data)
5648 {
5649         struct cmd_read_reg_bit_result *res = parsed_result;
5650         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5651 }
5652
5653 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5654         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5655 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5656         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5657                                  regbit, "regbit");
5658 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5659         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5660 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5661         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5662 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5663         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5664
5665 cmdline_parse_inst_t cmd_read_reg_bit = {
5666         .f = cmd_read_reg_bit_parsed,
5667         .data = NULL,
5668         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5669         .tokens = {
5670                 (void *)&cmd_read_reg_bit_read,
5671                 (void *)&cmd_read_reg_bit_regbit,
5672                 (void *)&cmd_read_reg_bit_port_id,
5673                 (void *)&cmd_read_reg_bit_reg_off,
5674                 (void *)&cmd_read_reg_bit_bit_pos,
5675                 NULL,
5676         },
5677 };
5678
5679 /* *** WRITE PORT REGISTER *** */
5680 struct cmd_write_reg_result {
5681         cmdline_fixed_string_t write;
5682         cmdline_fixed_string_t reg;
5683         uint8_t port_id;
5684         uint32_t reg_off;
5685         uint32_t value;
5686 };
5687
5688 static void
5689 cmd_write_reg_parsed(void *parsed_result,
5690                      __attribute__((unused)) struct cmdline *cl,
5691                      __attribute__((unused)) void *data)
5692 {
5693         struct cmd_write_reg_result *res = parsed_result;
5694         port_reg_set(res->port_id, res->reg_off, res->value);
5695 }
5696
5697 cmdline_parse_token_string_t cmd_write_reg_write =
5698         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
5699 cmdline_parse_token_string_t cmd_write_reg_reg =
5700         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
5701 cmdline_parse_token_num_t cmd_write_reg_port_id =
5702         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
5703 cmdline_parse_token_num_t cmd_write_reg_reg_off =
5704         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
5705 cmdline_parse_token_num_t cmd_write_reg_value =
5706         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
5707
5708 cmdline_parse_inst_t cmd_write_reg = {
5709         .f = cmd_write_reg_parsed,
5710         .data = NULL,
5711         .help_str = "write reg port_id reg_off reg_value",
5712         .tokens = {
5713                 (void *)&cmd_write_reg_write,
5714                 (void *)&cmd_write_reg_reg,
5715                 (void *)&cmd_write_reg_port_id,
5716                 (void *)&cmd_write_reg_reg_off,
5717                 (void *)&cmd_write_reg_value,
5718                 NULL,
5719         },
5720 };
5721
5722 /* *** WRITE PORT REGISTER BIT FIELD *** */
5723 struct cmd_write_reg_bit_field_result {
5724         cmdline_fixed_string_t write;
5725         cmdline_fixed_string_t regfield;
5726         uint8_t port_id;
5727         uint32_t reg_off;
5728         uint8_t bit1_pos;
5729         uint8_t bit2_pos;
5730         uint32_t value;
5731 };
5732
5733 static void
5734 cmd_write_reg_bit_field_parsed(void *parsed_result,
5735                                __attribute__((unused)) struct cmdline *cl,
5736                                __attribute__((unused)) void *data)
5737 {
5738         struct cmd_write_reg_bit_field_result *res = parsed_result;
5739         port_reg_bit_field_set(res->port_id, res->reg_off,
5740                           res->bit1_pos, res->bit2_pos, res->value);
5741 }
5742
5743 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
5744         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
5745                                  "write");
5746 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
5747         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
5748                                  regfield, "regfield");
5749 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
5750         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
5751                               UINT8);
5752 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
5753         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
5754                               UINT32);
5755 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
5756         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
5757                               UINT8);
5758 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
5759         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
5760                               UINT8);
5761 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
5762         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
5763                               UINT32);
5764
5765 cmdline_parse_inst_t cmd_write_reg_bit_field = {
5766         .f = cmd_write_reg_bit_field_parsed,
5767         .data = NULL,
5768         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
5769         "(set register bit field between bit_x and bit_y included)",
5770         .tokens = {
5771                 (void *)&cmd_write_reg_bit_field_write,
5772                 (void *)&cmd_write_reg_bit_field_regfield,
5773                 (void *)&cmd_write_reg_bit_field_port_id,
5774                 (void *)&cmd_write_reg_bit_field_reg_off,
5775                 (void *)&cmd_write_reg_bit_field_bit1_pos,
5776                 (void *)&cmd_write_reg_bit_field_bit2_pos,
5777                 (void *)&cmd_write_reg_bit_field_value,
5778                 NULL,
5779         },
5780 };
5781
5782 /* *** WRITE PORT REGISTER BIT *** */
5783 struct cmd_write_reg_bit_result {
5784         cmdline_fixed_string_t write;
5785         cmdline_fixed_string_t regbit;
5786         uint8_t port_id;
5787         uint32_t reg_off;
5788         uint8_t bit_pos;
5789         uint8_t value;
5790 };
5791
5792 static void
5793 cmd_write_reg_bit_parsed(void *parsed_result,
5794                          __attribute__((unused)) struct cmdline *cl,
5795                          __attribute__((unused)) void *data)
5796 {
5797         struct cmd_write_reg_bit_result *res = parsed_result;
5798         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
5799 }
5800
5801 cmdline_parse_token_string_t cmd_write_reg_bit_write =
5802         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
5803                                  "write");
5804 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
5805         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
5806                                  regbit, "regbit");
5807 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
5808         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
5809 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
5810         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
5811 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
5812         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
5813 cmdline_parse_token_num_t cmd_write_reg_bit_value =
5814         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
5815
5816 cmdline_parse_inst_t cmd_write_reg_bit = {
5817         .f = cmd_write_reg_bit_parsed,
5818         .data = NULL,
5819         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
5820         .tokens = {
5821                 (void *)&cmd_write_reg_bit_write,
5822                 (void *)&cmd_write_reg_bit_regbit,
5823                 (void *)&cmd_write_reg_bit_port_id,
5824                 (void *)&cmd_write_reg_bit_reg_off,
5825                 (void *)&cmd_write_reg_bit_bit_pos,
5826                 (void *)&cmd_write_reg_bit_value,
5827                 NULL,
5828         },
5829 };
5830
5831 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
5832 struct cmd_read_rxd_txd_result {
5833         cmdline_fixed_string_t read;
5834         cmdline_fixed_string_t rxd_txd;
5835         uint8_t port_id;
5836         uint16_t queue_id;
5837         uint16_t desc_id;
5838 };
5839
5840 static void
5841 cmd_read_rxd_txd_parsed(void *parsed_result,
5842                         __attribute__((unused)) struct cmdline *cl,
5843                         __attribute__((unused)) void *data)
5844 {
5845         struct cmd_read_rxd_txd_result *res = parsed_result;
5846
5847         if (!strcmp(res->rxd_txd, "rxd"))
5848                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5849         else if (!strcmp(res->rxd_txd, "txd"))
5850                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5851 }
5852
5853 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
5854         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
5855 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
5856         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
5857                                  "rxd#txd");
5858 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
5859         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
5860 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
5861         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
5862 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
5863         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
5864
5865 cmdline_parse_inst_t cmd_read_rxd_txd = {
5866         .f = cmd_read_rxd_txd_parsed,
5867         .data = NULL,
5868         .help_str = "read rxd|txd port_id queue_id rxd_id",
5869         .tokens = {
5870                 (void *)&cmd_read_rxd_txd_read,
5871                 (void *)&cmd_read_rxd_txd_rxd_txd,
5872                 (void *)&cmd_read_rxd_txd_port_id,
5873                 (void *)&cmd_read_rxd_txd_queue_id,
5874                 (void *)&cmd_read_rxd_txd_desc_id,
5875                 NULL,
5876         },
5877 };
5878
5879 /* *** QUIT *** */
5880 struct cmd_quit_result {
5881         cmdline_fixed_string_t quit;
5882 };
5883
5884 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
5885                             struct cmdline *cl,
5886                             __attribute__((unused)) void *data)
5887 {
5888         pmd_test_exit();
5889         cmdline_quit(cl);
5890 }
5891
5892 cmdline_parse_token_string_t cmd_quit_quit =
5893         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
5894
5895 cmdline_parse_inst_t cmd_quit = {
5896         .f = cmd_quit_parsed,
5897         .data = NULL,
5898         .help_str = "exit application",
5899         .tokens = {
5900                 (void *)&cmd_quit_quit,
5901                 NULL,
5902         },
5903 };
5904
5905 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
5906 struct cmd_mac_addr_result {
5907         cmdline_fixed_string_t mac_addr_cmd;
5908         cmdline_fixed_string_t what;
5909         uint8_t port_num;
5910         struct ether_addr address;
5911 };
5912
5913 static void cmd_mac_addr_parsed(void *parsed_result,
5914                 __attribute__((unused)) struct cmdline *cl,
5915                 __attribute__((unused)) void *data)
5916 {
5917         struct cmd_mac_addr_result *res = parsed_result;
5918         int ret;
5919
5920         if (strcmp(res->what, "add") == 0)
5921                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
5922         else
5923                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
5924
5925         /* check the return value and print it if is < 0 */
5926         if(ret < 0)
5927                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
5928
5929 }
5930
5931 cmdline_parse_token_string_t cmd_mac_addr_cmd =
5932         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
5933                                 "mac_addr");
5934 cmdline_parse_token_string_t cmd_mac_addr_what =
5935         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
5936                                 "add#remove");
5937 cmdline_parse_token_num_t cmd_mac_addr_portnum =
5938                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
5939 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
5940                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
5941
5942 cmdline_parse_inst_t cmd_mac_addr = {
5943         .f = cmd_mac_addr_parsed,
5944         .data = (void *)0,
5945         .help_str = "mac_addr add|remove X <address>: "
5946                         "add/remove MAC address on port X",
5947         .tokens = {
5948                 (void *)&cmd_mac_addr_cmd,
5949                 (void *)&cmd_mac_addr_what,
5950                 (void *)&cmd_mac_addr_portnum,
5951                 (void *)&cmd_mac_addr_addr,
5952                 NULL,
5953         },
5954 };
5955
5956
5957 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
5958 struct cmd_set_qmap_result {
5959         cmdline_fixed_string_t set;
5960         cmdline_fixed_string_t qmap;
5961         cmdline_fixed_string_t what;
5962         uint8_t port_id;
5963         uint16_t queue_id;
5964         uint8_t map_value;
5965 };
5966
5967 static void
5968 cmd_set_qmap_parsed(void *parsed_result,
5969                        __attribute__((unused)) struct cmdline *cl,
5970                        __attribute__((unused)) void *data)
5971 {
5972         struct cmd_set_qmap_result *res = parsed_result;
5973         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
5974
5975         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
5976 }
5977
5978 cmdline_parse_token_string_t cmd_setqmap_set =
5979         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5980                                  set, "set");
5981 cmdline_parse_token_string_t cmd_setqmap_qmap =
5982         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5983                                  qmap, "stat_qmap");
5984 cmdline_parse_token_string_t cmd_setqmap_what =
5985         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5986                                  what, "tx#rx");
5987 cmdline_parse_token_num_t cmd_setqmap_portid =
5988         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5989                               port_id, UINT8);
5990 cmdline_parse_token_num_t cmd_setqmap_queueid =
5991         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5992                               queue_id, UINT16);
5993 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
5994         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5995                               map_value, UINT8);
5996
5997 cmdline_parse_inst_t cmd_set_qmap = {
5998         .f = cmd_set_qmap_parsed,
5999         .data = NULL,
6000         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
6001         .tokens = {
6002                 (void *)&cmd_setqmap_set,
6003                 (void *)&cmd_setqmap_qmap,
6004                 (void *)&cmd_setqmap_what,
6005                 (void *)&cmd_setqmap_portid,
6006                 (void *)&cmd_setqmap_queueid,
6007                 (void *)&cmd_setqmap_mapvalue,
6008                 NULL,
6009         },
6010 };
6011
6012 /* *** CONFIGURE UNICAST HASH TABLE *** */
6013 struct cmd_set_uc_hash_table {
6014         cmdline_fixed_string_t set;
6015         cmdline_fixed_string_t port;
6016         uint8_t port_id;
6017         cmdline_fixed_string_t what;
6018         struct ether_addr address;
6019         cmdline_fixed_string_t mode;
6020 };
6021
6022 static void
6023 cmd_set_uc_hash_parsed(void *parsed_result,
6024                        __attribute__((unused)) struct cmdline *cl,
6025                        __attribute__((unused)) void *data)
6026 {
6027         int ret=0;
6028         struct cmd_set_uc_hash_table *res = parsed_result;
6029
6030         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6031
6032         if (strcmp(res->what, "uta") == 0)
6033                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6034                                                 &res->address,(uint8_t)is_on);
6035         if (ret < 0)
6036                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6037
6038 }
6039
6040 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6041         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6042                                  set, "set");
6043 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6044         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6045                                  port, "port");
6046 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6047         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6048                               port_id, UINT8);
6049 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6050         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6051                                  what, "uta");
6052 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6053         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6054                                 address);
6055 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6056         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6057                                  mode, "on#off");
6058
6059 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6060         .f = cmd_set_uc_hash_parsed,
6061         .data = NULL,
6062         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
6063         .tokens = {
6064                 (void *)&cmd_set_uc_hash_set,
6065                 (void *)&cmd_set_uc_hash_port,
6066                 (void *)&cmd_set_uc_hash_portid,
6067                 (void *)&cmd_set_uc_hash_what,
6068                 (void *)&cmd_set_uc_hash_mac,
6069                 (void *)&cmd_set_uc_hash_mode,
6070                 NULL,
6071         },
6072 };
6073
6074 struct cmd_set_uc_all_hash_table {
6075         cmdline_fixed_string_t set;
6076         cmdline_fixed_string_t port;
6077         uint8_t port_id;
6078         cmdline_fixed_string_t what;
6079         cmdline_fixed_string_t value;
6080         cmdline_fixed_string_t mode;
6081 };
6082
6083 static void
6084 cmd_set_uc_all_hash_parsed(void *parsed_result,
6085                        __attribute__((unused)) struct cmdline *cl,
6086                        __attribute__((unused)) void *data)
6087 {
6088         int ret=0;
6089         struct cmd_set_uc_all_hash_table *res = parsed_result;
6090
6091         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6092
6093         if ((strcmp(res->what, "uta") == 0) &&
6094                 (strcmp(res->value, "all") == 0))
6095                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6096         if (ret < 0)
6097                 printf("bad unicast hash table parameter,"
6098                         "return code = %d \n", ret);
6099 }
6100
6101 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6102         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6103                                  set, "set");
6104 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6105         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6106                                  port, "port");
6107 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6108         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6109                               port_id, UINT8);
6110 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6111         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6112                                  what, "uta");
6113 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6114         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6115                                 value,"all");
6116 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6117         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6118                                  mode, "on#off");
6119
6120 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6121         .f = cmd_set_uc_all_hash_parsed,
6122         .data = NULL,
6123         .help_str = "set port X uta all on|off (X = port number)",
6124         .tokens = {
6125                 (void *)&cmd_set_uc_all_hash_set,
6126                 (void *)&cmd_set_uc_all_hash_port,
6127                 (void *)&cmd_set_uc_all_hash_portid,
6128                 (void *)&cmd_set_uc_all_hash_what,
6129                 (void *)&cmd_set_uc_all_hash_value,
6130                 (void *)&cmd_set_uc_all_hash_mode,
6131                 NULL,
6132         },
6133 };
6134
6135 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6136 struct cmd_set_vf_macvlan_filter {
6137         cmdline_fixed_string_t set;
6138         cmdline_fixed_string_t port;
6139         uint8_t port_id;
6140         cmdline_fixed_string_t vf;
6141         uint8_t vf_id;
6142         struct ether_addr address;
6143         cmdline_fixed_string_t filter_type;
6144         cmdline_fixed_string_t mode;
6145 };
6146
6147 static void
6148 cmd_set_vf_macvlan_parsed(void *parsed_result,
6149                        __attribute__((unused)) struct cmdline *cl,
6150                        __attribute__((unused)) void *data)
6151 {
6152         int is_on, ret = 0;
6153         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6154         struct rte_eth_mac_filter filter;
6155
6156         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6157
6158         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6159
6160         /* set VF MAC filter */
6161         filter.is_vf = 1;
6162
6163         /* set VF ID */
6164         filter.dst_id = res->vf_id;
6165
6166         if (!strcmp(res->filter_type, "exact-mac"))
6167                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6168         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6169                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6170         else if (!strcmp(res->filter_type, "hashmac"))
6171                 filter.filter_type = RTE_MAC_HASH_MATCH;
6172         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6173                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6174
6175         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6176
6177         if (is_on)
6178                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6179                                         RTE_ETH_FILTER_MACVLAN,
6180                                         RTE_ETH_FILTER_ADD,
6181                                          &filter);
6182         else
6183                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6184                                         RTE_ETH_FILTER_MACVLAN,
6185                                         RTE_ETH_FILTER_DELETE,
6186                                         &filter);
6187
6188         if (ret < 0)
6189                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6190
6191 }
6192
6193 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6194         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6195                                  set, "set");
6196 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6197         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6198                                  port, "port");
6199 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6200         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6201                               port_id, UINT8);
6202 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6203         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6204                                  vf, "vf");
6205 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6206         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6207                                 vf_id, UINT8);
6208 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6209         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6210                                 address);
6211 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6212         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6213                                 filter_type, "exact-mac#exact-mac-vlan"
6214                                 "#hashmac#hashmac-vlan");
6215 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6216         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6217                                  mode, "on#off");
6218
6219 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6220         .f = cmd_set_vf_macvlan_parsed,
6221         .data = NULL,
6222         .help_str = "set port (portid) vf (vfid) (mac-addr) "
6223                         "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) "
6224                         "on|off\n"
6225                         "exact match rule:exact match of MAC or MAC and VLAN; "
6226                         "hash match rule: hash match of MAC and exact match "
6227                         "of VLAN",
6228         .tokens = {
6229                 (void *)&cmd_set_vf_macvlan_set,
6230                 (void *)&cmd_set_vf_macvlan_port,
6231                 (void *)&cmd_set_vf_macvlan_portid,
6232                 (void *)&cmd_set_vf_macvlan_vf,
6233                 (void *)&cmd_set_vf_macvlan_vf_id,
6234                 (void *)&cmd_set_vf_macvlan_mac,
6235                 (void *)&cmd_set_vf_macvlan_filter_type,
6236                 (void *)&cmd_set_vf_macvlan_mode,
6237                 NULL,
6238         },
6239 };
6240
6241 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6242 struct cmd_set_vf_traffic {
6243         cmdline_fixed_string_t set;
6244         cmdline_fixed_string_t port;
6245         uint8_t port_id;
6246         cmdline_fixed_string_t vf;
6247         uint8_t vf_id;
6248         cmdline_fixed_string_t what;
6249         cmdline_fixed_string_t mode;
6250 };
6251
6252 static void
6253 cmd_set_vf_traffic_parsed(void *parsed_result,
6254                        __attribute__((unused)) struct cmdline *cl,
6255                        __attribute__((unused)) void *data)
6256 {
6257         struct cmd_set_vf_traffic *res = parsed_result;
6258         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6259         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6260
6261         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6262 }
6263
6264 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6265         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6266                                  set, "set");
6267 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6268         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6269                                  port, "port");
6270 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6271         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6272                               port_id, UINT8);
6273 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6274         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6275                                  vf, "vf");
6276 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6277         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6278                               vf_id, UINT8);
6279 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6280         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6281                                  what, "tx#rx");
6282 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6283         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6284                                  mode, "on#off");
6285
6286 cmdline_parse_inst_t cmd_set_vf_traffic = {
6287         .f = cmd_set_vf_traffic_parsed,
6288         .data = NULL,
6289         .help_str = "set port X vf Y rx|tx on|off"
6290                         "(X = port number,Y = vf id)",
6291         .tokens = {
6292                 (void *)&cmd_setvf_traffic_set,
6293                 (void *)&cmd_setvf_traffic_port,
6294                 (void *)&cmd_setvf_traffic_portid,
6295                 (void *)&cmd_setvf_traffic_vf,
6296                 (void *)&cmd_setvf_traffic_vfid,
6297                 (void *)&cmd_setvf_traffic_what,
6298                 (void *)&cmd_setvf_traffic_mode,
6299                 NULL,
6300         },
6301 };
6302
6303 /* *** CONFIGURE VF RECEIVE MODE *** */
6304 struct cmd_set_vf_rxmode {
6305         cmdline_fixed_string_t set;
6306         cmdline_fixed_string_t port;
6307         uint8_t port_id;
6308         cmdline_fixed_string_t vf;
6309         uint8_t vf_id;
6310         cmdline_fixed_string_t what;
6311         cmdline_fixed_string_t mode;
6312         cmdline_fixed_string_t on;
6313 };
6314
6315 static void
6316 cmd_set_vf_rxmode_parsed(void *parsed_result,
6317                        __attribute__((unused)) struct cmdline *cl,
6318                        __attribute__((unused)) void *data)
6319 {
6320         int ret;
6321         uint16_t rx_mode = 0;
6322         struct cmd_set_vf_rxmode *res = parsed_result;
6323
6324         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6325         if (!strcmp(res->what,"rxmode")) {
6326                 if (!strcmp(res->mode, "AUPE"))
6327                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6328                 else if (!strcmp(res->mode, "ROPE"))
6329                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6330                 else if (!strcmp(res->mode, "BAM"))
6331                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6332                 else if (!strncmp(res->mode, "MPE",3))
6333                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6334         }
6335
6336         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
6337         if (ret < 0)
6338                 printf("bad VF receive mode parameter, return code = %d \n",
6339                 ret);
6340 }
6341
6342 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6343         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6344                                  set, "set");
6345 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6346         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6347                                  port, "port");
6348 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6349         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6350                               port_id, UINT8);
6351 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6352         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6353                                  vf, "vf");
6354 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6355         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6356                               vf_id, UINT8);
6357 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6358         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6359                                  what, "rxmode");
6360 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6361         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6362                                  mode, "AUPE#ROPE#BAM#MPE");
6363 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6364         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6365                                  on, "on#off");
6366
6367 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6368         .f = cmd_set_vf_rxmode_parsed,
6369         .data = NULL,
6370         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
6371         .tokens = {
6372                 (void *)&cmd_set_vf_rxmode_set,
6373                 (void *)&cmd_set_vf_rxmode_port,
6374                 (void *)&cmd_set_vf_rxmode_portid,
6375                 (void *)&cmd_set_vf_rxmode_vf,
6376                 (void *)&cmd_set_vf_rxmode_vfid,
6377                 (void *)&cmd_set_vf_rxmode_what,
6378                 (void *)&cmd_set_vf_rxmode_mode,
6379                 (void *)&cmd_set_vf_rxmode_on,
6380                 NULL,
6381         },
6382 };
6383
6384 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6385 struct cmd_vf_mac_addr_result {
6386         cmdline_fixed_string_t mac_addr_cmd;
6387         cmdline_fixed_string_t what;
6388         cmdline_fixed_string_t port;
6389         uint8_t port_num;
6390         cmdline_fixed_string_t vf;
6391         uint8_t vf_num;
6392         struct ether_addr address;
6393 };
6394
6395 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6396                 __attribute__((unused)) struct cmdline *cl,
6397                 __attribute__((unused)) void *data)
6398 {
6399         struct cmd_vf_mac_addr_result *res = parsed_result;
6400         int ret = 0;
6401
6402         if (strcmp(res->what, "add") == 0)
6403                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6404                                         &res->address, res->vf_num);
6405         if(ret < 0)
6406                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6407
6408 }
6409
6410 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6411         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6412                                 mac_addr_cmd,"mac_addr");
6413 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6414         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6415                                 what,"add");
6416 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6417         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6418                                 port,"port");
6419 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6420         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6421                                 port_num, UINT8);
6422 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6423         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6424                                 vf,"vf");
6425 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6426         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6427                                 vf_num, UINT8);
6428 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6429         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6430                                 address);
6431
6432 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6433         .f = cmd_vf_mac_addr_parsed,
6434         .data = (void *)0,
6435         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
6436         "Y = VF number)add MAC address filtering for a VF on port X",
6437         .tokens = {
6438                 (void *)&cmd_vf_mac_addr_cmd,
6439                 (void *)&cmd_vf_mac_addr_what,
6440                 (void *)&cmd_vf_mac_addr_port,
6441                 (void *)&cmd_vf_mac_addr_portnum,
6442                 (void *)&cmd_vf_mac_addr_vf,
6443                 (void *)&cmd_vf_mac_addr_vfnum,
6444                 (void *)&cmd_vf_mac_addr_addr,
6445                 NULL,
6446         },
6447 };
6448
6449 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6450 struct cmd_vf_rx_vlan_filter {
6451         cmdline_fixed_string_t rx_vlan;
6452         cmdline_fixed_string_t what;
6453         uint16_t vlan_id;
6454         cmdline_fixed_string_t port;
6455         uint8_t port_id;
6456         cmdline_fixed_string_t vf;
6457         uint64_t vf_mask;
6458 };
6459
6460 static void
6461 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6462                           __attribute__((unused)) struct cmdline *cl,
6463                           __attribute__((unused)) void *data)
6464 {
6465         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6466
6467         if (!strcmp(res->what, "add"))
6468                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6469         else
6470                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6471 }
6472
6473 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6474         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6475                                  rx_vlan, "rx_vlan");
6476 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6477         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6478                                  what, "add#rm");
6479 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6480         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6481                               vlan_id, UINT16);
6482 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6483         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6484                                  port, "port");
6485 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6486         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6487                               port_id, UINT8);
6488 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6489         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6490                                  vf, "vf");
6491 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6492         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6493                               vf_mask, UINT64);
6494
6495 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6496         .f = cmd_vf_rx_vlan_filter_parsed,
6497         .data = NULL,
6498         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
6499                 "Y = port number,Z = hexadecimal VF mask)",
6500         .tokens = {
6501                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6502                 (void *)&cmd_vf_rx_vlan_filter_what,
6503                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6504                 (void *)&cmd_vf_rx_vlan_filter_port,
6505                 (void *)&cmd_vf_rx_vlan_filter_portid,
6506                 (void *)&cmd_vf_rx_vlan_filter_vf,
6507                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6508                 NULL,
6509         },
6510 };
6511
6512 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6513 struct cmd_queue_rate_limit_result {
6514         cmdline_fixed_string_t set;
6515         cmdline_fixed_string_t port;
6516         uint8_t port_num;
6517         cmdline_fixed_string_t queue;
6518         uint8_t queue_num;
6519         cmdline_fixed_string_t rate;
6520         uint16_t rate_num;
6521 };
6522
6523 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6524                 __attribute__((unused)) struct cmdline *cl,
6525                 __attribute__((unused)) void *data)
6526 {
6527         struct cmd_queue_rate_limit_result *res = parsed_result;
6528         int ret = 0;
6529
6530         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6531                 && (strcmp(res->queue, "queue") == 0)
6532                 && (strcmp(res->rate, "rate") == 0))
6533                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6534                                         res->rate_num);
6535         if (ret < 0)
6536                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6537
6538 }
6539
6540 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6541         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6542                                 set, "set");
6543 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6544         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6545                                 port, "port");
6546 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6547         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6548                                 port_num, UINT8);
6549 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6550         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6551                                 queue, "queue");
6552 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6553         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6554                                 queue_num, UINT8);
6555 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6556         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6557                                 rate, "rate");
6558 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6559         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6560                                 rate_num, UINT16);
6561
6562 cmdline_parse_inst_t cmd_queue_rate_limit = {
6563         .f = cmd_queue_rate_limit_parsed,
6564         .data = (void *)0,
6565         .help_str = "set port X queue Y rate Z:(X = port number,"
6566         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6567         .tokens = {
6568                 (void *)&cmd_queue_rate_limit_set,
6569                 (void *)&cmd_queue_rate_limit_port,
6570                 (void *)&cmd_queue_rate_limit_portnum,
6571                 (void *)&cmd_queue_rate_limit_queue,
6572                 (void *)&cmd_queue_rate_limit_queuenum,
6573                 (void *)&cmd_queue_rate_limit_rate,
6574                 (void *)&cmd_queue_rate_limit_ratenum,
6575                 NULL,
6576         },
6577 };
6578
6579 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6580 struct cmd_vf_rate_limit_result {
6581         cmdline_fixed_string_t set;
6582         cmdline_fixed_string_t port;
6583         uint8_t port_num;
6584         cmdline_fixed_string_t vf;
6585         uint8_t vf_num;
6586         cmdline_fixed_string_t rate;
6587         uint16_t rate_num;
6588         cmdline_fixed_string_t q_msk;
6589         uint64_t q_msk_val;
6590 };
6591
6592 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6593                 __attribute__((unused)) struct cmdline *cl,
6594                 __attribute__((unused)) void *data)
6595 {
6596         struct cmd_vf_rate_limit_result *res = parsed_result;
6597         int ret = 0;
6598
6599         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6600                 && (strcmp(res->vf, "vf") == 0)
6601                 && (strcmp(res->rate, "rate") == 0)
6602                 && (strcmp(res->q_msk, "queue_mask") == 0))
6603                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6604                                         res->rate_num, res->q_msk_val);
6605         if (ret < 0)
6606                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6607
6608 }
6609
6610 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6611         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6612                                 set, "set");
6613 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6614         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6615                                 port, "port");
6616 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6617         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6618                                 port_num, UINT8);
6619 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6620         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6621                                 vf, "vf");
6622 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6623         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6624                                 vf_num, UINT8);
6625 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6626         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6627                                 rate, "rate");
6628 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6629         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6630                                 rate_num, UINT16);
6631 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6632         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6633                                 q_msk, "queue_mask");
6634 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6635         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6636                                 q_msk_val, UINT64);
6637
6638 cmdline_parse_inst_t cmd_vf_rate_limit = {
6639         .f = cmd_vf_rate_limit_parsed,
6640         .data = (void *)0,
6641         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6642         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6643         "for queues of VF on port X",
6644         .tokens = {
6645                 (void *)&cmd_vf_rate_limit_set,
6646                 (void *)&cmd_vf_rate_limit_port,
6647                 (void *)&cmd_vf_rate_limit_portnum,
6648                 (void *)&cmd_vf_rate_limit_vf,
6649                 (void *)&cmd_vf_rate_limit_vfnum,
6650                 (void *)&cmd_vf_rate_limit_rate,
6651                 (void *)&cmd_vf_rate_limit_ratenum,
6652                 (void *)&cmd_vf_rate_limit_q_msk,
6653                 (void *)&cmd_vf_rate_limit_q_msk_val,
6654                 NULL,
6655         },
6656 };
6657
6658 /* *** ADD TUNNEL FILTER OF A PORT *** */
6659 struct cmd_tunnel_filter_result {
6660         cmdline_fixed_string_t cmd;
6661         cmdline_fixed_string_t what;
6662         uint8_t port_id;
6663         struct ether_addr outer_mac;
6664         struct ether_addr inner_mac;
6665         cmdline_ipaddr_t ip_value;
6666         uint16_t inner_vlan;
6667         cmdline_fixed_string_t tunnel_type;
6668         cmdline_fixed_string_t filter_type;
6669         uint32_t tenant_id;
6670         uint16_t queue_num;
6671 };
6672
6673 static void
6674 cmd_tunnel_filter_parsed(void *parsed_result,
6675                           __attribute__((unused)) struct cmdline *cl,
6676                           __attribute__((unused)) void *data)
6677 {
6678         struct cmd_tunnel_filter_result *res = parsed_result;
6679         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
6680         int ret = 0;
6681
6682         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
6683
6684         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
6685         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
6686         tunnel_filter_conf.inner_vlan = res->inner_vlan;
6687
6688         if (res->ip_value.family == AF_INET) {
6689                 tunnel_filter_conf.ip_addr.ipv4_addr =
6690                         res->ip_value.addr.ipv4.s_addr;
6691                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
6692         } else {
6693                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
6694                         &(res->ip_value.addr.ipv6),
6695                         sizeof(struct in6_addr));
6696                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
6697         }
6698
6699         if (!strcmp(res->filter_type, "imac-ivlan"))
6700                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
6701         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
6702                 tunnel_filter_conf.filter_type =
6703                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
6704         else if (!strcmp(res->filter_type, "imac-tenid"))
6705                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
6706         else if (!strcmp(res->filter_type, "imac"))
6707                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
6708         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
6709                 tunnel_filter_conf.filter_type =
6710                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
6711         else if (!strcmp(res->filter_type, "oip"))
6712                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
6713         else if (!strcmp(res->filter_type, "iip"))
6714                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
6715         else {
6716                 printf("The filter type is not supported");
6717                 return;
6718         }
6719
6720         if (!strcmp(res->tunnel_type, "vxlan"))
6721                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
6722         else if (!strcmp(res->tunnel_type, "nvgre"))
6723                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
6724         else if (!strcmp(res->tunnel_type, "ipingre"))
6725                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
6726         else {
6727                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
6728                 return;
6729         }
6730
6731         tunnel_filter_conf.tenant_id = res->tenant_id;
6732         tunnel_filter_conf.queue_id = res->queue_num;
6733         if (!strcmp(res->what, "add"))
6734                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6735                                         RTE_ETH_FILTER_TUNNEL,
6736                                         RTE_ETH_FILTER_ADD,
6737                                         &tunnel_filter_conf);
6738         else
6739                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6740                                         RTE_ETH_FILTER_TUNNEL,
6741                                         RTE_ETH_FILTER_DELETE,
6742                                         &tunnel_filter_conf);
6743         if (ret < 0)
6744                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
6745                                 strerror(-ret));
6746
6747 }
6748 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
6749         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6750         cmd, "tunnel_filter");
6751 cmdline_parse_token_string_t cmd_tunnel_filter_what =
6752         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6753         what, "add#rm");
6754 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
6755         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6756         port_id, UINT8);
6757 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
6758         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6759         outer_mac);
6760 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
6761         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6762         inner_mac);
6763 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
6764         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6765         inner_vlan, UINT16);
6766 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
6767         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6768         ip_value);
6769 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
6770         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6771         tunnel_type, "vxlan#nvgre#ipingre");
6772
6773 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
6774         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6775         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
6776                 "imac#omac-imac-tenid");
6777 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
6778         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6779         tenant_id, UINT32);
6780 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
6781         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6782         queue_num, UINT16);
6783
6784 cmdline_parse_inst_t cmd_tunnel_filter = {
6785         .f = cmd_tunnel_filter_parsed,
6786         .data = (void *)0,
6787         .help_str = "add/rm tunnel filter of a port: "
6788                         "tunnel_filter add port_id outer_mac inner_mac ip "
6789                         "inner_vlan tunnel_type(vxlan|nvgre|ipingre) filter_type "
6790                         "(oip|iip|imac-ivlan|imac-ivlan-tenid|imac-tenid|"
6791                         "imac|omac-imac-tenid) "
6792                         "tenant_id queue_num",
6793         .tokens = {
6794                 (void *)&cmd_tunnel_filter_cmd,
6795                 (void *)&cmd_tunnel_filter_what,
6796                 (void *)&cmd_tunnel_filter_port_id,
6797                 (void *)&cmd_tunnel_filter_outer_mac,
6798                 (void *)&cmd_tunnel_filter_inner_mac,
6799                 (void *)&cmd_tunnel_filter_ip_value,
6800                 (void *)&cmd_tunnel_filter_innner_vlan,
6801                 (void *)&cmd_tunnel_filter_tunnel_type,
6802                 (void *)&cmd_tunnel_filter_filter_type,
6803                 (void *)&cmd_tunnel_filter_tenant_id,
6804                 (void *)&cmd_tunnel_filter_queue_num,
6805                 NULL,
6806         },
6807 };
6808
6809 /* *** CONFIGURE TUNNEL UDP PORT *** */
6810 struct cmd_tunnel_udp_config {
6811         cmdline_fixed_string_t cmd;
6812         cmdline_fixed_string_t what;
6813         uint16_t udp_port;
6814         uint8_t port_id;
6815 };
6816
6817 static void
6818 cmd_tunnel_udp_config_parsed(void *parsed_result,
6819                           __attribute__((unused)) struct cmdline *cl,
6820                           __attribute__((unused)) void *data)
6821 {
6822         struct cmd_tunnel_udp_config *res = parsed_result;
6823         struct rte_eth_udp_tunnel tunnel_udp;
6824         int ret;
6825
6826         tunnel_udp.udp_port = res->udp_port;
6827
6828         if (!strcmp(res->cmd, "rx_vxlan_port"))
6829                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
6830
6831         if (!strcmp(res->what, "add"))
6832                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
6833                                                       &tunnel_udp);
6834         else
6835                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
6836                                                          &tunnel_udp);
6837
6838         if (ret < 0)
6839                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
6840 }
6841
6842 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
6843         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6844                                 cmd, "rx_vxlan_port");
6845 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
6846         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6847                                 what, "add#rm");
6848 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
6849         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6850                                 udp_port, UINT16);
6851 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
6852         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6853                                 port_id, UINT8);
6854
6855 cmdline_parse_inst_t cmd_tunnel_udp_config = {
6856         .f = cmd_tunnel_udp_config_parsed,
6857         .data = (void *)0,
6858         .help_str = "add/rm an tunneling UDP port filter: "
6859                         "rx_vxlan_port add udp_port port_id",
6860         .tokens = {
6861                 (void *)&cmd_tunnel_udp_config_cmd,
6862                 (void *)&cmd_tunnel_udp_config_what,
6863                 (void *)&cmd_tunnel_udp_config_udp_port,
6864                 (void *)&cmd_tunnel_udp_config_port_id,
6865                 NULL,
6866         },
6867 };
6868
6869 /* *** GLOBAL CONFIG *** */
6870 struct cmd_global_config_result {
6871         cmdline_fixed_string_t cmd;
6872         uint8_t port_id;
6873         cmdline_fixed_string_t cfg_type;
6874         uint8_t len;
6875 };
6876
6877 static void
6878 cmd_global_config_parsed(void *parsed_result,
6879                          __attribute__((unused)) struct cmdline *cl,
6880                          __attribute__((unused)) void *data)
6881 {
6882         struct cmd_global_config_result *res = parsed_result;
6883         struct rte_eth_global_cfg conf;
6884         int ret;
6885
6886         memset(&conf, 0, sizeof(conf));
6887         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
6888         conf.cfg.gre_key_len = res->len;
6889         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
6890                                       RTE_ETH_FILTER_SET, &conf);
6891         if (ret != 0)
6892                 printf("Global config error\n");
6893 }
6894
6895 cmdline_parse_token_string_t cmd_global_config_cmd =
6896         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
6897                 "global_config");
6898 cmdline_parse_token_num_t cmd_global_config_port_id =
6899         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
6900 cmdline_parse_token_string_t cmd_global_config_type =
6901         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
6902                 cfg_type, "gre-key-len");
6903 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
6904         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
6905                 len, UINT8);
6906
6907 cmdline_parse_inst_t cmd_global_config = {
6908         .f = cmd_global_config_parsed,
6909         .data = (void *)NULL,
6910         .help_str = "global_config <port_id> gre-key-len <number>",
6911         .tokens = {
6912                 (void *)&cmd_global_config_cmd,
6913                 (void *)&cmd_global_config_port_id,
6914                 (void *)&cmd_global_config_type,
6915                 (void *)&cmd_global_config_gre_key_len,
6916                 NULL,
6917         },
6918 };
6919
6920 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
6921 struct cmd_set_mirror_mask_result {
6922         cmdline_fixed_string_t set;
6923         cmdline_fixed_string_t port;
6924         uint8_t port_id;
6925         cmdline_fixed_string_t mirror;
6926         uint8_t rule_id;
6927         cmdline_fixed_string_t what;
6928         cmdline_fixed_string_t value;
6929         cmdline_fixed_string_t dstpool;
6930         uint8_t dstpool_id;
6931         cmdline_fixed_string_t on;
6932 };
6933
6934 cmdline_parse_token_string_t cmd_mirror_mask_set =
6935         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6936                                 set, "set");
6937 cmdline_parse_token_string_t cmd_mirror_mask_port =
6938         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6939                                 port, "port");
6940 cmdline_parse_token_num_t cmd_mirror_mask_portid =
6941         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6942                                 port_id, UINT8);
6943 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
6944         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6945                                 mirror, "mirror-rule");
6946 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
6947         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6948                                 rule_id, UINT8);
6949 cmdline_parse_token_string_t cmd_mirror_mask_what =
6950         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6951                                 what, "pool-mirror-up#pool-mirror-down"
6952                                       "#vlan-mirror");
6953 cmdline_parse_token_string_t cmd_mirror_mask_value =
6954         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6955                                 value, NULL);
6956 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
6957         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6958                                 dstpool, "dst-pool");
6959 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
6960         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6961                                 dstpool_id, UINT8);
6962 cmdline_parse_token_string_t cmd_mirror_mask_on =
6963         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6964                                 on, "on#off");
6965
6966 static void
6967 cmd_set_mirror_mask_parsed(void *parsed_result,
6968                        __attribute__((unused)) struct cmdline *cl,
6969                        __attribute__((unused)) void *data)
6970 {
6971         int ret,nb_item,i;
6972         struct cmd_set_mirror_mask_result *res = parsed_result;
6973         struct rte_eth_mirror_conf mr_conf;
6974
6975         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
6976
6977         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
6978
6979         mr_conf.dst_pool = res->dstpool_id;
6980
6981         if (!strcmp(res->what, "pool-mirror-up")) {
6982                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6983                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
6984         } else if (!strcmp(res->what, "pool-mirror-down")) {
6985                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6986                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
6987         } else if (!strcmp(res->what, "vlan-mirror")) {
6988                 mr_conf.rule_type = ETH_MIRROR_VLAN;
6989                 nb_item = parse_item_list(res->value, "vlan",
6990                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
6991                 if (nb_item <= 0)
6992                         return;
6993
6994                 for (i = 0; i < nb_item; i++) {
6995                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
6996                                 printf("Invalid vlan_id: must be < 4096\n");
6997                                 return;
6998                         }
6999
7000                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
7001                         mr_conf.vlan.vlan_mask |= 1ULL << i;
7002                 }
7003         }
7004
7005         if (!strcmp(res->on, "on"))
7006                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7007                                                 res->rule_id, 1);
7008         else
7009                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7010                                                 res->rule_id, 0);
7011         if (ret < 0)
7012                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7013 }
7014
7015 cmdline_parse_inst_t cmd_set_mirror_mask = {
7016                 .f = cmd_set_mirror_mask_parsed,
7017                 .data = NULL,
7018                 .help_str = "set port X mirror-rule Y pool-mirror-up|pool-mirror-down|vlan-mirror"
7019                             " pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
7020                 .tokens = {
7021                         (void *)&cmd_mirror_mask_set,
7022                         (void *)&cmd_mirror_mask_port,
7023                         (void *)&cmd_mirror_mask_portid,
7024                         (void *)&cmd_mirror_mask_mirror,
7025                         (void *)&cmd_mirror_mask_ruleid,
7026                         (void *)&cmd_mirror_mask_what,
7027                         (void *)&cmd_mirror_mask_value,
7028                         (void *)&cmd_mirror_mask_dstpool,
7029                         (void *)&cmd_mirror_mask_poolid,
7030                         (void *)&cmd_mirror_mask_on,
7031                         NULL,
7032                 },
7033 };
7034
7035 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
7036 struct cmd_set_mirror_link_result {
7037         cmdline_fixed_string_t set;
7038         cmdline_fixed_string_t port;
7039         uint8_t port_id;
7040         cmdline_fixed_string_t mirror;
7041         uint8_t rule_id;
7042         cmdline_fixed_string_t what;
7043         cmdline_fixed_string_t dstpool;
7044         uint8_t dstpool_id;
7045         cmdline_fixed_string_t on;
7046 };
7047
7048 cmdline_parse_token_string_t cmd_mirror_link_set =
7049         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7050                                  set, "set");
7051 cmdline_parse_token_string_t cmd_mirror_link_port =
7052         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7053                                 port, "port");
7054 cmdline_parse_token_num_t cmd_mirror_link_portid =
7055         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7056                                 port_id, UINT8);
7057 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7058         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7059                                 mirror, "mirror-rule");
7060 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7061         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7062                             rule_id, UINT8);
7063 cmdline_parse_token_string_t cmd_mirror_link_what =
7064         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7065                                 what, "uplink-mirror#downlink-mirror");
7066 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7067         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7068                                 dstpool, "dst-pool");
7069 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7070         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7071                                 dstpool_id, UINT8);
7072 cmdline_parse_token_string_t cmd_mirror_link_on =
7073         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7074                                 on, "on#off");
7075
7076 static void
7077 cmd_set_mirror_link_parsed(void *parsed_result,
7078                        __attribute__((unused)) struct cmdline *cl,
7079                        __attribute__((unused)) void *data)
7080 {
7081         int ret;
7082         struct cmd_set_mirror_link_result *res = parsed_result;
7083         struct rte_eth_mirror_conf mr_conf;
7084
7085         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7086         if (!strcmp(res->what, "uplink-mirror"))
7087                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7088         else
7089                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7090
7091         mr_conf.dst_pool = res->dstpool_id;
7092
7093         if (!strcmp(res->on, "on"))
7094                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7095                                                 res->rule_id, 1);
7096         else
7097                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7098                                                 res->rule_id, 0);
7099
7100         /* check the return value and print it if is < 0 */
7101         if (ret < 0)
7102                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7103
7104 }
7105
7106 cmdline_parse_inst_t cmd_set_mirror_link = {
7107                 .f = cmd_set_mirror_link_parsed,
7108                 .data = NULL,
7109                 .help_str = "set port X mirror-rule Y uplink-mirror|"
7110                         "downlink-mirror dst-pool Z on|off",
7111                 .tokens = {
7112                         (void *)&cmd_mirror_link_set,
7113                         (void *)&cmd_mirror_link_port,
7114                         (void *)&cmd_mirror_link_portid,
7115                         (void *)&cmd_mirror_link_mirror,
7116                         (void *)&cmd_mirror_link_ruleid,
7117                         (void *)&cmd_mirror_link_what,
7118                         (void *)&cmd_mirror_link_dstpool,
7119                         (void *)&cmd_mirror_link_poolid,
7120                         (void *)&cmd_mirror_link_on,
7121                         NULL,
7122                 },
7123 };
7124
7125 /* *** RESET VM MIRROR RULE *** */
7126 struct cmd_rm_mirror_rule_result {
7127         cmdline_fixed_string_t reset;
7128         cmdline_fixed_string_t port;
7129         uint8_t port_id;
7130         cmdline_fixed_string_t mirror;
7131         uint8_t rule_id;
7132 };
7133
7134 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7135         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7136                                  reset, "reset");
7137 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7138         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7139                                 port, "port");
7140 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7141         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7142                                 port_id, UINT8);
7143 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7144         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7145                                 mirror, "mirror-rule");
7146 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7147         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7148                                 rule_id, UINT8);
7149
7150 static void
7151 cmd_reset_mirror_rule_parsed(void *parsed_result,
7152                        __attribute__((unused)) struct cmdline *cl,
7153                        __attribute__((unused)) void *data)
7154 {
7155         int ret;
7156         struct cmd_set_mirror_link_result *res = parsed_result;
7157         /* check rule_id */
7158         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7159         if(ret < 0)
7160                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7161 }
7162
7163 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7164                 .f = cmd_reset_mirror_rule_parsed,
7165                 .data = NULL,
7166                 .help_str = "reset port X mirror-rule Y",
7167                 .tokens = {
7168                         (void *)&cmd_rm_mirror_rule_reset,
7169                         (void *)&cmd_rm_mirror_rule_port,
7170                         (void *)&cmd_rm_mirror_rule_portid,
7171                         (void *)&cmd_rm_mirror_rule_mirror,
7172                         (void *)&cmd_rm_mirror_rule_ruleid,
7173                         NULL,
7174                 },
7175 };
7176
7177 /* ******************************************************************************** */
7178
7179 struct cmd_dump_result {
7180         cmdline_fixed_string_t dump;
7181 };
7182
7183 static void
7184 dump_struct_sizes(void)
7185 {
7186 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7187         DUMP_SIZE(struct rte_mbuf);
7188         DUMP_SIZE(struct rte_mempool);
7189         DUMP_SIZE(struct rte_ring);
7190 #undef DUMP_SIZE
7191 }
7192
7193 static void cmd_dump_parsed(void *parsed_result,
7194                             __attribute__((unused)) struct cmdline *cl,
7195                             __attribute__((unused)) void *data)
7196 {
7197         struct cmd_dump_result *res = parsed_result;
7198
7199         if (!strcmp(res->dump, "dump_physmem"))
7200                 rte_dump_physmem_layout(stdout);
7201         else if (!strcmp(res->dump, "dump_memzone"))
7202                 rte_memzone_dump(stdout);
7203         else if (!strcmp(res->dump, "dump_log_history"))
7204                 rte_log_dump_history(stdout);
7205         else if (!strcmp(res->dump, "dump_struct_sizes"))
7206                 dump_struct_sizes();
7207         else if (!strcmp(res->dump, "dump_ring"))
7208                 rte_ring_list_dump(stdout);
7209         else if (!strcmp(res->dump, "dump_mempool"))
7210                 rte_mempool_list_dump(stdout);
7211         else if (!strcmp(res->dump, "dump_devargs"))
7212                 rte_eal_devargs_dump(stdout);
7213 }
7214
7215 cmdline_parse_token_string_t cmd_dump_dump =
7216         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7217                 "dump_physmem#"
7218                 "dump_memzone#"
7219                 "dump_log_history#"
7220                 "dump_struct_sizes#"
7221                 "dump_ring#"
7222                 "dump_mempool#"
7223                 "dump_devargs");
7224
7225 cmdline_parse_inst_t cmd_dump = {
7226         .f = cmd_dump_parsed,  /* function to call */
7227         .data = NULL,      /* 2nd arg of func */
7228         .help_str = "dump status",
7229         .tokens = {        /* token list, NULL terminated */
7230                 (void *)&cmd_dump_dump,
7231                 NULL,
7232         },
7233 };
7234
7235 /* ******************************************************************************** */
7236
7237 struct cmd_dump_one_result {
7238         cmdline_fixed_string_t dump;
7239         cmdline_fixed_string_t name;
7240 };
7241
7242 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7243                                 __attribute__((unused)) void *data)
7244 {
7245         struct cmd_dump_one_result *res = parsed_result;
7246
7247         if (!strcmp(res->dump, "dump_ring")) {
7248                 struct rte_ring *r;
7249                 r = rte_ring_lookup(res->name);
7250                 if (r == NULL) {
7251                         cmdline_printf(cl, "Cannot find ring\n");
7252                         return;
7253                 }
7254                 rte_ring_dump(stdout, r);
7255         } else if (!strcmp(res->dump, "dump_mempool")) {
7256                 struct rte_mempool *mp;
7257                 mp = rte_mempool_lookup(res->name);
7258                 if (mp == NULL) {
7259                         cmdline_printf(cl, "Cannot find mempool\n");
7260                         return;
7261                 }
7262                 rte_mempool_dump(stdout, mp);
7263         }
7264 }
7265
7266 cmdline_parse_token_string_t cmd_dump_one_dump =
7267         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7268                                  "dump_ring#dump_mempool");
7269
7270 cmdline_parse_token_string_t cmd_dump_one_name =
7271         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7272
7273 cmdline_parse_inst_t cmd_dump_one = {
7274         .f = cmd_dump_one_parsed,  /* function to call */
7275         .data = NULL,      /* 2nd arg of func */
7276         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
7277         .tokens = {        /* token list, NULL terminated */
7278                 (void *)&cmd_dump_one_dump,
7279                 (void *)&cmd_dump_one_name,
7280                 NULL,
7281         },
7282 };
7283
7284 /* *** Add/Del syn filter *** */
7285 struct cmd_syn_filter_result {
7286         cmdline_fixed_string_t filter;
7287         uint8_t port_id;
7288         cmdline_fixed_string_t ops;
7289         cmdline_fixed_string_t priority;
7290         cmdline_fixed_string_t high;
7291         cmdline_fixed_string_t queue;
7292         uint16_t queue_id;
7293 };
7294
7295 static void
7296 cmd_syn_filter_parsed(void *parsed_result,
7297                         __attribute__((unused)) struct cmdline *cl,
7298                         __attribute__((unused)) void *data)
7299 {
7300         struct cmd_syn_filter_result *res = parsed_result;
7301         struct rte_eth_syn_filter syn_filter;
7302         int ret = 0;
7303
7304         ret = rte_eth_dev_filter_supported(res->port_id,
7305                                         RTE_ETH_FILTER_SYN);
7306         if (ret < 0) {
7307                 printf("syn filter is not supported on port %u.\n",
7308                                 res->port_id);
7309                 return;
7310         }
7311
7312         memset(&syn_filter, 0, sizeof(syn_filter));
7313
7314         if (!strcmp(res->ops, "add")) {
7315                 if (!strcmp(res->high, "high"))
7316                         syn_filter.hig_pri = 1;
7317                 else
7318                         syn_filter.hig_pri = 0;
7319
7320                 syn_filter.queue = res->queue_id;
7321                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7322                                                 RTE_ETH_FILTER_SYN,
7323                                                 RTE_ETH_FILTER_ADD,
7324                                                 &syn_filter);
7325         } else
7326                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7327                                                 RTE_ETH_FILTER_SYN,
7328                                                 RTE_ETH_FILTER_DELETE,
7329                                                 &syn_filter);
7330
7331         if (ret < 0)
7332                 printf("syn filter programming error: (%s)\n",
7333                                 strerror(-ret));
7334 }
7335
7336 cmdline_parse_token_string_t cmd_syn_filter_filter =
7337         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7338         filter, "syn_filter");
7339 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7340         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7341         port_id, UINT8);
7342 cmdline_parse_token_string_t cmd_syn_filter_ops =
7343         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7344         ops, "add#del");
7345 cmdline_parse_token_string_t cmd_syn_filter_priority =
7346         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7347                                 priority, "priority");
7348 cmdline_parse_token_string_t cmd_syn_filter_high =
7349         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7350                                 high, "high#low");
7351 cmdline_parse_token_string_t cmd_syn_filter_queue =
7352         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7353                                 queue, "queue");
7354 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7355         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7356                                 queue_id, UINT16);
7357
7358 cmdline_parse_inst_t cmd_syn_filter = {
7359         .f = cmd_syn_filter_parsed,
7360         .data = NULL,
7361         .help_str = "add/delete syn filter",
7362         .tokens = {
7363                 (void *)&cmd_syn_filter_filter,
7364                 (void *)&cmd_syn_filter_port_id,
7365                 (void *)&cmd_syn_filter_ops,
7366                 (void *)&cmd_syn_filter_priority,
7367                 (void *)&cmd_syn_filter_high,
7368                 (void *)&cmd_syn_filter_queue,
7369                 (void *)&cmd_syn_filter_queue_id,
7370                 NULL,
7371         },
7372 };
7373
7374 /* *** ADD/REMOVE A 2tuple FILTER *** */
7375 struct cmd_2tuple_filter_result {
7376         cmdline_fixed_string_t filter;
7377         uint8_t  port_id;
7378         cmdline_fixed_string_t ops;
7379         cmdline_fixed_string_t dst_port;
7380         uint16_t dst_port_value;
7381         cmdline_fixed_string_t protocol;
7382         uint8_t protocol_value;
7383         cmdline_fixed_string_t mask;
7384         uint8_t  mask_value;
7385         cmdline_fixed_string_t tcp_flags;
7386         uint8_t tcp_flags_value;
7387         cmdline_fixed_string_t priority;
7388         uint8_t  priority_value;
7389         cmdline_fixed_string_t queue;
7390         uint16_t  queue_id;
7391 };
7392
7393 static void
7394 cmd_2tuple_filter_parsed(void *parsed_result,
7395                         __attribute__((unused)) struct cmdline *cl,
7396                         __attribute__((unused)) void *data)
7397 {
7398         struct rte_eth_ntuple_filter filter;
7399         struct cmd_2tuple_filter_result *res = parsed_result;
7400         int ret = 0;
7401
7402         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7403         if (ret < 0) {
7404                 printf("ntuple filter is not supported on port %u.\n",
7405                         res->port_id);
7406                 return;
7407         }
7408
7409         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7410
7411         filter.flags = RTE_2TUPLE_FLAGS;
7412         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7413         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7414         filter.proto = res->protocol_value;
7415         filter.priority = res->priority_value;
7416         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7417                 printf("nonzero tcp_flags is only meaningful"
7418                         " when protocol is TCP.\n");
7419                 return;
7420         }
7421         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7422                 printf("invalid TCP flags.\n");
7423                 return;
7424         }
7425
7426         if (res->tcp_flags_value != 0) {
7427                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7428                 filter.tcp_flags = res->tcp_flags_value;
7429         }
7430
7431         /* need convert to big endian. */
7432         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7433         filter.queue = res->queue_id;
7434
7435         if (!strcmp(res->ops, "add"))
7436                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7437                                 RTE_ETH_FILTER_NTUPLE,
7438                                 RTE_ETH_FILTER_ADD,
7439                                 &filter);
7440         else
7441                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7442                                 RTE_ETH_FILTER_NTUPLE,
7443                                 RTE_ETH_FILTER_DELETE,
7444                                 &filter);
7445         if (ret < 0)
7446                 printf("2tuple filter programming error: (%s)\n",
7447                         strerror(-ret));
7448
7449 }
7450
7451 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7452         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7453                                  filter, "2tuple_filter");
7454 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7455         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7456                                 port_id, UINT8);
7457 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7458         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7459                                  ops, "add#del");
7460 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7461         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7462                                 dst_port, "dst_port");
7463 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7464         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7465                                 dst_port_value, UINT16);
7466 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7467         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7468                                 protocol, "protocol");
7469 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7470         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7471                                 protocol_value, UINT8);
7472 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7473         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7474                                 mask, "mask");
7475 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7476         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7477                                 mask_value, INT8);
7478 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7479         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7480                                 tcp_flags, "tcp_flags");
7481 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7482         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7483                                 tcp_flags_value, UINT8);
7484 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7485         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7486                                 priority, "priority");
7487 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7488         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7489                                 priority_value, UINT8);
7490 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7491         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7492                                 queue, "queue");
7493 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7494         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7495                                 queue_id, UINT16);
7496
7497 cmdline_parse_inst_t cmd_2tuple_filter = {
7498         .f = cmd_2tuple_filter_parsed,
7499         .data = NULL,
7500         .help_str = "add a 2tuple filter",
7501         .tokens = {
7502                 (void *)&cmd_2tuple_filter_filter,
7503                 (void *)&cmd_2tuple_filter_port_id,
7504                 (void *)&cmd_2tuple_filter_ops,
7505                 (void *)&cmd_2tuple_filter_dst_port,
7506                 (void *)&cmd_2tuple_filter_dst_port_value,
7507                 (void *)&cmd_2tuple_filter_protocol,
7508                 (void *)&cmd_2tuple_filter_protocol_value,
7509                 (void *)&cmd_2tuple_filter_mask,
7510                 (void *)&cmd_2tuple_filter_mask_value,
7511                 (void *)&cmd_2tuple_filter_tcp_flags,
7512                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7513                 (void *)&cmd_2tuple_filter_priority,
7514                 (void *)&cmd_2tuple_filter_priority_value,
7515                 (void *)&cmd_2tuple_filter_queue,
7516                 (void *)&cmd_2tuple_filter_queue_id,
7517                 NULL,
7518         },
7519 };
7520
7521 /* *** ADD/REMOVE A 5tuple FILTER *** */
7522 struct cmd_5tuple_filter_result {
7523         cmdline_fixed_string_t filter;
7524         uint8_t  port_id;
7525         cmdline_fixed_string_t ops;
7526         cmdline_fixed_string_t dst_ip;
7527         cmdline_ipaddr_t dst_ip_value;
7528         cmdline_fixed_string_t src_ip;
7529         cmdline_ipaddr_t src_ip_value;
7530         cmdline_fixed_string_t dst_port;
7531         uint16_t dst_port_value;
7532         cmdline_fixed_string_t src_port;
7533         uint16_t src_port_value;
7534         cmdline_fixed_string_t protocol;
7535         uint8_t protocol_value;
7536         cmdline_fixed_string_t mask;
7537         uint8_t  mask_value;
7538         cmdline_fixed_string_t tcp_flags;
7539         uint8_t tcp_flags_value;
7540         cmdline_fixed_string_t priority;
7541         uint8_t  priority_value;
7542         cmdline_fixed_string_t queue;
7543         uint16_t  queue_id;
7544 };
7545
7546 static void
7547 cmd_5tuple_filter_parsed(void *parsed_result,
7548                         __attribute__((unused)) struct cmdline *cl,
7549                         __attribute__((unused)) void *data)
7550 {
7551         struct rte_eth_ntuple_filter filter;
7552         struct cmd_5tuple_filter_result *res = parsed_result;
7553         int ret = 0;
7554
7555         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7556         if (ret < 0) {
7557                 printf("ntuple filter is not supported on port %u.\n",
7558                         res->port_id);
7559                 return;
7560         }
7561
7562         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7563
7564         filter.flags = RTE_5TUPLE_FLAGS;
7565         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
7566         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
7567         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
7568         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7569         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7570         filter.proto = res->protocol_value;
7571         filter.priority = res->priority_value;
7572         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7573                 printf("nonzero tcp_flags is only meaningful"
7574                         " when protocol is TCP.\n");
7575                 return;
7576         }
7577         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7578                 printf("invalid TCP flags.\n");
7579                 return;
7580         }
7581
7582         if (res->tcp_flags_value != 0) {
7583                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7584                 filter.tcp_flags = res->tcp_flags_value;
7585         }
7586
7587         if (res->dst_ip_value.family == AF_INET)
7588                 /* no need to convert, already big endian. */
7589                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
7590         else {
7591                 if (filter.dst_ip_mask == 0) {
7592                         printf("can not support ipv6 involved compare.\n");
7593                         return;
7594                 }
7595                 filter.dst_ip = 0;
7596         }
7597
7598         if (res->src_ip_value.family == AF_INET)
7599                 /* no need to convert, already big endian. */
7600                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
7601         else {
7602                 if (filter.src_ip_mask == 0) {
7603                         printf("can not support ipv6 involved compare.\n");
7604                         return;
7605                 }
7606                 filter.src_ip = 0;
7607         }
7608         /* need convert to big endian. */
7609         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7610         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
7611         filter.queue = res->queue_id;
7612
7613         if (!strcmp(res->ops, "add"))
7614                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7615                                 RTE_ETH_FILTER_NTUPLE,
7616                                 RTE_ETH_FILTER_ADD,
7617                                 &filter);
7618         else
7619                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7620                                 RTE_ETH_FILTER_NTUPLE,
7621                                 RTE_ETH_FILTER_DELETE,
7622                                 &filter);
7623         if (ret < 0)
7624                 printf("5tuple filter programming error: (%s)\n",
7625                         strerror(-ret));
7626 }
7627
7628 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
7629         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7630                                  filter, "5tuple_filter");
7631 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
7632         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7633                                 port_id, UINT8);
7634 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
7635         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7636                                  ops, "add#del");
7637 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
7638         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7639                                 dst_ip, "dst_ip");
7640 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
7641         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7642                                 dst_ip_value);
7643 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
7644         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7645                                 src_ip, "src_ip");
7646 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
7647         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7648                                 src_ip_value);
7649 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
7650         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7651                                 dst_port, "dst_port");
7652 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
7653         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7654                                 dst_port_value, UINT16);
7655 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
7656         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7657                                 src_port, "src_port");
7658 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
7659         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7660                                 src_port_value, UINT16);
7661 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
7662         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7663                                 protocol, "protocol");
7664 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
7665         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7666                                 protocol_value, UINT8);
7667 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
7668         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7669                                 mask, "mask");
7670 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
7671         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7672                                 mask_value, INT8);
7673 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
7674         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7675                                 tcp_flags, "tcp_flags");
7676 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
7677         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7678                                 tcp_flags_value, UINT8);
7679 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
7680         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7681                                 priority, "priority");
7682 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
7683         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7684                                 priority_value, UINT8);
7685 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
7686         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7687                                 queue, "queue");
7688 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7689         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7690                                 queue_id, UINT16);
7691
7692 cmdline_parse_inst_t cmd_5tuple_filter = {
7693         .f = cmd_5tuple_filter_parsed,
7694         .data = NULL,
7695         .help_str = "add/del a 5tuple filter",
7696         .tokens = {
7697                 (void *)&cmd_5tuple_filter_filter,
7698                 (void *)&cmd_5tuple_filter_port_id,
7699                 (void *)&cmd_5tuple_filter_ops,
7700                 (void *)&cmd_5tuple_filter_dst_ip,
7701                 (void *)&cmd_5tuple_filter_dst_ip_value,
7702                 (void *)&cmd_5tuple_filter_src_ip,
7703                 (void *)&cmd_5tuple_filter_src_ip_value,
7704                 (void *)&cmd_5tuple_filter_dst_port,
7705                 (void *)&cmd_5tuple_filter_dst_port_value,
7706                 (void *)&cmd_5tuple_filter_src_port,
7707                 (void *)&cmd_5tuple_filter_src_port_value,
7708                 (void *)&cmd_5tuple_filter_protocol,
7709                 (void *)&cmd_5tuple_filter_protocol_value,
7710                 (void *)&cmd_5tuple_filter_mask,
7711                 (void *)&cmd_5tuple_filter_mask_value,
7712                 (void *)&cmd_5tuple_filter_tcp_flags,
7713                 (void *)&cmd_5tuple_filter_tcp_flags_value,
7714                 (void *)&cmd_5tuple_filter_priority,
7715                 (void *)&cmd_5tuple_filter_priority_value,
7716                 (void *)&cmd_5tuple_filter_queue,
7717                 (void *)&cmd_5tuple_filter_queue_id,
7718                 NULL,
7719         },
7720 };
7721
7722 /* *** ADD/REMOVE A flex FILTER *** */
7723 struct cmd_flex_filter_result {
7724         cmdline_fixed_string_t filter;
7725         cmdline_fixed_string_t ops;
7726         uint8_t port_id;
7727         cmdline_fixed_string_t len;
7728         uint8_t len_value;
7729         cmdline_fixed_string_t bytes;
7730         cmdline_fixed_string_t bytes_value;
7731         cmdline_fixed_string_t mask;
7732         cmdline_fixed_string_t mask_value;
7733         cmdline_fixed_string_t priority;
7734         uint8_t priority_value;
7735         cmdline_fixed_string_t queue;
7736         uint16_t queue_id;
7737 };
7738
7739 static int xdigit2val(unsigned char c)
7740 {
7741         int val;
7742         if (isdigit(c))
7743                 val = c - '0';
7744         else if (isupper(c))
7745                 val = c - 'A' + 10;
7746         else
7747                 val = c - 'a' + 10;
7748         return val;
7749 }
7750
7751 static void
7752 cmd_flex_filter_parsed(void *parsed_result,
7753                           __attribute__((unused)) struct cmdline *cl,
7754                           __attribute__((unused)) void *data)
7755 {
7756         int ret = 0;
7757         struct rte_eth_flex_filter filter;
7758         struct cmd_flex_filter_result *res = parsed_result;
7759         char *bytes_ptr, *mask_ptr;
7760         uint16_t len, i, j = 0;
7761         char c;
7762         int val;
7763         uint8_t byte = 0;
7764
7765         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
7766                 printf("the len exceed the max length 128\n");
7767                 return;
7768         }
7769         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
7770         filter.len = res->len_value;
7771         filter.priority = res->priority_value;
7772         filter.queue = res->queue_id;
7773         bytes_ptr = res->bytes_value;
7774         mask_ptr = res->mask_value;
7775
7776          /* translate bytes string to array. */
7777         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
7778                 (bytes_ptr[1] == 'X')))
7779                 bytes_ptr += 2;
7780         len = strnlen(bytes_ptr, res->len_value * 2);
7781         if (len == 0 || (len % 8 != 0)) {
7782                 printf("please check len and bytes input\n");
7783                 return;
7784         }
7785         for (i = 0; i < len; i++) {
7786                 c = bytes_ptr[i];
7787                 if (isxdigit(c) == 0) {
7788                         /* invalid characters. */
7789                         printf("invalid input\n");
7790                         return;
7791                 }
7792                 val = xdigit2val(c);
7793                 if (i % 2) {
7794                         byte |= val;
7795                         filter.bytes[j] = byte;
7796                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
7797                         j++;
7798                         byte = 0;
7799                 } else
7800                         byte |= val << 4;
7801         }
7802         printf("\n");
7803          /* translate mask string to uint8_t array. */
7804         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
7805                 (mask_ptr[1] == 'X')))
7806                 mask_ptr += 2;
7807         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
7808         if (len == 0) {
7809                 printf("invalid input\n");
7810                 return;
7811         }
7812         j = 0;
7813         byte = 0;
7814         for (i = 0; i < len; i++) {
7815                 c = mask_ptr[i];
7816                 if (isxdigit(c) == 0) {
7817                         /* invalid characters. */
7818                         printf("invalid input\n");
7819                         return;
7820                 }
7821                 val = xdigit2val(c);
7822                 if (i % 2) {
7823                         byte |= val;
7824                         filter.mask[j] = byte;
7825                         printf("mask[%d]:%02x ", j, filter.mask[j]);
7826                         j++;
7827                         byte = 0;
7828                 } else
7829                         byte |= val << 4;
7830         }
7831         printf("\n");
7832
7833         if (!strcmp(res->ops, "add"))
7834                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7835                                 RTE_ETH_FILTER_FLEXIBLE,
7836                                 RTE_ETH_FILTER_ADD,
7837                                 &filter);
7838         else
7839                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7840                                 RTE_ETH_FILTER_FLEXIBLE,
7841                                 RTE_ETH_FILTER_DELETE,
7842                                 &filter);
7843
7844         if (ret < 0)
7845                 printf("flex filter setting error: (%s)\n", strerror(-ret));
7846 }
7847
7848 cmdline_parse_token_string_t cmd_flex_filter_filter =
7849         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7850                                 filter, "flex_filter");
7851 cmdline_parse_token_num_t cmd_flex_filter_port_id =
7852         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7853                                 port_id, UINT8);
7854 cmdline_parse_token_string_t cmd_flex_filter_ops =
7855         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7856                                 ops, "add#del");
7857 cmdline_parse_token_string_t cmd_flex_filter_len =
7858         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7859                                 len, "len");
7860 cmdline_parse_token_num_t cmd_flex_filter_len_value =
7861         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7862                                 len_value, UINT8);
7863 cmdline_parse_token_string_t cmd_flex_filter_bytes =
7864         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7865                                 bytes, "bytes");
7866 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
7867         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7868                                 bytes_value, NULL);
7869 cmdline_parse_token_string_t cmd_flex_filter_mask =
7870         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7871                                 mask, "mask");
7872 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
7873         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7874                                 mask_value, NULL);
7875 cmdline_parse_token_string_t cmd_flex_filter_priority =
7876         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7877                                 priority, "priority");
7878 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
7879         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7880                                 priority_value, UINT8);
7881 cmdline_parse_token_string_t cmd_flex_filter_queue =
7882         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7883                                 queue, "queue");
7884 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
7885         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7886                                 queue_id, UINT16);
7887 cmdline_parse_inst_t cmd_flex_filter = {
7888         .f = cmd_flex_filter_parsed,
7889         .data = NULL,
7890         .help_str = "add/del a flex filter",
7891         .tokens = {
7892                 (void *)&cmd_flex_filter_filter,
7893                 (void *)&cmd_flex_filter_port_id,
7894                 (void *)&cmd_flex_filter_ops,
7895                 (void *)&cmd_flex_filter_len,
7896                 (void *)&cmd_flex_filter_len_value,
7897                 (void *)&cmd_flex_filter_bytes,
7898                 (void *)&cmd_flex_filter_bytes_value,
7899                 (void *)&cmd_flex_filter_mask,
7900                 (void *)&cmd_flex_filter_mask_value,
7901                 (void *)&cmd_flex_filter_priority,
7902                 (void *)&cmd_flex_filter_priority_value,
7903                 (void *)&cmd_flex_filter_queue,
7904                 (void *)&cmd_flex_filter_queue_id,
7905                 NULL,
7906         },
7907 };
7908
7909 /* *** Filters Control *** */
7910
7911 /* *** deal with ethertype filter *** */
7912 struct cmd_ethertype_filter_result {
7913         cmdline_fixed_string_t filter;
7914         uint8_t port_id;
7915         cmdline_fixed_string_t ops;
7916         cmdline_fixed_string_t mac;
7917         struct ether_addr mac_addr;
7918         cmdline_fixed_string_t ethertype;
7919         uint16_t ethertype_value;
7920         cmdline_fixed_string_t drop;
7921         cmdline_fixed_string_t queue;
7922         uint16_t  queue_id;
7923 };
7924
7925 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
7926         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7927                                  filter, "ethertype_filter");
7928 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
7929         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7930                               port_id, UINT8);
7931 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
7932         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7933                                  ops, "add#del");
7934 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
7935         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7936                                  mac, "mac_addr#mac_ignr");
7937 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
7938         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
7939                                      mac_addr);
7940 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
7941         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7942                                  ethertype, "ethertype");
7943 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
7944         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7945                               ethertype_value, UINT16);
7946 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
7947         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7948                                  drop, "drop#fwd");
7949 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
7950         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7951                                  queue, "queue");
7952 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
7953         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7954                               queue_id, UINT16);
7955
7956 static void
7957 cmd_ethertype_filter_parsed(void *parsed_result,
7958                           __attribute__((unused)) struct cmdline *cl,
7959                           __attribute__((unused)) void *data)
7960 {
7961         struct cmd_ethertype_filter_result *res = parsed_result;
7962         struct rte_eth_ethertype_filter filter;
7963         int ret = 0;
7964
7965         ret = rte_eth_dev_filter_supported(res->port_id,
7966                         RTE_ETH_FILTER_ETHERTYPE);
7967         if (ret < 0) {
7968                 printf("ethertype filter is not supported on port %u.\n",
7969                         res->port_id);
7970                 return;
7971         }
7972
7973         memset(&filter, 0, sizeof(filter));
7974         if (!strcmp(res->mac, "mac_addr")) {
7975                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
7976                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
7977                         sizeof(struct ether_addr));
7978         }
7979         if (!strcmp(res->drop, "drop"))
7980                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
7981         filter.ether_type = res->ethertype_value;
7982         filter.queue = res->queue_id;
7983
7984         if (!strcmp(res->ops, "add"))
7985                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7986                                 RTE_ETH_FILTER_ETHERTYPE,
7987                                 RTE_ETH_FILTER_ADD,
7988                                 &filter);
7989         else
7990                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7991                                 RTE_ETH_FILTER_ETHERTYPE,
7992                                 RTE_ETH_FILTER_DELETE,
7993                                 &filter);
7994         if (ret < 0)
7995                 printf("ethertype filter programming error: (%s)\n",
7996                         strerror(-ret));
7997 }
7998
7999 cmdline_parse_inst_t cmd_ethertype_filter = {
8000         .f = cmd_ethertype_filter_parsed,
8001         .data = NULL,
8002         .help_str = "add or delete an ethertype filter entry",
8003         .tokens = {
8004                 (void *)&cmd_ethertype_filter_filter,
8005                 (void *)&cmd_ethertype_filter_port_id,
8006                 (void *)&cmd_ethertype_filter_ops,
8007                 (void *)&cmd_ethertype_filter_mac,
8008                 (void *)&cmd_ethertype_filter_mac_addr,
8009                 (void *)&cmd_ethertype_filter_ethertype,
8010                 (void *)&cmd_ethertype_filter_ethertype_value,
8011                 (void *)&cmd_ethertype_filter_drop,
8012                 (void *)&cmd_ethertype_filter_queue,
8013                 (void *)&cmd_ethertype_filter_queue_id,
8014                 NULL,
8015         },
8016 };
8017
8018 /* *** deal with flow director filter *** */
8019 struct cmd_flow_director_result {
8020         cmdline_fixed_string_t flow_director_filter;
8021         uint8_t port_id;
8022         cmdline_fixed_string_t mode;
8023         cmdline_fixed_string_t mode_value;
8024         cmdline_fixed_string_t ops;
8025         cmdline_fixed_string_t flow;
8026         cmdline_fixed_string_t flow_type;
8027         cmdline_fixed_string_t ether;
8028         uint16_t ether_type;
8029         cmdline_fixed_string_t src;
8030         cmdline_ipaddr_t ip_src;
8031         uint16_t port_src;
8032         cmdline_fixed_string_t dst;
8033         cmdline_ipaddr_t ip_dst;
8034         uint16_t port_dst;
8035         cmdline_fixed_string_t verify_tag;
8036         uint32_t verify_tag_value;
8037         cmdline_ipaddr_t tos;
8038         uint8_t tos_value;
8039         cmdline_ipaddr_t proto;
8040         uint8_t proto_value;
8041         cmdline_ipaddr_t ttl;
8042         uint8_t ttl_value;
8043         cmdline_fixed_string_t vlan;
8044         uint16_t vlan_value;
8045         cmdline_fixed_string_t flexbytes;
8046         cmdline_fixed_string_t flexbytes_value;
8047         cmdline_fixed_string_t pf_vf;
8048         cmdline_fixed_string_t drop;
8049         cmdline_fixed_string_t queue;
8050         uint16_t  queue_id;
8051         cmdline_fixed_string_t fd_id;
8052         uint32_t  fd_id_value;
8053         cmdline_fixed_string_t mac;
8054         struct ether_addr mac_addr;
8055         cmdline_fixed_string_t tunnel;
8056         cmdline_fixed_string_t tunnel_type;
8057         cmdline_fixed_string_t tunnel_id;
8058         uint32_t tunnel_id_value;
8059 };
8060
8061 static inline int
8062 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8063 {
8064         char s[256];
8065         const char *p, *p0 = q_arg;
8066         char *end;
8067         unsigned long int_fld;
8068         char *str_fld[max_num];
8069         int i;
8070         unsigned size;
8071         int ret = -1;
8072
8073         p = strchr(p0, '(');
8074         if (p == NULL)
8075                 return -1;
8076         ++p;
8077         p0 = strchr(p, ')');
8078         if (p0 == NULL)
8079                 return -1;
8080
8081         size = p0 - p;
8082         if (size >= sizeof(s))
8083                 return -1;
8084
8085         snprintf(s, sizeof(s), "%.*s", size, p);
8086         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8087         if (ret < 0 || ret > max_num)
8088                 return -1;
8089         for (i = 0; i < ret; i++) {
8090                 errno = 0;
8091                 int_fld = strtoul(str_fld[i], &end, 0);
8092                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8093                         return -1;
8094                 flexbytes[i] = (uint8_t)int_fld;
8095         }
8096         return ret;
8097 }
8098
8099 static uint16_t
8100 str2flowtype(char *string)
8101 {
8102         uint8_t i = 0;
8103         static const struct {
8104                 char str[32];
8105                 uint16_t type;
8106         } flowtype_str[] = {
8107                 {"raw", RTE_ETH_FLOW_RAW},
8108                 {"ipv4", RTE_ETH_FLOW_IPV4},
8109                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8110                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8111                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8112                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8113                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8114                 {"ipv6", RTE_ETH_FLOW_IPV6},
8115                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8116                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8117                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8118                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8119                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8120                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8121         };
8122
8123         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8124                 if (!strcmp(flowtype_str[i].str, string))
8125                         return flowtype_str[i].type;
8126         }
8127         return RTE_ETH_FLOW_UNKNOWN;
8128 }
8129
8130 static enum rte_eth_fdir_tunnel_type
8131 str2fdir_tunneltype(char *string)
8132 {
8133         uint8_t i = 0;
8134
8135         static const struct {
8136                 char str[32];
8137                 enum rte_eth_fdir_tunnel_type type;
8138         } tunneltype_str[] = {
8139                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8140                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8141         };
8142
8143         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8144                 if (!strcmp(tunneltype_str[i].str, string))
8145                         return tunneltype_str[i].type;
8146         }
8147         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8148 }
8149
8150 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8151 do { \
8152         if ((ip_addr).family == AF_INET) \
8153                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8154         else { \
8155                 printf("invalid parameter.\n"); \
8156                 return; \
8157         } \
8158 } while (0)
8159
8160 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8161 do { \
8162         if ((ip_addr).family == AF_INET6) \
8163                 (void)rte_memcpy(&(ip), \
8164                                  &((ip_addr).addr.ipv6), \
8165                                  sizeof(struct in6_addr)); \
8166         else { \
8167                 printf("invalid parameter.\n"); \
8168                 return; \
8169         } \
8170 } while (0)
8171
8172 static void
8173 cmd_flow_director_filter_parsed(void *parsed_result,
8174                           __attribute__((unused)) struct cmdline *cl,
8175                           __attribute__((unused)) void *data)
8176 {
8177         struct cmd_flow_director_result *res = parsed_result;
8178         struct rte_eth_fdir_filter entry;
8179         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8180         char *end;
8181         unsigned long vf_id;
8182         int ret = 0;
8183
8184         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8185         if (ret < 0) {
8186                 printf("flow director is not supported on port %u.\n",
8187                         res->port_id);
8188                 return;
8189         }
8190         memset(flexbytes, 0, sizeof(flexbytes));
8191         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8192
8193         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8194                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8195                         printf("Please set mode to MAC-VLAN.\n");
8196                         return;
8197                 }
8198         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8199                 if (strcmp(res->mode_value, "Tunnel")) {
8200                         printf("Please set mode to Tunnel.\n");
8201                         return;
8202                 }
8203         } else {
8204                 if (strcmp(res->mode_value, "IP")) {
8205                         printf("Please set mode to IP.\n");
8206                         return;
8207                 }
8208                 entry.input.flow_type = str2flowtype(res->flow_type);
8209         }
8210
8211         ret = parse_flexbytes(res->flexbytes_value,
8212                                         flexbytes,
8213                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8214         if (ret < 0) {
8215                 printf("error: Cannot parse flexbytes input.\n");
8216                 return;
8217         }
8218
8219         switch (entry.input.flow_type) {
8220         case RTE_ETH_FLOW_FRAG_IPV4:
8221         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8222                 entry.input.flow.ip4_flow.proto = res->proto_value;
8223         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8224         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8225                 IPV4_ADDR_TO_UINT(res->ip_dst,
8226                         entry.input.flow.ip4_flow.dst_ip);
8227                 IPV4_ADDR_TO_UINT(res->ip_src,
8228                         entry.input.flow.ip4_flow.src_ip);
8229                 entry.input.flow.ip4_flow.tos = res->tos_value;
8230                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8231                 /* need convert to big endian. */
8232                 entry.input.flow.udp4_flow.dst_port =
8233                                 rte_cpu_to_be_16(res->port_dst);
8234                 entry.input.flow.udp4_flow.src_port =
8235                                 rte_cpu_to_be_16(res->port_src);
8236                 break;
8237         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8238                 IPV4_ADDR_TO_UINT(res->ip_dst,
8239                         entry.input.flow.sctp4_flow.ip.dst_ip);
8240                 IPV4_ADDR_TO_UINT(res->ip_src,
8241                         entry.input.flow.sctp4_flow.ip.src_ip);
8242                 entry.input.flow.ip4_flow.tos = res->tos_value;
8243                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
8244                 /* need convert to big endian. */
8245                 entry.input.flow.sctp4_flow.dst_port =
8246                                 rte_cpu_to_be_16(res->port_dst);
8247                 entry.input.flow.sctp4_flow.src_port =
8248                                 rte_cpu_to_be_16(res->port_src);
8249                 entry.input.flow.sctp4_flow.verify_tag =
8250                                 rte_cpu_to_be_32(res->verify_tag_value);
8251                 break;
8252         case RTE_ETH_FLOW_FRAG_IPV6:
8253         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8254                 entry.input.flow.ipv6_flow.proto = res->proto_value;
8255         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8256         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8257                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8258                         entry.input.flow.ipv6_flow.dst_ip);
8259                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8260                         entry.input.flow.ipv6_flow.src_ip);
8261                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8262                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8263                 /* need convert to big endian. */
8264                 entry.input.flow.udp6_flow.dst_port =
8265                                 rte_cpu_to_be_16(res->port_dst);
8266                 entry.input.flow.udp6_flow.src_port =
8267                                 rte_cpu_to_be_16(res->port_src);
8268                 break;
8269         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8270                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8271                         entry.input.flow.sctp6_flow.ip.dst_ip);
8272                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8273                         entry.input.flow.sctp6_flow.ip.src_ip);
8274                 entry.input.flow.ipv6_flow.tc = res->tos_value;
8275                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
8276                 /* need convert to big endian. */
8277                 entry.input.flow.sctp6_flow.dst_port =
8278                                 rte_cpu_to_be_16(res->port_dst);
8279                 entry.input.flow.sctp6_flow.src_port =
8280                                 rte_cpu_to_be_16(res->port_src);
8281                 entry.input.flow.sctp6_flow.verify_tag =
8282                                 rte_cpu_to_be_32(res->verify_tag_value);
8283                 break;
8284         case RTE_ETH_FLOW_L2_PAYLOAD:
8285                 entry.input.flow.l2_flow.ether_type =
8286                         rte_cpu_to_be_16(res->ether_type);
8287                 break;
8288         default:
8289                 break;
8290         }
8291
8292         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8293                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8294                                  &res->mac_addr,
8295                                  sizeof(struct ether_addr));
8296
8297         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8298                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8299                                  &res->mac_addr,
8300                                  sizeof(struct ether_addr));
8301                 entry.input.flow.tunnel_flow.tunnel_type =
8302                         str2fdir_tunneltype(res->tunnel_type);
8303                 entry.input.flow.tunnel_flow.tunnel_id =
8304                         rte_cpu_to_be_32(res->tunnel_id_value);
8305         }
8306
8307         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8308                    flexbytes,
8309                    RTE_ETH_FDIR_MAX_FLEXLEN);
8310
8311         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8312
8313         entry.action.flex_off = 0;  /*use 0 by default */
8314         if (!strcmp(res->drop, "drop"))
8315                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8316         else
8317                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8318
8319         if (!strcmp(res->pf_vf, "pf"))
8320                 entry.input.flow_ext.is_vf = 0;
8321         else if (!strncmp(res->pf_vf, "vf", 2)) {
8322                 struct rte_eth_dev_info dev_info;
8323
8324                 memset(&dev_info, 0, sizeof(dev_info));
8325                 rte_eth_dev_info_get(res->port_id, &dev_info);
8326                 errno = 0;
8327                 vf_id = strtoul(res->pf_vf + 2, &end, 10);
8328                 if (errno != 0 || *end != '\0' || vf_id >= dev_info.max_vfs) {
8329                         printf("invalid parameter %s.\n", res->pf_vf);
8330                         return;
8331                 }
8332                 entry.input.flow_ext.is_vf = 1;
8333                 entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8334         } else {
8335                 printf("invalid parameter %s.\n", res->pf_vf);
8336                 return;
8337         }
8338
8339         /* set to report FD ID by default */
8340         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8341         entry.action.rx_queue = res->queue_id;
8342         entry.soft_id = res->fd_id_value;
8343         if (!strcmp(res->ops, "add"))
8344                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8345                                              RTE_ETH_FILTER_ADD, &entry);
8346         else if (!strcmp(res->ops, "del"))
8347                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8348                                              RTE_ETH_FILTER_DELETE, &entry);
8349         else
8350                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8351                                              RTE_ETH_FILTER_UPDATE, &entry);
8352         if (ret < 0)
8353                 printf("flow director programming error: (%s)\n",
8354                         strerror(-ret));
8355 }
8356
8357 cmdline_parse_token_string_t cmd_flow_director_filter =
8358         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8359                                  flow_director_filter, "flow_director_filter");
8360 cmdline_parse_token_num_t cmd_flow_director_port_id =
8361         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8362                               port_id, UINT8);
8363 cmdline_parse_token_string_t cmd_flow_director_ops =
8364         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8365                                  ops, "add#del#update");
8366 cmdline_parse_token_string_t cmd_flow_director_flow =
8367         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8368                                  flow, "flow");
8369 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8371                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8372                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8373 cmdline_parse_token_string_t cmd_flow_director_ether =
8374         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8375                                  ether, "ether");
8376 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8377         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8378                               ether_type, UINT16);
8379 cmdline_parse_token_string_t cmd_flow_director_src =
8380         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8381                                  src, "src");
8382 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8383         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8384                                  ip_src);
8385 cmdline_parse_token_num_t cmd_flow_director_port_src =
8386         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8387                               port_src, UINT16);
8388 cmdline_parse_token_string_t cmd_flow_director_dst =
8389         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8390                                  dst, "dst");
8391 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8392         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8393                                  ip_dst);
8394 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8395         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8396                               port_dst, UINT16);
8397 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8398         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8399                                   verify_tag, "verify_tag");
8400 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8401         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8402                               verify_tag_value, UINT32);
8403 cmdline_parse_token_string_t cmd_flow_director_tos =
8404         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8405                                  tos, "tos");
8406 cmdline_parse_token_num_t cmd_flow_director_tos_value =
8407         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8408                               tos_value, UINT8);
8409 cmdline_parse_token_string_t cmd_flow_director_proto =
8410         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8411                                  proto, "proto");
8412 cmdline_parse_token_num_t cmd_flow_director_proto_value =
8413         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8414                               proto_value, UINT8);
8415 cmdline_parse_token_string_t cmd_flow_director_ttl =
8416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8417                                  ttl, "ttl");
8418 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
8419         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8420                               ttl_value, UINT8);
8421 cmdline_parse_token_string_t cmd_flow_director_vlan =
8422         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8423                                  vlan, "vlan");
8424 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8425         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8426                               vlan_value, UINT16);
8427 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8429                                  flexbytes, "flexbytes");
8430 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8432                               flexbytes_value, NULL);
8433 cmdline_parse_token_string_t cmd_flow_director_drop =
8434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8435                                  drop, "drop#fwd");
8436 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8438                               pf_vf, NULL);
8439 cmdline_parse_token_string_t cmd_flow_director_queue =
8440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8441                                  queue, "queue");
8442 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8444                               queue_id, UINT16);
8445 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8446         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8447                                  fd_id, "fd_id");
8448 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8449         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8450                               fd_id_value, UINT32);
8451
8452 cmdline_parse_token_string_t cmd_flow_director_mode =
8453         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8454                                  mode, "mode");
8455 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8456         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8457                                  mode_value, "IP");
8458 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8459         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8460                                  mode_value, "MAC-VLAN");
8461 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8463                                  mode_value, "Tunnel");
8464 cmdline_parse_token_string_t cmd_flow_director_mac =
8465         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8466                                  mac, "mac");
8467 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8468         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8469                                     mac_addr);
8470 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8471         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8472                                  tunnel, "tunnel");
8473 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8474         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8475                                  tunnel_type, "NVGRE#VxLAN");
8476 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8477         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8478                                  tunnel_id, "tunnel-id");
8479 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8480         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8481                               tunnel_id_value, UINT32);
8482
8483 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8484         .f = cmd_flow_director_filter_parsed,
8485         .data = NULL,
8486         .help_str = "add or delete an ip flow director entry on NIC",
8487         .tokens = {
8488                 (void *)&cmd_flow_director_filter,
8489                 (void *)&cmd_flow_director_port_id,
8490                 (void *)&cmd_flow_director_mode,
8491                 (void *)&cmd_flow_director_mode_ip,
8492                 (void *)&cmd_flow_director_ops,
8493                 (void *)&cmd_flow_director_flow,
8494                 (void *)&cmd_flow_director_flow_type,
8495                 (void *)&cmd_flow_director_src,
8496                 (void *)&cmd_flow_director_ip_src,
8497                 (void *)&cmd_flow_director_dst,
8498                 (void *)&cmd_flow_director_ip_dst,
8499                 (void *)&cmd_flow_director_tos,
8500                 (void *)&cmd_flow_director_tos_value,
8501                 (void *)&cmd_flow_director_proto,
8502                 (void *)&cmd_flow_director_proto_value,
8503                 (void *)&cmd_flow_director_ttl,
8504                 (void *)&cmd_flow_director_ttl_value,
8505                 (void *)&cmd_flow_director_vlan,
8506                 (void *)&cmd_flow_director_vlan_value,
8507                 (void *)&cmd_flow_director_flexbytes,
8508                 (void *)&cmd_flow_director_flexbytes_value,
8509                 (void *)&cmd_flow_director_drop,
8510                 (void *)&cmd_flow_director_pf_vf,
8511                 (void *)&cmd_flow_director_queue,
8512                 (void *)&cmd_flow_director_queue_id,
8513                 (void *)&cmd_flow_director_fd_id,
8514                 (void *)&cmd_flow_director_fd_id_value,
8515                 NULL,
8516         },
8517 };
8518
8519 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8520         .f = cmd_flow_director_filter_parsed,
8521         .data = NULL,
8522         .help_str = "add or delete an udp/tcp flow director entry on NIC",
8523         .tokens = {
8524                 (void *)&cmd_flow_director_filter,
8525                 (void *)&cmd_flow_director_port_id,
8526                 (void *)&cmd_flow_director_mode,
8527                 (void *)&cmd_flow_director_mode_ip,
8528                 (void *)&cmd_flow_director_ops,
8529                 (void *)&cmd_flow_director_flow,
8530                 (void *)&cmd_flow_director_flow_type,
8531                 (void *)&cmd_flow_director_src,
8532                 (void *)&cmd_flow_director_ip_src,
8533                 (void *)&cmd_flow_director_port_src,
8534                 (void *)&cmd_flow_director_dst,
8535                 (void *)&cmd_flow_director_ip_dst,
8536                 (void *)&cmd_flow_director_port_dst,
8537                 (void *)&cmd_flow_director_tos,
8538                 (void *)&cmd_flow_director_tos_value,
8539                 (void *)&cmd_flow_director_ttl,
8540                 (void *)&cmd_flow_director_ttl_value,
8541                 (void *)&cmd_flow_director_vlan,
8542                 (void *)&cmd_flow_director_vlan_value,
8543                 (void *)&cmd_flow_director_flexbytes,
8544                 (void *)&cmd_flow_director_flexbytes_value,
8545                 (void *)&cmd_flow_director_drop,
8546                 (void *)&cmd_flow_director_pf_vf,
8547                 (void *)&cmd_flow_director_queue,
8548                 (void *)&cmd_flow_director_queue_id,
8549                 (void *)&cmd_flow_director_fd_id,
8550                 (void *)&cmd_flow_director_fd_id_value,
8551                 NULL,
8552         },
8553 };
8554
8555 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8556         .f = cmd_flow_director_filter_parsed,
8557         .data = NULL,
8558         .help_str = "add or delete a sctp flow director entry on NIC",
8559         .tokens = {
8560                 (void *)&cmd_flow_director_filter,
8561                 (void *)&cmd_flow_director_port_id,
8562                 (void *)&cmd_flow_director_mode,
8563                 (void *)&cmd_flow_director_mode_ip,
8564                 (void *)&cmd_flow_director_ops,
8565                 (void *)&cmd_flow_director_flow,
8566                 (void *)&cmd_flow_director_flow_type,
8567                 (void *)&cmd_flow_director_src,
8568                 (void *)&cmd_flow_director_ip_src,
8569                 (void *)&cmd_flow_director_port_dst,
8570                 (void *)&cmd_flow_director_dst,
8571                 (void *)&cmd_flow_director_ip_dst,
8572                 (void *)&cmd_flow_director_port_dst,
8573                 (void *)&cmd_flow_director_verify_tag,
8574                 (void *)&cmd_flow_director_verify_tag_value,
8575                 (void *)&cmd_flow_director_tos,
8576                 (void *)&cmd_flow_director_tos_value,
8577                 (void *)&cmd_flow_director_ttl,
8578                 (void *)&cmd_flow_director_ttl_value,
8579                 (void *)&cmd_flow_director_vlan,
8580                 (void *)&cmd_flow_director_vlan_value,
8581                 (void *)&cmd_flow_director_flexbytes,
8582                 (void *)&cmd_flow_director_flexbytes_value,
8583                 (void *)&cmd_flow_director_drop,
8584                 (void *)&cmd_flow_director_pf_vf,
8585                 (void *)&cmd_flow_director_queue,
8586                 (void *)&cmd_flow_director_queue_id,
8587                 (void *)&cmd_flow_director_fd_id,
8588                 (void *)&cmd_flow_director_fd_id_value,
8589                 NULL,
8590         },
8591 };
8592
8593 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
8594         .f = cmd_flow_director_filter_parsed,
8595         .data = NULL,
8596         .help_str = "add or delete a L2 flow director entry on NIC",
8597         .tokens = {
8598                 (void *)&cmd_flow_director_filter,
8599                 (void *)&cmd_flow_director_port_id,
8600                 (void *)&cmd_flow_director_mode,
8601                 (void *)&cmd_flow_director_mode_ip,
8602                 (void *)&cmd_flow_director_ops,
8603                 (void *)&cmd_flow_director_flow,
8604                 (void *)&cmd_flow_director_flow_type,
8605                 (void *)&cmd_flow_director_ether,
8606                 (void *)&cmd_flow_director_ether_type,
8607                 (void *)&cmd_flow_director_flexbytes,
8608                 (void *)&cmd_flow_director_flexbytes_value,
8609                 (void *)&cmd_flow_director_drop,
8610                 (void *)&cmd_flow_director_pf_vf,
8611                 (void *)&cmd_flow_director_queue,
8612                 (void *)&cmd_flow_director_queue_id,
8613                 (void *)&cmd_flow_director_fd_id,
8614                 (void *)&cmd_flow_director_fd_id_value,
8615                 NULL,
8616         },
8617 };
8618
8619 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
8620         .f = cmd_flow_director_filter_parsed,
8621         .data = NULL,
8622         .help_str = "add or delete a MAC VLAN flow director entry on NIC",
8623         .tokens = {
8624                 (void *)&cmd_flow_director_filter,
8625                 (void *)&cmd_flow_director_port_id,
8626                 (void *)&cmd_flow_director_mode,
8627                 (void *)&cmd_flow_director_mode_mac_vlan,
8628                 (void *)&cmd_flow_director_ops,
8629                 (void *)&cmd_flow_director_mac,
8630                 (void *)&cmd_flow_director_mac_addr,
8631                 (void *)&cmd_flow_director_vlan,
8632                 (void *)&cmd_flow_director_vlan_value,
8633                 (void *)&cmd_flow_director_flexbytes,
8634                 (void *)&cmd_flow_director_flexbytes_value,
8635                 (void *)&cmd_flow_director_drop,
8636                 (void *)&cmd_flow_director_queue,
8637                 (void *)&cmd_flow_director_queue_id,
8638                 (void *)&cmd_flow_director_fd_id,
8639                 (void *)&cmd_flow_director_fd_id_value,
8640                 NULL,
8641         },
8642 };
8643
8644 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
8645         .f = cmd_flow_director_filter_parsed,
8646         .data = NULL,
8647         .help_str = "add or delete a tunnel flow director entry on NIC",
8648         .tokens = {
8649                 (void *)&cmd_flow_director_filter,
8650                 (void *)&cmd_flow_director_port_id,
8651                 (void *)&cmd_flow_director_mode,
8652                 (void *)&cmd_flow_director_mode_tunnel,
8653                 (void *)&cmd_flow_director_ops,
8654                 (void *)&cmd_flow_director_mac,
8655                 (void *)&cmd_flow_director_mac_addr,
8656                 (void *)&cmd_flow_director_vlan,
8657                 (void *)&cmd_flow_director_vlan_value,
8658                 (void *)&cmd_flow_director_tunnel,
8659                 (void *)&cmd_flow_director_tunnel_type,
8660                 (void *)&cmd_flow_director_tunnel_id,
8661                 (void *)&cmd_flow_director_tunnel_id_value,
8662                 (void *)&cmd_flow_director_flexbytes,
8663                 (void *)&cmd_flow_director_flexbytes_value,
8664                 (void *)&cmd_flow_director_drop,
8665                 (void *)&cmd_flow_director_queue,
8666                 (void *)&cmd_flow_director_queue_id,
8667                 (void *)&cmd_flow_director_fd_id,
8668                 (void *)&cmd_flow_director_fd_id_value,
8669                 NULL,
8670         },
8671 };
8672
8673 struct cmd_flush_flow_director_result {
8674         cmdline_fixed_string_t flush_flow_director;
8675         uint8_t port_id;
8676 };
8677
8678 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
8679         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
8680                                  flush_flow_director, "flush_flow_director");
8681 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
8682         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
8683                               port_id, UINT8);
8684
8685 static void
8686 cmd_flush_flow_director_parsed(void *parsed_result,
8687                           __attribute__((unused)) struct cmdline *cl,
8688                           __attribute__((unused)) void *data)
8689 {
8690         struct cmd_flow_director_result *res = parsed_result;
8691         int ret = 0;
8692
8693         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8694         if (ret < 0) {
8695                 printf("flow director is not supported on port %u.\n",
8696                         res->port_id);
8697                 return;
8698         }
8699
8700         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8701                         RTE_ETH_FILTER_FLUSH, NULL);
8702         if (ret < 0)
8703                 printf("flow director table flushing error: (%s)\n",
8704                         strerror(-ret));
8705 }
8706
8707 cmdline_parse_inst_t cmd_flush_flow_director = {
8708         .f = cmd_flush_flow_director_parsed,
8709         .data = NULL,
8710         .help_str = "flush all flow director entries of a device on NIC",
8711         .tokens = {
8712                 (void *)&cmd_flush_flow_director_flush,
8713                 (void *)&cmd_flush_flow_director_port_id,
8714                 NULL,
8715         },
8716 };
8717
8718 /* *** deal with flow director mask *** */
8719 struct cmd_flow_director_mask_result {
8720         cmdline_fixed_string_t flow_director_mask;
8721         uint8_t port_id;
8722         cmdline_fixed_string_t mode;
8723         cmdline_fixed_string_t mode_value;
8724         cmdline_fixed_string_t vlan;
8725         uint16_t vlan_mask;
8726         cmdline_fixed_string_t src_mask;
8727         cmdline_ipaddr_t ipv4_src;
8728         cmdline_ipaddr_t ipv6_src;
8729         uint16_t port_src;
8730         cmdline_fixed_string_t dst_mask;
8731         cmdline_ipaddr_t ipv4_dst;
8732         cmdline_ipaddr_t ipv6_dst;
8733         uint16_t port_dst;
8734         cmdline_fixed_string_t mac;
8735         uint8_t mac_addr_byte_mask;
8736         cmdline_fixed_string_t tunnel_id;
8737         uint32_t tunnel_id_mask;
8738         cmdline_fixed_string_t tunnel_type;
8739         uint8_t tunnel_type_mask;
8740 };
8741
8742 static void
8743 cmd_flow_director_mask_parsed(void *parsed_result,
8744                           __attribute__((unused)) struct cmdline *cl,
8745                           __attribute__((unused)) void *data)
8746 {
8747         struct cmd_flow_director_mask_result *res = parsed_result;
8748         struct rte_eth_fdir_masks *mask;
8749         struct rte_port *port;
8750
8751         if (res->port_id > nb_ports) {
8752                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8753                 return;
8754         }
8755
8756         port = &ports[res->port_id];
8757         /** Check if the port is not started **/
8758         if (port->port_status != RTE_PORT_STOPPED) {
8759                 printf("Please stop port %d first\n", res->port_id);
8760                 return;
8761         }
8762
8763         mask = &port->dev_conf.fdir_conf.mask;
8764
8765         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8766                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8767                         printf("Please set mode to MAC-VLAN.\n");
8768                         return;
8769                 }
8770
8771                 mask->vlan_tci_mask = res->vlan_mask;
8772                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8773         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8774                 if (strcmp(res->mode_value, "Tunnel")) {
8775                         printf("Please set mode to Tunnel.\n");
8776                         return;
8777                 }
8778
8779                 mask->vlan_tci_mask = res->vlan_mask;
8780                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8781                 mask->tunnel_id_mask = res->tunnel_id_mask;
8782                 mask->tunnel_type_mask = res->tunnel_type_mask;
8783         } else {
8784                 if (strcmp(res->mode_value, "IP")) {
8785                         printf("Please set mode to IP.\n");
8786                         return;
8787                 }
8788
8789                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
8790                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
8791                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
8792                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
8793                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
8794                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
8795                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
8796         }
8797
8798         cmd_reconfig_device_queue(res->port_id, 1, 1);
8799 }
8800
8801 cmdline_parse_token_string_t cmd_flow_director_mask =
8802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8803                                  flow_director_mask, "flow_director_mask");
8804 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
8805         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8806                               port_id, UINT8);
8807 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
8808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8809                                  vlan, "vlan");
8810 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
8811         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8812                               vlan_mask, UINT16);
8813 cmdline_parse_token_string_t cmd_flow_director_mask_src =
8814         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8815                                  src_mask, "src_mask");
8816 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
8817         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8818                                  ipv4_src);
8819 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
8820         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8821                                  ipv6_src);
8822 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
8823         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8824                               port_src, UINT16);
8825 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
8826         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8827                                  dst_mask, "dst_mask");
8828 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
8829         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8830                                  ipv4_dst);
8831 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
8832         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8833                                  ipv6_dst);
8834 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
8835         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8836                               port_dst, UINT16);
8837
8838 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
8839         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8840                                  mode, "mode");
8841 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
8842         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8843                                  mode_value, "IP");
8844 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
8845         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8846                                  mode_value, "MAC-VLAN");
8847 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
8848         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8849                                  mode_value, "Tunnel");
8850 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
8851         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8852                                  mac, "mac");
8853 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
8854         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8855                               mac_addr_byte_mask, UINT8);
8856 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
8857         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8858                                  tunnel_type, "tunnel-type");
8859 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
8860         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8861                               tunnel_type_mask, UINT8);
8862 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
8863         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8864                                  tunnel_id, "tunnel-id");
8865 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
8866         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8867                               tunnel_id_mask, UINT32);
8868
8869 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
8870         .f = cmd_flow_director_mask_parsed,
8871         .data = NULL,
8872         .help_str = "set IP mode flow director's mask on NIC",
8873         .tokens = {
8874                 (void *)&cmd_flow_director_mask,
8875                 (void *)&cmd_flow_director_mask_port_id,
8876                 (void *)&cmd_flow_director_mask_mode,
8877                 (void *)&cmd_flow_director_mask_mode_ip,
8878                 (void *)&cmd_flow_director_mask_vlan,
8879                 (void *)&cmd_flow_director_mask_vlan_value,
8880                 (void *)&cmd_flow_director_mask_src,
8881                 (void *)&cmd_flow_director_mask_ipv4_src,
8882                 (void *)&cmd_flow_director_mask_ipv6_src,
8883                 (void *)&cmd_flow_director_mask_port_src,
8884                 (void *)&cmd_flow_director_mask_dst,
8885                 (void *)&cmd_flow_director_mask_ipv4_dst,
8886                 (void *)&cmd_flow_director_mask_ipv6_dst,
8887                 (void *)&cmd_flow_director_mask_port_dst,
8888                 NULL,
8889         },
8890 };
8891
8892 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
8893         .f = cmd_flow_director_mask_parsed,
8894         .data = NULL,
8895         .help_str = "set MAC VLAN mode flow director's mask on NIC",
8896         .tokens = {
8897                 (void *)&cmd_flow_director_mask,
8898                 (void *)&cmd_flow_director_mask_port_id,
8899                 (void *)&cmd_flow_director_mask_mode,
8900                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
8901                 (void *)&cmd_flow_director_mask_vlan,
8902                 (void *)&cmd_flow_director_mask_vlan_value,
8903                 (void *)&cmd_flow_director_mask_mac,
8904                 (void *)&cmd_flow_director_mask_mac_value,
8905                 NULL,
8906         },
8907 };
8908
8909 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
8910         .f = cmd_flow_director_mask_parsed,
8911         .data = NULL,
8912         .help_str = "set tunnel mode flow director's mask on NIC",
8913         .tokens = {
8914                 (void *)&cmd_flow_director_mask,
8915                 (void *)&cmd_flow_director_mask_port_id,
8916                 (void *)&cmd_flow_director_mask_mode,
8917                 (void *)&cmd_flow_director_mask_mode_tunnel,
8918                 (void *)&cmd_flow_director_mask_vlan,
8919                 (void *)&cmd_flow_director_mask_vlan_value,
8920                 (void *)&cmd_flow_director_mask_mac,
8921                 (void *)&cmd_flow_director_mask_mac_value,
8922                 (void *)&cmd_flow_director_mask_tunnel_type,
8923                 (void *)&cmd_flow_director_mask_tunnel_type_value,
8924                 (void *)&cmd_flow_director_mask_tunnel_id,
8925                 (void *)&cmd_flow_director_mask_tunnel_id_value,
8926                 NULL,
8927         },
8928 };
8929
8930 /* *** deal with flow director mask on flexible payload *** */
8931 struct cmd_flow_director_flex_mask_result {
8932         cmdline_fixed_string_t flow_director_flexmask;
8933         uint8_t port_id;
8934         cmdline_fixed_string_t flow;
8935         cmdline_fixed_string_t flow_type;
8936         cmdline_fixed_string_t mask;
8937 };
8938
8939 static void
8940 cmd_flow_director_flex_mask_parsed(void *parsed_result,
8941                           __attribute__((unused)) struct cmdline *cl,
8942                           __attribute__((unused)) void *data)
8943 {
8944         struct cmd_flow_director_flex_mask_result *res = parsed_result;
8945         struct rte_eth_fdir_info fdir_info;
8946         struct rte_eth_fdir_flex_mask flex_mask;
8947         struct rte_port *port;
8948         uint32_t flow_type_mask;
8949         uint16_t i;
8950         int ret;
8951
8952         if (res->port_id > nb_ports) {
8953                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8954                 return;
8955         }
8956
8957         port = &ports[res->port_id];
8958         /** Check if the port is not started **/
8959         if (port->port_status != RTE_PORT_STOPPED) {
8960                 printf("Please stop port %d first\n", res->port_id);
8961                 return;
8962         }
8963
8964         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
8965         ret = parse_flexbytes(res->mask,
8966                         flex_mask.mask,
8967                         RTE_ETH_FDIR_MAX_FLEXLEN);
8968         if (ret < 0) {
8969                 printf("error: Cannot parse mask input.\n");
8970                 return;
8971         }
8972
8973         memset(&fdir_info, 0, sizeof(fdir_info));
8974         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8975                                 RTE_ETH_FILTER_INFO, &fdir_info);
8976         if (ret < 0) {
8977                 printf("Cannot get FDir filter info\n");
8978                 return;
8979         }
8980
8981         if (!strcmp(res->flow_type, "none")) {
8982                 /* means don't specify the flow type */
8983                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
8984                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
8985                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
8986                                0, sizeof(struct rte_eth_fdir_flex_mask));
8987                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
8988                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
8989                                  &flex_mask,
8990                                  sizeof(struct rte_eth_fdir_flex_mask));
8991                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8992                 return;
8993         }
8994         flow_type_mask = fdir_info.flow_types_mask[0];
8995         if (!strcmp(res->flow_type, "all")) {
8996                 if (!flow_type_mask) {
8997                         printf("No flow type supported\n");
8998                         return;
8999                 }
9000                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
9001                         if (flow_type_mask & (1 << i)) {
9002                                 flex_mask.flow_type = i;
9003                                 fdir_set_flex_mask(res->port_id, &flex_mask);
9004                         }
9005                 }
9006                 cmd_reconfig_device_queue(res->port_id, 1, 1);
9007                 return;
9008         }
9009         flex_mask.flow_type = str2flowtype(res->flow_type);
9010         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
9011                 printf("Flow type %s not supported on port %d\n",
9012                                 res->flow_type, res->port_id);
9013                 return;
9014         }
9015         fdir_set_flex_mask(res->port_id, &flex_mask);
9016         cmd_reconfig_device_queue(res->port_id, 1, 1);
9017 }
9018
9019 cmdline_parse_token_string_t cmd_flow_director_flexmask =
9020         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9021                                  flow_director_flexmask,
9022                                  "flow_director_flex_mask");
9023 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
9024         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9025                               port_id, UINT8);
9026 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
9027         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9028                                  flow, "flow");
9029 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
9030         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9031                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9032                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
9033 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
9034         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
9035                                  mask, NULL);
9036
9037 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
9038         .f = cmd_flow_director_flex_mask_parsed,
9039         .data = NULL,
9040         .help_str = "set flow director's flex mask on NIC",
9041         .tokens = {
9042                 (void *)&cmd_flow_director_flexmask,
9043                 (void *)&cmd_flow_director_flexmask_port_id,
9044                 (void *)&cmd_flow_director_flexmask_flow,
9045                 (void *)&cmd_flow_director_flexmask_flow_type,
9046                 (void *)&cmd_flow_director_flexmask_mask,
9047                 NULL,
9048         },
9049 };
9050
9051 /* *** deal with flow director flexible payload configuration *** */
9052 struct cmd_flow_director_flexpayload_result {
9053         cmdline_fixed_string_t flow_director_flexpayload;
9054         uint8_t port_id;
9055         cmdline_fixed_string_t payload_layer;
9056         cmdline_fixed_string_t payload_cfg;
9057 };
9058
9059 static inline int
9060 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
9061 {
9062         char s[256];
9063         const char *p, *p0 = q_arg;
9064         char *end;
9065         unsigned long int_fld;
9066         char *str_fld[max_num];
9067         int i;
9068         unsigned size;
9069         int ret = -1;
9070
9071         p = strchr(p0, '(');
9072         if (p == NULL)
9073                 return -1;
9074         ++p;
9075         p0 = strchr(p, ')');
9076         if (p0 == NULL)
9077                 return -1;
9078
9079         size = p0 - p;
9080         if (size >= sizeof(s))
9081                 return -1;
9082
9083         snprintf(s, sizeof(s), "%.*s", size, p);
9084         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9085         if (ret < 0 || ret > max_num)
9086                 return -1;
9087         for (i = 0; i < ret; i++) {
9088                 errno = 0;
9089                 int_fld = strtoul(str_fld[i], &end, 0);
9090                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9091                         return -1;
9092                 offsets[i] = (uint16_t)int_fld;
9093         }
9094         return ret;
9095 }
9096
9097 static void
9098 cmd_flow_director_flxpld_parsed(void *parsed_result,
9099                           __attribute__((unused)) struct cmdline *cl,
9100                           __attribute__((unused)) void *data)
9101 {
9102         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9103         struct rte_eth_flex_payload_cfg flex_cfg;
9104         struct rte_port *port;
9105         int ret = 0;
9106
9107         if (res->port_id > nb_ports) {
9108                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9109                 return;
9110         }
9111
9112         port = &ports[res->port_id];
9113         /** Check if the port is not started **/
9114         if (port->port_status != RTE_PORT_STOPPED) {
9115                 printf("Please stop port %d first\n", res->port_id);
9116                 return;
9117         }
9118
9119         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9120
9121         if (!strcmp(res->payload_layer, "raw"))
9122                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9123         else if (!strcmp(res->payload_layer, "l2"))
9124                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9125         else if (!strcmp(res->payload_layer, "l3"))
9126                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9127         else if (!strcmp(res->payload_layer, "l4"))
9128                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9129
9130         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9131                             RTE_ETH_FDIR_MAX_FLEXLEN);
9132         if (ret < 0) {
9133                 printf("error: Cannot parse flex payload input.\n");
9134                 return;
9135         }
9136
9137         fdir_set_flex_payload(res->port_id, &flex_cfg);
9138         cmd_reconfig_device_queue(res->port_id, 1, 1);
9139 }
9140
9141 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9142         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9143                                  flow_director_flexpayload,
9144                                  "flow_director_flex_payload");
9145 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9146         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9147                               port_id, UINT8);
9148 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9149         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9150                                  payload_layer, "raw#l2#l3#l4");
9151 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9152         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9153                                  payload_cfg, NULL);
9154
9155 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9156         .f = cmd_flow_director_flxpld_parsed,
9157         .data = NULL,
9158         .help_str = "set flow director's flex payload on NIC",
9159         .tokens = {
9160                 (void *)&cmd_flow_director_flexpayload,
9161                 (void *)&cmd_flow_director_flexpayload_port_id,
9162                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9163                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9164                 NULL,
9165         },
9166 };
9167
9168 /* *** Classification Filters Control *** */
9169 /* *** Get symmetric hash enable per port *** */
9170 struct cmd_get_sym_hash_ena_per_port_result {
9171         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9172         uint8_t port_id;
9173 };
9174
9175 static void
9176 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9177                                  __rte_unused struct cmdline *cl,
9178                                  __rte_unused void *data)
9179 {
9180         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9181         struct rte_eth_hash_filter_info info;
9182         int ret;
9183
9184         if (rte_eth_dev_filter_supported(res->port_id,
9185                                 RTE_ETH_FILTER_HASH) < 0) {
9186                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9187                                                         res->port_id);
9188                 return;
9189         }
9190
9191         memset(&info, 0, sizeof(info));
9192         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9193         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9194                                                 RTE_ETH_FILTER_GET, &info);
9195
9196         if (ret < 0) {
9197                 printf("Cannot get symmetric hash enable per port "
9198                                         "on port %u\n", res->port_id);
9199                 return;
9200         }
9201
9202         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9203                                 "enabled" : "disabled", res->port_id);
9204 }
9205
9206 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9207         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9208                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9209 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9210         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9211                 port_id, UINT8);
9212
9213 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9214         .f = cmd_get_sym_hash_per_port_parsed,
9215         .data = NULL,
9216         .help_str = "get_sym_hash_ena_per_port port_id",
9217         .tokens = {
9218                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9219                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9220                 NULL,
9221         },
9222 };
9223
9224 /* *** Set symmetric hash enable per port *** */
9225 struct cmd_set_sym_hash_ena_per_port_result {
9226         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9227         cmdline_fixed_string_t enable;
9228         uint8_t port_id;
9229 };
9230
9231 static void
9232 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9233                                  __rte_unused struct cmdline *cl,
9234                                  __rte_unused void *data)
9235 {
9236         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9237         struct rte_eth_hash_filter_info info;
9238         int ret;
9239
9240         if (rte_eth_dev_filter_supported(res->port_id,
9241                                 RTE_ETH_FILTER_HASH) < 0) {
9242                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9243                                                         res->port_id);
9244                 return;
9245         }
9246
9247         memset(&info, 0, sizeof(info));
9248         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9249         if (!strcmp(res->enable, "enable"))
9250                 info.info.enable = 1;
9251         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9252                                         RTE_ETH_FILTER_SET, &info);
9253         if (ret < 0) {
9254                 printf("Cannot set symmetric hash enable per port on "
9255                                         "port %u\n", res->port_id);
9256                 return;
9257         }
9258         printf("Symmetric hash has been set to %s on port %u\n",
9259                                         res->enable, res->port_id);
9260 }
9261
9262 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9263         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9264                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9265 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9266         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9267                 port_id, UINT8);
9268 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9269         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9270                 enable, "enable#disable");
9271
9272 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9273         .f = cmd_set_sym_hash_per_port_parsed,
9274         .data = NULL,
9275         .help_str = "set_sym_hash_ena_per_port port_id enable|disable",
9276         .tokens = {
9277                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9278                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9279                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9280                 NULL,
9281         },
9282 };
9283
9284 /* Get global config of hash function */
9285 struct cmd_get_hash_global_config_result {
9286         cmdline_fixed_string_t get_hash_global_config;
9287         uint8_t port_id;
9288 };
9289
9290 static char *
9291 flowtype_to_str(uint16_t ftype)
9292 {
9293         uint16_t i;
9294         static struct {
9295                 char str[16];
9296                 uint16_t ftype;
9297         } ftype_table[] = {
9298                 {"ipv4", RTE_ETH_FLOW_IPV4},
9299                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9300                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9301                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9302                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9303                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9304                 {"ipv6", RTE_ETH_FLOW_IPV6},
9305                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9306                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9307                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9308                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9309                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9310                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9311         };
9312
9313         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9314                 if (ftype_table[i].ftype == ftype)
9315                         return ftype_table[i].str;
9316         }
9317
9318         return NULL;
9319 }
9320
9321 static void
9322 cmd_get_hash_global_config_parsed(void *parsed_result,
9323                                   __rte_unused struct cmdline *cl,
9324                                   __rte_unused void *data)
9325 {
9326         struct cmd_get_hash_global_config_result *res = parsed_result;
9327         struct rte_eth_hash_filter_info info;
9328         uint32_t idx, offset;
9329         uint16_t i;
9330         char *str;
9331         int ret;
9332
9333         if (rte_eth_dev_filter_supported(res->port_id,
9334                         RTE_ETH_FILTER_HASH) < 0) {
9335                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9336                                                         res->port_id);
9337                 return;
9338         }
9339
9340         memset(&info, 0, sizeof(info));
9341         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9342         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9343                                         RTE_ETH_FILTER_GET, &info);
9344         if (ret < 0) {
9345                 printf("Cannot get hash global configurations by port %d\n",
9346                                                         res->port_id);
9347                 return;
9348         }
9349
9350         switch (info.info.global_conf.hash_func) {
9351         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9352                 printf("Hash function is Toeplitz\n");
9353                 break;
9354         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9355                 printf("Hash function is Simple XOR\n");
9356                 break;
9357         default:
9358                 printf("Unknown hash function\n");
9359                 break;
9360         }
9361
9362         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9363                 idx = i / UINT32_BIT;
9364                 offset = i % UINT32_BIT;
9365                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9366                                                 (1UL << offset)))
9367                         continue;
9368                 str = flowtype_to_str(i);
9369                 if (!str)
9370                         continue;
9371                 printf("Symmetric hash is %s globally for flow type %s "
9372                                                         "by port %d\n",
9373                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9374                         (1UL << offset)) ? "enabled" : "disabled"), str,
9375                                                         res->port_id);
9376         }
9377 }
9378
9379 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9380         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9381                 get_hash_global_config, "get_hash_global_config");
9382 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9383         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9384                 port_id, UINT8);
9385
9386 cmdline_parse_inst_t cmd_get_hash_global_config = {
9387         .f = cmd_get_hash_global_config_parsed,
9388         .data = NULL,
9389         .help_str = "get_hash_global_config port_id",
9390         .tokens = {
9391                 (void *)&cmd_get_hash_global_config_all,
9392                 (void *)&cmd_get_hash_global_config_port_id,
9393                 NULL,
9394         },
9395 };
9396
9397 /* Set global config of hash function */
9398 struct cmd_set_hash_global_config_result {
9399         cmdline_fixed_string_t set_hash_global_config;
9400         uint8_t port_id;
9401         cmdline_fixed_string_t hash_func;
9402         cmdline_fixed_string_t flow_type;
9403         cmdline_fixed_string_t enable;
9404 };
9405
9406 static void
9407 cmd_set_hash_global_config_parsed(void *parsed_result,
9408                                   __rte_unused struct cmdline *cl,
9409                                   __rte_unused void *data)
9410 {
9411         struct cmd_set_hash_global_config_result *res = parsed_result;
9412         struct rte_eth_hash_filter_info info;
9413         uint32_t ftype, idx, offset;
9414         int ret;
9415
9416         if (rte_eth_dev_filter_supported(res->port_id,
9417                                 RTE_ETH_FILTER_HASH) < 0) {
9418                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9419                                                         res->port_id);
9420                 return;
9421         }
9422         memset(&info, 0, sizeof(info));
9423         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9424         if (!strcmp(res->hash_func, "toeplitz"))
9425                 info.info.global_conf.hash_func =
9426                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9427         else if (!strcmp(res->hash_func, "simple_xor"))
9428                 info.info.global_conf.hash_func =
9429                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9430         else if (!strcmp(res->hash_func, "default"))
9431                 info.info.global_conf.hash_func =
9432                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9433
9434         ftype = str2flowtype(res->flow_type);
9435         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9436         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9437         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9438         if (!strcmp(res->enable, "enable"))
9439                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9440                                                 (1UL << offset);
9441         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9442                                         RTE_ETH_FILTER_SET, &info);
9443         if (ret < 0)
9444                 printf("Cannot set global hash configurations by port %d\n",
9445                                                         res->port_id);
9446         else
9447                 printf("Global hash configurations have been set "
9448                         "succcessfully by port %d\n", res->port_id);
9449 }
9450
9451 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9452         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9453                 set_hash_global_config, "set_hash_global_config");
9454 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9455         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9456                 port_id, UINT8);
9457 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9458         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9459                 hash_func, "toeplitz#simple_xor#default");
9460 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9461         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9462                 flow_type,
9463                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9464                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9465 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
9466         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9467                 enable, "enable#disable");
9468
9469 cmdline_parse_inst_t cmd_set_hash_global_config = {
9470         .f = cmd_set_hash_global_config_parsed,
9471         .data = NULL,
9472         .help_str = "set_hash_global_config port_id "
9473                 "toeplitz|simple_xor|default "
9474                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
9475                 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9476                 "enable|disable",
9477         .tokens = {
9478                 (void *)&cmd_set_hash_global_config_all,
9479                 (void *)&cmd_set_hash_global_config_port_id,
9480                 (void *)&cmd_set_hash_global_config_hash_func,
9481                 (void *)&cmd_set_hash_global_config_flow_type,
9482                 (void *)&cmd_set_hash_global_config_enable,
9483                 NULL,
9484         },
9485 };
9486
9487 /* Set hash input set */
9488 struct cmd_set_hash_input_set_result {
9489         cmdline_fixed_string_t set_hash_input_set;
9490         uint8_t port_id;
9491         cmdline_fixed_string_t flow_type;
9492         cmdline_fixed_string_t inset_field;
9493         cmdline_fixed_string_t select;
9494 };
9495
9496 static enum rte_eth_input_set_field
9497 str2inset(char *string)
9498 {
9499         uint16_t i;
9500
9501         static const struct {
9502                 char str[32];
9503                 enum rte_eth_input_set_field inset;
9504         } inset_table[] = {
9505                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
9506                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
9507                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
9508                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
9509                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
9510                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
9511                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
9512                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
9513                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
9514                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
9515                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
9516                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
9517                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
9518                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
9519                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
9520                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
9521                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
9522                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
9523                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
9524                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
9525                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
9526                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
9527                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
9528                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
9529                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
9530                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
9531                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
9532                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
9533                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
9534                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
9535                 {"none", RTE_ETH_INPUT_SET_NONE},
9536         };
9537
9538         for (i = 0; i < RTE_DIM(inset_table); i++) {
9539                 if (!strcmp(string, inset_table[i].str))
9540                         return inset_table[i].inset;
9541         }
9542
9543         return RTE_ETH_INPUT_SET_UNKNOWN;
9544 }
9545
9546 static void
9547 cmd_set_hash_input_set_parsed(void *parsed_result,
9548                               __rte_unused struct cmdline *cl,
9549                               __rte_unused void *data)
9550 {
9551         struct cmd_set_hash_input_set_result *res = parsed_result;
9552         struct rte_eth_hash_filter_info info;
9553
9554         memset(&info, 0, sizeof(info));
9555         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
9556         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9557         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9558         info.info.input_set_conf.inset_size = 1;
9559         if (!strcmp(res->select, "select"))
9560                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9561         else if (!strcmp(res->select, "add"))
9562                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9563         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9564                                 RTE_ETH_FILTER_SET, &info);
9565 }
9566
9567 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
9568         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9569                 set_hash_input_set, "set_hash_input_set");
9570 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
9571         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
9572                 port_id, UINT8);
9573 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
9574         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9575                 flow_type,
9576                 "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
9577                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9578 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
9579         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9580                 inset_field,
9581                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
9582                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
9583                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
9584                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
9585                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
9586                 "fld-8th#none");
9587 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
9588         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9589                 select, "select#add");
9590
9591 cmdline_parse_inst_t cmd_set_hash_input_set = {
9592         .f = cmd_set_hash_input_set_parsed,
9593         .data = NULL,
9594         .help_str = "set_hash_input_set <port_id> "
9595         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
9596         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9597         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
9598         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
9599         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
9600         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9601         "fld-7th|fld-8th|none select|add",
9602         .tokens = {
9603                 (void *)&cmd_set_hash_input_set_cmd,
9604                 (void *)&cmd_set_hash_input_set_port_id,
9605                 (void *)&cmd_set_hash_input_set_flow_type,
9606                 (void *)&cmd_set_hash_input_set_field,
9607                 (void *)&cmd_set_hash_input_set_select,
9608                 NULL,
9609         },
9610 };
9611
9612 /* Set flow director input set */
9613 struct cmd_set_fdir_input_set_result {
9614         cmdline_fixed_string_t set_fdir_input_set;
9615         uint8_t port_id;
9616         cmdline_fixed_string_t flow_type;
9617         cmdline_fixed_string_t inset_field;
9618         cmdline_fixed_string_t select;
9619 };
9620
9621 static void
9622 cmd_set_fdir_input_set_parsed(void *parsed_result,
9623         __rte_unused struct cmdline *cl,
9624         __rte_unused void *data)
9625 {
9626         struct cmd_set_fdir_input_set_result *res = parsed_result;
9627         struct rte_eth_fdir_filter_info info;
9628
9629         memset(&info, 0, sizeof(info));
9630         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
9631         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9632         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9633         info.info.input_set_conf.inset_size = 1;
9634         if (!strcmp(res->select, "select"))
9635                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9636         else if (!strcmp(res->select, "add"))
9637                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9638         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9639                 RTE_ETH_FILTER_SET, &info);
9640 }
9641
9642 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
9643         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9644         set_fdir_input_set, "set_fdir_input_set");
9645 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
9646         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
9647         port_id, UINT8);
9648 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
9649         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9650         flow_type,
9651         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
9652         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9653 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
9654         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9655         inset_field,
9656         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
9657         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
9658         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
9659         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
9660         "sctp-veri-tag#none");
9661 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
9662         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9663         select, "select#add");
9664
9665 cmdline_parse_inst_t cmd_set_fdir_input_set = {
9666         .f = cmd_set_fdir_input_set_parsed,
9667         .data = NULL,
9668         .help_str = "set_fdir_input_set <port_id> "
9669         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
9670         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9671         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
9672         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
9673         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
9674         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
9675         "sctp-veri-tag|none select|add",
9676         .tokens = {
9677                 (void *)&cmd_set_fdir_input_set_cmd,
9678                 (void *)&cmd_set_fdir_input_set_port_id,
9679                 (void *)&cmd_set_fdir_input_set_flow_type,
9680                 (void *)&cmd_set_fdir_input_set_field,
9681                 (void *)&cmd_set_fdir_input_set_select,
9682                 NULL,
9683         },
9684 };
9685
9686 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
9687 struct cmd_mcast_addr_result {
9688         cmdline_fixed_string_t mcast_addr_cmd;
9689         cmdline_fixed_string_t what;
9690         uint8_t port_num;
9691         struct ether_addr mc_addr;
9692 };
9693
9694 static void cmd_mcast_addr_parsed(void *parsed_result,
9695                 __attribute__((unused)) struct cmdline *cl,
9696                 __attribute__((unused)) void *data)
9697 {
9698         struct cmd_mcast_addr_result *res = parsed_result;
9699
9700         if (!is_multicast_ether_addr(&res->mc_addr)) {
9701                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
9702                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
9703                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
9704                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
9705                 return;
9706         }
9707         if (strcmp(res->what, "add") == 0)
9708                 mcast_addr_add(res->port_num, &res->mc_addr);
9709         else
9710                 mcast_addr_remove(res->port_num, &res->mc_addr);
9711 }
9712
9713 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
9714         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
9715                                  mcast_addr_cmd, "mcast_addr");
9716 cmdline_parse_token_string_t cmd_mcast_addr_what =
9717         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
9718                                  "add#remove");
9719 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
9720         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
9721 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
9722         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
9723
9724 cmdline_parse_inst_t cmd_mcast_addr = {
9725         .f = cmd_mcast_addr_parsed,
9726         .data = (void *)0,
9727         .help_str = "mcast_addr add|remove X <mcast_addr>: add/remove multicast MAC address on port X",
9728         .tokens = {
9729                 (void *)&cmd_mcast_addr_cmd,
9730                 (void *)&cmd_mcast_addr_what,
9731                 (void *)&cmd_mcast_addr_portnum,
9732                 (void *)&cmd_mcast_addr_addr,
9733                 NULL,
9734         },
9735 };
9736
9737 /* l2 tunnel config
9738  * only support E-tag now.
9739  */
9740
9741 /* Ether type config */
9742 struct cmd_config_l2_tunnel_eth_type_result {
9743         cmdline_fixed_string_t port;
9744         cmdline_fixed_string_t config;
9745         cmdline_fixed_string_t all;
9746         uint8_t id;
9747         cmdline_fixed_string_t l2_tunnel;
9748         cmdline_fixed_string_t l2_tunnel_type;
9749         cmdline_fixed_string_t eth_type;
9750         uint16_t eth_type_val;
9751 };
9752
9753 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
9754         TOKEN_STRING_INITIALIZER
9755                 (struct cmd_config_l2_tunnel_eth_type_result,
9756                  port, "port");
9757 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
9758         TOKEN_STRING_INITIALIZER
9759                 (struct cmd_config_l2_tunnel_eth_type_result,
9760                  config, "config");
9761 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
9762         TOKEN_STRING_INITIALIZER
9763                 (struct cmd_config_l2_tunnel_eth_type_result,
9764                  all, "all");
9765 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
9766         TOKEN_NUM_INITIALIZER
9767                 (struct cmd_config_l2_tunnel_eth_type_result,
9768                  id, UINT8);
9769 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
9770         TOKEN_STRING_INITIALIZER
9771                 (struct cmd_config_l2_tunnel_eth_type_result,
9772                  l2_tunnel, "l2-tunnel");
9773 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
9774         TOKEN_STRING_INITIALIZER
9775                 (struct cmd_config_l2_tunnel_eth_type_result,
9776                  l2_tunnel_type, "E-tag");
9777 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
9778         TOKEN_STRING_INITIALIZER
9779                 (struct cmd_config_l2_tunnel_eth_type_result,
9780                  eth_type, "ether-type");
9781 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
9782         TOKEN_NUM_INITIALIZER
9783                 (struct cmd_config_l2_tunnel_eth_type_result,
9784                  eth_type_val, UINT16);
9785
9786 static enum rte_eth_tunnel_type
9787 str2fdir_l2_tunnel_type(char *string)
9788 {
9789         uint32_t i = 0;
9790
9791         static const struct {
9792                 char str[32];
9793                 enum rte_eth_tunnel_type type;
9794         } l2_tunnel_type_str[] = {
9795                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
9796         };
9797
9798         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
9799                 if (!strcmp(l2_tunnel_type_str[i].str, string))
9800                         return l2_tunnel_type_str[i].type;
9801         }
9802         return RTE_TUNNEL_TYPE_NONE;
9803 }
9804
9805 /* ether type config for all ports */
9806 static void
9807 cmd_config_l2_tunnel_eth_type_all_parsed
9808         (void *parsed_result,
9809          __attribute__((unused)) struct cmdline *cl,
9810          __attribute__((unused)) void *data)
9811 {
9812         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
9813         struct rte_eth_l2_tunnel_conf entry;
9814         portid_t pid;
9815
9816         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9817         entry.ether_type = res->eth_type_val;
9818
9819         FOREACH_PORT(pid, ports) {
9820                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
9821         }
9822 }
9823
9824 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
9825         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
9826         .data = NULL,
9827         .help_str = "port config all l2-tunnel ether-type",
9828         .tokens = {
9829                 (void *)&cmd_config_l2_tunnel_eth_type_port,
9830                 (void *)&cmd_config_l2_tunnel_eth_type_config,
9831                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
9832                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
9833                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
9834                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
9835                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
9836                 NULL,
9837         },
9838 };
9839
9840 /* ether type config for a specific port */
9841 static void
9842 cmd_config_l2_tunnel_eth_type_specific_parsed(
9843         void *parsed_result,
9844         __attribute__((unused)) struct cmdline *cl,
9845         __attribute__((unused)) void *data)
9846 {
9847         struct cmd_config_l2_tunnel_eth_type_result *res =
9848                  parsed_result;
9849         struct rte_eth_l2_tunnel_conf entry;
9850
9851         if (port_id_is_invalid(res->id, ENABLED_WARN))
9852                 return;
9853
9854         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9855         entry.ether_type = res->eth_type_val;
9856
9857         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
9858 }
9859
9860 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
9861         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
9862         .data = NULL,
9863         .help_str = "port config l2-tunnel ether-type",
9864         .tokens = {
9865                 (void *)&cmd_config_l2_tunnel_eth_type_port,
9866                 (void *)&cmd_config_l2_tunnel_eth_type_config,
9867                 (void *)&cmd_config_l2_tunnel_eth_type_id,
9868                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
9869                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
9870                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
9871                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
9872                 NULL,
9873         },
9874 };
9875
9876 /* Enable/disable l2 tunnel */
9877 struct cmd_config_l2_tunnel_en_dis_result {
9878         cmdline_fixed_string_t port;
9879         cmdline_fixed_string_t config;
9880         cmdline_fixed_string_t all;
9881         uint8_t id;
9882         cmdline_fixed_string_t l2_tunnel;
9883         cmdline_fixed_string_t l2_tunnel_type;
9884         cmdline_fixed_string_t en_dis;
9885 };
9886
9887 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
9888         TOKEN_STRING_INITIALIZER
9889                 (struct cmd_config_l2_tunnel_en_dis_result,
9890                  port, "port");
9891 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
9892         TOKEN_STRING_INITIALIZER
9893                 (struct cmd_config_l2_tunnel_en_dis_result,
9894                  config, "config");
9895 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
9896         TOKEN_STRING_INITIALIZER
9897                 (struct cmd_config_l2_tunnel_en_dis_result,
9898                  all, "all");
9899 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
9900         TOKEN_NUM_INITIALIZER
9901                 (struct cmd_config_l2_tunnel_en_dis_result,
9902                  id, UINT8);
9903 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
9904         TOKEN_STRING_INITIALIZER
9905                 (struct cmd_config_l2_tunnel_en_dis_result,
9906                  l2_tunnel, "l2-tunnel");
9907 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
9908         TOKEN_STRING_INITIALIZER
9909                 (struct cmd_config_l2_tunnel_en_dis_result,
9910                  l2_tunnel_type, "E-tag");
9911 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
9912         TOKEN_STRING_INITIALIZER
9913                 (struct cmd_config_l2_tunnel_en_dis_result,
9914                  en_dis, "enable#disable");
9915
9916 /* enable/disable l2 tunnel for all ports */
9917 static void
9918 cmd_config_l2_tunnel_en_dis_all_parsed(
9919         void *parsed_result,
9920         __attribute__((unused)) struct cmdline *cl,
9921         __attribute__((unused)) void *data)
9922 {
9923         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
9924         struct rte_eth_l2_tunnel_conf entry;
9925         portid_t pid;
9926         uint8_t en;
9927
9928         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9929
9930         if (!strcmp("enable", res->en_dis))
9931                 en = 1;
9932         else
9933                 en = 0;
9934
9935         FOREACH_PORT(pid, ports) {
9936                 rte_eth_dev_l2_tunnel_offload_set(pid,
9937                                                   &entry,
9938                                                   ETH_L2_TUNNEL_ENABLE_MASK,
9939                                                   en);
9940         }
9941 }
9942
9943 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
9944         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
9945         .data = NULL,
9946         .help_str = "port config all l2-tunnel enable/disable",
9947         .tokens = {
9948                 (void *)&cmd_config_l2_tunnel_en_dis_port,
9949                 (void *)&cmd_config_l2_tunnel_en_dis_config,
9950                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
9951                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
9952                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
9953                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
9954                 NULL,
9955         },
9956 };
9957
9958 /* enable/disable l2 tunnel for a port */
9959 static void
9960 cmd_config_l2_tunnel_en_dis_specific_parsed(
9961         void *parsed_result,
9962         __attribute__((unused)) struct cmdline *cl,
9963         __attribute__((unused)) void *data)
9964 {
9965         struct cmd_config_l2_tunnel_en_dis_result *res =
9966                 parsed_result;
9967         struct rte_eth_l2_tunnel_conf entry;
9968
9969         if (port_id_is_invalid(res->id, ENABLED_WARN))
9970                 return;
9971
9972         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9973
9974         if (!strcmp("enable", res->en_dis))
9975                 rte_eth_dev_l2_tunnel_offload_set(res->id,
9976                                                   &entry,
9977                                                   ETH_L2_TUNNEL_ENABLE_MASK,
9978                                                   1);
9979         else
9980                 rte_eth_dev_l2_tunnel_offload_set(res->id,
9981                                                   &entry,
9982                                                   ETH_L2_TUNNEL_ENABLE_MASK,
9983                                                   0);
9984 }
9985
9986 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
9987         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
9988         .data = NULL,
9989         .help_str = "port config l2-tunnel enable/disable",
9990         .tokens = {
9991                 (void *)&cmd_config_l2_tunnel_en_dis_port,
9992                 (void *)&cmd_config_l2_tunnel_en_dis_config,
9993                 (void *)&cmd_config_l2_tunnel_en_dis_id,
9994                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
9995                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
9996                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
9997                 NULL,
9998         },
9999 };
10000
10001 /* E-tag configuration */
10002
10003 /* Common result structure for all E-tag configuration */
10004 struct cmd_config_e_tag_result {
10005         cmdline_fixed_string_t e_tag;
10006         cmdline_fixed_string_t set;
10007         cmdline_fixed_string_t insertion;
10008         cmdline_fixed_string_t stripping;
10009         cmdline_fixed_string_t forwarding;
10010         cmdline_fixed_string_t filter;
10011         cmdline_fixed_string_t add;
10012         cmdline_fixed_string_t del;
10013         cmdline_fixed_string_t on;
10014         cmdline_fixed_string_t off;
10015         cmdline_fixed_string_t on_off;
10016         cmdline_fixed_string_t port_tag_id;
10017         uint32_t port_tag_id_val;
10018         cmdline_fixed_string_t e_tag_id;
10019         uint16_t e_tag_id_val;
10020         cmdline_fixed_string_t dst_pool;
10021         uint8_t dst_pool_val;
10022         cmdline_fixed_string_t port;
10023         uint8_t port_id;
10024         cmdline_fixed_string_t vf;
10025         uint8_t vf_id;
10026 };
10027
10028 /* Common CLI fields for all E-tag configuration */
10029 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
10030         TOKEN_STRING_INITIALIZER
10031                 (struct cmd_config_e_tag_result,
10032                  e_tag, "E-tag");
10033 cmdline_parse_token_string_t cmd_config_e_tag_set =
10034         TOKEN_STRING_INITIALIZER
10035                 (struct cmd_config_e_tag_result,
10036                  set, "set");
10037 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
10038         TOKEN_STRING_INITIALIZER
10039                 (struct cmd_config_e_tag_result,
10040                  insertion, "insertion");
10041 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
10042         TOKEN_STRING_INITIALIZER
10043                 (struct cmd_config_e_tag_result,
10044                  stripping, "stripping");
10045 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
10046         TOKEN_STRING_INITIALIZER
10047                 (struct cmd_config_e_tag_result,
10048                  forwarding, "forwarding");
10049 cmdline_parse_token_string_t cmd_config_e_tag_filter =
10050         TOKEN_STRING_INITIALIZER
10051                 (struct cmd_config_e_tag_result,
10052                  filter, "filter");
10053 cmdline_parse_token_string_t cmd_config_e_tag_add =
10054         TOKEN_STRING_INITIALIZER
10055                 (struct cmd_config_e_tag_result,
10056                  add, "add");
10057 cmdline_parse_token_string_t cmd_config_e_tag_del =
10058         TOKEN_STRING_INITIALIZER
10059                 (struct cmd_config_e_tag_result,
10060                  del, "del");
10061 cmdline_parse_token_string_t cmd_config_e_tag_on =
10062         TOKEN_STRING_INITIALIZER
10063                 (struct cmd_config_e_tag_result,
10064                  on, "on");
10065 cmdline_parse_token_string_t cmd_config_e_tag_off =
10066         TOKEN_STRING_INITIALIZER
10067                 (struct cmd_config_e_tag_result,
10068                  off, "off");
10069 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
10070         TOKEN_STRING_INITIALIZER
10071                 (struct cmd_config_e_tag_result,
10072                  on_off, "on#off");
10073 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
10074         TOKEN_STRING_INITIALIZER
10075                 (struct cmd_config_e_tag_result,
10076                  port_tag_id, "port-tag-id");
10077 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
10078         TOKEN_NUM_INITIALIZER
10079                 (struct cmd_config_e_tag_result,
10080                  port_tag_id_val, UINT32);
10081 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
10082         TOKEN_STRING_INITIALIZER
10083                 (struct cmd_config_e_tag_result,
10084                  e_tag_id, "e-tag-id");
10085 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
10086         TOKEN_NUM_INITIALIZER
10087                 (struct cmd_config_e_tag_result,
10088                  e_tag_id_val, UINT16);
10089 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
10090         TOKEN_STRING_INITIALIZER
10091                 (struct cmd_config_e_tag_result,
10092                  dst_pool, "dst-pool");
10093 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
10094         TOKEN_NUM_INITIALIZER
10095                 (struct cmd_config_e_tag_result,
10096                  dst_pool_val, UINT8);
10097 cmdline_parse_token_string_t cmd_config_e_tag_port =
10098         TOKEN_STRING_INITIALIZER
10099                 (struct cmd_config_e_tag_result,
10100                  port, "port");
10101 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
10102         TOKEN_NUM_INITIALIZER
10103                 (struct cmd_config_e_tag_result,
10104                  port_id, UINT8);
10105 cmdline_parse_token_string_t cmd_config_e_tag_vf =
10106         TOKEN_STRING_INITIALIZER
10107                 (struct cmd_config_e_tag_result,
10108                  vf, "vf");
10109 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
10110         TOKEN_NUM_INITIALIZER
10111                 (struct cmd_config_e_tag_result,
10112                  vf_id, UINT8);
10113
10114 /* E-tag insertion configuration */
10115 static void
10116 cmd_config_e_tag_insertion_en_parsed(
10117         void *parsed_result,
10118         __attribute__((unused)) struct cmdline *cl,
10119         __attribute__((unused)) void *data)
10120 {
10121         struct cmd_config_e_tag_result *res =
10122                 parsed_result;
10123         struct rte_eth_l2_tunnel_conf entry;
10124
10125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10126                 return;
10127
10128         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10129         entry.tunnel_id = res->port_tag_id_val;
10130         entry.vf_id = res->vf_id;
10131         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10132                                           &entry,
10133                                           ETH_L2_TUNNEL_INSERTION_MASK,
10134                                           1);
10135 }
10136
10137 static void
10138 cmd_config_e_tag_insertion_dis_parsed(
10139         void *parsed_result,
10140         __attribute__((unused)) struct cmdline *cl,
10141         __attribute__((unused)) void *data)
10142 {
10143         struct cmd_config_e_tag_result *res =
10144                 parsed_result;
10145         struct rte_eth_l2_tunnel_conf entry;
10146
10147         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10148                 return;
10149
10150         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10151         entry.vf_id = res->vf_id;
10152
10153         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
10154                                           &entry,
10155                                           ETH_L2_TUNNEL_INSERTION_MASK,
10156                                           0);
10157 }
10158
10159 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
10160         .f = cmd_config_e_tag_insertion_en_parsed,
10161         .data = NULL,
10162         .help_str = "E-tag insertion enable",
10163         .tokens = {
10164                 (void *)&cmd_config_e_tag_e_tag,
10165                 (void *)&cmd_config_e_tag_set,
10166                 (void *)&cmd_config_e_tag_insertion,
10167                 (void *)&cmd_config_e_tag_on,
10168                 (void *)&cmd_config_e_tag_port_tag_id,
10169                 (void *)&cmd_config_e_tag_port_tag_id_val,
10170                 (void *)&cmd_config_e_tag_port,
10171                 (void *)&cmd_config_e_tag_port_id,
10172                 (void *)&cmd_config_e_tag_vf,
10173                 (void *)&cmd_config_e_tag_vf_id,
10174                 NULL,
10175         },
10176 };
10177
10178 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
10179         .f = cmd_config_e_tag_insertion_dis_parsed,
10180         .data = NULL,
10181         .help_str = "E-tag insertion disable",
10182         .tokens = {
10183                 (void *)&cmd_config_e_tag_e_tag,
10184                 (void *)&cmd_config_e_tag_set,
10185                 (void *)&cmd_config_e_tag_insertion,
10186                 (void *)&cmd_config_e_tag_off,
10187                 (void *)&cmd_config_e_tag_port,
10188                 (void *)&cmd_config_e_tag_port_id,
10189                 (void *)&cmd_config_e_tag_vf,
10190                 (void *)&cmd_config_e_tag_vf_id,
10191                 NULL,
10192         },
10193 };
10194
10195 /* E-tag stripping configuration */
10196 static void
10197 cmd_config_e_tag_stripping_parsed(
10198         void *parsed_result,
10199         __attribute__((unused)) struct cmdline *cl,
10200         __attribute__((unused)) void *data)
10201 {
10202         struct cmd_config_e_tag_result *res =
10203                 parsed_result;
10204         struct rte_eth_l2_tunnel_conf entry;
10205
10206         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10207                 return;
10208
10209         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10210
10211         if (!strcmp(res->on_off, "on"))
10212                 rte_eth_dev_l2_tunnel_offload_set
10213                         (res->port_id,
10214                          &entry,
10215                          ETH_L2_TUNNEL_STRIPPING_MASK,
10216                          1);
10217         else
10218                 rte_eth_dev_l2_tunnel_offload_set
10219                         (res->port_id,
10220                          &entry,
10221                          ETH_L2_TUNNEL_STRIPPING_MASK,
10222                          0);
10223 }
10224
10225 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
10226         .f = cmd_config_e_tag_stripping_parsed,
10227         .data = NULL,
10228         .help_str = "E-tag stripping enable/disable",
10229         .tokens = {
10230                 (void *)&cmd_config_e_tag_e_tag,
10231                 (void *)&cmd_config_e_tag_set,
10232                 (void *)&cmd_config_e_tag_stripping,
10233                 (void *)&cmd_config_e_tag_on_off,
10234                 (void *)&cmd_config_e_tag_port,
10235                 (void *)&cmd_config_e_tag_port_id,
10236                 NULL,
10237         },
10238 };
10239
10240 /* E-tag forwarding configuration */
10241 static void
10242 cmd_config_e_tag_forwarding_parsed(
10243         void *parsed_result,
10244         __attribute__((unused)) struct cmdline *cl,
10245         __attribute__((unused)) void *data)
10246 {
10247         struct cmd_config_e_tag_result *res = parsed_result;
10248         struct rte_eth_l2_tunnel_conf entry;
10249
10250         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10251                 return;
10252
10253         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10254
10255         if (!strcmp(res->on_off, "on"))
10256                 rte_eth_dev_l2_tunnel_offload_set
10257                         (res->port_id,
10258                          &entry,
10259                          ETH_L2_TUNNEL_FORWARDING_MASK,
10260                          1);
10261         else
10262                 rte_eth_dev_l2_tunnel_offload_set
10263                         (res->port_id,
10264                          &entry,
10265                          ETH_L2_TUNNEL_FORWARDING_MASK,
10266                          0);
10267 }
10268
10269 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
10270         .f = cmd_config_e_tag_forwarding_parsed,
10271         .data = NULL,
10272         .help_str = "E-tag forwarding enable/disable",
10273         .tokens = {
10274                 (void *)&cmd_config_e_tag_e_tag,
10275                 (void *)&cmd_config_e_tag_set,
10276                 (void *)&cmd_config_e_tag_forwarding,
10277                 (void *)&cmd_config_e_tag_on_off,
10278                 (void *)&cmd_config_e_tag_port,
10279                 (void *)&cmd_config_e_tag_port_id,
10280                 NULL,
10281         },
10282 };
10283
10284 /* E-tag filter configuration */
10285 static void
10286 cmd_config_e_tag_filter_add_parsed(
10287         void *parsed_result,
10288         __attribute__((unused)) struct cmdline *cl,
10289         __attribute__((unused)) void *data)
10290 {
10291         struct cmd_config_e_tag_result *res = parsed_result;
10292         struct rte_eth_l2_tunnel_conf entry;
10293         int ret = 0;
10294
10295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10296                 return;
10297
10298         if (res->e_tag_id_val > 0x3fff) {
10299                 printf("e-tag-id must be equal or less than 0x3fff.\n");
10300                 return;
10301         }
10302
10303         ret = rte_eth_dev_filter_supported(res->port_id,
10304                                            RTE_ETH_FILTER_L2_TUNNEL);
10305         if (ret < 0) {
10306                 printf("E-tag filter is not supported on port %u.\n",
10307                        res->port_id);
10308                 return;
10309         }
10310
10311         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10312         entry.tunnel_id = res->e_tag_id_val;
10313         entry.pool = res->dst_pool_val;
10314
10315         ret = rte_eth_dev_filter_ctrl(res->port_id,
10316                                       RTE_ETH_FILTER_L2_TUNNEL,
10317                                       RTE_ETH_FILTER_ADD,
10318                                       &entry);
10319         if (ret < 0)
10320                 printf("E-tag filter programming error: (%s)\n",
10321                        strerror(-ret));
10322 }
10323
10324 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
10325         .f = cmd_config_e_tag_filter_add_parsed,
10326         .data = NULL,
10327         .help_str = "E-tag filter add",
10328         .tokens = {
10329                 (void *)&cmd_config_e_tag_e_tag,
10330                 (void *)&cmd_config_e_tag_set,
10331                 (void *)&cmd_config_e_tag_filter,
10332                 (void *)&cmd_config_e_tag_add,
10333                 (void *)&cmd_config_e_tag_e_tag_id,
10334                 (void *)&cmd_config_e_tag_e_tag_id_val,
10335                 (void *)&cmd_config_e_tag_dst_pool,
10336                 (void *)&cmd_config_e_tag_dst_pool_val,
10337                 (void *)&cmd_config_e_tag_port,
10338                 (void *)&cmd_config_e_tag_port_id,
10339                 NULL,
10340         },
10341 };
10342
10343 static void
10344 cmd_config_e_tag_filter_del_parsed(
10345         void *parsed_result,
10346         __attribute__((unused)) struct cmdline *cl,
10347         __attribute__((unused)) void *data)
10348 {
10349         struct cmd_config_e_tag_result *res = parsed_result;
10350         struct rte_eth_l2_tunnel_conf entry;
10351         int ret = 0;
10352
10353         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10354                 return;
10355
10356         if (res->e_tag_id_val > 0x3fff) {
10357                 printf("e-tag-id must be less than 0x3fff.\n");
10358                 return;
10359         }
10360
10361         ret = rte_eth_dev_filter_supported(res->port_id,
10362                                            RTE_ETH_FILTER_L2_TUNNEL);
10363         if (ret < 0) {
10364                 printf("E-tag filter is not supported on port %u.\n",
10365                        res->port_id);
10366                 return;
10367         }
10368
10369         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
10370         entry.tunnel_id = res->e_tag_id_val;
10371
10372         ret = rte_eth_dev_filter_ctrl(res->port_id,
10373                                       RTE_ETH_FILTER_L2_TUNNEL,
10374                                       RTE_ETH_FILTER_DELETE,
10375                                       &entry);
10376         if (ret < 0)
10377                 printf("E-tag filter programming error: (%s)\n",
10378                        strerror(-ret));
10379 }
10380
10381 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
10382         .f = cmd_config_e_tag_filter_del_parsed,
10383         .data = NULL,
10384         .help_str = "E-tag filter delete",
10385         .tokens = {
10386                 (void *)&cmd_config_e_tag_e_tag,
10387                 (void *)&cmd_config_e_tag_set,
10388                 (void *)&cmd_config_e_tag_filter,
10389                 (void *)&cmd_config_e_tag_del,
10390                 (void *)&cmd_config_e_tag_e_tag_id,
10391                 (void *)&cmd_config_e_tag_e_tag_id_val,
10392                 (void *)&cmd_config_e_tag_port,
10393                 (void *)&cmd_config_e_tag_port_id,
10394                 NULL,
10395         },
10396 };
10397
10398 /* ******************************************************************************** */
10399
10400 /* list of instructions */
10401 cmdline_parse_ctx_t main_ctx[] = {
10402         (cmdline_parse_inst_t *)&cmd_help_brief,
10403         (cmdline_parse_inst_t *)&cmd_help_long,
10404         (cmdline_parse_inst_t *)&cmd_quit,
10405         (cmdline_parse_inst_t *)&cmd_showport,
10406         (cmdline_parse_inst_t *)&cmd_showqueue,
10407         (cmdline_parse_inst_t *)&cmd_showportall,
10408         (cmdline_parse_inst_t *)&cmd_showcfg,
10409         (cmdline_parse_inst_t *)&cmd_start,
10410         (cmdline_parse_inst_t *)&cmd_start_tx_first,
10411         (cmdline_parse_inst_t *)&cmd_set_link_up,
10412         (cmdline_parse_inst_t *)&cmd_set_link_down,
10413         (cmdline_parse_inst_t *)&cmd_reset,
10414         (cmdline_parse_inst_t *)&cmd_set_numbers,
10415         (cmdline_parse_inst_t *)&cmd_set_txpkts,
10416         (cmdline_parse_inst_t *)&cmd_set_txsplit,
10417         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
10418         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
10419         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
10420         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
10421         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
10422         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
10423         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
10424         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
10425         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
10426         (cmdline_parse_inst_t *)&cmd_set_link_check,
10427 #ifdef RTE_NIC_BYPASS
10428         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
10429         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
10430         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
10431         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
10432 #endif
10433 #ifdef RTE_LIBRTE_PMD_BOND
10434         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
10435         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
10436         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
10437         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
10438         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
10439         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
10440         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
10441         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
10442         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
10443 #endif
10444         (cmdline_parse_inst_t *)&cmd_vlan_offload,
10445         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
10446         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
10447         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
10448         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
10449         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
10450         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
10451         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
10452         (cmdline_parse_inst_t *)&cmd_csum_set,
10453         (cmdline_parse_inst_t *)&cmd_csum_show,
10454         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
10455         (cmdline_parse_inst_t *)&cmd_tso_set,
10456         (cmdline_parse_inst_t *)&cmd_tso_show,
10457         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
10458         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
10459         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
10460         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
10461         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
10462         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
10463         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
10464         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
10465         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
10466         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
10467         (cmdline_parse_inst_t *)&cmd_config_dcb,
10468         (cmdline_parse_inst_t *)&cmd_read_reg,
10469         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
10470         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
10471         (cmdline_parse_inst_t *)&cmd_write_reg,
10472         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
10473         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
10474         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
10475         (cmdline_parse_inst_t *)&cmd_stop,
10476         (cmdline_parse_inst_t *)&cmd_mac_addr,
10477         (cmdline_parse_inst_t *)&cmd_set_qmap,
10478         (cmdline_parse_inst_t *)&cmd_operate_port,
10479         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
10480         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
10481         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
10482         (cmdline_parse_inst_t *)&cmd_config_speed_all,
10483         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
10484         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
10485         (cmdline_parse_inst_t *)&cmd_config_mtu,
10486         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
10487         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
10488         (cmdline_parse_inst_t *)&cmd_config_rss,
10489         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
10490         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
10491         (cmdline_parse_inst_t *)&cmd_showport_reta,
10492         (cmdline_parse_inst_t *)&cmd_config_burst,
10493         (cmdline_parse_inst_t *)&cmd_config_thresh,
10494         (cmdline_parse_inst_t *)&cmd_config_threshold,
10495         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
10496         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
10497         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
10498         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
10499         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
10500         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
10501         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
10502         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
10503         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
10504         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
10505         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
10506         (cmdline_parse_inst_t *)&cmd_global_config,
10507         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
10508         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
10509         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
10510         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
10511         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
10512         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
10513         (cmdline_parse_inst_t *)&cmd_dump,
10514         (cmdline_parse_inst_t *)&cmd_dump_one,
10515         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
10516         (cmdline_parse_inst_t *)&cmd_syn_filter,
10517         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
10518         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
10519         (cmdline_parse_inst_t *)&cmd_flex_filter,
10520         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
10521         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
10522         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
10523         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
10524         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
10525         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
10526         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
10527         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
10528         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
10529         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
10530         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
10531         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
10532         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
10533         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
10534         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
10535         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
10536         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
10537         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
10538         (cmdline_parse_inst_t *)&cmd_mcast_addr,
10539         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
10540         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
10541         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
10542         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
10543         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
10544         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
10545         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
10546         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
10547         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
10548         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
10549         NULL,
10550 };
10551
10552 /* prompt function, called from main on MASTER lcore */
10553 void
10554 prompt(void)
10555 {
10556         /* initialize non-constant commands */
10557         cmd_set_fwd_mode_init();
10558
10559         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
10560         if (testpmd_cl == NULL)
10561                 return;
10562         cmdline_interact(testpmd_cl);
10563         cmdline_stdin_exit(testpmd_cl);
10564 }
10565
10566 void
10567 prompt_exit(void)
10568 {
10569         if (testpmd_cl != NULL)
10570                 cmdline_quit(testpmd_cl);
10571 }
10572
10573 static void
10574 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
10575 {
10576         if (id == (portid_t)RTE_PORT_ALL) {
10577                 portid_t pid;
10578
10579                 FOREACH_PORT(pid, ports) {
10580                         /* check if need_reconfig has been set to 1 */
10581                         if (ports[pid].need_reconfig == 0)
10582                                 ports[pid].need_reconfig = dev;
10583                         /* check if need_reconfig_queues has been set to 1 */
10584                         if (ports[pid].need_reconfig_queues == 0)
10585                                 ports[pid].need_reconfig_queues = queue;
10586                 }
10587         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
10588                 /* check if need_reconfig has been set to 1 */
10589                 if (ports[id].need_reconfig == 0)
10590                         ports[id].need_reconfig = dev;
10591                 /* check if need_reconfig_queues has been set to 1 */
10592                 if (ports[id].need_reconfig_queues == 0)
10593                         ports[id].need_reconfig_queues = queue;
10594         }
10595 }
10596
10597 #ifdef RTE_NIC_BYPASS
10598 #include <rte_pci_dev_ids.h>
10599 uint8_t
10600 bypass_is_supported(portid_t port_id)
10601 {
10602         struct rte_port   *port;
10603         struct rte_pci_id *pci_id;
10604
10605         if (port_id_is_invalid(port_id, ENABLED_WARN))
10606                 return 0;
10607
10608         /* Get the device id. */
10609         port    = &ports[port_id];
10610         pci_id = &port->dev_info.pci_dev->id;
10611
10612         /* Check if NIC supports bypass. */
10613         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
10614                 return 1;
10615         }
10616         else {
10617                 printf("\tBypass not supported for port_id = %d.\n", port_id);
10618                 return 0;
10619         }
10620 }
10621 #endif