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