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