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