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