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