app/testpmd: enable UDP GSO in csum engine
[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|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 rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
179                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
180                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
181                         "    Display the RSS hash functions and RSS hash key"
182                         " of port X\n\n"
183
184                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
185                         "    Clear information for port_id, or all.\n\n"
186
187                         "show (rxq|txq) info (port_id) (queue_id)\n"
188                         "    Display information for configured RX/TX queue.\n\n"
189
190                         "show config (rxtx|cores|fwd|txpkts)\n"
191                         "    Display the given configuration.\n\n"
192
193                         "read rxd (port_id) (queue_id) (rxd_id)\n"
194                         "    Display an RX descriptor of a port RX queue.\n\n"
195
196                         "read txd (port_id) (queue_id) (txd_id)\n"
197                         "    Display a TX descriptor of a port TX queue.\n\n"
198
199                         "ddp get list (port_id)\n"
200                         "    Get ddp profile info list\n\n"
201
202                         "ddp get info (profile_path)\n"
203                         "    Get ddp profile information.\n\n"
204
205                         "show vf stats (port_id) (vf_id)\n"
206                         "    Display a VF's statistics.\n\n"
207
208                         "clear vf stats (port_id) (vf_id)\n"
209                         "    Reset a VF's statistics.\n\n"
210
211                         "show port (port_id) pctype mapping\n"
212                         "    Get flow ptype to pctype mapping on a port\n\n"
213
214                         "show port meter stats (port_id) (meter_id) (clear)\n"
215                         "    Get meter stats on a port\n\n"
216                         "show port tm cap (port_id)\n"
217                         "       Display the port TM capability.\n\n"
218
219                         "show port tm level cap (port_id) (level_id)\n"
220                         "       Display the port TM hierarchical level capability.\n\n"
221
222                         "show port tm node cap (port_id) (node_id)\n"
223                         "       Display the port TM node capability.\n\n"
224
225                         "show port tm node type (port_id) (node_id)\n"
226                         "       Display the port TM node type.\n\n"
227
228                         "show port tm node stats (port_id) (node_id) (clear)\n"
229                         "       Display the port TM node stats.\n\n"
230
231                 );
232         }
233
234         if (show_all || !strcmp(res->section, "config")) {
235                 cmdline_printf(
236                         cl,
237                         "\n"
238                         "Configuration:\n"
239                         "--------------\n"
240                         "Configuration changes only become active when"
241                         " forwarding is started/restarted.\n\n"
242
243                         "set default\n"
244                         "    Reset forwarding to the default configuration.\n\n"
245
246                         "set verbose (level)\n"
247                         "    Set the debug verbosity level X.\n\n"
248
249                         "set log global|(type) (level)\n"
250                         "    Set the log level.\n\n"
251
252                         "set nbport (num)\n"
253                         "    Set number of ports.\n\n"
254
255                         "set nbcore (num)\n"
256                         "    Set number of cores.\n\n"
257
258                         "set coremask (mask)\n"
259                         "    Set the forwarding cores hexadecimal mask.\n\n"
260
261                         "set portmask (mask)\n"
262                         "    Set the forwarding ports hexadecimal mask.\n\n"
263
264                         "set burst (num)\n"
265                         "    Set number of packets per burst.\n\n"
266
267                         "set burst tx delay (microseconds) retry (num)\n"
268                         "    Set the transmit delay time and number of retries,"
269                         " effective when retry is enabled.\n\n"
270
271                         "set txpkts (x[,y]*)\n"
272                         "    Set the length of each segment of TXONLY"
273                         " and optionally CSUM packets.\n\n"
274
275                         "set txsplit (off|on|rand)\n"
276                         "    Set the split policy for the TX packets."
277                         " Right now only applicable for CSUM and TXONLY"
278                         " modes\n\n"
279
280                         "set corelist (x[,y]*)\n"
281                         "    Set the list of forwarding cores.\n\n"
282
283                         "set portlist (x[,y]*)\n"
284                         "    Set the list of forwarding ports.\n\n"
285
286                         "set tx loopback (port_id) (on|off)\n"
287                         "    Enable or disable tx loopback.\n\n"
288
289                         "set all queues drop (port_id) (on|off)\n"
290                         "    Set drop enable bit for all queues.\n\n"
291
292                         "set vf split drop (port_id) (vf_id) (on|off)\n"
293                         "    Set split drop enable bit for a VF from the PF.\n\n"
294
295                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
296                         "    Set MAC antispoof for a VF from the PF.\n\n"
297
298                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
299                         "    Enable MACsec offload.\n\n"
300
301                         "set macsec offload (port_id) off\n"
302                         "    Disable MACsec offload.\n\n"
303
304                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
305                         "    Configure MACsec secure connection (SC).\n\n"
306
307                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
308                         "    Configure MACsec secure association (SA).\n\n"
309
310                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
311                         "    Set VF broadcast for a VF from the PF.\n\n"
312
313                         "vlan set strip (on|off) (port_id)\n"
314                         "    Set the VLAN strip on a port.\n\n"
315
316                         "vlan set stripq (on|off) (port_id,queue_id)\n"
317                         "    Set the VLAN strip for a queue on a port.\n\n"
318
319                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
320                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
321
322                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
323                         "    Set VLAN insert for a VF from the PF.\n\n"
324
325                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
326                         "    Set VLAN antispoof for a VF from the PF.\n\n"
327
328                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN tag for a VF from the PF.\n\n"
330
331                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
332                         "    Set a VF's max bandwidth(Mbps).\n\n"
333
334                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
335                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
336
337                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
338                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
339
340                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
341                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
342
343                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
344                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
345
346                         "vlan set filter (on|off) (port_id)\n"
347                         "    Set the VLAN filter on a port.\n\n"
348
349                         "vlan set qinq (on|off) (port_id)\n"
350                         "    Set the VLAN QinQ (extended queue in queue)"
351                         " on a port.\n\n"
352
353                         "vlan set (inner|outer) tpid (value) (port_id)\n"
354                         "    Set the VLAN TPID for Packet Filtering on"
355                         " a port\n\n"
356
357                         "rx_vlan add (vlan_id|all) (port_id)\n"
358                         "    Add a vlan_id, or all identifiers, to the set"
359                         " of VLAN identifiers filtered by port_id.\n\n"
360
361                         "rx_vlan rm (vlan_id|all) (port_id)\n"
362                         "    Remove a vlan_id, or all identifiers, from the set"
363                         " of VLAN identifiers filtered by port_id.\n\n"
364
365                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
366                         "    Add a vlan_id, to the set of VLAN identifiers"
367                         "filtered for VF(s) from port_id.\n\n"
368
369                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
370                         "    Remove a vlan_id, to the set of VLAN identifiers"
371                         "filtered for VF(s) from port_id.\n\n"
372
373                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
374                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
375                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
376                         "   add a tunnel filter of a port.\n\n"
377
378                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
379                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
380                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
381                         "   remove a tunnel filter of a port.\n\n"
382
383                         "rx_vxlan_port add (udp_port) (port_id)\n"
384                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
385
386                         "rx_vxlan_port rm (udp_port) (port_id)\n"
387                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
390                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
391                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
392
393                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
394                         "    Set port based TX VLAN insertion.\n\n"
395
396                         "tx_vlan reset (port_id)\n"
397                         "    Disable hardware insertion of a VLAN header in"
398                         " packets sent on a port.\n\n"
399
400                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
401                         "    Select hardware or software calculation of the"
402                         " checksum when transmitting a packet using the"
403                         " csum forward engine.\n"
404                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
405                         "    outer-ip concerns the outer IP layer in"
406                         " case the packet is recognized as a tunnel packet by"
407                         " the forward engine (vxlan, gre and ipip are supported)\n"
408                         "    Please check the NIC datasheet for HW limits.\n\n"
409
410                         "csum parse-tunnel (on|off) (tx_port_id)\n"
411                         "    If disabled, treat tunnel packets as non-tunneled"
412                         " packets (treat inner headers as payload). The port\n"
413                         "    argument is the port used for TX in csum forward"
414                         " engine.\n\n"
415
416                         "csum show (port_id)\n"
417                         "    Display tx checksum offload configuration\n\n"
418
419                         "tso set (segsize) (portid)\n"
420                         "    Enable TCP Segmentation Offload in csum forward"
421                         " engine.\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "tso show (portid)"
425                         "    Display the status of TCP Segmentation Offload.\n\n"
426
427                         "set port (port_id) gro on|off\n"
428                         "    Enable or disable Generic Receive Offload in"
429                         " csum forwarding engine.\n\n"
430
431                         "show port (port_id) gro\n"
432                         "    Display GRO configuration.\n\n"
433
434                         "set gro flush (cycles)\n"
435                         "    Set the cycle to flush GROed packets from"
436                         " reassembly tables.\n\n"
437
438                         "set port (port_id) gso (on|off)"
439                         "    Enable or disable Generic Segmentation Offload in"
440                         " csum forwarding engine.\n\n"
441
442                         "set gso segsz (length)\n"
443                         "    Set max packet length for output GSO segments,"
444                         " including packet header and payload.\n\n"
445
446                         "show port (port_id) gso\n"
447                         "    Show GSO configuration.\n\n"
448
449                         "set fwd (%s)\n"
450                         "    Set packet forwarding mode.\n\n"
451
452                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
453                         "    Add a MAC address on port_id.\n\n"
454
455                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
456                         "    Remove a MAC address from port_id.\n\n"
457
458                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Set the default MAC address for port_id.\n\n"
460
461                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
462                         "    Add a MAC address for a VF on the port.\n\n"
463
464                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Set the MAC address for a VF from the PF.\n\n"
466
467                         "set eth-peer (port_id) (peer_addr)\n"
468                         "    set the peer address for certain port.\n\n"
469
470                         "set port (port_id) uta (mac_address|all) (on|off)\n"
471                         "    Add/Remove a or all unicast hash filter(s)"
472                         "from port X.\n\n"
473
474                         "set promisc (port_id|all) (on|off)\n"
475                         "    Set the promiscuous mode on port_id, or all.\n\n"
476
477                         "set allmulti (port_id|all) (on|off)\n"
478                         "    Set the allmulti mode on port_id, or all.\n\n"
479
480                         "set vf promisc (port_id) (vf_id) (on|off)\n"
481                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
482
483                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
484                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
487                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
488                         " (on|off) autoneg (on|off) (port_id)\n"
489                         "set flow_ctrl rx (on|off) (portid)\n"
490                         "set flow_ctrl tx (on|off) (portid)\n"
491                         "set flow_ctrl high_water (high_water) (portid)\n"
492                         "set flow_ctrl low_water (low_water) (portid)\n"
493                         "set flow_ctrl pause_time (pause_time) (portid)\n"
494                         "set flow_ctrl send_xon (send_xon) (portid)\n"
495                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
496                         "set flow_ctrl autoneg (on|off) (port_id)\n"
497                         "    Set the link flow control parameter on a port.\n\n"
498
499                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
500                         " (low_water) (pause_time) (priority) (port_id)\n"
501                         "    Set the priority flow control parameter on a"
502                         " port.\n\n"
503
504                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
505                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
506                         " queue on port.\n"
507                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
508                         " on port 0 to mapping 5.\n\n"
509
510                         "set xstats-hide-zero on|off\n"
511                         "    Set the option to hide the zero values"
512                         " for xstats display.\n"
513
514                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
515                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
516
517                         "set port (port_id) vf (vf_id) (mac_addr)"
518                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
519                         "   Add/Remove unicast or multicast MAC addr filter"
520                         " for a VF.\n\n"
521
522                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
523                         "|MPE) (on|off)\n"
524                         "    AUPE:accepts untagged VLAN;"
525                         "ROPE:accept unicast hash\n\n"
526                         "    BAM:accepts broadcast packets;"
527                         "MPE:accepts all multicast packets\n\n"
528                         "    Enable/Disable a VF receive mode of a port\n\n"
529
530                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
531                         "    Set rate limit for a queue of a port\n\n"
532
533                         "set port (port_id) vf (vf_id) rate (rate_num) "
534                         "queue_mask (queue_mask_value)\n"
535                         "    Set rate limit for queues in VF of a port\n\n"
536
537                         "set port (port_id) mirror-rule (rule_id)"
538                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
539                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
540                         "   Set pool or vlan type mirror rule on a port.\n"
541                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
542                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
543                         " to pool 0.\n\n"
544
545                         "set port (port_id) mirror-rule (rule_id)"
546                         " (uplink-mirror|downlink-mirror) dst-pool"
547                         " (pool_id) (on|off)\n"
548                         "   Set uplink or downlink type mirror rule on a port.\n"
549                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
550                         " 0 on' enable mirror income traffic to pool 0.\n\n"
551
552                         "reset port (port_id) mirror-rule (rule_id)\n"
553                         "   Reset a mirror rule.\n\n"
554
555                         "set flush_rx (on|off)\n"
556                         "   Flush (default) or don't flush RX streams before"
557                         " forwarding. Mainly used with PCAP drivers.\n\n"
558
559                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
560                         "   Set the bypass mode for the lowest port on bypass enabled"
561                         " NIC.\n\n"
562
563                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
564                         "mode (normal|bypass|isolate) (port_id)\n"
565                         "   Set the event required to initiate specified bypass mode for"
566                         " the lowest port on a bypass enabled NIC where:\n"
567                         "       timeout   = enable bypass after watchdog timeout.\n"
568                         "       os_on     = enable bypass when OS/board is powered on.\n"
569                         "       os_off    = enable bypass when OS/board is powered off.\n"
570                         "       power_on  = enable bypass when power supply is turned on.\n"
571                         "       power_off = enable bypass when power supply is turned off."
572                         "\n\n"
573
574                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
575                         "   Set the bypass watchdog timeout to 'n' seconds"
576                         " where 0 = instant.\n\n"
577
578                         "show bypass config (port_id)\n"
579                         "   Show the bypass configuration for a bypass enabled NIC"
580                         " using the lowest port on the NIC.\n\n"
581
582 #ifdef RTE_LIBRTE_PMD_BOND
583                         "create bonded device (mode) (socket)\n"
584                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
585
586                         "add bonding slave (slave_id) (port_id)\n"
587                         "       Add a slave device to a bonded device.\n\n"
588
589                         "remove bonding slave (slave_id) (port_id)\n"
590                         "       Remove a slave device from a bonded device.\n\n"
591
592                         "set bonding mode (value) (port_id)\n"
593                         "       Set the bonding mode on a bonded device.\n\n"
594
595                         "set bonding primary (slave_id) (port_id)\n"
596                         "       Set the primary slave for a bonded device.\n\n"
597
598                         "show bonding config (port_id)\n"
599                         "       Show the bonding config for port_id.\n\n"
600
601                         "set bonding mac_addr (port_id) (address)\n"
602                         "       Set the MAC address of a bonded device.\n\n"
603
604                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
605                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
606
607                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
608                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
609
610                         "set bonding mon_period (port_id) (value)\n"
611                         "       Set the bonding link status monitoring polling period in ms.\n\n"
612
613                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
614                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
615
616 #endif
617                         "set link-up port (port_id)\n"
618                         "       Set link up for a port.\n\n"
619
620                         "set link-down port (port_id)\n"
621                         "       Set link down for a port.\n\n"
622
623                         "E-tag set insertion on port-tag-id (value)"
624                         " port (port_id) vf (vf_id)\n"
625                         "    Enable E-tag insertion for a VF on a port\n\n"
626
627                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
628                         "    Disable E-tag insertion for a VF on a port\n\n"
629
630                         "E-tag set stripping (on|off) port (port_id)\n"
631                         "    Enable/disable E-tag stripping on a port\n\n"
632
633                         "E-tag set forwarding (on|off) port (port_id)\n"
634                         "    Enable/disable E-tag based forwarding"
635                         " on a port\n\n"
636
637                         "E-tag set filter add e-tag-id (value) dst-pool"
638                         " (pool_id) port (port_id)\n"
639                         "    Add an E-tag forwarding filter on a port\n\n"
640
641                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
642                         "    Delete an E-tag forwarding filter on a port\n\n"
643
644 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
645                         "set port tm hierarchy default (port_id)\n"
646                         "       Set default traffic Management hierarchy on a port\n\n"
647
648 #endif
649                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
650                         "    Load a profile package on a port\n\n"
651
652                         "ddp del (port_id) (backup_profile_path)\n"
653                         "    Delete a profile package from a port\n\n"
654
655                         "ptype mapping get (port_id) (valid_only)\n"
656                         "    Get ptype mapping on a port\n\n"
657
658                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
659                         "    Replace target with the pkt_type in ptype mapping\n\n"
660
661                         "ptype mapping reset (port_id)\n"
662                         "    Reset ptype mapping on a port\n\n"
663
664                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
665                         "    Update a ptype mapping item on a port\n\n"
666
667                         "set port (port_id) queue-region region_id (value) "
668                         "queue_start_index (value) queue_num (value)\n"
669                         "    Set a queue region on a port\n\n"
670
671                         "set port (port_id) queue-region region_id (value) "
672                         "flowtype (value)\n"
673                         "    Set a flowtype region index on a port\n\n"
674
675                         "set port (port_id) queue-region UP (value) region_id (value)\n"
676                         "    Set the mapping of User Priority to "
677                         "queue region on a port\n\n"
678
679                         "set port (port_id) queue-region flush (on|off)\n"
680                         "    flush all queue region related configuration\n\n"
681
682                         "show port meter cap (port_id)\n"
683                         "    Show port meter capability information\n\n"
684
685                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
686                         "    meter profile add - srtcm rfc 2697\n\n"
687
688                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
689                         "    meter profile add - trtcm rfc 2698\n\n"
690
691                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
692                         "    meter profile add - trtcm rfc 4115\n\n"
693
694                         "del port meter profile (port_id) (profile_id)\n"
695                         "    meter profile delete\n\n"
696
697                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
698                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
699                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
700                         "(dscp_tbl_entry63)]\n"
701                         "    meter create\n\n"
702
703                         "enable port meter (port_id) (mtr_id)\n"
704                         "    meter enable\n\n"
705
706                         "disable port meter (port_id) (mtr_id)\n"
707                         "    meter disable\n\n"
708
709                         "del port meter (port_id) (mtr_id)\n"
710                         "    meter delete\n\n"
711
712                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
713                         "    meter update meter profile\n\n"
714
715                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
716                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
717                         "    update meter dscp table entries\n\n"
718
719                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
720                         "(action0) [(action1) (action2)]\n"
721                         "    meter update policer action\n\n"
722
723                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
724                         "    meter update stats\n\n"
725
726                         "show port (port_id) queue-region\n"
727                         "    show all queue region related configuration info\n\n"
728
729                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
730                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
731                         "       Add port tm node private shaper profile.\n\n"
732
733                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
734                         "       Delete port tm node private shaper profile.\n\n"
735
736                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
737                         " (shaper_profile_id)\n"
738                         "       Add/update port tm node shared shaper.\n\n"
739
740                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
741                         "       Delete port tm node shared shaper.\n\n"
742
743                         "set port tm node shaper profile (port_id) (node_id)"
744                         " (shaper_profile_id)\n"
745                         "       Set port tm node shaper profile.\n\n"
746
747                         "add port tm node wred profile (port_id) (wred_profile_id)"
748                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
749                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
750                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
751                         "       Add port tm node wred profile.\n\n"
752
753                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
754                         "       Delete port tm node wred profile.\n\n"
755
756                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
757                         " (priority) (weight) (level_id) (shaper_profile_id)"
758                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
759                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
760                         "       Add port tm nonleaf node.\n\n"
761
762                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
763                         " (priority) (weight) (level_id) (shaper_profile_id)"
764                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
765                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
766                         "       Add port tm leaf node.\n\n"
767
768                         "del port tm node (port_id) (node_id)\n"
769                         "       Delete port tm node.\n\n"
770
771                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
772                         " (priority) (weight)\n"
773                         "       Set port tm node parent.\n\n"
774
775                         "suspend port tm node (port_id) (node_id)"
776                         "       Suspend tm node.\n\n"
777
778                         "resume port tm node (port_id) (node_id)"
779                         "       Resume tm node.\n\n"
780
781                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
782                         "       Commit tm hierarchy.\n\n"
783
784                         , list_pkt_forwarding_modes()
785                 );
786         }
787
788         if (show_all || !strcmp(res->section, "ports")) {
789
790                 cmdline_printf(
791                         cl,
792                         "\n"
793                         "Port Operations:\n"
794                         "----------------\n\n"
795
796                         "port start (port_id|all)\n"
797                         "    Start all ports or port_id.\n\n"
798
799                         "port stop (port_id|all)\n"
800                         "    Stop all ports or port_id.\n\n"
801
802                         "port close (port_id|all)\n"
803                         "    Close all ports or port_id.\n\n"
804
805                         "port attach (ident)\n"
806                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
807
808                         "port detach (port_id)\n"
809                         "    Detach physical or virtual dev by port_id\n\n"
810
811                         "port config (port_id|all)"
812                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
813                         " duplex (half|full|auto)\n"
814                         "    Set speed and duplex for all ports or port_id\n\n"
815
816                         "port config (port_id|all) loopback (mode)\n"
817                         "    Set loopback mode for all ports or port_id\n\n"
818
819                         "port config all (rxq|txq|rxd|txd) (value)\n"
820                         "    Set number for rxq/txq/rxd/txd.\n\n"
821
822                         "port config all max-pkt-len (value)\n"
823                         "    Set the max packet length.\n\n"
824
825                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
826                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
827                         " (on|off)\n"
828                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
829                         " for ports.\n\n"
830
831                         "port config all rss (all|default|ip|tcp|udp|sctp|"
832                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
833                         "    Set the RSS mode.\n\n"
834
835                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
836                         "    Set the RSS redirection table.\n\n"
837
838                         "port config (port_id) dcb vt (on|off) (traffic_class)"
839                         " pfc (on|off)\n"
840                         "    Set the DCB mode.\n\n"
841
842                         "port config all burst (value)\n"
843                         "    Set the number of packets per burst.\n\n"
844
845                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
846                         " (value)\n"
847                         "    Set the ring prefetch/host/writeback threshold"
848                         " for tx/rx queue.\n\n"
849
850                         "port config all (txfreet|txrst|rxfreet) (value)\n"
851                         "    Set free threshold for rx/tx, or set"
852                         " tx rs bit threshold.\n\n"
853                         "port config mtu X value\n"
854                         "    Set the MTU of port X to a given value\n\n"
855
856                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
857                         "    Set a rx/tx queue's ring size configuration, the new"
858                         " value will take effect after command that (re-)start the port"
859                         " or command that setup the specific queue\n\n"
860
861                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
862                         "    Start/stop a rx/tx queue of port X. Only take effect"
863                         " when port X is started\n\n"
864
865                         "port (port_id) (rxq|txq) (queue_id) setup\n"
866                         "    Setup a rx/tx queue of port X.\n\n"
867
868                         "port config (port_id|all) l2-tunnel E-tag ether-type"
869                         " (value)\n"
870                         "    Set the value of E-tag ether-type.\n\n"
871
872                         "port config (port_id|all) l2-tunnel E-tag"
873                         " (enable|disable)\n"
874                         "    Enable/disable the E-tag support.\n\n"
875
876                         "port config (port_id) pctype mapping reset\n"
877                         "    Reset flow type to pctype mapping on a port\n\n"
878
879                         "port config (port_id) pctype mapping update"
880                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
881                         "    Update a flow type to pctype mapping item on a port\n\n"
882
883                         "port config (port_id) pctype (pctype_id) hash_inset|"
884                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
885                         " (field_idx)\n"
886                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
887
888                         "port config (port_id) pctype (pctype_id) hash_inset|"
889                         "fdir_inset|fdir_flx_inset clear all"
890                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
891
892                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
893                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
894                 );
895         }
896
897         if (show_all || !strcmp(res->section, "registers")) {
898
899                 cmdline_printf(
900                         cl,
901                         "\n"
902                         "Registers:\n"
903                         "----------\n\n"
904
905                         "read reg (port_id) (address)\n"
906                         "    Display value of a port register.\n\n"
907
908                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
909                         "    Display a port register bit field.\n\n"
910
911                         "read regbit (port_id) (address) (bit_x)\n"
912                         "    Display a single port register bit.\n\n"
913
914                         "write reg (port_id) (address) (value)\n"
915                         "    Set value of a port register.\n\n"
916
917                         "write regfield (port_id) (address) (bit_x) (bit_y)"
918                         " (value)\n"
919                         "    Set bit field of a port register.\n\n"
920
921                         "write regbit (port_id) (address) (bit_x) (value)\n"
922                         "    Set single bit value of a port register.\n\n"
923                 );
924         }
925         if (show_all || !strcmp(res->section, "filters")) {
926
927                 cmdline_printf(
928                         cl,
929                         "\n"
930                         "filters:\n"
931                         "--------\n\n"
932
933                         "ethertype_filter (port_id) (add|del)"
934                         " (mac_addr|mac_ignr) (mac_address) ethertype"
935                         " (ether_type) (drop|fwd) queue (queue_id)\n"
936                         "    Add/Del an ethertype filter.\n\n"
937
938                         "2tuple_filter (port_id) (add|del)"
939                         " dst_port (dst_port_value) protocol (protocol_value)"
940                         " mask (mask_value) tcp_flags (tcp_flags_value)"
941                         " priority (prio_value) queue (queue_id)\n"
942                         "    Add/Del a 2tuple filter.\n\n"
943
944                         "5tuple_filter (port_id) (add|del)"
945                         " dst_ip (dst_address) src_ip (src_address)"
946                         " dst_port (dst_port_value) src_port (src_port_value)"
947                         " protocol (protocol_value)"
948                         " mask (mask_value) tcp_flags (tcp_flags_value)"
949                         " priority (prio_value) queue (queue_id)\n"
950                         "    Add/Del a 5tuple filter.\n\n"
951
952                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
953                         "    Add/Del syn filter.\n\n"
954
955                         "flex_filter (port_id) (add|del) len (len_value)"
956                         " bytes (bytes_value) mask (mask_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a flex filter.\n\n"
959
960                         "flow_director_filter (port_id) mode IP (add|del|update)"
961                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
962                         " src (src_ip_address) dst (dst_ip_address)"
963                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an IP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tos (tos_value) ttl (ttl_value)"
974                         " vlan (vlan_value) flexbytes (flexbytes_value)"
975                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
976                         " fd_id (fd_id_value)\n"
977                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
978
979                         "flow_director_filter (port_id) mode IP (add|del|update)"
980                         " flow (ipv4-sctp|ipv6-sctp)"
981                         " src (src_ip_address) (src_port)"
982                         " dst (dst_ip_address) (dst_port)"
983                         " tag (verification_tag) "
984                         " tos (tos_value) ttl (ttl_value)"
985                         " vlan (vlan_value)"
986                         " flexbytes (flexbytes_value) (drop|fwd)"
987                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
988                         "    Add/Del a SCTP type flow director filter.\n\n"
989
990                         "flow_director_filter (port_id) mode IP (add|del|update)"
991                         " flow l2_payload ether (ethertype)"
992                         " flexbytes (flexbytes_value) (drop|fwd)"
993                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
994                         "    Add/Del a l2 payload type flow director filter.\n\n"
995
996                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
997                         " mac (mac_address) vlan (vlan_value)"
998                         " flexbytes (flexbytes_value) (drop|fwd)"
999                         " queue (queue_id) fd_id (fd_id_value)\n"
1000                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1003                         " mac (mac_address) vlan (vlan_value)"
1004                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1005                         " flexbytes (flexbytes_value) (drop|fwd)"
1006                         " queue (queue_id) fd_id (fd_id_value)\n"
1007                         "    Add/Del a Tunnel flow director filter.\n\n"
1008
1009                         "flow_director_filter (port_id) mode raw (add|del|update)"
1010                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1011                         " fd_id (fd_id_value) packet (packet file name)\n"
1012                         "    Add/Del a raw type flow director filter.\n\n"
1013
1014                         "flush_flow_director (port_id)\n"
1015                         "    Flush all flow director entries of a device.\n\n"
1016
1017                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1018                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1019                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1020                         "    Set flow director IP mask.\n\n"
1021
1022                         "flow_director_mask (port_id) mode MAC-VLAN"
1023                         " vlan (vlan_value)\n"
1024                         "    Set flow director MAC-VLAN mask.\n\n"
1025
1026                         "flow_director_mask (port_id) mode Tunnel"
1027                         " vlan (vlan_value) mac (mac_value)"
1028                         " tunnel-type (tunnel_type_value)"
1029                         " tunnel-id (tunnel_id_value)\n"
1030                         "    Set flow director Tunnel mask.\n\n"
1031
1032                         "flow_director_flex_mask (port_id)"
1033                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1034                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1035                         " (mask)\n"
1036                         "    Configure mask of flex payload.\n\n"
1037
1038                         "flow_director_flex_payload (port_id)"
1039                         " (raw|l2|l3|l4) (config)\n"
1040                         "    Configure flex payload selection.\n\n"
1041
1042                         "get_sym_hash_ena_per_port (port_id)\n"
1043                         "    get symmetric hash enable configuration per port.\n\n"
1044
1045                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1046                         "    set symmetric hash enable configuration per port"
1047                         " to enable or disable.\n\n"
1048
1049                         "get_hash_global_config (port_id)\n"
1050                         "    Get the global configurations of hash filters.\n\n"
1051
1052                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1053                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1054                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1055                         " (enable|disable)\n"
1056                         "    Set the global configurations of hash filters.\n\n"
1057
1058                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1059                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1060                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1061                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1062                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1063                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1064                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1065                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1066                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1067                         "fld-8th|none) (select|add)\n"
1068                         "    Set the input set for hash.\n\n"
1069
1070                         "set_fdir_input_set (port_id) "
1071                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1072                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1073                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1074                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1075                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1076                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1077                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1078                         " (select|add)\n"
1079                         "    Set the input set for FDir.\n\n"
1080
1081                         "flow validate {port_id}"
1082                         " [group {group_id}] [priority {level}]"
1083                         " [ingress] [egress]"
1084                         " pattern {item} [/ {item} [...]] / end"
1085                         " actions {action} [/ {action} [...]] / end\n"
1086                         "    Check whether a flow rule can be created.\n\n"
1087
1088                         "flow create {port_id}"
1089                         " [group {group_id}] [priority {level}]"
1090                         " [ingress] [egress]"
1091                         " pattern {item} [/ {item} [...]] / end"
1092                         " actions {action} [/ {action} [...]] / end\n"
1093                         "    Create a flow rule.\n\n"
1094
1095                         "flow destroy {port_id} rule {rule_id} [...]\n"
1096                         "    Destroy specific flow rules.\n\n"
1097
1098                         "flow flush {port_id}\n"
1099                         "    Destroy all flow rules.\n\n"
1100
1101                         "flow query {port_id} {rule_id} {action}\n"
1102                         "    Query an existing flow rule.\n\n"
1103
1104                         "flow list {port_id} [group {group_id}] [...]\n"
1105                         "    List existing flow rules sorted by priority,"
1106                         " filtered by group identifiers.\n\n"
1107
1108                         "flow isolate {port_id} {boolean}\n"
1109                         "    Restrict ingress traffic to the defined"
1110                         " flow rules\n\n"
1111                 );
1112         }
1113 }
1114
1115 cmdline_parse_token_string_t cmd_help_long_help =
1116         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1117
1118 cmdline_parse_token_string_t cmd_help_long_section =
1119         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1120                         "all#control#display#config#"
1121                         "ports#registers#filters");
1122
1123 cmdline_parse_inst_t cmd_help_long = {
1124         .f = cmd_help_long_parsed,
1125         .data = NULL,
1126         .help_str = "help all|control|display|config|ports|register|filters: "
1127                 "Show help",
1128         .tokens = {
1129                 (void *)&cmd_help_long_help,
1130                 (void *)&cmd_help_long_section,
1131                 NULL,
1132         },
1133 };
1134
1135
1136 /* *** start/stop/close all ports *** */
1137 struct cmd_operate_port_result {
1138         cmdline_fixed_string_t keyword;
1139         cmdline_fixed_string_t name;
1140         cmdline_fixed_string_t value;
1141 };
1142
1143 static void cmd_operate_port_parsed(void *parsed_result,
1144                                 __attribute__((unused)) struct cmdline *cl,
1145                                 __attribute__((unused)) void *data)
1146 {
1147         struct cmd_operate_port_result *res = parsed_result;
1148
1149         if (!strcmp(res->name, "start"))
1150                 start_port(RTE_PORT_ALL);
1151         else if (!strcmp(res->name, "stop"))
1152                 stop_port(RTE_PORT_ALL);
1153         else if (!strcmp(res->name, "close"))
1154                 close_port(RTE_PORT_ALL);
1155         else if (!strcmp(res->name, "reset"))
1156                 reset_port(RTE_PORT_ALL);
1157         else
1158                 printf("Unknown parameter\n");
1159 }
1160
1161 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1162         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1163                                                                 "port");
1164 cmdline_parse_token_string_t cmd_operate_port_all_port =
1165         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1166                                                 "start#stop#close#reset");
1167 cmdline_parse_token_string_t cmd_operate_port_all_all =
1168         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1169
1170 cmdline_parse_inst_t cmd_operate_port = {
1171         .f = cmd_operate_port_parsed,
1172         .data = NULL,
1173         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1174         .tokens = {
1175                 (void *)&cmd_operate_port_all_cmd,
1176                 (void *)&cmd_operate_port_all_port,
1177                 (void *)&cmd_operate_port_all_all,
1178                 NULL,
1179         },
1180 };
1181
1182 /* *** start/stop/close specific port *** */
1183 struct cmd_operate_specific_port_result {
1184         cmdline_fixed_string_t keyword;
1185         cmdline_fixed_string_t name;
1186         uint8_t value;
1187 };
1188
1189 static void cmd_operate_specific_port_parsed(void *parsed_result,
1190                         __attribute__((unused)) struct cmdline *cl,
1191                                 __attribute__((unused)) void *data)
1192 {
1193         struct cmd_operate_specific_port_result *res = parsed_result;
1194
1195         if (!strcmp(res->name, "start"))
1196                 start_port(res->value);
1197         else if (!strcmp(res->name, "stop"))
1198                 stop_port(res->value);
1199         else if (!strcmp(res->name, "close"))
1200                 close_port(res->value);
1201         else if (!strcmp(res->name, "reset"))
1202                 reset_port(res->value);
1203         else
1204                 printf("Unknown parameter\n");
1205 }
1206
1207 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1208         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1209                                                         keyword, "port");
1210 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1211         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1212                                                 name, "start#stop#close#reset");
1213 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1214         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1215                                                         value, UINT8);
1216
1217 cmdline_parse_inst_t cmd_operate_specific_port = {
1218         .f = cmd_operate_specific_port_parsed,
1219         .data = NULL,
1220         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1221         .tokens = {
1222                 (void *)&cmd_operate_specific_port_cmd,
1223                 (void *)&cmd_operate_specific_port_port,
1224                 (void *)&cmd_operate_specific_port_id,
1225                 NULL,
1226         },
1227 };
1228
1229 /* *** attach a specified port *** */
1230 struct cmd_operate_attach_port_result {
1231         cmdline_fixed_string_t port;
1232         cmdline_fixed_string_t keyword;
1233         cmdline_fixed_string_t identifier;
1234 };
1235
1236 static void cmd_operate_attach_port_parsed(void *parsed_result,
1237                                 __attribute__((unused)) struct cmdline *cl,
1238                                 __attribute__((unused)) void *data)
1239 {
1240         struct cmd_operate_attach_port_result *res = parsed_result;
1241
1242         if (!strcmp(res->keyword, "attach"))
1243                 attach_port(res->identifier);
1244         else
1245                 printf("Unknown parameter\n");
1246 }
1247
1248 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1249         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1250                         port, "port");
1251 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1252         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1253                         keyword, "attach");
1254 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1256                         identifier, NULL);
1257
1258 cmdline_parse_inst_t cmd_operate_attach_port = {
1259         .f = cmd_operate_attach_port_parsed,
1260         .data = NULL,
1261         .help_str = "port attach <identifier>: "
1262                 "(identifier: pci address or virtual dev name)",
1263         .tokens = {
1264                 (void *)&cmd_operate_attach_port_port,
1265                 (void *)&cmd_operate_attach_port_keyword,
1266                 (void *)&cmd_operate_attach_port_identifier,
1267                 NULL,
1268         },
1269 };
1270
1271 /* *** detach a specified port *** */
1272 struct cmd_operate_detach_port_result {
1273         cmdline_fixed_string_t port;
1274         cmdline_fixed_string_t keyword;
1275         portid_t port_id;
1276 };
1277
1278 static void cmd_operate_detach_port_parsed(void *parsed_result,
1279                                 __attribute__((unused)) struct cmdline *cl,
1280                                 __attribute__((unused)) void *data)
1281 {
1282         struct cmd_operate_detach_port_result *res = parsed_result;
1283
1284         if (!strcmp(res->keyword, "detach"))
1285                 detach_port(res->port_id);
1286         else
1287                 printf("Unknown parameter\n");
1288 }
1289
1290 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1291         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1292                         port, "port");
1293 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1294         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1295                         keyword, "detach");
1296 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1297         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1298                         port_id, UINT16);
1299
1300 cmdline_parse_inst_t cmd_operate_detach_port = {
1301         .f = cmd_operate_detach_port_parsed,
1302         .data = NULL,
1303         .help_str = "port detach <port_id>",
1304         .tokens = {
1305                 (void *)&cmd_operate_detach_port_port,
1306                 (void *)&cmd_operate_detach_port_keyword,
1307                 (void *)&cmd_operate_detach_port_port_id,
1308                 NULL,
1309         },
1310 };
1311
1312 /* *** configure speed for all ports *** */
1313 struct cmd_config_speed_all {
1314         cmdline_fixed_string_t port;
1315         cmdline_fixed_string_t keyword;
1316         cmdline_fixed_string_t all;
1317         cmdline_fixed_string_t item1;
1318         cmdline_fixed_string_t item2;
1319         cmdline_fixed_string_t value1;
1320         cmdline_fixed_string_t value2;
1321 };
1322
1323 static int
1324 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1325 {
1326
1327         int duplex;
1328
1329         if (!strcmp(duplexstr, "half")) {
1330                 duplex = ETH_LINK_HALF_DUPLEX;
1331         } else if (!strcmp(duplexstr, "full")) {
1332                 duplex = ETH_LINK_FULL_DUPLEX;
1333         } else if (!strcmp(duplexstr, "auto")) {
1334                 duplex = ETH_LINK_FULL_DUPLEX;
1335         } else {
1336                 printf("Unknown duplex parameter\n");
1337                 return -1;
1338         }
1339
1340         if (!strcmp(speedstr, "10")) {
1341                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1342                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1343         } else if (!strcmp(speedstr, "100")) {
1344                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1345                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1346         } else {
1347                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1348                         printf("Invalid speed/duplex parameters\n");
1349                         return -1;
1350                 }
1351                 if (!strcmp(speedstr, "1000")) {
1352                         *speed = ETH_LINK_SPEED_1G;
1353                 } else if (!strcmp(speedstr, "10000")) {
1354                         *speed = ETH_LINK_SPEED_10G;
1355                 } else if (!strcmp(speedstr, "25000")) {
1356                         *speed = ETH_LINK_SPEED_25G;
1357                 } else if (!strcmp(speedstr, "40000")) {
1358                         *speed = ETH_LINK_SPEED_40G;
1359                 } else if (!strcmp(speedstr, "50000")) {
1360                         *speed = ETH_LINK_SPEED_50G;
1361                 } else if (!strcmp(speedstr, "100000")) {
1362                         *speed = ETH_LINK_SPEED_100G;
1363                 } else if (!strcmp(speedstr, "auto")) {
1364                         *speed = ETH_LINK_SPEED_AUTONEG;
1365                 } else {
1366                         printf("Unknown speed parameter\n");
1367                         return -1;
1368                 }
1369         }
1370
1371         return 0;
1372 }
1373
1374 static void
1375 cmd_config_speed_all_parsed(void *parsed_result,
1376                         __attribute__((unused)) struct cmdline *cl,
1377                         __attribute__((unused)) void *data)
1378 {
1379         struct cmd_config_speed_all *res = parsed_result;
1380         uint32_t link_speed;
1381         portid_t pid;
1382
1383         if (!all_ports_stopped()) {
1384                 printf("Please stop all ports first\n");
1385                 return;
1386         }
1387
1388         if (parse_and_check_speed_duplex(res->value1, res->value2,
1389                         &link_speed) < 0)
1390                 return;
1391
1392         RTE_ETH_FOREACH_DEV(pid) {
1393                 ports[pid].dev_conf.link_speeds = link_speed;
1394         }
1395
1396         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1397 }
1398
1399 cmdline_parse_token_string_t cmd_config_speed_all_port =
1400         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1401 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1402         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1403                                                         "config");
1404 cmdline_parse_token_string_t cmd_config_speed_all_all =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1406 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1407         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1408 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1409         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1410                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1411 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1412         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1413 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1414         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1415                                                 "half#full#auto");
1416
1417 cmdline_parse_inst_t cmd_config_speed_all = {
1418         .f = cmd_config_speed_all_parsed,
1419         .data = NULL,
1420         .help_str = "port config all speed "
1421                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1422                                                         "half|full|auto",
1423         .tokens = {
1424                 (void *)&cmd_config_speed_all_port,
1425                 (void *)&cmd_config_speed_all_keyword,
1426                 (void *)&cmd_config_speed_all_all,
1427                 (void *)&cmd_config_speed_all_item1,
1428                 (void *)&cmd_config_speed_all_value1,
1429                 (void *)&cmd_config_speed_all_item2,
1430                 (void *)&cmd_config_speed_all_value2,
1431                 NULL,
1432         },
1433 };
1434
1435 /* *** configure speed for specific port *** */
1436 struct cmd_config_speed_specific {
1437         cmdline_fixed_string_t port;
1438         cmdline_fixed_string_t keyword;
1439         portid_t id;
1440         cmdline_fixed_string_t item1;
1441         cmdline_fixed_string_t item2;
1442         cmdline_fixed_string_t value1;
1443         cmdline_fixed_string_t value2;
1444 };
1445
1446 static void
1447 cmd_config_speed_specific_parsed(void *parsed_result,
1448                                 __attribute__((unused)) struct cmdline *cl,
1449                                 __attribute__((unused)) void *data)
1450 {
1451         struct cmd_config_speed_specific *res = parsed_result;
1452         uint32_t link_speed;
1453
1454         if (!all_ports_stopped()) {
1455                 printf("Please stop all ports first\n");
1456                 return;
1457         }
1458
1459         if (port_id_is_invalid(res->id, ENABLED_WARN))
1460                 return;
1461
1462         if (parse_and_check_speed_duplex(res->value1, res->value2,
1463                         &link_speed) < 0)
1464                 return;
1465
1466         ports[res->id].dev_conf.link_speeds = link_speed;
1467
1468         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1469 }
1470
1471
1472 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1473         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1474                                                                 "port");
1475 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1476         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1477                                                                 "config");
1478 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1479         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1480 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1482                                                                 "speed");
1483 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1484         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1485                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1486 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1488                                                                 "duplex");
1489 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1490         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1491                                                         "half#full#auto");
1492
1493 cmdline_parse_inst_t cmd_config_speed_specific = {
1494         .f = cmd_config_speed_specific_parsed,
1495         .data = NULL,
1496         .help_str = "port config <port_id> speed "
1497                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1498                                                         "half|full|auto",
1499         .tokens = {
1500                 (void *)&cmd_config_speed_specific_port,
1501                 (void *)&cmd_config_speed_specific_keyword,
1502                 (void *)&cmd_config_speed_specific_id,
1503                 (void *)&cmd_config_speed_specific_item1,
1504                 (void *)&cmd_config_speed_specific_value1,
1505                 (void *)&cmd_config_speed_specific_item2,
1506                 (void *)&cmd_config_speed_specific_value2,
1507                 NULL,
1508         },
1509 };
1510
1511 /* *** configure loopback for all ports *** */
1512 struct cmd_config_loopback_all {
1513         cmdline_fixed_string_t port;
1514         cmdline_fixed_string_t keyword;
1515         cmdline_fixed_string_t all;
1516         cmdline_fixed_string_t item;
1517         uint32_t mode;
1518 };
1519
1520 static void
1521 cmd_config_loopback_all_parsed(void *parsed_result,
1522                         __attribute__((unused)) struct cmdline *cl,
1523                         __attribute__((unused)) void *data)
1524 {
1525         struct cmd_config_loopback_all *res = parsed_result;
1526         portid_t pid;
1527
1528         if (!all_ports_stopped()) {
1529                 printf("Please stop all ports first\n");
1530                 return;
1531         }
1532
1533         RTE_ETH_FOREACH_DEV(pid) {
1534                 ports[pid].dev_conf.lpbk_mode = res->mode;
1535         }
1536
1537         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1538 }
1539
1540 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1541         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1542 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1543         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1544                                                         "config");
1545 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1546         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1547 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1548         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1549                                                         "loopback");
1550 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1551         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1552
1553 cmdline_parse_inst_t cmd_config_loopback_all = {
1554         .f = cmd_config_loopback_all_parsed,
1555         .data = NULL,
1556         .help_str = "port config all loopback <mode>",
1557         .tokens = {
1558                 (void *)&cmd_config_loopback_all_port,
1559                 (void *)&cmd_config_loopback_all_keyword,
1560                 (void *)&cmd_config_loopback_all_all,
1561                 (void *)&cmd_config_loopback_all_item,
1562                 (void *)&cmd_config_loopback_all_mode,
1563                 NULL,
1564         },
1565 };
1566
1567 /* *** configure loopback for specific port *** */
1568 struct cmd_config_loopback_specific {
1569         cmdline_fixed_string_t port;
1570         cmdline_fixed_string_t keyword;
1571         uint16_t port_id;
1572         cmdline_fixed_string_t item;
1573         uint32_t mode;
1574 };
1575
1576 static void
1577 cmd_config_loopback_specific_parsed(void *parsed_result,
1578                                 __attribute__((unused)) struct cmdline *cl,
1579                                 __attribute__((unused)) void *data)
1580 {
1581         struct cmd_config_loopback_specific *res = parsed_result;
1582
1583         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1584                 return;
1585
1586         if (!port_is_stopped(res->port_id)) {
1587                 printf("Please stop port %u first\n", res->port_id);
1588                 return;
1589         }
1590
1591         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1592
1593         cmd_reconfig_device_queue(res->port_id, 1, 1);
1594 }
1595
1596
1597 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1599                                                                 "port");
1600 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1601         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1602                                                                 "config");
1603 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1604         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1605                                                                 UINT16);
1606 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1607         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1608                                                                 "loopback");
1609 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1610         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1611                               UINT32);
1612
1613 cmdline_parse_inst_t cmd_config_loopback_specific = {
1614         .f = cmd_config_loopback_specific_parsed,
1615         .data = NULL,
1616         .help_str = "port config <port_id> loopback <mode>",
1617         .tokens = {
1618                 (void *)&cmd_config_loopback_specific_port,
1619                 (void *)&cmd_config_loopback_specific_keyword,
1620                 (void *)&cmd_config_loopback_specific_id,
1621                 (void *)&cmd_config_loopback_specific_item,
1622                 (void *)&cmd_config_loopback_specific_mode,
1623                 NULL,
1624         },
1625 };
1626
1627 /* *** configure txq/rxq, txd/rxd *** */
1628 struct cmd_config_rx_tx {
1629         cmdline_fixed_string_t port;
1630         cmdline_fixed_string_t keyword;
1631         cmdline_fixed_string_t all;
1632         cmdline_fixed_string_t name;
1633         uint16_t value;
1634 };
1635
1636 static void
1637 cmd_config_rx_tx_parsed(void *parsed_result,
1638                         __attribute__((unused)) struct cmdline *cl,
1639                         __attribute__((unused)) void *data)
1640 {
1641         struct cmd_config_rx_tx *res = parsed_result;
1642
1643         if (!all_ports_stopped()) {
1644                 printf("Please stop all ports first\n");
1645                 return;
1646         }
1647         if (!strcmp(res->name, "rxq")) {
1648                 if (!res->value && !nb_txq) {
1649                         printf("Warning: Either rx or tx queues should be non zero\n");
1650                         return;
1651                 }
1652                 if (check_nb_rxq(res->value) != 0)
1653                         return;
1654                 nb_rxq = res->value;
1655         }
1656         else if (!strcmp(res->name, "txq")) {
1657                 if (!res->value && !nb_rxq) {
1658                         printf("Warning: Either rx or tx queues should be non zero\n");
1659                         return;
1660                 }
1661                 if (check_nb_txq(res->value) != 0)
1662                         return;
1663                 nb_txq = res->value;
1664         }
1665         else if (!strcmp(res->name, "rxd")) {
1666                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1667                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1668                                         res->value, RTE_TEST_RX_DESC_MAX);
1669                         return;
1670                 }
1671                 nb_rxd = res->value;
1672         } else if (!strcmp(res->name, "txd")) {
1673                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1674                         printf("txd %d invalid - must be > 0 && <= %d\n",
1675                                         res->value, RTE_TEST_TX_DESC_MAX);
1676                         return;
1677                 }
1678                 nb_txd = res->value;
1679         } else {
1680                 printf("Unknown parameter\n");
1681                 return;
1682         }
1683
1684         fwd_config_setup();
1685
1686         init_port_config();
1687
1688         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1689 }
1690
1691 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1692         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1693 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1695 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1696         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1697 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1698         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1699                                                 "rxq#txq#rxd#txd");
1700 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1701         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1702
1703 cmdline_parse_inst_t cmd_config_rx_tx = {
1704         .f = cmd_config_rx_tx_parsed,
1705         .data = NULL,
1706         .help_str = "port config all rxq|txq|rxd|txd <value>",
1707         .tokens = {
1708                 (void *)&cmd_config_rx_tx_port,
1709                 (void *)&cmd_config_rx_tx_keyword,
1710                 (void *)&cmd_config_rx_tx_all,
1711                 (void *)&cmd_config_rx_tx_name,
1712                 (void *)&cmd_config_rx_tx_value,
1713                 NULL,
1714         },
1715 };
1716
1717 /* *** config max packet length *** */
1718 struct cmd_config_max_pkt_len_result {
1719         cmdline_fixed_string_t port;
1720         cmdline_fixed_string_t keyword;
1721         cmdline_fixed_string_t all;
1722         cmdline_fixed_string_t name;
1723         uint32_t value;
1724 };
1725
1726 static void
1727 cmd_config_max_pkt_len_parsed(void *parsed_result,
1728                                 __attribute__((unused)) struct cmdline *cl,
1729                                 __attribute__((unused)) void *data)
1730 {
1731         struct cmd_config_max_pkt_len_result *res = parsed_result;
1732         portid_t pid;
1733
1734         if (!all_ports_stopped()) {
1735                 printf("Please stop all ports first\n");
1736                 return;
1737         }
1738
1739         RTE_ETH_FOREACH_DEV(pid) {
1740                 struct rte_port *port = &ports[pid];
1741                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1742
1743                 if (!strcmp(res->name, "max-pkt-len")) {
1744                         if (res->value < ETHER_MIN_LEN) {
1745                                 printf("max-pkt-len can not be less than %d\n",
1746                                                 ETHER_MIN_LEN);
1747                                 return;
1748                         }
1749                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1750                                 return;
1751
1752                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1753                         if (res->value > ETHER_MAX_LEN)
1754                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1755                         else
1756                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1757                         port->dev_conf.rxmode.offloads = rx_offloads;
1758                 } else {
1759                         printf("Unknown parameter\n");
1760                         return;
1761                 }
1762         }
1763
1764         init_port_config();
1765
1766         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1767 }
1768
1769 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1770         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1771                                                                 "port");
1772 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1774                                                                 "config");
1775 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1777                                                                 "all");
1778 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1779         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1780                                                                 "max-pkt-len");
1781 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1782         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1783                                                                 UINT32);
1784
1785 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1786         .f = cmd_config_max_pkt_len_parsed,
1787         .data = NULL,
1788         .help_str = "port config all max-pkt-len <value>",
1789         .tokens = {
1790                 (void *)&cmd_config_max_pkt_len_port,
1791                 (void *)&cmd_config_max_pkt_len_keyword,
1792                 (void *)&cmd_config_max_pkt_len_all,
1793                 (void *)&cmd_config_max_pkt_len_name,
1794                 (void *)&cmd_config_max_pkt_len_value,
1795                 NULL,
1796         },
1797 };
1798
1799 /* *** configure port MTU *** */
1800 struct cmd_config_mtu_result {
1801         cmdline_fixed_string_t port;
1802         cmdline_fixed_string_t keyword;
1803         cmdline_fixed_string_t mtu;
1804         portid_t port_id;
1805         uint16_t value;
1806 };
1807
1808 static void
1809 cmd_config_mtu_parsed(void *parsed_result,
1810                       __attribute__((unused)) struct cmdline *cl,
1811                       __attribute__((unused)) void *data)
1812 {
1813         struct cmd_config_mtu_result *res = parsed_result;
1814
1815         if (res->value < ETHER_MIN_LEN) {
1816                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1817                 return;
1818         }
1819         port_mtu_set(res->port_id, res->value);
1820 }
1821
1822 cmdline_parse_token_string_t cmd_config_mtu_port =
1823         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1824                                  "port");
1825 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1826         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1827                                  "config");
1828 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1829         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1830                                  "mtu");
1831 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1832         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1833 cmdline_parse_token_num_t cmd_config_mtu_value =
1834         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1835
1836 cmdline_parse_inst_t cmd_config_mtu = {
1837         .f = cmd_config_mtu_parsed,
1838         .data = NULL,
1839         .help_str = "port config mtu <port_id> <value>",
1840         .tokens = {
1841                 (void *)&cmd_config_mtu_port,
1842                 (void *)&cmd_config_mtu_keyword,
1843                 (void *)&cmd_config_mtu_mtu,
1844                 (void *)&cmd_config_mtu_port_id,
1845                 (void *)&cmd_config_mtu_value,
1846                 NULL,
1847         },
1848 };
1849
1850 /* *** configure rx mode *** */
1851 struct cmd_config_rx_mode_flag {
1852         cmdline_fixed_string_t port;
1853         cmdline_fixed_string_t keyword;
1854         cmdline_fixed_string_t all;
1855         cmdline_fixed_string_t name;
1856         cmdline_fixed_string_t value;
1857 };
1858
1859 static void
1860 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1861                                 __attribute__((unused)) struct cmdline *cl,
1862                                 __attribute__((unused)) void *data)
1863 {
1864         struct cmd_config_rx_mode_flag *res = parsed_result;
1865         portid_t pid;
1866
1867         if (!all_ports_stopped()) {
1868                 printf("Please stop all ports first\n");
1869                 return;
1870         }
1871
1872         RTE_ETH_FOREACH_DEV(pid) {
1873                 struct rte_port *port;
1874                 uint64_t rx_offloads;
1875
1876                 port = &ports[pid];
1877                 rx_offloads = port->dev_conf.rxmode.offloads;
1878                 if (!strcmp(res->name, "crc-strip")) {
1879                         if (!strcmp(res->value, "on"))
1880                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1881                         else if (!strcmp(res->value, "off"))
1882                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1883                         else {
1884                                 printf("Unknown parameter\n");
1885                                 return;
1886                         }
1887                 } else if (!strcmp(res->name, "scatter")) {
1888                         if (!strcmp(res->value, "on")) {
1889                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1890                         } else if (!strcmp(res->value, "off")) {
1891                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1892                         } else {
1893                                 printf("Unknown parameter\n");
1894                                 return;
1895                         }
1896                 } else if (!strcmp(res->name, "rx-cksum")) {
1897                         if (!strcmp(res->value, "on"))
1898                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1899                         else if (!strcmp(res->value, "off"))
1900                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1901                         else {
1902                                 printf("Unknown parameter\n");
1903                                 return;
1904                         }
1905                 } else if (!strcmp(res->name, "rx-timestamp")) {
1906                         if (!strcmp(res->value, "on"))
1907                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1908                         else if (!strcmp(res->value, "off"))
1909                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1910                         else {
1911                                 printf("Unknown parameter\n");
1912                                 return;
1913                         }
1914                 } else if (!strcmp(res->name, "hw-vlan")) {
1915                         if (!strcmp(res->value, "on")) {
1916                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1917                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1918                         } else if (!strcmp(res->value, "off")) {
1919                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1920                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1921                         } else {
1922                                 printf("Unknown parameter\n");
1923                                 return;
1924                         }
1925                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1926                         if (!strcmp(res->value, "on"))
1927                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1928                         else if (!strcmp(res->value, "off"))
1929                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1930                         else {
1931                                 printf("Unknown parameter\n");
1932                                 return;
1933                         }
1934                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1935                         if (!strcmp(res->value, "on"))
1936                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1937                         else if (!strcmp(res->value, "off"))
1938                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1939                         else {
1940                                 printf("Unknown parameter\n");
1941                                 return;
1942                         }
1943                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1944                         if (!strcmp(res->value, "on"))
1945                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1946                         else if (!strcmp(res->value, "off"))
1947                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1948                         else {
1949                                 printf("Unknown parameter\n");
1950                                 return;
1951                         }
1952                 } else if (!strcmp(res->name, "drop-en")) {
1953                         if (!strcmp(res->value, "on"))
1954                                 rx_drop_en = 1;
1955                         else if (!strcmp(res->value, "off"))
1956                                 rx_drop_en = 0;
1957                         else {
1958                                 printf("Unknown parameter\n");
1959                                 return;
1960                         }
1961                 } else {
1962                         printf("Unknown parameter\n");
1963                         return;
1964                 }
1965                 port->dev_conf.rxmode.offloads = rx_offloads;
1966         }
1967
1968         init_port_config();
1969
1970         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1971 }
1972
1973 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1974         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1975 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1976         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1977                                                                 "config");
1978 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1979         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1980 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1981         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1982                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1983                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1984 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1985         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1986                                                         "on#off");
1987
1988 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1989         .f = cmd_config_rx_mode_flag_parsed,
1990         .data = NULL,
1991         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1992                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1993         .tokens = {
1994                 (void *)&cmd_config_rx_mode_flag_port,
1995                 (void *)&cmd_config_rx_mode_flag_keyword,
1996                 (void *)&cmd_config_rx_mode_flag_all,
1997                 (void *)&cmd_config_rx_mode_flag_name,
1998                 (void *)&cmd_config_rx_mode_flag_value,
1999                 NULL,
2000         },
2001 };
2002
2003 /* *** configure rss *** */
2004 struct cmd_config_rss {
2005         cmdline_fixed_string_t port;
2006         cmdline_fixed_string_t keyword;
2007         cmdline_fixed_string_t all;
2008         cmdline_fixed_string_t name;
2009         cmdline_fixed_string_t value;
2010 };
2011
2012 static void
2013 cmd_config_rss_parsed(void *parsed_result,
2014                         __attribute__((unused)) struct cmdline *cl,
2015                         __attribute__((unused)) void *data)
2016 {
2017         struct cmd_config_rss *res = parsed_result;
2018         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2019         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2020         int use_default = 0;
2021         int all_updated = 1;
2022         int diag;
2023         uint16_t i;
2024
2025         if (!strcmp(res->value, "all"))
2026                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2027                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2028                                         ETH_RSS_L2_PAYLOAD;
2029         else if (!strcmp(res->value, "ip"))
2030                 rss_conf.rss_hf = ETH_RSS_IP;
2031         else if (!strcmp(res->value, "udp"))
2032                 rss_conf.rss_hf = ETH_RSS_UDP;
2033         else if (!strcmp(res->value, "tcp"))
2034                 rss_conf.rss_hf = ETH_RSS_TCP;
2035         else if (!strcmp(res->value, "sctp"))
2036                 rss_conf.rss_hf = ETH_RSS_SCTP;
2037         else if (!strcmp(res->value, "ether"))
2038                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2039         else if (!strcmp(res->value, "port"))
2040                 rss_conf.rss_hf = ETH_RSS_PORT;
2041         else if (!strcmp(res->value, "vxlan"))
2042                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2043         else if (!strcmp(res->value, "geneve"))
2044                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2045         else if (!strcmp(res->value, "nvgre"))
2046                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2047         else if (!strcmp(res->value, "none"))
2048                 rss_conf.rss_hf = 0;
2049         else if (!strcmp(res->value, "default"))
2050                 use_default = 1;
2051         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2052                                                 atoi(res->value) < 64)
2053                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2054         else {
2055                 printf("Unknown parameter\n");
2056                 return;
2057         }
2058         rss_conf.rss_key = NULL;
2059         /* Update global configuration for RSS types. */
2060         RTE_ETH_FOREACH_DEV(i) {
2061                 struct rte_eth_rss_conf local_rss_conf;
2062
2063                 rte_eth_dev_info_get(i, &dev_info);
2064                 if (use_default)
2065                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2066
2067                 local_rss_conf = rss_conf;
2068                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2069                         dev_info.flow_type_rss_offloads;
2070                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2071                         printf("Port %u modified RSS hash function based on hardware support,"
2072                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2073                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2074                 }
2075                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2076                 if (diag < 0) {
2077                         all_updated = 0;
2078                         printf("Configuration of RSS hash at ethernet port %d "
2079                                 "failed with error (%d): %s.\n",
2080                                 i, -diag, strerror(-diag));
2081                 }
2082         }
2083         if (all_updated && !use_default)
2084                 rss_hf = rss_conf.rss_hf;
2085 }
2086
2087 cmdline_parse_token_string_t cmd_config_rss_port =
2088         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2089 cmdline_parse_token_string_t cmd_config_rss_keyword =
2090         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2091 cmdline_parse_token_string_t cmd_config_rss_all =
2092         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2093 cmdline_parse_token_string_t cmd_config_rss_name =
2094         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2095 cmdline_parse_token_string_t cmd_config_rss_value =
2096         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2097
2098 cmdline_parse_inst_t cmd_config_rss = {
2099         .f = cmd_config_rss_parsed,
2100         .data = NULL,
2101         .help_str = "port config all rss "
2102                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2103         .tokens = {
2104                 (void *)&cmd_config_rss_port,
2105                 (void *)&cmd_config_rss_keyword,
2106                 (void *)&cmd_config_rss_all,
2107                 (void *)&cmd_config_rss_name,
2108                 (void *)&cmd_config_rss_value,
2109                 NULL,
2110         },
2111 };
2112
2113 /* *** configure rss hash key *** */
2114 struct cmd_config_rss_hash_key {
2115         cmdline_fixed_string_t port;
2116         cmdline_fixed_string_t config;
2117         portid_t port_id;
2118         cmdline_fixed_string_t rss_hash_key;
2119         cmdline_fixed_string_t rss_type;
2120         cmdline_fixed_string_t key;
2121 };
2122
2123 static uint8_t
2124 hexa_digit_to_value(char hexa_digit)
2125 {
2126         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2127                 return (uint8_t) (hexa_digit - '0');
2128         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2129                 return (uint8_t) ((hexa_digit - 'a') + 10);
2130         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2131                 return (uint8_t) ((hexa_digit - 'A') + 10);
2132         /* Invalid hexa digit */
2133         return 0xFF;
2134 }
2135
2136 static uint8_t
2137 parse_and_check_key_hexa_digit(char *key, int idx)
2138 {
2139         uint8_t hexa_v;
2140
2141         hexa_v = hexa_digit_to_value(key[idx]);
2142         if (hexa_v == 0xFF)
2143                 printf("invalid key: character %c at position %d is not a "
2144                        "valid hexa digit\n", key[idx], idx);
2145         return hexa_v;
2146 }
2147
2148 static void
2149 cmd_config_rss_hash_key_parsed(void *parsed_result,
2150                                __attribute__((unused)) struct cmdline *cl,
2151                                __attribute__((unused)) void *data)
2152 {
2153         struct cmd_config_rss_hash_key *res = parsed_result;
2154         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2155         uint8_t xdgt0;
2156         uint8_t xdgt1;
2157         int i;
2158         struct rte_eth_dev_info dev_info;
2159         uint8_t hash_key_size;
2160         uint32_t key_len;
2161
2162         memset(&dev_info, 0, sizeof(dev_info));
2163         rte_eth_dev_info_get(res->port_id, &dev_info);
2164         if (dev_info.hash_key_size > 0 &&
2165                         dev_info.hash_key_size <= sizeof(hash_key))
2166                 hash_key_size = dev_info.hash_key_size;
2167         else {
2168                 printf("dev_info did not provide a valid hash key size\n");
2169                 return;
2170         }
2171         /* Check the length of the RSS hash key */
2172         key_len = strlen(res->key);
2173         if (key_len != (hash_key_size * 2)) {
2174                 printf("key length: %d invalid - key must be a string of %d"
2175                            " hexa-decimal numbers\n",
2176                            (int) key_len, hash_key_size * 2);
2177                 return;
2178         }
2179         /* Translate RSS hash key into binary representation */
2180         for (i = 0; i < hash_key_size; i++) {
2181                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2182                 if (xdgt0 == 0xFF)
2183                         return;
2184                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2185                 if (xdgt1 == 0xFF)
2186                         return;
2187                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2188         }
2189         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2190                         hash_key_size);
2191 }
2192
2193 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2194         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2195 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2196         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2197                                  "config");
2198 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2199         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2200 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2201         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2202                                  rss_hash_key, "rss-hash-key");
2203 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2204         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2205                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2206                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2207                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2208                                  "ipv6-tcp-ex#ipv6-udp-ex");
2209 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2210         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2211
2212 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2213         .f = cmd_config_rss_hash_key_parsed,
2214         .data = NULL,
2215         .help_str = "port config <port_id> rss-hash-key "
2216                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2217                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2218                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2219                 "<string of hex digits (variable length, NIC dependent)>",
2220         .tokens = {
2221                 (void *)&cmd_config_rss_hash_key_port,
2222                 (void *)&cmd_config_rss_hash_key_config,
2223                 (void *)&cmd_config_rss_hash_key_port_id,
2224                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2225                 (void *)&cmd_config_rss_hash_key_rss_type,
2226                 (void *)&cmd_config_rss_hash_key_value,
2227                 NULL,
2228         },
2229 };
2230
2231 /* *** configure port rxq/txq ring size *** */
2232 struct cmd_config_rxtx_ring_size {
2233         cmdline_fixed_string_t port;
2234         cmdline_fixed_string_t config;
2235         portid_t portid;
2236         cmdline_fixed_string_t rxtxq;
2237         uint16_t qid;
2238         cmdline_fixed_string_t rsize;
2239         uint16_t size;
2240 };
2241
2242 static void
2243 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2244                                  __attribute__((unused)) struct cmdline *cl,
2245                                  __attribute__((unused)) void *data)
2246 {
2247         struct cmd_config_rxtx_ring_size *res = parsed_result;
2248         struct rte_port *port;
2249         uint8_t isrx;
2250
2251         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2252                 return;
2253
2254         if (res->portid == (portid_t)RTE_PORT_ALL) {
2255                 printf("Invalid port id\n");
2256                 return;
2257         }
2258
2259         port = &ports[res->portid];
2260
2261         if (!strcmp(res->rxtxq, "rxq"))
2262                 isrx = 1;
2263         else if (!strcmp(res->rxtxq, "txq"))
2264                 isrx = 0;
2265         else {
2266                 printf("Unknown parameter\n");
2267                 return;
2268         }
2269
2270         if (isrx && rx_queue_id_is_invalid(res->qid))
2271                 return;
2272         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2273                 return;
2274
2275         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2276                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2277                        rx_free_thresh);
2278                 return;
2279         }
2280
2281         if (isrx)
2282                 port->nb_rx_desc[res->qid] = res->size;
2283         else
2284                 port->nb_tx_desc[res->qid] = res->size;
2285
2286         cmd_reconfig_device_queue(res->portid, 0, 1);
2287 }
2288
2289 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2290         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2291                                  port, "port");
2292 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2293         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2294                                  config, "config");
2295 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2296         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2297                                  portid, UINT16);
2298 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2300                                  rxtxq, "rxq#txq");
2301 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2302         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2303                               qid, UINT16);
2304 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2306                                  rsize, "ring_size");
2307 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2308         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2309                               size, UINT16);
2310
2311 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2312         .f = cmd_config_rxtx_ring_size_parsed,
2313         .data = NULL,
2314         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2315         .tokens = {
2316                 (void *)&cmd_config_rxtx_ring_size_port,
2317                 (void *)&cmd_config_rxtx_ring_size_config,
2318                 (void *)&cmd_config_rxtx_ring_size_portid,
2319                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2320                 (void *)&cmd_config_rxtx_ring_size_qid,
2321                 (void *)&cmd_config_rxtx_ring_size_rsize,
2322                 (void *)&cmd_config_rxtx_ring_size_size,
2323                 NULL,
2324         },
2325 };
2326
2327 /* *** configure port rxq/txq start/stop *** */
2328 struct cmd_config_rxtx_queue {
2329         cmdline_fixed_string_t port;
2330         portid_t portid;
2331         cmdline_fixed_string_t rxtxq;
2332         uint16_t qid;
2333         cmdline_fixed_string_t opname;
2334 };
2335
2336 static void
2337 cmd_config_rxtx_queue_parsed(void *parsed_result,
2338                         __attribute__((unused)) struct cmdline *cl,
2339                         __attribute__((unused)) void *data)
2340 {
2341         struct cmd_config_rxtx_queue *res = parsed_result;
2342         uint8_t isrx;
2343         uint8_t isstart;
2344         int ret = 0;
2345
2346         if (test_done == 0) {
2347                 printf("Please stop forwarding first\n");
2348                 return;
2349         }
2350
2351         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2352                 return;
2353
2354         if (port_is_started(res->portid) != 1) {
2355                 printf("Please start port %u first\n", res->portid);
2356                 return;
2357         }
2358
2359         if (!strcmp(res->rxtxq, "rxq"))
2360                 isrx = 1;
2361         else if (!strcmp(res->rxtxq, "txq"))
2362                 isrx = 0;
2363         else {
2364                 printf("Unknown parameter\n");
2365                 return;
2366         }
2367
2368         if (isrx && rx_queue_id_is_invalid(res->qid))
2369                 return;
2370         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2371                 return;
2372
2373         if (!strcmp(res->opname, "start"))
2374                 isstart = 1;
2375         else if (!strcmp(res->opname, "stop"))
2376                 isstart = 0;
2377         else {
2378                 printf("Unknown parameter\n");
2379                 return;
2380         }
2381
2382         if (isstart && isrx)
2383                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2384         else if (!isstart && isrx)
2385                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2386         else if (isstart && !isrx)
2387                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2388         else
2389                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2390
2391         if (ret == -ENOTSUP)
2392                 printf("Function not supported in PMD driver\n");
2393 }
2394
2395 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2396         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2397 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2398         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2399 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2401 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2402         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2403 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2404         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2405                                                 "start#stop");
2406
2407 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2408         .f = cmd_config_rxtx_queue_parsed,
2409         .data = NULL,
2410         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2411         .tokens = {
2412                 (void *)&cmd_config_rxtx_queue_port,
2413                 (void *)&cmd_config_rxtx_queue_portid,
2414                 (void *)&cmd_config_rxtx_queue_rxtxq,
2415                 (void *)&cmd_config_rxtx_queue_qid,
2416                 (void *)&cmd_config_rxtx_queue_opname,
2417                 NULL,
2418         },
2419 };
2420
2421 /* *** configure port rxq/txq setup *** */
2422 struct cmd_setup_rxtx_queue {
2423         cmdline_fixed_string_t port;
2424         portid_t portid;
2425         cmdline_fixed_string_t rxtxq;
2426         uint16_t qid;
2427         cmdline_fixed_string_t setup;
2428 };
2429
2430 /* Common CLI fields for queue setup */
2431 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2432         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2433 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2434         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2435 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2436         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2437 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2438         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2439 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2440         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2441
2442 static void
2443 cmd_setup_rxtx_queue_parsed(
2444         void *parsed_result,
2445         __attribute__((unused)) struct cmdline *cl,
2446         __attribute__((unused)) void *data)
2447 {
2448         struct cmd_setup_rxtx_queue *res = parsed_result;
2449         struct rte_port *port;
2450         struct rte_mempool *mp;
2451         unsigned int socket_id;
2452         uint8_t isrx = 0;
2453         int ret;
2454
2455         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2456                 return;
2457
2458         if (res->portid == (portid_t)RTE_PORT_ALL) {
2459                 printf("Invalid port id\n");
2460                 return;
2461         }
2462
2463         if (!strcmp(res->rxtxq, "rxq"))
2464                 isrx = 1;
2465         else if (!strcmp(res->rxtxq, "txq"))
2466                 isrx = 0;
2467         else {
2468                 printf("Unknown parameter\n");
2469                 return;
2470         }
2471
2472         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2473                 printf("Invalid rx queue\n");
2474                 return;
2475         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2476                 printf("Invalid tx queue\n");
2477                 return;
2478         }
2479
2480         port = &ports[res->portid];
2481         if (isrx) {
2482                 socket_id = rxring_numa[res->portid];
2483                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2484                         socket_id = port->socket_id;
2485
2486                 mp = mbuf_pool_find(socket_id);
2487                 if (mp == NULL) {
2488                         printf("Failed to setup RX queue: "
2489                                 "No mempool allocation"
2490                                 " on the socket %d\n",
2491                                 rxring_numa[res->portid]);
2492                         return;
2493                 }
2494                 ret = rte_eth_rx_queue_setup(res->portid,
2495                                              res->qid,
2496                                              port->nb_rx_desc[res->qid],
2497                                              socket_id,
2498                                              &port->rx_conf[res->qid],
2499                                              mp);
2500                 if (ret)
2501                         printf("Failed to setup RX queue\n");
2502         } else {
2503                 socket_id = txring_numa[res->portid];
2504                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2505                         socket_id = port->socket_id;
2506
2507                 ret = rte_eth_tx_queue_setup(res->portid,
2508                                              res->qid,
2509                                              port->nb_tx_desc[res->qid],
2510                                              socket_id,
2511                                              &port->tx_conf[res->qid]);
2512                 if (ret)
2513                         printf("Failed to setup TX queue\n");
2514         }
2515 }
2516
2517 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2518         .f = cmd_setup_rxtx_queue_parsed,
2519         .data = NULL,
2520         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2521         .tokens = {
2522                 (void *)&cmd_setup_rxtx_queue_port,
2523                 (void *)&cmd_setup_rxtx_queue_portid,
2524                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2525                 (void *)&cmd_setup_rxtx_queue_qid,
2526                 (void *)&cmd_setup_rxtx_queue_setup,
2527                 NULL,
2528         },
2529 };
2530
2531
2532 /* *** Configure RSS RETA *** */
2533 struct cmd_config_rss_reta {
2534         cmdline_fixed_string_t port;
2535         cmdline_fixed_string_t keyword;
2536         portid_t port_id;
2537         cmdline_fixed_string_t name;
2538         cmdline_fixed_string_t list_name;
2539         cmdline_fixed_string_t list_of_items;
2540 };
2541
2542 static int
2543 parse_reta_config(const char *str,
2544                   struct rte_eth_rss_reta_entry64 *reta_conf,
2545                   uint16_t nb_entries)
2546 {
2547         int i;
2548         unsigned size;
2549         uint16_t hash_index, idx, shift;
2550         uint16_t nb_queue;
2551         char s[256];
2552         const char *p, *p0 = str;
2553         char *end;
2554         enum fieldnames {
2555                 FLD_HASH_INDEX = 0,
2556                 FLD_QUEUE,
2557                 _NUM_FLD
2558         };
2559         unsigned long int_fld[_NUM_FLD];
2560         char *str_fld[_NUM_FLD];
2561
2562         while ((p = strchr(p0,'(')) != NULL) {
2563                 ++p;
2564                 if((p0 = strchr(p,')')) == NULL)
2565                         return -1;
2566
2567                 size = p0 - p;
2568                 if(size >= sizeof(s))
2569                         return -1;
2570
2571                 snprintf(s, sizeof(s), "%.*s", size, p);
2572                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2573                         return -1;
2574                 for (i = 0; i < _NUM_FLD; i++) {
2575                         errno = 0;
2576                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2577                         if (errno != 0 || end == str_fld[i] ||
2578                                         int_fld[i] > 65535)
2579                                 return -1;
2580                 }
2581
2582                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2583                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2584
2585                 if (hash_index >= nb_entries) {
2586                         printf("Invalid RETA hash index=%d\n", hash_index);
2587                         return -1;
2588                 }
2589
2590                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2591                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2592                 reta_conf[idx].mask |= (1ULL << shift);
2593                 reta_conf[idx].reta[shift] = nb_queue;
2594         }
2595
2596         return 0;
2597 }
2598
2599 static void
2600 cmd_set_rss_reta_parsed(void *parsed_result,
2601                         __attribute__((unused)) struct cmdline *cl,
2602                         __attribute__((unused)) void *data)
2603 {
2604         int ret;
2605         struct rte_eth_dev_info dev_info;
2606         struct rte_eth_rss_reta_entry64 reta_conf[8];
2607         struct cmd_config_rss_reta *res = parsed_result;
2608
2609         memset(&dev_info, 0, sizeof(dev_info));
2610         rte_eth_dev_info_get(res->port_id, &dev_info);
2611         if (dev_info.reta_size == 0) {
2612                 printf("Redirection table size is 0 which is "
2613                                         "invalid for RSS\n");
2614                 return;
2615         } else
2616                 printf("The reta size of port %d is %u\n",
2617                         res->port_id, dev_info.reta_size);
2618         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2619                 printf("Currently do not support more than %u entries of "
2620                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2621                 return;
2622         }
2623
2624         memset(reta_conf, 0, sizeof(reta_conf));
2625         if (!strcmp(res->list_name, "reta")) {
2626                 if (parse_reta_config(res->list_of_items, reta_conf,
2627                                                 dev_info.reta_size)) {
2628                         printf("Invalid RSS Redirection Table "
2629                                         "config entered\n");
2630                         return;
2631                 }
2632                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2633                                 reta_conf, dev_info.reta_size);
2634                 if (ret != 0)
2635                         printf("Bad redirection table parameter, "
2636                                         "return code = %d \n", ret);
2637         }
2638 }
2639
2640 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2641         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2642 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2643         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2644 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2645         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2646 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2647         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2648 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2649         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2650 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2651         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2652                                  NULL);
2653 cmdline_parse_inst_t cmd_config_rss_reta = {
2654         .f = cmd_set_rss_reta_parsed,
2655         .data = NULL,
2656         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2657         .tokens = {
2658                 (void *)&cmd_config_rss_reta_port,
2659                 (void *)&cmd_config_rss_reta_keyword,
2660                 (void *)&cmd_config_rss_reta_port_id,
2661                 (void *)&cmd_config_rss_reta_name,
2662                 (void *)&cmd_config_rss_reta_list_name,
2663                 (void *)&cmd_config_rss_reta_list_of_items,
2664                 NULL,
2665         },
2666 };
2667
2668 /* *** SHOW PORT RETA INFO *** */
2669 struct cmd_showport_reta {
2670         cmdline_fixed_string_t show;
2671         cmdline_fixed_string_t port;
2672         portid_t port_id;
2673         cmdline_fixed_string_t rss;
2674         cmdline_fixed_string_t reta;
2675         uint16_t size;
2676         cmdline_fixed_string_t list_of_items;
2677 };
2678
2679 static int
2680 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2681                            uint16_t nb_entries,
2682                            char *str)
2683 {
2684         uint32_t size;
2685         const char *p, *p0 = str;
2686         char s[256];
2687         char *end;
2688         char *str_fld[8];
2689         uint16_t i;
2690         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2691                         RTE_RETA_GROUP_SIZE;
2692         int ret;
2693
2694         p = strchr(p0, '(');
2695         if (p == NULL)
2696                 return -1;
2697         p++;
2698         p0 = strchr(p, ')');
2699         if (p0 == NULL)
2700                 return -1;
2701         size = p0 - p;
2702         if (size >= sizeof(s)) {
2703                 printf("The string size exceeds the internal buffer size\n");
2704                 return -1;
2705         }
2706         snprintf(s, sizeof(s), "%.*s", size, p);
2707         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2708         if (ret <= 0 || ret != num) {
2709                 printf("The bits of masks do not match the number of "
2710                                         "reta entries: %u\n", num);
2711                 return -1;
2712         }
2713         for (i = 0; i < ret; i++)
2714                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2715
2716         return 0;
2717 }
2718
2719 static void
2720 cmd_showport_reta_parsed(void *parsed_result,
2721                          __attribute__((unused)) struct cmdline *cl,
2722                          __attribute__((unused)) void *data)
2723 {
2724         struct cmd_showport_reta *res = parsed_result;
2725         struct rte_eth_rss_reta_entry64 reta_conf[8];
2726         struct rte_eth_dev_info dev_info;
2727         uint16_t max_reta_size;
2728
2729         memset(&dev_info, 0, sizeof(dev_info));
2730         rte_eth_dev_info_get(res->port_id, &dev_info);
2731         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2732         if (res->size == 0 || res->size > max_reta_size) {
2733                 printf("Invalid redirection table size: %u (1-%u)\n",
2734                         res->size, max_reta_size);
2735                 return;
2736         }
2737
2738         memset(reta_conf, 0, sizeof(reta_conf));
2739         if (showport_parse_reta_config(reta_conf, res->size,
2740                                 res->list_of_items) < 0) {
2741                 printf("Invalid string: %s for reta masks\n",
2742                                         res->list_of_items);
2743                 return;
2744         }
2745         port_rss_reta_info(res->port_id, reta_conf, res->size);
2746 }
2747
2748 cmdline_parse_token_string_t cmd_showport_reta_show =
2749         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2750 cmdline_parse_token_string_t cmd_showport_reta_port =
2751         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2752 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2753         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2754 cmdline_parse_token_string_t cmd_showport_reta_rss =
2755         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2756 cmdline_parse_token_string_t cmd_showport_reta_reta =
2757         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2758 cmdline_parse_token_num_t cmd_showport_reta_size =
2759         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2760 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2761         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2762                                         list_of_items, NULL);
2763
2764 cmdline_parse_inst_t cmd_showport_reta = {
2765         .f = cmd_showport_reta_parsed,
2766         .data = NULL,
2767         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2768         .tokens = {
2769                 (void *)&cmd_showport_reta_show,
2770                 (void *)&cmd_showport_reta_port,
2771                 (void *)&cmd_showport_reta_port_id,
2772                 (void *)&cmd_showport_reta_rss,
2773                 (void *)&cmd_showport_reta_reta,
2774                 (void *)&cmd_showport_reta_size,
2775                 (void *)&cmd_showport_reta_list_of_items,
2776                 NULL,
2777         },
2778 };
2779
2780 /* *** Show RSS hash configuration *** */
2781 struct cmd_showport_rss_hash {
2782         cmdline_fixed_string_t show;
2783         cmdline_fixed_string_t port;
2784         portid_t port_id;
2785         cmdline_fixed_string_t rss_hash;
2786         cmdline_fixed_string_t rss_type;
2787         cmdline_fixed_string_t key; /* optional argument */
2788 };
2789
2790 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2791                                 __attribute__((unused)) struct cmdline *cl,
2792                                 void *show_rss_key)
2793 {
2794         struct cmd_showport_rss_hash *res = parsed_result;
2795
2796         port_rss_hash_conf_show(res->port_id, res->rss_type,
2797                                 show_rss_key != NULL);
2798 }
2799
2800 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2801         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2802 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2803         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2804 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2805         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2806 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2807         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2808                                  "rss-hash");
2809 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2810         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2811                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2812                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2813                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2814                                  "ipv6-tcp-ex#ipv6-udp-ex");
2815 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2816         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2817
2818 cmdline_parse_inst_t cmd_showport_rss_hash = {
2819         .f = cmd_showport_rss_hash_parsed,
2820         .data = NULL,
2821         .help_str = "show port <port_id> rss-hash "
2822                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2823                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2824                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2825         .tokens = {
2826                 (void *)&cmd_showport_rss_hash_show,
2827                 (void *)&cmd_showport_rss_hash_port,
2828                 (void *)&cmd_showport_rss_hash_port_id,
2829                 (void *)&cmd_showport_rss_hash_rss_hash,
2830                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2831                 NULL,
2832         },
2833 };
2834
2835 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2836         .f = cmd_showport_rss_hash_parsed,
2837         .data = (void *)1,
2838         .help_str = "show port <port_id> rss-hash "
2839                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2840                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2841                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2842         .tokens = {
2843                 (void *)&cmd_showport_rss_hash_show,
2844                 (void *)&cmd_showport_rss_hash_port,
2845                 (void *)&cmd_showport_rss_hash_port_id,
2846                 (void *)&cmd_showport_rss_hash_rss_hash,
2847                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2848                 (void *)&cmd_showport_rss_hash_rss_key,
2849                 NULL,
2850         },
2851 };
2852
2853 /* *** Configure DCB *** */
2854 struct cmd_config_dcb {
2855         cmdline_fixed_string_t port;
2856         cmdline_fixed_string_t config;
2857         portid_t port_id;
2858         cmdline_fixed_string_t dcb;
2859         cmdline_fixed_string_t vt;
2860         cmdline_fixed_string_t vt_en;
2861         uint8_t num_tcs;
2862         cmdline_fixed_string_t pfc;
2863         cmdline_fixed_string_t pfc_en;
2864 };
2865
2866 static void
2867 cmd_config_dcb_parsed(void *parsed_result,
2868                         __attribute__((unused)) struct cmdline *cl,
2869                         __attribute__((unused)) void *data)
2870 {
2871         struct cmd_config_dcb *res = parsed_result;
2872         portid_t port_id = res->port_id;
2873         struct rte_port *port;
2874         uint8_t pfc_en;
2875         int ret;
2876
2877         port = &ports[port_id];
2878         /** Check if the port is not started **/
2879         if (port->port_status != RTE_PORT_STOPPED) {
2880                 printf("Please stop port %d first\n", port_id);
2881                 return;
2882         }
2883
2884         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2885                 printf("The invalid number of traffic class,"
2886                         " only 4 or 8 allowed.\n");
2887                 return;
2888         }
2889
2890         if (nb_fwd_lcores < res->num_tcs) {
2891                 printf("nb_cores shouldn't be less than number of TCs.\n");
2892                 return;
2893         }
2894         if (!strncmp(res->pfc_en, "on", 2))
2895                 pfc_en = 1;
2896         else
2897                 pfc_en = 0;
2898
2899         /* DCB in VT mode */
2900         if (!strncmp(res->vt_en, "on", 2))
2901                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2902                                 (enum rte_eth_nb_tcs)res->num_tcs,
2903                                 pfc_en);
2904         else
2905                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2906                                 (enum rte_eth_nb_tcs)res->num_tcs,
2907                                 pfc_en);
2908
2909
2910         if (ret != 0) {
2911                 printf("Cannot initialize network ports.\n");
2912                 return;
2913         }
2914
2915         cmd_reconfig_device_queue(port_id, 1, 1);
2916 }
2917
2918 cmdline_parse_token_string_t cmd_config_dcb_port =
2919         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2920 cmdline_parse_token_string_t cmd_config_dcb_config =
2921         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2922 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2923         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2924 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2925         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2926 cmdline_parse_token_string_t cmd_config_dcb_vt =
2927         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2928 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2929         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2930 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2931         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2932 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2933         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2934 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2935         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2936
2937 cmdline_parse_inst_t cmd_config_dcb = {
2938         .f = cmd_config_dcb_parsed,
2939         .data = NULL,
2940         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2941         .tokens = {
2942                 (void *)&cmd_config_dcb_port,
2943                 (void *)&cmd_config_dcb_config,
2944                 (void *)&cmd_config_dcb_port_id,
2945                 (void *)&cmd_config_dcb_dcb,
2946                 (void *)&cmd_config_dcb_vt,
2947                 (void *)&cmd_config_dcb_vt_en,
2948                 (void *)&cmd_config_dcb_num_tcs,
2949                 (void *)&cmd_config_dcb_pfc,
2950                 (void *)&cmd_config_dcb_pfc_en,
2951                 NULL,
2952         },
2953 };
2954
2955 /* *** configure number of packets per burst *** */
2956 struct cmd_config_burst {
2957         cmdline_fixed_string_t port;
2958         cmdline_fixed_string_t keyword;
2959         cmdline_fixed_string_t all;
2960         cmdline_fixed_string_t name;
2961         uint16_t value;
2962 };
2963
2964 static void
2965 cmd_config_burst_parsed(void *parsed_result,
2966                         __attribute__((unused)) struct cmdline *cl,
2967                         __attribute__((unused)) void *data)
2968 {
2969         struct cmd_config_burst *res = parsed_result;
2970         struct rte_eth_dev_info dev_info;
2971         uint16_t rec_nb_pkts;
2972
2973         if (!all_ports_stopped()) {
2974                 printf("Please stop all ports first\n");
2975                 return;
2976         }
2977
2978         if (!strcmp(res->name, "burst")) {
2979                 if (res->value == 0) {
2980                         /* If user gives a value of zero, query the PMD for
2981                          * its recommended Rx burst size. Testpmd uses a single
2982                          * size for all ports, so assume all ports are the same
2983                          * NIC model and use the values from Port 0.
2984                          */
2985                         rte_eth_dev_info_get(0, &dev_info);
2986                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2987
2988                         if (rec_nb_pkts == 0) {
2989                                 printf("PMD does not recommend a burst size.\n"
2990                                         "User provided value must be between"
2991                                         " 1 and %d\n", MAX_PKT_BURST);
2992                                 return;
2993                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2994                                 printf("PMD recommended burst size of %d"
2995                                         " exceeds maximum value of %d\n",
2996                                         rec_nb_pkts, MAX_PKT_BURST);
2997                                 return;
2998                         }
2999                         printf("Using PMD-provided burst value of %d\n",
3000                                 rec_nb_pkts);
3001                         nb_pkt_per_burst = rec_nb_pkts;
3002                 } else if (res->value > MAX_PKT_BURST) {
3003                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3004                         return;
3005                 } else
3006                         nb_pkt_per_burst = res->value;
3007         } else {
3008                 printf("Unknown parameter\n");
3009                 return;
3010         }
3011
3012         init_port_config();
3013
3014         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3015 }
3016
3017 cmdline_parse_token_string_t cmd_config_burst_port =
3018         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3019 cmdline_parse_token_string_t cmd_config_burst_keyword =
3020         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3021 cmdline_parse_token_string_t cmd_config_burst_all =
3022         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3023 cmdline_parse_token_string_t cmd_config_burst_name =
3024         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3025 cmdline_parse_token_num_t cmd_config_burst_value =
3026         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3027
3028 cmdline_parse_inst_t cmd_config_burst = {
3029         .f = cmd_config_burst_parsed,
3030         .data = NULL,
3031         .help_str = "port config all burst <value>",
3032         .tokens = {
3033                 (void *)&cmd_config_burst_port,
3034                 (void *)&cmd_config_burst_keyword,
3035                 (void *)&cmd_config_burst_all,
3036                 (void *)&cmd_config_burst_name,
3037                 (void *)&cmd_config_burst_value,
3038                 NULL,
3039         },
3040 };
3041
3042 /* *** configure rx/tx queues *** */
3043 struct cmd_config_thresh {
3044         cmdline_fixed_string_t port;
3045         cmdline_fixed_string_t keyword;
3046         cmdline_fixed_string_t all;
3047         cmdline_fixed_string_t name;
3048         uint8_t value;
3049 };
3050
3051 static void
3052 cmd_config_thresh_parsed(void *parsed_result,
3053                         __attribute__((unused)) struct cmdline *cl,
3054                         __attribute__((unused)) void *data)
3055 {
3056         struct cmd_config_thresh *res = parsed_result;
3057
3058         if (!all_ports_stopped()) {
3059                 printf("Please stop all ports first\n");
3060                 return;
3061         }
3062
3063         if (!strcmp(res->name, "txpt"))
3064                 tx_pthresh = res->value;
3065         else if(!strcmp(res->name, "txht"))
3066                 tx_hthresh = res->value;
3067         else if(!strcmp(res->name, "txwt"))
3068                 tx_wthresh = res->value;
3069         else if(!strcmp(res->name, "rxpt"))
3070                 rx_pthresh = res->value;
3071         else if(!strcmp(res->name, "rxht"))
3072                 rx_hthresh = res->value;
3073         else if(!strcmp(res->name, "rxwt"))
3074                 rx_wthresh = res->value;
3075         else {
3076                 printf("Unknown parameter\n");
3077                 return;
3078         }
3079
3080         init_port_config();
3081
3082         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3083 }
3084
3085 cmdline_parse_token_string_t cmd_config_thresh_port =
3086         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3087 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3088         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3089 cmdline_parse_token_string_t cmd_config_thresh_all =
3090         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3091 cmdline_parse_token_string_t cmd_config_thresh_name =
3092         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3093                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3094 cmdline_parse_token_num_t cmd_config_thresh_value =
3095         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3096
3097 cmdline_parse_inst_t cmd_config_thresh = {
3098         .f = cmd_config_thresh_parsed,
3099         .data = NULL,
3100         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3101         .tokens = {
3102                 (void *)&cmd_config_thresh_port,
3103                 (void *)&cmd_config_thresh_keyword,
3104                 (void *)&cmd_config_thresh_all,
3105                 (void *)&cmd_config_thresh_name,
3106                 (void *)&cmd_config_thresh_value,
3107                 NULL,
3108         },
3109 };
3110
3111 /* *** configure free/rs threshold *** */
3112 struct cmd_config_threshold {
3113         cmdline_fixed_string_t port;
3114         cmdline_fixed_string_t keyword;
3115         cmdline_fixed_string_t all;
3116         cmdline_fixed_string_t name;
3117         uint16_t value;
3118 };
3119
3120 static void
3121 cmd_config_threshold_parsed(void *parsed_result,
3122                         __attribute__((unused)) struct cmdline *cl,
3123                         __attribute__((unused)) void *data)
3124 {
3125         struct cmd_config_threshold *res = parsed_result;
3126
3127         if (!all_ports_stopped()) {
3128                 printf("Please stop all ports first\n");
3129                 return;
3130         }
3131
3132         if (!strcmp(res->name, "txfreet"))
3133                 tx_free_thresh = res->value;
3134         else if (!strcmp(res->name, "txrst"))
3135                 tx_rs_thresh = res->value;
3136         else if (!strcmp(res->name, "rxfreet"))
3137                 rx_free_thresh = res->value;
3138         else {
3139                 printf("Unknown parameter\n");
3140                 return;
3141         }
3142
3143         init_port_config();
3144
3145         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3146 }
3147
3148 cmdline_parse_token_string_t cmd_config_threshold_port =
3149         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3150 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3151         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3152                                                                 "config");
3153 cmdline_parse_token_string_t cmd_config_threshold_all =
3154         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3155 cmdline_parse_token_string_t cmd_config_threshold_name =
3156         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3157                                                 "txfreet#txrst#rxfreet");
3158 cmdline_parse_token_num_t cmd_config_threshold_value =
3159         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3160
3161 cmdline_parse_inst_t cmd_config_threshold = {
3162         .f = cmd_config_threshold_parsed,
3163         .data = NULL,
3164         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3165         .tokens = {
3166                 (void *)&cmd_config_threshold_port,
3167                 (void *)&cmd_config_threshold_keyword,
3168                 (void *)&cmd_config_threshold_all,
3169                 (void *)&cmd_config_threshold_name,
3170                 (void *)&cmd_config_threshold_value,
3171                 NULL,
3172         },
3173 };
3174
3175 /* *** stop *** */
3176 struct cmd_stop_result {
3177         cmdline_fixed_string_t stop;
3178 };
3179
3180 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3181                             __attribute__((unused)) struct cmdline *cl,
3182                             __attribute__((unused)) void *data)
3183 {
3184         stop_packet_forwarding();
3185 }
3186
3187 cmdline_parse_token_string_t cmd_stop_stop =
3188         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3189
3190 cmdline_parse_inst_t cmd_stop = {
3191         .f = cmd_stop_parsed,
3192         .data = NULL,
3193         .help_str = "stop: Stop packet forwarding",
3194         .tokens = {
3195                 (void *)&cmd_stop_stop,
3196                 NULL,
3197         },
3198 };
3199
3200 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3201
3202 unsigned int
3203 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3204                 unsigned int *parsed_items, int check_unique_values)
3205 {
3206         unsigned int nb_item;
3207         unsigned int value;
3208         unsigned int i;
3209         unsigned int j;
3210         int value_ok;
3211         char c;
3212
3213         /*
3214          * First parse all items in the list and store their value.
3215          */
3216         value = 0;
3217         nb_item = 0;
3218         value_ok = 0;
3219         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3220                 c = str[i];
3221                 if ((c >= '0') && (c <= '9')) {
3222                         value = (unsigned int) (value * 10 + (c - '0'));
3223                         value_ok = 1;
3224                         continue;
3225                 }
3226                 if (c != ',') {
3227                         printf("character %c is not a decimal digit\n", c);
3228                         return 0;
3229                 }
3230                 if (! value_ok) {
3231                         printf("No valid value before comma\n");
3232                         return 0;
3233                 }
3234                 if (nb_item < max_items) {
3235                         parsed_items[nb_item] = value;
3236                         value_ok = 0;
3237                         value = 0;
3238                 }
3239                 nb_item++;
3240         }
3241         if (nb_item >= max_items) {
3242                 printf("Number of %s = %u > %u (maximum items)\n",
3243                        item_name, nb_item + 1, max_items);
3244                 return 0;
3245         }
3246         parsed_items[nb_item++] = value;
3247         if (! check_unique_values)
3248                 return nb_item;
3249
3250         /*
3251          * Then, check that all values in the list are differents.
3252          * No optimization here...
3253          */
3254         for (i = 0; i < nb_item; i++) {
3255                 for (j = i + 1; j < nb_item; j++) {
3256                         if (parsed_items[j] == parsed_items[i]) {
3257                                 printf("duplicated %s %u at index %u and %u\n",
3258                                        item_name, parsed_items[i], i, j);
3259                                 return 0;
3260                         }
3261                 }
3262         }
3263         return nb_item;
3264 }
3265
3266 struct cmd_set_list_result {
3267         cmdline_fixed_string_t cmd_keyword;
3268         cmdline_fixed_string_t list_name;
3269         cmdline_fixed_string_t list_of_items;
3270 };
3271
3272 static void cmd_set_list_parsed(void *parsed_result,
3273                                 __attribute__((unused)) struct cmdline *cl,
3274                                 __attribute__((unused)) void *data)
3275 {
3276         struct cmd_set_list_result *res;
3277         union {
3278                 unsigned int lcorelist[RTE_MAX_LCORE];
3279                 unsigned int portlist[RTE_MAX_ETHPORTS];
3280         } parsed_items;
3281         unsigned int nb_item;
3282
3283         if (test_done == 0) {
3284                 printf("Please stop forwarding first\n");
3285                 return;
3286         }
3287
3288         res = parsed_result;
3289         if (!strcmp(res->list_name, "corelist")) {
3290                 nb_item = parse_item_list(res->list_of_items, "core",
3291                                           RTE_MAX_LCORE,
3292                                           parsed_items.lcorelist, 1);
3293                 if (nb_item > 0) {
3294                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3295                         fwd_config_setup();
3296                 }
3297                 return;
3298         }
3299         if (!strcmp(res->list_name, "portlist")) {
3300                 nb_item = parse_item_list(res->list_of_items, "port",
3301                                           RTE_MAX_ETHPORTS,
3302                                           parsed_items.portlist, 1);
3303                 if (nb_item > 0) {
3304                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3305                         fwd_config_setup();
3306                 }
3307         }
3308 }
3309
3310 cmdline_parse_token_string_t cmd_set_list_keyword =
3311         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3312                                  "set");
3313 cmdline_parse_token_string_t cmd_set_list_name =
3314         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3315                                  "corelist#portlist");
3316 cmdline_parse_token_string_t cmd_set_list_of_items =
3317         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3318                                  NULL);
3319
3320 cmdline_parse_inst_t cmd_set_fwd_list = {
3321         .f = cmd_set_list_parsed,
3322         .data = NULL,
3323         .help_str = "set corelist|portlist <list0[,list1]*>",
3324         .tokens = {
3325                 (void *)&cmd_set_list_keyword,
3326                 (void *)&cmd_set_list_name,
3327                 (void *)&cmd_set_list_of_items,
3328                 NULL,
3329         },
3330 };
3331
3332 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3333
3334 struct cmd_setmask_result {
3335         cmdline_fixed_string_t set;
3336         cmdline_fixed_string_t mask;
3337         uint64_t hexavalue;
3338 };
3339
3340 static void cmd_set_mask_parsed(void *parsed_result,
3341                                 __attribute__((unused)) struct cmdline *cl,
3342                                 __attribute__((unused)) void *data)
3343 {
3344         struct cmd_setmask_result *res = parsed_result;
3345
3346         if (test_done == 0) {
3347                 printf("Please stop forwarding first\n");
3348                 return;
3349         }
3350         if (!strcmp(res->mask, "coremask")) {
3351                 set_fwd_lcores_mask(res->hexavalue);
3352                 fwd_config_setup();
3353         } else if (!strcmp(res->mask, "portmask")) {
3354                 set_fwd_ports_mask(res->hexavalue);
3355                 fwd_config_setup();
3356         }
3357 }
3358
3359 cmdline_parse_token_string_t cmd_setmask_set =
3360         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3361 cmdline_parse_token_string_t cmd_setmask_mask =
3362         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3363                                  "coremask#portmask");
3364 cmdline_parse_token_num_t cmd_setmask_value =
3365         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3366
3367 cmdline_parse_inst_t cmd_set_fwd_mask = {
3368         .f = cmd_set_mask_parsed,
3369         .data = NULL,
3370         .help_str = "set coremask|portmask <hexadecimal value>",
3371         .tokens = {
3372                 (void *)&cmd_setmask_set,
3373                 (void *)&cmd_setmask_mask,
3374                 (void *)&cmd_setmask_value,
3375                 NULL,
3376         },
3377 };
3378
3379 /*
3380  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3381  */
3382 struct cmd_set_result {
3383         cmdline_fixed_string_t set;
3384         cmdline_fixed_string_t what;
3385         uint16_t value;
3386 };
3387
3388 static void cmd_set_parsed(void *parsed_result,
3389                            __attribute__((unused)) struct cmdline *cl,
3390                            __attribute__((unused)) void *data)
3391 {
3392         struct cmd_set_result *res = parsed_result;
3393         if (!strcmp(res->what, "nbport")) {
3394                 set_fwd_ports_number(res->value);
3395                 fwd_config_setup();
3396         } else if (!strcmp(res->what, "nbcore")) {
3397                 set_fwd_lcores_number(res->value);
3398                 fwd_config_setup();
3399         } else if (!strcmp(res->what, "burst"))
3400                 set_nb_pkt_per_burst(res->value);
3401         else if (!strcmp(res->what, "verbose"))
3402                 set_verbose_level(res->value);
3403 }
3404
3405 cmdline_parse_token_string_t cmd_set_set =
3406         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3407 cmdline_parse_token_string_t cmd_set_what =
3408         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3409                                  "nbport#nbcore#burst#verbose");
3410 cmdline_parse_token_num_t cmd_set_value =
3411         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3412
3413 cmdline_parse_inst_t cmd_set_numbers = {
3414         .f = cmd_set_parsed,
3415         .data = NULL,
3416         .help_str = "set nbport|nbcore|burst|verbose <value>",
3417         .tokens = {
3418                 (void *)&cmd_set_set,
3419                 (void *)&cmd_set_what,
3420                 (void *)&cmd_set_value,
3421                 NULL,
3422         },
3423 };
3424
3425 /* *** SET LOG LEVEL CONFIGURATION *** */
3426
3427 struct cmd_set_log_result {
3428         cmdline_fixed_string_t set;
3429         cmdline_fixed_string_t log;
3430         cmdline_fixed_string_t type;
3431         uint32_t level;
3432 };
3433
3434 static void
3435 cmd_set_log_parsed(void *parsed_result,
3436                    __attribute__((unused)) struct cmdline *cl,
3437                    __attribute__((unused)) void *data)
3438 {
3439         struct cmd_set_log_result *res;
3440         int ret;
3441
3442         res = parsed_result;
3443         if (!strcmp(res->type, "global"))
3444                 rte_log_set_global_level(res->level);
3445         else {
3446                 ret = rte_log_set_level_regexp(res->type, res->level);
3447                 if (ret < 0)
3448                         printf("Unable to set log level\n");
3449         }
3450 }
3451
3452 cmdline_parse_token_string_t cmd_set_log_set =
3453         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3454 cmdline_parse_token_string_t cmd_set_log_log =
3455         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3456 cmdline_parse_token_string_t cmd_set_log_type =
3457         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3458 cmdline_parse_token_num_t cmd_set_log_level =
3459         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3460
3461 cmdline_parse_inst_t cmd_set_log = {
3462         .f = cmd_set_log_parsed,
3463         .data = NULL,
3464         .help_str = "set log global|<type> <level>",
3465         .tokens = {
3466                 (void *)&cmd_set_log_set,
3467                 (void *)&cmd_set_log_log,
3468                 (void *)&cmd_set_log_type,
3469                 (void *)&cmd_set_log_level,
3470                 NULL,
3471         },
3472 };
3473
3474 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3475
3476 struct cmd_set_txpkts_result {
3477         cmdline_fixed_string_t cmd_keyword;
3478         cmdline_fixed_string_t txpkts;
3479         cmdline_fixed_string_t seg_lengths;
3480 };
3481
3482 static void
3483 cmd_set_txpkts_parsed(void *parsed_result,
3484                       __attribute__((unused)) struct cmdline *cl,
3485                       __attribute__((unused)) void *data)
3486 {
3487         struct cmd_set_txpkts_result *res;
3488         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3489         unsigned int nb_segs;
3490
3491         res = parsed_result;
3492         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3493                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3494         if (nb_segs > 0)
3495                 set_tx_pkt_segments(seg_lengths, nb_segs);
3496 }
3497
3498 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3499         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3500                                  cmd_keyword, "set");
3501 cmdline_parse_token_string_t cmd_set_txpkts_name =
3502         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3503                                  txpkts, "txpkts");
3504 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3505         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3506                                  seg_lengths, NULL);
3507
3508 cmdline_parse_inst_t cmd_set_txpkts = {
3509         .f = cmd_set_txpkts_parsed,
3510         .data = NULL,
3511         .help_str = "set txpkts <len0[,len1]*>",
3512         .tokens = {
3513                 (void *)&cmd_set_txpkts_keyword,
3514                 (void *)&cmd_set_txpkts_name,
3515                 (void *)&cmd_set_txpkts_lengths,
3516                 NULL,
3517         },
3518 };
3519
3520 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3521
3522 struct cmd_set_txsplit_result {
3523         cmdline_fixed_string_t cmd_keyword;
3524         cmdline_fixed_string_t txsplit;
3525         cmdline_fixed_string_t mode;
3526 };
3527
3528 static void
3529 cmd_set_txsplit_parsed(void *parsed_result,
3530                       __attribute__((unused)) struct cmdline *cl,
3531                       __attribute__((unused)) void *data)
3532 {
3533         struct cmd_set_txsplit_result *res;
3534
3535         res = parsed_result;
3536         set_tx_pkt_split(res->mode);
3537 }
3538
3539 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3540         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3541                                  cmd_keyword, "set");
3542 cmdline_parse_token_string_t cmd_set_txsplit_name =
3543         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3544                                  txsplit, "txsplit");
3545 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3546         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3547                                  mode, NULL);
3548
3549 cmdline_parse_inst_t cmd_set_txsplit = {
3550         .f = cmd_set_txsplit_parsed,
3551         .data = NULL,
3552         .help_str = "set txsplit on|off|rand",
3553         .tokens = {
3554                 (void *)&cmd_set_txsplit_keyword,
3555                 (void *)&cmd_set_txsplit_name,
3556                 (void *)&cmd_set_txsplit_mode,
3557                 NULL,
3558         },
3559 };
3560
3561 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3562 struct cmd_rx_vlan_filter_all_result {
3563         cmdline_fixed_string_t rx_vlan;
3564         cmdline_fixed_string_t what;
3565         cmdline_fixed_string_t all;
3566         portid_t port_id;
3567 };
3568
3569 static void
3570 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3571                               __attribute__((unused)) struct cmdline *cl,
3572                               __attribute__((unused)) void *data)
3573 {
3574         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3575
3576         if (!strcmp(res->what, "add"))
3577                 rx_vlan_all_filter_set(res->port_id, 1);
3578         else
3579                 rx_vlan_all_filter_set(res->port_id, 0);
3580 }
3581
3582 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3583         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3584                                  rx_vlan, "rx_vlan");
3585 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3586         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3587                                  what, "add#rm");
3588 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3589         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3590                                  all, "all");
3591 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3592         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3593                               port_id, UINT16);
3594
3595 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3596         .f = cmd_rx_vlan_filter_all_parsed,
3597         .data = NULL,
3598         .help_str = "rx_vlan add|rm all <port_id>: "
3599                 "Add/Remove all identifiers to/from the set of VLAN "
3600                 "identifiers filtered by a port",
3601         .tokens = {
3602                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3603                 (void *)&cmd_rx_vlan_filter_all_what,
3604                 (void *)&cmd_rx_vlan_filter_all_all,
3605                 (void *)&cmd_rx_vlan_filter_all_portid,
3606                 NULL,
3607         },
3608 };
3609
3610 /* *** VLAN OFFLOAD SET ON A PORT *** */
3611 struct cmd_vlan_offload_result {
3612         cmdline_fixed_string_t vlan;
3613         cmdline_fixed_string_t set;
3614         cmdline_fixed_string_t vlan_type;
3615         cmdline_fixed_string_t what;
3616         cmdline_fixed_string_t on;
3617         cmdline_fixed_string_t port_id;
3618 };
3619
3620 static void
3621 cmd_vlan_offload_parsed(void *parsed_result,
3622                           __attribute__((unused)) struct cmdline *cl,
3623                           __attribute__((unused)) void *data)
3624 {
3625         int on;
3626         struct cmd_vlan_offload_result *res = parsed_result;
3627         char *str;
3628         int i, len = 0;
3629         portid_t port_id = 0;
3630         unsigned int tmp;
3631
3632         str = res->port_id;
3633         len = strnlen(str, STR_TOKEN_SIZE);
3634         i = 0;
3635         /* Get port_id first */
3636         while(i < len){
3637                 if(str[i] == ',')
3638                         break;
3639
3640                 i++;
3641         }
3642         str[i]='\0';
3643         tmp = strtoul(str, NULL, 0);
3644         /* If port_id greater that what portid_t can represent, return */
3645         if(tmp >= RTE_MAX_ETHPORTS)
3646                 return;
3647         port_id = (portid_t)tmp;
3648
3649         if (!strcmp(res->on, "on"))
3650                 on = 1;
3651         else
3652                 on = 0;
3653
3654         if (!strcmp(res->what, "strip"))
3655                 rx_vlan_strip_set(port_id,  on);
3656         else if(!strcmp(res->what, "stripq")){
3657                 uint16_t queue_id = 0;
3658
3659                 /* No queue_id, return */
3660                 if(i + 1 >= len) {
3661                         printf("must specify (port,queue_id)\n");
3662                         return;
3663                 }
3664                 tmp = strtoul(str + i + 1, NULL, 0);
3665                 /* If queue_id greater that what 16-bits can represent, return */
3666                 if(tmp > 0xffff)
3667                         return;
3668
3669                 queue_id = (uint16_t)tmp;
3670                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3671         }
3672         else if (!strcmp(res->what, "filter"))
3673                 rx_vlan_filter_set(port_id, on);
3674         else
3675                 vlan_extend_set(port_id, on);
3676
3677         return;
3678 }
3679
3680 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3681         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3682                                  vlan, "vlan");
3683 cmdline_parse_token_string_t cmd_vlan_offload_set =
3684         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3685                                  set, "set");
3686 cmdline_parse_token_string_t cmd_vlan_offload_what =
3687         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3688                                  what, "strip#filter#qinq#stripq");
3689 cmdline_parse_token_string_t cmd_vlan_offload_on =
3690         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3691                               on, "on#off");
3692 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3693         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3694                               port_id, NULL);
3695
3696 cmdline_parse_inst_t cmd_vlan_offload = {
3697         .f = cmd_vlan_offload_parsed,
3698         .data = NULL,
3699         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3700                 "<port_id[,queue_id]>: "
3701                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3702         .tokens = {
3703                 (void *)&cmd_vlan_offload_vlan,
3704                 (void *)&cmd_vlan_offload_set,
3705                 (void *)&cmd_vlan_offload_what,
3706                 (void *)&cmd_vlan_offload_on,
3707                 (void *)&cmd_vlan_offload_portid,
3708                 NULL,
3709         },
3710 };
3711
3712 /* *** VLAN TPID SET ON A PORT *** */
3713 struct cmd_vlan_tpid_result {
3714         cmdline_fixed_string_t vlan;
3715         cmdline_fixed_string_t set;
3716         cmdline_fixed_string_t vlan_type;
3717         cmdline_fixed_string_t what;
3718         uint16_t tp_id;
3719         portid_t port_id;
3720 };
3721
3722 static void
3723 cmd_vlan_tpid_parsed(void *parsed_result,
3724                           __attribute__((unused)) struct cmdline *cl,
3725                           __attribute__((unused)) void *data)
3726 {
3727         struct cmd_vlan_tpid_result *res = parsed_result;
3728         enum rte_vlan_type vlan_type;
3729
3730         if (!strcmp(res->vlan_type, "inner"))
3731                 vlan_type = ETH_VLAN_TYPE_INNER;
3732         else if (!strcmp(res->vlan_type, "outer"))
3733                 vlan_type = ETH_VLAN_TYPE_OUTER;
3734         else {
3735                 printf("Unknown vlan type\n");
3736                 return;
3737         }
3738         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3739 }
3740
3741 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3742         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3743                                  vlan, "vlan");
3744 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3745         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3746                                  set, "set");
3747 cmdline_parse_token_string_t cmd_vlan_type =
3748         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3749                                  vlan_type, "inner#outer");
3750 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3751         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3752                                  what, "tpid");
3753 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3754         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3755                               tp_id, UINT16);
3756 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3757         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3758                               port_id, UINT16);
3759
3760 cmdline_parse_inst_t cmd_vlan_tpid = {
3761         .f = cmd_vlan_tpid_parsed,
3762         .data = NULL,
3763         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3764                 "Set the VLAN Ether type",
3765         .tokens = {
3766                 (void *)&cmd_vlan_tpid_vlan,
3767                 (void *)&cmd_vlan_tpid_set,
3768                 (void *)&cmd_vlan_type,
3769                 (void *)&cmd_vlan_tpid_what,
3770                 (void *)&cmd_vlan_tpid_tpid,
3771                 (void *)&cmd_vlan_tpid_portid,
3772                 NULL,
3773         },
3774 };
3775
3776 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3777 struct cmd_rx_vlan_filter_result {
3778         cmdline_fixed_string_t rx_vlan;
3779         cmdline_fixed_string_t what;
3780         uint16_t vlan_id;
3781         portid_t port_id;
3782 };
3783
3784 static void
3785 cmd_rx_vlan_filter_parsed(void *parsed_result,
3786                           __attribute__((unused)) struct cmdline *cl,
3787                           __attribute__((unused)) void *data)
3788 {
3789         struct cmd_rx_vlan_filter_result *res = parsed_result;
3790
3791         if (!strcmp(res->what, "add"))
3792                 rx_vft_set(res->port_id, res->vlan_id, 1);
3793         else
3794                 rx_vft_set(res->port_id, res->vlan_id, 0);
3795 }
3796
3797 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3798         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3799                                  rx_vlan, "rx_vlan");
3800 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3801         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3802                                  what, "add#rm");
3803 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3804         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3805                               vlan_id, UINT16);
3806 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3807         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3808                               port_id, UINT16);
3809
3810 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3811         .f = cmd_rx_vlan_filter_parsed,
3812         .data = NULL,
3813         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3814                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3815                 "identifiers filtered by a port",
3816         .tokens = {
3817                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3818                 (void *)&cmd_rx_vlan_filter_what,
3819                 (void *)&cmd_rx_vlan_filter_vlanid,
3820                 (void *)&cmd_rx_vlan_filter_portid,
3821                 NULL,
3822         },
3823 };
3824
3825 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3826 struct cmd_tx_vlan_set_result {
3827         cmdline_fixed_string_t tx_vlan;
3828         cmdline_fixed_string_t set;
3829         portid_t port_id;
3830         uint16_t vlan_id;
3831 };
3832
3833 static void
3834 cmd_tx_vlan_set_parsed(void *parsed_result,
3835                        __attribute__((unused)) struct cmdline *cl,
3836                        __attribute__((unused)) void *data)
3837 {
3838         struct cmd_tx_vlan_set_result *res = parsed_result;
3839
3840         if (!port_is_stopped(res->port_id)) {
3841                 printf("Please stop port %d first\n", res->port_id);
3842                 return;
3843         }
3844
3845         tx_vlan_set(res->port_id, res->vlan_id);
3846
3847         cmd_reconfig_device_queue(res->port_id, 1, 1);
3848 }
3849
3850 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3851         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3852                                  tx_vlan, "tx_vlan");
3853 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3854         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3855                                  set, "set");
3856 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3857         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3858                               port_id, UINT16);
3859 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3860         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3861                               vlan_id, UINT16);
3862
3863 cmdline_parse_inst_t cmd_tx_vlan_set = {
3864         .f = cmd_tx_vlan_set_parsed,
3865         .data = NULL,
3866         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3867                 "Enable hardware insertion of a single VLAN header "
3868                 "with a given TAG Identifier in packets sent on a port",
3869         .tokens = {
3870                 (void *)&cmd_tx_vlan_set_tx_vlan,
3871                 (void *)&cmd_tx_vlan_set_set,
3872                 (void *)&cmd_tx_vlan_set_portid,
3873                 (void *)&cmd_tx_vlan_set_vlanid,
3874                 NULL,
3875         },
3876 };
3877
3878 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3879 struct cmd_tx_vlan_set_qinq_result {
3880         cmdline_fixed_string_t tx_vlan;
3881         cmdline_fixed_string_t set;
3882         portid_t port_id;
3883         uint16_t vlan_id;
3884         uint16_t vlan_id_outer;
3885 };
3886
3887 static void
3888 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3889                             __attribute__((unused)) struct cmdline *cl,
3890                             __attribute__((unused)) void *data)
3891 {
3892         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3893
3894         if (!port_is_stopped(res->port_id)) {
3895                 printf("Please stop port %d first\n", res->port_id);
3896                 return;
3897         }
3898
3899         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3900
3901         cmd_reconfig_device_queue(res->port_id, 1, 1);
3902 }
3903
3904 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3905         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3906                 tx_vlan, "tx_vlan");
3907 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3908         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3909                 set, "set");
3910 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3911         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3912                 port_id, UINT16);
3913 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3914         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3915                 vlan_id, UINT16);
3916 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3917         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3918                 vlan_id_outer, UINT16);
3919
3920 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3921         .f = cmd_tx_vlan_set_qinq_parsed,
3922         .data = NULL,
3923         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3924                 "Enable hardware insertion of double VLAN header "
3925                 "with given TAG Identifiers in packets sent on a port",
3926         .tokens = {
3927                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3928                 (void *)&cmd_tx_vlan_set_qinq_set,
3929                 (void *)&cmd_tx_vlan_set_qinq_portid,
3930                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3931                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3932                 NULL,
3933         },
3934 };
3935
3936 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3937 struct cmd_tx_vlan_set_pvid_result {
3938         cmdline_fixed_string_t tx_vlan;
3939         cmdline_fixed_string_t set;
3940         cmdline_fixed_string_t pvid;
3941         portid_t port_id;
3942         uint16_t vlan_id;
3943         cmdline_fixed_string_t mode;
3944 };
3945
3946 static void
3947 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3948                             __attribute__((unused)) struct cmdline *cl,
3949                             __attribute__((unused)) void *data)
3950 {
3951         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3952
3953         if (strcmp(res->mode, "on") == 0)
3954                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3955         else
3956                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3957 }
3958
3959 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3960         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3961                                  tx_vlan, "tx_vlan");
3962 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3963         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3964                                  set, "set");
3965 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3966         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3967                                  pvid, "pvid");
3968 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3969         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3970                              port_id, UINT16);
3971 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3972         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3973                               vlan_id, UINT16);
3974 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3975         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3976                                  mode, "on#off");
3977
3978 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3979         .f = cmd_tx_vlan_set_pvid_parsed,
3980         .data = NULL,
3981         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3982         .tokens = {
3983                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3984                 (void *)&cmd_tx_vlan_set_pvid_set,
3985                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3986                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3987                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3988                 (void *)&cmd_tx_vlan_set_pvid_mode,
3989                 NULL,
3990         },
3991 };
3992
3993 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3994 struct cmd_tx_vlan_reset_result {
3995         cmdline_fixed_string_t tx_vlan;
3996         cmdline_fixed_string_t reset;
3997         portid_t port_id;
3998 };
3999
4000 static void
4001 cmd_tx_vlan_reset_parsed(void *parsed_result,
4002                          __attribute__((unused)) struct cmdline *cl,
4003                          __attribute__((unused)) void *data)
4004 {
4005         struct cmd_tx_vlan_reset_result *res = parsed_result;
4006
4007         if (!port_is_stopped(res->port_id)) {
4008                 printf("Please stop port %d first\n", res->port_id);
4009                 return;
4010         }
4011
4012         tx_vlan_reset(res->port_id);
4013
4014         cmd_reconfig_device_queue(res->port_id, 1, 1);
4015 }
4016
4017 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4018         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4019                                  tx_vlan, "tx_vlan");
4020 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4021         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4022                                  reset, "reset");
4023 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4024         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4025                               port_id, UINT16);
4026
4027 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4028         .f = cmd_tx_vlan_reset_parsed,
4029         .data = NULL,
4030         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4031                 "VLAN header in packets sent on a port",
4032         .tokens = {
4033                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4034                 (void *)&cmd_tx_vlan_reset_reset,
4035                 (void *)&cmd_tx_vlan_reset_portid,
4036                 NULL,
4037         },
4038 };
4039
4040
4041 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4042 struct cmd_csum_result {
4043         cmdline_fixed_string_t csum;
4044         cmdline_fixed_string_t mode;
4045         cmdline_fixed_string_t proto;
4046         cmdline_fixed_string_t hwsw;
4047         portid_t port_id;
4048 };
4049
4050 static void
4051 csum_show(int port_id)
4052 {
4053         struct rte_eth_dev_info dev_info;
4054         uint64_t tx_offloads;
4055
4056         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4057         printf("Parse tunnel is %s\n",
4058                 (ports[port_id].parse_tunnel) ? "on" : "off");
4059         printf("IP checksum offload is %s\n",
4060                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4061         printf("UDP checksum offload is %s\n",
4062                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4063         printf("TCP checksum offload is %s\n",
4064                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4065         printf("SCTP checksum offload is %s\n",
4066                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4067         printf("Outer-Ip checksum offload is %s\n",
4068                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4069
4070         /* display warnings if configuration is not supported by the NIC */
4071         rte_eth_dev_info_get(port_id, &dev_info);
4072         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4073                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4074                 printf("Warning: hardware IP checksum enabled but not "
4075                         "supported by port %d\n", port_id);
4076         }
4077         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4078                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4079                 printf("Warning: hardware UDP checksum enabled but not "
4080                         "supported by port %d\n", port_id);
4081         }
4082         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4083                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4084                 printf("Warning: hardware TCP checksum enabled but not "
4085                         "supported by port %d\n", port_id);
4086         }
4087         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4088                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4089                 printf("Warning: hardware SCTP checksum enabled but not "
4090                         "supported by port %d\n", port_id);
4091         }
4092         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4093                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4094                 printf("Warning: hardware outer IP checksum enabled but not "
4095                         "supported by port %d\n", port_id);
4096         }
4097 }
4098
4099 static void
4100 cmd_csum_parsed(void *parsed_result,
4101                        __attribute__((unused)) struct cmdline *cl,
4102                        __attribute__((unused)) void *data)
4103 {
4104         struct cmd_csum_result *res = parsed_result;
4105         int hw = 0;
4106         uint64_t csum_offloads = 0;
4107         struct rte_eth_dev_info dev_info;
4108
4109         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4110                 printf("invalid port %d\n", res->port_id);
4111                 return;
4112         }
4113         if (!port_is_stopped(res->port_id)) {
4114                 printf("Please stop port %d first\n", res->port_id);
4115                 return;
4116         }
4117
4118         rte_eth_dev_info_get(res->port_id, &dev_info);
4119         if (!strcmp(res->mode, "set")) {
4120
4121                 if (!strcmp(res->hwsw, "hw"))
4122                         hw = 1;
4123
4124                 if (!strcmp(res->proto, "ip")) {
4125                         if (hw == 0 || (dev_info.tx_offload_capa &
4126                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4127                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4128                         } else {
4129                                 printf("IP checksum offload is not supported "
4130                                        "by port %u\n", res->port_id);
4131                         }
4132                 } else if (!strcmp(res->proto, "udp")) {
4133                         if (hw == 0 || (dev_info.tx_offload_capa &
4134                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4135                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4136                         } else {
4137                                 printf("UDP checksum offload is not supported "
4138                                        "by port %u\n", res->port_id);
4139                         }
4140                 } else if (!strcmp(res->proto, "tcp")) {
4141                         if (hw == 0 || (dev_info.tx_offload_capa &
4142                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4143                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4144                         } else {
4145                                 printf("TCP checksum offload is not supported "
4146                                        "by port %u\n", res->port_id);
4147                         }
4148                 } else if (!strcmp(res->proto, "sctp")) {
4149                         if (hw == 0 || (dev_info.tx_offload_capa &
4150                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4151                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4152                         } else {
4153                                 printf("SCTP checksum offload is not supported "
4154                                        "by port %u\n", res->port_id);
4155                         }
4156                 } else if (!strcmp(res->proto, "outer-ip")) {
4157                         if (hw == 0 || (dev_info.tx_offload_capa &
4158                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4159                                 csum_offloads |=
4160                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4161                         } else {
4162                                 printf("Outer IP checksum offload is not "
4163                                        "supported by port %u\n", res->port_id);
4164                         }
4165                 }
4166
4167                 if (hw) {
4168                         ports[res->port_id].dev_conf.txmode.offloads |=
4169                                                         csum_offloads;
4170                 } else {
4171                         ports[res->port_id].dev_conf.txmode.offloads &=
4172                                                         (~csum_offloads);
4173                 }
4174         }
4175         csum_show(res->port_id);
4176
4177         cmd_reconfig_device_queue(res->port_id, 1, 1);
4178 }
4179
4180 cmdline_parse_token_string_t cmd_csum_csum =
4181         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4182                                 csum, "csum");
4183 cmdline_parse_token_string_t cmd_csum_mode =
4184         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4185                                 mode, "set");
4186 cmdline_parse_token_string_t cmd_csum_proto =
4187         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4188                                 proto, "ip#tcp#udp#sctp#outer-ip");
4189 cmdline_parse_token_string_t cmd_csum_hwsw =
4190         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4191                                 hwsw, "hw#sw");
4192 cmdline_parse_token_num_t cmd_csum_portid =
4193         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4194                                 port_id, UINT16);
4195
4196 cmdline_parse_inst_t cmd_csum_set = {
4197         .f = cmd_csum_parsed,
4198         .data = NULL,
4199         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4200                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4201                 "using csum forward engine",
4202         .tokens = {
4203                 (void *)&cmd_csum_csum,
4204                 (void *)&cmd_csum_mode,
4205                 (void *)&cmd_csum_proto,
4206                 (void *)&cmd_csum_hwsw,
4207                 (void *)&cmd_csum_portid,
4208                 NULL,
4209         },
4210 };
4211
4212 cmdline_parse_token_string_t cmd_csum_mode_show =
4213         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4214                                 mode, "show");
4215
4216 cmdline_parse_inst_t cmd_csum_show = {
4217         .f = cmd_csum_parsed,
4218         .data = NULL,
4219         .help_str = "csum show <port_id>: Show checksum offload configuration",
4220         .tokens = {
4221                 (void *)&cmd_csum_csum,
4222                 (void *)&cmd_csum_mode_show,
4223                 (void *)&cmd_csum_portid,
4224                 NULL,
4225         },
4226 };
4227
4228 /* Enable/disable tunnel parsing */
4229 struct cmd_csum_tunnel_result {
4230         cmdline_fixed_string_t csum;
4231         cmdline_fixed_string_t parse;
4232         cmdline_fixed_string_t onoff;
4233         portid_t port_id;
4234 };
4235
4236 static void
4237 cmd_csum_tunnel_parsed(void *parsed_result,
4238                        __attribute__((unused)) struct cmdline *cl,
4239                        __attribute__((unused)) void *data)
4240 {
4241         struct cmd_csum_tunnel_result *res = parsed_result;
4242
4243         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4244                 return;
4245
4246         if (!strcmp(res->onoff, "on"))
4247                 ports[res->port_id].parse_tunnel = 1;
4248         else
4249                 ports[res->port_id].parse_tunnel = 0;
4250
4251         csum_show(res->port_id);
4252 }
4253
4254 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4255         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4256                                 csum, "csum");
4257 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4258         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4259                                 parse, "parse_tunnel");
4260 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4261         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4262                                 onoff, "on#off");
4263 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4264         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4265                                 port_id, UINT16);
4266
4267 cmdline_parse_inst_t cmd_csum_tunnel = {
4268         .f = cmd_csum_tunnel_parsed,
4269         .data = NULL,
4270         .help_str = "csum parse_tunnel on|off <port_id>: "
4271                 "Enable/Disable parsing of tunnels for csum engine",
4272         .tokens = {
4273                 (void *)&cmd_csum_tunnel_csum,
4274                 (void *)&cmd_csum_tunnel_parse,
4275                 (void *)&cmd_csum_tunnel_onoff,
4276                 (void *)&cmd_csum_tunnel_portid,
4277                 NULL,
4278         },
4279 };
4280
4281 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4282 struct cmd_tso_set_result {
4283         cmdline_fixed_string_t tso;
4284         cmdline_fixed_string_t mode;
4285         uint16_t tso_segsz;
4286         portid_t port_id;
4287 };
4288
4289 static void
4290 cmd_tso_set_parsed(void *parsed_result,
4291                        __attribute__((unused)) struct cmdline *cl,
4292                        __attribute__((unused)) void *data)
4293 {
4294         struct cmd_tso_set_result *res = parsed_result;
4295         struct rte_eth_dev_info dev_info;
4296
4297         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4298                 return;
4299         if (!port_is_stopped(res->port_id)) {
4300                 printf("Please stop port %d first\n", res->port_id);
4301                 return;
4302         }
4303
4304         if (!strcmp(res->mode, "set"))
4305                 ports[res->port_id].tso_segsz = res->tso_segsz;
4306
4307         rte_eth_dev_info_get(res->port_id, &dev_info);
4308         if ((ports[res->port_id].tso_segsz != 0) &&
4309                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4310                 printf("Error: TSO is not supported by port %d\n",
4311                        res->port_id);
4312                 return;
4313         }
4314
4315         if (ports[res->port_id].tso_segsz == 0) {
4316                 ports[res->port_id].dev_conf.txmode.offloads &=
4317                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4318                 printf("TSO for non-tunneled packets is disabled\n");
4319         } else {
4320                 ports[res->port_id].dev_conf.txmode.offloads |=
4321                                                 DEV_TX_OFFLOAD_TCP_TSO;
4322                 printf("TSO segment size for non-tunneled packets is %d\n",
4323                         ports[res->port_id].tso_segsz);
4324         }
4325
4326         /* display warnings if configuration is not supported by the NIC */
4327         rte_eth_dev_info_get(res->port_id, &dev_info);
4328         if ((ports[res->port_id].tso_segsz != 0) &&
4329                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4330                 printf("Warning: TSO enabled but not "
4331                         "supported by port %d\n", res->port_id);
4332         }
4333
4334         cmd_reconfig_device_queue(res->port_id, 1, 1);
4335 }
4336
4337 cmdline_parse_token_string_t cmd_tso_set_tso =
4338         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4339                                 tso, "tso");
4340 cmdline_parse_token_string_t cmd_tso_set_mode =
4341         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4342                                 mode, "set");
4343 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4344         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4345                                 tso_segsz, UINT16);
4346 cmdline_parse_token_num_t cmd_tso_set_portid =
4347         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4348                                 port_id, UINT16);
4349
4350 cmdline_parse_inst_t cmd_tso_set = {
4351         .f = cmd_tso_set_parsed,
4352         .data = NULL,
4353         .help_str = "tso set <tso_segsz> <port_id>: "
4354                 "Set TSO segment size of non-tunneled packets for csum engine "
4355                 "(0 to disable)",
4356         .tokens = {
4357                 (void *)&cmd_tso_set_tso,
4358                 (void *)&cmd_tso_set_mode,
4359                 (void *)&cmd_tso_set_tso_segsz,
4360                 (void *)&cmd_tso_set_portid,
4361                 NULL,
4362         },
4363 };
4364
4365 cmdline_parse_token_string_t cmd_tso_show_mode =
4366         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4367                                 mode, "show");
4368
4369
4370 cmdline_parse_inst_t cmd_tso_show = {
4371         .f = cmd_tso_set_parsed,
4372         .data = NULL,
4373         .help_str = "tso show <port_id>: "
4374                 "Show TSO segment size of non-tunneled packets for csum engine",
4375         .tokens = {
4376                 (void *)&cmd_tso_set_tso,
4377                 (void *)&cmd_tso_show_mode,
4378                 (void *)&cmd_tso_set_portid,
4379                 NULL,
4380         },
4381 };
4382
4383 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4384 struct cmd_tunnel_tso_set_result {
4385         cmdline_fixed_string_t tso;
4386         cmdline_fixed_string_t mode;
4387         uint16_t tso_segsz;
4388         portid_t port_id;
4389 };
4390
4391 static struct rte_eth_dev_info
4392 check_tunnel_tso_nic_support(portid_t port_id)
4393 {
4394         struct rte_eth_dev_info dev_info;
4395
4396         rte_eth_dev_info_get(port_id, &dev_info);
4397         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4398                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4399                        "not enabled for port %d\n", port_id);
4400         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4401                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4402                        "not enabled for port %d\n", port_id);
4403         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4404                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4405                        "not enabled for port %d\n", port_id);
4406         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4407                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4408                        "not enabled for port %d\n", port_id);
4409         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4410                 printf("Warning: IP TUNNEL TSO not supported therefore "
4411                        "not enabled for port %d\n", port_id);
4412         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4413                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4414                        "not enabled for port %d\n", port_id);
4415         return dev_info;
4416 }
4417
4418 static void
4419 cmd_tunnel_tso_set_parsed(void *parsed_result,
4420                           __attribute__((unused)) struct cmdline *cl,
4421                           __attribute__((unused)) void *data)
4422 {
4423         struct cmd_tunnel_tso_set_result *res = parsed_result;
4424         struct rte_eth_dev_info dev_info;
4425
4426         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4427                 return;
4428         if (!port_is_stopped(res->port_id)) {
4429                 printf("Please stop port %d first\n", res->port_id);
4430                 return;
4431         }
4432
4433         if (!strcmp(res->mode, "set"))
4434                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4435
4436         dev_info = check_tunnel_tso_nic_support(res->port_id);
4437         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4438                 ports[res->port_id].dev_conf.txmode.offloads &=
4439                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4440                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4441                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4442                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4443                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4444                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4445                 printf("TSO for tunneled packets is disabled\n");
4446         } else {
4447                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4448                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4449                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4450                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4451                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4452                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4453
4454                 ports[res->port_id].dev_conf.txmode.offloads |=
4455                         (tso_offloads & dev_info.tx_offload_capa);
4456                 printf("TSO segment size for tunneled packets is %d\n",
4457                         ports[res->port_id].tunnel_tso_segsz);
4458
4459                 /* Below conditions are needed to make it work:
4460                  * (1) tunnel TSO is supported by the NIC;
4461                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4462                  * are recognized;
4463                  * (3) for tunneled pkts with outer L3 of IPv4,
4464                  * "csum set outer-ip" must be set to hw, because after tso,
4465                  * total_len of outer IP header is changed, and the checksum
4466                  * of outer IP header calculated by sw should be wrong; that
4467                  * is not necessary for IPv6 tunneled pkts because there's no
4468                  * checksum in IP header anymore.
4469                  */
4470
4471                 if (!ports[res->port_id].parse_tunnel)
4472                         printf("Warning: csum parse_tunnel must be set "
4473                                 "so that tunneled packets are recognized\n");
4474                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4475                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4476                         printf("Warning: csum set outer-ip must be set to hw "
4477                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4478         }
4479
4480         cmd_reconfig_device_queue(res->port_id, 1, 1);
4481 }
4482
4483 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4484         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4485                                 tso, "tunnel_tso");
4486 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4487         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4488                                 mode, "set");
4489 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4490         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4491                                 tso_segsz, UINT16);
4492 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4493         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4494                                 port_id, UINT16);
4495
4496 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4497         .f = cmd_tunnel_tso_set_parsed,
4498         .data = NULL,
4499         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4500                 "Set TSO segment size of tunneled packets for csum engine "
4501                 "(0 to disable)",
4502         .tokens = {
4503                 (void *)&cmd_tunnel_tso_set_tso,
4504                 (void *)&cmd_tunnel_tso_set_mode,
4505                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4506                 (void *)&cmd_tunnel_tso_set_portid,
4507                 NULL,
4508         },
4509 };
4510
4511 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4512         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4513                                 mode, "show");
4514
4515
4516 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4517         .f = cmd_tunnel_tso_set_parsed,
4518         .data = NULL,
4519         .help_str = "tunnel_tso show <port_id> "
4520                 "Show TSO segment size of tunneled packets for csum engine",
4521         .tokens = {
4522                 (void *)&cmd_tunnel_tso_set_tso,
4523                 (void *)&cmd_tunnel_tso_show_mode,
4524                 (void *)&cmd_tunnel_tso_set_portid,
4525                 NULL,
4526         },
4527 };
4528
4529 /* *** SET GRO FOR A PORT *** */
4530 struct cmd_gro_enable_result {
4531         cmdline_fixed_string_t cmd_set;
4532         cmdline_fixed_string_t cmd_port;
4533         cmdline_fixed_string_t cmd_keyword;
4534         cmdline_fixed_string_t cmd_onoff;
4535         portid_t cmd_pid;
4536 };
4537
4538 static void
4539 cmd_gro_enable_parsed(void *parsed_result,
4540                 __attribute__((unused)) struct cmdline *cl,
4541                 __attribute__((unused)) void *data)
4542 {
4543         struct cmd_gro_enable_result *res;
4544
4545         res = parsed_result;
4546         if (!strcmp(res->cmd_keyword, "gro"))
4547                 setup_gro(res->cmd_onoff, res->cmd_pid);
4548 }
4549
4550 cmdline_parse_token_string_t cmd_gro_enable_set =
4551         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4552                         cmd_set, "set");
4553 cmdline_parse_token_string_t cmd_gro_enable_port =
4554         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4555                         cmd_keyword, "port");
4556 cmdline_parse_token_num_t cmd_gro_enable_pid =
4557         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4558                         cmd_pid, UINT16);
4559 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4560         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4561                         cmd_keyword, "gro");
4562 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4563         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4564                         cmd_onoff, "on#off");
4565
4566 cmdline_parse_inst_t cmd_gro_enable = {
4567         .f = cmd_gro_enable_parsed,
4568         .data = NULL,
4569         .help_str = "set port <port_id> gro on|off",
4570         .tokens = {
4571                 (void *)&cmd_gro_enable_set,
4572                 (void *)&cmd_gro_enable_port,
4573                 (void *)&cmd_gro_enable_pid,
4574                 (void *)&cmd_gro_enable_keyword,
4575                 (void *)&cmd_gro_enable_onoff,
4576                 NULL,
4577         },
4578 };
4579
4580 /* *** DISPLAY GRO CONFIGURATION *** */
4581 struct cmd_gro_show_result {
4582         cmdline_fixed_string_t cmd_show;
4583         cmdline_fixed_string_t cmd_port;
4584         cmdline_fixed_string_t cmd_keyword;
4585         portid_t cmd_pid;
4586 };
4587
4588 static void
4589 cmd_gro_show_parsed(void *parsed_result,
4590                 __attribute__((unused)) struct cmdline *cl,
4591                 __attribute__((unused)) void *data)
4592 {
4593         struct cmd_gro_show_result *res;
4594
4595         res = parsed_result;
4596         if (!strcmp(res->cmd_keyword, "gro"))
4597                 show_gro(res->cmd_pid);
4598 }
4599
4600 cmdline_parse_token_string_t cmd_gro_show_show =
4601         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4602                         cmd_show, "show");
4603 cmdline_parse_token_string_t cmd_gro_show_port =
4604         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4605                         cmd_port, "port");
4606 cmdline_parse_token_num_t cmd_gro_show_pid =
4607         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4608                         cmd_pid, UINT16);
4609 cmdline_parse_token_string_t cmd_gro_show_keyword =
4610         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4611                         cmd_keyword, "gro");
4612
4613 cmdline_parse_inst_t cmd_gro_show = {
4614         .f = cmd_gro_show_parsed,
4615         .data = NULL,
4616         .help_str = "show port <port_id> gro",
4617         .tokens = {
4618                 (void *)&cmd_gro_show_show,
4619                 (void *)&cmd_gro_show_port,
4620                 (void *)&cmd_gro_show_pid,
4621                 (void *)&cmd_gro_show_keyword,
4622                 NULL,
4623         },
4624 };
4625
4626 /* *** SET FLUSH CYCLES FOR GRO *** */
4627 struct cmd_gro_flush_result {
4628         cmdline_fixed_string_t cmd_set;
4629         cmdline_fixed_string_t cmd_keyword;
4630         cmdline_fixed_string_t cmd_flush;
4631         uint8_t cmd_cycles;
4632 };
4633
4634 static void
4635 cmd_gro_flush_parsed(void *parsed_result,
4636                 __attribute__((unused)) struct cmdline *cl,
4637                 __attribute__((unused)) void *data)
4638 {
4639         struct cmd_gro_flush_result *res;
4640
4641         res = parsed_result;
4642         if ((!strcmp(res->cmd_keyword, "gro")) &&
4643                         (!strcmp(res->cmd_flush, "flush")))
4644                 setup_gro_flush_cycles(res->cmd_cycles);
4645 }
4646
4647 cmdline_parse_token_string_t cmd_gro_flush_set =
4648         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4649                         cmd_set, "set");
4650 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4651         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4652                         cmd_keyword, "gro");
4653 cmdline_parse_token_string_t cmd_gro_flush_flush =
4654         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4655                         cmd_flush, "flush");
4656 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4657         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4658                         cmd_cycles, UINT8);
4659
4660 cmdline_parse_inst_t cmd_gro_flush = {
4661         .f = cmd_gro_flush_parsed,
4662         .data = NULL,
4663         .help_str = "set gro flush <cycles>",
4664         .tokens = {
4665                 (void *)&cmd_gro_flush_set,
4666                 (void *)&cmd_gro_flush_keyword,
4667                 (void *)&cmd_gro_flush_flush,
4668                 (void *)&cmd_gro_flush_cycles,
4669                 NULL,
4670         },
4671 };
4672
4673 /* *** ENABLE/DISABLE GSO *** */
4674 struct cmd_gso_enable_result {
4675         cmdline_fixed_string_t cmd_set;
4676         cmdline_fixed_string_t cmd_port;
4677         cmdline_fixed_string_t cmd_keyword;
4678         cmdline_fixed_string_t cmd_mode;
4679         portid_t cmd_pid;
4680 };
4681
4682 static void
4683 cmd_gso_enable_parsed(void *parsed_result,
4684                 __attribute__((unused)) struct cmdline *cl,
4685                 __attribute__((unused)) void *data)
4686 {
4687         struct cmd_gso_enable_result *res;
4688
4689         res = parsed_result;
4690         if (!strcmp(res->cmd_keyword, "gso"))
4691                 setup_gso(res->cmd_mode, res->cmd_pid);
4692 }
4693
4694 cmdline_parse_token_string_t cmd_gso_enable_set =
4695         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4696                         cmd_set, "set");
4697 cmdline_parse_token_string_t cmd_gso_enable_port =
4698         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4699                         cmd_port, "port");
4700 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4701         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4702                         cmd_keyword, "gso");
4703 cmdline_parse_token_string_t cmd_gso_enable_mode =
4704         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4705                         cmd_mode, "on#off");
4706 cmdline_parse_token_num_t cmd_gso_enable_pid =
4707         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4708                         cmd_pid, UINT16);
4709
4710 cmdline_parse_inst_t cmd_gso_enable = {
4711         .f = cmd_gso_enable_parsed,
4712         .data = NULL,
4713         .help_str = "set port <port_id> gso on|off",
4714         .tokens = {
4715                 (void *)&cmd_gso_enable_set,
4716                 (void *)&cmd_gso_enable_port,
4717                 (void *)&cmd_gso_enable_pid,
4718                 (void *)&cmd_gso_enable_keyword,
4719                 (void *)&cmd_gso_enable_mode,
4720                 NULL,
4721         },
4722 };
4723
4724 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4725 struct cmd_gso_size_result {
4726         cmdline_fixed_string_t cmd_set;
4727         cmdline_fixed_string_t cmd_keyword;
4728         cmdline_fixed_string_t cmd_segsz;
4729         uint16_t cmd_size;
4730 };
4731
4732 static void
4733 cmd_gso_size_parsed(void *parsed_result,
4734                        __attribute__((unused)) struct cmdline *cl,
4735                        __attribute__((unused)) void *data)
4736 {
4737         struct cmd_gso_size_result *res = parsed_result;
4738
4739         if (test_done == 0) {
4740                 printf("Before setting GSO segsz, please first"
4741                                 " stop fowarding\n");
4742                 return;
4743         }
4744
4745         if (!strcmp(res->cmd_keyword, "gso") &&
4746                         !strcmp(res->cmd_segsz, "segsz")) {
4747                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4748                         printf("gso_size should be larger than %zu."
4749                                         " Please input a legal value\n",
4750                                         RTE_GSO_SEG_SIZE_MIN);
4751                 else
4752                         gso_max_segment_size = res->cmd_size;
4753         }
4754 }
4755
4756 cmdline_parse_token_string_t cmd_gso_size_set =
4757         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4758                                 cmd_set, "set");
4759 cmdline_parse_token_string_t cmd_gso_size_keyword =
4760         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4761                                 cmd_keyword, "gso");
4762 cmdline_parse_token_string_t cmd_gso_size_segsz =
4763         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4764                                 cmd_segsz, "segsz");
4765 cmdline_parse_token_num_t cmd_gso_size_size =
4766         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4767                                 cmd_size, UINT16);
4768
4769 cmdline_parse_inst_t cmd_gso_size = {
4770         .f = cmd_gso_size_parsed,
4771         .data = NULL,
4772         .help_str = "set gso segsz <length>",
4773         .tokens = {
4774                 (void *)&cmd_gso_size_set,
4775                 (void *)&cmd_gso_size_keyword,
4776                 (void *)&cmd_gso_size_segsz,
4777                 (void *)&cmd_gso_size_size,
4778                 NULL,
4779         },
4780 };
4781
4782 /* *** SHOW GSO CONFIGURATION *** */
4783 struct cmd_gso_show_result {
4784         cmdline_fixed_string_t cmd_show;
4785         cmdline_fixed_string_t cmd_port;
4786         cmdline_fixed_string_t cmd_keyword;
4787         portid_t cmd_pid;
4788 };
4789
4790 static void
4791 cmd_gso_show_parsed(void *parsed_result,
4792                        __attribute__((unused)) struct cmdline *cl,
4793                        __attribute__((unused)) void *data)
4794 {
4795         struct cmd_gso_show_result *res = parsed_result;
4796
4797         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4798                 printf("invalid port id %u\n", res->cmd_pid);
4799                 return;
4800         }
4801         if (!strcmp(res->cmd_keyword, "gso")) {
4802                 if (gso_ports[res->cmd_pid].enable) {
4803                         printf("Max GSO'd packet size: %uB\n"
4804                                         "Supported GSO types: TCP/IPv4, "
4805                                         "UDP/IPv4, VxLAN with inner "
4806                                         "TCP/IPv4 packet, GRE with inner "
4807                                         "TCP/IPv4 packet\n",
4808                                         gso_max_segment_size);
4809                 } else
4810                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4811         }
4812 }
4813
4814 cmdline_parse_token_string_t cmd_gso_show_show =
4815 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4816                 cmd_show, "show");
4817 cmdline_parse_token_string_t cmd_gso_show_port =
4818 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4819                 cmd_port, "port");
4820 cmdline_parse_token_string_t cmd_gso_show_keyword =
4821         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4822                                 cmd_keyword, "gso");
4823 cmdline_parse_token_num_t cmd_gso_show_pid =
4824         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4825                                 cmd_pid, UINT16);
4826
4827 cmdline_parse_inst_t cmd_gso_show = {
4828         .f = cmd_gso_show_parsed,
4829         .data = NULL,
4830         .help_str = "show port <port_id> gso",
4831         .tokens = {
4832                 (void *)&cmd_gso_show_show,
4833                 (void *)&cmd_gso_show_port,
4834                 (void *)&cmd_gso_show_pid,
4835                 (void *)&cmd_gso_show_keyword,
4836                 NULL,
4837         },
4838 };
4839
4840 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4841 struct cmd_set_flush_rx {
4842         cmdline_fixed_string_t set;
4843         cmdline_fixed_string_t flush_rx;
4844         cmdline_fixed_string_t mode;
4845 };
4846
4847 static void
4848 cmd_set_flush_rx_parsed(void *parsed_result,
4849                 __attribute__((unused)) struct cmdline *cl,
4850                 __attribute__((unused)) void *data)
4851 {
4852         struct cmd_set_flush_rx *res = parsed_result;
4853         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4854 }
4855
4856 cmdline_parse_token_string_t cmd_setflushrx_set =
4857         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4858                         set, "set");
4859 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4860         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4861                         flush_rx, "flush_rx");
4862 cmdline_parse_token_string_t cmd_setflushrx_mode =
4863         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4864                         mode, "on#off");
4865
4866
4867 cmdline_parse_inst_t cmd_set_flush_rx = {
4868         .f = cmd_set_flush_rx_parsed,
4869         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4870         .data = NULL,
4871         .tokens = {
4872                 (void *)&cmd_setflushrx_set,
4873                 (void *)&cmd_setflushrx_flush_rx,
4874                 (void *)&cmd_setflushrx_mode,
4875                 NULL,
4876         },
4877 };
4878
4879 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4880 struct cmd_set_link_check {
4881         cmdline_fixed_string_t set;
4882         cmdline_fixed_string_t link_check;
4883         cmdline_fixed_string_t mode;
4884 };
4885
4886 static void
4887 cmd_set_link_check_parsed(void *parsed_result,
4888                 __attribute__((unused)) struct cmdline *cl,
4889                 __attribute__((unused)) void *data)
4890 {
4891         struct cmd_set_link_check *res = parsed_result;
4892         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4893 }
4894
4895 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4896         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4897                         set, "set");
4898 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4899         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4900                         link_check, "link_check");
4901 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4902         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4903                         mode, "on#off");
4904
4905
4906 cmdline_parse_inst_t cmd_set_link_check = {
4907         .f = cmd_set_link_check_parsed,
4908         .help_str = "set link_check on|off: Enable/Disable link status check "
4909                     "when starting/stopping a port",
4910         .data = NULL,
4911         .tokens = {
4912                 (void *)&cmd_setlinkcheck_set,
4913                 (void *)&cmd_setlinkcheck_link_check,
4914                 (void *)&cmd_setlinkcheck_mode,
4915                 NULL,
4916         },
4917 };
4918
4919 /* *** SET NIC BYPASS MODE *** */
4920 struct cmd_set_bypass_mode_result {
4921         cmdline_fixed_string_t set;
4922         cmdline_fixed_string_t bypass;
4923         cmdline_fixed_string_t mode;
4924         cmdline_fixed_string_t value;
4925         portid_t port_id;
4926 };
4927
4928 static void
4929 cmd_set_bypass_mode_parsed(void *parsed_result,
4930                 __attribute__((unused)) struct cmdline *cl,
4931                 __attribute__((unused)) void *data)
4932 {
4933         struct cmd_set_bypass_mode_result *res = parsed_result;
4934         portid_t port_id = res->port_id;
4935         int32_t rc = -EINVAL;
4936
4937 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4938         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4939
4940         if (!strcmp(res->value, "bypass"))
4941                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4942         else if (!strcmp(res->value, "isolate"))
4943                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4944         else
4945                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4946
4947         /* Set the bypass mode for the relevant port. */
4948         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4949 #endif
4950         if (rc != 0)
4951                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4952 }
4953
4954 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4955         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4956                         set, "set");
4957 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4958         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4959                         bypass, "bypass");
4960 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4961         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4962                         mode, "mode");
4963 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4964         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4965                         value, "normal#bypass#isolate");
4966 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4967         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4968                                 port_id, UINT16);
4969
4970 cmdline_parse_inst_t cmd_set_bypass_mode = {
4971         .f = cmd_set_bypass_mode_parsed,
4972         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4973                     "Set the NIC bypass mode for port_id",
4974         .data = NULL,
4975         .tokens = {
4976                 (void *)&cmd_setbypass_mode_set,
4977                 (void *)&cmd_setbypass_mode_bypass,
4978                 (void *)&cmd_setbypass_mode_mode,
4979                 (void *)&cmd_setbypass_mode_value,
4980                 (void *)&cmd_setbypass_mode_port,
4981                 NULL,
4982         },
4983 };
4984
4985 /* *** SET NIC BYPASS EVENT *** */
4986 struct cmd_set_bypass_event_result {
4987         cmdline_fixed_string_t set;
4988         cmdline_fixed_string_t bypass;
4989         cmdline_fixed_string_t event;
4990         cmdline_fixed_string_t event_value;
4991         cmdline_fixed_string_t mode;
4992         cmdline_fixed_string_t mode_value;
4993         portid_t port_id;
4994 };
4995
4996 static void
4997 cmd_set_bypass_event_parsed(void *parsed_result,
4998                 __attribute__((unused)) struct cmdline *cl,
4999                 __attribute__((unused)) void *data)
5000 {
5001         int32_t rc = -EINVAL;
5002         struct cmd_set_bypass_event_result *res = parsed_result;
5003         portid_t port_id = res->port_id;
5004
5005 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5006         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5007         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5008
5009         if (!strcmp(res->event_value, "timeout"))
5010                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5011         else if (!strcmp(res->event_value, "os_on"))
5012                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5013         else if (!strcmp(res->event_value, "os_off"))
5014                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5015         else if (!strcmp(res->event_value, "power_on"))
5016                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5017         else if (!strcmp(res->event_value, "power_off"))
5018                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5019         else
5020                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5021
5022         if (!strcmp(res->mode_value, "bypass"))
5023                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5024         else if (!strcmp(res->mode_value, "isolate"))
5025                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5026         else
5027                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5028
5029         /* Set the watchdog timeout. */
5030         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5031
5032                 rc = -EINVAL;
5033                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5034                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5035                                                            bypass_timeout);
5036                 }
5037                 if (rc != 0) {
5038                         printf("Failed to set timeout value %u "
5039                         "for port %d, errto code: %d.\n",
5040                         bypass_timeout, port_id, rc);
5041                 }
5042         }
5043
5044         /* Set the bypass event to transition to bypass mode. */
5045         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5046                                               bypass_mode);
5047 #endif
5048
5049         if (rc != 0)
5050                 printf("\t Failed to set bypass event for port = %d.\n",
5051                        port_id);
5052 }
5053
5054 cmdline_parse_token_string_t cmd_setbypass_event_set =
5055         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5056                         set, "set");
5057 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5058         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5059                         bypass, "bypass");
5060 cmdline_parse_token_string_t cmd_setbypass_event_event =
5061         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5062                         event, "event");
5063 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5064         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5065                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5066 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5067         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5068                         mode, "mode");
5069 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5070         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5071                         mode_value, "normal#bypass#isolate");
5072 cmdline_parse_token_num_t cmd_setbypass_event_port =
5073         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5074                                 port_id, UINT16);
5075
5076 cmdline_parse_inst_t cmd_set_bypass_event = {
5077         .f = cmd_set_bypass_event_parsed,
5078         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5079                 "power_off mode normal|bypass|isolate <port_id>: "
5080                 "Set the NIC bypass event mode for port_id",
5081         .data = NULL,
5082         .tokens = {
5083                 (void *)&cmd_setbypass_event_set,
5084                 (void *)&cmd_setbypass_event_bypass,
5085                 (void *)&cmd_setbypass_event_event,
5086                 (void *)&cmd_setbypass_event_event_value,
5087                 (void *)&cmd_setbypass_event_mode,
5088                 (void *)&cmd_setbypass_event_mode_value,
5089                 (void *)&cmd_setbypass_event_port,
5090                 NULL,
5091         },
5092 };
5093
5094
5095 /* *** SET NIC BYPASS TIMEOUT *** */
5096 struct cmd_set_bypass_timeout_result {
5097         cmdline_fixed_string_t set;
5098         cmdline_fixed_string_t bypass;
5099         cmdline_fixed_string_t timeout;
5100         cmdline_fixed_string_t value;
5101 };
5102
5103 static void
5104 cmd_set_bypass_timeout_parsed(void *parsed_result,
5105                 __attribute__((unused)) struct cmdline *cl,
5106                 __attribute__((unused)) void *data)
5107 {
5108         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5109
5110 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5111         if (!strcmp(res->value, "1.5"))
5112                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5113         else if (!strcmp(res->value, "2"))
5114                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5115         else if (!strcmp(res->value, "3"))
5116                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5117         else if (!strcmp(res->value, "4"))
5118                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5119         else if (!strcmp(res->value, "8"))
5120                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5121         else if (!strcmp(res->value, "16"))
5122                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5123         else if (!strcmp(res->value, "32"))
5124                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5125         else
5126                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5127 #endif
5128 }
5129
5130 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5131         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5132                         set, "set");
5133 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5134         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5135                         bypass, "bypass");
5136 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5137         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5138                         timeout, "timeout");
5139 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5140         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5141                         value, "0#1.5#2#3#4#8#16#32");
5142
5143 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5144         .f = cmd_set_bypass_timeout_parsed,
5145         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5146                 "Set the NIC bypass watchdog timeout in seconds",
5147         .data = NULL,
5148         .tokens = {
5149                 (void *)&cmd_setbypass_timeout_set,
5150                 (void *)&cmd_setbypass_timeout_bypass,
5151                 (void *)&cmd_setbypass_timeout_timeout,
5152                 (void *)&cmd_setbypass_timeout_value,
5153                 NULL,
5154         },
5155 };
5156
5157 /* *** SHOW NIC BYPASS MODE *** */
5158 struct cmd_show_bypass_config_result {
5159         cmdline_fixed_string_t show;
5160         cmdline_fixed_string_t bypass;
5161         cmdline_fixed_string_t config;
5162         portid_t port_id;
5163 };
5164
5165 static void
5166 cmd_show_bypass_config_parsed(void *parsed_result,
5167                 __attribute__((unused)) struct cmdline *cl,
5168                 __attribute__((unused)) void *data)
5169 {
5170         struct cmd_show_bypass_config_result *res = parsed_result;
5171         portid_t port_id = res->port_id;
5172         int rc = -EINVAL;
5173 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5174         uint32_t event_mode;
5175         uint32_t bypass_mode;
5176         uint32_t timeout = bypass_timeout;
5177         int i;
5178
5179         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5180                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5181         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5182                 {"UNKNOWN", "normal", "bypass", "isolate"};
5183         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5184                 "NONE",
5185                 "OS/board on",
5186                 "power supply on",
5187                 "OS/board off",
5188                 "power supply off",
5189                 "timeout"};
5190         int num_events = (sizeof events) / (sizeof events[0]);
5191
5192         /* Display the bypass mode.*/
5193         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5194                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5195                 return;
5196         }
5197         else {
5198                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5199                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5200
5201                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5202         }
5203
5204         /* Display the bypass timeout.*/
5205         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5206                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5207
5208         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5209
5210         /* Display the bypass events and associated modes. */
5211         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5212
5213                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5214                         printf("\tFailed to get bypass mode for event = %s\n",
5215                                 events[i]);
5216                 } else {
5217                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5218                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5219
5220                         printf("\tbypass event: %-16s = %s\n", events[i],
5221                                 modes[event_mode]);
5222                 }
5223         }
5224 #endif
5225         if (rc != 0)
5226                 printf("\tFailed to get bypass configuration for port = %d\n",
5227                        port_id);
5228 }
5229
5230 cmdline_parse_token_string_t cmd_showbypass_config_show =
5231         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5232                         show, "show");
5233 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5234         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5235                         bypass, "bypass");
5236 cmdline_parse_token_string_t cmd_showbypass_config_config =
5237         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5238                         config, "config");
5239 cmdline_parse_token_num_t cmd_showbypass_config_port =
5240         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5241                                 port_id, UINT16);
5242
5243 cmdline_parse_inst_t cmd_show_bypass_config = {
5244         .f = cmd_show_bypass_config_parsed,
5245         .help_str = "show bypass config <port_id>: "
5246                     "Show the NIC bypass config for port_id",
5247         .data = NULL,
5248         .tokens = {
5249                 (void *)&cmd_showbypass_config_show,
5250                 (void *)&cmd_showbypass_config_bypass,
5251                 (void *)&cmd_showbypass_config_config,
5252                 (void *)&cmd_showbypass_config_port,
5253                 NULL,
5254         },
5255 };
5256
5257 #ifdef RTE_LIBRTE_PMD_BOND
5258 /* *** SET BONDING MODE *** */
5259 struct cmd_set_bonding_mode_result {
5260         cmdline_fixed_string_t set;
5261         cmdline_fixed_string_t bonding;
5262         cmdline_fixed_string_t mode;
5263         uint8_t value;
5264         portid_t port_id;
5265 };
5266
5267 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5268                 __attribute__((unused))  struct cmdline *cl,
5269                 __attribute__((unused)) void *data)
5270 {
5271         struct cmd_set_bonding_mode_result *res = parsed_result;
5272         portid_t port_id = res->port_id;
5273
5274         /* Set the bonding mode for the relevant port. */
5275         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5276                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5277 }
5278
5279 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5280 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5281                 set, "set");
5282 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5283 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5284                 bonding, "bonding");
5285 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5286 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5287                 mode, "mode");
5288 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5289 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5290                 value, UINT8);
5291 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5292 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5293                 port_id, UINT16);
5294
5295 cmdline_parse_inst_t cmd_set_bonding_mode = {
5296                 .f = cmd_set_bonding_mode_parsed,
5297                 .help_str = "set bonding mode <mode_value> <port_id>: "
5298                         "Set the bonding mode for port_id",
5299                 .data = NULL,
5300                 .tokens = {
5301                                 (void *) &cmd_setbonding_mode_set,
5302                                 (void *) &cmd_setbonding_mode_bonding,
5303                                 (void *) &cmd_setbonding_mode_mode,
5304                                 (void *) &cmd_setbonding_mode_value,
5305                                 (void *) &cmd_setbonding_mode_port,
5306                                 NULL
5307                 }
5308 };
5309
5310 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5311 struct cmd_set_bonding_lacp_dedicated_queues_result {
5312         cmdline_fixed_string_t set;
5313         cmdline_fixed_string_t bonding;
5314         cmdline_fixed_string_t lacp;
5315         cmdline_fixed_string_t dedicated_queues;
5316         portid_t port_id;
5317         cmdline_fixed_string_t mode;
5318 };
5319
5320 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5321                 __attribute__((unused))  struct cmdline *cl,
5322                 __attribute__((unused)) void *data)
5323 {
5324         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5325         portid_t port_id = res->port_id;
5326         struct rte_port *port;
5327
5328         port = &ports[port_id];
5329
5330         /** Check if the port is not started **/
5331         if (port->port_status != RTE_PORT_STOPPED) {
5332                 printf("Please stop port %d first\n", port_id);
5333                 return;
5334         }
5335
5336         if (!strcmp(res->mode, "enable")) {
5337                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5338                         printf("Dedicate queues for LACP control packets"
5339                                         " enabled\n");
5340                 else
5341                         printf("Enabling dedicate queues for LACP control "
5342                                         "packets on port %d failed\n", port_id);
5343         } else if (!strcmp(res->mode, "disable")) {
5344                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5345                         printf("Dedicated queues for LACP control packets "
5346                                         "disabled\n");
5347                 else
5348                         printf("Disabling dedicated queues for LACP control "
5349                                         "traffic on port %d failed\n", port_id);
5350         }
5351 }
5352
5353 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5354 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5355                 set, "set");
5356 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5357 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5358                 bonding, "bonding");
5359 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5360 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5361                 lacp, "lacp");
5362 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5363 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5364                 dedicated_queues, "dedicated_queues");
5365 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5366 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5367                 port_id, UINT16);
5368 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5369 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5370                 mode, "enable#disable");
5371
5372 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5373                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5374                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5375                         "enable|disable: "
5376                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5377                 .data = NULL,
5378                 .tokens = {
5379                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5380                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5381                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5382                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5383                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5384                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5385                         NULL
5386                 }
5387 };
5388
5389 /* *** SET BALANCE XMIT POLICY *** */
5390 struct cmd_set_bonding_balance_xmit_policy_result {
5391         cmdline_fixed_string_t set;
5392         cmdline_fixed_string_t bonding;
5393         cmdline_fixed_string_t balance_xmit_policy;
5394         portid_t port_id;
5395         cmdline_fixed_string_t policy;
5396 };
5397
5398 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5399                 __attribute__((unused))  struct cmdline *cl,
5400                 __attribute__((unused)) void *data)
5401 {
5402         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5403         portid_t port_id = res->port_id;
5404         uint8_t policy;
5405
5406         if (!strcmp(res->policy, "l2")) {
5407                 policy = BALANCE_XMIT_POLICY_LAYER2;
5408         } else if (!strcmp(res->policy, "l23")) {
5409                 policy = BALANCE_XMIT_POLICY_LAYER23;
5410         } else if (!strcmp(res->policy, "l34")) {
5411                 policy = BALANCE_XMIT_POLICY_LAYER34;
5412         } else {
5413                 printf("\t Invalid xmit policy selection");
5414                 return;
5415         }
5416
5417         /* Set the bonding mode for the relevant port. */
5418         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5419                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5420                                 port_id);
5421         }
5422 }
5423
5424 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5425 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5426                 set, "set");
5427 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5428 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5429                 bonding, "bonding");
5430 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5431 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5432                 balance_xmit_policy, "balance_xmit_policy");
5433 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5434 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5435                 port_id, UINT16);
5436 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5437 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5438                 policy, "l2#l23#l34");
5439
5440 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5441                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5442                 .help_str = "set bonding balance_xmit_policy <port_id> "
5443                         "l2|l23|l34: "
5444                         "Set the bonding balance_xmit_policy for port_id",
5445                 .data = NULL,
5446                 .tokens = {
5447                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5448                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5449                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5450                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5451                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5452                                 NULL
5453                 }
5454 };
5455
5456 /* *** SHOW NIC BONDING CONFIGURATION *** */
5457 struct cmd_show_bonding_config_result {
5458         cmdline_fixed_string_t show;
5459         cmdline_fixed_string_t bonding;
5460         cmdline_fixed_string_t config;
5461         portid_t port_id;
5462 };
5463
5464 static void cmd_show_bonding_config_parsed(void *parsed_result,
5465                 __attribute__((unused))  struct cmdline *cl,
5466                 __attribute__((unused)) void *data)
5467 {
5468         struct cmd_show_bonding_config_result *res = parsed_result;
5469         int bonding_mode, agg_mode;
5470         portid_t slaves[RTE_MAX_ETHPORTS];
5471         int num_slaves, num_active_slaves;
5472         int primary_id;
5473         int i;
5474         portid_t port_id = res->port_id;
5475
5476         /* Display the bonding mode.*/
5477         bonding_mode = rte_eth_bond_mode_get(port_id);
5478         if (bonding_mode < 0) {
5479                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5480                 return;
5481         } else
5482                 printf("\tBonding mode: %d\n", bonding_mode);
5483
5484         if (bonding_mode == BONDING_MODE_BALANCE) {
5485                 int balance_xmit_policy;
5486
5487                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5488                 if (balance_xmit_policy < 0) {
5489                         printf("\tFailed to get balance xmit policy for port = %d\n",
5490                                         port_id);
5491                         return;
5492                 } else {
5493                         printf("\tBalance Xmit Policy: ");
5494
5495                         switch (balance_xmit_policy) {
5496                         case BALANCE_XMIT_POLICY_LAYER2:
5497                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5498                                 break;
5499                         case BALANCE_XMIT_POLICY_LAYER23:
5500                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5501                                 break;
5502                         case BALANCE_XMIT_POLICY_LAYER34:
5503                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5504                                 break;
5505                         }
5506                         printf("\n");
5507                 }
5508         }
5509
5510         if (bonding_mode == BONDING_MODE_8023AD) {
5511                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5512                 printf("\tIEEE802.3AD Aggregator Mode: ");
5513                 switch (agg_mode) {
5514                 case AGG_BANDWIDTH:
5515                         printf("bandwidth");
5516                         break;
5517                 case AGG_STABLE:
5518                         printf("stable");
5519                         break;
5520                 case AGG_COUNT:
5521                         printf("count");
5522                         break;
5523                 }
5524                 printf("\n");
5525         }
5526
5527         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5528
5529         if (num_slaves < 0) {
5530                 printf("\tFailed to get slave list for port = %d\n", port_id);
5531                 return;
5532         }
5533         if (num_slaves > 0) {
5534                 printf("\tSlaves (%d): [", num_slaves);
5535                 for (i = 0; i < num_slaves - 1; i++)
5536                         printf("%d ", slaves[i]);
5537
5538                 printf("%d]\n", slaves[num_slaves - 1]);
5539         } else {
5540                 printf("\tSlaves: []\n");
5541
5542         }
5543
5544         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5545                         RTE_MAX_ETHPORTS);
5546
5547         if (num_active_slaves < 0) {
5548                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5549                 return;
5550         }
5551         if (num_active_slaves > 0) {
5552                 printf("\tActive Slaves (%d): [", num_active_slaves);
5553                 for (i = 0; i < num_active_slaves - 1; i++)
5554                         printf("%d ", slaves[i]);
5555
5556                 printf("%d]\n", slaves[num_active_slaves - 1]);
5557
5558         } else {
5559                 printf("\tActive Slaves: []\n");
5560
5561         }
5562
5563         primary_id = rte_eth_bond_primary_get(port_id);
5564         if (primary_id < 0) {
5565                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5566                 return;
5567         } else
5568                 printf("\tPrimary: [%d]\n", primary_id);
5569
5570 }
5571
5572 cmdline_parse_token_string_t cmd_showbonding_config_show =
5573 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5574                 show, "show");
5575 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5576 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5577                 bonding, "bonding");
5578 cmdline_parse_token_string_t cmd_showbonding_config_config =
5579 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5580                 config, "config");
5581 cmdline_parse_token_num_t cmd_showbonding_config_port =
5582 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5583                 port_id, UINT16);
5584
5585 cmdline_parse_inst_t cmd_show_bonding_config = {
5586                 .f = cmd_show_bonding_config_parsed,
5587                 .help_str = "show bonding config <port_id>: "
5588                         "Show the bonding config for port_id",
5589                 .data = NULL,
5590                 .tokens = {
5591                                 (void *)&cmd_showbonding_config_show,
5592                                 (void *)&cmd_showbonding_config_bonding,
5593                                 (void *)&cmd_showbonding_config_config,
5594                                 (void *)&cmd_showbonding_config_port,
5595                                 NULL
5596                 }
5597 };
5598
5599 /* *** SET BONDING PRIMARY *** */
5600 struct cmd_set_bonding_primary_result {
5601         cmdline_fixed_string_t set;
5602         cmdline_fixed_string_t bonding;
5603         cmdline_fixed_string_t primary;
5604         portid_t slave_id;
5605         portid_t port_id;
5606 };
5607
5608 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5609                 __attribute__((unused))  struct cmdline *cl,
5610                 __attribute__((unused)) void *data)
5611 {
5612         struct cmd_set_bonding_primary_result *res = parsed_result;
5613         portid_t master_port_id = res->port_id;
5614         portid_t slave_port_id = res->slave_id;
5615
5616         /* Set the primary slave for a bonded device. */
5617         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5618                 printf("\t Failed to set primary slave for port = %d.\n",
5619                                 master_port_id);
5620                 return;
5621         }
5622         init_port_config();
5623 }
5624
5625 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5626 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5627                 set, "set");
5628 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5629 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5630                 bonding, "bonding");
5631 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5632 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5633                 primary, "primary");
5634 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5635 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5636                 slave_id, UINT16);
5637 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5638 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5639                 port_id, UINT16);
5640
5641 cmdline_parse_inst_t cmd_set_bonding_primary = {
5642                 .f = cmd_set_bonding_primary_parsed,
5643                 .help_str = "set bonding primary <slave_id> <port_id>: "
5644                         "Set the primary slave for port_id",
5645                 .data = NULL,
5646                 .tokens = {
5647                                 (void *)&cmd_setbonding_primary_set,
5648                                 (void *)&cmd_setbonding_primary_bonding,
5649                                 (void *)&cmd_setbonding_primary_primary,
5650                                 (void *)&cmd_setbonding_primary_slave,
5651                                 (void *)&cmd_setbonding_primary_port,
5652                                 NULL
5653                 }
5654 };
5655
5656 /* *** ADD SLAVE *** */
5657 struct cmd_add_bonding_slave_result {
5658         cmdline_fixed_string_t add;
5659         cmdline_fixed_string_t bonding;
5660         cmdline_fixed_string_t slave;
5661         portid_t slave_id;
5662         portid_t port_id;
5663 };
5664
5665 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5666                 __attribute__((unused))  struct cmdline *cl,
5667                 __attribute__((unused)) void *data)
5668 {
5669         struct cmd_add_bonding_slave_result *res = parsed_result;
5670         portid_t master_port_id = res->port_id;
5671         portid_t slave_port_id = res->slave_id;
5672
5673         /* add the slave for a bonded device. */
5674         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5675                 printf("\t Failed to add slave %d to master port = %d.\n",
5676                                 slave_port_id, master_port_id);
5677                 return;
5678         }
5679         init_port_config();
5680         set_port_slave_flag(slave_port_id);
5681 }
5682
5683 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5684 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5685                 add, "add");
5686 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5687 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5688                 bonding, "bonding");
5689 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5690 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5691                 slave, "slave");
5692 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5693 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5694                 slave_id, UINT16);
5695 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5696 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5697                 port_id, UINT16);
5698
5699 cmdline_parse_inst_t cmd_add_bonding_slave = {
5700                 .f = cmd_add_bonding_slave_parsed,
5701                 .help_str = "add bonding slave <slave_id> <port_id>: "
5702                         "Add a slave device to a bonded device",
5703                 .data = NULL,
5704                 .tokens = {
5705                                 (void *)&cmd_addbonding_slave_add,
5706                                 (void *)&cmd_addbonding_slave_bonding,
5707                                 (void *)&cmd_addbonding_slave_slave,
5708                                 (void *)&cmd_addbonding_slave_slaveid,
5709                                 (void *)&cmd_addbonding_slave_port,
5710                                 NULL
5711                 }
5712 };
5713
5714 /* *** REMOVE SLAVE *** */
5715 struct cmd_remove_bonding_slave_result {
5716         cmdline_fixed_string_t remove;
5717         cmdline_fixed_string_t bonding;
5718         cmdline_fixed_string_t slave;
5719         portid_t slave_id;
5720         portid_t port_id;
5721 };
5722
5723 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5724                 __attribute__((unused))  struct cmdline *cl,
5725                 __attribute__((unused)) void *data)
5726 {
5727         struct cmd_remove_bonding_slave_result *res = parsed_result;
5728         portid_t master_port_id = res->port_id;
5729         portid_t slave_port_id = res->slave_id;
5730
5731         /* remove the slave from a bonded device. */
5732         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5733                 printf("\t Failed to remove slave %d from master port = %d.\n",
5734                                 slave_port_id, master_port_id);
5735                 return;
5736         }
5737         init_port_config();
5738         clear_port_slave_flag(slave_port_id);
5739 }
5740
5741 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5742                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5743                                 remove, "remove");
5744 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5745                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5746                                 bonding, "bonding");
5747 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5748                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5749                                 slave, "slave");
5750 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5751                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5752                                 slave_id, UINT16);
5753 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5754                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5755                                 port_id, UINT16);
5756
5757 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5758                 .f = cmd_remove_bonding_slave_parsed,
5759                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5760                         "Remove a slave device from a bonded device",
5761                 .data = NULL,
5762                 .tokens = {
5763                                 (void *)&cmd_removebonding_slave_remove,
5764                                 (void *)&cmd_removebonding_slave_bonding,
5765                                 (void *)&cmd_removebonding_slave_slave,
5766                                 (void *)&cmd_removebonding_slave_slaveid,
5767                                 (void *)&cmd_removebonding_slave_port,
5768                                 NULL
5769                 }
5770 };
5771
5772 /* *** CREATE BONDED DEVICE *** */
5773 struct cmd_create_bonded_device_result {
5774         cmdline_fixed_string_t create;
5775         cmdline_fixed_string_t bonded;
5776         cmdline_fixed_string_t device;
5777         uint8_t mode;
5778         uint8_t socket;
5779 };
5780
5781 static int bond_dev_num = 0;
5782
5783 static void cmd_create_bonded_device_parsed(void *parsed_result,
5784                 __attribute__((unused))  struct cmdline *cl,
5785                 __attribute__((unused)) void *data)
5786 {
5787         struct cmd_create_bonded_device_result *res = parsed_result;
5788         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5789         int port_id;
5790
5791         if (test_done == 0) {
5792                 printf("Please stop forwarding first\n");
5793                 return;
5794         }
5795
5796         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5797                         bond_dev_num++);
5798
5799         /* Create a new bonded device. */
5800         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5801         if (port_id < 0) {
5802                 printf("\t Failed to create bonded device.\n");
5803                 return;
5804         } else {
5805                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5806                                 port_id);
5807
5808                 /* Update number of ports */
5809                 nb_ports = rte_eth_dev_count_avail();
5810                 reconfig(port_id, res->socket);
5811                 rte_eth_promiscuous_enable(port_id);
5812         }
5813
5814 }
5815
5816 cmdline_parse_token_string_t cmd_createbonded_device_create =
5817                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5818                                 create, "create");
5819 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5820                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5821                                 bonded, "bonded");
5822 cmdline_parse_token_string_t cmd_createbonded_device_device =
5823                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5824                                 device, "device");
5825 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5826                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5827                                 mode, UINT8);
5828 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5829                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5830                                 socket, UINT8);
5831
5832 cmdline_parse_inst_t cmd_create_bonded_device = {
5833                 .f = cmd_create_bonded_device_parsed,
5834                 .help_str = "create bonded device <mode> <socket>: "
5835                         "Create a new bonded device with specific bonding mode and socket",
5836                 .data = NULL,
5837                 .tokens = {
5838                                 (void *)&cmd_createbonded_device_create,
5839                                 (void *)&cmd_createbonded_device_bonded,
5840                                 (void *)&cmd_createbonded_device_device,
5841                                 (void *)&cmd_createbonded_device_mode,
5842                                 (void *)&cmd_createbonded_device_socket,
5843                                 NULL
5844                 }
5845 };
5846
5847 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5848 struct cmd_set_bond_mac_addr_result {
5849         cmdline_fixed_string_t set;
5850         cmdline_fixed_string_t bonding;
5851         cmdline_fixed_string_t mac_addr;
5852         uint16_t port_num;
5853         struct ether_addr address;
5854 };
5855
5856 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5857                 __attribute__((unused))  struct cmdline *cl,
5858                 __attribute__((unused)) void *data)
5859 {
5860         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5861         int ret;
5862
5863         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5864                 return;
5865
5866         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5867
5868         /* check the return value and print it if is < 0 */
5869         if (ret < 0)
5870                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5871 }
5872
5873 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5874                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5875 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5876                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5877                                 "bonding");
5878 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5879                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5880                                 "mac_addr");
5881 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5882                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5883                                 port_num, UINT16);
5884 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5885                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5886
5887 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5888                 .f = cmd_set_bond_mac_addr_parsed,
5889                 .data = (void *) 0,
5890                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5891                 .tokens = {
5892                                 (void *)&cmd_set_bond_mac_addr_set,
5893                                 (void *)&cmd_set_bond_mac_addr_bonding,
5894                                 (void *)&cmd_set_bond_mac_addr_mac,
5895                                 (void *)&cmd_set_bond_mac_addr_portnum,
5896                                 (void *)&cmd_set_bond_mac_addr_addr,
5897                                 NULL
5898                 }
5899 };
5900
5901
5902 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5903 struct cmd_set_bond_mon_period_result {
5904         cmdline_fixed_string_t set;
5905         cmdline_fixed_string_t bonding;
5906         cmdline_fixed_string_t mon_period;
5907         uint16_t port_num;
5908         uint32_t period_ms;
5909 };
5910
5911 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5912                 __attribute__((unused))  struct cmdline *cl,
5913                 __attribute__((unused)) void *data)
5914 {
5915         struct cmd_set_bond_mon_period_result *res = parsed_result;
5916         int ret;
5917
5918         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5919
5920         /* check the return value and print it if is < 0 */
5921         if (ret < 0)
5922                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5923 }
5924
5925 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5926                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5927                                 set, "set");
5928 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5929                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5930                                 bonding, "bonding");
5931 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5932                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5933                                 mon_period,     "mon_period");
5934 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5935                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5936                                 port_num, UINT16);
5937 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5938                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5939                                 period_ms, UINT32);
5940
5941 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5942                 .f = cmd_set_bond_mon_period_parsed,
5943                 .data = (void *) 0,
5944                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5945                 .tokens = {
5946                                 (void *)&cmd_set_bond_mon_period_set,
5947                                 (void *)&cmd_set_bond_mon_period_bonding,
5948                                 (void *)&cmd_set_bond_mon_period_mon_period,
5949                                 (void *)&cmd_set_bond_mon_period_portnum,
5950                                 (void *)&cmd_set_bond_mon_period_period_ms,
5951                                 NULL
5952                 }
5953 };
5954
5955
5956
5957 struct cmd_set_bonding_agg_mode_policy_result {
5958         cmdline_fixed_string_t set;
5959         cmdline_fixed_string_t bonding;
5960         cmdline_fixed_string_t agg_mode;
5961         uint16_t port_num;
5962         cmdline_fixed_string_t policy;
5963 };
5964
5965
5966 static void
5967 cmd_set_bonding_agg_mode(void *parsed_result,
5968                 __attribute__((unused)) struct cmdline *cl,
5969                 __attribute__((unused)) void *data)
5970 {
5971         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5972         uint8_t policy = AGG_BANDWIDTH;
5973
5974         if (!strcmp(res->policy, "bandwidth"))
5975                 policy = AGG_BANDWIDTH;
5976         else if (!strcmp(res->policy, "stable"))
5977                 policy = AGG_STABLE;
5978         else if (!strcmp(res->policy, "count"))
5979                 policy = AGG_COUNT;
5980
5981         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5982 }
5983
5984
5985 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5986         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5987                                 set, "set");
5988 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5989         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5990                                 bonding, "bonding");
5991
5992 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5993         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5994                                 agg_mode, "agg_mode");
5995
5996 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5997         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5998                                 port_num, UINT16);
5999
6000 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6001         TOKEN_STRING_INITIALIZER(
6002                         struct cmd_set_bonding_balance_xmit_policy_result,
6003                 policy, "stable#bandwidth#count");
6004
6005 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6006         .f = cmd_set_bonding_agg_mode,
6007         .data = (void *) 0,
6008         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6009         .tokens = {
6010                         (void *)&cmd_set_bonding_agg_mode_set,
6011                         (void *)&cmd_set_bonding_agg_mode_bonding,
6012                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6013                         (void *)&cmd_set_bonding_agg_mode_portnum,
6014                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6015                         NULL
6016                 }
6017 };
6018
6019
6020 #endif /* RTE_LIBRTE_PMD_BOND */
6021
6022 /* *** SET FORWARDING MODE *** */
6023 struct cmd_set_fwd_mode_result {
6024         cmdline_fixed_string_t set;
6025         cmdline_fixed_string_t fwd;
6026         cmdline_fixed_string_t mode;
6027 };
6028
6029 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6030                                     __attribute__((unused)) struct cmdline *cl,
6031                                     __attribute__((unused)) void *data)
6032 {
6033         struct cmd_set_fwd_mode_result *res = parsed_result;
6034
6035         retry_enabled = 0;
6036         set_pkt_forwarding_mode(res->mode);
6037 }
6038
6039 cmdline_parse_token_string_t cmd_setfwd_set =
6040         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6041 cmdline_parse_token_string_t cmd_setfwd_fwd =
6042         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6043 cmdline_parse_token_string_t cmd_setfwd_mode =
6044         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6045                 "" /* defined at init */);
6046
6047 cmdline_parse_inst_t cmd_set_fwd_mode = {
6048         .f = cmd_set_fwd_mode_parsed,
6049         .data = NULL,
6050         .help_str = NULL, /* defined at init */
6051         .tokens = {
6052                 (void *)&cmd_setfwd_set,
6053                 (void *)&cmd_setfwd_fwd,
6054                 (void *)&cmd_setfwd_mode,
6055                 NULL,
6056         },
6057 };
6058
6059 static void cmd_set_fwd_mode_init(void)
6060 {
6061         char *modes, *c;
6062         static char token[128];
6063         static char help[256];
6064         cmdline_parse_token_string_t *token_struct;
6065
6066         modes = list_pkt_forwarding_modes();
6067         snprintf(help, sizeof(help), "set fwd %s: "
6068                 "Set packet forwarding mode", modes);
6069         cmd_set_fwd_mode.help_str = help;
6070
6071         /* string token separator is # */
6072         for (c = token; *modes != '\0'; modes++)
6073                 if (*modes == '|')
6074                         *c++ = '#';
6075                 else
6076                         *c++ = *modes;
6077         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6078         token_struct->string_data.str = token;
6079 }
6080
6081 /* *** SET RETRY FORWARDING MODE *** */
6082 struct cmd_set_fwd_retry_mode_result {
6083         cmdline_fixed_string_t set;
6084         cmdline_fixed_string_t fwd;
6085         cmdline_fixed_string_t mode;
6086         cmdline_fixed_string_t retry;
6087 };
6088
6089 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6090                             __attribute__((unused)) struct cmdline *cl,
6091                             __attribute__((unused)) void *data)
6092 {
6093         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6094
6095         retry_enabled = 1;
6096         set_pkt_forwarding_mode(res->mode);
6097 }
6098
6099 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6100         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6101                         set, "set");
6102 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6103         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6104                         fwd, "fwd");
6105 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6106         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6107                         mode,
6108                 "" /* defined at init */);
6109 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6110         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6111                         retry, "retry");
6112
6113 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6114         .f = cmd_set_fwd_retry_mode_parsed,
6115         .data = NULL,
6116         .help_str = NULL, /* defined at init */
6117         .tokens = {
6118                 (void *)&cmd_setfwd_retry_set,
6119                 (void *)&cmd_setfwd_retry_fwd,
6120                 (void *)&cmd_setfwd_retry_mode,
6121                 (void *)&cmd_setfwd_retry_retry,
6122                 NULL,
6123         },
6124 };
6125
6126 static void cmd_set_fwd_retry_mode_init(void)
6127 {
6128         char *modes, *c;
6129         static char token[128];
6130         static char help[256];
6131         cmdline_parse_token_string_t *token_struct;
6132
6133         modes = list_pkt_forwarding_retry_modes();
6134         snprintf(help, sizeof(help), "set fwd %s retry: "
6135                 "Set packet forwarding mode with retry", modes);
6136         cmd_set_fwd_retry_mode.help_str = help;
6137
6138         /* string token separator is # */
6139         for (c = token; *modes != '\0'; modes++)
6140                 if (*modes == '|')
6141                         *c++ = '#';
6142                 else
6143                         *c++ = *modes;
6144         token_struct = (cmdline_parse_token_string_t *)
6145                 cmd_set_fwd_retry_mode.tokens[2];
6146         token_struct->string_data.str = token;
6147 }
6148
6149 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6150 struct cmd_set_burst_tx_retry_result {
6151         cmdline_fixed_string_t set;
6152         cmdline_fixed_string_t burst;
6153         cmdline_fixed_string_t tx;
6154         cmdline_fixed_string_t delay;
6155         uint32_t time;
6156         cmdline_fixed_string_t retry;
6157         uint32_t retry_num;
6158 };
6159
6160 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6161                                         __attribute__((unused)) struct cmdline *cl,
6162                                         __attribute__((unused)) void *data)
6163 {
6164         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6165
6166         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6167                 && !strcmp(res->tx, "tx")) {
6168                 if (!strcmp(res->delay, "delay"))
6169                         burst_tx_delay_time = res->time;
6170                 if (!strcmp(res->retry, "retry"))
6171                         burst_tx_retry_num = res->retry_num;
6172         }
6173
6174 }
6175
6176 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6177         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6178 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6179         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6180                                  "burst");
6181 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6182         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6183 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6184         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6185 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6186         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6187 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6188         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6189 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6190         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6191
6192 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6193         .f = cmd_set_burst_tx_retry_parsed,
6194         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6195         .tokens = {
6196                 (void *)&cmd_set_burst_tx_retry_set,
6197                 (void *)&cmd_set_burst_tx_retry_burst,
6198                 (void *)&cmd_set_burst_tx_retry_tx,
6199                 (void *)&cmd_set_burst_tx_retry_delay,
6200                 (void *)&cmd_set_burst_tx_retry_time,
6201                 (void *)&cmd_set_burst_tx_retry_retry,
6202                 (void *)&cmd_set_burst_tx_retry_retry_num,
6203                 NULL,
6204         },
6205 };
6206
6207 /* *** SET PROMISC MODE *** */
6208 struct cmd_set_promisc_mode_result {
6209         cmdline_fixed_string_t set;
6210         cmdline_fixed_string_t promisc;
6211         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6212         uint16_t port_num;               /* valid if "allports" argument == 0 */
6213         cmdline_fixed_string_t mode;
6214 };
6215
6216 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6217                                         __attribute__((unused)) struct cmdline *cl,
6218                                         void *allports)
6219 {
6220         struct cmd_set_promisc_mode_result *res = parsed_result;
6221         int enable;
6222         portid_t i;
6223
6224         if (!strcmp(res->mode, "on"))
6225                 enable = 1;
6226         else
6227                 enable = 0;
6228
6229         /* all ports */
6230         if (allports) {
6231                 RTE_ETH_FOREACH_DEV(i) {
6232                         if (enable)
6233                                 rte_eth_promiscuous_enable(i);
6234                         else
6235                                 rte_eth_promiscuous_disable(i);
6236                 }
6237         }
6238         else {
6239                 if (enable)
6240                         rte_eth_promiscuous_enable(res->port_num);
6241                 else
6242                         rte_eth_promiscuous_disable(res->port_num);
6243         }
6244 }
6245
6246 cmdline_parse_token_string_t cmd_setpromisc_set =
6247         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6248 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6249         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6250                                  "promisc");
6251 cmdline_parse_token_string_t cmd_setpromisc_portall =
6252         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6253                                  "all");
6254 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6255         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6256                               UINT16);
6257 cmdline_parse_token_string_t cmd_setpromisc_mode =
6258         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6259                                  "on#off");
6260
6261 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6262         .f = cmd_set_promisc_mode_parsed,
6263         .data = (void *)1,
6264         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6265         .tokens = {
6266                 (void *)&cmd_setpromisc_set,
6267                 (void *)&cmd_setpromisc_promisc,
6268                 (void *)&cmd_setpromisc_portall,
6269                 (void *)&cmd_setpromisc_mode,
6270                 NULL,
6271         },
6272 };
6273
6274 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6275         .f = cmd_set_promisc_mode_parsed,
6276         .data = (void *)0,
6277         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6278         .tokens = {
6279                 (void *)&cmd_setpromisc_set,
6280                 (void *)&cmd_setpromisc_promisc,
6281                 (void *)&cmd_setpromisc_portnum,
6282                 (void *)&cmd_setpromisc_mode,
6283                 NULL,
6284         },
6285 };
6286
6287 /* *** SET ALLMULTI MODE *** */
6288 struct cmd_set_allmulti_mode_result {
6289         cmdline_fixed_string_t set;
6290         cmdline_fixed_string_t allmulti;
6291         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6292         uint16_t port_num;               /* valid if "allports" argument == 0 */
6293         cmdline_fixed_string_t mode;
6294 };
6295
6296 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6297                                         __attribute__((unused)) struct cmdline *cl,
6298                                         void *allports)
6299 {
6300         struct cmd_set_allmulti_mode_result *res = parsed_result;
6301         int enable;
6302         portid_t i;
6303
6304         if (!strcmp(res->mode, "on"))
6305                 enable = 1;
6306         else
6307                 enable = 0;
6308
6309         /* all ports */
6310         if (allports) {
6311                 RTE_ETH_FOREACH_DEV(i) {
6312                         if (enable)
6313                                 rte_eth_allmulticast_enable(i);
6314                         else
6315                                 rte_eth_allmulticast_disable(i);
6316                 }
6317         }
6318         else {
6319                 if (enable)
6320                         rte_eth_allmulticast_enable(res->port_num);
6321                 else
6322                         rte_eth_allmulticast_disable(res->port_num);
6323         }
6324 }
6325
6326 cmdline_parse_token_string_t cmd_setallmulti_set =
6327         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6328 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6329         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6330                                  "allmulti");
6331 cmdline_parse_token_string_t cmd_setallmulti_portall =
6332         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6333                                  "all");
6334 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6335         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6336                               UINT16);
6337 cmdline_parse_token_string_t cmd_setallmulti_mode =
6338         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6339                                  "on#off");
6340
6341 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6342         .f = cmd_set_allmulti_mode_parsed,
6343         .data = (void *)1,
6344         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6345         .tokens = {
6346                 (void *)&cmd_setallmulti_set,
6347                 (void *)&cmd_setallmulti_allmulti,
6348                 (void *)&cmd_setallmulti_portall,
6349                 (void *)&cmd_setallmulti_mode,
6350                 NULL,
6351         },
6352 };
6353
6354 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6355         .f = cmd_set_allmulti_mode_parsed,
6356         .data = (void *)0,
6357         .help_str = "set allmulti <port_id> on|off: "
6358                 "Set allmulti mode on port_id",
6359         .tokens = {
6360                 (void *)&cmd_setallmulti_set,
6361                 (void *)&cmd_setallmulti_allmulti,
6362                 (void *)&cmd_setallmulti_portnum,
6363                 (void *)&cmd_setallmulti_mode,
6364                 NULL,
6365         },
6366 };
6367
6368 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6369 struct cmd_link_flow_ctrl_set_result {
6370         cmdline_fixed_string_t set;
6371         cmdline_fixed_string_t flow_ctrl;
6372         cmdline_fixed_string_t rx;
6373         cmdline_fixed_string_t rx_lfc_mode;
6374         cmdline_fixed_string_t tx;
6375         cmdline_fixed_string_t tx_lfc_mode;
6376         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6377         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6378         cmdline_fixed_string_t autoneg_str;
6379         cmdline_fixed_string_t autoneg;
6380         cmdline_fixed_string_t hw_str;
6381         uint32_t high_water;
6382         cmdline_fixed_string_t lw_str;
6383         uint32_t low_water;
6384         cmdline_fixed_string_t pt_str;
6385         uint16_t pause_time;
6386         cmdline_fixed_string_t xon_str;
6387         uint16_t send_xon;
6388         portid_t port_id;
6389 };
6390
6391 cmdline_parse_token_string_t cmd_lfc_set_set =
6392         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6393                                 set, "set");
6394 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6395         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6396                                 flow_ctrl, "flow_ctrl");
6397 cmdline_parse_token_string_t cmd_lfc_set_rx =
6398         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6399                                 rx, "rx");
6400 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6401         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6402                                 rx_lfc_mode, "on#off");
6403 cmdline_parse_token_string_t cmd_lfc_set_tx =
6404         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6405                                 tx, "tx");
6406 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6407         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6408                                 tx_lfc_mode, "on#off");
6409 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6410         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6411                                 hw_str, "high_water");
6412 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6413         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6414                                 high_water, UINT32);
6415 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6416         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6417                                 lw_str, "low_water");
6418 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6419         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6420                                 low_water, UINT32);
6421 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6422         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6423                                 pt_str, "pause_time");
6424 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6425         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6426                                 pause_time, UINT16);
6427 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6428         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6429                                 xon_str, "send_xon");
6430 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6431         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6432                                 send_xon, UINT16);
6433 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6434         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6435                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6436 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6437         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6438                                 mac_ctrl_frame_fwd_mode, "on#off");
6439 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6440         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6441                                 autoneg_str, "autoneg");
6442 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6443         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6444                                 autoneg, "on#off");
6445 cmdline_parse_token_num_t cmd_lfc_set_portid =
6446         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6447                                 port_id, UINT16);
6448
6449 /* forward declaration */
6450 static void
6451 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6452                               void *data);
6453
6454 cmdline_parse_inst_t cmd_link_flow_control_set = {
6455         .f = cmd_link_flow_ctrl_set_parsed,
6456         .data = NULL,
6457         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6458                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6459                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6460         .tokens = {
6461                 (void *)&cmd_lfc_set_set,
6462                 (void *)&cmd_lfc_set_flow_ctrl,
6463                 (void *)&cmd_lfc_set_rx,
6464                 (void *)&cmd_lfc_set_rx_mode,
6465                 (void *)&cmd_lfc_set_tx,
6466                 (void *)&cmd_lfc_set_tx_mode,
6467                 (void *)&cmd_lfc_set_high_water,
6468                 (void *)&cmd_lfc_set_low_water,
6469                 (void *)&cmd_lfc_set_pause_time,
6470                 (void *)&cmd_lfc_set_send_xon,
6471                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6472                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6473                 (void *)&cmd_lfc_set_autoneg_str,
6474                 (void *)&cmd_lfc_set_autoneg,
6475                 (void *)&cmd_lfc_set_portid,
6476                 NULL,
6477         },
6478 };
6479
6480 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6481         .f = cmd_link_flow_ctrl_set_parsed,
6482         .data = (void *)&cmd_link_flow_control_set_rx,
6483         .help_str = "set flow_ctrl rx on|off <port_id>: "
6484                 "Change rx flow control parameter",
6485         .tokens = {
6486                 (void *)&cmd_lfc_set_set,
6487                 (void *)&cmd_lfc_set_flow_ctrl,
6488                 (void *)&cmd_lfc_set_rx,
6489                 (void *)&cmd_lfc_set_rx_mode,
6490                 (void *)&cmd_lfc_set_portid,
6491                 NULL,
6492         },
6493 };
6494
6495 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6496         .f = cmd_link_flow_ctrl_set_parsed,
6497         .data = (void *)&cmd_link_flow_control_set_tx,
6498         .help_str = "set flow_ctrl tx on|off <port_id>: "
6499                 "Change tx flow control parameter",
6500         .tokens = {
6501                 (void *)&cmd_lfc_set_set,
6502                 (void *)&cmd_lfc_set_flow_ctrl,
6503                 (void *)&cmd_lfc_set_tx,
6504                 (void *)&cmd_lfc_set_tx_mode,
6505                 (void *)&cmd_lfc_set_portid,
6506                 NULL,
6507         },
6508 };
6509
6510 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6511         .f = cmd_link_flow_ctrl_set_parsed,
6512         .data = (void *)&cmd_link_flow_control_set_hw,
6513         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6514                 "Change high water flow control parameter",
6515         .tokens = {
6516                 (void *)&cmd_lfc_set_set,
6517                 (void *)&cmd_lfc_set_flow_ctrl,
6518                 (void *)&cmd_lfc_set_high_water_str,
6519                 (void *)&cmd_lfc_set_high_water,
6520                 (void *)&cmd_lfc_set_portid,
6521                 NULL,
6522         },
6523 };
6524
6525 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6526         .f = cmd_link_flow_ctrl_set_parsed,
6527         .data = (void *)&cmd_link_flow_control_set_lw,
6528         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6529                 "Change low water flow control parameter",
6530         .tokens = {
6531                 (void *)&cmd_lfc_set_set,
6532                 (void *)&cmd_lfc_set_flow_ctrl,
6533                 (void *)&cmd_lfc_set_low_water_str,
6534                 (void *)&cmd_lfc_set_low_water,
6535                 (void *)&cmd_lfc_set_portid,
6536                 NULL,
6537         },
6538 };
6539
6540 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6541         .f = cmd_link_flow_ctrl_set_parsed,
6542         .data = (void *)&cmd_link_flow_control_set_pt,
6543         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6544                 "Change pause time flow control parameter",
6545         .tokens = {
6546                 (void *)&cmd_lfc_set_set,
6547                 (void *)&cmd_lfc_set_flow_ctrl,
6548                 (void *)&cmd_lfc_set_pause_time_str,
6549                 (void *)&cmd_lfc_set_pause_time,
6550                 (void *)&cmd_lfc_set_portid,
6551                 NULL,
6552         },
6553 };
6554
6555 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6556         .f = cmd_link_flow_ctrl_set_parsed,
6557         .data = (void *)&cmd_link_flow_control_set_xon,
6558         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6559                 "Change send_xon flow control parameter",
6560         .tokens = {
6561                 (void *)&cmd_lfc_set_set,
6562                 (void *)&cmd_lfc_set_flow_ctrl,
6563                 (void *)&cmd_lfc_set_send_xon_str,
6564                 (void *)&cmd_lfc_set_send_xon,
6565                 (void *)&cmd_lfc_set_portid,
6566                 NULL,
6567         },
6568 };
6569
6570 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6571         .f = cmd_link_flow_ctrl_set_parsed,
6572         .data = (void *)&cmd_link_flow_control_set_macfwd,
6573         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6574                 "Change mac ctrl fwd flow control parameter",
6575         .tokens = {
6576                 (void *)&cmd_lfc_set_set,
6577                 (void *)&cmd_lfc_set_flow_ctrl,
6578                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6579                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6580                 (void *)&cmd_lfc_set_portid,
6581                 NULL,
6582         },
6583 };
6584
6585 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6586         .f = cmd_link_flow_ctrl_set_parsed,
6587         .data = (void *)&cmd_link_flow_control_set_autoneg,
6588         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6589                 "Change autoneg flow control parameter",
6590         .tokens = {
6591                 (void *)&cmd_lfc_set_set,
6592                 (void *)&cmd_lfc_set_flow_ctrl,
6593                 (void *)&cmd_lfc_set_autoneg_str,
6594                 (void *)&cmd_lfc_set_autoneg,
6595                 (void *)&cmd_lfc_set_portid,
6596                 NULL,
6597         },
6598 };
6599
6600 static void
6601 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6602                               __attribute__((unused)) struct cmdline *cl,
6603                               void *data)
6604 {
6605         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6606         cmdline_parse_inst_t *cmd = data;
6607         struct rte_eth_fc_conf fc_conf;
6608         int rx_fc_en = 0;
6609         int tx_fc_en = 0;
6610         int ret;
6611
6612         /*
6613          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6614          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6615          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6616          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6617          */
6618         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6619                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6620         };
6621
6622         /* Partial command line, retrieve current configuration */
6623         if (cmd) {
6624                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6625                 if (ret != 0) {
6626                         printf("cannot get current flow ctrl parameters, return"
6627                                "code = %d\n", ret);
6628                         return;
6629                 }
6630
6631                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6632                     (fc_conf.mode == RTE_FC_FULL))
6633                         rx_fc_en = 1;
6634                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6635                     (fc_conf.mode == RTE_FC_FULL))
6636                         tx_fc_en = 1;
6637         }
6638
6639         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6640                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6641
6642         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6643                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6644
6645         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6646
6647         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6648                 fc_conf.high_water = res->high_water;
6649
6650         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6651                 fc_conf.low_water = res->low_water;
6652
6653         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6654                 fc_conf.pause_time = res->pause_time;
6655
6656         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6657                 fc_conf.send_xon = res->send_xon;
6658
6659         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6660                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6661                         fc_conf.mac_ctrl_frame_fwd = 1;
6662                 else
6663                         fc_conf.mac_ctrl_frame_fwd = 0;
6664         }
6665
6666         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6667                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6668
6669         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6670         if (ret != 0)
6671                 printf("bad flow contrl parameter, return code = %d \n", ret);
6672 }
6673
6674 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6675 struct cmd_priority_flow_ctrl_set_result {
6676         cmdline_fixed_string_t set;
6677         cmdline_fixed_string_t pfc_ctrl;
6678         cmdline_fixed_string_t rx;
6679         cmdline_fixed_string_t rx_pfc_mode;
6680         cmdline_fixed_string_t tx;
6681         cmdline_fixed_string_t tx_pfc_mode;
6682         uint32_t high_water;
6683         uint32_t low_water;
6684         uint16_t pause_time;
6685         uint8_t  priority;
6686         portid_t port_id;
6687 };
6688
6689 static void
6690 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6691                        __attribute__((unused)) struct cmdline *cl,
6692                        __attribute__((unused)) void *data)
6693 {
6694         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6695         struct rte_eth_pfc_conf pfc_conf;
6696         int rx_fc_enable, tx_fc_enable;
6697         int ret;
6698
6699         /*
6700          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6701          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6702          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6703          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6704          */
6705         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6706                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6707         };
6708
6709         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6710         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6711         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6712         pfc_conf.fc.high_water = res->high_water;
6713         pfc_conf.fc.low_water  = res->low_water;
6714         pfc_conf.fc.pause_time = res->pause_time;
6715         pfc_conf.priority      = res->priority;
6716
6717         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6718         if (ret != 0)
6719                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6720 }
6721
6722 cmdline_parse_token_string_t cmd_pfc_set_set =
6723         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6724                                 set, "set");
6725 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6726         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6727                                 pfc_ctrl, "pfc_ctrl");
6728 cmdline_parse_token_string_t cmd_pfc_set_rx =
6729         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6730                                 rx, "rx");
6731 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6732         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6733                                 rx_pfc_mode, "on#off");
6734 cmdline_parse_token_string_t cmd_pfc_set_tx =
6735         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6736                                 tx, "tx");
6737 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6738         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6739                                 tx_pfc_mode, "on#off");
6740 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6741         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6742                                 high_water, UINT32);
6743 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6744         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6745                                 low_water, UINT32);
6746 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6747         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6748                                 pause_time, UINT16);
6749 cmdline_parse_token_num_t cmd_pfc_set_priority =
6750         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6751                                 priority, UINT8);
6752 cmdline_parse_token_num_t cmd_pfc_set_portid =
6753         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6754                                 port_id, UINT16);
6755
6756 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6757         .f = cmd_priority_flow_ctrl_set_parsed,
6758         .data = NULL,
6759         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6760                 "<pause_time> <priority> <port_id>: "
6761                 "Configure the Ethernet priority flow control",
6762         .tokens = {
6763                 (void *)&cmd_pfc_set_set,
6764                 (void *)&cmd_pfc_set_flow_ctrl,
6765                 (void *)&cmd_pfc_set_rx,
6766                 (void *)&cmd_pfc_set_rx_mode,
6767                 (void *)&cmd_pfc_set_tx,
6768                 (void *)&cmd_pfc_set_tx_mode,
6769                 (void *)&cmd_pfc_set_high_water,
6770                 (void *)&cmd_pfc_set_low_water,
6771                 (void *)&cmd_pfc_set_pause_time,
6772                 (void *)&cmd_pfc_set_priority,
6773                 (void *)&cmd_pfc_set_portid,
6774                 NULL,
6775         },
6776 };
6777
6778 /* *** RESET CONFIGURATION *** */
6779 struct cmd_reset_result {
6780         cmdline_fixed_string_t reset;
6781         cmdline_fixed_string_t def;
6782 };
6783
6784 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6785                              struct cmdline *cl,
6786                              __attribute__((unused)) void *data)
6787 {
6788         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6789         set_def_fwd_config();
6790 }
6791
6792 cmdline_parse_token_string_t cmd_reset_set =
6793         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6794 cmdline_parse_token_string_t cmd_reset_def =
6795         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6796                                  "default");
6797
6798 cmdline_parse_inst_t cmd_reset = {
6799         .f = cmd_reset_parsed,
6800         .data = NULL,
6801         .help_str = "set default: Reset default forwarding configuration",
6802         .tokens = {
6803                 (void *)&cmd_reset_set,
6804                 (void *)&cmd_reset_def,
6805                 NULL,
6806         },
6807 };
6808
6809 /* *** START FORWARDING *** */
6810 struct cmd_start_result {
6811         cmdline_fixed_string_t start;
6812 };
6813
6814 cmdline_parse_token_string_t cmd_start_start =
6815         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6816
6817 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6818                              __attribute__((unused)) struct cmdline *cl,
6819                              __attribute__((unused)) void *data)
6820 {
6821         start_packet_forwarding(0);
6822 }
6823
6824 cmdline_parse_inst_t cmd_start = {
6825         .f = cmd_start_parsed,
6826         .data = NULL,
6827         .help_str = "start: Start packet forwarding",
6828         .tokens = {
6829                 (void *)&cmd_start_start,
6830                 NULL,
6831         },
6832 };
6833
6834 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6835 struct cmd_start_tx_first_result {
6836         cmdline_fixed_string_t start;
6837         cmdline_fixed_string_t tx_first;
6838 };
6839
6840 static void
6841 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6842                           __attribute__((unused)) struct cmdline *cl,
6843                           __attribute__((unused)) void *data)
6844 {
6845         start_packet_forwarding(1);
6846 }
6847
6848 cmdline_parse_token_string_t cmd_start_tx_first_start =
6849         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6850                                  "start");
6851 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6852         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6853                                  tx_first, "tx_first");
6854
6855 cmdline_parse_inst_t cmd_start_tx_first = {
6856         .f = cmd_start_tx_first_parsed,
6857         .data = NULL,
6858         .help_str = "start tx_first: Start packet forwarding, "
6859                 "after sending 1 burst of packets",
6860         .tokens = {
6861                 (void *)&cmd_start_tx_first_start,
6862                 (void *)&cmd_start_tx_first_tx_first,
6863                 NULL,
6864         },
6865 };
6866
6867 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6868 struct cmd_start_tx_first_n_result {
6869         cmdline_fixed_string_t start;
6870         cmdline_fixed_string_t tx_first;
6871         uint32_t tx_num;
6872 };
6873
6874 static void
6875 cmd_start_tx_first_n_parsed(void *parsed_result,
6876                           __attribute__((unused)) struct cmdline *cl,
6877                           __attribute__((unused)) void *data)
6878 {
6879         struct cmd_start_tx_first_n_result *res = parsed_result;
6880
6881         start_packet_forwarding(res->tx_num);
6882 }
6883
6884 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6885         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6886                         start, "start");
6887 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6888         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6889                         tx_first, "tx_first");
6890 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6891         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6892                         tx_num, UINT32);
6893
6894 cmdline_parse_inst_t cmd_start_tx_first_n = {
6895         .f = cmd_start_tx_first_n_parsed,
6896         .data = NULL,
6897         .help_str = "start tx_first <num>: "
6898                 "packet forwarding, after sending <num> bursts of packets",
6899         .tokens = {
6900                 (void *)&cmd_start_tx_first_n_start,
6901                 (void *)&cmd_start_tx_first_n_tx_first,
6902                 (void *)&cmd_start_tx_first_n_tx_num,
6903                 NULL,
6904         },
6905 };
6906
6907 /* *** SET LINK UP *** */
6908 struct cmd_set_link_up_result {
6909         cmdline_fixed_string_t set;
6910         cmdline_fixed_string_t link_up;
6911         cmdline_fixed_string_t port;
6912         portid_t port_id;
6913 };
6914
6915 cmdline_parse_token_string_t cmd_set_link_up_set =
6916         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6917 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6918         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6919                                 "link-up");
6920 cmdline_parse_token_string_t cmd_set_link_up_port =
6921         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6922 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6923         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6924
6925 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6926                              __attribute__((unused)) struct cmdline *cl,
6927                              __attribute__((unused)) void *data)
6928 {
6929         struct cmd_set_link_up_result *res = parsed_result;
6930         dev_set_link_up(res->port_id);
6931 }
6932
6933 cmdline_parse_inst_t cmd_set_link_up = {
6934         .f = cmd_set_link_up_parsed,
6935         .data = NULL,
6936         .help_str = "set link-up port <port id>",
6937         .tokens = {
6938                 (void *)&cmd_set_link_up_set,
6939                 (void *)&cmd_set_link_up_link_up,
6940                 (void *)&cmd_set_link_up_port,
6941                 (void *)&cmd_set_link_up_port_id,
6942                 NULL,
6943         },
6944 };
6945
6946 /* *** SET LINK DOWN *** */
6947 struct cmd_set_link_down_result {
6948         cmdline_fixed_string_t set;
6949         cmdline_fixed_string_t link_down;
6950         cmdline_fixed_string_t port;
6951         portid_t port_id;
6952 };
6953
6954 cmdline_parse_token_string_t cmd_set_link_down_set =
6955         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6956 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6957         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6958                                 "link-down");
6959 cmdline_parse_token_string_t cmd_set_link_down_port =
6960         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6961 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6962         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6963
6964 static void cmd_set_link_down_parsed(
6965                                 __attribute__((unused)) void *parsed_result,
6966                                 __attribute__((unused)) struct cmdline *cl,
6967                                 __attribute__((unused)) void *data)
6968 {
6969         struct cmd_set_link_down_result *res = parsed_result;
6970         dev_set_link_down(res->port_id);
6971 }
6972
6973 cmdline_parse_inst_t cmd_set_link_down = {
6974         .f = cmd_set_link_down_parsed,
6975         .data = NULL,
6976         .help_str = "set link-down port <port id>",
6977         .tokens = {
6978                 (void *)&cmd_set_link_down_set,
6979                 (void *)&cmd_set_link_down_link_down,
6980                 (void *)&cmd_set_link_down_port,
6981                 (void *)&cmd_set_link_down_port_id,
6982                 NULL,
6983         },
6984 };
6985
6986 /* *** SHOW CFG *** */
6987 struct cmd_showcfg_result {
6988         cmdline_fixed_string_t show;
6989         cmdline_fixed_string_t cfg;
6990         cmdline_fixed_string_t what;
6991 };
6992
6993 static void cmd_showcfg_parsed(void *parsed_result,
6994                                __attribute__((unused)) struct cmdline *cl,
6995                                __attribute__((unused)) void *data)
6996 {
6997         struct cmd_showcfg_result *res = parsed_result;
6998         if (!strcmp(res->what, "rxtx"))
6999                 rxtx_config_display();
7000         else if (!strcmp(res->what, "cores"))
7001                 fwd_lcores_config_display();
7002         else if (!strcmp(res->what, "fwd"))
7003                 pkt_fwd_config_display(&cur_fwd_config);
7004         else if (!strcmp(res->what, "txpkts"))
7005                 show_tx_pkt_segments();
7006 }
7007
7008 cmdline_parse_token_string_t cmd_showcfg_show =
7009         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7010 cmdline_parse_token_string_t cmd_showcfg_port =
7011         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7012 cmdline_parse_token_string_t cmd_showcfg_what =
7013         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7014                                  "rxtx#cores#fwd#txpkts");
7015
7016 cmdline_parse_inst_t cmd_showcfg = {
7017         .f = cmd_showcfg_parsed,
7018         .data = NULL,
7019         .help_str = "show config rxtx|cores|fwd|txpkts",
7020         .tokens = {
7021                 (void *)&cmd_showcfg_show,
7022                 (void *)&cmd_showcfg_port,
7023                 (void *)&cmd_showcfg_what,
7024                 NULL,
7025         },
7026 };
7027
7028 /* *** SHOW ALL PORT INFO *** */
7029 struct cmd_showportall_result {
7030         cmdline_fixed_string_t show;
7031         cmdline_fixed_string_t port;
7032         cmdline_fixed_string_t what;
7033         cmdline_fixed_string_t all;
7034 };
7035
7036 static void cmd_showportall_parsed(void *parsed_result,
7037                                 __attribute__((unused)) struct cmdline *cl,
7038                                 __attribute__((unused)) void *data)
7039 {
7040         portid_t i;
7041
7042         struct cmd_showportall_result *res = parsed_result;
7043         if (!strcmp(res->show, "clear")) {
7044                 if (!strcmp(res->what, "stats"))
7045                         RTE_ETH_FOREACH_DEV(i)
7046                                 nic_stats_clear(i);
7047                 else if (!strcmp(res->what, "xstats"))
7048                         RTE_ETH_FOREACH_DEV(i)
7049                                 nic_xstats_clear(i);
7050         } else if (!strcmp(res->what, "info"))
7051                 RTE_ETH_FOREACH_DEV(i)
7052                         port_infos_display(i);
7053         else if (!strcmp(res->what, "stats"))
7054                 RTE_ETH_FOREACH_DEV(i)
7055                         nic_stats_display(i);
7056         else if (!strcmp(res->what, "xstats"))
7057                 RTE_ETH_FOREACH_DEV(i)
7058                         nic_xstats_display(i);
7059         else if (!strcmp(res->what, "fdir"))
7060                 RTE_ETH_FOREACH_DEV(i)
7061                         fdir_get_infos(i);
7062         else if (!strcmp(res->what, "stat_qmap"))
7063                 RTE_ETH_FOREACH_DEV(i)
7064                         nic_stats_mapping_display(i);
7065         else if (!strcmp(res->what, "dcb_tc"))
7066                 RTE_ETH_FOREACH_DEV(i)
7067                         port_dcb_info_display(i);
7068         else if (!strcmp(res->what, "cap"))
7069                 RTE_ETH_FOREACH_DEV(i)
7070                         port_offload_cap_display(i);
7071 }
7072
7073 cmdline_parse_token_string_t cmd_showportall_show =
7074         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7075                                  "show#clear");
7076 cmdline_parse_token_string_t cmd_showportall_port =
7077         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7078 cmdline_parse_token_string_t cmd_showportall_what =
7079         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7080                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7081 cmdline_parse_token_string_t cmd_showportall_all =
7082         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7083 cmdline_parse_inst_t cmd_showportall = {
7084         .f = cmd_showportall_parsed,
7085         .data = NULL,
7086         .help_str = "show|clear port "
7087                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7088         .tokens = {
7089                 (void *)&cmd_showportall_show,
7090                 (void *)&cmd_showportall_port,
7091                 (void *)&cmd_showportall_what,
7092                 (void *)&cmd_showportall_all,
7093                 NULL,
7094         },
7095 };
7096
7097 /* *** SHOW PORT INFO *** */
7098 struct cmd_showport_result {
7099         cmdline_fixed_string_t show;
7100         cmdline_fixed_string_t port;
7101         cmdline_fixed_string_t what;
7102         uint16_t portnum;
7103 };
7104
7105 static void cmd_showport_parsed(void *parsed_result,
7106                                 __attribute__((unused)) struct cmdline *cl,
7107                                 __attribute__((unused)) void *data)
7108 {
7109         struct cmd_showport_result *res = parsed_result;
7110         if (!strcmp(res->show, "clear")) {
7111                 if (!strcmp(res->what, "stats"))
7112                         nic_stats_clear(res->portnum);
7113                 else if (!strcmp(res->what, "xstats"))
7114                         nic_xstats_clear(res->portnum);
7115         } else if (!strcmp(res->what, "info"))
7116                 port_infos_display(res->portnum);
7117         else if (!strcmp(res->what, "stats"))
7118                 nic_stats_display(res->portnum);
7119         else if (!strcmp(res->what, "xstats"))
7120                 nic_xstats_display(res->portnum);
7121         else if (!strcmp(res->what, "fdir"))
7122                  fdir_get_infos(res->portnum);
7123         else if (!strcmp(res->what, "stat_qmap"))
7124                 nic_stats_mapping_display(res->portnum);
7125         else if (!strcmp(res->what, "dcb_tc"))
7126                 port_dcb_info_display(res->portnum);
7127         else if (!strcmp(res->what, "cap"))
7128                 port_offload_cap_display(res->portnum);
7129 }
7130
7131 cmdline_parse_token_string_t cmd_showport_show =
7132         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7133                                  "show#clear");
7134 cmdline_parse_token_string_t cmd_showport_port =
7135         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7136 cmdline_parse_token_string_t cmd_showport_what =
7137         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7138                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7139 cmdline_parse_token_num_t cmd_showport_portnum =
7140         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7141
7142 cmdline_parse_inst_t cmd_showport = {
7143         .f = cmd_showport_parsed,
7144         .data = NULL,
7145         .help_str = "show|clear port "
7146                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7147                 "<port_id>",
7148         .tokens = {
7149                 (void *)&cmd_showport_show,
7150                 (void *)&cmd_showport_port,
7151                 (void *)&cmd_showport_what,
7152                 (void *)&cmd_showport_portnum,
7153                 NULL,
7154         },
7155 };
7156
7157 /* *** SHOW QUEUE INFO *** */
7158 struct cmd_showqueue_result {
7159         cmdline_fixed_string_t show;
7160         cmdline_fixed_string_t type;
7161         cmdline_fixed_string_t what;
7162         uint16_t portnum;
7163         uint16_t queuenum;
7164 };
7165
7166 static void
7167 cmd_showqueue_parsed(void *parsed_result,
7168         __attribute__((unused)) struct cmdline *cl,
7169         __attribute__((unused)) void *data)
7170 {
7171         struct cmd_showqueue_result *res = parsed_result;
7172
7173         if (!strcmp(res->type, "rxq"))
7174                 rx_queue_infos_display(res->portnum, res->queuenum);
7175         else if (!strcmp(res->type, "txq"))
7176                 tx_queue_infos_display(res->portnum, res->queuenum);
7177 }
7178
7179 cmdline_parse_token_string_t cmd_showqueue_show =
7180         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7181 cmdline_parse_token_string_t cmd_showqueue_type =
7182         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7183 cmdline_parse_token_string_t cmd_showqueue_what =
7184         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7185 cmdline_parse_token_num_t cmd_showqueue_portnum =
7186         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7187 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7188         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7189
7190 cmdline_parse_inst_t cmd_showqueue = {
7191         .f = cmd_showqueue_parsed,
7192         .data = NULL,
7193         .help_str = "show rxq|txq info <port_id> <queue_id>",
7194         .tokens = {
7195                 (void *)&cmd_showqueue_show,
7196                 (void *)&cmd_showqueue_type,
7197                 (void *)&cmd_showqueue_what,
7198                 (void *)&cmd_showqueue_portnum,
7199                 (void *)&cmd_showqueue_queuenum,
7200                 NULL,
7201         },
7202 };
7203
7204 /* *** READ PORT REGISTER *** */
7205 struct cmd_read_reg_result {
7206         cmdline_fixed_string_t read;
7207         cmdline_fixed_string_t reg;
7208         portid_t port_id;
7209         uint32_t reg_off;
7210 };
7211
7212 static void
7213 cmd_read_reg_parsed(void *parsed_result,
7214                     __attribute__((unused)) struct cmdline *cl,
7215                     __attribute__((unused)) void *data)
7216 {
7217         struct cmd_read_reg_result *res = parsed_result;
7218         port_reg_display(res->port_id, res->reg_off);
7219 }
7220
7221 cmdline_parse_token_string_t cmd_read_reg_read =
7222         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7223 cmdline_parse_token_string_t cmd_read_reg_reg =
7224         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7225 cmdline_parse_token_num_t cmd_read_reg_port_id =
7226         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7227 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7228         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7229
7230 cmdline_parse_inst_t cmd_read_reg = {
7231         .f = cmd_read_reg_parsed,
7232         .data = NULL,
7233         .help_str = "read reg <port_id> <reg_off>",
7234         .tokens = {
7235                 (void *)&cmd_read_reg_read,
7236                 (void *)&cmd_read_reg_reg,
7237                 (void *)&cmd_read_reg_port_id,
7238                 (void *)&cmd_read_reg_reg_off,
7239                 NULL,
7240         },
7241 };
7242
7243 /* *** READ PORT REGISTER BIT FIELD *** */
7244 struct cmd_read_reg_bit_field_result {
7245         cmdline_fixed_string_t read;
7246         cmdline_fixed_string_t regfield;
7247         portid_t port_id;
7248         uint32_t reg_off;
7249         uint8_t bit1_pos;
7250         uint8_t bit2_pos;
7251 };
7252
7253 static void
7254 cmd_read_reg_bit_field_parsed(void *parsed_result,
7255                               __attribute__((unused)) struct cmdline *cl,
7256                               __attribute__((unused)) void *data)
7257 {
7258         struct cmd_read_reg_bit_field_result *res = parsed_result;
7259         port_reg_bit_field_display(res->port_id, res->reg_off,
7260                                    res->bit1_pos, res->bit2_pos);
7261 }
7262
7263 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7264         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7265                                  "read");
7266 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7267         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7268                                  regfield, "regfield");
7269 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7270         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7271                               UINT16);
7272 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7273         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7274                               UINT32);
7275 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7276         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7277                               UINT8);
7278 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7279         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7280                               UINT8);
7281
7282 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7283         .f = cmd_read_reg_bit_field_parsed,
7284         .data = NULL,
7285         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7286         "Read register bit field between bit_x and bit_y included",
7287         .tokens = {
7288                 (void *)&cmd_read_reg_bit_field_read,
7289                 (void *)&cmd_read_reg_bit_field_regfield,
7290                 (void *)&cmd_read_reg_bit_field_port_id,
7291                 (void *)&cmd_read_reg_bit_field_reg_off,
7292                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7293                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7294                 NULL,
7295         },
7296 };
7297
7298 /* *** READ PORT REGISTER BIT *** */
7299 struct cmd_read_reg_bit_result {
7300         cmdline_fixed_string_t read;
7301         cmdline_fixed_string_t regbit;
7302         portid_t port_id;
7303         uint32_t reg_off;
7304         uint8_t bit_pos;
7305 };
7306
7307 static void
7308 cmd_read_reg_bit_parsed(void *parsed_result,
7309                         __attribute__((unused)) struct cmdline *cl,
7310                         __attribute__((unused)) void *data)
7311 {
7312         struct cmd_read_reg_bit_result *res = parsed_result;
7313         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7314 }
7315
7316 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7317         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7318 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7319         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7320                                  regbit, "regbit");
7321 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7322         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7323 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7324         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7325 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7326         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7327
7328 cmdline_parse_inst_t cmd_read_reg_bit = {
7329         .f = cmd_read_reg_bit_parsed,
7330         .data = NULL,
7331         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7332         .tokens = {
7333                 (void *)&cmd_read_reg_bit_read,
7334                 (void *)&cmd_read_reg_bit_regbit,
7335                 (void *)&cmd_read_reg_bit_port_id,
7336                 (void *)&cmd_read_reg_bit_reg_off,
7337                 (void *)&cmd_read_reg_bit_bit_pos,
7338                 NULL,
7339         },
7340 };
7341
7342 /* *** WRITE PORT REGISTER *** */
7343 struct cmd_write_reg_result {
7344         cmdline_fixed_string_t write;
7345         cmdline_fixed_string_t reg;
7346         portid_t port_id;
7347         uint32_t reg_off;
7348         uint32_t value;
7349 };
7350
7351 static void
7352 cmd_write_reg_parsed(void *parsed_result,
7353                      __attribute__((unused)) struct cmdline *cl,
7354                      __attribute__((unused)) void *data)
7355 {
7356         struct cmd_write_reg_result *res = parsed_result;
7357         port_reg_set(res->port_id, res->reg_off, res->value);
7358 }
7359
7360 cmdline_parse_token_string_t cmd_write_reg_write =
7361         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7362 cmdline_parse_token_string_t cmd_write_reg_reg =
7363         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7364 cmdline_parse_token_num_t cmd_write_reg_port_id =
7365         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7366 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7367         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7368 cmdline_parse_token_num_t cmd_write_reg_value =
7369         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7370
7371 cmdline_parse_inst_t cmd_write_reg = {
7372         .f = cmd_write_reg_parsed,
7373         .data = NULL,
7374         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7375         .tokens = {
7376                 (void *)&cmd_write_reg_write,
7377                 (void *)&cmd_write_reg_reg,
7378                 (void *)&cmd_write_reg_port_id,
7379                 (void *)&cmd_write_reg_reg_off,
7380                 (void *)&cmd_write_reg_value,
7381                 NULL,
7382         },
7383 };
7384
7385 /* *** WRITE PORT REGISTER BIT FIELD *** */
7386 struct cmd_write_reg_bit_field_result {
7387         cmdline_fixed_string_t write;
7388         cmdline_fixed_string_t regfield;
7389         portid_t port_id;
7390         uint32_t reg_off;
7391         uint8_t bit1_pos;
7392         uint8_t bit2_pos;
7393         uint32_t value;
7394 };
7395
7396 static void
7397 cmd_write_reg_bit_field_parsed(void *parsed_result,
7398                                __attribute__((unused)) struct cmdline *cl,
7399                                __attribute__((unused)) void *data)
7400 {
7401         struct cmd_write_reg_bit_field_result *res = parsed_result;
7402         port_reg_bit_field_set(res->port_id, res->reg_off,
7403                           res->bit1_pos, res->bit2_pos, res->value);
7404 }
7405
7406 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7407         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7408                                  "write");
7409 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7410         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7411                                  regfield, "regfield");
7412 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7413         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7414                               UINT16);
7415 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7416         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7417                               UINT32);
7418 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7419         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7420                               UINT8);
7421 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7422         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7423                               UINT8);
7424 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7425         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7426                               UINT32);
7427
7428 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7429         .f = cmd_write_reg_bit_field_parsed,
7430         .data = NULL,
7431         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7432                 "<reg_value>: "
7433                 "Set register bit field between bit_x and bit_y included",
7434         .tokens = {
7435                 (void *)&cmd_write_reg_bit_field_write,
7436                 (void *)&cmd_write_reg_bit_field_regfield,
7437                 (void *)&cmd_write_reg_bit_field_port_id,
7438                 (void *)&cmd_write_reg_bit_field_reg_off,
7439                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7440                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7441                 (void *)&cmd_write_reg_bit_field_value,
7442                 NULL,
7443         },
7444 };
7445
7446 /* *** WRITE PORT REGISTER BIT *** */
7447 struct cmd_write_reg_bit_result {
7448         cmdline_fixed_string_t write;
7449         cmdline_fixed_string_t regbit;
7450         portid_t port_id;
7451         uint32_t reg_off;
7452         uint8_t bit_pos;
7453         uint8_t value;
7454 };
7455
7456 static void
7457 cmd_write_reg_bit_parsed(void *parsed_result,
7458                          __attribute__((unused)) struct cmdline *cl,
7459                          __attribute__((unused)) void *data)
7460 {
7461         struct cmd_write_reg_bit_result *res = parsed_result;
7462         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7463 }
7464
7465 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7466         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7467                                  "write");
7468 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7469         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7470                                  regbit, "regbit");
7471 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7472         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7473 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7474         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7475 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7476         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7477 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7478         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7479
7480 cmdline_parse_inst_t cmd_write_reg_bit = {
7481         .f = cmd_write_reg_bit_parsed,
7482         .data = NULL,
7483         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7484                 "0 <= bit_x <= 31",
7485         .tokens = {
7486                 (void *)&cmd_write_reg_bit_write,
7487                 (void *)&cmd_write_reg_bit_regbit,
7488                 (void *)&cmd_write_reg_bit_port_id,
7489                 (void *)&cmd_write_reg_bit_reg_off,
7490                 (void *)&cmd_write_reg_bit_bit_pos,
7491                 (void *)&cmd_write_reg_bit_value,
7492                 NULL,
7493         },
7494 };
7495
7496 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7497 struct cmd_read_rxd_txd_result {
7498         cmdline_fixed_string_t read;
7499         cmdline_fixed_string_t rxd_txd;
7500         portid_t port_id;
7501         uint16_t queue_id;
7502         uint16_t desc_id;
7503 };
7504
7505 static void
7506 cmd_read_rxd_txd_parsed(void *parsed_result,
7507                         __attribute__((unused)) struct cmdline *cl,
7508                         __attribute__((unused)) void *data)
7509 {
7510         struct cmd_read_rxd_txd_result *res = parsed_result;
7511
7512         if (!strcmp(res->rxd_txd, "rxd"))
7513                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7514         else if (!strcmp(res->rxd_txd, "txd"))
7515                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7516 }
7517
7518 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7519         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7520 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7521         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7522                                  "rxd#txd");
7523 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7524         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7525 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7526         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7527 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7528         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7529
7530 cmdline_parse_inst_t cmd_read_rxd_txd = {
7531         .f = cmd_read_rxd_txd_parsed,
7532         .data = NULL,
7533         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7534         .tokens = {
7535                 (void *)&cmd_read_rxd_txd_read,
7536                 (void *)&cmd_read_rxd_txd_rxd_txd,
7537                 (void *)&cmd_read_rxd_txd_port_id,
7538                 (void *)&cmd_read_rxd_txd_queue_id,
7539                 (void *)&cmd_read_rxd_txd_desc_id,
7540                 NULL,
7541         },
7542 };
7543
7544 /* *** QUIT *** */
7545 struct cmd_quit_result {
7546         cmdline_fixed_string_t quit;
7547 };
7548
7549 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7550                             struct cmdline *cl,
7551                             __attribute__((unused)) void *data)
7552 {
7553         pmd_test_exit();
7554         cmdline_quit(cl);
7555 }
7556
7557 cmdline_parse_token_string_t cmd_quit_quit =
7558         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7559
7560 cmdline_parse_inst_t cmd_quit = {
7561         .f = cmd_quit_parsed,
7562         .data = NULL,
7563         .help_str = "quit: Exit application",
7564         .tokens = {
7565                 (void *)&cmd_quit_quit,
7566                 NULL,
7567         },
7568 };
7569
7570 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7571 struct cmd_mac_addr_result {
7572         cmdline_fixed_string_t mac_addr_cmd;
7573         cmdline_fixed_string_t what;
7574         uint16_t port_num;
7575         struct ether_addr address;
7576 };
7577
7578 static void cmd_mac_addr_parsed(void *parsed_result,
7579                 __attribute__((unused)) struct cmdline *cl,
7580                 __attribute__((unused)) void *data)
7581 {
7582         struct cmd_mac_addr_result *res = parsed_result;
7583         int ret;
7584
7585         if (strcmp(res->what, "add") == 0)
7586                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7587         else if (strcmp(res->what, "set") == 0)
7588                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7589                                                        &res->address);
7590         else
7591                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7592
7593         /* check the return value and print it if is < 0 */
7594         if(ret < 0)
7595                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7596
7597 }
7598
7599 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7600         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7601                                 "mac_addr");
7602 cmdline_parse_token_string_t cmd_mac_addr_what =
7603         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7604                                 "add#remove#set");
7605 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7606                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7607                                         UINT16);
7608 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7609                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7610
7611 cmdline_parse_inst_t cmd_mac_addr = {
7612         .f = cmd_mac_addr_parsed,
7613         .data = (void *)0,
7614         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7615                         "Add/Remove/Set MAC address on port_id",
7616         .tokens = {
7617                 (void *)&cmd_mac_addr_cmd,
7618                 (void *)&cmd_mac_addr_what,
7619                 (void *)&cmd_mac_addr_portnum,
7620                 (void *)&cmd_mac_addr_addr,
7621                 NULL,
7622         },
7623 };
7624
7625 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7626 struct cmd_eth_peer_result {
7627         cmdline_fixed_string_t set;
7628         cmdline_fixed_string_t eth_peer;
7629         portid_t port_id;
7630         cmdline_fixed_string_t peer_addr;
7631 };
7632
7633 static void cmd_set_eth_peer_parsed(void *parsed_result,
7634                         __attribute__((unused)) struct cmdline *cl,
7635                         __attribute__((unused)) void *data)
7636 {
7637                 struct cmd_eth_peer_result *res = parsed_result;
7638
7639                 if (test_done == 0) {
7640                         printf("Please stop forwarding first\n");
7641                         return;
7642                 }
7643                 if (!strcmp(res->eth_peer, "eth-peer")) {
7644                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7645                         fwd_config_setup();
7646                 }
7647 }
7648 cmdline_parse_token_string_t cmd_eth_peer_set =
7649         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7650 cmdline_parse_token_string_t cmd_eth_peer =
7651         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7652 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7653         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7654 cmdline_parse_token_string_t cmd_eth_peer_addr =
7655         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7656
7657 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7658         .f = cmd_set_eth_peer_parsed,
7659         .data = NULL,
7660         .help_str = "set eth-peer <port_id> <peer_mac>",
7661         .tokens = {
7662                 (void *)&cmd_eth_peer_set,
7663                 (void *)&cmd_eth_peer,
7664                 (void *)&cmd_eth_peer_port_id,
7665                 (void *)&cmd_eth_peer_addr,
7666                 NULL,
7667         },
7668 };
7669
7670 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7671 struct cmd_set_qmap_result {
7672         cmdline_fixed_string_t set;
7673         cmdline_fixed_string_t qmap;
7674         cmdline_fixed_string_t what;
7675         portid_t port_id;
7676         uint16_t queue_id;
7677         uint8_t map_value;
7678 };
7679
7680 static void
7681 cmd_set_qmap_parsed(void *parsed_result,
7682                        __attribute__((unused)) struct cmdline *cl,
7683                        __attribute__((unused)) void *data)
7684 {
7685         struct cmd_set_qmap_result *res = parsed_result;
7686         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7687
7688         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7689 }
7690
7691 cmdline_parse_token_string_t cmd_setqmap_set =
7692         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7693                                  set, "set");
7694 cmdline_parse_token_string_t cmd_setqmap_qmap =
7695         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7696                                  qmap, "stat_qmap");
7697 cmdline_parse_token_string_t cmd_setqmap_what =
7698         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7699                                  what, "tx#rx");
7700 cmdline_parse_token_num_t cmd_setqmap_portid =
7701         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7702                               port_id, UINT16);
7703 cmdline_parse_token_num_t cmd_setqmap_queueid =
7704         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7705                               queue_id, UINT16);
7706 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7707         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7708                               map_value, UINT8);
7709
7710 cmdline_parse_inst_t cmd_set_qmap = {
7711         .f = cmd_set_qmap_parsed,
7712         .data = NULL,
7713         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7714                 "Set statistics mapping value on tx|rx queue_id of port_id",
7715         .tokens = {
7716                 (void *)&cmd_setqmap_set,
7717                 (void *)&cmd_setqmap_qmap,
7718                 (void *)&cmd_setqmap_what,
7719                 (void *)&cmd_setqmap_portid,
7720                 (void *)&cmd_setqmap_queueid,
7721                 (void *)&cmd_setqmap_mapvalue,
7722                 NULL,
7723         },
7724 };
7725
7726 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7727 struct cmd_set_xstats_hide_zero_result {
7728         cmdline_fixed_string_t keyword;
7729         cmdline_fixed_string_t name;
7730         cmdline_fixed_string_t on_off;
7731 };
7732
7733 static void
7734 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7735                         __attribute__((unused)) struct cmdline *cl,
7736                         __attribute__((unused)) void *data)
7737 {
7738         struct cmd_set_xstats_hide_zero_result *res;
7739         uint16_t on_off = 0;
7740
7741         res = parsed_result;
7742         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7743         set_xstats_hide_zero(on_off);
7744 }
7745
7746 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7747         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7748                                  keyword, "set");
7749 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7750         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7751                                  name, "xstats-hide-zero");
7752 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7753         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7754                                  on_off, "on#off");
7755
7756 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7757         .f = cmd_set_xstats_hide_zero_parsed,
7758         .data = NULL,
7759         .help_str = "set xstats-hide-zero on|off",
7760         .tokens = {
7761                 (void *)&cmd_set_xstats_hide_zero_keyword,
7762                 (void *)&cmd_set_xstats_hide_zero_name,
7763                 (void *)&cmd_set_xstats_hide_zero_on_off,
7764                 NULL,
7765         },
7766 };
7767
7768 /* *** CONFIGURE UNICAST HASH TABLE *** */
7769 struct cmd_set_uc_hash_table {
7770         cmdline_fixed_string_t set;
7771         cmdline_fixed_string_t port;
7772         portid_t port_id;
7773         cmdline_fixed_string_t what;
7774         struct ether_addr address;
7775         cmdline_fixed_string_t mode;
7776 };
7777
7778 static void
7779 cmd_set_uc_hash_parsed(void *parsed_result,
7780                        __attribute__((unused)) struct cmdline *cl,
7781                        __attribute__((unused)) void *data)
7782 {
7783         int ret=0;
7784         struct cmd_set_uc_hash_table *res = parsed_result;
7785
7786         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7787
7788         if (strcmp(res->what, "uta") == 0)
7789                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7790                                                 &res->address,(uint8_t)is_on);
7791         if (ret < 0)
7792                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7793
7794 }
7795
7796 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7797         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7798                                  set, "set");
7799 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7800         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7801                                  port, "port");
7802 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7803         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7804                               port_id, UINT16);
7805 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7806         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7807                                  what, "uta");
7808 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7809         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7810                                 address);
7811 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7812         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7813                                  mode, "on#off");
7814
7815 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7816         .f = cmd_set_uc_hash_parsed,
7817         .data = NULL,
7818         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7819         .tokens = {
7820                 (void *)&cmd_set_uc_hash_set,
7821                 (void *)&cmd_set_uc_hash_port,
7822                 (void *)&cmd_set_uc_hash_portid,
7823                 (void *)&cmd_set_uc_hash_what,
7824                 (void *)&cmd_set_uc_hash_mac,
7825                 (void *)&cmd_set_uc_hash_mode,
7826                 NULL,
7827         },
7828 };
7829
7830 struct cmd_set_uc_all_hash_table {
7831         cmdline_fixed_string_t set;
7832         cmdline_fixed_string_t port;
7833         portid_t port_id;
7834         cmdline_fixed_string_t what;
7835         cmdline_fixed_string_t value;
7836         cmdline_fixed_string_t mode;
7837 };
7838
7839 static void
7840 cmd_set_uc_all_hash_parsed(void *parsed_result,
7841                        __attribute__((unused)) struct cmdline *cl,
7842                        __attribute__((unused)) void *data)
7843 {
7844         int ret=0;
7845         struct cmd_set_uc_all_hash_table *res = parsed_result;
7846
7847         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7848
7849         if ((strcmp(res->what, "uta") == 0) &&
7850                 (strcmp(res->value, "all") == 0))
7851                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7852         if (ret < 0)
7853                 printf("bad unicast hash table parameter,"
7854                         "return code = %d \n", ret);
7855 }
7856
7857 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7858         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7859                                  set, "set");
7860 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7861         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7862                                  port, "port");
7863 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7864         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7865                               port_id, UINT16);
7866 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7867         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7868                                  what, "uta");
7869 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7870         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7871                                 value,"all");
7872 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7873         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7874                                  mode, "on#off");
7875
7876 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7877         .f = cmd_set_uc_all_hash_parsed,
7878         .data = NULL,
7879         .help_str = "set port <port_id> uta all on|off",
7880         .tokens = {
7881                 (void *)&cmd_set_uc_all_hash_set,
7882                 (void *)&cmd_set_uc_all_hash_port,
7883                 (void *)&cmd_set_uc_all_hash_portid,
7884                 (void *)&cmd_set_uc_all_hash_what,
7885                 (void *)&cmd_set_uc_all_hash_value,
7886                 (void *)&cmd_set_uc_all_hash_mode,
7887                 NULL,
7888         },
7889 };
7890
7891 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7892 struct cmd_set_vf_macvlan_filter {
7893         cmdline_fixed_string_t set;
7894         cmdline_fixed_string_t port;
7895         portid_t port_id;
7896         cmdline_fixed_string_t vf;
7897         uint8_t vf_id;
7898         struct ether_addr address;
7899         cmdline_fixed_string_t filter_type;
7900         cmdline_fixed_string_t mode;
7901 };
7902
7903 static void
7904 cmd_set_vf_macvlan_parsed(void *parsed_result,
7905                        __attribute__((unused)) struct cmdline *cl,
7906                        __attribute__((unused)) void *data)
7907 {
7908         int is_on, ret = 0;
7909         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7910         struct rte_eth_mac_filter filter;
7911
7912         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7913
7914         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7915
7916         /* set VF MAC filter */
7917         filter.is_vf = 1;
7918
7919         /* set VF ID */
7920         filter.dst_id = res->vf_id;
7921
7922         if (!strcmp(res->filter_type, "exact-mac"))
7923                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7924         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7925                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7926         else if (!strcmp(res->filter_type, "hashmac"))
7927                 filter.filter_type = RTE_MAC_HASH_MATCH;
7928         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7929                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7930
7931         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7932
7933         if (is_on)
7934                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7935                                         RTE_ETH_FILTER_MACVLAN,
7936                                         RTE_ETH_FILTER_ADD,
7937                                          &filter);
7938         else
7939                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7940                                         RTE_ETH_FILTER_MACVLAN,
7941                                         RTE_ETH_FILTER_DELETE,
7942                                         &filter);
7943
7944         if (ret < 0)
7945                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7946
7947 }
7948
7949 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7950         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7951                                  set, "set");
7952 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7953         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7954                                  port, "port");
7955 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7956         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7957                               port_id, UINT16);
7958 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7959         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7960                                  vf, "vf");
7961 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7962         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7963                                 vf_id, UINT8);
7964 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7965         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7966                                 address);
7967 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7968         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7969                                 filter_type, "exact-mac#exact-mac-vlan"
7970                                 "#hashmac#hashmac-vlan");
7971 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7972         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7973                                  mode, "on#off");
7974
7975 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7976         .f = cmd_set_vf_macvlan_parsed,
7977         .data = NULL,
7978         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7979                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7980                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7981                 "hash match rule: hash match of MAC and exact match of VLAN",
7982         .tokens = {
7983                 (void *)&cmd_set_vf_macvlan_set,
7984                 (void *)&cmd_set_vf_macvlan_port,
7985                 (void *)&cmd_set_vf_macvlan_portid,
7986                 (void *)&cmd_set_vf_macvlan_vf,
7987                 (void *)&cmd_set_vf_macvlan_vf_id,
7988                 (void *)&cmd_set_vf_macvlan_mac,
7989                 (void *)&cmd_set_vf_macvlan_filter_type,
7990                 (void *)&cmd_set_vf_macvlan_mode,
7991                 NULL,
7992         },
7993 };
7994
7995 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7996 struct cmd_set_vf_traffic {
7997         cmdline_fixed_string_t set;
7998         cmdline_fixed_string_t port;
7999         portid_t port_id;
8000         cmdline_fixed_string_t vf;
8001         uint8_t vf_id;
8002         cmdline_fixed_string_t what;
8003         cmdline_fixed_string_t mode;
8004 };
8005
8006 static void
8007 cmd_set_vf_traffic_parsed(void *parsed_result,
8008                        __attribute__((unused)) struct cmdline *cl,
8009                        __attribute__((unused)) void *data)
8010 {
8011         struct cmd_set_vf_traffic *res = parsed_result;
8012         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8013         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8014
8015         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8016 }
8017
8018 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8019         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8020                                  set, "set");
8021 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8022         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8023                                  port, "port");
8024 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8025         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8026                               port_id, UINT16);
8027 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8028         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8029                                  vf, "vf");
8030 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8031         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8032                               vf_id, UINT8);
8033 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8034         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8035                                  what, "tx#rx");
8036 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8038                                  mode, "on#off");
8039
8040 cmdline_parse_inst_t cmd_set_vf_traffic = {
8041         .f = cmd_set_vf_traffic_parsed,
8042         .data = NULL,
8043         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8044         .tokens = {
8045                 (void *)&cmd_setvf_traffic_set,
8046                 (void *)&cmd_setvf_traffic_port,
8047                 (void *)&cmd_setvf_traffic_portid,
8048                 (void *)&cmd_setvf_traffic_vf,
8049                 (void *)&cmd_setvf_traffic_vfid,
8050                 (void *)&cmd_setvf_traffic_what,
8051                 (void *)&cmd_setvf_traffic_mode,
8052                 NULL,
8053         },
8054 };
8055
8056 /* *** CONFIGURE VF RECEIVE MODE *** */
8057 struct cmd_set_vf_rxmode {
8058         cmdline_fixed_string_t set;
8059         cmdline_fixed_string_t port;
8060         portid_t port_id;
8061         cmdline_fixed_string_t vf;
8062         uint8_t vf_id;
8063         cmdline_fixed_string_t what;
8064         cmdline_fixed_string_t mode;
8065         cmdline_fixed_string_t on;
8066 };
8067
8068 static void
8069 cmd_set_vf_rxmode_parsed(void *parsed_result,
8070                        __attribute__((unused)) struct cmdline *cl,
8071                        __attribute__((unused)) void *data)
8072 {
8073         int ret = -ENOTSUP;
8074         uint16_t rx_mode = 0;
8075         struct cmd_set_vf_rxmode *res = parsed_result;
8076
8077         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8078         if (!strcmp(res->what,"rxmode")) {
8079                 if (!strcmp(res->mode, "AUPE"))
8080                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8081                 else if (!strcmp(res->mode, "ROPE"))
8082                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8083                 else if (!strcmp(res->mode, "BAM"))
8084                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8085                 else if (!strncmp(res->mode, "MPE",3))
8086                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8087         }
8088
8089         RTE_SET_USED(is_on);
8090
8091 #ifdef RTE_LIBRTE_IXGBE_PMD
8092         if (ret == -ENOTSUP)
8093                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8094                                                   rx_mode, (uint8_t)is_on);
8095 #endif
8096 #ifdef RTE_LIBRTE_BNXT_PMD
8097         if (ret == -ENOTSUP)
8098                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8099                                                  rx_mode, (uint8_t)is_on);
8100 #endif
8101         if (ret < 0)
8102                 printf("bad VF receive mode parameter, return code = %d \n",
8103                 ret);
8104 }
8105
8106 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8107         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8108                                  set, "set");
8109 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8110         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8111                                  port, "port");
8112 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8113         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8114                               port_id, UINT16);
8115 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8116         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8117                                  vf, "vf");
8118 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8119         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8120                               vf_id, UINT8);
8121 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8122         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8123                                  what, "rxmode");
8124 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8125         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8126                                  mode, "AUPE#ROPE#BAM#MPE");
8127 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8128         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8129                                  on, "on#off");
8130
8131 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8132         .f = cmd_set_vf_rxmode_parsed,
8133         .data = NULL,
8134         .help_str = "set port <port_id> vf <vf_id> rxmode "
8135                 "AUPE|ROPE|BAM|MPE on|off",
8136         .tokens = {
8137                 (void *)&cmd_set_vf_rxmode_set,
8138                 (void *)&cmd_set_vf_rxmode_port,
8139                 (void *)&cmd_set_vf_rxmode_portid,
8140                 (void *)&cmd_set_vf_rxmode_vf,
8141                 (void *)&cmd_set_vf_rxmode_vfid,
8142                 (void *)&cmd_set_vf_rxmode_what,
8143                 (void *)&cmd_set_vf_rxmode_mode,
8144                 (void *)&cmd_set_vf_rxmode_on,
8145                 NULL,
8146         },
8147 };
8148
8149 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8150 struct cmd_vf_mac_addr_result {
8151         cmdline_fixed_string_t mac_addr_cmd;
8152         cmdline_fixed_string_t what;
8153         cmdline_fixed_string_t port;
8154         uint16_t port_num;
8155         cmdline_fixed_string_t vf;
8156         uint8_t vf_num;
8157         struct ether_addr address;
8158 };
8159
8160 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8161                 __attribute__((unused)) struct cmdline *cl,
8162                 __attribute__((unused)) void *data)
8163 {
8164         struct cmd_vf_mac_addr_result *res = parsed_result;
8165         int ret = -ENOTSUP;
8166
8167         if (strcmp(res->what, "add") != 0)
8168                 return;
8169
8170 #ifdef RTE_LIBRTE_I40E_PMD
8171         if (ret == -ENOTSUP)
8172                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8173                                                    &res->address);
8174 #endif
8175 #ifdef RTE_LIBRTE_BNXT_PMD
8176         if (ret == -ENOTSUP)
8177                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8178                                                 res->vf_num);
8179 #endif
8180
8181         if(ret < 0)
8182                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8183
8184 }
8185
8186 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8187         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8188                                 mac_addr_cmd,"mac_addr");
8189 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8190         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8191                                 what,"add");
8192 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8193         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8194                                 port,"port");
8195 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8196         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8197                                 port_num, UINT16);
8198 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8199         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8200                                 vf,"vf");
8201 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8202         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8203                                 vf_num, UINT8);
8204 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8205         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8206                                 address);
8207
8208 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8209         .f = cmd_vf_mac_addr_parsed,
8210         .data = (void *)0,
8211         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8212                 "Add MAC address filtering for a VF on port_id",
8213         .tokens = {
8214                 (void *)&cmd_vf_mac_addr_cmd,
8215                 (void *)&cmd_vf_mac_addr_what,
8216                 (void *)&cmd_vf_mac_addr_port,
8217                 (void *)&cmd_vf_mac_addr_portnum,
8218                 (void *)&cmd_vf_mac_addr_vf,
8219                 (void *)&cmd_vf_mac_addr_vfnum,
8220                 (void *)&cmd_vf_mac_addr_addr,
8221                 NULL,
8222         },
8223 };
8224
8225 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8226 struct cmd_vf_rx_vlan_filter {
8227         cmdline_fixed_string_t rx_vlan;
8228         cmdline_fixed_string_t what;
8229         uint16_t vlan_id;
8230         cmdline_fixed_string_t port;
8231         portid_t port_id;
8232         cmdline_fixed_string_t vf;
8233         uint64_t vf_mask;
8234 };
8235
8236 static void
8237 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8238                           __attribute__((unused)) struct cmdline *cl,
8239                           __attribute__((unused)) void *data)
8240 {
8241         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8242         int ret = -ENOTSUP;
8243
8244         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8245
8246 #ifdef RTE_LIBRTE_IXGBE_PMD
8247         if (ret == -ENOTSUP)
8248                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8249                                 res->vlan_id, res->vf_mask, is_add);
8250 #endif
8251 #ifdef RTE_LIBRTE_I40E_PMD
8252         if (ret == -ENOTSUP)
8253                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8254                                 res->vlan_id, res->vf_mask, is_add);
8255 #endif
8256 #ifdef RTE_LIBRTE_BNXT_PMD
8257         if (ret == -ENOTSUP)
8258                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8259                                 res->vlan_id, res->vf_mask, is_add);
8260 #endif
8261
8262         switch (ret) {
8263         case 0:
8264                 break;
8265         case -EINVAL:
8266                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8267                                 res->vlan_id, res->vf_mask);
8268                 break;
8269         case -ENODEV:
8270                 printf("invalid port_id %d\n", res->port_id);
8271                 break;
8272         case -ENOTSUP:
8273                 printf("function not implemented or supported\n");
8274                 break;
8275         default:
8276                 printf("programming error: (%s)\n", strerror(-ret));
8277         }
8278 }
8279
8280 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8281         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8282                                  rx_vlan, "rx_vlan");
8283 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8284         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8285                                  what, "add#rm");
8286 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8287         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8288                               vlan_id, UINT16);
8289 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8290         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8291                                  port, "port");
8292 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8293         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8294                               port_id, UINT16);
8295 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8296         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8297                                  vf, "vf");
8298 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8299         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8300                               vf_mask, UINT64);
8301
8302 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8303         .f = cmd_vf_rx_vlan_filter_parsed,
8304         .data = NULL,
8305         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8306                 "(vf_mask = hexadecimal VF mask)",
8307         .tokens = {
8308                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8309                 (void *)&cmd_vf_rx_vlan_filter_what,
8310                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8311                 (void *)&cmd_vf_rx_vlan_filter_port,
8312                 (void *)&cmd_vf_rx_vlan_filter_portid,
8313                 (void *)&cmd_vf_rx_vlan_filter_vf,
8314                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8315                 NULL,
8316         },
8317 };
8318
8319 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8320 struct cmd_queue_rate_limit_result {
8321         cmdline_fixed_string_t set;
8322         cmdline_fixed_string_t port;
8323         uint16_t port_num;
8324         cmdline_fixed_string_t queue;
8325         uint8_t queue_num;
8326         cmdline_fixed_string_t rate;
8327         uint16_t rate_num;
8328 };
8329
8330 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8331                 __attribute__((unused)) struct cmdline *cl,
8332                 __attribute__((unused)) void *data)
8333 {
8334         struct cmd_queue_rate_limit_result *res = parsed_result;
8335         int ret = 0;
8336
8337         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8338                 && (strcmp(res->queue, "queue") == 0)
8339                 && (strcmp(res->rate, "rate") == 0))
8340                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8341                                         res->rate_num);
8342         if (ret < 0)
8343                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8344
8345 }
8346
8347 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8348         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8349                                 set, "set");
8350 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8351         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8352                                 port, "port");
8353 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8354         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8355                                 port_num, UINT16);
8356 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8357         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8358                                 queue, "queue");
8359 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8360         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8361                                 queue_num, UINT8);
8362 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8363         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8364                                 rate, "rate");
8365 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8366         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8367                                 rate_num, UINT16);
8368
8369 cmdline_parse_inst_t cmd_queue_rate_limit = {
8370         .f = cmd_queue_rate_limit_parsed,
8371         .data = (void *)0,
8372         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8373                 "Set rate limit for a queue on port_id",
8374         .tokens = {
8375                 (void *)&cmd_queue_rate_limit_set,
8376                 (void *)&cmd_queue_rate_limit_port,
8377                 (void *)&cmd_queue_rate_limit_portnum,
8378                 (void *)&cmd_queue_rate_limit_queue,
8379                 (void *)&cmd_queue_rate_limit_queuenum,
8380                 (void *)&cmd_queue_rate_limit_rate,
8381                 (void *)&cmd_queue_rate_limit_ratenum,
8382                 NULL,
8383         },
8384 };
8385
8386 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8387 struct cmd_vf_rate_limit_result {
8388         cmdline_fixed_string_t set;
8389         cmdline_fixed_string_t port;
8390         uint16_t port_num;
8391         cmdline_fixed_string_t vf;
8392         uint8_t vf_num;
8393         cmdline_fixed_string_t rate;
8394         uint16_t rate_num;
8395         cmdline_fixed_string_t q_msk;
8396         uint64_t q_msk_val;
8397 };
8398
8399 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8400                 __attribute__((unused)) struct cmdline *cl,
8401                 __attribute__((unused)) void *data)
8402 {
8403         struct cmd_vf_rate_limit_result *res = parsed_result;
8404         int ret = 0;
8405
8406         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8407                 && (strcmp(res->vf, "vf") == 0)
8408                 && (strcmp(res->rate, "rate") == 0)
8409                 && (strcmp(res->q_msk, "queue_mask") == 0))
8410                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8411                                         res->rate_num, res->q_msk_val);
8412         if (ret < 0)
8413                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8414
8415 }
8416
8417 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8418         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8419                                 set, "set");
8420 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8421         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8422                                 port, "port");
8423 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8424         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8425                                 port_num, UINT16);
8426 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8427         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8428                                 vf, "vf");
8429 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8430         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8431                                 vf_num, UINT8);
8432 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8433         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8434                                 rate, "rate");
8435 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8436         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8437                                 rate_num, UINT16);
8438 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8439         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8440                                 q_msk, "queue_mask");
8441 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8442         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8443                                 q_msk_val, UINT64);
8444
8445 cmdline_parse_inst_t cmd_vf_rate_limit = {
8446         .f = cmd_vf_rate_limit_parsed,
8447         .data = (void *)0,
8448         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8449                 "queue_mask <queue_mask_value>: "
8450                 "Set rate limit for queues of VF on port_id",
8451         .tokens = {
8452                 (void *)&cmd_vf_rate_limit_set,
8453                 (void *)&cmd_vf_rate_limit_port,
8454                 (void *)&cmd_vf_rate_limit_portnum,
8455                 (void *)&cmd_vf_rate_limit_vf,
8456                 (void *)&cmd_vf_rate_limit_vfnum,
8457                 (void *)&cmd_vf_rate_limit_rate,
8458                 (void *)&cmd_vf_rate_limit_ratenum,
8459                 (void *)&cmd_vf_rate_limit_q_msk,
8460                 (void *)&cmd_vf_rate_limit_q_msk_val,
8461                 NULL,
8462         },
8463 };
8464
8465 /* *** ADD TUNNEL FILTER OF A PORT *** */
8466 struct cmd_tunnel_filter_result {
8467         cmdline_fixed_string_t cmd;
8468         cmdline_fixed_string_t what;
8469         portid_t port_id;
8470         struct ether_addr outer_mac;
8471         struct ether_addr inner_mac;
8472         cmdline_ipaddr_t ip_value;
8473         uint16_t inner_vlan;
8474         cmdline_fixed_string_t tunnel_type;
8475         cmdline_fixed_string_t filter_type;
8476         uint32_t tenant_id;
8477         uint16_t queue_num;
8478 };
8479
8480 static void
8481 cmd_tunnel_filter_parsed(void *parsed_result,
8482                           __attribute__((unused)) struct cmdline *cl,
8483                           __attribute__((unused)) void *data)
8484 {
8485         struct cmd_tunnel_filter_result *res = parsed_result;
8486         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8487         int ret = 0;
8488
8489         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8490
8491         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8492         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8493         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8494
8495         if (res->ip_value.family == AF_INET) {
8496                 tunnel_filter_conf.ip_addr.ipv4_addr =
8497                         res->ip_value.addr.ipv4.s_addr;
8498                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8499         } else {
8500                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8501                         &(res->ip_value.addr.ipv6),
8502                         sizeof(struct in6_addr));
8503                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8504         }
8505
8506         if (!strcmp(res->filter_type, "imac-ivlan"))
8507                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8508         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8509                 tunnel_filter_conf.filter_type =
8510                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8511         else if (!strcmp(res->filter_type, "imac-tenid"))
8512                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8513         else if (!strcmp(res->filter_type, "imac"))
8514                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8515         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8516                 tunnel_filter_conf.filter_type =
8517                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8518         else if (!strcmp(res->filter_type, "oip"))
8519                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8520         else if (!strcmp(res->filter_type, "iip"))
8521                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8522         else {
8523                 printf("The filter type is not supported");
8524                 return;
8525         }
8526
8527         if (!strcmp(res->tunnel_type, "vxlan"))
8528                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8529         else if (!strcmp(res->tunnel_type, "nvgre"))
8530                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8531         else if (!strcmp(res->tunnel_type, "ipingre"))
8532                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8533         else {
8534                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8535                 return;
8536         }
8537
8538         tunnel_filter_conf.tenant_id = res->tenant_id;
8539         tunnel_filter_conf.queue_id = res->queue_num;
8540         if (!strcmp(res->what, "add"))
8541                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8542                                         RTE_ETH_FILTER_TUNNEL,
8543                                         RTE_ETH_FILTER_ADD,
8544                                         &tunnel_filter_conf);
8545         else
8546                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8547                                         RTE_ETH_FILTER_TUNNEL,
8548                                         RTE_ETH_FILTER_DELETE,
8549                                         &tunnel_filter_conf);
8550         if (ret < 0)
8551                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8552                                 strerror(-ret));
8553
8554 }
8555 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8556         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8557         cmd, "tunnel_filter");
8558 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8559         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8560         what, "add#rm");
8561 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8562         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8563         port_id, UINT16);
8564 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8565         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8566         outer_mac);
8567 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8568         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8569         inner_mac);
8570 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8571         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8572         inner_vlan, UINT16);
8573 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8574         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8575         ip_value);
8576 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8577         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8578         tunnel_type, "vxlan#nvgre#ipingre");
8579
8580 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8581         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8582         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8583                 "imac#omac-imac-tenid");
8584 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8585         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8586         tenant_id, UINT32);
8587 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8588         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8589         queue_num, UINT16);
8590
8591 cmdline_parse_inst_t cmd_tunnel_filter = {
8592         .f = cmd_tunnel_filter_parsed,
8593         .data = (void *)0,
8594         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8595                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8596                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8597                 "<queue_id>: Add/Rm tunnel filter of a port",
8598         .tokens = {
8599                 (void *)&cmd_tunnel_filter_cmd,
8600                 (void *)&cmd_tunnel_filter_what,
8601                 (void *)&cmd_tunnel_filter_port_id,
8602                 (void *)&cmd_tunnel_filter_outer_mac,
8603                 (void *)&cmd_tunnel_filter_inner_mac,
8604                 (void *)&cmd_tunnel_filter_ip_value,
8605                 (void *)&cmd_tunnel_filter_innner_vlan,
8606                 (void *)&cmd_tunnel_filter_tunnel_type,
8607                 (void *)&cmd_tunnel_filter_filter_type,
8608                 (void *)&cmd_tunnel_filter_tenant_id,
8609                 (void *)&cmd_tunnel_filter_queue_num,
8610                 NULL,
8611         },
8612 };
8613
8614 /* *** CONFIGURE TUNNEL UDP PORT *** */
8615 struct cmd_tunnel_udp_config {
8616         cmdline_fixed_string_t cmd;
8617         cmdline_fixed_string_t what;
8618         uint16_t udp_port;
8619         portid_t port_id;
8620 };
8621
8622 static void
8623 cmd_tunnel_udp_config_parsed(void *parsed_result,
8624                           __attribute__((unused)) struct cmdline *cl,
8625                           __attribute__((unused)) void *data)
8626 {
8627         struct cmd_tunnel_udp_config *res = parsed_result;
8628         struct rte_eth_udp_tunnel tunnel_udp;
8629         int ret;
8630
8631         tunnel_udp.udp_port = res->udp_port;
8632
8633         if (!strcmp(res->cmd, "rx_vxlan_port"))
8634                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8635
8636         if (!strcmp(res->what, "add"))
8637                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8638                                                       &tunnel_udp);
8639         else
8640                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8641                                                          &tunnel_udp);
8642
8643         if (ret < 0)
8644                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8645 }
8646
8647 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8648         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8649                                 cmd, "rx_vxlan_port");
8650 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8651         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8652                                 what, "add#rm");
8653 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8654         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8655                                 udp_port, UINT16);
8656 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8657         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8658                                 port_id, UINT16);
8659
8660 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8661         .f = cmd_tunnel_udp_config_parsed,
8662         .data = (void *)0,
8663         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8664                 "Add/Remove a tunneling UDP port filter",
8665         .tokens = {
8666                 (void *)&cmd_tunnel_udp_config_cmd,
8667                 (void *)&cmd_tunnel_udp_config_what,
8668                 (void *)&cmd_tunnel_udp_config_udp_port,
8669                 (void *)&cmd_tunnel_udp_config_port_id,
8670                 NULL,
8671         },
8672 };
8673
8674 struct cmd_config_tunnel_udp_port {
8675         cmdline_fixed_string_t port;
8676         cmdline_fixed_string_t config;
8677         portid_t port_id;
8678         cmdline_fixed_string_t udp_tunnel_port;
8679         cmdline_fixed_string_t action;
8680         cmdline_fixed_string_t tunnel_type;
8681         uint16_t udp_port;
8682 };
8683
8684 static void
8685 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8686                                __attribute__((unused)) struct cmdline *cl,
8687                                __attribute__((unused)) void *data)
8688 {
8689         struct cmd_config_tunnel_udp_port *res = parsed_result;
8690         struct rte_eth_udp_tunnel tunnel_udp;
8691         int ret = 0;
8692
8693         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8694                 return;
8695
8696         tunnel_udp.udp_port = res->udp_port;
8697
8698         if (!strcmp(res->tunnel_type, "vxlan")) {
8699                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8700         } else if (!strcmp(res->tunnel_type, "geneve")) {
8701                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8702         } else {
8703                 printf("Invalid tunnel type\n");
8704                 return;
8705         }
8706
8707         if (!strcmp(res->action, "add"))
8708                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8709                                                       &tunnel_udp);
8710         else
8711                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8712                                                          &tunnel_udp);
8713
8714         if (ret < 0)
8715                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8716 }
8717
8718 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8719         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8720                                  "port");
8721 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8722         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8723                                  "config");
8724 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8725         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8726                               UINT16);
8727 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8728         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8729                                  udp_tunnel_port,
8730                                  "udp_tunnel_port");
8731 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8732         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8733                                  "add#rm");
8734 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8735         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8736                                  "vxlan#geneve");
8737 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8738         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8739                               UINT16);
8740
8741 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8742         .f = cmd_cfg_tunnel_udp_port_parsed,
8743         .data = NULL,
8744         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8745         .tokens = {
8746                 (void *)&cmd_config_tunnel_udp_port_port,
8747                 (void *)&cmd_config_tunnel_udp_port_config,
8748                 (void *)&cmd_config_tunnel_udp_port_port_id,
8749                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8750                 (void *)&cmd_config_tunnel_udp_port_action,
8751                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8752                 (void *)&cmd_config_tunnel_udp_port_value,
8753                 NULL,
8754         },
8755 };
8756
8757 /* *** GLOBAL CONFIG *** */
8758 struct cmd_global_config_result {
8759         cmdline_fixed_string_t cmd;
8760         portid_t port_id;
8761         cmdline_fixed_string_t cfg_type;
8762         uint8_t len;
8763 };
8764
8765 static void
8766 cmd_global_config_parsed(void *parsed_result,
8767                          __attribute__((unused)) struct cmdline *cl,
8768                          __attribute__((unused)) void *data)
8769 {
8770         struct cmd_global_config_result *res = parsed_result;
8771         struct rte_eth_global_cfg conf;
8772         int ret;
8773
8774         memset(&conf, 0, sizeof(conf));
8775         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8776         conf.cfg.gre_key_len = res->len;
8777         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8778                                       RTE_ETH_FILTER_SET, &conf);
8779         if (ret != 0)
8780                 printf("Global config error\n");
8781 }
8782
8783 cmdline_parse_token_string_t cmd_global_config_cmd =
8784         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8785                 "global_config");
8786 cmdline_parse_token_num_t cmd_global_config_port_id =
8787         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8788                                UINT16);
8789 cmdline_parse_token_string_t cmd_global_config_type =
8790         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8791                 cfg_type, "gre-key-len");
8792 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8793         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8794                 len, UINT8);
8795
8796 cmdline_parse_inst_t cmd_global_config = {
8797         .f = cmd_global_config_parsed,
8798         .data = (void *)NULL,
8799         .help_str = "global_config <port_id> gre-key-len <key_len>",
8800         .tokens = {
8801                 (void *)&cmd_global_config_cmd,
8802                 (void *)&cmd_global_config_port_id,
8803                 (void *)&cmd_global_config_type,
8804                 (void *)&cmd_global_config_gre_key_len,
8805                 NULL,
8806         },
8807 };
8808
8809 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8810 struct cmd_set_mirror_mask_result {
8811         cmdline_fixed_string_t set;
8812         cmdline_fixed_string_t port;
8813         portid_t port_id;
8814         cmdline_fixed_string_t mirror;
8815         uint8_t rule_id;
8816         cmdline_fixed_string_t what;
8817         cmdline_fixed_string_t value;
8818         cmdline_fixed_string_t dstpool;
8819         uint8_t dstpool_id;
8820         cmdline_fixed_string_t on;
8821 };
8822
8823 cmdline_parse_token_string_t cmd_mirror_mask_set =
8824         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8825                                 set, "set");
8826 cmdline_parse_token_string_t cmd_mirror_mask_port =
8827         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8828                                 port, "port");
8829 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8830         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8831                                 port_id, UINT16);
8832 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8833         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8834                                 mirror, "mirror-rule");
8835 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8836         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8837                                 rule_id, UINT8);
8838 cmdline_parse_token_string_t cmd_mirror_mask_what =
8839         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8840                                 what, "pool-mirror-up#pool-mirror-down"
8841                                       "#vlan-mirror");
8842 cmdline_parse_token_string_t cmd_mirror_mask_value =
8843         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8844                                 value, NULL);
8845 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8846         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8847                                 dstpool, "dst-pool");
8848 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8849         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8850                                 dstpool_id, UINT8);
8851 cmdline_parse_token_string_t cmd_mirror_mask_on =
8852         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8853                                 on, "on#off");
8854
8855 static void
8856 cmd_set_mirror_mask_parsed(void *parsed_result,
8857                        __attribute__((unused)) struct cmdline *cl,
8858                        __attribute__((unused)) void *data)
8859 {
8860         int ret,nb_item,i;
8861         struct cmd_set_mirror_mask_result *res = parsed_result;
8862         struct rte_eth_mirror_conf mr_conf;
8863
8864         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8865
8866         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8867
8868         mr_conf.dst_pool = res->dstpool_id;
8869
8870         if (!strcmp(res->what, "pool-mirror-up")) {
8871                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8872                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8873         } else if (!strcmp(res->what, "pool-mirror-down")) {
8874                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8875                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8876         } else if (!strcmp(res->what, "vlan-mirror")) {
8877                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8878                 nb_item = parse_item_list(res->value, "vlan",
8879                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8880                 if (nb_item <= 0)
8881                         return;
8882
8883                 for (i = 0; i < nb_item; i++) {
8884                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8885                                 printf("Invalid vlan_id: must be < 4096\n");
8886                                 return;
8887                         }
8888
8889                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8890                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8891                 }
8892         }
8893
8894         if (!strcmp(res->on, "on"))
8895                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8896                                                 res->rule_id, 1);
8897         else
8898                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8899                                                 res->rule_id, 0);
8900         if (ret < 0)
8901                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8902 }
8903
8904 cmdline_parse_inst_t cmd_set_mirror_mask = {
8905                 .f = cmd_set_mirror_mask_parsed,
8906                 .data = NULL,
8907                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8908                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8909                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8910                 .tokens = {
8911                         (void *)&cmd_mirror_mask_set,
8912                         (void *)&cmd_mirror_mask_port,
8913                         (void *)&cmd_mirror_mask_portid,
8914                         (void *)&cmd_mirror_mask_mirror,
8915                         (void *)&cmd_mirror_mask_ruleid,
8916                         (void *)&cmd_mirror_mask_what,
8917                         (void *)&cmd_mirror_mask_value,
8918                         (void *)&cmd_mirror_mask_dstpool,
8919                         (void *)&cmd_mirror_mask_poolid,
8920                         (void *)&cmd_mirror_mask_on,
8921                         NULL,
8922                 },
8923 };
8924
8925 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8926 struct cmd_set_mirror_link_result {
8927         cmdline_fixed_string_t set;
8928         cmdline_fixed_string_t port;
8929         portid_t port_id;
8930         cmdline_fixed_string_t mirror;
8931         uint8_t rule_id;
8932         cmdline_fixed_string_t what;
8933         cmdline_fixed_string_t dstpool;
8934         uint8_t dstpool_id;
8935         cmdline_fixed_string_t on;
8936 };
8937
8938 cmdline_parse_token_string_t cmd_mirror_link_set =
8939         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8940                                  set, "set");
8941 cmdline_parse_token_string_t cmd_mirror_link_port =
8942         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8943                                 port, "port");
8944 cmdline_parse_token_num_t cmd_mirror_link_portid =
8945         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8946                                 port_id, UINT16);
8947 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8948         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8949                                 mirror, "mirror-rule");
8950 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8951         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8952                             rule_id, UINT8);
8953 cmdline_parse_token_string_t cmd_mirror_link_what =
8954         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8955                                 what, "uplink-mirror#downlink-mirror");
8956 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8957         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8958                                 dstpool, "dst-pool");
8959 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8960         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8961                                 dstpool_id, UINT8);
8962 cmdline_parse_token_string_t cmd_mirror_link_on =
8963         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8964                                 on, "on#off");
8965
8966 static void
8967 cmd_set_mirror_link_parsed(void *parsed_result,
8968                        __attribute__((unused)) struct cmdline *cl,
8969                        __attribute__((unused)) void *data)
8970 {
8971         int ret;
8972         struct cmd_set_mirror_link_result *res = parsed_result;
8973         struct rte_eth_mirror_conf mr_conf;
8974
8975         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8976         if (!strcmp(res->what, "uplink-mirror"))
8977                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8978         else
8979                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8980
8981         mr_conf.dst_pool = res->dstpool_id;
8982
8983         if (!strcmp(res->on, "on"))
8984                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8985                                                 res->rule_id, 1);
8986         else
8987                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8988                                                 res->rule_id, 0);
8989
8990         /* check the return value and print it if is < 0 */
8991         if (ret < 0)
8992                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8993
8994 }
8995
8996 cmdline_parse_inst_t cmd_set_mirror_link = {
8997                 .f = cmd_set_mirror_link_parsed,
8998                 .data = NULL,
8999                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9000                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9001                 .tokens = {
9002                         (void *)&cmd_mirror_link_set,
9003                         (void *)&cmd_mirror_link_port,
9004                         (void *)&cmd_mirror_link_portid,
9005                         (void *)&cmd_mirror_link_mirror,
9006                         (void *)&cmd_mirror_link_ruleid,
9007                         (void *)&cmd_mirror_link_what,
9008                         (void *)&cmd_mirror_link_dstpool,
9009                         (void *)&cmd_mirror_link_poolid,
9010                         (void *)&cmd_mirror_link_on,
9011                         NULL,
9012                 },
9013 };
9014
9015 /* *** RESET VM MIRROR RULE *** */
9016 struct cmd_rm_mirror_rule_result {
9017         cmdline_fixed_string_t reset;
9018         cmdline_fixed_string_t port;
9019         portid_t port_id;
9020         cmdline_fixed_string_t mirror;
9021         uint8_t rule_id;
9022 };
9023
9024 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9025         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9026                                  reset, "reset");
9027 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9028         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9029                                 port, "port");
9030 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9031         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9032                                 port_id, UINT16);
9033 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9034         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9035                                 mirror, "mirror-rule");
9036 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9037         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9038                                 rule_id, UINT8);
9039
9040 static void
9041 cmd_reset_mirror_rule_parsed(void *parsed_result,
9042                        __attribute__((unused)) struct cmdline *cl,
9043                        __attribute__((unused)) void *data)
9044 {
9045         int ret;
9046         struct cmd_set_mirror_link_result *res = parsed_result;
9047         /* check rule_id */
9048         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9049         if(ret < 0)
9050                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9051 }
9052
9053 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9054                 .f = cmd_reset_mirror_rule_parsed,
9055                 .data = NULL,
9056                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9057                 .tokens = {
9058                         (void *)&cmd_rm_mirror_rule_reset,
9059                         (void *)&cmd_rm_mirror_rule_port,
9060                         (void *)&cmd_rm_mirror_rule_portid,
9061                         (void *)&cmd_rm_mirror_rule_mirror,
9062                         (void *)&cmd_rm_mirror_rule_ruleid,
9063                         NULL,
9064                 },
9065 };
9066
9067 /* ******************************************************************************** */
9068
9069 struct cmd_dump_result {
9070         cmdline_fixed_string_t dump;
9071 };
9072
9073 static void
9074 dump_struct_sizes(void)
9075 {
9076 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9077         DUMP_SIZE(struct rte_mbuf);
9078         DUMP_SIZE(struct rte_mempool);
9079         DUMP_SIZE(struct rte_ring);
9080 #undef DUMP_SIZE
9081 }
9082
9083 static void cmd_dump_parsed(void *parsed_result,
9084                             __attribute__((unused)) struct cmdline *cl,
9085                             __attribute__((unused)) void *data)
9086 {
9087         struct cmd_dump_result *res = parsed_result;
9088
9089         if (!strcmp(res->dump, "dump_physmem"))
9090                 rte_dump_physmem_layout(stdout);
9091         else if (!strcmp(res->dump, "dump_memzone"))
9092                 rte_memzone_dump(stdout);
9093         else if (!strcmp(res->dump, "dump_struct_sizes"))
9094                 dump_struct_sizes();
9095         else if (!strcmp(res->dump, "dump_ring"))
9096                 rte_ring_list_dump(stdout);
9097         else if (!strcmp(res->dump, "dump_mempool"))
9098                 rte_mempool_list_dump(stdout);
9099         else if (!strcmp(res->dump, "dump_devargs"))
9100                 rte_devargs_dump(stdout);
9101         else if (!strcmp(res->dump, "dump_log_types"))
9102                 rte_log_dump(stdout);
9103 }
9104
9105 cmdline_parse_token_string_t cmd_dump_dump =
9106         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9107                 "dump_physmem#"
9108                 "dump_memzone#"
9109                 "dump_struct_sizes#"
9110                 "dump_ring#"
9111                 "dump_mempool#"
9112                 "dump_devargs#"
9113                 "dump_log_types");
9114
9115 cmdline_parse_inst_t cmd_dump = {
9116         .f = cmd_dump_parsed,  /* function to call */
9117         .data = NULL,      /* 2nd arg of func */
9118         .help_str = "Dump status",
9119         .tokens = {        /* token list, NULL terminated */
9120                 (void *)&cmd_dump_dump,
9121                 NULL,
9122         },
9123 };
9124
9125 /* ******************************************************************************** */
9126
9127 struct cmd_dump_one_result {
9128         cmdline_fixed_string_t dump;
9129         cmdline_fixed_string_t name;
9130 };
9131
9132 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9133                                 __attribute__((unused)) void *data)
9134 {
9135         struct cmd_dump_one_result *res = parsed_result;
9136
9137         if (!strcmp(res->dump, "dump_ring")) {
9138                 struct rte_ring *r;
9139                 r = rte_ring_lookup(res->name);
9140                 if (r == NULL) {
9141                         cmdline_printf(cl, "Cannot find ring\n");
9142                         return;
9143                 }
9144                 rte_ring_dump(stdout, r);
9145         } else if (!strcmp(res->dump, "dump_mempool")) {
9146                 struct rte_mempool *mp;
9147                 mp = rte_mempool_lookup(res->name);
9148                 if (mp == NULL) {
9149                         cmdline_printf(cl, "Cannot find mempool\n");
9150                         return;
9151                 }
9152                 rte_mempool_dump(stdout, mp);
9153         }
9154 }
9155
9156 cmdline_parse_token_string_t cmd_dump_one_dump =
9157         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9158                                  "dump_ring#dump_mempool");
9159
9160 cmdline_parse_token_string_t cmd_dump_one_name =
9161         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9162
9163 cmdline_parse_inst_t cmd_dump_one = {
9164         .f = cmd_dump_one_parsed,  /* function to call */
9165         .data = NULL,      /* 2nd arg of func */
9166         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9167         .tokens = {        /* token list, NULL terminated */
9168                 (void *)&cmd_dump_one_dump,
9169                 (void *)&cmd_dump_one_name,
9170                 NULL,
9171         },
9172 };
9173
9174 /* *** Add/Del syn filter *** */
9175 struct cmd_syn_filter_result {
9176         cmdline_fixed_string_t filter;
9177         portid_t port_id;
9178         cmdline_fixed_string_t ops;
9179         cmdline_fixed_string_t priority;
9180         cmdline_fixed_string_t high;
9181         cmdline_fixed_string_t queue;
9182         uint16_t queue_id;
9183 };
9184
9185 static void
9186 cmd_syn_filter_parsed(void *parsed_result,
9187                         __attribute__((unused)) struct cmdline *cl,
9188                         __attribute__((unused)) void *data)
9189 {
9190         struct cmd_syn_filter_result *res = parsed_result;
9191         struct rte_eth_syn_filter syn_filter;
9192         int ret = 0;
9193
9194         ret = rte_eth_dev_filter_supported(res->port_id,
9195                                         RTE_ETH_FILTER_SYN);
9196         if (ret < 0) {
9197                 printf("syn filter is not supported on port %u.\n",
9198                                 res->port_id);
9199                 return;
9200         }
9201
9202         memset(&syn_filter, 0, sizeof(syn_filter));
9203
9204         if (!strcmp(res->ops, "add")) {
9205                 if (!strcmp(res->high, "high"))
9206                         syn_filter.hig_pri = 1;
9207                 else
9208                         syn_filter.hig_pri = 0;
9209
9210                 syn_filter.queue = res->queue_id;
9211                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9212                                                 RTE_ETH_FILTER_SYN,
9213                                                 RTE_ETH_FILTER_ADD,
9214                                                 &syn_filter);
9215         } else
9216                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9217                                                 RTE_ETH_FILTER_SYN,
9218                                                 RTE_ETH_FILTER_DELETE,
9219                                                 &syn_filter);
9220
9221         if (ret < 0)
9222                 printf("syn filter programming error: (%s)\n",
9223                                 strerror(-ret));
9224 }
9225
9226 cmdline_parse_token_string_t cmd_syn_filter_filter =
9227         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9228         filter, "syn_filter");
9229 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9230         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9231         port_id, UINT16);
9232 cmdline_parse_token_string_t cmd_syn_filter_ops =
9233         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9234         ops, "add#del");
9235 cmdline_parse_token_string_t cmd_syn_filter_priority =
9236         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9237                                 priority, "priority");
9238 cmdline_parse_token_string_t cmd_syn_filter_high =
9239         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9240                                 high, "high#low");
9241 cmdline_parse_token_string_t cmd_syn_filter_queue =
9242         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9243                                 queue, "queue");
9244 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9245         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9246                                 queue_id, UINT16);
9247
9248 cmdline_parse_inst_t cmd_syn_filter = {
9249         .f = cmd_syn_filter_parsed,
9250         .data = NULL,
9251         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9252                 "<queue_id>: Add/Delete syn filter",
9253         .tokens = {
9254                 (void *)&cmd_syn_filter_filter,
9255                 (void *)&cmd_syn_filter_port_id,
9256                 (void *)&cmd_syn_filter_ops,
9257                 (void *)&cmd_syn_filter_priority,
9258                 (void *)&cmd_syn_filter_high,
9259                 (void *)&cmd_syn_filter_queue,
9260                 (void *)&cmd_syn_filter_queue_id,
9261                 NULL,
9262         },
9263 };
9264
9265 /* *** queue region set *** */
9266 struct cmd_queue_region_result {
9267         cmdline_fixed_string_t set;
9268         cmdline_fixed_string_t port;
9269         portid_t port_id;
9270         cmdline_fixed_string_t cmd;
9271         cmdline_fixed_string_t region;
9272         uint8_t  region_id;
9273         cmdline_fixed_string_t queue_start_index;
9274         uint8_t  queue_id;
9275         cmdline_fixed_string_t queue_num;
9276         uint8_t  queue_num_value;
9277 };
9278
9279 static void
9280 cmd_queue_region_parsed(void *parsed_result,
9281                         __attribute__((unused)) struct cmdline *cl,
9282                         __attribute__((unused)) void *data)
9283 {
9284         struct cmd_queue_region_result *res = parsed_result;
9285         int ret = -ENOTSUP;
9286 #ifdef RTE_LIBRTE_I40E_PMD
9287         struct rte_pmd_i40e_queue_region_conf region_conf;
9288         enum rte_pmd_i40e_queue_region_op op_type;
9289 #endif
9290
9291         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9292                 return;
9293
9294 #ifdef RTE_LIBRTE_I40E_PMD
9295         memset(&region_conf, 0, sizeof(region_conf));
9296         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9297         region_conf.region_id = res->region_id;
9298         region_conf.queue_num = res->queue_num_value;
9299         region_conf.queue_start_index = res->queue_id;
9300
9301         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9302                                 op_type, &region_conf);
9303 #endif
9304
9305         switch (ret) {
9306         case 0:
9307                 break;
9308         case -ENOTSUP:
9309                 printf("function not implemented or supported\n");
9310                 break;
9311         default:
9312                 printf("queue region config error: (%s)\n", strerror(-ret));
9313         }
9314 }
9315
9316 cmdline_parse_token_string_t cmd_queue_region_set =
9317 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9318                 set, "set");
9319 cmdline_parse_token_string_t cmd_queue_region_port =
9320         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9321 cmdline_parse_token_num_t cmd_queue_region_port_id =
9322         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9323                                 port_id, UINT16);
9324 cmdline_parse_token_string_t cmd_queue_region_cmd =
9325         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9326                                  cmd, "queue-region");
9327 cmdline_parse_token_string_t cmd_queue_region_id =
9328         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9329                                 region, "region_id");
9330 cmdline_parse_token_num_t cmd_queue_region_index =
9331         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9332                                 region_id, UINT8);
9333 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9334         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9335                                 queue_start_index, "queue_start_index");
9336 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9337         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9338                                 queue_id, UINT8);
9339 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9340         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9341                                 queue_num, "queue_num");
9342 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9343         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9344                                 queue_num_value, UINT8);
9345
9346 cmdline_parse_inst_t cmd_queue_region = {
9347         .f = cmd_queue_region_parsed,
9348         .data = NULL,
9349         .help_str = "set port <port_id> queue-region region_id <value> "
9350                 "queue_start_index <value> queue_num <value>: Set a queue region",
9351         .tokens = {
9352                 (void *)&cmd_queue_region_set,
9353                 (void *)&cmd_queue_region_port,
9354                 (void *)&cmd_queue_region_port_id,
9355                 (void *)&cmd_queue_region_cmd,
9356                 (void *)&cmd_queue_region_id,
9357                 (void *)&cmd_queue_region_index,
9358                 (void *)&cmd_queue_region_queue_start_index,
9359                 (void *)&cmd_queue_region_queue_id,
9360                 (void *)&cmd_queue_region_queue_num,
9361                 (void *)&cmd_queue_region_queue_num_value,
9362                 NULL,
9363         },
9364 };
9365
9366 /* *** queue region and flowtype set *** */
9367 struct cmd_region_flowtype_result {
9368         cmdline_fixed_string_t set;
9369         cmdline_fixed_string_t port;
9370         portid_t port_id;
9371         cmdline_fixed_string_t cmd;
9372         cmdline_fixed_string_t region;
9373         uint8_t  region_id;
9374         cmdline_fixed_string_t flowtype;
9375         uint8_t  flowtype_id;
9376 };
9377
9378 static void
9379 cmd_region_flowtype_parsed(void *parsed_result,
9380                         __attribute__((unused)) struct cmdline *cl,
9381                         __attribute__((unused)) void *data)
9382 {
9383         struct cmd_region_flowtype_result *res = parsed_result;
9384         int ret = -ENOTSUP;
9385 #ifdef RTE_LIBRTE_I40E_PMD
9386         struct rte_pmd_i40e_queue_region_conf region_conf;
9387         enum rte_pmd_i40e_queue_region_op op_type;
9388 #endif
9389
9390         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9391                 return;
9392
9393 #ifdef RTE_LIBRTE_I40E_PMD
9394         memset(&region_conf, 0, sizeof(region_conf));
9395
9396         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9397         region_conf.region_id = res->region_id;
9398         region_conf.hw_flowtype = res->flowtype_id;
9399
9400         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9401                         op_type, &region_conf);
9402 #endif
9403
9404         switch (ret) {
9405         case 0:
9406                 break;
9407         case -ENOTSUP:
9408                 printf("function not implemented or supported\n");
9409                 break;
9410         default:
9411                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9412         }
9413 }
9414
9415 cmdline_parse_token_string_t cmd_region_flowtype_set =
9416 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9417                                 set, "set");
9418 cmdline_parse_token_string_t cmd_region_flowtype_port =
9419         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9420                                 port, "port");
9421 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9422         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9423                                 port_id, UINT16);
9424 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9425         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9426                                 cmd, "queue-region");
9427 cmdline_parse_token_string_t cmd_region_flowtype_index =
9428         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9429                                 region, "region_id");
9430 cmdline_parse_token_num_t cmd_region_flowtype_id =
9431         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9432                                 region_id, UINT8);
9433 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9434         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9435                                 flowtype, "flowtype");
9436 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9437         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9438                                 flowtype_id, UINT8);
9439 cmdline_parse_inst_t cmd_region_flowtype = {
9440         .f = cmd_region_flowtype_parsed,
9441         .data = NULL,
9442         .help_str = "set port <port_id> queue-region region_id <value> "
9443                 "flowtype <value>: Set a flowtype region index",
9444         .tokens = {
9445                 (void *)&cmd_region_flowtype_set,
9446                 (void *)&cmd_region_flowtype_port,
9447                 (void *)&cmd_region_flowtype_port_index,
9448                 (void *)&cmd_region_flowtype_cmd,
9449                 (void *)&cmd_region_flowtype_index,
9450                 (void *)&cmd_region_flowtype_id,
9451                 (void *)&cmd_region_flowtype_flow_index,
9452                 (void *)&cmd_region_flowtype_flow_id,
9453                 NULL,
9454         },
9455 };
9456
9457 /* *** User Priority (UP) to queue region (region_id) set *** */
9458 struct cmd_user_priority_region_result {
9459         cmdline_fixed_string_t set;
9460         cmdline_fixed_string_t port;
9461         portid_t port_id;
9462         cmdline_fixed_string_t cmd;
9463         cmdline_fixed_string_t user_priority;
9464         uint8_t  user_priority_id;
9465         cmdline_fixed_string_t region;
9466         uint8_t  region_id;
9467 };
9468
9469 static void
9470 cmd_user_priority_region_parsed(void *parsed_result,
9471                         __attribute__((unused)) struct cmdline *cl,
9472                         __attribute__((unused)) void *data)
9473 {
9474         struct cmd_user_priority_region_result *res = parsed_result;
9475         int ret = -ENOTSUP;
9476 #ifdef RTE_LIBRTE_I40E_PMD
9477         struct rte_pmd_i40e_queue_region_conf region_conf;
9478         enum rte_pmd_i40e_queue_region_op op_type;
9479 #endif
9480
9481         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9482                 return;
9483
9484 #ifdef RTE_LIBRTE_I40E_PMD
9485         memset(&region_conf, 0, sizeof(region_conf));
9486         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9487         region_conf.user_priority = res->user_priority_id;
9488         region_conf.region_id = res->region_id;
9489
9490         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9491                                 op_type, &region_conf);
9492 #endif
9493
9494         switch (ret) {
9495         case 0:
9496                 break;
9497         case -ENOTSUP:
9498                 printf("function not implemented or supported\n");
9499                 break;
9500         default:
9501                 printf("user_priority region config error: (%s)\n",
9502                                 strerror(-ret));
9503         }
9504 }
9505
9506 cmdline_parse_token_string_t cmd_user_priority_region_set =
9507         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9508                                 set, "set");
9509 cmdline_parse_token_string_t cmd_user_priority_region_port =
9510         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9511                                 port, "port");
9512 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9513         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9514                                 port_id, UINT16);
9515 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9516         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9517                                 cmd, "queue-region");
9518 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9519         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9520                                 user_priority, "UP");
9521 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9522         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9523                                 user_priority_id, UINT8);
9524 cmdline_parse_token_string_t cmd_user_priority_region_region =
9525         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9526                                 region, "region_id");
9527 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9528         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9529                                 region_id, UINT8);
9530
9531 cmdline_parse_inst_t cmd_user_priority_region = {
9532         .f = cmd_user_priority_region_parsed,
9533         .data = NULL,
9534         .help_str = "set port <port_id> queue-region UP <value> "
9535                 "region_id <value>: Set the mapping of User Priority (UP) "
9536                 "to queue region (region_id) ",
9537         .tokens = {
9538                 (void *)&cmd_user_priority_region_set,
9539                 (void *)&cmd_user_priority_region_port,
9540                 (void *)&cmd_user_priority_region_port_index,
9541                 (void *)&cmd_user_priority_region_cmd,
9542                 (void *)&cmd_user_priority_region_UP,
9543                 (void *)&cmd_user_priority_region_UP_id,
9544                 (void *)&cmd_user_priority_region_region,
9545                 (void *)&cmd_user_priority_region_region_id,
9546                 NULL,
9547         },
9548 };
9549
9550 /* *** flush all queue region related configuration *** */
9551 struct cmd_flush_queue_region_result {
9552         cmdline_fixed_string_t set;
9553         cmdline_fixed_string_t port;
9554         portid_t port_id;
9555         cmdline_fixed_string_t cmd;
9556         cmdline_fixed_string_t flush;
9557         cmdline_fixed_string_t what;
9558 };
9559
9560 static void
9561 cmd_flush_queue_region_parsed(void *parsed_result,
9562                         __attribute__((unused)) struct cmdline *cl,
9563                         __attribute__((unused)) void *data)
9564 {
9565         struct cmd_flush_queue_region_result *res = parsed_result;
9566         int ret = -ENOTSUP;
9567 #ifdef RTE_LIBRTE_I40E_PMD
9568         struct rte_pmd_i40e_queue_region_conf region_conf;
9569         enum rte_pmd_i40e_queue_region_op op_type;
9570 #endif
9571
9572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9573                 return;
9574
9575 #ifdef RTE_LIBRTE_I40E_PMD
9576         memset(&region_conf, 0, sizeof(region_conf));
9577
9578         if (strcmp(res->what, "on") == 0)
9579                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9580         else
9581                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9582
9583         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9584                                 op_type, &region_conf);
9585 #endif
9586
9587         switch (ret) {
9588         case 0:
9589                 break;
9590         case -ENOTSUP:
9591                 printf("function not implemented or supported\n");
9592                 break;
9593         default:
9594                 printf("queue region config flush error: (%s)\n",
9595                                 strerror(-ret));
9596         }
9597 }
9598
9599 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9600         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9601                                 set, "set");
9602 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9603         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9604                                 port, "port");
9605 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9606         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9607                                 port_id, UINT16);
9608 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9609         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9610                                 cmd, "queue-region");
9611 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9612         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9613                                 flush, "flush");
9614 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9615         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9616                                 what, "on#off");
9617
9618 cmdline_parse_inst_t cmd_flush_queue_region = {
9619         .f = cmd_flush_queue_region_parsed,
9620         .data = NULL,
9621         .help_str = "set port <port_id> queue-region flush on|off"
9622                 ": flush all queue region related configuration",
9623         .tokens = {
9624                 (void *)&cmd_flush_queue_region_set,
9625                 (void *)&cmd_flush_queue_region_port,
9626                 (void *)&cmd_flush_queue_region_port_index,
9627                 (void *)&cmd_flush_queue_region_cmd,
9628                 (void *)&cmd_flush_queue_region_flush,
9629                 (void *)&cmd_flush_queue_region_what,
9630                 NULL,
9631         },
9632 };
9633
9634 /* *** get all queue region related configuration info *** */
9635 struct cmd_show_queue_region_info {
9636         cmdline_fixed_string_t show;
9637         cmdline_fixed_string_t port;
9638         portid_t port_id;
9639         cmdline_fixed_string_t cmd;
9640 };
9641
9642 static void
9643 cmd_show_queue_region_info_parsed(void *parsed_result,
9644                         __attribute__((unused)) struct cmdline *cl,
9645                         __attribute__((unused)) void *data)
9646 {
9647         struct cmd_show_queue_region_info *res = parsed_result;
9648         int ret = -ENOTSUP;
9649 #ifdef RTE_LIBRTE_I40E_PMD
9650         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9651         enum rte_pmd_i40e_queue_region_op op_type;
9652 #endif
9653
9654         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9655                 return;
9656
9657 #ifdef RTE_LIBRTE_I40E_PMD
9658         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9659
9660         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9661
9662         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9663                                         op_type, &rte_pmd_regions);
9664
9665         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9666 #endif
9667
9668         switch (ret) {
9669         case 0:
9670                 break;
9671         case -ENOTSUP:
9672                 printf("function not implemented or supported\n");
9673                 break;
9674         default:
9675                 printf("queue region config info show error: (%s)\n",
9676                                 strerror(-ret));
9677         }
9678 }
9679
9680 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9681 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9682                                 show, "show");
9683 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9684         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9685                                 port, "port");
9686 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9687         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9688                                 port_id, UINT16);
9689 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9690         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9691                                 cmd, "queue-region");
9692
9693 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9694         .f = cmd_show_queue_region_info_parsed,
9695         .data = NULL,
9696         .help_str = "show port <port_id> queue-region"
9697                 ": show all queue region related configuration info",
9698         .tokens = {
9699                 (void *)&cmd_show_queue_region_info_get,
9700                 (void *)&cmd_show_queue_region_info_port,
9701                 (void *)&cmd_show_queue_region_info_port_index,
9702                 (void *)&cmd_show_queue_region_info_cmd,
9703                 NULL,
9704         },
9705 };
9706
9707 /* *** ADD/REMOVE A 2tuple FILTER *** */
9708 struct cmd_2tuple_filter_result {
9709         cmdline_fixed_string_t filter;
9710         portid_t port_id;
9711         cmdline_fixed_string_t ops;
9712         cmdline_fixed_string_t dst_port;
9713         uint16_t dst_port_value;
9714         cmdline_fixed_string_t protocol;
9715         uint8_t protocol_value;
9716         cmdline_fixed_string_t mask;
9717         uint8_t  mask_value;
9718         cmdline_fixed_string_t tcp_flags;
9719         uint8_t tcp_flags_value;
9720         cmdline_fixed_string_t priority;
9721         uint8_t  priority_value;
9722         cmdline_fixed_string_t queue;
9723         uint16_t  queue_id;
9724 };
9725
9726 static void
9727 cmd_2tuple_filter_parsed(void *parsed_result,
9728                         __attribute__((unused)) struct cmdline *cl,
9729                         __attribute__((unused)) void *data)
9730 {
9731         struct rte_eth_ntuple_filter filter;
9732         struct cmd_2tuple_filter_result *res = parsed_result;
9733         int ret = 0;
9734
9735         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9736         if (ret < 0) {
9737                 printf("ntuple filter is not supported on port %u.\n",
9738                         res->port_id);
9739                 return;
9740         }
9741
9742         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9743
9744         filter.flags = RTE_2TUPLE_FLAGS;
9745         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9746         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9747         filter.proto = res->protocol_value;
9748         filter.priority = res->priority_value;
9749         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9750                 printf("nonzero tcp_flags is only meaningful"
9751                         " when protocol is TCP.\n");
9752                 return;
9753         }
9754         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9755                 printf("invalid TCP flags.\n");
9756                 return;
9757         }
9758
9759         if (res->tcp_flags_value != 0) {
9760                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9761                 filter.tcp_flags = res->tcp_flags_value;
9762         }
9763
9764         /* need convert to big endian. */
9765         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9766         filter.queue = res->queue_id;
9767
9768         if (!strcmp(res->ops, "add"))
9769                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9770                                 RTE_ETH_FILTER_NTUPLE,
9771                                 RTE_ETH_FILTER_ADD,
9772                                 &filter);
9773         else
9774                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9775                                 RTE_ETH_FILTER_NTUPLE,
9776                                 RTE_ETH_FILTER_DELETE,
9777                                 &filter);
9778         if (ret < 0)
9779                 printf("2tuple filter programming error: (%s)\n",
9780                         strerror(-ret));
9781
9782 }
9783
9784 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9785         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9786                                  filter, "2tuple_filter");
9787 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9788         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9789                                 port_id, UINT16);
9790 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9791         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9792                                  ops, "add#del");
9793 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9794         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9795                                 dst_port, "dst_port");
9796 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9797         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9798                                 dst_port_value, UINT16);
9799 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9800         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9801                                 protocol, "protocol");
9802 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9803         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9804                                 protocol_value, UINT8);
9805 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9806         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9807                                 mask, "mask");
9808 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9809         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9810                                 mask_value, INT8);
9811 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9812         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9813                                 tcp_flags, "tcp_flags");
9814 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9815         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9816                                 tcp_flags_value, UINT8);
9817 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9818         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9819                                 priority, "priority");
9820 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9821         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9822                                 priority_value, UINT8);
9823 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9824         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9825                                 queue, "queue");
9826 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9827         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9828                                 queue_id, UINT16);
9829
9830 cmdline_parse_inst_t cmd_2tuple_filter = {
9831         .f = cmd_2tuple_filter_parsed,
9832         .data = NULL,
9833         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9834                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9835                 "<queue_id>: Add a 2tuple filter",
9836         .tokens = {
9837                 (void *)&cmd_2tuple_filter_filter,
9838                 (void *)&cmd_2tuple_filter_port_id,
9839                 (void *)&cmd_2tuple_filter_ops,
9840                 (void *)&cmd_2tuple_filter_dst_port,
9841                 (void *)&cmd_2tuple_filter_dst_port_value,
9842                 (void *)&cmd_2tuple_filter_protocol,
9843                 (void *)&cmd_2tuple_filter_protocol_value,
9844                 (void *)&cmd_2tuple_filter_mask,
9845                 (void *)&cmd_2tuple_filter_mask_value,
9846                 (void *)&cmd_2tuple_filter_tcp_flags,
9847                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9848                 (void *)&cmd_2tuple_filter_priority,
9849                 (void *)&cmd_2tuple_filter_priority_value,
9850                 (void *)&cmd_2tuple_filter_queue,
9851                 (void *)&cmd_2tuple_filter_queue_id,
9852                 NULL,
9853         },
9854 };
9855
9856 /* *** ADD/REMOVE A 5tuple FILTER *** */
9857 struct cmd_5tuple_filter_result {
9858         cmdline_fixed_string_t filter;
9859         portid_t port_id;
9860         cmdline_fixed_string_t ops;
9861         cmdline_fixed_string_t dst_ip;
9862         cmdline_ipaddr_t dst_ip_value;
9863         cmdline_fixed_string_t src_ip;
9864         cmdline_ipaddr_t src_ip_value;
9865         cmdline_fixed_string_t dst_port;
9866         uint16_t dst_port_value;
9867         cmdline_fixed_string_t src_port;
9868         uint16_t src_port_value;
9869         cmdline_fixed_string_t protocol;
9870         uint8_t protocol_value;
9871         cmdline_fixed_string_t mask;
9872         uint8_t  mask_value;
9873         cmdline_fixed_string_t tcp_flags;
9874         uint8_t tcp_flags_value;
9875         cmdline_fixed_string_t priority;
9876         uint8_t  priority_value;
9877         cmdline_fixed_string_t queue;
9878         uint16_t  queue_id;
9879 };
9880
9881 static void
9882 cmd_5tuple_filter_parsed(void *parsed_result,
9883                         __attribute__((unused)) struct cmdline *cl,
9884                         __attribute__((unused)) void *data)
9885 {
9886         struct rte_eth_ntuple_filter filter;
9887         struct cmd_5tuple_filter_result *res = parsed_result;
9888         int ret = 0;
9889
9890         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9891         if (ret < 0) {
9892                 printf("ntuple filter is not supported on port %u.\n",
9893                         res->port_id);
9894                 return;
9895         }
9896
9897         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9898
9899         filter.flags = RTE_5TUPLE_FLAGS;
9900         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9901         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9902         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9903         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9904         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9905         filter.proto = res->protocol_value;
9906         filter.priority = res->priority_value;
9907         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9908                 printf("nonzero tcp_flags is only meaningful"
9909                         " when protocol is TCP.\n");
9910                 return;
9911         }
9912         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9913                 printf("invalid TCP flags.\n");
9914                 return;
9915         }
9916
9917         if (res->tcp_flags_value != 0) {
9918                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9919                 filter.tcp_flags = res->tcp_flags_value;
9920         }
9921
9922         if (res->dst_ip_value.family == AF_INET)
9923                 /* no need to convert, already big endian. */
9924                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9925         else {
9926                 if (filter.dst_ip_mask == 0) {
9927                         printf("can not support ipv6 involved compare.\n");
9928                         return;
9929                 }
9930                 filter.dst_ip = 0;
9931         }
9932
9933         if (res->src_ip_value.family == AF_INET)
9934                 /* no need to convert, already big endian. */
9935                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9936         else {
9937                 if (filter.src_ip_mask == 0) {
9938                         printf("can not support ipv6 involved compare.\n");
9939                         return;
9940                 }
9941                 filter.src_ip = 0;
9942         }
9943         /* need convert to big endian. */
9944         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9945         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9946         filter.queue = res->queue_id;
9947
9948         if (!strcmp(res->ops, "add"))
9949                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9950                                 RTE_ETH_FILTER_NTUPLE,
9951                                 RTE_ETH_FILTER_ADD,
9952                                 &filter);
9953         else
9954                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9955                                 RTE_ETH_FILTER_NTUPLE,
9956                                 RTE_ETH_FILTER_DELETE,
9957                                 &filter);
9958         if (ret < 0)
9959                 printf("5tuple filter programming error: (%s)\n",
9960                         strerror(-ret));
9961 }
9962
9963 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9964         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9965                                  filter, "5tuple_filter");
9966 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9967         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9968                                 port_id, UINT16);
9969 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9970         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9971                                  ops, "add#del");
9972 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9973         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9974                                 dst_ip, "dst_ip");
9975 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9976         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9977                                 dst_ip_value);
9978 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9979         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9980                                 src_ip, "src_ip");
9981 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9982         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9983                                 src_ip_value);
9984 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9985         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9986                                 dst_port, "dst_port");
9987 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9988         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9989                                 dst_port_value, UINT16);
9990 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9991         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9992                                 src_port, "src_port");
9993 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9994         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9995                                 src_port_value, UINT16);
9996 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9997         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9998                                 protocol, "protocol");
9999 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10000         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10001                                 protocol_value, UINT8);
10002 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10003         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10004                                 mask, "mask");
10005 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10006         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10007                                 mask_value, INT8);
10008 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10009         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10010                                 tcp_flags, "tcp_flags");
10011 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10012         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10013                                 tcp_flags_value, UINT8);
10014 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10015         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10016                                 priority, "priority");
10017 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10018         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10019                                 priority_value, UINT8);
10020 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10021         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10022                                 queue, "queue");
10023 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10024         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10025                                 queue_id, UINT16);
10026
10027 cmdline_parse_inst_t cmd_5tuple_filter = {
10028         .f = cmd_5tuple_filter_parsed,
10029         .data = NULL,
10030         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10031                 "src_ip <value> dst_port <value> src_port <value> "
10032                 "protocol <value>  mask <value> tcp_flags <value> "
10033                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10034         .tokens = {
10035                 (void *)&cmd_5tuple_filter_filter,
10036                 (void *)&cmd_5tuple_filter_port_id,
10037                 (void *)&cmd_5tuple_filter_ops,
10038                 (void *)&cmd_5tuple_filter_dst_ip,
10039                 (void *)&cmd_5tuple_filter_dst_ip_value,
10040                 (void *)&cmd_5tuple_filter_src_ip,
10041                 (void *)&cmd_5tuple_filter_src_ip_value,
10042                 (void *)&cmd_5tuple_filter_dst_port,
10043                 (void *)&cmd_5tuple_filter_dst_port_value,
10044                 (void *)&cmd_5tuple_filter_src_port,
10045                 (void *)&cmd_5tuple_filter_src_port_value,
10046                 (void *)&cmd_5tuple_filter_protocol,
10047                 (void *)&cmd_5tuple_filter_protocol_value,
10048                 (void *)&cmd_5tuple_filter_mask,
10049                 (void *)&cmd_5tuple_filter_mask_value,
10050                 (void *)&cmd_5tuple_filter_tcp_flags,
10051                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10052                 (void *)&cmd_5tuple_filter_priority,
10053                 (void *)&cmd_5tuple_filter_priority_value,
10054                 (void *)&cmd_5tuple_filter_queue,
10055                 (void *)&cmd_5tuple_filter_queue_id,
10056                 NULL,
10057         },
10058 };
10059
10060 /* *** ADD/REMOVE A flex FILTER *** */
10061 struct cmd_flex_filter_result {
10062         cmdline_fixed_string_t filter;
10063         cmdline_fixed_string_t ops;
10064         portid_t port_id;
10065         cmdline_fixed_string_t len;
10066         uint8_t len_value;
10067         cmdline_fixed_string_t bytes;
10068         cmdline_fixed_string_t bytes_value;
10069         cmdline_fixed_string_t mask;
10070         cmdline_fixed_string_t mask_value;
10071         cmdline_fixed_string_t priority;
10072         uint8_t priority_value;
10073         cmdline_fixed_string_t queue;
10074         uint16_t queue_id;
10075 };
10076
10077 static int xdigit2val(unsigned char c)
10078 {
10079         int val;
10080         if (isdigit(c))
10081                 val = c - '0';
10082         else if (isupper(c))
10083                 val = c - 'A' + 10;
10084         else
10085                 val = c - 'a' + 10;
10086         return val;
10087 }
10088
10089 static void
10090 cmd_flex_filter_parsed(void *parsed_result,
10091                           __attribute__((unused)) struct cmdline *cl,
10092                           __attribute__((unused)) void *data)
10093 {
10094         int ret = 0;
10095         struct rte_eth_flex_filter filter;
10096         struct cmd_flex_filter_result *res = parsed_result;
10097         char *bytes_ptr, *mask_ptr;
10098         uint16_t len, i, j = 0;
10099         char c;
10100         int val;
10101         uint8_t byte = 0;
10102
10103         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10104                 printf("the len exceed the max length 128\n");
10105                 return;
10106         }
10107         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10108         filter.len = res->len_value;
10109         filter.priority = res->priority_value;
10110         filter.queue = res->queue_id;
10111         bytes_ptr = res->bytes_value;
10112         mask_ptr = res->mask_value;
10113
10114          /* translate bytes string to array. */
10115         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10116                 (bytes_ptr[1] == 'X')))
10117                 bytes_ptr += 2;
10118         len = strnlen(bytes_ptr, res->len_value * 2);
10119         if (len == 0 || (len % 8 != 0)) {
10120                 printf("please check len and bytes input\n");
10121                 return;
10122         }
10123         for (i = 0; i < len; i++) {
10124                 c = bytes_ptr[i];
10125                 if (isxdigit(c) == 0) {
10126                         /* invalid characters. */
10127                         printf("invalid input\n");
10128                         return;
10129                 }
10130                 val = xdigit2val(c);
10131                 if (i % 2) {
10132                         byte |= val;
10133                         filter.bytes[j] = byte;
10134                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10135                         j++;
10136                         byte = 0;
10137                 } else
10138                         byte |= val << 4;
10139         }
10140         printf("\n");
10141          /* translate mask string to uint8_t array. */
10142         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10143                 (mask_ptr[1] == 'X')))
10144                 mask_ptr += 2;
10145         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10146         if (len == 0) {
10147                 printf("invalid input\n");
10148                 return;
10149         }
10150         j = 0;
10151         byte = 0;
10152         for (i = 0; i < len; i++) {
10153                 c = mask_ptr[i];
10154                 if (isxdigit(c) == 0) {
10155                         /* invalid characters. */
10156                         printf("invalid input\n");
10157                         return;
10158                 }
10159                 val = xdigit2val(c);
10160                 if (i % 2) {
10161                         byte |= val;
10162                         filter.mask[j] = byte;
10163                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10164                         j++;
10165                         byte = 0;
10166                 } else
10167                         byte |= val << 4;
10168         }
10169         printf("\n");
10170
10171         if (!strcmp(res->ops, "add"))
10172                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10173                                 RTE_ETH_FILTER_FLEXIBLE,
10174                                 RTE_ETH_FILTER_ADD,
10175                                 &filter);
10176         else
10177                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10178                                 RTE_ETH_FILTER_FLEXIBLE,
10179                                 RTE_ETH_FILTER_DELETE,
10180                                 &filter);
10181
10182         if (ret < 0)
10183                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10184 }
10185
10186 cmdline_parse_token_string_t cmd_flex_filter_filter =
10187         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10188                                 filter, "flex_filter");
10189 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10190         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10191                                 port_id, UINT16);
10192 cmdline_parse_token_string_t cmd_flex_filter_ops =
10193         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10194                                 ops, "add#del");
10195 cmdline_parse_token_string_t cmd_flex_filter_len =
10196         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10197                                 len, "len");
10198 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10199         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10200                                 len_value, UINT8);
10201 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10202         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10203                                 bytes, "bytes");
10204 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10205         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10206                                 bytes_value, NULL);
10207 cmdline_parse_token_string_t cmd_flex_filter_mask =
10208         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10209                                 mask, "mask");
10210 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10211         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10212                                 mask_value, NULL);
10213 cmdline_parse_token_string_t cmd_flex_filter_priority =
10214         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10215                                 priority, "priority");
10216 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10217         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10218                                 priority_value, UINT8);
10219 cmdline_parse_token_string_t cmd_flex_filter_queue =
10220         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10221                                 queue, "queue");
10222 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10223         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10224                                 queue_id, UINT16);
10225 cmdline_parse_inst_t cmd_flex_filter = {
10226         .f = cmd_flex_filter_parsed,
10227         .data = NULL,
10228         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10229                 "<value> mask <value> priority <value> queue <queue_id>: "
10230                 "Add/Del a flex filter",
10231         .tokens = {
10232                 (void *)&cmd_flex_filter_filter,
10233                 (void *)&cmd_flex_filter_port_id,
10234                 (void *)&cmd_flex_filter_ops,
10235                 (void *)&cmd_flex_filter_len,
10236                 (void *)&cmd_flex_filter_len_value,
10237                 (void *)&cmd_flex_filter_bytes,
10238                 (void *)&cmd_flex_filter_bytes_value,
10239                 (void *)&cmd_flex_filter_mask,
10240                 (void *)&cmd_flex_filter_mask_value,
10241                 (void *)&cmd_flex_filter_priority,
10242                 (void *)&cmd_flex_filter_priority_value,
10243                 (void *)&cmd_flex_filter_queue,
10244                 (void *)&cmd_flex_filter_queue_id,
10245                 NULL,
10246         },
10247 };
10248
10249 /* *** Filters Control *** */
10250
10251 /* *** deal with ethertype filter *** */
10252 struct cmd_ethertype_filter_result {
10253         cmdline_fixed_string_t filter;
10254         portid_t port_id;
10255         cmdline_fixed_string_t ops;
10256         cmdline_fixed_string_t mac;
10257         struct ether_addr mac_addr;
10258         cmdline_fixed_string_t ethertype;
10259         uint16_t ethertype_value;
10260         cmdline_fixed_string_t drop;
10261         cmdline_fixed_string_t queue;
10262         uint16_t  queue_id;
10263 };
10264
10265 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10266         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10267                                  filter, "ethertype_filter");
10268 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10269         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10270                               port_id, UINT16);
10271 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10272         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10273                                  ops, "add#del");
10274 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10275         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10276                                  mac, "mac_addr#mac_ignr");
10277 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10278         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10279                                      mac_addr);
10280 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10281         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10282                                  ethertype, "ethertype");
10283 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10284         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10285                               ethertype_value, UINT16);
10286 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10287         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10288                                  drop, "drop#fwd");
10289 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10290         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10291                                  queue, "queue");
10292 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10293         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10294                               queue_id, UINT16);
10295
10296 static void
10297 cmd_ethertype_filter_parsed(void *parsed_result,
10298                           __attribute__((unused)) struct cmdline *cl,
10299                           __attribute__((unused)) void *data)
10300 {
10301         struct cmd_ethertype_filter_result *res = parsed_result;
10302         struct rte_eth_ethertype_filter filter;
10303         int ret = 0;
10304
10305         ret = rte_eth_dev_filter_supported(res->port_id,
10306                         RTE_ETH_FILTER_ETHERTYPE);
10307         if (ret < 0) {
10308                 printf("ethertype filter is not supported on port %u.\n",
10309                         res->port_id);
10310                 return;
10311         }
10312
10313         memset(&filter, 0, sizeof(filter));
10314         if (!strcmp(res->mac, "mac_addr")) {
10315                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10316                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10317                         sizeof(struct ether_addr));
10318         }
10319         if (!strcmp(res->drop, "drop"))
10320                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10321         filter.ether_type = res->ethertype_value;
10322         filter.queue = res->queue_id;
10323
10324         if (!strcmp(res->ops, "add"))
10325                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10326                                 RTE_ETH_FILTER_ETHERTYPE,
10327                                 RTE_ETH_FILTER_ADD,
10328                                 &filter);
10329         else
10330                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10331                                 RTE_ETH_FILTER_ETHERTYPE,
10332                                 RTE_ETH_FILTER_DELETE,
10333                                 &filter);
10334         if (ret < 0)
10335                 printf("ethertype filter programming error: (%s)\n",
10336                         strerror(-ret));
10337 }
10338
10339 cmdline_parse_inst_t cmd_ethertype_filter = {
10340         .f = cmd_ethertype_filter_parsed,
10341         .data = NULL,
10342         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10343                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10344                 "Add or delete an ethertype filter entry",
10345         .tokens = {
10346                 (void *)&cmd_ethertype_filter_filter,
10347                 (void *)&cmd_ethertype_filter_port_id,
10348                 (void *)&cmd_ethertype_filter_ops,
10349                 (void *)&cmd_ethertype_filter_mac,
10350                 (void *)&cmd_ethertype_filter_mac_addr,
10351                 (void *)&cmd_ethertype_filter_ethertype,
10352                 (void *)&cmd_ethertype_filter_ethertype_value,
10353                 (void *)&cmd_ethertype_filter_drop,
10354                 (void *)&cmd_ethertype_filter_queue,
10355                 (void *)&cmd_ethertype_filter_queue_id,
10356                 NULL,
10357         },
10358 };
10359
10360 /* *** deal with flow director filter *** */
10361 struct cmd_flow_director_result {
10362         cmdline_fixed_string_t flow_director_filter;
10363         portid_t port_id;
10364         cmdline_fixed_string_t mode;
10365         cmdline_fixed_string_t mode_value;
10366         cmdline_fixed_string_t ops;
10367         cmdline_fixed_string_t flow;
10368         cmdline_fixed_string_t flow_type;
10369         cmdline_fixed_string_t ether;
10370         uint16_t ether_type;
10371         cmdline_fixed_string_t src;
10372         cmdline_ipaddr_t ip_src;
10373         uint16_t port_src;
10374         cmdline_fixed_string_t dst;
10375         cmdline_ipaddr_t ip_dst;
10376         uint16_t port_dst;
10377         cmdline_fixed_string_t verify_tag;
10378         uint32_t verify_tag_value;
10379         cmdline_fixed_string_t tos;
10380         uint8_t tos_value;
10381         cmdline_fixed_string_t proto;
10382         uint8_t proto_value;
10383         cmdline_fixed_string_t ttl;
10384         uint8_t ttl_value;
10385         cmdline_fixed_string_t vlan;
10386         uint16_t vlan_value;
10387         cmdline_fixed_string_t flexbytes;
10388         cmdline_fixed_string_t flexbytes_value;
10389         cmdline_fixed_string_t pf_vf;
10390         cmdline_fixed_string_t drop;
10391         cmdline_fixed_string_t queue;
10392         uint16_t  queue_id;
10393         cmdline_fixed_string_t fd_id;
10394         uint32_t  fd_id_value;
10395         cmdline_fixed_string_t mac;
10396         struct ether_addr mac_addr;
10397         cmdline_fixed_string_t tunnel;
10398         cmdline_fixed_string_t tunnel_type;
10399         cmdline_fixed_string_t tunnel_id;
10400         uint32_t tunnel_id_value;
10401         cmdline_fixed_string_t packet;
10402         char filepath[];
10403 };
10404
10405 static inline int
10406 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10407 {
10408         char s[256];
10409         const char *p, *p0 = q_arg;
10410         char *end;
10411         unsigned long int_fld;
10412         char *str_fld[max_num];
10413         int i;
10414         unsigned size;
10415         int ret = -1;
10416
10417         p = strchr(p0, '(');
10418         if (p == NULL)
10419                 return -1;
10420         ++p;
10421         p0 = strchr(p, ')');
10422         if (p0 == NULL)
10423                 return -1;
10424
10425         size = p0 - p;
10426         if (size >= sizeof(s))
10427                 return -1;
10428
10429         snprintf(s, sizeof(s), "%.*s", size, p);
10430         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10431         if (ret < 0 || ret > max_num)
10432                 return -1;
10433         for (i = 0; i < ret; i++) {
10434                 errno = 0;
10435                 int_fld = strtoul(str_fld[i], &end, 0);
10436                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10437                         return -1;
10438                 flexbytes[i] = (uint8_t)int_fld;
10439         }
10440         return ret;
10441 }
10442
10443 static uint16_t
10444 str2flowtype(char *string)
10445 {
10446         uint8_t i = 0;
10447         static const struct {
10448                 char str[32];
10449                 uint16_t type;
10450         } flowtype_str[] = {
10451                 {"raw", RTE_ETH_FLOW_RAW},
10452                 {"ipv4", RTE_ETH_FLOW_IPV4},
10453                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10454                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10455                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10456                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10457                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10458                 {"ipv6", RTE_ETH_FLOW_IPV6},
10459                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10460                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10461                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10462                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10463                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10464                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10465         };
10466
10467         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10468                 if (!strcmp(flowtype_str[i].str, string))
10469                         return flowtype_str[i].type;
10470         }
10471
10472         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10473                 return (uint16_t)atoi(string);
10474
10475         return RTE_ETH_FLOW_UNKNOWN;
10476 }
10477
10478 static enum rte_eth_fdir_tunnel_type
10479 str2fdir_tunneltype(char *string)
10480 {
10481         uint8_t i = 0;
10482
10483         static const struct {
10484                 char str[32];
10485                 enum rte_eth_fdir_tunnel_type type;
10486         } tunneltype_str[] = {
10487                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10488                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10489         };
10490
10491         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10492                 if (!strcmp(tunneltype_str[i].str, string))
10493                         return tunneltype_str[i].type;
10494         }
10495         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10496 }
10497
10498 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10499 do { \
10500         if ((ip_addr).family == AF_INET) \
10501                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10502         else { \
10503                 printf("invalid parameter.\n"); \
10504                 return; \
10505         } \
10506 } while (0)
10507
10508 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10509 do { \
10510         if ((ip_addr).family == AF_INET6) \
10511                 rte_memcpy(&(ip), \
10512                                  &((ip_addr).addr.ipv6), \
10513                                  sizeof(struct in6_addr)); \
10514         else { \
10515                 printf("invalid parameter.\n"); \
10516                 return; \
10517         } \
10518 } while (0)
10519
10520 static void
10521 cmd_flow_director_filter_parsed(void *parsed_result,
10522                           __attribute__((unused)) struct cmdline *cl,
10523                           __attribute__((unused)) void *data)
10524 {
10525         struct cmd_flow_director_result *res = parsed_result;
10526         struct rte_eth_fdir_filter entry;
10527         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10528         char *end;
10529         unsigned long vf_id;
10530         int ret = 0;
10531
10532         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10533         if (ret < 0) {
10534                 printf("flow director is not supported on port %u.\n",
10535                         res->port_id);
10536                 return;
10537         }
10538         memset(flexbytes, 0, sizeof(flexbytes));
10539         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10540
10541         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10542                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10543                         printf("Please set mode to MAC-VLAN.\n");
10544                         return;
10545                 }
10546         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10547                 if (strcmp(res->mode_value, "Tunnel")) {
10548                         printf("Please set mode to Tunnel.\n");
10549                         return;
10550                 }
10551         } else {
10552                 if (!strcmp(res->mode_value, "raw")) {
10553 #ifdef RTE_LIBRTE_I40E_PMD
10554                         struct rte_pmd_i40e_flow_type_mapping
10555                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10556                         struct rte_pmd_i40e_pkt_template_conf conf;
10557                         uint16_t flow_type = str2flowtype(res->flow_type);
10558                         uint16_t i, port = res->port_id;
10559                         uint8_t add;
10560
10561                         memset(&conf, 0, sizeof(conf));
10562
10563                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10564                                 printf("Invalid flow type specified.\n");
10565                                 return;
10566                         }
10567                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10568                                                                  mapping);
10569                         if (ret)
10570                                 return;
10571                         if (mapping[flow_type].pctype == 0ULL) {
10572                                 printf("Invalid flow type specified.\n");
10573                                 return;
10574                         }
10575                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10576                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10577                                         conf.input.pctype = i;
10578                                         break;
10579                                 }
10580                         }
10581
10582                         conf.input.packet = open_file(res->filepath,
10583                                                 &conf.input.length);
10584                         if (!conf.input.packet)
10585                                 return;
10586                         if (!strcmp(res->drop, "drop"))
10587                                 conf.action.behavior =
10588                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10589                         else
10590                                 conf.action.behavior =
10591                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10592                         conf.action.report_status =
10593                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10594                         conf.action.rx_queue = res->queue_id;
10595                         conf.soft_id = res->fd_id_value;
10596                         add  = strcmp(res->ops, "del") ? 1 : 0;
10597                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10598                                                                         &conf,
10599                                                                         add);
10600                         if (ret < 0)
10601                                 printf("flow director config error: (%s)\n",
10602                                        strerror(-ret));
10603                         close_file(conf.input.packet);
10604 #endif
10605                         return;
10606                 } else if (strcmp(res->mode_value, "IP")) {
10607                         printf("Please set mode to IP or raw.\n");
10608                         return;
10609                 }
10610                 entry.input.flow_type = str2flowtype(res->flow_type);
10611         }
10612
10613         ret = parse_flexbytes(res->flexbytes_value,
10614                                         flexbytes,
10615                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10616         if (ret < 0) {
10617                 printf("error: Cannot parse flexbytes input.\n");
10618                 return;
10619         }
10620
10621         switch (entry.input.flow_type) {
10622         case RTE_ETH_FLOW_FRAG_IPV4:
10623         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10624                 entry.input.flow.ip4_flow.proto = res->proto_value;
10625                 /* fall-through */
10626         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10627         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10628                 IPV4_ADDR_TO_UINT(res->ip_dst,
10629                         entry.input.flow.ip4_flow.dst_ip);
10630                 IPV4_ADDR_TO_UINT(res->ip_src,
10631                         entry.input.flow.ip4_flow.src_ip);
10632                 entry.input.flow.ip4_flow.tos = res->tos_value;
10633                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10634                 /* need convert to big endian. */
10635                 entry.input.flow.udp4_flow.dst_port =
10636                                 rte_cpu_to_be_16(res->port_dst);
10637                 entry.input.flow.udp4_flow.src_port =
10638                                 rte_cpu_to_be_16(res->port_src);
10639                 break;
10640         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10641                 IPV4_ADDR_TO_UINT(res->ip_dst,
10642                         entry.input.flow.sctp4_flow.ip.dst_ip);
10643                 IPV4_ADDR_TO_UINT(res->ip_src,
10644                         entry.input.flow.sctp4_flow.ip.src_ip);
10645                 entry.input.flow.ip4_flow.tos = res->tos_value;
10646                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10647                 /* need convert to big endian. */
10648                 entry.input.flow.sctp4_flow.dst_port =
10649                                 rte_cpu_to_be_16(res->port_dst);
10650                 entry.input.flow.sctp4_flow.src_port =
10651                                 rte_cpu_to_be_16(res->port_src);
10652                 entry.input.flow.sctp4_flow.verify_tag =
10653                                 rte_cpu_to_be_32(res->verify_tag_value);
10654                 break;
10655         case RTE_ETH_FLOW_FRAG_IPV6:
10656         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10657                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10658                 /* fall-through */
10659         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10660         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10661                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10662                         entry.input.flow.ipv6_flow.dst_ip);
10663                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10664                         entry.input.flow.ipv6_flow.src_ip);
10665                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10666                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10667                 /* need convert to big endian. */
10668                 entry.input.flow.udp6_flow.dst_port =
10669                                 rte_cpu_to_be_16(res->port_dst);
10670                 entry.input.flow.udp6_flow.src_port =
10671                                 rte_cpu_to_be_16(res->port_src);
10672                 break;
10673         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10674                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10675                         entry.input.flow.sctp6_flow.ip.dst_ip);
10676                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10677                         entry.input.flow.sctp6_flow.ip.src_ip);
10678                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10679                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10680                 /* need convert to big endian. */
10681                 entry.input.flow.sctp6_flow.dst_port =
10682                                 rte_cpu_to_be_16(res->port_dst);
10683                 entry.input.flow.sctp6_flow.src_port =
10684                                 rte_cpu_to_be_16(res->port_src);
10685                 entry.input.flow.sctp6_flow.verify_tag =
10686                                 rte_cpu_to_be_32(res->verify_tag_value);
10687                 break;
10688         case RTE_ETH_FLOW_L2_PAYLOAD:
10689                 entry.input.flow.l2_flow.ether_type =
10690                         rte_cpu_to_be_16(res->ether_type);
10691                 break;
10692         default:
10693                 break;
10694         }
10695
10696         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10697                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10698                                  &res->mac_addr,
10699                                  sizeof(struct ether_addr));
10700
10701         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10702                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10703                                  &res->mac_addr,
10704                                  sizeof(struct ether_addr));
10705                 entry.input.flow.tunnel_flow.tunnel_type =
10706                         str2fdir_tunneltype(res->tunnel_type);
10707                 entry.input.flow.tunnel_flow.tunnel_id =
10708                         rte_cpu_to_be_32(res->tunnel_id_value);
10709         }
10710
10711         rte_memcpy(entry.input.flow_ext.flexbytes,
10712                    flexbytes,
10713                    RTE_ETH_FDIR_MAX_FLEXLEN);
10714
10715         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10716
10717         entry.action.flex_off = 0;  /*use 0 by default */
10718         if (!strcmp(res->drop, "drop"))
10719                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10720         else
10721                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10722
10723         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10724             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10725                 if (!strcmp(res->pf_vf, "pf"))
10726                         entry.input.flow_ext.is_vf = 0;
10727                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10728                         struct rte_eth_dev_info dev_info;
10729
10730                         memset(&dev_info, 0, sizeof(dev_info));
10731                         rte_eth_dev_info_get(res->port_id, &dev_info);
10732                         errno = 0;
10733                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10734                         if (errno != 0 || *end != '\0' ||
10735                             vf_id >= dev_info.max_vfs) {
10736                                 printf("invalid parameter %s.\n", res->pf_vf);
10737                                 return;
10738                         }
10739                         entry.input.flow_ext.is_vf = 1;
10740                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10741                 } else {
10742                         printf("invalid parameter %s.\n", res->pf_vf);
10743                         return;
10744                 }
10745         }
10746
10747         /* set to report FD ID by default */
10748         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10749         entry.action.rx_queue = res->queue_id;
10750         entry.soft_id = res->fd_id_value;
10751         if (!strcmp(res->ops, "add"))
10752                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10753                                              RTE_ETH_FILTER_ADD, &entry);
10754         else if (!strcmp(res->ops, "del"))
10755                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10756                                              RTE_ETH_FILTER_DELETE, &entry);
10757         else
10758                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10759                                              RTE_ETH_FILTER_UPDATE, &entry);
10760         if (ret < 0)
10761                 printf("flow director programming error: (%s)\n",
10762                         strerror(-ret));
10763 }
10764
10765 cmdline_parse_token_string_t cmd_flow_director_filter =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10767                                  flow_director_filter, "flow_director_filter");
10768 cmdline_parse_token_num_t cmd_flow_director_port_id =
10769         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10770                               port_id, UINT16);
10771 cmdline_parse_token_string_t cmd_flow_director_ops =
10772         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10773                                  ops, "add#del#update");
10774 cmdline_parse_token_string_t cmd_flow_director_flow =
10775         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10776                                  flow, "flow");
10777 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10778         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10779                 flow_type, NULL);
10780 cmdline_parse_token_string_t cmd_flow_director_ether =
10781         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10782                                  ether, "ether");
10783 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10784         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10785                               ether_type, UINT16);
10786 cmdline_parse_token_string_t cmd_flow_director_src =
10787         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10788                                  src, "src");
10789 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10790         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10791                                  ip_src);
10792 cmdline_parse_token_num_t cmd_flow_director_port_src =
10793         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10794                               port_src, UINT16);
10795 cmdline_parse_token_string_t cmd_flow_director_dst =
10796         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10797                                  dst, "dst");
10798 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10799         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10800                                  ip_dst);
10801 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10802         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10803                               port_dst, UINT16);
10804 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10805         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10806                                   verify_tag, "verify_tag");
10807 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10808         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10809                               verify_tag_value, UINT32);
10810 cmdline_parse_token_string_t cmd_flow_director_tos =
10811         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10812                                  tos, "tos");
10813 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10814         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10815                               tos_value, UINT8);
10816 cmdline_parse_token_string_t cmd_flow_director_proto =
10817         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10818                                  proto, "proto");
10819 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10820         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10821                               proto_value, UINT8);
10822 cmdline_parse_token_string_t cmd_flow_director_ttl =
10823         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10824                                  ttl, "ttl");
10825 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10826         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10827                               ttl_value, UINT8);
10828 cmdline_parse_token_string_t cmd_flow_director_vlan =
10829         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10830                                  vlan, "vlan");
10831 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10832         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10833                               vlan_value, UINT16);
10834 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10835         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10836                                  flexbytes, "flexbytes");
10837 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10838         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10839                               flexbytes_value, NULL);
10840 cmdline_parse_token_string_t cmd_flow_director_drop =
10841         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10842                                  drop, "drop#fwd");
10843 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10844         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10845                               pf_vf, NULL);
10846 cmdline_parse_token_string_t cmd_flow_director_queue =
10847         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10848                                  queue, "queue");
10849 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10850         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10851                               queue_id, UINT16);
10852 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10853         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10854                                  fd_id, "fd_id");
10855 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10856         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10857                               fd_id_value, UINT32);
10858
10859 cmdline_parse_token_string_t cmd_flow_director_mode =
10860         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10861                                  mode, "mode");
10862 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10863         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10864                                  mode_value, "IP");
10865 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10866         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10867                                  mode_value, "MAC-VLAN");
10868 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10869         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10870                                  mode_value, "Tunnel");
10871 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10872         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10873                                  mode_value, "raw");
10874 cmdline_parse_token_string_t cmd_flow_director_mac =
10875         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10876                                  mac, "mac");
10877 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10878         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10879                                     mac_addr);
10880 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10881         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10882                                  tunnel, "tunnel");
10883 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10884         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10885                                  tunnel_type, "NVGRE#VxLAN");
10886 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10887         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10888                                  tunnel_id, "tunnel-id");
10889 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10890         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10891                               tunnel_id_value, UINT32);
10892 cmdline_parse_token_string_t cmd_flow_director_packet =
10893         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10894                                  packet, "packet");
10895 cmdline_parse_token_string_t cmd_flow_director_filepath =
10896         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10897                                  filepath, NULL);
10898
10899 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10900         .f = cmd_flow_director_filter_parsed,
10901         .data = NULL,
10902         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10903                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10904                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10905                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10906                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10907                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10908                 "fd_id <fd_id_value>: "
10909                 "Add or delete an ip flow director entry on NIC",
10910         .tokens = {
10911                 (void *)&cmd_flow_director_filter,
10912                 (void *)&cmd_flow_director_port_id,
10913                 (void *)&cmd_flow_director_mode,
10914                 (void *)&cmd_flow_director_mode_ip,
10915                 (void *)&cmd_flow_director_ops,
10916                 (void *)&cmd_flow_director_flow,
10917                 (void *)&cmd_flow_director_flow_type,
10918                 (void *)&cmd_flow_director_src,
10919                 (void *)&cmd_flow_director_ip_src,
10920                 (void *)&cmd_flow_director_dst,
10921                 (void *)&cmd_flow_director_ip_dst,
10922                 (void *)&cmd_flow_director_tos,
10923                 (void *)&cmd_flow_director_tos_value,
10924                 (void *)&cmd_flow_director_proto,
10925                 (void *)&cmd_flow_director_proto_value,
10926                 (void *)&cmd_flow_director_ttl,
10927                 (void *)&cmd_flow_director_ttl_value,
10928                 (void *)&cmd_flow_director_vlan,
10929                 (void *)&cmd_flow_director_vlan_value,
10930                 (void *)&cmd_flow_director_flexbytes,
10931                 (void *)&cmd_flow_director_flexbytes_value,
10932                 (void *)&cmd_flow_director_drop,
10933                 (void *)&cmd_flow_director_pf_vf,
10934                 (void *)&cmd_flow_director_queue,
10935                 (void *)&cmd_flow_director_queue_id,
10936                 (void *)&cmd_flow_director_fd_id,
10937                 (void *)&cmd_flow_director_fd_id_value,
10938                 NULL,
10939         },
10940 };
10941
10942 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10943         .f = cmd_flow_director_filter_parsed,
10944         .data = NULL,
10945         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10946                 "director entry on NIC",
10947         .tokens = {
10948                 (void *)&cmd_flow_director_filter,
10949                 (void *)&cmd_flow_director_port_id,
10950                 (void *)&cmd_flow_director_mode,
10951                 (void *)&cmd_flow_director_mode_ip,
10952                 (void *)&cmd_flow_director_ops,
10953                 (void *)&cmd_flow_director_flow,
10954                 (void *)&cmd_flow_director_flow_type,
10955                 (void *)&cmd_flow_director_src,
10956                 (void *)&cmd_flow_director_ip_src,
10957                 (void *)&cmd_flow_director_port_src,
10958                 (void *)&cmd_flow_director_dst,
10959                 (void *)&cmd_flow_director_ip_dst,
10960                 (void *)&cmd_flow_director_port_dst,
10961                 (void *)&cmd_flow_director_tos,
10962                 (void *)&cmd_flow_director_tos_value,
10963                 (void *)&cmd_flow_director_ttl,
10964                 (void *)&cmd_flow_director_ttl_value,
10965                 (void *)&cmd_flow_director_vlan,
10966                 (void *)&cmd_flow_director_vlan_value,
10967                 (void *)&cmd_flow_director_flexbytes,
10968                 (void *)&cmd_flow_director_flexbytes_value,
10969                 (void *)&cmd_flow_director_drop,
10970                 (void *)&cmd_flow_director_pf_vf,
10971                 (void *)&cmd_flow_director_queue,
10972                 (void *)&cmd_flow_director_queue_id,
10973                 (void *)&cmd_flow_director_fd_id,
10974                 (void *)&cmd_flow_director_fd_id_value,
10975                 NULL,
10976         },
10977 };
10978
10979 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10980         .f = cmd_flow_director_filter_parsed,
10981         .data = NULL,
10982         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10983                 "director entry on NIC",
10984         .tokens = {
10985                 (void *)&cmd_flow_director_filter,
10986                 (void *)&cmd_flow_director_port_id,
10987                 (void *)&cmd_flow_director_mode,
10988                 (void *)&cmd_flow_director_mode_ip,
10989                 (void *)&cmd_flow_director_ops,
10990                 (void *)&cmd_flow_director_flow,
10991                 (void *)&cmd_flow_director_flow_type,
10992                 (void *)&cmd_flow_director_src,
10993                 (void *)&cmd_flow_director_ip_src,
10994                 (void *)&cmd_flow_director_port_src,
10995                 (void *)&cmd_flow_director_dst,
10996                 (void *)&cmd_flow_director_ip_dst,
10997                 (void *)&cmd_flow_director_port_dst,
10998                 (void *)&cmd_flow_director_verify_tag,
10999                 (void *)&cmd_flow_director_verify_tag_value,
11000                 (void *)&cmd_flow_director_tos,
11001                 (void *)&cmd_flow_director_tos_value,
11002                 (void *)&cmd_flow_director_ttl,
11003                 (void *)&cmd_flow_director_ttl_value,
11004                 (void *)&cmd_flow_director_vlan,
11005                 (void *)&cmd_flow_director_vlan_value,
11006                 (void *)&cmd_flow_director_flexbytes,
11007                 (void *)&cmd_flow_director_flexbytes_value,
11008                 (void *)&cmd_flow_director_drop,
11009                 (void *)&cmd_flow_director_pf_vf,
11010                 (void *)&cmd_flow_director_queue,
11011                 (void *)&cmd_flow_director_queue_id,
11012                 (void *)&cmd_flow_director_fd_id,
11013                 (void *)&cmd_flow_director_fd_id_value,
11014                 NULL,
11015         },
11016 };
11017
11018 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11019         .f = cmd_flow_director_filter_parsed,
11020         .data = NULL,
11021         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11022                 "director entry on NIC",
11023         .tokens = {
11024                 (void *)&cmd_flow_director_filter,
11025                 (void *)&cmd_flow_director_port_id,
11026                 (void *)&cmd_flow_director_mode,
11027                 (void *)&cmd_flow_director_mode_ip,
11028                 (void *)&cmd_flow_director_ops,
11029                 (void *)&cmd_flow_director_flow,
11030                 (void *)&cmd_flow_director_flow_type,
11031                 (void *)&cmd_flow_director_ether,
11032                 (void *)&cmd_flow_director_ether_type,
11033                 (void *)&cmd_flow_director_flexbytes,
11034                 (void *)&cmd_flow_director_flexbytes_value,
11035                 (void *)&cmd_flow_director_drop,
11036                 (void *)&cmd_flow_director_pf_vf,
11037                 (void *)&cmd_flow_director_queue,
11038                 (void *)&cmd_flow_director_queue_id,
11039                 (void *)&cmd_flow_director_fd_id,
11040                 (void *)&cmd_flow_director_fd_id_value,
11041                 NULL,
11042         },
11043 };
11044
11045 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11046         .f = cmd_flow_director_filter_parsed,
11047         .data = NULL,
11048         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11049                 "director entry on NIC",
11050         .tokens = {
11051                 (void *)&cmd_flow_director_filter,
11052                 (void *)&cmd_flow_director_port_id,
11053                 (void *)&cmd_flow_director_mode,
11054                 (void *)&cmd_flow_director_mode_mac_vlan,
11055                 (void *)&cmd_flow_director_ops,
11056                 (void *)&cmd_flow_director_mac,
11057                 (void *)&cmd_flow_director_mac_addr,
11058                 (void *)&cmd_flow_director_vlan,
11059                 (void *)&cmd_flow_director_vlan_value,
11060                 (void *)&cmd_flow_director_flexbytes,
11061                 (void *)&cmd_flow_director_flexbytes_value,
11062                 (void *)&cmd_flow_director_drop,
11063                 (void *)&cmd_flow_director_queue,
11064                 (void *)&cmd_flow_director_queue_id,
11065                 (void *)&cmd_flow_director_fd_id,
11066                 (void *)&cmd_flow_director_fd_id_value,
11067                 NULL,
11068         },
11069 };
11070
11071 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11072         .f = cmd_flow_director_filter_parsed,
11073         .data = NULL,
11074         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11075                 "director entry on NIC",
11076         .tokens = {
11077                 (void *)&cmd_flow_director_filter,
11078                 (void *)&cmd_flow_director_port_id,
11079                 (void *)&cmd_flow_director_mode,
11080                 (void *)&cmd_flow_director_mode_tunnel,
11081                 (void *)&cmd_flow_director_ops,
11082                 (void *)&cmd_flow_director_mac,
11083                 (void *)&cmd_flow_director_mac_addr,
11084                 (void *)&cmd_flow_director_vlan,
11085                 (void *)&cmd_flow_director_vlan_value,
11086                 (void *)&cmd_flow_director_tunnel,
11087                 (void *)&cmd_flow_director_tunnel_type,
11088                 (void *)&cmd_flow_director_tunnel_id,
11089                 (void *)&cmd_flow_director_tunnel_id_value,
11090                 (void *)&cmd_flow_director_flexbytes,
11091                 (void *)&cmd_flow_director_flexbytes_value,
11092                 (void *)&cmd_flow_director_drop,
11093                 (void *)&cmd_flow_director_queue,
11094                 (void *)&cmd_flow_director_queue_id,
11095                 (void *)&cmd_flow_director_fd_id,
11096                 (void *)&cmd_flow_director_fd_id_value,
11097                 NULL,
11098         },
11099 };
11100
11101 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11102         .f = cmd_flow_director_filter_parsed,
11103         .data = NULL,
11104         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11105                 "director entry on NIC",
11106         .tokens = {
11107                 (void *)&cmd_flow_director_filter,
11108                 (void *)&cmd_flow_director_port_id,
11109                 (void *)&cmd_flow_director_mode,
11110                 (void *)&cmd_flow_director_mode_raw,
11111                 (void *)&cmd_flow_director_ops,
11112                 (void *)&cmd_flow_director_flow,
11113                 (void *)&cmd_flow_director_flow_type,
11114                 (void *)&cmd_flow_director_drop,
11115                 (void *)&cmd_flow_director_queue,
11116                 (void *)&cmd_flow_director_queue_id,
11117                 (void *)&cmd_flow_director_fd_id,
11118                 (void *)&cmd_flow_director_fd_id_value,
11119                 (void *)&cmd_flow_director_packet,
11120                 (void *)&cmd_flow_director_filepath,
11121                 NULL,
11122         },
11123 };
11124
11125 struct cmd_flush_flow_director_result {
11126         cmdline_fixed_string_t flush_flow_director;
11127         portid_t port_id;
11128 };
11129
11130 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11131         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11132                                  flush_flow_director, "flush_flow_director");
11133 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11134         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11135                               port_id, UINT16);
11136
11137 static void
11138 cmd_flush_flow_director_parsed(void *parsed_result,
11139                           __attribute__((unused)) struct cmdline *cl,
11140                           __attribute__((unused)) void *data)
11141 {
11142         struct cmd_flow_director_result *res = parsed_result;
11143         int ret = 0;
11144
11145         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11146         if (ret < 0) {
11147                 printf("flow director is not supported on port %u.\n",
11148                         res->port_id);
11149                 return;
11150         }
11151
11152         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11153                         RTE_ETH_FILTER_FLUSH, NULL);
11154         if (ret < 0)
11155                 printf("flow director table flushing error: (%s)\n",
11156                         strerror(-ret));
11157 }
11158
11159 cmdline_parse_inst_t cmd_flush_flow_director = {
11160         .f = cmd_flush_flow_director_parsed,
11161         .data = NULL,
11162         .help_str = "flush_flow_director <port_id>: "
11163                 "Flush all flow director entries of a device on NIC",
11164         .tokens = {
11165                 (void *)&cmd_flush_flow_director_flush,
11166                 (void *)&cmd_flush_flow_director_port_id,
11167                 NULL,
11168         },
11169 };
11170
11171 /* *** deal with flow director mask *** */
11172 struct cmd_flow_director_mask_result {
11173         cmdline_fixed_string_t flow_director_mask;
11174         portid_t port_id;
11175         cmdline_fixed_string_t mode;
11176         cmdline_fixed_string_t mode_value;
11177         cmdline_fixed_string_t vlan;
11178         uint16_t vlan_mask;
11179         cmdline_fixed_string_t src_mask;
11180         cmdline_ipaddr_t ipv4_src;
11181         cmdline_ipaddr_t ipv6_src;
11182         uint16_t port_src;
11183         cmdline_fixed_string_t dst_mask;
11184         cmdline_ipaddr_t ipv4_dst;
11185         cmdline_ipaddr_t ipv6_dst;
11186         uint16_t port_dst;
11187         cmdline_fixed_string_t mac;
11188         uint8_t mac_addr_byte_mask;
11189         cmdline_fixed_string_t tunnel_id;
11190         uint32_t tunnel_id_mask;
11191         cmdline_fixed_string_t tunnel_type;
11192         uint8_t tunnel_type_mask;
11193 };
11194
11195 static void
11196 cmd_flow_director_mask_parsed(void *parsed_result,
11197                           __attribute__((unused)) struct cmdline *cl,
11198                           __attribute__((unused)) void *data)
11199 {
11200         struct cmd_flow_director_mask_result *res = parsed_result;
11201         struct rte_eth_fdir_masks *mask;
11202         struct rte_port *port;
11203
11204         port = &ports[res->port_id];
11205         /** Check if the port is not started **/
11206         if (port->port_status != RTE_PORT_STOPPED) {
11207                 printf("Please stop port %d first\n", res->port_id);
11208                 return;
11209         }
11210
11211         mask = &port->dev_conf.fdir_conf.mask;
11212
11213         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11214                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11215                         printf("Please set mode to MAC-VLAN.\n");
11216                         return;
11217                 }
11218
11219                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11220         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11221                 if (strcmp(res->mode_value, "Tunnel")) {
11222                         printf("Please set mode to Tunnel.\n");
11223                         return;
11224                 }
11225
11226                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11227                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11228                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11229                 mask->tunnel_type_mask = res->tunnel_type_mask;
11230         } else {
11231                 if (strcmp(res->mode_value, "IP")) {
11232                         printf("Please set mode to IP.\n");
11233                         return;
11234                 }
11235
11236                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11237                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11238                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11239                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11240                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11241                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11242                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11243         }
11244
11245         cmd_reconfig_device_queue(res->port_id, 1, 1);
11246 }
11247
11248 cmdline_parse_token_string_t cmd_flow_director_mask =
11249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11250                                  flow_director_mask, "flow_director_mask");
11251 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11252         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11253                               port_id, UINT16);
11254 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11256                                  vlan, "vlan");
11257 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11258         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11259                               vlan_mask, UINT16);
11260 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11262                                  src_mask, "src_mask");
11263 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11264         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11265                                  ipv4_src);
11266 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11267         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11268                                  ipv6_src);
11269 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11270         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11271                               port_src, UINT16);
11272 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11273         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11274                                  dst_mask, "dst_mask");
11275 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11276         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11277                                  ipv4_dst);
11278 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11279         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11280                                  ipv6_dst);
11281 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11282         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11283                               port_dst, UINT16);
11284
11285 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11287                                  mode, "mode");
11288 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11289         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11290                                  mode_value, "IP");
11291 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11292         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11293                                  mode_value, "MAC-VLAN");
11294 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11296                                  mode_value, "Tunnel");
11297 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11299                                  mac, "mac");
11300 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11301         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11302                               mac_addr_byte_mask, UINT8);
11303 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11304         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11305                                  tunnel_type, "tunnel-type");
11306 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11307         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11308                               tunnel_type_mask, UINT8);
11309 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11311                                  tunnel_id, "tunnel-id");
11312 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11313         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11314                               tunnel_id_mask, UINT32);
11315
11316 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11317         .f = cmd_flow_director_mask_parsed,
11318         .data = NULL,
11319         .help_str = "flow_director_mask ... : "
11320                 "Set IP mode flow director's mask on NIC",
11321         .tokens = {
11322                 (void *)&cmd_flow_director_mask,
11323                 (void *)&cmd_flow_director_mask_port_id,
11324                 (void *)&cmd_flow_director_mask_mode,
11325                 (void *)&cmd_flow_director_mask_mode_ip,
11326                 (void *)&cmd_flow_director_mask_vlan,
11327                 (void *)&cmd_flow_director_mask_vlan_value,
11328                 (void *)&cmd_flow_director_mask_src,
11329                 (void *)&cmd_flow_director_mask_ipv4_src,
11330                 (void *)&cmd_flow_director_mask_ipv6_src,
11331                 (void *)&cmd_flow_director_mask_port_src,
11332                 (void *)&cmd_flow_director_mask_dst,
11333                 (void *)&cmd_flow_director_mask_ipv4_dst,
11334                 (void *)&cmd_flow_director_mask_ipv6_dst,
11335                 (void *)&cmd_flow_director_mask_port_dst,
11336                 NULL,
11337         },
11338 };
11339
11340 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11341         .f = cmd_flow_director_mask_parsed,
11342         .data = NULL,
11343         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11344                 "flow director's mask on NIC",
11345         .tokens = {
11346                 (void *)&cmd_flow_director_mask,
11347                 (void *)&cmd_flow_director_mask_port_id,
11348                 (void *)&cmd_flow_director_mask_mode,
11349                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11350                 (void *)&cmd_flow_director_mask_vlan,
11351                 (void *)&cmd_flow_director_mask_vlan_value,
11352                 NULL,
11353         },
11354 };
11355
11356 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11357         .f = cmd_flow_director_mask_parsed,
11358         .data = NULL,
11359         .help_str = "flow_director_mask ... : Set tunnel mode "
11360                 "flow director's mask on NIC",
11361         .tokens = {
11362                 (void *)&cmd_flow_director_mask,
11363                 (void *)&cmd_flow_director_mask_port_id,
11364                 (void *)&cmd_flow_director_mask_mode,
11365                 (void *)&cmd_flow_director_mask_mode_tunnel,
11366                 (void *)&cmd_flow_director_mask_vlan,
11367                 (void *)&cmd_flow_director_mask_vlan_value,
11368                 (void *)&cmd_flow_director_mask_mac,
11369                 (void *)&cmd_flow_director_mask_mac_value,
11370                 (void *)&cmd_flow_director_mask_tunnel_type,
11371                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11372                 (void *)&cmd_flow_director_mask_tunnel_id,
11373                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11374                 NULL,
11375         },
11376 };
11377
11378 /* *** deal with flow director mask on flexible payload *** */
11379 struct cmd_flow_director_flex_mask_result {
11380         cmdline_fixed_string_t flow_director_flexmask;
11381         portid_t port_id;
11382         cmdline_fixed_string_t flow;
11383         cmdline_fixed_string_t flow_type;
11384         cmdline_fixed_string_t mask;
11385 };
11386
11387 static void
11388 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11389                           __attribute__((unused)) struct cmdline *cl,
11390                           __attribute__((unused)) void *data)
11391 {
11392         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11393         struct rte_eth_fdir_info fdir_info;
11394         struct rte_eth_fdir_flex_mask flex_mask;
11395         struct rte_port *port;
11396         uint64_t flow_type_mask;
11397         uint16_t i;
11398         int ret;
11399
11400         port = &ports[res->port_id];
11401         /** Check if the port is not started **/
11402         if (port->port_status != RTE_PORT_STOPPED) {
11403                 printf("Please stop port %d first\n", res->port_id);
11404                 return;
11405         }
11406
11407         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11408         ret = parse_flexbytes(res->mask,
11409                         flex_mask.mask,
11410                         RTE_ETH_FDIR_MAX_FLEXLEN);
11411         if (ret < 0) {
11412                 printf("error: Cannot parse mask input.\n");
11413                 return;
11414         }
11415
11416         memset(&fdir_info, 0, sizeof(fdir_info));
11417         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11418                                 RTE_ETH_FILTER_INFO, &fdir_info);
11419         if (ret < 0) {
11420                 printf("Cannot get FDir filter info\n");
11421                 return;
11422         }
11423
11424         if (!strcmp(res->flow_type, "none")) {
11425                 /* means don't specify the flow type */
11426                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11427                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11428                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11429                                0, sizeof(struct rte_eth_fdir_flex_mask));
11430                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11431                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11432                                  &flex_mask,
11433                                  sizeof(struct rte_eth_fdir_flex_mask));
11434                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11435                 return;
11436         }
11437         flow_type_mask = fdir_info.flow_types_mask[0];
11438         if (!strcmp(res->flow_type, "all")) {
11439                 if (!flow_type_mask) {
11440                         printf("No flow type supported\n");
11441                         return;
11442                 }
11443                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11444                         if (flow_type_mask & (1ULL << i)) {
11445                                 flex_mask.flow_type = i;
11446                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11447                         }
11448                 }
11449                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11450                 return;
11451         }
11452         flex_mask.flow_type = str2flowtype(res->flow_type);
11453         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11454                 printf("Flow type %s not supported on port %d\n",
11455                                 res->flow_type, res->port_id);
11456                 return;
11457         }
11458         fdir_set_flex_mask(res->port_id, &flex_mask);
11459         cmd_reconfig_device_queue(res->port_id, 1, 1);
11460 }
11461
11462 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11463         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11464                                  flow_director_flexmask,
11465                                  "flow_director_flex_mask");
11466 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11467         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11468                               port_id, UINT16);
11469 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11471                                  flow, "flow");
11472 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11473         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11474                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11475                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11476 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11477         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11478                                  mask, NULL);
11479
11480 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11481         .f = cmd_flow_director_flex_mask_parsed,
11482         .data = NULL,
11483         .help_str = "flow_director_flex_mask ... : "
11484                 "Set flow director's flex mask on NIC",
11485         .tokens = {
11486                 (void *)&cmd_flow_director_flexmask,
11487                 (void *)&cmd_flow_director_flexmask_port_id,
11488                 (void *)&cmd_flow_director_flexmask_flow,
11489                 (void *)&cmd_flow_director_flexmask_flow_type,
11490                 (void *)&cmd_flow_director_flexmask_mask,
11491                 NULL,
11492         },
11493 };
11494
11495 /* *** deal with flow director flexible payload configuration *** */
11496 struct cmd_flow_director_flexpayload_result {
11497         cmdline_fixed_string_t flow_director_flexpayload;
11498         portid_t port_id;
11499         cmdline_fixed_string_t payload_layer;
11500         cmdline_fixed_string_t payload_cfg;
11501 };
11502
11503 static inline int
11504 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11505 {
11506         char s[256];
11507         const char *p, *p0 = q_arg;
11508         char *end;
11509         unsigned long int_fld;
11510         char *str_fld[max_num];
11511         int i;
11512         unsigned size;
11513         int ret = -1;
11514
11515         p = strchr(p0, '(');
11516         if (p == NULL)
11517                 return -1;
11518         ++p;
11519         p0 = strchr(p, ')');
11520         if (p0 == NULL)
11521                 return -1;
11522
11523         size = p0 - p;
11524         if (size >= sizeof(s))
11525                 return -1;
11526
11527         snprintf(s, sizeof(s), "%.*s", size, p);
11528         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11529         if (ret < 0 || ret > max_num)
11530                 return -1;
11531         for (i = 0; i < ret; i++) {
11532                 errno = 0;
11533                 int_fld = strtoul(str_fld[i], &end, 0);
11534                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11535                         return -1;
11536                 offsets[i] = (uint16_t)int_fld;
11537         }
11538         return ret;
11539 }
11540
11541 static void
11542 cmd_flow_director_flxpld_parsed(void *parsed_result,
11543                           __attribute__((unused)) struct cmdline *cl,
11544                           __attribute__((unused)) void *data)
11545 {
11546         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11547         struct rte_eth_flex_payload_cfg flex_cfg;
11548         struct rte_port *port;
11549         int ret = 0;
11550
11551         port = &ports[res->port_id];
11552         /** Check if the port is not started **/
11553         if (port->port_status != RTE_PORT_STOPPED) {
11554                 printf("Please stop port %d first\n", res->port_id);
11555                 return;
11556         }
11557
11558         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11559
11560         if (!strcmp(res->payload_layer, "raw"))
11561                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11562         else if (!strcmp(res->payload_layer, "l2"))
11563                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11564         else if (!strcmp(res->payload_layer, "l3"))
11565                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11566         else if (!strcmp(res->payload_layer, "l4"))
11567                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11568
11569         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11570                             RTE_ETH_FDIR_MAX_FLEXLEN);
11571         if (ret < 0) {
11572                 printf("error: Cannot parse flex payload input.\n");
11573                 return;
11574         }
11575
11576         fdir_set_flex_payload(res->port_id, &flex_cfg);
11577         cmd_reconfig_device_queue(res->port_id, 1, 1);
11578 }
11579
11580 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11581         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11582                                  flow_director_flexpayload,
11583                                  "flow_director_flex_payload");
11584 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11585         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11586                               port_id, UINT16);
11587 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11588         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11589                                  payload_layer, "raw#l2#l3#l4");
11590 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11591         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11592                                  payload_cfg, NULL);
11593
11594 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11595         .f = cmd_flow_director_flxpld_parsed,
11596         .data = NULL,
11597         .help_str = "flow_director_flexpayload ... : "
11598                 "Set flow director's flex payload on NIC",
11599         .tokens = {
11600                 (void *)&cmd_flow_director_flexpayload,
11601                 (void *)&cmd_flow_director_flexpayload_port_id,
11602                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11603                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11604                 NULL,
11605         },
11606 };
11607
11608 /* Generic flow interface command. */
11609 extern cmdline_parse_inst_t cmd_flow;
11610
11611 /* *** Classification Filters Control *** */
11612 /* *** Get symmetric hash enable per port *** */
11613 struct cmd_get_sym_hash_ena_per_port_result {
11614         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11615         portid_t port_id;
11616 };
11617
11618 static void
11619 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11620                                  __rte_unused struct cmdline *cl,
11621                                  __rte_unused void *data)
11622 {
11623         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11624         struct rte_eth_hash_filter_info info;
11625         int ret;
11626
11627         if (rte_eth_dev_filter_supported(res->port_id,
11628                                 RTE_ETH_FILTER_HASH) < 0) {
11629                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11630                                                         res->port_id);
11631                 return;
11632         }
11633
11634         memset(&info, 0, sizeof(info));
11635         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11636         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11637                                                 RTE_ETH_FILTER_GET, &info);
11638
11639         if (ret < 0) {
11640                 printf("Cannot get symmetric hash enable per port "
11641                                         "on port %u\n", res->port_id);
11642                 return;
11643         }
11644
11645         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11646                                 "enabled" : "disabled", res->port_id);
11647 }
11648
11649 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11650         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11651                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11652 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11653         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11654                 port_id, UINT16);
11655
11656 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11657         .f = cmd_get_sym_hash_per_port_parsed,
11658         .data = NULL,
11659         .help_str = "get_sym_hash_ena_per_port <port_id>",
11660         .tokens = {
11661                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11662                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11663                 NULL,
11664         },
11665 };
11666
11667 /* *** Set symmetric hash enable per port *** */
11668 struct cmd_set_sym_hash_ena_per_port_result {
11669         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11670         cmdline_fixed_string_t enable;
11671         portid_t port_id;
11672 };
11673
11674 static void
11675 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11676                                  __rte_unused struct cmdline *cl,
11677                                  __rte_unused void *data)
11678 {
11679         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11680         struct rte_eth_hash_filter_info info;
11681         int ret;
11682
11683         if (rte_eth_dev_filter_supported(res->port_id,
11684                                 RTE_ETH_FILTER_HASH) < 0) {
11685                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11686                                                         res->port_id);
11687                 return;
11688         }
11689
11690         memset(&info, 0, sizeof(info));
11691         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11692         if (!strcmp(res->enable, "enable"))
11693                 info.info.enable = 1;
11694         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11695                                         RTE_ETH_FILTER_SET, &info);
11696         if (ret < 0) {
11697                 printf("Cannot set symmetric hash enable per port on "
11698                                         "port %u\n", res->port_id);
11699                 return;
11700         }
11701         printf("Symmetric hash has been set to %s on port %u\n",
11702                                         res->enable, res->port_id);
11703 }
11704
11705 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11706         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11707                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11708 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11709         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11710                 port_id, UINT16);
11711 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11712         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11713                 enable, "enable#disable");
11714
11715 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11716         .f = cmd_set_sym_hash_per_port_parsed,
11717         .data = NULL,
11718         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11719         .tokens = {
11720                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11721                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11722                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11723                 NULL,
11724         },
11725 };
11726
11727 /* Get global config of hash function */
11728 struct cmd_get_hash_global_config_result {
11729         cmdline_fixed_string_t get_hash_global_config;
11730         portid_t port_id;
11731 };
11732
11733 static char *
11734 flowtype_to_str(uint16_t ftype)
11735 {
11736         uint16_t i;
11737         static struct {
11738                 char str[16];
11739                 uint16_t ftype;
11740         } ftype_table[] = {
11741                 {"ipv4", RTE_ETH_FLOW_IPV4},
11742                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11743                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11744                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11745                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11746                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11747                 {"ipv6", RTE_ETH_FLOW_IPV6},
11748                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11749                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11750                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11751                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11752                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11753                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11754                 {"port", RTE_ETH_FLOW_PORT},
11755                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11756                 {"geneve", RTE_ETH_FLOW_GENEVE},
11757                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11758         };
11759
11760         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11761                 if (ftype_table[i].ftype == ftype)
11762                         return ftype_table[i].str;
11763         }
11764
11765         return NULL;
11766 }
11767
11768 static void
11769 cmd_get_hash_global_config_parsed(void *parsed_result,
11770                                   __rte_unused struct cmdline *cl,
11771                                   __rte_unused void *data)
11772 {
11773         struct cmd_get_hash_global_config_result *res = parsed_result;
11774         struct rte_eth_hash_filter_info info;
11775         uint32_t idx, offset;
11776         uint16_t i;
11777         char *str;
11778         int ret;
11779
11780         if (rte_eth_dev_filter_supported(res->port_id,
11781                         RTE_ETH_FILTER_HASH) < 0) {
11782                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11783                                                         res->port_id);
11784                 return;
11785         }
11786
11787         memset(&info, 0, sizeof(info));
11788         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11789         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11790                                         RTE_ETH_FILTER_GET, &info);
11791         if (ret < 0) {
11792                 printf("Cannot get hash global configurations by port %d\n",
11793                                                         res->port_id);
11794                 return;
11795         }
11796
11797         switch (info.info.global_conf.hash_func) {
11798         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11799                 printf("Hash function is Toeplitz\n");
11800                 break;
11801         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11802                 printf("Hash function is Simple XOR\n");
11803                 break;
11804         default:
11805                 printf("Unknown hash function\n");
11806                 break;
11807         }
11808
11809         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11810                 idx = i / UINT64_BIT;
11811                 offset = i % UINT64_BIT;
11812                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11813                                                 (1ULL << offset)))
11814                         continue;
11815                 str = flowtype_to_str(i);
11816                 if (!str)
11817                         continue;
11818                 printf("Symmetric hash is %s globally for flow type %s "
11819                                                         "by port %d\n",
11820                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11821                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11822                                                         res->port_id);
11823         }
11824 }
11825
11826 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11827         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11828                 get_hash_global_config, "get_hash_global_config");
11829 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11830         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11831                 port_id, UINT16);
11832
11833 cmdline_parse_inst_t cmd_get_hash_global_config = {
11834         .f = cmd_get_hash_global_config_parsed,
11835         .data = NULL,
11836         .help_str = "get_hash_global_config <port_id>",
11837         .tokens = {
11838                 (void *)&cmd_get_hash_global_config_all,
11839                 (void *)&cmd_get_hash_global_config_port_id,
11840                 NULL,
11841         },
11842 };
11843
11844 /* Set global config of hash function */
11845 struct cmd_set_hash_global_config_result {
11846         cmdline_fixed_string_t set_hash_global_config;
11847         portid_t port_id;
11848         cmdline_fixed_string_t hash_func;
11849         cmdline_fixed_string_t flow_type;
11850         cmdline_fixed_string_t enable;
11851 };
11852
11853 static void
11854 cmd_set_hash_global_config_parsed(void *parsed_result,
11855                                   __rte_unused struct cmdline *cl,
11856                                   __rte_unused void *data)
11857 {
11858         struct cmd_set_hash_global_config_result *res = parsed_result;
11859         struct rte_eth_hash_filter_info info;
11860         uint32_t ftype, idx, offset;
11861         int ret;
11862
11863         if (rte_eth_dev_filter_supported(res->port_id,
11864                                 RTE_ETH_FILTER_HASH) < 0) {
11865                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11866                                                         res->port_id);
11867                 return;
11868         }
11869         memset(&info, 0, sizeof(info));
11870         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11871         if (!strcmp(res->hash_func, "toeplitz"))
11872                 info.info.global_conf.hash_func =
11873                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11874         else if (!strcmp(res->hash_func, "simple_xor"))
11875                 info.info.global_conf.hash_func =
11876                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11877         else if (!strcmp(res->hash_func, "default"))
11878                 info.info.global_conf.hash_func =
11879                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11880
11881         ftype = str2flowtype(res->flow_type);
11882         idx = ftype / UINT64_BIT;
11883         offset = ftype % UINT64_BIT;
11884         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11885         if (!strcmp(res->enable, "enable"))
11886                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11887                                                 (1ULL << offset);
11888         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11889                                         RTE_ETH_FILTER_SET, &info);
11890         if (ret < 0)
11891                 printf("Cannot set global hash configurations by port %d\n",
11892                                                         res->port_id);
11893         else
11894                 printf("Global hash configurations have been set "
11895                         "succcessfully by port %d\n", res->port_id);
11896 }
11897
11898 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11899         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11900                 set_hash_global_config, "set_hash_global_config");
11901 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11902         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11903                 port_id, UINT16);
11904 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11905         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11906                 hash_func, "toeplitz#simple_xor#default");
11907 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11908         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11909                 flow_type,
11910                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11911                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11912 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11913         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11914                 enable, "enable#disable");
11915
11916 cmdline_parse_inst_t cmd_set_hash_global_config = {
11917         .f = cmd_set_hash_global_config_parsed,
11918         .data = NULL,
11919         .help_str = "set_hash_global_config <port_id> "
11920                 "toeplitz|simple_xor|default "
11921                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11922                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11923                 "l2_payload enable|disable",
11924         .tokens = {
11925                 (void *)&cmd_set_hash_global_config_all,
11926                 (void *)&cmd_set_hash_global_config_port_id,
11927                 (void *)&cmd_set_hash_global_config_hash_func,
11928                 (void *)&cmd_set_hash_global_config_flow_type,
11929                 (void *)&cmd_set_hash_global_config_enable,
11930                 NULL,
11931         },
11932 };
11933
11934 /* Set hash input set */
11935 struct cmd_set_hash_input_set_result {
11936         cmdline_fixed_string_t set_hash_input_set;
11937         portid_t port_id;
11938         cmdline_fixed_string_t flow_type;
11939         cmdline_fixed_string_t inset_field;
11940         cmdline_fixed_string_t select;
11941 };
11942
11943 static enum rte_eth_input_set_field
11944 str2inset(char *string)
11945 {
11946         uint16_t i;
11947
11948         static const struct {
11949                 char str[32];
11950                 enum rte_eth_input_set_field inset;
11951         } inset_table[] = {
11952                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11953                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11954                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11955                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11956                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11957                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11958                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11959                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11960                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11961                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11962                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11963                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11964                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11965                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11966                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11967                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11968                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11969                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11970                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11971                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11972                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11973                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11974                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11975                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11976                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11977                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11978                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11979                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11980                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11981                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11982                 {"none", RTE_ETH_INPUT_SET_NONE},
11983         };
11984
11985         for (i = 0; i < RTE_DIM(inset_table); i++) {
11986                 if (!strcmp(string, inset_table[i].str))
11987                         return inset_table[i].inset;
11988         }
11989
11990         return RTE_ETH_INPUT_SET_UNKNOWN;
11991 }
11992
11993 static void
11994 cmd_set_hash_input_set_parsed(void *parsed_result,
11995                               __rte_unused struct cmdline *cl,
11996                               __rte_unused void *data)
11997 {
11998         struct cmd_set_hash_input_set_result *res = parsed_result;
11999         struct rte_eth_hash_filter_info info;
12000
12001         memset(&info, 0, sizeof(info));
12002         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12003         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12004         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12005         info.info.input_set_conf.inset_size = 1;
12006         if (!strcmp(res->select, "select"))
12007                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12008         else if (!strcmp(res->select, "add"))
12009                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12010         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12011                                 RTE_ETH_FILTER_SET, &info);
12012 }
12013
12014 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12015         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12016                 set_hash_input_set, "set_hash_input_set");
12017 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12018         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12019                 port_id, UINT16);
12020 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12021         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12022                 flow_type, NULL);
12023 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12024         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12025                 inset_field,
12026                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12027                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12028                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12029                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12030                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12031                 "fld-8th#none");
12032 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12033         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12034                 select, "select#add");
12035
12036 cmdline_parse_inst_t cmd_set_hash_input_set = {
12037         .f = cmd_set_hash_input_set_parsed,
12038         .data = NULL,
12039         .help_str = "set_hash_input_set <port_id> "
12040         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12041         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12042         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12043         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12044         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12045         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12046         "fld-7th|fld-8th|none select|add",
12047         .tokens = {
12048                 (void *)&cmd_set_hash_input_set_cmd,
12049                 (void *)&cmd_set_hash_input_set_port_id,
12050                 (void *)&cmd_set_hash_input_set_flow_type,
12051                 (void *)&cmd_set_hash_input_set_field,
12052                 (void *)&cmd_set_hash_input_set_select,
12053                 NULL,
12054         },
12055 };
12056
12057 /* Set flow director input set */
12058 struct cmd_set_fdir_input_set_result {
12059         cmdline_fixed_string_t set_fdir_input_set;
12060         portid_t port_id;
12061         cmdline_fixed_string_t flow_type;
12062         cmdline_fixed_string_t inset_field;
12063         cmdline_fixed_string_t select;
12064 };
12065
12066 static void
12067 cmd_set_fdir_input_set_parsed(void *parsed_result,
12068         __rte_unused struct cmdline *cl,
12069         __rte_unused void *data)
12070 {
12071         struct cmd_set_fdir_input_set_result *res = parsed_result;
12072         struct rte_eth_fdir_filter_info info;
12073
12074         memset(&info, 0, sizeof(info));
12075         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12076         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12077         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12078         info.info.input_set_conf.inset_size = 1;
12079         if (!strcmp(res->select, "select"))
12080                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12081         else if (!strcmp(res->select, "add"))
12082                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12083         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12084                 RTE_ETH_FILTER_SET, &info);
12085 }
12086
12087 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12088         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12089         set_fdir_input_set, "set_fdir_input_set");
12090 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12091         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12092         port_id, UINT16);
12093 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12094         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12095         flow_type,
12096         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12097         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12098 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12099         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12100         inset_field,
12101         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12102         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12103         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12104         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12105         "sctp-veri-tag#none");
12106 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12107         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12108         select, "select#add");
12109
12110 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12111         .f = cmd_set_fdir_input_set_parsed,
12112         .data = NULL,
12113         .help_str = "set_fdir_input_set <port_id> "
12114         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12115         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12116         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12117         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12118         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12119         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12120         "sctp-veri-tag|none select|add",
12121         .tokens = {
12122                 (void *)&cmd_set_fdir_input_set_cmd,
12123                 (void *)&cmd_set_fdir_input_set_port_id,
12124                 (void *)&cmd_set_fdir_input_set_flow_type,
12125                 (void *)&cmd_set_fdir_input_set_field,
12126                 (void *)&cmd_set_fdir_input_set_select,
12127                 NULL,
12128         },
12129 };
12130
12131 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12132 struct cmd_mcast_addr_result {
12133         cmdline_fixed_string_t mcast_addr_cmd;
12134         cmdline_fixed_string_t what;
12135         uint16_t port_num;
12136         struct ether_addr mc_addr;
12137 };
12138
12139 static void cmd_mcast_addr_parsed(void *parsed_result,
12140                 __attribute__((unused)) struct cmdline *cl,
12141                 __attribute__((unused)) void *data)
12142 {
12143         struct cmd_mcast_addr_result *res = parsed_result;
12144
12145         if (!is_multicast_ether_addr(&res->mc_addr)) {
12146                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12147                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12148                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12149                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12150                 return;
12151         }
12152         if (strcmp(res->what, "add") == 0)
12153                 mcast_addr_add(res->port_num, &res->mc_addr);
12154         else
12155                 mcast_addr_remove(res->port_num, &res->mc_addr);
12156 }
12157
12158 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12159         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12160                                  mcast_addr_cmd, "mcast_addr");
12161 cmdline_parse_token_string_t cmd_mcast_addr_what =
12162         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12163                                  "add#remove");
12164 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12165         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12166 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12167         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12168
12169 cmdline_parse_inst_t cmd_mcast_addr = {
12170         .f = cmd_mcast_addr_parsed,
12171         .data = (void *)0,
12172         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12173                 "Add/Remove multicast MAC address on port_id",
12174         .tokens = {
12175                 (void *)&cmd_mcast_addr_cmd,
12176                 (void *)&cmd_mcast_addr_what,
12177                 (void *)&cmd_mcast_addr_portnum,
12178                 (void *)&cmd_mcast_addr_addr,
12179                 NULL,
12180         },
12181 };
12182
12183 /* l2 tunnel config
12184  * only support E-tag now.
12185  */
12186
12187 /* Ether type config */
12188 struct cmd_config_l2_tunnel_eth_type_result {
12189         cmdline_fixed_string_t port;
12190         cmdline_fixed_string_t config;
12191         cmdline_fixed_string_t all;
12192         portid_t id;
12193         cmdline_fixed_string_t l2_tunnel;
12194         cmdline_fixed_string_t l2_tunnel_type;
12195         cmdline_fixed_string_t eth_type;
12196         uint16_t eth_type_val;
12197 };
12198
12199 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12200         TOKEN_STRING_INITIALIZER
12201                 (struct cmd_config_l2_tunnel_eth_type_result,
12202                  port, "port");
12203 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12204         TOKEN_STRING_INITIALIZER
12205                 (struct cmd_config_l2_tunnel_eth_type_result,
12206                  config, "config");
12207 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12208         TOKEN_STRING_INITIALIZER
12209                 (struct cmd_config_l2_tunnel_eth_type_result,
12210                  all, "all");
12211 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12212         TOKEN_NUM_INITIALIZER
12213                 (struct cmd_config_l2_tunnel_eth_type_result,
12214                  id, UINT16);
12215 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12216         TOKEN_STRING_INITIALIZER
12217                 (struct cmd_config_l2_tunnel_eth_type_result,
12218                  l2_tunnel, "l2-tunnel");
12219 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12220         TOKEN_STRING_INITIALIZER
12221                 (struct cmd_config_l2_tunnel_eth_type_result,
12222                  l2_tunnel_type, "E-tag");
12223 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12224         TOKEN_STRING_INITIALIZER
12225                 (struct cmd_config_l2_tunnel_eth_type_result,
12226                  eth_type, "ether-type");
12227 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12228         TOKEN_NUM_INITIALIZER
12229                 (struct cmd_config_l2_tunnel_eth_type_result,
12230                  eth_type_val, UINT16);
12231
12232 static enum rte_eth_tunnel_type
12233 str2fdir_l2_tunnel_type(char *string)
12234 {
12235         uint32_t i = 0;
12236
12237         static const struct {
12238                 char str[32];
12239                 enum rte_eth_tunnel_type type;
12240         } l2_tunnel_type_str[] = {
12241                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12242         };
12243
12244         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12245                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12246                         return l2_tunnel_type_str[i].type;
12247         }
12248         return RTE_TUNNEL_TYPE_NONE;
12249 }
12250
12251 /* ether type config for all ports */
12252 static void
12253 cmd_config_l2_tunnel_eth_type_all_parsed
12254         (void *parsed_result,
12255          __attribute__((unused)) struct cmdline *cl,
12256          __attribute__((unused)) void *data)
12257 {
12258         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12259         struct rte_eth_l2_tunnel_conf entry;
12260         portid_t pid;
12261
12262         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12263         entry.ether_type = res->eth_type_val;
12264
12265         RTE_ETH_FOREACH_DEV(pid) {
12266                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12267         }
12268 }
12269
12270 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12271         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12272         .data = NULL,
12273         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12274         .tokens = {
12275                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12276                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12277                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12278                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12279                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12280                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12281                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12282                 NULL,
12283         },
12284 };
12285
12286 /* ether type config for a specific port */
12287 static void
12288 cmd_config_l2_tunnel_eth_type_specific_parsed(
12289         void *parsed_result,
12290         __attribute__((unused)) struct cmdline *cl,
12291         __attribute__((unused)) void *data)
12292 {
12293         struct cmd_config_l2_tunnel_eth_type_result *res =
12294                  parsed_result;
12295         struct rte_eth_l2_tunnel_conf entry;
12296
12297         if (port_id_is_invalid(res->id, ENABLED_WARN))
12298                 return;
12299
12300         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12301         entry.ether_type = res->eth_type_val;
12302
12303         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12304 }
12305
12306 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12307         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12308         .data = NULL,
12309         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12310         .tokens = {
12311                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12312                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12313                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12314                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12315                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12316                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12317                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12318                 NULL,
12319         },
12320 };
12321
12322 /* Enable/disable l2 tunnel */
12323 struct cmd_config_l2_tunnel_en_dis_result {
12324         cmdline_fixed_string_t port;
12325         cmdline_fixed_string_t config;
12326         cmdline_fixed_string_t all;
12327         portid_t id;
12328         cmdline_fixed_string_t l2_tunnel;
12329         cmdline_fixed_string_t l2_tunnel_type;
12330         cmdline_fixed_string_t en_dis;
12331 };
12332
12333 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12334         TOKEN_STRING_INITIALIZER
12335                 (struct cmd_config_l2_tunnel_en_dis_result,
12336                  port, "port");
12337 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12338         TOKEN_STRING_INITIALIZER
12339                 (struct cmd_config_l2_tunnel_en_dis_result,
12340                  config, "config");
12341 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12342         TOKEN_STRING_INITIALIZER
12343                 (struct cmd_config_l2_tunnel_en_dis_result,
12344                  all, "all");
12345 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12346         TOKEN_NUM_INITIALIZER
12347                 (struct cmd_config_l2_tunnel_en_dis_result,
12348                  id, UINT16);
12349 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12350         TOKEN_STRING_INITIALIZER
12351                 (struct cmd_config_l2_tunnel_en_dis_result,
12352                  l2_tunnel, "l2-tunnel");
12353 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12354         TOKEN_STRING_INITIALIZER
12355                 (struct cmd_config_l2_tunnel_en_dis_result,
12356                  l2_tunnel_type, "E-tag");
12357 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12358         TOKEN_STRING_INITIALIZER
12359                 (struct cmd_config_l2_tunnel_en_dis_result,
12360                  en_dis, "enable#disable");
12361
12362 /* enable/disable l2 tunnel for all ports */
12363 static void
12364 cmd_config_l2_tunnel_en_dis_all_parsed(
12365         void *parsed_result,
12366         __attribute__((unused)) struct cmdline *cl,
12367         __attribute__((unused)) void *data)
12368 {
12369         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12370         struct rte_eth_l2_tunnel_conf entry;
12371         portid_t pid;
12372         uint8_t en;
12373
12374         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12375
12376         if (!strcmp("enable", res->en_dis))
12377                 en = 1;
12378         else
12379                 en = 0;
12380
12381         RTE_ETH_FOREACH_DEV(pid) {
12382                 rte_eth_dev_l2_tunnel_offload_set(pid,
12383                                                   &entry,
12384                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12385                                                   en);
12386         }
12387 }
12388
12389 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12390         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12391         .data = NULL,
12392         .help_str = "port config all l2-tunnel E-tag enable|disable",
12393         .tokens = {
12394                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12395                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12396                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12397                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12398                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12399                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12400                 NULL,
12401         },
12402 };
12403
12404 /* enable/disable l2 tunnel for a port */
12405 static void
12406 cmd_config_l2_tunnel_en_dis_specific_parsed(
12407         void *parsed_result,
12408         __attribute__((unused)) struct cmdline *cl,
12409         __attribute__((unused)) void *data)
12410 {
12411         struct cmd_config_l2_tunnel_en_dis_result *res =
12412                 parsed_result;
12413         struct rte_eth_l2_tunnel_conf entry;
12414
12415         if (port_id_is_invalid(res->id, ENABLED_WARN))
12416                 return;
12417
12418         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12419
12420         if (!strcmp("enable", res->en_dis))
12421                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12422                                                   &entry,
12423                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12424                                                   1);
12425         else
12426                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12427                                                   &entry,
12428                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12429                                                   0);
12430 }
12431
12432 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12433         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12434         .data = NULL,
12435         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12436         .tokens = {
12437                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12438                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12439                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12440                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12441                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12442                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12443                 NULL,
12444         },
12445 };
12446
12447 /* E-tag configuration */
12448
12449 /* Common result structure for all E-tag configuration */
12450 struct cmd_config_e_tag_result {
12451         cmdline_fixed_string_t e_tag;
12452         cmdline_fixed_string_t set;
12453         cmdline_fixed_string_t insertion;
12454         cmdline_fixed_string_t stripping;
12455         cmdline_fixed_string_t forwarding;
12456         cmdline_fixed_string_t filter;
12457         cmdline_fixed_string_t add;
12458         cmdline_fixed_string_t del;
12459         cmdline_fixed_string_t on;
12460         cmdline_fixed_string_t off;
12461         cmdline_fixed_string_t on_off;
12462         cmdline_fixed_string_t port_tag_id;
12463         uint32_t port_tag_id_val;
12464         cmdline_fixed_string_t e_tag_id;
12465         uint16_t e_tag_id_val;
12466         cmdline_fixed_string_t dst_pool;
12467         uint8_t dst_pool_val;
12468         cmdline_fixed_string_t port;
12469         portid_t port_id;
12470         cmdline_fixed_string_t vf;
12471         uint8_t vf_id;
12472 };
12473
12474 /* Common CLI fields for all E-tag configuration */
12475 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12476         TOKEN_STRING_INITIALIZER
12477                 (struct cmd_config_e_tag_result,
12478                  e_tag, "E-tag");
12479 cmdline_parse_token_string_t cmd_config_e_tag_set =
12480         TOKEN_STRING_INITIALIZER
12481                 (struct cmd_config_e_tag_result,
12482                  set, "set");
12483 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12484         TOKEN_STRING_INITIALIZER
12485                 (struct cmd_config_e_tag_result,
12486                  insertion, "insertion");
12487 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12488         TOKEN_STRING_INITIALIZER
12489                 (struct cmd_config_e_tag_result,
12490                  stripping, "stripping");
12491 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12492         TOKEN_STRING_INITIALIZER
12493                 (struct cmd_config_e_tag_result,
12494                  forwarding, "forwarding");
12495 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12496         TOKEN_STRING_INITIALIZER
12497                 (struct cmd_config_e_tag_result,
12498                  filter, "filter");
12499 cmdline_parse_token_string_t cmd_config_e_tag_add =
12500         TOKEN_STRING_INITIALIZER
12501                 (struct cmd_config_e_tag_result,
12502                  add, "add");
12503 cmdline_parse_token_string_t cmd_config_e_tag_del =
12504         TOKEN_STRING_INITIALIZER
12505                 (struct cmd_config_e_tag_result,
12506                  del, "del");
12507 cmdline_parse_token_string_t cmd_config_e_tag_on =
12508         TOKEN_STRING_INITIALIZER
12509                 (struct cmd_config_e_tag_result,
12510                  on, "on");
12511 cmdline_parse_token_string_t cmd_config_e_tag_off =
12512         TOKEN_STRING_INITIALIZER
12513                 (struct cmd_config_e_tag_result,
12514                  off, "off");
12515 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12516         TOKEN_STRING_INITIALIZER
12517                 (struct cmd_config_e_tag_result,
12518                  on_off, "on#off");
12519 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12520         TOKEN_STRING_INITIALIZER
12521                 (struct cmd_config_e_tag_result,
12522                  port_tag_id, "port-tag-id");
12523 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12524         TOKEN_NUM_INITIALIZER
12525                 (struct cmd_config_e_tag_result,
12526                  port_tag_id_val, UINT32);
12527 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12528         TOKEN_STRING_INITIALIZER
12529                 (struct cmd_config_e_tag_result,
12530                  e_tag_id, "e-tag-id");
12531 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12532         TOKEN_NUM_INITIALIZER
12533                 (struct cmd_config_e_tag_result,
12534                  e_tag_id_val, UINT16);
12535 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12536         TOKEN_STRING_INITIALIZER
12537                 (struct cmd_config_e_tag_result,
12538                  dst_pool, "dst-pool");
12539 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12540         TOKEN_NUM_INITIALIZER
12541                 (struct cmd_config_e_tag_result,
12542                  dst_pool_val, UINT8);
12543 cmdline_parse_token_string_t cmd_config_e_tag_port =
12544         TOKEN_STRING_INITIALIZER
12545                 (struct cmd_config_e_tag_result,
12546                  port, "port");
12547 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12548         TOKEN_NUM_INITIALIZER
12549                 (struct cmd_config_e_tag_result,
12550                  port_id, UINT16);
12551 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12552         TOKEN_STRING_INITIALIZER
12553                 (struct cmd_config_e_tag_result,
12554                  vf, "vf");
12555 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12556         TOKEN_NUM_INITIALIZER
12557                 (struct cmd_config_e_tag_result,
12558                  vf_id, UINT8);
12559
12560 /* E-tag insertion configuration */
12561 static void
12562 cmd_config_e_tag_insertion_en_parsed(
12563         void *parsed_result,
12564         __attribute__((unused)) struct cmdline *cl,
12565         __attribute__((unused)) void *data)
12566 {
12567         struct cmd_config_e_tag_result *res =
12568                 parsed_result;
12569         struct rte_eth_l2_tunnel_conf entry;
12570
12571         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12572                 return;
12573
12574         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12575         entry.tunnel_id = res->port_tag_id_val;
12576         entry.vf_id = res->vf_id;
12577         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12578                                           &entry,
12579                                           ETH_L2_TUNNEL_INSERTION_MASK,
12580                                           1);
12581 }
12582
12583 static void
12584 cmd_config_e_tag_insertion_dis_parsed(
12585         void *parsed_result,
12586         __attribute__((unused)) struct cmdline *cl,
12587         __attribute__((unused)) void *data)
12588 {
12589         struct cmd_config_e_tag_result *res =
12590                 parsed_result;
12591         struct rte_eth_l2_tunnel_conf entry;
12592
12593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12594                 return;
12595
12596         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12597         entry.vf_id = res->vf_id;
12598
12599         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12600                                           &entry,
12601                                           ETH_L2_TUNNEL_INSERTION_MASK,
12602                                           0);
12603 }
12604
12605 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12606         .f = cmd_config_e_tag_insertion_en_parsed,
12607         .data = NULL,
12608         .help_str = "E-tag ... : E-tag insertion enable",
12609         .tokens = {
12610                 (void *)&cmd_config_e_tag_e_tag,
12611                 (void *)&cmd_config_e_tag_set,
12612                 (void *)&cmd_config_e_tag_insertion,
12613                 (void *)&cmd_config_e_tag_on,
12614                 (void *)&cmd_config_e_tag_port_tag_id,
12615                 (void *)&cmd_config_e_tag_port_tag_id_val,
12616                 (void *)&cmd_config_e_tag_port,
12617                 (void *)&cmd_config_e_tag_port_id,
12618                 (void *)&cmd_config_e_tag_vf,
12619                 (void *)&cmd_config_e_tag_vf_id,
12620                 NULL,
12621         },
12622 };
12623
12624 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12625         .f = cmd_config_e_tag_insertion_dis_parsed,
12626         .data = NULL,
12627         .help_str = "E-tag ... : E-tag insertion disable",
12628         .tokens = {
12629                 (void *)&cmd_config_e_tag_e_tag,
12630                 (void *)&cmd_config_e_tag_set,
12631                 (void *)&cmd_config_e_tag_insertion,
12632                 (void *)&cmd_config_e_tag_off,
12633                 (void *)&cmd_config_e_tag_port,
12634                 (void *)&cmd_config_e_tag_port_id,
12635                 (void *)&cmd_config_e_tag_vf,
12636                 (void *)&cmd_config_e_tag_vf_id,
12637                 NULL,
12638         },
12639 };
12640
12641 /* E-tag stripping configuration */
12642 static void
12643 cmd_config_e_tag_stripping_parsed(
12644         void *parsed_result,
12645         __attribute__((unused)) struct cmdline *cl,
12646         __attribute__((unused)) void *data)
12647 {
12648         struct cmd_config_e_tag_result *res =
12649                 parsed_result;
12650         struct rte_eth_l2_tunnel_conf entry;
12651
12652         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12653                 return;
12654
12655         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12656
12657         if (!strcmp(res->on_off, "on"))
12658                 rte_eth_dev_l2_tunnel_offload_set
12659                         (res->port_id,
12660                          &entry,
12661                          ETH_L2_TUNNEL_STRIPPING_MASK,
12662                          1);
12663         else
12664                 rte_eth_dev_l2_tunnel_offload_set
12665                         (res->port_id,
12666                          &entry,
12667                          ETH_L2_TUNNEL_STRIPPING_MASK,
12668                          0);
12669 }
12670
12671 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12672         .f = cmd_config_e_tag_stripping_parsed,
12673         .data = NULL,
12674         .help_str = "E-tag ... : E-tag stripping enable/disable",
12675         .tokens = {
12676                 (void *)&cmd_config_e_tag_e_tag,
12677                 (void *)&cmd_config_e_tag_set,
12678                 (void *)&cmd_config_e_tag_stripping,
12679                 (void *)&cmd_config_e_tag_on_off,
12680                 (void *)&cmd_config_e_tag_port,
12681                 (void *)&cmd_config_e_tag_port_id,
12682                 NULL,
12683         },
12684 };
12685
12686 /* E-tag forwarding configuration */
12687 static void
12688 cmd_config_e_tag_forwarding_parsed(
12689         void *parsed_result,
12690         __attribute__((unused)) struct cmdline *cl,
12691         __attribute__((unused)) void *data)
12692 {
12693         struct cmd_config_e_tag_result *res = parsed_result;
12694         struct rte_eth_l2_tunnel_conf entry;
12695
12696         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12697                 return;
12698
12699         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12700
12701         if (!strcmp(res->on_off, "on"))
12702                 rte_eth_dev_l2_tunnel_offload_set
12703                         (res->port_id,
12704                          &entry,
12705                          ETH_L2_TUNNEL_FORWARDING_MASK,
12706                          1);
12707         else
12708                 rte_eth_dev_l2_tunnel_offload_set
12709                         (res->port_id,
12710                          &entry,
12711                          ETH_L2_TUNNEL_FORWARDING_MASK,
12712                          0);
12713 }
12714
12715 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12716         .f = cmd_config_e_tag_forwarding_parsed,
12717         .data = NULL,
12718         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12719         .tokens = {
12720                 (void *)&cmd_config_e_tag_e_tag,
12721                 (void *)&cmd_config_e_tag_set,
12722                 (void *)&cmd_config_e_tag_forwarding,
12723                 (void *)&cmd_config_e_tag_on_off,
12724                 (void *)&cmd_config_e_tag_port,
12725                 (void *)&cmd_config_e_tag_port_id,
12726                 NULL,
12727         },
12728 };
12729
12730 /* E-tag filter configuration */
12731 static void
12732 cmd_config_e_tag_filter_add_parsed(
12733         void *parsed_result,
12734         __attribute__((unused)) struct cmdline *cl,
12735         __attribute__((unused)) void *data)
12736 {
12737         struct cmd_config_e_tag_result *res = parsed_result;
12738         struct rte_eth_l2_tunnel_conf entry;
12739         int ret = 0;
12740
12741         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12742                 return;
12743
12744         if (res->e_tag_id_val > 0x3fff) {
12745                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12746                 return;
12747         }
12748
12749         ret = rte_eth_dev_filter_supported(res->port_id,
12750                                            RTE_ETH_FILTER_L2_TUNNEL);
12751         if (ret < 0) {
12752                 printf("E-tag filter is not supported on port %u.\n",
12753                        res->port_id);
12754                 return;
12755         }
12756
12757         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12758         entry.tunnel_id = res->e_tag_id_val;
12759         entry.pool = res->dst_pool_val;
12760
12761         ret = rte_eth_dev_filter_ctrl(res->port_id,
12762                                       RTE_ETH_FILTER_L2_TUNNEL,
12763                                       RTE_ETH_FILTER_ADD,
12764                                       &entry);
12765         if (ret < 0)
12766                 printf("E-tag filter programming error: (%s)\n",
12767                        strerror(-ret));
12768 }
12769
12770 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12771         .f = cmd_config_e_tag_filter_add_parsed,
12772         .data = NULL,
12773         .help_str = "E-tag ... : E-tag filter add",
12774         .tokens = {
12775                 (void *)&cmd_config_e_tag_e_tag,
12776                 (void *)&cmd_config_e_tag_set,
12777                 (void *)&cmd_config_e_tag_filter,
12778                 (void *)&cmd_config_e_tag_add,
12779                 (void *)&cmd_config_e_tag_e_tag_id,
12780                 (void *)&cmd_config_e_tag_e_tag_id_val,
12781                 (void *)&cmd_config_e_tag_dst_pool,
12782                 (void *)&cmd_config_e_tag_dst_pool_val,
12783                 (void *)&cmd_config_e_tag_port,
12784                 (void *)&cmd_config_e_tag_port_id,
12785                 NULL,
12786         },
12787 };
12788
12789 static void
12790 cmd_config_e_tag_filter_del_parsed(
12791         void *parsed_result,
12792         __attribute__((unused)) struct cmdline *cl,
12793         __attribute__((unused)) void *data)
12794 {
12795         struct cmd_config_e_tag_result *res = parsed_result;
12796         struct rte_eth_l2_tunnel_conf entry;
12797         int ret = 0;
12798
12799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12800                 return;
12801
12802         if (res->e_tag_id_val > 0x3fff) {
12803                 printf("e-tag-id must be less than 0x3fff.\n");
12804                 return;
12805         }
12806
12807         ret = rte_eth_dev_filter_supported(res->port_id,
12808                                            RTE_ETH_FILTER_L2_TUNNEL);
12809         if (ret < 0) {
12810                 printf("E-tag filter is not supported on port %u.\n",
12811                        res->port_id);
12812                 return;
12813         }
12814
12815         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12816         entry.tunnel_id = res->e_tag_id_val;
12817
12818         ret = rte_eth_dev_filter_ctrl(res->port_id,
12819                                       RTE_ETH_FILTER_L2_TUNNEL,
12820                                       RTE_ETH_FILTER_DELETE,
12821                                       &entry);
12822         if (ret < 0)
12823                 printf("E-tag filter programming error: (%s)\n",
12824                        strerror(-ret));
12825 }
12826
12827 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12828         .f = cmd_config_e_tag_filter_del_parsed,
12829         .data = NULL,
12830         .help_str = "E-tag ... : E-tag filter delete",
12831         .tokens = {
12832                 (void *)&cmd_config_e_tag_e_tag,
12833                 (void *)&cmd_config_e_tag_set,
12834                 (void *)&cmd_config_e_tag_filter,
12835                 (void *)&cmd_config_e_tag_del,
12836                 (void *)&cmd_config_e_tag_e_tag_id,
12837                 (void *)&cmd_config_e_tag_e_tag_id_val,
12838                 (void *)&cmd_config_e_tag_port,
12839                 (void *)&cmd_config_e_tag_port_id,
12840                 NULL,
12841         },
12842 };
12843
12844 /* vf vlan anti spoof configuration */
12845
12846 /* Common result structure for vf vlan anti spoof */
12847 struct cmd_vf_vlan_anti_spoof_result {
12848         cmdline_fixed_string_t set;
12849         cmdline_fixed_string_t vf;
12850         cmdline_fixed_string_t vlan;
12851         cmdline_fixed_string_t antispoof;
12852         portid_t port_id;
12853         uint32_t vf_id;
12854         cmdline_fixed_string_t on_off;
12855 };
12856
12857 /* Common CLI fields for vf vlan anti spoof enable disable */
12858 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12859         TOKEN_STRING_INITIALIZER
12860                 (struct cmd_vf_vlan_anti_spoof_result,
12861                  set, "set");
12862 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_vf_vlan_anti_spoof_result,
12865                  vf, "vf");
12866 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_vf_vlan_anti_spoof_result,
12869                  vlan, "vlan");
12870 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12871         TOKEN_STRING_INITIALIZER
12872                 (struct cmd_vf_vlan_anti_spoof_result,
12873                  antispoof, "antispoof");
12874 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12875         TOKEN_NUM_INITIALIZER
12876                 (struct cmd_vf_vlan_anti_spoof_result,
12877                  port_id, UINT16);
12878 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12879         TOKEN_NUM_INITIALIZER
12880                 (struct cmd_vf_vlan_anti_spoof_result,
12881                  vf_id, UINT32);
12882 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12883         TOKEN_STRING_INITIALIZER
12884                 (struct cmd_vf_vlan_anti_spoof_result,
12885                  on_off, "on#off");
12886
12887 static void
12888 cmd_set_vf_vlan_anti_spoof_parsed(
12889         void *parsed_result,
12890         __attribute__((unused)) struct cmdline *cl,
12891         __attribute__((unused)) void *data)
12892 {
12893         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12894         int ret = -ENOTSUP;
12895
12896         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12897
12898         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12899                 return;
12900
12901 #ifdef RTE_LIBRTE_IXGBE_PMD
12902         if (ret == -ENOTSUP)
12903                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12904                                 res->vf_id, is_on);
12905 #endif
12906 #ifdef RTE_LIBRTE_I40E_PMD
12907         if (ret == -ENOTSUP)
12908                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12909                                 res->vf_id, is_on);
12910 #endif
12911 #ifdef RTE_LIBRTE_BNXT_PMD
12912         if (ret == -ENOTSUP)
12913                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12914                                 res->vf_id, is_on);
12915 #endif
12916
12917         switch (ret) {
12918         case 0:
12919                 break;
12920         case -EINVAL:
12921                 printf("invalid vf_id %d\n", res->vf_id);
12922                 break;
12923         case -ENODEV:
12924                 printf("invalid port_id %d\n", res->port_id);
12925                 break;
12926         case -ENOTSUP:
12927                 printf("function not implemented\n");
12928                 break;
12929         default:
12930                 printf("programming error: (%s)\n", strerror(-ret));
12931         }
12932 }
12933
12934 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12935         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12936         .data = NULL,
12937         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12938         .tokens = {
12939                 (void *)&cmd_vf_vlan_anti_spoof_set,
12940                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12941                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12942                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12943                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12944                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12945                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12946                 NULL,
12947         },
12948 };
12949
12950 /* vf mac anti spoof configuration */
12951
12952 /* Common result structure for vf mac anti spoof */
12953 struct cmd_vf_mac_anti_spoof_result {
12954         cmdline_fixed_string_t set;
12955         cmdline_fixed_string_t vf;
12956         cmdline_fixed_string_t mac;
12957         cmdline_fixed_string_t antispoof;
12958         portid_t port_id;
12959         uint32_t vf_id;
12960         cmdline_fixed_string_t on_off;
12961 };
12962
12963 /* Common CLI fields for vf mac anti spoof enable disable */
12964 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12965         TOKEN_STRING_INITIALIZER
12966                 (struct cmd_vf_mac_anti_spoof_result,
12967                  set, "set");
12968 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12969         TOKEN_STRING_INITIALIZER
12970                 (struct cmd_vf_mac_anti_spoof_result,
12971                  vf, "vf");
12972 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12973         TOKEN_STRING_INITIALIZER
12974                 (struct cmd_vf_mac_anti_spoof_result,
12975                  mac, "mac");
12976 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12977         TOKEN_STRING_INITIALIZER
12978                 (struct cmd_vf_mac_anti_spoof_result,
12979                  antispoof, "antispoof");
12980 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12981         TOKEN_NUM_INITIALIZER
12982                 (struct cmd_vf_mac_anti_spoof_result,
12983                  port_id, UINT16);
12984 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12985         TOKEN_NUM_INITIALIZER
12986                 (struct cmd_vf_mac_anti_spoof_result,
12987                  vf_id, UINT32);
12988 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12989         TOKEN_STRING_INITIALIZER
12990                 (struct cmd_vf_mac_anti_spoof_result,
12991                  on_off, "on#off");
12992
12993 static void
12994 cmd_set_vf_mac_anti_spoof_parsed(
12995         void *parsed_result,
12996         __attribute__((unused)) struct cmdline *cl,
12997         __attribute__((unused)) void *data)
12998 {
12999         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13000         int ret = -ENOTSUP;
13001
13002         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13003
13004         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13005                 return;
13006
13007 #ifdef RTE_LIBRTE_IXGBE_PMD
13008         if (ret == -ENOTSUP)
13009                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13010                         res->vf_id, is_on);
13011 #endif
13012 #ifdef RTE_LIBRTE_I40E_PMD
13013         if (ret == -ENOTSUP)
13014                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13015                         res->vf_id, is_on);
13016 #endif
13017 #ifdef RTE_LIBRTE_BNXT_PMD
13018         if (ret == -ENOTSUP)
13019                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13020                         res->vf_id, is_on);
13021 #endif
13022
13023         switch (ret) {
13024         case 0:
13025                 break;
13026         case -EINVAL:
13027                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13028                 break;
13029         case -ENODEV:
13030                 printf("invalid port_id %d\n", res->port_id);
13031                 break;
13032         case -ENOTSUP:
13033                 printf("function not implemented\n");
13034                 break;
13035         default:
13036                 printf("programming error: (%s)\n", strerror(-ret));
13037         }
13038 }
13039
13040 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13041         .f = cmd_set_vf_mac_anti_spoof_parsed,
13042         .data = NULL,
13043         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13044         .tokens = {
13045                 (void *)&cmd_vf_mac_anti_spoof_set,
13046                 (void *)&cmd_vf_mac_anti_spoof_vf,
13047                 (void *)&cmd_vf_mac_anti_spoof_mac,
13048                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13049                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13050                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13051                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13052                 NULL,
13053         },
13054 };
13055
13056 /* vf vlan strip queue configuration */
13057
13058 /* Common result structure for vf mac anti spoof */
13059 struct cmd_vf_vlan_stripq_result {
13060         cmdline_fixed_string_t set;
13061         cmdline_fixed_string_t vf;
13062         cmdline_fixed_string_t vlan;
13063         cmdline_fixed_string_t stripq;
13064         portid_t port_id;
13065         uint16_t vf_id;
13066         cmdline_fixed_string_t on_off;
13067 };
13068
13069 /* Common CLI fields for vf vlan strip enable disable */
13070 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13071         TOKEN_STRING_INITIALIZER
13072                 (struct cmd_vf_vlan_stripq_result,
13073                  set, "set");
13074 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_vf_vlan_stripq_result,
13077                  vf, "vf");
13078 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_vf_vlan_stripq_result,
13081                  vlan, "vlan");
13082 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13083         TOKEN_STRING_INITIALIZER
13084                 (struct cmd_vf_vlan_stripq_result,
13085                  stripq, "stripq");
13086 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13087         TOKEN_NUM_INITIALIZER
13088                 (struct cmd_vf_vlan_stripq_result,
13089                  port_id, UINT16);
13090 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13091         TOKEN_NUM_INITIALIZER
13092                 (struct cmd_vf_vlan_stripq_result,
13093                  vf_id, UINT16);
13094 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13095         TOKEN_STRING_INITIALIZER
13096                 (struct cmd_vf_vlan_stripq_result,
13097                  on_off, "on#off");
13098
13099 static void
13100 cmd_set_vf_vlan_stripq_parsed(
13101         void *parsed_result,
13102         __attribute__((unused)) struct cmdline *cl,
13103         __attribute__((unused)) void *data)
13104 {
13105         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13106         int ret = -ENOTSUP;
13107
13108         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13109
13110         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13111                 return;
13112
13113 #ifdef RTE_LIBRTE_IXGBE_PMD
13114         if (ret == -ENOTSUP)
13115                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13116                         res->vf_id, is_on);
13117 #endif
13118 #ifdef RTE_LIBRTE_I40E_PMD
13119         if (ret == -ENOTSUP)
13120                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13121                         res->vf_id, is_on);
13122 #endif
13123 #ifdef RTE_LIBRTE_BNXT_PMD
13124         if (ret == -ENOTSUP)
13125                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13126                         res->vf_id, is_on);
13127 #endif
13128
13129         switch (ret) {
13130         case 0:
13131                 break;
13132         case -EINVAL:
13133                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13134                 break;
13135         case -ENODEV:
13136                 printf("invalid port_id %d\n", res->port_id);
13137                 break;
13138         case -ENOTSUP:
13139                 printf("function not implemented\n");
13140                 break;
13141         default:
13142                 printf("programming error: (%s)\n", strerror(-ret));
13143         }
13144 }
13145
13146 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13147         .f = cmd_set_vf_vlan_stripq_parsed,
13148         .data = NULL,
13149         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13150         .tokens = {
13151                 (void *)&cmd_vf_vlan_stripq_set,
13152                 (void *)&cmd_vf_vlan_stripq_vf,
13153                 (void *)&cmd_vf_vlan_stripq_vlan,
13154                 (void *)&cmd_vf_vlan_stripq_stripq,
13155                 (void *)&cmd_vf_vlan_stripq_port_id,
13156                 (void *)&cmd_vf_vlan_stripq_vf_id,
13157                 (void *)&cmd_vf_vlan_stripq_on_off,
13158                 NULL,
13159         },
13160 };
13161
13162 /* vf vlan insert configuration */
13163
13164 /* Common result structure for vf vlan insert */
13165 struct cmd_vf_vlan_insert_result {
13166         cmdline_fixed_string_t set;
13167         cmdline_fixed_string_t vf;
13168         cmdline_fixed_string_t vlan;
13169         cmdline_fixed_string_t insert;
13170         portid_t port_id;
13171         uint16_t vf_id;
13172         uint16_t vlan_id;
13173 };
13174
13175 /* Common CLI fields for vf vlan insert enable disable */
13176 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13177         TOKEN_STRING_INITIALIZER
13178                 (struct cmd_vf_vlan_insert_result,
13179                  set, "set");
13180 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13181         TOKEN_STRING_INITIALIZER
13182                 (struct cmd_vf_vlan_insert_result,
13183                  vf, "vf");
13184 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13185         TOKEN_STRING_INITIALIZER
13186                 (struct cmd_vf_vlan_insert_result,
13187                  vlan, "vlan");
13188 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13189         TOKEN_STRING_INITIALIZER
13190                 (struct cmd_vf_vlan_insert_result,
13191                  insert, "insert");
13192 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13193         TOKEN_NUM_INITIALIZER
13194                 (struct cmd_vf_vlan_insert_result,
13195                  port_id, UINT16);
13196 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13197         TOKEN_NUM_INITIALIZER
13198                 (struct cmd_vf_vlan_insert_result,
13199                  vf_id, UINT16);
13200 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13201         TOKEN_NUM_INITIALIZER
13202                 (struct cmd_vf_vlan_insert_result,
13203                  vlan_id, UINT16);
13204
13205 static void
13206 cmd_set_vf_vlan_insert_parsed(
13207         void *parsed_result,
13208         __attribute__((unused)) struct cmdline *cl,
13209         __attribute__((unused)) void *data)
13210 {
13211         struct cmd_vf_vlan_insert_result *res = parsed_result;
13212         int ret = -ENOTSUP;
13213
13214         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13215                 return;
13216
13217 #ifdef RTE_LIBRTE_IXGBE_PMD
13218         if (ret == -ENOTSUP)
13219                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13220                         res->vlan_id);
13221 #endif
13222 #ifdef RTE_LIBRTE_I40E_PMD
13223         if (ret == -ENOTSUP)
13224                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13225                         res->vlan_id);
13226 #endif
13227 #ifdef RTE_LIBRTE_BNXT_PMD
13228         if (ret == -ENOTSUP)
13229                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13230                         res->vlan_id);
13231 #endif
13232
13233         switch (ret) {
13234         case 0:
13235                 break;
13236         case -EINVAL:
13237                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13238                 break;
13239         case -ENODEV:
13240                 printf("invalid port_id %d\n", res->port_id);
13241                 break;
13242         case -ENOTSUP:
13243                 printf("function not implemented\n");
13244                 break;
13245         default:
13246                 printf("programming error: (%s)\n", strerror(-ret));
13247         }
13248 }
13249
13250 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13251         .f = cmd_set_vf_vlan_insert_parsed,
13252         .data = NULL,
13253         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13254         .tokens = {
13255                 (void *)&cmd_vf_vlan_insert_set,
13256                 (void *)&cmd_vf_vlan_insert_vf,
13257                 (void *)&cmd_vf_vlan_insert_vlan,
13258                 (void *)&cmd_vf_vlan_insert_insert,
13259                 (void *)&cmd_vf_vlan_insert_port_id,
13260                 (void *)&cmd_vf_vlan_insert_vf_id,
13261                 (void *)&cmd_vf_vlan_insert_vlan_id,
13262                 NULL,
13263         },
13264 };
13265
13266 /* tx loopback configuration */
13267
13268 /* Common result structure for tx loopback */
13269 struct cmd_tx_loopback_result {
13270         cmdline_fixed_string_t set;
13271         cmdline_fixed_string_t tx;
13272         cmdline_fixed_string_t loopback;
13273         portid_t port_id;
13274         cmdline_fixed_string_t on_off;
13275 };
13276
13277 /* Common CLI fields for tx loopback enable disable */
13278 cmdline_parse_token_string_t cmd_tx_loopback_set =
13279         TOKEN_STRING_INITIALIZER
13280                 (struct cmd_tx_loopback_result,
13281                  set, "set");
13282 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13283         TOKEN_STRING_INITIALIZER
13284                 (struct cmd_tx_loopback_result,
13285                  tx, "tx");
13286 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13287         TOKEN_STRING_INITIALIZER
13288                 (struct cmd_tx_loopback_result,
13289                  loopback, "loopback");
13290 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13291         TOKEN_NUM_INITIALIZER
13292                 (struct cmd_tx_loopback_result,
13293                  port_id, UINT16);
13294 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13295         TOKEN_STRING_INITIALIZER
13296                 (struct cmd_tx_loopback_result,
13297                  on_off, "on#off");
13298
13299 static void
13300 cmd_set_tx_loopback_parsed(
13301         void *parsed_result,
13302         __attribute__((unused)) struct cmdline *cl,
13303         __attribute__((unused)) void *data)
13304 {
13305         struct cmd_tx_loopback_result *res = parsed_result;
13306         int ret = -ENOTSUP;
13307
13308         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13309
13310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13311                 return;
13312
13313 #ifdef RTE_LIBRTE_IXGBE_PMD
13314         if (ret == -ENOTSUP)
13315                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13316 #endif
13317 #ifdef RTE_LIBRTE_I40E_PMD
13318         if (ret == -ENOTSUP)
13319                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13320 #endif
13321 #ifdef RTE_LIBRTE_BNXT_PMD
13322         if (ret == -ENOTSUP)
13323                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13324 #endif
13325 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13326         if (ret == -ENOTSUP)
13327                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13328 #endif
13329
13330         switch (ret) {
13331         case 0:
13332                 break;
13333         case -EINVAL:
13334                 printf("invalid is_on %d\n", is_on);
13335                 break;
13336         case -ENODEV:
13337                 printf("invalid port_id %d\n", res->port_id);
13338                 break;
13339         case -ENOTSUP:
13340                 printf("function not implemented\n");
13341                 break;
13342         default:
13343                 printf("programming error: (%s)\n", strerror(-ret));
13344         }
13345 }
13346
13347 cmdline_parse_inst_t cmd_set_tx_loopback = {
13348         .f = cmd_set_tx_loopback_parsed,
13349         .data = NULL,
13350         .help_str = "set tx loopback <port_id> on|off",
13351         .tokens = {
13352                 (void *)&cmd_tx_loopback_set,
13353                 (void *)&cmd_tx_loopback_tx,
13354                 (void *)&cmd_tx_loopback_loopback,
13355                 (void *)&cmd_tx_loopback_port_id,
13356                 (void *)&cmd_tx_loopback_on_off,
13357                 NULL,
13358         },
13359 };
13360
13361 /* all queues drop enable configuration */
13362
13363 /* Common result structure for all queues drop enable */
13364 struct cmd_all_queues_drop_en_result {
13365         cmdline_fixed_string_t set;
13366         cmdline_fixed_string_t all;
13367         cmdline_fixed_string_t queues;
13368         cmdline_fixed_string_t drop;
13369         portid_t port_id;
13370         cmdline_fixed_string_t on_off;
13371 };
13372
13373 /* Common CLI fields for tx loopback enable disable */
13374 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13375         TOKEN_STRING_INITIALIZER
13376                 (struct cmd_all_queues_drop_en_result,
13377                  set, "set");
13378 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13379         TOKEN_STRING_INITIALIZER
13380                 (struct cmd_all_queues_drop_en_result,
13381                  all, "all");
13382 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13383         TOKEN_STRING_INITIALIZER
13384                 (struct cmd_all_queues_drop_en_result,
13385                  queues, "queues");
13386 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13387         TOKEN_STRING_INITIALIZER
13388                 (struct cmd_all_queues_drop_en_result,
13389                  drop, "drop");
13390 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13391         TOKEN_NUM_INITIALIZER
13392                 (struct cmd_all_queues_drop_en_result,
13393                  port_id, UINT16);
13394 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13395         TOKEN_STRING_INITIALIZER
13396                 (struct cmd_all_queues_drop_en_result,
13397                  on_off, "on#off");
13398
13399 static void
13400 cmd_set_all_queues_drop_en_parsed(
13401         void *parsed_result,
13402         __attribute__((unused)) struct cmdline *cl,
13403         __attribute__((unused)) void *data)
13404 {
13405         struct cmd_all_queues_drop_en_result *res = parsed_result;
13406         int ret = -ENOTSUP;
13407         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13408
13409         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13410                 return;
13411
13412 #ifdef RTE_LIBRTE_IXGBE_PMD
13413         if (ret == -ENOTSUP)
13414                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13415 #endif
13416 #ifdef RTE_LIBRTE_BNXT_PMD
13417         if (ret == -ENOTSUP)
13418                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13419 #endif
13420         switch (ret) {
13421         case 0:
13422                 break;
13423         case -EINVAL:
13424                 printf("invalid is_on %d\n", is_on);
13425                 break;
13426         case -ENODEV:
13427                 printf("invalid port_id %d\n", res->port_id);
13428                 break;
13429         case -ENOTSUP:
13430                 printf("function not implemented\n");
13431                 break;
13432         default:
13433                 printf("programming error: (%s)\n", strerror(-ret));
13434         }
13435 }
13436
13437 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13438         .f = cmd_set_all_queues_drop_en_parsed,
13439         .data = NULL,
13440         .help_str = "set all queues drop <port_id> on|off",
13441         .tokens = {
13442                 (void *)&cmd_all_queues_drop_en_set,
13443                 (void *)&cmd_all_queues_drop_en_all,
13444                 (void *)&cmd_all_queues_drop_en_queues,
13445                 (void *)&cmd_all_queues_drop_en_drop,
13446                 (void *)&cmd_all_queues_drop_en_port_id,
13447                 (void *)&cmd_all_queues_drop_en_on_off,
13448                 NULL,
13449         },
13450 };
13451
13452 /* vf split drop enable configuration */
13453
13454 /* Common result structure for vf split drop enable */
13455 struct cmd_vf_split_drop_en_result {
13456         cmdline_fixed_string_t set;
13457         cmdline_fixed_string_t vf;
13458         cmdline_fixed_string_t split;
13459         cmdline_fixed_string_t drop;
13460         portid_t port_id;
13461         uint16_t vf_id;
13462         cmdline_fixed_string_t on_off;
13463 };
13464
13465 /* Common CLI fields for vf split drop enable disable */
13466 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13467         TOKEN_STRING_INITIALIZER
13468                 (struct cmd_vf_split_drop_en_result,
13469                  set, "set");
13470 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13471         TOKEN_STRING_INITIALIZER
13472                 (struct cmd_vf_split_drop_en_result,
13473                  vf, "vf");
13474 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13475         TOKEN_STRING_INITIALIZER
13476                 (struct cmd_vf_split_drop_en_result,
13477                  split, "split");
13478 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13479         TOKEN_STRING_INITIALIZER
13480                 (struct cmd_vf_split_drop_en_result,
13481                  drop, "drop");
13482 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13483         TOKEN_NUM_INITIALIZER
13484                 (struct cmd_vf_split_drop_en_result,
13485                  port_id, UINT16);
13486 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13487         TOKEN_NUM_INITIALIZER
13488                 (struct cmd_vf_split_drop_en_result,
13489                  vf_id, UINT16);
13490 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13491         TOKEN_STRING_INITIALIZER
13492                 (struct cmd_vf_split_drop_en_result,
13493                  on_off, "on#off");
13494
13495 static void
13496 cmd_set_vf_split_drop_en_parsed(
13497         void *parsed_result,
13498         __attribute__((unused)) struct cmdline *cl,
13499         __attribute__((unused)) void *data)
13500 {
13501         struct cmd_vf_split_drop_en_result *res = parsed_result;
13502         int ret = -ENOTSUP;
13503         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13504
13505         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13506                 return;
13507
13508 #ifdef RTE_LIBRTE_IXGBE_PMD
13509         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13510                         is_on);
13511 #endif
13512         switch (ret) {
13513         case 0:
13514                 break;
13515         case -EINVAL:
13516                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13517                 break;
13518         case -ENODEV:
13519                 printf("invalid port_id %d\n", res->port_id);
13520                 break;
13521         case -ENOTSUP:
13522                 printf("not supported on port %d\n", res->port_id);
13523                 break;
13524         default:
13525                 printf("programming error: (%s)\n", strerror(-ret));
13526         }
13527 }
13528
13529 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13530         .f = cmd_set_vf_split_drop_en_parsed,
13531         .data = NULL,
13532         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13533         .tokens = {
13534                 (void *)&cmd_vf_split_drop_en_set,
13535                 (void *)&cmd_vf_split_drop_en_vf,
13536                 (void *)&cmd_vf_split_drop_en_split,
13537                 (void *)&cmd_vf_split_drop_en_drop,
13538                 (void *)&cmd_vf_split_drop_en_port_id,
13539                 (void *)&cmd_vf_split_drop_en_vf_id,
13540                 (void *)&cmd_vf_split_drop_en_on_off,
13541                 NULL,
13542         },
13543 };
13544
13545 /* vf mac address configuration */
13546
13547 /* Common result structure for vf mac address */
13548 struct cmd_set_vf_mac_addr_result {
13549         cmdline_fixed_string_t set;
13550         cmdline_fixed_string_t vf;
13551         cmdline_fixed_string_t mac;
13552         cmdline_fixed_string_t addr;
13553         portid_t port_id;
13554         uint16_t vf_id;
13555         struct ether_addr mac_addr;
13556
13557 };
13558
13559 /* Common CLI fields for vf split drop enable disable */
13560 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13561         TOKEN_STRING_INITIALIZER
13562                 (struct cmd_set_vf_mac_addr_result,
13563                  set, "set");
13564 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13565         TOKEN_STRING_INITIALIZER
13566                 (struct cmd_set_vf_mac_addr_result,
13567                  vf, "vf");
13568 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13569         TOKEN_STRING_INITIALIZER
13570                 (struct cmd_set_vf_mac_addr_result,
13571                  mac, "mac");
13572 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13573         TOKEN_STRING_INITIALIZER
13574                 (struct cmd_set_vf_mac_addr_result,
13575                  addr, "addr");
13576 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13577         TOKEN_NUM_INITIALIZER
13578                 (struct cmd_set_vf_mac_addr_result,
13579                  port_id, UINT16);
13580 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13581         TOKEN_NUM_INITIALIZER
13582                 (struct cmd_set_vf_mac_addr_result,
13583                  vf_id, UINT16);
13584 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13585         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13586                  mac_addr);
13587
13588 static void
13589 cmd_set_vf_mac_addr_parsed(
13590         void *parsed_result,
13591         __attribute__((unused)) struct cmdline *cl,
13592         __attribute__((unused)) void *data)
13593 {
13594         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13595         int ret = -ENOTSUP;
13596
13597         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13598                 return;
13599
13600 #ifdef RTE_LIBRTE_IXGBE_PMD
13601         if (ret == -ENOTSUP)
13602                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13603                                 &res->mac_addr);
13604 #endif
13605 #ifdef RTE_LIBRTE_I40E_PMD
13606         if (ret == -ENOTSUP)
13607                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13608                                 &res->mac_addr);
13609 #endif
13610 #ifdef RTE_LIBRTE_BNXT_PMD
13611         if (ret == -ENOTSUP)
13612                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13613                                 &res->mac_addr);
13614 #endif
13615
13616         switch (ret) {
13617         case 0:
13618                 break;
13619         case -EINVAL:
13620                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13621                 break;
13622         case -ENODEV:
13623                 printf("invalid port_id %d\n", res->port_id);
13624                 break;
13625         case -ENOTSUP:
13626                 printf("function not implemented\n");
13627                 break;
13628         default:
13629                 printf("programming error: (%s)\n", strerror(-ret));
13630         }
13631 }
13632
13633 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13634         .f = cmd_set_vf_mac_addr_parsed,
13635         .data = NULL,
13636         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13637         .tokens = {
13638                 (void *)&cmd_set_vf_mac_addr_set,
13639                 (void *)&cmd_set_vf_mac_addr_vf,
13640                 (void *)&cmd_set_vf_mac_addr_mac,
13641                 (void *)&cmd_set_vf_mac_addr_addr,
13642                 (void *)&cmd_set_vf_mac_addr_port_id,
13643                 (void *)&cmd_set_vf_mac_addr_vf_id,
13644                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13645                 NULL,
13646         },
13647 };
13648
13649 /* MACsec configuration */
13650
13651 /* Common result structure for MACsec offload enable */
13652 struct cmd_macsec_offload_on_result {
13653         cmdline_fixed_string_t set;
13654         cmdline_fixed_string_t macsec;
13655         cmdline_fixed_string_t offload;
13656         portid_t port_id;
13657         cmdline_fixed_string_t on;
13658         cmdline_fixed_string_t encrypt;
13659         cmdline_fixed_string_t en_on_off;
13660         cmdline_fixed_string_t replay_protect;
13661         cmdline_fixed_string_t rp_on_off;
13662 };
13663
13664 /* Common CLI fields for MACsec offload disable */
13665 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13666         TOKEN_STRING_INITIALIZER
13667                 (struct cmd_macsec_offload_on_result,
13668                  set, "set");
13669 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13670         TOKEN_STRING_INITIALIZER
13671                 (struct cmd_macsec_offload_on_result,
13672                  macsec, "macsec");
13673 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13674         TOKEN_STRING_INITIALIZER
13675                 (struct cmd_macsec_offload_on_result,
13676                  offload, "offload");
13677 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13678         TOKEN_NUM_INITIALIZER
13679                 (struct cmd_macsec_offload_on_result,
13680                  port_id, UINT16);
13681 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13682         TOKEN_STRING_INITIALIZER
13683                 (struct cmd_macsec_offload_on_result,
13684                  on, "on");
13685 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13686         TOKEN_STRING_INITIALIZER
13687                 (struct cmd_macsec_offload_on_result,
13688                  encrypt, "encrypt");
13689 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13690         TOKEN_STRING_INITIALIZER
13691                 (struct cmd_macsec_offload_on_result,
13692                  en_on_off, "on#off");
13693 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13694         TOKEN_STRING_INITIALIZER
13695                 (struct cmd_macsec_offload_on_result,
13696                  replay_protect, "replay-protect");
13697 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13698         TOKEN_STRING_INITIALIZER
13699                 (struct cmd_macsec_offload_on_result,
13700                  rp_on_off, "on#off");
13701
13702 static void
13703 cmd_set_macsec_offload_on_parsed(
13704         void *parsed_result,
13705         __attribute__((unused)) struct cmdline *cl,
13706         __attribute__((unused)) void *data)
13707 {
13708         struct cmd_macsec_offload_on_result *res = parsed_result;
13709         int ret = -ENOTSUP;
13710         portid_t port_id = res->port_id;
13711         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13712         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13713         struct rte_eth_dev_info dev_info;
13714
13715         if (port_id_is_invalid(port_id, ENABLED_WARN))
13716                 return;
13717         if (!port_is_stopped(port_id)) {
13718                 printf("Please stop port %d first\n", port_id);
13719                 return;
13720         }
13721
13722         rte_eth_dev_info_get(port_id, &dev_info);
13723         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13724 #ifdef RTE_LIBRTE_IXGBE_PMD
13725                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13726 #endif
13727         }
13728         RTE_SET_USED(en);
13729         RTE_SET_USED(rp);
13730
13731         switch (ret) {
13732         case 0:
13733                 ports[port_id].dev_conf.txmode.offloads |=
13734                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13735                 cmd_reconfig_device_queue(port_id, 1, 1);
13736                 break;
13737         case -ENODEV:
13738                 printf("invalid port_id %d\n", port_id);
13739                 break;
13740         case -ENOTSUP:
13741                 printf("not supported on port %d\n", port_id);
13742                 break;
13743         default:
13744                 printf("programming error: (%s)\n", strerror(-ret));
13745         }
13746 }
13747
13748 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13749         .f = cmd_set_macsec_offload_on_parsed,
13750         .data = NULL,
13751         .help_str = "set macsec offload <port_id> on "
13752                 "encrypt on|off replay-protect on|off",
13753         .tokens = {
13754                 (void *)&cmd_macsec_offload_on_set,
13755                 (void *)&cmd_macsec_offload_on_macsec,
13756                 (void *)&cmd_macsec_offload_on_offload,
13757                 (void *)&cmd_macsec_offload_on_port_id,
13758                 (void *)&cmd_macsec_offload_on_on,
13759                 (void *)&cmd_macsec_offload_on_encrypt,
13760                 (void *)&cmd_macsec_offload_on_en_on_off,
13761                 (void *)&cmd_macsec_offload_on_replay_protect,
13762                 (void *)&cmd_macsec_offload_on_rp_on_off,
13763                 NULL,
13764         },
13765 };
13766
13767 /* Common result structure for MACsec offload disable */
13768 struct cmd_macsec_offload_off_result {
13769         cmdline_fixed_string_t set;
13770         cmdline_fixed_string_t macsec;
13771         cmdline_fixed_string_t offload;
13772         portid_t port_id;
13773         cmdline_fixed_string_t off;
13774 };
13775
13776 /* Common CLI fields for MACsec offload disable */
13777 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13778         TOKEN_STRING_INITIALIZER
13779                 (struct cmd_macsec_offload_off_result,
13780                  set, "set");
13781 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13782         TOKEN_STRING_INITIALIZER
13783                 (struct cmd_macsec_offload_off_result,
13784                  macsec, "macsec");
13785 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13786         TOKEN_STRING_INITIALIZER
13787                 (struct cmd_macsec_offload_off_result,
13788                  offload, "offload");
13789 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13790         TOKEN_NUM_INITIALIZER
13791                 (struct cmd_macsec_offload_off_result,
13792                  port_id, UINT16);
13793 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13794         TOKEN_STRING_INITIALIZER
13795                 (struct cmd_macsec_offload_off_result,
13796                  off, "off");
13797
13798 static void
13799 cmd_set_macsec_offload_off_parsed(
13800         void *parsed_result,
13801         __attribute__((unused)) struct cmdline *cl,
13802         __attribute__((unused)) void *data)
13803 {
13804         struct cmd_macsec_offload_off_result *res = parsed_result;
13805         int ret = -ENOTSUP;
13806         struct rte_eth_dev_info dev_info;
13807         portid_t port_id = res->port_id;
13808
13809         if (port_id_is_invalid(port_id, ENABLED_WARN))
13810                 return;
13811         if (!port_is_stopped(port_id)) {
13812                 printf("Please stop port %d first\n", port_id);
13813                 return;
13814         }
13815
13816         rte_eth_dev_info_get(port_id, &dev_info);
13817         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13818 #ifdef RTE_LIBRTE_IXGBE_PMD
13819                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13820 #endif
13821         }
13822         switch (ret) {
13823         case 0:
13824                 ports[port_id].dev_conf.txmode.offloads &=
13825                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13826                 cmd_reconfig_device_queue(port_id, 1, 1);
13827                 break;
13828         case -ENODEV:
13829                 printf("invalid port_id %d\n", port_id);
13830                 break;
13831         case -ENOTSUP:
13832                 printf("not supported on port %d\n", port_id);
13833                 break;
13834         default:
13835                 printf("programming error: (%s)\n", strerror(-ret));
13836         }
13837 }
13838
13839 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13840         .f = cmd_set_macsec_offload_off_parsed,
13841         .data = NULL,
13842         .help_str = "set macsec offload <port_id> off",
13843         .tokens = {
13844                 (void *)&cmd_macsec_offload_off_set,
13845                 (void *)&cmd_macsec_offload_off_macsec,
13846                 (void *)&cmd_macsec_offload_off_offload,
13847                 (void *)&cmd_macsec_offload_off_port_id,
13848                 (void *)&cmd_macsec_offload_off_off,
13849                 NULL,
13850         },
13851 };
13852
13853 /* Common result structure for MACsec secure connection configure */
13854 struct cmd_macsec_sc_result {
13855         cmdline_fixed_string_t set;
13856         cmdline_fixed_string_t macsec;
13857         cmdline_fixed_string_t sc;
13858         cmdline_fixed_string_t tx_rx;
13859         portid_t port_id;
13860         struct ether_addr mac;
13861         uint16_t pi;
13862 };
13863
13864 /* Common CLI fields for MACsec secure connection configure */
13865 cmdline_parse_token_string_t cmd_macsec_sc_set =
13866         TOKEN_STRING_INITIALIZER
13867                 (struct cmd_macsec_sc_result,
13868                  set, "set");
13869 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13870         TOKEN_STRING_INITIALIZER
13871                 (struct cmd_macsec_sc_result,
13872                  macsec, "macsec");
13873 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13874         TOKEN_STRING_INITIALIZER
13875                 (struct cmd_macsec_sc_result,
13876                  sc, "sc");
13877 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13878         TOKEN_STRING_INITIALIZER
13879                 (struct cmd_macsec_sc_result,
13880                  tx_rx, "tx#rx");
13881 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13882         TOKEN_NUM_INITIALIZER
13883                 (struct cmd_macsec_sc_result,
13884                  port_id, UINT16);
13885 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13886         TOKEN_ETHERADDR_INITIALIZER
13887                 (struct cmd_macsec_sc_result,
13888                  mac);
13889 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13890         TOKEN_NUM_INITIALIZER
13891                 (struct cmd_macsec_sc_result,
13892                  pi, UINT16);
13893
13894 static void
13895 cmd_set_macsec_sc_parsed(
13896         void *parsed_result,
13897         __attribute__((unused)) struct cmdline *cl,
13898         __attribute__((unused)) void *data)
13899 {
13900         struct cmd_macsec_sc_result *res = parsed_result;
13901         int ret = -ENOTSUP;
13902         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13903
13904 #ifdef RTE_LIBRTE_IXGBE_PMD
13905         ret = is_tx ?
13906                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13907                                 res->mac.addr_bytes) :
13908                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13909                                 res->mac.addr_bytes, res->pi);
13910 #endif
13911         RTE_SET_USED(is_tx);
13912
13913         switch (ret) {
13914         case 0:
13915                 break;
13916         case -ENODEV:
13917                 printf("invalid port_id %d\n", res->port_id);
13918                 break;
13919         case -ENOTSUP:
13920                 printf("not supported on port %d\n", res->port_id);
13921                 break;
13922         default:
13923                 printf("programming error: (%s)\n", strerror(-ret));
13924         }
13925 }
13926
13927 cmdline_parse_inst_t cmd_set_macsec_sc = {
13928         .f = cmd_set_macsec_sc_parsed,
13929         .data = NULL,
13930         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13931         .tokens = {
13932                 (void *)&cmd_macsec_sc_set,
13933                 (void *)&cmd_macsec_sc_macsec,
13934                 (void *)&cmd_macsec_sc_sc,
13935                 (void *)&cmd_macsec_sc_tx_rx,
13936                 (void *)&cmd_macsec_sc_port_id,
13937                 (void *)&cmd_macsec_sc_mac,
13938                 (void *)&cmd_macsec_sc_pi,
13939                 NULL,
13940         },
13941 };
13942
13943 /* Common result structure for MACsec secure connection configure */
13944 struct cmd_macsec_sa_result {
13945         cmdline_fixed_string_t set;
13946         cmdline_fixed_string_t macsec;
13947         cmdline_fixed_string_t sa;
13948         cmdline_fixed_string_t tx_rx;
13949         portid_t port_id;
13950         uint8_t idx;
13951         uint8_t an;
13952         uint32_t pn;
13953         cmdline_fixed_string_t key;
13954 };
13955
13956 /* Common CLI fields for MACsec secure connection configure */
13957 cmdline_parse_token_string_t cmd_macsec_sa_set =
13958         TOKEN_STRING_INITIALIZER
13959                 (struct cmd_macsec_sa_result,
13960                  set, "set");
13961 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13962         TOKEN_STRING_INITIALIZER
13963                 (struct cmd_macsec_sa_result,
13964                  macsec, "macsec");
13965 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13966         TOKEN_STRING_INITIALIZER
13967                 (struct cmd_macsec_sa_result,
13968                  sa, "sa");
13969 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13970         TOKEN_STRING_INITIALIZER
13971                 (struct cmd_macsec_sa_result,
13972                  tx_rx, "tx#rx");
13973 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13974         TOKEN_NUM_INITIALIZER
13975                 (struct cmd_macsec_sa_result,
13976                  port_id, UINT16);
13977 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13978         TOKEN_NUM_INITIALIZER
13979                 (struct cmd_macsec_sa_result,
13980                  idx, UINT8);
13981 cmdline_parse_token_num_t cmd_macsec_sa_an =
13982         TOKEN_NUM_INITIALIZER
13983                 (struct cmd_macsec_sa_result,
13984                  an, UINT8);
13985 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13986         TOKEN_NUM_INITIALIZER
13987                 (struct cmd_macsec_sa_result,
13988                  pn, UINT32);
13989 cmdline_parse_token_string_t cmd_macsec_sa_key =
13990         TOKEN_STRING_INITIALIZER
13991                 (struct cmd_macsec_sa_result,
13992                  key, NULL);
13993
13994 static void
13995 cmd_set_macsec_sa_parsed(
13996         void *parsed_result,
13997         __attribute__((unused)) struct cmdline *cl,
13998         __attribute__((unused)) void *data)
13999 {
14000         struct cmd_macsec_sa_result *res = parsed_result;
14001         int ret = -ENOTSUP;
14002         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14003         uint8_t key[16] = { 0 };
14004         uint8_t xdgt0;
14005         uint8_t xdgt1;
14006         int key_len;
14007         int i;
14008
14009         key_len = strlen(res->key) / 2;
14010         if (key_len > 16)
14011                 key_len = 16;
14012
14013         for (i = 0; i < key_len; i++) {
14014                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14015                 if (xdgt0 == 0xFF)
14016                         return;
14017                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14018                 if (xdgt1 == 0xFF)
14019                         return;
14020                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14021         }
14022
14023 #ifdef RTE_LIBRTE_IXGBE_PMD
14024         ret = is_tx ?
14025                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14026                         res->idx, res->an, res->pn, key) :
14027                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14028                         res->idx, res->an, res->pn, key);
14029 #endif
14030         RTE_SET_USED(is_tx);
14031         RTE_SET_USED(key);
14032
14033         switch (ret) {
14034         case 0:
14035                 break;
14036         case -EINVAL:
14037                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14038                 break;
14039         case -ENODEV:
14040                 printf("invalid port_id %d\n", res->port_id);
14041                 break;
14042         case -ENOTSUP:
14043                 printf("not supported on port %d\n", res->port_id);
14044                 break;
14045         default:
14046                 printf("programming error: (%s)\n", strerror(-ret));
14047         }
14048 }
14049
14050 cmdline_parse_inst_t cmd_set_macsec_sa = {
14051         .f = cmd_set_macsec_sa_parsed,
14052         .data = NULL,
14053         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14054         .tokens = {
14055                 (void *)&cmd_macsec_sa_set,
14056                 (void *)&cmd_macsec_sa_macsec,
14057                 (void *)&cmd_macsec_sa_sa,
14058                 (void *)&cmd_macsec_sa_tx_rx,
14059                 (void *)&cmd_macsec_sa_port_id,
14060                 (void *)&cmd_macsec_sa_idx,
14061                 (void *)&cmd_macsec_sa_an,
14062                 (void *)&cmd_macsec_sa_pn,
14063                 (void *)&cmd_macsec_sa_key,
14064                 NULL,
14065         },
14066 };
14067
14068 /* VF unicast promiscuous mode configuration */
14069
14070 /* Common result structure for VF unicast promiscuous mode */
14071 struct cmd_vf_promisc_result {
14072         cmdline_fixed_string_t set;
14073         cmdline_fixed_string_t vf;
14074         cmdline_fixed_string_t promisc;
14075         portid_t port_id;
14076         uint32_t vf_id;
14077         cmdline_fixed_string_t on_off;
14078 };
14079
14080 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14081 cmdline_parse_token_string_t cmd_vf_promisc_set =
14082         TOKEN_STRING_INITIALIZER
14083                 (struct cmd_vf_promisc_result,
14084                  set, "set");
14085 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14086         TOKEN_STRING_INITIALIZER
14087                 (struct cmd_vf_promisc_result,
14088                  vf, "vf");
14089 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14090         TOKEN_STRING_INITIALIZER
14091                 (struct cmd_vf_promisc_result,
14092                  promisc, "promisc");
14093 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14094         TOKEN_NUM_INITIALIZER
14095                 (struct cmd_vf_promisc_result,
14096                  port_id, UINT16);
14097 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14098         TOKEN_NUM_INITIALIZER
14099                 (struct cmd_vf_promisc_result,
14100                  vf_id, UINT32);
14101 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14102         TOKEN_STRING_INITIALIZER
14103                 (struct cmd_vf_promisc_result,
14104                  on_off, "on#off");
14105
14106 static void
14107 cmd_set_vf_promisc_parsed(
14108         void *parsed_result,
14109         __attribute__((unused)) struct cmdline *cl,
14110         __attribute__((unused)) void *data)
14111 {
14112         struct cmd_vf_promisc_result *res = parsed_result;
14113         int ret = -ENOTSUP;
14114
14115         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14116
14117         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14118                 return;
14119
14120 #ifdef RTE_LIBRTE_I40E_PMD
14121         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14122                                                   res->vf_id, is_on);
14123 #endif
14124
14125         switch (ret) {
14126         case 0:
14127                 break;
14128         case -EINVAL:
14129                 printf("invalid vf_id %d\n", res->vf_id);
14130                 break;
14131         case -ENODEV:
14132                 printf("invalid port_id %d\n", res->port_id);
14133                 break;
14134         case -ENOTSUP:
14135                 printf("function not implemented\n");
14136                 break;
14137         default:
14138                 printf("programming error: (%s)\n", strerror(-ret));
14139         }
14140 }
14141
14142 cmdline_parse_inst_t cmd_set_vf_promisc = {
14143         .f = cmd_set_vf_promisc_parsed,
14144         .data = NULL,
14145         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14146                 "Set unicast promiscuous mode for a VF from the PF",
14147         .tokens = {
14148                 (void *)&cmd_vf_promisc_set,
14149                 (void *)&cmd_vf_promisc_vf,
14150                 (void *)&cmd_vf_promisc_promisc,
14151                 (void *)&cmd_vf_promisc_port_id,
14152                 (void *)&cmd_vf_promisc_vf_id,
14153                 (void *)&cmd_vf_promisc_on_off,
14154                 NULL,
14155         },
14156 };
14157
14158 /* VF multicast promiscuous mode configuration */
14159
14160 /* Common result structure for VF multicast promiscuous mode */
14161 struct cmd_vf_allmulti_result {
14162         cmdline_fixed_string_t set;
14163         cmdline_fixed_string_t vf;
14164         cmdline_fixed_string_t allmulti;
14165         portid_t port_id;
14166         uint32_t vf_id;
14167         cmdline_fixed_string_t on_off;
14168 };
14169
14170 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14171 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14172         TOKEN_STRING_INITIALIZER
14173                 (struct cmd_vf_allmulti_result,
14174                  set, "set");
14175 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14176         TOKEN_STRING_INITIALIZER
14177                 (struct cmd_vf_allmulti_result,
14178                  vf, "vf");
14179 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14180         TOKEN_STRING_INITIALIZER
14181                 (struct cmd_vf_allmulti_result,
14182                  allmulti, "allmulti");
14183 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14184         TOKEN_NUM_INITIALIZER
14185                 (struct cmd_vf_allmulti_result,
14186                  port_id, UINT16);
14187 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14188         TOKEN_NUM_INITIALIZER
14189                 (struct cmd_vf_allmulti_result,
14190                  vf_id, UINT32);
14191 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14192         TOKEN_STRING_INITIALIZER
14193                 (struct cmd_vf_allmulti_result,
14194                  on_off, "on#off");
14195
14196 static void
14197 cmd_set_vf_allmulti_parsed(
14198         void *parsed_result,
14199         __attribute__((unused)) struct cmdline *cl,
14200         __attribute__((unused)) void *data)
14201 {
14202         struct cmd_vf_allmulti_result *res = parsed_result;
14203         int ret = -ENOTSUP;
14204
14205         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14206
14207         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14208                 return;
14209
14210 #ifdef RTE_LIBRTE_I40E_PMD
14211         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14212                                                     res->vf_id, is_on);
14213 #endif
14214
14215         switch (ret) {
14216         case 0:
14217                 break;
14218         case -EINVAL:
14219                 printf("invalid vf_id %d\n", res->vf_id);
14220                 break;
14221         case -ENODEV:
14222                 printf("invalid port_id %d\n", res->port_id);
14223                 break;
14224         case -ENOTSUP:
14225                 printf("function not implemented\n");
14226                 break;
14227         default:
14228                 printf("programming error: (%s)\n", strerror(-ret));
14229         }
14230 }
14231
14232 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14233         .f = cmd_set_vf_allmulti_parsed,
14234         .data = NULL,
14235         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14236                 "Set multicast promiscuous mode for a VF from the PF",
14237         .tokens = {
14238                 (void *)&cmd_vf_allmulti_set,
14239                 (void *)&cmd_vf_allmulti_vf,
14240                 (void *)&cmd_vf_allmulti_allmulti,
14241                 (void *)&cmd_vf_allmulti_port_id,
14242                 (void *)&cmd_vf_allmulti_vf_id,
14243                 (void *)&cmd_vf_allmulti_on_off,
14244                 NULL,
14245         },
14246 };
14247
14248 /* vf broadcast mode configuration */
14249
14250 /* Common result structure for vf broadcast */
14251 struct cmd_set_vf_broadcast_result {
14252         cmdline_fixed_string_t set;
14253         cmdline_fixed_string_t vf;
14254         cmdline_fixed_string_t broadcast;
14255         portid_t port_id;
14256         uint16_t vf_id;
14257         cmdline_fixed_string_t on_off;
14258 };
14259
14260 /* Common CLI fields for vf broadcast enable disable */
14261 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14262         TOKEN_STRING_INITIALIZER
14263                 (struct cmd_set_vf_broadcast_result,
14264                  set, "set");
14265 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14266         TOKEN_STRING_INITIALIZER
14267                 (struct cmd_set_vf_broadcast_result,
14268                  vf, "vf");
14269 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14270         TOKEN_STRING_INITIALIZER
14271                 (struct cmd_set_vf_broadcast_result,
14272                  broadcast, "broadcast");
14273 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14274         TOKEN_NUM_INITIALIZER
14275                 (struct cmd_set_vf_broadcast_result,
14276                  port_id, UINT16);
14277 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14278         TOKEN_NUM_INITIALIZER
14279                 (struct cmd_set_vf_broadcast_result,
14280                  vf_id, UINT16);
14281 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14282         TOKEN_STRING_INITIALIZER
14283                 (struct cmd_set_vf_broadcast_result,
14284                  on_off, "on#off");
14285
14286 static void
14287 cmd_set_vf_broadcast_parsed(
14288         void *parsed_result,
14289         __attribute__((unused)) struct cmdline *cl,
14290         __attribute__((unused)) void *data)
14291 {
14292         struct cmd_set_vf_broadcast_result *res = parsed_result;
14293         int ret = -ENOTSUP;
14294
14295         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14296
14297         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14298                 return;
14299
14300 #ifdef RTE_LIBRTE_I40E_PMD
14301         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14302                                             res->vf_id, is_on);
14303 #endif
14304
14305         switch (ret) {
14306         case 0:
14307                 break;
14308         case -EINVAL:
14309                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14310                 break;
14311         case -ENODEV:
14312                 printf("invalid port_id %d\n", res->port_id);
14313                 break;
14314         case -ENOTSUP:
14315                 printf("function not implemented\n");
14316                 break;
14317         default:
14318                 printf("programming error: (%s)\n", strerror(-ret));
14319         }
14320 }
14321
14322 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14323         .f = cmd_set_vf_broadcast_parsed,
14324         .data = NULL,
14325         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14326         .tokens = {
14327                 (void *)&cmd_set_vf_broadcast_set,
14328                 (void *)&cmd_set_vf_broadcast_vf,
14329                 (void *)&cmd_set_vf_broadcast_broadcast,
14330                 (void *)&cmd_set_vf_broadcast_port_id,
14331                 (void *)&cmd_set_vf_broadcast_vf_id,
14332                 (void *)&cmd_set_vf_broadcast_on_off,
14333                 NULL,
14334         },
14335 };
14336
14337 /* vf vlan tag configuration */
14338
14339 /* Common result structure for vf vlan tag */
14340 struct cmd_set_vf_vlan_tag_result {
14341         cmdline_fixed_string_t set;
14342         cmdline_fixed_string_t vf;
14343         cmdline_fixed_string_t vlan;
14344         cmdline_fixed_string_t tag;
14345         portid_t port_id;
14346         uint16_t vf_id;
14347         cmdline_fixed_string_t on_off;
14348 };
14349
14350 /* Common CLI fields for vf vlan tag enable disable */
14351 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14352         TOKEN_STRING_INITIALIZER
14353                 (struct cmd_set_vf_vlan_tag_result,
14354                  set, "set");
14355 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14356         TOKEN_STRING_INITIALIZER
14357                 (struct cmd_set_vf_vlan_tag_result,
14358                  vf, "vf");
14359 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14360         TOKEN_STRING_INITIALIZER
14361                 (struct cmd_set_vf_vlan_tag_result,
14362                  vlan, "vlan");
14363 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14364         TOKEN_STRING_INITIALIZER
14365                 (struct cmd_set_vf_vlan_tag_result,
14366                  tag, "tag");
14367 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14368         TOKEN_NUM_INITIALIZER
14369                 (struct cmd_set_vf_vlan_tag_result,
14370                  port_id, UINT16);
14371 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14372         TOKEN_NUM_INITIALIZER
14373                 (struct cmd_set_vf_vlan_tag_result,
14374                  vf_id, UINT16);
14375 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14376         TOKEN_STRING_INITIALIZER
14377                 (struct cmd_set_vf_vlan_tag_result,
14378                  on_off, "on#off");
14379
14380 static void
14381 cmd_set_vf_vlan_tag_parsed(
14382         void *parsed_result,
14383         __attribute__((unused)) struct cmdline *cl,
14384         __attribute__((unused)) void *data)
14385 {
14386         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14387         int ret = -ENOTSUP;
14388
14389         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14390
14391         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14392                 return;
14393
14394 #ifdef RTE_LIBRTE_I40E_PMD
14395         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14396                                            res->vf_id, is_on);
14397 #endif
14398
14399         switch (ret) {
14400         case 0:
14401                 break;
14402         case -EINVAL:
14403                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14404                 break;
14405         case -ENODEV:
14406                 printf("invalid port_id %d\n", res->port_id);
14407                 break;
14408         case -ENOTSUP:
14409                 printf("function not implemented\n");
14410                 break;
14411         default:
14412                 printf("programming error: (%s)\n", strerror(-ret));
14413         }
14414 }
14415
14416 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14417         .f = cmd_set_vf_vlan_tag_parsed,
14418         .data = NULL,
14419         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14420         .tokens = {
14421                 (void *)&cmd_set_vf_vlan_tag_set,
14422                 (void *)&cmd_set_vf_vlan_tag_vf,
14423                 (void *)&cmd_set_vf_vlan_tag_vlan,
14424                 (void *)&cmd_set_vf_vlan_tag_tag,
14425                 (void *)&cmd_set_vf_vlan_tag_port_id,
14426                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14427                 (void *)&cmd_set_vf_vlan_tag_on_off,
14428                 NULL,
14429         },
14430 };
14431
14432 /* Common definition of VF and TC TX bandwidth configuration */
14433 struct cmd_vf_tc_bw_result {
14434         cmdline_fixed_string_t set;
14435         cmdline_fixed_string_t vf;
14436         cmdline_fixed_string_t tc;
14437         cmdline_fixed_string_t tx;
14438         cmdline_fixed_string_t min_bw;
14439         cmdline_fixed_string_t max_bw;
14440         cmdline_fixed_string_t strict_link_prio;
14441         portid_t port_id;
14442         uint16_t vf_id;
14443         uint8_t tc_no;
14444         uint32_t bw;
14445         cmdline_fixed_string_t bw_list;
14446         uint8_t tc_map;
14447 };
14448
14449 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14450         TOKEN_STRING_INITIALIZER
14451                 (struct cmd_vf_tc_bw_result,
14452                  set, "set");
14453 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14454         TOKEN_STRING_INITIALIZER
14455                 (struct cmd_vf_tc_bw_result,
14456                  vf, "vf");
14457 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14458         TOKEN_STRING_INITIALIZER
14459                 (struct cmd_vf_tc_bw_result,
14460                  tc, "tc");
14461 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14462         TOKEN_STRING_INITIALIZER
14463                 (struct cmd_vf_tc_bw_result,
14464                  tx, "tx");
14465 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14466         TOKEN_STRING_INITIALIZER
14467                 (struct cmd_vf_tc_bw_result,
14468                  strict_link_prio, "strict-link-priority");
14469 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14470         TOKEN_STRING_INITIALIZER
14471                 (struct cmd_vf_tc_bw_result,
14472                  min_bw, "min-bandwidth");
14473 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14474         TOKEN_STRING_INITIALIZER
14475                 (struct cmd_vf_tc_bw_result,
14476                  max_bw, "max-bandwidth");
14477 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14478         TOKEN_NUM_INITIALIZER
14479                 (struct cmd_vf_tc_bw_result,
14480                  port_id, UINT16);
14481 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14482         TOKEN_NUM_INITIALIZER
14483                 (struct cmd_vf_tc_bw_result,
14484                  vf_id, UINT16);
14485 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14486         TOKEN_NUM_INITIALIZER
14487                 (struct cmd_vf_tc_bw_result,
14488                  tc_no, UINT8);
14489 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14490         TOKEN_NUM_INITIALIZER
14491                 (struct cmd_vf_tc_bw_result,
14492                  bw, UINT32);
14493 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14494         TOKEN_STRING_INITIALIZER
14495                 (struct cmd_vf_tc_bw_result,
14496                  bw_list, NULL);
14497 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14498         TOKEN_NUM_INITIALIZER
14499                 (struct cmd_vf_tc_bw_result,
14500                  tc_map, UINT8);
14501
14502 /* VF max bandwidth setting */
14503 static void
14504 cmd_vf_max_bw_parsed(
14505         void *parsed_result,
14506         __attribute__((unused)) struct cmdline *cl,
14507         __attribute__((unused)) void *data)
14508 {
14509         struct cmd_vf_tc_bw_result *res = parsed_result;
14510         int ret = -ENOTSUP;
14511
14512         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14513                 return;
14514
14515 #ifdef RTE_LIBRTE_I40E_PMD
14516         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14517                                          res->vf_id, res->bw);
14518 #endif
14519
14520         switch (ret) {
14521         case 0:
14522                 break;
14523         case -EINVAL:
14524                 printf("invalid vf_id %d or bandwidth %d\n",
14525                        res->vf_id, res->bw);
14526                 break;
14527         case -ENODEV:
14528                 printf("invalid port_id %d\n", res->port_id);
14529                 break;
14530         case -ENOTSUP:
14531                 printf("function not implemented\n");
14532                 break;
14533         default:
14534                 printf("programming error: (%s)\n", strerror(-ret));
14535         }
14536 }
14537
14538 cmdline_parse_inst_t cmd_vf_max_bw = {
14539         .f = cmd_vf_max_bw_parsed,
14540         .data = NULL,
14541         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14542         .tokens = {
14543                 (void *)&cmd_vf_tc_bw_set,
14544                 (void *)&cmd_vf_tc_bw_vf,
14545                 (void *)&cmd_vf_tc_bw_tx,
14546                 (void *)&cmd_vf_tc_bw_max_bw,
14547                 (void *)&cmd_vf_tc_bw_port_id,
14548                 (void *)&cmd_vf_tc_bw_vf_id,
14549                 (void *)&cmd_vf_tc_bw_bw,
14550                 NULL,
14551         },
14552 };
14553
14554 static int
14555 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14556                            uint8_t *tc_num,
14557                            char *str)
14558 {
14559         uint32_t size;
14560         const char *p, *p0 = str;
14561         char s[256];
14562         char *end;
14563         char *str_fld[16];
14564         uint16_t i;
14565         int ret;
14566
14567         p = strchr(p0, '(');
14568         if (p == NULL) {
14569                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14570                 return -1;
14571         }
14572         p++;
14573         p0 = strchr(p, ')');
14574         if (p0 == NULL) {
14575                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14576                 return -1;
14577         }
14578         size = p0 - p;
14579         if (size >= sizeof(s)) {
14580                 printf("The string size exceeds the internal buffer size\n");
14581                 return -1;
14582         }
14583         snprintf(s, sizeof(s), "%.*s", size, p);
14584         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14585         if (ret <= 0) {
14586                 printf("Failed to get the bandwidth list. ");
14587                 return -1;
14588         }
14589         *tc_num = ret;
14590         for (i = 0; i < ret; i++)
14591                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14592
14593         return 0;
14594 }
14595
14596 /* TC min bandwidth setting */
14597 static void
14598 cmd_vf_tc_min_bw_parsed(
14599         void *parsed_result,
14600         __attribute__((unused)) struct cmdline *cl,
14601         __attribute__((unused)) void *data)
14602 {
14603         struct cmd_vf_tc_bw_result *res = parsed_result;
14604         uint8_t tc_num;
14605         uint8_t bw[16];
14606         int ret = -ENOTSUP;
14607
14608         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14609                 return;
14610
14611         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14612         if (ret)
14613                 return;
14614
14615 #ifdef RTE_LIBRTE_I40E_PMD
14616         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14617                                               tc_num, bw);
14618 #endif
14619
14620         switch (ret) {
14621         case 0:
14622                 break;
14623         case -EINVAL:
14624                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14625                 break;
14626         case -ENODEV:
14627                 printf("invalid port_id %d\n", res->port_id);
14628                 break;
14629         case -ENOTSUP:
14630                 printf("function not implemented\n");
14631                 break;
14632         default:
14633                 printf("programming error: (%s)\n", strerror(-ret));
14634         }
14635 }
14636
14637 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14638         .f = cmd_vf_tc_min_bw_parsed,
14639         .data = NULL,
14640         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14641                     " <bw1, bw2, ...>",
14642         .tokens = {
14643                 (void *)&cmd_vf_tc_bw_set,
14644                 (void *)&cmd_vf_tc_bw_vf,
14645                 (void *)&cmd_vf_tc_bw_tc,
14646                 (void *)&cmd_vf_tc_bw_tx,
14647                 (void *)&cmd_vf_tc_bw_min_bw,
14648                 (void *)&cmd_vf_tc_bw_port_id,
14649                 (void *)&cmd_vf_tc_bw_vf_id,
14650                 (void *)&cmd_vf_tc_bw_bw_list,
14651                 NULL,
14652         },
14653 };
14654
14655 static void
14656 cmd_tc_min_bw_parsed(
14657         void *parsed_result,
14658         __attribute__((unused)) struct cmdline *cl,
14659         __attribute__((unused)) void *data)
14660 {
14661         struct cmd_vf_tc_bw_result *res = parsed_result;
14662         struct rte_port *port;
14663         uint8_t tc_num;
14664         uint8_t bw[16];
14665         int ret = -ENOTSUP;
14666
14667         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14668                 return;
14669
14670         port = &ports[res->port_id];
14671         /** Check if the port is not started **/
14672         if (port->port_status != RTE_PORT_STOPPED) {
14673                 printf("Please stop port %d first\n", res->port_id);
14674                 return;
14675         }
14676
14677         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14678         if (ret)
14679                 return;
14680
14681 #ifdef RTE_LIBRTE_IXGBE_PMD
14682         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14683 #endif
14684
14685         switch (ret) {
14686         case 0:
14687                 break;
14688         case -EINVAL:
14689                 printf("invalid bandwidth\n");
14690                 break;
14691         case -ENODEV:
14692                 printf("invalid port_id %d\n", res->port_id);
14693                 break;
14694         case -ENOTSUP:
14695                 printf("function not implemented\n");
14696                 break;
14697         default:
14698                 printf("programming error: (%s)\n", strerror(-ret));
14699         }
14700 }
14701
14702 cmdline_parse_inst_t cmd_tc_min_bw = {
14703         .f = cmd_tc_min_bw_parsed,
14704         .data = NULL,
14705         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14706         .tokens = {
14707                 (void *)&cmd_vf_tc_bw_set,
14708                 (void *)&cmd_vf_tc_bw_tc,
14709                 (void *)&cmd_vf_tc_bw_tx,
14710                 (void *)&cmd_vf_tc_bw_min_bw,
14711                 (void *)&cmd_vf_tc_bw_port_id,
14712                 (void *)&cmd_vf_tc_bw_bw_list,
14713                 NULL,
14714         },
14715 };
14716
14717 /* TC max bandwidth setting */
14718 static void
14719 cmd_vf_tc_max_bw_parsed(
14720         void *parsed_result,
14721         __attribute__((unused)) struct cmdline *cl,
14722         __attribute__((unused)) void *data)
14723 {
14724         struct cmd_vf_tc_bw_result *res = parsed_result;
14725         int ret = -ENOTSUP;
14726
14727         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14728                 return;
14729
14730 #ifdef RTE_LIBRTE_I40E_PMD
14731         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14732                                             res->tc_no, res->bw);
14733 #endif
14734
14735         switch (ret) {
14736         case 0:
14737                 break;
14738         case -EINVAL:
14739                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14740                        res->vf_id, res->tc_no, res->bw);
14741                 break;
14742         case -ENODEV:
14743                 printf("invalid port_id %d\n", res->port_id);
14744                 break;
14745         case -ENOTSUP:
14746                 printf("function not implemented\n");
14747                 break;
14748         default:
14749                 printf("programming error: (%s)\n", strerror(-ret));
14750         }
14751 }
14752
14753 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14754         .f = cmd_vf_tc_max_bw_parsed,
14755         .data = NULL,
14756         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14757                     " <bandwidth>",
14758         .tokens = {
14759                 (void *)&cmd_vf_tc_bw_set,
14760                 (void *)&cmd_vf_tc_bw_vf,
14761                 (void *)&cmd_vf_tc_bw_tc,
14762                 (void *)&cmd_vf_tc_bw_tx,
14763                 (void *)&cmd_vf_tc_bw_max_bw,
14764                 (void *)&cmd_vf_tc_bw_port_id,
14765                 (void *)&cmd_vf_tc_bw_vf_id,
14766                 (void *)&cmd_vf_tc_bw_tc_no,
14767                 (void *)&cmd_vf_tc_bw_bw,
14768                 NULL,
14769         },
14770 };
14771
14772
14773 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14774
14775 /* *** Set Port default Traffic Management Hierarchy *** */
14776 struct cmd_set_port_tm_hierarchy_default_result {
14777         cmdline_fixed_string_t set;
14778         cmdline_fixed_string_t port;
14779         cmdline_fixed_string_t tm;
14780         cmdline_fixed_string_t hierarchy;
14781         cmdline_fixed_string_t def;
14782         portid_t port_id;
14783 };
14784
14785 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14786         TOKEN_STRING_INITIALIZER(
14787                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14788 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14789         TOKEN_STRING_INITIALIZER(
14790                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14791 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14792         TOKEN_STRING_INITIALIZER(
14793                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14794 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14795         TOKEN_STRING_INITIALIZER(
14796                 struct cmd_set_port_tm_hierarchy_default_result,
14797                         hierarchy, "hierarchy");
14798 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14799         TOKEN_STRING_INITIALIZER(
14800                 struct cmd_set_port_tm_hierarchy_default_result,
14801                         def, "default");
14802 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14803         TOKEN_NUM_INITIALIZER(
14804                 struct cmd_set_port_tm_hierarchy_default_result,
14805                         port_id, UINT16);
14806
14807 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14808         __attribute__((unused)) struct cmdline *cl,
14809         __attribute__((unused)) void *data)
14810 {
14811         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14812         struct rte_port *p;
14813         portid_t port_id = res->port_id;
14814
14815         if (port_id_is_invalid(port_id, ENABLED_WARN))
14816                 return;
14817
14818         p = &ports[port_id];
14819
14820         /* Port tm flag */
14821         if (p->softport.tm_flag == 0) {
14822                 printf("  tm not enabled on port %u (error)\n", port_id);
14823                 return;
14824         }
14825
14826         /* Forward mode: tm */
14827         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14828                 printf("  tm mode not enabled(error)\n");
14829                 return;
14830         }
14831
14832         /* Set the default tm hierarchy */
14833         p->softport.tm.default_hierarchy_enable = 1;
14834 }
14835
14836 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14837         .f = cmd_set_port_tm_hierarchy_default_parsed,
14838         .data = NULL,
14839         .help_str = "set port tm hierarchy default <port_id>",
14840         .tokens = {
14841                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14842                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14843                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14844                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14845                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14846                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14847                 NULL,
14848         },
14849 };
14850 #endif
14851
14852 /* Strict link priority scheduling mode setting */
14853 static void
14854 cmd_strict_link_prio_parsed(
14855         void *parsed_result,
14856         __attribute__((unused)) struct cmdline *cl,
14857         __attribute__((unused)) void *data)
14858 {
14859         struct cmd_vf_tc_bw_result *res = parsed_result;
14860         int ret = -ENOTSUP;
14861
14862         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14863                 return;
14864
14865 #ifdef RTE_LIBRTE_I40E_PMD
14866         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14867 #endif
14868
14869         switch (ret) {
14870         case 0:
14871                 break;
14872         case -EINVAL:
14873                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14874                 break;
14875         case -ENODEV:
14876                 printf("invalid port_id %d\n", res->port_id);
14877                 break;
14878         case -ENOTSUP:
14879                 printf("function not implemented\n");
14880                 break;
14881         default:
14882                 printf("programming error: (%s)\n", strerror(-ret));
14883         }
14884 }
14885
14886 cmdline_parse_inst_t cmd_strict_link_prio = {
14887         .f = cmd_strict_link_prio_parsed,
14888         .data = NULL,
14889         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14890         .tokens = {
14891                 (void *)&cmd_vf_tc_bw_set,
14892                 (void *)&cmd_vf_tc_bw_tx,
14893                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14894                 (void *)&cmd_vf_tc_bw_port_id,
14895                 (void *)&cmd_vf_tc_bw_tc_map,
14896                 NULL,
14897         },
14898 };
14899
14900 /* Load dynamic device personalization*/
14901 struct cmd_ddp_add_result {
14902         cmdline_fixed_string_t ddp;
14903         cmdline_fixed_string_t add;
14904         portid_t port_id;
14905         char filepath[];
14906 };
14907
14908 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14909         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14910 cmdline_parse_token_string_t cmd_ddp_add_add =
14911         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14912 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14913         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14914 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14915         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14916
14917 static void
14918 cmd_ddp_add_parsed(
14919         void *parsed_result,
14920         __attribute__((unused)) struct cmdline *cl,
14921         __attribute__((unused)) void *data)
14922 {
14923         struct cmd_ddp_add_result *res = parsed_result;
14924         uint8_t *buff;
14925         uint32_t size;
14926         char *filepath;
14927         char *file_fld[2];
14928         int file_num;
14929         int ret = -ENOTSUP;
14930
14931         if (!all_ports_stopped()) {
14932                 printf("Please stop all ports first\n");
14933                 return;
14934         }
14935
14936         filepath = strdup(res->filepath);
14937         if (filepath == NULL) {
14938                 printf("Failed to allocate memory\n");
14939                 return;
14940         }
14941         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14942
14943         buff = open_file(file_fld[0], &size);
14944         if (!buff) {
14945                 free((void *)filepath);
14946                 return;
14947         }
14948
14949 #ifdef RTE_LIBRTE_I40E_PMD
14950         if (ret == -ENOTSUP)
14951                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14952                                                buff, size,
14953                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14954 #endif
14955
14956         if (ret == -EEXIST)
14957                 printf("Profile has already existed.\n");
14958         else if (ret < 0)
14959                 printf("Failed to load profile.\n");
14960         else if (file_num == 2)
14961                 save_file(file_fld[1], buff, size);
14962
14963         close_file(buff);
14964         free((void *)filepath);
14965 }
14966
14967 cmdline_parse_inst_t cmd_ddp_add = {
14968         .f = cmd_ddp_add_parsed,
14969         .data = NULL,
14970         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14971         .tokens = {
14972                 (void *)&cmd_ddp_add_ddp,
14973                 (void *)&cmd_ddp_add_add,
14974                 (void *)&cmd_ddp_add_port_id,
14975                 (void *)&cmd_ddp_add_filepath,
14976                 NULL,
14977         },
14978 };
14979
14980 /* Delete dynamic device personalization*/
14981 struct cmd_ddp_del_result {
14982         cmdline_fixed_string_t ddp;
14983         cmdline_fixed_string_t del;
14984         portid_t port_id;
14985         char filepath[];
14986 };
14987
14988 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14989         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14990 cmdline_parse_token_string_t cmd_ddp_del_del =
14991         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14992 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14993         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14994 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14995         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14996
14997 static void
14998 cmd_ddp_del_parsed(
14999         void *parsed_result,
15000         __attribute__((unused)) struct cmdline *cl,
15001         __attribute__((unused)) void *data)
15002 {
15003         struct cmd_ddp_del_result *res = parsed_result;
15004         uint8_t *buff;
15005         uint32_t size;
15006         int ret = -ENOTSUP;
15007
15008         if (!all_ports_stopped()) {
15009                 printf("Please stop all ports first\n");
15010                 return;
15011         }
15012
15013         buff = open_file(res->filepath, &size);
15014         if (!buff)
15015                 return;
15016
15017 #ifdef RTE_LIBRTE_I40E_PMD
15018         if (ret == -ENOTSUP)
15019                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15020                                                buff, size,
15021                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15022 #endif
15023
15024         if (ret == -EACCES)
15025                 printf("Profile does not exist.\n");
15026         else if (ret < 0)
15027                 printf("Failed to delete profile.\n");
15028
15029         close_file(buff);
15030 }
15031
15032 cmdline_parse_inst_t cmd_ddp_del = {
15033         .f = cmd_ddp_del_parsed,
15034         .data = NULL,
15035         .help_str = "ddp del <port_id> <backup_profile_path>",
15036         .tokens = {
15037                 (void *)&cmd_ddp_del_ddp,
15038                 (void *)&cmd_ddp_del_del,
15039                 (void *)&cmd_ddp_del_port_id,
15040                 (void *)&cmd_ddp_del_filepath,
15041                 NULL,
15042         },
15043 };
15044
15045 /* Get dynamic device personalization profile info */
15046 struct cmd_ddp_info_result {
15047         cmdline_fixed_string_t ddp;
15048         cmdline_fixed_string_t get;
15049         cmdline_fixed_string_t info;
15050         char filepath[];
15051 };
15052
15053 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15054         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15055 cmdline_parse_token_string_t cmd_ddp_info_get =
15056         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15057 cmdline_parse_token_string_t cmd_ddp_info_info =
15058         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15059 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15060         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15061
15062 static void
15063 cmd_ddp_info_parsed(
15064         void *parsed_result,
15065         __attribute__((unused)) struct cmdline *cl,
15066         __attribute__((unused)) void *data)
15067 {
15068         struct cmd_ddp_info_result *res = parsed_result;
15069         uint8_t *pkg;
15070         uint32_t pkg_size;
15071         int ret = -ENOTSUP;
15072 #ifdef RTE_LIBRTE_I40E_PMD
15073         uint32_t i, j, n;
15074         uint8_t *buff;
15075         uint32_t buff_size = 0;
15076         struct rte_pmd_i40e_profile_info info;
15077         uint32_t dev_num = 0;
15078         struct rte_pmd_i40e_ddp_device_id *devs;
15079         uint32_t proto_num = 0;
15080         struct rte_pmd_i40e_proto_info *proto = NULL;
15081         uint32_t pctype_num = 0;
15082         struct rte_pmd_i40e_ptype_info *pctype;
15083         uint32_t ptype_num = 0;
15084         struct rte_pmd_i40e_ptype_info *ptype;
15085         uint8_t proto_id;
15086
15087 #endif
15088
15089         pkg = open_file(res->filepath, &pkg_size);
15090         if (!pkg)
15091                 return;
15092
15093 #ifdef RTE_LIBRTE_I40E_PMD
15094         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15095                                 (uint8_t *)&info, sizeof(info),
15096                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15097         if (!ret) {
15098                 printf("Global Track id:       0x%x\n", info.track_id);
15099                 printf("Global Version:        %d.%d.%d.%d\n",
15100                         info.version.major,
15101                         info.version.minor,
15102                         info.version.update,
15103                         info.version.draft);
15104                 printf("Global Package name:   %s\n\n", info.name);
15105         }
15106
15107         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15108                                 (uint8_t *)&info, sizeof(info),
15109                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15110         if (!ret) {
15111                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15112                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15113                         info.version.major,
15114                         info.version.minor,
15115                         info.version.update,
15116                         info.version.draft);
15117                 printf("i40e Profile name:     %s\n\n", info.name);
15118         }
15119
15120         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15121                                 (uint8_t *)&buff_size, sizeof(buff_size),
15122                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15123         if (!ret && buff_size) {
15124                 buff = (uint8_t *)malloc(buff_size);
15125                 if (buff) {
15126                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15127                                                 buff, buff_size,
15128                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15129                         if (!ret)
15130                                 printf("Package Notes:\n%s\n\n", buff);
15131                         free(buff);
15132                 }
15133         }
15134
15135         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15136                                 (uint8_t *)&dev_num, sizeof(dev_num),
15137                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15138         if (!ret && dev_num) {
15139                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15140                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15141                 if (devs) {
15142                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15143                                                 (uint8_t *)devs, buff_size,
15144                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15145                         if (!ret) {
15146                                 printf("List of supported devices:\n");
15147                                 for (i = 0; i < dev_num; i++) {
15148                                         printf("  %04X:%04X %04X:%04X\n",
15149                                                 devs[i].vendor_dev_id >> 16,
15150                                                 devs[i].vendor_dev_id & 0xFFFF,
15151                                                 devs[i].sub_vendor_dev_id >> 16,
15152                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15153                                 }
15154                                 printf("\n");
15155                         }
15156                         free(devs);
15157                 }
15158         }
15159
15160         /* get information about protocols and packet types */
15161         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15162                 (uint8_t *)&proto_num, sizeof(proto_num),
15163                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15164         if (ret || !proto_num)
15165                 goto no_print_return;
15166
15167         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15168         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15169         if (!proto)
15170                 goto no_print_return;
15171
15172         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15173                                         buff_size,
15174                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15175         if (!ret) {
15176                 printf("List of used protocols:\n");
15177                 for (i = 0; i < proto_num; i++)
15178                         printf("  %2u: %s\n", proto[i].proto_id,
15179                                proto[i].name);
15180                 printf("\n");
15181         }
15182         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15183                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15184                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15185         if (ret || !pctype_num)
15186                 goto no_print_pctypes;
15187
15188         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15189         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15190         if (!pctype)
15191                 goto no_print_pctypes;
15192
15193         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15194                                         buff_size,
15195                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15196         if (ret) {
15197                 free(pctype);
15198                 goto no_print_pctypes;
15199         }
15200
15201         printf("List of defined packet classification types:\n");
15202         for (i = 0; i < pctype_num; i++) {
15203                 printf("  %2u:", pctype[i].ptype_id);
15204                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15205                         proto_id = pctype[i].protocols[j];
15206                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15207                                 for (n = 0; n < proto_num; n++) {
15208                                         if (proto[n].proto_id == proto_id) {
15209                                                 printf(" %s", proto[n].name);
15210                                                 break;
15211                                         }
15212                                 }
15213                         }
15214                 }
15215                 printf("\n");
15216         }
15217         printf("\n");
15218         free(pctype);
15219
15220 no_print_pctypes:
15221
15222         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15223                                         sizeof(ptype_num),
15224                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15225         if (ret || !ptype_num)
15226                 goto no_print_return;
15227
15228         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15229         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15230         if (!ptype)
15231                 goto no_print_return;
15232
15233         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15234                                         buff_size,
15235                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15236         if (ret) {
15237                 free(ptype);
15238                 goto no_print_return;
15239         }
15240         printf("List of defined packet types:\n");
15241         for (i = 0; i < ptype_num; i++) {
15242                 printf("  %2u:", ptype[i].ptype_id);
15243                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15244                         proto_id = ptype[i].protocols[j];
15245                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15246                                 for (n = 0; n < proto_num; n++) {
15247                                         if (proto[n].proto_id == proto_id) {
15248                                                 printf(" %s", proto[n].name);
15249                                                 break;
15250                                         }
15251                                 }
15252                         }
15253                 }
15254                 printf("\n");
15255         }
15256         free(ptype);
15257         printf("\n");
15258
15259         ret = 0;
15260 no_print_return:
15261         if (proto)
15262                 free(proto);
15263 #endif
15264         if (ret == -ENOTSUP)
15265                 printf("Function not supported in PMD driver\n");
15266         close_file(pkg);
15267 }
15268
15269 cmdline_parse_inst_t cmd_ddp_get_info = {
15270         .f = cmd_ddp_info_parsed,
15271         .data = NULL,
15272         .help_str = "ddp get info <profile_path>",
15273         .tokens = {
15274                 (void *)&cmd_ddp_info_ddp,
15275                 (void *)&cmd_ddp_info_get,
15276                 (void *)&cmd_ddp_info_info,
15277                 (void *)&cmd_ddp_info_filepath,
15278                 NULL,
15279         },
15280 };
15281
15282 /* Get dynamic device personalization profile info list*/
15283 #define PROFILE_INFO_SIZE 48
15284 #define MAX_PROFILE_NUM 16
15285
15286 struct cmd_ddp_get_list_result {
15287         cmdline_fixed_string_t ddp;
15288         cmdline_fixed_string_t get;
15289         cmdline_fixed_string_t list;
15290         portid_t port_id;
15291 };
15292
15293 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15294         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15295 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15296         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15297 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15298         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15299 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15300         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15301
15302 static void
15303 cmd_ddp_get_list_parsed(
15304         __attribute__((unused)) void *parsed_result,
15305         __attribute__((unused)) struct cmdline *cl,
15306         __attribute__((unused)) void *data)
15307 {
15308 #ifdef RTE_LIBRTE_I40E_PMD
15309         struct cmd_ddp_get_list_result *res = parsed_result;
15310         struct rte_pmd_i40e_profile_list *p_list;
15311         struct rte_pmd_i40e_profile_info *p_info;
15312         uint32_t p_num;
15313         uint32_t size;
15314         uint32_t i;
15315 #endif
15316         int ret = -ENOTSUP;
15317
15318 #ifdef RTE_LIBRTE_I40E_PMD
15319         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15320         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15321         if (!p_list)
15322                 printf("%s: Failed to malloc buffer\n", __func__);
15323
15324         if (ret == -ENOTSUP)
15325                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15326                                                 (uint8_t *)p_list, size);
15327
15328         if (!ret) {
15329                 p_num = p_list->p_count;
15330                 printf("Profile number is: %d\n\n", p_num);
15331
15332                 for (i = 0; i < p_num; i++) {
15333                         p_info = &p_list->p_info[i];
15334                         printf("Profile %d:\n", i);
15335                         printf("Track id:     0x%x\n", p_info->track_id);
15336                         printf("Version:      %d.%d.%d.%d\n",
15337                                p_info->version.major,
15338                                p_info->version.minor,
15339                                p_info->version.update,
15340                                p_info->version.draft);
15341                         printf("Profile name: %s\n\n", p_info->name);
15342                 }
15343         }
15344
15345         free(p_list);
15346 #endif
15347
15348         if (ret < 0)
15349                 printf("Failed to get ddp list\n");
15350 }
15351
15352 cmdline_parse_inst_t cmd_ddp_get_list = {
15353         .f = cmd_ddp_get_list_parsed,
15354         .data = NULL,
15355         .help_str = "ddp get list <port_id>",
15356         .tokens = {
15357                 (void *)&cmd_ddp_get_list_ddp,
15358                 (void *)&cmd_ddp_get_list_get,
15359                 (void *)&cmd_ddp_get_list_list,
15360                 (void *)&cmd_ddp_get_list_port_id,
15361                 NULL,
15362         },
15363 };
15364
15365 /* Configure input set */
15366 struct cmd_cfg_input_set_result {
15367         cmdline_fixed_string_t port;
15368         cmdline_fixed_string_t cfg;
15369         portid_t port_id;
15370         cmdline_fixed_string_t pctype;
15371         uint8_t pctype_id;
15372         cmdline_fixed_string_t inset_type;
15373         cmdline_fixed_string_t opt;
15374         cmdline_fixed_string_t field;
15375         uint8_t field_idx;
15376 };
15377
15378 static void
15379 cmd_cfg_input_set_parsed(
15380         __attribute__((unused)) void *parsed_result,
15381         __attribute__((unused)) struct cmdline *cl,
15382         __attribute__((unused)) void *data)
15383 {
15384 #ifdef RTE_LIBRTE_I40E_PMD
15385         struct cmd_cfg_input_set_result *res = parsed_result;
15386         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15387         struct rte_pmd_i40e_inset inset;
15388 #endif
15389         int ret = -ENOTSUP;
15390
15391         if (!all_ports_stopped()) {
15392                 printf("Please stop all ports first\n");
15393                 return;
15394         }
15395
15396 #ifdef RTE_LIBRTE_I40E_PMD
15397         if (!strcmp(res->inset_type, "hash_inset"))
15398                 inset_type = INSET_HASH;
15399         else if (!strcmp(res->inset_type, "fdir_inset"))
15400                 inset_type = INSET_FDIR;
15401         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15402                 inset_type = INSET_FDIR_FLX;
15403         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15404                                      &inset, inset_type);
15405         if (ret) {
15406                 printf("Failed to get input set.\n");
15407                 return;
15408         }
15409
15410         if (!strcmp(res->opt, "get")) {
15411                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15412                                                    res->field_idx);
15413                 if (ret)
15414                         printf("Field index %d is enabled.\n", res->field_idx);
15415                 else
15416                         printf("Field index %d is disabled.\n", res->field_idx);
15417                 return;
15418         } else if (!strcmp(res->opt, "set"))
15419                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15420                                                    res->field_idx);
15421         else if (!strcmp(res->opt, "clear"))
15422                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15423                                                      res->field_idx);
15424         if (ret) {
15425                 printf("Failed to configure input set field.\n");
15426                 return;
15427         }
15428
15429         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15430                                      &inset, inset_type);
15431         if (ret) {
15432                 printf("Failed to set input set.\n");
15433                 return;
15434         }
15435 #endif
15436
15437         if (ret == -ENOTSUP)
15438                 printf("Function not supported\n");
15439 }
15440
15441 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15442         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15443                                  port, "port");
15444 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15445         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15446                                  cfg, "config");
15447 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15448         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15449                               port_id, UINT16);
15450 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15451         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15452                                  pctype, "pctype");
15453 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15454         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15455                               pctype_id, UINT8);
15456 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15457         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15458                                  inset_type,
15459                                  "hash_inset#fdir_inset#fdir_flx_inset");
15460 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15461         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15462                                  opt, "get#set#clear");
15463 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15464         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15465                                  field, "field");
15466 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15467         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15468                               field_idx, UINT8);
15469
15470 cmdline_parse_inst_t cmd_cfg_input_set = {
15471         .f = cmd_cfg_input_set_parsed,
15472         .data = NULL,
15473         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15474                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15475         .tokens = {
15476                 (void *)&cmd_cfg_input_set_port,
15477                 (void *)&cmd_cfg_input_set_cfg,
15478                 (void *)&cmd_cfg_input_set_port_id,
15479                 (void *)&cmd_cfg_input_set_pctype,
15480                 (void *)&cmd_cfg_input_set_pctype_id,
15481                 (void *)&cmd_cfg_input_set_inset_type,
15482                 (void *)&cmd_cfg_input_set_opt,
15483                 (void *)&cmd_cfg_input_set_field,
15484                 (void *)&cmd_cfg_input_set_field_idx,
15485                 NULL,
15486         },
15487 };
15488
15489 /* Clear input set */
15490 struct cmd_clear_input_set_result {
15491         cmdline_fixed_string_t port;
15492         cmdline_fixed_string_t cfg;
15493         portid_t port_id;
15494         cmdline_fixed_string_t pctype;
15495         uint8_t pctype_id;
15496         cmdline_fixed_string_t inset_type;
15497         cmdline_fixed_string_t clear;
15498         cmdline_fixed_string_t all;
15499 };
15500
15501 static void
15502 cmd_clear_input_set_parsed(
15503         __attribute__((unused)) void *parsed_result,
15504         __attribute__((unused)) struct cmdline *cl,
15505         __attribute__((unused)) void *data)
15506 {
15507 #ifdef RTE_LIBRTE_I40E_PMD
15508         struct cmd_clear_input_set_result *res = parsed_result;
15509         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15510         struct rte_pmd_i40e_inset inset;
15511 #endif
15512         int ret = -ENOTSUP;
15513
15514         if (!all_ports_stopped()) {
15515                 printf("Please stop all ports first\n");
15516                 return;
15517         }
15518
15519 #ifdef RTE_LIBRTE_I40E_PMD
15520         if (!strcmp(res->inset_type, "hash_inset"))
15521                 inset_type = INSET_HASH;
15522         else if (!strcmp(res->inset_type, "fdir_inset"))
15523                 inset_type = INSET_FDIR;
15524         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15525                 inset_type = INSET_FDIR_FLX;
15526
15527         memset(&inset, 0, sizeof(inset));
15528
15529         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15530                                      &inset, inset_type);
15531         if (ret) {
15532                 printf("Failed to clear input set.\n");
15533                 return;
15534         }
15535
15536 #endif
15537
15538         if (ret == -ENOTSUP)
15539                 printf("Function not supported\n");
15540 }
15541
15542 cmdline_parse_token_string_t cmd_clear_input_set_port =
15543         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15544                                  port, "port");
15545 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15546         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15547                                  cfg, "config");
15548 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15549         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15550                               port_id, UINT16);
15551 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15552         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15553                                  pctype, "pctype");
15554 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15555         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15556                               pctype_id, UINT8);
15557 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15558         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15559                                  inset_type,
15560                                  "hash_inset#fdir_inset#fdir_flx_inset");
15561 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15562         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15563                                  clear, "clear");
15564 cmdline_parse_token_string_t cmd_clear_input_set_all =
15565         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15566                                  all, "all");
15567
15568 cmdline_parse_inst_t cmd_clear_input_set = {
15569         .f = cmd_clear_input_set_parsed,
15570         .data = NULL,
15571         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15572                     "fdir_inset|fdir_flx_inset clear all",
15573         .tokens = {
15574                 (void *)&cmd_clear_input_set_port,
15575                 (void *)&cmd_clear_input_set_cfg,
15576                 (void *)&cmd_clear_input_set_port_id,
15577                 (void *)&cmd_clear_input_set_pctype,
15578                 (void *)&cmd_clear_input_set_pctype_id,
15579                 (void *)&cmd_clear_input_set_inset_type,
15580                 (void *)&cmd_clear_input_set_clear,
15581                 (void *)&cmd_clear_input_set_all,
15582                 NULL,
15583         },
15584 };
15585
15586 /* show vf stats */
15587
15588 /* Common result structure for show vf stats */
15589 struct cmd_show_vf_stats_result {
15590         cmdline_fixed_string_t show;
15591         cmdline_fixed_string_t vf;
15592         cmdline_fixed_string_t stats;
15593         portid_t port_id;
15594         uint16_t vf_id;
15595 };
15596
15597 /* Common CLI fields show vf stats*/
15598 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15599         TOKEN_STRING_INITIALIZER
15600                 (struct cmd_show_vf_stats_result,
15601                  show, "show");
15602 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15603         TOKEN_STRING_INITIALIZER
15604                 (struct cmd_show_vf_stats_result,
15605                  vf, "vf");
15606 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15607         TOKEN_STRING_INITIALIZER
15608                 (struct cmd_show_vf_stats_result,
15609                  stats, "stats");
15610 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15611         TOKEN_NUM_INITIALIZER
15612                 (struct cmd_show_vf_stats_result,
15613                  port_id, UINT16);
15614 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15615         TOKEN_NUM_INITIALIZER
15616                 (struct cmd_show_vf_stats_result,
15617                  vf_id, UINT16);
15618
15619 static void
15620 cmd_show_vf_stats_parsed(
15621         void *parsed_result,
15622         __attribute__((unused)) struct cmdline *cl,
15623         __attribute__((unused)) void *data)
15624 {
15625         struct cmd_show_vf_stats_result *res = parsed_result;
15626         struct rte_eth_stats stats;
15627         int ret = -ENOTSUP;
15628         static const char *nic_stats_border = "########################";
15629
15630         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15631                 return;
15632
15633         memset(&stats, 0, sizeof(stats));
15634
15635 #ifdef RTE_LIBRTE_I40E_PMD
15636         if (ret == -ENOTSUP)
15637                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15638                                                 res->vf_id,
15639                                                 &stats);
15640 #endif
15641 #ifdef RTE_LIBRTE_BNXT_PMD
15642         if (ret == -ENOTSUP)
15643                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15644                                                 res->vf_id,
15645                                                 &stats);
15646 #endif
15647
15648         switch (ret) {
15649         case 0:
15650                 break;
15651         case -EINVAL:
15652                 printf("invalid vf_id %d\n", res->vf_id);
15653                 break;
15654         case -ENODEV:
15655                 printf("invalid port_id %d\n", res->port_id);
15656                 break;
15657         case -ENOTSUP:
15658                 printf("function not implemented\n");
15659                 break;
15660         default:
15661                 printf("programming error: (%s)\n", strerror(-ret));
15662         }
15663
15664         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15665                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15666
15667         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15668                "%-"PRIu64"\n",
15669                stats.ipackets, stats.imissed, stats.ibytes);
15670         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15671         printf("  RX-nombuf:  %-10"PRIu64"\n",
15672                stats.rx_nombuf);
15673         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15674                "%-"PRIu64"\n",
15675                stats.opackets, stats.oerrors, stats.obytes);
15676
15677         printf("  %s############################%s\n",
15678                                nic_stats_border, nic_stats_border);
15679 }
15680
15681 cmdline_parse_inst_t cmd_show_vf_stats = {
15682         .f = cmd_show_vf_stats_parsed,
15683         .data = NULL,
15684         .help_str = "show vf stats <port_id> <vf_id>",
15685         .tokens = {
15686                 (void *)&cmd_show_vf_stats_show,
15687                 (void *)&cmd_show_vf_stats_vf,
15688                 (void *)&cmd_show_vf_stats_stats,
15689                 (void *)&cmd_show_vf_stats_port_id,
15690                 (void *)&cmd_show_vf_stats_vf_id,
15691                 NULL,
15692         },
15693 };
15694
15695 /* clear vf stats */
15696
15697 /* Common result structure for clear vf stats */
15698 struct cmd_clear_vf_stats_result {
15699         cmdline_fixed_string_t clear;
15700         cmdline_fixed_string_t vf;
15701         cmdline_fixed_string_t stats;
15702         portid_t port_id;
15703         uint16_t vf_id;
15704 };
15705
15706 /* Common CLI fields clear vf stats*/
15707 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15708         TOKEN_STRING_INITIALIZER
15709                 (struct cmd_clear_vf_stats_result,
15710                  clear, "clear");
15711 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15712         TOKEN_STRING_INITIALIZER
15713                 (struct cmd_clear_vf_stats_result,
15714                  vf, "vf");
15715 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15716         TOKEN_STRING_INITIALIZER
15717                 (struct cmd_clear_vf_stats_result,
15718                  stats, "stats");
15719 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15720         TOKEN_NUM_INITIALIZER
15721                 (struct cmd_clear_vf_stats_result,
15722                  port_id, UINT16);
15723 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15724         TOKEN_NUM_INITIALIZER
15725                 (struct cmd_clear_vf_stats_result,
15726                  vf_id, UINT16);
15727
15728 static void
15729 cmd_clear_vf_stats_parsed(
15730         void *parsed_result,
15731         __attribute__((unused)) struct cmdline *cl,
15732         __attribute__((unused)) void *data)
15733 {
15734         struct cmd_clear_vf_stats_result *res = parsed_result;
15735         int ret = -ENOTSUP;
15736
15737         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15738                 return;
15739
15740 #ifdef RTE_LIBRTE_I40E_PMD
15741         if (ret == -ENOTSUP)
15742                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15743                                                   res->vf_id);
15744 #endif
15745 #ifdef RTE_LIBRTE_BNXT_PMD
15746         if (ret == -ENOTSUP)
15747                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15748                                                   res->vf_id);
15749 #endif
15750
15751         switch (ret) {
15752         case 0:
15753                 break;
15754         case -EINVAL:
15755                 printf("invalid vf_id %d\n", res->vf_id);
15756                 break;
15757         case -ENODEV:
15758                 printf("invalid port_id %d\n", res->port_id);
15759                 break;
15760         case -ENOTSUP:
15761                 printf("function not implemented\n");
15762                 break;
15763         default:
15764                 printf("programming error: (%s)\n", strerror(-ret));
15765         }
15766 }
15767
15768 cmdline_parse_inst_t cmd_clear_vf_stats = {
15769         .f = cmd_clear_vf_stats_parsed,
15770         .data = NULL,
15771         .help_str = "clear vf stats <port_id> <vf_id>",
15772         .tokens = {
15773                 (void *)&cmd_clear_vf_stats_clear,
15774                 (void *)&cmd_clear_vf_stats_vf,
15775                 (void *)&cmd_clear_vf_stats_stats,
15776                 (void *)&cmd_clear_vf_stats_port_id,
15777                 (void *)&cmd_clear_vf_stats_vf_id,
15778                 NULL,
15779         },
15780 };
15781
15782 /* port config pctype mapping reset */
15783
15784 /* Common result structure for port config pctype mapping reset */
15785 struct cmd_pctype_mapping_reset_result {
15786         cmdline_fixed_string_t port;
15787         cmdline_fixed_string_t config;
15788         portid_t port_id;
15789         cmdline_fixed_string_t pctype;
15790         cmdline_fixed_string_t mapping;
15791         cmdline_fixed_string_t reset;
15792 };
15793
15794 /* Common CLI fields for port config pctype mapping reset*/
15795 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15796         TOKEN_STRING_INITIALIZER
15797                 (struct cmd_pctype_mapping_reset_result,
15798                  port, "port");
15799 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15800         TOKEN_STRING_INITIALIZER
15801                 (struct cmd_pctype_mapping_reset_result,
15802                  config, "config");
15803 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15804         TOKEN_NUM_INITIALIZER
15805                 (struct cmd_pctype_mapping_reset_result,
15806                  port_id, UINT16);
15807 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15808         TOKEN_STRING_INITIALIZER
15809                 (struct cmd_pctype_mapping_reset_result,
15810                  pctype, "pctype");
15811 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15812         TOKEN_STRING_INITIALIZER
15813                 (struct cmd_pctype_mapping_reset_result,
15814                  mapping, "mapping");
15815 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15816         TOKEN_STRING_INITIALIZER
15817                 (struct cmd_pctype_mapping_reset_result,
15818                  reset, "reset");
15819
15820 static void
15821 cmd_pctype_mapping_reset_parsed(
15822         void *parsed_result,
15823         __attribute__((unused)) struct cmdline *cl,
15824         __attribute__((unused)) void *data)
15825 {
15826         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15827         int ret = -ENOTSUP;
15828
15829         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15830                 return;
15831
15832 #ifdef RTE_LIBRTE_I40E_PMD
15833         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15834 #endif
15835
15836         switch (ret) {
15837         case 0:
15838                 break;
15839         case -ENODEV:
15840                 printf("invalid port_id %d\n", res->port_id);
15841                 break;
15842         case -ENOTSUP:
15843                 printf("function not implemented\n");
15844                 break;
15845         default:
15846                 printf("programming error: (%s)\n", strerror(-ret));
15847         }
15848 }
15849
15850 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15851         .f = cmd_pctype_mapping_reset_parsed,
15852         .data = NULL,
15853         .help_str = "port config <port_id> pctype mapping reset",
15854         .tokens = {
15855                 (void *)&cmd_pctype_mapping_reset_port,
15856                 (void *)&cmd_pctype_mapping_reset_config,
15857                 (void *)&cmd_pctype_mapping_reset_port_id,
15858                 (void *)&cmd_pctype_mapping_reset_pctype,
15859                 (void *)&cmd_pctype_mapping_reset_mapping,
15860                 (void *)&cmd_pctype_mapping_reset_reset,
15861                 NULL,
15862         },
15863 };
15864
15865 /* show port pctype mapping */
15866
15867 /* Common result structure for show port pctype mapping */
15868 struct cmd_pctype_mapping_get_result {
15869         cmdline_fixed_string_t show;
15870         cmdline_fixed_string_t port;
15871         portid_t port_id;
15872         cmdline_fixed_string_t pctype;
15873         cmdline_fixed_string_t mapping;
15874 };
15875
15876 /* Common CLI fields for pctype mapping get */
15877 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15878         TOKEN_STRING_INITIALIZER
15879                 (struct cmd_pctype_mapping_get_result,
15880                  show, "show");
15881 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15882         TOKEN_STRING_INITIALIZER
15883                 (struct cmd_pctype_mapping_get_result,
15884                  port, "port");
15885 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15886         TOKEN_NUM_INITIALIZER
15887                 (struct cmd_pctype_mapping_get_result,
15888                  port_id, UINT16);
15889 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15890         TOKEN_STRING_INITIALIZER
15891                 (struct cmd_pctype_mapping_get_result,
15892                  pctype, "pctype");
15893 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15894         TOKEN_STRING_INITIALIZER
15895                 (struct cmd_pctype_mapping_get_result,
15896                  mapping, "mapping");
15897
15898 static void
15899 cmd_pctype_mapping_get_parsed(
15900         void *parsed_result,
15901         __attribute__((unused)) struct cmdline *cl,
15902         __attribute__((unused)) void *data)
15903 {
15904         struct cmd_pctype_mapping_get_result *res = parsed_result;
15905         int ret = -ENOTSUP;
15906 #ifdef RTE_LIBRTE_I40E_PMD
15907         struct rte_pmd_i40e_flow_type_mapping
15908                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15909         int i, j, first_pctype;
15910 #endif
15911
15912         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15913                 return;
15914
15915 #ifdef RTE_LIBRTE_I40E_PMD
15916         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15917 #endif
15918
15919         switch (ret) {
15920         case 0:
15921                 break;
15922         case -ENODEV:
15923                 printf("invalid port_id %d\n", res->port_id);
15924                 return;
15925         case -ENOTSUP:
15926                 printf("function not implemented\n");
15927                 return;
15928         default:
15929                 printf("programming error: (%s)\n", strerror(-ret));
15930                 return;
15931         }
15932
15933 #ifdef RTE_LIBRTE_I40E_PMD
15934         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15935                 if (mapping[i].pctype != 0ULL) {
15936                         first_pctype = 1;
15937
15938                         printf("pctype: ");
15939                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15940                                 if (mapping[i].pctype & (1ULL << j)) {
15941                                         printf(first_pctype ?
15942                                                "%02d" : ",%02d", j);
15943                                         first_pctype = 0;
15944                                 }
15945                         }
15946                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15947                 }
15948         }
15949 #endif
15950 }
15951
15952 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15953         .f = cmd_pctype_mapping_get_parsed,
15954         .data = NULL,
15955         .help_str = "show port <port_id> pctype mapping",
15956         .tokens = {
15957                 (void *)&cmd_pctype_mapping_get_show,
15958                 (void *)&cmd_pctype_mapping_get_port,
15959                 (void *)&cmd_pctype_mapping_get_port_id,
15960                 (void *)&cmd_pctype_mapping_get_pctype,
15961                 (void *)&cmd_pctype_mapping_get_mapping,
15962                 NULL,
15963         },
15964 };
15965
15966 /* port config pctype mapping update */
15967
15968 /* Common result structure for port config pctype mapping update */
15969 struct cmd_pctype_mapping_update_result {
15970         cmdline_fixed_string_t port;
15971         cmdline_fixed_string_t config;
15972         portid_t port_id;
15973         cmdline_fixed_string_t pctype;
15974         cmdline_fixed_string_t mapping;
15975         cmdline_fixed_string_t update;
15976         cmdline_fixed_string_t pctype_list;
15977         uint16_t flow_type;
15978 };
15979
15980 /* Common CLI fields for pctype mapping update*/
15981 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15982         TOKEN_STRING_INITIALIZER
15983                 (struct cmd_pctype_mapping_update_result,
15984                  port, "port");
15985 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15986         TOKEN_STRING_INITIALIZER
15987                 (struct cmd_pctype_mapping_update_result,
15988                  config, "config");
15989 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15990         TOKEN_NUM_INITIALIZER
15991                 (struct cmd_pctype_mapping_update_result,
15992                  port_id, UINT16);
15993 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15994         TOKEN_STRING_INITIALIZER
15995                 (struct cmd_pctype_mapping_update_result,
15996                  pctype, "pctype");
15997 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15998         TOKEN_STRING_INITIALIZER
15999                 (struct cmd_pctype_mapping_update_result,
16000                  mapping, "mapping");
16001 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16002         TOKEN_STRING_INITIALIZER
16003                 (struct cmd_pctype_mapping_update_result,
16004                  update, "update");
16005 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16006         TOKEN_STRING_INITIALIZER
16007                 (struct cmd_pctype_mapping_update_result,
16008                  pctype_list, NULL);
16009 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16010         TOKEN_NUM_INITIALIZER
16011                 (struct cmd_pctype_mapping_update_result,
16012                  flow_type, UINT16);
16013
16014 static void
16015 cmd_pctype_mapping_update_parsed(
16016         void *parsed_result,
16017         __attribute__((unused)) struct cmdline *cl,
16018         __attribute__((unused)) void *data)
16019 {
16020         struct cmd_pctype_mapping_update_result *res = parsed_result;
16021         int ret = -ENOTSUP;
16022 #ifdef RTE_LIBRTE_I40E_PMD
16023         struct rte_pmd_i40e_flow_type_mapping mapping;
16024         unsigned int i;
16025         unsigned int nb_item;
16026         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16027 #endif
16028
16029         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16030                 return;
16031
16032 #ifdef RTE_LIBRTE_I40E_PMD
16033         nb_item = parse_item_list(res->pctype_list, "pctypes",
16034                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16035         mapping.flow_type = res->flow_type;
16036         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16037                 mapping.pctype |= (1ULL << pctype_list[i]);
16038         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16039                                                 &mapping,
16040                                                 1,
16041                                                 0);
16042 #endif
16043
16044         switch (ret) {
16045         case 0:
16046                 break;
16047         case -EINVAL:
16048                 printf("invalid pctype or flow type\n");
16049                 break;
16050         case -ENODEV:
16051                 printf("invalid port_id %d\n", res->port_id);
16052                 break;
16053         case -ENOTSUP:
16054                 printf("function not implemented\n");
16055                 break;
16056         default:
16057                 printf("programming error: (%s)\n", strerror(-ret));
16058         }
16059 }
16060
16061 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16062         .f = cmd_pctype_mapping_update_parsed,
16063         .data = NULL,
16064         .help_str = "port config <port_id> pctype mapping update"
16065         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16066         .tokens = {
16067                 (void *)&cmd_pctype_mapping_update_port,
16068                 (void *)&cmd_pctype_mapping_update_config,
16069                 (void *)&cmd_pctype_mapping_update_port_id,
16070                 (void *)&cmd_pctype_mapping_update_pctype,
16071                 (void *)&cmd_pctype_mapping_update_mapping,
16072                 (void *)&cmd_pctype_mapping_update_update,
16073                 (void *)&cmd_pctype_mapping_update_pc_type,
16074                 (void *)&cmd_pctype_mapping_update_flow_type,
16075                 NULL,
16076         },
16077 };
16078
16079 /* ptype mapping get */
16080
16081 /* Common result structure for ptype mapping get */
16082 struct cmd_ptype_mapping_get_result {
16083         cmdline_fixed_string_t ptype;
16084         cmdline_fixed_string_t mapping;
16085         cmdline_fixed_string_t get;
16086         portid_t port_id;
16087         uint8_t valid_only;
16088 };
16089
16090 /* Common CLI fields for ptype mapping get */
16091 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16092         TOKEN_STRING_INITIALIZER
16093                 (struct cmd_ptype_mapping_get_result,
16094                  ptype, "ptype");
16095 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16096         TOKEN_STRING_INITIALIZER
16097                 (struct cmd_ptype_mapping_get_result,
16098                  mapping, "mapping");
16099 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16100         TOKEN_STRING_INITIALIZER
16101                 (struct cmd_ptype_mapping_get_result,
16102                  get, "get");
16103 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16104         TOKEN_NUM_INITIALIZER
16105                 (struct cmd_ptype_mapping_get_result,
16106                  port_id, UINT16);
16107 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16108         TOKEN_NUM_INITIALIZER
16109                 (struct cmd_ptype_mapping_get_result,
16110                  valid_only, UINT8);
16111
16112 static void
16113 cmd_ptype_mapping_get_parsed(
16114         void *parsed_result,
16115         __attribute__((unused)) struct cmdline *cl,
16116         __attribute__((unused)) void *data)
16117 {
16118         struct cmd_ptype_mapping_get_result *res = parsed_result;
16119         int ret = -ENOTSUP;
16120 #ifdef RTE_LIBRTE_I40E_PMD
16121         int max_ptype_num = 256;
16122         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16123         uint16_t count;
16124         int i;
16125 #endif
16126
16127         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16128                 return;
16129
16130 #ifdef RTE_LIBRTE_I40E_PMD
16131         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16132                                         mapping,
16133                                         max_ptype_num,
16134                                         &count,
16135                                         res->valid_only);
16136 #endif
16137
16138         switch (ret) {
16139         case 0:
16140                 break;
16141         case -ENODEV:
16142                 printf("invalid port_id %d\n", res->port_id);
16143                 break;
16144         case -ENOTSUP:
16145                 printf("function not implemented\n");
16146                 break;
16147         default:
16148                 printf("programming error: (%s)\n", strerror(-ret));
16149         }
16150
16151 #ifdef RTE_LIBRTE_I40E_PMD
16152         if (!ret) {
16153                 for (i = 0; i < count; i++)
16154                         printf("%3d\t0x%08x\n",
16155                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16156         }
16157 #endif
16158 }
16159
16160 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16161         .f = cmd_ptype_mapping_get_parsed,
16162         .data = NULL,
16163         .help_str = "ptype mapping get <port_id> <valid_only>",
16164         .tokens = {
16165                 (void *)&cmd_ptype_mapping_get_ptype,
16166                 (void *)&cmd_ptype_mapping_get_mapping,
16167                 (void *)&cmd_ptype_mapping_get_get,
16168                 (void *)&cmd_ptype_mapping_get_port_id,
16169                 (void *)&cmd_ptype_mapping_get_valid_only,
16170                 NULL,
16171         },
16172 };
16173
16174 /* ptype mapping replace */
16175
16176 /* Common result structure for ptype mapping replace */
16177 struct cmd_ptype_mapping_replace_result {
16178         cmdline_fixed_string_t ptype;
16179         cmdline_fixed_string_t mapping;
16180         cmdline_fixed_string_t replace;
16181         portid_t port_id;
16182         uint32_t target;
16183         uint8_t mask;
16184         uint32_t pkt_type;
16185 };
16186
16187 /* Common CLI fields for ptype mapping replace */
16188 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16189         TOKEN_STRING_INITIALIZER
16190                 (struct cmd_ptype_mapping_replace_result,
16191                  ptype, "ptype");
16192 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16193         TOKEN_STRING_INITIALIZER
16194                 (struct cmd_ptype_mapping_replace_result,
16195                  mapping, "mapping");
16196 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16197         TOKEN_STRING_INITIALIZER
16198                 (struct cmd_ptype_mapping_replace_result,
16199                  replace, "replace");
16200 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16201         TOKEN_NUM_INITIALIZER
16202                 (struct cmd_ptype_mapping_replace_result,
16203                  port_id, UINT16);
16204 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16205         TOKEN_NUM_INITIALIZER
16206                 (struct cmd_ptype_mapping_replace_result,
16207                  target, UINT32);
16208 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16209         TOKEN_NUM_INITIALIZER
16210                 (struct cmd_ptype_mapping_replace_result,
16211                  mask, UINT8);
16212 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16213         TOKEN_NUM_INITIALIZER
16214                 (struct cmd_ptype_mapping_replace_result,
16215                  pkt_type, UINT32);
16216
16217 static void
16218 cmd_ptype_mapping_replace_parsed(
16219         void *parsed_result,
16220         __attribute__((unused)) struct cmdline *cl,
16221         __attribute__((unused)) void *data)
16222 {
16223         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16224         int ret = -ENOTSUP;
16225
16226         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16227                 return;
16228
16229 #ifdef RTE_LIBRTE_I40E_PMD
16230         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16231                                         res->target,
16232                                         res->mask,
16233                                         res->pkt_type);
16234 #endif
16235
16236         switch (ret) {
16237         case 0:
16238                 break;
16239         case -EINVAL:
16240                 printf("invalid ptype 0x%8x or 0x%8x\n",
16241                                 res->target, res->pkt_type);
16242                 break;
16243         case -ENODEV:
16244                 printf("invalid port_id %d\n", res->port_id);
16245                 break;
16246         case -ENOTSUP:
16247                 printf("function not implemented\n");
16248                 break;
16249         default:
16250                 printf("programming error: (%s)\n", strerror(-ret));
16251         }
16252 }
16253
16254 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16255         .f = cmd_ptype_mapping_replace_parsed,
16256         .data = NULL,
16257         .help_str =
16258                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16259         .tokens = {
16260                 (void *)&cmd_ptype_mapping_replace_ptype,
16261                 (void *)&cmd_ptype_mapping_replace_mapping,
16262                 (void *)&cmd_ptype_mapping_replace_replace,
16263                 (void *)&cmd_ptype_mapping_replace_port_id,
16264                 (void *)&cmd_ptype_mapping_replace_target,
16265                 (void *)&cmd_ptype_mapping_replace_mask,
16266                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16267                 NULL,
16268         },
16269 };
16270
16271 /* ptype mapping reset */
16272
16273 /* Common result structure for ptype mapping reset */
16274 struct cmd_ptype_mapping_reset_result {
16275         cmdline_fixed_string_t ptype;
16276         cmdline_fixed_string_t mapping;
16277         cmdline_fixed_string_t reset;
16278         portid_t port_id;
16279 };
16280
16281 /* Common CLI fields for ptype mapping reset*/
16282 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16283         TOKEN_STRING_INITIALIZER
16284                 (struct cmd_ptype_mapping_reset_result,
16285                  ptype, "ptype");
16286 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16287         TOKEN_STRING_INITIALIZER
16288                 (struct cmd_ptype_mapping_reset_result,
16289                  mapping, "mapping");
16290 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16291         TOKEN_STRING_INITIALIZER
16292                 (struct cmd_ptype_mapping_reset_result,
16293                  reset, "reset");
16294 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16295         TOKEN_NUM_INITIALIZER
16296                 (struct cmd_ptype_mapping_reset_result,
16297                  port_id, UINT16);
16298
16299 static void
16300 cmd_ptype_mapping_reset_parsed(
16301         void *parsed_result,
16302         __attribute__((unused)) struct cmdline *cl,
16303         __attribute__((unused)) void *data)
16304 {
16305         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16306         int ret = -ENOTSUP;
16307
16308         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16309                 return;
16310
16311 #ifdef RTE_LIBRTE_I40E_PMD
16312         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16313 #endif
16314
16315         switch (ret) {
16316         case 0:
16317                 break;
16318         case -ENODEV:
16319                 printf("invalid port_id %d\n", res->port_id);
16320                 break;
16321         case -ENOTSUP:
16322                 printf("function not implemented\n");
16323                 break;
16324         default:
16325                 printf("programming error: (%s)\n", strerror(-ret));
16326         }
16327 }
16328
16329 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16330         .f = cmd_ptype_mapping_reset_parsed,
16331         .data = NULL,
16332         .help_str = "ptype mapping reset <port_id>",
16333         .tokens = {
16334                 (void *)&cmd_ptype_mapping_reset_ptype,
16335                 (void *)&cmd_ptype_mapping_reset_mapping,
16336                 (void *)&cmd_ptype_mapping_reset_reset,
16337                 (void *)&cmd_ptype_mapping_reset_port_id,
16338                 NULL,
16339         },
16340 };
16341
16342 /* ptype mapping update */
16343
16344 /* Common result structure for ptype mapping update */
16345 struct cmd_ptype_mapping_update_result {
16346         cmdline_fixed_string_t ptype;
16347         cmdline_fixed_string_t mapping;
16348         cmdline_fixed_string_t reset;
16349         portid_t port_id;
16350         uint8_t hw_ptype;
16351         uint32_t sw_ptype;
16352 };
16353
16354 /* Common CLI fields for ptype mapping update*/
16355 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16356         TOKEN_STRING_INITIALIZER
16357                 (struct cmd_ptype_mapping_update_result,
16358                  ptype, "ptype");
16359 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16360         TOKEN_STRING_INITIALIZER
16361                 (struct cmd_ptype_mapping_update_result,
16362                  mapping, "mapping");
16363 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16364         TOKEN_STRING_INITIALIZER
16365                 (struct cmd_ptype_mapping_update_result,
16366                  reset, "update");
16367 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16368         TOKEN_NUM_INITIALIZER
16369                 (struct cmd_ptype_mapping_update_result,
16370                  port_id, UINT16);
16371 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16372         TOKEN_NUM_INITIALIZER
16373                 (struct cmd_ptype_mapping_update_result,
16374                  hw_ptype, UINT8);
16375 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16376         TOKEN_NUM_INITIALIZER
16377                 (struct cmd_ptype_mapping_update_result,
16378                  sw_ptype, UINT32);
16379
16380 static void
16381 cmd_ptype_mapping_update_parsed(
16382         void *parsed_result,
16383         __attribute__((unused)) struct cmdline *cl,
16384         __attribute__((unused)) void *data)
16385 {
16386         struct cmd_ptype_mapping_update_result *res = parsed_result;
16387         int ret = -ENOTSUP;
16388 #ifdef RTE_LIBRTE_I40E_PMD
16389         struct rte_pmd_i40e_ptype_mapping mapping;
16390 #endif
16391         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16392                 return;
16393
16394 #ifdef RTE_LIBRTE_I40E_PMD
16395         mapping.hw_ptype = res->hw_ptype;
16396         mapping.sw_ptype = res->sw_ptype;
16397         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16398                                                 &mapping,
16399                                                 1,
16400                                                 0);
16401 #endif
16402
16403         switch (ret) {
16404         case 0:
16405                 break;
16406         case -EINVAL:
16407                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16408                 break;
16409         case -ENODEV:
16410                 printf("invalid port_id %d\n", res->port_id);
16411                 break;
16412         case -ENOTSUP:
16413                 printf("function not implemented\n");
16414                 break;
16415         default:
16416                 printf("programming error: (%s)\n", strerror(-ret));
16417         }
16418 }
16419
16420 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16421         .f = cmd_ptype_mapping_update_parsed,
16422         .data = NULL,
16423         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16424         .tokens = {
16425                 (void *)&cmd_ptype_mapping_update_ptype,
16426                 (void *)&cmd_ptype_mapping_update_mapping,
16427                 (void *)&cmd_ptype_mapping_update_update,
16428                 (void *)&cmd_ptype_mapping_update_port_id,
16429                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16430                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16431                 NULL,
16432         },
16433 };
16434
16435 /* Common result structure for file commands */
16436 struct cmd_cmdfile_result {
16437         cmdline_fixed_string_t load;
16438         cmdline_fixed_string_t filename;
16439 };
16440
16441 /* Common CLI fields for file commands */
16442 cmdline_parse_token_string_t cmd_load_cmdfile =
16443         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16444 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16445         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16446
16447 static void
16448 cmd_load_from_file_parsed(
16449         void *parsed_result,
16450         __attribute__((unused)) struct cmdline *cl,
16451         __attribute__((unused)) void *data)
16452 {
16453         struct cmd_cmdfile_result *res = parsed_result;
16454
16455         cmdline_read_from_file(res->filename);
16456 }
16457
16458 cmdline_parse_inst_t cmd_load_from_file = {
16459         .f = cmd_load_from_file_parsed,
16460         .data = NULL,
16461         .help_str = "load <filename>",
16462         .tokens = {
16463                 (void *)&cmd_load_cmdfile,
16464                 (void *)&cmd_load_cmdfile_filename,
16465                 NULL,
16466         },
16467 };
16468
16469 /* Get Rx offloads capabilities */
16470 struct cmd_rx_offload_get_capa_result {
16471         cmdline_fixed_string_t show;
16472         cmdline_fixed_string_t port;
16473         portid_t port_id;
16474         cmdline_fixed_string_t rx_offload;
16475         cmdline_fixed_string_t capabilities;
16476 };
16477
16478 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16479         TOKEN_STRING_INITIALIZER
16480                 (struct cmd_rx_offload_get_capa_result,
16481                  show, "show");
16482 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16483         TOKEN_STRING_INITIALIZER
16484                 (struct cmd_rx_offload_get_capa_result,
16485                  port, "port");
16486 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16487         TOKEN_NUM_INITIALIZER
16488                 (struct cmd_rx_offload_get_capa_result,
16489                  port_id, UINT16);
16490 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16491         TOKEN_STRING_INITIALIZER
16492                 (struct cmd_rx_offload_get_capa_result,
16493                  rx_offload, "rx_offload");
16494 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16495         TOKEN_STRING_INITIALIZER
16496                 (struct cmd_rx_offload_get_capa_result,
16497                  capabilities, "capabilities");
16498
16499 static void
16500 print_rx_offloads(uint64_t offloads)
16501 {
16502         uint64_t single_offload;
16503         int begin;
16504         int end;
16505         int bit;
16506
16507         if (offloads == 0)
16508                 return;
16509
16510         begin = __builtin_ctzll(offloads);
16511         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16512
16513         single_offload = 1 << begin;
16514         for (bit = begin; bit < end; bit++) {
16515                 if (offloads & single_offload)
16516                         printf(" %s",
16517                                rte_eth_dev_rx_offload_name(single_offload));
16518                 single_offload <<= 1;
16519         }
16520 }
16521
16522 static void
16523 cmd_rx_offload_get_capa_parsed(
16524         void *parsed_result,
16525         __attribute__((unused)) struct cmdline *cl,
16526         __attribute__((unused)) void *data)
16527 {
16528         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16529         struct rte_eth_dev_info dev_info;
16530         portid_t port_id = res->port_id;
16531         uint64_t queue_offloads;
16532         uint64_t port_offloads;
16533
16534         rte_eth_dev_info_get(port_id, &dev_info);
16535         queue_offloads = dev_info.rx_queue_offload_capa;
16536         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16537
16538         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16539         printf("  Per Queue :");
16540         print_rx_offloads(queue_offloads);
16541
16542         printf("\n");
16543         printf("  Per Port  :");
16544         print_rx_offloads(port_offloads);
16545         printf("\n\n");
16546 }
16547
16548 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16549         .f = cmd_rx_offload_get_capa_parsed,
16550         .data = NULL,
16551         .help_str = "show port <port_id> rx_offload capabilities",
16552         .tokens = {
16553                 (void *)&cmd_rx_offload_get_capa_show,
16554                 (void *)&cmd_rx_offload_get_capa_port,
16555                 (void *)&cmd_rx_offload_get_capa_port_id,
16556                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16557                 (void *)&cmd_rx_offload_get_capa_capabilities,
16558                 NULL,
16559         }
16560 };
16561
16562 /* Get Rx offloads configuration */
16563 struct cmd_rx_offload_get_configuration_result {
16564         cmdline_fixed_string_t show;
16565         cmdline_fixed_string_t port;
16566         portid_t port_id;
16567         cmdline_fixed_string_t rx_offload;
16568         cmdline_fixed_string_t configuration;
16569 };
16570
16571 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16572         TOKEN_STRING_INITIALIZER
16573                 (struct cmd_rx_offload_get_configuration_result,
16574                  show, "show");
16575 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16576         TOKEN_STRING_INITIALIZER
16577                 (struct cmd_rx_offload_get_configuration_result,
16578                  port, "port");
16579 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16580         TOKEN_NUM_INITIALIZER
16581                 (struct cmd_rx_offload_get_configuration_result,
16582                  port_id, UINT16);
16583 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16584         TOKEN_STRING_INITIALIZER
16585                 (struct cmd_rx_offload_get_configuration_result,
16586                  rx_offload, "rx_offload");
16587 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16588         TOKEN_STRING_INITIALIZER
16589                 (struct cmd_rx_offload_get_configuration_result,
16590                  configuration, "configuration");
16591
16592 static void
16593 cmd_rx_offload_get_configuration_parsed(
16594         void *parsed_result,
16595         __attribute__((unused)) struct cmdline *cl,
16596         __attribute__((unused)) void *data)
16597 {
16598         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16599         struct rte_eth_dev_info dev_info;
16600         portid_t port_id = res->port_id;
16601         struct rte_port *port = &ports[port_id];
16602         uint64_t port_offloads;
16603         uint64_t queue_offloads;
16604         uint16_t nb_rx_queues;
16605         int q;
16606
16607         printf("Rx Offloading Configuration of port %d :\n", port_id);
16608
16609         port_offloads = port->dev_conf.rxmode.offloads;
16610         printf("  Port :");
16611         print_rx_offloads(port_offloads);
16612         printf("\n");
16613
16614         rte_eth_dev_info_get(port_id, &dev_info);
16615         nb_rx_queues = dev_info.nb_rx_queues;
16616         for (q = 0; q < nb_rx_queues; q++) {
16617                 queue_offloads = port->rx_conf[q].offloads;
16618                 printf("  Queue[%2d] :", q);
16619                 print_rx_offloads(queue_offloads);
16620                 printf("\n");
16621         }
16622         printf("\n");
16623 }
16624
16625 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16626         .f = cmd_rx_offload_get_configuration_parsed,
16627         .data = NULL,
16628         .help_str = "show port <port_id> rx_offload configuration",
16629         .tokens = {
16630                 (void *)&cmd_rx_offload_get_configuration_show,
16631                 (void *)&cmd_rx_offload_get_configuration_port,
16632                 (void *)&cmd_rx_offload_get_configuration_port_id,
16633                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16634                 (void *)&cmd_rx_offload_get_configuration_configuration,
16635                 NULL,
16636         }
16637 };
16638
16639 /* Enable/Disable a per port offloading */
16640 struct cmd_config_per_port_rx_offload_result {
16641         cmdline_fixed_string_t port;
16642         cmdline_fixed_string_t config;
16643         portid_t port_id;
16644         cmdline_fixed_string_t rx_offload;
16645         cmdline_fixed_string_t offload;
16646         cmdline_fixed_string_t on_off;
16647 };
16648
16649 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16650         TOKEN_STRING_INITIALIZER
16651                 (struct cmd_config_per_port_rx_offload_result,
16652                  port, "port");
16653 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16654         TOKEN_STRING_INITIALIZER
16655                 (struct cmd_config_per_port_rx_offload_result,
16656                  config, "config");
16657 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16658         TOKEN_NUM_INITIALIZER
16659                 (struct cmd_config_per_port_rx_offload_result,
16660                  port_id, UINT16);
16661 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16662         TOKEN_STRING_INITIALIZER
16663                 (struct cmd_config_per_port_rx_offload_result,
16664                  rx_offload, "rx_offload");
16665 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16666         TOKEN_STRING_INITIALIZER
16667                 (struct cmd_config_per_port_rx_offload_result,
16668                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16669                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16670                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16671                            "crc_strip#scatter#timestamp#security");
16672 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16673         TOKEN_STRING_INITIALIZER
16674                 (struct cmd_config_per_port_rx_offload_result,
16675                  on_off, "on#off");
16676
16677 static uint64_t
16678 search_rx_offload(const char *name)
16679 {
16680         uint64_t single_offload;
16681         const char *single_name;
16682         int found = 0;
16683         unsigned int bit;
16684
16685         single_offload = 1;
16686         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16687                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16688                 if (!strcasecmp(single_name, name)) {
16689                         found = 1;
16690                         break;
16691                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16692                         break;
16693                 else if (single_name == NULL)
16694                         break;
16695                 single_offload <<= 1;
16696         }
16697
16698         if (found)
16699                 return single_offload;
16700
16701         return 0;
16702 }
16703
16704 static void
16705 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16706                                 __attribute__((unused)) struct cmdline *cl,
16707                                 __attribute__((unused)) void *data)
16708 {
16709         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16710         portid_t port_id = res->port_id;
16711         struct rte_eth_dev_info dev_info;
16712         struct rte_port *port = &ports[port_id];
16713         uint64_t single_offload;
16714         uint16_t nb_rx_queues;
16715         int q;
16716
16717         if (port->port_status != RTE_PORT_STOPPED) {
16718                 printf("Error: Can't config offload when Port %d "
16719                        "is not stopped\n", port_id);
16720                 return;
16721         }
16722
16723         single_offload = search_rx_offload(res->offload);
16724         if (single_offload == 0) {
16725                 printf("Unknown offload name: %s\n", res->offload);
16726                 return;
16727         }
16728
16729         rte_eth_dev_info_get(port_id, &dev_info);
16730         nb_rx_queues = dev_info.nb_rx_queues;
16731         if (!strcmp(res->on_off, "on")) {
16732                 port->dev_conf.rxmode.offloads |= single_offload;
16733                 for (q = 0; q < nb_rx_queues; q++)
16734                         port->rx_conf[q].offloads |= single_offload;
16735         } else {
16736                 port->dev_conf.rxmode.offloads &= ~single_offload;
16737                 for (q = 0; q < nb_rx_queues; q++)
16738                         port->rx_conf[q].offloads &= ~single_offload;
16739         }
16740
16741         cmd_reconfig_device_queue(port_id, 1, 1);
16742 }
16743
16744 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16745         .f = cmd_config_per_port_rx_offload_parsed,
16746         .data = NULL,
16747         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16748                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16749                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16750                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16751                     "on|off",
16752         .tokens = {
16753                 (void *)&cmd_config_per_port_rx_offload_result_port,
16754                 (void *)&cmd_config_per_port_rx_offload_result_config,
16755                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16756                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16757                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16758                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16759                 NULL,
16760         }
16761 };
16762
16763 /* Enable/Disable a per queue offloading */
16764 struct cmd_config_per_queue_rx_offload_result {
16765         cmdline_fixed_string_t port;
16766         portid_t port_id;
16767         cmdline_fixed_string_t rxq;
16768         uint16_t queue_id;
16769         cmdline_fixed_string_t rx_offload;
16770         cmdline_fixed_string_t offload;
16771         cmdline_fixed_string_t on_off;
16772 };
16773
16774 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16775         TOKEN_STRING_INITIALIZER
16776                 (struct cmd_config_per_queue_rx_offload_result,
16777                  port, "port");
16778 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16779         TOKEN_NUM_INITIALIZER
16780                 (struct cmd_config_per_queue_rx_offload_result,
16781                  port_id, UINT16);
16782 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16783         TOKEN_STRING_INITIALIZER
16784                 (struct cmd_config_per_queue_rx_offload_result,
16785                  rxq, "rxq");
16786 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16787         TOKEN_NUM_INITIALIZER
16788                 (struct cmd_config_per_queue_rx_offload_result,
16789                  queue_id, UINT16);
16790 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16791         TOKEN_STRING_INITIALIZER
16792                 (struct cmd_config_per_queue_rx_offload_result,
16793                  rx_offload, "rx_offload");
16794 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16795         TOKEN_STRING_INITIALIZER
16796                 (struct cmd_config_per_queue_rx_offload_result,
16797                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16798                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16799                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16800                            "crc_strip#scatter#timestamp#security");
16801 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16802         TOKEN_STRING_INITIALIZER
16803                 (struct cmd_config_per_queue_rx_offload_result,
16804                  on_off, "on#off");
16805
16806 static void
16807 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16808                                 __attribute__((unused)) struct cmdline *cl,
16809                                 __attribute__((unused)) void *data)
16810 {
16811         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16812         struct rte_eth_dev_info dev_info;
16813         portid_t port_id = res->port_id;
16814         uint16_t queue_id = res->queue_id;
16815         struct rte_port *port = &ports[port_id];
16816         uint64_t single_offload;
16817
16818         if (port->port_status != RTE_PORT_STOPPED) {
16819                 printf("Error: Can't config offload when Port %d "
16820                        "is not stopped\n", port_id);
16821                 return;
16822         }
16823
16824         rte_eth_dev_info_get(port_id, &dev_info);
16825         if (queue_id >= dev_info.nb_rx_queues) {
16826                 printf("Error: input queue_id should be 0 ... "
16827                        "%d\n", dev_info.nb_rx_queues - 1);
16828                 return;
16829         }
16830
16831         single_offload = search_rx_offload(res->offload);
16832         if (single_offload == 0) {
16833                 printf("Unknown offload name: %s\n", res->offload);
16834                 return;
16835         }
16836
16837         if (!strcmp(res->on_off, "on"))
16838                 port->rx_conf[queue_id].offloads |= single_offload;
16839         else
16840                 port->rx_conf[queue_id].offloads &= ~single_offload;
16841
16842         cmd_reconfig_device_queue(port_id, 1, 1);
16843 }
16844
16845 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16846         .f = cmd_config_per_queue_rx_offload_parsed,
16847         .data = NULL,
16848         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16849                     "vlan_strip|ipv4_cksum|"
16850                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16851                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16852                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16853                     "on|off",
16854         .tokens = {
16855                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16856                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16857                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16858                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16859                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16860                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16861                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16862                 NULL,
16863         }
16864 };
16865
16866 /* Get Tx offloads capabilities */
16867 struct cmd_tx_offload_get_capa_result {
16868         cmdline_fixed_string_t show;
16869         cmdline_fixed_string_t port;
16870         portid_t port_id;
16871         cmdline_fixed_string_t tx_offload;
16872         cmdline_fixed_string_t capabilities;
16873 };
16874
16875 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16876         TOKEN_STRING_INITIALIZER
16877                 (struct cmd_tx_offload_get_capa_result,
16878                  show, "show");
16879 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16880         TOKEN_STRING_INITIALIZER
16881                 (struct cmd_tx_offload_get_capa_result,
16882                  port, "port");
16883 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16884         TOKEN_NUM_INITIALIZER
16885                 (struct cmd_tx_offload_get_capa_result,
16886                  port_id, UINT16);
16887 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16888         TOKEN_STRING_INITIALIZER
16889                 (struct cmd_tx_offload_get_capa_result,
16890                  tx_offload, "tx_offload");
16891 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16892         TOKEN_STRING_INITIALIZER
16893                 (struct cmd_tx_offload_get_capa_result,
16894                  capabilities, "capabilities");
16895
16896 static void
16897 print_tx_offloads(uint64_t offloads)
16898 {
16899         uint64_t single_offload;
16900         int begin;
16901         int end;
16902         int bit;
16903
16904         if (offloads == 0)
16905                 return;
16906
16907         begin = __builtin_ctzll(offloads);
16908         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16909
16910         single_offload = 1 << begin;
16911         for (bit = begin; bit < end; bit++) {
16912                 if (offloads & single_offload)
16913                         printf(" %s",
16914                                rte_eth_dev_tx_offload_name(single_offload));
16915                 single_offload <<= 1;
16916         }
16917 }
16918
16919 static void
16920 cmd_tx_offload_get_capa_parsed(
16921         void *parsed_result,
16922         __attribute__((unused)) struct cmdline *cl,
16923         __attribute__((unused)) void *data)
16924 {
16925         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16926         struct rte_eth_dev_info dev_info;
16927         portid_t port_id = res->port_id;
16928         uint64_t queue_offloads;
16929         uint64_t port_offloads;
16930
16931         rte_eth_dev_info_get(port_id, &dev_info);
16932         queue_offloads = dev_info.tx_queue_offload_capa;
16933         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16934
16935         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16936         printf("  Per Queue :");
16937         print_tx_offloads(queue_offloads);
16938
16939         printf("\n");
16940         printf("  Per Port  :");
16941         print_tx_offloads(port_offloads);
16942         printf("\n\n");
16943 }
16944
16945 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16946         .f = cmd_tx_offload_get_capa_parsed,
16947         .data = NULL,
16948         .help_str = "show port <port_id> tx_offload capabilities",
16949         .tokens = {
16950                 (void *)&cmd_tx_offload_get_capa_show,
16951                 (void *)&cmd_tx_offload_get_capa_port,
16952                 (void *)&cmd_tx_offload_get_capa_port_id,
16953                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16954                 (void *)&cmd_tx_offload_get_capa_capabilities,
16955                 NULL,
16956         }
16957 };
16958
16959 /* Get Tx offloads configuration */
16960 struct cmd_tx_offload_get_configuration_result {
16961         cmdline_fixed_string_t show;
16962         cmdline_fixed_string_t port;
16963         portid_t port_id;
16964         cmdline_fixed_string_t tx_offload;
16965         cmdline_fixed_string_t configuration;
16966 };
16967
16968 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16969         TOKEN_STRING_INITIALIZER
16970                 (struct cmd_tx_offload_get_configuration_result,
16971                  show, "show");
16972 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16973         TOKEN_STRING_INITIALIZER
16974                 (struct cmd_tx_offload_get_configuration_result,
16975                  port, "port");
16976 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16977         TOKEN_NUM_INITIALIZER
16978                 (struct cmd_tx_offload_get_configuration_result,
16979                  port_id, UINT16);
16980 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16981         TOKEN_STRING_INITIALIZER
16982                 (struct cmd_tx_offload_get_configuration_result,
16983                  tx_offload, "tx_offload");
16984 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16985         TOKEN_STRING_INITIALIZER
16986                 (struct cmd_tx_offload_get_configuration_result,
16987                  configuration, "configuration");
16988
16989 static void
16990 cmd_tx_offload_get_configuration_parsed(
16991         void *parsed_result,
16992         __attribute__((unused)) struct cmdline *cl,
16993         __attribute__((unused)) void *data)
16994 {
16995         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16996         struct rte_eth_dev_info dev_info;
16997         portid_t port_id = res->port_id;
16998         struct rte_port *port = &ports[port_id];
16999         uint64_t port_offloads;
17000         uint64_t queue_offloads;
17001         uint16_t nb_tx_queues;
17002         int q;
17003
17004         printf("Tx Offloading Configuration of port %d :\n", port_id);
17005
17006         port_offloads = port->dev_conf.txmode.offloads;
17007         printf("  Port :");
17008         print_tx_offloads(port_offloads);
17009         printf("\n");
17010
17011         rte_eth_dev_info_get(port_id, &dev_info);
17012         nb_tx_queues = dev_info.nb_tx_queues;
17013         for (q = 0; q < nb_tx_queues; q++) {
17014                 queue_offloads = port->tx_conf[q].offloads;
17015                 printf("  Queue[%2d] :", q);
17016                 print_tx_offloads(queue_offloads);
17017                 printf("\n");
17018         }
17019         printf("\n");
17020 }
17021
17022 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17023         .f = cmd_tx_offload_get_configuration_parsed,
17024         .data = NULL,
17025         .help_str = "show port <port_id> tx_offload configuration",
17026         .tokens = {
17027                 (void *)&cmd_tx_offload_get_configuration_show,
17028                 (void *)&cmd_tx_offload_get_configuration_port,
17029                 (void *)&cmd_tx_offload_get_configuration_port_id,
17030                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17031                 (void *)&cmd_tx_offload_get_configuration_configuration,
17032                 NULL,
17033         }
17034 };
17035
17036 /* Enable/Disable a per port offloading */
17037 struct cmd_config_per_port_tx_offload_result {
17038         cmdline_fixed_string_t port;
17039         cmdline_fixed_string_t config;
17040         portid_t port_id;
17041         cmdline_fixed_string_t tx_offload;
17042         cmdline_fixed_string_t offload;
17043         cmdline_fixed_string_t on_off;
17044 };
17045
17046 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17047         TOKEN_STRING_INITIALIZER
17048                 (struct cmd_config_per_port_tx_offload_result,
17049                  port, "port");
17050 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17051         TOKEN_STRING_INITIALIZER
17052                 (struct cmd_config_per_port_tx_offload_result,
17053                  config, "config");
17054 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17055         TOKEN_NUM_INITIALIZER
17056                 (struct cmd_config_per_port_tx_offload_result,
17057                  port_id, UINT16);
17058 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17059         TOKEN_STRING_INITIALIZER
17060                 (struct cmd_config_per_port_tx_offload_result,
17061                  tx_offload, "tx_offload");
17062 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17063         TOKEN_STRING_INITIALIZER
17064                 (struct cmd_config_per_port_tx_offload_result,
17065                  offload, "vlan_insert#ipv4_cksum#udp_cksum#udp_cksum#"
17066                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17067                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17068                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17069                           "mt_lockfree#multi_segs#fast_free#security");
17070 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17071         TOKEN_STRING_INITIALIZER
17072                 (struct cmd_config_per_port_tx_offload_result,
17073                  on_off, "on#off");
17074
17075 static uint64_t
17076 search_tx_offload(const char *name)
17077 {
17078         uint64_t single_offload;
17079         const char *single_name;
17080         int found = 0;
17081         unsigned int bit;
17082
17083         single_offload = 1;
17084         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17085                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17086                 if (!strcasecmp(single_name, name)) {
17087                         found = 1;
17088                         break;
17089                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17090                         break;
17091                 else if (single_name == NULL)
17092                         break;
17093                 single_offload <<= 1;
17094         }
17095
17096         if (found)
17097                 return single_offload;
17098
17099         return 0;
17100 }
17101
17102 static void
17103 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17104                                 __attribute__((unused)) struct cmdline *cl,
17105                                 __attribute__((unused)) void *data)
17106 {
17107         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17108         portid_t port_id = res->port_id;
17109         struct rte_eth_dev_info dev_info;
17110         struct rte_port *port = &ports[port_id];
17111         uint64_t single_offload;
17112         uint16_t nb_tx_queues;
17113         int q;
17114
17115         if (port->port_status != RTE_PORT_STOPPED) {
17116                 printf("Error: Can't config offload when Port %d "
17117                        "is not stopped\n", port_id);
17118                 return;
17119         }
17120
17121         single_offload = search_tx_offload(res->offload);
17122         if (single_offload == 0) {
17123                 printf("Unknown offload name: %s\n", res->offload);
17124                 return;
17125         }
17126
17127         rte_eth_dev_info_get(port_id, &dev_info);
17128         nb_tx_queues = dev_info.nb_tx_queues;
17129         if (!strcmp(res->on_off, "on")) {
17130                 port->dev_conf.txmode.offloads |= single_offload;
17131                 for (q = 0; q < nb_tx_queues; q++)
17132                         port->tx_conf[q].offloads |= single_offload;
17133         } else {
17134                 port->dev_conf.txmode.offloads &= ~single_offload;
17135                 for (q = 0; q < nb_tx_queues; q++)
17136                         port->tx_conf[q].offloads &= ~single_offload;
17137         }
17138
17139         cmd_reconfig_device_queue(port_id, 1, 1);
17140 }
17141
17142 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17143         .f = cmd_config_per_port_tx_offload_parsed,
17144         .data = NULL,
17145         .help_str = "port config <port_id> tx_offload "
17146                     "vlan_insert|ipv4_cksum|udp_cksum|udp_cksum|"
17147                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17148                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17149                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17150                     "mt_lockfree|multi_segs|fast_free|security "
17151                     "on|off",
17152         .tokens = {
17153                 (void *)&cmd_config_per_port_tx_offload_result_port,
17154                 (void *)&cmd_config_per_port_tx_offload_result_config,
17155                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17156                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17157                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17158                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17159                 NULL,
17160         }
17161 };
17162
17163 /* Enable/Disable a per queue offloading */
17164 struct cmd_config_per_queue_tx_offload_result {
17165         cmdline_fixed_string_t port;
17166         portid_t port_id;
17167         cmdline_fixed_string_t txq;
17168         uint16_t queue_id;
17169         cmdline_fixed_string_t tx_offload;
17170         cmdline_fixed_string_t offload;
17171         cmdline_fixed_string_t on_off;
17172 };
17173
17174 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17175         TOKEN_STRING_INITIALIZER
17176                 (struct cmd_config_per_queue_tx_offload_result,
17177                  port, "port");
17178 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17179         TOKEN_NUM_INITIALIZER
17180                 (struct cmd_config_per_queue_tx_offload_result,
17181                  port_id, UINT16);
17182 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17183         TOKEN_STRING_INITIALIZER
17184                 (struct cmd_config_per_queue_tx_offload_result,
17185                  txq, "txq");
17186 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17187         TOKEN_NUM_INITIALIZER
17188                 (struct cmd_config_per_queue_tx_offload_result,
17189                  queue_id, UINT16);
17190 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17191         TOKEN_STRING_INITIALIZER
17192                 (struct cmd_config_per_queue_tx_offload_result,
17193                  tx_offload, "tx_offload");
17194 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17195         TOKEN_STRING_INITIALIZER
17196                 (struct cmd_config_per_queue_tx_offload_result,
17197                  offload, "vlan_insert#ipv4_cksum#udp_cksum#udp_cksum#"
17198                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17199                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17200                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17201                           "mt_lockfree#multi_segs#fast_free#security");
17202 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17203         TOKEN_STRING_INITIALIZER
17204                 (struct cmd_config_per_queue_tx_offload_result,
17205                  on_off, "on#off");
17206
17207 static void
17208 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17209                                 __attribute__((unused)) struct cmdline *cl,
17210                                 __attribute__((unused)) void *data)
17211 {
17212         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17213         struct rte_eth_dev_info dev_info;
17214         portid_t port_id = res->port_id;
17215         uint16_t queue_id = res->queue_id;
17216         struct rte_port *port = &ports[port_id];
17217         uint64_t single_offload;
17218
17219         if (port->port_status != RTE_PORT_STOPPED) {
17220                 printf("Error: Can't config offload when Port %d "
17221                        "is not stopped\n", port_id);
17222                 return;
17223         }
17224
17225         rte_eth_dev_info_get(port_id, &dev_info);
17226         if (queue_id >= dev_info.nb_tx_queues) {
17227                 printf("Error: input queue_id should be 0 ... "
17228                        "%d\n", dev_info.nb_tx_queues - 1);
17229                 return;
17230         }
17231
17232         single_offload = search_tx_offload(res->offload);
17233         if (single_offload == 0) {
17234                 printf("Unknown offload name: %s\n", res->offload);
17235                 return;
17236         }
17237
17238         if (!strcmp(res->on_off, "on"))
17239                 port->tx_conf[queue_id].offloads |= single_offload;
17240         else
17241                 port->tx_conf[queue_id].offloads &= ~single_offload;
17242
17243         cmd_reconfig_device_queue(port_id, 1, 1);
17244 }
17245
17246 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17247         .f = cmd_config_per_queue_tx_offload_parsed,
17248         .data = NULL,
17249         .help_str = "port <port_id> txq <queue_id> tx_offload "
17250                     "vlan_insert|ipv4_cksum|udp_cksum|udp_cksum|"
17251                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17252                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17253                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17254                     "mt_lockfree|multi_segs|fast_free|security "
17255                     "on|off",
17256         .tokens = {
17257                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17258                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17259                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17260                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17261                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17262                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17263                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17264                 NULL,
17265         }
17266 };
17267
17268 /* ******************************************************************************** */
17269
17270 /* list of instructions */
17271 cmdline_parse_ctx_t main_ctx[] = {
17272         (cmdline_parse_inst_t *)&cmd_help_brief,
17273         (cmdline_parse_inst_t *)&cmd_help_long,
17274         (cmdline_parse_inst_t *)&cmd_quit,
17275         (cmdline_parse_inst_t *)&cmd_load_from_file,
17276         (cmdline_parse_inst_t *)&cmd_showport,
17277         (cmdline_parse_inst_t *)&cmd_showqueue,
17278         (cmdline_parse_inst_t *)&cmd_showportall,
17279         (cmdline_parse_inst_t *)&cmd_showcfg,
17280         (cmdline_parse_inst_t *)&cmd_start,
17281         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17282         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17283         (cmdline_parse_inst_t *)&cmd_set_link_up,
17284         (cmdline_parse_inst_t *)&cmd_set_link_down,
17285         (cmdline_parse_inst_t *)&cmd_reset,
17286         (cmdline_parse_inst_t *)&cmd_set_numbers,
17287         (cmdline_parse_inst_t *)&cmd_set_log,
17288         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17289         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17290         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17291         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17292         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17293         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17294         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17295         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17296         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17297         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17298         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17299         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17300         (cmdline_parse_inst_t *)&cmd_set_link_check,
17301         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17302         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17303         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17304         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17305 #ifdef RTE_LIBRTE_PMD_BOND
17306         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17307         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17308         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17309         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17310         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17311         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17312         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17313         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17314         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17315         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17316         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17317 #endif
17318         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17319         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17320         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17321         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17322         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17323         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17324         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17325         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17326         (cmdline_parse_inst_t *)&cmd_csum_set,
17327         (cmdline_parse_inst_t *)&cmd_csum_show,
17328         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17329         (cmdline_parse_inst_t *)&cmd_tso_set,
17330         (cmdline_parse_inst_t *)&cmd_tso_show,
17331         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17332         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17333         (cmdline_parse_inst_t *)&cmd_gro_enable,
17334         (cmdline_parse_inst_t *)&cmd_gro_flush,
17335         (cmdline_parse_inst_t *)&cmd_gro_show,
17336         (cmdline_parse_inst_t *)&cmd_gso_enable,
17337         (cmdline_parse_inst_t *)&cmd_gso_size,
17338         (cmdline_parse_inst_t *)&cmd_gso_show,
17339         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17340         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17341         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17342         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17343         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17344         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17345         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17346         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17347         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17348         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17349         (cmdline_parse_inst_t *)&cmd_config_dcb,
17350         (cmdline_parse_inst_t *)&cmd_read_reg,
17351         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17352         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17353         (cmdline_parse_inst_t *)&cmd_write_reg,
17354         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17355         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17356         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17357         (cmdline_parse_inst_t *)&cmd_stop,
17358         (cmdline_parse_inst_t *)&cmd_mac_addr,
17359         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17360         (cmdline_parse_inst_t *)&cmd_set_qmap,
17361         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17362         (cmdline_parse_inst_t *)&cmd_operate_port,
17363         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17364         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17365         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17366         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17367         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17368         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17369         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17370         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17371         (cmdline_parse_inst_t *)&cmd_config_mtu,
17372         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17373         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17374         (cmdline_parse_inst_t *)&cmd_config_rss,
17375         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17376         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17377         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17378         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17379         (cmdline_parse_inst_t *)&cmd_showport_reta,
17380         (cmdline_parse_inst_t *)&cmd_config_burst,
17381         (cmdline_parse_inst_t *)&cmd_config_thresh,
17382         (cmdline_parse_inst_t *)&cmd_config_threshold,
17383         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17384         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17385         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17386         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17387         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17388         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17389         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17390         (cmdline_parse_inst_t *)&cmd_global_config,
17391         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17392         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17393         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17394         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17395         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17396         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17397         (cmdline_parse_inst_t *)&cmd_dump,
17398         (cmdline_parse_inst_t *)&cmd_dump_one,
17399         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17400         (cmdline_parse_inst_t *)&cmd_syn_filter,
17401         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17402         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17403         (cmdline_parse_inst_t *)&cmd_flex_filter,
17404         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17405         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17406         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17407         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17408         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17409         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17410         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17411         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17412         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17413         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17414         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17415         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17416         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17417         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17418         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17419         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17420         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17421         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17422         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17423         (cmdline_parse_inst_t *)&cmd_flow,
17424         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17425         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17426         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17427         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17428         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17429         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17430         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17431         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17432         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17433         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17434         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17435         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17436         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17437         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17438         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17439         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17440         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17441         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17442         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17443         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17444         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17445         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17446         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17447         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17448         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17449         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17450         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17451         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17452         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17453         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17454         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17455         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17456         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17457         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17458         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17459         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17460         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17461         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17462         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17463         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17464         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17465         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17466         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17467         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17468         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17469         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17470         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17471         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17472         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17473 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17474         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17475 #endif
17476         (cmdline_parse_inst_t *)&cmd_ddp_add,
17477         (cmdline_parse_inst_t *)&cmd_ddp_del,
17478         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17479         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17480         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17481         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17482         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17483         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17484         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17485         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17486         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17487         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17488
17489         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17490         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17491         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17492         (cmdline_parse_inst_t *)&cmd_queue_region,
17493         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17494         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17495         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17496         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17497         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17498         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17499         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17500         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17501         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17502         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17503         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17504         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17505         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17506         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17507         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17508         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17509         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17510         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17511         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17512         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17513         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17514         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17515         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17516         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17517         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17518         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17519         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17520         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17521         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17522         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17523         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17524         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17525 #ifdef RTE_LIBRTE_BPF
17526         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17527         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17528 #endif
17529         NULL,
17530 };
17531
17532 /* read cmdline commands from file */
17533 void
17534 cmdline_read_from_file(const char *filename)
17535 {
17536         struct cmdline *cl;
17537
17538         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17539         if (cl == NULL) {
17540                 printf("Failed to create file based cmdline context: %s\n",
17541                        filename);
17542                 return;
17543         }
17544
17545         cmdline_interact(cl);
17546         cmdline_quit(cl);
17547
17548         cmdline_free(cl);
17549
17550         printf("Read CLI commands from %s\n", filename);
17551 }
17552
17553 /* prompt function, called from main on MASTER lcore */
17554 void
17555 prompt(void)
17556 {
17557         /* initialize non-constant commands */
17558         cmd_set_fwd_mode_init();
17559         cmd_set_fwd_retry_mode_init();
17560
17561         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17562         if (testpmd_cl == NULL)
17563                 return;
17564         cmdline_interact(testpmd_cl);
17565         cmdline_stdin_exit(testpmd_cl);
17566 }
17567
17568 void
17569 prompt_exit(void)
17570 {
17571         if (testpmd_cl != NULL)
17572                 cmdline_quit(testpmd_cl);
17573 }
17574
17575 static void
17576 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17577 {
17578         if (id == (portid_t)RTE_PORT_ALL) {
17579                 portid_t pid;
17580
17581                 RTE_ETH_FOREACH_DEV(pid) {
17582                         /* check if need_reconfig has been set to 1 */
17583                         if (ports[pid].need_reconfig == 0)
17584                                 ports[pid].need_reconfig = dev;
17585                         /* check if need_reconfig_queues has been set to 1 */
17586                         if (ports[pid].need_reconfig_queues == 0)
17587                                 ports[pid].need_reconfig_queues = queue;
17588                 }
17589         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17590                 /* check if need_reconfig has been set to 1 */
17591                 if (ports[id].need_reconfig == 0)
17592                         ports[id].need_reconfig = dev;
17593                 /* check if need_reconfig_queues has been set to 1 */
17594                 if (ports[id].need_reconfig_queues == 0)
17595                         ports[id].need_reconfig_queues = queue;
17596         }
17597 }