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