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