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