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