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