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