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