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