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