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