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