app/testpmd: add new command for show port info
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.h"
78 #include "bpf_cmd.h"
79
80 static struct cmdline *testpmd_cl;
81
82 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
83
84 /* *** Help command with introduction. *** */
85 struct cmd_help_brief_result {
86         cmdline_fixed_string_t help;
87 };
88
89 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
90                                   struct cmdline *cl,
91                                   __attribute__((unused)) void *data)
92 {
93         cmdline_printf(
94                 cl,
95                 "\n"
96                 "Help is available for the following sections:\n\n"
97                 "    help control    : Start and stop forwarding.\n"
98                 "    help display    : Displaying port, stats and config "
99                 "information.\n"
100                 "    help config     : Configuration information.\n"
101                 "    help ports      : Configuring ports.\n"
102                 "    help registers  : Reading and setting port registers.\n"
103                 "    help filters    : Filters configuration help.\n"
104                 "    help all        : All of the above sections.\n\n"
105         );
106
107 }
108
109 cmdline_parse_token_string_t cmd_help_brief_help =
110         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
111
112 cmdline_parse_inst_t cmd_help_brief = {
113         .f = cmd_help_brief_parsed,
114         .data = NULL,
115         .help_str = "help: Show help",
116         .tokens = {
117                 (void *)&cmd_help_brief_help,
118                 NULL,
119         },
120 };
121
122 /* *** Help command with help sections. *** */
123 struct cmd_help_long_result {
124         cmdline_fixed_string_t help;
125         cmdline_fixed_string_t section;
126 };
127
128 static void cmd_help_long_parsed(void *parsed_result,
129                                  struct cmdline *cl,
130                                  __attribute__((unused)) void *data)
131 {
132         int show_all = 0;
133         struct cmd_help_long_result *res = parsed_result;
134
135         if (!strcmp(res->section, "all"))
136                 show_all = 1;
137
138         if (show_all || !strcmp(res->section, "control")) {
139
140                 cmdline_printf(
141                         cl,
142                         "\n"
143                         "Control forwarding:\n"
144                         "-------------------\n\n"
145
146                         "start\n"
147                         "    Start packet forwarding with current configuration.\n\n"
148
149                         "start tx_first\n"
150                         "    Start packet forwarding with current config"
151                         " after sending one burst of packets.\n\n"
152
153                         "stop\n"
154                         "    Stop packet forwarding, and display accumulated"
155                         " statistics.\n\n"
156
157                         "quit\n"
158                         "    Quit to prompt.\n\n"
159                 );
160         }
161
162         if (show_all || !strcmp(res->section, "display")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Display:\n"
168                         "--------\n\n"
169
170                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
171                         "    Display information for port_id, or all.\n\n"
172
173                         "show port X rss reta (size) (mask0,mask1,...)\n"
174                         "    Display the rss redirection table entry indicated"
175                         " by masks on port X. size is used to indicate the"
176                         " hardware supported reta size\n\n"
177
178                         "show port (port_id) rss-hash [key]\n"
179                         "    Display the RSS hash functions and RSS hash key of port\n\n"
180
181                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
182                         "    Clear information for port_id, or all.\n\n"
183
184                         "show (rxq|txq) info (port_id) (queue_id)\n"
185                         "    Display information for configured RX/TX queue.\n\n"
186
187                         "show config (rxtx|cores|fwd|txpkts)\n"
188                         "    Display the given configuration.\n\n"
189
190                         "read rxd (port_id) (queue_id) (rxd_id)\n"
191                         "    Display an RX descriptor of a port RX queue.\n\n"
192
193                         "read txd (port_id) (queue_id) (txd_id)\n"
194                         "    Display a TX descriptor of a port TX queue.\n\n"
195
196                         "ddp get list (port_id)\n"
197                         "    Get ddp profile info list\n\n"
198
199                         "ddp get info (profile_path)\n"
200                         "    Get ddp profile information.\n\n"
201
202                         "show vf stats (port_id) (vf_id)\n"
203                         "    Display a VF's statistics.\n\n"
204
205                         "clear vf stats (port_id) (vf_id)\n"
206                         "    Reset a VF's statistics.\n\n"
207
208                         "show port (port_id) pctype mapping\n"
209                         "    Get flow ptype to pctype mapping on a port\n\n"
210
211                         "show port meter stats (port_id) (meter_id) (clear)\n"
212                         "    Get meter stats on a port\n\n"
213                         "show port tm cap (port_id)\n"
214                         "       Display the port TM capability.\n\n"
215
216                         "show port tm level cap (port_id) (level_id)\n"
217                         "       Display the port TM hierarchical level capability.\n\n"
218
219                         "show port tm node cap (port_id) (node_id)\n"
220                         "       Display the port TM node capability.\n\n"
221
222                         "show port tm node type (port_id) (node_id)\n"
223                         "       Display the port TM node type.\n\n"
224
225                         "show port tm node stats (port_id) (node_id) (clear)\n"
226                         "       Display the port TM node stats.\n\n"
227
228                 );
229         }
230
231         if (show_all || !strcmp(res->section, "config")) {
232                 cmdline_printf(
233                         cl,
234                         "\n"
235                         "Configuration:\n"
236                         "--------------\n"
237                         "Configuration changes only become active when"
238                         " forwarding is started/restarted.\n\n"
239
240                         "set default\n"
241                         "    Reset forwarding to the default configuration.\n\n"
242
243                         "set verbose (level)\n"
244                         "    Set the debug verbosity level X.\n\n"
245
246                         "set log global|(type) (level)\n"
247                         "    Set the log level.\n\n"
248
249                         "set nbport (num)\n"
250                         "    Set number of ports.\n\n"
251
252                         "set nbcore (num)\n"
253                         "    Set number of cores.\n\n"
254
255                         "set coremask (mask)\n"
256                         "    Set the forwarding cores hexadecimal mask.\n\n"
257
258                         "set portmask (mask)\n"
259                         "    Set the forwarding ports hexadecimal mask.\n\n"
260
261                         "set burst (num)\n"
262                         "    Set number of packets per burst.\n\n"
263
264                         "set burst tx delay (microseconds) retry (num)\n"
265                         "    Set the transmit delay time and number of retries,"
266                         " effective when retry is enabled.\n\n"
267
268                         "set txpkts (x[,y]*)\n"
269                         "    Set the length of each segment of TXONLY"
270                         " and optionally CSUM packets.\n\n"
271
272                         "set txsplit (off|on|rand)\n"
273                         "    Set the split policy for the TX packets."
274                         " Right now only applicable for CSUM and TXONLY"
275                         " modes\n\n"
276
277                         "set corelist (x[,y]*)\n"
278                         "    Set the list of forwarding cores.\n\n"
279
280                         "set portlist (x[,y]*)\n"
281                         "    Set the list of forwarding ports.\n\n"
282
283                         "set tx loopback (port_id) (on|off)\n"
284                         "    Enable or disable tx loopback.\n\n"
285
286                         "set all queues drop (port_id) (on|off)\n"
287                         "    Set drop enable bit for all queues.\n\n"
288
289                         "set vf split drop (port_id) (vf_id) (on|off)\n"
290                         "    Set split drop enable bit for a VF from the PF.\n\n"
291
292                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
293                         "    Set MAC antispoof for a VF from the PF.\n\n"
294
295                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
296                         "    Enable MACsec offload.\n\n"
297
298                         "set macsec offload (port_id) off\n"
299                         "    Disable MACsec offload.\n\n"
300
301                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
302                         "    Configure MACsec secure connection (SC).\n\n"
303
304                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
305                         "    Configure MACsec secure association (SA).\n\n"
306
307                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
308                         "    Set VF broadcast for a VF from the PF.\n\n"
309
310                         "vlan set strip (on|off) (port_id)\n"
311                         "    Set the VLAN strip on a port.\n\n"
312
313                         "vlan set stripq (on|off) (port_id,queue_id)\n"
314                         "    Set the VLAN strip for a queue on a port.\n\n"
315
316                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
317                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
318
319                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
320                         "    Set VLAN insert for a VF from the PF.\n\n"
321
322                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
323                         "    Set VLAN antispoof for a VF from the PF.\n\n"
324
325                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
326                         "    Set VLAN tag for a VF from the PF.\n\n"
327
328                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
329                         "    Set a VF's max bandwidth(Mbps).\n\n"
330
331                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
332                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
333
334                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
335                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
336
337                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
338                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
339
340                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
341                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
342
343                         "vlan set filter (on|off) (port_id)\n"
344                         "    Set the VLAN filter on a port.\n\n"
345
346                         "vlan set qinq (on|off) (port_id)\n"
347                         "    Set the VLAN QinQ (extended queue in queue)"
348                         " on a port.\n\n"
349
350                         "vlan set (inner|outer) tpid (value) (port_id)\n"
351                         "    Set the VLAN TPID for Packet Filtering on"
352                         " a port\n\n"
353
354                         "rx_vlan add (vlan_id|all) (port_id)\n"
355                         "    Add a vlan_id, or all identifiers, to the set"
356                         " of VLAN identifiers filtered by port_id.\n\n"
357
358                         "rx_vlan rm (vlan_id|all) (port_id)\n"
359                         "    Remove a vlan_id, or all identifiers, from the set"
360                         " of VLAN identifiers filtered by port_id.\n\n"
361
362                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
363                         "    Add a vlan_id, to the set of VLAN identifiers"
364                         "filtered for VF(s) from port_id.\n\n"
365
366                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
367                         "    Remove a vlan_id, to the set of VLAN identifiers"
368                         "filtered for VF(s) from port_id.\n\n"
369
370                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
371                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
372                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
373                         "   add a tunnel filter of a port.\n\n"
374
375                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
376                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
377                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
378                         "   remove a tunnel filter of a port.\n\n"
379
380                         "rx_vxlan_port add (udp_port) (port_id)\n"
381                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
382
383                         "rx_vxlan_port rm (udp_port) (port_id)\n"
384                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
385
386                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
387                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
388                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
389
390                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
391                         "    Set port based TX VLAN insertion.\n\n"
392
393                         "tx_vlan reset (port_id)\n"
394                         "    Disable hardware insertion of a VLAN header in"
395                         " packets sent on a port.\n\n"
396
397                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
398                         "    Select hardware or software calculation of the"
399                         " checksum when transmitting a packet using the"
400                         " csum forward engine.\n"
401                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
402                         "    outer-ip concerns the outer IP layer in"
403                         "    outer-udp concerns the outer UDP layer in"
404                         " case the packet is recognized as a tunnel packet by"
405                         " the forward engine (vxlan, gre and ipip are supported)\n"
406                         "    Please check the NIC datasheet for HW limits.\n\n"
407
408                         "csum parse-tunnel (on|off) (tx_port_id)\n"
409                         "    If disabled, treat tunnel packets as non-tunneled"
410                         " packets (treat inner headers as payload). The port\n"
411                         "    argument is the port used for TX in csum forward"
412                         " engine.\n\n"
413
414                         "csum show (port_id)\n"
415                         "    Display tx checksum offload configuration\n\n"
416
417                         "tso set (segsize) (portid)\n"
418                         "    Enable TCP Segmentation Offload in csum forward"
419                         " engine.\n"
420                         "    Please check the NIC datasheet for HW limits.\n\n"
421
422                         "tso show (portid)"
423                         "    Display the status of TCP Segmentation Offload.\n\n"
424
425                         "set port (port_id) gro on|off\n"
426                         "    Enable or disable Generic Receive Offload in"
427                         " csum forwarding engine.\n\n"
428
429                         "show port (port_id) gro\n"
430                         "    Display GRO configuration.\n\n"
431
432                         "set gro flush (cycles)\n"
433                         "    Set the cycle to flush GROed packets from"
434                         " reassembly tables.\n\n"
435
436                         "set port (port_id) gso (on|off)"
437                         "    Enable or disable Generic Segmentation Offload in"
438                         " csum forwarding engine.\n\n"
439
440                         "set gso segsz (length)\n"
441                         "    Set max packet length for output GSO segments,"
442                         " including packet header and payload.\n\n"
443
444                         "show port (port_id) gso\n"
445                         "    Show GSO configuration.\n\n"
446
447                         "set fwd (%s)\n"
448                         "    Set packet forwarding mode.\n\n"
449
450                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
451                         "    Add a MAC address on port_id.\n\n"
452
453                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
454                         "    Remove a MAC address from port_id.\n\n"
455
456                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
457                         "    Set the default MAC address for port_id.\n\n"
458
459                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
460                         "    Add a MAC address for a VF on the port.\n\n"
461
462                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
463                         "    Set the MAC address for a VF from the PF.\n\n"
464
465                         "set eth-peer (port_id) (peer_addr)\n"
466                         "    set the peer address for certain port.\n\n"
467
468                         "set port (port_id) uta (mac_address|all) (on|off)\n"
469                         "    Add/Remove a or all unicast hash filter(s)"
470                         "from port X.\n\n"
471
472                         "set promisc (port_id|all) (on|off)\n"
473                         "    Set the promiscuous mode on port_id, or all.\n\n"
474
475                         "set allmulti (port_id|all) (on|off)\n"
476                         "    Set the allmulti mode on port_id, or all.\n\n"
477
478                         "set vf promisc (port_id) (vf_id) (on|off)\n"
479                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
480
481                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
482                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
483
484                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
485                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
486                         " (on|off) autoneg (on|off) (port_id)\n"
487                         "set flow_ctrl rx (on|off) (portid)\n"
488                         "set flow_ctrl tx (on|off) (portid)\n"
489                         "set flow_ctrl high_water (high_water) (portid)\n"
490                         "set flow_ctrl low_water (low_water) (portid)\n"
491                         "set flow_ctrl pause_time (pause_time) (portid)\n"
492                         "set flow_ctrl send_xon (send_xon) (portid)\n"
493                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
494                         "set flow_ctrl autoneg (on|off) (port_id)\n"
495                         "    Set the link flow control parameter on a port.\n\n"
496
497                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
498                         " (low_water) (pause_time) (priority) (port_id)\n"
499                         "    Set the priority flow control parameter on a"
500                         " port.\n\n"
501
502                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
503                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
504                         " queue on port.\n"
505                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
506                         " on port 0 to mapping 5.\n\n"
507
508                         "set xstats-hide-zero on|off\n"
509                         "    Set the option to hide the zero values"
510                         " for xstats display.\n"
511
512                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
513                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
514
515                         "set port (port_id) vf (vf_id) (mac_addr)"
516                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
517                         "   Add/Remove unicast or multicast MAC addr filter"
518                         " for a VF.\n\n"
519
520                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
521                         "|MPE) (on|off)\n"
522                         "    AUPE:accepts untagged VLAN;"
523                         "ROPE:accept unicast hash\n\n"
524                         "    BAM:accepts broadcast packets;"
525                         "MPE:accepts all multicast packets\n\n"
526                         "    Enable/Disable a VF receive mode of a port\n\n"
527
528                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
529                         "    Set rate limit for a queue of a port\n\n"
530
531                         "set port (port_id) vf (vf_id) rate (rate_num) "
532                         "queue_mask (queue_mask_value)\n"
533                         "    Set rate limit for queues in VF of a port\n\n"
534
535                         "set port (port_id) mirror-rule (rule_id)"
536                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
537                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
538                         "   Set pool or vlan type mirror rule on a port.\n"
539                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
540                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
541                         " to pool 0.\n\n"
542
543                         "set port (port_id) mirror-rule (rule_id)"
544                         " (uplink-mirror|downlink-mirror) dst-pool"
545                         " (pool_id) (on|off)\n"
546                         "   Set uplink or downlink type mirror rule on a port.\n"
547                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
548                         " 0 on' enable mirror income traffic to pool 0.\n\n"
549
550                         "reset port (port_id) mirror-rule (rule_id)\n"
551                         "   Reset a mirror rule.\n\n"
552
553                         "set flush_rx (on|off)\n"
554                         "   Flush (default) or don't flush RX streams before"
555                         " forwarding. Mainly used with PCAP drivers.\n\n"
556
557                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
558                         "   Set the bypass mode for the lowest port on bypass enabled"
559                         " NIC.\n\n"
560
561                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
562                         "mode (normal|bypass|isolate) (port_id)\n"
563                         "   Set the event required to initiate specified bypass mode for"
564                         " the lowest port on a bypass enabled NIC where:\n"
565                         "       timeout   = enable bypass after watchdog timeout.\n"
566                         "       os_on     = enable bypass when OS/board is powered on.\n"
567                         "       os_off    = enable bypass when OS/board is powered off.\n"
568                         "       power_on  = enable bypass when power supply is turned on.\n"
569                         "       power_off = enable bypass when power supply is turned off."
570                         "\n\n"
571
572                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
573                         "   Set the bypass watchdog timeout to 'n' seconds"
574                         " where 0 = instant.\n\n"
575
576                         "show bypass config (port_id)\n"
577                         "   Show the bypass configuration for a bypass enabled NIC"
578                         " using the lowest port on the NIC.\n\n"
579
580 #ifdef RTE_LIBRTE_PMD_BOND
581                         "create bonded device (mode) (socket)\n"
582                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
583
584                         "add bonding slave (slave_id) (port_id)\n"
585                         "       Add a slave device to a bonded device.\n\n"
586
587                         "remove bonding slave (slave_id) (port_id)\n"
588                         "       Remove a slave device from a bonded device.\n\n"
589
590                         "set bonding mode (value) (port_id)\n"
591                         "       Set the bonding mode on a bonded device.\n\n"
592
593                         "set bonding primary (slave_id) (port_id)\n"
594                         "       Set the primary slave for a bonded device.\n\n"
595
596                         "show bonding config (port_id)\n"
597                         "       Show the bonding config for port_id.\n\n"
598
599                         "set bonding mac_addr (port_id) (address)\n"
600                         "       Set the MAC address of a bonded device.\n\n"
601
602                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
603                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
604
605                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
606                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
607
608                         "set bonding mon_period (port_id) (value)\n"
609                         "       Set the bonding link status monitoring polling period in ms.\n\n"
610
611                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
612                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
613
614 #endif
615                         "set link-up port (port_id)\n"
616                         "       Set link up for a port.\n\n"
617
618                         "set link-down port (port_id)\n"
619                         "       Set link down for a port.\n\n"
620
621                         "E-tag set insertion on port-tag-id (value)"
622                         " port (port_id) vf (vf_id)\n"
623                         "    Enable E-tag insertion for a VF on a port\n\n"
624
625                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
626                         "    Disable E-tag insertion for a VF on a port\n\n"
627
628                         "E-tag set stripping (on|off) port (port_id)\n"
629                         "    Enable/disable E-tag stripping on a port\n\n"
630
631                         "E-tag set forwarding (on|off) port (port_id)\n"
632                         "    Enable/disable E-tag based forwarding"
633                         " on a port\n\n"
634
635                         "E-tag set filter add e-tag-id (value) dst-pool"
636                         " (pool_id) port (port_id)\n"
637                         "    Add an E-tag forwarding filter on a port\n\n"
638
639                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
640                         "    Delete an E-tag forwarding filter on a port\n\n"
641
642 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
643                         "set port tm hierarchy default (port_id)\n"
644                         "       Set default traffic Management hierarchy on a port\n\n"
645
646 #endif
647                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
648                         "    Load a profile package on a port\n\n"
649
650                         "ddp del (port_id) (backup_profile_path)\n"
651                         "    Delete a profile package from a port\n\n"
652
653                         "ptype mapping get (port_id) (valid_only)\n"
654                         "    Get ptype mapping on a port\n\n"
655
656                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
657                         "    Replace target with the pkt_type in ptype mapping\n\n"
658
659                         "ptype mapping reset (port_id)\n"
660                         "    Reset ptype mapping on a port\n\n"
661
662                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
663                         "    Update a ptype mapping item on a port\n\n"
664
665                         "set port (port_id) queue-region region_id (value) "
666                         "queue_start_index (value) queue_num (value)\n"
667                         "    Set a queue region on a port\n\n"
668
669                         "set port (port_id) queue-region region_id (value) "
670                         "flowtype (value)\n"
671                         "    Set a flowtype region index on a port\n\n"
672
673                         "set port (port_id) queue-region UP (value) region_id (value)\n"
674                         "    Set the mapping of User Priority to "
675                         "queue region on a port\n\n"
676
677                         "set port (port_id) queue-region flush (on|off)\n"
678                         "    flush all queue region related configuration\n\n"
679
680                         "show port meter cap (port_id)\n"
681                         "    Show port meter capability information\n\n"
682
683                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
684                         "    meter profile add - srtcm rfc 2697\n\n"
685
686                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
687                         "    meter profile add - trtcm rfc 2698\n\n"
688
689                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
690                         "    meter profile add - trtcm rfc 4115\n\n"
691
692                         "del port meter profile (port_id) (profile_id)\n"
693                         "    meter profile delete\n\n"
694
695                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
696                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
697                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
698                         "(dscp_tbl_entry63)]\n"
699                         "    meter create\n\n"
700
701                         "enable port meter (port_id) (mtr_id)\n"
702                         "    meter enable\n\n"
703
704                         "disable port meter (port_id) (mtr_id)\n"
705                         "    meter disable\n\n"
706
707                         "del port meter (port_id) (mtr_id)\n"
708                         "    meter delete\n\n"
709
710                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
711                         "    meter update meter profile\n\n"
712
713                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
714                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
715                         "    update meter dscp table entries\n\n"
716
717                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
718                         "(action0) [(action1) (action2)]\n"
719                         "    meter update policer action\n\n"
720
721                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
722                         "    meter update stats\n\n"
723
724                         "show port (port_id) queue-region\n"
725                         "    show all queue region related configuration info\n\n"
726
727                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
728                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
729                         "       Add port tm node private shaper profile.\n\n"
730
731                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
732                         "       Delete port tm node private shaper profile.\n\n"
733
734                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
735                         " (shaper_profile_id)\n"
736                         "       Add/update port tm node shared shaper.\n\n"
737
738                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
739                         "       Delete port tm node shared shaper.\n\n"
740
741                         "set port tm node shaper profile (port_id) (node_id)"
742                         " (shaper_profile_id)\n"
743                         "       Set port tm node shaper profile.\n\n"
744
745                         "add port tm node wred profile (port_id) (wred_profile_id)"
746                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
747                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
748                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
749                         "       Add port tm node wred profile.\n\n"
750
751                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
752                         "       Delete port tm node wred profile.\n\n"
753
754                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
755                         " (priority) (weight) (level_id) (shaper_profile_id)"
756                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
757                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
758                         "       Add port tm nonleaf node.\n\n"
759
760                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
761                         " (priority) (weight) (level_id) (shaper_profile_id)"
762                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
763                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
764                         "       Add port tm leaf node.\n\n"
765
766                         "del port tm node (port_id) (node_id)\n"
767                         "       Delete port tm node.\n\n"
768
769                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
770                         " (priority) (weight)\n"
771                         "       Set port tm node parent.\n\n"
772
773                         "suspend port tm node (port_id) (node_id)"
774                         "       Suspend tm node.\n\n"
775
776                         "resume port tm node (port_id) (node_id)"
777                         "       Resume tm node.\n\n"
778
779                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
780                         "       Commit tm hierarchy.\n\n"
781
782                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
783                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
784                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
785                         "       Configure the VXLAN encapsulation for flows.\n\n"
786
787                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
788                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
789                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
790                         " eth-dst (eth-dst)\n"
791                         "       Configure the VXLAN encapsulation for flows.\n\n"
792
793                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
794                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
795                         " (eth-dst)\n"
796                         "       Configure the NVGRE encapsulation for flows.\n\n"
797
798                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
799                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
800                         " eth-src (eth-src) eth-dst (eth-dst)\n"
801                         "       Configure the NVGRE encapsulation for flows.\n\n"
802
803                         , list_pkt_forwarding_modes()
804                 );
805         }
806
807         if (show_all || !strcmp(res->section, "ports")) {
808
809                 cmdline_printf(
810                         cl,
811                         "\n"
812                         "Port Operations:\n"
813                         "----------------\n\n"
814
815                         "port start (port_id|all)\n"
816                         "    Start all ports or port_id.\n\n"
817
818                         "port stop (port_id|all)\n"
819                         "    Stop all ports or port_id.\n\n"
820
821                         "port close (port_id|all)\n"
822                         "    Close all ports or port_id.\n\n"
823
824                         "port attach (ident)\n"
825                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
826
827                         "port detach (port_id)\n"
828                         "    Detach physical or virtual dev by port_id\n\n"
829
830                         "port config (port_id|all)"
831                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
832                         " duplex (half|full|auto)\n"
833                         "    Set speed and duplex for all ports or port_id\n\n"
834
835                         "port config (port_id|all) loopback (mode)\n"
836                         "    Set loopback mode for all ports or port_id\n\n"
837
838                         "port config all (rxq|txq|rxd|txd) (value)\n"
839                         "    Set number for rxq/txq/rxd/txd.\n\n"
840
841                         "port config all max-pkt-len (value)\n"
842                         "    Set the max packet length.\n\n"
843
844                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
845                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
846                         " (on|off)\n"
847                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
848                         " for ports.\n\n"
849
850                         "port config all rss (all|default|ip|tcp|udp|sctp|"
851                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
852                         "    Set the RSS mode.\n\n"
853
854                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
855                         "    Set the RSS redirection table.\n\n"
856
857                         "port config (port_id) dcb vt (on|off) (traffic_class)"
858                         " pfc (on|off)\n"
859                         "    Set the DCB mode.\n\n"
860
861                         "port config all burst (value)\n"
862                         "    Set the number of packets per burst.\n\n"
863
864                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
865                         " (value)\n"
866                         "    Set the ring prefetch/host/writeback threshold"
867                         " for tx/rx queue.\n\n"
868
869                         "port config all (txfreet|txrst|rxfreet) (value)\n"
870                         "    Set free threshold for rx/tx, or set"
871                         " tx rs bit threshold.\n\n"
872                         "port config mtu X value\n"
873                         "    Set the MTU of port X to a given value\n\n"
874
875                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
876                         "    Set a rx/tx queue's ring size configuration, the new"
877                         " value will take effect after command that (re-)start the port"
878                         " or command that setup the specific queue\n\n"
879
880                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
881                         "    Start/stop a rx/tx queue of port X. Only take effect"
882                         " when port X is started\n\n"
883
884                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
885                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
886                         " take effect when port X is stopped.\n\n"
887
888                         "port (port_id) (rxq|txq) (queue_id) setup\n"
889                         "    Setup a rx/tx queue of port X.\n\n"
890
891                         "port config (port_id|all) l2-tunnel E-tag ether-type"
892                         " (value)\n"
893                         "    Set the value of E-tag ether-type.\n\n"
894
895                         "port config (port_id|all) l2-tunnel E-tag"
896                         " (enable|disable)\n"
897                         "    Enable/disable the E-tag support.\n\n"
898
899                         "port config (port_id) pctype mapping reset\n"
900                         "    Reset flow type to pctype mapping on a port\n\n"
901
902                         "port config (port_id) pctype mapping update"
903                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
904                         "    Update a flow type to pctype mapping item on a port\n\n"
905
906                         "port config (port_id) pctype (pctype_id) hash_inset|"
907                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
908                         " (field_idx)\n"
909                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
910
911                         "port config (port_id) pctype (pctype_id) hash_inset|"
912                         "fdir_inset|fdir_flx_inset clear all"
913                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
914
915                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
916                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
917                 );
918         }
919
920         if (show_all || !strcmp(res->section, "registers")) {
921
922                 cmdline_printf(
923                         cl,
924                         "\n"
925                         "Registers:\n"
926                         "----------\n\n"
927
928                         "read reg (port_id) (address)\n"
929                         "    Display value of a port register.\n\n"
930
931                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
932                         "    Display a port register bit field.\n\n"
933
934                         "read regbit (port_id) (address) (bit_x)\n"
935                         "    Display a single port register bit.\n\n"
936
937                         "write reg (port_id) (address) (value)\n"
938                         "    Set value of a port register.\n\n"
939
940                         "write regfield (port_id) (address) (bit_x) (bit_y)"
941                         " (value)\n"
942                         "    Set bit field of a port register.\n\n"
943
944                         "write regbit (port_id) (address) (bit_x) (value)\n"
945                         "    Set single bit value of a port register.\n\n"
946                 );
947         }
948         if (show_all || !strcmp(res->section, "filters")) {
949
950                 cmdline_printf(
951                         cl,
952                         "\n"
953                         "filters:\n"
954                         "--------\n\n"
955
956                         "ethertype_filter (port_id) (add|del)"
957                         " (mac_addr|mac_ignr) (mac_address) ethertype"
958                         " (ether_type) (drop|fwd) queue (queue_id)\n"
959                         "    Add/Del an ethertype filter.\n\n"
960
961                         "2tuple_filter (port_id) (add|del)"
962                         " dst_port (dst_port_value) protocol (protocol_value)"
963                         " mask (mask_value) tcp_flags (tcp_flags_value)"
964                         " priority (prio_value) queue (queue_id)\n"
965                         "    Add/Del a 2tuple filter.\n\n"
966
967                         "5tuple_filter (port_id) (add|del)"
968                         " dst_ip (dst_address) src_ip (src_address)"
969                         " dst_port (dst_port_value) src_port (src_port_value)"
970                         " protocol (protocol_value)"
971                         " mask (mask_value) tcp_flags (tcp_flags_value)"
972                         " priority (prio_value) queue (queue_id)\n"
973                         "    Add/Del a 5tuple filter.\n\n"
974
975                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
976                         "    Add/Del syn filter.\n\n"
977
978                         "flex_filter (port_id) (add|del) len (len_value)"
979                         " bytes (bytes_value) mask (mask_value)"
980                         " priority (prio_value) queue (queue_id)\n"
981                         "    Add/Del a flex filter.\n\n"
982
983                         "flow_director_filter (port_id) mode IP (add|del|update)"
984                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
985                         " src (src_ip_address) dst (dst_ip_address)"
986                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
987                         " vlan (vlan_value) flexbytes (flexbytes_value)"
988                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
989                         " fd_id (fd_id_value)\n"
990                         "    Add/Del an IP type flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode IP (add|del|update)"
993                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
994                         " src (src_ip_address) (src_port)"
995                         " dst (dst_ip_address) (dst_port)"
996                         " tos (tos_value) ttl (ttl_value)"
997                         " vlan (vlan_value) flexbytes (flexbytes_value)"
998                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
999                         " fd_id (fd_id_value)\n"
1000                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode IP (add|del|update)"
1003                         " flow (ipv4-sctp|ipv6-sctp)"
1004                         " src (src_ip_address) (src_port)"
1005                         " dst (dst_ip_address) (dst_port)"
1006                         " tag (verification_tag) "
1007                         " tos (tos_value) ttl (ttl_value)"
1008                         " vlan (vlan_value)"
1009                         " flexbytes (flexbytes_value) (drop|fwd)"
1010                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1011                         "    Add/Del a SCTP type flow director filter.\n\n"
1012
1013                         "flow_director_filter (port_id) mode IP (add|del|update)"
1014                         " flow l2_payload ether (ethertype)"
1015                         " flexbytes (flexbytes_value) (drop|fwd)"
1016                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1017                         "    Add/Del a l2 payload type flow director filter.\n\n"
1018
1019                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1020                         " mac (mac_address) vlan (vlan_value)"
1021                         " flexbytes (flexbytes_value) (drop|fwd)"
1022                         " queue (queue_id) fd_id (fd_id_value)\n"
1023                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1026                         " mac (mac_address) vlan (vlan_value)"
1027                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1028                         " flexbytes (flexbytes_value) (drop|fwd)"
1029                         " queue (queue_id) fd_id (fd_id_value)\n"
1030                         "    Add/Del a Tunnel flow director filter.\n\n"
1031
1032                         "flow_director_filter (port_id) mode raw (add|del|update)"
1033                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1034                         " fd_id (fd_id_value) packet (packet file name)\n"
1035                         "    Add/Del a raw type flow director filter.\n\n"
1036
1037                         "flush_flow_director (port_id)\n"
1038                         "    Flush all flow director entries of a device.\n\n"
1039
1040                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1041                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1042                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1043                         "    Set flow director IP mask.\n\n"
1044
1045                         "flow_director_mask (port_id) mode MAC-VLAN"
1046                         " vlan (vlan_value)\n"
1047                         "    Set flow director MAC-VLAN mask.\n\n"
1048
1049                         "flow_director_mask (port_id) mode Tunnel"
1050                         " vlan (vlan_value) mac (mac_value)"
1051                         " tunnel-type (tunnel_type_value)"
1052                         " tunnel-id (tunnel_id_value)\n"
1053                         "    Set flow director Tunnel mask.\n\n"
1054
1055                         "flow_director_flex_mask (port_id)"
1056                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1057                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1058                         " (mask)\n"
1059                         "    Configure mask of flex payload.\n\n"
1060
1061                         "flow_director_flex_payload (port_id)"
1062                         " (raw|l2|l3|l4) (config)\n"
1063                         "    Configure flex payload selection.\n\n"
1064
1065                         "get_sym_hash_ena_per_port (port_id)\n"
1066                         "    get symmetric hash enable configuration per port.\n\n"
1067
1068                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1069                         "    set symmetric hash enable configuration per port"
1070                         " to enable or disable.\n\n"
1071
1072                         "get_hash_global_config (port_id)\n"
1073                         "    Get the global configurations of hash filters.\n\n"
1074
1075                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1076                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1077                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1078                         " (enable|disable)\n"
1079                         "    Set the global configurations of hash filters.\n\n"
1080
1081                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1082                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1083                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1084                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1085                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1086                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1087                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1088                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1089                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1090                         "fld-8th|none) (select|add)\n"
1091                         "    Set the input set for hash.\n\n"
1092
1093                         "set_fdir_input_set (port_id) "
1094                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1095                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1096                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1097                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1098                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1099                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1100                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1101                         " (select|add)\n"
1102                         "    Set the input set for FDir.\n\n"
1103
1104                         "flow validate {port_id}"
1105                         " [group {group_id}] [priority {level}]"
1106                         " [ingress] [egress]"
1107                         " pattern {item} [/ {item} [...]] / end"
1108                         " actions {action} [/ {action} [...]] / end\n"
1109                         "    Check whether a flow rule can be created.\n\n"
1110
1111                         "flow create {port_id}"
1112                         " [group {group_id}] [priority {level}]"
1113                         " [ingress] [egress]"
1114                         " pattern {item} [/ {item} [...]] / end"
1115                         " actions {action} [/ {action} [...]] / end\n"
1116                         "    Create a flow rule.\n\n"
1117
1118                         "flow destroy {port_id} rule {rule_id} [...]\n"
1119                         "    Destroy specific flow rules.\n\n"
1120
1121                         "flow flush {port_id}\n"
1122                         "    Destroy all flow rules.\n\n"
1123
1124                         "flow query {port_id} {rule_id} {action}\n"
1125                         "    Query an existing flow rule.\n\n"
1126
1127                         "flow list {port_id} [group {group_id}] [...]\n"
1128                         "    List existing flow rules sorted by priority,"
1129                         " filtered by group identifiers.\n\n"
1130
1131                         "flow isolate {port_id} {boolean}\n"
1132                         "    Restrict ingress traffic to the defined"
1133                         " flow rules\n\n"
1134                 );
1135         }
1136 }
1137
1138 cmdline_parse_token_string_t cmd_help_long_help =
1139         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1140
1141 cmdline_parse_token_string_t cmd_help_long_section =
1142         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1143                         "all#control#display#config#"
1144                         "ports#registers#filters");
1145
1146 cmdline_parse_inst_t cmd_help_long = {
1147         .f = cmd_help_long_parsed,
1148         .data = NULL,
1149         .help_str = "help all|control|display|config|ports|register|filters: "
1150                 "Show help",
1151         .tokens = {
1152                 (void *)&cmd_help_long_help,
1153                 (void *)&cmd_help_long_section,
1154                 NULL,
1155         },
1156 };
1157
1158
1159 /* *** start/stop/close all ports *** */
1160 struct cmd_operate_port_result {
1161         cmdline_fixed_string_t keyword;
1162         cmdline_fixed_string_t name;
1163         cmdline_fixed_string_t value;
1164 };
1165
1166 static void cmd_operate_port_parsed(void *parsed_result,
1167                                 __attribute__((unused)) struct cmdline *cl,
1168                                 __attribute__((unused)) void *data)
1169 {
1170         struct cmd_operate_port_result *res = parsed_result;
1171
1172         if (!strcmp(res->name, "start"))
1173                 start_port(RTE_PORT_ALL);
1174         else if (!strcmp(res->name, "stop"))
1175                 stop_port(RTE_PORT_ALL);
1176         else if (!strcmp(res->name, "close"))
1177                 close_port(RTE_PORT_ALL);
1178         else if (!strcmp(res->name, "reset"))
1179                 reset_port(RTE_PORT_ALL);
1180         else
1181                 printf("Unknown parameter\n");
1182 }
1183
1184 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1185         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1186                                                                 "port");
1187 cmdline_parse_token_string_t cmd_operate_port_all_port =
1188         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1189                                                 "start#stop#close#reset");
1190 cmdline_parse_token_string_t cmd_operate_port_all_all =
1191         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1192
1193 cmdline_parse_inst_t cmd_operate_port = {
1194         .f = cmd_operate_port_parsed,
1195         .data = NULL,
1196         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1197         .tokens = {
1198                 (void *)&cmd_operate_port_all_cmd,
1199                 (void *)&cmd_operate_port_all_port,
1200                 (void *)&cmd_operate_port_all_all,
1201                 NULL,
1202         },
1203 };
1204
1205 /* *** start/stop/close specific port *** */
1206 struct cmd_operate_specific_port_result {
1207         cmdline_fixed_string_t keyword;
1208         cmdline_fixed_string_t name;
1209         uint8_t value;
1210 };
1211
1212 static void cmd_operate_specific_port_parsed(void *parsed_result,
1213                         __attribute__((unused)) struct cmdline *cl,
1214                                 __attribute__((unused)) void *data)
1215 {
1216         struct cmd_operate_specific_port_result *res = parsed_result;
1217
1218         if (!strcmp(res->name, "start"))
1219                 start_port(res->value);
1220         else if (!strcmp(res->name, "stop"))
1221                 stop_port(res->value);
1222         else if (!strcmp(res->name, "close"))
1223                 close_port(res->value);
1224         else if (!strcmp(res->name, "reset"))
1225                 reset_port(res->value);
1226         else
1227                 printf("Unknown parameter\n");
1228 }
1229
1230 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1231         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1232                                                         keyword, "port");
1233 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1235                                                 name, "start#stop#close#reset");
1236 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1237         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1238                                                         value, UINT8);
1239
1240 cmdline_parse_inst_t cmd_operate_specific_port = {
1241         .f = cmd_operate_specific_port_parsed,
1242         .data = NULL,
1243         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1244         .tokens = {
1245                 (void *)&cmd_operate_specific_port_cmd,
1246                 (void *)&cmd_operate_specific_port_port,
1247                 (void *)&cmd_operate_specific_port_id,
1248                 NULL,
1249         },
1250 };
1251
1252 /* *** attach a specified port *** */
1253 struct cmd_operate_attach_port_result {
1254         cmdline_fixed_string_t port;
1255         cmdline_fixed_string_t keyword;
1256         cmdline_fixed_string_t identifier;
1257 };
1258
1259 static void cmd_operate_attach_port_parsed(void *parsed_result,
1260                                 __attribute__((unused)) struct cmdline *cl,
1261                                 __attribute__((unused)) void *data)
1262 {
1263         struct cmd_operate_attach_port_result *res = parsed_result;
1264
1265         if (!strcmp(res->keyword, "attach"))
1266                 attach_port(res->identifier);
1267         else
1268                 printf("Unknown parameter\n");
1269 }
1270
1271 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1272         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1273                         port, "port");
1274 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1275         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1276                         keyword, "attach");
1277 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1278         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1279                         identifier, NULL);
1280
1281 cmdline_parse_inst_t cmd_operate_attach_port = {
1282         .f = cmd_operate_attach_port_parsed,
1283         .data = NULL,
1284         .help_str = "port attach <identifier>: "
1285                 "(identifier: pci address or virtual dev name)",
1286         .tokens = {
1287                 (void *)&cmd_operate_attach_port_port,
1288                 (void *)&cmd_operate_attach_port_keyword,
1289                 (void *)&cmd_operate_attach_port_identifier,
1290                 NULL,
1291         },
1292 };
1293
1294 /* *** detach a specified port *** */
1295 struct cmd_operate_detach_port_result {
1296         cmdline_fixed_string_t port;
1297         cmdline_fixed_string_t keyword;
1298         portid_t port_id;
1299 };
1300
1301 static void cmd_operate_detach_port_parsed(void *parsed_result,
1302                                 __attribute__((unused)) struct cmdline *cl,
1303                                 __attribute__((unused)) void *data)
1304 {
1305         struct cmd_operate_detach_port_result *res = parsed_result;
1306
1307         if (!strcmp(res->keyword, "detach"))
1308                 detach_port(res->port_id);
1309         else
1310                 printf("Unknown parameter\n");
1311 }
1312
1313 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1314         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1315                         port, "port");
1316 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1317         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1318                         keyword, "detach");
1319 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1320         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1321                         port_id, UINT16);
1322
1323 cmdline_parse_inst_t cmd_operate_detach_port = {
1324         .f = cmd_operate_detach_port_parsed,
1325         .data = NULL,
1326         .help_str = "port detach <port_id>",
1327         .tokens = {
1328                 (void *)&cmd_operate_detach_port_port,
1329                 (void *)&cmd_operate_detach_port_keyword,
1330                 (void *)&cmd_operate_detach_port_port_id,
1331                 NULL,
1332         },
1333 };
1334
1335 /* *** configure speed for all ports *** */
1336 struct cmd_config_speed_all {
1337         cmdline_fixed_string_t port;
1338         cmdline_fixed_string_t keyword;
1339         cmdline_fixed_string_t all;
1340         cmdline_fixed_string_t item1;
1341         cmdline_fixed_string_t item2;
1342         cmdline_fixed_string_t value1;
1343         cmdline_fixed_string_t value2;
1344 };
1345
1346 static int
1347 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1348 {
1349
1350         int duplex;
1351
1352         if (!strcmp(duplexstr, "half")) {
1353                 duplex = ETH_LINK_HALF_DUPLEX;
1354         } else if (!strcmp(duplexstr, "full")) {
1355                 duplex = ETH_LINK_FULL_DUPLEX;
1356         } else if (!strcmp(duplexstr, "auto")) {
1357                 duplex = ETH_LINK_FULL_DUPLEX;
1358         } else {
1359                 printf("Unknown duplex parameter\n");
1360                 return -1;
1361         }
1362
1363         if (!strcmp(speedstr, "10")) {
1364                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1365                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1366         } else if (!strcmp(speedstr, "100")) {
1367                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1368                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1369         } else {
1370                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1371                         printf("Invalid speed/duplex parameters\n");
1372                         return -1;
1373                 }
1374                 if (!strcmp(speedstr, "1000")) {
1375                         *speed = ETH_LINK_SPEED_1G;
1376                 } else if (!strcmp(speedstr, "10000")) {
1377                         *speed = ETH_LINK_SPEED_10G;
1378                 } else if (!strcmp(speedstr, "25000")) {
1379                         *speed = ETH_LINK_SPEED_25G;
1380                 } else if (!strcmp(speedstr, "40000")) {
1381                         *speed = ETH_LINK_SPEED_40G;
1382                 } else if (!strcmp(speedstr, "50000")) {
1383                         *speed = ETH_LINK_SPEED_50G;
1384                 } else if (!strcmp(speedstr, "100000")) {
1385                         *speed = ETH_LINK_SPEED_100G;
1386                 } else if (!strcmp(speedstr, "auto")) {
1387                         *speed = ETH_LINK_SPEED_AUTONEG;
1388                 } else {
1389                         printf("Unknown speed parameter\n");
1390                         return -1;
1391                 }
1392         }
1393
1394         return 0;
1395 }
1396
1397 static void
1398 cmd_config_speed_all_parsed(void *parsed_result,
1399                         __attribute__((unused)) struct cmdline *cl,
1400                         __attribute__((unused)) void *data)
1401 {
1402         struct cmd_config_speed_all *res = parsed_result;
1403         uint32_t link_speed;
1404         portid_t pid;
1405
1406         if (!all_ports_stopped()) {
1407                 printf("Please stop all ports first\n");
1408                 return;
1409         }
1410
1411         if (parse_and_check_speed_duplex(res->value1, res->value2,
1412                         &link_speed) < 0)
1413                 return;
1414
1415         RTE_ETH_FOREACH_DEV(pid) {
1416                 ports[pid].dev_conf.link_speeds = link_speed;
1417         }
1418
1419         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1420 }
1421
1422 cmdline_parse_token_string_t cmd_config_speed_all_port =
1423         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1424 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1425         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1426                                                         "config");
1427 cmdline_parse_token_string_t cmd_config_speed_all_all =
1428         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1429 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1430         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1431 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1432         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1433                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1434 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1435         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1436 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1437         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1438                                                 "half#full#auto");
1439
1440 cmdline_parse_inst_t cmd_config_speed_all = {
1441         .f = cmd_config_speed_all_parsed,
1442         .data = NULL,
1443         .help_str = "port config all speed "
1444                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1445                                                         "half|full|auto",
1446         .tokens = {
1447                 (void *)&cmd_config_speed_all_port,
1448                 (void *)&cmd_config_speed_all_keyword,
1449                 (void *)&cmd_config_speed_all_all,
1450                 (void *)&cmd_config_speed_all_item1,
1451                 (void *)&cmd_config_speed_all_value1,
1452                 (void *)&cmd_config_speed_all_item2,
1453                 (void *)&cmd_config_speed_all_value2,
1454                 NULL,
1455         },
1456 };
1457
1458 /* *** configure speed for specific port *** */
1459 struct cmd_config_speed_specific {
1460         cmdline_fixed_string_t port;
1461         cmdline_fixed_string_t keyword;
1462         portid_t id;
1463         cmdline_fixed_string_t item1;
1464         cmdline_fixed_string_t item2;
1465         cmdline_fixed_string_t value1;
1466         cmdline_fixed_string_t value2;
1467 };
1468
1469 static void
1470 cmd_config_speed_specific_parsed(void *parsed_result,
1471                                 __attribute__((unused)) struct cmdline *cl,
1472                                 __attribute__((unused)) void *data)
1473 {
1474         struct cmd_config_speed_specific *res = parsed_result;
1475         uint32_t link_speed;
1476
1477         if (!all_ports_stopped()) {
1478                 printf("Please stop all ports first\n");
1479                 return;
1480         }
1481
1482         if (port_id_is_invalid(res->id, ENABLED_WARN))
1483                 return;
1484
1485         if (parse_and_check_speed_duplex(res->value1, res->value2,
1486                         &link_speed) < 0)
1487                 return;
1488
1489         ports[res->id].dev_conf.link_speeds = link_speed;
1490
1491         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1492 }
1493
1494
1495 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1496         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1497                                                                 "port");
1498 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1499         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1500                                                                 "config");
1501 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1502         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1503 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1504         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1505                                                                 "speed");
1506 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1507         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1508                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1509 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1510         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1511                                                                 "duplex");
1512 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1513         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1514                                                         "half#full#auto");
1515
1516 cmdline_parse_inst_t cmd_config_speed_specific = {
1517         .f = cmd_config_speed_specific_parsed,
1518         .data = NULL,
1519         .help_str = "port config <port_id> speed "
1520                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1521                                                         "half|full|auto",
1522         .tokens = {
1523                 (void *)&cmd_config_speed_specific_port,
1524                 (void *)&cmd_config_speed_specific_keyword,
1525                 (void *)&cmd_config_speed_specific_id,
1526                 (void *)&cmd_config_speed_specific_item1,
1527                 (void *)&cmd_config_speed_specific_value1,
1528                 (void *)&cmd_config_speed_specific_item2,
1529                 (void *)&cmd_config_speed_specific_value2,
1530                 NULL,
1531         },
1532 };
1533
1534 /* *** configure loopback for all ports *** */
1535 struct cmd_config_loopback_all {
1536         cmdline_fixed_string_t port;
1537         cmdline_fixed_string_t keyword;
1538         cmdline_fixed_string_t all;
1539         cmdline_fixed_string_t item;
1540         uint32_t mode;
1541 };
1542
1543 static void
1544 cmd_config_loopback_all_parsed(void *parsed_result,
1545                         __attribute__((unused)) struct cmdline *cl,
1546                         __attribute__((unused)) void *data)
1547 {
1548         struct cmd_config_loopback_all *res = parsed_result;
1549         portid_t pid;
1550
1551         if (!all_ports_stopped()) {
1552                 printf("Please stop all ports first\n");
1553                 return;
1554         }
1555
1556         RTE_ETH_FOREACH_DEV(pid) {
1557                 ports[pid].dev_conf.lpbk_mode = res->mode;
1558         }
1559
1560         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1561 }
1562
1563 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1565 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1566         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1567                                                         "config");
1568 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1569         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1570 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1572                                                         "loopback");
1573 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1574         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1575
1576 cmdline_parse_inst_t cmd_config_loopback_all = {
1577         .f = cmd_config_loopback_all_parsed,
1578         .data = NULL,
1579         .help_str = "port config all loopback <mode>",
1580         .tokens = {
1581                 (void *)&cmd_config_loopback_all_port,
1582                 (void *)&cmd_config_loopback_all_keyword,
1583                 (void *)&cmd_config_loopback_all_all,
1584                 (void *)&cmd_config_loopback_all_item,
1585                 (void *)&cmd_config_loopback_all_mode,
1586                 NULL,
1587         },
1588 };
1589
1590 /* *** configure loopback for specific port *** */
1591 struct cmd_config_loopback_specific {
1592         cmdline_fixed_string_t port;
1593         cmdline_fixed_string_t keyword;
1594         uint16_t port_id;
1595         cmdline_fixed_string_t item;
1596         uint32_t mode;
1597 };
1598
1599 static void
1600 cmd_config_loopback_specific_parsed(void *parsed_result,
1601                                 __attribute__((unused)) struct cmdline *cl,
1602                                 __attribute__((unused)) void *data)
1603 {
1604         struct cmd_config_loopback_specific *res = parsed_result;
1605
1606         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1607                 return;
1608
1609         if (!port_is_stopped(res->port_id)) {
1610                 printf("Please stop port %u first\n", res->port_id);
1611                 return;
1612         }
1613
1614         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1615
1616         cmd_reconfig_device_queue(res->port_id, 1, 1);
1617 }
1618
1619
1620 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1621         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1622                                                                 "port");
1623 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1624         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1625                                                                 "config");
1626 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1627         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1628                                                                 UINT16);
1629 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1630         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1631                                                                 "loopback");
1632 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1633         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1634                               UINT32);
1635
1636 cmdline_parse_inst_t cmd_config_loopback_specific = {
1637         .f = cmd_config_loopback_specific_parsed,
1638         .data = NULL,
1639         .help_str = "port config <port_id> loopback <mode>",
1640         .tokens = {
1641                 (void *)&cmd_config_loopback_specific_port,
1642                 (void *)&cmd_config_loopback_specific_keyword,
1643                 (void *)&cmd_config_loopback_specific_id,
1644                 (void *)&cmd_config_loopback_specific_item,
1645                 (void *)&cmd_config_loopback_specific_mode,
1646                 NULL,
1647         },
1648 };
1649
1650 /* *** configure txq/rxq, txd/rxd *** */
1651 struct cmd_config_rx_tx {
1652         cmdline_fixed_string_t port;
1653         cmdline_fixed_string_t keyword;
1654         cmdline_fixed_string_t all;
1655         cmdline_fixed_string_t name;
1656         uint16_t value;
1657 };
1658
1659 static void
1660 cmd_config_rx_tx_parsed(void *parsed_result,
1661                         __attribute__((unused)) struct cmdline *cl,
1662                         __attribute__((unused)) void *data)
1663 {
1664         struct cmd_config_rx_tx *res = parsed_result;
1665
1666         if (!all_ports_stopped()) {
1667                 printf("Please stop all ports first\n");
1668                 return;
1669         }
1670         if (!strcmp(res->name, "rxq")) {
1671                 if (!res->value && !nb_txq) {
1672                         printf("Warning: Either rx or tx queues should be non zero\n");
1673                         return;
1674                 }
1675                 if (check_nb_rxq(res->value) != 0)
1676                         return;
1677                 nb_rxq = res->value;
1678         }
1679         else if (!strcmp(res->name, "txq")) {
1680                 if (!res->value && !nb_rxq) {
1681                         printf("Warning: Either rx or tx queues should be non zero\n");
1682                         return;
1683                 }
1684                 if (check_nb_txq(res->value) != 0)
1685                         return;
1686                 nb_txq = res->value;
1687         }
1688         else if (!strcmp(res->name, "rxd")) {
1689                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1690                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1691                                         res->value, RTE_TEST_RX_DESC_MAX);
1692                         return;
1693                 }
1694                 nb_rxd = res->value;
1695         } else if (!strcmp(res->name, "txd")) {
1696                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1697                         printf("txd %d invalid - must be > 0 && <= %d\n",
1698                                         res->value, RTE_TEST_TX_DESC_MAX);
1699                         return;
1700                 }
1701                 nb_txd = res->value;
1702         } else {
1703                 printf("Unknown parameter\n");
1704                 return;
1705         }
1706
1707         fwd_config_setup();
1708
1709         init_port_config();
1710
1711         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1712 }
1713
1714 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1716 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1717         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1718 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1719         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1720 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1722                                                 "rxq#txq#rxd#txd");
1723 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1724         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1725
1726 cmdline_parse_inst_t cmd_config_rx_tx = {
1727         .f = cmd_config_rx_tx_parsed,
1728         .data = NULL,
1729         .help_str = "port config all rxq|txq|rxd|txd <value>",
1730         .tokens = {
1731                 (void *)&cmd_config_rx_tx_port,
1732                 (void *)&cmd_config_rx_tx_keyword,
1733                 (void *)&cmd_config_rx_tx_all,
1734                 (void *)&cmd_config_rx_tx_name,
1735                 (void *)&cmd_config_rx_tx_value,
1736                 NULL,
1737         },
1738 };
1739
1740 /* *** config max packet length *** */
1741 struct cmd_config_max_pkt_len_result {
1742         cmdline_fixed_string_t port;
1743         cmdline_fixed_string_t keyword;
1744         cmdline_fixed_string_t all;
1745         cmdline_fixed_string_t name;
1746         uint32_t value;
1747 };
1748
1749 static void
1750 cmd_config_max_pkt_len_parsed(void *parsed_result,
1751                                 __attribute__((unused)) struct cmdline *cl,
1752                                 __attribute__((unused)) void *data)
1753 {
1754         struct cmd_config_max_pkt_len_result *res = parsed_result;
1755         portid_t pid;
1756
1757         if (!all_ports_stopped()) {
1758                 printf("Please stop all ports first\n");
1759                 return;
1760         }
1761
1762         RTE_ETH_FOREACH_DEV(pid) {
1763                 struct rte_port *port = &ports[pid];
1764                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1765
1766                 if (!strcmp(res->name, "max-pkt-len")) {
1767                         if (res->value < ETHER_MIN_LEN) {
1768                                 printf("max-pkt-len can not be less than %d\n",
1769                                                 ETHER_MIN_LEN);
1770                                 return;
1771                         }
1772                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1773                                 return;
1774
1775                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1776                         if (res->value > ETHER_MAX_LEN)
1777                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1778                         else
1779                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1780                         port->dev_conf.rxmode.offloads = rx_offloads;
1781                 } else {
1782                         printf("Unknown parameter\n");
1783                         return;
1784                 }
1785         }
1786
1787         init_port_config();
1788
1789         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1790 }
1791
1792 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1794                                                                 "port");
1795 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1796         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1797                                                                 "config");
1798 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1799         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1800                                                                 "all");
1801 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1802         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1803                                                                 "max-pkt-len");
1804 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1805         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1806                                                                 UINT32);
1807
1808 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1809         .f = cmd_config_max_pkt_len_parsed,
1810         .data = NULL,
1811         .help_str = "port config all max-pkt-len <value>",
1812         .tokens = {
1813                 (void *)&cmd_config_max_pkt_len_port,
1814                 (void *)&cmd_config_max_pkt_len_keyword,
1815                 (void *)&cmd_config_max_pkt_len_all,
1816                 (void *)&cmd_config_max_pkt_len_name,
1817                 (void *)&cmd_config_max_pkt_len_value,
1818                 NULL,
1819         },
1820 };
1821
1822 /* *** configure port MTU *** */
1823 struct cmd_config_mtu_result {
1824         cmdline_fixed_string_t port;
1825         cmdline_fixed_string_t keyword;
1826         cmdline_fixed_string_t mtu;
1827         portid_t port_id;
1828         uint16_t value;
1829 };
1830
1831 static void
1832 cmd_config_mtu_parsed(void *parsed_result,
1833                       __attribute__((unused)) struct cmdline *cl,
1834                       __attribute__((unused)) void *data)
1835 {
1836         struct cmd_config_mtu_result *res = parsed_result;
1837
1838         if (res->value < ETHER_MIN_LEN) {
1839                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1840                 return;
1841         }
1842         port_mtu_set(res->port_id, res->value);
1843 }
1844
1845 cmdline_parse_token_string_t cmd_config_mtu_port =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1847                                  "port");
1848 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1850                                  "config");
1851 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1853                                  "mtu");
1854 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1855         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1856 cmdline_parse_token_num_t cmd_config_mtu_value =
1857         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1858
1859 cmdline_parse_inst_t cmd_config_mtu = {
1860         .f = cmd_config_mtu_parsed,
1861         .data = NULL,
1862         .help_str = "port config mtu <port_id> <value>",
1863         .tokens = {
1864                 (void *)&cmd_config_mtu_port,
1865                 (void *)&cmd_config_mtu_keyword,
1866                 (void *)&cmd_config_mtu_mtu,
1867                 (void *)&cmd_config_mtu_port_id,
1868                 (void *)&cmd_config_mtu_value,
1869                 NULL,
1870         },
1871 };
1872
1873 /* *** configure rx mode *** */
1874 struct cmd_config_rx_mode_flag {
1875         cmdline_fixed_string_t port;
1876         cmdline_fixed_string_t keyword;
1877         cmdline_fixed_string_t all;
1878         cmdline_fixed_string_t name;
1879         cmdline_fixed_string_t value;
1880 };
1881
1882 static void
1883 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1884                                 __attribute__((unused)) struct cmdline *cl,
1885                                 __attribute__((unused)) void *data)
1886 {
1887         struct cmd_config_rx_mode_flag *res = parsed_result;
1888         portid_t pid;
1889
1890         if (!all_ports_stopped()) {
1891                 printf("Please stop all ports first\n");
1892                 return;
1893         }
1894
1895         RTE_ETH_FOREACH_DEV(pid) {
1896                 struct rte_port *port;
1897                 uint64_t rx_offloads;
1898
1899                 port = &ports[pid];
1900                 rx_offloads = port->dev_conf.rxmode.offloads;
1901                 if (!strcmp(res->name, "crc-strip")) {
1902                         if (!strcmp(res->value, "on")) {
1903                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
1904                         } else if (!strcmp(res->value, "off")) {
1905                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
1906                         } else {
1907                                 printf("Unknown parameter\n");
1908                                 return;
1909                         }
1910                 } else if (!strcmp(res->name, "scatter")) {
1911                         if (!strcmp(res->value, "on")) {
1912                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1913                         } else if (!strcmp(res->value, "off")) {
1914                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1915                         } else {
1916                                 printf("Unknown parameter\n");
1917                                 return;
1918                         }
1919                 } else if (!strcmp(res->name, "rx-cksum")) {
1920                         if (!strcmp(res->value, "on"))
1921                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1922                         else if (!strcmp(res->value, "off"))
1923                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1924                         else {
1925                                 printf("Unknown parameter\n");
1926                                 return;
1927                         }
1928                 } else if (!strcmp(res->name, "rx-timestamp")) {
1929                         if (!strcmp(res->value, "on"))
1930                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1931                         else if (!strcmp(res->value, "off"))
1932                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1933                         else {
1934                                 printf("Unknown parameter\n");
1935                                 return;
1936                         }
1937                 } else if (!strcmp(res->name, "hw-vlan")) {
1938                         if (!strcmp(res->value, "on")) {
1939                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1940                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1941                         } else if (!strcmp(res->value, "off")) {
1942                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1943                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1944                         } else {
1945                                 printf("Unknown parameter\n");
1946                                 return;
1947                         }
1948                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1949                         if (!strcmp(res->value, "on"))
1950                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1951                         else if (!strcmp(res->value, "off"))
1952                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1953                         else {
1954                                 printf("Unknown parameter\n");
1955                                 return;
1956                         }
1957                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1958                         if (!strcmp(res->value, "on"))
1959                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1960                         else if (!strcmp(res->value, "off"))
1961                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1962                         else {
1963                                 printf("Unknown parameter\n");
1964                                 return;
1965                         }
1966                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1967                         if (!strcmp(res->value, "on"))
1968                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1969                         else if (!strcmp(res->value, "off"))
1970                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1971                         else {
1972                                 printf("Unknown parameter\n");
1973                                 return;
1974                         }
1975                 } else if (!strcmp(res->name, "drop-en")) {
1976                         if (!strcmp(res->value, "on"))
1977                                 rx_drop_en = 1;
1978                         else if (!strcmp(res->value, "off"))
1979                                 rx_drop_en = 0;
1980                         else {
1981                                 printf("Unknown parameter\n");
1982                                 return;
1983                         }
1984                 } else {
1985                         printf("Unknown parameter\n");
1986                         return;
1987                 }
1988                 port->dev_conf.rxmode.offloads = rx_offloads;
1989         }
1990
1991         init_port_config();
1992
1993         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1994 }
1995
1996 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1997         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1998 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1999         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2000                                                                 "config");
2001 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2002         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2003 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2004         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2005                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2006                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2007 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2008         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2009                                                         "on#off");
2010
2011 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2012         .f = cmd_config_rx_mode_flag_parsed,
2013         .data = NULL,
2014         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2015                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2016         .tokens = {
2017                 (void *)&cmd_config_rx_mode_flag_port,
2018                 (void *)&cmd_config_rx_mode_flag_keyword,
2019                 (void *)&cmd_config_rx_mode_flag_all,
2020                 (void *)&cmd_config_rx_mode_flag_name,
2021                 (void *)&cmd_config_rx_mode_flag_value,
2022                 NULL,
2023         },
2024 };
2025
2026 /* *** configure rss *** */
2027 struct cmd_config_rss {
2028         cmdline_fixed_string_t port;
2029         cmdline_fixed_string_t keyword;
2030         cmdline_fixed_string_t all;
2031         cmdline_fixed_string_t name;
2032         cmdline_fixed_string_t value;
2033 };
2034
2035 static void
2036 cmd_config_rss_parsed(void *parsed_result,
2037                         __attribute__((unused)) struct cmdline *cl,
2038                         __attribute__((unused)) void *data)
2039 {
2040         struct cmd_config_rss *res = parsed_result;
2041         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2042         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2043         int use_default = 0;
2044         int all_updated = 1;
2045         int diag;
2046         uint16_t i;
2047
2048         if (!strcmp(res->value, "all"))
2049                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2050                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2051                                         ETH_RSS_L2_PAYLOAD;
2052         else if (!strcmp(res->value, "ip"))
2053                 rss_conf.rss_hf = ETH_RSS_IP;
2054         else if (!strcmp(res->value, "udp"))
2055                 rss_conf.rss_hf = ETH_RSS_UDP;
2056         else if (!strcmp(res->value, "tcp"))
2057                 rss_conf.rss_hf = ETH_RSS_TCP;
2058         else if (!strcmp(res->value, "sctp"))
2059                 rss_conf.rss_hf = ETH_RSS_SCTP;
2060         else if (!strcmp(res->value, "ether"))
2061                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2062         else if (!strcmp(res->value, "port"))
2063                 rss_conf.rss_hf = ETH_RSS_PORT;
2064         else if (!strcmp(res->value, "vxlan"))
2065                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2066         else if (!strcmp(res->value, "geneve"))
2067                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2068         else if (!strcmp(res->value, "nvgre"))
2069                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2070         else if (!strcmp(res->value, "none"))
2071                 rss_conf.rss_hf = 0;
2072         else if (!strcmp(res->value, "default"))
2073                 use_default = 1;
2074         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2075                                                 atoi(res->value) < 64)
2076                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2077         else {
2078                 printf("Unknown parameter\n");
2079                 return;
2080         }
2081         rss_conf.rss_key = NULL;
2082         /* Update global configuration for RSS types. */
2083         RTE_ETH_FOREACH_DEV(i) {
2084                 struct rte_eth_rss_conf local_rss_conf;
2085
2086                 rte_eth_dev_info_get(i, &dev_info);
2087                 if (use_default)
2088                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2089
2090                 local_rss_conf = rss_conf;
2091                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2092                         dev_info.flow_type_rss_offloads;
2093                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2094                         printf("Port %u modified RSS hash function based on hardware support,"
2095                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2096                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2097                 }
2098                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2099                 if (diag < 0) {
2100                         all_updated = 0;
2101                         printf("Configuration of RSS hash at ethernet port %d "
2102                                 "failed with error (%d): %s.\n",
2103                                 i, -diag, strerror(-diag));
2104                 }
2105         }
2106         if (all_updated && !use_default)
2107                 rss_hf = rss_conf.rss_hf;
2108 }
2109
2110 cmdline_parse_token_string_t cmd_config_rss_port =
2111         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2112 cmdline_parse_token_string_t cmd_config_rss_keyword =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2114 cmdline_parse_token_string_t cmd_config_rss_all =
2115         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2116 cmdline_parse_token_string_t cmd_config_rss_name =
2117         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2118 cmdline_parse_token_string_t cmd_config_rss_value =
2119         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2120
2121 cmdline_parse_inst_t cmd_config_rss = {
2122         .f = cmd_config_rss_parsed,
2123         .data = NULL,
2124         .help_str = "port config all rss "
2125                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2126         .tokens = {
2127                 (void *)&cmd_config_rss_port,
2128                 (void *)&cmd_config_rss_keyword,
2129                 (void *)&cmd_config_rss_all,
2130                 (void *)&cmd_config_rss_name,
2131                 (void *)&cmd_config_rss_value,
2132                 NULL,
2133         },
2134 };
2135
2136 /* *** configure rss hash key *** */
2137 struct cmd_config_rss_hash_key {
2138         cmdline_fixed_string_t port;
2139         cmdline_fixed_string_t config;
2140         portid_t port_id;
2141         cmdline_fixed_string_t rss_hash_key;
2142         cmdline_fixed_string_t rss_type;
2143         cmdline_fixed_string_t key;
2144 };
2145
2146 static uint8_t
2147 hexa_digit_to_value(char hexa_digit)
2148 {
2149         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2150                 return (uint8_t) (hexa_digit - '0');
2151         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2152                 return (uint8_t) ((hexa_digit - 'a') + 10);
2153         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2154                 return (uint8_t) ((hexa_digit - 'A') + 10);
2155         /* Invalid hexa digit */
2156         return 0xFF;
2157 }
2158
2159 static uint8_t
2160 parse_and_check_key_hexa_digit(char *key, int idx)
2161 {
2162         uint8_t hexa_v;
2163
2164         hexa_v = hexa_digit_to_value(key[idx]);
2165         if (hexa_v == 0xFF)
2166                 printf("invalid key: character %c at position %d is not a "
2167                        "valid hexa digit\n", key[idx], idx);
2168         return hexa_v;
2169 }
2170
2171 static void
2172 cmd_config_rss_hash_key_parsed(void *parsed_result,
2173                                __attribute__((unused)) struct cmdline *cl,
2174                                __attribute__((unused)) void *data)
2175 {
2176         struct cmd_config_rss_hash_key *res = parsed_result;
2177         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2178         uint8_t xdgt0;
2179         uint8_t xdgt1;
2180         int i;
2181         struct rte_eth_dev_info dev_info;
2182         uint8_t hash_key_size;
2183         uint32_t key_len;
2184
2185         memset(&dev_info, 0, sizeof(dev_info));
2186         rte_eth_dev_info_get(res->port_id, &dev_info);
2187         if (dev_info.hash_key_size > 0 &&
2188                         dev_info.hash_key_size <= sizeof(hash_key))
2189                 hash_key_size = dev_info.hash_key_size;
2190         else {
2191                 printf("dev_info did not provide a valid hash key size\n");
2192                 return;
2193         }
2194         /* Check the length of the RSS hash key */
2195         key_len = strlen(res->key);
2196         if (key_len != (hash_key_size * 2)) {
2197                 printf("key length: %d invalid - key must be a string of %d"
2198                            " hexa-decimal numbers\n",
2199                            (int) key_len, hash_key_size * 2);
2200                 return;
2201         }
2202         /* Translate RSS hash key into binary representation */
2203         for (i = 0; i < hash_key_size; i++) {
2204                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2205                 if (xdgt0 == 0xFF)
2206                         return;
2207                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2208                 if (xdgt1 == 0xFF)
2209                         return;
2210                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2211         }
2212         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2213                         hash_key_size);
2214 }
2215
2216 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2217         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2218 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2219         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2220                                  "config");
2221 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2222         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2223 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2225                                  rss_hash_key, "rss-hash-key");
2226 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2227         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2228                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2229                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2230                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2231                                  "ipv6-tcp-ex#ipv6-udp-ex");
2232 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2233         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2234
2235 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2236         .f = cmd_config_rss_hash_key_parsed,
2237         .data = NULL,
2238         .help_str = "port config <port_id> rss-hash-key "
2239                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2240                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2241                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2242                 "<string of hex digits (variable length, NIC dependent)>",
2243         .tokens = {
2244                 (void *)&cmd_config_rss_hash_key_port,
2245                 (void *)&cmd_config_rss_hash_key_config,
2246                 (void *)&cmd_config_rss_hash_key_port_id,
2247                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2248                 (void *)&cmd_config_rss_hash_key_rss_type,
2249                 (void *)&cmd_config_rss_hash_key_value,
2250                 NULL,
2251         },
2252 };
2253
2254 /* *** configure port rxq/txq ring size *** */
2255 struct cmd_config_rxtx_ring_size {
2256         cmdline_fixed_string_t port;
2257         cmdline_fixed_string_t config;
2258         portid_t portid;
2259         cmdline_fixed_string_t rxtxq;
2260         uint16_t qid;
2261         cmdline_fixed_string_t rsize;
2262         uint16_t size;
2263 };
2264
2265 static void
2266 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2267                                  __attribute__((unused)) struct cmdline *cl,
2268                                  __attribute__((unused)) void *data)
2269 {
2270         struct cmd_config_rxtx_ring_size *res = parsed_result;
2271         struct rte_port *port;
2272         uint8_t isrx;
2273
2274         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2275                 return;
2276
2277         if (res->portid == (portid_t)RTE_PORT_ALL) {
2278                 printf("Invalid port id\n");
2279                 return;
2280         }
2281
2282         port = &ports[res->portid];
2283
2284         if (!strcmp(res->rxtxq, "rxq"))
2285                 isrx = 1;
2286         else if (!strcmp(res->rxtxq, "txq"))
2287                 isrx = 0;
2288         else {
2289                 printf("Unknown parameter\n");
2290                 return;
2291         }
2292
2293         if (isrx && rx_queue_id_is_invalid(res->qid))
2294                 return;
2295         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2296                 return;
2297
2298         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2299                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2300                        rx_free_thresh);
2301                 return;
2302         }
2303
2304         if (isrx)
2305                 port->nb_rx_desc[res->qid] = res->size;
2306         else
2307                 port->nb_tx_desc[res->qid] = res->size;
2308
2309         cmd_reconfig_device_queue(res->portid, 0, 1);
2310 }
2311
2312 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2313         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2314                                  port, "port");
2315 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2316         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2317                                  config, "config");
2318 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2319         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2320                                  portid, UINT16);
2321 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2322         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2323                                  rxtxq, "rxq#txq");
2324 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2325         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2326                               qid, UINT16);
2327 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2328         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2329                                  rsize, "ring_size");
2330 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2331         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2332                               size, UINT16);
2333
2334 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2335         .f = cmd_config_rxtx_ring_size_parsed,
2336         .data = NULL,
2337         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2338         .tokens = {
2339                 (void *)&cmd_config_rxtx_ring_size_port,
2340                 (void *)&cmd_config_rxtx_ring_size_config,
2341                 (void *)&cmd_config_rxtx_ring_size_portid,
2342                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2343                 (void *)&cmd_config_rxtx_ring_size_qid,
2344                 (void *)&cmd_config_rxtx_ring_size_rsize,
2345                 (void *)&cmd_config_rxtx_ring_size_size,
2346                 NULL,
2347         },
2348 };
2349
2350 /* *** configure port rxq/txq start/stop *** */
2351 struct cmd_config_rxtx_queue {
2352         cmdline_fixed_string_t port;
2353         portid_t portid;
2354         cmdline_fixed_string_t rxtxq;
2355         uint16_t qid;
2356         cmdline_fixed_string_t opname;
2357 };
2358
2359 static void
2360 cmd_config_rxtx_queue_parsed(void *parsed_result,
2361                         __attribute__((unused)) struct cmdline *cl,
2362                         __attribute__((unused)) void *data)
2363 {
2364         struct cmd_config_rxtx_queue *res = parsed_result;
2365         uint8_t isrx;
2366         uint8_t isstart;
2367         int ret = 0;
2368
2369         if (test_done == 0) {
2370                 printf("Please stop forwarding first\n");
2371                 return;
2372         }
2373
2374         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2375                 return;
2376
2377         if (port_is_started(res->portid) != 1) {
2378                 printf("Please start port %u first\n", res->portid);
2379                 return;
2380         }
2381
2382         if (!strcmp(res->rxtxq, "rxq"))
2383                 isrx = 1;
2384         else if (!strcmp(res->rxtxq, "txq"))
2385                 isrx = 0;
2386         else {
2387                 printf("Unknown parameter\n");
2388                 return;
2389         }
2390
2391         if (isrx && rx_queue_id_is_invalid(res->qid))
2392                 return;
2393         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2394                 return;
2395
2396         if (!strcmp(res->opname, "start"))
2397                 isstart = 1;
2398         else if (!strcmp(res->opname, "stop"))
2399                 isstart = 0;
2400         else {
2401                 printf("Unknown parameter\n");
2402                 return;
2403         }
2404
2405         if (isstart && isrx)
2406                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2407         else if (!isstart && isrx)
2408                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2409         else if (isstart && !isrx)
2410                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2411         else
2412                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2413
2414         if (ret == -ENOTSUP)
2415                 printf("Function not supported in PMD driver\n");
2416 }
2417
2418 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2420 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2421         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2422 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2423         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2424 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2425         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2426 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2427         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2428                                                 "start#stop");
2429
2430 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2431         .f = cmd_config_rxtx_queue_parsed,
2432         .data = NULL,
2433         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2434         .tokens = {
2435                 (void *)&cmd_config_rxtx_queue_port,
2436                 (void *)&cmd_config_rxtx_queue_portid,
2437                 (void *)&cmd_config_rxtx_queue_rxtxq,
2438                 (void *)&cmd_config_rxtx_queue_qid,
2439                 (void *)&cmd_config_rxtx_queue_opname,
2440                 NULL,
2441         },
2442 };
2443
2444 /* *** configure port rxq/txq deferred start on/off *** */
2445 struct cmd_config_deferred_start_rxtx_queue {
2446         cmdline_fixed_string_t port;
2447         portid_t port_id;
2448         cmdline_fixed_string_t rxtxq;
2449         uint16_t qid;
2450         cmdline_fixed_string_t opname;
2451         cmdline_fixed_string_t state;
2452 };
2453
2454 static void
2455 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2456                         __attribute__((unused)) struct cmdline *cl,
2457                         __attribute__((unused)) void *data)
2458 {
2459         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2460         struct rte_port *port;
2461         uint8_t isrx;
2462         uint8_t ison;
2463         uint8_t needreconfig = 0;
2464
2465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2466                 return;
2467
2468         if (port_is_started(res->port_id) != 0) {
2469                 printf("Please stop port %u first\n", res->port_id);
2470                 return;
2471         }
2472
2473         port = &ports[res->port_id];
2474
2475         isrx = !strcmp(res->rxtxq, "rxq");
2476
2477         if (isrx && rx_queue_id_is_invalid(res->qid))
2478                 return;
2479         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2480                 return;
2481
2482         ison = !strcmp(res->state, "on");
2483
2484         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2485                 port->rx_conf[res->qid].rx_deferred_start = ison;
2486                 needreconfig = 1;
2487         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2488                 port->tx_conf[res->qid].tx_deferred_start = ison;
2489                 needreconfig = 1;
2490         }
2491
2492         if (needreconfig)
2493                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2494 }
2495
2496 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2497         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2498                                                 port, "port");
2499 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2500         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2501                                                 port_id, UINT16);
2502 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2503         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2504                                                 rxtxq, "rxq#txq");
2505 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2506         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2507                                                 qid, UINT16);
2508 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2509         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2510                                                 opname, "deferred_start");
2511 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2512         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2513                                                 state, "on#off");
2514
2515 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2516         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2517         .data = NULL,
2518         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2519         .tokens = {
2520                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2521                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2522                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2523                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2524                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2525                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2526                 NULL,
2527         },
2528 };
2529
2530 /* *** configure port rxq/txq setup *** */
2531 struct cmd_setup_rxtx_queue {
2532         cmdline_fixed_string_t port;
2533         portid_t portid;
2534         cmdline_fixed_string_t rxtxq;
2535         uint16_t qid;
2536         cmdline_fixed_string_t setup;
2537 };
2538
2539 /* Common CLI fields for queue setup */
2540 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2541         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2542 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2543         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2544 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2545         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2546 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2547         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2548 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2549         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2550
2551 static void
2552 cmd_setup_rxtx_queue_parsed(
2553         void *parsed_result,
2554         __attribute__((unused)) struct cmdline *cl,
2555         __attribute__((unused)) void *data)
2556 {
2557         struct cmd_setup_rxtx_queue *res = parsed_result;
2558         struct rte_port *port;
2559         struct rte_mempool *mp;
2560         unsigned int socket_id;
2561         uint8_t isrx = 0;
2562         int ret;
2563
2564         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2565                 return;
2566
2567         if (res->portid == (portid_t)RTE_PORT_ALL) {
2568                 printf("Invalid port id\n");
2569                 return;
2570         }
2571
2572         if (!strcmp(res->rxtxq, "rxq"))
2573                 isrx = 1;
2574         else if (!strcmp(res->rxtxq, "txq"))
2575                 isrx = 0;
2576         else {
2577                 printf("Unknown parameter\n");
2578                 return;
2579         }
2580
2581         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2582                 printf("Invalid rx queue\n");
2583                 return;
2584         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2585                 printf("Invalid tx queue\n");
2586                 return;
2587         }
2588
2589         port = &ports[res->portid];
2590         if (isrx) {
2591                 socket_id = rxring_numa[res->portid];
2592                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2593                         socket_id = port->socket_id;
2594
2595                 mp = mbuf_pool_find(socket_id);
2596                 if (mp == NULL) {
2597                         printf("Failed to setup RX queue: "
2598                                 "No mempool allocation"
2599                                 " on the socket %d\n",
2600                                 rxring_numa[res->portid]);
2601                         return;
2602                 }
2603                 ret = rte_eth_rx_queue_setup(res->portid,
2604                                              res->qid,
2605                                              port->nb_rx_desc[res->qid],
2606                                              socket_id,
2607                                              &port->rx_conf[res->qid],
2608                                              mp);
2609                 if (ret)
2610                         printf("Failed to setup RX queue\n");
2611         } else {
2612                 socket_id = txring_numa[res->portid];
2613                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2614                         socket_id = port->socket_id;
2615
2616                 ret = rte_eth_tx_queue_setup(res->portid,
2617                                              res->qid,
2618                                              port->nb_tx_desc[res->qid],
2619                                              socket_id,
2620                                              &port->tx_conf[res->qid]);
2621                 if (ret)
2622                         printf("Failed to setup TX queue\n");
2623         }
2624 }
2625
2626 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2627         .f = cmd_setup_rxtx_queue_parsed,
2628         .data = NULL,
2629         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2630         .tokens = {
2631                 (void *)&cmd_setup_rxtx_queue_port,
2632                 (void *)&cmd_setup_rxtx_queue_portid,
2633                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2634                 (void *)&cmd_setup_rxtx_queue_qid,
2635                 (void *)&cmd_setup_rxtx_queue_setup,
2636                 NULL,
2637         },
2638 };
2639
2640
2641 /* *** Configure RSS RETA *** */
2642 struct cmd_config_rss_reta {
2643         cmdline_fixed_string_t port;
2644         cmdline_fixed_string_t keyword;
2645         portid_t port_id;
2646         cmdline_fixed_string_t name;
2647         cmdline_fixed_string_t list_name;
2648         cmdline_fixed_string_t list_of_items;
2649 };
2650
2651 static int
2652 parse_reta_config(const char *str,
2653                   struct rte_eth_rss_reta_entry64 *reta_conf,
2654                   uint16_t nb_entries)
2655 {
2656         int i;
2657         unsigned size;
2658         uint16_t hash_index, idx, shift;
2659         uint16_t nb_queue;
2660         char s[256];
2661         const char *p, *p0 = str;
2662         char *end;
2663         enum fieldnames {
2664                 FLD_HASH_INDEX = 0,
2665                 FLD_QUEUE,
2666                 _NUM_FLD
2667         };
2668         unsigned long int_fld[_NUM_FLD];
2669         char *str_fld[_NUM_FLD];
2670
2671         while ((p = strchr(p0,'(')) != NULL) {
2672                 ++p;
2673                 if((p0 = strchr(p,')')) == NULL)
2674                         return -1;
2675
2676                 size = p0 - p;
2677                 if(size >= sizeof(s))
2678                         return -1;
2679
2680                 snprintf(s, sizeof(s), "%.*s", size, p);
2681                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2682                         return -1;
2683                 for (i = 0; i < _NUM_FLD; i++) {
2684                         errno = 0;
2685                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2686                         if (errno != 0 || end == str_fld[i] ||
2687                                         int_fld[i] > 65535)
2688                                 return -1;
2689                 }
2690
2691                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2692                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2693
2694                 if (hash_index >= nb_entries) {
2695                         printf("Invalid RETA hash index=%d\n", hash_index);
2696                         return -1;
2697                 }
2698
2699                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2700                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2701                 reta_conf[idx].mask |= (1ULL << shift);
2702                 reta_conf[idx].reta[shift] = nb_queue;
2703         }
2704
2705         return 0;
2706 }
2707
2708 static void
2709 cmd_set_rss_reta_parsed(void *parsed_result,
2710                         __attribute__((unused)) struct cmdline *cl,
2711                         __attribute__((unused)) void *data)
2712 {
2713         int ret;
2714         struct rte_eth_dev_info dev_info;
2715         struct rte_eth_rss_reta_entry64 reta_conf[8];
2716         struct cmd_config_rss_reta *res = parsed_result;
2717
2718         memset(&dev_info, 0, sizeof(dev_info));
2719         rte_eth_dev_info_get(res->port_id, &dev_info);
2720         if (dev_info.reta_size == 0) {
2721                 printf("Redirection table size is 0 which is "
2722                                         "invalid for RSS\n");
2723                 return;
2724         } else
2725                 printf("The reta size of port %d is %u\n",
2726                         res->port_id, dev_info.reta_size);
2727         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2728                 printf("Currently do not support more than %u entries of "
2729                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2730                 return;
2731         }
2732
2733         memset(reta_conf, 0, sizeof(reta_conf));
2734         if (!strcmp(res->list_name, "reta")) {
2735                 if (parse_reta_config(res->list_of_items, reta_conf,
2736                                                 dev_info.reta_size)) {
2737                         printf("Invalid RSS Redirection Table "
2738                                         "config entered\n");
2739                         return;
2740                 }
2741                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2742                                 reta_conf, dev_info.reta_size);
2743                 if (ret != 0)
2744                         printf("Bad redirection table parameter, "
2745                                         "return code = %d \n", ret);
2746         }
2747 }
2748
2749 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2750         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2751 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2752         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2753 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2754         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2755 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2756         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2757 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2758         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2759 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2760         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2761                                  NULL);
2762 cmdline_parse_inst_t cmd_config_rss_reta = {
2763         .f = cmd_set_rss_reta_parsed,
2764         .data = NULL,
2765         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2766         .tokens = {
2767                 (void *)&cmd_config_rss_reta_port,
2768                 (void *)&cmd_config_rss_reta_keyword,
2769                 (void *)&cmd_config_rss_reta_port_id,
2770                 (void *)&cmd_config_rss_reta_name,
2771                 (void *)&cmd_config_rss_reta_list_name,
2772                 (void *)&cmd_config_rss_reta_list_of_items,
2773                 NULL,
2774         },
2775 };
2776
2777 /* *** SHOW PORT RETA INFO *** */
2778 struct cmd_showport_reta {
2779         cmdline_fixed_string_t show;
2780         cmdline_fixed_string_t port;
2781         portid_t port_id;
2782         cmdline_fixed_string_t rss;
2783         cmdline_fixed_string_t reta;
2784         uint16_t size;
2785         cmdline_fixed_string_t list_of_items;
2786 };
2787
2788 static int
2789 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2790                            uint16_t nb_entries,
2791                            char *str)
2792 {
2793         uint32_t size;
2794         const char *p, *p0 = str;
2795         char s[256];
2796         char *end;
2797         char *str_fld[8];
2798         uint16_t i;
2799         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2800                         RTE_RETA_GROUP_SIZE;
2801         int ret;
2802
2803         p = strchr(p0, '(');
2804         if (p == NULL)
2805                 return -1;
2806         p++;
2807         p0 = strchr(p, ')');
2808         if (p0 == NULL)
2809                 return -1;
2810         size = p0 - p;
2811         if (size >= sizeof(s)) {
2812                 printf("The string size exceeds the internal buffer size\n");
2813                 return -1;
2814         }
2815         snprintf(s, sizeof(s), "%.*s", size, p);
2816         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2817         if (ret <= 0 || ret != num) {
2818                 printf("The bits of masks do not match the number of "
2819                                         "reta entries: %u\n", num);
2820                 return -1;
2821         }
2822         for (i = 0; i < ret; i++)
2823                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2824
2825         return 0;
2826 }
2827
2828 static void
2829 cmd_showport_reta_parsed(void *parsed_result,
2830                          __attribute__((unused)) struct cmdline *cl,
2831                          __attribute__((unused)) void *data)
2832 {
2833         struct cmd_showport_reta *res = parsed_result;
2834         struct rte_eth_rss_reta_entry64 reta_conf[8];
2835         struct rte_eth_dev_info dev_info;
2836         uint16_t max_reta_size;
2837
2838         memset(&dev_info, 0, sizeof(dev_info));
2839         rte_eth_dev_info_get(res->port_id, &dev_info);
2840         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2841         if (res->size == 0 || res->size > max_reta_size) {
2842                 printf("Invalid redirection table size: %u (1-%u)\n",
2843                         res->size, max_reta_size);
2844                 return;
2845         }
2846
2847         memset(reta_conf, 0, sizeof(reta_conf));
2848         if (showport_parse_reta_config(reta_conf, res->size,
2849                                 res->list_of_items) < 0) {
2850                 printf("Invalid string: %s for reta masks\n",
2851                                         res->list_of_items);
2852                 return;
2853         }
2854         port_rss_reta_info(res->port_id, reta_conf, res->size);
2855 }
2856
2857 cmdline_parse_token_string_t cmd_showport_reta_show =
2858         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2859 cmdline_parse_token_string_t cmd_showport_reta_port =
2860         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2861 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2862         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2863 cmdline_parse_token_string_t cmd_showport_reta_rss =
2864         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2865 cmdline_parse_token_string_t cmd_showport_reta_reta =
2866         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2867 cmdline_parse_token_num_t cmd_showport_reta_size =
2868         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2869 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2870         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2871                                         list_of_items, NULL);
2872
2873 cmdline_parse_inst_t cmd_showport_reta = {
2874         .f = cmd_showport_reta_parsed,
2875         .data = NULL,
2876         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2877         .tokens = {
2878                 (void *)&cmd_showport_reta_show,
2879                 (void *)&cmd_showport_reta_port,
2880                 (void *)&cmd_showport_reta_port_id,
2881                 (void *)&cmd_showport_reta_rss,
2882                 (void *)&cmd_showport_reta_reta,
2883                 (void *)&cmd_showport_reta_size,
2884                 (void *)&cmd_showport_reta_list_of_items,
2885                 NULL,
2886         },
2887 };
2888
2889 /* *** Show RSS hash configuration *** */
2890 struct cmd_showport_rss_hash {
2891         cmdline_fixed_string_t show;
2892         cmdline_fixed_string_t port;
2893         portid_t port_id;
2894         cmdline_fixed_string_t rss_hash;
2895         cmdline_fixed_string_t rss_type;
2896         cmdline_fixed_string_t key; /* optional argument */
2897 };
2898
2899 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2900                                 __attribute__((unused)) struct cmdline *cl,
2901                                 void *show_rss_key)
2902 {
2903         struct cmd_showport_rss_hash *res = parsed_result;
2904
2905         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
2906 }
2907
2908 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2909         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2910 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2911         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2912 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2913         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2914 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2915         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2916                                  "rss-hash");
2917 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2918         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2919
2920 cmdline_parse_inst_t cmd_showport_rss_hash = {
2921         .f = cmd_showport_rss_hash_parsed,
2922         .data = NULL,
2923         .help_str = "show port <port_id> rss-hash",
2924         .tokens = {
2925                 (void *)&cmd_showport_rss_hash_show,
2926                 (void *)&cmd_showport_rss_hash_port,
2927                 (void *)&cmd_showport_rss_hash_port_id,
2928                 (void *)&cmd_showport_rss_hash_rss_hash,
2929                 NULL,
2930         },
2931 };
2932
2933 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2934         .f = cmd_showport_rss_hash_parsed,
2935         .data = (void *)1,
2936         .help_str = "show port <port_id> rss-hash key",
2937         .tokens = {
2938                 (void *)&cmd_showport_rss_hash_show,
2939                 (void *)&cmd_showport_rss_hash_port,
2940                 (void *)&cmd_showport_rss_hash_port_id,
2941                 (void *)&cmd_showport_rss_hash_rss_hash,
2942                 (void *)&cmd_showport_rss_hash_rss_key,
2943                 NULL,
2944         },
2945 };
2946
2947 /* *** Configure DCB *** */
2948 struct cmd_config_dcb {
2949         cmdline_fixed_string_t port;
2950         cmdline_fixed_string_t config;
2951         portid_t port_id;
2952         cmdline_fixed_string_t dcb;
2953         cmdline_fixed_string_t vt;
2954         cmdline_fixed_string_t vt_en;
2955         uint8_t num_tcs;
2956         cmdline_fixed_string_t pfc;
2957         cmdline_fixed_string_t pfc_en;
2958 };
2959
2960 static void
2961 cmd_config_dcb_parsed(void *parsed_result,
2962                         __attribute__((unused)) struct cmdline *cl,
2963                         __attribute__((unused)) void *data)
2964 {
2965         struct cmd_config_dcb *res = parsed_result;
2966         portid_t port_id = res->port_id;
2967         struct rte_port *port;
2968         uint8_t pfc_en;
2969         int ret;
2970
2971         port = &ports[port_id];
2972         /** Check if the port is not started **/
2973         if (port->port_status != RTE_PORT_STOPPED) {
2974                 printf("Please stop port %d first\n", port_id);
2975                 return;
2976         }
2977
2978         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2979                 printf("The invalid number of traffic class,"
2980                         " only 4 or 8 allowed.\n");
2981                 return;
2982         }
2983
2984         if (nb_fwd_lcores < res->num_tcs) {
2985                 printf("nb_cores shouldn't be less than number of TCs.\n");
2986                 return;
2987         }
2988         if (!strncmp(res->pfc_en, "on", 2))
2989                 pfc_en = 1;
2990         else
2991                 pfc_en = 0;
2992
2993         /* DCB in VT mode */
2994         if (!strncmp(res->vt_en, "on", 2))
2995                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2996                                 (enum rte_eth_nb_tcs)res->num_tcs,
2997                                 pfc_en);
2998         else
2999                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3000                                 (enum rte_eth_nb_tcs)res->num_tcs,
3001                                 pfc_en);
3002
3003
3004         if (ret != 0) {
3005                 printf("Cannot initialize network ports.\n");
3006                 return;
3007         }
3008
3009         cmd_reconfig_device_queue(port_id, 1, 1);
3010 }
3011
3012 cmdline_parse_token_string_t cmd_config_dcb_port =
3013         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3014 cmdline_parse_token_string_t cmd_config_dcb_config =
3015         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3016 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3017         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3018 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3019         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3020 cmdline_parse_token_string_t cmd_config_dcb_vt =
3021         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3022 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3023         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3024 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3025         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3026 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3027         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3028 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3029         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3030
3031 cmdline_parse_inst_t cmd_config_dcb = {
3032         .f = cmd_config_dcb_parsed,
3033         .data = NULL,
3034         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3035         .tokens = {
3036                 (void *)&cmd_config_dcb_port,
3037                 (void *)&cmd_config_dcb_config,
3038                 (void *)&cmd_config_dcb_port_id,
3039                 (void *)&cmd_config_dcb_dcb,
3040                 (void *)&cmd_config_dcb_vt,
3041                 (void *)&cmd_config_dcb_vt_en,
3042                 (void *)&cmd_config_dcb_num_tcs,
3043                 (void *)&cmd_config_dcb_pfc,
3044                 (void *)&cmd_config_dcb_pfc_en,
3045                 NULL,
3046         },
3047 };
3048
3049 /* *** configure number of packets per burst *** */
3050 struct cmd_config_burst {
3051         cmdline_fixed_string_t port;
3052         cmdline_fixed_string_t keyword;
3053         cmdline_fixed_string_t all;
3054         cmdline_fixed_string_t name;
3055         uint16_t value;
3056 };
3057
3058 static void
3059 cmd_config_burst_parsed(void *parsed_result,
3060                         __attribute__((unused)) struct cmdline *cl,
3061                         __attribute__((unused)) void *data)
3062 {
3063         struct cmd_config_burst *res = parsed_result;
3064         struct rte_eth_dev_info dev_info;
3065         uint16_t rec_nb_pkts;
3066
3067         if (!all_ports_stopped()) {
3068                 printf("Please stop all ports first\n");
3069                 return;
3070         }
3071
3072         if (!strcmp(res->name, "burst")) {
3073                 if (res->value == 0) {
3074                         /* If user gives a value of zero, query the PMD for
3075                          * its recommended Rx burst size. Testpmd uses a single
3076                          * size for all ports, so assume all ports are the same
3077                          * NIC model and use the values from Port 0.
3078                          */
3079                         rte_eth_dev_info_get(0, &dev_info);
3080                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3081
3082                         if (rec_nb_pkts == 0) {
3083                                 printf("PMD does not recommend a burst size.\n"
3084                                         "User provided value must be between"
3085                                         " 1 and %d\n", MAX_PKT_BURST);
3086                                 return;
3087                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3088                                 printf("PMD recommended burst size of %d"
3089                                         " exceeds maximum value of %d\n",
3090                                         rec_nb_pkts, MAX_PKT_BURST);
3091                                 return;
3092                         }
3093                         printf("Using PMD-provided burst value of %d\n",
3094                                 rec_nb_pkts);
3095                         nb_pkt_per_burst = rec_nb_pkts;
3096                 } else if (res->value > MAX_PKT_BURST) {
3097                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3098                         return;
3099                 } else
3100                         nb_pkt_per_burst = res->value;
3101         } else {
3102                 printf("Unknown parameter\n");
3103                 return;
3104         }
3105
3106         init_port_config();
3107
3108         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3109 }
3110
3111 cmdline_parse_token_string_t cmd_config_burst_port =
3112         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3113 cmdline_parse_token_string_t cmd_config_burst_keyword =
3114         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3115 cmdline_parse_token_string_t cmd_config_burst_all =
3116         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3117 cmdline_parse_token_string_t cmd_config_burst_name =
3118         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3119 cmdline_parse_token_num_t cmd_config_burst_value =
3120         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3121
3122 cmdline_parse_inst_t cmd_config_burst = {
3123         .f = cmd_config_burst_parsed,
3124         .data = NULL,
3125         .help_str = "port config all burst <value>",
3126         .tokens = {
3127                 (void *)&cmd_config_burst_port,
3128                 (void *)&cmd_config_burst_keyword,
3129                 (void *)&cmd_config_burst_all,
3130                 (void *)&cmd_config_burst_name,
3131                 (void *)&cmd_config_burst_value,
3132                 NULL,
3133         },
3134 };
3135
3136 /* *** configure rx/tx queues *** */
3137 struct cmd_config_thresh {
3138         cmdline_fixed_string_t port;
3139         cmdline_fixed_string_t keyword;
3140         cmdline_fixed_string_t all;
3141         cmdline_fixed_string_t name;
3142         uint8_t value;
3143 };
3144
3145 static void
3146 cmd_config_thresh_parsed(void *parsed_result,
3147                         __attribute__((unused)) struct cmdline *cl,
3148                         __attribute__((unused)) void *data)
3149 {
3150         struct cmd_config_thresh *res = parsed_result;
3151
3152         if (!all_ports_stopped()) {
3153                 printf("Please stop all ports first\n");
3154                 return;
3155         }
3156
3157         if (!strcmp(res->name, "txpt"))
3158                 tx_pthresh = res->value;
3159         else if(!strcmp(res->name, "txht"))
3160                 tx_hthresh = res->value;
3161         else if(!strcmp(res->name, "txwt"))
3162                 tx_wthresh = res->value;
3163         else if(!strcmp(res->name, "rxpt"))
3164                 rx_pthresh = res->value;
3165         else if(!strcmp(res->name, "rxht"))
3166                 rx_hthresh = res->value;
3167         else if(!strcmp(res->name, "rxwt"))
3168                 rx_wthresh = res->value;
3169         else {
3170                 printf("Unknown parameter\n");
3171                 return;
3172         }
3173
3174         init_port_config();
3175
3176         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3177 }
3178
3179 cmdline_parse_token_string_t cmd_config_thresh_port =
3180         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3181 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3182         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3183 cmdline_parse_token_string_t cmd_config_thresh_all =
3184         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3185 cmdline_parse_token_string_t cmd_config_thresh_name =
3186         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3187                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3188 cmdline_parse_token_num_t cmd_config_thresh_value =
3189         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3190
3191 cmdline_parse_inst_t cmd_config_thresh = {
3192         .f = cmd_config_thresh_parsed,
3193         .data = NULL,
3194         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3195         .tokens = {
3196                 (void *)&cmd_config_thresh_port,
3197                 (void *)&cmd_config_thresh_keyword,
3198                 (void *)&cmd_config_thresh_all,
3199                 (void *)&cmd_config_thresh_name,
3200                 (void *)&cmd_config_thresh_value,
3201                 NULL,
3202         },
3203 };
3204
3205 /* *** configure free/rs threshold *** */
3206 struct cmd_config_threshold {
3207         cmdline_fixed_string_t port;
3208         cmdline_fixed_string_t keyword;
3209         cmdline_fixed_string_t all;
3210         cmdline_fixed_string_t name;
3211         uint16_t value;
3212 };
3213
3214 static void
3215 cmd_config_threshold_parsed(void *parsed_result,
3216                         __attribute__((unused)) struct cmdline *cl,
3217                         __attribute__((unused)) void *data)
3218 {
3219         struct cmd_config_threshold *res = parsed_result;
3220
3221         if (!all_ports_stopped()) {
3222                 printf("Please stop all ports first\n");
3223                 return;
3224         }
3225
3226         if (!strcmp(res->name, "txfreet"))
3227                 tx_free_thresh = res->value;
3228         else if (!strcmp(res->name, "txrst"))
3229                 tx_rs_thresh = res->value;
3230         else if (!strcmp(res->name, "rxfreet"))
3231                 rx_free_thresh = res->value;
3232         else {
3233                 printf("Unknown parameter\n");
3234                 return;
3235         }
3236
3237         init_port_config();
3238
3239         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3240 }
3241
3242 cmdline_parse_token_string_t cmd_config_threshold_port =
3243         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3244 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3245         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3246                                                                 "config");
3247 cmdline_parse_token_string_t cmd_config_threshold_all =
3248         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3249 cmdline_parse_token_string_t cmd_config_threshold_name =
3250         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3251                                                 "txfreet#txrst#rxfreet");
3252 cmdline_parse_token_num_t cmd_config_threshold_value =
3253         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3254
3255 cmdline_parse_inst_t cmd_config_threshold = {
3256         .f = cmd_config_threshold_parsed,
3257         .data = NULL,
3258         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3259         .tokens = {
3260                 (void *)&cmd_config_threshold_port,
3261                 (void *)&cmd_config_threshold_keyword,
3262                 (void *)&cmd_config_threshold_all,
3263                 (void *)&cmd_config_threshold_name,
3264                 (void *)&cmd_config_threshold_value,
3265                 NULL,
3266         },
3267 };
3268
3269 /* *** stop *** */
3270 struct cmd_stop_result {
3271         cmdline_fixed_string_t stop;
3272 };
3273
3274 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3275                             __attribute__((unused)) struct cmdline *cl,
3276                             __attribute__((unused)) void *data)
3277 {
3278         stop_packet_forwarding();
3279 }
3280
3281 cmdline_parse_token_string_t cmd_stop_stop =
3282         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3283
3284 cmdline_parse_inst_t cmd_stop = {
3285         .f = cmd_stop_parsed,
3286         .data = NULL,
3287         .help_str = "stop: Stop packet forwarding",
3288         .tokens = {
3289                 (void *)&cmd_stop_stop,
3290                 NULL,
3291         },
3292 };
3293
3294 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3295
3296 unsigned int
3297 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3298                 unsigned int *parsed_items, int check_unique_values)
3299 {
3300         unsigned int nb_item;
3301         unsigned int value;
3302         unsigned int i;
3303         unsigned int j;
3304         int value_ok;
3305         char c;
3306
3307         /*
3308          * First parse all items in the list and store their value.
3309          */
3310         value = 0;
3311         nb_item = 0;
3312         value_ok = 0;
3313         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3314                 c = str[i];
3315                 if ((c >= '0') && (c <= '9')) {
3316                         value = (unsigned int) (value * 10 + (c - '0'));
3317                         value_ok = 1;
3318                         continue;
3319                 }
3320                 if (c != ',') {
3321                         printf("character %c is not a decimal digit\n", c);
3322                         return 0;
3323                 }
3324                 if (! value_ok) {
3325                         printf("No valid value before comma\n");
3326                         return 0;
3327                 }
3328                 if (nb_item < max_items) {
3329                         parsed_items[nb_item] = value;
3330                         value_ok = 0;
3331                         value = 0;
3332                 }
3333                 nb_item++;
3334         }
3335         if (nb_item >= max_items) {
3336                 printf("Number of %s = %u > %u (maximum items)\n",
3337                        item_name, nb_item + 1, max_items);
3338                 return 0;
3339         }
3340         parsed_items[nb_item++] = value;
3341         if (! check_unique_values)
3342                 return nb_item;
3343
3344         /*
3345          * Then, check that all values in the list are differents.
3346          * No optimization here...
3347          */
3348         for (i = 0; i < nb_item; i++) {
3349                 for (j = i + 1; j < nb_item; j++) {
3350                         if (parsed_items[j] == parsed_items[i]) {
3351                                 printf("duplicated %s %u at index %u and %u\n",
3352                                        item_name, parsed_items[i], i, j);
3353                                 return 0;
3354                         }
3355                 }
3356         }
3357         return nb_item;
3358 }
3359
3360 struct cmd_set_list_result {
3361         cmdline_fixed_string_t cmd_keyword;
3362         cmdline_fixed_string_t list_name;
3363         cmdline_fixed_string_t list_of_items;
3364 };
3365
3366 static void cmd_set_list_parsed(void *parsed_result,
3367                                 __attribute__((unused)) struct cmdline *cl,
3368                                 __attribute__((unused)) void *data)
3369 {
3370         struct cmd_set_list_result *res;
3371         union {
3372                 unsigned int lcorelist[RTE_MAX_LCORE];
3373                 unsigned int portlist[RTE_MAX_ETHPORTS];
3374         } parsed_items;
3375         unsigned int nb_item;
3376
3377         if (test_done == 0) {
3378                 printf("Please stop forwarding first\n");
3379                 return;
3380         }
3381
3382         res = parsed_result;
3383         if (!strcmp(res->list_name, "corelist")) {
3384                 nb_item = parse_item_list(res->list_of_items, "core",
3385                                           RTE_MAX_LCORE,
3386                                           parsed_items.lcorelist, 1);
3387                 if (nb_item > 0) {
3388                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3389                         fwd_config_setup();
3390                 }
3391                 return;
3392         }
3393         if (!strcmp(res->list_name, "portlist")) {
3394                 nb_item = parse_item_list(res->list_of_items, "port",
3395                                           RTE_MAX_ETHPORTS,
3396                                           parsed_items.portlist, 1);
3397                 if (nb_item > 0) {
3398                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3399                         fwd_config_setup();
3400                 }
3401         }
3402 }
3403
3404 cmdline_parse_token_string_t cmd_set_list_keyword =
3405         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3406                                  "set");
3407 cmdline_parse_token_string_t cmd_set_list_name =
3408         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3409                                  "corelist#portlist");
3410 cmdline_parse_token_string_t cmd_set_list_of_items =
3411         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3412                                  NULL);
3413
3414 cmdline_parse_inst_t cmd_set_fwd_list = {
3415         .f = cmd_set_list_parsed,
3416         .data = NULL,
3417         .help_str = "set corelist|portlist <list0[,list1]*>",
3418         .tokens = {
3419                 (void *)&cmd_set_list_keyword,
3420                 (void *)&cmd_set_list_name,
3421                 (void *)&cmd_set_list_of_items,
3422                 NULL,
3423         },
3424 };
3425
3426 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3427
3428 struct cmd_setmask_result {
3429         cmdline_fixed_string_t set;
3430         cmdline_fixed_string_t mask;
3431         uint64_t hexavalue;
3432 };
3433
3434 static void cmd_set_mask_parsed(void *parsed_result,
3435                                 __attribute__((unused)) struct cmdline *cl,
3436                                 __attribute__((unused)) void *data)
3437 {
3438         struct cmd_setmask_result *res = parsed_result;
3439
3440         if (test_done == 0) {
3441                 printf("Please stop forwarding first\n");
3442                 return;
3443         }
3444         if (!strcmp(res->mask, "coremask")) {
3445                 set_fwd_lcores_mask(res->hexavalue);
3446                 fwd_config_setup();
3447         } else if (!strcmp(res->mask, "portmask")) {
3448                 set_fwd_ports_mask(res->hexavalue);
3449                 fwd_config_setup();
3450         }
3451 }
3452
3453 cmdline_parse_token_string_t cmd_setmask_set =
3454         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3455 cmdline_parse_token_string_t cmd_setmask_mask =
3456         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3457                                  "coremask#portmask");
3458 cmdline_parse_token_num_t cmd_setmask_value =
3459         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3460
3461 cmdline_parse_inst_t cmd_set_fwd_mask = {
3462         .f = cmd_set_mask_parsed,
3463         .data = NULL,
3464         .help_str = "set coremask|portmask <hexadecimal value>",
3465         .tokens = {
3466                 (void *)&cmd_setmask_set,
3467                 (void *)&cmd_setmask_mask,
3468                 (void *)&cmd_setmask_value,
3469                 NULL,
3470         },
3471 };
3472
3473 /*
3474  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3475  */
3476 struct cmd_set_result {
3477         cmdline_fixed_string_t set;
3478         cmdline_fixed_string_t what;
3479         uint16_t value;
3480 };
3481
3482 static void cmd_set_parsed(void *parsed_result,
3483                            __attribute__((unused)) struct cmdline *cl,
3484                            __attribute__((unused)) void *data)
3485 {
3486         struct cmd_set_result *res = parsed_result;
3487         if (!strcmp(res->what, "nbport")) {
3488                 set_fwd_ports_number(res->value);
3489                 fwd_config_setup();
3490         } else if (!strcmp(res->what, "nbcore")) {
3491                 set_fwd_lcores_number(res->value);
3492                 fwd_config_setup();
3493         } else if (!strcmp(res->what, "burst"))
3494                 set_nb_pkt_per_burst(res->value);
3495         else if (!strcmp(res->what, "verbose"))
3496                 set_verbose_level(res->value);
3497 }
3498
3499 cmdline_parse_token_string_t cmd_set_set =
3500         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3501 cmdline_parse_token_string_t cmd_set_what =
3502         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3503                                  "nbport#nbcore#burst#verbose");
3504 cmdline_parse_token_num_t cmd_set_value =
3505         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3506
3507 cmdline_parse_inst_t cmd_set_numbers = {
3508         .f = cmd_set_parsed,
3509         .data = NULL,
3510         .help_str = "set nbport|nbcore|burst|verbose <value>",
3511         .tokens = {
3512                 (void *)&cmd_set_set,
3513                 (void *)&cmd_set_what,
3514                 (void *)&cmd_set_value,
3515                 NULL,
3516         },
3517 };
3518
3519 /* *** SET LOG LEVEL CONFIGURATION *** */
3520
3521 struct cmd_set_log_result {
3522         cmdline_fixed_string_t set;
3523         cmdline_fixed_string_t log;
3524         cmdline_fixed_string_t type;
3525         uint32_t level;
3526 };
3527
3528 static void
3529 cmd_set_log_parsed(void *parsed_result,
3530                    __attribute__((unused)) struct cmdline *cl,
3531                    __attribute__((unused)) void *data)
3532 {
3533         struct cmd_set_log_result *res;
3534         int ret;
3535
3536         res = parsed_result;
3537         if (!strcmp(res->type, "global"))
3538                 rte_log_set_global_level(res->level);
3539         else {
3540                 ret = rte_log_set_level_regexp(res->type, res->level);
3541                 if (ret < 0)
3542                         printf("Unable to set log level\n");
3543         }
3544 }
3545
3546 cmdline_parse_token_string_t cmd_set_log_set =
3547         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3548 cmdline_parse_token_string_t cmd_set_log_log =
3549         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3550 cmdline_parse_token_string_t cmd_set_log_type =
3551         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3552 cmdline_parse_token_num_t cmd_set_log_level =
3553         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3554
3555 cmdline_parse_inst_t cmd_set_log = {
3556         .f = cmd_set_log_parsed,
3557         .data = NULL,
3558         .help_str = "set log global|<type> <level>",
3559         .tokens = {
3560                 (void *)&cmd_set_log_set,
3561                 (void *)&cmd_set_log_log,
3562                 (void *)&cmd_set_log_type,
3563                 (void *)&cmd_set_log_level,
3564                 NULL,
3565         },
3566 };
3567
3568 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3569
3570 struct cmd_set_txpkts_result {
3571         cmdline_fixed_string_t cmd_keyword;
3572         cmdline_fixed_string_t txpkts;
3573         cmdline_fixed_string_t seg_lengths;
3574 };
3575
3576 static void
3577 cmd_set_txpkts_parsed(void *parsed_result,
3578                       __attribute__((unused)) struct cmdline *cl,
3579                       __attribute__((unused)) void *data)
3580 {
3581         struct cmd_set_txpkts_result *res;
3582         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3583         unsigned int nb_segs;
3584
3585         res = parsed_result;
3586         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3587                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3588         if (nb_segs > 0)
3589                 set_tx_pkt_segments(seg_lengths, nb_segs);
3590 }
3591
3592 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3593         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3594                                  cmd_keyword, "set");
3595 cmdline_parse_token_string_t cmd_set_txpkts_name =
3596         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3597                                  txpkts, "txpkts");
3598 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3599         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3600                                  seg_lengths, NULL);
3601
3602 cmdline_parse_inst_t cmd_set_txpkts = {
3603         .f = cmd_set_txpkts_parsed,
3604         .data = NULL,
3605         .help_str = "set txpkts <len0[,len1]*>",
3606         .tokens = {
3607                 (void *)&cmd_set_txpkts_keyword,
3608                 (void *)&cmd_set_txpkts_name,
3609                 (void *)&cmd_set_txpkts_lengths,
3610                 NULL,
3611         },
3612 };
3613
3614 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3615
3616 struct cmd_set_txsplit_result {
3617         cmdline_fixed_string_t cmd_keyword;
3618         cmdline_fixed_string_t txsplit;
3619         cmdline_fixed_string_t mode;
3620 };
3621
3622 static void
3623 cmd_set_txsplit_parsed(void *parsed_result,
3624                       __attribute__((unused)) struct cmdline *cl,
3625                       __attribute__((unused)) void *data)
3626 {
3627         struct cmd_set_txsplit_result *res;
3628
3629         res = parsed_result;
3630         set_tx_pkt_split(res->mode);
3631 }
3632
3633 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3634         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3635                                  cmd_keyword, "set");
3636 cmdline_parse_token_string_t cmd_set_txsplit_name =
3637         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3638                                  txsplit, "txsplit");
3639 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3640         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3641                                  mode, NULL);
3642
3643 cmdline_parse_inst_t cmd_set_txsplit = {
3644         .f = cmd_set_txsplit_parsed,
3645         .data = NULL,
3646         .help_str = "set txsplit on|off|rand",
3647         .tokens = {
3648                 (void *)&cmd_set_txsplit_keyword,
3649                 (void *)&cmd_set_txsplit_name,
3650                 (void *)&cmd_set_txsplit_mode,
3651                 NULL,
3652         },
3653 };
3654
3655 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3656 struct cmd_rx_vlan_filter_all_result {
3657         cmdline_fixed_string_t rx_vlan;
3658         cmdline_fixed_string_t what;
3659         cmdline_fixed_string_t all;
3660         portid_t port_id;
3661 };
3662
3663 static void
3664 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3665                               __attribute__((unused)) struct cmdline *cl,
3666                               __attribute__((unused)) void *data)
3667 {
3668         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3669
3670         if (!strcmp(res->what, "add"))
3671                 rx_vlan_all_filter_set(res->port_id, 1);
3672         else
3673                 rx_vlan_all_filter_set(res->port_id, 0);
3674 }
3675
3676 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3677         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3678                                  rx_vlan, "rx_vlan");
3679 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3680         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3681                                  what, "add#rm");
3682 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3683         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3684                                  all, "all");
3685 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3686         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3687                               port_id, UINT16);
3688
3689 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3690         .f = cmd_rx_vlan_filter_all_parsed,
3691         .data = NULL,
3692         .help_str = "rx_vlan add|rm all <port_id>: "
3693                 "Add/Remove all identifiers to/from the set of VLAN "
3694                 "identifiers filtered by a port",
3695         .tokens = {
3696                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3697                 (void *)&cmd_rx_vlan_filter_all_what,
3698                 (void *)&cmd_rx_vlan_filter_all_all,
3699                 (void *)&cmd_rx_vlan_filter_all_portid,
3700                 NULL,
3701         },
3702 };
3703
3704 /* *** VLAN OFFLOAD SET ON A PORT *** */
3705 struct cmd_vlan_offload_result {
3706         cmdline_fixed_string_t vlan;
3707         cmdline_fixed_string_t set;
3708         cmdline_fixed_string_t vlan_type;
3709         cmdline_fixed_string_t what;
3710         cmdline_fixed_string_t on;
3711         cmdline_fixed_string_t port_id;
3712 };
3713
3714 static void
3715 cmd_vlan_offload_parsed(void *parsed_result,
3716                           __attribute__((unused)) struct cmdline *cl,
3717                           __attribute__((unused)) void *data)
3718 {
3719         int on;
3720         struct cmd_vlan_offload_result *res = parsed_result;
3721         char *str;
3722         int i, len = 0;
3723         portid_t port_id = 0;
3724         unsigned int tmp;
3725
3726         str = res->port_id;
3727         len = strnlen(str, STR_TOKEN_SIZE);
3728         i = 0;
3729         /* Get port_id first */
3730         while(i < len){
3731                 if(str[i] == ',')
3732                         break;
3733
3734                 i++;
3735         }
3736         str[i]='\0';
3737         tmp = strtoul(str, NULL, 0);
3738         /* If port_id greater that what portid_t can represent, return */
3739         if(tmp >= RTE_MAX_ETHPORTS)
3740                 return;
3741         port_id = (portid_t)tmp;
3742
3743         if (!strcmp(res->on, "on"))
3744                 on = 1;
3745         else
3746                 on = 0;
3747
3748         if (!strcmp(res->what, "strip"))
3749                 rx_vlan_strip_set(port_id,  on);
3750         else if(!strcmp(res->what, "stripq")){
3751                 uint16_t queue_id = 0;
3752
3753                 /* No queue_id, return */
3754                 if(i + 1 >= len) {
3755                         printf("must specify (port,queue_id)\n");
3756                         return;
3757                 }
3758                 tmp = strtoul(str + i + 1, NULL, 0);
3759                 /* If queue_id greater that what 16-bits can represent, return */
3760                 if(tmp > 0xffff)
3761                         return;
3762
3763                 queue_id = (uint16_t)tmp;
3764                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3765         }
3766         else if (!strcmp(res->what, "filter"))
3767                 rx_vlan_filter_set(port_id, on);
3768         else
3769                 vlan_extend_set(port_id, on);
3770
3771         return;
3772 }
3773
3774 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3775         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3776                                  vlan, "vlan");
3777 cmdline_parse_token_string_t cmd_vlan_offload_set =
3778         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3779                                  set, "set");
3780 cmdline_parse_token_string_t cmd_vlan_offload_what =
3781         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3782                                  what, "strip#filter#qinq#stripq");
3783 cmdline_parse_token_string_t cmd_vlan_offload_on =
3784         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3785                               on, "on#off");
3786 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3787         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3788                               port_id, NULL);
3789
3790 cmdline_parse_inst_t cmd_vlan_offload = {
3791         .f = cmd_vlan_offload_parsed,
3792         .data = NULL,
3793         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3794                 "<port_id[,queue_id]>: "
3795                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3796         .tokens = {
3797                 (void *)&cmd_vlan_offload_vlan,
3798                 (void *)&cmd_vlan_offload_set,
3799                 (void *)&cmd_vlan_offload_what,
3800                 (void *)&cmd_vlan_offload_on,
3801                 (void *)&cmd_vlan_offload_portid,
3802                 NULL,
3803         },
3804 };
3805
3806 /* *** VLAN TPID SET ON A PORT *** */
3807 struct cmd_vlan_tpid_result {
3808         cmdline_fixed_string_t vlan;
3809         cmdline_fixed_string_t set;
3810         cmdline_fixed_string_t vlan_type;
3811         cmdline_fixed_string_t what;
3812         uint16_t tp_id;
3813         portid_t port_id;
3814 };
3815
3816 static void
3817 cmd_vlan_tpid_parsed(void *parsed_result,
3818                           __attribute__((unused)) struct cmdline *cl,
3819                           __attribute__((unused)) void *data)
3820 {
3821         struct cmd_vlan_tpid_result *res = parsed_result;
3822         enum rte_vlan_type vlan_type;
3823
3824         if (!strcmp(res->vlan_type, "inner"))
3825                 vlan_type = ETH_VLAN_TYPE_INNER;
3826         else if (!strcmp(res->vlan_type, "outer"))
3827                 vlan_type = ETH_VLAN_TYPE_OUTER;
3828         else {
3829                 printf("Unknown vlan type\n");
3830                 return;
3831         }
3832         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3833 }
3834
3835 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3836         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3837                                  vlan, "vlan");
3838 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3839         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3840                                  set, "set");
3841 cmdline_parse_token_string_t cmd_vlan_type =
3842         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3843                                  vlan_type, "inner#outer");
3844 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3845         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3846                                  what, "tpid");
3847 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3848         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3849                               tp_id, UINT16);
3850 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3851         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3852                               port_id, UINT16);
3853
3854 cmdline_parse_inst_t cmd_vlan_tpid = {
3855         .f = cmd_vlan_tpid_parsed,
3856         .data = NULL,
3857         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3858                 "Set the VLAN Ether type",
3859         .tokens = {
3860                 (void *)&cmd_vlan_tpid_vlan,
3861                 (void *)&cmd_vlan_tpid_set,
3862                 (void *)&cmd_vlan_type,
3863                 (void *)&cmd_vlan_tpid_what,
3864                 (void *)&cmd_vlan_tpid_tpid,
3865                 (void *)&cmd_vlan_tpid_portid,
3866                 NULL,
3867         },
3868 };
3869
3870 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3871 struct cmd_rx_vlan_filter_result {
3872         cmdline_fixed_string_t rx_vlan;
3873         cmdline_fixed_string_t what;
3874         uint16_t vlan_id;
3875         portid_t port_id;
3876 };
3877
3878 static void
3879 cmd_rx_vlan_filter_parsed(void *parsed_result,
3880                           __attribute__((unused)) struct cmdline *cl,
3881                           __attribute__((unused)) void *data)
3882 {
3883         struct cmd_rx_vlan_filter_result *res = parsed_result;
3884
3885         if (!strcmp(res->what, "add"))
3886                 rx_vft_set(res->port_id, res->vlan_id, 1);
3887         else
3888                 rx_vft_set(res->port_id, res->vlan_id, 0);
3889 }
3890
3891 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3892         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3893                                  rx_vlan, "rx_vlan");
3894 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3895         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3896                                  what, "add#rm");
3897 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3898         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3899                               vlan_id, UINT16);
3900 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3901         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3902                               port_id, UINT16);
3903
3904 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3905         .f = cmd_rx_vlan_filter_parsed,
3906         .data = NULL,
3907         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3908                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3909                 "identifiers filtered by a port",
3910         .tokens = {
3911                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3912                 (void *)&cmd_rx_vlan_filter_what,
3913                 (void *)&cmd_rx_vlan_filter_vlanid,
3914                 (void *)&cmd_rx_vlan_filter_portid,
3915                 NULL,
3916         },
3917 };
3918
3919 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3920 struct cmd_tx_vlan_set_result {
3921         cmdline_fixed_string_t tx_vlan;
3922         cmdline_fixed_string_t set;
3923         portid_t port_id;
3924         uint16_t vlan_id;
3925 };
3926
3927 static void
3928 cmd_tx_vlan_set_parsed(void *parsed_result,
3929                        __attribute__((unused)) struct cmdline *cl,
3930                        __attribute__((unused)) void *data)
3931 {
3932         struct cmd_tx_vlan_set_result *res = parsed_result;
3933
3934         if (!port_is_stopped(res->port_id)) {
3935                 printf("Please stop port %d first\n", res->port_id);
3936                 return;
3937         }
3938
3939         tx_vlan_set(res->port_id, res->vlan_id);
3940
3941         cmd_reconfig_device_queue(res->port_id, 1, 1);
3942 }
3943
3944 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3945         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3946                                  tx_vlan, "tx_vlan");
3947 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3948         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3949                                  set, "set");
3950 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3951         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3952                               port_id, UINT16);
3953 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3954         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3955                               vlan_id, UINT16);
3956
3957 cmdline_parse_inst_t cmd_tx_vlan_set = {
3958         .f = cmd_tx_vlan_set_parsed,
3959         .data = NULL,
3960         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3961                 "Enable hardware insertion of a single VLAN header "
3962                 "with a given TAG Identifier in packets sent on a port",
3963         .tokens = {
3964                 (void *)&cmd_tx_vlan_set_tx_vlan,
3965                 (void *)&cmd_tx_vlan_set_set,
3966                 (void *)&cmd_tx_vlan_set_portid,
3967                 (void *)&cmd_tx_vlan_set_vlanid,
3968                 NULL,
3969         },
3970 };
3971
3972 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3973 struct cmd_tx_vlan_set_qinq_result {
3974         cmdline_fixed_string_t tx_vlan;
3975         cmdline_fixed_string_t set;
3976         portid_t port_id;
3977         uint16_t vlan_id;
3978         uint16_t vlan_id_outer;
3979 };
3980
3981 static void
3982 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3983                             __attribute__((unused)) struct cmdline *cl,
3984                             __attribute__((unused)) void *data)
3985 {
3986         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3987
3988         if (!port_is_stopped(res->port_id)) {
3989                 printf("Please stop port %d first\n", res->port_id);
3990                 return;
3991         }
3992
3993         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3994
3995         cmd_reconfig_device_queue(res->port_id, 1, 1);
3996 }
3997
3998 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3999         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4000                 tx_vlan, "tx_vlan");
4001 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4002         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4003                 set, "set");
4004 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4005         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4006                 port_id, UINT16);
4007 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4008         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4009                 vlan_id, UINT16);
4010 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4011         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4012                 vlan_id_outer, UINT16);
4013
4014 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4015         .f = cmd_tx_vlan_set_qinq_parsed,
4016         .data = NULL,
4017         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4018                 "Enable hardware insertion of double VLAN header "
4019                 "with given TAG Identifiers in packets sent on a port",
4020         .tokens = {
4021                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4022                 (void *)&cmd_tx_vlan_set_qinq_set,
4023                 (void *)&cmd_tx_vlan_set_qinq_portid,
4024                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4025                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4026                 NULL,
4027         },
4028 };
4029
4030 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4031 struct cmd_tx_vlan_set_pvid_result {
4032         cmdline_fixed_string_t tx_vlan;
4033         cmdline_fixed_string_t set;
4034         cmdline_fixed_string_t pvid;
4035         portid_t port_id;
4036         uint16_t vlan_id;
4037         cmdline_fixed_string_t mode;
4038 };
4039
4040 static void
4041 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4042                             __attribute__((unused)) struct cmdline *cl,
4043                             __attribute__((unused)) void *data)
4044 {
4045         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4046
4047         if (strcmp(res->mode, "on") == 0)
4048                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4049         else
4050                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4051 }
4052
4053 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4054         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4055                                  tx_vlan, "tx_vlan");
4056 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4057         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4058                                  set, "set");
4059 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4060         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4061                                  pvid, "pvid");
4062 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4063         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4064                              port_id, UINT16);
4065 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4066         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4067                               vlan_id, UINT16);
4068 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4069         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4070                                  mode, "on#off");
4071
4072 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4073         .f = cmd_tx_vlan_set_pvid_parsed,
4074         .data = NULL,
4075         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4076         .tokens = {
4077                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4078                 (void *)&cmd_tx_vlan_set_pvid_set,
4079                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4080                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4081                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4082                 (void *)&cmd_tx_vlan_set_pvid_mode,
4083                 NULL,
4084         },
4085 };
4086
4087 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4088 struct cmd_tx_vlan_reset_result {
4089         cmdline_fixed_string_t tx_vlan;
4090         cmdline_fixed_string_t reset;
4091         portid_t port_id;
4092 };
4093
4094 static void
4095 cmd_tx_vlan_reset_parsed(void *parsed_result,
4096                          __attribute__((unused)) struct cmdline *cl,
4097                          __attribute__((unused)) void *data)
4098 {
4099         struct cmd_tx_vlan_reset_result *res = parsed_result;
4100
4101         if (!port_is_stopped(res->port_id)) {
4102                 printf("Please stop port %d first\n", res->port_id);
4103                 return;
4104         }
4105
4106         tx_vlan_reset(res->port_id);
4107
4108         cmd_reconfig_device_queue(res->port_id, 1, 1);
4109 }
4110
4111 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4112         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4113                                  tx_vlan, "tx_vlan");
4114 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4115         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4116                                  reset, "reset");
4117 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4118         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4119                               port_id, UINT16);
4120
4121 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4122         .f = cmd_tx_vlan_reset_parsed,
4123         .data = NULL,
4124         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4125                 "VLAN header in packets sent on a port",
4126         .tokens = {
4127                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4128                 (void *)&cmd_tx_vlan_reset_reset,
4129                 (void *)&cmd_tx_vlan_reset_portid,
4130                 NULL,
4131         },
4132 };
4133
4134
4135 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4136 struct cmd_csum_result {
4137         cmdline_fixed_string_t csum;
4138         cmdline_fixed_string_t mode;
4139         cmdline_fixed_string_t proto;
4140         cmdline_fixed_string_t hwsw;
4141         portid_t port_id;
4142 };
4143
4144 static void
4145 csum_show(int port_id)
4146 {
4147         struct rte_eth_dev_info dev_info;
4148         uint64_t tx_offloads;
4149
4150         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4151         printf("Parse tunnel is %s\n",
4152                 (ports[port_id].parse_tunnel) ? "on" : "off");
4153         printf("IP checksum offload is %s\n",
4154                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4155         printf("UDP checksum offload is %s\n",
4156                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4157         printf("TCP checksum offload is %s\n",
4158                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4159         printf("SCTP checksum offload is %s\n",
4160                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4161         printf("Outer-Ip checksum offload is %s\n",
4162                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4163         printf("Outer-Udp checksum offload is %s\n",
4164                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4165
4166         /* display warnings if configuration is not supported by the NIC */
4167         rte_eth_dev_info_get(port_id, &dev_info);
4168         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4169                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4170                 printf("Warning: hardware IP checksum enabled but not "
4171                         "supported by port %d\n", port_id);
4172         }
4173         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4174                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4175                 printf("Warning: hardware UDP checksum enabled but not "
4176                         "supported by port %d\n", port_id);
4177         }
4178         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4179                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4180                 printf("Warning: hardware TCP checksum enabled but not "
4181                         "supported by port %d\n", port_id);
4182         }
4183         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4184                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4185                 printf("Warning: hardware SCTP checksum enabled but not "
4186                         "supported by port %d\n", port_id);
4187         }
4188         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4189                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4190                 printf("Warning: hardware outer IP checksum enabled but not "
4191                         "supported by port %d\n", port_id);
4192         }
4193         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4194                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4195                         == 0) {
4196                 printf("Warning: hardware outer UDP checksum enabled but not "
4197                         "supported by port %d\n", port_id);
4198         }
4199 }
4200
4201 static void
4202 cmd_csum_parsed(void *parsed_result,
4203                        __attribute__((unused)) struct cmdline *cl,
4204                        __attribute__((unused)) void *data)
4205 {
4206         struct cmd_csum_result *res = parsed_result;
4207         int hw = 0;
4208         uint64_t csum_offloads = 0;
4209         struct rte_eth_dev_info dev_info;
4210
4211         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4212                 printf("invalid port %d\n", res->port_id);
4213                 return;
4214         }
4215         if (!port_is_stopped(res->port_id)) {
4216                 printf("Please stop port %d first\n", res->port_id);
4217                 return;
4218         }
4219
4220         rte_eth_dev_info_get(res->port_id, &dev_info);
4221         if (!strcmp(res->mode, "set")) {
4222
4223                 if (!strcmp(res->hwsw, "hw"))
4224                         hw = 1;
4225
4226                 if (!strcmp(res->proto, "ip")) {
4227                         if (hw == 0 || (dev_info.tx_offload_capa &
4228                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4229                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4230                         } else {
4231                                 printf("IP checksum offload is not supported "
4232                                        "by port %u\n", res->port_id);
4233                         }
4234                 } else if (!strcmp(res->proto, "udp")) {
4235                         if (hw == 0 || (dev_info.tx_offload_capa &
4236                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4237                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4238                         } else {
4239                                 printf("UDP checksum offload is not supported "
4240                                        "by port %u\n", res->port_id);
4241                         }
4242                 } else if (!strcmp(res->proto, "tcp")) {
4243                         if (hw == 0 || (dev_info.tx_offload_capa &
4244                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4245                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4246                         } else {
4247                                 printf("TCP checksum offload is not supported "
4248                                        "by port %u\n", res->port_id);
4249                         }
4250                 } else if (!strcmp(res->proto, "sctp")) {
4251                         if (hw == 0 || (dev_info.tx_offload_capa &
4252                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4253                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4254                         } else {
4255                                 printf("SCTP checksum offload is not supported "
4256                                        "by port %u\n", res->port_id);
4257                         }
4258                 } else if (!strcmp(res->proto, "outer-ip")) {
4259                         if (hw == 0 || (dev_info.tx_offload_capa &
4260                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4261                                 csum_offloads |=
4262                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4263                         } else {
4264                                 printf("Outer IP checksum offload is not "
4265                                        "supported by port %u\n", res->port_id);
4266                         }
4267                 } else if (!strcmp(res->proto, "outer-udp")) {
4268                         if (hw == 0 || (dev_info.tx_offload_capa &
4269                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4270                                 csum_offloads |=
4271                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4272                         } else {
4273                                 printf("Outer UDP checksum offload is not "
4274                                        "supported by port %u\n", res->port_id);
4275                         }
4276                 }
4277
4278                 if (hw) {
4279                         ports[res->port_id].dev_conf.txmode.offloads |=
4280                                                         csum_offloads;
4281                 } else {
4282                         ports[res->port_id].dev_conf.txmode.offloads &=
4283                                                         (~csum_offloads);
4284                 }
4285         }
4286         csum_show(res->port_id);
4287
4288         cmd_reconfig_device_queue(res->port_id, 1, 1);
4289 }
4290
4291 cmdline_parse_token_string_t cmd_csum_csum =
4292         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4293                                 csum, "csum");
4294 cmdline_parse_token_string_t cmd_csum_mode =
4295         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4296                                 mode, "set");
4297 cmdline_parse_token_string_t cmd_csum_proto =
4298         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4299                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4300 cmdline_parse_token_string_t cmd_csum_hwsw =
4301         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4302                                 hwsw, "hw#sw");
4303 cmdline_parse_token_num_t cmd_csum_portid =
4304         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4305                                 port_id, UINT16);
4306
4307 cmdline_parse_inst_t cmd_csum_set = {
4308         .f = cmd_csum_parsed,
4309         .data = NULL,
4310         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4311                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4312                 "using csum forward engine",
4313         .tokens = {
4314                 (void *)&cmd_csum_csum,
4315                 (void *)&cmd_csum_mode,
4316                 (void *)&cmd_csum_proto,
4317                 (void *)&cmd_csum_hwsw,
4318                 (void *)&cmd_csum_portid,
4319                 NULL,
4320         },
4321 };
4322
4323 cmdline_parse_token_string_t cmd_csum_mode_show =
4324         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4325                                 mode, "show");
4326
4327 cmdline_parse_inst_t cmd_csum_show = {
4328         .f = cmd_csum_parsed,
4329         .data = NULL,
4330         .help_str = "csum show <port_id>: Show checksum offload configuration",
4331         .tokens = {
4332                 (void *)&cmd_csum_csum,
4333                 (void *)&cmd_csum_mode_show,
4334                 (void *)&cmd_csum_portid,
4335                 NULL,
4336         },
4337 };
4338
4339 /* Enable/disable tunnel parsing */
4340 struct cmd_csum_tunnel_result {
4341         cmdline_fixed_string_t csum;
4342         cmdline_fixed_string_t parse;
4343         cmdline_fixed_string_t onoff;
4344         portid_t port_id;
4345 };
4346
4347 static void
4348 cmd_csum_tunnel_parsed(void *parsed_result,
4349                        __attribute__((unused)) struct cmdline *cl,
4350                        __attribute__((unused)) void *data)
4351 {
4352         struct cmd_csum_tunnel_result *res = parsed_result;
4353
4354         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4355                 return;
4356
4357         if (!strcmp(res->onoff, "on"))
4358                 ports[res->port_id].parse_tunnel = 1;
4359         else
4360                 ports[res->port_id].parse_tunnel = 0;
4361
4362         csum_show(res->port_id);
4363 }
4364
4365 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4366         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4367                                 csum, "csum");
4368 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4369         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4370                                 parse, "parse-tunnel");
4371 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4372         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4373                                 onoff, "on#off");
4374 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4375         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4376                                 port_id, UINT16);
4377
4378 cmdline_parse_inst_t cmd_csum_tunnel = {
4379         .f = cmd_csum_tunnel_parsed,
4380         .data = NULL,
4381         .help_str = "csum parse-tunnel on|off <port_id>: "
4382                 "Enable/Disable parsing of tunnels for csum engine",
4383         .tokens = {
4384                 (void *)&cmd_csum_tunnel_csum,
4385                 (void *)&cmd_csum_tunnel_parse,
4386                 (void *)&cmd_csum_tunnel_onoff,
4387                 (void *)&cmd_csum_tunnel_portid,
4388                 NULL,
4389         },
4390 };
4391
4392 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4393 struct cmd_tso_set_result {
4394         cmdline_fixed_string_t tso;
4395         cmdline_fixed_string_t mode;
4396         uint16_t tso_segsz;
4397         portid_t port_id;
4398 };
4399
4400 static void
4401 cmd_tso_set_parsed(void *parsed_result,
4402                        __attribute__((unused)) struct cmdline *cl,
4403                        __attribute__((unused)) void *data)
4404 {
4405         struct cmd_tso_set_result *res = parsed_result;
4406         struct rte_eth_dev_info dev_info;
4407
4408         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4409                 return;
4410         if (!port_is_stopped(res->port_id)) {
4411                 printf("Please stop port %d first\n", res->port_id);
4412                 return;
4413         }
4414
4415         if (!strcmp(res->mode, "set"))
4416                 ports[res->port_id].tso_segsz = res->tso_segsz;
4417
4418         rte_eth_dev_info_get(res->port_id, &dev_info);
4419         if ((ports[res->port_id].tso_segsz != 0) &&
4420                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4421                 printf("Error: TSO is not supported by port %d\n",
4422                        res->port_id);
4423                 return;
4424         }
4425
4426         if (ports[res->port_id].tso_segsz == 0) {
4427                 ports[res->port_id].dev_conf.txmode.offloads &=
4428                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4429                 printf("TSO for non-tunneled packets is disabled\n");
4430         } else {
4431                 ports[res->port_id].dev_conf.txmode.offloads |=
4432                                                 DEV_TX_OFFLOAD_TCP_TSO;
4433                 printf("TSO segment size for non-tunneled packets is %d\n",
4434                         ports[res->port_id].tso_segsz);
4435         }
4436
4437         /* display warnings if configuration is not supported by the NIC */
4438         rte_eth_dev_info_get(res->port_id, &dev_info);
4439         if ((ports[res->port_id].tso_segsz != 0) &&
4440                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4441                 printf("Warning: TSO enabled but not "
4442                         "supported by port %d\n", res->port_id);
4443         }
4444
4445         cmd_reconfig_device_queue(res->port_id, 1, 1);
4446 }
4447
4448 cmdline_parse_token_string_t cmd_tso_set_tso =
4449         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4450                                 tso, "tso");
4451 cmdline_parse_token_string_t cmd_tso_set_mode =
4452         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4453                                 mode, "set");
4454 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4455         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4456                                 tso_segsz, UINT16);
4457 cmdline_parse_token_num_t cmd_tso_set_portid =
4458         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4459                                 port_id, UINT16);
4460
4461 cmdline_parse_inst_t cmd_tso_set = {
4462         .f = cmd_tso_set_parsed,
4463         .data = NULL,
4464         .help_str = "tso set <tso_segsz> <port_id>: "
4465                 "Set TSO segment size of non-tunneled packets for csum engine "
4466                 "(0 to disable)",
4467         .tokens = {
4468                 (void *)&cmd_tso_set_tso,
4469                 (void *)&cmd_tso_set_mode,
4470                 (void *)&cmd_tso_set_tso_segsz,
4471                 (void *)&cmd_tso_set_portid,
4472                 NULL,
4473         },
4474 };
4475
4476 cmdline_parse_token_string_t cmd_tso_show_mode =
4477         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4478                                 mode, "show");
4479
4480
4481 cmdline_parse_inst_t cmd_tso_show = {
4482         .f = cmd_tso_set_parsed,
4483         .data = NULL,
4484         .help_str = "tso show <port_id>: "
4485                 "Show TSO segment size of non-tunneled packets for csum engine",
4486         .tokens = {
4487                 (void *)&cmd_tso_set_tso,
4488                 (void *)&cmd_tso_show_mode,
4489                 (void *)&cmd_tso_set_portid,
4490                 NULL,
4491         },
4492 };
4493
4494 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4495 struct cmd_tunnel_tso_set_result {
4496         cmdline_fixed_string_t tso;
4497         cmdline_fixed_string_t mode;
4498         uint16_t tso_segsz;
4499         portid_t port_id;
4500 };
4501
4502 static struct rte_eth_dev_info
4503 check_tunnel_tso_nic_support(portid_t port_id)
4504 {
4505         struct rte_eth_dev_info dev_info;
4506
4507         rte_eth_dev_info_get(port_id, &dev_info);
4508         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4509                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4510                        "not enabled for port %d\n", port_id);
4511         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4512                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4513                        "not enabled for port %d\n", port_id);
4514         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4515                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4516                        "not enabled for port %d\n", port_id);
4517         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4518                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4519                        "not enabled for port %d\n", port_id);
4520         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4521                 printf("Warning: IP TUNNEL TSO not supported therefore "
4522                        "not enabled for port %d\n", port_id);
4523         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4524                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4525                        "not enabled for port %d\n", port_id);
4526         return dev_info;
4527 }
4528
4529 static void
4530 cmd_tunnel_tso_set_parsed(void *parsed_result,
4531                           __attribute__((unused)) struct cmdline *cl,
4532                           __attribute__((unused)) void *data)
4533 {
4534         struct cmd_tunnel_tso_set_result *res = parsed_result;
4535         struct rte_eth_dev_info dev_info;
4536
4537         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4538                 return;
4539         if (!port_is_stopped(res->port_id)) {
4540                 printf("Please stop port %d first\n", res->port_id);
4541                 return;
4542         }
4543
4544         if (!strcmp(res->mode, "set"))
4545                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4546
4547         dev_info = check_tunnel_tso_nic_support(res->port_id);
4548         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4549                 ports[res->port_id].dev_conf.txmode.offloads &=
4550                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4551                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4552                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4553                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4554                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4555                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4556                 printf("TSO for tunneled packets is disabled\n");
4557         } else {
4558                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4559                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4560                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4561                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4562                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4563                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4564
4565                 ports[res->port_id].dev_conf.txmode.offloads |=
4566                         (tso_offloads & dev_info.tx_offload_capa);
4567                 printf("TSO segment size for tunneled packets is %d\n",
4568                         ports[res->port_id].tunnel_tso_segsz);
4569
4570                 /* Below conditions are needed to make it work:
4571                  * (1) tunnel TSO is supported by the NIC;
4572                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4573                  * are recognized;
4574                  * (3) for tunneled pkts with outer L3 of IPv4,
4575                  * "csum set outer-ip" must be set to hw, because after tso,
4576                  * total_len of outer IP header is changed, and the checksum
4577                  * of outer IP header calculated by sw should be wrong; that
4578                  * is not necessary for IPv6 tunneled pkts because there's no
4579                  * checksum in IP header anymore.
4580                  */
4581
4582                 if (!ports[res->port_id].parse_tunnel)
4583                         printf("Warning: csum parse_tunnel must be set "
4584                                 "so that tunneled packets are recognized\n");
4585                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4586                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4587                         printf("Warning: csum set outer-ip must be set to hw "
4588                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4589         }
4590
4591         cmd_reconfig_device_queue(res->port_id, 1, 1);
4592 }
4593
4594 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4595         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4596                                 tso, "tunnel_tso");
4597 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4598         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4599                                 mode, "set");
4600 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4601         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4602                                 tso_segsz, UINT16);
4603 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4604         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4605                                 port_id, UINT16);
4606
4607 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4608         .f = cmd_tunnel_tso_set_parsed,
4609         .data = NULL,
4610         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4611                 "Set TSO segment size of tunneled packets for csum engine "
4612                 "(0 to disable)",
4613         .tokens = {
4614                 (void *)&cmd_tunnel_tso_set_tso,
4615                 (void *)&cmd_tunnel_tso_set_mode,
4616                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4617                 (void *)&cmd_tunnel_tso_set_portid,
4618                 NULL,
4619         },
4620 };
4621
4622 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4623         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4624                                 mode, "show");
4625
4626
4627 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4628         .f = cmd_tunnel_tso_set_parsed,
4629         .data = NULL,
4630         .help_str = "tunnel_tso show <port_id> "
4631                 "Show TSO segment size of tunneled packets for csum engine",
4632         .tokens = {
4633                 (void *)&cmd_tunnel_tso_set_tso,
4634                 (void *)&cmd_tunnel_tso_show_mode,
4635                 (void *)&cmd_tunnel_tso_set_portid,
4636                 NULL,
4637         },
4638 };
4639
4640 /* *** SET GRO FOR A PORT *** */
4641 struct cmd_gro_enable_result {
4642         cmdline_fixed_string_t cmd_set;
4643         cmdline_fixed_string_t cmd_port;
4644         cmdline_fixed_string_t cmd_keyword;
4645         cmdline_fixed_string_t cmd_onoff;
4646         portid_t cmd_pid;
4647 };
4648
4649 static void
4650 cmd_gro_enable_parsed(void *parsed_result,
4651                 __attribute__((unused)) struct cmdline *cl,
4652                 __attribute__((unused)) void *data)
4653 {
4654         struct cmd_gro_enable_result *res;
4655
4656         res = parsed_result;
4657         if (!strcmp(res->cmd_keyword, "gro"))
4658                 setup_gro(res->cmd_onoff, res->cmd_pid);
4659 }
4660
4661 cmdline_parse_token_string_t cmd_gro_enable_set =
4662         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4663                         cmd_set, "set");
4664 cmdline_parse_token_string_t cmd_gro_enable_port =
4665         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4666                         cmd_keyword, "port");
4667 cmdline_parse_token_num_t cmd_gro_enable_pid =
4668         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4669                         cmd_pid, UINT16);
4670 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4671         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4672                         cmd_keyword, "gro");
4673 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4674         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4675                         cmd_onoff, "on#off");
4676
4677 cmdline_parse_inst_t cmd_gro_enable = {
4678         .f = cmd_gro_enable_parsed,
4679         .data = NULL,
4680         .help_str = "set port <port_id> gro on|off",
4681         .tokens = {
4682                 (void *)&cmd_gro_enable_set,
4683                 (void *)&cmd_gro_enable_port,
4684                 (void *)&cmd_gro_enable_pid,
4685                 (void *)&cmd_gro_enable_keyword,
4686                 (void *)&cmd_gro_enable_onoff,
4687                 NULL,
4688         },
4689 };
4690
4691 /* *** DISPLAY GRO CONFIGURATION *** */
4692 struct cmd_gro_show_result {
4693         cmdline_fixed_string_t cmd_show;
4694         cmdline_fixed_string_t cmd_port;
4695         cmdline_fixed_string_t cmd_keyword;
4696         portid_t cmd_pid;
4697 };
4698
4699 static void
4700 cmd_gro_show_parsed(void *parsed_result,
4701                 __attribute__((unused)) struct cmdline *cl,
4702                 __attribute__((unused)) void *data)
4703 {
4704         struct cmd_gro_show_result *res;
4705
4706         res = parsed_result;
4707         if (!strcmp(res->cmd_keyword, "gro"))
4708                 show_gro(res->cmd_pid);
4709 }
4710
4711 cmdline_parse_token_string_t cmd_gro_show_show =
4712         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4713                         cmd_show, "show");
4714 cmdline_parse_token_string_t cmd_gro_show_port =
4715         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4716                         cmd_port, "port");
4717 cmdline_parse_token_num_t cmd_gro_show_pid =
4718         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4719                         cmd_pid, UINT16);
4720 cmdline_parse_token_string_t cmd_gro_show_keyword =
4721         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4722                         cmd_keyword, "gro");
4723
4724 cmdline_parse_inst_t cmd_gro_show = {
4725         .f = cmd_gro_show_parsed,
4726         .data = NULL,
4727         .help_str = "show port <port_id> gro",
4728         .tokens = {
4729                 (void *)&cmd_gro_show_show,
4730                 (void *)&cmd_gro_show_port,
4731                 (void *)&cmd_gro_show_pid,
4732                 (void *)&cmd_gro_show_keyword,
4733                 NULL,
4734         },
4735 };
4736
4737 /* *** SET FLUSH CYCLES FOR GRO *** */
4738 struct cmd_gro_flush_result {
4739         cmdline_fixed_string_t cmd_set;
4740         cmdline_fixed_string_t cmd_keyword;
4741         cmdline_fixed_string_t cmd_flush;
4742         uint8_t cmd_cycles;
4743 };
4744
4745 static void
4746 cmd_gro_flush_parsed(void *parsed_result,
4747                 __attribute__((unused)) struct cmdline *cl,
4748                 __attribute__((unused)) void *data)
4749 {
4750         struct cmd_gro_flush_result *res;
4751
4752         res = parsed_result;
4753         if ((!strcmp(res->cmd_keyword, "gro")) &&
4754                         (!strcmp(res->cmd_flush, "flush")))
4755                 setup_gro_flush_cycles(res->cmd_cycles);
4756 }
4757
4758 cmdline_parse_token_string_t cmd_gro_flush_set =
4759         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4760                         cmd_set, "set");
4761 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4762         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4763                         cmd_keyword, "gro");
4764 cmdline_parse_token_string_t cmd_gro_flush_flush =
4765         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4766                         cmd_flush, "flush");
4767 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4768         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4769                         cmd_cycles, UINT8);
4770
4771 cmdline_parse_inst_t cmd_gro_flush = {
4772         .f = cmd_gro_flush_parsed,
4773         .data = NULL,
4774         .help_str = "set gro flush <cycles>",
4775         .tokens = {
4776                 (void *)&cmd_gro_flush_set,
4777                 (void *)&cmd_gro_flush_keyword,
4778                 (void *)&cmd_gro_flush_flush,
4779                 (void *)&cmd_gro_flush_cycles,
4780                 NULL,
4781         },
4782 };
4783
4784 /* *** ENABLE/DISABLE GSO *** */
4785 struct cmd_gso_enable_result {
4786         cmdline_fixed_string_t cmd_set;
4787         cmdline_fixed_string_t cmd_port;
4788         cmdline_fixed_string_t cmd_keyword;
4789         cmdline_fixed_string_t cmd_mode;
4790         portid_t cmd_pid;
4791 };
4792
4793 static void
4794 cmd_gso_enable_parsed(void *parsed_result,
4795                 __attribute__((unused)) struct cmdline *cl,
4796                 __attribute__((unused)) void *data)
4797 {
4798         struct cmd_gso_enable_result *res;
4799
4800         res = parsed_result;
4801         if (!strcmp(res->cmd_keyword, "gso"))
4802                 setup_gso(res->cmd_mode, res->cmd_pid);
4803 }
4804
4805 cmdline_parse_token_string_t cmd_gso_enable_set =
4806         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4807                         cmd_set, "set");
4808 cmdline_parse_token_string_t cmd_gso_enable_port =
4809         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4810                         cmd_port, "port");
4811 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4812         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4813                         cmd_keyword, "gso");
4814 cmdline_parse_token_string_t cmd_gso_enable_mode =
4815         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4816                         cmd_mode, "on#off");
4817 cmdline_parse_token_num_t cmd_gso_enable_pid =
4818         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4819                         cmd_pid, UINT16);
4820
4821 cmdline_parse_inst_t cmd_gso_enable = {
4822         .f = cmd_gso_enable_parsed,
4823         .data = NULL,
4824         .help_str = "set port <port_id> gso on|off",
4825         .tokens = {
4826                 (void *)&cmd_gso_enable_set,
4827                 (void *)&cmd_gso_enable_port,
4828                 (void *)&cmd_gso_enable_pid,
4829                 (void *)&cmd_gso_enable_keyword,
4830                 (void *)&cmd_gso_enable_mode,
4831                 NULL,
4832         },
4833 };
4834
4835 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4836 struct cmd_gso_size_result {
4837         cmdline_fixed_string_t cmd_set;
4838         cmdline_fixed_string_t cmd_keyword;
4839         cmdline_fixed_string_t cmd_segsz;
4840         uint16_t cmd_size;
4841 };
4842
4843 static void
4844 cmd_gso_size_parsed(void *parsed_result,
4845                        __attribute__((unused)) struct cmdline *cl,
4846                        __attribute__((unused)) void *data)
4847 {
4848         struct cmd_gso_size_result *res = parsed_result;
4849
4850         if (test_done == 0) {
4851                 printf("Before setting GSO segsz, please first"
4852                                 " stop fowarding\n");
4853                 return;
4854         }
4855
4856         if (!strcmp(res->cmd_keyword, "gso") &&
4857                         !strcmp(res->cmd_segsz, "segsz")) {
4858                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4859                         printf("gso_size should be larger than %zu."
4860                                         " Please input a legal value\n",
4861                                         RTE_GSO_SEG_SIZE_MIN);
4862                 else
4863                         gso_max_segment_size = res->cmd_size;
4864         }
4865 }
4866
4867 cmdline_parse_token_string_t cmd_gso_size_set =
4868         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4869                                 cmd_set, "set");
4870 cmdline_parse_token_string_t cmd_gso_size_keyword =
4871         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4872                                 cmd_keyword, "gso");
4873 cmdline_parse_token_string_t cmd_gso_size_segsz =
4874         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4875                                 cmd_segsz, "segsz");
4876 cmdline_parse_token_num_t cmd_gso_size_size =
4877         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4878                                 cmd_size, UINT16);
4879
4880 cmdline_parse_inst_t cmd_gso_size = {
4881         .f = cmd_gso_size_parsed,
4882         .data = NULL,
4883         .help_str = "set gso segsz <length>",
4884         .tokens = {
4885                 (void *)&cmd_gso_size_set,
4886                 (void *)&cmd_gso_size_keyword,
4887                 (void *)&cmd_gso_size_segsz,
4888                 (void *)&cmd_gso_size_size,
4889                 NULL,
4890         },
4891 };
4892
4893 /* *** SHOW GSO CONFIGURATION *** */
4894 struct cmd_gso_show_result {
4895         cmdline_fixed_string_t cmd_show;
4896         cmdline_fixed_string_t cmd_port;
4897         cmdline_fixed_string_t cmd_keyword;
4898         portid_t cmd_pid;
4899 };
4900
4901 static void
4902 cmd_gso_show_parsed(void *parsed_result,
4903                        __attribute__((unused)) struct cmdline *cl,
4904                        __attribute__((unused)) void *data)
4905 {
4906         struct cmd_gso_show_result *res = parsed_result;
4907
4908         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4909                 printf("invalid port id %u\n", res->cmd_pid);
4910                 return;
4911         }
4912         if (!strcmp(res->cmd_keyword, "gso")) {
4913                 if (gso_ports[res->cmd_pid].enable) {
4914                         printf("Max GSO'd packet size: %uB\n"
4915                                         "Supported GSO types: TCP/IPv4, "
4916                                         "UDP/IPv4, VxLAN with inner "
4917                                         "TCP/IPv4 packet, GRE with inner "
4918                                         "TCP/IPv4 packet\n",
4919                                         gso_max_segment_size);
4920                 } else
4921                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4922         }
4923 }
4924
4925 cmdline_parse_token_string_t cmd_gso_show_show =
4926 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4927                 cmd_show, "show");
4928 cmdline_parse_token_string_t cmd_gso_show_port =
4929 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4930                 cmd_port, "port");
4931 cmdline_parse_token_string_t cmd_gso_show_keyword =
4932         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4933                                 cmd_keyword, "gso");
4934 cmdline_parse_token_num_t cmd_gso_show_pid =
4935         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4936                                 cmd_pid, UINT16);
4937
4938 cmdline_parse_inst_t cmd_gso_show = {
4939         .f = cmd_gso_show_parsed,
4940         .data = NULL,
4941         .help_str = "show port <port_id> gso",
4942         .tokens = {
4943                 (void *)&cmd_gso_show_show,
4944                 (void *)&cmd_gso_show_port,
4945                 (void *)&cmd_gso_show_pid,
4946                 (void *)&cmd_gso_show_keyword,
4947                 NULL,
4948         },
4949 };
4950
4951 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4952 struct cmd_set_flush_rx {
4953         cmdline_fixed_string_t set;
4954         cmdline_fixed_string_t flush_rx;
4955         cmdline_fixed_string_t mode;
4956 };
4957
4958 static void
4959 cmd_set_flush_rx_parsed(void *parsed_result,
4960                 __attribute__((unused)) struct cmdline *cl,
4961                 __attribute__((unused)) void *data)
4962 {
4963         struct cmd_set_flush_rx *res = parsed_result;
4964         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4965 }
4966
4967 cmdline_parse_token_string_t cmd_setflushrx_set =
4968         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4969                         set, "set");
4970 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4971         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4972                         flush_rx, "flush_rx");
4973 cmdline_parse_token_string_t cmd_setflushrx_mode =
4974         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4975                         mode, "on#off");
4976
4977
4978 cmdline_parse_inst_t cmd_set_flush_rx = {
4979         .f = cmd_set_flush_rx_parsed,
4980         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4981         .data = NULL,
4982         .tokens = {
4983                 (void *)&cmd_setflushrx_set,
4984                 (void *)&cmd_setflushrx_flush_rx,
4985                 (void *)&cmd_setflushrx_mode,
4986                 NULL,
4987         },
4988 };
4989
4990 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4991 struct cmd_set_link_check {
4992         cmdline_fixed_string_t set;
4993         cmdline_fixed_string_t link_check;
4994         cmdline_fixed_string_t mode;
4995 };
4996
4997 static void
4998 cmd_set_link_check_parsed(void *parsed_result,
4999                 __attribute__((unused)) struct cmdline *cl,
5000                 __attribute__((unused)) void *data)
5001 {
5002         struct cmd_set_link_check *res = parsed_result;
5003         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5004 }
5005
5006 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5007         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5008                         set, "set");
5009 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5010         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5011                         link_check, "link_check");
5012 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5013         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5014                         mode, "on#off");
5015
5016
5017 cmdline_parse_inst_t cmd_set_link_check = {
5018         .f = cmd_set_link_check_parsed,
5019         .help_str = "set link_check on|off: Enable/Disable link status check "
5020                     "when starting/stopping a port",
5021         .data = NULL,
5022         .tokens = {
5023                 (void *)&cmd_setlinkcheck_set,
5024                 (void *)&cmd_setlinkcheck_link_check,
5025                 (void *)&cmd_setlinkcheck_mode,
5026                 NULL,
5027         },
5028 };
5029
5030 /* *** SET NIC BYPASS MODE *** */
5031 struct cmd_set_bypass_mode_result {
5032         cmdline_fixed_string_t set;
5033         cmdline_fixed_string_t bypass;
5034         cmdline_fixed_string_t mode;
5035         cmdline_fixed_string_t value;
5036         portid_t port_id;
5037 };
5038
5039 static void
5040 cmd_set_bypass_mode_parsed(void *parsed_result,
5041                 __attribute__((unused)) struct cmdline *cl,
5042                 __attribute__((unused)) void *data)
5043 {
5044         struct cmd_set_bypass_mode_result *res = parsed_result;
5045         portid_t port_id = res->port_id;
5046         int32_t rc = -EINVAL;
5047
5048 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5049         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5050
5051         if (!strcmp(res->value, "bypass"))
5052                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5053         else if (!strcmp(res->value, "isolate"))
5054                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5055         else
5056                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5057
5058         /* Set the bypass mode for the relevant port. */
5059         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5060 #endif
5061         if (rc != 0)
5062                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5063 }
5064
5065 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5066         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5067                         set, "set");
5068 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5069         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5070                         bypass, "bypass");
5071 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5072         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5073                         mode, "mode");
5074 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5075         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5076                         value, "normal#bypass#isolate");
5077 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5078         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5079                                 port_id, UINT16);
5080
5081 cmdline_parse_inst_t cmd_set_bypass_mode = {
5082         .f = cmd_set_bypass_mode_parsed,
5083         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5084                     "Set the NIC bypass mode for port_id",
5085         .data = NULL,
5086         .tokens = {
5087                 (void *)&cmd_setbypass_mode_set,
5088                 (void *)&cmd_setbypass_mode_bypass,
5089                 (void *)&cmd_setbypass_mode_mode,
5090                 (void *)&cmd_setbypass_mode_value,
5091                 (void *)&cmd_setbypass_mode_port,
5092                 NULL,
5093         },
5094 };
5095
5096 /* *** SET NIC BYPASS EVENT *** */
5097 struct cmd_set_bypass_event_result {
5098         cmdline_fixed_string_t set;
5099         cmdline_fixed_string_t bypass;
5100         cmdline_fixed_string_t event;
5101         cmdline_fixed_string_t event_value;
5102         cmdline_fixed_string_t mode;
5103         cmdline_fixed_string_t mode_value;
5104         portid_t port_id;
5105 };
5106
5107 static void
5108 cmd_set_bypass_event_parsed(void *parsed_result,
5109                 __attribute__((unused)) struct cmdline *cl,
5110                 __attribute__((unused)) void *data)
5111 {
5112         int32_t rc = -EINVAL;
5113         struct cmd_set_bypass_event_result *res = parsed_result;
5114         portid_t port_id = res->port_id;
5115
5116 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5117         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5118         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5119
5120         if (!strcmp(res->event_value, "timeout"))
5121                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5122         else if (!strcmp(res->event_value, "os_on"))
5123                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5124         else if (!strcmp(res->event_value, "os_off"))
5125                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5126         else if (!strcmp(res->event_value, "power_on"))
5127                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5128         else if (!strcmp(res->event_value, "power_off"))
5129                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5130         else
5131                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5132
5133         if (!strcmp(res->mode_value, "bypass"))
5134                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5135         else if (!strcmp(res->mode_value, "isolate"))
5136                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5137         else
5138                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5139
5140         /* Set the watchdog timeout. */
5141         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5142
5143                 rc = -EINVAL;
5144                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5145                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5146                                                            bypass_timeout);
5147                 }
5148                 if (rc != 0) {
5149                         printf("Failed to set timeout value %u "
5150                         "for port %d, errto code: %d.\n",
5151                         bypass_timeout, port_id, rc);
5152                 }
5153         }
5154
5155         /* Set the bypass event to transition to bypass mode. */
5156         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5157                                               bypass_mode);
5158 #endif
5159
5160         if (rc != 0)
5161                 printf("\t Failed to set bypass event for port = %d.\n",
5162                        port_id);
5163 }
5164
5165 cmdline_parse_token_string_t cmd_setbypass_event_set =
5166         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5167                         set, "set");
5168 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5169         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5170                         bypass, "bypass");
5171 cmdline_parse_token_string_t cmd_setbypass_event_event =
5172         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5173                         event, "event");
5174 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5175         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5176                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5177 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5178         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5179                         mode, "mode");
5180 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5181         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5182                         mode_value, "normal#bypass#isolate");
5183 cmdline_parse_token_num_t cmd_setbypass_event_port =
5184         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5185                                 port_id, UINT16);
5186
5187 cmdline_parse_inst_t cmd_set_bypass_event = {
5188         .f = cmd_set_bypass_event_parsed,
5189         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5190                 "power_off mode normal|bypass|isolate <port_id>: "
5191                 "Set the NIC bypass event mode for port_id",
5192         .data = NULL,
5193         .tokens = {
5194                 (void *)&cmd_setbypass_event_set,
5195                 (void *)&cmd_setbypass_event_bypass,
5196                 (void *)&cmd_setbypass_event_event,
5197                 (void *)&cmd_setbypass_event_event_value,
5198                 (void *)&cmd_setbypass_event_mode,
5199                 (void *)&cmd_setbypass_event_mode_value,
5200                 (void *)&cmd_setbypass_event_port,
5201                 NULL,
5202         },
5203 };
5204
5205
5206 /* *** SET NIC BYPASS TIMEOUT *** */
5207 struct cmd_set_bypass_timeout_result {
5208         cmdline_fixed_string_t set;
5209         cmdline_fixed_string_t bypass;
5210         cmdline_fixed_string_t timeout;
5211         cmdline_fixed_string_t value;
5212 };
5213
5214 static void
5215 cmd_set_bypass_timeout_parsed(void *parsed_result,
5216                 __attribute__((unused)) struct cmdline *cl,
5217                 __attribute__((unused)) void *data)
5218 {
5219         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5220
5221 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5222         if (!strcmp(res->value, "1.5"))
5223                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5224         else if (!strcmp(res->value, "2"))
5225                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5226         else if (!strcmp(res->value, "3"))
5227                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5228         else if (!strcmp(res->value, "4"))
5229                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5230         else if (!strcmp(res->value, "8"))
5231                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5232         else if (!strcmp(res->value, "16"))
5233                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5234         else if (!strcmp(res->value, "32"))
5235                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5236         else
5237                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5238 #endif
5239 }
5240
5241 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5242         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5243                         set, "set");
5244 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5245         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5246                         bypass, "bypass");
5247 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5248         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5249                         timeout, "timeout");
5250 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5251         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5252                         value, "0#1.5#2#3#4#8#16#32");
5253
5254 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5255         .f = cmd_set_bypass_timeout_parsed,
5256         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5257                 "Set the NIC bypass watchdog timeout in seconds",
5258         .data = NULL,
5259         .tokens = {
5260                 (void *)&cmd_setbypass_timeout_set,
5261                 (void *)&cmd_setbypass_timeout_bypass,
5262                 (void *)&cmd_setbypass_timeout_timeout,
5263                 (void *)&cmd_setbypass_timeout_value,
5264                 NULL,
5265         },
5266 };
5267
5268 /* *** SHOW NIC BYPASS MODE *** */
5269 struct cmd_show_bypass_config_result {
5270         cmdline_fixed_string_t show;
5271         cmdline_fixed_string_t bypass;
5272         cmdline_fixed_string_t config;
5273         portid_t port_id;
5274 };
5275
5276 static void
5277 cmd_show_bypass_config_parsed(void *parsed_result,
5278                 __attribute__((unused)) struct cmdline *cl,
5279                 __attribute__((unused)) void *data)
5280 {
5281         struct cmd_show_bypass_config_result *res = parsed_result;
5282         portid_t port_id = res->port_id;
5283         int rc = -EINVAL;
5284 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5285         uint32_t event_mode;
5286         uint32_t bypass_mode;
5287         uint32_t timeout = bypass_timeout;
5288         int i;
5289
5290         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5291                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5292         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5293                 {"UNKNOWN", "normal", "bypass", "isolate"};
5294         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5295                 "NONE",
5296                 "OS/board on",
5297                 "power supply on",
5298                 "OS/board off",
5299                 "power supply off",
5300                 "timeout"};
5301         int num_events = (sizeof events) / (sizeof events[0]);
5302
5303         /* Display the bypass mode.*/
5304         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5305                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5306                 return;
5307         }
5308         else {
5309                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5310                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5311
5312                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5313         }
5314
5315         /* Display the bypass timeout.*/
5316         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5317                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5318
5319         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5320
5321         /* Display the bypass events and associated modes. */
5322         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5323
5324                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5325                         printf("\tFailed to get bypass mode for event = %s\n",
5326                                 events[i]);
5327                 } else {
5328                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5329                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5330
5331                         printf("\tbypass event: %-16s = %s\n", events[i],
5332                                 modes[event_mode]);
5333                 }
5334         }
5335 #endif
5336         if (rc != 0)
5337                 printf("\tFailed to get bypass configuration for port = %d\n",
5338                        port_id);
5339 }
5340
5341 cmdline_parse_token_string_t cmd_showbypass_config_show =
5342         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5343                         show, "show");
5344 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5345         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5346                         bypass, "bypass");
5347 cmdline_parse_token_string_t cmd_showbypass_config_config =
5348         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5349                         config, "config");
5350 cmdline_parse_token_num_t cmd_showbypass_config_port =
5351         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5352                                 port_id, UINT16);
5353
5354 cmdline_parse_inst_t cmd_show_bypass_config = {
5355         .f = cmd_show_bypass_config_parsed,
5356         .help_str = "show bypass config <port_id>: "
5357                     "Show the NIC bypass config for port_id",
5358         .data = NULL,
5359         .tokens = {
5360                 (void *)&cmd_showbypass_config_show,
5361                 (void *)&cmd_showbypass_config_bypass,
5362                 (void *)&cmd_showbypass_config_config,
5363                 (void *)&cmd_showbypass_config_port,
5364                 NULL,
5365         },
5366 };
5367
5368 #ifdef RTE_LIBRTE_PMD_BOND
5369 /* *** SET BONDING MODE *** */
5370 struct cmd_set_bonding_mode_result {
5371         cmdline_fixed_string_t set;
5372         cmdline_fixed_string_t bonding;
5373         cmdline_fixed_string_t mode;
5374         uint8_t value;
5375         portid_t port_id;
5376 };
5377
5378 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5379                 __attribute__((unused))  struct cmdline *cl,
5380                 __attribute__((unused)) void *data)
5381 {
5382         struct cmd_set_bonding_mode_result *res = parsed_result;
5383         portid_t port_id = res->port_id;
5384
5385         /* Set the bonding mode for the relevant port. */
5386         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5387                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5388 }
5389
5390 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5391 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5392                 set, "set");
5393 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5394 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5395                 bonding, "bonding");
5396 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5397 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5398                 mode, "mode");
5399 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5400 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5401                 value, UINT8);
5402 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5403 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5404                 port_id, UINT16);
5405
5406 cmdline_parse_inst_t cmd_set_bonding_mode = {
5407                 .f = cmd_set_bonding_mode_parsed,
5408                 .help_str = "set bonding mode <mode_value> <port_id>: "
5409                         "Set the bonding mode for port_id",
5410                 .data = NULL,
5411                 .tokens = {
5412                                 (void *) &cmd_setbonding_mode_set,
5413                                 (void *) &cmd_setbonding_mode_bonding,
5414                                 (void *) &cmd_setbonding_mode_mode,
5415                                 (void *) &cmd_setbonding_mode_value,
5416                                 (void *) &cmd_setbonding_mode_port,
5417                                 NULL
5418                 }
5419 };
5420
5421 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5422 struct cmd_set_bonding_lacp_dedicated_queues_result {
5423         cmdline_fixed_string_t set;
5424         cmdline_fixed_string_t bonding;
5425         cmdline_fixed_string_t lacp;
5426         cmdline_fixed_string_t dedicated_queues;
5427         portid_t port_id;
5428         cmdline_fixed_string_t mode;
5429 };
5430
5431 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5432                 __attribute__((unused))  struct cmdline *cl,
5433                 __attribute__((unused)) void *data)
5434 {
5435         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5436         portid_t port_id = res->port_id;
5437         struct rte_port *port;
5438
5439         port = &ports[port_id];
5440
5441         /** Check if the port is not started **/
5442         if (port->port_status != RTE_PORT_STOPPED) {
5443                 printf("Please stop port %d first\n", port_id);
5444                 return;
5445         }
5446
5447         if (!strcmp(res->mode, "enable")) {
5448                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5449                         printf("Dedicate queues for LACP control packets"
5450                                         " enabled\n");
5451                 else
5452                         printf("Enabling dedicate queues for LACP control "
5453                                         "packets on port %d failed\n", port_id);
5454         } else if (!strcmp(res->mode, "disable")) {
5455                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5456                         printf("Dedicated queues for LACP control packets "
5457                                         "disabled\n");
5458                 else
5459                         printf("Disabling dedicated queues for LACP control "
5460                                         "traffic on port %d failed\n", port_id);
5461         }
5462 }
5463
5464 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5465 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5466                 set, "set");
5467 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5468 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5469                 bonding, "bonding");
5470 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5471 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5472                 lacp, "lacp");
5473 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5474 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5475                 dedicated_queues, "dedicated_queues");
5476 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5477 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5478                 port_id, UINT16);
5479 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5480 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5481                 mode, "enable#disable");
5482
5483 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5484                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5485                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5486                         "enable|disable: "
5487                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5488                 .data = NULL,
5489                 .tokens = {
5490                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5491                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5492                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5493                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5494                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5495                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5496                         NULL
5497                 }
5498 };
5499
5500 /* *** SET BALANCE XMIT POLICY *** */
5501 struct cmd_set_bonding_balance_xmit_policy_result {
5502         cmdline_fixed_string_t set;
5503         cmdline_fixed_string_t bonding;
5504         cmdline_fixed_string_t balance_xmit_policy;
5505         portid_t port_id;
5506         cmdline_fixed_string_t policy;
5507 };
5508
5509 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5510                 __attribute__((unused))  struct cmdline *cl,
5511                 __attribute__((unused)) void *data)
5512 {
5513         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5514         portid_t port_id = res->port_id;
5515         uint8_t policy;
5516
5517         if (!strcmp(res->policy, "l2")) {
5518                 policy = BALANCE_XMIT_POLICY_LAYER2;
5519         } else if (!strcmp(res->policy, "l23")) {
5520                 policy = BALANCE_XMIT_POLICY_LAYER23;
5521         } else if (!strcmp(res->policy, "l34")) {
5522                 policy = BALANCE_XMIT_POLICY_LAYER34;
5523         } else {
5524                 printf("\t Invalid xmit policy selection");
5525                 return;
5526         }
5527
5528         /* Set the bonding mode for the relevant port. */
5529         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5530                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5531                                 port_id);
5532         }
5533 }
5534
5535 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5536 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5537                 set, "set");
5538 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5539 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5540                 bonding, "bonding");
5541 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5542 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5543                 balance_xmit_policy, "balance_xmit_policy");
5544 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5545 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5546                 port_id, UINT16);
5547 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5548 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5549                 policy, "l2#l23#l34");
5550
5551 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5552                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5553                 .help_str = "set bonding balance_xmit_policy <port_id> "
5554                         "l2|l23|l34: "
5555                         "Set the bonding balance_xmit_policy for port_id",
5556                 .data = NULL,
5557                 .tokens = {
5558                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5559                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5560                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5561                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5562                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5563                                 NULL
5564                 }
5565 };
5566
5567 /* *** SHOW NIC BONDING CONFIGURATION *** */
5568 struct cmd_show_bonding_config_result {
5569         cmdline_fixed_string_t show;
5570         cmdline_fixed_string_t bonding;
5571         cmdline_fixed_string_t config;
5572         portid_t port_id;
5573 };
5574
5575 static void cmd_show_bonding_config_parsed(void *parsed_result,
5576                 __attribute__((unused))  struct cmdline *cl,
5577                 __attribute__((unused)) void *data)
5578 {
5579         struct cmd_show_bonding_config_result *res = parsed_result;
5580         int bonding_mode, agg_mode;
5581         portid_t slaves[RTE_MAX_ETHPORTS];
5582         int num_slaves, num_active_slaves;
5583         int primary_id;
5584         int i;
5585         portid_t port_id = res->port_id;
5586
5587         /* Display the bonding mode.*/
5588         bonding_mode = rte_eth_bond_mode_get(port_id);
5589         if (bonding_mode < 0) {
5590                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5591                 return;
5592         } else
5593                 printf("\tBonding mode: %d\n", bonding_mode);
5594
5595         if (bonding_mode == BONDING_MODE_BALANCE) {
5596                 int balance_xmit_policy;
5597
5598                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5599                 if (balance_xmit_policy < 0) {
5600                         printf("\tFailed to get balance xmit policy for port = %d\n",
5601                                         port_id);
5602                         return;
5603                 } else {
5604                         printf("\tBalance Xmit Policy: ");
5605
5606                         switch (balance_xmit_policy) {
5607                         case BALANCE_XMIT_POLICY_LAYER2:
5608                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5609                                 break;
5610                         case BALANCE_XMIT_POLICY_LAYER23:
5611                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5612                                 break;
5613                         case BALANCE_XMIT_POLICY_LAYER34:
5614                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5615                                 break;
5616                         }
5617                         printf("\n");
5618                 }
5619         }
5620
5621         if (bonding_mode == BONDING_MODE_8023AD) {
5622                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5623                 printf("\tIEEE802.3AD Aggregator Mode: ");
5624                 switch (agg_mode) {
5625                 case AGG_BANDWIDTH:
5626                         printf("bandwidth");
5627                         break;
5628                 case AGG_STABLE:
5629                         printf("stable");
5630                         break;
5631                 case AGG_COUNT:
5632                         printf("count");
5633                         break;
5634                 }
5635                 printf("\n");
5636         }
5637
5638         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5639
5640         if (num_slaves < 0) {
5641                 printf("\tFailed to get slave list for port = %d\n", port_id);
5642                 return;
5643         }
5644         if (num_slaves > 0) {
5645                 printf("\tSlaves (%d): [", num_slaves);
5646                 for (i = 0; i < num_slaves - 1; i++)
5647                         printf("%d ", slaves[i]);
5648
5649                 printf("%d]\n", slaves[num_slaves - 1]);
5650         } else {
5651                 printf("\tSlaves: []\n");
5652
5653         }
5654
5655         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5656                         RTE_MAX_ETHPORTS);
5657
5658         if (num_active_slaves < 0) {
5659                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5660                 return;
5661         }
5662         if (num_active_slaves > 0) {
5663                 printf("\tActive Slaves (%d): [", num_active_slaves);
5664                 for (i = 0; i < num_active_slaves - 1; i++)
5665                         printf("%d ", slaves[i]);
5666
5667                 printf("%d]\n", slaves[num_active_slaves - 1]);
5668
5669         } else {
5670                 printf("\tActive Slaves: []\n");
5671
5672         }
5673
5674         primary_id = rte_eth_bond_primary_get(port_id);
5675         if (primary_id < 0) {
5676                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5677                 return;
5678         } else
5679                 printf("\tPrimary: [%d]\n", primary_id);
5680
5681 }
5682
5683 cmdline_parse_token_string_t cmd_showbonding_config_show =
5684 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5685                 show, "show");
5686 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5687 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5688                 bonding, "bonding");
5689 cmdline_parse_token_string_t cmd_showbonding_config_config =
5690 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5691                 config, "config");
5692 cmdline_parse_token_num_t cmd_showbonding_config_port =
5693 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5694                 port_id, UINT16);
5695
5696 cmdline_parse_inst_t cmd_show_bonding_config = {
5697                 .f = cmd_show_bonding_config_parsed,
5698                 .help_str = "show bonding config <port_id>: "
5699                         "Show the bonding config for port_id",
5700                 .data = NULL,
5701                 .tokens = {
5702                                 (void *)&cmd_showbonding_config_show,
5703                                 (void *)&cmd_showbonding_config_bonding,
5704                                 (void *)&cmd_showbonding_config_config,
5705                                 (void *)&cmd_showbonding_config_port,
5706                                 NULL
5707                 }
5708 };
5709
5710 /* *** SET BONDING PRIMARY *** */
5711 struct cmd_set_bonding_primary_result {
5712         cmdline_fixed_string_t set;
5713         cmdline_fixed_string_t bonding;
5714         cmdline_fixed_string_t primary;
5715         portid_t slave_id;
5716         portid_t port_id;
5717 };
5718
5719 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5720                 __attribute__((unused))  struct cmdline *cl,
5721                 __attribute__((unused)) void *data)
5722 {
5723         struct cmd_set_bonding_primary_result *res = parsed_result;
5724         portid_t master_port_id = res->port_id;
5725         portid_t slave_port_id = res->slave_id;
5726
5727         /* Set the primary slave for a bonded device. */
5728         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5729                 printf("\t Failed to set primary slave for port = %d.\n",
5730                                 master_port_id);
5731                 return;
5732         }
5733         init_port_config();
5734 }
5735
5736 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5737 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5738                 set, "set");
5739 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5740 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5741                 bonding, "bonding");
5742 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5743 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5744                 primary, "primary");
5745 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5746 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5747                 slave_id, UINT16);
5748 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5749 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5750                 port_id, UINT16);
5751
5752 cmdline_parse_inst_t cmd_set_bonding_primary = {
5753                 .f = cmd_set_bonding_primary_parsed,
5754                 .help_str = "set bonding primary <slave_id> <port_id>: "
5755                         "Set the primary slave for port_id",
5756                 .data = NULL,
5757                 .tokens = {
5758                                 (void *)&cmd_setbonding_primary_set,
5759                                 (void *)&cmd_setbonding_primary_bonding,
5760                                 (void *)&cmd_setbonding_primary_primary,
5761                                 (void *)&cmd_setbonding_primary_slave,
5762                                 (void *)&cmd_setbonding_primary_port,
5763                                 NULL
5764                 }
5765 };
5766
5767 /* *** ADD SLAVE *** */
5768 struct cmd_add_bonding_slave_result {
5769         cmdline_fixed_string_t add;
5770         cmdline_fixed_string_t bonding;
5771         cmdline_fixed_string_t slave;
5772         portid_t slave_id;
5773         portid_t port_id;
5774 };
5775
5776 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5777                 __attribute__((unused))  struct cmdline *cl,
5778                 __attribute__((unused)) void *data)
5779 {
5780         struct cmd_add_bonding_slave_result *res = parsed_result;
5781         portid_t master_port_id = res->port_id;
5782         portid_t slave_port_id = res->slave_id;
5783
5784         /* add the slave for a bonded device. */
5785         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5786                 printf("\t Failed to add slave %d to master port = %d.\n",
5787                                 slave_port_id, master_port_id);
5788                 return;
5789         }
5790         init_port_config();
5791         set_port_slave_flag(slave_port_id);
5792 }
5793
5794 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5795 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5796                 add, "add");
5797 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5798 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5799                 bonding, "bonding");
5800 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5801 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5802                 slave, "slave");
5803 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5804 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5805                 slave_id, UINT16);
5806 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5807 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5808                 port_id, UINT16);
5809
5810 cmdline_parse_inst_t cmd_add_bonding_slave = {
5811                 .f = cmd_add_bonding_slave_parsed,
5812                 .help_str = "add bonding slave <slave_id> <port_id>: "
5813                         "Add a slave device to a bonded device",
5814                 .data = NULL,
5815                 .tokens = {
5816                                 (void *)&cmd_addbonding_slave_add,
5817                                 (void *)&cmd_addbonding_slave_bonding,
5818                                 (void *)&cmd_addbonding_slave_slave,
5819                                 (void *)&cmd_addbonding_slave_slaveid,
5820                                 (void *)&cmd_addbonding_slave_port,
5821                                 NULL
5822                 }
5823 };
5824
5825 /* *** REMOVE SLAVE *** */
5826 struct cmd_remove_bonding_slave_result {
5827         cmdline_fixed_string_t remove;
5828         cmdline_fixed_string_t bonding;
5829         cmdline_fixed_string_t slave;
5830         portid_t slave_id;
5831         portid_t port_id;
5832 };
5833
5834 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5835                 __attribute__((unused))  struct cmdline *cl,
5836                 __attribute__((unused)) void *data)
5837 {
5838         struct cmd_remove_bonding_slave_result *res = parsed_result;
5839         portid_t master_port_id = res->port_id;
5840         portid_t slave_port_id = res->slave_id;
5841
5842         /* remove the slave from a bonded device. */
5843         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5844                 printf("\t Failed to remove slave %d from master port = %d.\n",
5845                                 slave_port_id, master_port_id);
5846                 return;
5847         }
5848         init_port_config();
5849         clear_port_slave_flag(slave_port_id);
5850 }
5851
5852 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5853                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5854                                 remove, "remove");
5855 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5856                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5857                                 bonding, "bonding");
5858 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5859                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5860                                 slave, "slave");
5861 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5862                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5863                                 slave_id, UINT16);
5864 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5865                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5866                                 port_id, UINT16);
5867
5868 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5869                 .f = cmd_remove_bonding_slave_parsed,
5870                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5871                         "Remove a slave device from a bonded device",
5872                 .data = NULL,
5873                 .tokens = {
5874                                 (void *)&cmd_removebonding_slave_remove,
5875                                 (void *)&cmd_removebonding_slave_bonding,
5876                                 (void *)&cmd_removebonding_slave_slave,
5877                                 (void *)&cmd_removebonding_slave_slaveid,
5878                                 (void *)&cmd_removebonding_slave_port,
5879                                 NULL
5880                 }
5881 };
5882
5883 /* *** CREATE BONDED DEVICE *** */
5884 struct cmd_create_bonded_device_result {
5885         cmdline_fixed_string_t create;
5886         cmdline_fixed_string_t bonded;
5887         cmdline_fixed_string_t device;
5888         uint8_t mode;
5889         uint8_t socket;
5890 };
5891
5892 static int bond_dev_num = 0;
5893
5894 static void cmd_create_bonded_device_parsed(void *parsed_result,
5895                 __attribute__((unused))  struct cmdline *cl,
5896                 __attribute__((unused)) void *data)
5897 {
5898         struct cmd_create_bonded_device_result *res = parsed_result;
5899         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5900         int port_id;
5901
5902         if (test_done == 0) {
5903                 printf("Please stop forwarding first\n");
5904                 return;
5905         }
5906
5907         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5908                         bond_dev_num++);
5909
5910         /* Create a new bonded device. */
5911         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5912         if (port_id < 0) {
5913                 printf("\t Failed to create bonded device.\n");
5914                 return;
5915         } else {
5916                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5917                                 port_id);
5918
5919                 /* Update number of ports */
5920                 nb_ports = rte_eth_dev_count_avail();
5921                 reconfig(port_id, res->socket);
5922                 rte_eth_promiscuous_enable(port_id);
5923         }
5924
5925 }
5926
5927 cmdline_parse_token_string_t cmd_createbonded_device_create =
5928                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5929                                 create, "create");
5930 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5931                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5932                                 bonded, "bonded");
5933 cmdline_parse_token_string_t cmd_createbonded_device_device =
5934                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5935                                 device, "device");
5936 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5937                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5938                                 mode, UINT8);
5939 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5940                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5941                                 socket, UINT8);
5942
5943 cmdline_parse_inst_t cmd_create_bonded_device = {
5944                 .f = cmd_create_bonded_device_parsed,
5945                 .help_str = "create bonded device <mode> <socket>: "
5946                         "Create a new bonded device with specific bonding mode and socket",
5947                 .data = NULL,
5948                 .tokens = {
5949                                 (void *)&cmd_createbonded_device_create,
5950                                 (void *)&cmd_createbonded_device_bonded,
5951                                 (void *)&cmd_createbonded_device_device,
5952                                 (void *)&cmd_createbonded_device_mode,
5953                                 (void *)&cmd_createbonded_device_socket,
5954                                 NULL
5955                 }
5956 };
5957
5958 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5959 struct cmd_set_bond_mac_addr_result {
5960         cmdline_fixed_string_t set;
5961         cmdline_fixed_string_t bonding;
5962         cmdline_fixed_string_t mac_addr;
5963         uint16_t port_num;
5964         struct ether_addr address;
5965 };
5966
5967 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5968                 __attribute__((unused))  struct cmdline *cl,
5969                 __attribute__((unused)) void *data)
5970 {
5971         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5972         int ret;
5973
5974         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5975                 return;
5976
5977         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5978
5979         /* check the return value and print it if is < 0 */
5980         if (ret < 0)
5981                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5982 }
5983
5984 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5985                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5986 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5987                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5988                                 "bonding");
5989 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5990                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5991                                 "mac_addr");
5992 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5993                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5994                                 port_num, UINT16);
5995 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5996                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5997
5998 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5999                 .f = cmd_set_bond_mac_addr_parsed,
6000                 .data = (void *) 0,
6001                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6002                 .tokens = {
6003                                 (void *)&cmd_set_bond_mac_addr_set,
6004                                 (void *)&cmd_set_bond_mac_addr_bonding,
6005                                 (void *)&cmd_set_bond_mac_addr_mac,
6006                                 (void *)&cmd_set_bond_mac_addr_portnum,
6007                                 (void *)&cmd_set_bond_mac_addr_addr,
6008                                 NULL
6009                 }
6010 };
6011
6012
6013 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6014 struct cmd_set_bond_mon_period_result {
6015         cmdline_fixed_string_t set;
6016         cmdline_fixed_string_t bonding;
6017         cmdline_fixed_string_t mon_period;
6018         uint16_t port_num;
6019         uint32_t period_ms;
6020 };
6021
6022 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6023                 __attribute__((unused))  struct cmdline *cl,
6024                 __attribute__((unused)) void *data)
6025 {
6026         struct cmd_set_bond_mon_period_result *res = parsed_result;
6027         int ret;
6028
6029         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6030
6031         /* check the return value and print it if is < 0 */
6032         if (ret < 0)
6033                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6034 }
6035
6036 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6037                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6038                                 set, "set");
6039 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6040                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6041                                 bonding, "bonding");
6042 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6043                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6044                                 mon_period,     "mon_period");
6045 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6046                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6047                                 port_num, UINT16);
6048 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6049                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6050                                 period_ms, UINT32);
6051
6052 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6053                 .f = cmd_set_bond_mon_period_parsed,
6054                 .data = (void *) 0,
6055                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6056                 .tokens = {
6057                                 (void *)&cmd_set_bond_mon_period_set,
6058                                 (void *)&cmd_set_bond_mon_period_bonding,
6059                                 (void *)&cmd_set_bond_mon_period_mon_period,
6060                                 (void *)&cmd_set_bond_mon_period_portnum,
6061                                 (void *)&cmd_set_bond_mon_period_period_ms,
6062                                 NULL
6063                 }
6064 };
6065
6066
6067
6068 struct cmd_set_bonding_agg_mode_policy_result {
6069         cmdline_fixed_string_t set;
6070         cmdline_fixed_string_t bonding;
6071         cmdline_fixed_string_t agg_mode;
6072         uint16_t port_num;
6073         cmdline_fixed_string_t policy;
6074 };
6075
6076
6077 static void
6078 cmd_set_bonding_agg_mode(void *parsed_result,
6079                 __attribute__((unused)) struct cmdline *cl,
6080                 __attribute__((unused)) void *data)
6081 {
6082         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6083         uint8_t policy = AGG_BANDWIDTH;
6084
6085         if (!strcmp(res->policy, "bandwidth"))
6086                 policy = AGG_BANDWIDTH;
6087         else if (!strcmp(res->policy, "stable"))
6088                 policy = AGG_STABLE;
6089         else if (!strcmp(res->policy, "count"))
6090                 policy = AGG_COUNT;
6091
6092         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6093 }
6094
6095
6096 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6097         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6098                                 set, "set");
6099 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6100         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6101                                 bonding, "bonding");
6102
6103 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6104         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6105                                 agg_mode, "agg_mode");
6106
6107 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6108         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6109                                 port_num, UINT16);
6110
6111 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6112         TOKEN_STRING_INITIALIZER(
6113                         struct cmd_set_bonding_balance_xmit_policy_result,
6114                 policy, "stable#bandwidth#count");
6115
6116 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6117         .f = cmd_set_bonding_agg_mode,
6118         .data = (void *) 0,
6119         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6120         .tokens = {
6121                         (void *)&cmd_set_bonding_agg_mode_set,
6122                         (void *)&cmd_set_bonding_agg_mode_bonding,
6123                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6124                         (void *)&cmd_set_bonding_agg_mode_portnum,
6125                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6126                         NULL
6127                 }
6128 };
6129
6130
6131 #endif /* RTE_LIBRTE_PMD_BOND */
6132
6133 /* *** SET FORWARDING MODE *** */
6134 struct cmd_set_fwd_mode_result {
6135         cmdline_fixed_string_t set;
6136         cmdline_fixed_string_t fwd;
6137         cmdline_fixed_string_t mode;
6138 };
6139
6140 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6141                                     __attribute__((unused)) struct cmdline *cl,
6142                                     __attribute__((unused)) void *data)
6143 {
6144         struct cmd_set_fwd_mode_result *res = parsed_result;
6145
6146         retry_enabled = 0;
6147         set_pkt_forwarding_mode(res->mode);
6148 }
6149
6150 cmdline_parse_token_string_t cmd_setfwd_set =
6151         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6152 cmdline_parse_token_string_t cmd_setfwd_fwd =
6153         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6154 cmdline_parse_token_string_t cmd_setfwd_mode =
6155         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6156                 "" /* defined at init */);
6157
6158 cmdline_parse_inst_t cmd_set_fwd_mode = {
6159         .f = cmd_set_fwd_mode_parsed,
6160         .data = NULL,
6161         .help_str = NULL, /* defined at init */
6162         .tokens = {
6163                 (void *)&cmd_setfwd_set,
6164                 (void *)&cmd_setfwd_fwd,
6165                 (void *)&cmd_setfwd_mode,
6166                 NULL,
6167         },
6168 };
6169
6170 static void cmd_set_fwd_mode_init(void)
6171 {
6172         char *modes, *c;
6173         static char token[128];
6174         static char help[256];
6175         cmdline_parse_token_string_t *token_struct;
6176
6177         modes = list_pkt_forwarding_modes();
6178         snprintf(help, sizeof(help), "set fwd %s: "
6179                 "Set packet forwarding mode", modes);
6180         cmd_set_fwd_mode.help_str = help;
6181
6182         /* string token separator is # */
6183         for (c = token; *modes != '\0'; modes++)
6184                 if (*modes == '|')
6185                         *c++ = '#';
6186                 else
6187                         *c++ = *modes;
6188         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6189         token_struct->string_data.str = token;
6190 }
6191
6192 /* *** SET RETRY FORWARDING MODE *** */
6193 struct cmd_set_fwd_retry_mode_result {
6194         cmdline_fixed_string_t set;
6195         cmdline_fixed_string_t fwd;
6196         cmdline_fixed_string_t mode;
6197         cmdline_fixed_string_t retry;
6198 };
6199
6200 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6201                             __attribute__((unused)) struct cmdline *cl,
6202                             __attribute__((unused)) void *data)
6203 {
6204         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6205
6206         retry_enabled = 1;
6207         set_pkt_forwarding_mode(res->mode);
6208 }
6209
6210 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6211         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6212                         set, "set");
6213 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6214         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6215                         fwd, "fwd");
6216 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6217         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6218                         mode,
6219                 "" /* defined at init */);
6220 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6221         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6222                         retry, "retry");
6223
6224 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6225         .f = cmd_set_fwd_retry_mode_parsed,
6226         .data = NULL,
6227         .help_str = NULL, /* defined at init */
6228         .tokens = {
6229                 (void *)&cmd_setfwd_retry_set,
6230                 (void *)&cmd_setfwd_retry_fwd,
6231                 (void *)&cmd_setfwd_retry_mode,
6232                 (void *)&cmd_setfwd_retry_retry,
6233                 NULL,
6234         },
6235 };
6236
6237 static void cmd_set_fwd_retry_mode_init(void)
6238 {
6239         char *modes, *c;
6240         static char token[128];
6241         static char help[256];
6242         cmdline_parse_token_string_t *token_struct;
6243
6244         modes = list_pkt_forwarding_retry_modes();
6245         snprintf(help, sizeof(help), "set fwd %s retry: "
6246                 "Set packet forwarding mode with retry", modes);
6247         cmd_set_fwd_retry_mode.help_str = help;
6248
6249         /* string token separator is # */
6250         for (c = token; *modes != '\0'; modes++)
6251                 if (*modes == '|')
6252                         *c++ = '#';
6253                 else
6254                         *c++ = *modes;
6255         token_struct = (cmdline_parse_token_string_t *)
6256                 cmd_set_fwd_retry_mode.tokens[2];
6257         token_struct->string_data.str = token;
6258 }
6259
6260 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6261 struct cmd_set_burst_tx_retry_result {
6262         cmdline_fixed_string_t set;
6263         cmdline_fixed_string_t burst;
6264         cmdline_fixed_string_t tx;
6265         cmdline_fixed_string_t delay;
6266         uint32_t time;
6267         cmdline_fixed_string_t retry;
6268         uint32_t retry_num;
6269 };
6270
6271 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6272                                         __attribute__((unused)) struct cmdline *cl,
6273                                         __attribute__((unused)) void *data)
6274 {
6275         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6276
6277         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6278                 && !strcmp(res->tx, "tx")) {
6279                 if (!strcmp(res->delay, "delay"))
6280                         burst_tx_delay_time = res->time;
6281                 if (!strcmp(res->retry, "retry"))
6282                         burst_tx_retry_num = res->retry_num;
6283         }
6284
6285 }
6286
6287 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6288         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6289 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6290         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6291                                  "burst");
6292 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6293         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6294 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6295         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6296 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6297         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6298 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6299         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6300 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6301         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6302
6303 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6304         .f = cmd_set_burst_tx_retry_parsed,
6305         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6306         .tokens = {
6307                 (void *)&cmd_set_burst_tx_retry_set,
6308                 (void *)&cmd_set_burst_tx_retry_burst,
6309                 (void *)&cmd_set_burst_tx_retry_tx,
6310                 (void *)&cmd_set_burst_tx_retry_delay,
6311                 (void *)&cmd_set_burst_tx_retry_time,
6312                 (void *)&cmd_set_burst_tx_retry_retry,
6313                 (void *)&cmd_set_burst_tx_retry_retry_num,
6314                 NULL,
6315         },
6316 };
6317
6318 /* *** SET PROMISC MODE *** */
6319 struct cmd_set_promisc_mode_result {
6320         cmdline_fixed_string_t set;
6321         cmdline_fixed_string_t promisc;
6322         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6323         uint16_t port_num;               /* valid if "allports" argument == 0 */
6324         cmdline_fixed_string_t mode;
6325 };
6326
6327 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6328                                         __attribute__((unused)) struct cmdline *cl,
6329                                         void *allports)
6330 {
6331         struct cmd_set_promisc_mode_result *res = parsed_result;
6332         int enable;
6333         portid_t i;
6334
6335         if (!strcmp(res->mode, "on"))
6336                 enable = 1;
6337         else
6338                 enable = 0;
6339
6340         /* all ports */
6341         if (allports) {
6342                 RTE_ETH_FOREACH_DEV(i) {
6343                         if (enable)
6344                                 rte_eth_promiscuous_enable(i);
6345                         else
6346                                 rte_eth_promiscuous_disable(i);
6347                 }
6348         }
6349         else {
6350                 if (enable)
6351                         rte_eth_promiscuous_enable(res->port_num);
6352                 else
6353                         rte_eth_promiscuous_disable(res->port_num);
6354         }
6355 }
6356
6357 cmdline_parse_token_string_t cmd_setpromisc_set =
6358         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6359 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6360         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6361                                  "promisc");
6362 cmdline_parse_token_string_t cmd_setpromisc_portall =
6363         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6364                                  "all");
6365 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6366         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6367                               UINT16);
6368 cmdline_parse_token_string_t cmd_setpromisc_mode =
6369         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6370                                  "on#off");
6371
6372 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6373         .f = cmd_set_promisc_mode_parsed,
6374         .data = (void *)1,
6375         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6376         .tokens = {
6377                 (void *)&cmd_setpromisc_set,
6378                 (void *)&cmd_setpromisc_promisc,
6379                 (void *)&cmd_setpromisc_portall,
6380                 (void *)&cmd_setpromisc_mode,
6381                 NULL,
6382         },
6383 };
6384
6385 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6386         .f = cmd_set_promisc_mode_parsed,
6387         .data = (void *)0,
6388         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6389         .tokens = {
6390                 (void *)&cmd_setpromisc_set,
6391                 (void *)&cmd_setpromisc_promisc,
6392                 (void *)&cmd_setpromisc_portnum,
6393                 (void *)&cmd_setpromisc_mode,
6394                 NULL,
6395         },
6396 };
6397
6398 /* *** SET ALLMULTI MODE *** */
6399 struct cmd_set_allmulti_mode_result {
6400         cmdline_fixed_string_t set;
6401         cmdline_fixed_string_t allmulti;
6402         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6403         uint16_t port_num;               /* valid if "allports" argument == 0 */
6404         cmdline_fixed_string_t mode;
6405 };
6406
6407 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6408                                         __attribute__((unused)) struct cmdline *cl,
6409                                         void *allports)
6410 {
6411         struct cmd_set_allmulti_mode_result *res = parsed_result;
6412         int enable;
6413         portid_t i;
6414
6415         if (!strcmp(res->mode, "on"))
6416                 enable = 1;
6417         else
6418                 enable = 0;
6419
6420         /* all ports */
6421         if (allports) {
6422                 RTE_ETH_FOREACH_DEV(i) {
6423                         if (enable)
6424                                 rte_eth_allmulticast_enable(i);
6425                         else
6426                                 rte_eth_allmulticast_disable(i);
6427                 }
6428         }
6429         else {
6430                 if (enable)
6431                         rte_eth_allmulticast_enable(res->port_num);
6432                 else
6433                         rte_eth_allmulticast_disable(res->port_num);
6434         }
6435 }
6436
6437 cmdline_parse_token_string_t cmd_setallmulti_set =
6438         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6439 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6440         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6441                                  "allmulti");
6442 cmdline_parse_token_string_t cmd_setallmulti_portall =
6443         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6444                                  "all");
6445 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6446         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6447                               UINT16);
6448 cmdline_parse_token_string_t cmd_setallmulti_mode =
6449         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6450                                  "on#off");
6451
6452 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6453         .f = cmd_set_allmulti_mode_parsed,
6454         .data = (void *)1,
6455         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6456         .tokens = {
6457                 (void *)&cmd_setallmulti_set,
6458                 (void *)&cmd_setallmulti_allmulti,
6459                 (void *)&cmd_setallmulti_portall,
6460                 (void *)&cmd_setallmulti_mode,
6461                 NULL,
6462         },
6463 };
6464
6465 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6466         .f = cmd_set_allmulti_mode_parsed,
6467         .data = (void *)0,
6468         .help_str = "set allmulti <port_id> on|off: "
6469                 "Set allmulti mode on port_id",
6470         .tokens = {
6471                 (void *)&cmd_setallmulti_set,
6472                 (void *)&cmd_setallmulti_allmulti,
6473                 (void *)&cmd_setallmulti_portnum,
6474                 (void *)&cmd_setallmulti_mode,
6475                 NULL,
6476         },
6477 };
6478
6479 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6480 struct cmd_link_flow_ctrl_set_result {
6481         cmdline_fixed_string_t set;
6482         cmdline_fixed_string_t flow_ctrl;
6483         cmdline_fixed_string_t rx;
6484         cmdline_fixed_string_t rx_lfc_mode;
6485         cmdline_fixed_string_t tx;
6486         cmdline_fixed_string_t tx_lfc_mode;
6487         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6488         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6489         cmdline_fixed_string_t autoneg_str;
6490         cmdline_fixed_string_t autoneg;
6491         cmdline_fixed_string_t hw_str;
6492         uint32_t high_water;
6493         cmdline_fixed_string_t lw_str;
6494         uint32_t low_water;
6495         cmdline_fixed_string_t pt_str;
6496         uint16_t pause_time;
6497         cmdline_fixed_string_t xon_str;
6498         uint16_t send_xon;
6499         portid_t port_id;
6500 };
6501
6502 cmdline_parse_token_string_t cmd_lfc_set_set =
6503         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6504                                 set, "set");
6505 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6506         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6507                                 flow_ctrl, "flow_ctrl");
6508 cmdline_parse_token_string_t cmd_lfc_set_rx =
6509         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6510                                 rx, "rx");
6511 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6512         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6513                                 rx_lfc_mode, "on#off");
6514 cmdline_parse_token_string_t cmd_lfc_set_tx =
6515         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6516                                 tx, "tx");
6517 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6518         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6519                                 tx_lfc_mode, "on#off");
6520 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6521         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6522                                 hw_str, "high_water");
6523 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6524         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6525                                 high_water, UINT32);
6526 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6527         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6528                                 lw_str, "low_water");
6529 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6530         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6531                                 low_water, UINT32);
6532 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6533         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6534                                 pt_str, "pause_time");
6535 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6536         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6537                                 pause_time, UINT16);
6538 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6539         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6540                                 xon_str, "send_xon");
6541 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6542         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6543                                 send_xon, UINT16);
6544 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6545         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6546                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6547 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6548         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6549                                 mac_ctrl_frame_fwd_mode, "on#off");
6550 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6551         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6552                                 autoneg_str, "autoneg");
6553 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6554         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6555                                 autoneg, "on#off");
6556 cmdline_parse_token_num_t cmd_lfc_set_portid =
6557         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6558                                 port_id, UINT16);
6559
6560 /* forward declaration */
6561 static void
6562 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6563                               void *data);
6564
6565 cmdline_parse_inst_t cmd_link_flow_control_set = {
6566         .f = cmd_link_flow_ctrl_set_parsed,
6567         .data = NULL,
6568         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6569                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6570                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6571         .tokens = {
6572                 (void *)&cmd_lfc_set_set,
6573                 (void *)&cmd_lfc_set_flow_ctrl,
6574                 (void *)&cmd_lfc_set_rx,
6575                 (void *)&cmd_lfc_set_rx_mode,
6576                 (void *)&cmd_lfc_set_tx,
6577                 (void *)&cmd_lfc_set_tx_mode,
6578                 (void *)&cmd_lfc_set_high_water,
6579                 (void *)&cmd_lfc_set_low_water,
6580                 (void *)&cmd_lfc_set_pause_time,
6581                 (void *)&cmd_lfc_set_send_xon,
6582                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6583                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6584                 (void *)&cmd_lfc_set_autoneg_str,
6585                 (void *)&cmd_lfc_set_autoneg,
6586                 (void *)&cmd_lfc_set_portid,
6587                 NULL,
6588         },
6589 };
6590
6591 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6592         .f = cmd_link_flow_ctrl_set_parsed,
6593         .data = (void *)&cmd_link_flow_control_set_rx,
6594         .help_str = "set flow_ctrl rx on|off <port_id>: "
6595                 "Change rx flow control parameter",
6596         .tokens = {
6597                 (void *)&cmd_lfc_set_set,
6598                 (void *)&cmd_lfc_set_flow_ctrl,
6599                 (void *)&cmd_lfc_set_rx,
6600                 (void *)&cmd_lfc_set_rx_mode,
6601                 (void *)&cmd_lfc_set_portid,
6602                 NULL,
6603         },
6604 };
6605
6606 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6607         .f = cmd_link_flow_ctrl_set_parsed,
6608         .data = (void *)&cmd_link_flow_control_set_tx,
6609         .help_str = "set flow_ctrl tx on|off <port_id>: "
6610                 "Change tx flow control parameter",
6611         .tokens = {
6612                 (void *)&cmd_lfc_set_set,
6613                 (void *)&cmd_lfc_set_flow_ctrl,
6614                 (void *)&cmd_lfc_set_tx,
6615                 (void *)&cmd_lfc_set_tx_mode,
6616                 (void *)&cmd_lfc_set_portid,
6617                 NULL,
6618         },
6619 };
6620
6621 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6622         .f = cmd_link_flow_ctrl_set_parsed,
6623         .data = (void *)&cmd_link_flow_control_set_hw,
6624         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6625                 "Change high water flow control parameter",
6626         .tokens = {
6627                 (void *)&cmd_lfc_set_set,
6628                 (void *)&cmd_lfc_set_flow_ctrl,
6629                 (void *)&cmd_lfc_set_high_water_str,
6630                 (void *)&cmd_lfc_set_high_water,
6631                 (void *)&cmd_lfc_set_portid,
6632                 NULL,
6633         },
6634 };
6635
6636 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6637         .f = cmd_link_flow_ctrl_set_parsed,
6638         .data = (void *)&cmd_link_flow_control_set_lw,
6639         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6640                 "Change low water flow control parameter",
6641         .tokens = {
6642                 (void *)&cmd_lfc_set_set,
6643                 (void *)&cmd_lfc_set_flow_ctrl,
6644                 (void *)&cmd_lfc_set_low_water_str,
6645                 (void *)&cmd_lfc_set_low_water,
6646                 (void *)&cmd_lfc_set_portid,
6647                 NULL,
6648         },
6649 };
6650
6651 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6652         .f = cmd_link_flow_ctrl_set_parsed,
6653         .data = (void *)&cmd_link_flow_control_set_pt,
6654         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6655                 "Change pause time flow control parameter",
6656         .tokens = {
6657                 (void *)&cmd_lfc_set_set,
6658                 (void *)&cmd_lfc_set_flow_ctrl,
6659                 (void *)&cmd_lfc_set_pause_time_str,
6660                 (void *)&cmd_lfc_set_pause_time,
6661                 (void *)&cmd_lfc_set_portid,
6662                 NULL,
6663         },
6664 };
6665
6666 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6667         .f = cmd_link_flow_ctrl_set_parsed,
6668         .data = (void *)&cmd_link_flow_control_set_xon,
6669         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6670                 "Change send_xon flow control parameter",
6671         .tokens = {
6672                 (void *)&cmd_lfc_set_set,
6673                 (void *)&cmd_lfc_set_flow_ctrl,
6674                 (void *)&cmd_lfc_set_send_xon_str,
6675                 (void *)&cmd_lfc_set_send_xon,
6676                 (void *)&cmd_lfc_set_portid,
6677                 NULL,
6678         },
6679 };
6680
6681 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6682         .f = cmd_link_flow_ctrl_set_parsed,
6683         .data = (void *)&cmd_link_flow_control_set_macfwd,
6684         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6685                 "Change mac ctrl fwd flow control parameter",
6686         .tokens = {
6687                 (void *)&cmd_lfc_set_set,
6688                 (void *)&cmd_lfc_set_flow_ctrl,
6689                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6690                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6691                 (void *)&cmd_lfc_set_portid,
6692                 NULL,
6693         },
6694 };
6695
6696 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6697         .f = cmd_link_flow_ctrl_set_parsed,
6698         .data = (void *)&cmd_link_flow_control_set_autoneg,
6699         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6700                 "Change autoneg flow control parameter",
6701         .tokens = {
6702                 (void *)&cmd_lfc_set_set,
6703                 (void *)&cmd_lfc_set_flow_ctrl,
6704                 (void *)&cmd_lfc_set_autoneg_str,
6705                 (void *)&cmd_lfc_set_autoneg,
6706                 (void *)&cmd_lfc_set_portid,
6707                 NULL,
6708         },
6709 };
6710
6711 static void
6712 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6713                               __attribute__((unused)) struct cmdline *cl,
6714                               void *data)
6715 {
6716         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6717         cmdline_parse_inst_t *cmd = data;
6718         struct rte_eth_fc_conf fc_conf;
6719         int rx_fc_en = 0;
6720         int tx_fc_en = 0;
6721         int ret;
6722
6723         /*
6724          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6725          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6726          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6727          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6728          */
6729         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6730                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6731         };
6732
6733         /* Partial command line, retrieve current configuration */
6734         if (cmd) {
6735                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6736                 if (ret != 0) {
6737                         printf("cannot get current flow ctrl parameters, return"
6738                                "code = %d\n", ret);
6739                         return;
6740                 }
6741
6742                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6743                     (fc_conf.mode == RTE_FC_FULL))
6744                         rx_fc_en = 1;
6745                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6746                     (fc_conf.mode == RTE_FC_FULL))
6747                         tx_fc_en = 1;
6748         }
6749
6750         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6751                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6752
6753         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6754                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6755
6756         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6757
6758         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6759                 fc_conf.high_water = res->high_water;
6760
6761         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6762                 fc_conf.low_water = res->low_water;
6763
6764         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6765                 fc_conf.pause_time = res->pause_time;
6766
6767         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6768                 fc_conf.send_xon = res->send_xon;
6769
6770         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6771                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6772                         fc_conf.mac_ctrl_frame_fwd = 1;
6773                 else
6774                         fc_conf.mac_ctrl_frame_fwd = 0;
6775         }
6776
6777         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6778                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6779
6780         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6781         if (ret != 0)
6782                 printf("bad flow contrl parameter, return code = %d \n", ret);
6783 }
6784
6785 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6786 struct cmd_priority_flow_ctrl_set_result {
6787         cmdline_fixed_string_t set;
6788         cmdline_fixed_string_t pfc_ctrl;
6789         cmdline_fixed_string_t rx;
6790         cmdline_fixed_string_t rx_pfc_mode;
6791         cmdline_fixed_string_t tx;
6792         cmdline_fixed_string_t tx_pfc_mode;
6793         uint32_t high_water;
6794         uint32_t low_water;
6795         uint16_t pause_time;
6796         uint8_t  priority;
6797         portid_t port_id;
6798 };
6799
6800 static void
6801 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6802                        __attribute__((unused)) struct cmdline *cl,
6803                        __attribute__((unused)) void *data)
6804 {
6805         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6806         struct rte_eth_pfc_conf pfc_conf;
6807         int rx_fc_enable, tx_fc_enable;
6808         int ret;
6809
6810         /*
6811          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6812          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6813          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6814          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6815          */
6816         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6817                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6818         };
6819
6820         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6821         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6822         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6823         pfc_conf.fc.high_water = res->high_water;
6824         pfc_conf.fc.low_water  = res->low_water;
6825         pfc_conf.fc.pause_time = res->pause_time;
6826         pfc_conf.priority      = res->priority;
6827
6828         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6829         if (ret != 0)
6830                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6831 }
6832
6833 cmdline_parse_token_string_t cmd_pfc_set_set =
6834         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6835                                 set, "set");
6836 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6837         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6838                                 pfc_ctrl, "pfc_ctrl");
6839 cmdline_parse_token_string_t cmd_pfc_set_rx =
6840         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6841                                 rx, "rx");
6842 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6843         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6844                                 rx_pfc_mode, "on#off");
6845 cmdline_parse_token_string_t cmd_pfc_set_tx =
6846         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6847                                 tx, "tx");
6848 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6849         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6850                                 tx_pfc_mode, "on#off");
6851 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6852         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6853                                 high_water, UINT32);
6854 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6855         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6856                                 low_water, UINT32);
6857 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6858         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6859                                 pause_time, UINT16);
6860 cmdline_parse_token_num_t cmd_pfc_set_priority =
6861         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6862                                 priority, UINT8);
6863 cmdline_parse_token_num_t cmd_pfc_set_portid =
6864         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6865                                 port_id, UINT16);
6866
6867 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6868         .f = cmd_priority_flow_ctrl_set_parsed,
6869         .data = NULL,
6870         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6871                 "<pause_time> <priority> <port_id>: "
6872                 "Configure the Ethernet priority flow control",
6873         .tokens = {
6874                 (void *)&cmd_pfc_set_set,
6875                 (void *)&cmd_pfc_set_flow_ctrl,
6876                 (void *)&cmd_pfc_set_rx,
6877                 (void *)&cmd_pfc_set_rx_mode,
6878                 (void *)&cmd_pfc_set_tx,
6879                 (void *)&cmd_pfc_set_tx_mode,
6880                 (void *)&cmd_pfc_set_high_water,
6881                 (void *)&cmd_pfc_set_low_water,
6882                 (void *)&cmd_pfc_set_pause_time,
6883                 (void *)&cmd_pfc_set_priority,
6884                 (void *)&cmd_pfc_set_portid,
6885                 NULL,
6886         },
6887 };
6888
6889 /* *** RESET CONFIGURATION *** */
6890 struct cmd_reset_result {
6891         cmdline_fixed_string_t reset;
6892         cmdline_fixed_string_t def;
6893 };
6894
6895 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6896                              struct cmdline *cl,
6897                              __attribute__((unused)) void *data)
6898 {
6899         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6900         set_def_fwd_config();
6901 }
6902
6903 cmdline_parse_token_string_t cmd_reset_set =
6904         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6905 cmdline_parse_token_string_t cmd_reset_def =
6906         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6907                                  "default");
6908
6909 cmdline_parse_inst_t cmd_reset = {
6910         .f = cmd_reset_parsed,
6911         .data = NULL,
6912         .help_str = "set default: Reset default forwarding configuration",
6913         .tokens = {
6914                 (void *)&cmd_reset_set,
6915                 (void *)&cmd_reset_def,
6916                 NULL,
6917         },
6918 };
6919
6920 /* *** START FORWARDING *** */
6921 struct cmd_start_result {
6922         cmdline_fixed_string_t start;
6923 };
6924
6925 cmdline_parse_token_string_t cmd_start_start =
6926         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6927
6928 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6929                              __attribute__((unused)) struct cmdline *cl,
6930                              __attribute__((unused)) void *data)
6931 {
6932         start_packet_forwarding(0);
6933 }
6934
6935 cmdline_parse_inst_t cmd_start = {
6936         .f = cmd_start_parsed,
6937         .data = NULL,
6938         .help_str = "start: Start packet forwarding",
6939         .tokens = {
6940                 (void *)&cmd_start_start,
6941                 NULL,
6942         },
6943 };
6944
6945 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6946 struct cmd_start_tx_first_result {
6947         cmdline_fixed_string_t start;
6948         cmdline_fixed_string_t tx_first;
6949 };
6950
6951 static void
6952 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6953                           __attribute__((unused)) struct cmdline *cl,
6954                           __attribute__((unused)) void *data)
6955 {
6956         start_packet_forwarding(1);
6957 }
6958
6959 cmdline_parse_token_string_t cmd_start_tx_first_start =
6960         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6961                                  "start");
6962 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6963         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6964                                  tx_first, "tx_first");
6965
6966 cmdline_parse_inst_t cmd_start_tx_first = {
6967         .f = cmd_start_tx_first_parsed,
6968         .data = NULL,
6969         .help_str = "start tx_first: Start packet forwarding, "
6970                 "after sending 1 burst of packets",
6971         .tokens = {
6972                 (void *)&cmd_start_tx_first_start,
6973                 (void *)&cmd_start_tx_first_tx_first,
6974                 NULL,
6975         },
6976 };
6977
6978 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6979 struct cmd_start_tx_first_n_result {
6980         cmdline_fixed_string_t start;
6981         cmdline_fixed_string_t tx_first;
6982         uint32_t tx_num;
6983 };
6984
6985 static void
6986 cmd_start_tx_first_n_parsed(void *parsed_result,
6987                           __attribute__((unused)) struct cmdline *cl,
6988                           __attribute__((unused)) void *data)
6989 {
6990         struct cmd_start_tx_first_n_result *res = parsed_result;
6991
6992         start_packet_forwarding(res->tx_num);
6993 }
6994
6995 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6996         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6997                         start, "start");
6998 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6999         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7000                         tx_first, "tx_first");
7001 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7002         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7003                         tx_num, UINT32);
7004
7005 cmdline_parse_inst_t cmd_start_tx_first_n = {
7006         .f = cmd_start_tx_first_n_parsed,
7007         .data = NULL,
7008         .help_str = "start tx_first <num>: "
7009                 "packet forwarding, after sending <num> bursts of packets",
7010         .tokens = {
7011                 (void *)&cmd_start_tx_first_n_start,
7012                 (void *)&cmd_start_tx_first_n_tx_first,
7013                 (void *)&cmd_start_tx_first_n_tx_num,
7014                 NULL,
7015         },
7016 };
7017
7018 /* *** SET LINK UP *** */
7019 struct cmd_set_link_up_result {
7020         cmdline_fixed_string_t set;
7021         cmdline_fixed_string_t link_up;
7022         cmdline_fixed_string_t port;
7023         portid_t port_id;
7024 };
7025
7026 cmdline_parse_token_string_t cmd_set_link_up_set =
7027         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7028 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7029         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7030                                 "link-up");
7031 cmdline_parse_token_string_t cmd_set_link_up_port =
7032         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7033 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7034         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7035
7036 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7037                              __attribute__((unused)) struct cmdline *cl,
7038                              __attribute__((unused)) void *data)
7039 {
7040         struct cmd_set_link_up_result *res = parsed_result;
7041         dev_set_link_up(res->port_id);
7042 }
7043
7044 cmdline_parse_inst_t cmd_set_link_up = {
7045         .f = cmd_set_link_up_parsed,
7046         .data = NULL,
7047         .help_str = "set link-up port <port id>",
7048         .tokens = {
7049                 (void *)&cmd_set_link_up_set,
7050                 (void *)&cmd_set_link_up_link_up,
7051                 (void *)&cmd_set_link_up_port,
7052                 (void *)&cmd_set_link_up_port_id,
7053                 NULL,
7054         },
7055 };
7056
7057 /* *** SET LINK DOWN *** */
7058 struct cmd_set_link_down_result {
7059         cmdline_fixed_string_t set;
7060         cmdline_fixed_string_t link_down;
7061         cmdline_fixed_string_t port;
7062         portid_t port_id;
7063 };
7064
7065 cmdline_parse_token_string_t cmd_set_link_down_set =
7066         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7067 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7068         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7069                                 "link-down");
7070 cmdline_parse_token_string_t cmd_set_link_down_port =
7071         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7072 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7073         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7074
7075 static void cmd_set_link_down_parsed(
7076                                 __attribute__((unused)) void *parsed_result,
7077                                 __attribute__((unused)) struct cmdline *cl,
7078                                 __attribute__((unused)) void *data)
7079 {
7080         struct cmd_set_link_down_result *res = parsed_result;
7081         dev_set_link_down(res->port_id);
7082 }
7083
7084 cmdline_parse_inst_t cmd_set_link_down = {
7085         .f = cmd_set_link_down_parsed,
7086         .data = NULL,
7087         .help_str = "set link-down port <port id>",
7088         .tokens = {
7089                 (void *)&cmd_set_link_down_set,
7090                 (void *)&cmd_set_link_down_link_down,
7091                 (void *)&cmd_set_link_down_port,
7092                 (void *)&cmd_set_link_down_port_id,
7093                 NULL,
7094         },
7095 };
7096
7097 /* *** SHOW CFG *** */
7098 struct cmd_showcfg_result {
7099         cmdline_fixed_string_t show;
7100         cmdline_fixed_string_t cfg;
7101         cmdline_fixed_string_t what;
7102 };
7103
7104 static void cmd_showcfg_parsed(void *parsed_result,
7105                                __attribute__((unused)) struct cmdline *cl,
7106                                __attribute__((unused)) void *data)
7107 {
7108         struct cmd_showcfg_result *res = parsed_result;
7109         if (!strcmp(res->what, "rxtx"))
7110                 rxtx_config_display();
7111         else if (!strcmp(res->what, "cores"))
7112                 fwd_lcores_config_display();
7113         else if (!strcmp(res->what, "fwd"))
7114                 pkt_fwd_config_display(&cur_fwd_config);
7115         else if (!strcmp(res->what, "txpkts"))
7116                 show_tx_pkt_segments();
7117 }
7118
7119 cmdline_parse_token_string_t cmd_showcfg_show =
7120         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7121 cmdline_parse_token_string_t cmd_showcfg_port =
7122         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7123 cmdline_parse_token_string_t cmd_showcfg_what =
7124         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7125                                  "rxtx#cores#fwd#txpkts");
7126
7127 cmdline_parse_inst_t cmd_showcfg = {
7128         .f = cmd_showcfg_parsed,
7129         .data = NULL,
7130         .help_str = "show config rxtx|cores|fwd|txpkts",
7131         .tokens = {
7132                 (void *)&cmd_showcfg_show,
7133                 (void *)&cmd_showcfg_port,
7134                 (void *)&cmd_showcfg_what,
7135                 NULL,
7136         },
7137 };
7138
7139 /* *** SHOW ALL PORT INFO *** */
7140 struct cmd_showportall_result {
7141         cmdline_fixed_string_t show;
7142         cmdline_fixed_string_t port;
7143         cmdline_fixed_string_t what;
7144         cmdline_fixed_string_t all;
7145 };
7146
7147 static void cmd_showportall_parsed(void *parsed_result,
7148                                 __attribute__((unused)) struct cmdline *cl,
7149                                 __attribute__((unused)) void *data)
7150 {
7151         portid_t i;
7152
7153         struct cmd_showportall_result *res = parsed_result;
7154         if (!strcmp(res->show, "clear")) {
7155                 if (!strcmp(res->what, "stats"))
7156                         RTE_ETH_FOREACH_DEV(i)
7157                                 nic_stats_clear(i);
7158                 else if (!strcmp(res->what, "xstats"))
7159                         RTE_ETH_FOREACH_DEV(i)
7160                                 nic_xstats_clear(i);
7161         } else if (!strcmp(res->what, "info"))
7162                 RTE_ETH_FOREACH_DEV(i)
7163                         port_infos_display(i);
7164         else if (!strcmp(res->what, "summary")) {
7165                 port_summary_header_display();
7166                 RTE_ETH_FOREACH_DEV(i)
7167                         port_summary_display(i);
7168         }
7169         else if (!strcmp(res->what, "stats"))
7170                 RTE_ETH_FOREACH_DEV(i)
7171                         nic_stats_display(i);
7172         else if (!strcmp(res->what, "xstats"))
7173                 RTE_ETH_FOREACH_DEV(i)
7174                         nic_xstats_display(i);
7175         else if (!strcmp(res->what, "fdir"))
7176                 RTE_ETH_FOREACH_DEV(i)
7177                         fdir_get_infos(i);
7178         else if (!strcmp(res->what, "stat_qmap"))
7179                 RTE_ETH_FOREACH_DEV(i)
7180                         nic_stats_mapping_display(i);
7181         else if (!strcmp(res->what, "dcb_tc"))
7182                 RTE_ETH_FOREACH_DEV(i)
7183                         port_dcb_info_display(i);
7184         else if (!strcmp(res->what, "cap"))
7185                 RTE_ETH_FOREACH_DEV(i)
7186                         port_offload_cap_display(i);
7187 }
7188
7189 cmdline_parse_token_string_t cmd_showportall_show =
7190         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7191                                  "show#clear");
7192 cmdline_parse_token_string_t cmd_showportall_port =
7193         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7194 cmdline_parse_token_string_t cmd_showportall_what =
7195         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7196                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7197 cmdline_parse_token_string_t cmd_showportall_all =
7198         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7199 cmdline_parse_inst_t cmd_showportall = {
7200         .f = cmd_showportall_parsed,
7201         .data = NULL,
7202         .help_str = "show|clear port "
7203                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7204         .tokens = {
7205                 (void *)&cmd_showportall_show,
7206                 (void *)&cmd_showportall_port,
7207                 (void *)&cmd_showportall_what,
7208                 (void *)&cmd_showportall_all,
7209                 NULL,
7210         },
7211 };
7212
7213 /* *** SHOW PORT INFO *** */
7214 struct cmd_showport_result {
7215         cmdline_fixed_string_t show;
7216         cmdline_fixed_string_t port;
7217         cmdline_fixed_string_t what;
7218         uint16_t portnum;
7219 };
7220
7221 static void cmd_showport_parsed(void *parsed_result,
7222                                 __attribute__((unused)) struct cmdline *cl,
7223                                 __attribute__((unused)) void *data)
7224 {
7225         struct cmd_showport_result *res = parsed_result;
7226         if (!strcmp(res->show, "clear")) {
7227                 if (!strcmp(res->what, "stats"))
7228                         nic_stats_clear(res->portnum);
7229                 else if (!strcmp(res->what, "xstats"))
7230                         nic_xstats_clear(res->portnum);
7231         } else if (!strcmp(res->what, "info"))
7232                 port_infos_display(res->portnum);
7233         else if (!strcmp(res->what, "summary")) {
7234                 port_summary_header_display();
7235                 port_summary_display(res->portnum);
7236         }
7237         else if (!strcmp(res->what, "stats"))
7238                 nic_stats_display(res->portnum);
7239         else if (!strcmp(res->what, "xstats"))
7240                 nic_xstats_display(res->portnum);
7241         else if (!strcmp(res->what, "fdir"))
7242                  fdir_get_infos(res->portnum);
7243         else if (!strcmp(res->what, "stat_qmap"))
7244                 nic_stats_mapping_display(res->portnum);
7245         else if (!strcmp(res->what, "dcb_tc"))
7246                 port_dcb_info_display(res->portnum);
7247         else if (!strcmp(res->what, "cap"))
7248                 port_offload_cap_display(res->portnum);
7249 }
7250
7251 cmdline_parse_token_string_t cmd_showport_show =
7252         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7253                                  "show#clear");
7254 cmdline_parse_token_string_t cmd_showport_port =
7255         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7256 cmdline_parse_token_string_t cmd_showport_what =
7257         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7258                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7259 cmdline_parse_token_num_t cmd_showport_portnum =
7260         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7261
7262 cmdline_parse_inst_t cmd_showport = {
7263         .f = cmd_showport_parsed,
7264         .data = NULL,
7265         .help_str = "show|clear port "
7266                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7267                 "<port_id>",
7268         .tokens = {
7269                 (void *)&cmd_showport_show,
7270                 (void *)&cmd_showport_port,
7271                 (void *)&cmd_showport_what,
7272                 (void *)&cmd_showport_portnum,
7273                 NULL,
7274         },
7275 };
7276
7277 /* *** SHOW QUEUE INFO *** */
7278 struct cmd_showqueue_result {
7279         cmdline_fixed_string_t show;
7280         cmdline_fixed_string_t type;
7281         cmdline_fixed_string_t what;
7282         uint16_t portnum;
7283         uint16_t queuenum;
7284 };
7285
7286 static void
7287 cmd_showqueue_parsed(void *parsed_result,
7288         __attribute__((unused)) struct cmdline *cl,
7289         __attribute__((unused)) void *data)
7290 {
7291         struct cmd_showqueue_result *res = parsed_result;
7292
7293         if (!strcmp(res->type, "rxq"))
7294                 rx_queue_infos_display(res->portnum, res->queuenum);
7295         else if (!strcmp(res->type, "txq"))
7296                 tx_queue_infos_display(res->portnum, res->queuenum);
7297 }
7298
7299 cmdline_parse_token_string_t cmd_showqueue_show =
7300         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7301 cmdline_parse_token_string_t cmd_showqueue_type =
7302         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7303 cmdline_parse_token_string_t cmd_showqueue_what =
7304         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7305 cmdline_parse_token_num_t cmd_showqueue_portnum =
7306         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7307 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7308         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7309
7310 cmdline_parse_inst_t cmd_showqueue = {
7311         .f = cmd_showqueue_parsed,
7312         .data = NULL,
7313         .help_str = "show rxq|txq info <port_id> <queue_id>",
7314         .tokens = {
7315                 (void *)&cmd_showqueue_show,
7316                 (void *)&cmd_showqueue_type,
7317                 (void *)&cmd_showqueue_what,
7318                 (void *)&cmd_showqueue_portnum,
7319                 (void *)&cmd_showqueue_queuenum,
7320                 NULL,
7321         },
7322 };
7323
7324 /* *** READ PORT REGISTER *** */
7325 struct cmd_read_reg_result {
7326         cmdline_fixed_string_t read;
7327         cmdline_fixed_string_t reg;
7328         portid_t port_id;
7329         uint32_t reg_off;
7330 };
7331
7332 static void
7333 cmd_read_reg_parsed(void *parsed_result,
7334                     __attribute__((unused)) struct cmdline *cl,
7335                     __attribute__((unused)) void *data)
7336 {
7337         struct cmd_read_reg_result *res = parsed_result;
7338         port_reg_display(res->port_id, res->reg_off);
7339 }
7340
7341 cmdline_parse_token_string_t cmd_read_reg_read =
7342         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7343 cmdline_parse_token_string_t cmd_read_reg_reg =
7344         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7345 cmdline_parse_token_num_t cmd_read_reg_port_id =
7346         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7347 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7348         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7349
7350 cmdline_parse_inst_t cmd_read_reg = {
7351         .f = cmd_read_reg_parsed,
7352         .data = NULL,
7353         .help_str = "read reg <port_id> <reg_off>",
7354         .tokens = {
7355                 (void *)&cmd_read_reg_read,
7356                 (void *)&cmd_read_reg_reg,
7357                 (void *)&cmd_read_reg_port_id,
7358                 (void *)&cmd_read_reg_reg_off,
7359                 NULL,
7360         },
7361 };
7362
7363 /* *** READ PORT REGISTER BIT FIELD *** */
7364 struct cmd_read_reg_bit_field_result {
7365         cmdline_fixed_string_t read;
7366         cmdline_fixed_string_t regfield;
7367         portid_t port_id;
7368         uint32_t reg_off;
7369         uint8_t bit1_pos;
7370         uint8_t bit2_pos;
7371 };
7372
7373 static void
7374 cmd_read_reg_bit_field_parsed(void *parsed_result,
7375                               __attribute__((unused)) struct cmdline *cl,
7376                               __attribute__((unused)) void *data)
7377 {
7378         struct cmd_read_reg_bit_field_result *res = parsed_result;
7379         port_reg_bit_field_display(res->port_id, res->reg_off,
7380                                    res->bit1_pos, res->bit2_pos);
7381 }
7382
7383 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7384         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7385                                  "read");
7386 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7387         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7388                                  regfield, "regfield");
7389 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7390         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7391                               UINT16);
7392 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7393         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7394                               UINT32);
7395 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7396         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7397                               UINT8);
7398 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7399         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7400                               UINT8);
7401
7402 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7403         .f = cmd_read_reg_bit_field_parsed,
7404         .data = NULL,
7405         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7406         "Read register bit field between bit_x and bit_y included",
7407         .tokens = {
7408                 (void *)&cmd_read_reg_bit_field_read,
7409                 (void *)&cmd_read_reg_bit_field_regfield,
7410                 (void *)&cmd_read_reg_bit_field_port_id,
7411                 (void *)&cmd_read_reg_bit_field_reg_off,
7412                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7413                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7414                 NULL,
7415         },
7416 };
7417
7418 /* *** READ PORT REGISTER BIT *** */
7419 struct cmd_read_reg_bit_result {
7420         cmdline_fixed_string_t read;
7421         cmdline_fixed_string_t regbit;
7422         portid_t port_id;
7423         uint32_t reg_off;
7424         uint8_t bit_pos;
7425 };
7426
7427 static void
7428 cmd_read_reg_bit_parsed(void *parsed_result,
7429                         __attribute__((unused)) struct cmdline *cl,
7430                         __attribute__((unused)) void *data)
7431 {
7432         struct cmd_read_reg_bit_result *res = parsed_result;
7433         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7434 }
7435
7436 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7437         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7438 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7439         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7440                                  regbit, "regbit");
7441 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7442         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7443 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7444         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7445 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7446         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7447
7448 cmdline_parse_inst_t cmd_read_reg_bit = {
7449         .f = cmd_read_reg_bit_parsed,
7450         .data = NULL,
7451         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7452         .tokens = {
7453                 (void *)&cmd_read_reg_bit_read,
7454                 (void *)&cmd_read_reg_bit_regbit,
7455                 (void *)&cmd_read_reg_bit_port_id,
7456                 (void *)&cmd_read_reg_bit_reg_off,
7457                 (void *)&cmd_read_reg_bit_bit_pos,
7458                 NULL,
7459         },
7460 };
7461
7462 /* *** WRITE PORT REGISTER *** */
7463 struct cmd_write_reg_result {
7464         cmdline_fixed_string_t write;
7465         cmdline_fixed_string_t reg;
7466         portid_t port_id;
7467         uint32_t reg_off;
7468         uint32_t value;
7469 };
7470
7471 static void
7472 cmd_write_reg_parsed(void *parsed_result,
7473                      __attribute__((unused)) struct cmdline *cl,
7474                      __attribute__((unused)) void *data)
7475 {
7476         struct cmd_write_reg_result *res = parsed_result;
7477         port_reg_set(res->port_id, res->reg_off, res->value);
7478 }
7479
7480 cmdline_parse_token_string_t cmd_write_reg_write =
7481         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7482 cmdline_parse_token_string_t cmd_write_reg_reg =
7483         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7484 cmdline_parse_token_num_t cmd_write_reg_port_id =
7485         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7486 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7487         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7488 cmdline_parse_token_num_t cmd_write_reg_value =
7489         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7490
7491 cmdline_parse_inst_t cmd_write_reg = {
7492         .f = cmd_write_reg_parsed,
7493         .data = NULL,
7494         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7495         .tokens = {
7496                 (void *)&cmd_write_reg_write,
7497                 (void *)&cmd_write_reg_reg,
7498                 (void *)&cmd_write_reg_port_id,
7499                 (void *)&cmd_write_reg_reg_off,
7500                 (void *)&cmd_write_reg_value,
7501                 NULL,
7502         },
7503 };
7504
7505 /* *** WRITE PORT REGISTER BIT FIELD *** */
7506 struct cmd_write_reg_bit_field_result {
7507         cmdline_fixed_string_t write;
7508         cmdline_fixed_string_t regfield;
7509         portid_t port_id;
7510         uint32_t reg_off;
7511         uint8_t bit1_pos;
7512         uint8_t bit2_pos;
7513         uint32_t value;
7514 };
7515
7516 static void
7517 cmd_write_reg_bit_field_parsed(void *parsed_result,
7518                                __attribute__((unused)) struct cmdline *cl,
7519                                __attribute__((unused)) void *data)
7520 {
7521         struct cmd_write_reg_bit_field_result *res = parsed_result;
7522         port_reg_bit_field_set(res->port_id, res->reg_off,
7523                           res->bit1_pos, res->bit2_pos, res->value);
7524 }
7525
7526 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7527         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7528                                  "write");
7529 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7530         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7531                                  regfield, "regfield");
7532 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7533         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7534                               UINT16);
7535 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7536         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7537                               UINT32);
7538 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7539         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7540                               UINT8);
7541 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7542         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7543                               UINT8);
7544 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7545         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7546                               UINT32);
7547
7548 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7549         .f = cmd_write_reg_bit_field_parsed,
7550         .data = NULL,
7551         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7552                 "<reg_value>: "
7553                 "Set register bit field between bit_x and bit_y included",
7554         .tokens = {
7555                 (void *)&cmd_write_reg_bit_field_write,
7556                 (void *)&cmd_write_reg_bit_field_regfield,
7557                 (void *)&cmd_write_reg_bit_field_port_id,
7558                 (void *)&cmd_write_reg_bit_field_reg_off,
7559                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7560                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7561                 (void *)&cmd_write_reg_bit_field_value,
7562                 NULL,
7563         },
7564 };
7565
7566 /* *** WRITE PORT REGISTER BIT *** */
7567 struct cmd_write_reg_bit_result {
7568         cmdline_fixed_string_t write;
7569         cmdline_fixed_string_t regbit;
7570         portid_t port_id;
7571         uint32_t reg_off;
7572         uint8_t bit_pos;
7573         uint8_t value;
7574 };
7575
7576 static void
7577 cmd_write_reg_bit_parsed(void *parsed_result,
7578                          __attribute__((unused)) struct cmdline *cl,
7579                          __attribute__((unused)) void *data)
7580 {
7581         struct cmd_write_reg_bit_result *res = parsed_result;
7582         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7583 }
7584
7585 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7586         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7587                                  "write");
7588 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7589         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7590                                  regbit, "regbit");
7591 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7592         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7593 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7594         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7595 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7596         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7597 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7598         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7599
7600 cmdline_parse_inst_t cmd_write_reg_bit = {
7601         .f = cmd_write_reg_bit_parsed,
7602         .data = NULL,
7603         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7604                 "0 <= bit_x <= 31",
7605         .tokens = {
7606                 (void *)&cmd_write_reg_bit_write,
7607                 (void *)&cmd_write_reg_bit_regbit,
7608                 (void *)&cmd_write_reg_bit_port_id,
7609                 (void *)&cmd_write_reg_bit_reg_off,
7610                 (void *)&cmd_write_reg_bit_bit_pos,
7611                 (void *)&cmd_write_reg_bit_value,
7612                 NULL,
7613         },
7614 };
7615
7616 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7617 struct cmd_read_rxd_txd_result {
7618         cmdline_fixed_string_t read;
7619         cmdline_fixed_string_t rxd_txd;
7620         portid_t port_id;
7621         uint16_t queue_id;
7622         uint16_t desc_id;
7623 };
7624
7625 static void
7626 cmd_read_rxd_txd_parsed(void *parsed_result,
7627                         __attribute__((unused)) struct cmdline *cl,
7628                         __attribute__((unused)) void *data)
7629 {
7630         struct cmd_read_rxd_txd_result *res = parsed_result;
7631
7632         if (!strcmp(res->rxd_txd, "rxd"))
7633                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7634         else if (!strcmp(res->rxd_txd, "txd"))
7635                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7636 }
7637
7638 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7639         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7640 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7641         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7642                                  "rxd#txd");
7643 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7644         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7645 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7646         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7647 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7648         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7649
7650 cmdline_parse_inst_t cmd_read_rxd_txd = {
7651         .f = cmd_read_rxd_txd_parsed,
7652         .data = NULL,
7653         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7654         .tokens = {
7655                 (void *)&cmd_read_rxd_txd_read,
7656                 (void *)&cmd_read_rxd_txd_rxd_txd,
7657                 (void *)&cmd_read_rxd_txd_port_id,
7658                 (void *)&cmd_read_rxd_txd_queue_id,
7659                 (void *)&cmd_read_rxd_txd_desc_id,
7660                 NULL,
7661         },
7662 };
7663
7664 /* *** QUIT *** */
7665 struct cmd_quit_result {
7666         cmdline_fixed_string_t quit;
7667 };
7668
7669 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7670                             struct cmdline *cl,
7671                             __attribute__((unused)) void *data)
7672 {
7673         pmd_test_exit();
7674         cmdline_quit(cl);
7675 }
7676
7677 cmdline_parse_token_string_t cmd_quit_quit =
7678         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7679
7680 cmdline_parse_inst_t cmd_quit = {
7681         .f = cmd_quit_parsed,
7682         .data = NULL,
7683         .help_str = "quit: Exit application",
7684         .tokens = {
7685                 (void *)&cmd_quit_quit,
7686                 NULL,
7687         },
7688 };
7689
7690 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7691 struct cmd_mac_addr_result {
7692         cmdline_fixed_string_t mac_addr_cmd;
7693         cmdline_fixed_string_t what;
7694         uint16_t port_num;
7695         struct ether_addr address;
7696 };
7697
7698 static void cmd_mac_addr_parsed(void *parsed_result,
7699                 __attribute__((unused)) struct cmdline *cl,
7700                 __attribute__((unused)) void *data)
7701 {
7702         struct cmd_mac_addr_result *res = parsed_result;
7703         int ret;
7704
7705         if (strcmp(res->what, "add") == 0)
7706                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7707         else if (strcmp(res->what, "set") == 0)
7708                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7709                                                        &res->address);
7710         else
7711                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7712
7713         /* check the return value and print it if is < 0 */
7714         if(ret < 0)
7715                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7716
7717 }
7718
7719 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7720         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7721                                 "mac_addr");
7722 cmdline_parse_token_string_t cmd_mac_addr_what =
7723         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7724                                 "add#remove#set");
7725 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7726                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7727                                         UINT16);
7728 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7729                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7730
7731 cmdline_parse_inst_t cmd_mac_addr = {
7732         .f = cmd_mac_addr_parsed,
7733         .data = (void *)0,
7734         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7735                         "Add/Remove/Set MAC address on port_id",
7736         .tokens = {
7737                 (void *)&cmd_mac_addr_cmd,
7738                 (void *)&cmd_mac_addr_what,
7739                 (void *)&cmd_mac_addr_portnum,
7740                 (void *)&cmd_mac_addr_addr,
7741                 NULL,
7742         },
7743 };
7744
7745 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7746 struct cmd_eth_peer_result {
7747         cmdline_fixed_string_t set;
7748         cmdline_fixed_string_t eth_peer;
7749         portid_t port_id;
7750         cmdline_fixed_string_t peer_addr;
7751 };
7752
7753 static void cmd_set_eth_peer_parsed(void *parsed_result,
7754                         __attribute__((unused)) struct cmdline *cl,
7755                         __attribute__((unused)) void *data)
7756 {
7757                 struct cmd_eth_peer_result *res = parsed_result;
7758
7759                 if (test_done == 0) {
7760                         printf("Please stop forwarding first\n");
7761                         return;
7762                 }
7763                 if (!strcmp(res->eth_peer, "eth-peer")) {
7764                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7765                         fwd_config_setup();
7766                 }
7767 }
7768 cmdline_parse_token_string_t cmd_eth_peer_set =
7769         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7770 cmdline_parse_token_string_t cmd_eth_peer =
7771         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7772 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7773         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7774 cmdline_parse_token_string_t cmd_eth_peer_addr =
7775         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7776
7777 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7778         .f = cmd_set_eth_peer_parsed,
7779         .data = NULL,
7780         .help_str = "set eth-peer <port_id> <peer_mac>",
7781         .tokens = {
7782                 (void *)&cmd_eth_peer_set,
7783                 (void *)&cmd_eth_peer,
7784                 (void *)&cmd_eth_peer_port_id,
7785                 (void *)&cmd_eth_peer_addr,
7786                 NULL,
7787         },
7788 };
7789
7790 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7791 struct cmd_set_qmap_result {
7792         cmdline_fixed_string_t set;
7793         cmdline_fixed_string_t qmap;
7794         cmdline_fixed_string_t what;
7795         portid_t port_id;
7796         uint16_t queue_id;
7797         uint8_t map_value;
7798 };
7799
7800 static void
7801 cmd_set_qmap_parsed(void *parsed_result,
7802                        __attribute__((unused)) struct cmdline *cl,
7803                        __attribute__((unused)) void *data)
7804 {
7805         struct cmd_set_qmap_result *res = parsed_result;
7806         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7807
7808         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7809 }
7810
7811 cmdline_parse_token_string_t cmd_setqmap_set =
7812         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7813                                  set, "set");
7814 cmdline_parse_token_string_t cmd_setqmap_qmap =
7815         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7816                                  qmap, "stat_qmap");
7817 cmdline_parse_token_string_t cmd_setqmap_what =
7818         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7819                                  what, "tx#rx");
7820 cmdline_parse_token_num_t cmd_setqmap_portid =
7821         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7822                               port_id, UINT16);
7823 cmdline_parse_token_num_t cmd_setqmap_queueid =
7824         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7825                               queue_id, UINT16);
7826 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7827         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7828                               map_value, UINT8);
7829
7830 cmdline_parse_inst_t cmd_set_qmap = {
7831         .f = cmd_set_qmap_parsed,
7832         .data = NULL,
7833         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7834                 "Set statistics mapping value on tx|rx queue_id of port_id",
7835         .tokens = {
7836                 (void *)&cmd_setqmap_set,
7837                 (void *)&cmd_setqmap_qmap,
7838                 (void *)&cmd_setqmap_what,
7839                 (void *)&cmd_setqmap_portid,
7840                 (void *)&cmd_setqmap_queueid,
7841                 (void *)&cmd_setqmap_mapvalue,
7842                 NULL,
7843         },
7844 };
7845
7846 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7847 struct cmd_set_xstats_hide_zero_result {
7848         cmdline_fixed_string_t keyword;
7849         cmdline_fixed_string_t name;
7850         cmdline_fixed_string_t on_off;
7851 };
7852
7853 static void
7854 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7855                         __attribute__((unused)) struct cmdline *cl,
7856                         __attribute__((unused)) void *data)
7857 {
7858         struct cmd_set_xstats_hide_zero_result *res;
7859         uint16_t on_off = 0;
7860
7861         res = parsed_result;
7862         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7863         set_xstats_hide_zero(on_off);
7864 }
7865
7866 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7867         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7868                                  keyword, "set");
7869 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7870         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7871                                  name, "xstats-hide-zero");
7872 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7873         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7874                                  on_off, "on#off");
7875
7876 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7877         .f = cmd_set_xstats_hide_zero_parsed,
7878         .data = NULL,
7879         .help_str = "set xstats-hide-zero on|off",
7880         .tokens = {
7881                 (void *)&cmd_set_xstats_hide_zero_keyword,
7882                 (void *)&cmd_set_xstats_hide_zero_name,
7883                 (void *)&cmd_set_xstats_hide_zero_on_off,
7884                 NULL,
7885         },
7886 };
7887
7888 /* *** CONFIGURE UNICAST HASH TABLE *** */
7889 struct cmd_set_uc_hash_table {
7890         cmdline_fixed_string_t set;
7891         cmdline_fixed_string_t port;
7892         portid_t port_id;
7893         cmdline_fixed_string_t what;
7894         struct ether_addr address;
7895         cmdline_fixed_string_t mode;
7896 };
7897
7898 static void
7899 cmd_set_uc_hash_parsed(void *parsed_result,
7900                        __attribute__((unused)) struct cmdline *cl,
7901                        __attribute__((unused)) void *data)
7902 {
7903         int ret=0;
7904         struct cmd_set_uc_hash_table *res = parsed_result;
7905
7906         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7907
7908         if (strcmp(res->what, "uta") == 0)
7909                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7910                                                 &res->address,(uint8_t)is_on);
7911         if (ret < 0)
7912                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7913
7914 }
7915
7916 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7917         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7918                                  set, "set");
7919 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7920         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7921                                  port, "port");
7922 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7923         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7924                               port_id, UINT16);
7925 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7926         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7927                                  what, "uta");
7928 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7929         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7930                                 address);
7931 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7932         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7933                                  mode, "on#off");
7934
7935 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7936         .f = cmd_set_uc_hash_parsed,
7937         .data = NULL,
7938         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7939         .tokens = {
7940                 (void *)&cmd_set_uc_hash_set,
7941                 (void *)&cmd_set_uc_hash_port,
7942                 (void *)&cmd_set_uc_hash_portid,
7943                 (void *)&cmd_set_uc_hash_what,
7944                 (void *)&cmd_set_uc_hash_mac,
7945                 (void *)&cmd_set_uc_hash_mode,
7946                 NULL,
7947         },
7948 };
7949
7950 struct cmd_set_uc_all_hash_table {
7951         cmdline_fixed_string_t set;
7952         cmdline_fixed_string_t port;
7953         portid_t port_id;
7954         cmdline_fixed_string_t what;
7955         cmdline_fixed_string_t value;
7956         cmdline_fixed_string_t mode;
7957 };
7958
7959 static void
7960 cmd_set_uc_all_hash_parsed(void *parsed_result,
7961                        __attribute__((unused)) struct cmdline *cl,
7962                        __attribute__((unused)) void *data)
7963 {
7964         int ret=0;
7965         struct cmd_set_uc_all_hash_table *res = parsed_result;
7966
7967         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7968
7969         if ((strcmp(res->what, "uta") == 0) &&
7970                 (strcmp(res->value, "all") == 0))
7971                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7972         if (ret < 0)
7973                 printf("bad unicast hash table parameter,"
7974                         "return code = %d \n", ret);
7975 }
7976
7977 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7978         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7979                                  set, "set");
7980 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7981         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7982                                  port, "port");
7983 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7984         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7985                               port_id, UINT16);
7986 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7987         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7988                                  what, "uta");
7989 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7990         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7991                                 value,"all");
7992 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7993         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7994                                  mode, "on#off");
7995
7996 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7997         .f = cmd_set_uc_all_hash_parsed,
7998         .data = NULL,
7999         .help_str = "set port <port_id> uta all on|off",
8000         .tokens = {
8001                 (void *)&cmd_set_uc_all_hash_set,
8002                 (void *)&cmd_set_uc_all_hash_port,
8003                 (void *)&cmd_set_uc_all_hash_portid,
8004                 (void *)&cmd_set_uc_all_hash_what,
8005                 (void *)&cmd_set_uc_all_hash_value,
8006                 (void *)&cmd_set_uc_all_hash_mode,
8007                 NULL,
8008         },
8009 };
8010
8011 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8012 struct cmd_set_vf_macvlan_filter {
8013         cmdline_fixed_string_t set;
8014         cmdline_fixed_string_t port;
8015         portid_t port_id;
8016         cmdline_fixed_string_t vf;
8017         uint8_t vf_id;
8018         struct ether_addr address;
8019         cmdline_fixed_string_t filter_type;
8020         cmdline_fixed_string_t mode;
8021 };
8022
8023 static void
8024 cmd_set_vf_macvlan_parsed(void *parsed_result,
8025                        __attribute__((unused)) struct cmdline *cl,
8026                        __attribute__((unused)) void *data)
8027 {
8028         int is_on, ret = 0;
8029         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8030         struct rte_eth_mac_filter filter;
8031
8032         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8033
8034         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
8035
8036         /* set VF MAC filter */
8037         filter.is_vf = 1;
8038
8039         /* set VF ID */
8040         filter.dst_id = res->vf_id;
8041
8042         if (!strcmp(res->filter_type, "exact-mac"))
8043                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8044         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8045                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8046         else if (!strcmp(res->filter_type, "hashmac"))
8047                 filter.filter_type = RTE_MAC_HASH_MATCH;
8048         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8049                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8050
8051         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8052
8053         if (is_on)
8054                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8055                                         RTE_ETH_FILTER_MACVLAN,
8056                                         RTE_ETH_FILTER_ADD,
8057                                          &filter);
8058         else
8059                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8060                                         RTE_ETH_FILTER_MACVLAN,
8061                                         RTE_ETH_FILTER_DELETE,
8062                                         &filter);
8063
8064         if (ret < 0)
8065                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8066
8067 }
8068
8069 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8070         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8071                                  set, "set");
8072 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8073         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8074                                  port, "port");
8075 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8076         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8077                               port_id, UINT16);
8078 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8079         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8080                                  vf, "vf");
8081 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8082         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8083                                 vf_id, UINT8);
8084 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8085         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8086                                 address);
8087 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8088         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8089                                 filter_type, "exact-mac#exact-mac-vlan"
8090                                 "#hashmac#hashmac-vlan");
8091 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8092         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8093                                  mode, "on#off");
8094
8095 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8096         .f = cmd_set_vf_macvlan_parsed,
8097         .data = NULL,
8098         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8099                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8100                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8101                 "hash match rule: hash match of MAC and exact match of VLAN",
8102         .tokens = {
8103                 (void *)&cmd_set_vf_macvlan_set,
8104                 (void *)&cmd_set_vf_macvlan_port,
8105                 (void *)&cmd_set_vf_macvlan_portid,
8106                 (void *)&cmd_set_vf_macvlan_vf,
8107                 (void *)&cmd_set_vf_macvlan_vf_id,
8108                 (void *)&cmd_set_vf_macvlan_mac,
8109                 (void *)&cmd_set_vf_macvlan_filter_type,
8110                 (void *)&cmd_set_vf_macvlan_mode,
8111                 NULL,
8112         },
8113 };
8114
8115 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8116 struct cmd_set_vf_traffic {
8117         cmdline_fixed_string_t set;
8118         cmdline_fixed_string_t port;
8119         portid_t port_id;
8120         cmdline_fixed_string_t vf;
8121         uint8_t vf_id;
8122         cmdline_fixed_string_t what;
8123         cmdline_fixed_string_t mode;
8124 };
8125
8126 static void
8127 cmd_set_vf_traffic_parsed(void *parsed_result,
8128                        __attribute__((unused)) struct cmdline *cl,
8129                        __attribute__((unused)) void *data)
8130 {
8131         struct cmd_set_vf_traffic *res = parsed_result;
8132         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8133         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8134
8135         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8136 }
8137
8138 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8139         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8140                                  set, "set");
8141 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8142         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8143                                  port, "port");
8144 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8145         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8146                               port_id, UINT16);
8147 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8148         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8149                                  vf, "vf");
8150 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8151         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8152                               vf_id, UINT8);
8153 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8154         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8155                                  what, "tx#rx");
8156 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8157         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8158                                  mode, "on#off");
8159
8160 cmdline_parse_inst_t cmd_set_vf_traffic = {
8161         .f = cmd_set_vf_traffic_parsed,
8162         .data = NULL,
8163         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8164         .tokens = {
8165                 (void *)&cmd_setvf_traffic_set,
8166                 (void *)&cmd_setvf_traffic_port,
8167                 (void *)&cmd_setvf_traffic_portid,
8168                 (void *)&cmd_setvf_traffic_vf,
8169                 (void *)&cmd_setvf_traffic_vfid,
8170                 (void *)&cmd_setvf_traffic_what,
8171                 (void *)&cmd_setvf_traffic_mode,
8172                 NULL,
8173         },
8174 };
8175
8176 /* *** CONFIGURE VF RECEIVE MODE *** */
8177 struct cmd_set_vf_rxmode {
8178         cmdline_fixed_string_t set;
8179         cmdline_fixed_string_t port;
8180         portid_t port_id;
8181         cmdline_fixed_string_t vf;
8182         uint8_t vf_id;
8183         cmdline_fixed_string_t what;
8184         cmdline_fixed_string_t mode;
8185         cmdline_fixed_string_t on;
8186 };
8187
8188 static void
8189 cmd_set_vf_rxmode_parsed(void *parsed_result,
8190                        __attribute__((unused)) struct cmdline *cl,
8191                        __attribute__((unused)) void *data)
8192 {
8193         int ret = -ENOTSUP;
8194         uint16_t rx_mode = 0;
8195         struct cmd_set_vf_rxmode *res = parsed_result;
8196
8197         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8198         if (!strcmp(res->what,"rxmode")) {
8199                 if (!strcmp(res->mode, "AUPE"))
8200                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8201                 else if (!strcmp(res->mode, "ROPE"))
8202                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8203                 else if (!strcmp(res->mode, "BAM"))
8204                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8205                 else if (!strncmp(res->mode, "MPE",3))
8206                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8207         }
8208
8209         RTE_SET_USED(is_on);
8210
8211 #ifdef RTE_LIBRTE_IXGBE_PMD
8212         if (ret == -ENOTSUP)
8213                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8214                                                   rx_mode, (uint8_t)is_on);
8215 #endif
8216 #ifdef RTE_LIBRTE_BNXT_PMD
8217         if (ret == -ENOTSUP)
8218                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8219                                                  rx_mode, (uint8_t)is_on);
8220 #endif
8221         if (ret < 0)
8222                 printf("bad VF receive mode parameter, return code = %d \n",
8223                 ret);
8224 }
8225
8226 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8227         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8228                                  set, "set");
8229 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8230         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8231                                  port, "port");
8232 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8233         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8234                               port_id, UINT16);
8235 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8236         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8237                                  vf, "vf");
8238 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8239         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8240                               vf_id, UINT8);
8241 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8242         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8243                                  what, "rxmode");
8244 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8245         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8246                                  mode, "AUPE#ROPE#BAM#MPE");
8247 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8248         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8249                                  on, "on#off");
8250
8251 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8252         .f = cmd_set_vf_rxmode_parsed,
8253         .data = NULL,
8254         .help_str = "set port <port_id> vf <vf_id> rxmode "
8255                 "AUPE|ROPE|BAM|MPE on|off",
8256         .tokens = {
8257                 (void *)&cmd_set_vf_rxmode_set,
8258                 (void *)&cmd_set_vf_rxmode_port,
8259                 (void *)&cmd_set_vf_rxmode_portid,
8260                 (void *)&cmd_set_vf_rxmode_vf,
8261                 (void *)&cmd_set_vf_rxmode_vfid,
8262                 (void *)&cmd_set_vf_rxmode_what,
8263                 (void *)&cmd_set_vf_rxmode_mode,
8264                 (void *)&cmd_set_vf_rxmode_on,
8265                 NULL,
8266         },
8267 };
8268
8269 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8270 struct cmd_vf_mac_addr_result {
8271         cmdline_fixed_string_t mac_addr_cmd;
8272         cmdline_fixed_string_t what;
8273         cmdline_fixed_string_t port;
8274         uint16_t port_num;
8275         cmdline_fixed_string_t vf;
8276         uint8_t vf_num;
8277         struct ether_addr address;
8278 };
8279
8280 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8281                 __attribute__((unused)) struct cmdline *cl,
8282                 __attribute__((unused)) void *data)
8283 {
8284         struct cmd_vf_mac_addr_result *res = parsed_result;
8285         int ret = -ENOTSUP;
8286
8287         if (strcmp(res->what, "add") != 0)
8288                 return;
8289
8290 #ifdef RTE_LIBRTE_I40E_PMD
8291         if (ret == -ENOTSUP)
8292                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8293                                                    &res->address);
8294 #endif
8295 #ifdef RTE_LIBRTE_BNXT_PMD
8296         if (ret == -ENOTSUP)
8297                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8298                                                 res->vf_num);
8299 #endif
8300
8301         if(ret < 0)
8302                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8303
8304 }
8305
8306 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8307         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8308                                 mac_addr_cmd,"mac_addr");
8309 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8310         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8311                                 what,"add");
8312 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8313         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8314                                 port,"port");
8315 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8316         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8317                                 port_num, UINT16);
8318 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8319         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8320                                 vf,"vf");
8321 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8322         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8323                                 vf_num, UINT8);
8324 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8325         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8326                                 address);
8327
8328 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8329         .f = cmd_vf_mac_addr_parsed,
8330         .data = (void *)0,
8331         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8332                 "Add MAC address filtering for a VF on port_id",
8333         .tokens = {
8334                 (void *)&cmd_vf_mac_addr_cmd,
8335                 (void *)&cmd_vf_mac_addr_what,
8336                 (void *)&cmd_vf_mac_addr_port,
8337                 (void *)&cmd_vf_mac_addr_portnum,
8338                 (void *)&cmd_vf_mac_addr_vf,
8339                 (void *)&cmd_vf_mac_addr_vfnum,
8340                 (void *)&cmd_vf_mac_addr_addr,
8341                 NULL,
8342         },
8343 };
8344
8345 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8346 struct cmd_vf_rx_vlan_filter {
8347         cmdline_fixed_string_t rx_vlan;
8348         cmdline_fixed_string_t what;
8349         uint16_t vlan_id;
8350         cmdline_fixed_string_t port;
8351         portid_t port_id;
8352         cmdline_fixed_string_t vf;
8353         uint64_t vf_mask;
8354 };
8355
8356 static void
8357 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8358                           __attribute__((unused)) struct cmdline *cl,
8359                           __attribute__((unused)) void *data)
8360 {
8361         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8362         int ret = -ENOTSUP;
8363
8364         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8365
8366 #ifdef RTE_LIBRTE_IXGBE_PMD
8367         if (ret == -ENOTSUP)
8368                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8369                                 res->vlan_id, res->vf_mask, is_add);
8370 #endif
8371 #ifdef RTE_LIBRTE_I40E_PMD
8372         if (ret == -ENOTSUP)
8373                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8374                                 res->vlan_id, res->vf_mask, is_add);
8375 #endif
8376 #ifdef RTE_LIBRTE_BNXT_PMD
8377         if (ret == -ENOTSUP)
8378                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8379                                 res->vlan_id, res->vf_mask, is_add);
8380 #endif
8381
8382         switch (ret) {
8383         case 0:
8384                 break;
8385         case -EINVAL:
8386                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8387                                 res->vlan_id, res->vf_mask);
8388                 break;
8389         case -ENODEV:
8390                 printf("invalid port_id %d\n", res->port_id);
8391                 break;
8392         case -ENOTSUP:
8393                 printf("function not implemented or supported\n");
8394                 break;
8395         default:
8396                 printf("programming error: (%s)\n", strerror(-ret));
8397         }
8398 }
8399
8400 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8401         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8402                                  rx_vlan, "rx_vlan");
8403 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8404         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8405                                  what, "add#rm");
8406 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8407         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8408                               vlan_id, UINT16);
8409 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8410         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8411                                  port, "port");
8412 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8413         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8414                               port_id, UINT16);
8415 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8416         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8417                                  vf, "vf");
8418 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8419         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8420                               vf_mask, UINT64);
8421
8422 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8423         .f = cmd_vf_rx_vlan_filter_parsed,
8424         .data = NULL,
8425         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8426                 "(vf_mask = hexadecimal VF mask)",
8427         .tokens = {
8428                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8429                 (void *)&cmd_vf_rx_vlan_filter_what,
8430                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8431                 (void *)&cmd_vf_rx_vlan_filter_port,
8432                 (void *)&cmd_vf_rx_vlan_filter_portid,
8433                 (void *)&cmd_vf_rx_vlan_filter_vf,
8434                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8435                 NULL,
8436         },
8437 };
8438
8439 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8440 struct cmd_queue_rate_limit_result {
8441         cmdline_fixed_string_t set;
8442         cmdline_fixed_string_t port;
8443         uint16_t port_num;
8444         cmdline_fixed_string_t queue;
8445         uint8_t queue_num;
8446         cmdline_fixed_string_t rate;
8447         uint16_t rate_num;
8448 };
8449
8450 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8451                 __attribute__((unused)) struct cmdline *cl,
8452                 __attribute__((unused)) void *data)
8453 {
8454         struct cmd_queue_rate_limit_result *res = parsed_result;
8455         int ret = 0;
8456
8457         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8458                 && (strcmp(res->queue, "queue") == 0)
8459                 && (strcmp(res->rate, "rate") == 0))
8460                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8461                                         res->rate_num);
8462         if (ret < 0)
8463                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8464
8465 }
8466
8467 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8468         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8469                                 set, "set");
8470 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8471         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8472                                 port, "port");
8473 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8474         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8475                                 port_num, UINT16);
8476 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8477         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8478                                 queue, "queue");
8479 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8480         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8481                                 queue_num, UINT8);
8482 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8483         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8484                                 rate, "rate");
8485 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8486         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8487                                 rate_num, UINT16);
8488
8489 cmdline_parse_inst_t cmd_queue_rate_limit = {
8490         .f = cmd_queue_rate_limit_parsed,
8491         .data = (void *)0,
8492         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8493                 "Set rate limit for a queue on port_id",
8494         .tokens = {
8495                 (void *)&cmd_queue_rate_limit_set,
8496                 (void *)&cmd_queue_rate_limit_port,
8497                 (void *)&cmd_queue_rate_limit_portnum,
8498                 (void *)&cmd_queue_rate_limit_queue,
8499                 (void *)&cmd_queue_rate_limit_queuenum,
8500                 (void *)&cmd_queue_rate_limit_rate,
8501                 (void *)&cmd_queue_rate_limit_ratenum,
8502                 NULL,
8503         },
8504 };
8505
8506 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8507 struct cmd_vf_rate_limit_result {
8508         cmdline_fixed_string_t set;
8509         cmdline_fixed_string_t port;
8510         uint16_t port_num;
8511         cmdline_fixed_string_t vf;
8512         uint8_t vf_num;
8513         cmdline_fixed_string_t rate;
8514         uint16_t rate_num;
8515         cmdline_fixed_string_t q_msk;
8516         uint64_t q_msk_val;
8517 };
8518
8519 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8520                 __attribute__((unused)) struct cmdline *cl,
8521                 __attribute__((unused)) void *data)
8522 {
8523         struct cmd_vf_rate_limit_result *res = parsed_result;
8524         int ret = 0;
8525
8526         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8527                 && (strcmp(res->vf, "vf") == 0)
8528                 && (strcmp(res->rate, "rate") == 0)
8529                 && (strcmp(res->q_msk, "queue_mask") == 0))
8530                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8531                                         res->rate_num, res->q_msk_val);
8532         if (ret < 0)
8533                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8534
8535 }
8536
8537 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8538         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8539                                 set, "set");
8540 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8541         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8542                                 port, "port");
8543 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8544         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8545                                 port_num, UINT16);
8546 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8547         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8548                                 vf, "vf");
8549 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8550         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8551                                 vf_num, UINT8);
8552 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8553         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8554                                 rate, "rate");
8555 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8556         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8557                                 rate_num, UINT16);
8558 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8559         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8560                                 q_msk, "queue_mask");
8561 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8562         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8563                                 q_msk_val, UINT64);
8564
8565 cmdline_parse_inst_t cmd_vf_rate_limit = {
8566         .f = cmd_vf_rate_limit_parsed,
8567         .data = (void *)0,
8568         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8569                 "queue_mask <queue_mask_value>: "
8570                 "Set rate limit for queues of VF on port_id",
8571         .tokens = {
8572                 (void *)&cmd_vf_rate_limit_set,
8573                 (void *)&cmd_vf_rate_limit_port,
8574                 (void *)&cmd_vf_rate_limit_portnum,
8575                 (void *)&cmd_vf_rate_limit_vf,
8576                 (void *)&cmd_vf_rate_limit_vfnum,
8577                 (void *)&cmd_vf_rate_limit_rate,
8578                 (void *)&cmd_vf_rate_limit_ratenum,
8579                 (void *)&cmd_vf_rate_limit_q_msk,
8580                 (void *)&cmd_vf_rate_limit_q_msk_val,
8581                 NULL,
8582         },
8583 };
8584
8585 /* *** ADD TUNNEL FILTER OF A PORT *** */
8586 struct cmd_tunnel_filter_result {
8587         cmdline_fixed_string_t cmd;
8588         cmdline_fixed_string_t what;
8589         portid_t port_id;
8590         struct ether_addr outer_mac;
8591         struct ether_addr inner_mac;
8592         cmdline_ipaddr_t ip_value;
8593         uint16_t inner_vlan;
8594         cmdline_fixed_string_t tunnel_type;
8595         cmdline_fixed_string_t filter_type;
8596         uint32_t tenant_id;
8597         uint16_t queue_num;
8598 };
8599
8600 static void
8601 cmd_tunnel_filter_parsed(void *parsed_result,
8602                           __attribute__((unused)) struct cmdline *cl,
8603                           __attribute__((unused)) void *data)
8604 {
8605         struct cmd_tunnel_filter_result *res = parsed_result;
8606         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8607         int ret = 0;
8608
8609         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8610
8611         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8612         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8613         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8614
8615         if (res->ip_value.family == AF_INET) {
8616                 tunnel_filter_conf.ip_addr.ipv4_addr =
8617                         res->ip_value.addr.ipv4.s_addr;
8618                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8619         } else {
8620                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8621                         &(res->ip_value.addr.ipv6),
8622                         sizeof(struct in6_addr));
8623                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8624         }
8625
8626         if (!strcmp(res->filter_type, "imac-ivlan"))
8627                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8628         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8629                 tunnel_filter_conf.filter_type =
8630                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8631         else if (!strcmp(res->filter_type, "imac-tenid"))
8632                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8633         else if (!strcmp(res->filter_type, "imac"))
8634                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8635         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8636                 tunnel_filter_conf.filter_type =
8637                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8638         else if (!strcmp(res->filter_type, "oip"))
8639                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8640         else if (!strcmp(res->filter_type, "iip"))
8641                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8642         else {
8643                 printf("The filter type is not supported");
8644                 return;
8645         }
8646
8647         if (!strcmp(res->tunnel_type, "vxlan"))
8648                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8649         else if (!strcmp(res->tunnel_type, "nvgre"))
8650                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8651         else if (!strcmp(res->tunnel_type, "ipingre"))
8652                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8653         else {
8654                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8655                 return;
8656         }
8657
8658         tunnel_filter_conf.tenant_id = res->tenant_id;
8659         tunnel_filter_conf.queue_id = res->queue_num;
8660         if (!strcmp(res->what, "add"))
8661                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8662                                         RTE_ETH_FILTER_TUNNEL,
8663                                         RTE_ETH_FILTER_ADD,
8664                                         &tunnel_filter_conf);
8665         else
8666                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8667                                         RTE_ETH_FILTER_TUNNEL,
8668                                         RTE_ETH_FILTER_DELETE,
8669                                         &tunnel_filter_conf);
8670         if (ret < 0)
8671                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8672                                 strerror(-ret));
8673
8674 }
8675 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8676         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8677         cmd, "tunnel_filter");
8678 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8679         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8680         what, "add#rm");
8681 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8682         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8683         port_id, UINT16);
8684 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8685         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8686         outer_mac);
8687 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8688         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8689         inner_mac);
8690 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8691         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8692         inner_vlan, UINT16);
8693 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8694         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8695         ip_value);
8696 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8697         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8698         tunnel_type, "vxlan#nvgre#ipingre");
8699
8700 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8701         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8702         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8703                 "imac#omac-imac-tenid");
8704 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8705         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8706         tenant_id, UINT32);
8707 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8708         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8709         queue_num, UINT16);
8710
8711 cmdline_parse_inst_t cmd_tunnel_filter = {
8712         .f = cmd_tunnel_filter_parsed,
8713         .data = (void *)0,
8714         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8715                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8716                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8717                 "<queue_id>: Add/Rm tunnel filter of a port",
8718         .tokens = {
8719                 (void *)&cmd_tunnel_filter_cmd,
8720                 (void *)&cmd_tunnel_filter_what,
8721                 (void *)&cmd_tunnel_filter_port_id,
8722                 (void *)&cmd_tunnel_filter_outer_mac,
8723                 (void *)&cmd_tunnel_filter_inner_mac,
8724                 (void *)&cmd_tunnel_filter_ip_value,
8725                 (void *)&cmd_tunnel_filter_innner_vlan,
8726                 (void *)&cmd_tunnel_filter_tunnel_type,
8727                 (void *)&cmd_tunnel_filter_filter_type,
8728                 (void *)&cmd_tunnel_filter_tenant_id,
8729                 (void *)&cmd_tunnel_filter_queue_num,
8730                 NULL,
8731         },
8732 };
8733
8734 /* *** CONFIGURE TUNNEL UDP PORT *** */
8735 struct cmd_tunnel_udp_config {
8736         cmdline_fixed_string_t cmd;
8737         cmdline_fixed_string_t what;
8738         uint16_t udp_port;
8739         portid_t port_id;
8740 };
8741
8742 static void
8743 cmd_tunnel_udp_config_parsed(void *parsed_result,
8744                           __attribute__((unused)) struct cmdline *cl,
8745                           __attribute__((unused)) void *data)
8746 {
8747         struct cmd_tunnel_udp_config *res = parsed_result;
8748         struct rte_eth_udp_tunnel tunnel_udp;
8749         int ret;
8750
8751         tunnel_udp.udp_port = res->udp_port;
8752
8753         if (!strcmp(res->cmd, "rx_vxlan_port"))
8754                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8755
8756         if (!strcmp(res->what, "add"))
8757                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8758                                                       &tunnel_udp);
8759         else
8760                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8761                                                          &tunnel_udp);
8762
8763         if (ret < 0)
8764                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8765 }
8766
8767 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8768         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8769                                 cmd, "rx_vxlan_port");
8770 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8771         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8772                                 what, "add#rm");
8773 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8774         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8775                                 udp_port, UINT16);
8776 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8777         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8778                                 port_id, UINT16);
8779
8780 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8781         .f = cmd_tunnel_udp_config_parsed,
8782         .data = (void *)0,
8783         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8784                 "Add/Remove a tunneling UDP port filter",
8785         .tokens = {
8786                 (void *)&cmd_tunnel_udp_config_cmd,
8787                 (void *)&cmd_tunnel_udp_config_what,
8788                 (void *)&cmd_tunnel_udp_config_udp_port,
8789                 (void *)&cmd_tunnel_udp_config_port_id,
8790                 NULL,
8791         },
8792 };
8793
8794 struct cmd_config_tunnel_udp_port {
8795         cmdline_fixed_string_t port;
8796         cmdline_fixed_string_t config;
8797         portid_t port_id;
8798         cmdline_fixed_string_t udp_tunnel_port;
8799         cmdline_fixed_string_t action;
8800         cmdline_fixed_string_t tunnel_type;
8801         uint16_t udp_port;
8802 };
8803
8804 static void
8805 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8806                                __attribute__((unused)) struct cmdline *cl,
8807                                __attribute__((unused)) void *data)
8808 {
8809         struct cmd_config_tunnel_udp_port *res = parsed_result;
8810         struct rte_eth_udp_tunnel tunnel_udp;
8811         int ret = 0;
8812
8813         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8814                 return;
8815
8816         tunnel_udp.udp_port = res->udp_port;
8817
8818         if (!strcmp(res->tunnel_type, "vxlan")) {
8819                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8820         } else if (!strcmp(res->tunnel_type, "geneve")) {
8821                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8822         } else {
8823                 printf("Invalid tunnel type\n");
8824                 return;
8825         }
8826
8827         if (!strcmp(res->action, "add"))
8828                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8829                                                       &tunnel_udp);
8830         else
8831                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8832                                                          &tunnel_udp);
8833
8834         if (ret < 0)
8835                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8836 }
8837
8838 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8839         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8840                                  "port");
8841 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8842         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8843                                  "config");
8844 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8845         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8846                               UINT16);
8847 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8848         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8849                                  udp_tunnel_port,
8850                                  "udp_tunnel_port");
8851 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8852         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8853                                  "add#rm");
8854 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8855         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8856                                  "vxlan#geneve");
8857 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8858         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8859                               UINT16);
8860
8861 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8862         .f = cmd_cfg_tunnel_udp_port_parsed,
8863         .data = NULL,
8864         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8865         .tokens = {
8866                 (void *)&cmd_config_tunnel_udp_port_port,
8867                 (void *)&cmd_config_tunnel_udp_port_config,
8868                 (void *)&cmd_config_tunnel_udp_port_port_id,
8869                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8870                 (void *)&cmd_config_tunnel_udp_port_action,
8871                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8872                 (void *)&cmd_config_tunnel_udp_port_value,
8873                 NULL,
8874         },
8875 };
8876
8877 /* *** GLOBAL CONFIG *** */
8878 struct cmd_global_config_result {
8879         cmdline_fixed_string_t cmd;
8880         portid_t port_id;
8881         cmdline_fixed_string_t cfg_type;
8882         uint8_t len;
8883 };
8884
8885 static void
8886 cmd_global_config_parsed(void *parsed_result,
8887                          __attribute__((unused)) struct cmdline *cl,
8888                          __attribute__((unused)) void *data)
8889 {
8890         struct cmd_global_config_result *res = parsed_result;
8891         struct rte_eth_global_cfg conf;
8892         int ret;
8893
8894         memset(&conf, 0, sizeof(conf));
8895         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8896         conf.cfg.gre_key_len = res->len;
8897         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8898                                       RTE_ETH_FILTER_SET, &conf);
8899         if (ret != 0)
8900                 printf("Global config error\n");
8901 }
8902
8903 cmdline_parse_token_string_t cmd_global_config_cmd =
8904         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8905                 "global_config");
8906 cmdline_parse_token_num_t cmd_global_config_port_id =
8907         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8908                                UINT16);
8909 cmdline_parse_token_string_t cmd_global_config_type =
8910         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8911                 cfg_type, "gre-key-len");
8912 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8913         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8914                 len, UINT8);
8915
8916 cmdline_parse_inst_t cmd_global_config = {
8917         .f = cmd_global_config_parsed,
8918         .data = (void *)NULL,
8919         .help_str = "global_config <port_id> gre-key-len <key_len>",
8920         .tokens = {
8921                 (void *)&cmd_global_config_cmd,
8922                 (void *)&cmd_global_config_port_id,
8923                 (void *)&cmd_global_config_type,
8924                 (void *)&cmd_global_config_gre_key_len,
8925                 NULL,
8926         },
8927 };
8928
8929 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8930 struct cmd_set_mirror_mask_result {
8931         cmdline_fixed_string_t set;
8932         cmdline_fixed_string_t port;
8933         portid_t port_id;
8934         cmdline_fixed_string_t mirror;
8935         uint8_t rule_id;
8936         cmdline_fixed_string_t what;
8937         cmdline_fixed_string_t value;
8938         cmdline_fixed_string_t dstpool;
8939         uint8_t dstpool_id;
8940         cmdline_fixed_string_t on;
8941 };
8942
8943 cmdline_parse_token_string_t cmd_mirror_mask_set =
8944         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8945                                 set, "set");
8946 cmdline_parse_token_string_t cmd_mirror_mask_port =
8947         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8948                                 port, "port");
8949 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8950         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8951                                 port_id, UINT16);
8952 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8953         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8954                                 mirror, "mirror-rule");
8955 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8956         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8957                                 rule_id, UINT8);
8958 cmdline_parse_token_string_t cmd_mirror_mask_what =
8959         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8960                                 what, "pool-mirror-up#pool-mirror-down"
8961                                       "#vlan-mirror");
8962 cmdline_parse_token_string_t cmd_mirror_mask_value =
8963         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8964                                 value, NULL);
8965 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8966         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8967                                 dstpool, "dst-pool");
8968 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8969         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8970                                 dstpool_id, UINT8);
8971 cmdline_parse_token_string_t cmd_mirror_mask_on =
8972         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8973                                 on, "on#off");
8974
8975 static void
8976 cmd_set_mirror_mask_parsed(void *parsed_result,
8977                        __attribute__((unused)) struct cmdline *cl,
8978                        __attribute__((unused)) void *data)
8979 {
8980         int ret,nb_item,i;
8981         struct cmd_set_mirror_mask_result *res = parsed_result;
8982         struct rte_eth_mirror_conf mr_conf;
8983
8984         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8985
8986         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8987
8988         mr_conf.dst_pool = res->dstpool_id;
8989
8990         if (!strcmp(res->what, "pool-mirror-up")) {
8991                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8992                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8993         } else if (!strcmp(res->what, "pool-mirror-down")) {
8994                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8995                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8996         } else if (!strcmp(res->what, "vlan-mirror")) {
8997                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8998                 nb_item = parse_item_list(res->value, "vlan",
8999                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9000                 if (nb_item <= 0)
9001                         return;
9002
9003                 for (i = 0; i < nb_item; i++) {
9004                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
9005                                 printf("Invalid vlan_id: must be < 4096\n");
9006                                 return;
9007                         }
9008
9009                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9010                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9011                 }
9012         }
9013
9014         if (!strcmp(res->on, "on"))
9015                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9016                                                 res->rule_id, 1);
9017         else
9018                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9019                                                 res->rule_id, 0);
9020         if (ret < 0)
9021                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9022 }
9023
9024 cmdline_parse_inst_t cmd_set_mirror_mask = {
9025                 .f = cmd_set_mirror_mask_parsed,
9026                 .data = NULL,
9027                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9028                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9029                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9030                 .tokens = {
9031                         (void *)&cmd_mirror_mask_set,
9032                         (void *)&cmd_mirror_mask_port,
9033                         (void *)&cmd_mirror_mask_portid,
9034                         (void *)&cmd_mirror_mask_mirror,
9035                         (void *)&cmd_mirror_mask_ruleid,
9036                         (void *)&cmd_mirror_mask_what,
9037                         (void *)&cmd_mirror_mask_value,
9038                         (void *)&cmd_mirror_mask_dstpool,
9039                         (void *)&cmd_mirror_mask_poolid,
9040                         (void *)&cmd_mirror_mask_on,
9041                         NULL,
9042                 },
9043 };
9044
9045 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9046 struct cmd_set_mirror_link_result {
9047         cmdline_fixed_string_t set;
9048         cmdline_fixed_string_t port;
9049         portid_t port_id;
9050         cmdline_fixed_string_t mirror;
9051         uint8_t rule_id;
9052         cmdline_fixed_string_t what;
9053         cmdline_fixed_string_t dstpool;
9054         uint8_t dstpool_id;
9055         cmdline_fixed_string_t on;
9056 };
9057
9058 cmdline_parse_token_string_t cmd_mirror_link_set =
9059         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9060                                  set, "set");
9061 cmdline_parse_token_string_t cmd_mirror_link_port =
9062         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9063                                 port, "port");
9064 cmdline_parse_token_num_t cmd_mirror_link_portid =
9065         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9066                                 port_id, UINT16);
9067 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9068         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9069                                 mirror, "mirror-rule");
9070 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9071         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9072                             rule_id, UINT8);
9073 cmdline_parse_token_string_t cmd_mirror_link_what =
9074         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9075                                 what, "uplink-mirror#downlink-mirror");
9076 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9077         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9078                                 dstpool, "dst-pool");
9079 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9080         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9081                                 dstpool_id, UINT8);
9082 cmdline_parse_token_string_t cmd_mirror_link_on =
9083         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9084                                 on, "on#off");
9085
9086 static void
9087 cmd_set_mirror_link_parsed(void *parsed_result,
9088                        __attribute__((unused)) struct cmdline *cl,
9089                        __attribute__((unused)) void *data)
9090 {
9091         int ret;
9092         struct cmd_set_mirror_link_result *res = parsed_result;
9093         struct rte_eth_mirror_conf mr_conf;
9094
9095         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9096         if (!strcmp(res->what, "uplink-mirror"))
9097                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9098         else
9099                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9100
9101         mr_conf.dst_pool = res->dstpool_id;
9102
9103         if (!strcmp(res->on, "on"))
9104                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9105                                                 res->rule_id, 1);
9106         else
9107                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9108                                                 res->rule_id, 0);
9109
9110         /* check the return value and print it if is < 0 */
9111         if (ret < 0)
9112                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9113
9114 }
9115
9116 cmdline_parse_inst_t cmd_set_mirror_link = {
9117                 .f = cmd_set_mirror_link_parsed,
9118                 .data = NULL,
9119                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9120                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9121                 .tokens = {
9122                         (void *)&cmd_mirror_link_set,
9123                         (void *)&cmd_mirror_link_port,
9124                         (void *)&cmd_mirror_link_portid,
9125                         (void *)&cmd_mirror_link_mirror,
9126                         (void *)&cmd_mirror_link_ruleid,
9127                         (void *)&cmd_mirror_link_what,
9128                         (void *)&cmd_mirror_link_dstpool,
9129                         (void *)&cmd_mirror_link_poolid,
9130                         (void *)&cmd_mirror_link_on,
9131                         NULL,
9132                 },
9133 };
9134
9135 /* *** RESET VM MIRROR RULE *** */
9136 struct cmd_rm_mirror_rule_result {
9137         cmdline_fixed_string_t reset;
9138         cmdline_fixed_string_t port;
9139         portid_t port_id;
9140         cmdline_fixed_string_t mirror;
9141         uint8_t rule_id;
9142 };
9143
9144 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9145         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9146                                  reset, "reset");
9147 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9148         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9149                                 port, "port");
9150 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9151         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9152                                 port_id, UINT16);
9153 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9154         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9155                                 mirror, "mirror-rule");
9156 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9157         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9158                                 rule_id, UINT8);
9159
9160 static void
9161 cmd_reset_mirror_rule_parsed(void *parsed_result,
9162                        __attribute__((unused)) struct cmdline *cl,
9163                        __attribute__((unused)) void *data)
9164 {
9165         int ret;
9166         struct cmd_set_mirror_link_result *res = parsed_result;
9167         /* check rule_id */
9168         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9169         if(ret < 0)
9170                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9171 }
9172
9173 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9174                 .f = cmd_reset_mirror_rule_parsed,
9175                 .data = NULL,
9176                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9177                 .tokens = {
9178                         (void *)&cmd_rm_mirror_rule_reset,
9179                         (void *)&cmd_rm_mirror_rule_port,
9180                         (void *)&cmd_rm_mirror_rule_portid,
9181                         (void *)&cmd_rm_mirror_rule_mirror,
9182                         (void *)&cmd_rm_mirror_rule_ruleid,
9183                         NULL,
9184                 },
9185 };
9186
9187 /* ******************************************************************************** */
9188
9189 struct cmd_dump_result {
9190         cmdline_fixed_string_t dump;
9191 };
9192
9193 static void
9194 dump_struct_sizes(void)
9195 {
9196 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9197         DUMP_SIZE(struct rte_mbuf);
9198         DUMP_SIZE(struct rte_mempool);
9199         DUMP_SIZE(struct rte_ring);
9200 #undef DUMP_SIZE
9201 }
9202
9203 static void cmd_dump_parsed(void *parsed_result,
9204                             __attribute__((unused)) struct cmdline *cl,
9205                             __attribute__((unused)) void *data)
9206 {
9207         struct cmd_dump_result *res = parsed_result;
9208
9209         if (!strcmp(res->dump, "dump_physmem"))
9210                 rte_dump_physmem_layout(stdout);
9211         else if (!strcmp(res->dump, "dump_memzone"))
9212                 rte_memzone_dump(stdout);
9213         else if (!strcmp(res->dump, "dump_struct_sizes"))
9214                 dump_struct_sizes();
9215         else if (!strcmp(res->dump, "dump_ring"))
9216                 rte_ring_list_dump(stdout);
9217         else if (!strcmp(res->dump, "dump_mempool"))
9218                 rte_mempool_list_dump(stdout);
9219         else if (!strcmp(res->dump, "dump_devargs"))
9220                 rte_devargs_dump(stdout);
9221         else if (!strcmp(res->dump, "dump_log_types"))
9222                 rte_log_dump(stdout);
9223 }
9224
9225 cmdline_parse_token_string_t cmd_dump_dump =
9226         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9227                 "dump_physmem#"
9228                 "dump_memzone#"
9229                 "dump_struct_sizes#"
9230                 "dump_ring#"
9231                 "dump_mempool#"
9232                 "dump_devargs#"
9233                 "dump_log_types");
9234
9235 cmdline_parse_inst_t cmd_dump = {
9236         .f = cmd_dump_parsed,  /* function to call */
9237         .data = NULL,      /* 2nd arg of func */
9238         .help_str = "Dump status",
9239         .tokens = {        /* token list, NULL terminated */
9240                 (void *)&cmd_dump_dump,
9241                 NULL,
9242         },
9243 };
9244
9245 /* ******************************************************************************** */
9246
9247 struct cmd_dump_one_result {
9248         cmdline_fixed_string_t dump;
9249         cmdline_fixed_string_t name;
9250 };
9251
9252 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9253                                 __attribute__((unused)) void *data)
9254 {
9255         struct cmd_dump_one_result *res = parsed_result;
9256
9257         if (!strcmp(res->dump, "dump_ring")) {
9258                 struct rte_ring *r;
9259                 r = rte_ring_lookup(res->name);
9260                 if (r == NULL) {
9261                         cmdline_printf(cl, "Cannot find ring\n");
9262                         return;
9263                 }
9264                 rte_ring_dump(stdout, r);
9265         } else if (!strcmp(res->dump, "dump_mempool")) {
9266                 struct rte_mempool *mp;
9267                 mp = rte_mempool_lookup(res->name);
9268                 if (mp == NULL) {
9269                         cmdline_printf(cl, "Cannot find mempool\n");
9270                         return;
9271                 }
9272                 rte_mempool_dump(stdout, mp);
9273         }
9274 }
9275
9276 cmdline_parse_token_string_t cmd_dump_one_dump =
9277         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9278                                  "dump_ring#dump_mempool");
9279
9280 cmdline_parse_token_string_t cmd_dump_one_name =
9281         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9282
9283 cmdline_parse_inst_t cmd_dump_one = {
9284         .f = cmd_dump_one_parsed,  /* function to call */
9285         .data = NULL,      /* 2nd arg of func */
9286         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9287         .tokens = {        /* token list, NULL terminated */
9288                 (void *)&cmd_dump_one_dump,
9289                 (void *)&cmd_dump_one_name,
9290                 NULL,
9291         },
9292 };
9293
9294 /* *** Add/Del syn filter *** */
9295 struct cmd_syn_filter_result {
9296         cmdline_fixed_string_t filter;
9297         portid_t port_id;
9298         cmdline_fixed_string_t ops;
9299         cmdline_fixed_string_t priority;
9300         cmdline_fixed_string_t high;
9301         cmdline_fixed_string_t queue;
9302         uint16_t queue_id;
9303 };
9304
9305 static void
9306 cmd_syn_filter_parsed(void *parsed_result,
9307                         __attribute__((unused)) struct cmdline *cl,
9308                         __attribute__((unused)) void *data)
9309 {
9310         struct cmd_syn_filter_result *res = parsed_result;
9311         struct rte_eth_syn_filter syn_filter;
9312         int ret = 0;
9313
9314         ret = rte_eth_dev_filter_supported(res->port_id,
9315                                         RTE_ETH_FILTER_SYN);
9316         if (ret < 0) {
9317                 printf("syn filter is not supported on port %u.\n",
9318                                 res->port_id);
9319                 return;
9320         }
9321
9322         memset(&syn_filter, 0, sizeof(syn_filter));
9323
9324         if (!strcmp(res->ops, "add")) {
9325                 if (!strcmp(res->high, "high"))
9326                         syn_filter.hig_pri = 1;
9327                 else
9328                         syn_filter.hig_pri = 0;
9329
9330                 syn_filter.queue = res->queue_id;
9331                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9332                                                 RTE_ETH_FILTER_SYN,
9333                                                 RTE_ETH_FILTER_ADD,
9334                                                 &syn_filter);
9335         } else
9336                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9337                                                 RTE_ETH_FILTER_SYN,
9338                                                 RTE_ETH_FILTER_DELETE,
9339                                                 &syn_filter);
9340
9341         if (ret < 0)
9342                 printf("syn filter programming error: (%s)\n",
9343                                 strerror(-ret));
9344 }
9345
9346 cmdline_parse_token_string_t cmd_syn_filter_filter =
9347         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9348         filter, "syn_filter");
9349 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9350         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9351         port_id, UINT16);
9352 cmdline_parse_token_string_t cmd_syn_filter_ops =
9353         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9354         ops, "add#del");
9355 cmdline_parse_token_string_t cmd_syn_filter_priority =
9356         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9357                                 priority, "priority");
9358 cmdline_parse_token_string_t cmd_syn_filter_high =
9359         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9360                                 high, "high#low");
9361 cmdline_parse_token_string_t cmd_syn_filter_queue =
9362         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9363                                 queue, "queue");
9364 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9365         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9366                                 queue_id, UINT16);
9367
9368 cmdline_parse_inst_t cmd_syn_filter = {
9369         .f = cmd_syn_filter_parsed,
9370         .data = NULL,
9371         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9372                 "<queue_id>: Add/Delete syn filter",
9373         .tokens = {
9374                 (void *)&cmd_syn_filter_filter,
9375                 (void *)&cmd_syn_filter_port_id,
9376                 (void *)&cmd_syn_filter_ops,
9377                 (void *)&cmd_syn_filter_priority,
9378                 (void *)&cmd_syn_filter_high,
9379                 (void *)&cmd_syn_filter_queue,
9380                 (void *)&cmd_syn_filter_queue_id,
9381                 NULL,
9382         },
9383 };
9384
9385 /* *** queue region set *** */
9386 struct cmd_queue_region_result {
9387         cmdline_fixed_string_t set;
9388         cmdline_fixed_string_t port;
9389         portid_t port_id;
9390         cmdline_fixed_string_t cmd;
9391         cmdline_fixed_string_t region;
9392         uint8_t  region_id;
9393         cmdline_fixed_string_t queue_start_index;
9394         uint8_t  queue_id;
9395         cmdline_fixed_string_t queue_num;
9396         uint8_t  queue_num_value;
9397 };
9398
9399 static void
9400 cmd_queue_region_parsed(void *parsed_result,
9401                         __attribute__((unused)) struct cmdline *cl,
9402                         __attribute__((unused)) void *data)
9403 {
9404         struct cmd_queue_region_result *res = parsed_result;
9405         int ret = -ENOTSUP;
9406 #ifdef RTE_LIBRTE_I40E_PMD
9407         struct rte_pmd_i40e_queue_region_conf region_conf;
9408         enum rte_pmd_i40e_queue_region_op op_type;
9409 #endif
9410
9411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9412                 return;
9413
9414 #ifdef RTE_LIBRTE_I40E_PMD
9415         memset(&region_conf, 0, sizeof(region_conf));
9416         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9417         region_conf.region_id = res->region_id;
9418         region_conf.queue_num = res->queue_num_value;
9419         region_conf.queue_start_index = res->queue_id;
9420
9421         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9422                                 op_type, &region_conf);
9423 #endif
9424
9425         switch (ret) {
9426         case 0:
9427                 break;
9428         case -ENOTSUP:
9429                 printf("function not implemented or supported\n");
9430                 break;
9431         default:
9432                 printf("queue region config error: (%s)\n", strerror(-ret));
9433         }
9434 }
9435
9436 cmdline_parse_token_string_t cmd_queue_region_set =
9437 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9438                 set, "set");
9439 cmdline_parse_token_string_t cmd_queue_region_port =
9440         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9441 cmdline_parse_token_num_t cmd_queue_region_port_id =
9442         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9443                                 port_id, UINT16);
9444 cmdline_parse_token_string_t cmd_queue_region_cmd =
9445         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9446                                  cmd, "queue-region");
9447 cmdline_parse_token_string_t cmd_queue_region_id =
9448         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9449                                 region, "region_id");
9450 cmdline_parse_token_num_t cmd_queue_region_index =
9451         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9452                                 region_id, UINT8);
9453 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9454         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9455                                 queue_start_index, "queue_start_index");
9456 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9457         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9458                                 queue_id, UINT8);
9459 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9460         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9461                                 queue_num, "queue_num");
9462 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9463         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9464                                 queue_num_value, UINT8);
9465
9466 cmdline_parse_inst_t cmd_queue_region = {
9467         .f = cmd_queue_region_parsed,
9468         .data = NULL,
9469         .help_str = "set port <port_id> queue-region region_id <value> "
9470                 "queue_start_index <value> queue_num <value>: Set a queue region",
9471         .tokens = {
9472                 (void *)&cmd_queue_region_set,
9473                 (void *)&cmd_queue_region_port,
9474                 (void *)&cmd_queue_region_port_id,
9475                 (void *)&cmd_queue_region_cmd,
9476                 (void *)&cmd_queue_region_id,
9477                 (void *)&cmd_queue_region_index,
9478                 (void *)&cmd_queue_region_queue_start_index,
9479                 (void *)&cmd_queue_region_queue_id,
9480                 (void *)&cmd_queue_region_queue_num,
9481                 (void *)&cmd_queue_region_queue_num_value,
9482                 NULL,
9483         },
9484 };
9485
9486 /* *** queue region and flowtype set *** */
9487 struct cmd_region_flowtype_result {
9488         cmdline_fixed_string_t set;
9489         cmdline_fixed_string_t port;
9490         portid_t port_id;
9491         cmdline_fixed_string_t cmd;
9492         cmdline_fixed_string_t region;
9493         uint8_t  region_id;
9494         cmdline_fixed_string_t flowtype;
9495         uint8_t  flowtype_id;
9496 };
9497
9498 static void
9499 cmd_region_flowtype_parsed(void *parsed_result,
9500                         __attribute__((unused)) struct cmdline *cl,
9501                         __attribute__((unused)) void *data)
9502 {
9503         struct cmd_region_flowtype_result *res = parsed_result;
9504         int ret = -ENOTSUP;
9505 #ifdef RTE_LIBRTE_I40E_PMD
9506         struct rte_pmd_i40e_queue_region_conf region_conf;
9507         enum rte_pmd_i40e_queue_region_op op_type;
9508 #endif
9509
9510         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9511                 return;
9512
9513 #ifdef RTE_LIBRTE_I40E_PMD
9514         memset(&region_conf, 0, sizeof(region_conf));
9515
9516         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9517         region_conf.region_id = res->region_id;
9518         region_conf.hw_flowtype = res->flowtype_id;
9519
9520         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9521                         op_type, &region_conf);
9522 #endif
9523
9524         switch (ret) {
9525         case 0:
9526                 break;
9527         case -ENOTSUP:
9528                 printf("function not implemented or supported\n");
9529                 break;
9530         default:
9531                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9532         }
9533 }
9534
9535 cmdline_parse_token_string_t cmd_region_flowtype_set =
9536 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9537                                 set, "set");
9538 cmdline_parse_token_string_t cmd_region_flowtype_port =
9539         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9540                                 port, "port");
9541 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9542         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9543                                 port_id, UINT16);
9544 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9545         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9546                                 cmd, "queue-region");
9547 cmdline_parse_token_string_t cmd_region_flowtype_index =
9548         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9549                                 region, "region_id");
9550 cmdline_parse_token_num_t cmd_region_flowtype_id =
9551         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9552                                 region_id, UINT8);
9553 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9554         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9555                                 flowtype, "flowtype");
9556 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9557         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9558                                 flowtype_id, UINT8);
9559 cmdline_parse_inst_t cmd_region_flowtype = {
9560         .f = cmd_region_flowtype_parsed,
9561         .data = NULL,
9562         .help_str = "set port <port_id> queue-region region_id <value> "
9563                 "flowtype <value>: Set a flowtype region index",
9564         .tokens = {
9565                 (void *)&cmd_region_flowtype_set,
9566                 (void *)&cmd_region_flowtype_port,
9567                 (void *)&cmd_region_flowtype_port_index,
9568                 (void *)&cmd_region_flowtype_cmd,
9569                 (void *)&cmd_region_flowtype_index,
9570                 (void *)&cmd_region_flowtype_id,
9571                 (void *)&cmd_region_flowtype_flow_index,
9572                 (void *)&cmd_region_flowtype_flow_id,
9573                 NULL,
9574         },
9575 };
9576
9577 /* *** User Priority (UP) to queue region (region_id) set *** */
9578 struct cmd_user_priority_region_result {
9579         cmdline_fixed_string_t set;
9580         cmdline_fixed_string_t port;
9581         portid_t port_id;
9582         cmdline_fixed_string_t cmd;
9583         cmdline_fixed_string_t user_priority;
9584         uint8_t  user_priority_id;
9585         cmdline_fixed_string_t region;
9586         uint8_t  region_id;
9587 };
9588
9589 static void
9590 cmd_user_priority_region_parsed(void *parsed_result,
9591                         __attribute__((unused)) struct cmdline *cl,
9592                         __attribute__((unused)) void *data)
9593 {
9594         struct cmd_user_priority_region_result *res = parsed_result;
9595         int ret = -ENOTSUP;
9596 #ifdef RTE_LIBRTE_I40E_PMD
9597         struct rte_pmd_i40e_queue_region_conf region_conf;
9598         enum rte_pmd_i40e_queue_region_op op_type;
9599 #endif
9600
9601         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9602                 return;
9603
9604 #ifdef RTE_LIBRTE_I40E_PMD
9605         memset(&region_conf, 0, sizeof(region_conf));
9606         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9607         region_conf.user_priority = res->user_priority_id;
9608         region_conf.region_id = res->region_id;
9609
9610         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9611                                 op_type, &region_conf);
9612 #endif
9613
9614         switch (ret) {
9615         case 0:
9616                 break;
9617         case -ENOTSUP:
9618                 printf("function not implemented or supported\n");
9619                 break;
9620         default:
9621                 printf("user_priority region config error: (%s)\n",
9622                                 strerror(-ret));
9623         }
9624 }
9625
9626 cmdline_parse_token_string_t cmd_user_priority_region_set =
9627         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9628                                 set, "set");
9629 cmdline_parse_token_string_t cmd_user_priority_region_port =
9630         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9631                                 port, "port");
9632 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9633         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9634                                 port_id, UINT16);
9635 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9636         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9637                                 cmd, "queue-region");
9638 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9639         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9640                                 user_priority, "UP");
9641 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9642         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9643                                 user_priority_id, UINT8);
9644 cmdline_parse_token_string_t cmd_user_priority_region_region =
9645         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9646                                 region, "region_id");
9647 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9648         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9649                                 region_id, UINT8);
9650
9651 cmdline_parse_inst_t cmd_user_priority_region = {
9652         .f = cmd_user_priority_region_parsed,
9653         .data = NULL,
9654         .help_str = "set port <port_id> queue-region UP <value> "
9655                 "region_id <value>: Set the mapping of User Priority (UP) "
9656                 "to queue region (region_id) ",
9657         .tokens = {
9658                 (void *)&cmd_user_priority_region_set,
9659                 (void *)&cmd_user_priority_region_port,
9660                 (void *)&cmd_user_priority_region_port_index,
9661                 (void *)&cmd_user_priority_region_cmd,
9662                 (void *)&cmd_user_priority_region_UP,
9663                 (void *)&cmd_user_priority_region_UP_id,
9664                 (void *)&cmd_user_priority_region_region,
9665                 (void *)&cmd_user_priority_region_region_id,
9666                 NULL,
9667         },
9668 };
9669
9670 /* *** flush all queue region related configuration *** */
9671 struct cmd_flush_queue_region_result {
9672         cmdline_fixed_string_t set;
9673         cmdline_fixed_string_t port;
9674         portid_t port_id;
9675         cmdline_fixed_string_t cmd;
9676         cmdline_fixed_string_t flush;
9677         cmdline_fixed_string_t what;
9678 };
9679
9680 static void
9681 cmd_flush_queue_region_parsed(void *parsed_result,
9682                         __attribute__((unused)) struct cmdline *cl,
9683                         __attribute__((unused)) void *data)
9684 {
9685         struct cmd_flush_queue_region_result *res = parsed_result;
9686         int ret = -ENOTSUP;
9687 #ifdef RTE_LIBRTE_I40E_PMD
9688         struct rte_pmd_i40e_queue_region_conf region_conf;
9689         enum rte_pmd_i40e_queue_region_op op_type;
9690 #endif
9691
9692         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9693                 return;
9694
9695 #ifdef RTE_LIBRTE_I40E_PMD
9696         memset(&region_conf, 0, sizeof(region_conf));
9697
9698         if (strcmp(res->what, "on") == 0)
9699                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9700         else
9701                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9702
9703         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9704                                 op_type, &region_conf);
9705 #endif
9706
9707         switch (ret) {
9708         case 0:
9709                 break;
9710         case -ENOTSUP:
9711                 printf("function not implemented or supported\n");
9712                 break;
9713         default:
9714                 printf("queue region config flush error: (%s)\n",
9715                                 strerror(-ret));
9716         }
9717 }
9718
9719 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9720         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9721                                 set, "set");
9722 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9723         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9724                                 port, "port");
9725 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9726         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9727                                 port_id, UINT16);
9728 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9729         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9730                                 cmd, "queue-region");
9731 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9732         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9733                                 flush, "flush");
9734 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9735         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9736                                 what, "on#off");
9737
9738 cmdline_parse_inst_t cmd_flush_queue_region = {
9739         .f = cmd_flush_queue_region_parsed,
9740         .data = NULL,
9741         .help_str = "set port <port_id> queue-region flush on|off"
9742                 ": flush all queue region related configuration",
9743         .tokens = {
9744                 (void *)&cmd_flush_queue_region_set,
9745                 (void *)&cmd_flush_queue_region_port,
9746                 (void *)&cmd_flush_queue_region_port_index,
9747                 (void *)&cmd_flush_queue_region_cmd,
9748                 (void *)&cmd_flush_queue_region_flush,
9749                 (void *)&cmd_flush_queue_region_what,
9750                 NULL,
9751         },
9752 };
9753
9754 /* *** get all queue region related configuration info *** */
9755 struct cmd_show_queue_region_info {
9756         cmdline_fixed_string_t show;
9757         cmdline_fixed_string_t port;
9758         portid_t port_id;
9759         cmdline_fixed_string_t cmd;
9760 };
9761
9762 static void
9763 cmd_show_queue_region_info_parsed(void *parsed_result,
9764                         __attribute__((unused)) struct cmdline *cl,
9765                         __attribute__((unused)) void *data)
9766 {
9767         struct cmd_show_queue_region_info *res = parsed_result;
9768         int ret = -ENOTSUP;
9769 #ifdef RTE_LIBRTE_I40E_PMD
9770         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9771         enum rte_pmd_i40e_queue_region_op op_type;
9772 #endif
9773
9774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9775                 return;
9776
9777 #ifdef RTE_LIBRTE_I40E_PMD
9778         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9779
9780         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9781
9782         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9783                                         op_type, &rte_pmd_regions);
9784
9785         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9786 #endif
9787
9788         switch (ret) {
9789         case 0:
9790                 break;
9791         case -ENOTSUP:
9792                 printf("function not implemented or supported\n");
9793                 break;
9794         default:
9795                 printf("queue region config info show error: (%s)\n",
9796                                 strerror(-ret));
9797         }
9798 }
9799
9800 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9801 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9802                                 show, "show");
9803 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9804         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9805                                 port, "port");
9806 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9807         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9808                                 port_id, UINT16);
9809 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9810         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9811                                 cmd, "queue-region");
9812
9813 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9814         .f = cmd_show_queue_region_info_parsed,
9815         .data = NULL,
9816         .help_str = "show port <port_id> queue-region"
9817                 ": show all queue region related configuration info",
9818         .tokens = {
9819                 (void *)&cmd_show_queue_region_info_get,
9820                 (void *)&cmd_show_queue_region_info_port,
9821                 (void *)&cmd_show_queue_region_info_port_index,
9822                 (void *)&cmd_show_queue_region_info_cmd,
9823                 NULL,
9824         },
9825 };
9826
9827 /* *** ADD/REMOVE A 2tuple FILTER *** */
9828 struct cmd_2tuple_filter_result {
9829         cmdline_fixed_string_t filter;
9830         portid_t port_id;
9831         cmdline_fixed_string_t ops;
9832         cmdline_fixed_string_t dst_port;
9833         uint16_t dst_port_value;
9834         cmdline_fixed_string_t protocol;
9835         uint8_t protocol_value;
9836         cmdline_fixed_string_t mask;
9837         uint8_t  mask_value;
9838         cmdline_fixed_string_t tcp_flags;
9839         uint8_t tcp_flags_value;
9840         cmdline_fixed_string_t priority;
9841         uint8_t  priority_value;
9842         cmdline_fixed_string_t queue;
9843         uint16_t  queue_id;
9844 };
9845
9846 static void
9847 cmd_2tuple_filter_parsed(void *parsed_result,
9848                         __attribute__((unused)) struct cmdline *cl,
9849                         __attribute__((unused)) void *data)
9850 {
9851         struct rte_eth_ntuple_filter filter;
9852         struct cmd_2tuple_filter_result *res = parsed_result;
9853         int ret = 0;
9854
9855         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9856         if (ret < 0) {
9857                 printf("ntuple filter is not supported on port %u.\n",
9858                         res->port_id);
9859                 return;
9860         }
9861
9862         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9863
9864         filter.flags = RTE_2TUPLE_FLAGS;
9865         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9866         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9867         filter.proto = res->protocol_value;
9868         filter.priority = res->priority_value;
9869         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9870                 printf("nonzero tcp_flags is only meaningful"
9871                         " when protocol is TCP.\n");
9872                 return;
9873         }
9874         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9875                 printf("invalid TCP flags.\n");
9876                 return;
9877         }
9878
9879         if (res->tcp_flags_value != 0) {
9880                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9881                 filter.tcp_flags = res->tcp_flags_value;
9882         }
9883
9884         /* need convert to big endian. */
9885         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9886         filter.queue = res->queue_id;
9887
9888         if (!strcmp(res->ops, "add"))
9889                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9890                                 RTE_ETH_FILTER_NTUPLE,
9891                                 RTE_ETH_FILTER_ADD,
9892                                 &filter);
9893         else
9894                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9895                                 RTE_ETH_FILTER_NTUPLE,
9896                                 RTE_ETH_FILTER_DELETE,
9897                                 &filter);
9898         if (ret < 0)
9899                 printf("2tuple filter programming error: (%s)\n",
9900                         strerror(-ret));
9901
9902 }
9903
9904 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9905         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9906                                  filter, "2tuple_filter");
9907 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9908         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9909                                 port_id, UINT16);
9910 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9911         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9912                                  ops, "add#del");
9913 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9914         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9915                                 dst_port, "dst_port");
9916 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9917         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9918                                 dst_port_value, UINT16);
9919 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9920         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9921                                 protocol, "protocol");
9922 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9923         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9924                                 protocol_value, UINT8);
9925 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9926         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9927                                 mask, "mask");
9928 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9929         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9930                                 mask_value, INT8);
9931 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9932         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9933                                 tcp_flags, "tcp_flags");
9934 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9935         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9936                                 tcp_flags_value, UINT8);
9937 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9938         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9939                                 priority, "priority");
9940 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9941         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9942                                 priority_value, UINT8);
9943 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9944         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9945                                 queue, "queue");
9946 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9947         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9948                                 queue_id, UINT16);
9949
9950 cmdline_parse_inst_t cmd_2tuple_filter = {
9951         .f = cmd_2tuple_filter_parsed,
9952         .data = NULL,
9953         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9954                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9955                 "<queue_id>: Add a 2tuple filter",
9956         .tokens = {
9957                 (void *)&cmd_2tuple_filter_filter,
9958                 (void *)&cmd_2tuple_filter_port_id,
9959                 (void *)&cmd_2tuple_filter_ops,
9960                 (void *)&cmd_2tuple_filter_dst_port,
9961                 (void *)&cmd_2tuple_filter_dst_port_value,
9962                 (void *)&cmd_2tuple_filter_protocol,
9963                 (void *)&cmd_2tuple_filter_protocol_value,
9964                 (void *)&cmd_2tuple_filter_mask,
9965                 (void *)&cmd_2tuple_filter_mask_value,
9966                 (void *)&cmd_2tuple_filter_tcp_flags,
9967                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9968                 (void *)&cmd_2tuple_filter_priority,
9969                 (void *)&cmd_2tuple_filter_priority_value,
9970                 (void *)&cmd_2tuple_filter_queue,
9971                 (void *)&cmd_2tuple_filter_queue_id,
9972                 NULL,
9973         },
9974 };
9975
9976 /* *** ADD/REMOVE A 5tuple FILTER *** */
9977 struct cmd_5tuple_filter_result {
9978         cmdline_fixed_string_t filter;
9979         portid_t port_id;
9980         cmdline_fixed_string_t ops;
9981         cmdline_fixed_string_t dst_ip;
9982         cmdline_ipaddr_t dst_ip_value;
9983         cmdline_fixed_string_t src_ip;
9984         cmdline_ipaddr_t src_ip_value;
9985         cmdline_fixed_string_t dst_port;
9986         uint16_t dst_port_value;
9987         cmdline_fixed_string_t src_port;
9988         uint16_t src_port_value;
9989         cmdline_fixed_string_t protocol;
9990         uint8_t protocol_value;
9991         cmdline_fixed_string_t mask;
9992         uint8_t  mask_value;
9993         cmdline_fixed_string_t tcp_flags;
9994         uint8_t tcp_flags_value;
9995         cmdline_fixed_string_t priority;
9996         uint8_t  priority_value;
9997         cmdline_fixed_string_t queue;
9998         uint16_t  queue_id;
9999 };
10000
10001 static void
10002 cmd_5tuple_filter_parsed(void *parsed_result,
10003                         __attribute__((unused)) struct cmdline *cl,
10004                         __attribute__((unused)) void *data)
10005 {
10006         struct rte_eth_ntuple_filter filter;
10007         struct cmd_5tuple_filter_result *res = parsed_result;
10008         int ret = 0;
10009
10010         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10011         if (ret < 0) {
10012                 printf("ntuple filter is not supported on port %u.\n",
10013                         res->port_id);
10014                 return;
10015         }
10016
10017         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10018
10019         filter.flags = RTE_5TUPLE_FLAGS;
10020         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10021         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10022         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10023         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10024         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10025         filter.proto = res->protocol_value;
10026         filter.priority = res->priority_value;
10027         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10028                 printf("nonzero tcp_flags is only meaningful"
10029                         " when protocol is TCP.\n");
10030                 return;
10031         }
10032         if (res->tcp_flags_value > TCP_FLAG_ALL) {
10033                 printf("invalid TCP flags.\n");
10034                 return;
10035         }
10036
10037         if (res->tcp_flags_value != 0) {
10038                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10039                 filter.tcp_flags = res->tcp_flags_value;
10040         }
10041
10042         if (res->dst_ip_value.family == AF_INET)
10043                 /* no need to convert, already big endian. */
10044                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10045         else {
10046                 if (filter.dst_ip_mask == 0) {
10047                         printf("can not support ipv6 involved compare.\n");
10048                         return;
10049                 }
10050                 filter.dst_ip = 0;
10051         }
10052
10053         if (res->src_ip_value.family == AF_INET)
10054                 /* no need to convert, already big endian. */
10055                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10056         else {
10057                 if (filter.src_ip_mask == 0) {
10058                         printf("can not support ipv6 involved compare.\n");
10059                         return;
10060                 }
10061                 filter.src_ip = 0;
10062         }
10063         /* need convert to big endian. */
10064         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10065         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10066         filter.queue = res->queue_id;
10067
10068         if (!strcmp(res->ops, "add"))
10069                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10070                                 RTE_ETH_FILTER_NTUPLE,
10071                                 RTE_ETH_FILTER_ADD,
10072                                 &filter);
10073         else
10074                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10075                                 RTE_ETH_FILTER_NTUPLE,
10076                                 RTE_ETH_FILTER_DELETE,
10077                                 &filter);
10078         if (ret < 0)
10079                 printf("5tuple filter programming error: (%s)\n",
10080                         strerror(-ret));
10081 }
10082
10083 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10084         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10085                                  filter, "5tuple_filter");
10086 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10087         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10088                                 port_id, UINT16);
10089 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10090         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10091                                  ops, "add#del");
10092 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10093         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10094                                 dst_ip, "dst_ip");
10095 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10096         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10097                                 dst_ip_value);
10098 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10099         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10100                                 src_ip, "src_ip");
10101 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10102         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10103                                 src_ip_value);
10104 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10105         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10106                                 dst_port, "dst_port");
10107 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10108         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10109                                 dst_port_value, UINT16);
10110 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10111         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10112                                 src_port, "src_port");
10113 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10114         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10115                                 src_port_value, UINT16);
10116 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10117         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10118                                 protocol, "protocol");
10119 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10120         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10121                                 protocol_value, UINT8);
10122 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10123         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10124                                 mask, "mask");
10125 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10126         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10127                                 mask_value, INT8);
10128 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10129         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10130                                 tcp_flags, "tcp_flags");
10131 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10132         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10133                                 tcp_flags_value, UINT8);
10134 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10135         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10136                                 priority, "priority");
10137 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10138         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10139                                 priority_value, UINT8);
10140 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10141         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10142                                 queue, "queue");
10143 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10144         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10145                                 queue_id, UINT16);
10146
10147 cmdline_parse_inst_t cmd_5tuple_filter = {
10148         .f = cmd_5tuple_filter_parsed,
10149         .data = NULL,
10150         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10151                 "src_ip <value> dst_port <value> src_port <value> "
10152                 "protocol <value>  mask <value> tcp_flags <value> "
10153                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10154         .tokens = {
10155                 (void *)&cmd_5tuple_filter_filter,
10156                 (void *)&cmd_5tuple_filter_port_id,
10157                 (void *)&cmd_5tuple_filter_ops,
10158                 (void *)&cmd_5tuple_filter_dst_ip,
10159                 (void *)&cmd_5tuple_filter_dst_ip_value,
10160                 (void *)&cmd_5tuple_filter_src_ip,
10161                 (void *)&cmd_5tuple_filter_src_ip_value,
10162                 (void *)&cmd_5tuple_filter_dst_port,
10163                 (void *)&cmd_5tuple_filter_dst_port_value,
10164                 (void *)&cmd_5tuple_filter_src_port,
10165                 (void *)&cmd_5tuple_filter_src_port_value,
10166                 (void *)&cmd_5tuple_filter_protocol,
10167                 (void *)&cmd_5tuple_filter_protocol_value,
10168                 (void *)&cmd_5tuple_filter_mask,
10169                 (void *)&cmd_5tuple_filter_mask_value,
10170                 (void *)&cmd_5tuple_filter_tcp_flags,
10171                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10172                 (void *)&cmd_5tuple_filter_priority,
10173                 (void *)&cmd_5tuple_filter_priority_value,
10174                 (void *)&cmd_5tuple_filter_queue,
10175                 (void *)&cmd_5tuple_filter_queue_id,
10176                 NULL,
10177         },
10178 };
10179
10180 /* *** ADD/REMOVE A flex FILTER *** */
10181 struct cmd_flex_filter_result {
10182         cmdline_fixed_string_t filter;
10183         cmdline_fixed_string_t ops;
10184         portid_t port_id;
10185         cmdline_fixed_string_t len;
10186         uint8_t len_value;
10187         cmdline_fixed_string_t bytes;
10188         cmdline_fixed_string_t bytes_value;
10189         cmdline_fixed_string_t mask;
10190         cmdline_fixed_string_t mask_value;
10191         cmdline_fixed_string_t priority;
10192         uint8_t priority_value;
10193         cmdline_fixed_string_t queue;
10194         uint16_t queue_id;
10195 };
10196
10197 static int xdigit2val(unsigned char c)
10198 {
10199         int val;
10200         if (isdigit(c))
10201                 val = c - '0';
10202         else if (isupper(c))
10203                 val = c - 'A' + 10;
10204         else
10205                 val = c - 'a' + 10;
10206         return val;
10207 }
10208
10209 static void
10210 cmd_flex_filter_parsed(void *parsed_result,
10211                           __attribute__((unused)) struct cmdline *cl,
10212                           __attribute__((unused)) void *data)
10213 {
10214         int ret = 0;
10215         struct rte_eth_flex_filter filter;
10216         struct cmd_flex_filter_result *res = parsed_result;
10217         char *bytes_ptr, *mask_ptr;
10218         uint16_t len, i, j = 0;
10219         char c;
10220         int val;
10221         uint8_t byte = 0;
10222
10223         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10224                 printf("the len exceed the max length 128\n");
10225                 return;
10226         }
10227         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10228         filter.len = res->len_value;
10229         filter.priority = res->priority_value;
10230         filter.queue = res->queue_id;
10231         bytes_ptr = res->bytes_value;
10232         mask_ptr = res->mask_value;
10233
10234          /* translate bytes string to array. */
10235         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10236                 (bytes_ptr[1] == 'X')))
10237                 bytes_ptr += 2;
10238         len = strnlen(bytes_ptr, res->len_value * 2);
10239         if (len == 0 || (len % 8 != 0)) {
10240                 printf("please check len and bytes input\n");
10241                 return;
10242         }
10243         for (i = 0; i < len; i++) {
10244                 c = bytes_ptr[i];
10245                 if (isxdigit(c) == 0) {
10246                         /* invalid characters. */
10247                         printf("invalid input\n");
10248                         return;
10249                 }
10250                 val = xdigit2val(c);
10251                 if (i % 2) {
10252                         byte |= val;
10253                         filter.bytes[j] = byte;
10254                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10255                         j++;
10256                         byte = 0;
10257                 } else
10258                         byte |= val << 4;
10259         }
10260         printf("\n");
10261          /* translate mask string to uint8_t array. */
10262         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10263                 (mask_ptr[1] == 'X')))
10264                 mask_ptr += 2;
10265         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10266         if (len == 0) {
10267                 printf("invalid input\n");
10268                 return;
10269         }
10270         j = 0;
10271         byte = 0;
10272         for (i = 0; i < len; i++) {
10273                 c = mask_ptr[i];
10274                 if (isxdigit(c) == 0) {
10275                         /* invalid characters. */
10276                         printf("invalid input\n");
10277                         return;
10278                 }
10279                 val = xdigit2val(c);
10280                 if (i % 2) {
10281                         byte |= val;
10282                         filter.mask[j] = byte;
10283                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10284                         j++;
10285                         byte = 0;
10286                 } else
10287                         byte |= val << 4;
10288         }
10289         printf("\n");
10290
10291         if (!strcmp(res->ops, "add"))
10292                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10293                                 RTE_ETH_FILTER_FLEXIBLE,
10294                                 RTE_ETH_FILTER_ADD,
10295                                 &filter);
10296         else
10297                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10298                                 RTE_ETH_FILTER_FLEXIBLE,
10299                                 RTE_ETH_FILTER_DELETE,
10300                                 &filter);
10301
10302         if (ret < 0)
10303                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10304 }
10305
10306 cmdline_parse_token_string_t cmd_flex_filter_filter =
10307         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10308                                 filter, "flex_filter");
10309 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10310         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10311                                 port_id, UINT16);
10312 cmdline_parse_token_string_t cmd_flex_filter_ops =
10313         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10314                                 ops, "add#del");
10315 cmdline_parse_token_string_t cmd_flex_filter_len =
10316         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10317                                 len, "len");
10318 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10319         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10320                                 len_value, UINT8);
10321 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10322         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10323                                 bytes, "bytes");
10324 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10325         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10326                                 bytes_value, NULL);
10327 cmdline_parse_token_string_t cmd_flex_filter_mask =
10328         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10329                                 mask, "mask");
10330 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10331         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10332                                 mask_value, NULL);
10333 cmdline_parse_token_string_t cmd_flex_filter_priority =
10334         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10335                                 priority, "priority");
10336 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10337         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10338                                 priority_value, UINT8);
10339 cmdline_parse_token_string_t cmd_flex_filter_queue =
10340         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10341                                 queue, "queue");
10342 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10343         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10344                                 queue_id, UINT16);
10345 cmdline_parse_inst_t cmd_flex_filter = {
10346         .f = cmd_flex_filter_parsed,
10347         .data = NULL,
10348         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10349                 "<value> mask <value> priority <value> queue <queue_id>: "
10350                 "Add/Del a flex filter",
10351         .tokens = {
10352                 (void *)&cmd_flex_filter_filter,
10353                 (void *)&cmd_flex_filter_port_id,
10354                 (void *)&cmd_flex_filter_ops,
10355                 (void *)&cmd_flex_filter_len,
10356                 (void *)&cmd_flex_filter_len_value,
10357                 (void *)&cmd_flex_filter_bytes,
10358                 (void *)&cmd_flex_filter_bytes_value,
10359                 (void *)&cmd_flex_filter_mask,
10360                 (void *)&cmd_flex_filter_mask_value,
10361                 (void *)&cmd_flex_filter_priority,
10362                 (void *)&cmd_flex_filter_priority_value,
10363                 (void *)&cmd_flex_filter_queue,
10364                 (void *)&cmd_flex_filter_queue_id,
10365                 NULL,
10366         },
10367 };
10368
10369 /* *** Filters Control *** */
10370
10371 /* *** deal with ethertype filter *** */
10372 struct cmd_ethertype_filter_result {
10373         cmdline_fixed_string_t filter;
10374         portid_t port_id;
10375         cmdline_fixed_string_t ops;
10376         cmdline_fixed_string_t mac;
10377         struct ether_addr mac_addr;
10378         cmdline_fixed_string_t ethertype;
10379         uint16_t ethertype_value;
10380         cmdline_fixed_string_t drop;
10381         cmdline_fixed_string_t queue;
10382         uint16_t  queue_id;
10383 };
10384
10385 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10386         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10387                                  filter, "ethertype_filter");
10388 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10389         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10390                               port_id, UINT16);
10391 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10392         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10393                                  ops, "add#del");
10394 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10395         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10396                                  mac, "mac_addr#mac_ignr");
10397 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10398         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10399                                      mac_addr);
10400 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10401         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10402                                  ethertype, "ethertype");
10403 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10404         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10405                               ethertype_value, UINT16);
10406 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10407         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10408                                  drop, "drop#fwd");
10409 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10410         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10411                                  queue, "queue");
10412 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10413         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10414                               queue_id, UINT16);
10415
10416 static void
10417 cmd_ethertype_filter_parsed(void *parsed_result,
10418                           __attribute__((unused)) struct cmdline *cl,
10419                           __attribute__((unused)) void *data)
10420 {
10421         struct cmd_ethertype_filter_result *res = parsed_result;
10422         struct rte_eth_ethertype_filter filter;
10423         int ret = 0;
10424
10425         ret = rte_eth_dev_filter_supported(res->port_id,
10426                         RTE_ETH_FILTER_ETHERTYPE);
10427         if (ret < 0) {
10428                 printf("ethertype filter is not supported on port %u.\n",
10429                         res->port_id);
10430                 return;
10431         }
10432
10433         memset(&filter, 0, sizeof(filter));
10434         if (!strcmp(res->mac, "mac_addr")) {
10435                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10436                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10437                         sizeof(struct ether_addr));
10438         }
10439         if (!strcmp(res->drop, "drop"))
10440                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10441         filter.ether_type = res->ethertype_value;
10442         filter.queue = res->queue_id;
10443
10444         if (!strcmp(res->ops, "add"))
10445                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10446                                 RTE_ETH_FILTER_ETHERTYPE,
10447                                 RTE_ETH_FILTER_ADD,
10448                                 &filter);
10449         else
10450                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10451                                 RTE_ETH_FILTER_ETHERTYPE,
10452                                 RTE_ETH_FILTER_DELETE,
10453                                 &filter);
10454         if (ret < 0)
10455                 printf("ethertype filter programming error: (%s)\n",
10456                         strerror(-ret));
10457 }
10458
10459 cmdline_parse_inst_t cmd_ethertype_filter = {
10460         .f = cmd_ethertype_filter_parsed,
10461         .data = NULL,
10462         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10463                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10464                 "Add or delete an ethertype filter entry",
10465         .tokens = {
10466                 (void *)&cmd_ethertype_filter_filter,
10467                 (void *)&cmd_ethertype_filter_port_id,
10468                 (void *)&cmd_ethertype_filter_ops,
10469                 (void *)&cmd_ethertype_filter_mac,
10470                 (void *)&cmd_ethertype_filter_mac_addr,
10471                 (void *)&cmd_ethertype_filter_ethertype,
10472                 (void *)&cmd_ethertype_filter_ethertype_value,
10473                 (void *)&cmd_ethertype_filter_drop,
10474                 (void *)&cmd_ethertype_filter_queue,
10475                 (void *)&cmd_ethertype_filter_queue_id,
10476                 NULL,
10477         },
10478 };
10479
10480 /* *** deal with flow director filter *** */
10481 struct cmd_flow_director_result {
10482         cmdline_fixed_string_t flow_director_filter;
10483         portid_t port_id;
10484         cmdline_fixed_string_t mode;
10485         cmdline_fixed_string_t mode_value;
10486         cmdline_fixed_string_t ops;
10487         cmdline_fixed_string_t flow;
10488         cmdline_fixed_string_t flow_type;
10489         cmdline_fixed_string_t ether;
10490         uint16_t ether_type;
10491         cmdline_fixed_string_t src;
10492         cmdline_ipaddr_t ip_src;
10493         uint16_t port_src;
10494         cmdline_fixed_string_t dst;
10495         cmdline_ipaddr_t ip_dst;
10496         uint16_t port_dst;
10497         cmdline_fixed_string_t verify_tag;
10498         uint32_t verify_tag_value;
10499         cmdline_fixed_string_t tos;
10500         uint8_t tos_value;
10501         cmdline_fixed_string_t proto;
10502         uint8_t proto_value;
10503         cmdline_fixed_string_t ttl;
10504         uint8_t ttl_value;
10505         cmdline_fixed_string_t vlan;
10506         uint16_t vlan_value;
10507         cmdline_fixed_string_t flexbytes;
10508         cmdline_fixed_string_t flexbytes_value;
10509         cmdline_fixed_string_t pf_vf;
10510         cmdline_fixed_string_t drop;
10511         cmdline_fixed_string_t queue;
10512         uint16_t  queue_id;
10513         cmdline_fixed_string_t fd_id;
10514         uint32_t  fd_id_value;
10515         cmdline_fixed_string_t mac;
10516         struct ether_addr mac_addr;
10517         cmdline_fixed_string_t tunnel;
10518         cmdline_fixed_string_t tunnel_type;
10519         cmdline_fixed_string_t tunnel_id;
10520         uint32_t tunnel_id_value;
10521         cmdline_fixed_string_t packet;
10522         char filepath[];
10523 };
10524
10525 static inline int
10526 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10527 {
10528         char s[256];
10529         const char *p, *p0 = q_arg;
10530         char *end;
10531         unsigned long int_fld;
10532         char *str_fld[max_num];
10533         int i;
10534         unsigned size;
10535         int ret = -1;
10536
10537         p = strchr(p0, '(');
10538         if (p == NULL)
10539                 return -1;
10540         ++p;
10541         p0 = strchr(p, ')');
10542         if (p0 == NULL)
10543                 return -1;
10544
10545         size = p0 - p;
10546         if (size >= sizeof(s))
10547                 return -1;
10548
10549         snprintf(s, sizeof(s), "%.*s", size, p);
10550         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10551         if (ret < 0 || ret > max_num)
10552                 return -1;
10553         for (i = 0; i < ret; i++) {
10554                 errno = 0;
10555                 int_fld = strtoul(str_fld[i], &end, 0);
10556                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10557                         return -1;
10558                 flexbytes[i] = (uint8_t)int_fld;
10559         }
10560         return ret;
10561 }
10562
10563 static uint16_t
10564 str2flowtype(char *string)
10565 {
10566         uint8_t i = 0;
10567         static const struct {
10568                 char str[32];
10569                 uint16_t type;
10570         } flowtype_str[] = {
10571                 {"raw", RTE_ETH_FLOW_RAW},
10572                 {"ipv4", RTE_ETH_FLOW_IPV4},
10573                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10574                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10575                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10576                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10577                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10578                 {"ipv6", RTE_ETH_FLOW_IPV6},
10579                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10580                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10581                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10582                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10583                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10584                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10585         };
10586
10587         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10588                 if (!strcmp(flowtype_str[i].str, string))
10589                         return flowtype_str[i].type;
10590         }
10591
10592         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10593                 return (uint16_t)atoi(string);
10594
10595         return RTE_ETH_FLOW_UNKNOWN;
10596 }
10597
10598 static enum rte_eth_fdir_tunnel_type
10599 str2fdir_tunneltype(char *string)
10600 {
10601         uint8_t i = 0;
10602
10603         static const struct {
10604                 char str[32];
10605                 enum rte_eth_fdir_tunnel_type type;
10606         } tunneltype_str[] = {
10607                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10608                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10609         };
10610
10611         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10612                 if (!strcmp(tunneltype_str[i].str, string))
10613                         return tunneltype_str[i].type;
10614         }
10615         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10616 }
10617
10618 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10619 do { \
10620         if ((ip_addr).family == AF_INET) \
10621                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10622         else { \
10623                 printf("invalid parameter.\n"); \
10624                 return; \
10625         } \
10626 } while (0)
10627
10628 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10629 do { \
10630         if ((ip_addr).family == AF_INET6) \
10631                 rte_memcpy(&(ip), \
10632                                  &((ip_addr).addr.ipv6), \
10633                                  sizeof(struct in6_addr)); \
10634         else { \
10635                 printf("invalid parameter.\n"); \
10636                 return; \
10637         } \
10638 } while (0)
10639
10640 static void
10641 cmd_flow_director_filter_parsed(void *parsed_result,
10642                           __attribute__((unused)) struct cmdline *cl,
10643                           __attribute__((unused)) void *data)
10644 {
10645         struct cmd_flow_director_result *res = parsed_result;
10646         struct rte_eth_fdir_filter entry;
10647         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10648         char *end;
10649         unsigned long vf_id;
10650         int ret = 0;
10651
10652         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10653         if (ret < 0) {
10654                 printf("flow director is not supported on port %u.\n",
10655                         res->port_id);
10656                 return;
10657         }
10658         memset(flexbytes, 0, sizeof(flexbytes));
10659         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10660
10661         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10662                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10663                         printf("Please set mode to MAC-VLAN.\n");
10664                         return;
10665                 }
10666         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10667                 if (strcmp(res->mode_value, "Tunnel")) {
10668                         printf("Please set mode to Tunnel.\n");
10669                         return;
10670                 }
10671         } else {
10672                 if (!strcmp(res->mode_value, "raw")) {
10673 #ifdef RTE_LIBRTE_I40E_PMD
10674                         struct rte_pmd_i40e_flow_type_mapping
10675                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10676                         struct rte_pmd_i40e_pkt_template_conf conf;
10677                         uint16_t flow_type = str2flowtype(res->flow_type);
10678                         uint16_t i, port = res->port_id;
10679                         uint8_t add;
10680
10681                         memset(&conf, 0, sizeof(conf));
10682
10683                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10684                                 printf("Invalid flow type specified.\n");
10685                                 return;
10686                         }
10687                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10688                                                                  mapping);
10689                         if (ret)
10690                                 return;
10691                         if (mapping[flow_type].pctype == 0ULL) {
10692                                 printf("Invalid flow type specified.\n");
10693                                 return;
10694                         }
10695                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10696                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10697                                         conf.input.pctype = i;
10698                                         break;
10699                                 }
10700                         }
10701
10702                         conf.input.packet = open_file(res->filepath,
10703                                                 &conf.input.length);
10704                         if (!conf.input.packet)
10705                                 return;
10706                         if (!strcmp(res->drop, "drop"))
10707                                 conf.action.behavior =
10708                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10709                         else
10710                                 conf.action.behavior =
10711                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10712                         conf.action.report_status =
10713                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10714                         conf.action.rx_queue = res->queue_id;
10715                         conf.soft_id = res->fd_id_value;
10716                         add  = strcmp(res->ops, "del") ? 1 : 0;
10717                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10718                                                                         &conf,
10719                                                                         add);
10720                         if (ret < 0)
10721                                 printf("flow director config error: (%s)\n",
10722                                        strerror(-ret));
10723                         close_file(conf.input.packet);
10724 #endif
10725                         return;
10726                 } else if (strcmp(res->mode_value, "IP")) {
10727                         printf("Please set mode to IP or raw.\n");
10728                         return;
10729                 }
10730                 entry.input.flow_type = str2flowtype(res->flow_type);
10731         }
10732
10733         ret = parse_flexbytes(res->flexbytes_value,
10734                                         flexbytes,
10735                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10736         if (ret < 0) {
10737                 printf("error: Cannot parse flexbytes input.\n");
10738                 return;
10739         }
10740
10741         switch (entry.input.flow_type) {
10742         case RTE_ETH_FLOW_FRAG_IPV4:
10743         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10744                 entry.input.flow.ip4_flow.proto = res->proto_value;
10745                 /* fall-through */
10746         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10747         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10748                 IPV4_ADDR_TO_UINT(res->ip_dst,
10749                         entry.input.flow.ip4_flow.dst_ip);
10750                 IPV4_ADDR_TO_UINT(res->ip_src,
10751                         entry.input.flow.ip4_flow.src_ip);
10752                 entry.input.flow.ip4_flow.tos = res->tos_value;
10753                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10754                 /* need convert to big endian. */
10755                 entry.input.flow.udp4_flow.dst_port =
10756                                 rte_cpu_to_be_16(res->port_dst);
10757                 entry.input.flow.udp4_flow.src_port =
10758                                 rte_cpu_to_be_16(res->port_src);
10759                 break;
10760         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10761                 IPV4_ADDR_TO_UINT(res->ip_dst,
10762                         entry.input.flow.sctp4_flow.ip.dst_ip);
10763                 IPV4_ADDR_TO_UINT(res->ip_src,
10764                         entry.input.flow.sctp4_flow.ip.src_ip);
10765                 entry.input.flow.ip4_flow.tos = res->tos_value;
10766                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10767                 /* need convert to big endian. */
10768                 entry.input.flow.sctp4_flow.dst_port =
10769                                 rte_cpu_to_be_16(res->port_dst);
10770                 entry.input.flow.sctp4_flow.src_port =
10771                                 rte_cpu_to_be_16(res->port_src);
10772                 entry.input.flow.sctp4_flow.verify_tag =
10773                                 rte_cpu_to_be_32(res->verify_tag_value);
10774                 break;
10775         case RTE_ETH_FLOW_FRAG_IPV6:
10776         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10777                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10778                 /* fall-through */
10779         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10780         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10781                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10782                         entry.input.flow.ipv6_flow.dst_ip);
10783                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10784                         entry.input.flow.ipv6_flow.src_ip);
10785                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10786                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10787                 /* need convert to big endian. */
10788                 entry.input.flow.udp6_flow.dst_port =
10789                                 rte_cpu_to_be_16(res->port_dst);
10790                 entry.input.flow.udp6_flow.src_port =
10791                                 rte_cpu_to_be_16(res->port_src);
10792                 break;
10793         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10794                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10795                         entry.input.flow.sctp6_flow.ip.dst_ip);
10796                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10797                         entry.input.flow.sctp6_flow.ip.src_ip);
10798                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10799                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10800                 /* need convert to big endian. */
10801                 entry.input.flow.sctp6_flow.dst_port =
10802                                 rte_cpu_to_be_16(res->port_dst);
10803                 entry.input.flow.sctp6_flow.src_port =
10804                                 rte_cpu_to_be_16(res->port_src);
10805                 entry.input.flow.sctp6_flow.verify_tag =
10806                                 rte_cpu_to_be_32(res->verify_tag_value);
10807                 break;
10808         case RTE_ETH_FLOW_L2_PAYLOAD:
10809                 entry.input.flow.l2_flow.ether_type =
10810                         rte_cpu_to_be_16(res->ether_type);
10811                 break;
10812         default:
10813                 break;
10814         }
10815
10816         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10817                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10818                                  &res->mac_addr,
10819                                  sizeof(struct ether_addr));
10820
10821         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10822                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10823                                  &res->mac_addr,
10824                                  sizeof(struct ether_addr));
10825                 entry.input.flow.tunnel_flow.tunnel_type =
10826                         str2fdir_tunneltype(res->tunnel_type);
10827                 entry.input.flow.tunnel_flow.tunnel_id =
10828                         rte_cpu_to_be_32(res->tunnel_id_value);
10829         }
10830
10831         rte_memcpy(entry.input.flow_ext.flexbytes,
10832                    flexbytes,
10833                    RTE_ETH_FDIR_MAX_FLEXLEN);
10834
10835         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10836
10837         entry.action.flex_off = 0;  /*use 0 by default */
10838         if (!strcmp(res->drop, "drop"))
10839                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10840         else
10841                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10842
10843         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10844             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10845                 if (!strcmp(res->pf_vf, "pf"))
10846                         entry.input.flow_ext.is_vf = 0;
10847                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10848                         struct rte_eth_dev_info dev_info;
10849
10850                         memset(&dev_info, 0, sizeof(dev_info));
10851                         rte_eth_dev_info_get(res->port_id, &dev_info);
10852                         errno = 0;
10853                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10854                         if (errno != 0 || *end != '\0' ||
10855                             vf_id >= dev_info.max_vfs) {
10856                                 printf("invalid parameter %s.\n", res->pf_vf);
10857                                 return;
10858                         }
10859                         entry.input.flow_ext.is_vf = 1;
10860                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10861                 } else {
10862                         printf("invalid parameter %s.\n", res->pf_vf);
10863                         return;
10864                 }
10865         }
10866
10867         /* set to report FD ID by default */
10868         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10869         entry.action.rx_queue = res->queue_id;
10870         entry.soft_id = res->fd_id_value;
10871         if (!strcmp(res->ops, "add"))
10872                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10873                                              RTE_ETH_FILTER_ADD, &entry);
10874         else if (!strcmp(res->ops, "del"))
10875                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10876                                              RTE_ETH_FILTER_DELETE, &entry);
10877         else
10878                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10879                                              RTE_ETH_FILTER_UPDATE, &entry);
10880         if (ret < 0)
10881                 printf("flow director programming error: (%s)\n",
10882                         strerror(-ret));
10883 }
10884
10885 cmdline_parse_token_string_t cmd_flow_director_filter =
10886         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10887                                  flow_director_filter, "flow_director_filter");
10888 cmdline_parse_token_num_t cmd_flow_director_port_id =
10889         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10890                               port_id, UINT16);
10891 cmdline_parse_token_string_t cmd_flow_director_ops =
10892         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10893                                  ops, "add#del#update");
10894 cmdline_parse_token_string_t cmd_flow_director_flow =
10895         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10896                                  flow, "flow");
10897 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10898         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10899                 flow_type, NULL);
10900 cmdline_parse_token_string_t cmd_flow_director_ether =
10901         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10902                                  ether, "ether");
10903 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10904         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10905                               ether_type, UINT16);
10906 cmdline_parse_token_string_t cmd_flow_director_src =
10907         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10908                                  src, "src");
10909 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10910         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10911                                  ip_src);
10912 cmdline_parse_token_num_t cmd_flow_director_port_src =
10913         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10914                               port_src, UINT16);
10915 cmdline_parse_token_string_t cmd_flow_director_dst =
10916         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10917                                  dst, "dst");
10918 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10919         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10920                                  ip_dst);
10921 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10922         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10923                               port_dst, UINT16);
10924 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10925         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10926                                   verify_tag, "verify_tag");
10927 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10928         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10929                               verify_tag_value, UINT32);
10930 cmdline_parse_token_string_t cmd_flow_director_tos =
10931         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10932                                  tos, "tos");
10933 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10934         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10935                               tos_value, UINT8);
10936 cmdline_parse_token_string_t cmd_flow_director_proto =
10937         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10938                                  proto, "proto");
10939 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10940         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10941                               proto_value, UINT8);
10942 cmdline_parse_token_string_t cmd_flow_director_ttl =
10943         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10944                                  ttl, "ttl");
10945 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10946         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10947                               ttl_value, UINT8);
10948 cmdline_parse_token_string_t cmd_flow_director_vlan =
10949         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10950                                  vlan, "vlan");
10951 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10952         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10953                               vlan_value, UINT16);
10954 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10955         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10956                                  flexbytes, "flexbytes");
10957 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10958         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10959                               flexbytes_value, NULL);
10960 cmdline_parse_token_string_t cmd_flow_director_drop =
10961         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10962                                  drop, "drop#fwd");
10963 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10964         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10965                               pf_vf, NULL);
10966 cmdline_parse_token_string_t cmd_flow_director_queue =
10967         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10968                                  queue, "queue");
10969 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10970         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10971                               queue_id, UINT16);
10972 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10973         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10974                                  fd_id, "fd_id");
10975 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10976         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10977                               fd_id_value, UINT32);
10978
10979 cmdline_parse_token_string_t cmd_flow_director_mode =
10980         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10981                                  mode, "mode");
10982 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10983         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10984                                  mode_value, "IP");
10985 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10986         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10987                                  mode_value, "MAC-VLAN");
10988 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10989         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10990                                  mode_value, "Tunnel");
10991 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10992         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10993                                  mode_value, "raw");
10994 cmdline_parse_token_string_t cmd_flow_director_mac =
10995         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10996                                  mac, "mac");
10997 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10998         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10999                                     mac_addr);
11000 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11001         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11002                                  tunnel, "tunnel");
11003 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11004         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11005                                  tunnel_type, "NVGRE#VxLAN");
11006 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11007         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11008                                  tunnel_id, "tunnel-id");
11009 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11010         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11011                               tunnel_id_value, UINT32);
11012 cmdline_parse_token_string_t cmd_flow_director_packet =
11013         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11014                                  packet, "packet");
11015 cmdline_parse_token_string_t cmd_flow_director_filepath =
11016         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11017                                  filepath, NULL);
11018
11019 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11020         .f = cmd_flow_director_filter_parsed,
11021         .data = NULL,
11022         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11023                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11024                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11025                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11026                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11027                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11028                 "fd_id <fd_id_value>: "
11029                 "Add or delete an ip flow director entry on NIC",
11030         .tokens = {
11031                 (void *)&cmd_flow_director_filter,
11032                 (void *)&cmd_flow_director_port_id,
11033                 (void *)&cmd_flow_director_mode,
11034                 (void *)&cmd_flow_director_mode_ip,
11035                 (void *)&cmd_flow_director_ops,
11036                 (void *)&cmd_flow_director_flow,
11037                 (void *)&cmd_flow_director_flow_type,
11038                 (void *)&cmd_flow_director_src,
11039                 (void *)&cmd_flow_director_ip_src,
11040                 (void *)&cmd_flow_director_dst,
11041                 (void *)&cmd_flow_director_ip_dst,
11042                 (void *)&cmd_flow_director_tos,
11043                 (void *)&cmd_flow_director_tos_value,
11044                 (void *)&cmd_flow_director_proto,
11045                 (void *)&cmd_flow_director_proto_value,
11046                 (void *)&cmd_flow_director_ttl,
11047                 (void *)&cmd_flow_director_ttl_value,
11048                 (void *)&cmd_flow_director_vlan,
11049                 (void *)&cmd_flow_director_vlan_value,
11050                 (void *)&cmd_flow_director_flexbytes,
11051                 (void *)&cmd_flow_director_flexbytes_value,
11052                 (void *)&cmd_flow_director_drop,
11053                 (void *)&cmd_flow_director_pf_vf,
11054                 (void *)&cmd_flow_director_queue,
11055                 (void *)&cmd_flow_director_queue_id,
11056                 (void *)&cmd_flow_director_fd_id,
11057                 (void *)&cmd_flow_director_fd_id_value,
11058                 NULL,
11059         },
11060 };
11061
11062 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11063         .f = cmd_flow_director_filter_parsed,
11064         .data = NULL,
11065         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11066                 "director entry on NIC",
11067         .tokens = {
11068                 (void *)&cmd_flow_director_filter,
11069                 (void *)&cmd_flow_director_port_id,
11070                 (void *)&cmd_flow_director_mode,
11071                 (void *)&cmd_flow_director_mode_ip,
11072                 (void *)&cmd_flow_director_ops,
11073                 (void *)&cmd_flow_director_flow,
11074                 (void *)&cmd_flow_director_flow_type,
11075                 (void *)&cmd_flow_director_src,
11076                 (void *)&cmd_flow_director_ip_src,
11077                 (void *)&cmd_flow_director_port_src,
11078                 (void *)&cmd_flow_director_dst,
11079                 (void *)&cmd_flow_director_ip_dst,
11080                 (void *)&cmd_flow_director_port_dst,
11081                 (void *)&cmd_flow_director_tos,
11082                 (void *)&cmd_flow_director_tos_value,
11083                 (void *)&cmd_flow_director_ttl,
11084                 (void *)&cmd_flow_director_ttl_value,
11085                 (void *)&cmd_flow_director_vlan,
11086                 (void *)&cmd_flow_director_vlan_value,
11087                 (void *)&cmd_flow_director_flexbytes,
11088                 (void *)&cmd_flow_director_flexbytes_value,
11089                 (void *)&cmd_flow_director_drop,
11090                 (void *)&cmd_flow_director_pf_vf,
11091                 (void *)&cmd_flow_director_queue,
11092                 (void *)&cmd_flow_director_queue_id,
11093                 (void *)&cmd_flow_director_fd_id,
11094                 (void *)&cmd_flow_director_fd_id_value,
11095                 NULL,
11096         },
11097 };
11098
11099 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11100         .f = cmd_flow_director_filter_parsed,
11101         .data = NULL,
11102         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11103                 "director entry on NIC",
11104         .tokens = {
11105                 (void *)&cmd_flow_director_filter,
11106                 (void *)&cmd_flow_director_port_id,
11107                 (void *)&cmd_flow_director_mode,
11108                 (void *)&cmd_flow_director_mode_ip,
11109                 (void *)&cmd_flow_director_ops,
11110                 (void *)&cmd_flow_director_flow,
11111                 (void *)&cmd_flow_director_flow_type,
11112                 (void *)&cmd_flow_director_src,
11113                 (void *)&cmd_flow_director_ip_src,
11114                 (void *)&cmd_flow_director_port_src,
11115                 (void *)&cmd_flow_director_dst,
11116                 (void *)&cmd_flow_director_ip_dst,
11117                 (void *)&cmd_flow_director_port_dst,
11118                 (void *)&cmd_flow_director_verify_tag,
11119                 (void *)&cmd_flow_director_verify_tag_value,
11120                 (void *)&cmd_flow_director_tos,
11121                 (void *)&cmd_flow_director_tos_value,
11122                 (void *)&cmd_flow_director_ttl,
11123                 (void *)&cmd_flow_director_ttl_value,
11124                 (void *)&cmd_flow_director_vlan,
11125                 (void *)&cmd_flow_director_vlan_value,
11126                 (void *)&cmd_flow_director_flexbytes,
11127                 (void *)&cmd_flow_director_flexbytes_value,
11128                 (void *)&cmd_flow_director_drop,
11129                 (void *)&cmd_flow_director_pf_vf,
11130                 (void *)&cmd_flow_director_queue,
11131                 (void *)&cmd_flow_director_queue_id,
11132                 (void *)&cmd_flow_director_fd_id,
11133                 (void *)&cmd_flow_director_fd_id_value,
11134                 NULL,
11135         },
11136 };
11137
11138 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11139         .f = cmd_flow_director_filter_parsed,
11140         .data = NULL,
11141         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11142                 "director entry on NIC",
11143         .tokens = {
11144                 (void *)&cmd_flow_director_filter,
11145                 (void *)&cmd_flow_director_port_id,
11146                 (void *)&cmd_flow_director_mode,
11147                 (void *)&cmd_flow_director_mode_ip,
11148                 (void *)&cmd_flow_director_ops,
11149                 (void *)&cmd_flow_director_flow,
11150                 (void *)&cmd_flow_director_flow_type,
11151                 (void *)&cmd_flow_director_ether,
11152                 (void *)&cmd_flow_director_ether_type,
11153                 (void *)&cmd_flow_director_flexbytes,
11154                 (void *)&cmd_flow_director_flexbytes_value,
11155                 (void *)&cmd_flow_director_drop,
11156                 (void *)&cmd_flow_director_pf_vf,
11157                 (void *)&cmd_flow_director_queue,
11158                 (void *)&cmd_flow_director_queue_id,
11159                 (void *)&cmd_flow_director_fd_id,
11160                 (void *)&cmd_flow_director_fd_id_value,
11161                 NULL,
11162         },
11163 };
11164
11165 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11166         .f = cmd_flow_director_filter_parsed,
11167         .data = NULL,
11168         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11169                 "director entry on NIC",
11170         .tokens = {
11171                 (void *)&cmd_flow_director_filter,
11172                 (void *)&cmd_flow_director_port_id,
11173                 (void *)&cmd_flow_director_mode,
11174                 (void *)&cmd_flow_director_mode_mac_vlan,
11175                 (void *)&cmd_flow_director_ops,
11176                 (void *)&cmd_flow_director_mac,
11177                 (void *)&cmd_flow_director_mac_addr,
11178                 (void *)&cmd_flow_director_vlan,
11179                 (void *)&cmd_flow_director_vlan_value,
11180                 (void *)&cmd_flow_director_flexbytes,
11181                 (void *)&cmd_flow_director_flexbytes_value,
11182                 (void *)&cmd_flow_director_drop,
11183                 (void *)&cmd_flow_director_queue,
11184                 (void *)&cmd_flow_director_queue_id,
11185                 (void *)&cmd_flow_director_fd_id,
11186                 (void *)&cmd_flow_director_fd_id_value,
11187                 NULL,
11188         },
11189 };
11190
11191 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11192         .f = cmd_flow_director_filter_parsed,
11193         .data = NULL,
11194         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11195                 "director entry on NIC",
11196         .tokens = {
11197                 (void *)&cmd_flow_director_filter,
11198                 (void *)&cmd_flow_director_port_id,
11199                 (void *)&cmd_flow_director_mode,
11200                 (void *)&cmd_flow_director_mode_tunnel,
11201                 (void *)&cmd_flow_director_ops,
11202                 (void *)&cmd_flow_director_mac,
11203                 (void *)&cmd_flow_director_mac_addr,
11204                 (void *)&cmd_flow_director_vlan,
11205                 (void *)&cmd_flow_director_vlan_value,
11206                 (void *)&cmd_flow_director_tunnel,
11207                 (void *)&cmd_flow_director_tunnel_type,
11208                 (void *)&cmd_flow_director_tunnel_id,
11209                 (void *)&cmd_flow_director_tunnel_id_value,
11210                 (void *)&cmd_flow_director_flexbytes,
11211                 (void *)&cmd_flow_director_flexbytes_value,
11212                 (void *)&cmd_flow_director_drop,
11213                 (void *)&cmd_flow_director_queue,
11214                 (void *)&cmd_flow_director_queue_id,
11215                 (void *)&cmd_flow_director_fd_id,
11216                 (void *)&cmd_flow_director_fd_id_value,
11217                 NULL,
11218         },
11219 };
11220
11221 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11222         .f = cmd_flow_director_filter_parsed,
11223         .data = NULL,
11224         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11225                 "director entry on NIC",
11226         .tokens = {
11227                 (void *)&cmd_flow_director_filter,
11228                 (void *)&cmd_flow_director_port_id,
11229                 (void *)&cmd_flow_director_mode,
11230                 (void *)&cmd_flow_director_mode_raw,
11231                 (void *)&cmd_flow_director_ops,
11232                 (void *)&cmd_flow_director_flow,
11233                 (void *)&cmd_flow_director_flow_type,
11234                 (void *)&cmd_flow_director_drop,
11235                 (void *)&cmd_flow_director_queue,
11236                 (void *)&cmd_flow_director_queue_id,
11237                 (void *)&cmd_flow_director_fd_id,
11238                 (void *)&cmd_flow_director_fd_id_value,
11239                 (void *)&cmd_flow_director_packet,
11240                 (void *)&cmd_flow_director_filepath,
11241                 NULL,
11242         },
11243 };
11244
11245 struct cmd_flush_flow_director_result {
11246         cmdline_fixed_string_t flush_flow_director;
11247         portid_t port_id;
11248 };
11249
11250 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11251         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11252                                  flush_flow_director, "flush_flow_director");
11253 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11254         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11255                               port_id, UINT16);
11256
11257 static void
11258 cmd_flush_flow_director_parsed(void *parsed_result,
11259                           __attribute__((unused)) struct cmdline *cl,
11260                           __attribute__((unused)) void *data)
11261 {
11262         struct cmd_flow_director_result *res = parsed_result;
11263         int ret = 0;
11264
11265         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11266         if (ret < 0) {
11267                 printf("flow director is not supported on port %u.\n",
11268                         res->port_id);
11269                 return;
11270         }
11271
11272         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11273                         RTE_ETH_FILTER_FLUSH, NULL);
11274         if (ret < 0)
11275                 printf("flow director table flushing error: (%s)\n",
11276                         strerror(-ret));
11277 }
11278
11279 cmdline_parse_inst_t cmd_flush_flow_director = {
11280         .f = cmd_flush_flow_director_parsed,
11281         .data = NULL,
11282         .help_str = "flush_flow_director <port_id>: "
11283                 "Flush all flow director entries of a device on NIC",
11284         .tokens = {
11285                 (void *)&cmd_flush_flow_director_flush,
11286                 (void *)&cmd_flush_flow_director_port_id,
11287                 NULL,
11288         },
11289 };
11290
11291 /* *** deal with flow director mask *** */
11292 struct cmd_flow_director_mask_result {
11293         cmdline_fixed_string_t flow_director_mask;
11294         portid_t port_id;
11295         cmdline_fixed_string_t mode;
11296         cmdline_fixed_string_t mode_value;
11297         cmdline_fixed_string_t vlan;
11298         uint16_t vlan_mask;
11299         cmdline_fixed_string_t src_mask;
11300         cmdline_ipaddr_t ipv4_src;
11301         cmdline_ipaddr_t ipv6_src;
11302         uint16_t port_src;
11303         cmdline_fixed_string_t dst_mask;
11304         cmdline_ipaddr_t ipv4_dst;
11305         cmdline_ipaddr_t ipv6_dst;
11306         uint16_t port_dst;
11307         cmdline_fixed_string_t mac;
11308         uint8_t mac_addr_byte_mask;
11309         cmdline_fixed_string_t tunnel_id;
11310         uint32_t tunnel_id_mask;
11311         cmdline_fixed_string_t tunnel_type;
11312         uint8_t tunnel_type_mask;
11313 };
11314
11315 static void
11316 cmd_flow_director_mask_parsed(void *parsed_result,
11317                           __attribute__((unused)) struct cmdline *cl,
11318                           __attribute__((unused)) void *data)
11319 {
11320         struct cmd_flow_director_mask_result *res = parsed_result;
11321         struct rte_eth_fdir_masks *mask;
11322         struct rte_port *port;
11323
11324         port = &ports[res->port_id];
11325         /** Check if the port is not started **/
11326         if (port->port_status != RTE_PORT_STOPPED) {
11327                 printf("Please stop port %d first\n", res->port_id);
11328                 return;
11329         }
11330
11331         mask = &port->dev_conf.fdir_conf.mask;
11332
11333         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11334                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11335                         printf("Please set mode to MAC-VLAN.\n");
11336                         return;
11337                 }
11338
11339                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11340         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11341                 if (strcmp(res->mode_value, "Tunnel")) {
11342                         printf("Please set mode to Tunnel.\n");
11343                         return;
11344                 }
11345
11346                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11347                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11348                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11349                 mask->tunnel_type_mask = res->tunnel_type_mask;
11350         } else {
11351                 if (strcmp(res->mode_value, "IP")) {
11352                         printf("Please set mode to IP.\n");
11353                         return;
11354                 }
11355
11356                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11357                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11358                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11359                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11360                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11361                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11362                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11363         }
11364
11365         cmd_reconfig_device_queue(res->port_id, 1, 1);
11366 }
11367
11368 cmdline_parse_token_string_t cmd_flow_director_mask =
11369         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11370                                  flow_director_mask, "flow_director_mask");
11371 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11372         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11373                               port_id, UINT16);
11374 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11375         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11376                                  vlan, "vlan");
11377 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11378         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11379                               vlan_mask, UINT16);
11380 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11381         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11382                                  src_mask, "src_mask");
11383 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11384         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11385                                  ipv4_src);
11386 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11387         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11388                                  ipv6_src);
11389 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11390         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11391                               port_src, UINT16);
11392 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11393         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11394                                  dst_mask, "dst_mask");
11395 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11396         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11397                                  ipv4_dst);
11398 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11399         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11400                                  ipv6_dst);
11401 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11402         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11403                               port_dst, UINT16);
11404
11405 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11406         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11407                                  mode, "mode");
11408 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11409         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11410                                  mode_value, "IP");
11411 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11412         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11413                                  mode_value, "MAC-VLAN");
11414 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11415         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11416                                  mode_value, "Tunnel");
11417 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11418         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11419                                  mac, "mac");
11420 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11421         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11422                               mac_addr_byte_mask, UINT8);
11423 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11425                                  tunnel_type, "tunnel-type");
11426 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11427         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11428                               tunnel_type_mask, UINT8);
11429 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11431                                  tunnel_id, "tunnel-id");
11432 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11433         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11434                               tunnel_id_mask, UINT32);
11435
11436 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11437         .f = cmd_flow_director_mask_parsed,
11438         .data = NULL,
11439         .help_str = "flow_director_mask ... : "
11440                 "Set IP mode flow director's mask on NIC",
11441         .tokens = {
11442                 (void *)&cmd_flow_director_mask,
11443                 (void *)&cmd_flow_director_mask_port_id,
11444                 (void *)&cmd_flow_director_mask_mode,
11445                 (void *)&cmd_flow_director_mask_mode_ip,
11446                 (void *)&cmd_flow_director_mask_vlan,
11447                 (void *)&cmd_flow_director_mask_vlan_value,
11448                 (void *)&cmd_flow_director_mask_src,
11449                 (void *)&cmd_flow_director_mask_ipv4_src,
11450                 (void *)&cmd_flow_director_mask_ipv6_src,
11451                 (void *)&cmd_flow_director_mask_port_src,
11452                 (void *)&cmd_flow_director_mask_dst,
11453                 (void *)&cmd_flow_director_mask_ipv4_dst,
11454                 (void *)&cmd_flow_director_mask_ipv6_dst,
11455                 (void *)&cmd_flow_director_mask_port_dst,
11456                 NULL,
11457         },
11458 };
11459
11460 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11461         .f = cmd_flow_director_mask_parsed,
11462         .data = NULL,
11463         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11464                 "flow director's mask on NIC",
11465         .tokens = {
11466                 (void *)&cmd_flow_director_mask,
11467                 (void *)&cmd_flow_director_mask_port_id,
11468                 (void *)&cmd_flow_director_mask_mode,
11469                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11470                 (void *)&cmd_flow_director_mask_vlan,
11471                 (void *)&cmd_flow_director_mask_vlan_value,
11472                 NULL,
11473         },
11474 };
11475
11476 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11477         .f = cmd_flow_director_mask_parsed,
11478         .data = NULL,
11479         .help_str = "flow_director_mask ... : Set tunnel mode "
11480                 "flow director's mask on NIC",
11481         .tokens = {
11482                 (void *)&cmd_flow_director_mask,
11483                 (void *)&cmd_flow_director_mask_port_id,
11484                 (void *)&cmd_flow_director_mask_mode,
11485                 (void *)&cmd_flow_director_mask_mode_tunnel,
11486                 (void *)&cmd_flow_director_mask_vlan,
11487                 (void *)&cmd_flow_director_mask_vlan_value,
11488                 (void *)&cmd_flow_director_mask_mac,
11489                 (void *)&cmd_flow_director_mask_mac_value,
11490                 (void *)&cmd_flow_director_mask_tunnel_type,
11491                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11492                 (void *)&cmd_flow_director_mask_tunnel_id,
11493                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11494                 NULL,
11495         },
11496 };
11497
11498 /* *** deal with flow director mask on flexible payload *** */
11499 struct cmd_flow_director_flex_mask_result {
11500         cmdline_fixed_string_t flow_director_flexmask;
11501         portid_t port_id;
11502         cmdline_fixed_string_t flow;
11503         cmdline_fixed_string_t flow_type;
11504         cmdline_fixed_string_t mask;
11505 };
11506
11507 static void
11508 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11509                           __attribute__((unused)) struct cmdline *cl,
11510                           __attribute__((unused)) void *data)
11511 {
11512         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11513         struct rte_eth_fdir_info fdir_info;
11514         struct rte_eth_fdir_flex_mask flex_mask;
11515         struct rte_port *port;
11516         uint64_t flow_type_mask;
11517         uint16_t i;
11518         int ret;
11519
11520         port = &ports[res->port_id];
11521         /** Check if the port is not started **/
11522         if (port->port_status != RTE_PORT_STOPPED) {
11523                 printf("Please stop port %d first\n", res->port_id);
11524                 return;
11525         }
11526
11527         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11528         ret = parse_flexbytes(res->mask,
11529                         flex_mask.mask,
11530                         RTE_ETH_FDIR_MAX_FLEXLEN);
11531         if (ret < 0) {
11532                 printf("error: Cannot parse mask input.\n");
11533                 return;
11534         }
11535
11536         memset(&fdir_info, 0, sizeof(fdir_info));
11537         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11538                                 RTE_ETH_FILTER_INFO, &fdir_info);
11539         if (ret < 0) {
11540                 printf("Cannot get FDir filter info\n");
11541                 return;
11542         }
11543
11544         if (!strcmp(res->flow_type, "none")) {
11545                 /* means don't specify the flow type */
11546                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11547                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11548                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11549                                0, sizeof(struct rte_eth_fdir_flex_mask));
11550                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11551                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11552                                  &flex_mask,
11553                                  sizeof(struct rte_eth_fdir_flex_mask));
11554                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11555                 return;
11556         }
11557         flow_type_mask = fdir_info.flow_types_mask[0];
11558         if (!strcmp(res->flow_type, "all")) {
11559                 if (!flow_type_mask) {
11560                         printf("No flow type supported\n");
11561                         return;
11562                 }
11563                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11564                         if (flow_type_mask & (1ULL << i)) {
11565                                 flex_mask.flow_type = i;
11566                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11567                         }
11568                 }
11569                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11570                 return;
11571         }
11572         flex_mask.flow_type = str2flowtype(res->flow_type);
11573         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11574                 printf("Flow type %s not supported on port %d\n",
11575                                 res->flow_type, res->port_id);
11576                 return;
11577         }
11578         fdir_set_flex_mask(res->port_id, &flex_mask);
11579         cmd_reconfig_device_queue(res->port_id, 1, 1);
11580 }
11581
11582 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11583         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11584                                  flow_director_flexmask,
11585                                  "flow_director_flex_mask");
11586 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11587         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11588                               port_id, UINT16);
11589 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11591                                  flow, "flow");
11592 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11593         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11594                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11595                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11596 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11597         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11598                                  mask, NULL);
11599
11600 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11601         .f = cmd_flow_director_flex_mask_parsed,
11602         .data = NULL,
11603         .help_str = "flow_director_flex_mask ... : "
11604                 "Set flow director's flex mask on NIC",
11605         .tokens = {
11606                 (void *)&cmd_flow_director_flexmask,
11607                 (void *)&cmd_flow_director_flexmask_port_id,
11608                 (void *)&cmd_flow_director_flexmask_flow,
11609                 (void *)&cmd_flow_director_flexmask_flow_type,
11610                 (void *)&cmd_flow_director_flexmask_mask,
11611                 NULL,
11612         },
11613 };
11614
11615 /* *** deal with flow director flexible payload configuration *** */
11616 struct cmd_flow_director_flexpayload_result {
11617         cmdline_fixed_string_t flow_director_flexpayload;
11618         portid_t port_id;
11619         cmdline_fixed_string_t payload_layer;
11620         cmdline_fixed_string_t payload_cfg;
11621 };
11622
11623 static inline int
11624 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11625 {
11626         char s[256];
11627         const char *p, *p0 = q_arg;
11628         char *end;
11629         unsigned long int_fld;
11630         char *str_fld[max_num];
11631         int i;
11632         unsigned size;
11633         int ret = -1;
11634
11635         p = strchr(p0, '(');
11636         if (p == NULL)
11637                 return -1;
11638         ++p;
11639         p0 = strchr(p, ')');
11640         if (p0 == NULL)
11641                 return -1;
11642
11643         size = p0 - p;
11644         if (size >= sizeof(s))
11645                 return -1;
11646
11647         snprintf(s, sizeof(s), "%.*s", size, p);
11648         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11649         if (ret < 0 || ret > max_num)
11650                 return -1;
11651         for (i = 0; i < ret; i++) {
11652                 errno = 0;
11653                 int_fld = strtoul(str_fld[i], &end, 0);
11654                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11655                         return -1;
11656                 offsets[i] = (uint16_t)int_fld;
11657         }
11658         return ret;
11659 }
11660
11661 static void
11662 cmd_flow_director_flxpld_parsed(void *parsed_result,
11663                           __attribute__((unused)) struct cmdline *cl,
11664                           __attribute__((unused)) void *data)
11665 {
11666         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11667         struct rte_eth_flex_payload_cfg flex_cfg;
11668         struct rte_port *port;
11669         int ret = 0;
11670
11671         port = &ports[res->port_id];
11672         /** Check if the port is not started **/
11673         if (port->port_status != RTE_PORT_STOPPED) {
11674                 printf("Please stop port %d first\n", res->port_id);
11675                 return;
11676         }
11677
11678         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11679
11680         if (!strcmp(res->payload_layer, "raw"))
11681                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11682         else if (!strcmp(res->payload_layer, "l2"))
11683                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11684         else if (!strcmp(res->payload_layer, "l3"))
11685                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11686         else if (!strcmp(res->payload_layer, "l4"))
11687                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11688
11689         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11690                             RTE_ETH_FDIR_MAX_FLEXLEN);
11691         if (ret < 0) {
11692                 printf("error: Cannot parse flex payload input.\n");
11693                 return;
11694         }
11695
11696         fdir_set_flex_payload(res->port_id, &flex_cfg);
11697         cmd_reconfig_device_queue(res->port_id, 1, 1);
11698 }
11699
11700 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11701         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11702                                  flow_director_flexpayload,
11703                                  "flow_director_flex_payload");
11704 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11705         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11706                               port_id, UINT16);
11707 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11708         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11709                                  payload_layer, "raw#l2#l3#l4");
11710 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11711         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11712                                  payload_cfg, NULL);
11713
11714 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11715         .f = cmd_flow_director_flxpld_parsed,
11716         .data = NULL,
11717         .help_str = "flow_director_flexpayload ... : "
11718                 "Set flow director's flex payload on NIC",
11719         .tokens = {
11720                 (void *)&cmd_flow_director_flexpayload,
11721                 (void *)&cmd_flow_director_flexpayload_port_id,
11722                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11723                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11724                 NULL,
11725         },
11726 };
11727
11728 /* Generic flow interface command. */
11729 extern cmdline_parse_inst_t cmd_flow;
11730
11731 /* *** Classification Filters Control *** */
11732 /* *** Get symmetric hash enable per port *** */
11733 struct cmd_get_sym_hash_ena_per_port_result {
11734         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11735         portid_t port_id;
11736 };
11737
11738 static void
11739 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11740                                  __rte_unused struct cmdline *cl,
11741                                  __rte_unused void *data)
11742 {
11743         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11744         struct rte_eth_hash_filter_info info;
11745         int ret;
11746
11747         if (rte_eth_dev_filter_supported(res->port_id,
11748                                 RTE_ETH_FILTER_HASH) < 0) {
11749                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11750                                                         res->port_id);
11751                 return;
11752         }
11753
11754         memset(&info, 0, sizeof(info));
11755         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11756         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11757                                                 RTE_ETH_FILTER_GET, &info);
11758
11759         if (ret < 0) {
11760                 printf("Cannot get symmetric hash enable per port "
11761                                         "on port %u\n", res->port_id);
11762                 return;
11763         }
11764
11765         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11766                                 "enabled" : "disabled", res->port_id);
11767 }
11768
11769 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11770         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11771                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11772 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11773         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11774                 port_id, UINT16);
11775
11776 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11777         .f = cmd_get_sym_hash_per_port_parsed,
11778         .data = NULL,
11779         .help_str = "get_sym_hash_ena_per_port <port_id>",
11780         .tokens = {
11781                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11782                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11783                 NULL,
11784         },
11785 };
11786
11787 /* *** Set symmetric hash enable per port *** */
11788 struct cmd_set_sym_hash_ena_per_port_result {
11789         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11790         cmdline_fixed_string_t enable;
11791         portid_t port_id;
11792 };
11793
11794 static void
11795 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11796                                  __rte_unused struct cmdline *cl,
11797                                  __rte_unused void *data)
11798 {
11799         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11800         struct rte_eth_hash_filter_info info;
11801         int ret;
11802
11803         if (rte_eth_dev_filter_supported(res->port_id,
11804                                 RTE_ETH_FILTER_HASH) < 0) {
11805                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11806                                                         res->port_id);
11807                 return;
11808         }
11809
11810         memset(&info, 0, sizeof(info));
11811         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11812         if (!strcmp(res->enable, "enable"))
11813                 info.info.enable = 1;
11814         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11815                                         RTE_ETH_FILTER_SET, &info);
11816         if (ret < 0) {
11817                 printf("Cannot set symmetric hash enable per port on "
11818                                         "port %u\n", res->port_id);
11819                 return;
11820         }
11821         printf("Symmetric hash has been set to %s on port %u\n",
11822                                         res->enable, res->port_id);
11823 }
11824
11825 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11826         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11827                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11828 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11829         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11830                 port_id, UINT16);
11831 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11832         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11833                 enable, "enable#disable");
11834
11835 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11836         .f = cmd_set_sym_hash_per_port_parsed,
11837         .data = NULL,
11838         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11839         .tokens = {
11840                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11841                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11842                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11843                 NULL,
11844         },
11845 };
11846
11847 /* Get global config of hash function */
11848 struct cmd_get_hash_global_config_result {
11849         cmdline_fixed_string_t get_hash_global_config;
11850         portid_t port_id;
11851 };
11852
11853 static char *
11854 flowtype_to_str(uint16_t ftype)
11855 {
11856         uint16_t i;
11857         static struct {
11858                 char str[16];
11859                 uint16_t ftype;
11860         } ftype_table[] = {
11861                 {"ipv4", RTE_ETH_FLOW_IPV4},
11862                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11863                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11864                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11865                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11866                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11867                 {"ipv6", RTE_ETH_FLOW_IPV6},
11868                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11869                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11870                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11871                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11872                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11873                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11874                 {"port", RTE_ETH_FLOW_PORT},
11875                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11876                 {"geneve", RTE_ETH_FLOW_GENEVE},
11877                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11878         };
11879
11880         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11881                 if (ftype_table[i].ftype == ftype)
11882                         return ftype_table[i].str;
11883         }
11884
11885         return NULL;
11886 }
11887
11888 static void
11889 cmd_get_hash_global_config_parsed(void *parsed_result,
11890                                   __rte_unused struct cmdline *cl,
11891                                   __rte_unused void *data)
11892 {
11893         struct cmd_get_hash_global_config_result *res = parsed_result;
11894         struct rte_eth_hash_filter_info info;
11895         uint32_t idx, offset;
11896         uint16_t i;
11897         char *str;
11898         int ret;
11899
11900         if (rte_eth_dev_filter_supported(res->port_id,
11901                         RTE_ETH_FILTER_HASH) < 0) {
11902                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11903                                                         res->port_id);
11904                 return;
11905         }
11906
11907         memset(&info, 0, sizeof(info));
11908         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11909         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11910                                         RTE_ETH_FILTER_GET, &info);
11911         if (ret < 0) {
11912                 printf("Cannot get hash global configurations by port %d\n",
11913                                                         res->port_id);
11914                 return;
11915         }
11916
11917         switch (info.info.global_conf.hash_func) {
11918         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11919                 printf("Hash function is Toeplitz\n");
11920                 break;
11921         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11922                 printf("Hash function is Simple XOR\n");
11923                 break;
11924         default:
11925                 printf("Unknown hash function\n");
11926                 break;
11927         }
11928
11929         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11930                 idx = i / UINT64_BIT;
11931                 offset = i % UINT64_BIT;
11932                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11933                                                 (1ULL << offset)))
11934                         continue;
11935                 str = flowtype_to_str(i);
11936                 if (!str)
11937                         continue;
11938                 printf("Symmetric hash is %s globally for flow type %s "
11939                                                         "by port %d\n",
11940                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11941                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11942                                                         res->port_id);
11943         }
11944 }
11945
11946 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11947         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11948                 get_hash_global_config, "get_hash_global_config");
11949 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11950         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11951                 port_id, UINT16);
11952
11953 cmdline_parse_inst_t cmd_get_hash_global_config = {
11954         .f = cmd_get_hash_global_config_parsed,
11955         .data = NULL,
11956         .help_str = "get_hash_global_config <port_id>",
11957         .tokens = {
11958                 (void *)&cmd_get_hash_global_config_all,
11959                 (void *)&cmd_get_hash_global_config_port_id,
11960                 NULL,
11961         },
11962 };
11963
11964 /* Set global config of hash function */
11965 struct cmd_set_hash_global_config_result {
11966         cmdline_fixed_string_t set_hash_global_config;
11967         portid_t port_id;
11968         cmdline_fixed_string_t hash_func;
11969         cmdline_fixed_string_t flow_type;
11970         cmdline_fixed_string_t enable;
11971 };
11972
11973 static void
11974 cmd_set_hash_global_config_parsed(void *parsed_result,
11975                                   __rte_unused struct cmdline *cl,
11976                                   __rte_unused void *data)
11977 {
11978         struct cmd_set_hash_global_config_result *res = parsed_result;
11979         struct rte_eth_hash_filter_info info;
11980         uint32_t ftype, idx, offset;
11981         int ret;
11982
11983         if (rte_eth_dev_filter_supported(res->port_id,
11984                                 RTE_ETH_FILTER_HASH) < 0) {
11985                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11986                                                         res->port_id);
11987                 return;
11988         }
11989         memset(&info, 0, sizeof(info));
11990         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11991         if (!strcmp(res->hash_func, "toeplitz"))
11992                 info.info.global_conf.hash_func =
11993                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11994         else if (!strcmp(res->hash_func, "simple_xor"))
11995                 info.info.global_conf.hash_func =
11996                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11997         else if (!strcmp(res->hash_func, "default"))
11998                 info.info.global_conf.hash_func =
11999                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12000
12001         ftype = str2flowtype(res->flow_type);
12002         idx = ftype / UINT64_BIT;
12003         offset = ftype % UINT64_BIT;
12004         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12005         if (!strcmp(res->enable, "enable"))
12006                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12007                                                 (1ULL << offset);
12008         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12009                                         RTE_ETH_FILTER_SET, &info);
12010         if (ret < 0)
12011                 printf("Cannot set global hash configurations by port %d\n",
12012                                                         res->port_id);
12013         else
12014                 printf("Global hash configurations have been set "
12015                         "succcessfully by port %d\n", res->port_id);
12016 }
12017
12018 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12019         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12020                 set_hash_global_config, "set_hash_global_config");
12021 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12022         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12023                 port_id, UINT16);
12024 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12025         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12026                 hash_func, "toeplitz#simple_xor#default");
12027 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12028         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12029                 flow_type,
12030                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12031                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12032 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12033         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12034                 enable, "enable#disable");
12035
12036 cmdline_parse_inst_t cmd_set_hash_global_config = {
12037         .f = cmd_set_hash_global_config_parsed,
12038         .data = NULL,
12039         .help_str = "set_hash_global_config <port_id> "
12040                 "toeplitz|simple_xor|default "
12041                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12042                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12043                 "l2_payload enable|disable",
12044         .tokens = {
12045                 (void *)&cmd_set_hash_global_config_all,
12046                 (void *)&cmd_set_hash_global_config_port_id,
12047                 (void *)&cmd_set_hash_global_config_hash_func,
12048                 (void *)&cmd_set_hash_global_config_flow_type,
12049                 (void *)&cmd_set_hash_global_config_enable,
12050                 NULL,
12051         },
12052 };
12053
12054 /* Set hash input set */
12055 struct cmd_set_hash_input_set_result {
12056         cmdline_fixed_string_t set_hash_input_set;
12057         portid_t port_id;
12058         cmdline_fixed_string_t flow_type;
12059         cmdline_fixed_string_t inset_field;
12060         cmdline_fixed_string_t select;
12061 };
12062
12063 static enum rte_eth_input_set_field
12064 str2inset(char *string)
12065 {
12066         uint16_t i;
12067
12068         static const struct {
12069                 char str[32];
12070                 enum rte_eth_input_set_field inset;
12071         } inset_table[] = {
12072                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12073                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12074                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12075                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12076                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12077                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12078                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12079                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12080                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12081                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12082                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12083                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12084                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12085                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12086                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12087                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12088                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12089                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12090                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12091                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12092                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12093                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12094                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12095                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12096                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12097                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12098                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12099                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12100                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12101                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12102                 {"none", RTE_ETH_INPUT_SET_NONE},
12103         };
12104
12105         for (i = 0; i < RTE_DIM(inset_table); i++) {
12106                 if (!strcmp(string, inset_table[i].str))
12107                         return inset_table[i].inset;
12108         }
12109
12110         return RTE_ETH_INPUT_SET_UNKNOWN;
12111 }
12112
12113 static void
12114 cmd_set_hash_input_set_parsed(void *parsed_result,
12115                               __rte_unused struct cmdline *cl,
12116                               __rte_unused void *data)
12117 {
12118         struct cmd_set_hash_input_set_result *res = parsed_result;
12119         struct rte_eth_hash_filter_info info;
12120
12121         memset(&info, 0, sizeof(info));
12122         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12123         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12124         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12125         info.info.input_set_conf.inset_size = 1;
12126         if (!strcmp(res->select, "select"))
12127                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12128         else if (!strcmp(res->select, "add"))
12129                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12130         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12131                                 RTE_ETH_FILTER_SET, &info);
12132 }
12133
12134 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12135         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12136                 set_hash_input_set, "set_hash_input_set");
12137 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12138         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12139                 port_id, UINT16);
12140 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12141         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12142                 flow_type, NULL);
12143 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12144         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12145                 inset_field,
12146                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12147                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12148                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12149                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12150                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12151                 "fld-8th#none");
12152 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12153         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12154                 select, "select#add");
12155
12156 cmdline_parse_inst_t cmd_set_hash_input_set = {
12157         .f = cmd_set_hash_input_set_parsed,
12158         .data = NULL,
12159         .help_str = "set_hash_input_set <port_id> "
12160         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12161         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12162         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12163         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12164         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12165         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12166         "fld-7th|fld-8th|none select|add",
12167         .tokens = {
12168                 (void *)&cmd_set_hash_input_set_cmd,
12169                 (void *)&cmd_set_hash_input_set_port_id,
12170                 (void *)&cmd_set_hash_input_set_flow_type,
12171                 (void *)&cmd_set_hash_input_set_field,
12172                 (void *)&cmd_set_hash_input_set_select,
12173                 NULL,
12174         },
12175 };
12176
12177 /* Set flow director input set */
12178 struct cmd_set_fdir_input_set_result {
12179         cmdline_fixed_string_t set_fdir_input_set;
12180         portid_t port_id;
12181         cmdline_fixed_string_t flow_type;
12182         cmdline_fixed_string_t inset_field;
12183         cmdline_fixed_string_t select;
12184 };
12185
12186 static void
12187 cmd_set_fdir_input_set_parsed(void *parsed_result,
12188         __rte_unused struct cmdline *cl,
12189         __rte_unused void *data)
12190 {
12191         struct cmd_set_fdir_input_set_result *res = parsed_result;
12192         struct rte_eth_fdir_filter_info info;
12193
12194         memset(&info, 0, sizeof(info));
12195         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12196         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12197         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12198         info.info.input_set_conf.inset_size = 1;
12199         if (!strcmp(res->select, "select"))
12200                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12201         else if (!strcmp(res->select, "add"))
12202                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12203         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12204                 RTE_ETH_FILTER_SET, &info);
12205 }
12206
12207 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12208         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12209         set_fdir_input_set, "set_fdir_input_set");
12210 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12211         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12212         port_id, UINT16);
12213 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12214         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12215         flow_type,
12216         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12217         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12218 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12219         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12220         inset_field,
12221         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12222         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12223         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12224         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12225         "sctp-veri-tag#none");
12226 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12227         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12228         select, "select#add");
12229
12230 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12231         .f = cmd_set_fdir_input_set_parsed,
12232         .data = NULL,
12233         .help_str = "set_fdir_input_set <port_id> "
12234         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12235         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12236         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12237         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12238         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12239         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12240         "sctp-veri-tag|none select|add",
12241         .tokens = {
12242                 (void *)&cmd_set_fdir_input_set_cmd,
12243                 (void *)&cmd_set_fdir_input_set_port_id,
12244                 (void *)&cmd_set_fdir_input_set_flow_type,
12245                 (void *)&cmd_set_fdir_input_set_field,
12246                 (void *)&cmd_set_fdir_input_set_select,
12247                 NULL,
12248         },
12249 };
12250
12251 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12252 struct cmd_mcast_addr_result {
12253         cmdline_fixed_string_t mcast_addr_cmd;
12254         cmdline_fixed_string_t what;
12255         uint16_t port_num;
12256         struct ether_addr mc_addr;
12257 };
12258
12259 static void cmd_mcast_addr_parsed(void *parsed_result,
12260                 __attribute__((unused)) struct cmdline *cl,
12261                 __attribute__((unused)) void *data)
12262 {
12263         struct cmd_mcast_addr_result *res = parsed_result;
12264
12265         if (!is_multicast_ether_addr(&res->mc_addr)) {
12266                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12267                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12268                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12269                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12270                 return;
12271         }
12272         if (strcmp(res->what, "add") == 0)
12273                 mcast_addr_add(res->port_num, &res->mc_addr);
12274         else
12275                 mcast_addr_remove(res->port_num, &res->mc_addr);
12276 }
12277
12278 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12279         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12280                                  mcast_addr_cmd, "mcast_addr");
12281 cmdline_parse_token_string_t cmd_mcast_addr_what =
12282         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12283                                  "add#remove");
12284 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12285         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12286 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12287         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12288
12289 cmdline_parse_inst_t cmd_mcast_addr = {
12290         .f = cmd_mcast_addr_parsed,
12291         .data = (void *)0,
12292         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12293                 "Add/Remove multicast MAC address on port_id",
12294         .tokens = {
12295                 (void *)&cmd_mcast_addr_cmd,
12296                 (void *)&cmd_mcast_addr_what,
12297                 (void *)&cmd_mcast_addr_portnum,
12298                 (void *)&cmd_mcast_addr_addr,
12299                 NULL,
12300         },
12301 };
12302
12303 /* l2 tunnel config
12304  * only support E-tag now.
12305  */
12306
12307 /* Ether type config */
12308 struct cmd_config_l2_tunnel_eth_type_result {
12309         cmdline_fixed_string_t port;
12310         cmdline_fixed_string_t config;
12311         cmdline_fixed_string_t all;
12312         portid_t id;
12313         cmdline_fixed_string_t l2_tunnel;
12314         cmdline_fixed_string_t l2_tunnel_type;
12315         cmdline_fixed_string_t eth_type;
12316         uint16_t eth_type_val;
12317 };
12318
12319 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12320         TOKEN_STRING_INITIALIZER
12321                 (struct cmd_config_l2_tunnel_eth_type_result,
12322                  port, "port");
12323 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12324         TOKEN_STRING_INITIALIZER
12325                 (struct cmd_config_l2_tunnel_eth_type_result,
12326                  config, "config");
12327 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12328         TOKEN_STRING_INITIALIZER
12329                 (struct cmd_config_l2_tunnel_eth_type_result,
12330                  all, "all");
12331 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12332         TOKEN_NUM_INITIALIZER
12333                 (struct cmd_config_l2_tunnel_eth_type_result,
12334                  id, UINT16);
12335 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12336         TOKEN_STRING_INITIALIZER
12337                 (struct cmd_config_l2_tunnel_eth_type_result,
12338                  l2_tunnel, "l2-tunnel");
12339 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12340         TOKEN_STRING_INITIALIZER
12341                 (struct cmd_config_l2_tunnel_eth_type_result,
12342                  l2_tunnel_type, "E-tag");
12343 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12344         TOKEN_STRING_INITIALIZER
12345                 (struct cmd_config_l2_tunnel_eth_type_result,
12346                  eth_type, "ether-type");
12347 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12348         TOKEN_NUM_INITIALIZER
12349                 (struct cmd_config_l2_tunnel_eth_type_result,
12350                  eth_type_val, UINT16);
12351
12352 static enum rte_eth_tunnel_type
12353 str2fdir_l2_tunnel_type(char *string)
12354 {
12355         uint32_t i = 0;
12356
12357         static const struct {
12358                 char str[32];
12359                 enum rte_eth_tunnel_type type;
12360         } l2_tunnel_type_str[] = {
12361                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12362         };
12363
12364         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12365                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12366                         return l2_tunnel_type_str[i].type;
12367         }
12368         return RTE_TUNNEL_TYPE_NONE;
12369 }
12370
12371 /* ether type config for all ports */
12372 static void
12373 cmd_config_l2_tunnel_eth_type_all_parsed
12374         (void *parsed_result,
12375          __attribute__((unused)) struct cmdline *cl,
12376          __attribute__((unused)) void *data)
12377 {
12378         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12379         struct rte_eth_l2_tunnel_conf entry;
12380         portid_t pid;
12381
12382         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12383         entry.ether_type = res->eth_type_val;
12384
12385         RTE_ETH_FOREACH_DEV(pid) {
12386                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12387         }
12388 }
12389
12390 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12391         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12392         .data = NULL,
12393         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12394         .tokens = {
12395                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12396                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12397                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12398                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12399                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12400                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12401                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12402                 NULL,
12403         },
12404 };
12405
12406 /* ether type config for a specific port */
12407 static void
12408 cmd_config_l2_tunnel_eth_type_specific_parsed(
12409         void *parsed_result,
12410         __attribute__((unused)) struct cmdline *cl,
12411         __attribute__((unused)) void *data)
12412 {
12413         struct cmd_config_l2_tunnel_eth_type_result *res =
12414                  parsed_result;
12415         struct rte_eth_l2_tunnel_conf entry;
12416
12417         if (port_id_is_invalid(res->id, ENABLED_WARN))
12418                 return;
12419
12420         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12421         entry.ether_type = res->eth_type_val;
12422
12423         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12424 }
12425
12426 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12427         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12428         .data = NULL,
12429         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12430         .tokens = {
12431                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12432                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12433                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12434                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12435                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12436                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12437                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12438                 NULL,
12439         },
12440 };
12441
12442 /* Enable/disable l2 tunnel */
12443 struct cmd_config_l2_tunnel_en_dis_result {
12444         cmdline_fixed_string_t port;
12445         cmdline_fixed_string_t config;
12446         cmdline_fixed_string_t all;
12447         portid_t id;
12448         cmdline_fixed_string_t l2_tunnel;
12449         cmdline_fixed_string_t l2_tunnel_type;
12450         cmdline_fixed_string_t en_dis;
12451 };
12452
12453 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12454         TOKEN_STRING_INITIALIZER
12455                 (struct cmd_config_l2_tunnel_en_dis_result,
12456                  port, "port");
12457 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12458         TOKEN_STRING_INITIALIZER
12459                 (struct cmd_config_l2_tunnel_en_dis_result,
12460                  config, "config");
12461 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12462         TOKEN_STRING_INITIALIZER
12463                 (struct cmd_config_l2_tunnel_en_dis_result,
12464                  all, "all");
12465 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12466         TOKEN_NUM_INITIALIZER
12467                 (struct cmd_config_l2_tunnel_en_dis_result,
12468                  id, UINT16);
12469 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12470         TOKEN_STRING_INITIALIZER
12471                 (struct cmd_config_l2_tunnel_en_dis_result,
12472                  l2_tunnel, "l2-tunnel");
12473 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12474         TOKEN_STRING_INITIALIZER
12475                 (struct cmd_config_l2_tunnel_en_dis_result,
12476                  l2_tunnel_type, "E-tag");
12477 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12478         TOKEN_STRING_INITIALIZER
12479                 (struct cmd_config_l2_tunnel_en_dis_result,
12480                  en_dis, "enable#disable");
12481
12482 /* enable/disable l2 tunnel for all ports */
12483 static void
12484 cmd_config_l2_tunnel_en_dis_all_parsed(
12485         void *parsed_result,
12486         __attribute__((unused)) struct cmdline *cl,
12487         __attribute__((unused)) void *data)
12488 {
12489         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12490         struct rte_eth_l2_tunnel_conf entry;
12491         portid_t pid;
12492         uint8_t en;
12493
12494         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12495
12496         if (!strcmp("enable", res->en_dis))
12497                 en = 1;
12498         else
12499                 en = 0;
12500
12501         RTE_ETH_FOREACH_DEV(pid) {
12502                 rte_eth_dev_l2_tunnel_offload_set(pid,
12503                                                   &entry,
12504                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12505                                                   en);
12506         }
12507 }
12508
12509 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12510         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12511         .data = NULL,
12512         .help_str = "port config all l2-tunnel E-tag enable|disable",
12513         .tokens = {
12514                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12515                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12516                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12517                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12518                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12519                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12520                 NULL,
12521         },
12522 };
12523
12524 /* enable/disable l2 tunnel for a port */
12525 static void
12526 cmd_config_l2_tunnel_en_dis_specific_parsed(
12527         void *parsed_result,
12528         __attribute__((unused)) struct cmdline *cl,
12529         __attribute__((unused)) void *data)
12530 {
12531         struct cmd_config_l2_tunnel_en_dis_result *res =
12532                 parsed_result;
12533         struct rte_eth_l2_tunnel_conf entry;
12534
12535         if (port_id_is_invalid(res->id, ENABLED_WARN))
12536                 return;
12537
12538         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12539
12540         if (!strcmp("enable", res->en_dis))
12541                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12542                                                   &entry,
12543                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12544                                                   1);
12545         else
12546                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12547                                                   &entry,
12548                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12549                                                   0);
12550 }
12551
12552 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12553         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12554         .data = NULL,
12555         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12556         .tokens = {
12557                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12558                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12559                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12560                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12561                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12562                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12563                 NULL,
12564         },
12565 };
12566
12567 /* E-tag configuration */
12568
12569 /* Common result structure for all E-tag configuration */
12570 struct cmd_config_e_tag_result {
12571         cmdline_fixed_string_t e_tag;
12572         cmdline_fixed_string_t set;
12573         cmdline_fixed_string_t insertion;
12574         cmdline_fixed_string_t stripping;
12575         cmdline_fixed_string_t forwarding;
12576         cmdline_fixed_string_t filter;
12577         cmdline_fixed_string_t add;
12578         cmdline_fixed_string_t del;
12579         cmdline_fixed_string_t on;
12580         cmdline_fixed_string_t off;
12581         cmdline_fixed_string_t on_off;
12582         cmdline_fixed_string_t port_tag_id;
12583         uint32_t port_tag_id_val;
12584         cmdline_fixed_string_t e_tag_id;
12585         uint16_t e_tag_id_val;
12586         cmdline_fixed_string_t dst_pool;
12587         uint8_t dst_pool_val;
12588         cmdline_fixed_string_t port;
12589         portid_t port_id;
12590         cmdline_fixed_string_t vf;
12591         uint8_t vf_id;
12592 };
12593
12594 /* Common CLI fields for all E-tag configuration */
12595 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12596         TOKEN_STRING_INITIALIZER
12597                 (struct cmd_config_e_tag_result,
12598                  e_tag, "E-tag");
12599 cmdline_parse_token_string_t cmd_config_e_tag_set =
12600         TOKEN_STRING_INITIALIZER
12601                 (struct cmd_config_e_tag_result,
12602                  set, "set");
12603 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12604         TOKEN_STRING_INITIALIZER
12605                 (struct cmd_config_e_tag_result,
12606                  insertion, "insertion");
12607 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12608         TOKEN_STRING_INITIALIZER
12609                 (struct cmd_config_e_tag_result,
12610                  stripping, "stripping");
12611 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12612         TOKEN_STRING_INITIALIZER
12613                 (struct cmd_config_e_tag_result,
12614                  forwarding, "forwarding");
12615 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12616         TOKEN_STRING_INITIALIZER
12617                 (struct cmd_config_e_tag_result,
12618                  filter, "filter");
12619 cmdline_parse_token_string_t cmd_config_e_tag_add =
12620         TOKEN_STRING_INITIALIZER
12621                 (struct cmd_config_e_tag_result,
12622                  add, "add");
12623 cmdline_parse_token_string_t cmd_config_e_tag_del =
12624         TOKEN_STRING_INITIALIZER
12625                 (struct cmd_config_e_tag_result,
12626                  del, "del");
12627 cmdline_parse_token_string_t cmd_config_e_tag_on =
12628         TOKEN_STRING_INITIALIZER
12629                 (struct cmd_config_e_tag_result,
12630                  on, "on");
12631 cmdline_parse_token_string_t cmd_config_e_tag_off =
12632         TOKEN_STRING_INITIALIZER
12633                 (struct cmd_config_e_tag_result,
12634                  off, "off");
12635 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12636         TOKEN_STRING_INITIALIZER
12637                 (struct cmd_config_e_tag_result,
12638                  on_off, "on#off");
12639 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12640         TOKEN_STRING_INITIALIZER
12641                 (struct cmd_config_e_tag_result,
12642                  port_tag_id, "port-tag-id");
12643 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12644         TOKEN_NUM_INITIALIZER
12645                 (struct cmd_config_e_tag_result,
12646                  port_tag_id_val, UINT32);
12647 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12648         TOKEN_STRING_INITIALIZER
12649                 (struct cmd_config_e_tag_result,
12650                  e_tag_id, "e-tag-id");
12651 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12652         TOKEN_NUM_INITIALIZER
12653                 (struct cmd_config_e_tag_result,
12654                  e_tag_id_val, UINT16);
12655 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12656         TOKEN_STRING_INITIALIZER
12657                 (struct cmd_config_e_tag_result,
12658                  dst_pool, "dst-pool");
12659 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12660         TOKEN_NUM_INITIALIZER
12661                 (struct cmd_config_e_tag_result,
12662                  dst_pool_val, UINT8);
12663 cmdline_parse_token_string_t cmd_config_e_tag_port =
12664         TOKEN_STRING_INITIALIZER
12665                 (struct cmd_config_e_tag_result,
12666                  port, "port");
12667 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12668         TOKEN_NUM_INITIALIZER
12669                 (struct cmd_config_e_tag_result,
12670                  port_id, UINT16);
12671 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12672         TOKEN_STRING_INITIALIZER
12673                 (struct cmd_config_e_tag_result,
12674                  vf, "vf");
12675 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12676         TOKEN_NUM_INITIALIZER
12677                 (struct cmd_config_e_tag_result,
12678                  vf_id, UINT8);
12679
12680 /* E-tag insertion configuration */
12681 static void
12682 cmd_config_e_tag_insertion_en_parsed(
12683         void *parsed_result,
12684         __attribute__((unused)) struct cmdline *cl,
12685         __attribute__((unused)) void *data)
12686 {
12687         struct cmd_config_e_tag_result *res =
12688                 parsed_result;
12689         struct rte_eth_l2_tunnel_conf entry;
12690
12691         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12692                 return;
12693
12694         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12695         entry.tunnel_id = res->port_tag_id_val;
12696         entry.vf_id = res->vf_id;
12697         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12698                                           &entry,
12699                                           ETH_L2_TUNNEL_INSERTION_MASK,
12700                                           1);
12701 }
12702
12703 static void
12704 cmd_config_e_tag_insertion_dis_parsed(
12705         void *parsed_result,
12706         __attribute__((unused)) struct cmdline *cl,
12707         __attribute__((unused)) void *data)
12708 {
12709         struct cmd_config_e_tag_result *res =
12710                 parsed_result;
12711         struct rte_eth_l2_tunnel_conf entry;
12712
12713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12714                 return;
12715
12716         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12717         entry.vf_id = res->vf_id;
12718
12719         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12720                                           &entry,
12721                                           ETH_L2_TUNNEL_INSERTION_MASK,
12722                                           0);
12723 }
12724
12725 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12726         .f = cmd_config_e_tag_insertion_en_parsed,
12727         .data = NULL,
12728         .help_str = "E-tag ... : E-tag insertion enable",
12729         .tokens = {
12730                 (void *)&cmd_config_e_tag_e_tag,
12731                 (void *)&cmd_config_e_tag_set,
12732                 (void *)&cmd_config_e_tag_insertion,
12733                 (void *)&cmd_config_e_tag_on,
12734                 (void *)&cmd_config_e_tag_port_tag_id,
12735                 (void *)&cmd_config_e_tag_port_tag_id_val,
12736                 (void *)&cmd_config_e_tag_port,
12737                 (void *)&cmd_config_e_tag_port_id,
12738                 (void *)&cmd_config_e_tag_vf,
12739                 (void *)&cmd_config_e_tag_vf_id,
12740                 NULL,
12741         },
12742 };
12743
12744 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12745         .f = cmd_config_e_tag_insertion_dis_parsed,
12746         .data = NULL,
12747         .help_str = "E-tag ... : E-tag insertion disable",
12748         .tokens = {
12749                 (void *)&cmd_config_e_tag_e_tag,
12750                 (void *)&cmd_config_e_tag_set,
12751                 (void *)&cmd_config_e_tag_insertion,
12752                 (void *)&cmd_config_e_tag_off,
12753                 (void *)&cmd_config_e_tag_port,
12754                 (void *)&cmd_config_e_tag_port_id,
12755                 (void *)&cmd_config_e_tag_vf,
12756                 (void *)&cmd_config_e_tag_vf_id,
12757                 NULL,
12758         },
12759 };
12760
12761 /* E-tag stripping configuration */
12762 static void
12763 cmd_config_e_tag_stripping_parsed(
12764         void *parsed_result,
12765         __attribute__((unused)) struct cmdline *cl,
12766         __attribute__((unused)) void *data)
12767 {
12768         struct cmd_config_e_tag_result *res =
12769                 parsed_result;
12770         struct rte_eth_l2_tunnel_conf entry;
12771
12772         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12773                 return;
12774
12775         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12776
12777         if (!strcmp(res->on_off, "on"))
12778                 rte_eth_dev_l2_tunnel_offload_set
12779                         (res->port_id,
12780                          &entry,
12781                          ETH_L2_TUNNEL_STRIPPING_MASK,
12782                          1);
12783         else
12784                 rte_eth_dev_l2_tunnel_offload_set
12785                         (res->port_id,
12786                          &entry,
12787                          ETH_L2_TUNNEL_STRIPPING_MASK,
12788                          0);
12789 }
12790
12791 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12792         .f = cmd_config_e_tag_stripping_parsed,
12793         .data = NULL,
12794         .help_str = "E-tag ... : E-tag stripping enable/disable",
12795         .tokens = {
12796                 (void *)&cmd_config_e_tag_e_tag,
12797                 (void *)&cmd_config_e_tag_set,
12798                 (void *)&cmd_config_e_tag_stripping,
12799                 (void *)&cmd_config_e_tag_on_off,
12800                 (void *)&cmd_config_e_tag_port,
12801                 (void *)&cmd_config_e_tag_port_id,
12802                 NULL,
12803         },
12804 };
12805
12806 /* E-tag forwarding configuration */
12807 static void
12808 cmd_config_e_tag_forwarding_parsed(
12809         void *parsed_result,
12810         __attribute__((unused)) struct cmdline *cl,
12811         __attribute__((unused)) void *data)
12812 {
12813         struct cmd_config_e_tag_result *res = parsed_result;
12814         struct rte_eth_l2_tunnel_conf entry;
12815
12816         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12817                 return;
12818
12819         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12820
12821         if (!strcmp(res->on_off, "on"))
12822                 rte_eth_dev_l2_tunnel_offload_set
12823                         (res->port_id,
12824                          &entry,
12825                          ETH_L2_TUNNEL_FORWARDING_MASK,
12826                          1);
12827         else
12828                 rte_eth_dev_l2_tunnel_offload_set
12829                         (res->port_id,
12830                          &entry,
12831                          ETH_L2_TUNNEL_FORWARDING_MASK,
12832                          0);
12833 }
12834
12835 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12836         .f = cmd_config_e_tag_forwarding_parsed,
12837         .data = NULL,
12838         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12839         .tokens = {
12840                 (void *)&cmd_config_e_tag_e_tag,
12841                 (void *)&cmd_config_e_tag_set,
12842                 (void *)&cmd_config_e_tag_forwarding,
12843                 (void *)&cmd_config_e_tag_on_off,
12844                 (void *)&cmd_config_e_tag_port,
12845                 (void *)&cmd_config_e_tag_port_id,
12846                 NULL,
12847         },
12848 };
12849
12850 /* E-tag filter configuration */
12851 static void
12852 cmd_config_e_tag_filter_add_parsed(
12853         void *parsed_result,
12854         __attribute__((unused)) struct cmdline *cl,
12855         __attribute__((unused)) void *data)
12856 {
12857         struct cmd_config_e_tag_result *res = parsed_result;
12858         struct rte_eth_l2_tunnel_conf entry;
12859         int ret = 0;
12860
12861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12862                 return;
12863
12864         if (res->e_tag_id_val > 0x3fff) {
12865                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12866                 return;
12867         }
12868
12869         ret = rte_eth_dev_filter_supported(res->port_id,
12870                                            RTE_ETH_FILTER_L2_TUNNEL);
12871         if (ret < 0) {
12872                 printf("E-tag filter is not supported on port %u.\n",
12873                        res->port_id);
12874                 return;
12875         }
12876
12877         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12878         entry.tunnel_id = res->e_tag_id_val;
12879         entry.pool = res->dst_pool_val;
12880
12881         ret = rte_eth_dev_filter_ctrl(res->port_id,
12882                                       RTE_ETH_FILTER_L2_TUNNEL,
12883                                       RTE_ETH_FILTER_ADD,
12884                                       &entry);
12885         if (ret < 0)
12886                 printf("E-tag filter programming error: (%s)\n",
12887                        strerror(-ret));
12888 }
12889
12890 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12891         .f = cmd_config_e_tag_filter_add_parsed,
12892         .data = NULL,
12893         .help_str = "E-tag ... : E-tag filter add",
12894         .tokens = {
12895                 (void *)&cmd_config_e_tag_e_tag,
12896                 (void *)&cmd_config_e_tag_set,
12897                 (void *)&cmd_config_e_tag_filter,
12898                 (void *)&cmd_config_e_tag_add,
12899                 (void *)&cmd_config_e_tag_e_tag_id,
12900                 (void *)&cmd_config_e_tag_e_tag_id_val,
12901                 (void *)&cmd_config_e_tag_dst_pool,
12902                 (void *)&cmd_config_e_tag_dst_pool_val,
12903                 (void *)&cmd_config_e_tag_port,
12904                 (void *)&cmd_config_e_tag_port_id,
12905                 NULL,
12906         },
12907 };
12908
12909 static void
12910 cmd_config_e_tag_filter_del_parsed(
12911         void *parsed_result,
12912         __attribute__((unused)) struct cmdline *cl,
12913         __attribute__((unused)) void *data)
12914 {
12915         struct cmd_config_e_tag_result *res = parsed_result;
12916         struct rte_eth_l2_tunnel_conf entry;
12917         int ret = 0;
12918
12919         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12920                 return;
12921
12922         if (res->e_tag_id_val > 0x3fff) {
12923                 printf("e-tag-id must be less than 0x3fff.\n");
12924                 return;
12925         }
12926
12927         ret = rte_eth_dev_filter_supported(res->port_id,
12928                                            RTE_ETH_FILTER_L2_TUNNEL);
12929         if (ret < 0) {
12930                 printf("E-tag filter is not supported on port %u.\n",
12931                        res->port_id);
12932                 return;
12933         }
12934
12935         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12936         entry.tunnel_id = res->e_tag_id_val;
12937
12938         ret = rte_eth_dev_filter_ctrl(res->port_id,
12939                                       RTE_ETH_FILTER_L2_TUNNEL,
12940                                       RTE_ETH_FILTER_DELETE,
12941                                       &entry);
12942         if (ret < 0)
12943                 printf("E-tag filter programming error: (%s)\n",
12944                        strerror(-ret));
12945 }
12946
12947 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12948         .f = cmd_config_e_tag_filter_del_parsed,
12949         .data = NULL,
12950         .help_str = "E-tag ... : E-tag filter delete",
12951         .tokens = {
12952                 (void *)&cmd_config_e_tag_e_tag,
12953                 (void *)&cmd_config_e_tag_set,
12954                 (void *)&cmd_config_e_tag_filter,
12955                 (void *)&cmd_config_e_tag_del,
12956                 (void *)&cmd_config_e_tag_e_tag_id,
12957                 (void *)&cmd_config_e_tag_e_tag_id_val,
12958                 (void *)&cmd_config_e_tag_port,
12959                 (void *)&cmd_config_e_tag_port_id,
12960                 NULL,
12961         },
12962 };
12963
12964 /* vf vlan anti spoof configuration */
12965
12966 /* Common result structure for vf vlan anti spoof */
12967 struct cmd_vf_vlan_anti_spoof_result {
12968         cmdline_fixed_string_t set;
12969         cmdline_fixed_string_t vf;
12970         cmdline_fixed_string_t vlan;
12971         cmdline_fixed_string_t antispoof;
12972         portid_t port_id;
12973         uint32_t vf_id;
12974         cmdline_fixed_string_t on_off;
12975 };
12976
12977 /* Common CLI fields for vf vlan anti spoof enable disable */
12978 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12979         TOKEN_STRING_INITIALIZER
12980                 (struct cmd_vf_vlan_anti_spoof_result,
12981                  set, "set");
12982 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12983         TOKEN_STRING_INITIALIZER
12984                 (struct cmd_vf_vlan_anti_spoof_result,
12985                  vf, "vf");
12986 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12987         TOKEN_STRING_INITIALIZER
12988                 (struct cmd_vf_vlan_anti_spoof_result,
12989                  vlan, "vlan");
12990 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12991         TOKEN_STRING_INITIALIZER
12992                 (struct cmd_vf_vlan_anti_spoof_result,
12993                  antispoof, "antispoof");
12994 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12995         TOKEN_NUM_INITIALIZER
12996                 (struct cmd_vf_vlan_anti_spoof_result,
12997                  port_id, UINT16);
12998 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12999         TOKEN_NUM_INITIALIZER
13000                 (struct cmd_vf_vlan_anti_spoof_result,
13001                  vf_id, UINT32);
13002 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13003         TOKEN_STRING_INITIALIZER
13004                 (struct cmd_vf_vlan_anti_spoof_result,
13005                  on_off, "on#off");
13006
13007 static void
13008 cmd_set_vf_vlan_anti_spoof_parsed(
13009         void *parsed_result,
13010         __attribute__((unused)) struct cmdline *cl,
13011         __attribute__((unused)) void *data)
13012 {
13013         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13014         int ret = -ENOTSUP;
13015
13016         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13017
13018         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13019                 return;
13020
13021 #ifdef RTE_LIBRTE_IXGBE_PMD
13022         if (ret == -ENOTSUP)
13023                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13024                                 res->vf_id, is_on);
13025 #endif
13026 #ifdef RTE_LIBRTE_I40E_PMD
13027         if (ret == -ENOTSUP)
13028                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13029                                 res->vf_id, is_on);
13030 #endif
13031 #ifdef RTE_LIBRTE_BNXT_PMD
13032         if (ret == -ENOTSUP)
13033                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13034                                 res->vf_id, is_on);
13035 #endif
13036
13037         switch (ret) {
13038         case 0:
13039                 break;
13040         case -EINVAL:
13041                 printf("invalid vf_id %d\n", res->vf_id);
13042                 break;
13043         case -ENODEV:
13044                 printf("invalid port_id %d\n", res->port_id);
13045                 break;
13046         case -ENOTSUP:
13047                 printf("function not implemented\n");
13048                 break;
13049         default:
13050                 printf("programming error: (%s)\n", strerror(-ret));
13051         }
13052 }
13053
13054 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13055         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13056         .data = NULL,
13057         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13058         .tokens = {
13059                 (void *)&cmd_vf_vlan_anti_spoof_set,
13060                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13061                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13062                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13063                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13064                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13065                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13066                 NULL,
13067         },
13068 };
13069
13070 /* vf mac anti spoof configuration */
13071
13072 /* Common result structure for vf mac anti spoof */
13073 struct cmd_vf_mac_anti_spoof_result {
13074         cmdline_fixed_string_t set;
13075         cmdline_fixed_string_t vf;
13076         cmdline_fixed_string_t mac;
13077         cmdline_fixed_string_t antispoof;
13078         portid_t port_id;
13079         uint32_t vf_id;
13080         cmdline_fixed_string_t on_off;
13081 };
13082
13083 /* Common CLI fields for vf mac anti spoof enable disable */
13084 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_vf_mac_anti_spoof_result,
13087                  set, "set");
13088 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13089         TOKEN_STRING_INITIALIZER
13090                 (struct cmd_vf_mac_anti_spoof_result,
13091                  vf, "vf");
13092 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13093         TOKEN_STRING_INITIALIZER
13094                 (struct cmd_vf_mac_anti_spoof_result,
13095                  mac, "mac");
13096 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13097         TOKEN_STRING_INITIALIZER
13098                 (struct cmd_vf_mac_anti_spoof_result,
13099                  antispoof, "antispoof");
13100 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13101         TOKEN_NUM_INITIALIZER
13102                 (struct cmd_vf_mac_anti_spoof_result,
13103                  port_id, UINT16);
13104 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13105         TOKEN_NUM_INITIALIZER
13106                 (struct cmd_vf_mac_anti_spoof_result,
13107                  vf_id, UINT32);
13108 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13109         TOKEN_STRING_INITIALIZER
13110                 (struct cmd_vf_mac_anti_spoof_result,
13111                  on_off, "on#off");
13112
13113 static void
13114 cmd_set_vf_mac_anti_spoof_parsed(
13115         void *parsed_result,
13116         __attribute__((unused)) struct cmdline *cl,
13117         __attribute__((unused)) void *data)
13118 {
13119         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13120         int ret = -ENOTSUP;
13121
13122         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13123
13124         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13125                 return;
13126
13127 #ifdef RTE_LIBRTE_IXGBE_PMD
13128         if (ret == -ENOTSUP)
13129                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13130                         res->vf_id, is_on);
13131 #endif
13132 #ifdef RTE_LIBRTE_I40E_PMD
13133         if (ret == -ENOTSUP)
13134                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13135                         res->vf_id, is_on);
13136 #endif
13137 #ifdef RTE_LIBRTE_BNXT_PMD
13138         if (ret == -ENOTSUP)
13139                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13140                         res->vf_id, is_on);
13141 #endif
13142
13143         switch (ret) {
13144         case 0:
13145                 break;
13146         case -EINVAL:
13147                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13148                 break;
13149         case -ENODEV:
13150                 printf("invalid port_id %d\n", res->port_id);
13151                 break;
13152         case -ENOTSUP:
13153                 printf("function not implemented\n");
13154                 break;
13155         default:
13156                 printf("programming error: (%s)\n", strerror(-ret));
13157         }
13158 }
13159
13160 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13161         .f = cmd_set_vf_mac_anti_spoof_parsed,
13162         .data = NULL,
13163         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13164         .tokens = {
13165                 (void *)&cmd_vf_mac_anti_spoof_set,
13166                 (void *)&cmd_vf_mac_anti_spoof_vf,
13167                 (void *)&cmd_vf_mac_anti_spoof_mac,
13168                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13169                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13170                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13171                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13172                 NULL,
13173         },
13174 };
13175
13176 /* vf vlan strip queue configuration */
13177
13178 /* Common result structure for vf mac anti spoof */
13179 struct cmd_vf_vlan_stripq_result {
13180         cmdline_fixed_string_t set;
13181         cmdline_fixed_string_t vf;
13182         cmdline_fixed_string_t vlan;
13183         cmdline_fixed_string_t stripq;
13184         portid_t port_id;
13185         uint16_t vf_id;
13186         cmdline_fixed_string_t on_off;
13187 };
13188
13189 /* Common CLI fields for vf vlan strip enable disable */
13190 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13191         TOKEN_STRING_INITIALIZER
13192                 (struct cmd_vf_vlan_stripq_result,
13193                  set, "set");
13194 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13195         TOKEN_STRING_INITIALIZER
13196                 (struct cmd_vf_vlan_stripq_result,
13197                  vf, "vf");
13198 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13199         TOKEN_STRING_INITIALIZER
13200                 (struct cmd_vf_vlan_stripq_result,
13201                  vlan, "vlan");
13202 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13203         TOKEN_STRING_INITIALIZER
13204                 (struct cmd_vf_vlan_stripq_result,
13205                  stripq, "stripq");
13206 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13207         TOKEN_NUM_INITIALIZER
13208                 (struct cmd_vf_vlan_stripq_result,
13209                  port_id, UINT16);
13210 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13211         TOKEN_NUM_INITIALIZER
13212                 (struct cmd_vf_vlan_stripq_result,
13213                  vf_id, UINT16);
13214 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13215         TOKEN_STRING_INITIALIZER
13216                 (struct cmd_vf_vlan_stripq_result,
13217                  on_off, "on#off");
13218
13219 static void
13220 cmd_set_vf_vlan_stripq_parsed(
13221         void *parsed_result,
13222         __attribute__((unused)) struct cmdline *cl,
13223         __attribute__((unused)) void *data)
13224 {
13225         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13226         int ret = -ENOTSUP;
13227
13228         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13229
13230         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13231                 return;
13232
13233 #ifdef RTE_LIBRTE_IXGBE_PMD
13234         if (ret == -ENOTSUP)
13235                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13236                         res->vf_id, is_on);
13237 #endif
13238 #ifdef RTE_LIBRTE_I40E_PMD
13239         if (ret == -ENOTSUP)
13240                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13241                         res->vf_id, is_on);
13242 #endif
13243 #ifdef RTE_LIBRTE_BNXT_PMD
13244         if (ret == -ENOTSUP)
13245                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13246                         res->vf_id, is_on);
13247 #endif
13248
13249         switch (ret) {
13250         case 0:
13251                 break;
13252         case -EINVAL:
13253                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13254                 break;
13255         case -ENODEV:
13256                 printf("invalid port_id %d\n", res->port_id);
13257                 break;
13258         case -ENOTSUP:
13259                 printf("function not implemented\n");
13260                 break;
13261         default:
13262                 printf("programming error: (%s)\n", strerror(-ret));
13263         }
13264 }
13265
13266 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13267         .f = cmd_set_vf_vlan_stripq_parsed,
13268         .data = NULL,
13269         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13270         .tokens = {
13271                 (void *)&cmd_vf_vlan_stripq_set,
13272                 (void *)&cmd_vf_vlan_stripq_vf,
13273                 (void *)&cmd_vf_vlan_stripq_vlan,
13274                 (void *)&cmd_vf_vlan_stripq_stripq,
13275                 (void *)&cmd_vf_vlan_stripq_port_id,
13276                 (void *)&cmd_vf_vlan_stripq_vf_id,
13277                 (void *)&cmd_vf_vlan_stripq_on_off,
13278                 NULL,
13279         },
13280 };
13281
13282 /* vf vlan insert configuration */
13283
13284 /* Common result structure for vf vlan insert */
13285 struct cmd_vf_vlan_insert_result {
13286         cmdline_fixed_string_t set;
13287         cmdline_fixed_string_t vf;
13288         cmdline_fixed_string_t vlan;
13289         cmdline_fixed_string_t insert;
13290         portid_t port_id;
13291         uint16_t vf_id;
13292         uint16_t vlan_id;
13293 };
13294
13295 /* Common CLI fields for vf vlan insert enable disable */
13296 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13297         TOKEN_STRING_INITIALIZER
13298                 (struct cmd_vf_vlan_insert_result,
13299                  set, "set");
13300 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13301         TOKEN_STRING_INITIALIZER
13302                 (struct cmd_vf_vlan_insert_result,
13303                  vf, "vf");
13304 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13305         TOKEN_STRING_INITIALIZER
13306                 (struct cmd_vf_vlan_insert_result,
13307                  vlan, "vlan");
13308 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13309         TOKEN_STRING_INITIALIZER
13310                 (struct cmd_vf_vlan_insert_result,
13311                  insert, "insert");
13312 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13313         TOKEN_NUM_INITIALIZER
13314                 (struct cmd_vf_vlan_insert_result,
13315                  port_id, UINT16);
13316 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13317         TOKEN_NUM_INITIALIZER
13318                 (struct cmd_vf_vlan_insert_result,
13319                  vf_id, UINT16);
13320 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13321         TOKEN_NUM_INITIALIZER
13322                 (struct cmd_vf_vlan_insert_result,
13323                  vlan_id, UINT16);
13324
13325 static void
13326 cmd_set_vf_vlan_insert_parsed(
13327         void *parsed_result,
13328         __attribute__((unused)) struct cmdline *cl,
13329         __attribute__((unused)) void *data)
13330 {
13331         struct cmd_vf_vlan_insert_result *res = parsed_result;
13332         int ret = -ENOTSUP;
13333
13334         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13335                 return;
13336
13337 #ifdef RTE_LIBRTE_IXGBE_PMD
13338         if (ret == -ENOTSUP)
13339                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13340                         res->vlan_id);
13341 #endif
13342 #ifdef RTE_LIBRTE_I40E_PMD
13343         if (ret == -ENOTSUP)
13344                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13345                         res->vlan_id);
13346 #endif
13347 #ifdef RTE_LIBRTE_BNXT_PMD
13348         if (ret == -ENOTSUP)
13349                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13350                         res->vlan_id);
13351 #endif
13352
13353         switch (ret) {
13354         case 0:
13355                 break;
13356         case -EINVAL:
13357                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13358                 break;
13359         case -ENODEV:
13360                 printf("invalid port_id %d\n", res->port_id);
13361                 break;
13362         case -ENOTSUP:
13363                 printf("function not implemented\n");
13364                 break;
13365         default:
13366                 printf("programming error: (%s)\n", strerror(-ret));
13367         }
13368 }
13369
13370 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13371         .f = cmd_set_vf_vlan_insert_parsed,
13372         .data = NULL,
13373         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13374         .tokens = {
13375                 (void *)&cmd_vf_vlan_insert_set,
13376                 (void *)&cmd_vf_vlan_insert_vf,
13377                 (void *)&cmd_vf_vlan_insert_vlan,
13378                 (void *)&cmd_vf_vlan_insert_insert,
13379                 (void *)&cmd_vf_vlan_insert_port_id,
13380                 (void *)&cmd_vf_vlan_insert_vf_id,
13381                 (void *)&cmd_vf_vlan_insert_vlan_id,
13382                 NULL,
13383         },
13384 };
13385
13386 /* tx loopback configuration */
13387
13388 /* Common result structure for tx loopback */
13389 struct cmd_tx_loopback_result {
13390         cmdline_fixed_string_t set;
13391         cmdline_fixed_string_t tx;
13392         cmdline_fixed_string_t loopback;
13393         portid_t port_id;
13394         cmdline_fixed_string_t on_off;
13395 };
13396
13397 /* Common CLI fields for tx loopback enable disable */
13398 cmdline_parse_token_string_t cmd_tx_loopback_set =
13399         TOKEN_STRING_INITIALIZER
13400                 (struct cmd_tx_loopback_result,
13401                  set, "set");
13402 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13403         TOKEN_STRING_INITIALIZER
13404                 (struct cmd_tx_loopback_result,
13405                  tx, "tx");
13406 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13407         TOKEN_STRING_INITIALIZER
13408                 (struct cmd_tx_loopback_result,
13409                  loopback, "loopback");
13410 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13411         TOKEN_NUM_INITIALIZER
13412                 (struct cmd_tx_loopback_result,
13413                  port_id, UINT16);
13414 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13415         TOKEN_STRING_INITIALIZER
13416                 (struct cmd_tx_loopback_result,
13417                  on_off, "on#off");
13418
13419 static void
13420 cmd_set_tx_loopback_parsed(
13421         void *parsed_result,
13422         __attribute__((unused)) struct cmdline *cl,
13423         __attribute__((unused)) void *data)
13424 {
13425         struct cmd_tx_loopback_result *res = parsed_result;
13426         int ret = -ENOTSUP;
13427
13428         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13429
13430         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13431                 return;
13432
13433 #ifdef RTE_LIBRTE_IXGBE_PMD
13434         if (ret == -ENOTSUP)
13435                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13436 #endif
13437 #ifdef RTE_LIBRTE_I40E_PMD
13438         if (ret == -ENOTSUP)
13439                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13440 #endif
13441 #ifdef RTE_LIBRTE_BNXT_PMD
13442         if (ret == -ENOTSUP)
13443                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13444 #endif
13445 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13446         if (ret == -ENOTSUP)
13447                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13448 #endif
13449
13450         switch (ret) {
13451         case 0:
13452                 break;
13453         case -EINVAL:
13454                 printf("invalid is_on %d\n", is_on);
13455                 break;
13456         case -ENODEV:
13457                 printf("invalid port_id %d\n", res->port_id);
13458                 break;
13459         case -ENOTSUP:
13460                 printf("function not implemented\n");
13461                 break;
13462         default:
13463                 printf("programming error: (%s)\n", strerror(-ret));
13464         }
13465 }
13466
13467 cmdline_parse_inst_t cmd_set_tx_loopback = {
13468         .f = cmd_set_tx_loopback_parsed,
13469         .data = NULL,
13470         .help_str = "set tx loopback <port_id> on|off",
13471         .tokens = {
13472                 (void *)&cmd_tx_loopback_set,
13473                 (void *)&cmd_tx_loopback_tx,
13474                 (void *)&cmd_tx_loopback_loopback,
13475                 (void *)&cmd_tx_loopback_port_id,
13476                 (void *)&cmd_tx_loopback_on_off,
13477                 NULL,
13478         },
13479 };
13480
13481 /* all queues drop enable configuration */
13482
13483 /* Common result structure for all queues drop enable */
13484 struct cmd_all_queues_drop_en_result {
13485         cmdline_fixed_string_t set;
13486         cmdline_fixed_string_t all;
13487         cmdline_fixed_string_t queues;
13488         cmdline_fixed_string_t drop;
13489         portid_t port_id;
13490         cmdline_fixed_string_t on_off;
13491 };
13492
13493 /* Common CLI fields for tx loopback enable disable */
13494 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13495         TOKEN_STRING_INITIALIZER
13496                 (struct cmd_all_queues_drop_en_result,
13497                  set, "set");
13498 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13499         TOKEN_STRING_INITIALIZER
13500                 (struct cmd_all_queues_drop_en_result,
13501                  all, "all");
13502 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13503         TOKEN_STRING_INITIALIZER
13504                 (struct cmd_all_queues_drop_en_result,
13505                  queues, "queues");
13506 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13507         TOKEN_STRING_INITIALIZER
13508                 (struct cmd_all_queues_drop_en_result,
13509                  drop, "drop");
13510 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13511         TOKEN_NUM_INITIALIZER
13512                 (struct cmd_all_queues_drop_en_result,
13513                  port_id, UINT16);
13514 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13515         TOKEN_STRING_INITIALIZER
13516                 (struct cmd_all_queues_drop_en_result,
13517                  on_off, "on#off");
13518
13519 static void
13520 cmd_set_all_queues_drop_en_parsed(
13521         void *parsed_result,
13522         __attribute__((unused)) struct cmdline *cl,
13523         __attribute__((unused)) void *data)
13524 {
13525         struct cmd_all_queues_drop_en_result *res = parsed_result;
13526         int ret = -ENOTSUP;
13527         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13528
13529         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13530                 return;
13531
13532 #ifdef RTE_LIBRTE_IXGBE_PMD
13533         if (ret == -ENOTSUP)
13534                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13535 #endif
13536 #ifdef RTE_LIBRTE_BNXT_PMD
13537         if (ret == -ENOTSUP)
13538                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13539 #endif
13540         switch (ret) {
13541         case 0:
13542                 break;
13543         case -EINVAL:
13544                 printf("invalid is_on %d\n", is_on);
13545                 break;
13546         case -ENODEV:
13547                 printf("invalid port_id %d\n", res->port_id);
13548                 break;
13549         case -ENOTSUP:
13550                 printf("function not implemented\n");
13551                 break;
13552         default:
13553                 printf("programming error: (%s)\n", strerror(-ret));
13554         }
13555 }
13556
13557 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13558         .f = cmd_set_all_queues_drop_en_parsed,
13559         .data = NULL,
13560         .help_str = "set all queues drop <port_id> on|off",
13561         .tokens = {
13562                 (void *)&cmd_all_queues_drop_en_set,
13563                 (void *)&cmd_all_queues_drop_en_all,
13564                 (void *)&cmd_all_queues_drop_en_queues,
13565                 (void *)&cmd_all_queues_drop_en_drop,
13566                 (void *)&cmd_all_queues_drop_en_port_id,
13567                 (void *)&cmd_all_queues_drop_en_on_off,
13568                 NULL,
13569         },
13570 };
13571
13572 /* vf split drop enable configuration */
13573
13574 /* Common result structure for vf split drop enable */
13575 struct cmd_vf_split_drop_en_result {
13576         cmdline_fixed_string_t set;
13577         cmdline_fixed_string_t vf;
13578         cmdline_fixed_string_t split;
13579         cmdline_fixed_string_t drop;
13580         portid_t port_id;
13581         uint16_t vf_id;
13582         cmdline_fixed_string_t on_off;
13583 };
13584
13585 /* Common CLI fields for vf split drop enable disable */
13586 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13587         TOKEN_STRING_INITIALIZER
13588                 (struct cmd_vf_split_drop_en_result,
13589                  set, "set");
13590 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13591         TOKEN_STRING_INITIALIZER
13592                 (struct cmd_vf_split_drop_en_result,
13593                  vf, "vf");
13594 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13595         TOKEN_STRING_INITIALIZER
13596                 (struct cmd_vf_split_drop_en_result,
13597                  split, "split");
13598 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13599         TOKEN_STRING_INITIALIZER
13600                 (struct cmd_vf_split_drop_en_result,
13601                  drop, "drop");
13602 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13603         TOKEN_NUM_INITIALIZER
13604                 (struct cmd_vf_split_drop_en_result,
13605                  port_id, UINT16);
13606 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13607         TOKEN_NUM_INITIALIZER
13608                 (struct cmd_vf_split_drop_en_result,
13609                  vf_id, UINT16);
13610 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13611         TOKEN_STRING_INITIALIZER
13612                 (struct cmd_vf_split_drop_en_result,
13613                  on_off, "on#off");
13614
13615 static void
13616 cmd_set_vf_split_drop_en_parsed(
13617         void *parsed_result,
13618         __attribute__((unused)) struct cmdline *cl,
13619         __attribute__((unused)) void *data)
13620 {
13621         struct cmd_vf_split_drop_en_result *res = parsed_result;
13622         int ret = -ENOTSUP;
13623         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13624
13625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13626                 return;
13627
13628 #ifdef RTE_LIBRTE_IXGBE_PMD
13629         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13630                         is_on);
13631 #endif
13632         switch (ret) {
13633         case 0:
13634                 break;
13635         case -EINVAL:
13636                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13637                 break;
13638         case -ENODEV:
13639                 printf("invalid port_id %d\n", res->port_id);
13640                 break;
13641         case -ENOTSUP:
13642                 printf("not supported on port %d\n", res->port_id);
13643                 break;
13644         default:
13645                 printf("programming error: (%s)\n", strerror(-ret));
13646         }
13647 }
13648
13649 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13650         .f = cmd_set_vf_split_drop_en_parsed,
13651         .data = NULL,
13652         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13653         .tokens = {
13654                 (void *)&cmd_vf_split_drop_en_set,
13655                 (void *)&cmd_vf_split_drop_en_vf,
13656                 (void *)&cmd_vf_split_drop_en_split,
13657                 (void *)&cmd_vf_split_drop_en_drop,
13658                 (void *)&cmd_vf_split_drop_en_port_id,
13659                 (void *)&cmd_vf_split_drop_en_vf_id,
13660                 (void *)&cmd_vf_split_drop_en_on_off,
13661                 NULL,
13662         },
13663 };
13664
13665 /* vf mac address configuration */
13666
13667 /* Common result structure for vf mac address */
13668 struct cmd_set_vf_mac_addr_result {
13669         cmdline_fixed_string_t set;
13670         cmdline_fixed_string_t vf;
13671         cmdline_fixed_string_t mac;
13672         cmdline_fixed_string_t addr;
13673         portid_t port_id;
13674         uint16_t vf_id;
13675         struct ether_addr mac_addr;
13676
13677 };
13678
13679 /* Common CLI fields for vf split drop enable disable */
13680 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13681         TOKEN_STRING_INITIALIZER
13682                 (struct cmd_set_vf_mac_addr_result,
13683                  set, "set");
13684 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_set_vf_mac_addr_result,
13687                  vf, "vf");
13688 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13689         TOKEN_STRING_INITIALIZER
13690                 (struct cmd_set_vf_mac_addr_result,
13691                  mac, "mac");
13692 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13693         TOKEN_STRING_INITIALIZER
13694                 (struct cmd_set_vf_mac_addr_result,
13695                  addr, "addr");
13696 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13697         TOKEN_NUM_INITIALIZER
13698                 (struct cmd_set_vf_mac_addr_result,
13699                  port_id, UINT16);
13700 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13701         TOKEN_NUM_INITIALIZER
13702                 (struct cmd_set_vf_mac_addr_result,
13703                  vf_id, UINT16);
13704 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13705         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13706                  mac_addr);
13707
13708 static void
13709 cmd_set_vf_mac_addr_parsed(
13710         void *parsed_result,
13711         __attribute__((unused)) struct cmdline *cl,
13712         __attribute__((unused)) void *data)
13713 {
13714         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13715         int ret = -ENOTSUP;
13716
13717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13718                 return;
13719
13720 #ifdef RTE_LIBRTE_IXGBE_PMD
13721         if (ret == -ENOTSUP)
13722                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13723                                 &res->mac_addr);
13724 #endif
13725 #ifdef RTE_LIBRTE_I40E_PMD
13726         if (ret == -ENOTSUP)
13727                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13728                                 &res->mac_addr);
13729 #endif
13730 #ifdef RTE_LIBRTE_BNXT_PMD
13731         if (ret == -ENOTSUP)
13732                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13733                                 &res->mac_addr);
13734 #endif
13735
13736         switch (ret) {
13737         case 0:
13738                 break;
13739         case -EINVAL:
13740                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13741                 break;
13742         case -ENODEV:
13743                 printf("invalid port_id %d\n", res->port_id);
13744                 break;
13745         case -ENOTSUP:
13746                 printf("function not implemented\n");
13747                 break;
13748         default:
13749                 printf("programming error: (%s)\n", strerror(-ret));
13750         }
13751 }
13752
13753 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13754         .f = cmd_set_vf_mac_addr_parsed,
13755         .data = NULL,
13756         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13757         .tokens = {
13758                 (void *)&cmd_set_vf_mac_addr_set,
13759                 (void *)&cmd_set_vf_mac_addr_vf,
13760                 (void *)&cmd_set_vf_mac_addr_mac,
13761                 (void *)&cmd_set_vf_mac_addr_addr,
13762                 (void *)&cmd_set_vf_mac_addr_port_id,
13763                 (void *)&cmd_set_vf_mac_addr_vf_id,
13764                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13765                 NULL,
13766         },
13767 };
13768
13769 /* MACsec configuration */
13770
13771 /* Common result structure for MACsec offload enable */
13772 struct cmd_macsec_offload_on_result {
13773         cmdline_fixed_string_t set;
13774         cmdline_fixed_string_t macsec;
13775         cmdline_fixed_string_t offload;
13776         portid_t port_id;
13777         cmdline_fixed_string_t on;
13778         cmdline_fixed_string_t encrypt;
13779         cmdline_fixed_string_t en_on_off;
13780         cmdline_fixed_string_t replay_protect;
13781         cmdline_fixed_string_t rp_on_off;
13782 };
13783
13784 /* Common CLI fields for MACsec offload disable */
13785 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13786         TOKEN_STRING_INITIALIZER
13787                 (struct cmd_macsec_offload_on_result,
13788                  set, "set");
13789 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13790         TOKEN_STRING_INITIALIZER
13791                 (struct cmd_macsec_offload_on_result,
13792                  macsec, "macsec");
13793 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13794         TOKEN_STRING_INITIALIZER
13795                 (struct cmd_macsec_offload_on_result,
13796                  offload, "offload");
13797 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13798         TOKEN_NUM_INITIALIZER
13799                 (struct cmd_macsec_offload_on_result,
13800                  port_id, UINT16);
13801 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13802         TOKEN_STRING_INITIALIZER
13803                 (struct cmd_macsec_offload_on_result,
13804                  on, "on");
13805 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13806         TOKEN_STRING_INITIALIZER
13807                 (struct cmd_macsec_offload_on_result,
13808                  encrypt, "encrypt");
13809 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13810         TOKEN_STRING_INITIALIZER
13811                 (struct cmd_macsec_offload_on_result,
13812                  en_on_off, "on#off");
13813 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13814         TOKEN_STRING_INITIALIZER
13815                 (struct cmd_macsec_offload_on_result,
13816                  replay_protect, "replay-protect");
13817 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13818         TOKEN_STRING_INITIALIZER
13819                 (struct cmd_macsec_offload_on_result,
13820                  rp_on_off, "on#off");
13821
13822 static void
13823 cmd_set_macsec_offload_on_parsed(
13824         void *parsed_result,
13825         __attribute__((unused)) struct cmdline *cl,
13826         __attribute__((unused)) void *data)
13827 {
13828         struct cmd_macsec_offload_on_result *res = parsed_result;
13829         int ret = -ENOTSUP;
13830         portid_t port_id = res->port_id;
13831         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13832         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13833         struct rte_eth_dev_info dev_info;
13834
13835         if (port_id_is_invalid(port_id, ENABLED_WARN))
13836                 return;
13837         if (!port_is_stopped(port_id)) {
13838                 printf("Please stop port %d first\n", port_id);
13839                 return;
13840         }
13841
13842         rte_eth_dev_info_get(port_id, &dev_info);
13843         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13844 #ifdef RTE_LIBRTE_IXGBE_PMD
13845                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13846 #endif
13847         }
13848         RTE_SET_USED(en);
13849         RTE_SET_USED(rp);
13850
13851         switch (ret) {
13852         case 0:
13853                 ports[port_id].dev_conf.txmode.offloads |=
13854                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13855                 cmd_reconfig_device_queue(port_id, 1, 1);
13856                 break;
13857         case -ENODEV:
13858                 printf("invalid port_id %d\n", port_id);
13859                 break;
13860         case -ENOTSUP:
13861                 printf("not supported on port %d\n", port_id);
13862                 break;
13863         default:
13864                 printf("programming error: (%s)\n", strerror(-ret));
13865         }
13866 }
13867
13868 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13869         .f = cmd_set_macsec_offload_on_parsed,
13870         .data = NULL,
13871         .help_str = "set macsec offload <port_id> on "
13872                 "encrypt on|off replay-protect on|off",
13873         .tokens = {
13874                 (void *)&cmd_macsec_offload_on_set,
13875                 (void *)&cmd_macsec_offload_on_macsec,
13876                 (void *)&cmd_macsec_offload_on_offload,
13877                 (void *)&cmd_macsec_offload_on_port_id,
13878                 (void *)&cmd_macsec_offload_on_on,
13879                 (void *)&cmd_macsec_offload_on_encrypt,
13880                 (void *)&cmd_macsec_offload_on_en_on_off,
13881                 (void *)&cmd_macsec_offload_on_replay_protect,
13882                 (void *)&cmd_macsec_offload_on_rp_on_off,
13883                 NULL,
13884         },
13885 };
13886
13887 /* Common result structure for MACsec offload disable */
13888 struct cmd_macsec_offload_off_result {
13889         cmdline_fixed_string_t set;
13890         cmdline_fixed_string_t macsec;
13891         cmdline_fixed_string_t offload;
13892         portid_t port_id;
13893         cmdline_fixed_string_t off;
13894 };
13895
13896 /* Common CLI fields for MACsec offload disable */
13897 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13898         TOKEN_STRING_INITIALIZER
13899                 (struct cmd_macsec_offload_off_result,
13900                  set, "set");
13901 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13902         TOKEN_STRING_INITIALIZER
13903                 (struct cmd_macsec_offload_off_result,
13904                  macsec, "macsec");
13905 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13906         TOKEN_STRING_INITIALIZER
13907                 (struct cmd_macsec_offload_off_result,
13908                  offload, "offload");
13909 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13910         TOKEN_NUM_INITIALIZER
13911                 (struct cmd_macsec_offload_off_result,
13912                  port_id, UINT16);
13913 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13914         TOKEN_STRING_INITIALIZER
13915                 (struct cmd_macsec_offload_off_result,
13916                  off, "off");
13917
13918 static void
13919 cmd_set_macsec_offload_off_parsed(
13920         void *parsed_result,
13921         __attribute__((unused)) struct cmdline *cl,
13922         __attribute__((unused)) void *data)
13923 {
13924         struct cmd_macsec_offload_off_result *res = parsed_result;
13925         int ret = -ENOTSUP;
13926         struct rte_eth_dev_info dev_info;
13927         portid_t port_id = res->port_id;
13928
13929         if (port_id_is_invalid(port_id, ENABLED_WARN))
13930                 return;
13931         if (!port_is_stopped(port_id)) {
13932                 printf("Please stop port %d first\n", port_id);
13933                 return;
13934         }
13935
13936         rte_eth_dev_info_get(port_id, &dev_info);
13937         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13938 #ifdef RTE_LIBRTE_IXGBE_PMD
13939                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13940 #endif
13941         }
13942         switch (ret) {
13943         case 0:
13944                 ports[port_id].dev_conf.txmode.offloads &=
13945                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13946                 cmd_reconfig_device_queue(port_id, 1, 1);
13947                 break;
13948         case -ENODEV:
13949                 printf("invalid port_id %d\n", port_id);
13950                 break;
13951         case -ENOTSUP:
13952                 printf("not supported on port %d\n", port_id);
13953                 break;
13954         default:
13955                 printf("programming error: (%s)\n", strerror(-ret));
13956         }
13957 }
13958
13959 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13960         .f = cmd_set_macsec_offload_off_parsed,
13961         .data = NULL,
13962         .help_str = "set macsec offload <port_id> off",
13963         .tokens = {
13964                 (void *)&cmd_macsec_offload_off_set,
13965                 (void *)&cmd_macsec_offload_off_macsec,
13966                 (void *)&cmd_macsec_offload_off_offload,
13967                 (void *)&cmd_macsec_offload_off_port_id,
13968                 (void *)&cmd_macsec_offload_off_off,
13969                 NULL,
13970         },
13971 };
13972
13973 /* Common result structure for MACsec secure connection configure */
13974 struct cmd_macsec_sc_result {
13975         cmdline_fixed_string_t set;
13976         cmdline_fixed_string_t macsec;
13977         cmdline_fixed_string_t sc;
13978         cmdline_fixed_string_t tx_rx;
13979         portid_t port_id;
13980         struct ether_addr mac;
13981         uint16_t pi;
13982 };
13983
13984 /* Common CLI fields for MACsec secure connection configure */
13985 cmdline_parse_token_string_t cmd_macsec_sc_set =
13986         TOKEN_STRING_INITIALIZER
13987                 (struct cmd_macsec_sc_result,
13988                  set, "set");
13989 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13990         TOKEN_STRING_INITIALIZER
13991                 (struct cmd_macsec_sc_result,
13992                  macsec, "macsec");
13993 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13994         TOKEN_STRING_INITIALIZER
13995                 (struct cmd_macsec_sc_result,
13996                  sc, "sc");
13997 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13998         TOKEN_STRING_INITIALIZER
13999                 (struct cmd_macsec_sc_result,
14000                  tx_rx, "tx#rx");
14001 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14002         TOKEN_NUM_INITIALIZER
14003                 (struct cmd_macsec_sc_result,
14004                  port_id, UINT16);
14005 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14006         TOKEN_ETHERADDR_INITIALIZER
14007                 (struct cmd_macsec_sc_result,
14008                  mac);
14009 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14010         TOKEN_NUM_INITIALIZER
14011                 (struct cmd_macsec_sc_result,
14012                  pi, UINT16);
14013
14014 static void
14015 cmd_set_macsec_sc_parsed(
14016         void *parsed_result,
14017         __attribute__((unused)) struct cmdline *cl,
14018         __attribute__((unused)) void *data)
14019 {
14020         struct cmd_macsec_sc_result *res = parsed_result;
14021         int ret = -ENOTSUP;
14022         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14023
14024 #ifdef RTE_LIBRTE_IXGBE_PMD
14025         ret = is_tx ?
14026                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14027                                 res->mac.addr_bytes) :
14028                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14029                                 res->mac.addr_bytes, res->pi);
14030 #endif
14031         RTE_SET_USED(is_tx);
14032
14033         switch (ret) {
14034         case 0:
14035                 break;
14036         case -ENODEV:
14037                 printf("invalid port_id %d\n", res->port_id);
14038                 break;
14039         case -ENOTSUP:
14040                 printf("not supported on port %d\n", res->port_id);
14041                 break;
14042         default:
14043                 printf("programming error: (%s)\n", strerror(-ret));
14044         }
14045 }
14046
14047 cmdline_parse_inst_t cmd_set_macsec_sc = {
14048         .f = cmd_set_macsec_sc_parsed,
14049         .data = NULL,
14050         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14051         .tokens = {
14052                 (void *)&cmd_macsec_sc_set,
14053                 (void *)&cmd_macsec_sc_macsec,
14054                 (void *)&cmd_macsec_sc_sc,
14055                 (void *)&cmd_macsec_sc_tx_rx,
14056                 (void *)&cmd_macsec_sc_port_id,
14057                 (void *)&cmd_macsec_sc_mac,
14058                 (void *)&cmd_macsec_sc_pi,
14059                 NULL,
14060         },
14061 };
14062
14063 /* Common result structure for MACsec secure connection configure */
14064 struct cmd_macsec_sa_result {
14065         cmdline_fixed_string_t set;
14066         cmdline_fixed_string_t macsec;
14067         cmdline_fixed_string_t sa;
14068         cmdline_fixed_string_t tx_rx;
14069         portid_t port_id;
14070         uint8_t idx;
14071         uint8_t an;
14072         uint32_t pn;
14073         cmdline_fixed_string_t key;
14074 };
14075
14076 /* Common CLI fields for MACsec secure connection configure */
14077 cmdline_parse_token_string_t cmd_macsec_sa_set =
14078         TOKEN_STRING_INITIALIZER
14079                 (struct cmd_macsec_sa_result,
14080                  set, "set");
14081 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14082         TOKEN_STRING_INITIALIZER
14083                 (struct cmd_macsec_sa_result,
14084                  macsec, "macsec");
14085 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14086         TOKEN_STRING_INITIALIZER
14087                 (struct cmd_macsec_sa_result,
14088                  sa, "sa");
14089 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14090         TOKEN_STRING_INITIALIZER
14091                 (struct cmd_macsec_sa_result,
14092                  tx_rx, "tx#rx");
14093 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14094         TOKEN_NUM_INITIALIZER
14095                 (struct cmd_macsec_sa_result,
14096                  port_id, UINT16);
14097 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14098         TOKEN_NUM_INITIALIZER
14099                 (struct cmd_macsec_sa_result,
14100                  idx, UINT8);
14101 cmdline_parse_token_num_t cmd_macsec_sa_an =
14102         TOKEN_NUM_INITIALIZER
14103                 (struct cmd_macsec_sa_result,
14104                  an, UINT8);
14105 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14106         TOKEN_NUM_INITIALIZER
14107                 (struct cmd_macsec_sa_result,
14108                  pn, UINT32);
14109 cmdline_parse_token_string_t cmd_macsec_sa_key =
14110         TOKEN_STRING_INITIALIZER
14111                 (struct cmd_macsec_sa_result,
14112                  key, NULL);
14113
14114 static void
14115 cmd_set_macsec_sa_parsed(
14116         void *parsed_result,
14117         __attribute__((unused)) struct cmdline *cl,
14118         __attribute__((unused)) void *data)
14119 {
14120         struct cmd_macsec_sa_result *res = parsed_result;
14121         int ret = -ENOTSUP;
14122         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14123         uint8_t key[16] = { 0 };
14124         uint8_t xdgt0;
14125         uint8_t xdgt1;
14126         int key_len;
14127         int i;
14128
14129         key_len = strlen(res->key) / 2;
14130         if (key_len > 16)
14131                 key_len = 16;
14132
14133         for (i = 0; i < key_len; i++) {
14134                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14135                 if (xdgt0 == 0xFF)
14136                         return;
14137                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14138                 if (xdgt1 == 0xFF)
14139                         return;
14140                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14141         }
14142
14143 #ifdef RTE_LIBRTE_IXGBE_PMD
14144         ret = is_tx ?
14145                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14146                         res->idx, res->an, res->pn, key) :
14147                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14148                         res->idx, res->an, res->pn, key);
14149 #endif
14150         RTE_SET_USED(is_tx);
14151         RTE_SET_USED(key);
14152
14153         switch (ret) {
14154         case 0:
14155                 break;
14156         case -EINVAL:
14157                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14158                 break;
14159         case -ENODEV:
14160                 printf("invalid port_id %d\n", res->port_id);
14161                 break;
14162         case -ENOTSUP:
14163                 printf("not supported on port %d\n", res->port_id);
14164                 break;
14165         default:
14166                 printf("programming error: (%s)\n", strerror(-ret));
14167         }
14168 }
14169
14170 cmdline_parse_inst_t cmd_set_macsec_sa = {
14171         .f = cmd_set_macsec_sa_parsed,
14172         .data = NULL,
14173         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14174         .tokens = {
14175                 (void *)&cmd_macsec_sa_set,
14176                 (void *)&cmd_macsec_sa_macsec,
14177                 (void *)&cmd_macsec_sa_sa,
14178                 (void *)&cmd_macsec_sa_tx_rx,
14179                 (void *)&cmd_macsec_sa_port_id,
14180                 (void *)&cmd_macsec_sa_idx,
14181                 (void *)&cmd_macsec_sa_an,
14182                 (void *)&cmd_macsec_sa_pn,
14183                 (void *)&cmd_macsec_sa_key,
14184                 NULL,
14185         },
14186 };
14187
14188 /* VF unicast promiscuous mode configuration */
14189
14190 /* Common result structure for VF unicast promiscuous mode */
14191 struct cmd_vf_promisc_result {
14192         cmdline_fixed_string_t set;
14193         cmdline_fixed_string_t vf;
14194         cmdline_fixed_string_t promisc;
14195         portid_t port_id;
14196         uint32_t vf_id;
14197         cmdline_fixed_string_t on_off;
14198 };
14199
14200 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14201 cmdline_parse_token_string_t cmd_vf_promisc_set =
14202         TOKEN_STRING_INITIALIZER
14203                 (struct cmd_vf_promisc_result,
14204                  set, "set");
14205 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14206         TOKEN_STRING_INITIALIZER
14207                 (struct cmd_vf_promisc_result,
14208                  vf, "vf");
14209 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14210         TOKEN_STRING_INITIALIZER
14211                 (struct cmd_vf_promisc_result,
14212                  promisc, "promisc");
14213 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14214         TOKEN_NUM_INITIALIZER
14215                 (struct cmd_vf_promisc_result,
14216                  port_id, UINT16);
14217 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14218         TOKEN_NUM_INITIALIZER
14219                 (struct cmd_vf_promisc_result,
14220                  vf_id, UINT32);
14221 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14222         TOKEN_STRING_INITIALIZER
14223                 (struct cmd_vf_promisc_result,
14224                  on_off, "on#off");
14225
14226 static void
14227 cmd_set_vf_promisc_parsed(
14228         void *parsed_result,
14229         __attribute__((unused)) struct cmdline *cl,
14230         __attribute__((unused)) void *data)
14231 {
14232         struct cmd_vf_promisc_result *res = parsed_result;
14233         int ret = -ENOTSUP;
14234
14235         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14236
14237         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14238                 return;
14239
14240 #ifdef RTE_LIBRTE_I40E_PMD
14241         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14242                                                   res->vf_id, is_on);
14243 #endif
14244
14245         switch (ret) {
14246         case 0:
14247                 break;
14248         case -EINVAL:
14249                 printf("invalid vf_id %d\n", res->vf_id);
14250                 break;
14251         case -ENODEV:
14252                 printf("invalid port_id %d\n", res->port_id);
14253                 break;
14254         case -ENOTSUP:
14255                 printf("function not implemented\n");
14256                 break;
14257         default:
14258                 printf("programming error: (%s)\n", strerror(-ret));
14259         }
14260 }
14261
14262 cmdline_parse_inst_t cmd_set_vf_promisc = {
14263         .f = cmd_set_vf_promisc_parsed,
14264         .data = NULL,
14265         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14266                 "Set unicast promiscuous mode for a VF from the PF",
14267         .tokens = {
14268                 (void *)&cmd_vf_promisc_set,
14269                 (void *)&cmd_vf_promisc_vf,
14270                 (void *)&cmd_vf_promisc_promisc,
14271                 (void *)&cmd_vf_promisc_port_id,
14272                 (void *)&cmd_vf_promisc_vf_id,
14273                 (void *)&cmd_vf_promisc_on_off,
14274                 NULL,
14275         },
14276 };
14277
14278 /* VF multicast promiscuous mode configuration */
14279
14280 /* Common result structure for VF multicast promiscuous mode */
14281 struct cmd_vf_allmulti_result {
14282         cmdline_fixed_string_t set;
14283         cmdline_fixed_string_t vf;
14284         cmdline_fixed_string_t allmulti;
14285         portid_t port_id;
14286         uint32_t vf_id;
14287         cmdline_fixed_string_t on_off;
14288 };
14289
14290 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14291 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14292         TOKEN_STRING_INITIALIZER
14293                 (struct cmd_vf_allmulti_result,
14294                  set, "set");
14295 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14296         TOKEN_STRING_INITIALIZER
14297                 (struct cmd_vf_allmulti_result,
14298                  vf, "vf");
14299 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14300         TOKEN_STRING_INITIALIZER
14301                 (struct cmd_vf_allmulti_result,
14302                  allmulti, "allmulti");
14303 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14304         TOKEN_NUM_INITIALIZER
14305                 (struct cmd_vf_allmulti_result,
14306                  port_id, UINT16);
14307 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14308         TOKEN_NUM_INITIALIZER
14309                 (struct cmd_vf_allmulti_result,
14310                  vf_id, UINT32);
14311 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14312         TOKEN_STRING_INITIALIZER
14313                 (struct cmd_vf_allmulti_result,
14314                  on_off, "on#off");
14315
14316 static void
14317 cmd_set_vf_allmulti_parsed(
14318         void *parsed_result,
14319         __attribute__((unused)) struct cmdline *cl,
14320         __attribute__((unused)) void *data)
14321 {
14322         struct cmd_vf_allmulti_result *res = parsed_result;
14323         int ret = -ENOTSUP;
14324
14325         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14326
14327         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14328                 return;
14329
14330 #ifdef RTE_LIBRTE_I40E_PMD
14331         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14332                                                     res->vf_id, is_on);
14333 #endif
14334
14335         switch (ret) {
14336         case 0:
14337                 break;
14338         case -EINVAL:
14339                 printf("invalid vf_id %d\n", res->vf_id);
14340                 break;
14341         case -ENODEV:
14342                 printf("invalid port_id %d\n", res->port_id);
14343                 break;
14344         case -ENOTSUP:
14345                 printf("function not implemented\n");
14346                 break;
14347         default:
14348                 printf("programming error: (%s)\n", strerror(-ret));
14349         }
14350 }
14351
14352 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14353         .f = cmd_set_vf_allmulti_parsed,
14354         .data = NULL,
14355         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14356                 "Set multicast promiscuous mode for a VF from the PF",
14357         .tokens = {
14358                 (void *)&cmd_vf_allmulti_set,
14359                 (void *)&cmd_vf_allmulti_vf,
14360                 (void *)&cmd_vf_allmulti_allmulti,
14361                 (void *)&cmd_vf_allmulti_port_id,
14362                 (void *)&cmd_vf_allmulti_vf_id,
14363                 (void *)&cmd_vf_allmulti_on_off,
14364                 NULL,
14365         },
14366 };
14367
14368 /* vf broadcast mode configuration */
14369
14370 /* Common result structure for vf broadcast */
14371 struct cmd_set_vf_broadcast_result {
14372         cmdline_fixed_string_t set;
14373         cmdline_fixed_string_t vf;
14374         cmdline_fixed_string_t broadcast;
14375         portid_t port_id;
14376         uint16_t vf_id;
14377         cmdline_fixed_string_t on_off;
14378 };
14379
14380 /* Common CLI fields for vf broadcast enable disable */
14381 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14382         TOKEN_STRING_INITIALIZER
14383                 (struct cmd_set_vf_broadcast_result,
14384                  set, "set");
14385 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14386         TOKEN_STRING_INITIALIZER
14387                 (struct cmd_set_vf_broadcast_result,
14388                  vf, "vf");
14389 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14390         TOKEN_STRING_INITIALIZER
14391                 (struct cmd_set_vf_broadcast_result,
14392                  broadcast, "broadcast");
14393 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14394         TOKEN_NUM_INITIALIZER
14395                 (struct cmd_set_vf_broadcast_result,
14396                  port_id, UINT16);
14397 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14398         TOKEN_NUM_INITIALIZER
14399                 (struct cmd_set_vf_broadcast_result,
14400                  vf_id, UINT16);
14401 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14402         TOKEN_STRING_INITIALIZER
14403                 (struct cmd_set_vf_broadcast_result,
14404                  on_off, "on#off");
14405
14406 static void
14407 cmd_set_vf_broadcast_parsed(
14408         void *parsed_result,
14409         __attribute__((unused)) struct cmdline *cl,
14410         __attribute__((unused)) void *data)
14411 {
14412         struct cmd_set_vf_broadcast_result *res = parsed_result;
14413         int ret = -ENOTSUP;
14414
14415         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14416
14417         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14418                 return;
14419
14420 #ifdef RTE_LIBRTE_I40E_PMD
14421         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14422                                             res->vf_id, is_on);
14423 #endif
14424
14425         switch (ret) {
14426         case 0:
14427                 break;
14428         case -EINVAL:
14429                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14430                 break;
14431         case -ENODEV:
14432                 printf("invalid port_id %d\n", res->port_id);
14433                 break;
14434         case -ENOTSUP:
14435                 printf("function not implemented\n");
14436                 break;
14437         default:
14438                 printf("programming error: (%s)\n", strerror(-ret));
14439         }
14440 }
14441
14442 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14443         .f = cmd_set_vf_broadcast_parsed,
14444         .data = NULL,
14445         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14446         .tokens = {
14447                 (void *)&cmd_set_vf_broadcast_set,
14448                 (void *)&cmd_set_vf_broadcast_vf,
14449                 (void *)&cmd_set_vf_broadcast_broadcast,
14450                 (void *)&cmd_set_vf_broadcast_port_id,
14451                 (void *)&cmd_set_vf_broadcast_vf_id,
14452                 (void *)&cmd_set_vf_broadcast_on_off,
14453                 NULL,
14454         },
14455 };
14456
14457 /* vf vlan tag configuration */
14458
14459 /* Common result structure for vf vlan tag */
14460 struct cmd_set_vf_vlan_tag_result {
14461         cmdline_fixed_string_t set;
14462         cmdline_fixed_string_t vf;
14463         cmdline_fixed_string_t vlan;
14464         cmdline_fixed_string_t tag;
14465         portid_t port_id;
14466         uint16_t vf_id;
14467         cmdline_fixed_string_t on_off;
14468 };
14469
14470 /* Common CLI fields for vf vlan tag enable disable */
14471 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14472         TOKEN_STRING_INITIALIZER
14473                 (struct cmd_set_vf_vlan_tag_result,
14474                  set, "set");
14475 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14476         TOKEN_STRING_INITIALIZER
14477                 (struct cmd_set_vf_vlan_tag_result,
14478                  vf, "vf");
14479 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14480         TOKEN_STRING_INITIALIZER
14481                 (struct cmd_set_vf_vlan_tag_result,
14482                  vlan, "vlan");
14483 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14484         TOKEN_STRING_INITIALIZER
14485                 (struct cmd_set_vf_vlan_tag_result,
14486                  tag, "tag");
14487 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14488         TOKEN_NUM_INITIALIZER
14489                 (struct cmd_set_vf_vlan_tag_result,
14490                  port_id, UINT16);
14491 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14492         TOKEN_NUM_INITIALIZER
14493                 (struct cmd_set_vf_vlan_tag_result,
14494                  vf_id, UINT16);
14495 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14496         TOKEN_STRING_INITIALIZER
14497                 (struct cmd_set_vf_vlan_tag_result,
14498                  on_off, "on#off");
14499
14500 static void
14501 cmd_set_vf_vlan_tag_parsed(
14502         void *parsed_result,
14503         __attribute__((unused)) struct cmdline *cl,
14504         __attribute__((unused)) void *data)
14505 {
14506         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14507         int ret = -ENOTSUP;
14508
14509         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14510
14511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14512                 return;
14513
14514 #ifdef RTE_LIBRTE_I40E_PMD
14515         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14516                                            res->vf_id, is_on);
14517 #endif
14518
14519         switch (ret) {
14520         case 0:
14521                 break;
14522         case -EINVAL:
14523                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14524                 break;
14525         case -ENODEV:
14526                 printf("invalid port_id %d\n", res->port_id);
14527                 break;
14528         case -ENOTSUP:
14529                 printf("function not implemented\n");
14530                 break;
14531         default:
14532                 printf("programming error: (%s)\n", strerror(-ret));
14533         }
14534 }
14535
14536 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14537         .f = cmd_set_vf_vlan_tag_parsed,
14538         .data = NULL,
14539         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14540         .tokens = {
14541                 (void *)&cmd_set_vf_vlan_tag_set,
14542                 (void *)&cmd_set_vf_vlan_tag_vf,
14543                 (void *)&cmd_set_vf_vlan_tag_vlan,
14544                 (void *)&cmd_set_vf_vlan_tag_tag,
14545                 (void *)&cmd_set_vf_vlan_tag_port_id,
14546                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14547                 (void *)&cmd_set_vf_vlan_tag_on_off,
14548                 NULL,
14549         },
14550 };
14551
14552 /* Common definition of VF and TC TX bandwidth configuration */
14553 struct cmd_vf_tc_bw_result {
14554         cmdline_fixed_string_t set;
14555         cmdline_fixed_string_t vf;
14556         cmdline_fixed_string_t tc;
14557         cmdline_fixed_string_t tx;
14558         cmdline_fixed_string_t min_bw;
14559         cmdline_fixed_string_t max_bw;
14560         cmdline_fixed_string_t strict_link_prio;
14561         portid_t port_id;
14562         uint16_t vf_id;
14563         uint8_t tc_no;
14564         uint32_t bw;
14565         cmdline_fixed_string_t bw_list;
14566         uint8_t tc_map;
14567 };
14568
14569 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14570         TOKEN_STRING_INITIALIZER
14571                 (struct cmd_vf_tc_bw_result,
14572                  set, "set");
14573 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14574         TOKEN_STRING_INITIALIZER
14575                 (struct cmd_vf_tc_bw_result,
14576                  vf, "vf");
14577 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14578         TOKEN_STRING_INITIALIZER
14579                 (struct cmd_vf_tc_bw_result,
14580                  tc, "tc");
14581 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14582         TOKEN_STRING_INITIALIZER
14583                 (struct cmd_vf_tc_bw_result,
14584                  tx, "tx");
14585 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14586         TOKEN_STRING_INITIALIZER
14587                 (struct cmd_vf_tc_bw_result,
14588                  strict_link_prio, "strict-link-priority");
14589 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14590         TOKEN_STRING_INITIALIZER
14591                 (struct cmd_vf_tc_bw_result,
14592                  min_bw, "min-bandwidth");
14593 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14594         TOKEN_STRING_INITIALIZER
14595                 (struct cmd_vf_tc_bw_result,
14596                  max_bw, "max-bandwidth");
14597 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14598         TOKEN_NUM_INITIALIZER
14599                 (struct cmd_vf_tc_bw_result,
14600                  port_id, UINT16);
14601 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14602         TOKEN_NUM_INITIALIZER
14603                 (struct cmd_vf_tc_bw_result,
14604                  vf_id, UINT16);
14605 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14606         TOKEN_NUM_INITIALIZER
14607                 (struct cmd_vf_tc_bw_result,
14608                  tc_no, UINT8);
14609 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14610         TOKEN_NUM_INITIALIZER
14611                 (struct cmd_vf_tc_bw_result,
14612                  bw, UINT32);
14613 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14614         TOKEN_STRING_INITIALIZER
14615                 (struct cmd_vf_tc_bw_result,
14616                  bw_list, NULL);
14617 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14618         TOKEN_NUM_INITIALIZER
14619                 (struct cmd_vf_tc_bw_result,
14620                  tc_map, UINT8);
14621
14622 /* VF max bandwidth setting */
14623 static void
14624 cmd_vf_max_bw_parsed(
14625         void *parsed_result,
14626         __attribute__((unused)) struct cmdline *cl,
14627         __attribute__((unused)) void *data)
14628 {
14629         struct cmd_vf_tc_bw_result *res = parsed_result;
14630         int ret = -ENOTSUP;
14631
14632         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14633                 return;
14634
14635 #ifdef RTE_LIBRTE_I40E_PMD
14636         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14637                                          res->vf_id, res->bw);
14638 #endif
14639
14640         switch (ret) {
14641         case 0:
14642                 break;
14643         case -EINVAL:
14644                 printf("invalid vf_id %d or bandwidth %d\n",
14645                        res->vf_id, res->bw);
14646                 break;
14647         case -ENODEV:
14648                 printf("invalid port_id %d\n", res->port_id);
14649                 break;
14650         case -ENOTSUP:
14651                 printf("function not implemented\n");
14652                 break;
14653         default:
14654                 printf("programming error: (%s)\n", strerror(-ret));
14655         }
14656 }
14657
14658 cmdline_parse_inst_t cmd_vf_max_bw = {
14659         .f = cmd_vf_max_bw_parsed,
14660         .data = NULL,
14661         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14662         .tokens = {
14663                 (void *)&cmd_vf_tc_bw_set,
14664                 (void *)&cmd_vf_tc_bw_vf,
14665                 (void *)&cmd_vf_tc_bw_tx,
14666                 (void *)&cmd_vf_tc_bw_max_bw,
14667                 (void *)&cmd_vf_tc_bw_port_id,
14668                 (void *)&cmd_vf_tc_bw_vf_id,
14669                 (void *)&cmd_vf_tc_bw_bw,
14670                 NULL,
14671         },
14672 };
14673
14674 static int
14675 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14676                            uint8_t *tc_num,
14677                            char *str)
14678 {
14679         uint32_t size;
14680         const char *p, *p0 = str;
14681         char s[256];
14682         char *end;
14683         char *str_fld[16];
14684         uint16_t i;
14685         int ret;
14686
14687         p = strchr(p0, '(');
14688         if (p == NULL) {
14689                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14690                 return -1;
14691         }
14692         p++;
14693         p0 = strchr(p, ')');
14694         if (p0 == NULL) {
14695                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14696                 return -1;
14697         }
14698         size = p0 - p;
14699         if (size >= sizeof(s)) {
14700                 printf("The string size exceeds the internal buffer size\n");
14701                 return -1;
14702         }
14703         snprintf(s, sizeof(s), "%.*s", size, p);
14704         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14705         if (ret <= 0) {
14706                 printf("Failed to get the bandwidth list. ");
14707                 return -1;
14708         }
14709         *tc_num = ret;
14710         for (i = 0; i < ret; i++)
14711                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14712
14713         return 0;
14714 }
14715
14716 /* TC min bandwidth setting */
14717 static void
14718 cmd_vf_tc_min_bw_parsed(
14719         void *parsed_result,
14720         __attribute__((unused)) struct cmdline *cl,
14721         __attribute__((unused)) void *data)
14722 {
14723         struct cmd_vf_tc_bw_result *res = parsed_result;
14724         uint8_t tc_num;
14725         uint8_t bw[16];
14726         int ret = -ENOTSUP;
14727
14728         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14729                 return;
14730
14731         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14732         if (ret)
14733                 return;
14734
14735 #ifdef RTE_LIBRTE_I40E_PMD
14736         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14737                                               tc_num, bw);
14738 #endif
14739
14740         switch (ret) {
14741         case 0:
14742                 break;
14743         case -EINVAL:
14744                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14745                 break;
14746         case -ENODEV:
14747                 printf("invalid port_id %d\n", res->port_id);
14748                 break;
14749         case -ENOTSUP:
14750                 printf("function not implemented\n");
14751                 break;
14752         default:
14753                 printf("programming error: (%s)\n", strerror(-ret));
14754         }
14755 }
14756
14757 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14758         .f = cmd_vf_tc_min_bw_parsed,
14759         .data = NULL,
14760         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14761                     " <bw1, bw2, ...>",
14762         .tokens = {
14763                 (void *)&cmd_vf_tc_bw_set,
14764                 (void *)&cmd_vf_tc_bw_vf,
14765                 (void *)&cmd_vf_tc_bw_tc,
14766                 (void *)&cmd_vf_tc_bw_tx,
14767                 (void *)&cmd_vf_tc_bw_min_bw,
14768                 (void *)&cmd_vf_tc_bw_port_id,
14769                 (void *)&cmd_vf_tc_bw_vf_id,
14770                 (void *)&cmd_vf_tc_bw_bw_list,
14771                 NULL,
14772         },
14773 };
14774
14775 static void
14776 cmd_tc_min_bw_parsed(
14777         void *parsed_result,
14778         __attribute__((unused)) struct cmdline *cl,
14779         __attribute__((unused)) void *data)
14780 {
14781         struct cmd_vf_tc_bw_result *res = parsed_result;
14782         struct rte_port *port;
14783         uint8_t tc_num;
14784         uint8_t bw[16];
14785         int ret = -ENOTSUP;
14786
14787         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14788                 return;
14789
14790         port = &ports[res->port_id];
14791         /** Check if the port is not started **/
14792         if (port->port_status != RTE_PORT_STOPPED) {
14793                 printf("Please stop port %d first\n", res->port_id);
14794                 return;
14795         }
14796
14797         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14798         if (ret)
14799                 return;
14800
14801 #ifdef RTE_LIBRTE_IXGBE_PMD
14802         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14803 #endif
14804
14805         switch (ret) {
14806         case 0:
14807                 break;
14808         case -EINVAL:
14809                 printf("invalid bandwidth\n");
14810                 break;
14811         case -ENODEV:
14812                 printf("invalid port_id %d\n", res->port_id);
14813                 break;
14814         case -ENOTSUP:
14815                 printf("function not implemented\n");
14816                 break;
14817         default:
14818                 printf("programming error: (%s)\n", strerror(-ret));
14819         }
14820 }
14821
14822 cmdline_parse_inst_t cmd_tc_min_bw = {
14823         .f = cmd_tc_min_bw_parsed,
14824         .data = NULL,
14825         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14826         .tokens = {
14827                 (void *)&cmd_vf_tc_bw_set,
14828                 (void *)&cmd_vf_tc_bw_tc,
14829                 (void *)&cmd_vf_tc_bw_tx,
14830                 (void *)&cmd_vf_tc_bw_min_bw,
14831                 (void *)&cmd_vf_tc_bw_port_id,
14832                 (void *)&cmd_vf_tc_bw_bw_list,
14833                 NULL,
14834         },
14835 };
14836
14837 /* TC max bandwidth setting */
14838 static void
14839 cmd_vf_tc_max_bw_parsed(
14840         void *parsed_result,
14841         __attribute__((unused)) struct cmdline *cl,
14842         __attribute__((unused)) void *data)
14843 {
14844         struct cmd_vf_tc_bw_result *res = parsed_result;
14845         int ret = -ENOTSUP;
14846
14847         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14848                 return;
14849
14850 #ifdef RTE_LIBRTE_I40E_PMD
14851         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14852                                             res->tc_no, res->bw);
14853 #endif
14854
14855         switch (ret) {
14856         case 0:
14857                 break;
14858         case -EINVAL:
14859                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14860                        res->vf_id, res->tc_no, res->bw);
14861                 break;
14862         case -ENODEV:
14863                 printf("invalid port_id %d\n", res->port_id);
14864                 break;
14865         case -ENOTSUP:
14866                 printf("function not implemented\n");
14867                 break;
14868         default:
14869                 printf("programming error: (%s)\n", strerror(-ret));
14870         }
14871 }
14872
14873 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14874         .f = cmd_vf_tc_max_bw_parsed,
14875         .data = NULL,
14876         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14877                     " <bandwidth>",
14878         .tokens = {
14879                 (void *)&cmd_vf_tc_bw_set,
14880                 (void *)&cmd_vf_tc_bw_vf,
14881                 (void *)&cmd_vf_tc_bw_tc,
14882                 (void *)&cmd_vf_tc_bw_tx,
14883                 (void *)&cmd_vf_tc_bw_max_bw,
14884                 (void *)&cmd_vf_tc_bw_port_id,
14885                 (void *)&cmd_vf_tc_bw_vf_id,
14886                 (void *)&cmd_vf_tc_bw_tc_no,
14887                 (void *)&cmd_vf_tc_bw_bw,
14888                 NULL,
14889         },
14890 };
14891
14892
14893 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14894
14895 /* *** Set Port default Traffic Management Hierarchy *** */
14896 struct cmd_set_port_tm_hierarchy_default_result {
14897         cmdline_fixed_string_t set;
14898         cmdline_fixed_string_t port;
14899         cmdline_fixed_string_t tm;
14900         cmdline_fixed_string_t hierarchy;
14901         cmdline_fixed_string_t def;
14902         portid_t port_id;
14903 };
14904
14905 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14906         TOKEN_STRING_INITIALIZER(
14907                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14908 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14909         TOKEN_STRING_INITIALIZER(
14910                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14911 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14912         TOKEN_STRING_INITIALIZER(
14913                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14914 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14915         TOKEN_STRING_INITIALIZER(
14916                 struct cmd_set_port_tm_hierarchy_default_result,
14917                         hierarchy, "hierarchy");
14918 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14919         TOKEN_STRING_INITIALIZER(
14920                 struct cmd_set_port_tm_hierarchy_default_result,
14921                         def, "default");
14922 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14923         TOKEN_NUM_INITIALIZER(
14924                 struct cmd_set_port_tm_hierarchy_default_result,
14925                         port_id, UINT16);
14926
14927 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14928         __attribute__((unused)) struct cmdline *cl,
14929         __attribute__((unused)) void *data)
14930 {
14931         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14932         struct rte_port *p;
14933         portid_t port_id = res->port_id;
14934
14935         if (port_id_is_invalid(port_id, ENABLED_WARN))
14936                 return;
14937
14938         p = &ports[port_id];
14939
14940         /* Forward mode: tm */
14941         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
14942                 printf("  softnicfwd mode not enabled(error)\n");
14943                 return;
14944         }
14945
14946         /* Set the default tm hierarchy */
14947         p->softport.default_tm_hierarchy_enable = 1;
14948 }
14949
14950 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14951         .f = cmd_set_port_tm_hierarchy_default_parsed,
14952         .data = NULL,
14953         .help_str = "set port tm hierarchy default <port_id>",
14954         .tokens = {
14955                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14956                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14957                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14958                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14959                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14960                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14961                 NULL,
14962         },
14963 };
14964 #endif
14965
14966 /** Set VXLAN encapsulation details */
14967 struct cmd_set_vxlan_result {
14968         cmdline_fixed_string_t set;
14969         cmdline_fixed_string_t vxlan;
14970         cmdline_fixed_string_t pos_token;
14971         cmdline_fixed_string_t ip_version;
14972         uint32_t vlan_present:1;
14973         uint32_t vni;
14974         uint16_t udp_src;
14975         uint16_t udp_dst;
14976         cmdline_ipaddr_t ip_src;
14977         cmdline_ipaddr_t ip_dst;
14978         uint16_t tci;
14979         struct ether_addr eth_src;
14980         struct ether_addr eth_dst;
14981 };
14982
14983 cmdline_parse_token_string_t cmd_set_vxlan_set =
14984         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
14985 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
14986         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
14987 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
14988         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14989                                  "vxlan-with-vlan");
14990 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
14991         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14992                                  "ip-version");
14993 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
14994         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
14995                                  "ipv4#ipv6");
14996 cmdline_parse_token_string_t cmd_set_vxlan_vni =
14997         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14998                                  "vni");
14999 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15000         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15001 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15002         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15003                                  "udp-src");
15004 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15005         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15006 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15007         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15008                                  "udp-dst");
15009 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15010         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15011 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15012         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15013                                  "ip-src");
15014 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15015         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15016 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15017         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15018                                  "ip-dst");
15019 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15020         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15021 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15022         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15023                                  "vlan-tci");
15024 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15025         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15026 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15027         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15028                                  "eth-src");
15029 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15030         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15031 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15032         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15033                                  "eth-dst");
15034 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15035         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15036
15037 static void cmd_set_vxlan_parsed(void *parsed_result,
15038         __attribute__((unused)) struct cmdline *cl,
15039         __attribute__((unused)) void *data)
15040 {
15041         struct cmd_set_vxlan_result *res = parsed_result;
15042         union {
15043                 uint32_t vxlan_id;
15044                 uint8_t vni[4];
15045         } id = {
15046                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15047         };
15048
15049         if (strcmp(res->vxlan, "vxlan") == 0)
15050                 vxlan_encap_conf.select_vlan = 0;
15051         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15052                 vxlan_encap_conf.select_vlan = 1;
15053         if (strcmp(res->ip_version, "ipv4") == 0)
15054                 vxlan_encap_conf.select_ipv4 = 1;
15055         else if (strcmp(res->ip_version, "ipv6") == 0)
15056                 vxlan_encap_conf.select_ipv4 = 0;
15057         else
15058                 return;
15059         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15060         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15061         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15062         if (vxlan_encap_conf.select_ipv4) {
15063                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15064                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15065         } else {
15066                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15067                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15068         }
15069         if (vxlan_encap_conf.select_vlan)
15070                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15071         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15072                    ETHER_ADDR_LEN);
15073         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15074                    ETHER_ADDR_LEN);
15075 }
15076
15077 cmdline_parse_inst_t cmd_set_vxlan = {
15078         .f = cmd_set_vxlan_parsed,
15079         .data = NULL,
15080         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15081                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15082                 " eth-src <eth-src> eth-dst <eth-dst>",
15083         .tokens = {
15084                 (void *)&cmd_set_vxlan_set,
15085                 (void *)&cmd_set_vxlan_vxlan,
15086                 (void *)&cmd_set_vxlan_ip_version,
15087                 (void *)&cmd_set_vxlan_ip_version_value,
15088                 (void *)&cmd_set_vxlan_vni,
15089                 (void *)&cmd_set_vxlan_vni_value,
15090                 (void *)&cmd_set_vxlan_udp_src,
15091                 (void *)&cmd_set_vxlan_udp_src_value,
15092                 (void *)&cmd_set_vxlan_udp_dst,
15093                 (void *)&cmd_set_vxlan_udp_dst_value,
15094                 (void *)&cmd_set_vxlan_ip_src,
15095                 (void *)&cmd_set_vxlan_ip_src_value,
15096                 (void *)&cmd_set_vxlan_ip_dst,
15097                 (void *)&cmd_set_vxlan_ip_dst_value,
15098                 (void *)&cmd_set_vxlan_eth_src,
15099                 (void *)&cmd_set_vxlan_eth_src_value,
15100                 (void *)&cmd_set_vxlan_eth_dst,
15101                 (void *)&cmd_set_vxlan_eth_dst_value,
15102                 NULL,
15103         },
15104 };
15105
15106 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15107         .f = cmd_set_vxlan_parsed,
15108         .data = NULL,
15109         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15110                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15111                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15112                 " <eth-dst>",
15113         .tokens = {
15114                 (void *)&cmd_set_vxlan_set,
15115                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15116                 (void *)&cmd_set_vxlan_ip_version,
15117                 (void *)&cmd_set_vxlan_ip_version_value,
15118                 (void *)&cmd_set_vxlan_vni,
15119                 (void *)&cmd_set_vxlan_vni_value,
15120                 (void *)&cmd_set_vxlan_udp_src,
15121                 (void *)&cmd_set_vxlan_udp_src_value,
15122                 (void *)&cmd_set_vxlan_udp_dst,
15123                 (void *)&cmd_set_vxlan_udp_dst_value,
15124                 (void *)&cmd_set_vxlan_ip_src,
15125                 (void *)&cmd_set_vxlan_ip_src_value,
15126                 (void *)&cmd_set_vxlan_ip_dst,
15127                 (void *)&cmd_set_vxlan_ip_dst_value,
15128                 (void *)&cmd_set_vxlan_vlan,
15129                 (void *)&cmd_set_vxlan_vlan_value,
15130                 (void *)&cmd_set_vxlan_eth_src,
15131                 (void *)&cmd_set_vxlan_eth_src_value,
15132                 (void *)&cmd_set_vxlan_eth_dst,
15133                 (void *)&cmd_set_vxlan_eth_dst_value,
15134                 NULL,
15135         },
15136 };
15137
15138 /** Set NVGRE encapsulation details */
15139 struct cmd_set_nvgre_result {
15140         cmdline_fixed_string_t set;
15141         cmdline_fixed_string_t nvgre;
15142         cmdline_fixed_string_t pos_token;
15143         cmdline_fixed_string_t ip_version;
15144         uint32_t tni;
15145         cmdline_ipaddr_t ip_src;
15146         cmdline_ipaddr_t ip_dst;
15147         uint16_t tci;
15148         struct ether_addr eth_src;
15149         struct ether_addr eth_dst;
15150 };
15151
15152 cmdline_parse_token_string_t cmd_set_nvgre_set =
15153         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15154 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15155         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15156 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15157         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15158                                  "nvgre-with-vlan");
15159 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15160         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15161                                  "ip-version");
15162 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15163         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15164                                  "ipv4#ipv6");
15165 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15166         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15167                                  "tni");
15168 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15169         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15170 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15171         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15172                                  "ip-src");
15173 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15174         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15175 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15176         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15177                                  "ip-dst");
15178 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15179         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15180 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15181         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15182                                  "vlan-tci");
15183 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15184         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15185 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15186         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15187                                  "eth-src");
15188 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15189         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15190 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15191         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15192                                  "eth-dst");
15193 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15194         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15195
15196 static void cmd_set_nvgre_parsed(void *parsed_result,
15197         __attribute__((unused)) struct cmdline *cl,
15198         __attribute__((unused)) void *data)
15199 {
15200         struct cmd_set_nvgre_result *res = parsed_result;
15201         union {
15202                 uint32_t nvgre_tni;
15203                 uint8_t tni[4];
15204         } id = {
15205                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15206         };
15207
15208         if (strcmp(res->nvgre, "nvgre") == 0)
15209                 nvgre_encap_conf.select_vlan = 0;
15210         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15211                 nvgre_encap_conf.select_vlan = 1;
15212         if (strcmp(res->ip_version, "ipv4") == 0)
15213                 nvgre_encap_conf.select_ipv4 = 1;
15214         else if (strcmp(res->ip_version, "ipv6") == 0)
15215                 nvgre_encap_conf.select_ipv4 = 0;
15216         else
15217                 return;
15218         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15219         if (nvgre_encap_conf.select_ipv4) {
15220                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15221                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15222         } else {
15223                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15224                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15225         }
15226         if (nvgre_encap_conf.select_vlan)
15227                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15228         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15229                    ETHER_ADDR_LEN);
15230         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15231                    ETHER_ADDR_LEN);
15232 }
15233
15234 cmdline_parse_inst_t cmd_set_nvgre = {
15235         .f = cmd_set_nvgre_parsed,
15236         .data = NULL,
15237         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15238                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15239                 " eth-dst <eth-dst>",
15240         .tokens = {
15241                 (void *)&cmd_set_nvgre_set,
15242                 (void *)&cmd_set_nvgre_nvgre,
15243                 (void *)&cmd_set_nvgre_ip_version,
15244                 (void *)&cmd_set_nvgre_ip_version_value,
15245                 (void *)&cmd_set_nvgre_tni,
15246                 (void *)&cmd_set_nvgre_tni_value,
15247                 (void *)&cmd_set_nvgre_ip_src,
15248                 (void *)&cmd_set_nvgre_ip_src_value,
15249                 (void *)&cmd_set_nvgre_ip_dst,
15250                 (void *)&cmd_set_nvgre_ip_dst_value,
15251                 (void *)&cmd_set_nvgre_eth_src,
15252                 (void *)&cmd_set_nvgre_eth_src_value,
15253                 (void *)&cmd_set_nvgre_eth_dst,
15254                 (void *)&cmd_set_nvgre_eth_dst_value,
15255                 NULL,
15256         },
15257 };
15258
15259 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15260         .f = cmd_set_nvgre_parsed,
15261         .data = NULL,
15262         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15263                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15264                 " eth-src <eth-src> eth-dst <eth-dst>",
15265         .tokens = {
15266                 (void *)&cmd_set_nvgre_set,
15267                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15268                 (void *)&cmd_set_nvgre_ip_version,
15269                 (void *)&cmd_set_nvgre_ip_version_value,
15270                 (void *)&cmd_set_nvgre_tni,
15271                 (void *)&cmd_set_nvgre_tni_value,
15272                 (void *)&cmd_set_nvgre_ip_src,
15273                 (void *)&cmd_set_nvgre_ip_src_value,
15274                 (void *)&cmd_set_nvgre_ip_dst,
15275                 (void *)&cmd_set_nvgre_ip_dst_value,
15276                 (void *)&cmd_set_nvgre_vlan,
15277                 (void *)&cmd_set_nvgre_vlan_value,
15278                 (void *)&cmd_set_nvgre_eth_src,
15279                 (void *)&cmd_set_nvgre_eth_src_value,
15280                 (void *)&cmd_set_nvgre_eth_dst,
15281                 (void *)&cmd_set_nvgre_eth_dst_value,
15282                 NULL,
15283         },
15284 };
15285
15286 /* Strict link priority scheduling mode setting */
15287 static void
15288 cmd_strict_link_prio_parsed(
15289         void *parsed_result,
15290         __attribute__((unused)) struct cmdline *cl,
15291         __attribute__((unused)) void *data)
15292 {
15293         struct cmd_vf_tc_bw_result *res = parsed_result;
15294         int ret = -ENOTSUP;
15295
15296         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15297                 return;
15298
15299 #ifdef RTE_LIBRTE_I40E_PMD
15300         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15301 #endif
15302
15303         switch (ret) {
15304         case 0:
15305                 break;
15306         case -EINVAL:
15307                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15308                 break;
15309         case -ENODEV:
15310                 printf("invalid port_id %d\n", res->port_id);
15311                 break;
15312         case -ENOTSUP:
15313                 printf("function not implemented\n");
15314                 break;
15315         default:
15316                 printf("programming error: (%s)\n", strerror(-ret));
15317         }
15318 }
15319
15320 cmdline_parse_inst_t cmd_strict_link_prio = {
15321         .f = cmd_strict_link_prio_parsed,
15322         .data = NULL,
15323         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
15324         .tokens = {
15325                 (void *)&cmd_vf_tc_bw_set,
15326                 (void *)&cmd_vf_tc_bw_tx,
15327                 (void *)&cmd_vf_tc_bw_strict_link_prio,
15328                 (void *)&cmd_vf_tc_bw_port_id,
15329                 (void *)&cmd_vf_tc_bw_tc_map,
15330                 NULL,
15331         },
15332 };
15333
15334 /* Load dynamic device personalization*/
15335 struct cmd_ddp_add_result {
15336         cmdline_fixed_string_t ddp;
15337         cmdline_fixed_string_t add;
15338         portid_t port_id;
15339         char filepath[];
15340 };
15341
15342 cmdline_parse_token_string_t cmd_ddp_add_ddp =
15343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
15344 cmdline_parse_token_string_t cmd_ddp_add_add =
15345         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
15346 cmdline_parse_token_num_t cmd_ddp_add_port_id =
15347         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
15348 cmdline_parse_token_string_t cmd_ddp_add_filepath =
15349         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
15350
15351 static void
15352 cmd_ddp_add_parsed(
15353         void *parsed_result,
15354         __attribute__((unused)) struct cmdline *cl,
15355         __attribute__((unused)) void *data)
15356 {
15357         struct cmd_ddp_add_result *res = parsed_result;
15358         uint8_t *buff;
15359         uint32_t size;
15360         char *filepath;
15361         char *file_fld[2];
15362         int file_num;
15363         int ret = -ENOTSUP;
15364
15365         if (!all_ports_stopped()) {
15366                 printf("Please stop all ports first\n");
15367                 return;
15368         }
15369
15370         filepath = strdup(res->filepath);
15371         if (filepath == NULL) {
15372                 printf("Failed to allocate memory\n");
15373                 return;
15374         }
15375         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
15376
15377         buff = open_file(file_fld[0], &size);
15378         if (!buff) {
15379                 free((void *)filepath);
15380                 return;
15381         }
15382
15383 #ifdef RTE_LIBRTE_I40E_PMD
15384         if (ret == -ENOTSUP)
15385                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15386                                                buff, size,
15387                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
15388 #endif
15389
15390         if (ret == -EEXIST)
15391                 printf("Profile has already existed.\n");
15392         else if (ret < 0)
15393                 printf("Failed to load profile.\n");
15394         else if (file_num == 2)
15395                 save_file(file_fld[1], buff, size);
15396
15397         close_file(buff);
15398         free((void *)filepath);
15399 }
15400
15401 cmdline_parse_inst_t cmd_ddp_add = {
15402         .f = cmd_ddp_add_parsed,
15403         .data = NULL,
15404         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
15405         .tokens = {
15406                 (void *)&cmd_ddp_add_ddp,
15407                 (void *)&cmd_ddp_add_add,
15408                 (void *)&cmd_ddp_add_port_id,
15409                 (void *)&cmd_ddp_add_filepath,
15410                 NULL,
15411         },
15412 };
15413
15414 /* Delete dynamic device personalization*/
15415 struct cmd_ddp_del_result {
15416         cmdline_fixed_string_t ddp;
15417         cmdline_fixed_string_t del;
15418         portid_t port_id;
15419         char filepath[];
15420 };
15421
15422 cmdline_parse_token_string_t cmd_ddp_del_ddp =
15423         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
15424 cmdline_parse_token_string_t cmd_ddp_del_del =
15425         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
15426 cmdline_parse_token_num_t cmd_ddp_del_port_id =
15427         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
15428 cmdline_parse_token_string_t cmd_ddp_del_filepath =
15429         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
15430
15431 static void
15432 cmd_ddp_del_parsed(
15433         void *parsed_result,
15434         __attribute__((unused)) struct cmdline *cl,
15435         __attribute__((unused)) void *data)
15436 {
15437         struct cmd_ddp_del_result *res = parsed_result;
15438         uint8_t *buff;
15439         uint32_t size;
15440         int ret = -ENOTSUP;
15441
15442         if (!all_ports_stopped()) {
15443                 printf("Please stop all ports first\n");
15444                 return;
15445         }
15446
15447         buff = open_file(res->filepath, &size);
15448         if (!buff)
15449                 return;
15450
15451 #ifdef RTE_LIBRTE_I40E_PMD
15452         if (ret == -ENOTSUP)
15453                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15454                                                buff, size,
15455                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15456 #endif
15457
15458         if (ret == -EACCES)
15459                 printf("Profile does not exist.\n");
15460         else if (ret < 0)
15461                 printf("Failed to delete profile.\n");
15462
15463         close_file(buff);
15464 }
15465
15466 cmdline_parse_inst_t cmd_ddp_del = {
15467         .f = cmd_ddp_del_parsed,
15468         .data = NULL,
15469         .help_str = "ddp del <port_id> <backup_profile_path>",
15470         .tokens = {
15471                 (void *)&cmd_ddp_del_ddp,
15472                 (void *)&cmd_ddp_del_del,
15473                 (void *)&cmd_ddp_del_port_id,
15474                 (void *)&cmd_ddp_del_filepath,
15475                 NULL,
15476         },
15477 };
15478
15479 /* Get dynamic device personalization profile info */
15480 struct cmd_ddp_info_result {
15481         cmdline_fixed_string_t ddp;
15482         cmdline_fixed_string_t get;
15483         cmdline_fixed_string_t info;
15484         char filepath[];
15485 };
15486
15487 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15488         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15489 cmdline_parse_token_string_t cmd_ddp_info_get =
15490         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15491 cmdline_parse_token_string_t cmd_ddp_info_info =
15492         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15493 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15494         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15495
15496 static void
15497 cmd_ddp_info_parsed(
15498         void *parsed_result,
15499         __attribute__((unused)) struct cmdline *cl,
15500         __attribute__((unused)) void *data)
15501 {
15502         struct cmd_ddp_info_result *res = parsed_result;
15503         uint8_t *pkg;
15504         uint32_t pkg_size;
15505         int ret = -ENOTSUP;
15506 #ifdef RTE_LIBRTE_I40E_PMD
15507         uint32_t i, j, n;
15508         uint8_t *buff;
15509         uint32_t buff_size = 0;
15510         struct rte_pmd_i40e_profile_info info;
15511         uint32_t dev_num = 0;
15512         struct rte_pmd_i40e_ddp_device_id *devs;
15513         uint32_t proto_num = 0;
15514         struct rte_pmd_i40e_proto_info *proto = NULL;
15515         uint32_t pctype_num = 0;
15516         struct rte_pmd_i40e_ptype_info *pctype;
15517         uint32_t ptype_num = 0;
15518         struct rte_pmd_i40e_ptype_info *ptype;
15519         uint8_t proto_id;
15520
15521 #endif
15522
15523         pkg = open_file(res->filepath, &pkg_size);
15524         if (!pkg)
15525                 return;
15526
15527 #ifdef RTE_LIBRTE_I40E_PMD
15528         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15529                                 (uint8_t *)&info, sizeof(info),
15530                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15531         if (!ret) {
15532                 printf("Global Track id:       0x%x\n", info.track_id);
15533                 printf("Global Version:        %d.%d.%d.%d\n",
15534                         info.version.major,
15535                         info.version.minor,
15536                         info.version.update,
15537                         info.version.draft);
15538                 printf("Global Package name:   %s\n\n", info.name);
15539         }
15540
15541         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15542                                 (uint8_t *)&info, sizeof(info),
15543                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15544         if (!ret) {
15545                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15546                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15547                         info.version.major,
15548                         info.version.minor,
15549                         info.version.update,
15550                         info.version.draft);
15551                 printf("i40e Profile name:     %s\n\n", info.name);
15552         }
15553
15554         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15555                                 (uint8_t *)&buff_size, sizeof(buff_size),
15556                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15557         if (!ret && buff_size) {
15558                 buff = (uint8_t *)malloc(buff_size);
15559                 if (buff) {
15560                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15561                                                 buff, buff_size,
15562                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15563                         if (!ret)
15564                                 printf("Package Notes:\n%s\n\n", buff);
15565                         free(buff);
15566                 }
15567         }
15568
15569         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15570                                 (uint8_t *)&dev_num, sizeof(dev_num),
15571                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15572         if (!ret && dev_num) {
15573                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15574                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15575                 if (devs) {
15576                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15577                                                 (uint8_t *)devs, buff_size,
15578                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15579                         if (!ret) {
15580                                 printf("List of supported devices:\n");
15581                                 for (i = 0; i < dev_num; i++) {
15582                                         printf("  %04X:%04X %04X:%04X\n",
15583                                                 devs[i].vendor_dev_id >> 16,
15584                                                 devs[i].vendor_dev_id & 0xFFFF,
15585                                                 devs[i].sub_vendor_dev_id >> 16,
15586                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15587                                 }
15588                                 printf("\n");
15589                         }
15590                         free(devs);
15591                 }
15592         }
15593
15594         /* get information about protocols and packet types */
15595         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15596                 (uint8_t *)&proto_num, sizeof(proto_num),
15597                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15598         if (ret || !proto_num)
15599                 goto no_print_return;
15600
15601         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15602         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15603         if (!proto)
15604                 goto no_print_return;
15605
15606         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15607                                         buff_size,
15608                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15609         if (!ret) {
15610                 printf("List of used protocols:\n");
15611                 for (i = 0; i < proto_num; i++)
15612                         printf("  %2u: %s\n", proto[i].proto_id,
15613                                proto[i].name);
15614                 printf("\n");
15615         }
15616         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15617                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15618                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15619         if (ret || !pctype_num)
15620                 goto no_print_pctypes;
15621
15622         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15623         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15624         if (!pctype)
15625                 goto no_print_pctypes;
15626
15627         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15628                                         buff_size,
15629                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15630         if (ret) {
15631                 free(pctype);
15632                 goto no_print_pctypes;
15633         }
15634
15635         printf("List of defined packet classification types:\n");
15636         for (i = 0; i < pctype_num; i++) {
15637                 printf("  %2u:", pctype[i].ptype_id);
15638                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15639                         proto_id = pctype[i].protocols[j];
15640                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15641                                 for (n = 0; n < proto_num; n++) {
15642                                         if (proto[n].proto_id == proto_id) {
15643                                                 printf(" %s", proto[n].name);
15644                                                 break;
15645                                         }
15646                                 }
15647                         }
15648                 }
15649                 printf("\n");
15650         }
15651         printf("\n");
15652         free(pctype);
15653
15654 no_print_pctypes:
15655
15656         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15657                                         sizeof(ptype_num),
15658                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15659         if (ret || !ptype_num)
15660                 goto no_print_return;
15661
15662         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15663         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15664         if (!ptype)
15665                 goto no_print_return;
15666
15667         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15668                                         buff_size,
15669                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15670         if (ret) {
15671                 free(ptype);
15672                 goto no_print_return;
15673         }
15674         printf("List of defined packet types:\n");
15675         for (i = 0; i < ptype_num; i++) {
15676                 printf("  %2u:", ptype[i].ptype_id);
15677                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15678                         proto_id = ptype[i].protocols[j];
15679                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15680                                 for (n = 0; n < proto_num; n++) {
15681                                         if (proto[n].proto_id == proto_id) {
15682                                                 printf(" %s", proto[n].name);
15683                                                 break;
15684                                         }
15685                                 }
15686                         }
15687                 }
15688                 printf("\n");
15689         }
15690         free(ptype);
15691         printf("\n");
15692
15693         ret = 0;
15694 no_print_return:
15695         if (proto)
15696                 free(proto);
15697 #endif
15698         if (ret == -ENOTSUP)
15699                 printf("Function not supported in PMD driver\n");
15700         close_file(pkg);
15701 }
15702
15703 cmdline_parse_inst_t cmd_ddp_get_info = {
15704         .f = cmd_ddp_info_parsed,
15705         .data = NULL,
15706         .help_str = "ddp get info <profile_path>",
15707         .tokens = {
15708                 (void *)&cmd_ddp_info_ddp,
15709                 (void *)&cmd_ddp_info_get,
15710                 (void *)&cmd_ddp_info_info,
15711                 (void *)&cmd_ddp_info_filepath,
15712                 NULL,
15713         },
15714 };
15715
15716 /* Get dynamic device personalization profile info list*/
15717 #define PROFILE_INFO_SIZE 48
15718 #define MAX_PROFILE_NUM 16
15719
15720 struct cmd_ddp_get_list_result {
15721         cmdline_fixed_string_t ddp;
15722         cmdline_fixed_string_t get;
15723         cmdline_fixed_string_t list;
15724         portid_t port_id;
15725 };
15726
15727 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15728         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15729 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15730         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15731 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15732         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15733 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15734         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15735
15736 static void
15737 cmd_ddp_get_list_parsed(
15738         __attribute__((unused)) void *parsed_result,
15739         __attribute__((unused)) struct cmdline *cl,
15740         __attribute__((unused)) void *data)
15741 {
15742 #ifdef RTE_LIBRTE_I40E_PMD
15743         struct cmd_ddp_get_list_result *res = parsed_result;
15744         struct rte_pmd_i40e_profile_list *p_list;
15745         struct rte_pmd_i40e_profile_info *p_info;
15746         uint32_t p_num;
15747         uint32_t size;
15748         uint32_t i;
15749 #endif
15750         int ret = -ENOTSUP;
15751
15752 #ifdef RTE_LIBRTE_I40E_PMD
15753         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15754         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15755         if (!p_list)
15756                 printf("%s: Failed to malloc buffer\n", __func__);
15757
15758         if (ret == -ENOTSUP)
15759                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15760                                                 (uint8_t *)p_list, size);
15761
15762         if (!ret) {
15763                 p_num = p_list->p_count;
15764                 printf("Profile number is: %d\n\n", p_num);
15765
15766                 for (i = 0; i < p_num; i++) {
15767                         p_info = &p_list->p_info[i];
15768                         printf("Profile %d:\n", i);
15769                         printf("Track id:     0x%x\n", p_info->track_id);
15770                         printf("Version:      %d.%d.%d.%d\n",
15771                                p_info->version.major,
15772                                p_info->version.minor,
15773                                p_info->version.update,
15774                                p_info->version.draft);
15775                         printf("Profile name: %s\n\n", p_info->name);
15776                 }
15777         }
15778
15779         free(p_list);
15780 #endif
15781
15782         if (ret < 0)
15783                 printf("Failed to get ddp list\n");
15784 }
15785
15786 cmdline_parse_inst_t cmd_ddp_get_list = {
15787         .f = cmd_ddp_get_list_parsed,
15788         .data = NULL,
15789         .help_str = "ddp get list <port_id>",
15790         .tokens = {
15791                 (void *)&cmd_ddp_get_list_ddp,
15792                 (void *)&cmd_ddp_get_list_get,
15793                 (void *)&cmd_ddp_get_list_list,
15794                 (void *)&cmd_ddp_get_list_port_id,
15795                 NULL,
15796         },
15797 };
15798
15799 /* Configure input set */
15800 struct cmd_cfg_input_set_result {
15801         cmdline_fixed_string_t port;
15802         cmdline_fixed_string_t cfg;
15803         portid_t port_id;
15804         cmdline_fixed_string_t pctype;
15805         uint8_t pctype_id;
15806         cmdline_fixed_string_t inset_type;
15807         cmdline_fixed_string_t opt;
15808         cmdline_fixed_string_t field;
15809         uint8_t field_idx;
15810 };
15811
15812 static void
15813 cmd_cfg_input_set_parsed(
15814         __attribute__((unused)) void *parsed_result,
15815         __attribute__((unused)) struct cmdline *cl,
15816         __attribute__((unused)) void *data)
15817 {
15818 #ifdef RTE_LIBRTE_I40E_PMD
15819         struct cmd_cfg_input_set_result *res = parsed_result;
15820         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15821         struct rte_pmd_i40e_inset inset;
15822 #endif
15823         int ret = -ENOTSUP;
15824
15825         if (!all_ports_stopped()) {
15826                 printf("Please stop all ports first\n");
15827                 return;
15828         }
15829
15830 #ifdef RTE_LIBRTE_I40E_PMD
15831         if (!strcmp(res->inset_type, "hash_inset"))
15832                 inset_type = INSET_HASH;
15833         else if (!strcmp(res->inset_type, "fdir_inset"))
15834                 inset_type = INSET_FDIR;
15835         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15836                 inset_type = INSET_FDIR_FLX;
15837         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15838                                      &inset, inset_type);
15839         if (ret) {
15840                 printf("Failed to get input set.\n");
15841                 return;
15842         }
15843
15844         if (!strcmp(res->opt, "get")) {
15845                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15846                                                    res->field_idx);
15847                 if (ret)
15848                         printf("Field index %d is enabled.\n", res->field_idx);
15849                 else
15850                         printf("Field index %d is disabled.\n", res->field_idx);
15851                 return;
15852         } else if (!strcmp(res->opt, "set"))
15853                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15854                                                    res->field_idx);
15855         else if (!strcmp(res->opt, "clear"))
15856                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15857                                                      res->field_idx);
15858         if (ret) {
15859                 printf("Failed to configure input set field.\n");
15860                 return;
15861         }
15862
15863         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15864                                      &inset, inset_type);
15865         if (ret) {
15866                 printf("Failed to set input set.\n");
15867                 return;
15868         }
15869 #endif
15870
15871         if (ret == -ENOTSUP)
15872                 printf("Function not supported\n");
15873 }
15874
15875 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15876         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15877                                  port, "port");
15878 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15879         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15880                                  cfg, "config");
15881 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15882         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15883                               port_id, UINT16);
15884 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15885         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15886                                  pctype, "pctype");
15887 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15888         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15889                               pctype_id, UINT8);
15890 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15891         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15892                                  inset_type,
15893                                  "hash_inset#fdir_inset#fdir_flx_inset");
15894 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15895         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15896                                  opt, "get#set#clear");
15897 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15898         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15899                                  field, "field");
15900 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15901         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15902                               field_idx, UINT8);
15903
15904 cmdline_parse_inst_t cmd_cfg_input_set = {
15905         .f = cmd_cfg_input_set_parsed,
15906         .data = NULL,
15907         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15908                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15909         .tokens = {
15910                 (void *)&cmd_cfg_input_set_port,
15911                 (void *)&cmd_cfg_input_set_cfg,
15912                 (void *)&cmd_cfg_input_set_port_id,
15913                 (void *)&cmd_cfg_input_set_pctype,
15914                 (void *)&cmd_cfg_input_set_pctype_id,
15915                 (void *)&cmd_cfg_input_set_inset_type,
15916                 (void *)&cmd_cfg_input_set_opt,
15917                 (void *)&cmd_cfg_input_set_field,
15918                 (void *)&cmd_cfg_input_set_field_idx,
15919                 NULL,
15920         },
15921 };
15922
15923 /* Clear input set */
15924 struct cmd_clear_input_set_result {
15925         cmdline_fixed_string_t port;
15926         cmdline_fixed_string_t cfg;
15927         portid_t port_id;
15928         cmdline_fixed_string_t pctype;
15929         uint8_t pctype_id;
15930         cmdline_fixed_string_t inset_type;
15931         cmdline_fixed_string_t clear;
15932         cmdline_fixed_string_t all;
15933 };
15934
15935 static void
15936 cmd_clear_input_set_parsed(
15937         __attribute__((unused)) void *parsed_result,
15938         __attribute__((unused)) struct cmdline *cl,
15939         __attribute__((unused)) void *data)
15940 {
15941 #ifdef RTE_LIBRTE_I40E_PMD
15942         struct cmd_clear_input_set_result *res = parsed_result;
15943         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15944         struct rte_pmd_i40e_inset inset;
15945 #endif
15946         int ret = -ENOTSUP;
15947
15948         if (!all_ports_stopped()) {
15949                 printf("Please stop all ports first\n");
15950                 return;
15951         }
15952
15953 #ifdef RTE_LIBRTE_I40E_PMD
15954         if (!strcmp(res->inset_type, "hash_inset"))
15955                 inset_type = INSET_HASH;
15956         else if (!strcmp(res->inset_type, "fdir_inset"))
15957                 inset_type = INSET_FDIR;
15958         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15959                 inset_type = INSET_FDIR_FLX;
15960
15961         memset(&inset, 0, sizeof(inset));
15962
15963         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15964                                      &inset, inset_type);
15965         if (ret) {
15966                 printf("Failed to clear input set.\n");
15967                 return;
15968         }
15969
15970 #endif
15971
15972         if (ret == -ENOTSUP)
15973                 printf("Function not supported\n");
15974 }
15975
15976 cmdline_parse_token_string_t cmd_clear_input_set_port =
15977         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15978                                  port, "port");
15979 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15980         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15981                                  cfg, "config");
15982 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15983         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15984                               port_id, UINT16);
15985 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15986         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15987                                  pctype, "pctype");
15988 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15989         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15990                               pctype_id, UINT8);
15991 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15992         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15993                                  inset_type,
15994                                  "hash_inset#fdir_inset#fdir_flx_inset");
15995 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15996         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15997                                  clear, "clear");
15998 cmdline_parse_token_string_t cmd_clear_input_set_all =
15999         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16000                                  all, "all");
16001
16002 cmdline_parse_inst_t cmd_clear_input_set = {
16003         .f = cmd_clear_input_set_parsed,
16004         .data = NULL,
16005         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16006                     "fdir_inset|fdir_flx_inset clear all",
16007         .tokens = {
16008                 (void *)&cmd_clear_input_set_port,
16009                 (void *)&cmd_clear_input_set_cfg,
16010                 (void *)&cmd_clear_input_set_port_id,
16011                 (void *)&cmd_clear_input_set_pctype,
16012                 (void *)&cmd_clear_input_set_pctype_id,
16013                 (void *)&cmd_clear_input_set_inset_type,
16014                 (void *)&cmd_clear_input_set_clear,
16015                 (void *)&cmd_clear_input_set_all,
16016                 NULL,
16017         },
16018 };
16019
16020 /* show vf stats */
16021
16022 /* Common result structure for show vf stats */
16023 struct cmd_show_vf_stats_result {
16024         cmdline_fixed_string_t show;
16025         cmdline_fixed_string_t vf;
16026         cmdline_fixed_string_t stats;
16027         portid_t port_id;
16028         uint16_t vf_id;
16029 };
16030
16031 /* Common CLI fields show vf stats*/
16032 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16033         TOKEN_STRING_INITIALIZER
16034                 (struct cmd_show_vf_stats_result,
16035                  show, "show");
16036 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16037         TOKEN_STRING_INITIALIZER
16038                 (struct cmd_show_vf_stats_result,
16039                  vf, "vf");
16040 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16041         TOKEN_STRING_INITIALIZER
16042                 (struct cmd_show_vf_stats_result,
16043                  stats, "stats");
16044 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16045         TOKEN_NUM_INITIALIZER
16046                 (struct cmd_show_vf_stats_result,
16047                  port_id, UINT16);
16048 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16049         TOKEN_NUM_INITIALIZER
16050                 (struct cmd_show_vf_stats_result,
16051                  vf_id, UINT16);
16052
16053 static void
16054 cmd_show_vf_stats_parsed(
16055         void *parsed_result,
16056         __attribute__((unused)) struct cmdline *cl,
16057         __attribute__((unused)) void *data)
16058 {
16059         struct cmd_show_vf_stats_result *res = parsed_result;
16060         struct rte_eth_stats stats;
16061         int ret = -ENOTSUP;
16062         static const char *nic_stats_border = "########################";
16063
16064         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16065                 return;
16066
16067         memset(&stats, 0, sizeof(stats));
16068
16069 #ifdef RTE_LIBRTE_I40E_PMD
16070         if (ret == -ENOTSUP)
16071                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16072                                                 res->vf_id,
16073                                                 &stats);
16074 #endif
16075 #ifdef RTE_LIBRTE_BNXT_PMD
16076         if (ret == -ENOTSUP)
16077                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16078                                                 res->vf_id,
16079                                                 &stats);
16080 #endif
16081
16082         switch (ret) {
16083         case 0:
16084                 break;
16085         case -EINVAL:
16086                 printf("invalid vf_id %d\n", res->vf_id);
16087                 break;
16088         case -ENODEV:
16089                 printf("invalid port_id %d\n", res->port_id);
16090                 break;
16091         case -ENOTSUP:
16092                 printf("function not implemented\n");
16093                 break;
16094         default:
16095                 printf("programming error: (%s)\n", strerror(-ret));
16096         }
16097
16098         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16099                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16100
16101         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16102                "%-"PRIu64"\n",
16103                stats.ipackets, stats.imissed, stats.ibytes);
16104         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16105         printf("  RX-nombuf:  %-10"PRIu64"\n",
16106                stats.rx_nombuf);
16107         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16108                "%-"PRIu64"\n",
16109                stats.opackets, stats.oerrors, stats.obytes);
16110
16111         printf("  %s############################%s\n",
16112                                nic_stats_border, nic_stats_border);
16113 }
16114
16115 cmdline_parse_inst_t cmd_show_vf_stats = {
16116         .f = cmd_show_vf_stats_parsed,
16117         .data = NULL,
16118         .help_str = "show vf stats <port_id> <vf_id>",
16119         .tokens = {
16120                 (void *)&cmd_show_vf_stats_show,
16121                 (void *)&cmd_show_vf_stats_vf,
16122                 (void *)&cmd_show_vf_stats_stats,
16123                 (void *)&cmd_show_vf_stats_port_id,
16124                 (void *)&cmd_show_vf_stats_vf_id,
16125                 NULL,
16126         },
16127 };
16128
16129 /* clear vf stats */
16130
16131 /* Common result structure for clear vf stats */
16132 struct cmd_clear_vf_stats_result {
16133         cmdline_fixed_string_t clear;
16134         cmdline_fixed_string_t vf;
16135         cmdline_fixed_string_t stats;
16136         portid_t port_id;
16137         uint16_t vf_id;
16138 };
16139
16140 /* Common CLI fields clear vf stats*/
16141 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16142         TOKEN_STRING_INITIALIZER
16143                 (struct cmd_clear_vf_stats_result,
16144                  clear, "clear");
16145 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16146         TOKEN_STRING_INITIALIZER
16147                 (struct cmd_clear_vf_stats_result,
16148                  vf, "vf");
16149 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16150         TOKEN_STRING_INITIALIZER
16151                 (struct cmd_clear_vf_stats_result,
16152                  stats, "stats");
16153 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16154         TOKEN_NUM_INITIALIZER
16155                 (struct cmd_clear_vf_stats_result,
16156                  port_id, UINT16);
16157 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16158         TOKEN_NUM_INITIALIZER
16159                 (struct cmd_clear_vf_stats_result,
16160                  vf_id, UINT16);
16161
16162 static void
16163 cmd_clear_vf_stats_parsed(
16164         void *parsed_result,
16165         __attribute__((unused)) struct cmdline *cl,
16166         __attribute__((unused)) void *data)
16167 {
16168         struct cmd_clear_vf_stats_result *res = parsed_result;
16169         int ret = -ENOTSUP;
16170
16171         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16172                 return;
16173
16174 #ifdef RTE_LIBRTE_I40E_PMD
16175         if (ret == -ENOTSUP)
16176                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16177                                                   res->vf_id);
16178 #endif
16179 #ifdef RTE_LIBRTE_BNXT_PMD
16180         if (ret == -ENOTSUP)
16181                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16182                                                   res->vf_id);
16183 #endif
16184
16185         switch (ret) {
16186         case 0:
16187                 break;
16188         case -EINVAL:
16189                 printf("invalid vf_id %d\n", res->vf_id);
16190                 break;
16191         case -ENODEV:
16192                 printf("invalid port_id %d\n", res->port_id);
16193                 break;
16194         case -ENOTSUP:
16195                 printf("function not implemented\n");
16196                 break;
16197         default:
16198                 printf("programming error: (%s)\n", strerror(-ret));
16199         }
16200 }
16201
16202 cmdline_parse_inst_t cmd_clear_vf_stats = {
16203         .f = cmd_clear_vf_stats_parsed,
16204         .data = NULL,
16205         .help_str = "clear vf stats <port_id> <vf_id>",
16206         .tokens = {
16207                 (void *)&cmd_clear_vf_stats_clear,
16208                 (void *)&cmd_clear_vf_stats_vf,
16209                 (void *)&cmd_clear_vf_stats_stats,
16210                 (void *)&cmd_clear_vf_stats_port_id,
16211                 (void *)&cmd_clear_vf_stats_vf_id,
16212                 NULL,
16213         },
16214 };
16215
16216 /* port config pctype mapping reset */
16217
16218 /* Common result structure for port config pctype mapping reset */
16219 struct cmd_pctype_mapping_reset_result {
16220         cmdline_fixed_string_t port;
16221         cmdline_fixed_string_t config;
16222         portid_t port_id;
16223         cmdline_fixed_string_t pctype;
16224         cmdline_fixed_string_t mapping;
16225         cmdline_fixed_string_t reset;
16226 };
16227
16228 /* Common CLI fields for port config pctype mapping reset*/
16229 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16230         TOKEN_STRING_INITIALIZER
16231                 (struct cmd_pctype_mapping_reset_result,
16232                  port, "port");
16233 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16234         TOKEN_STRING_INITIALIZER
16235                 (struct cmd_pctype_mapping_reset_result,
16236                  config, "config");
16237 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16238         TOKEN_NUM_INITIALIZER
16239                 (struct cmd_pctype_mapping_reset_result,
16240                  port_id, UINT16);
16241 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16242         TOKEN_STRING_INITIALIZER
16243                 (struct cmd_pctype_mapping_reset_result,
16244                  pctype, "pctype");
16245 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16246         TOKEN_STRING_INITIALIZER
16247                 (struct cmd_pctype_mapping_reset_result,
16248                  mapping, "mapping");
16249 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16250         TOKEN_STRING_INITIALIZER
16251                 (struct cmd_pctype_mapping_reset_result,
16252                  reset, "reset");
16253
16254 static void
16255 cmd_pctype_mapping_reset_parsed(
16256         void *parsed_result,
16257         __attribute__((unused)) struct cmdline *cl,
16258         __attribute__((unused)) void *data)
16259 {
16260         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16261         int ret = -ENOTSUP;
16262
16263         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16264                 return;
16265
16266 #ifdef RTE_LIBRTE_I40E_PMD
16267         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16268 #endif
16269
16270         switch (ret) {
16271         case 0:
16272                 break;
16273         case -ENODEV:
16274                 printf("invalid port_id %d\n", res->port_id);
16275                 break;
16276         case -ENOTSUP:
16277                 printf("function not implemented\n");
16278                 break;
16279         default:
16280                 printf("programming error: (%s)\n", strerror(-ret));
16281         }
16282 }
16283
16284 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16285         .f = cmd_pctype_mapping_reset_parsed,
16286         .data = NULL,
16287         .help_str = "port config <port_id> pctype mapping reset",
16288         .tokens = {
16289                 (void *)&cmd_pctype_mapping_reset_port,
16290                 (void *)&cmd_pctype_mapping_reset_config,
16291                 (void *)&cmd_pctype_mapping_reset_port_id,
16292                 (void *)&cmd_pctype_mapping_reset_pctype,
16293                 (void *)&cmd_pctype_mapping_reset_mapping,
16294                 (void *)&cmd_pctype_mapping_reset_reset,
16295                 NULL,
16296         },
16297 };
16298
16299 /* show port pctype mapping */
16300
16301 /* Common result structure for show port pctype mapping */
16302 struct cmd_pctype_mapping_get_result {
16303         cmdline_fixed_string_t show;
16304         cmdline_fixed_string_t port;
16305         portid_t port_id;
16306         cmdline_fixed_string_t pctype;
16307         cmdline_fixed_string_t mapping;
16308 };
16309
16310 /* Common CLI fields for pctype mapping get */
16311 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16312         TOKEN_STRING_INITIALIZER
16313                 (struct cmd_pctype_mapping_get_result,
16314                  show, "show");
16315 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16316         TOKEN_STRING_INITIALIZER
16317                 (struct cmd_pctype_mapping_get_result,
16318                  port, "port");
16319 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
16320         TOKEN_NUM_INITIALIZER
16321                 (struct cmd_pctype_mapping_get_result,
16322                  port_id, UINT16);
16323 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
16324         TOKEN_STRING_INITIALIZER
16325                 (struct cmd_pctype_mapping_get_result,
16326                  pctype, "pctype");
16327 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
16328         TOKEN_STRING_INITIALIZER
16329                 (struct cmd_pctype_mapping_get_result,
16330                  mapping, "mapping");
16331
16332 static void
16333 cmd_pctype_mapping_get_parsed(
16334         void *parsed_result,
16335         __attribute__((unused)) struct cmdline *cl,
16336         __attribute__((unused)) void *data)
16337 {
16338         struct cmd_pctype_mapping_get_result *res = parsed_result;
16339         int ret = -ENOTSUP;
16340 #ifdef RTE_LIBRTE_I40E_PMD
16341         struct rte_pmd_i40e_flow_type_mapping
16342                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
16343         int i, j, first_pctype;
16344 #endif
16345
16346         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16347                 return;
16348
16349 #ifdef RTE_LIBRTE_I40E_PMD
16350         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
16351 #endif
16352
16353         switch (ret) {
16354         case 0:
16355                 break;
16356         case -ENODEV:
16357                 printf("invalid port_id %d\n", res->port_id);
16358                 return;
16359         case -ENOTSUP:
16360                 printf("function not implemented\n");
16361                 return;
16362         default:
16363                 printf("programming error: (%s)\n", strerror(-ret));
16364                 return;
16365         }
16366
16367 #ifdef RTE_LIBRTE_I40E_PMD
16368         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
16369                 if (mapping[i].pctype != 0ULL) {
16370                         first_pctype = 1;
16371
16372                         printf("pctype: ");
16373                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
16374                                 if (mapping[i].pctype & (1ULL << j)) {
16375                                         printf(first_pctype ?
16376                                                "%02d" : ",%02d", j);
16377                                         first_pctype = 0;
16378                                 }
16379                         }
16380                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
16381                 }
16382         }
16383 #endif
16384 }
16385
16386 cmdline_parse_inst_t cmd_pctype_mapping_get = {
16387         .f = cmd_pctype_mapping_get_parsed,
16388         .data = NULL,
16389         .help_str = "show port <port_id> pctype mapping",
16390         .tokens = {
16391                 (void *)&cmd_pctype_mapping_get_show,
16392                 (void *)&cmd_pctype_mapping_get_port,
16393                 (void *)&cmd_pctype_mapping_get_port_id,
16394                 (void *)&cmd_pctype_mapping_get_pctype,
16395                 (void *)&cmd_pctype_mapping_get_mapping,
16396                 NULL,
16397         },
16398 };
16399
16400 /* port config pctype mapping update */
16401
16402 /* Common result structure for port config pctype mapping update */
16403 struct cmd_pctype_mapping_update_result {
16404         cmdline_fixed_string_t port;
16405         cmdline_fixed_string_t config;
16406         portid_t port_id;
16407         cmdline_fixed_string_t pctype;
16408         cmdline_fixed_string_t mapping;
16409         cmdline_fixed_string_t update;
16410         cmdline_fixed_string_t pctype_list;
16411         uint16_t flow_type;
16412 };
16413
16414 /* Common CLI fields for pctype mapping update*/
16415 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
16416         TOKEN_STRING_INITIALIZER
16417                 (struct cmd_pctype_mapping_update_result,
16418                  port, "port");
16419 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
16420         TOKEN_STRING_INITIALIZER
16421                 (struct cmd_pctype_mapping_update_result,
16422                  config, "config");
16423 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
16424         TOKEN_NUM_INITIALIZER
16425                 (struct cmd_pctype_mapping_update_result,
16426                  port_id, UINT16);
16427 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
16428         TOKEN_STRING_INITIALIZER
16429                 (struct cmd_pctype_mapping_update_result,
16430                  pctype, "pctype");
16431 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
16432         TOKEN_STRING_INITIALIZER
16433                 (struct cmd_pctype_mapping_update_result,
16434                  mapping, "mapping");
16435 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16436         TOKEN_STRING_INITIALIZER
16437                 (struct cmd_pctype_mapping_update_result,
16438                  update, "update");
16439 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16440         TOKEN_STRING_INITIALIZER
16441                 (struct cmd_pctype_mapping_update_result,
16442                  pctype_list, NULL);
16443 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16444         TOKEN_NUM_INITIALIZER
16445                 (struct cmd_pctype_mapping_update_result,
16446                  flow_type, UINT16);
16447
16448 static void
16449 cmd_pctype_mapping_update_parsed(
16450         void *parsed_result,
16451         __attribute__((unused)) struct cmdline *cl,
16452         __attribute__((unused)) void *data)
16453 {
16454         struct cmd_pctype_mapping_update_result *res = parsed_result;
16455         int ret = -ENOTSUP;
16456 #ifdef RTE_LIBRTE_I40E_PMD
16457         struct rte_pmd_i40e_flow_type_mapping mapping;
16458         unsigned int i;
16459         unsigned int nb_item;
16460         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16461 #endif
16462
16463         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16464                 return;
16465
16466 #ifdef RTE_LIBRTE_I40E_PMD
16467         nb_item = parse_item_list(res->pctype_list, "pctypes",
16468                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16469         mapping.flow_type = res->flow_type;
16470         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16471                 mapping.pctype |= (1ULL << pctype_list[i]);
16472         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16473                                                 &mapping,
16474                                                 1,
16475                                                 0);
16476 #endif
16477
16478         switch (ret) {
16479         case 0:
16480                 break;
16481         case -EINVAL:
16482                 printf("invalid pctype or flow type\n");
16483                 break;
16484         case -ENODEV:
16485                 printf("invalid port_id %d\n", res->port_id);
16486                 break;
16487         case -ENOTSUP:
16488                 printf("function not implemented\n");
16489                 break;
16490         default:
16491                 printf("programming error: (%s)\n", strerror(-ret));
16492         }
16493 }
16494
16495 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16496         .f = cmd_pctype_mapping_update_parsed,
16497         .data = NULL,
16498         .help_str = "port config <port_id> pctype mapping update"
16499         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16500         .tokens = {
16501                 (void *)&cmd_pctype_mapping_update_port,
16502                 (void *)&cmd_pctype_mapping_update_config,
16503                 (void *)&cmd_pctype_mapping_update_port_id,
16504                 (void *)&cmd_pctype_mapping_update_pctype,
16505                 (void *)&cmd_pctype_mapping_update_mapping,
16506                 (void *)&cmd_pctype_mapping_update_update,
16507                 (void *)&cmd_pctype_mapping_update_pc_type,
16508                 (void *)&cmd_pctype_mapping_update_flow_type,
16509                 NULL,
16510         },
16511 };
16512
16513 /* ptype mapping get */
16514
16515 /* Common result structure for ptype mapping get */
16516 struct cmd_ptype_mapping_get_result {
16517         cmdline_fixed_string_t ptype;
16518         cmdline_fixed_string_t mapping;
16519         cmdline_fixed_string_t get;
16520         portid_t port_id;
16521         uint8_t valid_only;
16522 };
16523
16524 /* Common CLI fields for ptype mapping get */
16525 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16526         TOKEN_STRING_INITIALIZER
16527                 (struct cmd_ptype_mapping_get_result,
16528                  ptype, "ptype");
16529 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16530         TOKEN_STRING_INITIALIZER
16531                 (struct cmd_ptype_mapping_get_result,
16532                  mapping, "mapping");
16533 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16534         TOKEN_STRING_INITIALIZER
16535                 (struct cmd_ptype_mapping_get_result,
16536                  get, "get");
16537 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16538         TOKEN_NUM_INITIALIZER
16539                 (struct cmd_ptype_mapping_get_result,
16540                  port_id, UINT16);
16541 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16542         TOKEN_NUM_INITIALIZER
16543                 (struct cmd_ptype_mapping_get_result,
16544                  valid_only, UINT8);
16545
16546 static void
16547 cmd_ptype_mapping_get_parsed(
16548         void *parsed_result,
16549         __attribute__((unused)) struct cmdline *cl,
16550         __attribute__((unused)) void *data)
16551 {
16552         struct cmd_ptype_mapping_get_result *res = parsed_result;
16553         int ret = -ENOTSUP;
16554 #ifdef RTE_LIBRTE_I40E_PMD
16555         int max_ptype_num = 256;
16556         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16557         uint16_t count;
16558         int i;
16559 #endif
16560
16561         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16562                 return;
16563
16564 #ifdef RTE_LIBRTE_I40E_PMD
16565         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16566                                         mapping,
16567                                         max_ptype_num,
16568                                         &count,
16569                                         res->valid_only);
16570 #endif
16571
16572         switch (ret) {
16573         case 0:
16574                 break;
16575         case -ENODEV:
16576                 printf("invalid port_id %d\n", res->port_id);
16577                 break;
16578         case -ENOTSUP:
16579                 printf("function not implemented\n");
16580                 break;
16581         default:
16582                 printf("programming error: (%s)\n", strerror(-ret));
16583         }
16584
16585 #ifdef RTE_LIBRTE_I40E_PMD
16586         if (!ret) {
16587                 for (i = 0; i < count; i++)
16588                         printf("%3d\t0x%08x\n",
16589                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16590         }
16591 #endif
16592 }
16593
16594 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16595         .f = cmd_ptype_mapping_get_parsed,
16596         .data = NULL,
16597         .help_str = "ptype mapping get <port_id> <valid_only>",
16598         .tokens = {
16599                 (void *)&cmd_ptype_mapping_get_ptype,
16600                 (void *)&cmd_ptype_mapping_get_mapping,
16601                 (void *)&cmd_ptype_mapping_get_get,
16602                 (void *)&cmd_ptype_mapping_get_port_id,
16603                 (void *)&cmd_ptype_mapping_get_valid_only,
16604                 NULL,
16605         },
16606 };
16607
16608 /* ptype mapping replace */
16609
16610 /* Common result structure for ptype mapping replace */
16611 struct cmd_ptype_mapping_replace_result {
16612         cmdline_fixed_string_t ptype;
16613         cmdline_fixed_string_t mapping;
16614         cmdline_fixed_string_t replace;
16615         portid_t port_id;
16616         uint32_t target;
16617         uint8_t mask;
16618         uint32_t pkt_type;
16619 };
16620
16621 /* Common CLI fields for ptype mapping replace */
16622 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16623         TOKEN_STRING_INITIALIZER
16624                 (struct cmd_ptype_mapping_replace_result,
16625                  ptype, "ptype");
16626 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16627         TOKEN_STRING_INITIALIZER
16628                 (struct cmd_ptype_mapping_replace_result,
16629                  mapping, "mapping");
16630 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16631         TOKEN_STRING_INITIALIZER
16632                 (struct cmd_ptype_mapping_replace_result,
16633                  replace, "replace");
16634 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16635         TOKEN_NUM_INITIALIZER
16636                 (struct cmd_ptype_mapping_replace_result,
16637                  port_id, UINT16);
16638 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16639         TOKEN_NUM_INITIALIZER
16640                 (struct cmd_ptype_mapping_replace_result,
16641                  target, UINT32);
16642 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16643         TOKEN_NUM_INITIALIZER
16644                 (struct cmd_ptype_mapping_replace_result,
16645                  mask, UINT8);
16646 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16647         TOKEN_NUM_INITIALIZER
16648                 (struct cmd_ptype_mapping_replace_result,
16649                  pkt_type, UINT32);
16650
16651 static void
16652 cmd_ptype_mapping_replace_parsed(
16653         void *parsed_result,
16654         __attribute__((unused)) struct cmdline *cl,
16655         __attribute__((unused)) void *data)
16656 {
16657         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16658         int ret = -ENOTSUP;
16659
16660         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16661                 return;
16662
16663 #ifdef RTE_LIBRTE_I40E_PMD
16664         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16665                                         res->target,
16666                                         res->mask,
16667                                         res->pkt_type);
16668 #endif
16669
16670         switch (ret) {
16671         case 0:
16672                 break;
16673         case -EINVAL:
16674                 printf("invalid ptype 0x%8x or 0x%8x\n",
16675                                 res->target, res->pkt_type);
16676                 break;
16677         case -ENODEV:
16678                 printf("invalid port_id %d\n", res->port_id);
16679                 break;
16680         case -ENOTSUP:
16681                 printf("function not implemented\n");
16682                 break;
16683         default:
16684                 printf("programming error: (%s)\n", strerror(-ret));
16685         }
16686 }
16687
16688 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16689         .f = cmd_ptype_mapping_replace_parsed,
16690         .data = NULL,
16691         .help_str =
16692                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16693         .tokens = {
16694                 (void *)&cmd_ptype_mapping_replace_ptype,
16695                 (void *)&cmd_ptype_mapping_replace_mapping,
16696                 (void *)&cmd_ptype_mapping_replace_replace,
16697                 (void *)&cmd_ptype_mapping_replace_port_id,
16698                 (void *)&cmd_ptype_mapping_replace_target,
16699                 (void *)&cmd_ptype_mapping_replace_mask,
16700                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16701                 NULL,
16702         },
16703 };
16704
16705 /* ptype mapping reset */
16706
16707 /* Common result structure for ptype mapping reset */
16708 struct cmd_ptype_mapping_reset_result {
16709         cmdline_fixed_string_t ptype;
16710         cmdline_fixed_string_t mapping;
16711         cmdline_fixed_string_t reset;
16712         portid_t port_id;
16713 };
16714
16715 /* Common CLI fields for ptype mapping reset*/
16716 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16717         TOKEN_STRING_INITIALIZER
16718                 (struct cmd_ptype_mapping_reset_result,
16719                  ptype, "ptype");
16720 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16721         TOKEN_STRING_INITIALIZER
16722                 (struct cmd_ptype_mapping_reset_result,
16723                  mapping, "mapping");
16724 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16725         TOKEN_STRING_INITIALIZER
16726                 (struct cmd_ptype_mapping_reset_result,
16727                  reset, "reset");
16728 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16729         TOKEN_NUM_INITIALIZER
16730                 (struct cmd_ptype_mapping_reset_result,
16731                  port_id, UINT16);
16732
16733 static void
16734 cmd_ptype_mapping_reset_parsed(
16735         void *parsed_result,
16736         __attribute__((unused)) struct cmdline *cl,
16737         __attribute__((unused)) void *data)
16738 {
16739         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16740         int ret = -ENOTSUP;
16741
16742         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16743                 return;
16744
16745 #ifdef RTE_LIBRTE_I40E_PMD
16746         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16747 #endif
16748
16749         switch (ret) {
16750         case 0:
16751                 break;
16752         case -ENODEV:
16753                 printf("invalid port_id %d\n", res->port_id);
16754                 break;
16755         case -ENOTSUP:
16756                 printf("function not implemented\n");
16757                 break;
16758         default:
16759                 printf("programming error: (%s)\n", strerror(-ret));
16760         }
16761 }
16762
16763 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16764         .f = cmd_ptype_mapping_reset_parsed,
16765         .data = NULL,
16766         .help_str = "ptype mapping reset <port_id>",
16767         .tokens = {
16768                 (void *)&cmd_ptype_mapping_reset_ptype,
16769                 (void *)&cmd_ptype_mapping_reset_mapping,
16770                 (void *)&cmd_ptype_mapping_reset_reset,
16771                 (void *)&cmd_ptype_mapping_reset_port_id,
16772                 NULL,
16773         },
16774 };
16775
16776 /* ptype mapping update */
16777
16778 /* Common result structure for ptype mapping update */
16779 struct cmd_ptype_mapping_update_result {
16780         cmdline_fixed_string_t ptype;
16781         cmdline_fixed_string_t mapping;
16782         cmdline_fixed_string_t reset;
16783         portid_t port_id;
16784         uint8_t hw_ptype;
16785         uint32_t sw_ptype;
16786 };
16787
16788 /* Common CLI fields for ptype mapping update*/
16789 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16790         TOKEN_STRING_INITIALIZER
16791                 (struct cmd_ptype_mapping_update_result,
16792                  ptype, "ptype");
16793 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16794         TOKEN_STRING_INITIALIZER
16795                 (struct cmd_ptype_mapping_update_result,
16796                  mapping, "mapping");
16797 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16798         TOKEN_STRING_INITIALIZER
16799                 (struct cmd_ptype_mapping_update_result,
16800                  reset, "update");
16801 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16802         TOKEN_NUM_INITIALIZER
16803                 (struct cmd_ptype_mapping_update_result,
16804                  port_id, UINT16);
16805 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16806         TOKEN_NUM_INITIALIZER
16807                 (struct cmd_ptype_mapping_update_result,
16808                  hw_ptype, UINT8);
16809 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16810         TOKEN_NUM_INITIALIZER
16811                 (struct cmd_ptype_mapping_update_result,
16812                  sw_ptype, UINT32);
16813
16814 static void
16815 cmd_ptype_mapping_update_parsed(
16816         void *parsed_result,
16817         __attribute__((unused)) struct cmdline *cl,
16818         __attribute__((unused)) void *data)
16819 {
16820         struct cmd_ptype_mapping_update_result *res = parsed_result;
16821         int ret = -ENOTSUP;
16822 #ifdef RTE_LIBRTE_I40E_PMD
16823         struct rte_pmd_i40e_ptype_mapping mapping;
16824 #endif
16825         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16826                 return;
16827
16828 #ifdef RTE_LIBRTE_I40E_PMD
16829         mapping.hw_ptype = res->hw_ptype;
16830         mapping.sw_ptype = res->sw_ptype;
16831         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16832                                                 &mapping,
16833                                                 1,
16834                                                 0);
16835 #endif
16836
16837         switch (ret) {
16838         case 0:
16839                 break;
16840         case -EINVAL:
16841                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16842                 break;
16843         case -ENODEV:
16844                 printf("invalid port_id %d\n", res->port_id);
16845                 break;
16846         case -ENOTSUP:
16847                 printf("function not implemented\n");
16848                 break;
16849         default:
16850                 printf("programming error: (%s)\n", strerror(-ret));
16851         }
16852 }
16853
16854 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16855         .f = cmd_ptype_mapping_update_parsed,
16856         .data = NULL,
16857         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16858         .tokens = {
16859                 (void *)&cmd_ptype_mapping_update_ptype,
16860                 (void *)&cmd_ptype_mapping_update_mapping,
16861                 (void *)&cmd_ptype_mapping_update_update,
16862                 (void *)&cmd_ptype_mapping_update_port_id,
16863                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16864                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16865                 NULL,
16866         },
16867 };
16868
16869 /* Common result structure for file commands */
16870 struct cmd_cmdfile_result {
16871         cmdline_fixed_string_t load;
16872         cmdline_fixed_string_t filename;
16873 };
16874
16875 /* Common CLI fields for file commands */
16876 cmdline_parse_token_string_t cmd_load_cmdfile =
16877         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16878 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16879         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16880
16881 static void
16882 cmd_load_from_file_parsed(
16883         void *parsed_result,
16884         __attribute__((unused)) struct cmdline *cl,
16885         __attribute__((unused)) void *data)
16886 {
16887         struct cmd_cmdfile_result *res = parsed_result;
16888
16889         cmdline_read_from_file(res->filename);
16890 }
16891
16892 cmdline_parse_inst_t cmd_load_from_file = {
16893         .f = cmd_load_from_file_parsed,
16894         .data = NULL,
16895         .help_str = "load <filename>",
16896         .tokens = {
16897                 (void *)&cmd_load_cmdfile,
16898                 (void *)&cmd_load_cmdfile_filename,
16899                 NULL,
16900         },
16901 };
16902
16903 /* Get Rx offloads capabilities */
16904 struct cmd_rx_offload_get_capa_result {
16905         cmdline_fixed_string_t show;
16906         cmdline_fixed_string_t port;
16907         portid_t port_id;
16908         cmdline_fixed_string_t rx_offload;
16909         cmdline_fixed_string_t capabilities;
16910 };
16911
16912 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16913         TOKEN_STRING_INITIALIZER
16914                 (struct cmd_rx_offload_get_capa_result,
16915                  show, "show");
16916 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16917         TOKEN_STRING_INITIALIZER
16918                 (struct cmd_rx_offload_get_capa_result,
16919                  port, "port");
16920 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16921         TOKEN_NUM_INITIALIZER
16922                 (struct cmd_rx_offload_get_capa_result,
16923                  port_id, UINT16);
16924 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16925         TOKEN_STRING_INITIALIZER
16926                 (struct cmd_rx_offload_get_capa_result,
16927                  rx_offload, "rx_offload");
16928 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16929         TOKEN_STRING_INITIALIZER
16930                 (struct cmd_rx_offload_get_capa_result,
16931                  capabilities, "capabilities");
16932
16933 static void
16934 print_rx_offloads(uint64_t offloads)
16935 {
16936         uint64_t single_offload;
16937         int begin;
16938         int end;
16939         int bit;
16940
16941         if (offloads == 0)
16942                 return;
16943
16944         begin = __builtin_ctzll(offloads);
16945         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16946
16947         single_offload = 1 << begin;
16948         for (bit = begin; bit < end; bit++) {
16949                 if (offloads & single_offload)
16950                         printf(" %s",
16951                                rte_eth_dev_rx_offload_name(single_offload));
16952                 single_offload <<= 1;
16953         }
16954 }
16955
16956 static void
16957 cmd_rx_offload_get_capa_parsed(
16958         void *parsed_result,
16959         __attribute__((unused)) struct cmdline *cl,
16960         __attribute__((unused)) void *data)
16961 {
16962         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16963         struct rte_eth_dev_info dev_info;
16964         portid_t port_id = res->port_id;
16965         uint64_t queue_offloads;
16966         uint64_t port_offloads;
16967
16968         rte_eth_dev_info_get(port_id, &dev_info);
16969         queue_offloads = dev_info.rx_queue_offload_capa;
16970         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16971
16972         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16973         printf("  Per Queue :");
16974         print_rx_offloads(queue_offloads);
16975
16976         printf("\n");
16977         printf("  Per Port  :");
16978         print_rx_offloads(port_offloads);
16979         printf("\n\n");
16980 }
16981
16982 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16983         .f = cmd_rx_offload_get_capa_parsed,
16984         .data = NULL,
16985         .help_str = "show port <port_id> rx_offload capabilities",
16986         .tokens = {
16987                 (void *)&cmd_rx_offload_get_capa_show,
16988                 (void *)&cmd_rx_offload_get_capa_port,
16989                 (void *)&cmd_rx_offload_get_capa_port_id,
16990                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16991                 (void *)&cmd_rx_offload_get_capa_capabilities,
16992                 NULL,
16993         }
16994 };
16995
16996 /* Get Rx offloads configuration */
16997 struct cmd_rx_offload_get_configuration_result {
16998         cmdline_fixed_string_t show;
16999         cmdline_fixed_string_t port;
17000         portid_t port_id;
17001         cmdline_fixed_string_t rx_offload;
17002         cmdline_fixed_string_t configuration;
17003 };
17004
17005 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17006         TOKEN_STRING_INITIALIZER
17007                 (struct cmd_rx_offload_get_configuration_result,
17008                  show, "show");
17009 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17010         TOKEN_STRING_INITIALIZER
17011                 (struct cmd_rx_offload_get_configuration_result,
17012                  port, "port");
17013 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17014         TOKEN_NUM_INITIALIZER
17015                 (struct cmd_rx_offload_get_configuration_result,
17016                  port_id, UINT16);
17017 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17018         TOKEN_STRING_INITIALIZER
17019                 (struct cmd_rx_offload_get_configuration_result,
17020                  rx_offload, "rx_offload");
17021 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17022         TOKEN_STRING_INITIALIZER
17023                 (struct cmd_rx_offload_get_configuration_result,
17024                  configuration, "configuration");
17025
17026 static void
17027 cmd_rx_offload_get_configuration_parsed(
17028         void *parsed_result,
17029         __attribute__((unused)) struct cmdline *cl,
17030         __attribute__((unused)) void *data)
17031 {
17032         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17033         struct rte_eth_dev_info dev_info;
17034         portid_t port_id = res->port_id;
17035         struct rte_port *port = &ports[port_id];
17036         uint64_t port_offloads;
17037         uint64_t queue_offloads;
17038         uint16_t nb_rx_queues;
17039         int q;
17040
17041         printf("Rx Offloading Configuration of port %d :\n", port_id);
17042
17043         port_offloads = port->dev_conf.rxmode.offloads;
17044         printf("  Port :");
17045         print_rx_offloads(port_offloads);
17046         printf("\n");
17047
17048         rte_eth_dev_info_get(port_id, &dev_info);
17049         nb_rx_queues = dev_info.nb_rx_queues;
17050         for (q = 0; q < nb_rx_queues; q++) {
17051                 queue_offloads = port->rx_conf[q].offloads;
17052                 printf("  Queue[%2d] :", q);
17053                 print_rx_offloads(queue_offloads);
17054                 printf("\n");
17055         }
17056         printf("\n");
17057 }
17058
17059 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17060         .f = cmd_rx_offload_get_configuration_parsed,
17061         .data = NULL,
17062         .help_str = "show port <port_id> rx_offload configuration",
17063         .tokens = {
17064                 (void *)&cmd_rx_offload_get_configuration_show,
17065                 (void *)&cmd_rx_offload_get_configuration_port,
17066                 (void *)&cmd_rx_offload_get_configuration_port_id,
17067                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17068                 (void *)&cmd_rx_offload_get_configuration_configuration,
17069                 NULL,
17070         }
17071 };
17072
17073 /* Enable/Disable a per port offloading */
17074 struct cmd_config_per_port_rx_offload_result {
17075         cmdline_fixed_string_t port;
17076         cmdline_fixed_string_t config;
17077         portid_t port_id;
17078         cmdline_fixed_string_t rx_offload;
17079         cmdline_fixed_string_t offload;
17080         cmdline_fixed_string_t on_off;
17081 };
17082
17083 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17084         TOKEN_STRING_INITIALIZER
17085                 (struct cmd_config_per_port_rx_offload_result,
17086                  port, "port");
17087 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17088         TOKEN_STRING_INITIALIZER
17089                 (struct cmd_config_per_port_rx_offload_result,
17090                  config, "config");
17091 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
17092         TOKEN_NUM_INITIALIZER
17093                 (struct cmd_config_per_port_rx_offload_result,
17094                  port_id, UINT16);
17095 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17096         TOKEN_STRING_INITIALIZER
17097                 (struct cmd_config_per_port_rx_offload_result,
17098                  rx_offload, "rx_offload");
17099 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17100         TOKEN_STRING_INITIALIZER
17101                 (struct cmd_config_per_port_rx_offload_result,
17102                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17103                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17104                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17105                            "crc_strip#scatter#timestamp#security#keep_crc");
17106 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17107         TOKEN_STRING_INITIALIZER
17108                 (struct cmd_config_per_port_rx_offload_result,
17109                  on_off, "on#off");
17110
17111 static uint64_t
17112 search_rx_offload(const char *name)
17113 {
17114         uint64_t single_offload;
17115         const char *single_name;
17116         int found = 0;
17117         unsigned int bit;
17118
17119         single_offload = 1;
17120         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17121                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17122                 if (!strcasecmp(single_name, name)) {
17123                         found = 1;
17124                         break;
17125                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17126                         break;
17127                 else if (single_name == NULL)
17128                         break;
17129                 single_offload <<= 1;
17130         }
17131
17132         if (found)
17133                 return single_offload;
17134
17135         return 0;
17136 }
17137
17138 static void
17139 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17140                                 __attribute__((unused)) struct cmdline *cl,
17141                                 __attribute__((unused)) void *data)
17142 {
17143         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17144         portid_t port_id = res->port_id;
17145         struct rte_eth_dev_info dev_info;
17146         struct rte_port *port = &ports[port_id];
17147         uint64_t single_offload;
17148         uint16_t nb_rx_queues;
17149         int q;
17150
17151         if (port->port_status != RTE_PORT_STOPPED) {
17152                 printf("Error: Can't config offload when Port %d "
17153                        "is not stopped\n", port_id);
17154                 return;
17155         }
17156
17157         single_offload = search_rx_offload(res->offload);
17158         if (single_offload == 0) {
17159                 printf("Unknown offload name: %s\n", res->offload);
17160                 return;
17161         }
17162
17163         rte_eth_dev_info_get(port_id, &dev_info);
17164         nb_rx_queues = dev_info.nb_rx_queues;
17165         if (!strcmp(res->on_off, "on")) {
17166                 port->dev_conf.rxmode.offloads |= single_offload;
17167                 for (q = 0; q < nb_rx_queues; q++)
17168                         port->rx_conf[q].offloads |= single_offload;
17169         } else {
17170                 port->dev_conf.rxmode.offloads &= ~single_offload;
17171                 for (q = 0; q < nb_rx_queues; q++)
17172                         port->rx_conf[q].offloads &= ~single_offload;
17173         }
17174
17175         cmd_reconfig_device_queue(port_id, 1, 1);
17176 }
17177
17178 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17179         .f = cmd_config_per_port_rx_offload_parsed,
17180         .data = NULL,
17181         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17182                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17183                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17184                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17185                     "on|off",
17186         .tokens = {
17187                 (void *)&cmd_config_per_port_rx_offload_result_port,
17188                 (void *)&cmd_config_per_port_rx_offload_result_config,
17189                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17190                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17191                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17192                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17193                 NULL,
17194         }
17195 };
17196
17197 /* Enable/Disable a per queue offloading */
17198 struct cmd_config_per_queue_rx_offload_result {
17199         cmdline_fixed_string_t port;
17200         portid_t port_id;
17201         cmdline_fixed_string_t rxq;
17202         uint16_t queue_id;
17203         cmdline_fixed_string_t rx_offload;
17204         cmdline_fixed_string_t offload;
17205         cmdline_fixed_string_t on_off;
17206 };
17207
17208 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17209         TOKEN_STRING_INITIALIZER
17210                 (struct cmd_config_per_queue_rx_offload_result,
17211                  port, "port");
17212 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17213         TOKEN_NUM_INITIALIZER
17214                 (struct cmd_config_per_queue_rx_offload_result,
17215                  port_id, UINT16);
17216 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17217         TOKEN_STRING_INITIALIZER
17218                 (struct cmd_config_per_queue_rx_offload_result,
17219                  rxq, "rxq");
17220 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17221         TOKEN_NUM_INITIALIZER
17222                 (struct cmd_config_per_queue_rx_offload_result,
17223                  queue_id, UINT16);
17224 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17225         TOKEN_STRING_INITIALIZER
17226                 (struct cmd_config_per_queue_rx_offload_result,
17227                  rx_offload, "rx_offload");
17228 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17229         TOKEN_STRING_INITIALIZER
17230                 (struct cmd_config_per_queue_rx_offload_result,
17231                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17232                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17233                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17234                            "crc_strip#scatter#timestamp#security#keep_crc");
17235 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17236         TOKEN_STRING_INITIALIZER
17237                 (struct cmd_config_per_queue_rx_offload_result,
17238                  on_off, "on#off");
17239
17240 static void
17241 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17242                                 __attribute__((unused)) struct cmdline *cl,
17243                                 __attribute__((unused)) void *data)
17244 {
17245         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17246         struct rte_eth_dev_info dev_info;
17247         portid_t port_id = res->port_id;
17248         uint16_t queue_id = res->queue_id;
17249         struct rte_port *port = &ports[port_id];
17250         uint64_t single_offload;
17251
17252         if (port->port_status != RTE_PORT_STOPPED) {
17253                 printf("Error: Can't config offload when Port %d "
17254                        "is not stopped\n", port_id);
17255                 return;
17256         }
17257
17258         rte_eth_dev_info_get(port_id, &dev_info);
17259         if (queue_id >= dev_info.nb_rx_queues) {
17260                 printf("Error: input queue_id should be 0 ... "
17261                        "%d\n", dev_info.nb_rx_queues - 1);
17262                 return;
17263         }
17264
17265         single_offload = search_rx_offload(res->offload);
17266         if (single_offload == 0) {
17267                 printf("Unknown offload name: %s\n", res->offload);
17268                 return;
17269         }
17270
17271         if (!strcmp(res->on_off, "on"))
17272                 port->rx_conf[queue_id].offloads |= single_offload;
17273         else
17274                 port->rx_conf[queue_id].offloads &= ~single_offload;
17275
17276         cmd_reconfig_device_queue(port_id, 1, 1);
17277 }
17278
17279 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17280         .f = cmd_config_per_queue_rx_offload_parsed,
17281         .data = NULL,
17282         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17283                     "vlan_strip|ipv4_cksum|"
17284                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17285                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17286                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17287                     "on|off",
17288         .tokens = {
17289                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17290                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17291                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17292                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17293                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17294                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17295                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17296                 NULL,
17297         }
17298 };
17299
17300 /* Get Tx offloads capabilities */
17301 struct cmd_tx_offload_get_capa_result {
17302         cmdline_fixed_string_t show;
17303         cmdline_fixed_string_t port;
17304         portid_t port_id;
17305         cmdline_fixed_string_t tx_offload;
17306         cmdline_fixed_string_t capabilities;
17307 };
17308
17309 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17310         TOKEN_STRING_INITIALIZER
17311                 (struct cmd_tx_offload_get_capa_result,
17312                  show, "show");
17313 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17314         TOKEN_STRING_INITIALIZER
17315                 (struct cmd_tx_offload_get_capa_result,
17316                  port, "port");
17317 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17318         TOKEN_NUM_INITIALIZER
17319                 (struct cmd_tx_offload_get_capa_result,
17320                  port_id, UINT16);
17321 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
17322         TOKEN_STRING_INITIALIZER
17323                 (struct cmd_tx_offload_get_capa_result,
17324                  tx_offload, "tx_offload");
17325 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
17326         TOKEN_STRING_INITIALIZER
17327                 (struct cmd_tx_offload_get_capa_result,
17328                  capabilities, "capabilities");
17329
17330 static void
17331 print_tx_offloads(uint64_t offloads)
17332 {
17333         uint64_t single_offload;
17334         int begin;
17335         int end;
17336         int bit;
17337
17338         if (offloads == 0)
17339                 return;
17340
17341         begin = __builtin_ctzll(offloads);
17342         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17343
17344         single_offload = 1 << begin;
17345         for (bit = begin; bit < end; bit++) {
17346                 if (offloads & single_offload)
17347                         printf(" %s",
17348                                rte_eth_dev_tx_offload_name(single_offload));
17349                 single_offload <<= 1;
17350         }
17351 }
17352
17353 static void
17354 cmd_tx_offload_get_capa_parsed(
17355         void *parsed_result,
17356         __attribute__((unused)) struct cmdline *cl,
17357         __attribute__((unused)) void *data)
17358 {
17359         struct cmd_tx_offload_get_capa_result *res = parsed_result;
17360         struct rte_eth_dev_info dev_info;
17361         portid_t port_id = res->port_id;
17362         uint64_t queue_offloads;
17363         uint64_t port_offloads;
17364
17365         rte_eth_dev_info_get(port_id, &dev_info);
17366         queue_offloads = dev_info.tx_queue_offload_capa;
17367         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
17368
17369         printf("Tx Offloading Capabilities of port %d :\n", port_id);
17370         printf("  Per Queue :");
17371         print_tx_offloads(queue_offloads);
17372
17373         printf("\n");
17374         printf("  Per Port  :");
17375         print_tx_offloads(port_offloads);
17376         printf("\n\n");
17377 }
17378
17379 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
17380         .f = cmd_tx_offload_get_capa_parsed,
17381         .data = NULL,
17382         .help_str = "show port <port_id> tx_offload capabilities",
17383         .tokens = {
17384                 (void *)&cmd_tx_offload_get_capa_show,
17385                 (void *)&cmd_tx_offload_get_capa_port,
17386                 (void *)&cmd_tx_offload_get_capa_port_id,
17387                 (void *)&cmd_tx_offload_get_capa_tx_offload,
17388                 (void *)&cmd_tx_offload_get_capa_capabilities,
17389                 NULL,
17390         }
17391 };
17392
17393 /* Get Tx offloads configuration */
17394 struct cmd_tx_offload_get_configuration_result {
17395         cmdline_fixed_string_t show;
17396         cmdline_fixed_string_t port;
17397         portid_t port_id;
17398         cmdline_fixed_string_t tx_offload;
17399         cmdline_fixed_string_t configuration;
17400 };
17401
17402 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
17403         TOKEN_STRING_INITIALIZER
17404                 (struct cmd_tx_offload_get_configuration_result,
17405                  show, "show");
17406 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
17407         TOKEN_STRING_INITIALIZER
17408                 (struct cmd_tx_offload_get_configuration_result,
17409                  port, "port");
17410 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
17411         TOKEN_NUM_INITIALIZER
17412                 (struct cmd_tx_offload_get_configuration_result,
17413                  port_id, UINT16);
17414 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
17415         TOKEN_STRING_INITIALIZER
17416                 (struct cmd_tx_offload_get_configuration_result,
17417                  tx_offload, "tx_offload");
17418 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
17419         TOKEN_STRING_INITIALIZER
17420                 (struct cmd_tx_offload_get_configuration_result,
17421                  configuration, "configuration");
17422
17423 static void
17424 cmd_tx_offload_get_configuration_parsed(
17425         void *parsed_result,
17426         __attribute__((unused)) struct cmdline *cl,
17427         __attribute__((unused)) void *data)
17428 {
17429         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
17430         struct rte_eth_dev_info dev_info;
17431         portid_t port_id = res->port_id;
17432         struct rte_port *port = &ports[port_id];
17433         uint64_t port_offloads;
17434         uint64_t queue_offloads;
17435         uint16_t nb_tx_queues;
17436         int q;
17437
17438         printf("Tx Offloading Configuration of port %d :\n", port_id);
17439
17440         port_offloads = port->dev_conf.txmode.offloads;
17441         printf("  Port :");
17442         print_tx_offloads(port_offloads);
17443         printf("\n");
17444
17445         rte_eth_dev_info_get(port_id, &dev_info);
17446         nb_tx_queues = dev_info.nb_tx_queues;
17447         for (q = 0; q < nb_tx_queues; q++) {
17448                 queue_offloads = port->tx_conf[q].offloads;
17449                 printf("  Queue[%2d] :", q);
17450                 print_tx_offloads(queue_offloads);
17451                 printf("\n");
17452         }
17453         printf("\n");
17454 }
17455
17456 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17457         .f = cmd_tx_offload_get_configuration_parsed,
17458         .data = NULL,
17459         .help_str = "show port <port_id> tx_offload configuration",
17460         .tokens = {
17461                 (void *)&cmd_tx_offload_get_configuration_show,
17462                 (void *)&cmd_tx_offload_get_configuration_port,
17463                 (void *)&cmd_tx_offload_get_configuration_port_id,
17464                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17465                 (void *)&cmd_tx_offload_get_configuration_configuration,
17466                 NULL,
17467         }
17468 };
17469
17470 /* Enable/Disable a per port offloading */
17471 struct cmd_config_per_port_tx_offload_result {
17472         cmdline_fixed_string_t port;
17473         cmdline_fixed_string_t config;
17474         portid_t port_id;
17475         cmdline_fixed_string_t tx_offload;
17476         cmdline_fixed_string_t offload;
17477         cmdline_fixed_string_t on_off;
17478 };
17479
17480 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17481         TOKEN_STRING_INITIALIZER
17482                 (struct cmd_config_per_port_tx_offload_result,
17483                  port, "port");
17484 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17485         TOKEN_STRING_INITIALIZER
17486                 (struct cmd_config_per_port_tx_offload_result,
17487                  config, "config");
17488 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17489         TOKEN_NUM_INITIALIZER
17490                 (struct cmd_config_per_port_tx_offload_result,
17491                  port_id, UINT16);
17492 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17493         TOKEN_STRING_INITIALIZER
17494                 (struct cmd_config_per_port_tx_offload_result,
17495                  tx_offload, "tx_offload");
17496 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17497         TOKEN_STRING_INITIALIZER
17498                 (struct cmd_config_per_port_tx_offload_result,
17499                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17500                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17501                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17502                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17503                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
17504 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17505         TOKEN_STRING_INITIALIZER
17506                 (struct cmd_config_per_port_tx_offload_result,
17507                  on_off, "on#off");
17508
17509 static uint64_t
17510 search_tx_offload(const char *name)
17511 {
17512         uint64_t single_offload;
17513         const char *single_name;
17514         int found = 0;
17515         unsigned int bit;
17516
17517         single_offload = 1;
17518         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17519                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17520                 if (!strcasecmp(single_name, name)) {
17521                         found = 1;
17522                         break;
17523                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17524                         break;
17525                 else if (single_name == NULL)
17526                         break;
17527                 single_offload <<= 1;
17528         }
17529
17530         if (found)
17531                 return single_offload;
17532
17533         return 0;
17534 }
17535
17536 static void
17537 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17538                                 __attribute__((unused)) struct cmdline *cl,
17539                                 __attribute__((unused)) void *data)
17540 {
17541         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17542         portid_t port_id = res->port_id;
17543         struct rte_eth_dev_info dev_info;
17544         struct rte_port *port = &ports[port_id];
17545         uint64_t single_offload;
17546         uint16_t nb_tx_queues;
17547         int q;
17548
17549         if (port->port_status != RTE_PORT_STOPPED) {
17550                 printf("Error: Can't config offload when Port %d "
17551                        "is not stopped\n", port_id);
17552                 return;
17553         }
17554
17555         single_offload = search_tx_offload(res->offload);
17556         if (single_offload == 0) {
17557                 printf("Unknown offload name: %s\n", res->offload);
17558                 return;
17559         }
17560
17561         rte_eth_dev_info_get(port_id, &dev_info);
17562         nb_tx_queues = dev_info.nb_tx_queues;
17563         if (!strcmp(res->on_off, "on")) {
17564                 port->dev_conf.txmode.offloads |= single_offload;
17565                 for (q = 0; q < nb_tx_queues; q++)
17566                         port->tx_conf[q].offloads |= single_offload;
17567         } else {
17568                 port->dev_conf.txmode.offloads &= ~single_offload;
17569                 for (q = 0; q < nb_tx_queues; q++)
17570                         port->tx_conf[q].offloads &= ~single_offload;
17571         }
17572
17573         cmd_reconfig_device_queue(port_id, 1, 1);
17574 }
17575
17576 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17577         .f = cmd_config_per_port_tx_offload_parsed,
17578         .data = NULL,
17579         .help_str = "port config <port_id> tx_offload "
17580                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17581                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17582                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17583                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17584                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
17585                     "on|off",
17586         .tokens = {
17587                 (void *)&cmd_config_per_port_tx_offload_result_port,
17588                 (void *)&cmd_config_per_port_tx_offload_result_config,
17589                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17590                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17591                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17592                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17593                 NULL,
17594         }
17595 };
17596
17597 /* Enable/Disable a per queue offloading */
17598 struct cmd_config_per_queue_tx_offload_result {
17599         cmdline_fixed_string_t port;
17600         portid_t port_id;
17601         cmdline_fixed_string_t txq;
17602         uint16_t queue_id;
17603         cmdline_fixed_string_t tx_offload;
17604         cmdline_fixed_string_t offload;
17605         cmdline_fixed_string_t on_off;
17606 };
17607
17608 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17609         TOKEN_STRING_INITIALIZER
17610                 (struct cmd_config_per_queue_tx_offload_result,
17611                  port, "port");
17612 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17613         TOKEN_NUM_INITIALIZER
17614                 (struct cmd_config_per_queue_tx_offload_result,
17615                  port_id, UINT16);
17616 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17617         TOKEN_STRING_INITIALIZER
17618                 (struct cmd_config_per_queue_tx_offload_result,
17619                  txq, "txq");
17620 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17621         TOKEN_NUM_INITIALIZER
17622                 (struct cmd_config_per_queue_tx_offload_result,
17623                  queue_id, UINT16);
17624 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17625         TOKEN_STRING_INITIALIZER
17626                 (struct cmd_config_per_queue_tx_offload_result,
17627                  tx_offload, "tx_offload");
17628 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17629         TOKEN_STRING_INITIALIZER
17630                 (struct cmd_config_per_queue_tx_offload_result,
17631                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17632                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17633                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17634                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17635                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
17636 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17637         TOKEN_STRING_INITIALIZER
17638                 (struct cmd_config_per_queue_tx_offload_result,
17639                  on_off, "on#off");
17640
17641 static void
17642 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17643                                 __attribute__((unused)) struct cmdline *cl,
17644                                 __attribute__((unused)) void *data)
17645 {
17646         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17647         struct rte_eth_dev_info dev_info;
17648         portid_t port_id = res->port_id;
17649         uint16_t queue_id = res->queue_id;
17650         struct rte_port *port = &ports[port_id];
17651         uint64_t single_offload;
17652
17653         if (port->port_status != RTE_PORT_STOPPED) {
17654                 printf("Error: Can't config offload when Port %d "
17655                        "is not stopped\n", port_id);
17656                 return;
17657         }
17658
17659         rte_eth_dev_info_get(port_id, &dev_info);
17660         if (queue_id >= dev_info.nb_tx_queues) {
17661                 printf("Error: input queue_id should be 0 ... "
17662                        "%d\n", dev_info.nb_tx_queues - 1);
17663                 return;
17664         }
17665
17666         single_offload = search_tx_offload(res->offload);
17667         if (single_offload == 0) {
17668                 printf("Unknown offload name: %s\n", res->offload);
17669                 return;
17670         }
17671
17672         if (!strcmp(res->on_off, "on"))
17673                 port->tx_conf[queue_id].offloads |= single_offload;
17674         else
17675                 port->tx_conf[queue_id].offloads &= ~single_offload;
17676
17677         cmd_reconfig_device_queue(port_id, 1, 1);
17678 }
17679
17680 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17681         .f = cmd_config_per_queue_tx_offload_parsed,
17682         .data = NULL,
17683         .help_str = "port <port_id> txq <queue_id> tx_offload "
17684                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17685                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17686                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17687                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17688                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
17689                     "on|off",
17690         .tokens = {
17691                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17692                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17693                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17694                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17695                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17696                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17697                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17698                 NULL,
17699         }
17700 };
17701
17702 /* ******************************************************************************** */
17703
17704 /* list of instructions */
17705 cmdline_parse_ctx_t main_ctx[] = {
17706         (cmdline_parse_inst_t *)&cmd_help_brief,
17707         (cmdline_parse_inst_t *)&cmd_help_long,
17708         (cmdline_parse_inst_t *)&cmd_quit,
17709         (cmdline_parse_inst_t *)&cmd_load_from_file,
17710         (cmdline_parse_inst_t *)&cmd_showport,
17711         (cmdline_parse_inst_t *)&cmd_showqueue,
17712         (cmdline_parse_inst_t *)&cmd_showportall,
17713         (cmdline_parse_inst_t *)&cmd_showcfg,
17714         (cmdline_parse_inst_t *)&cmd_start,
17715         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17716         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17717         (cmdline_parse_inst_t *)&cmd_set_link_up,
17718         (cmdline_parse_inst_t *)&cmd_set_link_down,
17719         (cmdline_parse_inst_t *)&cmd_reset,
17720         (cmdline_parse_inst_t *)&cmd_set_numbers,
17721         (cmdline_parse_inst_t *)&cmd_set_log,
17722         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17723         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17724         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17725         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17726         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17727         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17728         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17729         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17730         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17731         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17732         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17733         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17734         (cmdline_parse_inst_t *)&cmd_set_link_check,
17735         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17736         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17737         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17738         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17739 #ifdef RTE_LIBRTE_PMD_BOND
17740         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17741         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17742         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17743         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17744         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17745         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17746         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17747         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17748         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17749         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17750         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17751 #endif
17752         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17753         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17754         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17755         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17756         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17757         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17758         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17759         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17760         (cmdline_parse_inst_t *)&cmd_csum_set,
17761         (cmdline_parse_inst_t *)&cmd_csum_show,
17762         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17763         (cmdline_parse_inst_t *)&cmd_tso_set,
17764         (cmdline_parse_inst_t *)&cmd_tso_show,
17765         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17766         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17767         (cmdline_parse_inst_t *)&cmd_gro_enable,
17768         (cmdline_parse_inst_t *)&cmd_gro_flush,
17769         (cmdline_parse_inst_t *)&cmd_gro_show,
17770         (cmdline_parse_inst_t *)&cmd_gso_enable,
17771         (cmdline_parse_inst_t *)&cmd_gso_size,
17772         (cmdline_parse_inst_t *)&cmd_gso_show,
17773         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17774         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17775         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17776         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17777         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17778         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17779         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17780         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17781         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17782         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17783         (cmdline_parse_inst_t *)&cmd_config_dcb,
17784         (cmdline_parse_inst_t *)&cmd_read_reg,
17785         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17786         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17787         (cmdline_parse_inst_t *)&cmd_write_reg,
17788         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17789         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17790         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17791         (cmdline_parse_inst_t *)&cmd_stop,
17792         (cmdline_parse_inst_t *)&cmd_mac_addr,
17793         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17794         (cmdline_parse_inst_t *)&cmd_set_qmap,
17795         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17796         (cmdline_parse_inst_t *)&cmd_operate_port,
17797         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17798         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17799         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17800         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17801         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17802         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17803         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17804         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17805         (cmdline_parse_inst_t *)&cmd_config_mtu,
17806         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17807         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17808         (cmdline_parse_inst_t *)&cmd_config_rss,
17809         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17810         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17811         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17812         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17813         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17814         (cmdline_parse_inst_t *)&cmd_showport_reta,
17815         (cmdline_parse_inst_t *)&cmd_config_burst,
17816         (cmdline_parse_inst_t *)&cmd_config_thresh,
17817         (cmdline_parse_inst_t *)&cmd_config_threshold,
17818         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17819         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17820         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17821         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17822         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17823         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17824         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17825         (cmdline_parse_inst_t *)&cmd_global_config,
17826         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17827         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17828         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17829         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17830         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17831         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17832         (cmdline_parse_inst_t *)&cmd_dump,
17833         (cmdline_parse_inst_t *)&cmd_dump_one,
17834         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17835         (cmdline_parse_inst_t *)&cmd_syn_filter,
17836         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17837         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17838         (cmdline_parse_inst_t *)&cmd_flex_filter,
17839         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17840         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17841         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17842         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17843         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17844         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17845         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17846         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17847         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17848         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17849         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17850         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17851         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17852         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17853         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17854         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17855         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17856         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17857         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17858         (cmdline_parse_inst_t *)&cmd_flow,
17859         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17860         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17861         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17862         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17863         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17864         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17865         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17866         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17867         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17868         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17869         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17870         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17871         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17872         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17873         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17874         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17875         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17876         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17877         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17878         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17879         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17880         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17881         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17882         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17883         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17884         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17885         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17886         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17887         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17888         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17889         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17890         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17891         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17892         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17893         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17894         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17895         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17896         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17897         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17898         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17899         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17900         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17901         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17902         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17903         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17904         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17905         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17906         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17907         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17908 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17909         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17910 #endif
17911         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17912         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17913         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17914         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17915         (cmdline_parse_inst_t *)&cmd_ddp_add,
17916         (cmdline_parse_inst_t *)&cmd_ddp_del,
17917         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17918         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17919         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17920         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17921         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17922         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17923         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17924         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17925         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17926         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17927
17928         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17929         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17930         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17931         (cmdline_parse_inst_t *)&cmd_queue_region,
17932         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17933         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17934         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17935         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17936         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17937         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17938         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17939         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17940         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17941         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17942         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17943         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17944         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17945         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17946         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17947         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17948         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17949         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17950         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17951         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17952         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17953         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17954         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17955         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17956         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17957         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17958         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17959         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17960         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17961         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17962         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17963         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17964 #ifdef RTE_LIBRTE_BPF
17965         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17966         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17967 #endif
17968         NULL,
17969 };
17970
17971 /* read cmdline commands from file */
17972 void
17973 cmdline_read_from_file(const char *filename)
17974 {
17975         struct cmdline *cl;
17976
17977         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17978         if (cl == NULL) {
17979                 printf("Failed to create file based cmdline context: %s\n",
17980                        filename);
17981                 return;
17982         }
17983
17984         cmdline_interact(cl);
17985         cmdline_quit(cl);
17986
17987         cmdline_free(cl);
17988
17989         printf("Read CLI commands from %s\n", filename);
17990 }
17991
17992 /* prompt function, called from main on MASTER lcore */
17993 void
17994 prompt(void)
17995 {
17996         /* initialize non-constant commands */
17997         cmd_set_fwd_mode_init();
17998         cmd_set_fwd_retry_mode_init();
17999
18000         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18001         if (testpmd_cl == NULL)
18002                 return;
18003         cmdline_interact(testpmd_cl);
18004         cmdline_stdin_exit(testpmd_cl);
18005 }
18006
18007 void
18008 prompt_exit(void)
18009 {
18010         if (testpmd_cl != NULL)
18011                 cmdline_quit(testpmd_cl);
18012 }
18013
18014 static void
18015 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18016 {
18017         if (id == (portid_t)RTE_PORT_ALL) {
18018                 portid_t pid;
18019
18020                 RTE_ETH_FOREACH_DEV(pid) {
18021                         /* check if need_reconfig has been set to 1 */
18022                         if (ports[pid].need_reconfig == 0)
18023                                 ports[pid].need_reconfig = dev;
18024                         /* check if need_reconfig_queues has been set to 1 */
18025                         if (ports[pid].need_reconfig_queues == 0)
18026                                 ports[pid].need_reconfig_queues = queue;
18027                 }
18028         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18029                 /* check if need_reconfig has been set to 1 */
18030                 if (ports[id].need_reconfig == 0)
18031                         ports[id].need_reconfig = dev;
18032                 /* check if need_reconfig_queues has been set to 1 */
18033                 if (ports[id].need_reconfig_queues == 0)
18034                         ports[id].need_reconfig_queues = queue;
18035         }
18036 }