net/fm10k: remove unused constant
[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                 if (use_default) {
2062                         rte_eth_dev_info_get(i, &dev_info);
2063                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2064                 }
2065                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
2066                 if (diag < 0) {
2067                         all_updated = 0;
2068                         printf("Configuration of RSS hash at ethernet port %d "
2069                                 "failed with error (%d): %s.\n",
2070                                 i, -diag, strerror(-diag));
2071                 }
2072         }
2073         if (all_updated && !use_default)
2074                 rss_hf = rss_conf.rss_hf;
2075 }
2076
2077 cmdline_parse_token_string_t cmd_config_rss_port =
2078         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2079 cmdline_parse_token_string_t cmd_config_rss_keyword =
2080         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2081 cmdline_parse_token_string_t cmd_config_rss_all =
2082         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2083 cmdline_parse_token_string_t cmd_config_rss_name =
2084         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2085 cmdline_parse_token_string_t cmd_config_rss_value =
2086         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2087
2088 cmdline_parse_inst_t cmd_config_rss = {
2089         .f = cmd_config_rss_parsed,
2090         .data = NULL,
2091         .help_str = "port config all rss "
2092                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2093         .tokens = {
2094                 (void *)&cmd_config_rss_port,
2095                 (void *)&cmd_config_rss_keyword,
2096                 (void *)&cmd_config_rss_all,
2097                 (void *)&cmd_config_rss_name,
2098                 (void *)&cmd_config_rss_value,
2099                 NULL,
2100         },
2101 };
2102
2103 /* *** configure rss hash key *** */
2104 struct cmd_config_rss_hash_key {
2105         cmdline_fixed_string_t port;
2106         cmdline_fixed_string_t config;
2107         portid_t port_id;
2108         cmdline_fixed_string_t rss_hash_key;
2109         cmdline_fixed_string_t rss_type;
2110         cmdline_fixed_string_t key;
2111 };
2112
2113 static uint8_t
2114 hexa_digit_to_value(char hexa_digit)
2115 {
2116         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2117                 return (uint8_t) (hexa_digit - '0');
2118         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2119                 return (uint8_t) ((hexa_digit - 'a') + 10);
2120         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2121                 return (uint8_t) ((hexa_digit - 'A') + 10);
2122         /* Invalid hexa digit */
2123         return 0xFF;
2124 }
2125
2126 static uint8_t
2127 parse_and_check_key_hexa_digit(char *key, int idx)
2128 {
2129         uint8_t hexa_v;
2130
2131         hexa_v = hexa_digit_to_value(key[idx]);
2132         if (hexa_v == 0xFF)
2133                 printf("invalid key: character %c at position %d is not a "
2134                        "valid hexa digit\n", key[idx], idx);
2135         return hexa_v;
2136 }
2137
2138 static void
2139 cmd_config_rss_hash_key_parsed(void *parsed_result,
2140                                __attribute__((unused)) struct cmdline *cl,
2141                                __attribute__((unused)) void *data)
2142 {
2143         struct cmd_config_rss_hash_key *res = parsed_result;
2144         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2145         uint8_t xdgt0;
2146         uint8_t xdgt1;
2147         int i;
2148         struct rte_eth_dev_info dev_info;
2149         uint8_t hash_key_size;
2150         uint32_t key_len;
2151
2152         memset(&dev_info, 0, sizeof(dev_info));
2153         rte_eth_dev_info_get(res->port_id, &dev_info);
2154         if (dev_info.hash_key_size > 0 &&
2155                         dev_info.hash_key_size <= sizeof(hash_key))
2156                 hash_key_size = dev_info.hash_key_size;
2157         else {
2158                 printf("dev_info did not provide a valid hash key size\n");
2159                 return;
2160         }
2161         /* Check the length of the RSS hash key */
2162         key_len = strlen(res->key);
2163         if (key_len != (hash_key_size * 2)) {
2164                 printf("key length: %d invalid - key must be a string of %d"
2165                            " hexa-decimal numbers\n",
2166                            (int) key_len, hash_key_size * 2);
2167                 return;
2168         }
2169         /* Translate RSS hash key into binary representation */
2170         for (i = 0; i < hash_key_size; i++) {
2171                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2172                 if (xdgt0 == 0xFF)
2173                         return;
2174                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2175                 if (xdgt1 == 0xFF)
2176                         return;
2177                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2178         }
2179         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2180                         hash_key_size);
2181 }
2182
2183 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2184         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2185 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2186         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2187                                  "config");
2188 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2189         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2190 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2191         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2192                                  rss_hash_key, "rss-hash-key");
2193 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2194         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2195                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2196                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2197                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2198                                  "ipv6-tcp-ex#ipv6-udp-ex");
2199 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2200         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2201
2202 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2203         .f = cmd_config_rss_hash_key_parsed,
2204         .data = NULL,
2205         .help_str = "port config <port_id> rss-hash-key "
2206                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2207                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2208                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2209                 "<string of hex digits (variable length, NIC dependent)>",
2210         .tokens = {
2211                 (void *)&cmd_config_rss_hash_key_port,
2212                 (void *)&cmd_config_rss_hash_key_config,
2213                 (void *)&cmd_config_rss_hash_key_port_id,
2214                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2215                 (void *)&cmd_config_rss_hash_key_rss_type,
2216                 (void *)&cmd_config_rss_hash_key_value,
2217                 NULL,
2218         },
2219 };
2220
2221 /* *** configure port rxq/txq ring size *** */
2222 struct cmd_config_rxtx_ring_size {
2223         cmdline_fixed_string_t port;
2224         cmdline_fixed_string_t config;
2225         portid_t portid;
2226         cmdline_fixed_string_t rxtxq;
2227         uint16_t qid;
2228         cmdline_fixed_string_t rsize;
2229         uint16_t size;
2230 };
2231
2232 static void
2233 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2234                                  __attribute__((unused)) struct cmdline *cl,
2235                                  __attribute__((unused)) void *data)
2236 {
2237         struct cmd_config_rxtx_ring_size *res = parsed_result;
2238         struct rte_port *port;
2239         uint8_t isrx;
2240
2241         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2242                 return;
2243
2244         if (res->portid == (portid_t)RTE_PORT_ALL) {
2245                 printf("Invalid port id\n");
2246                 return;
2247         }
2248
2249         port = &ports[res->portid];
2250
2251         if (!strcmp(res->rxtxq, "rxq"))
2252                 isrx = 1;
2253         else if (!strcmp(res->rxtxq, "txq"))
2254                 isrx = 0;
2255         else {
2256                 printf("Unknown parameter\n");
2257                 return;
2258         }
2259
2260         if (isrx && rx_queue_id_is_invalid(res->qid))
2261                 return;
2262         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2263                 return;
2264
2265         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2266                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2267                        rx_free_thresh);
2268                 return;
2269         }
2270
2271         if (isrx)
2272                 port->nb_rx_desc[res->qid] = res->size;
2273         else
2274                 port->nb_tx_desc[res->qid] = res->size;
2275
2276         cmd_reconfig_device_queue(res->portid, 0, 1);
2277 }
2278
2279 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2280         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2281                                  port, "port");
2282 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2283         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2284                                  config, "config");
2285 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2286         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2287                                  portid, UINT16);
2288 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2289         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2290                                  rxtxq, "rxq#txq");
2291 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2292         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2293                               qid, UINT16);
2294 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2295         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2296                                  rsize, "ring_size");
2297 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2298         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2299                               size, UINT16);
2300
2301 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2302         .f = cmd_config_rxtx_ring_size_parsed,
2303         .data = NULL,
2304         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2305         .tokens = {
2306                 (void *)&cmd_config_rxtx_ring_size_port,
2307                 (void *)&cmd_config_rxtx_ring_size_config,
2308                 (void *)&cmd_config_rxtx_ring_size_portid,
2309                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2310                 (void *)&cmd_config_rxtx_ring_size_qid,
2311                 (void *)&cmd_config_rxtx_ring_size_rsize,
2312                 (void *)&cmd_config_rxtx_ring_size_size,
2313                 NULL,
2314         },
2315 };
2316
2317 /* *** configure port rxq/txq start/stop *** */
2318 struct cmd_config_rxtx_queue {
2319         cmdline_fixed_string_t port;
2320         portid_t portid;
2321         cmdline_fixed_string_t rxtxq;
2322         uint16_t qid;
2323         cmdline_fixed_string_t opname;
2324 };
2325
2326 static void
2327 cmd_config_rxtx_queue_parsed(void *parsed_result,
2328                         __attribute__((unused)) struct cmdline *cl,
2329                         __attribute__((unused)) void *data)
2330 {
2331         struct cmd_config_rxtx_queue *res = parsed_result;
2332         uint8_t isrx;
2333         uint8_t isstart;
2334         int ret = 0;
2335
2336         if (test_done == 0) {
2337                 printf("Please stop forwarding first\n");
2338                 return;
2339         }
2340
2341         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2342                 return;
2343
2344         if (port_is_started(res->portid) != 1) {
2345                 printf("Please start port %u first\n", res->portid);
2346                 return;
2347         }
2348
2349         if (!strcmp(res->rxtxq, "rxq"))
2350                 isrx = 1;
2351         else if (!strcmp(res->rxtxq, "txq"))
2352                 isrx = 0;
2353         else {
2354                 printf("Unknown parameter\n");
2355                 return;
2356         }
2357
2358         if (isrx && rx_queue_id_is_invalid(res->qid))
2359                 return;
2360         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2361                 return;
2362
2363         if (!strcmp(res->opname, "start"))
2364                 isstart = 1;
2365         else if (!strcmp(res->opname, "stop"))
2366                 isstart = 0;
2367         else {
2368                 printf("Unknown parameter\n");
2369                 return;
2370         }
2371
2372         if (isstart && isrx)
2373                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2374         else if (!isstart && isrx)
2375                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2376         else if (isstart && !isrx)
2377                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2378         else
2379                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2380
2381         if (ret == -ENOTSUP)
2382                 printf("Function not supported in PMD driver\n");
2383 }
2384
2385 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2386         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2387 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2388         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2389 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2390         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2391 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2392         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2393 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2394         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2395                                                 "start#stop");
2396
2397 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2398         .f = cmd_config_rxtx_queue_parsed,
2399         .data = NULL,
2400         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2401         .tokens = {
2402                 (void *)&cmd_config_rxtx_queue_port,
2403                 (void *)&cmd_config_rxtx_queue_portid,
2404                 (void *)&cmd_config_rxtx_queue_rxtxq,
2405                 (void *)&cmd_config_rxtx_queue_qid,
2406                 (void *)&cmd_config_rxtx_queue_opname,
2407                 NULL,
2408         },
2409 };
2410
2411 /* *** configure port rxq/txq setup *** */
2412 struct cmd_setup_rxtx_queue {
2413         cmdline_fixed_string_t port;
2414         portid_t portid;
2415         cmdline_fixed_string_t rxtxq;
2416         uint16_t qid;
2417         cmdline_fixed_string_t setup;
2418 };
2419
2420 /* Common CLI fields for queue setup */
2421 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2422         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2423 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2424         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2425 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2426         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2427 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2428         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2429 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2430         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2431
2432 static void
2433 cmd_setup_rxtx_queue_parsed(
2434         void *parsed_result,
2435         __attribute__((unused)) struct cmdline *cl,
2436         __attribute__((unused)) void *data)
2437 {
2438         struct cmd_setup_rxtx_queue *res = parsed_result;
2439         struct rte_port *port;
2440         struct rte_mempool *mp;
2441         unsigned int socket_id;
2442         uint8_t isrx = 0;
2443         int ret;
2444
2445         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2446                 return;
2447
2448         if (res->portid == (portid_t)RTE_PORT_ALL) {
2449                 printf("Invalid port id\n");
2450                 return;
2451         }
2452
2453         if (!strcmp(res->rxtxq, "rxq"))
2454                 isrx = 1;
2455         else if (!strcmp(res->rxtxq, "txq"))
2456                 isrx = 0;
2457         else {
2458                 printf("Unknown parameter\n");
2459                 return;
2460         }
2461
2462         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2463                 printf("Invalid rx queue\n");
2464                 return;
2465         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2466                 printf("Invalid tx queue\n");
2467                 return;
2468         }
2469
2470         port = &ports[res->portid];
2471         if (isrx) {
2472                 socket_id = rxring_numa[res->portid];
2473                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2474                         socket_id = port->socket_id;
2475
2476                 mp = mbuf_pool_find(socket_id);
2477                 if (mp == NULL) {
2478                         printf("Failed to setup RX queue: "
2479                                 "No mempool allocation"
2480                                 " on the socket %d\n",
2481                                 rxring_numa[res->portid]);
2482                         return;
2483                 }
2484                 ret = rte_eth_rx_queue_setup(res->portid,
2485                                              res->qid,
2486                                              port->nb_rx_desc[res->qid],
2487                                              socket_id,
2488                                              &port->rx_conf[res->qid],
2489                                              mp);
2490                 if (ret)
2491                         printf("Failed to setup RX queue\n");
2492         } else {
2493                 socket_id = txring_numa[res->portid];
2494                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2495                         socket_id = port->socket_id;
2496
2497                 ret = rte_eth_tx_queue_setup(res->portid,
2498                                              res->qid,
2499                                              port->nb_tx_desc[res->qid],
2500                                              socket_id,
2501                                              &port->tx_conf[res->qid]);
2502                 if (ret)
2503                         printf("Failed to setup TX queue\n");
2504         }
2505 }
2506
2507 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2508         .f = cmd_setup_rxtx_queue_parsed,
2509         .data = NULL,
2510         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2511         .tokens = {
2512                 (void *)&cmd_setup_rxtx_queue_port,
2513                 (void *)&cmd_setup_rxtx_queue_portid,
2514                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2515                 (void *)&cmd_setup_rxtx_queue_qid,
2516                 (void *)&cmd_setup_rxtx_queue_setup,
2517                 NULL,
2518         },
2519 };
2520
2521
2522 /* *** Configure RSS RETA *** */
2523 struct cmd_config_rss_reta {
2524         cmdline_fixed_string_t port;
2525         cmdline_fixed_string_t keyword;
2526         portid_t port_id;
2527         cmdline_fixed_string_t name;
2528         cmdline_fixed_string_t list_name;
2529         cmdline_fixed_string_t list_of_items;
2530 };
2531
2532 static int
2533 parse_reta_config(const char *str,
2534                   struct rte_eth_rss_reta_entry64 *reta_conf,
2535                   uint16_t nb_entries)
2536 {
2537         int i;
2538         unsigned size;
2539         uint16_t hash_index, idx, shift;
2540         uint16_t nb_queue;
2541         char s[256];
2542         const char *p, *p0 = str;
2543         char *end;
2544         enum fieldnames {
2545                 FLD_HASH_INDEX = 0,
2546                 FLD_QUEUE,
2547                 _NUM_FLD
2548         };
2549         unsigned long int_fld[_NUM_FLD];
2550         char *str_fld[_NUM_FLD];
2551
2552         while ((p = strchr(p0,'(')) != NULL) {
2553                 ++p;
2554                 if((p0 = strchr(p,')')) == NULL)
2555                         return -1;
2556
2557                 size = p0 - p;
2558                 if(size >= sizeof(s))
2559                         return -1;
2560
2561                 snprintf(s, sizeof(s), "%.*s", size, p);
2562                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2563                         return -1;
2564                 for (i = 0; i < _NUM_FLD; i++) {
2565                         errno = 0;
2566                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2567                         if (errno != 0 || end == str_fld[i] ||
2568                                         int_fld[i] > 65535)
2569                                 return -1;
2570                 }
2571
2572                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2573                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2574
2575                 if (hash_index >= nb_entries) {
2576                         printf("Invalid RETA hash index=%d\n", hash_index);
2577                         return -1;
2578                 }
2579
2580                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2581                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2582                 reta_conf[idx].mask |= (1ULL << shift);
2583                 reta_conf[idx].reta[shift] = nb_queue;
2584         }
2585
2586         return 0;
2587 }
2588
2589 static void
2590 cmd_set_rss_reta_parsed(void *parsed_result,
2591                         __attribute__((unused)) struct cmdline *cl,
2592                         __attribute__((unused)) void *data)
2593 {
2594         int ret;
2595         struct rte_eth_dev_info dev_info;
2596         struct rte_eth_rss_reta_entry64 reta_conf[8];
2597         struct cmd_config_rss_reta *res = parsed_result;
2598
2599         memset(&dev_info, 0, sizeof(dev_info));
2600         rte_eth_dev_info_get(res->port_id, &dev_info);
2601         if (dev_info.reta_size == 0) {
2602                 printf("Redirection table size is 0 which is "
2603                                         "invalid for RSS\n");
2604                 return;
2605         } else
2606                 printf("The reta size of port %d is %u\n",
2607                         res->port_id, dev_info.reta_size);
2608         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2609                 printf("Currently do not support more than %u entries of "
2610                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2611                 return;
2612         }
2613
2614         memset(reta_conf, 0, sizeof(reta_conf));
2615         if (!strcmp(res->list_name, "reta")) {
2616                 if (parse_reta_config(res->list_of_items, reta_conf,
2617                                                 dev_info.reta_size)) {
2618                         printf("Invalid RSS Redirection Table "
2619                                         "config entered\n");
2620                         return;
2621                 }
2622                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2623                                 reta_conf, dev_info.reta_size);
2624                 if (ret != 0)
2625                         printf("Bad redirection table parameter, "
2626                                         "return code = %d \n", ret);
2627         }
2628 }
2629
2630 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2631         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2632 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2633         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2634 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2635         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2636 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2637         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2638 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2639         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2640 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2641         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2642                                  NULL);
2643 cmdline_parse_inst_t cmd_config_rss_reta = {
2644         .f = cmd_set_rss_reta_parsed,
2645         .data = NULL,
2646         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2647         .tokens = {
2648                 (void *)&cmd_config_rss_reta_port,
2649                 (void *)&cmd_config_rss_reta_keyword,
2650                 (void *)&cmd_config_rss_reta_port_id,
2651                 (void *)&cmd_config_rss_reta_name,
2652                 (void *)&cmd_config_rss_reta_list_name,
2653                 (void *)&cmd_config_rss_reta_list_of_items,
2654                 NULL,
2655         },
2656 };
2657
2658 /* *** SHOW PORT RETA INFO *** */
2659 struct cmd_showport_reta {
2660         cmdline_fixed_string_t show;
2661         cmdline_fixed_string_t port;
2662         portid_t port_id;
2663         cmdline_fixed_string_t rss;
2664         cmdline_fixed_string_t reta;
2665         uint16_t size;
2666         cmdline_fixed_string_t list_of_items;
2667 };
2668
2669 static int
2670 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2671                            uint16_t nb_entries,
2672                            char *str)
2673 {
2674         uint32_t size;
2675         const char *p, *p0 = str;
2676         char s[256];
2677         char *end;
2678         char *str_fld[8];
2679         uint16_t i;
2680         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2681                         RTE_RETA_GROUP_SIZE;
2682         int ret;
2683
2684         p = strchr(p0, '(');
2685         if (p == NULL)
2686                 return -1;
2687         p++;
2688         p0 = strchr(p, ')');
2689         if (p0 == NULL)
2690                 return -1;
2691         size = p0 - p;
2692         if (size >= sizeof(s)) {
2693                 printf("The string size exceeds the internal buffer size\n");
2694                 return -1;
2695         }
2696         snprintf(s, sizeof(s), "%.*s", size, p);
2697         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2698         if (ret <= 0 || ret != num) {
2699                 printf("The bits of masks do not match the number of "
2700                                         "reta entries: %u\n", num);
2701                 return -1;
2702         }
2703         for (i = 0; i < ret; i++)
2704                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2705
2706         return 0;
2707 }
2708
2709 static void
2710 cmd_showport_reta_parsed(void *parsed_result,
2711                          __attribute__((unused)) struct cmdline *cl,
2712                          __attribute__((unused)) void *data)
2713 {
2714         struct cmd_showport_reta *res = parsed_result;
2715         struct rte_eth_rss_reta_entry64 reta_conf[8];
2716         struct rte_eth_dev_info dev_info;
2717         uint16_t max_reta_size;
2718
2719         memset(&dev_info, 0, sizeof(dev_info));
2720         rte_eth_dev_info_get(res->port_id, &dev_info);
2721         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2722         if (res->size == 0 || res->size > max_reta_size) {
2723                 printf("Invalid redirection table size: %u (1-%u)\n",
2724                         res->size, max_reta_size);
2725                 return;
2726         }
2727
2728         memset(reta_conf, 0, sizeof(reta_conf));
2729         if (showport_parse_reta_config(reta_conf, res->size,
2730                                 res->list_of_items) < 0) {
2731                 printf("Invalid string: %s for reta masks\n",
2732                                         res->list_of_items);
2733                 return;
2734         }
2735         port_rss_reta_info(res->port_id, reta_conf, res->size);
2736 }
2737
2738 cmdline_parse_token_string_t cmd_showport_reta_show =
2739         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2740 cmdline_parse_token_string_t cmd_showport_reta_port =
2741         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2742 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2743         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2744 cmdline_parse_token_string_t cmd_showport_reta_rss =
2745         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2746 cmdline_parse_token_string_t cmd_showport_reta_reta =
2747         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2748 cmdline_parse_token_num_t cmd_showport_reta_size =
2749         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2750 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2751         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2752                                         list_of_items, NULL);
2753
2754 cmdline_parse_inst_t cmd_showport_reta = {
2755         .f = cmd_showport_reta_parsed,
2756         .data = NULL,
2757         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2758         .tokens = {
2759                 (void *)&cmd_showport_reta_show,
2760                 (void *)&cmd_showport_reta_port,
2761                 (void *)&cmd_showport_reta_port_id,
2762                 (void *)&cmd_showport_reta_rss,
2763                 (void *)&cmd_showport_reta_reta,
2764                 (void *)&cmd_showport_reta_size,
2765                 (void *)&cmd_showport_reta_list_of_items,
2766                 NULL,
2767         },
2768 };
2769
2770 /* *** Show RSS hash configuration *** */
2771 struct cmd_showport_rss_hash {
2772         cmdline_fixed_string_t show;
2773         cmdline_fixed_string_t port;
2774         portid_t port_id;
2775         cmdline_fixed_string_t rss_hash;
2776         cmdline_fixed_string_t rss_type;
2777         cmdline_fixed_string_t key; /* optional argument */
2778 };
2779
2780 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2781                                 __attribute__((unused)) struct cmdline *cl,
2782                                 void *show_rss_key)
2783 {
2784         struct cmd_showport_rss_hash *res = parsed_result;
2785
2786         port_rss_hash_conf_show(res->port_id, res->rss_type,
2787                                 show_rss_key != NULL);
2788 }
2789
2790 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2791         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2792 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2793         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2794 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2795         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2796 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2797         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2798                                  "rss-hash");
2799 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2800         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2801                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2802                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2803                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2804                                  "ipv6-tcp-ex#ipv6-udp-ex");
2805 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2806         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2807
2808 cmdline_parse_inst_t cmd_showport_rss_hash = {
2809         .f = cmd_showport_rss_hash_parsed,
2810         .data = NULL,
2811         .help_str = "show port <port_id> rss-hash "
2812                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2813                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2814                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2815         .tokens = {
2816                 (void *)&cmd_showport_rss_hash_show,
2817                 (void *)&cmd_showport_rss_hash_port,
2818                 (void *)&cmd_showport_rss_hash_port_id,
2819                 (void *)&cmd_showport_rss_hash_rss_hash,
2820                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2821                 NULL,
2822         },
2823 };
2824
2825 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2826         .f = cmd_showport_rss_hash_parsed,
2827         .data = (void *)1,
2828         .help_str = "show port <port_id> rss-hash "
2829                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2830                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2831                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2832         .tokens = {
2833                 (void *)&cmd_showport_rss_hash_show,
2834                 (void *)&cmd_showport_rss_hash_port,
2835                 (void *)&cmd_showport_rss_hash_port_id,
2836                 (void *)&cmd_showport_rss_hash_rss_hash,
2837                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2838                 (void *)&cmd_showport_rss_hash_rss_key,
2839                 NULL,
2840         },
2841 };
2842
2843 /* *** Configure DCB *** */
2844 struct cmd_config_dcb {
2845         cmdline_fixed_string_t port;
2846         cmdline_fixed_string_t config;
2847         portid_t port_id;
2848         cmdline_fixed_string_t dcb;
2849         cmdline_fixed_string_t vt;
2850         cmdline_fixed_string_t vt_en;
2851         uint8_t num_tcs;
2852         cmdline_fixed_string_t pfc;
2853         cmdline_fixed_string_t pfc_en;
2854 };
2855
2856 static void
2857 cmd_config_dcb_parsed(void *parsed_result,
2858                         __attribute__((unused)) struct cmdline *cl,
2859                         __attribute__((unused)) void *data)
2860 {
2861         struct cmd_config_dcb *res = parsed_result;
2862         portid_t port_id = res->port_id;
2863         struct rte_port *port;
2864         uint8_t pfc_en;
2865         int ret;
2866
2867         port = &ports[port_id];
2868         /** Check if the port is not started **/
2869         if (port->port_status != RTE_PORT_STOPPED) {
2870                 printf("Please stop port %d first\n", port_id);
2871                 return;
2872         }
2873
2874         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2875                 printf("The invalid number of traffic class,"
2876                         " only 4 or 8 allowed.\n");
2877                 return;
2878         }
2879
2880         if (nb_fwd_lcores < res->num_tcs) {
2881                 printf("nb_cores shouldn't be less than number of TCs.\n");
2882                 return;
2883         }
2884         if (!strncmp(res->pfc_en, "on", 2))
2885                 pfc_en = 1;
2886         else
2887                 pfc_en = 0;
2888
2889         /* DCB in VT mode */
2890         if (!strncmp(res->vt_en, "on", 2))
2891                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2892                                 (enum rte_eth_nb_tcs)res->num_tcs,
2893                                 pfc_en);
2894         else
2895                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2896                                 (enum rte_eth_nb_tcs)res->num_tcs,
2897                                 pfc_en);
2898
2899
2900         if (ret != 0) {
2901                 printf("Cannot initialize network ports.\n");
2902                 return;
2903         }
2904
2905         cmd_reconfig_device_queue(port_id, 1, 1);
2906 }
2907
2908 cmdline_parse_token_string_t cmd_config_dcb_port =
2909         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2910 cmdline_parse_token_string_t cmd_config_dcb_config =
2911         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2912 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2913         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2914 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2915         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2916 cmdline_parse_token_string_t cmd_config_dcb_vt =
2917         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2918 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2919         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2920 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2921         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2922 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2923         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2924 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2925         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2926
2927 cmdline_parse_inst_t cmd_config_dcb = {
2928         .f = cmd_config_dcb_parsed,
2929         .data = NULL,
2930         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2931         .tokens = {
2932                 (void *)&cmd_config_dcb_port,
2933                 (void *)&cmd_config_dcb_config,
2934                 (void *)&cmd_config_dcb_port_id,
2935                 (void *)&cmd_config_dcb_dcb,
2936                 (void *)&cmd_config_dcb_vt,
2937                 (void *)&cmd_config_dcb_vt_en,
2938                 (void *)&cmd_config_dcb_num_tcs,
2939                 (void *)&cmd_config_dcb_pfc,
2940                 (void *)&cmd_config_dcb_pfc_en,
2941                 NULL,
2942         },
2943 };
2944
2945 /* *** configure number of packets per burst *** */
2946 struct cmd_config_burst {
2947         cmdline_fixed_string_t port;
2948         cmdline_fixed_string_t keyword;
2949         cmdline_fixed_string_t all;
2950         cmdline_fixed_string_t name;
2951         uint16_t value;
2952 };
2953
2954 static void
2955 cmd_config_burst_parsed(void *parsed_result,
2956                         __attribute__((unused)) struct cmdline *cl,
2957                         __attribute__((unused)) void *data)
2958 {
2959         struct cmd_config_burst *res = parsed_result;
2960         struct rte_eth_dev_info dev_info;
2961         uint16_t rec_nb_pkts;
2962
2963         if (!all_ports_stopped()) {
2964                 printf("Please stop all ports first\n");
2965                 return;
2966         }
2967
2968         if (!strcmp(res->name, "burst")) {
2969                 if (res->value == 0) {
2970                         /* If user gives a value of zero, query the PMD for
2971                          * its recommended Rx burst size. Testpmd uses a single
2972                          * size for all ports, so assume all ports are the same
2973                          * NIC model and use the values from Port 0.
2974                          */
2975                         rte_eth_dev_info_get(0, &dev_info);
2976                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2977
2978                         if (rec_nb_pkts == 0) {
2979                                 printf("PMD does not recommend a burst size.\n"
2980                                         "User provided value must be between"
2981                                         " 1 and %d\n", MAX_PKT_BURST);
2982                                 return;
2983                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2984                                 printf("PMD recommended burst size of %d"
2985                                         " exceeds maximum value of %d\n",
2986                                         rec_nb_pkts, MAX_PKT_BURST);
2987                                 return;
2988                         }
2989                         printf("Using PMD-provided burst value of %d\n",
2990                                 rec_nb_pkts);
2991                         nb_pkt_per_burst = rec_nb_pkts;
2992                 } else if (res->value > MAX_PKT_BURST) {
2993                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2994                         return;
2995                 } else
2996                         nb_pkt_per_burst = res->value;
2997         } else {
2998                 printf("Unknown parameter\n");
2999                 return;
3000         }
3001
3002         init_port_config();
3003
3004         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3005 }
3006
3007 cmdline_parse_token_string_t cmd_config_burst_port =
3008         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3009 cmdline_parse_token_string_t cmd_config_burst_keyword =
3010         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3011 cmdline_parse_token_string_t cmd_config_burst_all =
3012         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3013 cmdline_parse_token_string_t cmd_config_burst_name =
3014         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3015 cmdline_parse_token_num_t cmd_config_burst_value =
3016         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3017
3018 cmdline_parse_inst_t cmd_config_burst = {
3019         .f = cmd_config_burst_parsed,
3020         .data = NULL,
3021         .help_str = "port config all burst <value>",
3022         .tokens = {
3023                 (void *)&cmd_config_burst_port,
3024                 (void *)&cmd_config_burst_keyword,
3025                 (void *)&cmd_config_burst_all,
3026                 (void *)&cmd_config_burst_name,
3027                 (void *)&cmd_config_burst_value,
3028                 NULL,
3029         },
3030 };
3031
3032 /* *** configure rx/tx queues *** */
3033 struct cmd_config_thresh {
3034         cmdline_fixed_string_t port;
3035         cmdline_fixed_string_t keyword;
3036         cmdline_fixed_string_t all;
3037         cmdline_fixed_string_t name;
3038         uint8_t value;
3039 };
3040
3041 static void
3042 cmd_config_thresh_parsed(void *parsed_result,
3043                         __attribute__((unused)) struct cmdline *cl,
3044                         __attribute__((unused)) void *data)
3045 {
3046         struct cmd_config_thresh *res = parsed_result;
3047
3048         if (!all_ports_stopped()) {
3049                 printf("Please stop all ports first\n");
3050                 return;
3051         }
3052
3053         if (!strcmp(res->name, "txpt"))
3054                 tx_pthresh = res->value;
3055         else if(!strcmp(res->name, "txht"))
3056                 tx_hthresh = res->value;
3057         else if(!strcmp(res->name, "txwt"))
3058                 tx_wthresh = res->value;
3059         else if(!strcmp(res->name, "rxpt"))
3060                 rx_pthresh = res->value;
3061         else if(!strcmp(res->name, "rxht"))
3062                 rx_hthresh = res->value;
3063         else if(!strcmp(res->name, "rxwt"))
3064                 rx_wthresh = res->value;
3065         else {
3066                 printf("Unknown parameter\n");
3067                 return;
3068         }
3069
3070         init_port_config();
3071
3072         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3073 }
3074
3075 cmdline_parse_token_string_t cmd_config_thresh_port =
3076         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3077 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3078         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3079 cmdline_parse_token_string_t cmd_config_thresh_all =
3080         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3081 cmdline_parse_token_string_t cmd_config_thresh_name =
3082         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3083                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3084 cmdline_parse_token_num_t cmd_config_thresh_value =
3085         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3086
3087 cmdline_parse_inst_t cmd_config_thresh = {
3088         .f = cmd_config_thresh_parsed,
3089         .data = NULL,
3090         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3091         .tokens = {
3092                 (void *)&cmd_config_thresh_port,
3093                 (void *)&cmd_config_thresh_keyword,
3094                 (void *)&cmd_config_thresh_all,
3095                 (void *)&cmd_config_thresh_name,
3096                 (void *)&cmd_config_thresh_value,
3097                 NULL,
3098         },
3099 };
3100
3101 /* *** configure free/rs threshold *** */
3102 struct cmd_config_threshold {
3103         cmdline_fixed_string_t port;
3104         cmdline_fixed_string_t keyword;
3105         cmdline_fixed_string_t all;
3106         cmdline_fixed_string_t name;
3107         uint16_t value;
3108 };
3109
3110 static void
3111 cmd_config_threshold_parsed(void *parsed_result,
3112                         __attribute__((unused)) struct cmdline *cl,
3113                         __attribute__((unused)) void *data)
3114 {
3115         struct cmd_config_threshold *res = parsed_result;
3116
3117         if (!all_ports_stopped()) {
3118                 printf("Please stop all ports first\n");
3119                 return;
3120         }
3121
3122         if (!strcmp(res->name, "txfreet"))
3123                 tx_free_thresh = res->value;
3124         else if (!strcmp(res->name, "txrst"))
3125                 tx_rs_thresh = res->value;
3126         else if (!strcmp(res->name, "rxfreet"))
3127                 rx_free_thresh = res->value;
3128         else {
3129                 printf("Unknown parameter\n");
3130                 return;
3131         }
3132
3133         init_port_config();
3134
3135         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3136 }
3137
3138 cmdline_parse_token_string_t cmd_config_threshold_port =
3139         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3140 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3141         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3142                                                                 "config");
3143 cmdline_parse_token_string_t cmd_config_threshold_all =
3144         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3145 cmdline_parse_token_string_t cmd_config_threshold_name =
3146         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3147                                                 "txfreet#txrst#rxfreet");
3148 cmdline_parse_token_num_t cmd_config_threshold_value =
3149         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3150
3151 cmdline_parse_inst_t cmd_config_threshold = {
3152         .f = cmd_config_threshold_parsed,
3153         .data = NULL,
3154         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3155         .tokens = {
3156                 (void *)&cmd_config_threshold_port,
3157                 (void *)&cmd_config_threshold_keyword,
3158                 (void *)&cmd_config_threshold_all,
3159                 (void *)&cmd_config_threshold_name,
3160                 (void *)&cmd_config_threshold_value,
3161                 NULL,
3162         },
3163 };
3164
3165 /* *** stop *** */
3166 struct cmd_stop_result {
3167         cmdline_fixed_string_t stop;
3168 };
3169
3170 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3171                             __attribute__((unused)) struct cmdline *cl,
3172                             __attribute__((unused)) void *data)
3173 {
3174         stop_packet_forwarding();
3175 }
3176
3177 cmdline_parse_token_string_t cmd_stop_stop =
3178         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3179
3180 cmdline_parse_inst_t cmd_stop = {
3181         .f = cmd_stop_parsed,
3182         .data = NULL,
3183         .help_str = "stop: Stop packet forwarding",
3184         .tokens = {
3185                 (void *)&cmd_stop_stop,
3186                 NULL,
3187         },
3188 };
3189
3190 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3191
3192 unsigned int
3193 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3194                 unsigned int *parsed_items, int check_unique_values)
3195 {
3196         unsigned int nb_item;
3197         unsigned int value;
3198         unsigned int i;
3199         unsigned int j;
3200         int value_ok;
3201         char c;
3202
3203         /*
3204          * First parse all items in the list and store their value.
3205          */
3206         value = 0;
3207         nb_item = 0;
3208         value_ok = 0;
3209         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3210                 c = str[i];
3211                 if ((c >= '0') && (c <= '9')) {
3212                         value = (unsigned int) (value * 10 + (c - '0'));
3213                         value_ok = 1;
3214                         continue;
3215                 }
3216                 if (c != ',') {
3217                         printf("character %c is not a decimal digit\n", c);
3218                         return 0;
3219                 }
3220                 if (! value_ok) {
3221                         printf("No valid value before comma\n");
3222                         return 0;
3223                 }
3224                 if (nb_item < max_items) {
3225                         parsed_items[nb_item] = value;
3226                         value_ok = 0;
3227                         value = 0;
3228                 }
3229                 nb_item++;
3230         }
3231         if (nb_item >= max_items) {
3232                 printf("Number of %s = %u > %u (maximum items)\n",
3233                        item_name, nb_item + 1, max_items);
3234                 return 0;
3235         }
3236         parsed_items[nb_item++] = value;
3237         if (! check_unique_values)
3238                 return nb_item;
3239
3240         /*
3241          * Then, check that all values in the list are differents.
3242          * No optimization here...
3243          */
3244         for (i = 0; i < nb_item; i++) {
3245                 for (j = i + 1; j < nb_item; j++) {
3246                         if (parsed_items[j] == parsed_items[i]) {
3247                                 printf("duplicated %s %u at index %u and %u\n",
3248                                        item_name, parsed_items[i], i, j);
3249                                 return 0;
3250                         }
3251                 }
3252         }
3253         return nb_item;
3254 }
3255
3256 struct cmd_set_list_result {
3257         cmdline_fixed_string_t cmd_keyword;
3258         cmdline_fixed_string_t list_name;
3259         cmdline_fixed_string_t list_of_items;
3260 };
3261
3262 static void cmd_set_list_parsed(void *parsed_result,
3263                                 __attribute__((unused)) struct cmdline *cl,
3264                                 __attribute__((unused)) void *data)
3265 {
3266         struct cmd_set_list_result *res;
3267         union {
3268                 unsigned int lcorelist[RTE_MAX_LCORE];
3269                 unsigned int portlist[RTE_MAX_ETHPORTS];
3270         } parsed_items;
3271         unsigned int nb_item;
3272
3273         if (test_done == 0) {
3274                 printf("Please stop forwarding first\n");
3275                 return;
3276         }
3277
3278         res = parsed_result;
3279         if (!strcmp(res->list_name, "corelist")) {
3280                 nb_item = parse_item_list(res->list_of_items, "core",
3281                                           RTE_MAX_LCORE,
3282                                           parsed_items.lcorelist, 1);
3283                 if (nb_item > 0) {
3284                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3285                         fwd_config_setup();
3286                 }
3287                 return;
3288         }
3289         if (!strcmp(res->list_name, "portlist")) {
3290                 nb_item = parse_item_list(res->list_of_items, "port",
3291                                           RTE_MAX_ETHPORTS,
3292                                           parsed_items.portlist, 1);
3293                 if (nb_item > 0) {
3294                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3295                         fwd_config_setup();
3296                 }
3297         }
3298 }
3299
3300 cmdline_parse_token_string_t cmd_set_list_keyword =
3301         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3302                                  "set");
3303 cmdline_parse_token_string_t cmd_set_list_name =
3304         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3305                                  "corelist#portlist");
3306 cmdline_parse_token_string_t cmd_set_list_of_items =
3307         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3308                                  NULL);
3309
3310 cmdline_parse_inst_t cmd_set_fwd_list = {
3311         .f = cmd_set_list_parsed,
3312         .data = NULL,
3313         .help_str = "set corelist|portlist <list0[,list1]*>",
3314         .tokens = {
3315                 (void *)&cmd_set_list_keyword,
3316                 (void *)&cmd_set_list_name,
3317                 (void *)&cmd_set_list_of_items,
3318                 NULL,
3319         },
3320 };
3321
3322 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3323
3324 struct cmd_setmask_result {
3325         cmdline_fixed_string_t set;
3326         cmdline_fixed_string_t mask;
3327         uint64_t hexavalue;
3328 };
3329
3330 static void cmd_set_mask_parsed(void *parsed_result,
3331                                 __attribute__((unused)) struct cmdline *cl,
3332                                 __attribute__((unused)) void *data)
3333 {
3334         struct cmd_setmask_result *res = parsed_result;
3335
3336         if (test_done == 0) {
3337                 printf("Please stop forwarding first\n");
3338                 return;
3339         }
3340         if (!strcmp(res->mask, "coremask")) {
3341                 set_fwd_lcores_mask(res->hexavalue);
3342                 fwd_config_setup();
3343         } else if (!strcmp(res->mask, "portmask")) {
3344                 set_fwd_ports_mask(res->hexavalue);
3345                 fwd_config_setup();
3346         }
3347 }
3348
3349 cmdline_parse_token_string_t cmd_setmask_set =
3350         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3351 cmdline_parse_token_string_t cmd_setmask_mask =
3352         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3353                                  "coremask#portmask");
3354 cmdline_parse_token_num_t cmd_setmask_value =
3355         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3356
3357 cmdline_parse_inst_t cmd_set_fwd_mask = {
3358         .f = cmd_set_mask_parsed,
3359         .data = NULL,
3360         .help_str = "set coremask|portmask <hexadecimal value>",
3361         .tokens = {
3362                 (void *)&cmd_setmask_set,
3363                 (void *)&cmd_setmask_mask,
3364                 (void *)&cmd_setmask_value,
3365                 NULL,
3366         },
3367 };
3368
3369 /*
3370  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3371  */
3372 struct cmd_set_result {
3373         cmdline_fixed_string_t set;
3374         cmdline_fixed_string_t what;
3375         uint16_t value;
3376 };
3377
3378 static void cmd_set_parsed(void *parsed_result,
3379                            __attribute__((unused)) struct cmdline *cl,
3380                            __attribute__((unused)) void *data)
3381 {
3382         struct cmd_set_result *res = parsed_result;
3383         if (!strcmp(res->what, "nbport")) {
3384                 set_fwd_ports_number(res->value);
3385                 fwd_config_setup();
3386         } else if (!strcmp(res->what, "nbcore")) {
3387                 set_fwd_lcores_number(res->value);
3388                 fwd_config_setup();
3389         } else if (!strcmp(res->what, "burst"))
3390                 set_nb_pkt_per_burst(res->value);
3391         else if (!strcmp(res->what, "verbose"))
3392                 set_verbose_level(res->value);
3393 }
3394
3395 cmdline_parse_token_string_t cmd_set_set =
3396         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3397 cmdline_parse_token_string_t cmd_set_what =
3398         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3399                                  "nbport#nbcore#burst#verbose");
3400 cmdline_parse_token_num_t cmd_set_value =
3401         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3402
3403 cmdline_parse_inst_t cmd_set_numbers = {
3404         .f = cmd_set_parsed,
3405         .data = NULL,
3406         .help_str = "set nbport|nbcore|burst|verbose <value>",
3407         .tokens = {
3408                 (void *)&cmd_set_set,
3409                 (void *)&cmd_set_what,
3410                 (void *)&cmd_set_value,
3411                 NULL,
3412         },
3413 };
3414
3415 /* *** SET LOG LEVEL CONFIGURATION *** */
3416
3417 struct cmd_set_log_result {
3418         cmdline_fixed_string_t set;
3419         cmdline_fixed_string_t log;
3420         cmdline_fixed_string_t type;
3421         uint32_t level;
3422 };
3423
3424 static void
3425 cmd_set_log_parsed(void *parsed_result,
3426                    __attribute__((unused)) struct cmdline *cl,
3427                    __attribute__((unused)) void *data)
3428 {
3429         struct cmd_set_log_result *res;
3430         int ret;
3431
3432         res = parsed_result;
3433         if (!strcmp(res->type, "global"))
3434                 rte_log_set_global_level(res->level);
3435         else {
3436                 ret = rte_log_set_level_regexp(res->type, res->level);
3437                 if (ret < 0)
3438                         printf("Unable to set log level\n");
3439         }
3440 }
3441
3442 cmdline_parse_token_string_t cmd_set_log_set =
3443         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3444 cmdline_parse_token_string_t cmd_set_log_log =
3445         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3446 cmdline_parse_token_string_t cmd_set_log_type =
3447         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3448 cmdline_parse_token_num_t cmd_set_log_level =
3449         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3450
3451 cmdline_parse_inst_t cmd_set_log = {
3452         .f = cmd_set_log_parsed,
3453         .data = NULL,
3454         .help_str = "set log global|<type> <level>",
3455         .tokens = {
3456                 (void *)&cmd_set_log_set,
3457                 (void *)&cmd_set_log_log,
3458                 (void *)&cmd_set_log_type,
3459                 (void *)&cmd_set_log_level,
3460                 NULL,
3461         },
3462 };
3463
3464 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3465
3466 struct cmd_set_txpkts_result {
3467         cmdline_fixed_string_t cmd_keyword;
3468         cmdline_fixed_string_t txpkts;
3469         cmdline_fixed_string_t seg_lengths;
3470 };
3471
3472 static void
3473 cmd_set_txpkts_parsed(void *parsed_result,
3474                       __attribute__((unused)) struct cmdline *cl,
3475                       __attribute__((unused)) void *data)
3476 {
3477         struct cmd_set_txpkts_result *res;
3478         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3479         unsigned int nb_segs;
3480
3481         res = parsed_result;
3482         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3483                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3484         if (nb_segs > 0)
3485                 set_tx_pkt_segments(seg_lengths, nb_segs);
3486 }
3487
3488 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3489         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3490                                  cmd_keyword, "set");
3491 cmdline_parse_token_string_t cmd_set_txpkts_name =
3492         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3493                                  txpkts, "txpkts");
3494 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3495         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3496                                  seg_lengths, NULL);
3497
3498 cmdline_parse_inst_t cmd_set_txpkts = {
3499         .f = cmd_set_txpkts_parsed,
3500         .data = NULL,
3501         .help_str = "set txpkts <len0[,len1]*>",
3502         .tokens = {
3503                 (void *)&cmd_set_txpkts_keyword,
3504                 (void *)&cmd_set_txpkts_name,
3505                 (void *)&cmd_set_txpkts_lengths,
3506                 NULL,
3507         },
3508 };
3509
3510 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3511
3512 struct cmd_set_txsplit_result {
3513         cmdline_fixed_string_t cmd_keyword;
3514         cmdline_fixed_string_t txsplit;
3515         cmdline_fixed_string_t mode;
3516 };
3517
3518 static void
3519 cmd_set_txsplit_parsed(void *parsed_result,
3520                       __attribute__((unused)) struct cmdline *cl,
3521                       __attribute__((unused)) void *data)
3522 {
3523         struct cmd_set_txsplit_result *res;
3524
3525         res = parsed_result;
3526         set_tx_pkt_split(res->mode);
3527 }
3528
3529 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3530         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3531                                  cmd_keyword, "set");
3532 cmdline_parse_token_string_t cmd_set_txsplit_name =
3533         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3534                                  txsplit, "txsplit");
3535 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3536         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3537                                  mode, NULL);
3538
3539 cmdline_parse_inst_t cmd_set_txsplit = {
3540         .f = cmd_set_txsplit_parsed,
3541         .data = NULL,
3542         .help_str = "set txsplit on|off|rand",
3543         .tokens = {
3544                 (void *)&cmd_set_txsplit_keyword,
3545                 (void *)&cmd_set_txsplit_name,
3546                 (void *)&cmd_set_txsplit_mode,
3547                 NULL,
3548         },
3549 };
3550
3551 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3552 struct cmd_rx_vlan_filter_all_result {
3553         cmdline_fixed_string_t rx_vlan;
3554         cmdline_fixed_string_t what;
3555         cmdline_fixed_string_t all;
3556         portid_t port_id;
3557 };
3558
3559 static void
3560 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3561                               __attribute__((unused)) struct cmdline *cl,
3562                               __attribute__((unused)) void *data)
3563 {
3564         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3565
3566         if (!strcmp(res->what, "add"))
3567                 rx_vlan_all_filter_set(res->port_id, 1);
3568         else
3569                 rx_vlan_all_filter_set(res->port_id, 0);
3570 }
3571
3572 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3573         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3574                                  rx_vlan, "rx_vlan");
3575 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3576         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3577                                  what, "add#rm");
3578 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3579         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3580                                  all, "all");
3581 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3582         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3583                               port_id, UINT16);
3584
3585 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3586         .f = cmd_rx_vlan_filter_all_parsed,
3587         .data = NULL,
3588         .help_str = "rx_vlan add|rm all <port_id>: "
3589                 "Add/Remove all identifiers to/from the set of VLAN "
3590                 "identifiers filtered by a port",
3591         .tokens = {
3592                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3593                 (void *)&cmd_rx_vlan_filter_all_what,
3594                 (void *)&cmd_rx_vlan_filter_all_all,
3595                 (void *)&cmd_rx_vlan_filter_all_portid,
3596                 NULL,
3597         },
3598 };
3599
3600 /* *** VLAN OFFLOAD SET ON A PORT *** */
3601 struct cmd_vlan_offload_result {
3602         cmdline_fixed_string_t vlan;
3603         cmdline_fixed_string_t set;
3604         cmdline_fixed_string_t vlan_type;
3605         cmdline_fixed_string_t what;
3606         cmdline_fixed_string_t on;
3607         cmdline_fixed_string_t port_id;
3608 };
3609
3610 static void
3611 cmd_vlan_offload_parsed(void *parsed_result,
3612                           __attribute__((unused)) struct cmdline *cl,
3613                           __attribute__((unused)) void *data)
3614 {
3615         int on;
3616         struct cmd_vlan_offload_result *res = parsed_result;
3617         char *str;
3618         int i, len = 0;
3619         portid_t port_id = 0;
3620         unsigned int tmp;
3621
3622         str = res->port_id;
3623         len = strnlen(str, STR_TOKEN_SIZE);
3624         i = 0;
3625         /* Get port_id first */
3626         while(i < len){
3627                 if(str[i] == ',')
3628                         break;
3629
3630                 i++;
3631         }
3632         str[i]='\0';
3633         tmp = strtoul(str, NULL, 0);
3634         /* If port_id greater that what portid_t can represent, return */
3635         if(tmp >= RTE_MAX_ETHPORTS)
3636                 return;
3637         port_id = (portid_t)tmp;
3638
3639         if (!strcmp(res->on, "on"))
3640                 on = 1;
3641         else
3642                 on = 0;
3643
3644         if (!strcmp(res->what, "strip"))
3645                 rx_vlan_strip_set(port_id,  on);
3646         else if(!strcmp(res->what, "stripq")){
3647                 uint16_t queue_id = 0;
3648
3649                 /* No queue_id, return */
3650                 if(i + 1 >= len) {
3651                         printf("must specify (port,queue_id)\n");
3652                         return;
3653                 }
3654                 tmp = strtoul(str + i + 1, NULL, 0);
3655                 /* If queue_id greater that what 16-bits can represent, return */
3656                 if(tmp > 0xffff)
3657                         return;
3658
3659                 queue_id = (uint16_t)tmp;
3660                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3661         }
3662         else if (!strcmp(res->what, "filter"))
3663                 rx_vlan_filter_set(port_id, on);
3664         else
3665                 vlan_extend_set(port_id, on);
3666
3667         return;
3668 }
3669
3670 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3671         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3672                                  vlan, "vlan");
3673 cmdline_parse_token_string_t cmd_vlan_offload_set =
3674         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3675                                  set, "set");
3676 cmdline_parse_token_string_t cmd_vlan_offload_what =
3677         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3678                                  what, "strip#filter#qinq#stripq");
3679 cmdline_parse_token_string_t cmd_vlan_offload_on =
3680         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3681                               on, "on#off");
3682 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3683         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3684                               port_id, NULL);
3685
3686 cmdline_parse_inst_t cmd_vlan_offload = {
3687         .f = cmd_vlan_offload_parsed,
3688         .data = NULL,
3689         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3690                 "<port_id[,queue_id]>: "
3691                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3692         .tokens = {
3693                 (void *)&cmd_vlan_offload_vlan,
3694                 (void *)&cmd_vlan_offload_set,
3695                 (void *)&cmd_vlan_offload_what,
3696                 (void *)&cmd_vlan_offload_on,
3697                 (void *)&cmd_vlan_offload_portid,
3698                 NULL,
3699         },
3700 };
3701
3702 /* *** VLAN TPID SET ON A PORT *** */
3703 struct cmd_vlan_tpid_result {
3704         cmdline_fixed_string_t vlan;
3705         cmdline_fixed_string_t set;
3706         cmdline_fixed_string_t vlan_type;
3707         cmdline_fixed_string_t what;
3708         uint16_t tp_id;
3709         portid_t port_id;
3710 };
3711
3712 static void
3713 cmd_vlan_tpid_parsed(void *parsed_result,
3714                           __attribute__((unused)) struct cmdline *cl,
3715                           __attribute__((unused)) void *data)
3716 {
3717         struct cmd_vlan_tpid_result *res = parsed_result;
3718         enum rte_vlan_type vlan_type;
3719
3720         if (!strcmp(res->vlan_type, "inner"))
3721                 vlan_type = ETH_VLAN_TYPE_INNER;
3722         else if (!strcmp(res->vlan_type, "outer"))
3723                 vlan_type = ETH_VLAN_TYPE_OUTER;
3724         else {
3725                 printf("Unknown vlan type\n");
3726                 return;
3727         }
3728         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3729 }
3730
3731 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3732         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3733                                  vlan, "vlan");
3734 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3735         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3736                                  set, "set");
3737 cmdline_parse_token_string_t cmd_vlan_type =
3738         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3739                                  vlan_type, "inner#outer");
3740 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3741         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3742                                  what, "tpid");
3743 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3744         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3745                               tp_id, UINT16);
3746 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3747         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3748                               port_id, UINT16);
3749
3750 cmdline_parse_inst_t cmd_vlan_tpid = {
3751         .f = cmd_vlan_tpid_parsed,
3752         .data = NULL,
3753         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3754                 "Set the VLAN Ether type",
3755         .tokens = {
3756                 (void *)&cmd_vlan_tpid_vlan,
3757                 (void *)&cmd_vlan_tpid_set,
3758                 (void *)&cmd_vlan_type,
3759                 (void *)&cmd_vlan_tpid_what,
3760                 (void *)&cmd_vlan_tpid_tpid,
3761                 (void *)&cmd_vlan_tpid_portid,
3762                 NULL,
3763         },
3764 };
3765
3766 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3767 struct cmd_rx_vlan_filter_result {
3768         cmdline_fixed_string_t rx_vlan;
3769         cmdline_fixed_string_t what;
3770         uint16_t vlan_id;
3771         portid_t port_id;
3772 };
3773
3774 static void
3775 cmd_rx_vlan_filter_parsed(void *parsed_result,
3776                           __attribute__((unused)) struct cmdline *cl,
3777                           __attribute__((unused)) void *data)
3778 {
3779         struct cmd_rx_vlan_filter_result *res = parsed_result;
3780
3781         if (!strcmp(res->what, "add"))
3782                 rx_vft_set(res->port_id, res->vlan_id, 1);
3783         else
3784                 rx_vft_set(res->port_id, res->vlan_id, 0);
3785 }
3786
3787 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3788         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3789                                  rx_vlan, "rx_vlan");
3790 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3791         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3792                                  what, "add#rm");
3793 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3794         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3795                               vlan_id, UINT16);
3796 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3797         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3798                               port_id, UINT16);
3799
3800 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3801         .f = cmd_rx_vlan_filter_parsed,
3802         .data = NULL,
3803         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3804                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3805                 "identifiers filtered by a port",
3806         .tokens = {
3807                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3808                 (void *)&cmd_rx_vlan_filter_what,
3809                 (void *)&cmd_rx_vlan_filter_vlanid,
3810                 (void *)&cmd_rx_vlan_filter_portid,
3811                 NULL,
3812         },
3813 };
3814
3815 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3816 struct cmd_tx_vlan_set_result {
3817         cmdline_fixed_string_t tx_vlan;
3818         cmdline_fixed_string_t set;
3819         portid_t port_id;
3820         uint16_t vlan_id;
3821 };
3822
3823 static void
3824 cmd_tx_vlan_set_parsed(void *parsed_result,
3825                        __attribute__((unused)) struct cmdline *cl,
3826                        __attribute__((unused)) void *data)
3827 {
3828         struct cmd_tx_vlan_set_result *res = parsed_result;
3829
3830         if (!port_is_stopped(res->port_id)) {
3831                 printf("Please stop port %d first\n", res->port_id);
3832                 return;
3833         }
3834
3835         tx_vlan_set(res->port_id, res->vlan_id);
3836
3837         cmd_reconfig_device_queue(res->port_id, 1, 1);
3838 }
3839
3840 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3841         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3842                                  tx_vlan, "tx_vlan");
3843 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3844         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3845                                  set, "set");
3846 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3847         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3848                               port_id, UINT16);
3849 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3850         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3851                               vlan_id, UINT16);
3852
3853 cmdline_parse_inst_t cmd_tx_vlan_set = {
3854         .f = cmd_tx_vlan_set_parsed,
3855         .data = NULL,
3856         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3857                 "Enable hardware insertion of a single VLAN header "
3858                 "with a given TAG Identifier in packets sent on a port",
3859         .tokens = {
3860                 (void *)&cmd_tx_vlan_set_tx_vlan,
3861                 (void *)&cmd_tx_vlan_set_set,
3862                 (void *)&cmd_tx_vlan_set_portid,
3863                 (void *)&cmd_tx_vlan_set_vlanid,
3864                 NULL,
3865         },
3866 };
3867
3868 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3869 struct cmd_tx_vlan_set_qinq_result {
3870         cmdline_fixed_string_t tx_vlan;
3871         cmdline_fixed_string_t set;
3872         portid_t port_id;
3873         uint16_t vlan_id;
3874         uint16_t vlan_id_outer;
3875 };
3876
3877 static void
3878 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3879                             __attribute__((unused)) struct cmdline *cl,
3880                             __attribute__((unused)) void *data)
3881 {
3882         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3883
3884         if (!port_is_stopped(res->port_id)) {
3885                 printf("Please stop port %d first\n", res->port_id);
3886                 return;
3887         }
3888
3889         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3890
3891         cmd_reconfig_device_queue(res->port_id, 1, 1);
3892 }
3893
3894 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3895         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3896                 tx_vlan, "tx_vlan");
3897 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3898         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3899                 set, "set");
3900 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3901         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3902                 port_id, UINT16);
3903 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3904         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3905                 vlan_id, UINT16);
3906 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3907         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3908                 vlan_id_outer, UINT16);
3909
3910 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3911         .f = cmd_tx_vlan_set_qinq_parsed,
3912         .data = NULL,
3913         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3914                 "Enable hardware insertion of double VLAN header "
3915                 "with given TAG Identifiers in packets sent on a port",
3916         .tokens = {
3917                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3918                 (void *)&cmd_tx_vlan_set_qinq_set,
3919                 (void *)&cmd_tx_vlan_set_qinq_portid,
3920                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3921                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3922                 NULL,
3923         },
3924 };
3925
3926 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3927 struct cmd_tx_vlan_set_pvid_result {
3928         cmdline_fixed_string_t tx_vlan;
3929         cmdline_fixed_string_t set;
3930         cmdline_fixed_string_t pvid;
3931         portid_t port_id;
3932         uint16_t vlan_id;
3933         cmdline_fixed_string_t mode;
3934 };
3935
3936 static void
3937 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3938                             __attribute__((unused)) struct cmdline *cl,
3939                             __attribute__((unused)) void *data)
3940 {
3941         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3942
3943         if (strcmp(res->mode, "on") == 0)
3944                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3945         else
3946                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3947 }
3948
3949 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3950         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3951                                  tx_vlan, "tx_vlan");
3952 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3953         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3954                                  set, "set");
3955 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3956         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3957                                  pvid, "pvid");
3958 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3959         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3960                              port_id, UINT16);
3961 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3962         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3963                               vlan_id, UINT16);
3964 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3965         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3966                                  mode, "on#off");
3967
3968 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3969         .f = cmd_tx_vlan_set_pvid_parsed,
3970         .data = NULL,
3971         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3972         .tokens = {
3973                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3974                 (void *)&cmd_tx_vlan_set_pvid_set,
3975                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3976                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3977                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3978                 (void *)&cmd_tx_vlan_set_pvid_mode,
3979                 NULL,
3980         },
3981 };
3982
3983 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3984 struct cmd_tx_vlan_reset_result {
3985         cmdline_fixed_string_t tx_vlan;
3986         cmdline_fixed_string_t reset;
3987         portid_t port_id;
3988 };
3989
3990 static void
3991 cmd_tx_vlan_reset_parsed(void *parsed_result,
3992                          __attribute__((unused)) struct cmdline *cl,
3993                          __attribute__((unused)) void *data)
3994 {
3995         struct cmd_tx_vlan_reset_result *res = parsed_result;
3996
3997         if (!port_is_stopped(res->port_id)) {
3998                 printf("Please stop port %d first\n", res->port_id);
3999                 return;
4000         }
4001
4002         tx_vlan_reset(res->port_id);
4003
4004         cmd_reconfig_device_queue(res->port_id, 1, 1);
4005 }
4006
4007 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4008         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4009                                  tx_vlan, "tx_vlan");
4010 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4011         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4012                                  reset, "reset");
4013 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4014         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4015                               port_id, UINT16);
4016
4017 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4018         .f = cmd_tx_vlan_reset_parsed,
4019         .data = NULL,
4020         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4021                 "VLAN header in packets sent on a port",
4022         .tokens = {
4023                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4024                 (void *)&cmd_tx_vlan_reset_reset,
4025                 (void *)&cmd_tx_vlan_reset_portid,
4026                 NULL,
4027         },
4028 };
4029
4030
4031 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4032 struct cmd_csum_result {
4033         cmdline_fixed_string_t csum;
4034         cmdline_fixed_string_t mode;
4035         cmdline_fixed_string_t proto;
4036         cmdline_fixed_string_t hwsw;
4037         portid_t port_id;
4038 };
4039
4040 static void
4041 csum_show(int port_id)
4042 {
4043         struct rte_eth_dev_info dev_info;
4044         uint64_t tx_offloads;
4045
4046         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4047         printf("Parse tunnel is %s\n",
4048                 (ports[port_id].parse_tunnel) ? "on" : "off");
4049         printf("IP checksum offload is %s\n",
4050                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4051         printf("UDP checksum offload is %s\n",
4052                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4053         printf("TCP checksum offload is %s\n",
4054                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4055         printf("SCTP checksum offload is %s\n",
4056                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4057         printf("Outer-Ip checksum offload is %s\n",
4058                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4059
4060         /* display warnings if configuration is not supported by the NIC */
4061         rte_eth_dev_info_get(port_id, &dev_info);
4062         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4063                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4064                 printf("Warning: hardware IP checksum enabled but not "
4065                         "supported by port %d\n", port_id);
4066         }
4067         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4068                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4069                 printf("Warning: hardware UDP checksum enabled but not "
4070                         "supported by port %d\n", port_id);
4071         }
4072         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4073                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4074                 printf("Warning: hardware TCP checksum enabled but not "
4075                         "supported by port %d\n", port_id);
4076         }
4077         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4078                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4079                 printf("Warning: hardware SCTP checksum enabled but not "
4080                         "supported by port %d\n", port_id);
4081         }
4082         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4083                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4084                 printf("Warning: hardware outer IP checksum enabled but not "
4085                         "supported by port %d\n", port_id);
4086         }
4087 }
4088
4089 static void
4090 cmd_csum_parsed(void *parsed_result,
4091                        __attribute__((unused)) struct cmdline *cl,
4092                        __attribute__((unused)) void *data)
4093 {
4094         struct cmd_csum_result *res = parsed_result;
4095         int hw = 0;
4096         uint64_t csum_offloads = 0;
4097         struct rte_eth_dev_info dev_info;
4098
4099         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4100                 printf("invalid port %d\n", res->port_id);
4101                 return;
4102         }
4103         if (!port_is_stopped(res->port_id)) {
4104                 printf("Please stop port %d first\n", res->port_id);
4105                 return;
4106         }
4107
4108         rte_eth_dev_info_get(res->port_id, &dev_info);
4109         if (!strcmp(res->mode, "set")) {
4110
4111                 if (!strcmp(res->hwsw, "hw"))
4112                         hw = 1;
4113
4114                 if (!strcmp(res->proto, "ip")) {
4115                         if (hw == 0 || (dev_info.tx_offload_capa &
4116                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4117                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4118                         } else {
4119                                 printf("IP checksum offload is not supported "
4120                                        "by port %u\n", res->port_id);
4121                         }
4122                 } else if (!strcmp(res->proto, "udp")) {
4123                         if (hw == 0 || (dev_info.tx_offload_capa &
4124                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4125                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4126                         } else {
4127                                 printf("UDP checksum offload is not supported "
4128                                        "by port %u\n", res->port_id);
4129                         }
4130                 } else if (!strcmp(res->proto, "tcp")) {
4131                         if (hw == 0 || (dev_info.tx_offload_capa &
4132                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4133                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4134                         } else {
4135                                 printf("TCP checksum offload is not supported "
4136                                        "by port %u\n", res->port_id);
4137                         }
4138                 } else if (!strcmp(res->proto, "sctp")) {
4139                         if (hw == 0 || (dev_info.tx_offload_capa &
4140                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4141                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4142                         } else {
4143                                 printf("SCTP checksum offload is not supported "
4144                                        "by port %u\n", res->port_id);
4145                         }
4146                 } else if (!strcmp(res->proto, "outer-ip")) {
4147                         if (hw == 0 || (dev_info.tx_offload_capa &
4148                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4149                                 csum_offloads |=
4150                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4151                         } else {
4152                                 printf("Outer IP checksum offload is not "
4153                                        "supported by port %u\n", res->port_id);
4154                         }
4155                 }
4156
4157                 if (hw) {
4158                         ports[res->port_id].dev_conf.txmode.offloads |=
4159                                                         csum_offloads;
4160                 } else {
4161                         ports[res->port_id].dev_conf.txmode.offloads &=
4162                                                         (~csum_offloads);
4163                 }
4164         }
4165         csum_show(res->port_id);
4166
4167         cmd_reconfig_device_queue(res->port_id, 1, 1);
4168 }
4169
4170 cmdline_parse_token_string_t cmd_csum_csum =
4171         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4172                                 csum, "csum");
4173 cmdline_parse_token_string_t cmd_csum_mode =
4174         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4175                                 mode, "set");
4176 cmdline_parse_token_string_t cmd_csum_proto =
4177         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4178                                 proto, "ip#tcp#udp#sctp#outer-ip");
4179 cmdline_parse_token_string_t cmd_csum_hwsw =
4180         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4181                                 hwsw, "hw#sw");
4182 cmdline_parse_token_num_t cmd_csum_portid =
4183         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4184                                 port_id, UINT16);
4185
4186 cmdline_parse_inst_t cmd_csum_set = {
4187         .f = cmd_csum_parsed,
4188         .data = NULL,
4189         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4190                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4191                 "using csum forward engine",
4192         .tokens = {
4193                 (void *)&cmd_csum_csum,
4194                 (void *)&cmd_csum_mode,
4195                 (void *)&cmd_csum_proto,
4196                 (void *)&cmd_csum_hwsw,
4197                 (void *)&cmd_csum_portid,
4198                 NULL,
4199         },
4200 };
4201
4202 cmdline_parse_token_string_t cmd_csum_mode_show =
4203         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4204                                 mode, "show");
4205
4206 cmdline_parse_inst_t cmd_csum_show = {
4207         .f = cmd_csum_parsed,
4208         .data = NULL,
4209         .help_str = "csum show <port_id>: Show checksum offload configuration",
4210         .tokens = {
4211                 (void *)&cmd_csum_csum,
4212                 (void *)&cmd_csum_mode_show,
4213                 (void *)&cmd_csum_portid,
4214                 NULL,
4215         },
4216 };
4217
4218 /* Enable/disable tunnel parsing */
4219 struct cmd_csum_tunnel_result {
4220         cmdline_fixed_string_t csum;
4221         cmdline_fixed_string_t parse;
4222         cmdline_fixed_string_t onoff;
4223         portid_t port_id;
4224 };
4225
4226 static void
4227 cmd_csum_tunnel_parsed(void *parsed_result,
4228                        __attribute__((unused)) struct cmdline *cl,
4229                        __attribute__((unused)) void *data)
4230 {
4231         struct cmd_csum_tunnel_result *res = parsed_result;
4232
4233         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4234                 return;
4235
4236         if (!strcmp(res->onoff, "on"))
4237                 ports[res->port_id].parse_tunnel = 1;
4238         else
4239                 ports[res->port_id].parse_tunnel = 0;
4240
4241         csum_show(res->port_id);
4242 }
4243
4244 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4245         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4246                                 csum, "csum");
4247 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4248         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4249                                 parse, "parse_tunnel");
4250 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4251         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4252                                 onoff, "on#off");
4253 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4254         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4255                                 port_id, UINT16);
4256
4257 cmdline_parse_inst_t cmd_csum_tunnel = {
4258         .f = cmd_csum_tunnel_parsed,
4259         .data = NULL,
4260         .help_str = "csum parse_tunnel on|off <port_id>: "
4261                 "Enable/Disable parsing of tunnels for csum engine",
4262         .tokens = {
4263                 (void *)&cmd_csum_tunnel_csum,
4264                 (void *)&cmd_csum_tunnel_parse,
4265                 (void *)&cmd_csum_tunnel_onoff,
4266                 (void *)&cmd_csum_tunnel_portid,
4267                 NULL,
4268         },
4269 };
4270
4271 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4272 struct cmd_tso_set_result {
4273         cmdline_fixed_string_t tso;
4274         cmdline_fixed_string_t mode;
4275         uint16_t tso_segsz;
4276         portid_t port_id;
4277 };
4278
4279 static void
4280 cmd_tso_set_parsed(void *parsed_result,
4281                        __attribute__((unused)) struct cmdline *cl,
4282                        __attribute__((unused)) void *data)
4283 {
4284         struct cmd_tso_set_result *res = parsed_result;
4285         struct rte_eth_dev_info dev_info;
4286
4287         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4288                 return;
4289         if (!port_is_stopped(res->port_id)) {
4290                 printf("Please stop port %d first\n", res->port_id);
4291                 return;
4292         }
4293
4294         if (!strcmp(res->mode, "set"))
4295                 ports[res->port_id].tso_segsz = res->tso_segsz;
4296
4297         rte_eth_dev_info_get(res->port_id, &dev_info);
4298         if ((ports[res->port_id].tso_segsz != 0) &&
4299                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4300                 printf("Error: TSO is not supported by port %d\n",
4301                        res->port_id);
4302                 return;
4303         }
4304
4305         if (ports[res->port_id].tso_segsz == 0) {
4306                 ports[res->port_id].dev_conf.txmode.offloads &=
4307                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4308                 printf("TSO for non-tunneled packets is disabled\n");
4309         } else {
4310                 ports[res->port_id].dev_conf.txmode.offloads |=
4311                                                 DEV_TX_OFFLOAD_TCP_TSO;
4312                 printf("TSO segment size for non-tunneled packets is %d\n",
4313                         ports[res->port_id].tso_segsz);
4314         }
4315
4316         /* display warnings if configuration is not supported by the NIC */
4317         rte_eth_dev_info_get(res->port_id, &dev_info);
4318         if ((ports[res->port_id].tso_segsz != 0) &&
4319                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4320                 printf("Warning: TSO enabled but not "
4321                         "supported by port %d\n", res->port_id);
4322         }
4323
4324         cmd_reconfig_device_queue(res->port_id, 1, 1);
4325 }
4326
4327 cmdline_parse_token_string_t cmd_tso_set_tso =
4328         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4329                                 tso, "tso");
4330 cmdline_parse_token_string_t cmd_tso_set_mode =
4331         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4332                                 mode, "set");
4333 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4334         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4335                                 tso_segsz, UINT16);
4336 cmdline_parse_token_num_t cmd_tso_set_portid =
4337         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4338                                 port_id, UINT16);
4339
4340 cmdline_parse_inst_t cmd_tso_set = {
4341         .f = cmd_tso_set_parsed,
4342         .data = NULL,
4343         .help_str = "tso set <tso_segsz> <port_id>: "
4344                 "Set TSO segment size of non-tunneled packets for csum engine "
4345                 "(0 to disable)",
4346         .tokens = {
4347                 (void *)&cmd_tso_set_tso,
4348                 (void *)&cmd_tso_set_mode,
4349                 (void *)&cmd_tso_set_tso_segsz,
4350                 (void *)&cmd_tso_set_portid,
4351                 NULL,
4352         },
4353 };
4354
4355 cmdline_parse_token_string_t cmd_tso_show_mode =
4356         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4357                                 mode, "show");
4358
4359
4360 cmdline_parse_inst_t cmd_tso_show = {
4361         .f = cmd_tso_set_parsed,
4362         .data = NULL,
4363         .help_str = "tso show <port_id>: "
4364                 "Show TSO segment size of non-tunneled packets for csum engine",
4365         .tokens = {
4366                 (void *)&cmd_tso_set_tso,
4367                 (void *)&cmd_tso_show_mode,
4368                 (void *)&cmd_tso_set_portid,
4369                 NULL,
4370         },
4371 };
4372
4373 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4374 struct cmd_tunnel_tso_set_result {
4375         cmdline_fixed_string_t tso;
4376         cmdline_fixed_string_t mode;
4377         uint16_t tso_segsz;
4378         portid_t port_id;
4379 };
4380
4381 static struct rte_eth_dev_info
4382 check_tunnel_tso_nic_support(portid_t port_id)
4383 {
4384         struct rte_eth_dev_info dev_info;
4385
4386         rte_eth_dev_info_get(port_id, &dev_info);
4387         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4388                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4389                        "not enabled for port %d\n", port_id);
4390         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4391                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4392                        "not enabled for port %d\n", port_id);
4393         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4394                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4395                        "not enabled for port %d\n", port_id);
4396         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4397                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4398                        "not enabled for port %d\n", port_id);
4399         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4400                 printf("Warning: IP TUNNEL TSO not supported therefore "
4401                        "not enabled for port %d\n", port_id);
4402         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4403                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4404                        "not enabled for port %d\n", port_id);
4405         return dev_info;
4406 }
4407
4408 static void
4409 cmd_tunnel_tso_set_parsed(void *parsed_result,
4410                           __attribute__((unused)) struct cmdline *cl,
4411                           __attribute__((unused)) void *data)
4412 {
4413         struct cmd_tunnel_tso_set_result *res = parsed_result;
4414         struct rte_eth_dev_info dev_info;
4415
4416         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4417                 return;
4418         if (!port_is_stopped(res->port_id)) {
4419                 printf("Please stop port %d first\n", res->port_id);
4420                 return;
4421         }
4422
4423         if (!strcmp(res->mode, "set"))
4424                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4425
4426         dev_info = check_tunnel_tso_nic_support(res->port_id);
4427         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4428                 ports[res->port_id].dev_conf.txmode.offloads &=
4429                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4430                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4431                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4432                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4433                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4434                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4435                 printf("TSO for tunneled packets is disabled\n");
4436         } else {
4437                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4438                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4439                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4440                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4441                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4442                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4443
4444                 ports[res->port_id].dev_conf.txmode.offloads |=
4445                         (tso_offloads & dev_info.tx_offload_capa);
4446                 printf("TSO segment size for tunneled packets is %d\n",
4447                         ports[res->port_id].tunnel_tso_segsz);
4448
4449                 /* Below conditions are needed to make it work:
4450                  * (1) tunnel TSO is supported by the NIC;
4451                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4452                  * are recognized;
4453                  * (3) for tunneled pkts with outer L3 of IPv4,
4454                  * "csum set outer-ip" must be set to hw, because after tso,
4455                  * total_len of outer IP header is changed, and the checksum
4456                  * of outer IP header calculated by sw should be wrong; that
4457                  * is not necessary for IPv6 tunneled pkts because there's no
4458                  * checksum in IP header anymore.
4459                  */
4460
4461                 if (!ports[res->port_id].parse_tunnel)
4462                         printf("Warning: csum parse_tunnel must be set "
4463                                 "so that tunneled packets are recognized\n");
4464                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4465                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4466                         printf("Warning: csum set outer-ip must be set to hw "
4467                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4468         }
4469
4470         cmd_reconfig_device_queue(res->port_id, 1, 1);
4471 }
4472
4473 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4474         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4475                                 tso, "tunnel_tso");
4476 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4477         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4478                                 mode, "set");
4479 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4480         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4481                                 tso_segsz, UINT16);
4482 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4483         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4484                                 port_id, UINT16);
4485
4486 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4487         .f = cmd_tunnel_tso_set_parsed,
4488         .data = NULL,
4489         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4490                 "Set TSO segment size of tunneled packets for csum engine "
4491                 "(0 to disable)",
4492         .tokens = {
4493                 (void *)&cmd_tunnel_tso_set_tso,
4494                 (void *)&cmd_tunnel_tso_set_mode,
4495                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4496                 (void *)&cmd_tunnel_tso_set_portid,
4497                 NULL,
4498         },
4499 };
4500
4501 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4502         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4503                                 mode, "show");
4504
4505
4506 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4507         .f = cmd_tunnel_tso_set_parsed,
4508         .data = NULL,
4509         .help_str = "tunnel_tso show <port_id> "
4510                 "Show TSO segment size of tunneled packets for csum engine",
4511         .tokens = {
4512                 (void *)&cmd_tunnel_tso_set_tso,
4513                 (void *)&cmd_tunnel_tso_show_mode,
4514                 (void *)&cmd_tunnel_tso_set_portid,
4515                 NULL,
4516         },
4517 };
4518
4519 /* *** SET GRO FOR A PORT *** */
4520 struct cmd_gro_enable_result {
4521         cmdline_fixed_string_t cmd_set;
4522         cmdline_fixed_string_t cmd_port;
4523         cmdline_fixed_string_t cmd_keyword;
4524         cmdline_fixed_string_t cmd_onoff;
4525         portid_t cmd_pid;
4526 };
4527
4528 static void
4529 cmd_gro_enable_parsed(void *parsed_result,
4530                 __attribute__((unused)) struct cmdline *cl,
4531                 __attribute__((unused)) void *data)
4532 {
4533         struct cmd_gro_enable_result *res;
4534
4535         res = parsed_result;
4536         if (!strcmp(res->cmd_keyword, "gro"))
4537                 setup_gro(res->cmd_onoff, res->cmd_pid);
4538 }
4539
4540 cmdline_parse_token_string_t cmd_gro_enable_set =
4541         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4542                         cmd_set, "set");
4543 cmdline_parse_token_string_t cmd_gro_enable_port =
4544         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4545                         cmd_keyword, "port");
4546 cmdline_parse_token_num_t cmd_gro_enable_pid =
4547         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4548                         cmd_pid, UINT16);
4549 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4550         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4551                         cmd_keyword, "gro");
4552 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4553         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4554                         cmd_onoff, "on#off");
4555
4556 cmdline_parse_inst_t cmd_gro_enable = {
4557         .f = cmd_gro_enable_parsed,
4558         .data = NULL,
4559         .help_str = "set port <port_id> gro on|off",
4560         .tokens = {
4561                 (void *)&cmd_gro_enable_set,
4562                 (void *)&cmd_gro_enable_port,
4563                 (void *)&cmd_gro_enable_pid,
4564                 (void *)&cmd_gro_enable_keyword,
4565                 (void *)&cmd_gro_enable_onoff,
4566                 NULL,
4567         },
4568 };
4569
4570 /* *** DISPLAY GRO CONFIGURATION *** */
4571 struct cmd_gro_show_result {
4572         cmdline_fixed_string_t cmd_show;
4573         cmdline_fixed_string_t cmd_port;
4574         cmdline_fixed_string_t cmd_keyword;
4575         portid_t cmd_pid;
4576 };
4577
4578 static void
4579 cmd_gro_show_parsed(void *parsed_result,
4580                 __attribute__((unused)) struct cmdline *cl,
4581                 __attribute__((unused)) void *data)
4582 {
4583         struct cmd_gro_show_result *res;
4584
4585         res = parsed_result;
4586         if (!strcmp(res->cmd_keyword, "gro"))
4587                 show_gro(res->cmd_pid);
4588 }
4589
4590 cmdline_parse_token_string_t cmd_gro_show_show =
4591         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4592                         cmd_show, "show");
4593 cmdline_parse_token_string_t cmd_gro_show_port =
4594         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4595                         cmd_port, "port");
4596 cmdline_parse_token_num_t cmd_gro_show_pid =
4597         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4598                         cmd_pid, UINT16);
4599 cmdline_parse_token_string_t cmd_gro_show_keyword =
4600         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4601                         cmd_keyword, "gro");
4602
4603 cmdline_parse_inst_t cmd_gro_show = {
4604         .f = cmd_gro_show_parsed,
4605         .data = NULL,
4606         .help_str = "show port <port_id> gro",
4607         .tokens = {
4608                 (void *)&cmd_gro_show_show,
4609                 (void *)&cmd_gro_show_port,
4610                 (void *)&cmd_gro_show_pid,
4611                 (void *)&cmd_gro_show_keyword,
4612                 NULL,
4613         },
4614 };
4615
4616 /* *** SET FLUSH CYCLES FOR GRO *** */
4617 struct cmd_gro_flush_result {
4618         cmdline_fixed_string_t cmd_set;
4619         cmdline_fixed_string_t cmd_keyword;
4620         cmdline_fixed_string_t cmd_flush;
4621         uint8_t cmd_cycles;
4622 };
4623
4624 static void
4625 cmd_gro_flush_parsed(void *parsed_result,
4626                 __attribute__((unused)) struct cmdline *cl,
4627                 __attribute__((unused)) void *data)
4628 {
4629         struct cmd_gro_flush_result *res;
4630
4631         res = parsed_result;
4632         if ((!strcmp(res->cmd_keyword, "gro")) &&
4633                         (!strcmp(res->cmd_flush, "flush")))
4634                 setup_gro_flush_cycles(res->cmd_cycles);
4635 }
4636
4637 cmdline_parse_token_string_t cmd_gro_flush_set =
4638         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4639                         cmd_set, "set");
4640 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4641         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4642                         cmd_keyword, "gro");
4643 cmdline_parse_token_string_t cmd_gro_flush_flush =
4644         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4645                         cmd_flush, "flush");
4646 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4647         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4648                         cmd_cycles, UINT8);
4649
4650 cmdline_parse_inst_t cmd_gro_flush = {
4651         .f = cmd_gro_flush_parsed,
4652         .data = NULL,
4653         .help_str = "set gro flush <cycles>",
4654         .tokens = {
4655                 (void *)&cmd_gro_flush_set,
4656                 (void *)&cmd_gro_flush_keyword,
4657                 (void *)&cmd_gro_flush_flush,
4658                 (void *)&cmd_gro_flush_cycles,
4659                 NULL,
4660         },
4661 };
4662
4663 /* *** ENABLE/DISABLE GSO *** */
4664 struct cmd_gso_enable_result {
4665         cmdline_fixed_string_t cmd_set;
4666         cmdline_fixed_string_t cmd_port;
4667         cmdline_fixed_string_t cmd_keyword;
4668         cmdline_fixed_string_t cmd_mode;
4669         portid_t cmd_pid;
4670 };
4671
4672 static void
4673 cmd_gso_enable_parsed(void *parsed_result,
4674                 __attribute__((unused)) struct cmdline *cl,
4675                 __attribute__((unused)) void *data)
4676 {
4677         struct cmd_gso_enable_result *res;
4678
4679         res = parsed_result;
4680         if (!strcmp(res->cmd_keyword, "gso"))
4681                 setup_gso(res->cmd_mode, res->cmd_pid);
4682 }
4683
4684 cmdline_parse_token_string_t cmd_gso_enable_set =
4685         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4686                         cmd_set, "set");
4687 cmdline_parse_token_string_t cmd_gso_enable_port =
4688         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4689                         cmd_port, "port");
4690 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4691         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4692                         cmd_keyword, "gso");
4693 cmdline_parse_token_string_t cmd_gso_enable_mode =
4694         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4695                         cmd_mode, "on#off");
4696 cmdline_parse_token_num_t cmd_gso_enable_pid =
4697         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4698                         cmd_pid, UINT16);
4699
4700 cmdline_parse_inst_t cmd_gso_enable = {
4701         .f = cmd_gso_enable_parsed,
4702         .data = NULL,
4703         .help_str = "set port <port_id> gso on|off",
4704         .tokens = {
4705                 (void *)&cmd_gso_enable_set,
4706                 (void *)&cmd_gso_enable_port,
4707                 (void *)&cmd_gso_enable_pid,
4708                 (void *)&cmd_gso_enable_keyword,
4709                 (void *)&cmd_gso_enable_mode,
4710                 NULL,
4711         },
4712 };
4713
4714 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4715 struct cmd_gso_size_result {
4716         cmdline_fixed_string_t cmd_set;
4717         cmdline_fixed_string_t cmd_keyword;
4718         cmdline_fixed_string_t cmd_segsz;
4719         uint16_t cmd_size;
4720 };
4721
4722 static void
4723 cmd_gso_size_parsed(void *parsed_result,
4724                        __attribute__((unused)) struct cmdline *cl,
4725                        __attribute__((unused)) void *data)
4726 {
4727         struct cmd_gso_size_result *res = parsed_result;
4728
4729         if (test_done == 0) {
4730                 printf("Before setting GSO segsz, please first"
4731                                 " stop fowarding\n");
4732                 return;
4733         }
4734
4735         if (!strcmp(res->cmd_keyword, "gso") &&
4736                         !strcmp(res->cmd_segsz, "segsz")) {
4737                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4738                         printf("gso_size should be larger than %zu."
4739                                         " Please input a legal value\n",
4740                                         RTE_GSO_SEG_SIZE_MIN);
4741                 else
4742                         gso_max_segment_size = res->cmd_size;
4743         }
4744 }
4745
4746 cmdline_parse_token_string_t cmd_gso_size_set =
4747         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4748                                 cmd_set, "set");
4749 cmdline_parse_token_string_t cmd_gso_size_keyword =
4750         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4751                                 cmd_keyword, "gso");
4752 cmdline_parse_token_string_t cmd_gso_size_segsz =
4753         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4754                                 cmd_segsz, "segsz");
4755 cmdline_parse_token_num_t cmd_gso_size_size =
4756         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4757                                 cmd_size, UINT16);
4758
4759 cmdline_parse_inst_t cmd_gso_size = {
4760         .f = cmd_gso_size_parsed,
4761         .data = NULL,
4762         .help_str = "set gso segsz <length>",
4763         .tokens = {
4764                 (void *)&cmd_gso_size_set,
4765                 (void *)&cmd_gso_size_keyword,
4766                 (void *)&cmd_gso_size_segsz,
4767                 (void *)&cmd_gso_size_size,
4768                 NULL,
4769         },
4770 };
4771
4772 /* *** SHOW GSO CONFIGURATION *** */
4773 struct cmd_gso_show_result {
4774         cmdline_fixed_string_t cmd_show;
4775         cmdline_fixed_string_t cmd_port;
4776         cmdline_fixed_string_t cmd_keyword;
4777         portid_t cmd_pid;
4778 };
4779
4780 static void
4781 cmd_gso_show_parsed(void *parsed_result,
4782                        __attribute__((unused)) struct cmdline *cl,
4783                        __attribute__((unused)) void *data)
4784 {
4785         struct cmd_gso_show_result *res = parsed_result;
4786
4787         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4788                 printf("invalid port id %u\n", res->cmd_pid);
4789                 return;
4790         }
4791         if (!strcmp(res->cmd_keyword, "gso")) {
4792                 if (gso_ports[res->cmd_pid].enable) {
4793                         printf("Max GSO'd packet size: %uB\n"
4794                                         "Supported GSO types: TCP/IPv4, "
4795                                         "VxLAN with inner TCP/IPv4 packet, "
4796                                         "GRE with inner TCP/IPv4  packet\n",
4797                                         gso_max_segment_size);
4798                 } else
4799                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4800         }
4801 }
4802
4803 cmdline_parse_token_string_t cmd_gso_show_show =
4804 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4805                 cmd_show, "show");
4806 cmdline_parse_token_string_t cmd_gso_show_port =
4807 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4808                 cmd_port, "port");
4809 cmdline_parse_token_string_t cmd_gso_show_keyword =
4810         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4811                                 cmd_keyword, "gso");
4812 cmdline_parse_token_num_t cmd_gso_show_pid =
4813         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4814                                 cmd_pid, UINT16);
4815
4816 cmdline_parse_inst_t cmd_gso_show = {
4817         .f = cmd_gso_show_parsed,
4818         .data = NULL,
4819         .help_str = "show port <port_id> gso",
4820         .tokens = {
4821                 (void *)&cmd_gso_show_show,
4822                 (void *)&cmd_gso_show_port,
4823                 (void *)&cmd_gso_show_pid,
4824                 (void *)&cmd_gso_show_keyword,
4825                 NULL,
4826         },
4827 };
4828
4829 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4830 struct cmd_set_flush_rx {
4831         cmdline_fixed_string_t set;
4832         cmdline_fixed_string_t flush_rx;
4833         cmdline_fixed_string_t mode;
4834 };
4835
4836 static void
4837 cmd_set_flush_rx_parsed(void *parsed_result,
4838                 __attribute__((unused)) struct cmdline *cl,
4839                 __attribute__((unused)) void *data)
4840 {
4841         struct cmd_set_flush_rx *res = parsed_result;
4842         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4843 }
4844
4845 cmdline_parse_token_string_t cmd_setflushrx_set =
4846         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4847                         set, "set");
4848 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4849         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4850                         flush_rx, "flush_rx");
4851 cmdline_parse_token_string_t cmd_setflushrx_mode =
4852         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4853                         mode, "on#off");
4854
4855
4856 cmdline_parse_inst_t cmd_set_flush_rx = {
4857         .f = cmd_set_flush_rx_parsed,
4858         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4859         .data = NULL,
4860         .tokens = {
4861                 (void *)&cmd_setflushrx_set,
4862                 (void *)&cmd_setflushrx_flush_rx,
4863                 (void *)&cmd_setflushrx_mode,
4864                 NULL,
4865         },
4866 };
4867
4868 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4869 struct cmd_set_link_check {
4870         cmdline_fixed_string_t set;
4871         cmdline_fixed_string_t link_check;
4872         cmdline_fixed_string_t mode;
4873 };
4874
4875 static void
4876 cmd_set_link_check_parsed(void *parsed_result,
4877                 __attribute__((unused)) struct cmdline *cl,
4878                 __attribute__((unused)) void *data)
4879 {
4880         struct cmd_set_link_check *res = parsed_result;
4881         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4882 }
4883
4884 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4885         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4886                         set, "set");
4887 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4888         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4889                         link_check, "link_check");
4890 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4891         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4892                         mode, "on#off");
4893
4894
4895 cmdline_parse_inst_t cmd_set_link_check = {
4896         .f = cmd_set_link_check_parsed,
4897         .help_str = "set link_check on|off: Enable/Disable link status check "
4898                     "when starting/stopping a port",
4899         .data = NULL,
4900         .tokens = {
4901                 (void *)&cmd_setlinkcheck_set,
4902                 (void *)&cmd_setlinkcheck_link_check,
4903                 (void *)&cmd_setlinkcheck_mode,
4904                 NULL,
4905         },
4906 };
4907
4908 /* *** SET NIC BYPASS MODE *** */
4909 struct cmd_set_bypass_mode_result {
4910         cmdline_fixed_string_t set;
4911         cmdline_fixed_string_t bypass;
4912         cmdline_fixed_string_t mode;
4913         cmdline_fixed_string_t value;
4914         portid_t port_id;
4915 };
4916
4917 static void
4918 cmd_set_bypass_mode_parsed(void *parsed_result,
4919                 __attribute__((unused)) struct cmdline *cl,
4920                 __attribute__((unused)) void *data)
4921 {
4922         struct cmd_set_bypass_mode_result *res = parsed_result;
4923         portid_t port_id = res->port_id;
4924         int32_t rc = -EINVAL;
4925
4926 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4927         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4928
4929         if (!strcmp(res->value, "bypass"))
4930                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4931         else if (!strcmp(res->value, "isolate"))
4932                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4933         else
4934                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4935
4936         /* Set the bypass mode for the relevant port. */
4937         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4938 #endif
4939         if (rc != 0)
4940                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4941 }
4942
4943 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4944         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4945                         set, "set");
4946 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4947         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4948                         bypass, "bypass");
4949 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4950         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4951                         mode, "mode");
4952 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4953         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4954                         value, "normal#bypass#isolate");
4955 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4956         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4957                                 port_id, UINT16);
4958
4959 cmdline_parse_inst_t cmd_set_bypass_mode = {
4960         .f = cmd_set_bypass_mode_parsed,
4961         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4962                     "Set the NIC bypass mode for port_id",
4963         .data = NULL,
4964         .tokens = {
4965                 (void *)&cmd_setbypass_mode_set,
4966                 (void *)&cmd_setbypass_mode_bypass,
4967                 (void *)&cmd_setbypass_mode_mode,
4968                 (void *)&cmd_setbypass_mode_value,
4969                 (void *)&cmd_setbypass_mode_port,
4970                 NULL,
4971         },
4972 };
4973
4974 /* *** SET NIC BYPASS EVENT *** */
4975 struct cmd_set_bypass_event_result {
4976         cmdline_fixed_string_t set;
4977         cmdline_fixed_string_t bypass;
4978         cmdline_fixed_string_t event;
4979         cmdline_fixed_string_t event_value;
4980         cmdline_fixed_string_t mode;
4981         cmdline_fixed_string_t mode_value;
4982         portid_t port_id;
4983 };
4984
4985 static void
4986 cmd_set_bypass_event_parsed(void *parsed_result,
4987                 __attribute__((unused)) struct cmdline *cl,
4988                 __attribute__((unused)) void *data)
4989 {
4990         int32_t rc = -EINVAL;
4991         struct cmd_set_bypass_event_result *res = parsed_result;
4992         portid_t port_id = res->port_id;
4993
4994 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4995         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4996         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4997
4998         if (!strcmp(res->event_value, "timeout"))
4999                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5000         else if (!strcmp(res->event_value, "os_on"))
5001                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5002         else if (!strcmp(res->event_value, "os_off"))
5003                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5004         else if (!strcmp(res->event_value, "power_on"))
5005                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5006         else if (!strcmp(res->event_value, "power_off"))
5007                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5008         else
5009                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5010
5011         if (!strcmp(res->mode_value, "bypass"))
5012                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5013         else if (!strcmp(res->mode_value, "isolate"))
5014                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5015         else
5016                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5017
5018         /* Set the watchdog timeout. */
5019         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5020
5021                 rc = -EINVAL;
5022                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5023                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5024                                                            bypass_timeout);
5025                 }
5026                 if (rc != 0) {
5027                         printf("Failed to set timeout value %u "
5028                         "for port %d, errto code: %d.\n",
5029                         bypass_timeout, port_id, rc);
5030                 }
5031         }
5032
5033         /* Set the bypass event to transition to bypass mode. */
5034         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5035                                               bypass_mode);
5036 #endif
5037
5038         if (rc != 0)
5039                 printf("\t Failed to set bypass event for port = %d.\n",
5040                        port_id);
5041 }
5042
5043 cmdline_parse_token_string_t cmd_setbypass_event_set =
5044         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5045                         set, "set");
5046 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5047         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5048                         bypass, "bypass");
5049 cmdline_parse_token_string_t cmd_setbypass_event_event =
5050         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5051                         event, "event");
5052 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5053         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5054                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5055 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5056         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5057                         mode, "mode");
5058 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5059         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5060                         mode_value, "normal#bypass#isolate");
5061 cmdline_parse_token_num_t cmd_setbypass_event_port =
5062         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5063                                 port_id, UINT16);
5064
5065 cmdline_parse_inst_t cmd_set_bypass_event = {
5066         .f = cmd_set_bypass_event_parsed,
5067         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5068                 "power_off mode normal|bypass|isolate <port_id>: "
5069                 "Set the NIC bypass event mode for port_id",
5070         .data = NULL,
5071         .tokens = {
5072                 (void *)&cmd_setbypass_event_set,
5073                 (void *)&cmd_setbypass_event_bypass,
5074                 (void *)&cmd_setbypass_event_event,
5075                 (void *)&cmd_setbypass_event_event_value,
5076                 (void *)&cmd_setbypass_event_mode,
5077                 (void *)&cmd_setbypass_event_mode_value,
5078                 (void *)&cmd_setbypass_event_port,
5079                 NULL,
5080         },
5081 };
5082
5083
5084 /* *** SET NIC BYPASS TIMEOUT *** */
5085 struct cmd_set_bypass_timeout_result {
5086         cmdline_fixed_string_t set;
5087         cmdline_fixed_string_t bypass;
5088         cmdline_fixed_string_t timeout;
5089         cmdline_fixed_string_t value;
5090 };
5091
5092 static void
5093 cmd_set_bypass_timeout_parsed(void *parsed_result,
5094                 __attribute__((unused)) struct cmdline *cl,
5095                 __attribute__((unused)) void *data)
5096 {
5097         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5098
5099 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5100         if (!strcmp(res->value, "1.5"))
5101                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5102         else if (!strcmp(res->value, "2"))
5103                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5104         else if (!strcmp(res->value, "3"))
5105                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5106         else if (!strcmp(res->value, "4"))
5107                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5108         else if (!strcmp(res->value, "8"))
5109                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5110         else if (!strcmp(res->value, "16"))
5111                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5112         else if (!strcmp(res->value, "32"))
5113                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5114         else
5115                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5116 #endif
5117 }
5118
5119 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5120         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5121                         set, "set");
5122 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5123         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5124                         bypass, "bypass");
5125 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5126         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5127                         timeout, "timeout");
5128 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5129         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5130                         value, "0#1.5#2#3#4#8#16#32");
5131
5132 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5133         .f = cmd_set_bypass_timeout_parsed,
5134         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5135                 "Set the NIC bypass watchdog timeout in seconds",
5136         .data = NULL,
5137         .tokens = {
5138                 (void *)&cmd_setbypass_timeout_set,
5139                 (void *)&cmd_setbypass_timeout_bypass,
5140                 (void *)&cmd_setbypass_timeout_timeout,
5141                 (void *)&cmd_setbypass_timeout_value,
5142                 NULL,
5143         },
5144 };
5145
5146 /* *** SHOW NIC BYPASS MODE *** */
5147 struct cmd_show_bypass_config_result {
5148         cmdline_fixed_string_t show;
5149         cmdline_fixed_string_t bypass;
5150         cmdline_fixed_string_t config;
5151         portid_t port_id;
5152 };
5153
5154 static void
5155 cmd_show_bypass_config_parsed(void *parsed_result,
5156                 __attribute__((unused)) struct cmdline *cl,
5157                 __attribute__((unused)) void *data)
5158 {
5159         struct cmd_show_bypass_config_result *res = parsed_result;
5160         portid_t port_id = res->port_id;
5161         int rc = -EINVAL;
5162 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5163         uint32_t event_mode;
5164         uint32_t bypass_mode;
5165         uint32_t timeout = bypass_timeout;
5166         int i;
5167
5168         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5169                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5170         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5171                 {"UNKNOWN", "normal", "bypass", "isolate"};
5172         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5173                 "NONE",
5174                 "OS/board on",
5175                 "power supply on",
5176                 "OS/board off",
5177                 "power supply off",
5178                 "timeout"};
5179         int num_events = (sizeof events) / (sizeof events[0]);
5180
5181         /* Display the bypass mode.*/
5182         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5183                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5184                 return;
5185         }
5186         else {
5187                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5188                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5189
5190                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5191         }
5192
5193         /* Display the bypass timeout.*/
5194         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5195                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5196
5197         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5198
5199         /* Display the bypass events and associated modes. */
5200         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5201
5202                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5203                         printf("\tFailed to get bypass mode for event = %s\n",
5204                                 events[i]);
5205                 } else {
5206                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5207                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5208
5209                         printf("\tbypass event: %-16s = %s\n", events[i],
5210                                 modes[event_mode]);
5211                 }
5212         }
5213 #endif
5214         if (rc != 0)
5215                 printf("\tFailed to get bypass configuration for port = %d\n",
5216                        port_id);
5217 }
5218
5219 cmdline_parse_token_string_t cmd_showbypass_config_show =
5220         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5221                         show, "show");
5222 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5223         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5224                         bypass, "bypass");
5225 cmdline_parse_token_string_t cmd_showbypass_config_config =
5226         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5227                         config, "config");
5228 cmdline_parse_token_num_t cmd_showbypass_config_port =
5229         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5230                                 port_id, UINT16);
5231
5232 cmdline_parse_inst_t cmd_show_bypass_config = {
5233         .f = cmd_show_bypass_config_parsed,
5234         .help_str = "show bypass config <port_id>: "
5235                     "Show the NIC bypass config for port_id",
5236         .data = NULL,
5237         .tokens = {
5238                 (void *)&cmd_showbypass_config_show,
5239                 (void *)&cmd_showbypass_config_bypass,
5240                 (void *)&cmd_showbypass_config_config,
5241                 (void *)&cmd_showbypass_config_port,
5242                 NULL,
5243         },
5244 };
5245
5246 #ifdef RTE_LIBRTE_PMD_BOND
5247 /* *** SET BONDING MODE *** */
5248 struct cmd_set_bonding_mode_result {
5249         cmdline_fixed_string_t set;
5250         cmdline_fixed_string_t bonding;
5251         cmdline_fixed_string_t mode;
5252         uint8_t value;
5253         portid_t port_id;
5254 };
5255
5256 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5257                 __attribute__((unused))  struct cmdline *cl,
5258                 __attribute__((unused)) void *data)
5259 {
5260         struct cmd_set_bonding_mode_result *res = parsed_result;
5261         portid_t port_id = res->port_id;
5262
5263         /* Set the bonding mode for the relevant port. */
5264         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5265                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5266 }
5267
5268 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5269 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5270                 set, "set");
5271 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5272 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5273                 bonding, "bonding");
5274 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5275 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5276                 mode, "mode");
5277 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5278 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5279                 value, UINT8);
5280 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5281 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5282                 port_id, UINT16);
5283
5284 cmdline_parse_inst_t cmd_set_bonding_mode = {
5285                 .f = cmd_set_bonding_mode_parsed,
5286                 .help_str = "set bonding mode <mode_value> <port_id>: "
5287                         "Set the bonding mode for port_id",
5288                 .data = NULL,
5289                 .tokens = {
5290                                 (void *) &cmd_setbonding_mode_set,
5291                                 (void *) &cmd_setbonding_mode_bonding,
5292                                 (void *) &cmd_setbonding_mode_mode,
5293                                 (void *) &cmd_setbonding_mode_value,
5294                                 (void *) &cmd_setbonding_mode_port,
5295                                 NULL
5296                 }
5297 };
5298
5299 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5300 struct cmd_set_bonding_lacp_dedicated_queues_result {
5301         cmdline_fixed_string_t set;
5302         cmdline_fixed_string_t bonding;
5303         cmdline_fixed_string_t lacp;
5304         cmdline_fixed_string_t dedicated_queues;
5305         portid_t port_id;
5306         cmdline_fixed_string_t mode;
5307 };
5308
5309 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5310                 __attribute__((unused))  struct cmdline *cl,
5311                 __attribute__((unused)) void *data)
5312 {
5313         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5314         portid_t port_id = res->port_id;
5315         struct rte_port *port;
5316
5317         port = &ports[port_id];
5318
5319         /** Check if the port is not started **/
5320         if (port->port_status != RTE_PORT_STOPPED) {
5321                 printf("Please stop port %d first\n", port_id);
5322                 return;
5323         }
5324
5325         if (!strcmp(res->mode, "enable")) {
5326                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5327                         printf("Dedicate queues for LACP control packets"
5328                                         " enabled\n");
5329                 else
5330                         printf("Enabling dedicate queues for LACP control "
5331                                         "packets on port %d failed\n", port_id);
5332         } else if (!strcmp(res->mode, "disable")) {
5333                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5334                         printf("Dedicated queues for LACP control packets "
5335                                         "disabled\n");
5336                 else
5337                         printf("Disabling dedicated queues for LACP control "
5338                                         "traffic on port %d failed\n", port_id);
5339         }
5340 }
5341
5342 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5343 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5344                 set, "set");
5345 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5346 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5347                 bonding, "bonding");
5348 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5349 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5350                 lacp, "lacp");
5351 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5352 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5353                 dedicated_queues, "dedicated_queues");
5354 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5355 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5356                 port_id, UINT16);
5357 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5358 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5359                 mode, "enable#disable");
5360
5361 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5362                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5363                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5364                         "enable|disable: "
5365                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5366                 .data = NULL,
5367                 .tokens = {
5368                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5369                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5370                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5371                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5372                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5373                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5374                         NULL
5375                 }
5376 };
5377
5378 /* *** SET BALANCE XMIT POLICY *** */
5379 struct cmd_set_bonding_balance_xmit_policy_result {
5380         cmdline_fixed_string_t set;
5381         cmdline_fixed_string_t bonding;
5382         cmdline_fixed_string_t balance_xmit_policy;
5383         portid_t port_id;
5384         cmdline_fixed_string_t policy;
5385 };
5386
5387 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5388                 __attribute__((unused))  struct cmdline *cl,
5389                 __attribute__((unused)) void *data)
5390 {
5391         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5392         portid_t port_id = res->port_id;
5393         uint8_t policy;
5394
5395         if (!strcmp(res->policy, "l2")) {
5396                 policy = BALANCE_XMIT_POLICY_LAYER2;
5397         } else if (!strcmp(res->policy, "l23")) {
5398                 policy = BALANCE_XMIT_POLICY_LAYER23;
5399         } else if (!strcmp(res->policy, "l34")) {
5400                 policy = BALANCE_XMIT_POLICY_LAYER34;
5401         } else {
5402                 printf("\t Invalid xmit policy selection");
5403                 return;
5404         }
5405
5406         /* Set the bonding mode for the relevant port. */
5407         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5408                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5409                                 port_id);
5410         }
5411 }
5412
5413 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5414 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5415                 set, "set");
5416 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5417 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5418                 bonding, "bonding");
5419 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5420 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5421                 balance_xmit_policy, "balance_xmit_policy");
5422 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5423 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5424                 port_id, UINT16);
5425 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5426 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5427                 policy, "l2#l23#l34");
5428
5429 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5430                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5431                 .help_str = "set bonding balance_xmit_policy <port_id> "
5432                         "l2|l23|l34: "
5433                         "Set the bonding balance_xmit_policy for port_id",
5434                 .data = NULL,
5435                 .tokens = {
5436                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5437                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5438                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5439                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5440                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5441                                 NULL
5442                 }
5443 };
5444
5445 /* *** SHOW NIC BONDING CONFIGURATION *** */
5446 struct cmd_show_bonding_config_result {
5447         cmdline_fixed_string_t show;
5448         cmdline_fixed_string_t bonding;
5449         cmdline_fixed_string_t config;
5450         portid_t port_id;
5451 };
5452
5453 static void cmd_show_bonding_config_parsed(void *parsed_result,
5454                 __attribute__((unused))  struct cmdline *cl,
5455                 __attribute__((unused)) void *data)
5456 {
5457         struct cmd_show_bonding_config_result *res = parsed_result;
5458         int bonding_mode, agg_mode;
5459         portid_t slaves[RTE_MAX_ETHPORTS];
5460         int num_slaves, num_active_slaves;
5461         int primary_id;
5462         int i;
5463         portid_t port_id = res->port_id;
5464
5465         /* Display the bonding mode.*/
5466         bonding_mode = rte_eth_bond_mode_get(port_id);
5467         if (bonding_mode < 0) {
5468                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5469                 return;
5470         } else
5471                 printf("\tBonding mode: %d\n", bonding_mode);
5472
5473         if (bonding_mode == BONDING_MODE_BALANCE) {
5474                 int balance_xmit_policy;
5475
5476                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5477                 if (balance_xmit_policy < 0) {
5478                         printf("\tFailed to get balance xmit policy for port = %d\n",
5479                                         port_id);
5480                         return;
5481                 } else {
5482                         printf("\tBalance Xmit Policy: ");
5483
5484                         switch (balance_xmit_policy) {
5485                         case BALANCE_XMIT_POLICY_LAYER2:
5486                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5487                                 break;
5488                         case BALANCE_XMIT_POLICY_LAYER23:
5489                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5490                                 break;
5491                         case BALANCE_XMIT_POLICY_LAYER34:
5492                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5493                                 break;
5494                         }
5495                         printf("\n");
5496                 }
5497         }
5498
5499         if (bonding_mode == BONDING_MODE_8023AD) {
5500                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5501                 printf("\tIEEE802.3AD Aggregator Mode: ");
5502                 switch (agg_mode) {
5503                 case AGG_BANDWIDTH:
5504                         printf("bandwidth");
5505                         break;
5506                 case AGG_STABLE:
5507                         printf("stable");
5508                         break;
5509                 case AGG_COUNT:
5510                         printf("count");
5511                         break;
5512                 }
5513                 printf("\n");
5514         }
5515
5516         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5517
5518         if (num_slaves < 0) {
5519                 printf("\tFailed to get slave list for port = %d\n", port_id);
5520                 return;
5521         }
5522         if (num_slaves > 0) {
5523                 printf("\tSlaves (%d): [", num_slaves);
5524                 for (i = 0; i < num_slaves - 1; i++)
5525                         printf("%d ", slaves[i]);
5526
5527                 printf("%d]\n", slaves[num_slaves - 1]);
5528         } else {
5529                 printf("\tSlaves: []\n");
5530
5531         }
5532
5533         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5534                         RTE_MAX_ETHPORTS);
5535
5536         if (num_active_slaves < 0) {
5537                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5538                 return;
5539         }
5540         if (num_active_slaves > 0) {
5541                 printf("\tActive Slaves (%d): [", num_active_slaves);
5542                 for (i = 0; i < num_active_slaves - 1; i++)
5543                         printf("%d ", slaves[i]);
5544
5545                 printf("%d]\n", slaves[num_active_slaves - 1]);
5546
5547         } else {
5548                 printf("\tActive Slaves: []\n");
5549
5550         }
5551
5552         primary_id = rte_eth_bond_primary_get(port_id);
5553         if (primary_id < 0) {
5554                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5555                 return;
5556         } else
5557                 printf("\tPrimary: [%d]\n", primary_id);
5558
5559 }
5560
5561 cmdline_parse_token_string_t cmd_showbonding_config_show =
5562 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5563                 show, "show");
5564 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5565 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5566                 bonding, "bonding");
5567 cmdline_parse_token_string_t cmd_showbonding_config_config =
5568 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5569                 config, "config");
5570 cmdline_parse_token_num_t cmd_showbonding_config_port =
5571 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5572                 port_id, UINT16);
5573
5574 cmdline_parse_inst_t cmd_show_bonding_config = {
5575                 .f = cmd_show_bonding_config_parsed,
5576                 .help_str = "show bonding config <port_id>: "
5577                         "Show the bonding config for port_id",
5578                 .data = NULL,
5579                 .tokens = {
5580                                 (void *)&cmd_showbonding_config_show,
5581                                 (void *)&cmd_showbonding_config_bonding,
5582                                 (void *)&cmd_showbonding_config_config,
5583                                 (void *)&cmd_showbonding_config_port,
5584                                 NULL
5585                 }
5586 };
5587
5588 /* *** SET BONDING PRIMARY *** */
5589 struct cmd_set_bonding_primary_result {
5590         cmdline_fixed_string_t set;
5591         cmdline_fixed_string_t bonding;
5592         cmdline_fixed_string_t primary;
5593         portid_t slave_id;
5594         portid_t port_id;
5595 };
5596
5597 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5598                 __attribute__((unused))  struct cmdline *cl,
5599                 __attribute__((unused)) void *data)
5600 {
5601         struct cmd_set_bonding_primary_result *res = parsed_result;
5602         portid_t master_port_id = res->port_id;
5603         portid_t slave_port_id = res->slave_id;
5604
5605         /* Set the primary slave for a bonded device. */
5606         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5607                 printf("\t Failed to set primary slave for port = %d.\n",
5608                                 master_port_id);
5609                 return;
5610         }
5611         init_port_config();
5612 }
5613
5614 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5615 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5616                 set, "set");
5617 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5618 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5619                 bonding, "bonding");
5620 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5621 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5622                 primary, "primary");
5623 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5624 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5625                 slave_id, UINT16);
5626 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5627 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5628                 port_id, UINT16);
5629
5630 cmdline_parse_inst_t cmd_set_bonding_primary = {
5631                 .f = cmd_set_bonding_primary_parsed,
5632                 .help_str = "set bonding primary <slave_id> <port_id>: "
5633                         "Set the primary slave for port_id",
5634                 .data = NULL,
5635                 .tokens = {
5636                                 (void *)&cmd_setbonding_primary_set,
5637                                 (void *)&cmd_setbonding_primary_bonding,
5638                                 (void *)&cmd_setbonding_primary_primary,
5639                                 (void *)&cmd_setbonding_primary_slave,
5640                                 (void *)&cmd_setbonding_primary_port,
5641                                 NULL
5642                 }
5643 };
5644
5645 /* *** ADD SLAVE *** */
5646 struct cmd_add_bonding_slave_result {
5647         cmdline_fixed_string_t add;
5648         cmdline_fixed_string_t bonding;
5649         cmdline_fixed_string_t slave;
5650         portid_t slave_id;
5651         portid_t port_id;
5652 };
5653
5654 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5655                 __attribute__((unused))  struct cmdline *cl,
5656                 __attribute__((unused)) void *data)
5657 {
5658         struct cmd_add_bonding_slave_result *res = parsed_result;
5659         portid_t master_port_id = res->port_id;
5660         portid_t slave_port_id = res->slave_id;
5661
5662         /* add the slave for a bonded device. */
5663         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5664                 printf("\t Failed to add slave %d to master port = %d.\n",
5665                                 slave_port_id, master_port_id);
5666                 return;
5667         }
5668         init_port_config();
5669         set_port_slave_flag(slave_port_id);
5670 }
5671
5672 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5673 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5674                 add, "add");
5675 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5676 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5677                 bonding, "bonding");
5678 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5679 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5680                 slave, "slave");
5681 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5682 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5683                 slave_id, UINT16);
5684 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5685 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5686                 port_id, UINT16);
5687
5688 cmdline_parse_inst_t cmd_add_bonding_slave = {
5689                 .f = cmd_add_bonding_slave_parsed,
5690                 .help_str = "add bonding slave <slave_id> <port_id>: "
5691                         "Add a slave device to a bonded device",
5692                 .data = NULL,
5693                 .tokens = {
5694                                 (void *)&cmd_addbonding_slave_add,
5695                                 (void *)&cmd_addbonding_slave_bonding,
5696                                 (void *)&cmd_addbonding_slave_slave,
5697                                 (void *)&cmd_addbonding_slave_slaveid,
5698                                 (void *)&cmd_addbonding_slave_port,
5699                                 NULL
5700                 }
5701 };
5702
5703 /* *** REMOVE SLAVE *** */
5704 struct cmd_remove_bonding_slave_result {
5705         cmdline_fixed_string_t remove;
5706         cmdline_fixed_string_t bonding;
5707         cmdline_fixed_string_t slave;
5708         portid_t slave_id;
5709         portid_t port_id;
5710 };
5711
5712 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5713                 __attribute__((unused))  struct cmdline *cl,
5714                 __attribute__((unused)) void *data)
5715 {
5716         struct cmd_remove_bonding_slave_result *res = parsed_result;
5717         portid_t master_port_id = res->port_id;
5718         portid_t slave_port_id = res->slave_id;
5719
5720         /* remove the slave from a bonded device. */
5721         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5722                 printf("\t Failed to remove slave %d from master port = %d.\n",
5723                                 slave_port_id, master_port_id);
5724                 return;
5725         }
5726         init_port_config();
5727         clear_port_slave_flag(slave_port_id);
5728 }
5729
5730 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5731                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5732                                 remove, "remove");
5733 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5734                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5735                                 bonding, "bonding");
5736 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5737                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5738                                 slave, "slave");
5739 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5740                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5741                                 slave_id, UINT16);
5742 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5743                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5744                                 port_id, UINT16);
5745
5746 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5747                 .f = cmd_remove_bonding_slave_parsed,
5748                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5749                         "Remove a slave device from a bonded device",
5750                 .data = NULL,
5751                 .tokens = {
5752                                 (void *)&cmd_removebonding_slave_remove,
5753                                 (void *)&cmd_removebonding_slave_bonding,
5754                                 (void *)&cmd_removebonding_slave_slave,
5755                                 (void *)&cmd_removebonding_slave_slaveid,
5756                                 (void *)&cmd_removebonding_slave_port,
5757                                 NULL
5758                 }
5759 };
5760
5761 /* *** CREATE BONDED DEVICE *** */
5762 struct cmd_create_bonded_device_result {
5763         cmdline_fixed_string_t create;
5764         cmdline_fixed_string_t bonded;
5765         cmdline_fixed_string_t device;
5766         uint8_t mode;
5767         uint8_t socket;
5768 };
5769
5770 static int bond_dev_num = 0;
5771
5772 static void cmd_create_bonded_device_parsed(void *parsed_result,
5773                 __attribute__((unused))  struct cmdline *cl,
5774                 __attribute__((unused)) void *data)
5775 {
5776         struct cmd_create_bonded_device_result *res = parsed_result;
5777         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5778         int port_id;
5779
5780         if (test_done == 0) {
5781                 printf("Please stop forwarding first\n");
5782                 return;
5783         }
5784
5785         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5786                         bond_dev_num++);
5787
5788         /* Create a new bonded device. */
5789         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5790         if (port_id < 0) {
5791                 printf("\t Failed to create bonded device.\n");
5792                 return;
5793         } else {
5794                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5795                                 port_id);
5796
5797                 /* Update number of ports */
5798                 nb_ports = rte_eth_dev_count_avail();
5799                 reconfig(port_id, res->socket);
5800                 rte_eth_promiscuous_enable(port_id);
5801         }
5802
5803 }
5804
5805 cmdline_parse_token_string_t cmd_createbonded_device_create =
5806                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5807                                 create, "create");
5808 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5809                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5810                                 bonded, "bonded");
5811 cmdline_parse_token_string_t cmd_createbonded_device_device =
5812                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5813                                 device, "device");
5814 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5815                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5816                                 mode, UINT8);
5817 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5818                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5819                                 socket, UINT8);
5820
5821 cmdline_parse_inst_t cmd_create_bonded_device = {
5822                 .f = cmd_create_bonded_device_parsed,
5823                 .help_str = "create bonded device <mode> <socket>: "
5824                         "Create a new bonded device with specific bonding mode and socket",
5825                 .data = NULL,
5826                 .tokens = {
5827                                 (void *)&cmd_createbonded_device_create,
5828                                 (void *)&cmd_createbonded_device_bonded,
5829                                 (void *)&cmd_createbonded_device_device,
5830                                 (void *)&cmd_createbonded_device_mode,
5831                                 (void *)&cmd_createbonded_device_socket,
5832                                 NULL
5833                 }
5834 };
5835
5836 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5837 struct cmd_set_bond_mac_addr_result {
5838         cmdline_fixed_string_t set;
5839         cmdline_fixed_string_t bonding;
5840         cmdline_fixed_string_t mac_addr;
5841         uint16_t port_num;
5842         struct ether_addr address;
5843 };
5844
5845 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5846                 __attribute__((unused))  struct cmdline *cl,
5847                 __attribute__((unused)) void *data)
5848 {
5849         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5850         int ret;
5851
5852         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5853                 return;
5854
5855         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5856
5857         /* check the return value and print it if is < 0 */
5858         if (ret < 0)
5859                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5860 }
5861
5862 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5863                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5864 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5865                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5866                                 "bonding");
5867 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5868                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5869                                 "mac_addr");
5870 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5871                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5872                                 port_num, UINT16);
5873 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5874                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5875
5876 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5877                 .f = cmd_set_bond_mac_addr_parsed,
5878                 .data = (void *) 0,
5879                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5880                 .tokens = {
5881                                 (void *)&cmd_set_bond_mac_addr_set,
5882                                 (void *)&cmd_set_bond_mac_addr_bonding,
5883                                 (void *)&cmd_set_bond_mac_addr_mac,
5884                                 (void *)&cmd_set_bond_mac_addr_portnum,
5885                                 (void *)&cmd_set_bond_mac_addr_addr,
5886                                 NULL
5887                 }
5888 };
5889
5890
5891 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5892 struct cmd_set_bond_mon_period_result {
5893         cmdline_fixed_string_t set;
5894         cmdline_fixed_string_t bonding;
5895         cmdline_fixed_string_t mon_period;
5896         uint16_t port_num;
5897         uint32_t period_ms;
5898 };
5899
5900 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5901                 __attribute__((unused))  struct cmdline *cl,
5902                 __attribute__((unused)) void *data)
5903 {
5904         struct cmd_set_bond_mon_period_result *res = parsed_result;
5905         int ret;
5906
5907         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5908
5909         /* check the return value and print it if is < 0 */
5910         if (ret < 0)
5911                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5912 }
5913
5914 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5915                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5916                                 set, "set");
5917 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5918                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5919                                 bonding, "bonding");
5920 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5921                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5922                                 mon_period,     "mon_period");
5923 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5924                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5925                                 port_num, UINT16);
5926 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5927                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5928                                 period_ms, UINT32);
5929
5930 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5931                 .f = cmd_set_bond_mon_period_parsed,
5932                 .data = (void *) 0,
5933                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5934                 .tokens = {
5935                                 (void *)&cmd_set_bond_mon_period_set,
5936                                 (void *)&cmd_set_bond_mon_period_bonding,
5937                                 (void *)&cmd_set_bond_mon_period_mon_period,
5938                                 (void *)&cmd_set_bond_mon_period_portnum,
5939                                 (void *)&cmd_set_bond_mon_period_period_ms,
5940                                 NULL
5941                 }
5942 };
5943
5944
5945
5946 struct cmd_set_bonding_agg_mode_policy_result {
5947         cmdline_fixed_string_t set;
5948         cmdline_fixed_string_t bonding;
5949         cmdline_fixed_string_t agg_mode;
5950         uint16_t port_num;
5951         cmdline_fixed_string_t policy;
5952 };
5953
5954
5955 static void
5956 cmd_set_bonding_agg_mode(void *parsed_result,
5957                 __attribute__((unused)) struct cmdline *cl,
5958                 __attribute__((unused)) void *data)
5959 {
5960         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5961         uint8_t policy = AGG_BANDWIDTH;
5962
5963         if (!strcmp(res->policy, "bandwidth"))
5964                 policy = AGG_BANDWIDTH;
5965         else if (!strcmp(res->policy, "stable"))
5966                 policy = AGG_STABLE;
5967         else if (!strcmp(res->policy, "count"))
5968                 policy = AGG_COUNT;
5969
5970         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5971 }
5972
5973
5974 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5975         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5976                                 set, "set");
5977 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5978         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5979                                 bonding, "bonding");
5980
5981 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5982         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5983                                 agg_mode, "agg_mode");
5984
5985 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5986         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5987                                 port_num, UINT16);
5988
5989 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5990         TOKEN_STRING_INITIALIZER(
5991                         struct cmd_set_bonding_balance_xmit_policy_result,
5992                 policy, "stable#bandwidth#count");
5993
5994 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5995         .f = cmd_set_bonding_agg_mode,
5996         .data = (void *) 0,
5997         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5998         .tokens = {
5999                         (void *)&cmd_set_bonding_agg_mode_set,
6000                         (void *)&cmd_set_bonding_agg_mode_bonding,
6001                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6002                         (void *)&cmd_set_bonding_agg_mode_portnum,
6003                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6004                         NULL
6005                 }
6006 };
6007
6008
6009 #endif /* RTE_LIBRTE_PMD_BOND */
6010
6011 /* *** SET FORWARDING MODE *** */
6012 struct cmd_set_fwd_mode_result {
6013         cmdline_fixed_string_t set;
6014         cmdline_fixed_string_t fwd;
6015         cmdline_fixed_string_t mode;
6016 };
6017
6018 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6019                                     __attribute__((unused)) struct cmdline *cl,
6020                                     __attribute__((unused)) void *data)
6021 {
6022         struct cmd_set_fwd_mode_result *res = parsed_result;
6023
6024         retry_enabled = 0;
6025         set_pkt_forwarding_mode(res->mode);
6026 }
6027
6028 cmdline_parse_token_string_t cmd_setfwd_set =
6029         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6030 cmdline_parse_token_string_t cmd_setfwd_fwd =
6031         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6032 cmdline_parse_token_string_t cmd_setfwd_mode =
6033         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6034                 "" /* defined at init */);
6035
6036 cmdline_parse_inst_t cmd_set_fwd_mode = {
6037         .f = cmd_set_fwd_mode_parsed,
6038         .data = NULL,
6039         .help_str = NULL, /* defined at init */
6040         .tokens = {
6041                 (void *)&cmd_setfwd_set,
6042                 (void *)&cmd_setfwd_fwd,
6043                 (void *)&cmd_setfwd_mode,
6044                 NULL,
6045         },
6046 };
6047
6048 static void cmd_set_fwd_mode_init(void)
6049 {
6050         char *modes, *c;
6051         static char token[128];
6052         static char help[256];
6053         cmdline_parse_token_string_t *token_struct;
6054
6055         modes = list_pkt_forwarding_modes();
6056         snprintf(help, sizeof(help), "set fwd %s: "
6057                 "Set packet forwarding mode", modes);
6058         cmd_set_fwd_mode.help_str = help;
6059
6060         /* string token separator is # */
6061         for (c = token; *modes != '\0'; modes++)
6062                 if (*modes == '|')
6063                         *c++ = '#';
6064                 else
6065                         *c++ = *modes;
6066         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6067         token_struct->string_data.str = token;
6068 }
6069
6070 /* *** SET RETRY FORWARDING MODE *** */
6071 struct cmd_set_fwd_retry_mode_result {
6072         cmdline_fixed_string_t set;
6073         cmdline_fixed_string_t fwd;
6074         cmdline_fixed_string_t mode;
6075         cmdline_fixed_string_t retry;
6076 };
6077
6078 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6079                             __attribute__((unused)) struct cmdline *cl,
6080                             __attribute__((unused)) void *data)
6081 {
6082         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6083
6084         retry_enabled = 1;
6085         set_pkt_forwarding_mode(res->mode);
6086 }
6087
6088 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6089         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6090                         set, "set");
6091 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6092         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6093                         fwd, "fwd");
6094 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6095         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6096                         mode,
6097                 "" /* defined at init */);
6098 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6099         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6100                         retry, "retry");
6101
6102 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6103         .f = cmd_set_fwd_retry_mode_parsed,
6104         .data = NULL,
6105         .help_str = NULL, /* defined at init */
6106         .tokens = {
6107                 (void *)&cmd_setfwd_retry_set,
6108                 (void *)&cmd_setfwd_retry_fwd,
6109                 (void *)&cmd_setfwd_retry_mode,
6110                 (void *)&cmd_setfwd_retry_retry,
6111                 NULL,
6112         },
6113 };
6114
6115 static void cmd_set_fwd_retry_mode_init(void)
6116 {
6117         char *modes, *c;
6118         static char token[128];
6119         static char help[256];
6120         cmdline_parse_token_string_t *token_struct;
6121
6122         modes = list_pkt_forwarding_retry_modes();
6123         snprintf(help, sizeof(help), "set fwd %s retry: "
6124                 "Set packet forwarding mode with retry", modes);
6125         cmd_set_fwd_retry_mode.help_str = help;
6126
6127         /* string token separator is # */
6128         for (c = token; *modes != '\0'; modes++)
6129                 if (*modes == '|')
6130                         *c++ = '#';
6131                 else
6132                         *c++ = *modes;
6133         token_struct = (cmdline_parse_token_string_t *)
6134                 cmd_set_fwd_retry_mode.tokens[2];
6135         token_struct->string_data.str = token;
6136 }
6137
6138 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6139 struct cmd_set_burst_tx_retry_result {
6140         cmdline_fixed_string_t set;
6141         cmdline_fixed_string_t burst;
6142         cmdline_fixed_string_t tx;
6143         cmdline_fixed_string_t delay;
6144         uint32_t time;
6145         cmdline_fixed_string_t retry;
6146         uint32_t retry_num;
6147 };
6148
6149 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6150                                         __attribute__((unused)) struct cmdline *cl,
6151                                         __attribute__((unused)) void *data)
6152 {
6153         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6154
6155         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6156                 && !strcmp(res->tx, "tx")) {
6157                 if (!strcmp(res->delay, "delay"))
6158                         burst_tx_delay_time = res->time;
6159                 if (!strcmp(res->retry, "retry"))
6160                         burst_tx_retry_num = res->retry_num;
6161         }
6162
6163 }
6164
6165 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6166         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6167 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6168         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6169                                  "burst");
6170 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6171         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6172 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6173         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6174 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6175         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6176 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6177         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6178 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6179         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6180
6181 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6182         .f = cmd_set_burst_tx_retry_parsed,
6183         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6184         .tokens = {
6185                 (void *)&cmd_set_burst_tx_retry_set,
6186                 (void *)&cmd_set_burst_tx_retry_burst,
6187                 (void *)&cmd_set_burst_tx_retry_tx,
6188                 (void *)&cmd_set_burst_tx_retry_delay,
6189                 (void *)&cmd_set_burst_tx_retry_time,
6190                 (void *)&cmd_set_burst_tx_retry_retry,
6191                 (void *)&cmd_set_burst_tx_retry_retry_num,
6192                 NULL,
6193         },
6194 };
6195
6196 /* *** SET PROMISC MODE *** */
6197 struct cmd_set_promisc_mode_result {
6198         cmdline_fixed_string_t set;
6199         cmdline_fixed_string_t promisc;
6200         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6201         uint16_t port_num;               /* valid if "allports" argument == 0 */
6202         cmdline_fixed_string_t mode;
6203 };
6204
6205 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6206                                         __attribute__((unused)) struct cmdline *cl,
6207                                         void *allports)
6208 {
6209         struct cmd_set_promisc_mode_result *res = parsed_result;
6210         int enable;
6211         portid_t i;
6212
6213         if (!strcmp(res->mode, "on"))
6214                 enable = 1;
6215         else
6216                 enable = 0;
6217
6218         /* all ports */
6219         if (allports) {
6220                 RTE_ETH_FOREACH_DEV(i) {
6221                         if (enable)
6222                                 rte_eth_promiscuous_enable(i);
6223                         else
6224                                 rte_eth_promiscuous_disable(i);
6225                 }
6226         }
6227         else {
6228                 if (enable)
6229                         rte_eth_promiscuous_enable(res->port_num);
6230                 else
6231                         rte_eth_promiscuous_disable(res->port_num);
6232         }
6233 }
6234
6235 cmdline_parse_token_string_t cmd_setpromisc_set =
6236         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6237 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6238         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6239                                  "promisc");
6240 cmdline_parse_token_string_t cmd_setpromisc_portall =
6241         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6242                                  "all");
6243 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6244         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6245                               UINT16);
6246 cmdline_parse_token_string_t cmd_setpromisc_mode =
6247         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6248                                  "on#off");
6249
6250 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6251         .f = cmd_set_promisc_mode_parsed,
6252         .data = (void *)1,
6253         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6254         .tokens = {
6255                 (void *)&cmd_setpromisc_set,
6256                 (void *)&cmd_setpromisc_promisc,
6257                 (void *)&cmd_setpromisc_portall,
6258                 (void *)&cmd_setpromisc_mode,
6259                 NULL,
6260         },
6261 };
6262
6263 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6264         .f = cmd_set_promisc_mode_parsed,
6265         .data = (void *)0,
6266         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6267         .tokens = {
6268                 (void *)&cmd_setpromisc_set,
6269                 (void *)&cmd_setpromisc_promisc,
6270                 (void *)&cmd_setpromisc_portnum,
6271                 (void *)&cmd_setpromisc_mode,
6272                 NULL,
6273         },
6274 };
6275
6276 /* *** SET ALLMULTI MODE *** */
6277 struct cmd_set_allmulti_mode_result {
6278         cmdline_fixed_string_t set;
6279         cmdline_fixed_string_t allmulti;
6280         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6281         uint16_t port_num;               /* valid if "allports" argument == 0 */
6282         cmdline_fixed_string_t mode;
6283 };
6284
6285 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6286                                         __attribute__((unused)) struct cmdline *cl,
6287                                         void *allports)
6288 {
6289         struct cmd_set_allmulti_mode_result *res = parsed_result;
6290         int enable;
6291         portid_t i;
6292
6293         if (!strcmp(res->mode, "on"))
6294                 enable = 1;
6295         else
6296                 enable = 0;
6297
6298         /* all ports */
6299         if (allports) {
6300                 RTE_ETH_FOREACH_DEV(i) {
6301                         if (enable)
6302                                 rte_eth_allmulticast_enable(i);
6303                         else
6304                                 rte_eth_allmulticast_disable(i);
6305                 }
6306         }
6307         else {
6308                 if (enable)
6309                         rte_eth_allmulticast_enable(res->port_num);
6310                 else
6311                         rte_eth_allmulticast_disable(res->port_num);
6312         }
6313 }
6314
6315 cmdline_parse_token_string_t cmd_setallmulti_set =
6316         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6317 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6318         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6319                                  "allmulti");
6320 cmdline_parse_token_string_t cmd_setallmulti_portall =
6321         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6322                                  "all");
6323 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6324         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6325                               UINT16);
6326 cmdline_parse_token_string_t cmd_setallmulti_mode =
6327         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6328                                  "on#off");
6329
6330 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6331         .f = cmd_set_allmulti_mode_parsed,
6332         .data = (void *)1,
6333         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6334         .tokens = {
6335                 (void *)&cmd_setallmulti_set,
6336                 (void *)&cmd_setallmulti_allmulti,
6337                 (void *)&cmd_setallmulti_portall,
6338                 (void *)&cmd_setallmulti_mode,
6339                 NULL,
6340         },
6341 };
6342
6343 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6344         .f = cmd_set_allmulti_mode_parsed,
6345         .data = (void *)0,
6346         .help_str = "set allmulti <port_id> on|off: "
6347                 "Set allmulti mode on port_id",
6348         .tokens = {
6349                 (void *)&cmd_setallmulti_set,
6350                 (void *)&cmd_setallmulti_allmulti,
6351                 (void *)&cmd_setallmulti_portnum,
6352                 (void *)&cmd_setallmulti_mode,
6353                 NULL,
6354         },
6355 };
6356
6357 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6358 struct cmd_link_flow_ctrl_set_result {
6359         cmdline_fixed_string_t set;
6360         cmdline_fixed_string_t flow_ctrl;
6361         cmdline_fixed_string_t rx;
6362         cmdline_fixed_string_t rx_lfc_mode;
6363         cmdline_fixed_string_t tx;
6364         cmdline_fixed_string_t tx_lfc_mode;
6365         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6366         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6367         cmdline_fixed_string_t autoneg_str;
6368         cmdline_fixed_string_t autoneg;
6369         cmdline_fixed_string_t hw_str;
6370         uint32_t high_water;
6371         cmdline_fixed_string_t lw_str;
6372         uint32_t low_water;
6373         cmdline_fixed_string_t pt_str;
6374         uint16_t pause_time;
6375         cmdline_fixed_string_t xon_str;
6376         uint16_t send_xon;
6377         portid_t port_id;
6378 };
6379
6380 cmdline_parse_token_string_t cmd_lfc_set_set =
6381         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6382                                 set, "set");
6383 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6384         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6385                                 flow_ctrl, "flow_ctrl");
6386 cmdline_parse_token_string_t cmd_lfc_set_rx =
6387         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6388                                 rx, "rx");
6389 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6390         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6391                                 rx_lfc_mode, "on#off");
6392 cmdline_parse_token_string_t cmd_lfc_set_tx =
6393         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6394                                 tx, "tx");
6395 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6396         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6397                                 tx_lfc_mode, "on#off");
6398 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6399         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6400                                 hw_str, "high_water");
6401 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6402         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6403                                 high_water, UINT32);
6404 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6405         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6406                                 lw_str, "low_water");
6407 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6408         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6409                                 low_water, UINT32);
6410 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6411         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6412                                 pt_str, "pause_time");
6413 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6414         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6415                                 pause_time, UINT16);
6416 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6417         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6418                                 xon_str, "send_xon");
6419 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6420         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6421                                 send_xon, UINT16);
6422 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6423         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6424                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6425 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6426         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6427                                 mac_ctrl_frame_fwd_mode, "on#off");
6428 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6429         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6430                                 autoneg_str, "autoneg");
6431 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6432         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6433                                 autoneg, "on#off");
6434 cmdline_parse_token_num_t cmd_lfc_set_portid =
6435         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6436                                 port_id, UINT16);
6437
6438 /* forward declaration */
6439 static void
6440 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6441                               void *data);
6442
6443 cmdline_parse_inst_t cmd_link_flow_control_set = {
6444         .f = cmd_link_flow_ctrl_set_parsed,
6445         .data = NULL,
6446         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6447                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6448                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6449         .tokens = {
6450                 (void *)&cmd_lfc_set_set,
6451                 (void *)&cmd_lfc_set_flow_ctrl,
6452                 (void *)&cmd_lfc_set_rx,
6453                 (void *)&cmd_lfc_set_rx_mode,
6454                 (void *)&cmd_lfc_set_tx,
6455                 (void *)&cmd_lfc_set_tx_mode,
6456                 (void *)&cmd_lfc_set_high_water,
6457                 (void *)&cmd_lfc_set_low_water,
6458                 (void *)&cmd_lfc_set_pause_time,
6459                 (void *)&cmd_lfc_set_send_xon,
6460                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6461                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6462                 (void *)&cmd_lfc_set_autoneg_str,
6463                 (void *)&cmd_lfc_set_autoneg,
6464                 (void *)&cmd_lfc_set_portid,
6465                 NULL,
6466         },
6467 };
6468
6469 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6470         .f = cmd_link_flow_ctrl_set_parsed,
6471         .data = (void *)&cmd_link_flow_control_set_rx,
6472         .help_str = "set flow_ctrl rx on|off <port_id>: "
6473                 "Change rx flow control parameter",
6474         .tokens = {
6475                 (void *)&cmd_lfc_set_set,
6476                 (void *)&cmd_lfc_set_flow_ctrl,
6477                 (void *)&cmd_lfc_set_rx,
6478                 (void *)&cmd_lfc_set_rx_mode,
6479                 (void *)&cmd_lfc_set_portid,
6480                 NULL,
6481         },
6482 };
6483
6484 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6485         .f = cmd_link_flow_ctrl_set_parsed,
6486         .data = (void *)&cmd_link_flow_control_set_tx,
6487         .help_str = "set flow_ctrl tx on|off <port_id>: "
6488                 "Change tx flow control parameter",
6489         .tokens = {
6490                 (void *)&cmd_lfc_set_set,
6491                 (void *)&cmd_lfc_set_flow_ctrl,
6492                 (void *)&cmd_lfc_set_tx,
6493                 (void *)&cmd_lfc_set_tx_mode,
6494                 (void *)&cmd_lfc_set_portid,
6495                 NULL,
6496         },
6497 };
6498
6499 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6500         .f = cmd_link_flow_ctrl_set_parsed,
6501         .data = (void *)&cmd_link_flow_control_set_hw,
6502         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6503                 "Change high water flow control parameter",
6504         .tokens = {
6505                 (void *)&cmd_lfc_set_set,
6506                 (void *)&cmd_lfc_set_flow_ctrl,
6507                 (void *)&cmd_lfc_set_high_water_str,
6508                 (void *)&cmd_lfc_set_high_water,
6509                 (void *)&cmd_lfc_set_portid,
6510                 NULL,
6511         },
6512 };
6513
6514 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6515         .f = cmd_link_flow_ctrl_set_parsed,
6516         .data = (void *)&cmd_link_flow_control_set_lw,
6517         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6518                 "Change low water flow control parameter",
6519         .tokens = {
6520                 (void *)&cmd_lfc_set_set,
6521                 (void *)&cmd_lfc_set_flow_ctrl,
6522                 (void *)&cmd_lfc_set_low_water_str,
6523                 (void *)&cmd_lfc_set_low_water,
6524                 (void *)&cmd_lfc_set_portid,
6525                 NULL,
6526         },
6527 };
6528
6529 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6530         .f = cmd_link_flow_ctrl_set_parsed,
6531         .data = (void *)&cmd_link_flow_control_set_pt,
6532         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6533                 "Change pause time flow control parameter",
6534         .tokens = {
6535                 (void *)&cmd_lfc_set_set,
6536                 (void *)&cmd_lfc_set_flow_ctrl,
6537                 (void *)&cmd_lfc_set_pause_time_str,
6538                 (void *)&cmd_lfc_set_pause_time,
6539                 (void *)&cmd_lfc_set_portid,
6540                 NULL,
6541         },
6542 };
6543
6544 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6545         .f = cmd_link_flow_ctrl_set_parsed,
6546         .data = (void *)&cmd_link_flow_control_set_xon,
6547         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6548                 "Change send_xon flow control parameter",
6549         .tokens = {
6550                 (void *)&cmd_lfc_set_set,
6551                 (void *)&cmd_lfc_set_flow_ctrl,
6552                 (void *)&cmd_lfc_set_send_xon_str,
6553                 (void *)&cmd_lfc_set_send_xon,
6554                 (void *)&cmd_lfc_set_portid,
6555                 NULL,
6556         },
6557 };
6558
6559 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6560         .f = cmd_link_flow_ctrl_set_parsed,
6561         .data = (void *)&cmd_link_flow_control_set_macfwd,
6562         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6563                 "Change mac ctrl fwd flow control parameter",
6564         .tokens = {
6565                 (void *)&cmd_lfc_set_set,
6566                 (void *)&cmd_lfc_set_flow_ctrl,
6567                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6568                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6569                 (void *)&cmd_lfc_set_portid,
6570                 NULL,
6571         },
6572 };
6573
6574 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6575         .f = cmd_link_flow_ctrl_set_parsed,
6576         .data = (void *)&cmd_link_flow_control_set_autoneg,
6577         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6578                 "Change autoneg flow control parameter",
6579         .tokens = {
6580                 (void *)&cmd_lfc_set_set,
6581                 (void *)&cmd_lfc_set_flow_ctrl,
6582                 (void *)&cmd_lfc_set_autoneg_str,
6583                 (void *)&cmd_lfc_set_autoneg,
6584                 (void *)&cmd_lfc_set_portid,
6585                 NULL,
6586         },
6587 };
6588
6589 static void
6590 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6591                               __attribute__((unused)) struct cmdline *cl,
6592                               void *data)
6593 {
6594         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6595         cmdline_parse_inst_t *cmd = data;
6596         struct rte_eth_fc_conf fc_conf;
6597         int rx_fc_en = 0;
6598         int tx_fc_en = 0;
6599         int ret;
6600
6601         /*
6602          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6603          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6604          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6605          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6606          */
6607         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6608                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6609         };
6610
6611         /* Partial command line, retrieve current configuration */
6612         if (cmd) {
6613                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6614                 if (ret != 0) {
6615                         printf("cannot get current flow ctrl parameters, return"
6616                                "code = %d\n", ret);
6617                         return;
6618                 }
6619
6620                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6621                     (fc_conf.mode == RTE_FC_FULL))
6622                         rx_fc_en = 1;
6623                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6624                     (fc_conf.mode == RTE_FC_FULL))
6625                         tx_fc_en = 1;
6626         }
6627
6628         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6629                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6630
6631         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6632                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6633
6634         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6635
6636         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6637                 fc_conf.high_water = res->high_water;
6638
6639         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6640                 fc_conf.low_water = res->low_water;
6641
6642         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6643                 fc_conf.pause_time = res->pause_time;
6644
6645         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6646                 fc_conf.send_xon = res->send_xon;
6647
6648         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6649                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6650                         fc_conf.mac_ctrl_frame_fwd = 1;
6651                 else
6652                         fc_conf.mac_ctrl_frame_fwd = 0;
6653         }
6654
6655         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6656                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6657
6658         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6659         if (ret != 0)
6660                 printf("bad flow contrl parameter, return code = %d \n", ret);
6661 }
6662
6663 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6664 struct cmd_priority_flow_ctrl_set_result {
6665         cmdline_fixed_string_t set;
6666         cmdline_fixed_string_t pfc_ctrl;
6667         cmdline_fixed_string_t rx;
6668         cmdline_fixed_string_t rx_pfc_mode;
6669         cmdline_fixed_string_t tx;
6670         cmdline_fixed_string_t tx_pfc_mode;
6671         uint32_t high_water;
6672         uint32_t low_water;
6673         uint16_t pause_time;
6674         uint8_t  priority;
6675         portid_t port_id;
6676 };
6677
6678 static void
6679 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6680                        __attribute__((unused)) struct cmdline *cl,
6681                        __attribute__((unused)) void *data)
6682 {
6683         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6684         struct rte_eth_pfc_conf pfc_conf;
6685         int rx_fc_enable, tx_fc_enable;
6686         int ret;
6687
6688         /*
6689          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6690          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6691          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6692          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6693          */
6694         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6695                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6696         };
6697
6698         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6699         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6700         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6701         pfc_conf.fc.high_water = res->high_water;
6702         pfc_conf.fc.low_water  = res->low_water;
6703         pfc_conf.fc.pause_time = res->pause_time;
6704         pfc_conf.priority      = res->priority;
6705
6706         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6707         if (ret != 0)
6708                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6709 }
6710
6711 cmdline_parse_token_string_t cmd_pfc_set_set =
6712         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6713                                 set, "set");
6714 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6715         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6716                                 pfc_ctrl, "pfc_ctrl");
6717 cmdline_parse_token_string_t cmd_pfc_set_rx =
6718         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6719                                 rx, "rx");
6720 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6721         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6722                                 rx_pfc_mode, "on#off");
6723 cmdline_parse_token_string_t cmd_pfc_set_tx =
6724         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6725                                 tx, "tx");
6726 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6727         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6728                                 tx_pfc_mode, "on#off");
6729 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6730         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6731                                 high_water, UINT32);
6732 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6733         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6734                                 low_water, UINT32);
6735 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6736         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6737                                 pause_time, UINT16);
6738 cmdline_parse_token_num_t cmd_pfc_set_priority =
6739         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6740                                 priority, UINT8);
6741 cmdline_parse_token_num_t cmd_pfc_set_portid =
6742         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6743                                 port_id, UINT16);
6744
6745 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6746         .f = cmd_priority_flow_ctrl_set_parsed,
6747         .data = NULL,
6748         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6749                 "<pause_time> <priority> <port_id>: "
6750                 "Configure the Ethernet priority flow control",
6751         .tokens = {
6752                 (void *)&cmd_pfc_set_set,
6753                 (void *)&cmd_pfc_set_flow_ctrl,
6754                 (void *)&cmd_pfc_set_rx,
6755                 (void *)&cmd_pfc_set_rx_mode,
6756                 (void *)&cmd_pfc_set_tx,
6757                 (void *)&cmd_pfc_set_tx_mode,
6758                 (void *)&cmd_pfc_set_high_water,
6759                 (void *)&cmd_pfc_set_low_water,
6760                 (void *)&cmd_pfc_set_pause_time,
6761                 (void *)&cmd_pfc_set_priority,
6762                 (void *)&cmd_pfc_set_portid,
6763                 NULL,
6764         },
6765 };
6766
6767 /* *** RESET CONFIGURATION *** */
6768 struct cmd_reset_result {
6769         cmdline_fixed_string_t reset;
6770         cmdline_fixed_string_t def;
6771 };
6772
6773 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6774                              struct cmdline *cl,
6775                              __attribute__((unused)) void *data)
6776 {
6777         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6778         set_def_fwd_config();
6779 }
6780
6781 cmdline_parse_token_string_t cmd_reset_set =
6782         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6783 cmdline_parse_token_string_t cmd_reset_def =
6784         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6785                                  "default");
6786
6787 cmdline_parse_inst_t cmd_reset = {
6788         .f = cmd_reset_parsed,
6789         .data = NULL,
6790         .help_str = "set default: Reset default forwarding configuration",
6791         .tokens = {
6792                 (void *)&cmd_reset_set,
6793                 (void *)&cmd_reset_def,
6794                 NULL,
6795         },
6796 };
6797
6798 /* *** START FORWARDING *** */
6799 struct cmd_start_result {
6800         cmdline_fixed_string_t start;
6801 };
6802
6803 cmdline_parse_token_string_t cmd_start_start =
6804         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6805
6806 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6807                              __attribute__((unused)) struct cmdline *cl,
6808                              __attribute__((unused)) void *data)
6809 {
6810         start_packet_forwarding(0);
6811 }
6812
6813 cmdline_parse_inst_t cmd_start = {
6814         .f = cmd_start_parsed,
6815         .data = NULL,
6816         .help_str = "start: Start packet forwarding",
6817         .tokens = {
6818                 (void *)&cmd_start_start,
6819                 NULL,
6820         },
6821 };
6822
6823 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6824 struct cmd_start_tx_first_result {
6825         cmdline_fixed_string_t start;
6826         cmdline_fixed_string_t tx_first;
6827 };
6828
6829 static void
6830 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6831                           __attribute__((unused)) struct cmdline *cl,
6832                           __attribute__((unused)) void *data)
6833 {
6834         start_packet_forwarding(1);
6835 }
6836
6837 cmdline_parse_token_string_t cmd_start_tx_first_start =
6838         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6839                                  "start");
6840 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6841         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6842                                  tx_first, "tx_first");
6843
6844 cmdline_parse_inst_t cmd_start_tx_first = {
6845         .f = cmd_start_tx_first_parsed,
6846         .data = NULL,
6847         .help_str = "start tx_first: Start packet forwarding, "
6848                 "after sending 1 burst of packets",
6849         .tokens = {
6850                 (void *)&cmd_start_tx_first_start,
6851                 (void *)&cmd_start_tx_first_tx_first,
6852                 NULL,
6853         },
6854 };
6855
6856 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6857 struct cmd_start_tx_first_n_result {
6858         cmdline_fixed_string_t start;
6859         cmdline_fixed_string_t tx_first;
6860         uint32_t tx_num;
6861 };
6862
6863 static void
6864 cmd_start_tx_first_n_parsed(void *parsed_result,
6865                           __attribute__((unused)) struct cmdline *cl,
6866                           __attribute__((unused)) void *data)
6867 {
6868         struct cmd_start_tx_first_n_result *res = parsed_result;
6869
6870         start_packet_forwarding(res->tx_num);
6871 }
6872
6873 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6874         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6875                         start, "start");
6876 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6877         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6878                         tx_first, "tx_first");
6879 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6880         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6881                         tx_num, UINT32);
6882
6883 cmdline_parse_inst_t cmd_start_tx_first_n = {
6884         .f = cmd_start_tx_first_n_parsed,
6885         .data = NULL,
6886         .help_str = "start tx_first <num>: "
6887                 "packet forwarding, after sending <num> bursts of packets",
6888         .tokens = {
6889                 (void *)&cmd_start_tx_first_n_start,
6890                 (void *)&cmd_start_tx_first_n_tx_first,
6891                 (void *)&cmd_start_tx_first_n_tx_num,
6892                 NULL,
6893         },
6894 };
6895
6896 /* *** SET LINK UP *** */
6897 struct cmd_set_link_up_result {
6898         cmdline_fixed_string_t set;
6899         cmdline_fixed_string_t link_up;
6900         cmdline_fixed_string_t port;
6901         portid_t port_id;
6902 };
6903
6904 cmdline_parse_token_string_t cmd_set_link_up_set =
6905         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6906 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6907         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6908                                 "link-up");
6909 cmdline_parse_token_string_t cmd_set_link_up_port =
6910         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6911 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6912         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6913
6914 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6915                              __attribute__((unused)) struct cmdline *cl,
6916                              __attribute__((unused)) void *data)
6917 {
6918         struct cmd_set_link_up_result *res = parsed_result;
6919         dev_set_link_up(res->port_id);
6920 }
6921
6922 cmdline_parse_inst_t cmd_set_link_up = {
6923         .f = cmd_set_link_up_parsed,
6924         .data = NULL,
6925         .help_str = "set link-up port <port id>",
6926         .tokens = {
6927                 (void *)&cmd_set_link_up_set,
6928                 (void *)&cmd_set_link_up_link_up,
6929                 (void *)&cmd_set_link_up_port,
6930                 (void *)&cmd_set_link_up_port_id,
6931                 NULL,
6932         },
6933 };
6934
6935 /* *** SET LINK DOWN *** */
6936 struct cmd_set_link_down_result {
6937         cmdline_fixed_string_t set;
6938         cmdline_fixed_string_t link_down;
6939         cmdline_fixed_string_t port;
6940         portid_t port_id;
6941 };
6942
6943 cmdline_parse_token_string_t cmd_set_link_down_set =
6944         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6945 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6946         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6947                                 "link-down");
6948 cmdline_parse_token_string_t cmd_set_link_down_port =
6949         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6950 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6951         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6952
6953 static void cmd_set_link_down_parsed(
6954                                 __attribute__((unused)) void *parsed_result,
6955                                 __attribute__((unused)) struct cmdline *cl,
6956                                 __attribute__((unused)) void *data)
6957 {
6958         struct cmd_set_link_down_result *res = parsed_result;
6959         dev_set_link_down(res->port_id);
6960 }
6961
6962 cmdline_parse_inst_t cmd_set_link_down = {
6963         .f = cmd_set_link_down_parsed,
6964         .data = NULL,
6965         .help_str = "set link-down port <port id>",
6966         .tokens = {
6967                 (void *)&cmd_set_link_down_set,
6968                 (void *)&cmd_set_link_down_link_down,
6969                 (void *)&cmd_set_link_down_port,
6970                 (void *)&cmd_set_link_down_port_id,
6971                 NULL,
6972         },
6973 };
6974
6975 /* *** SHOW CFG *** */
6976 struct cmd_showcfg_result {
6977         cmdline_fixed_string_t show;
6978         cmdline_fixed_string_t cfg;
6979         cmdline_fixed_string_t what;
6980 };
6981
6982 static void cmd_showcfg_parsed(void *parsed_result,
6983                                __attribute__((unused)) struct cmdline *cl,
6984                                __attribute__((unused)) void *data)
6985 {
6986         struct cmd_showcfg_result *res = parsed_result;
6987         if (!strcmp(res->what, "rxtx"))
6988                 rxtx_config_display();
6989         else if (!strcmp(res->what, "cores"))
6990                 fwd_lcores_config_display();
6991         else if (!strcmp(res->what, "fwd"))
6992                 pkt_fwd_config_display(&cur_fwd_config);
6993         else if (!strcmp(res->what, "txpkts"))
6994                 show_tx_pkt_segments();
6995 }
6996
6997 cmdline_parse_token_string_t cmd_showcfg_show =
6998         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6999 cmdline_parse_token_string_t cmd_showcfg_port =
7000         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7001 cmdline_parse_token_string_t cmd_showcfg_what =
7002         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7003                                  "rxtx#cores#fwd#txpkts");
7004
7005 cmdline_parse_inst_t cmd_showcfg = {
7006         .f = cmd_showcfg_parsed,
7007         .data = NULL,
7008         .help_str = "show config rxtx|cores|fwd|txpkts",
7009         .tokens = {
7010                 (void *)&cmd_showcfg_show,
7011                 (void *)&cmd_showcfg_port,
7012                 (void *)&cmd_showcfg_what,
7013                 NULL,
7014         },
7015 };
7016
7017 /* *** SHOW ALL PORT INFO *** */
7018 struct cmd_showportall_result {
7019         cmdline_fixed_string_t show;
7020         cmdline_fixed_string_t port;
7021         cmdline_fixed_string_t what;
7022         cmdline_fixed_string_t all;
7023 };
7024
7025 static void cmd_showportall_parsed(void *parsed_result,
7026                                 __attribute__((unused)) struct cmdline *cl,
7027                                 __attribute__((unused)) void *data)
7028 {
7029         portid_t i;
7030
7031         struct cmd_showportall_result *res = parsed_result;
7032         if (!strcmp(res->show, "clear")) {
7033                 if (!strcmp(res->what, "stats"))
7034                         RTE_ETH_FOREACH_DEV(i)
7035                                 nic_stats_clear(i);
7036                 else if (!strcmp(res->what, "xstats"))
7037                         RTE_ETH_FOREACH_DEV(i)
7038                                 nic_xstats_clear(i);
7039         } else if (!strcmp(res->what, "info"))
7040                 RTE_ETH_FOREACH_DEV(i)
7041                         port_infos_display(i);
7042         else if (!strcmp(res->what, "stats"))
7043                 RTE_ETH_FOREACH_DEV(i)
7044                         nic_stats_display(i);
7045         else if (!strcmp(res->what, "xstats"))
7046                 RTE_ETH_FOREACH_DEV(i)
7047                         nic_xstats_display(i);
7048         else if (!strcmp(res->what, "fdir"))
7049                 RTE_ETH_FOREACH_DEV(i)
7050                         fdir_get_infos(i);
7051         else if (!strcmp(res->what, "stat_qmap"))
7052                 RTE_ETH_FOREACH_DEV(i)
7053                         nic_stats_mapping_display(i);
7054         else if (!strcmp(res->what, "dcb_tc"))
7055                 RTE_ETH_FOREACH_DEV(i)
7056                         port_dcb_info_display(i);
7057         else if (!strcmp(res->what, "cap"))
7058                 RTE_ETH_FOREACH_DEV(i)
7059                         port_offload_cap_display(i);
7060 }
7061
7062 cmdline_parse_token_string_t cmd_showportall_show =
7063         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7064                                  "show#clear");
7065 cmdline_parse_token_string_t cmd_showportall_port =
7066         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7067 cmdline_parse_token_string_t cmd_showportall_what =
7068         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7069                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7070 cmdline_parse_token_string_t cmd_showportall_all =
7071         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7072 cmdline_parse_inst_t cmd_showportall = {
7073         .f = cmd_showportall_parsed,
7074         .data = NULL,
7075         .help_str = "show|clear port "
7076                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7077         .tokens = {
7078                 (void *)&cmd_showportall_show,
7079                 (void *)&cmd_showportall_port,
7080                 (void *)&cmd_showportall_what,
7081                 (void *)&cmd_showportall_all,
7082                 NULL,
7083         },
7084 };
7085
7086 /* *** SHOW PORT INFO *** */
7087 struct cmd_showport_result {
7088         cmdline_fixed_string_t show;
7089         cmdline_fixed_string_t port;
7090         cmdline_fixed_string_t what;
7091         uint16_t portnum;
7092 };
7093
7094 static void cmd_showport_parsed(void *parsed_result,
7095                                 __attribute__((unused)) struct cmdline *cl,
7096                                 __attribute__((unused)) void *data)
7097 {
7098         struct cmd_showport_result *res = parsed_result;
7099         if (!strcmp(res->show, "clear")) {
7100                 if (!strcmp(res->what, "stats"))
7101                         nic_stats_clear(res->portnum);
7102                 else if (!strcmp(res->what, "xstats"))
7103                         nic_xstats_clear(res->portnum);
7104         } else if (!strcmp(res->what, "info"))
7105                 port_infos_display(res->portnum);
7106         else if (!strcmp(res->what, "stats"))
7107                 nic_stats_display(res->portnum);
7108         else if (!strcmp(res->what, "xstats"))
7109                 nic_xstats_display(res->portnum);
7110         else if (!strcmp(res->what, "fdir"))
7111                  fdir_get_infos(res->portnum);
7112         else if (!strcmp(res->what, "stat_qmap"))
7113                 nic_stats_mapping_display(res->portnum);
7114         else if (!strcmp(res->what, "dcb_tc"))
7115                 port_dcb_info_display(res->portnum);
7116         else if (!strcmp(res->what, "cap"))
7117                 port_offload_cap_display(res->portnum);
7118 }
7119
7120 cmdline_parse_token_string_t cmd_showport_show =
7121         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7122                                  "show#clear");
7123 cmdline_parse_token_string_t cmd_showport_port =
7124         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7125 cmdline_parse_token_string_t cmd_showport_what =
7126         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7127                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7128 cmdline_parse_token_num_t cmd_showport_portnum =
7129         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7130
7131 cmdline_parse_inst_t cmd_showport = {
7132         .f = cmd_showport_parsed,
7133         .data = NULL,
7134         .help_str = "show|clear port "
7135                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7136                 "<port_id>",
7137         .tokens = {
7138                 (void *)&cmd_showport_show,
7139                 (void *)&cmd_showport_port,
7140                 (void *)&cmd_showport_what,
7141                 (void *)&cmd_showport_portnum,
7142                 NULL,
7143         },
7144 };
7145
7146 /* *** SHOW QUEUE INFO *** */
7147 struct cmd_showqueue_result {
7148         cmdline_fixed_string_t show;
7149         cmdline_fixed_string_t type;
7150         cmdline_fixed_string_t what;
7151         uint16_t portnum;
7152         uint16_t queuenum;
7153 };
7154
7155 static void
7156 cmd_showqueue_parsed(void *parsed_result,
7157         __attribute__((unused)) struct cmdline *cl,
7158         __attribute__((unused)) void *data)
7159 {
7160         struct cmd_showqueue_result *res = parsed_result;
7161
7162         if (!strcmp(res->type, "rxq"))
7163                 rx_queue_infos_display(res->portnum, res->queuenum);
7164         else if (!strcmp(res->type, "txq"))
7165                 tx_queue_infos_display(res->portnum, res->queuenum);
7166 }
7167
7168 cmdline_parse_token_string_t cmd_showqueue_show =
7169         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7170 cmdline_parse_token_string_t cmd_showqueue_type =
7171         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7172 cmdline_parse_token_string_t cmd_showqueue_what =
7173         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7174 cmdline_parse_token_num_t cmd_showqueue_portnum =
7175         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7176 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7177         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7178
7179 cmdline_parse_inst_t cmd_showqueue = {
7180         .f = cmd_showqueue_parsed,
7181         .data = NULL,
7182         .help_str = "show rxq|txq info <port_id> <queue_id>",
7183         .tokens = {
7184                 (void *)&cmd_showqueue_show,
7185                 (void *)&cmd_showqueue_type,
7186                 (void *)&cmd_showqueue_what,
7187                 (void *)&cmd_showqueue_portnum,
7188                 (void *)&cmd_showqueue_queuenum,
7189                 NULL,
7190         },
7191 };
7192
7193 /* *** READ PORT REGISTER *** */
7194 struct cmd_read_reg_result {
7195         cmdline_fixed_string_t read;
7196         cmdline_fixed_string_t reg;
7197         portid_t port_id;
7198         uint32_t reg_off;
7199 };
7200
7201 static void
7202 cmd_read_reg_parsed(void *parsed_result,
7203                     __attribute__((unused)) struct cmdline *cl,
7204                     __attribute__((unused)) void *data)
7205 {
7206         struct cmd_read_reg_result *res = parsed_result;
7207         port_reg_display(res->port_id, res->reg_off);
7208 }
7209
7210 cmdline_parse_token_string_t cmd_read_reg_read =
7211         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7212 cmdline_parse_token_string_t cmd_read_reg_reg =
7213         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7214 cmdline_parse_token_num_t cmd_read_reg_port_id =
7215         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7216 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7217         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7218
7219 cmdline_parse_inst_t cmd_read_reg = {
7220         .f = cmd_read_reg_parsed,
7221         .data = NULL,
7222         .help_str = "read reg <port_id> <reg_off>",
7223         .tokens = {
7224                 (void *)&cmd_read_reg_read,
7225                 (void *)&cmd_read_reg_reg,
7226                 (void *)&cmd_read_reg_port_id,
7227                 (void *)&cmd_read_reg_reg_off,
7228                 NULL,
7229         },
7230 };
7231
7232 /* *** READ PORT REGISTER BIT FIELD *** */
7233 struct cmd_read_reg_bit_field_result {
7234         cmdline_fixed_string_t read;
7235         cmdline_fixed_string_t regfield;
7236         portid_t port_id;
7237         uint32_t reg_off;
7238         uint8_t bit1_pos;
7239         uint8_t bit2_pos;
7240 };
7241
7242 static void
7243 cmd_read_reg_bit_field_parsed(void *parsed_result,
7244                               __attribute__((unused)) struct cmdline *cl,
7245                               __attribute__((unused)) void *data)
7246 {
7247         struct cmd_read_reg_bit_field_result *res = parsed_result;
7248         port_reg_bit_field_display(res->port_id, res->reg_off,
7249                                    res->bit1_pos, res->bit2_pos);
7250 }
7251
7252 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7253         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7254                                  "read");
7255 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7256         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7257                                  regfield, "regfield");
7258 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7259         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7260                               UINT16);
7261 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7262         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7263                               UINT32);
7264 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7265         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7266                               UINT8);
7267 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7268         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7269                               UINT8);
7270
7271 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7272         .f = cmd_read_reg_bit_field_parsed,
7273         .data = NULL,
7274         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7275         "Read register bit field between bit_x and bit_y included",
7276         .tokens = {
7277                 (void *)&cmd_read_reg_bit_field_read,
7278                 (void *)&cmd_read_reg_bit_field_regfield,
7279                 (void *)&cmd_read_reg_bit_field_port_id,
7280                 (void *)&cmd_read_reg_bit_field_reg_off,
7281                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7282                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7283                 NULL,
7284         },
7285 };
7286
7287 /* *** READ PORT REGISTER BIT *** */
7288 struct cmd_read_reg_bit_result {
7289         cmdline_fixed_string_t read;
7290         cmdline_fixed_string_t regbit;
7291         portid_t port_id;
7292         uint32_t reg_off;
7293         uint8_t bit_pos;
7294 };
7295
7296 static void
7297 cmd_read_reg_bit_parsed(void *parsed_result,
7298                         __attribute__((unused)) struct cmdline *cl,
7299                         __attribute__((unused)) void *data)
7300 {
7301         struct cmd_read_reg_bit_result *res = parsed_result;
7302         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7303 }
7304
7305 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7306         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7307 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7308         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7309                                  regbit, "regbit");
7310 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7311         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7312 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7313         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7314 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7315         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7316
7317 cmdline_parse_inst_t cmd_read_reg_bit = {
7318         .f = cmd_read_reg_bit_parsed,
7319         .data = NULL,
7320         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7321         .tokens = {
7322                 (void *)&cmd_read_reg_bit_read,
7323                 (void *)&cmd_read_reg_bit_regbit,
7324                 (void *)&cmd_read_reg_bit_port_id,
7325                 (void *)&cmd_read_reg_bit_reg_off,
7326                 (void *)&cmd_read_reg_bit_bit_pos,
7327                 NULL,
7328         },
7329 };
7330
7331 /* *** WRITE PORT REGISTER *** */
7332 struct cmd_write_reg_result {
7333         cmdline_fixed_string_t write;
7334         cmdline_fixed_string_t reg;
7335         portid_t port_id;
7336         uint32_t reg_off;
7337         uint32_t value;
7338 };
7339
7340 static void
7341 cmd_write_reg_parsed(void *parsed_result,
7342                      __attribute__((unused)) struct cmdline *cl,
7343                      __attribute__((unused)) void *data)
7344 {
7345         struct cmd_write_reg_result *res = parsed_result;
7346         port_reg_set(res->port_id, res->reg_off, res->value);
7347 }
7348
7349 cmdline_parse_token_string_t cmd_write_reg_write =
7350         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7351 cmdline_parse_token_string_t cmd_write_reg_reg =
7352         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7353 cmdline_parse_token_num_t cmd_write_reg_port_id =
7354         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7355 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7356         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7357 cmdline_parse_token_num_t cmd_write_reg_value =
7358         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7359
7360 cmdline_parse_inst_t cmd_write_reg = {
7361         .f = cmd_write_reg_parsed,
7362         .data = NULL,
7363         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7364         .tokens = {
7365                 (void *)&cmd_write_reg_write,
7366                 (void *)&cmd_write_reg_reg,
7367                 (void *)&cmd_write_reg_port_id,
7368                 (void *)&cmd_write_reg_reg_off,
7369                 (void *)&cmd_write_reg_value,
7370                 NULL,
7371         },
7372 };
7373
7374 /* *** WRITE PORT REGISTER BIT FIELD *** */
7375 struct cmd_write_reg_bit_field_result {
7376         cmdline_fixed_string_t write;
7377         cmdline_fixed_string_t regfield;
7378         portid_t port_id;
7379         uint32_t reg_off;
7380         uint8_t bit1_pos;
7381         uint8_t bit2_pos;
7382         uint32_t value;
7383 };
7384
7385 static void
7386 cmd_write_reg_bit_field_parsed(void *parsed_result,
7387                                __attribute__((unused)) struct cmdline *cl,
7388                                __attribute__((unused)) void *data)
7389 {
7390         struct cmd_write_reg_bit_field_result *res = parsed_result;
7391         port_reg_bit_field_set(res->port_id, res->reg_off,
7392                           res->bit1_pos, res->bit2_pos, res->value);
7393 }
7394
7395 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7396         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7397                                  "write");
7398 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7399         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7400                                  regfield, "regfield");
7401 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7402         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7403                               UINT16);
7404 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7405         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7406                               UINT32);
7407 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7408         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7409                               UINT8);
7410 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7411         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7412                               UINT8);
7413 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7414         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7415                               UINT32);
7416
7417 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7418         .f = cmd_write_reg_bit_field_parsed,
7419         .data = NULL,
7420         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7421                 "<reg_value>: "
7422                 "Set register bit field between bit_x and bit_y included",
7423         .tokens = {
7424                 (void *)&cmd_write_reg_bit_field_write,
7425                 (void *)&cmd_write_reg_bit_field_regfield,
7426                 (void *)&cmd_write_reg_bit_field_port_id,
7427                 (void *)&cmd_write_reg_bit_field_reg_off,
7428                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7429                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7430                 (void *)&cmd_write_reg_bit_field_value,
7431                 NULL,
7432         },
7433 };
7434
7435 /* *** WRITE PORT REGISTER BIT *** */
7436 struct cmd_write_reg_bit_result {
7437         cmdline_fixed_string_t write;
7438         cmdline_fixed_string_t regbit;
7439         portid_t port_id;
7440         uint32_t reg_off;
7441         uint8_t bit_pos;
7442         uint8_t value;
7443 };
7444
7445 static void
7446 cmd_write_reg_bit_parsed(void *parsed_result,
7447                          __attribute__((unused)) struct cmdline *cl,
7448                          __attribute__((unused)) void *data)
7449 {
7450         struct cmd_write_reg_bit_result *res = parsed_result;
7451         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7452 }
7453
7454 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7455         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7456                                  "write");
7457 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7458         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7459                                  regbit, "regbit");
7460 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7461         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7462 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7463         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7464 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7465         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7466 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7467         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7468
7469 cmdline_parse_inst_t cmd_write_reg_bit = {
7470         .f = cmd_write_reg_bit_parsed,
7471         .data = NULL,
7472         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7473                 "0 <= bit_x <= 31",
7474         .tokens = {
7475                 (void *)&cmd_write_reg_bit_write,
7476                 (void *)&cmd_write_reg_bit_regbit,
7477                 (void *)&cmd_write_reg_bit_port_id,
7478                 (void *)&cmd_write_reg_bit_reg_off,
7479                 (void *)&cmd_write_reg_bit_bit_pos,
7480                 (void *)&cmd_write_reg_bit_value,
7481                 NULL,
7482         },
7483 };
7484
7485 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7486 struct cmd_read_rxd_txd_result {
7487         cmdline_fixed_string_t read;
7488         cmdline_fixed_string_t rxd_txd;
7489         portid_t port_id;
7490         uint16_t queue_id;
7491         uint16_t desc_id;
7492 };
7493
7494 static void
7495 cmd_read_rxd_txd_parsed(void *parsed_result,
7496                         __attribute__((unused)) struct cmdline *cl,
7497                         __attribute__((unused)) void *data)
7498 {
7499         struct cmd_read_rxd_txd_result *res = parsed_result;
7500
7501         if (!strcmp(res->rxd_txd, "rxd"))
7502                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7503         else if (!strcmp(res->rxd_txd, "txd"))
7504                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7505 }
7506
7507 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7508         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7509 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7510         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7511                                  "rxd#txd");
7512 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7513         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7514 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7515         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7516 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7517         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7518
7519 cmdline_parse_inst_t cmd_read_rxd_txd = {
7520         .f = cmd_read_rxd_txd_parsed,
7521         .data = NULL,
7522         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7523         .tokens = {
7524                 (void *)&cmd_read_rxd_txd_read,
7525                 (void *)&cmd_read_rxd_txd_rxd_txd,
7526                 (void *)&cmd_read_rxd_txd_port_id,
7527                 (void *)&cmd_read_rxd_txd_queue_id,
7528                 (void *)&cmd_read_rxd_txd_desc_id,
7529                 NULL,
7530         },
7531 };
7532
7533 /* *** QUIT *** */
7534 struct cmd_quit_result {
7535         cmdline_fixed_string_t quit;
7536 };
7537
7538 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7539                             struct cmdline *cl,
7540                             __attribute__((unused)) void *data)
7541 {
7542         pmd_test_exit();
7543         cmdline_quit(cl);
7544 }
7545
7546 cmdline_parse_token_string_t cmd_quit_quit =
7547         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7548
7549 cmdline_parse_inst_t cmd_quit = {
7550         .f = cmd_quit_parsed,
7551         .data = NULL,
7552         .help_str = "quit: Exit application",
7553         .tokens = {
7554                 (void *)&cmd_quit_quit,
7555                 NULL,
7556         },
7557 };
7558
7559 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7560 struct cmd_mac_addr_result {
7561         cmdline_fixed_string_t mac_addr_cmd;
7562         cmdline_fixed_string_t what;
7563         uint16_t port_num;
7564         struct ether_addr address;
7565 };
7566
7567 static void cmd_mac_addr_parsed(void *parsed_result,
7568                 __attribute__((unused)) struct cmdline *cl,
7569                 __attribute__((unused)) void *data)
7570 {
7571         struct cmd_mac_addr_result *res = parsed_result;
7572         int ret;
7573
7574         if (strcmp(res->what, "add") == 0)
7575                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7576         else if (strcmp(res->what, "set") == 0)
7577                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7578                                                        &res->address);
7579         else
7580                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7581
7582         /* check the return value and print it if is < 0 */
7583         if(ret < 0)
7584                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7585
7586 }
7587
7588 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7589         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7590                                 "mac_addr");
7591 cmdline_parse_token_string_t cmd_mac_addr_what =
7592         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7593                                 "add#remove#set");
7594 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7595                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7596                                         UINT16);
7597 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7598                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7599
7600 cmdline_parse_inst_t cmd_mac_addr = {
7601         .f = cmd_mac_addr_parsed,
7602         .data = (void *)0,
7603         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7604                         "Add/Remove/Set MAC address on port_id",
7605         .tokens = {
7606                 (void *)&cmd_mac_addr_cmd,
7607                 (void *)&cmd_mac_addr_what,
7608                 (void *)&cmd_mac_addr_portnum,
7609                 (void *)&cmd_mac_addr_addr,
7610                 NULL,
7611         },
7612 };
7613
7614 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7615 struct cmd_eth_peer_result {
7616         cmdline_fixed_string_t set;
7617         cmdline_fixed_string_t eth_peer;
7618         portid_t port_id;
7619         cmdline_fixed_string_t peer_addr;
7620 };
7621
7622 static void cmd_set_eth_peer_parsed(void *parsed_result,
7623                         __attribute__((unused)) struct cmdline *cl,
7624                         __attribute__((unused)) void *data)
7625 {
7626                 struct cmd_eth_peer_result *res = parsed_result;
7627
7628                 if (test_done == 0) {
7629                         printf("Please stop forwarding first\n");
7630                         return;
7631                 }
7632                 if (!strcmp(res->eth_peer, "eth-peer")) {
7633                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7634                         fwd_config_setup();
7635                 }
7636 }
7637 cmdline_parse_token_string_t cmd_eth_peer_set =
7638         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7639 cmdline_parse_token_string_t cmd_eth_peer =
7640         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7641 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7642         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7643 cmdline_parse_token_string_t cmd_eth_peer_addr =
7644         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7645
7646 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7647         .f = cmd_set_eth_peer_parsed,
7648         .data = NULL,
7649         .help_str = "set eth-peer <port_id> <peer_mac>",
7650         .tokens = {
7651                 (void *)&cmd_eth_peer_set,
7652                 (void *)&cmd_eth_peer,
7653                 (void *)&cmd_eth_peer_port_id,
7654                 (void *)&cmd_eth_peer_addr,
7655                 NULL,
7656         },
7657 };
7658
7659 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7660 struct cmd_set_qmap_result {
7661         cmdline_fixed_string_t set;
7662         cmdline_fixed_string_t qmap;
7663         cmdline_fixed_string_t what;
7664         portid_t port_id;
7665         uint16_t queue_id;
7666         uint8_t map_value;
7667 };
7668
7669 static void
7670 cmd_set_qmap_parsed(void *parsed_result,
7671                        __attribute__((unused)) struct cmdline *cl,
7672                        __attribute__((unused)) void *data)
7673 {
7674         struct cmd_set_qmap_result *res = parsed_result;
7675         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7676
7677         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7678 }
7679
7680 cmdline_parse_token_string_t cmd_setqmap_set =
7681         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7682                                  set, "set");
7683 cmdline_parse_token_string_t cmd_setqmap_qmap =
7684         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7685                                  qmap, "stat_qmap");
7686 cmdline_parse_token_string_t cmd_setqmap_what =
7687         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7688                                  what, "tx#rx");
7689 cmdline_parse_token_num_t cmd_setqmap_portid =
7690         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7691                               port_id, UINT16);
7692 cmdline_parse_token_num_t cmd_setqmap_queueid =
7693         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7694                               queue_id, UINT16);
7695 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7696         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7697                               map_value, UINT8);
7698
7699 cmdline_parse_inst_t cmd_set_qmap = {
7700         .f = cmd_set_qmap_parsed,
7701         .data = NULL,
7702         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7703                 "Set statistics mapping value on tx|rx queue_id of port_id",
7704         .tokens = {
7705                 (void *)&cmd_setqmap_set,
7706                 (void *)&cmd_setqmap_qmap,
7707                 (void *)&cmd_setqmap_what,
7708                 (void *)&cmd_setqmap_portid,
7709                 (void *)&cmd_setqmap_queueid,
7710                 (void *)&cmd_setqmap_mapvalue,
7711                 NULL,
7712         },
7713 };
7714
7715 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7716 struct cmd_set_xstats_hide_zero_result {
7717         cmdline_fixed_string_t keyword;
7718         cmdline_fixed_string_t name;
7719         cmdline_fixed_string_t on_off;
7720 };
7721
7722 static void
7723 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7724                         __attribute__((unused)) struct cmdline *cl,
7725                         __attribute__((unused)) void *data)
7726 {
7727         struct cmd_set_xstats_hide_zero_result *res;
7728         uint16_t on_off = 0;
7729
7730         res = parsed_result;
7731         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7732         set_xstats_hide_zero(on_off);
7733 }
7734
7735 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7736         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7737                                  keyword, "set");
7738 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7739         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7740                                  name, "xstats-hide-zero");
7741 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7742         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7743                                  on_off, "on#off");
7744
7745 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7746         .f = cmd_set_xstats_hide_zero_parsed,
7747         .data = NULL,
7748         .help_str = "set xstats-hide-zero on|off",
7749         .tokens = {
7750                 (void *)&cmd_set_xstats_hide_zero_keyword,
7751                 (void *)&cmd_set_xstats_hide_zero_name,
7752                 (void *)&cmd_set_xstats_hide_zero_on_off,
7753                 NULL,
7754         },
7755 };
7756
7757 /* *** CONFIGURE UNICAST HASH TABLE *** */
7758 struct cmd_set_uc_hash_table {
7759         cmdline_fixed_string_t set;
7760         cmdline_fixed_string_t port;
7761         portid_t port_id;
7762         cmdline_fixed_string_t what;
7763         struct ether_addr address;
7764         cmdline_fixed_string_t mode;
7765 };
7766
7767 static void
7768 cmd_set_uc_hash_parsed(void *parsed_result,
7769                        __attribute__((unused)) struct cmdline *cl,
7770                        __attribute__((unused)) void *data)
7771 {
7772         int ret=0;
7773         struct cmd_set_uc_hash_table *res = parsed_result;
7774
7775         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7776
7777         if (strcmp(res->what, "uta") == 0)
7778                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7779                                                 &res->address,(uint8_t)is_on);
7780         if (ret < 0)
7781                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7782
7783 }
7784
7785 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7786         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7787                                  set, "set");
7788 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7789         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7790                                  port, "port");
7791 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7792         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7793                               port_id, UINT16);
7794 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7795         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7796                                  what, "uta");
7797 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7798         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7799                                 address);
7800 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7801         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7802                                  mode, "on#off");
7803
7804 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7805         .f = cmd_set_uc_hash_parsed,
7806         .data = NULL,
7807         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7808         .tokens = {
7809                 (void *)&cmd_set_uc_hash_set,
7810                 (void *)&cmd_set_uc_hash_port,
7811                 (void *)&cmd_set_uc_hash_portid,
7812                 (void *)&cmd_set_uc_hash_what,
7813                 (void *)&cmd_set_uc_hash_mac,
7814                 (void *)&cmd_set_uc_hash_mode,
7815                 NULL,
7816         },
7817 };
7818
7819 struct cmd_set_uc_all_hash_table {
7820         cmdline_fixed_string_t set;
7821         cmdline_fixed_string_t port;
7822         portid_t port_id;
7823         cmdline_fixed_string_t what;
7824         cmdline_fixed_string_t value;
7825         cmdline_fixed_string_t mode;
7826 };
7827
7828 static void
7829 cmd_set_uc_all_hash_parsed(void *parsed_result,
7830                        __attribute__((unused)) struct cmdline *cl,
7831                        __attribute__((unused)) void *data)
7832 {
7833         int ret=0;
7834         struct cmd_set_uc_all_hash_table *res = parsed_result;
7835
7836         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7837
7838         if ((strcmp(res->what, "uta") == 0) &&
7839                 (strcmp(res->value, "all") == 0))
7840                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7841         if (ret < 0)
7842                 printf("bad unicast hash table parameter,"
7843                         "return code = %d \n", ret);
7844 }
7845
7846 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7847         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7848                                  set, "set");
7849 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7850         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7851                                  port, "port");
7852 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7853         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7854                               port_id, UINT16);
7855 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7856         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7857                                  what, "uta");
7858 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7859         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7860                                 value,"all");
7861 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7862         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7863                                  mode, "on#off");
7864
7865 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7866         .f = cmd_set_uc_all_hash_parsed,
7867         .data = NULL,
7868         .help_str = "set port <port_id> uta all on|off",
7869         .tokens = {
7870                 (void *)&cmd_set_uc_all_hash_set,
7871                 (void *)&cmd_set_uc_all_hash_port,
7872                 (void *)&cmd_set_uc_all_hash_portid,
7873                 (void *)&cmd_set_uc_all_hash_what,
7874                 (void *)&cmd_set_uc_all_hash_value,
7875                 (void *)&cmd_set_uc_all_hash_mode,
7876                 NULL,
7877         },
7878 };
7879
7880 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7881 struct cmd_set_vf_macvlan_filter {
7882         cmdline_fixed_string_t set;
7883         cmdline_fixed_string_t port;
7884         portid_t port_id;
7885         cmdline_fixed_string_t vf;
7886         uint8_t vf_id;
7887         struct ether_addr address;
7888         cmdline_fixed_string_t filter_type;
7889         cmdline_fixed_string_t mode;
7890 };
7891
7892 static void
7893 cmd_set_vf_macvlan_parsed(void *parsed_result,
7894                        __attribute__((unused)) struct cmdline *cl,
7895                        __attribute__((unused)) void *data)
7896 {
7897         int is_on, ret = 0;
7898         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7899         struct rte_eth_mac_filter filter;
7900
7901         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7902
7903         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7904
7905         /* set VF MAC filter */
7906         filter.is_vf = 1;
7907
7908         /* set VF ID */
7909         filter.dst_id = res->vf_id;
7910
7911         if (!strcmp(res->filter_type, "exact-mac"))
7912                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7913         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7914                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7915         else if (!strcmp(res->filter_type, "hashmac"))
7916                 filter.filter_type = RTE_MAC_HASH_MATCH;
7917         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7918                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7919
7920         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7921
7922         if (is_on)
7923                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7924                                         RTE_ETH_FILTER_MACVLAN,
7925                                         RTE_ETH_FILTER_ADD,
7926                                          &filter);
7927         else
7928                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7929                                         RTE_ETH_FILTER_MACVLAN,
7930                                         RTE_ETH_FILTER_DELETE,
7931                                         &filter);
7932
7933         if (ret < 0)
7934                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7935
7936 }
7937
7938 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7939         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7940                                  set, "set");
7941 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7942         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7943                                  port, "port");
7944 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7945         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7946                               port_id, UINT16);
7947 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7948         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7949                                  vf, "vf");
7950 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7951         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7952                                 vf_id, UINT8);
7953 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7954         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7955                                 address);
7956 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7957         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7958                                 filter_type, "exact-mac#exact-mac-vlan"
7959                                 "#hashmac#hashmac-vlan");
7960 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7961         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7962                                  mode, "on#off");
7963
7964 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7965         .f = cmd_set_vf_macvlan_parsed,
7966         .data = NULL,
7967         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7968                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7969                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7970                 "hash match rule: hash match of MAC and exact match of VLAN",
7971         .tokens = {
7972                 (void *)&cmd_set_vf_macvlan_set,
7973                 (void *)&cmd_set_vf_macvlan_port,
7974                 (void *)&cmd_set_vf_macvlan_portid,
7975                 (void *)&cmd_set_vf_macvlan_vf,
7976                 (void *)&cmd_set_vf_macvlan_vf_id,
7977                 (void *)&cmd_set_vf_macvlan_mac,
7978                 (void *)&cmd_set_vf_macvlan_filter_type,
7979                 (void *)&cmd_set_vf_macvlan_mode,
7980                 NULL,
7981         },
7982 };
7983
7984 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7985 struct cmd_set_vf_traffic {
7986         cmdline_fixed_string_t set;
7987         cmdline_fixed_string_t port;
7988         portid_t port_id;
7989         cmdline_fixed_string_t vf;
7990         uint8_t vf_id;
7991         cmdline_fixed_string_t what;
7992         cmdline_fixed_string_t mode;
7993 };
7994
7995 static void
7996 cmd_set_vf_traffic_parsed(void *parsed_result,
7997                        __attribute__((unused)) struct cmdline *cl,
7998                        __attribute__((unused)) void *data)
7999 {
8000         struct cmd_set_vf_traffic *res = parsed_result;
8001         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8002         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8003
8004         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8005 }
8006
8007 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8008         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8009                                  set, "set");
8010 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8011         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8012                                  port, "port");
8013 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8014         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8015                               port_id, UINT16);
8016 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8017         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8018                                  vf, "vf");
8019 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8020         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8021                               vf_id, UINT8);
8022 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8023         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8024                                  what, "tx#rx");
8025 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8026         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8027                                  mode, "on#off");
8028
8029 cmdline_parse_inst_t cmd_set_vf_traffic = {
8030         .f = cmd_set_vf_traffic_parsed,
8031         .data = NULL,
8032         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8033         .tokens = {
8034                 (void *)&cmd_setvf_traffic_set,
8035                 (void *)&cmd_setvf_traffic_port,
8036                 (void *)&cmd_setvf_traffic_portid,
8037                 (void *)&cmd_setvf_traffic_vf,
8038                 (void *)&cmd_setvf_traffic_vfid,
8039                 (void *)&cmd_setvf_traffic_what,
8040                 (void *)&cmd_setvf_traffic_mode,
8041                 NULL,
8042         },
8043 };
8044
8045 /* *** CONFIGURE VF RECEIVE MODE *** */
8046 struct cmd_set_vf_rxmode {
8047         cmdline_fixed_string_t set;
8048         cmdline_fixed_string_t port;
8049         portid_t port_id;
8050         cmdline_fixed_string_t vf;
8051         uint8_t vf_id;
8052         cmdline_fixed_string_t what;
8053         cmdline_fixed_string_t mode;
8054         cmdline_fixed_string_t on;
8055 };
8056
8057 static void
8058 cmd_set_vf_rxmode_parsed(void *parsed_result,
8059                        __attribute__((unused)) struct cmdline *cl,
8060                        __attribute__((unused)) void *data)
8061 {
8062         int ret = -ENOTSUP;
8063         uint16_t rx_mode = 0;
8064         struct cmd_set_vf_rxmode *res = parsed_result;
8065
8066         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8067         if (!strcmp(res->what,"rxmode")) {
8068                 if (!strcmp(res->mode, "AUPE"))
8069                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8070                 else if (!strcmp(res->mode, "ROPE"))
8071                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8072                 else if (!strcmp(res->mode, "BAM"))
8073                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8074                 else if (!strncmp(res->mode, "MPE",3))
8075                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8076         }
8077
8078         RTE_SET_USED(is_on);
8079
8080 #ifdef RTE_LIBRTE_IXGBE_PMD
8081         if (ret == -ENOTSUP)
8082                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8083                                                   rx_mode, (uint8_t)is_on);
8084 #endif
8085 #ifdef RTE_LIBRTE_BNXT_PMD
8086         if (ret == -ENOTSUP)
8087                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8088                                                  rx_mode, (uint8_t)is_on);
8089 #endif
8090         if (ret < 0)
8091                 printf("bad VF receive mode parameter, return code = %d \n",
8092                 ret);
8093 }
8094
8095 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8096         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8097                                  set, "set");
8098 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8099         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8100                                  port, "port");
8101 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8102         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8103                               port_id, UINT16);
8104 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8105         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8106                                  vf, "vf");
8107 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8108         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8109                               vf_id, UINT8);
8110 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8111         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8112                                  what, "rxmode");
8113 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8114         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8115                                  mode, "AUPE#ROPE#BAM#MPE");
8116 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8117         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8118                                  on, "on#off");
8119
8120 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8121         .f = cmd_set_vf_rxmode_parsed,
8122         .data = NULL,
8123         .help_str = "set port <port_id> vf <vf_id> rxmode "
8124                 "AUPE|ROPE|BAM|MPE on|off",
8125         .tokens = {
8126                 (void *)&cmd_set_vf_rxmode_set,
8127                 (void *)&cmd_set_vf_rxmode_port,
8128                 (void *)&cmd_set_vf_rxmode_portid,
8129                 (void *)&cmd_set_vf_rxmode_vf,
8130                 (void *)&cmd_set_vf_rxmode_vfid,
8131                 (void *)&cmd_set_vf_rxmode_what,
8132                 (void *)&cmd_set_vf_rxmode_mode,
8133                 (void *)&cmd_set_vf_rxmode_on,
8134                 NULL,
8135         },
8136 };
8137
8138 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8139 struct cmd_vf_mac_addr_result {
8140         cmdline_fixed_string_t mac_addr_cmd;
8141         cmdline_fixed_string_t what;
8142         cmdline_fixed_string_t port;
8143         uint16_t port_num;
8144         cmdline_fixed_string_t vf;
8145         uint8_t vf_num;
8146         struct ether_addr address;
8147 };
8148
8149 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8150                 __attribute__((unused)) struct cmdline *cl,
8151                 __attribute__((unused)) void *data)
8152 {
8153         struct cmd_vf_mac_addr_result *res = parsed_result;
8154         int ret = -ENOTSUP;
8155
8156         if (strcmp(res->what, "add") != 0)
8157                 return;
8158
8159 #ifdef RTE_LIBRTE_I40E_PMD
8160         if (ret == -ENOTSUP)
8161                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8162                                                    &res->address);
8163 #endif
8164 #ifdef RTE_LIBRTE_BNXT_PMD
8165         if (ret == -ENOTSUP)
8166                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8167                                                 res->vf_num);
8168 #endif
8169
8170         if(ret < 0)
8171                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8172
8173 }
8174
8175 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8176         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8177                                 mac_addr_cmd,"mac_addr");
8178 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8179         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8180                                 what,"add");
8181 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8182         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8183                                 port,"port");
8184 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8185         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8186                                 port_num, UINT16);
8187 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8188         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8189                                 vf,"vf");
8190 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8191         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8192                                 vf_num, UINT8);
8193 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8194         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8195                                 address);
8196
8197 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8198         .f = cmd_vf_mac_addr_parsed,
8199         .data = (void *)0,
8200         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8201                 "Add MAC address filtering for a VF on port_id",
8202         .tokens = {
8203                 (void *)&cmd_vf_mac_addr_cmd,
8204                 (void *)&cmd_vf_mac_addr_what,
8205                 (void *)&cmd_vf_mac_addr_port,
8206                 (void *)&cmd_vf_mac_addr_portnum,
8207                 (void *)&cmd_vf_mac_addr_vf,
8208                 (void *)&cmd_vf_mac_addr_vfnum,
8209                 (void *)&cmd_vf_mac_addr_addr,
8210                 NULL,
8211         },
8212 };
8213
8214 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8215 struct cmd_vf_rx_vlan_filter {
8216         cmdline_fixed_string_t rx_vlan;
8217         cmdline_fixed_string_t what;
8218         uint16_t vlan_id;
8219         cmdline_fixed_string_t port;
8220         portid_t port_id;
8221         cmdline_fixed_string_t vf;
8222         uint64_t vf_mask;
8223 };
8224
8225 static void
8226 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8227                           __attribute__((unused)) struct cmdline *cl,
8228                           __attribute__((unused)) void *data)
8229 {
8230         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8231         int ret = -ENOTSUP;
8232
8233         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8234
8235 #ifdef RTE_LIBRTE_IXGBE_PMD
8236         if (ret == -ENOTSUP)
8237                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8238                                 res->vlan_id, res->vf_mask, is_add);
8239 #endif
8240 #ifdef RTE_LIBRTE_I40E_PMD
8241         if (ret == -ENOTSUP)
8242                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8243                                 res->vlan_id, res->vf_mask, is_add);
8244 #endif
8245 #ifdef RTE_LIBRTE_BNXT_PMD
8246         if (ret == -ENOTSUP)
8247                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8248                                 res->vlan_id, res->vf_mask, is_add);
8249 #endif
8250
8251         switch (ret) {
8252         case 0:
8253                 break;
8254         case -EINVAL:
8255                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8256                                 res->vlan_id, res->vf_mask);
8257                 break;
8258         case -ENODEV:
8259                 printf("invalid port_id %d\n", res->port_id);
8260                 break;
8261         case -ENOTSUP:
8262                 printf("function not implemented or supported\n");
8263                 break;
8264         default:
8265                 printf("programming error: (%s)\n", strerror(-ret));
8266         }
8267 }
8268
8269 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8270         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8271                                  rx_vlan, "rx_vlan");
8272 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8273         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8274                                  what, "add#rm");
8275 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8276         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8277                               vlan_id, UINT16);
8278 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8279         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8280                                  port, "port");
8281 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8282         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8283                               port_id, UINT16);
8284 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8285         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8286                                  vf, "vf");
8287 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8288         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8289                               vf_mask, UINT64);
8290
8291 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8292         .f = cmd_vf_rx_vlan_filter_parsed,
8293         .data = NULL,
8294         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8295                 "(vf_mask = hexadecimal VF mask)",
8296         .tokens = {
8297                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8298                 (void *)&cmd_vf_rx_vlan_filter_what,
8299                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8300                 (void *)&cmd_vf_rx_vlan_filter_port,
8301                 (void *)&cmd_vf_rx_vlan_filter_portid,
8302                 (void *)&cmd_vf_rx_vlan_filter_vf,
8303                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8304                 NULL,
8305         },
8306 };
8307
8308 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8309 struct cmd_queue_rate_limit_result {
8310         cmdline_fixed_string_t set;
8311         cmdline_fixed_string_t port;
8312         uint16_t port_num;
8313         cmdline_fixed_string_t queue;
8314         uint8_t queue_num;
8315         cmdline_fixed_string_t rate;
8316         uint16_t rate_num;
8317 };
8318
8319 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8320                 __attribute__((unused)) struct cmdline *cl,
8321                 __attribute__((unused)) void *data)
8322 {
8323         struct cmd_queue_rate_limit_result *res = parsed_result;
8324         int ret = 0;
8325
8326         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8327                 && (strcmp(res->queue, "queue") == 0)
8328                 && (strcmp(res->rate, "rate") == 0))
8329                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8330                                         res->rate_num);
8331         if (ret < 0)
8332                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8333
8334 }
8335
8336 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8337         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8338                                 set, "set");
8339 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8340         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8341                                 port, "port");
8342 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8343         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8344                                 port_num, UINT16);
8345 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8346         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8347                                 queue, "queue");
8348 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8349         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8350                                 queue_num, UINT8);
8351 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8352         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8353                                 rate, "rate");
8354 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8355         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8356                                 rate_num, UINT16);
8357
8358 cmdline_parse_inst_t cmd_queue_rate_limit = {
8359         .f = cmd_queue_rate_limit_parsed,
8360         .data = (void *)0,
8361         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8362                 "Set rate limit for a queue on port_id",
8363         .tokens = {
8364                 (void *)&cmd_queue_rate_limit_set,
8365                 (void *)&cmd_queue_rate_limit_port,
8366                 (void *)&cmd_queue_rate_limit_portnum,
8367                 (void *)&cmd_queue_rate_limit_queue,
8368                 (void *)&cmd_queue_rate_limit_queuenum,
8369                 (void *)&cmd_queue_rate_limit_rate,
8370                 (void *)&cmd_queue_rate_limit_ratenum,
8371                 NULL,
8372         },
8373 };
8374
8375 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8376 struct cmd_vf_rate_limit_result {
8377         cmdline_fixed_string_t set;
8378         cmdline_fixed_string_t port;
8379         uint16_t port_num;
8380         cmdline_fixed_string_t vf;
8381         uint8_t vf_num;
8382         cmdline_fixed_string_t rate;
8383         uint16_t rate_num;
8384         cmdline_fixed_string_t q_msk;
8385         uint64_t q_msk_val;
8386 };
8387
8388 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8389                 __attribute__((unused)) struct cmdline *cl,
8390                 __attribute__((unused)) void *data)
8391 {
8392         struct cmd_vf_rate_limit_result *res = parsed_result;
8393         int ret = 0;
8394
8395         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8396                 && (strcmp(res->vf, "vf") == 0)
8397                 && (strcmp(res->rate, "rate") == 0)
8398                 && (strcmp(res->q_msk, "queue_mask") == 0))
8399                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8400                                         res->rate_num, res->q_msk_val);
8401         if (ret < 0)
8402                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8403
8404 }
8405
8406 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8407         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8408                                 set, "set");
8409 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8410         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8411                                 port, "port");
8412 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8413         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8414                                 port_num, UINT16);
8415 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8416         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8417                                 vf, "vf");
8418 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8419         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8420                                 vf_num, UINT8);
8421 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8422         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8423                                 rate, "rate");
8424 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8425         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8426                                 rate_num, UINT16);
8427 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8428         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8429                                 q_msk, "queue_mask");
8430 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8431         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8432                                 q_msk_val, UINT64);
8433
8434 cmdline_parse_inst_t cmd_vf_rate_limit = {
8435         .f = cmd_vf_rate_limit_parsed,
8436         .data = (void *)0,
8437         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8438                 "queue_mask <queue_mask_value>: "
8439                 "Set rate limit for queues of VF on port_id",
8440         .tokens = {
8441                 (void *)&cmd_vf_rate_limit_set,
8442                 (void *)&cmd_vf_rate_limit_port,
8443                 (void *)&cmd_vf_rate_limit_portnum,
8444                 (void *)&cmd_vf_rate_limit_vf,
8445                 (void *)&cmd_vf_rate_limit_vfnum,
8446                 (void *)&cmd_vf_rate_limit_rate,
8447                 (void *)&cmd_vf_rate_limit_ratenum,
8448                 (void *)&cmd_vf_rate_limit_q_msk,
8449                 (void *)&cmd_vf_rate_limit_q_msk_val,
8450                 NULL,
8451         },
8452 };
8453
8454 /* *** ADD TUNNEL FILTER OF A PORT *** */
8455 struct cmd_tunnel_filter_result {
8456         cmdline_fixed_string_t cmd;
8457         cmdline_fixed_string_t what;
8458         portid_t port_id;
8459         struct ether_addr outer_mac;
8460         struct ether_addr inner_mac;
8461         cmdline_ipaddr_t ip_value;
8462         uint16_t inner_vlan;
8463         cmdline_fixed_string_t tunnel_type;
8464         cmdline_fixed_string_t filter_type;
8465         uint32_t tenant_id;
8466         uint16_t queue_num;
8467 };
8468
8469 static void
8470 cmd_tunnel_filter_parsed(void *parsed_result,
8471                           __attribute__((unused)) struct cmdline *cl,
8472                           __attribute__((unused)) void *data)
8473 {
8474         struct cmd_tunnel_filter_result *res = parsed_result;
8475         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8476         int ret = 0;
8477
8478         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8479
8480         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8481         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8482         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8483
8484         if (res->ip_value.family == AF_INET) {
8485                 tunnel_filter_conf.ip_addr.ipv4_addr =
8486                         res->ip_value.addr.ipv4.s_addr;
8487                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8488         } else {
8489                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8490                         &(res->ip_value.addr.ipv6),
8491                         sizeof(struct in6_addr));
8492                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8493         }
8494
8495         if (!strcmp(res->filter_type, "imac-ivlan"))
8496                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8497         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8498                 tunnel_filter_conf.filter_type =
8499                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8500         else if (!strcmp(res->filter_type, "imac-tenid"))
8501                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8502         else if (!strcmp(res->filter_type, "imac"))
8503                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8504         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8505                 tunnel_filter_conf.filter_type =
8506                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8507         else if (!strcmp(res->filter_type, "oip"))
8508                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8509         else if (!strcmp(res->filter_type, "iip"))
8510                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8511         else {
8512                 printf("The filter type is not supported");
8513                 return;
8514         }
8515
8516         if (!strcmp(res->tunnel_type, "vxlan"))
8517                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8518         else if (!strcmp(res->tunnel_type, "nvgre"))
8519                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8520         else if (!strcmp(res->tunnel_type, "ipingre"))
8521                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8522         else {
8523                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8524                 return;
8525         }
8526
8527         tunnel_filter_conf.tenant_id = res->tenant_id;
8528         tunnel_filter_conf.queue_id = res->queue_num;
8529         if (!strcmp(res->what, "add"))
8530                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8531                                         RTE_ETH_FILTER_TUNNEL,
8532                                         RTE_ETH_FILTER_ADD,
8533                                         &tunnel_filter_conf);
8534         else
8535                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8536                                         RTE_ETH_FILTER_TUNNEL,
8537                                         RTE_ETH_FILTER_DELETE,
8538                                         &tunnel_filter_conf);
8539         if (ret < 0)
8540                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8541                                 strerror(-ret));
8542
8543 }
8544 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8545         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8546         cmd, "tunnel_filter");
8547 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8548         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8549         what, "add#rm");
8550 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8551         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8552         port_id, UINT16);
8553 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8554         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8555         outer_mac);
8556 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8557         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8558         inner_mac);
8559 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8560         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8561         inner_vlan, UINT16);
8562 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8563         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8564         ip_value);
8565 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8566         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8567         tunnel_type, "vxlan#nvgre#ipingre");
8568
8569 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8570         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8571         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8572                 "imac#omac-imac-tenid");
8573 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8574         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8575         tenant_id, UINT32);
8576 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8577         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8578         queue_num, UINT16);
8579
8580 cmdline_parse_inst_t cmd_tunnel_filter = {
8581         .f = cmd_tunnel_filter_parsed,
8582         .data = (void *)0,
8583         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8584                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8585                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8586                 "<queue_id>: Add/Rm tunnel filter of a port",
8587         .tokens = {
8588                 (void *)&cmd_tunnel_filter_cmd,
8589                 (void *)&cmd_tunnel_filter_what,
8590                 (void *)&cmd_tunnel_filter_port_id,
8591                 (void *)&cmd_tunnel_filter_outer_mac,
8592                 (void *)&cmd_tunnel_filter_inner_mac,
8593                 (void *)&cmd_tunnel_filter_ip_value,
8594                 (void *)&cmd_tunnel_filter_innner_vlan,
8595                 (void *)&cmd_tunnel_filter_tunnel_type,
8596                 (void *)&cmd_tunnel_filter_filter_type,
8597                 (void *)&cmd_tunnel_filter_tenant_id,
8598                 (void *)&cmd_tunnel_filter_queue_num,
8599                 NULL,
8600         },
8601 };
8602
8603 /* *** CONFIGURE TUNNEL UDP PORT *** */
8604 struct cmd_tunnel_udp_config {
8605         cmdline_fixed_string_t cmd;
8606         cmdline_fixed_string_t what;
8607         uint16_t udp_port;
8608         portid_t port_id;
8609 };
8610
8611 static void
8612 cmd_tunnel_udp_config_parsed(void *parsed_result,
8613                           __attribute__((unused)) struct cmdline *cl,
8614                           __attribute__((unused)) void *data)
8615 {
8616         struct cmd_tunnel_udp_config *res = parsed_result;
8617         struct rte_eth_udp_tunnel tunnel_udp;
8618         int ret;
8619
8620         tunnel_udp.udp_port = res->udp_port;
8621
8622         if (!strcmp(res->cmd, "rx_vxlan_port"))
8623                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8624
8625         if (!strcmp(res->what, "add"))
8626                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8627                                                       &tunnel_udp);
8628         else
8629                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8630                                                          &tunnel_udp);
8631
8632         if (ret < 0)
8633                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8634 }
8635
8636 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8637         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8638                                 cmd, "rx_vxlan_port");
8639 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8640         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8641                                 what, "add#rm");
8642 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8643         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8644                                 udp_port, UINT16);
8645 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8646         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8647                                 port_id, UINT16);
8648
8649 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8650         .f = cmd_tunnel_udp_config_parsed,
8651         .data = (void *)0,
8652         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8653                 "Add/Remove a tunneling UDP port filter",
8654         .tokens = {
8655                 (void *)&cmd_tunnel_udp_config_cmd,
8656                 (void *)&cmd_tunnel_udp_config_what,
8657                 (void *)&cmd_tunnel_udp_config_udp_port,
8658                 (void *)&cmd_tunnel_udp_config_port_id,
8659                 NULL,
8660         },
8661 };
8662
8663 struct cmd_config_tunnel_udp_port {
8664         cmdline_fixed_string_t port;
8665         cmdline_fixed_string_t config;
8666         portid_t port_id;
8667         cmdline_fixed_string_t udp_tunnel_port;
8668         cmdline_fixed_string_t action;
8669         cmdline_fixed_string_t tunnel_type;
8670         uint16_t udp_port;
8671 };
8672
8673 static void
8674 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8675                                __attribute__((unused)) struct cmdline *cl,
8676                                __attribute__((unused)) void *data)
8677 {
8678         struct cmd_config_tunnel_udp_port *res = parsed_result;
8679         struct rte_eth_udp_tunnel tunnel_udp;
8680         int ret = 0;
8681
8682         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8683                 return;
8684
8685         tunnel_udp.udp_port = res->udp_port;
8686
8687         if (!strcmp(res->tunnel_type, "vxlan")) {
8688                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8689         } else if (!strcmp(res->tunnel_type, "geneve")) {
8690                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8691         } else {
8692                 printf("Invalid tunnel type\n");
8693                 return;
8694         }
8695
8696         if (!strcmp(res->action, "add"))
8697                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8698                                                       &tunnel_udp);
8699         else
8700                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8701                                                          &tunnel_udp);
8702
8703         if (ret < 0)
8704                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8705 }
8706
8707 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8708         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8709                                  "port");
8710 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8711         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8712                                  "config");
8713 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8714         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8715                               UINT16);
8716 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8717         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8718                                  udp_tunnel_port,
8719                                  "udp_tunnel_port");
8720 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8721         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8722                                  "add#rm");
8723 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8724         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8725                                  "vxlan#geneve");
8726 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8727         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8728                               UINT16);
8729
8730 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8731         .f = cmd_cfg_tunnel_udp_port_parsed,
8732         .data = NULL,
8733         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8734         .tokens = {
8735                 (void *)&cmd_config_tunnel_udp_port_port,
8736                 (void *)&cmd_config_tunnel_udp_port_config,
8737                 (void *)&cmd_config_tunnel_udp_port_port_id,
8738                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8739                 (void *)&cmd_config_tunnel_udp_port_action,
8740                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8741                 (void *)&cmd_config_tunnel_udp_port_value,
8742                 NULL,
8743         },
8744 };
8745
8746 /* *** GLOBAL CONFIG *** */
8747 struct cmd_global_config_result {
8748         cmdline_fixed_string_t cmd;
8749         portid_t port_id;
8750         cmdline_fixed_string_t cfg_type;
8751         uint8_t len;
8752 };
8753
8754 static void
8755 cmd_global_config_parsed(void *parsed_result,
8756                          __attribute__((unused)) struct cmdline *cl,
8757                          __attribute__((unused)) void *data)
8758 {
8759         struct cmd_global_config_result *res = parsed_result;
8760         struct rte_eth_global_cfg conf;
8761         int ret;
8762
8763         memset(&conf, 0, sizeof(conf));
8764         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8765         conf.cfg.gre_key_len = res->len;
8766         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8767                                       RTE_ETH_FILTER_SET, &conf);
8768         if (ret != 0)
8769                 printf("Global config error\n");
8770 }
8771
8772 cmdline_parse_token_string_t cmd_global_config_cmd =
8773         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8774                 "global_config");
8775 cmdline_parse_token_num_t cmd_global_config_port_id =
8776         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8777                                UINT16);
8778 cmdline_parse_token_string_t cmd_global_config_type =
8779         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8780                 cfg_type, "gre-key-len");
8781 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8782         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8783                 len, UINT8);
8784
8785 cmdline_parse_inst_t cmd_global_config = {
8786         .f = cmd_global_config_parsed,
8787         .data = (void *)NULL,
8788         .help_str = "global_config <port_id> gre-key-len <key_len>",
8789         .tokens = {
8790                 (void *)&cmd_global_config_cmd,
8791                 (void *)&cmd_global_config_port_id,
8792                 (void *)&cmd_global_config_type,
8793                 (void *)&cmd_global_config_gre_key_len,
8794                 NULL,
8795         },
8796 };
8797
8798 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8799 struct cmd_set_mirror_mask_result {
8800         cmdline_fixed_string_t set;
8801         cmdline_fixed_string_t port;
8802         portid_t port_id;
8803         cmdline_fixed_string_t mirror;
8804         uint8_t rule_id;
8805         cmdline_fixed_string_t what;
8806         cmdline_fixed_string_t value;
8807         cmdline_fixed_string_t dstpool;
8808         uint8_t dstpool_id;
8809         cmdline_fixed_string_t on;
8810 };
8811
8812 cmdline_parse_token_string_t cmd_mirror_mask_set =
8813         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8814                                 set, "set");
8815 cmdline_parse_token_string_t cmd_mirror_mask_port =
8816         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8817                                 port, "port");
8818 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8819         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8820                                 port_id, UINT16);
8821 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8822         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8823                                 mirror, "mirror-rule");
8824 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8825         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8826                                 rule_id, UINT8);
8827 cmdline_parse_token_string_t cmd_mirror_mask_what =
8828         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8829                                 what, "pool-mirror-up#pool-mirror-down"
8830                                       "#vlan-mirror");
8831 cmdline_parse_token_string_t cmd_mirror_mask_value =
8832         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8833                                 value, NULL);
8834 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8835         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8836                                 dstpool, "dst-pool");
8837 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8838         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8839                                 dstpool_id, UINT8);
8840 cmdline_parse_token_string_t cmd_mirror_mask_on =
8841         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8842                                 on, "on#off");
8843
8844 static void
8845 cmd_set_mirror_mask_parsed(void *parsed_result,
8846                        __attribute__((unused)) struct cmdline *cl,
8847                        __attribute__((unused)) void *data)
8848 {
8849         int ret,nb_item,i;
8850         struct cmd_set_mirror_mask_result *res = parsed_result;
8851         struct rte_eth_mirror_conf mr_conf;
8852
8853         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8854
8855         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8856
8857         mr_conf.dst_pool = res->dstpool_id;
8858
8859         if (!strcmp(res->what, "pool-mirror-up")) {
8860                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8861                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8862         } else if (!strcmp(res->what, "pool-mirror-down")) {
8863                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8864                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8865         } else if (!strcmp(res->what, "vlan-mirror")) {
8866                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8867                 nb_item = parse_item_list(res->value, "vlan",
8868                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8869                 if (nb_item <= 0)
8870                         return;
8871
8872                 for (i = 0; i < nb_item; i++) {
8873                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8874                                 printf("Invalid vlan_id: must be < 4096\n");
8875                                 return;
8876                         }
8877
8878                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8879                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8880                 }
8881         }
8882
8883         if (!strcmp(res->on, "on"))
8884                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8885                                                 res->rule_id, 1);
8886         else
8887                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8888                                                 res->rule_id, 0);
8889         if (ret < 0)
8890                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8891 }
8892
8893 cmdline_parse_inst_t cmd_set_mirror_mask = {
8894                 .f = cmd_set_mirror_mask_parsed,
8895                 .data = NULL,
8896                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8897                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8898                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8899                 .tokens = {
8900                         (void *)&cmd_mirror_mask_set,
8901                         (void *)&cmd_mirror_mask_port,
8902                         (void *)&cmd_mirror_mask_portid,
8903                         (void *)&cmd_mirror_mask_mirror,
8904                         (void *)&cmd_mirror_mask_ruleid,
8905                         (void *)&cmd_mirror_mask_what,
8906                         (void *)&cmd_mirror_mask_value,
8907                         (void *)&cmd_mirror_mask_dstpool,
8908                         (void *)&cmd_mirror_mask_poolid,
8909                         (void *)&cmd_mirror_mask_on,
8910                         NULL,
8911                 },
8912 };
8913
8914 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8915 struct cmd_set_mirror_link_result {
8916         cmdline_fixed_string_t set;
8917         cmdline_fixed_string_t port;
8918         portid_t port_id;
8919         cmdline_fixed_string_t mirror;
8920         uint8_t rule_id;
8921         cmdline_fixed_string_t what;
8922         cmdline_fixed_string_t dstpool;
8923         uint8_t dstpool_id;
8924         cmdline_fixed_string_t on;
8925 };
8926
8927 cmdline_parse_token_string_t cmd_mirror_link_set =
8928         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8929                                  set, "set");
8930 cmdline_parse_token_string_t cmd_mirror_link_port =
8931         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8932                                 port, "port");
8933 cmdline_parse_token_num_t cmd_mirror_link_portid =
8934         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8935                                 port_id, UINT16);
8936 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8937         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8938                                 mirror, "mirror-rule");
8939 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8940         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8941                             rule_id, UINT8);
8942 cmdline_parse_token_string_t cmd_mirror_link_what =
8943         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8944                                 what, "uplink-mirror#downlink-mirror");
8945 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8946         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8947                                 dstpool, "dst-pool");
8948 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8949         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8950                                 dstpool_id, UINT8);
8951 cmdline_parse_token_string_t cmd_mirror_link_on =
8952         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8953                                 on, "on#off");
8954
8955 static void
8956 cmd_set_mirror_link_parsed(void *parsed_result,
8957                        __attribute__((unused)) struct cmdline *cl,
8958                        __attribute__((unused)) void *data)
8959 {
8960         int ret;
8961         struct cmd_set_mirror_link_result *res = parsed_result;
8962         struct rte_eth_mirror_conf mr_conf;
8963
8964         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8965         if (!strcmp(res->what, "uplink-mirror"))
8966                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8967         else
8968                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8969
8970         mr_conf.dst_pool = res->dstpool_id;
8971
8972         if (!strcmp(res->on, "on"))
8973                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8974                                                 res->rule_id, 1);
8975         else
8976                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8977                                                 res->rule_id, 0);
8978
8979         /* check the return value and print it if is < 0 */
8980         if (ret < 0)
8981                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8982
8983 }
8984
8985 cmdline_parse_inst_t cmd_set_mirror_link = {
8986                 .f = cmd_set_mirror_link_parsed,
8987                 .data = NULL,
8988                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8989                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8990                 .tokens = {
8991                         (void *)&cmd_mirror_link_set,
8992                         (void *)&cmd_mirror_link_port,
8993                         (void *)&cmd_mirror_link_portid,
8994                         (void *)&cmd_mirror_link_mirror,
8995                         (void *)&cmd_mirror_link_ruleid,
8996                         (void *)&cmd_mirror_link_what,
8997                         (void *)&cmd_mirror_link_dstpool,
8998                         (void *)&cmd_mirror_link_poolid,
8999                         (void *)&cmd_mirror_link_on,
9000                         NULL,
9001                 },
9002 };
9003
9004 /* *** RESET VM MIRROR RULE *** */
9005 struct cmd_rm_mirror_rule_result {
9006         cmdline_fixed_string_t reset;
9007         cmdline_fixed_string_t port;
9008         portid_t port_id;
9009         cmdline_fixed_string_t mirror;
9010         uint8_t rule_id;
9011 };
9012
9013 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9014         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9015                                  reset, "reset");
9016 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9017         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9018                                 port, "port");
9019 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9020         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9021                                 port_id, UINT16);
9022 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9023         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9024                                 mirror, "mirror-rule");
9025 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9026         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9027                                 rule_id, UINT8);
9028
9029 static void
9030 cmd_reset_mirror_rule_parsed(void *parsed_result,
9031                        __attribute__((unused)) struct cmdline *cl,
9032                        __attribute__((unused)) void *data)
9033 {
9034         int ret;
9035         struct cmd_set_mirror_link_result *res = parsed_result;
9036         /* check rule_id */
9037         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9038         if(ret < 0)
9039                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9040 }
9041
9042 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9043                 .f = cmd_reset_mirror_rule_parsed,
9044                 .data = NULL,
9045                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9046                 .tokens = {
9047                         (void *)&cmd_rm_mirror_rule_reset,
9048                         (void *)&cmd_rm_mirror_rule_port,
9049                         (void *)&cmd_rm_mirror_rule_portid,
9050                         (void *)&cmd_rm_mirror_rule_mirror,
9051                         (void *)&cmd_rm_mirror_rule_ruleid,
9052                         NULL,
9053                 },
9054 };
9055
9056 /* ******************************************************************************** */
9057
9058 struct cmd_dump_result {
9059         cmdline_fixed_string_t dump;
9060 };
9061
9062 static void
9063 dump_struct_sizes(void)
9064 {
9065 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9066         DUMP_SIZE(struct rte_mbuf);
9067         DUMP_SIZE(struct rte_mempool);
9068         DUMP_SIZE(struct rte_ring);
9069 #undef DUMP_SIZE
9070 }
9071
9072 static void cmd_dump_parsed(void *parsed_result,
9073                             __attribute__((unused)) struct cmdline *cl,
9074                             __attribute__((unused)) void *data)
9075 {
9076         struct cmd_dump_result *res = parsed_result;
9077
9078         if (!strcmp(res->dump, "dump_physmem"))
9079                 rte_dump_physmem_layout(stdout);
9080         else if (!strcmp(res->dump, "dump_memzone"))
9081                 rte_memzone_dump(stdout);
9082         else if (!strcmp(res->dump, "dump_struct_sizes"))
9083                 dump_struct_sizes();
9084         else if (!strcmp(res->dump, "dump_ring"))
9085                 rte_ring_list_dump(stdout);
9086         else if (!strcmp(res->dump, "dump_mempool"))
9087                 rte_mempool_list_dump(stdout);
9088         else if (!strcmp(res->dump, "dump_devargs"))
9089                 rte_devargs_dump(stdout);
9090         else if (!strcmp(res->dump, "dump_log_types"))
9091                 rte_log_dump(stdout);
9092 }
9093
9094 cmdline_parse_token_string_t cmd_dump_dump =
9095         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9096                 "dump_physmem#"
9097                 "dump_memzone#"
9098                 "dump_struct_sizes#"
9099                 "dump_ring#"
9100                 "dump_mempool#"
9101                 "dump_devargs#"
9102                 "dump_log_types");
9103
9104 cmdline_parse_inst_t cmd_dump = {
9105         .f = cmd_dump_parsed,  /* function to call */
9106         .data = NULL,      /* 2nd arg of func */
9107         .help_str = "Dump status",
9108         .tokens = {        /* token list, NULL terminated */
9109                 (void *)&cmd_dump_dump,
9110                 NULL,
9111         },
9112 };
9113
9114 /* ******************************************************************************** */
9115
9116 struct cmd_dump_one_result {
9117         cmdline_fixed_string_t dump;
9118         cmdline_fixed_string_t name;
9119 };
9120
9121 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9122                                 __attribute__((unused)) void *data)
9123 {
9124         struct cmd_dump_one_result *res = parsed_result;
9125
9126         if (!strcmp(res->dump, "dump_ring")) {
9127                 struct rte_ring *r;
9128                 r = rte_ring_lookup(res->name);
9129                 if (r == NULL) {
9130                         cmdline_printf(cl, "Cannot find ring\n");
9131                         return;
9132                 }
9133                 rte_ring_dump(stdout, r);
9134         } else if (!strcmp(res->dump, "dump_mempool")) {
9135                 struct rte_mempool *mp;
9136                 mp = rte_mempool_lookup(res->name);
9137                 if (mp == NULL) {
9138                         cmdline_printf(cl, "Cannot find mempool\n");
9139                         return;
9140                 }
9141                 rte_mempool_dump(stdout, mp);
9142         }
9143 }
9144
9145 cmdline_parse_token_string_t cmd_dump_one_dump =
9146         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9147                                  "dump_ring#dump_mempool");
9148
9149 cmdline_parse_token_string_t cmd_dump_one_name =
9150         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9151
9152 cmdline_parse_inst_t cmd_dump_one = {
9153         .f = cmd_dump_one_parsed,  /* function to call */
9154         .data = NULL,      /* 2nd arg of func */
9155         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9156         .tokens = {        /* token list, NULL terminated */
9157                 (void *)&cmd_dump_one_dump,
9158                 (void *)&cmd_dump_one_name,
9159                 NULL,
9160         },
9161 };
9162
9163 /* *** Add/Del syn filter *** */
9164 struct cmd_syn_filter_result {
9165         cmdline_fixed_string_t filter;
9166         portid_t port_id;
9167         cmdline_fixed_string_t ops;
9168         cmdline_fixed_string_t priority;
9169         cmdline_fixed_string_t high;
9170         cmdline_fixed_string_t queue;
9171         uint16_t queue_id;
9172 };
9173
9174 static void
9175 cmd_syn_filter_parsed(void *parsed_result,
9176                         __attribute__((unused)) struct cmdline *cl,
9177                         __attribute__((unused)) void *data)
9178 {
9179         struct cmd_syn_filter_result *res = parsed_result;
9180         struct rte_eth_syn_filter syn_filter;
9181         int ret = 0;
9182
9183         ret = rte_eth_dev_filter_supported(res->port_id,
9184                                         RTE_ETH_FILTER_SYN);
9185         if (ret < 0) {
9186                 printf("syn filter is not supported on port %u.\n",
9187                                 res->port_id);
9188                 return;
9189         }
9190
9191         memset(&syn_filter, 0, sizeof(syn_filter));
9192
9193         if (!strcmp(res->ops, "add")) {
9194                 if (!strcmp(res->high, "high"))
9195                         syn_filter.hig_pri = 1;
9196                 else
9197                         syn_filter.hig_pri = 0;
9198
9199                 syn_filter.queue = res->queue_id;
9200                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9201                                                 RTE_ETH_FILTER_SYN,
9202                                                 RTE_ETH_FILTER_ADD,
9203                                                 &syn_filter);
9204         } else
9205                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9206                                                 RTE_ETH_FILTER_SYN,
9207                                                 RTE_ETH_FILTER_DELETE,
9208                                                 &syn_filter);
9209
9210         if (ret < 0)
9211                 printf("syn filter programming error: (%s)\n",
9212                                 strerror(-ret));
9213 }
9214
9215 cmdline_parse_token_string_t cmd_syn_filter_filter =
9216         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9217         filter, "syn_filter");
9218 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9219         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9220         port_id, UINT16);
9221 cmdline_parse_token_string_t cmd_syn_filter_ops =
9222         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9223         ops, "add#del");
9224 cmdline_parse_token_string_t cmd_syn_filter_priority =
9225         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9226                                 priority, "priority");
9227 cmdline_parse_token_string_t cmd_syn_filter_high =
9228         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9229                                 high, "high#low");
9230 cmdline_parse_token_string_t cmd_syn_filter_queue =
9231         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9232                                 queue, "queue");
9233 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9234         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9235                                 queue_id, UINT16);
9236
9237 cmdline_parse_inst_t cmd_syn_filter = {
9238         .f = cmd_syn_filter_parsed,
9239         .data = NULL,
9240         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9241                 "<queue_id>: Add/Delete syn filter",
9242         .tokens = {
9243                 (void *)&cmd_syn_filter_filter,
9244                 (void *)&cmd_syn_filter_port_id,
9245                 (void *)&cmd_syn_filter_ops,
9246                 (void *)&cmd_syn_filter_priority,
9247                 (void *)&cmd_syn_filter_high,
9248                 (void *)&cmd_syn_filter_queue,
9249                 (void *)&cmd_syn_filter_queue_id,
9250                 NULL,
9251         },
9252 };
9253
9254 /* *** queue region set *** */
9255 struct cmd_queue_region_result {
9256         cmdline_fixed_string_t set;
9257         cmdline_fixed_string_t port;
9258         portid_t port_id;
9259         cmdline_fixed_string_t cmd;
9260         cmdline_fixed_string_t region;
9261         uint8_t  region_id;
9262         cmdline_fixed_string_t queue_start_index;
9263         uint8_t  queue_id;
9264         cmdline_fixed_string_t queue_num;
9265         uint8_t  queue_num_value;
9266 };
9267
9268 static void
9269 cmd_queue_region_parsed(void *parsed_result,
9270                         __attribute__((unused)) struct cmdline *cl,
9271                         __attribute__((unused)) void *data)
9272 {
9273         struct cmd_queue_region_result *res = parsed_result;
9274         int ret = -ENOTSUP;
9275 #ifdef RTE_LIBRTE_I40E_PMD
9276         struct rte_pmd_i40e_queue_region_conf region_conf;
9277         enum rte_pmd_i40e_queue_region_op op_type;
9278 #endif
9279
9280         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9281                 return;
9282
9283 #ifdef RTE_LIBRTE_I40E_PMD
9284         memset(&region_conf, 0, sizeof(region_conf));
9285         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9286         region_conf.region_id = res->region_id;
9287         region_conf.queue_num = res->queue_num_value;
9288         region_conf.queue_start_index = res->queue_id;
9289
9290         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9291                                 op_type, &region_conf);
9292 #endif
9293
9294         switch (ret) {
9295         case 0:
9296                 break;
9297         case -ENOTSUP:
9298                 printf("function not implemented or supported\n");
9299                 break;
9300         default:
9301                 printf("queue region config error: (%s)\n", strerror(-ret));
9302         }
9303 }
9304
9305 cmdline_parse_token_string_t cmd_queue_region_set =
9306 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9307                 set, "set");
9308 cmdline_parse_token_string_t cmd_queue_region_port =
9309         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9310 cmdline_parse_token_num_t cmd_queue_region_port_id =
9311         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9312                                 port_id, UINT16);
9313 cmdline_parse_token_string_t cmd_queue_region_cmd =
9314         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9315                                  cmd, "queue-region");
9316 cmdline_parse_token_string_t cmd_queue_region_id =
9317         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9318                                 region, "region_id");
9319 cmdline_parse_token_num_t cmd_queue_region_index =
9320         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9321                                 region_id, UINT8);
9322 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9323         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9324                                 queue_start_index, "queue_start_index");
9325 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9326         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9327                                 queue_id, UINT8);
9328 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9329         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9330                                 queue_num, "queue_num");
9331 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9332         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9333                                 queue_num_value, UINT8);
9334
9335 cmdline_parse_inst_t cmd_queue_region = {
9336         .f = cmd_queue_region_parsed,
9337         .data = NULL,
9338         .help_str = "set port <port_id> queue-region region_id <value> "
9339                 "queue_start_index <value> queue_num <value>: Set a queue region",
9340         .tokens = {
9341                 (void *)&cmd_queue_region_set,
9342                 (void *)&cmd_queue_region_port,
9343                 (void *)&cmd_queue_region_port_id,
9344                 (void *)&cmd_queue_region_cmd,
9345                 (void *)&cmd_queue_region_id,
9346                 (void *)&cmd_queue_region_index,
9347                 (void *)&cmd_queue_region_queue_start_index,
9348                 (void *)&cmd_queue_region_queue_id,
9349                 (void *)&cmd_queue_region_queue_num,
9350                 (void *)&cmd_queue_region_queue_num_value,
9351                 NULL,
9352         },
9353 };
9354
9355 /* *** queue region and flowtype set *** */
9356 struct cmd_region_flowtype_result {
9357         cmdline_fixed_string_t set;
9358         cmdline_fixed_string_t port;
9359         portid_t port_id;
9360         cmdline_fixed_string_t cmd;
9361         cmdline_fixed_string_t region;
9362         uint8_t  region_id;
9363         cmdline_fixed_string_t flowtype;
9364         uint8_t  flowtype_id;
9365 };
9366
9367 static void
9368 cmd_region_flowtype_parsed(void *parsed_result,
9369                         __attribute__((unused)) struct cmdline *cl,
9370                         __attribute__((unused)) void *data)
9371 {
9372         struct cmd_region_flowtype_result *res = parsed_result;
9373         int ret = -ENOTSUP;
9374 #ifdef RTE_LIBRTE_I40E_PMD
9375         struct rte_pmd_i40e_queue_region_conf region_conf;
9376         enum rte_pmd_i40e_queue_region_op op_type;
9377 #endif
9378
9379         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9380                 return;
9381
9382 #ifdef RTE_LIBRTE_I40E_PMD
9383         memset(&region_conf, 0, sizeof(region_conf));
9384
9385         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9386         region_conf.region_id = res->region_id;
9387         region_conf.hw_flowtype = res->flowtype_id;
9388
9389         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9390                         op_type, &region_conf);
9391 #endif
9392
9393         switch (ret) {
9394         case 0:
9395                 break;
9396         case -ENOTSUP:
9397                 printf("function not implemented or supported\n");
9398                 break;
9399         default:
9400                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9401         }
9402 }
9403
9404 cmdline_parse_token_string_t cmd_region_flowtype_set =
9405 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9406                                 set, "set");
9407 cmdline_parse_token_string_t cmd_region_flowtype_port =
9408         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9409                                 port, "port");
9410 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9411         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9412                                 port_id, UINT16);
9413 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9414         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9415                                 cmd, "queue-region");
9416 cmdline_parse_token_string_t cmd_region_flowtype_index =
9417         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9418                                 region, "region_id");
9419 cmdline_parse_token_num_t cmd_region_flowtype_id =
9420         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9421                                 region_id, UINT8);
9422 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9423         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9424                                 flowtype, "flowtype");
9425 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9426         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9427                                 flowtype_id, UINT8);
9428 cmdline_parse_inst_t cmd_region_flowtype = {
9429         .f = cmd_region_flowtype_parsed,
9430         .data = NULL,
9431         .help_str = "set port <port_id> queue-region region_id <value> "
9432                 "flowtype <value>: Set a flowtype region index",
9433         .tokens = {
9434                 (void *)&cmd_region_flowtype_set,
9435                 (void *)&cmd_region_flowtype_port,
9436                 (void *)&cmd_region_flowtype_port_index,
9437                 (void *)&cmd_region_flowtype_cmd,
9438                 (void *)&cmd_region_flowtype_index,
9439                 (void *)&cmd_region_flowtype_id,
9440                 (void *)&cmd_region_flowtype_flow_index,
9441                 (void *)&cmd_region_flowtype_flow_id,
9442                 NULL,
9443         },
9444 };
9445
9446 /* *** User Priority (UP) to queue region (region_id) set *** */
9447 struct cmd_user_priority_region_result {
9448         cmdline_fixed_string_t set;
9449         cmdline_fixed_string_t port;
9450         portid_t port_id;
9451         cmdline_fixed_string_t cmd;
9452         cmdline_fixed_string_t user_priority;
9453         uint8_t  user_priority_id;
9454         cmdline_fixed_string_t region;
9455         uint8_t  region_id;
9456 };
9457
9458 static void
9459 cmd_user_priority_region_parsed(void *parsed_result,
9460                         __attribute__((unused)) struct cmdline *cl,
9461                         __attribute__((unused)) void *data)
9462 {
9463         struct cmd_user_priority_region_result *res = parsed_result;
9464         int ret = -ENOTSUP;
9465 #ifdef RTE_LIBRTE_I40E_PMD
9466         struct rte_pmd_i40e_queue_region_conf region_conf;
9467         enum rte_pmd_i40e_queue_region_op op_type;
9468 #endif
9469
9470         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9471                 return;
9472
9473 #ifdef RTE_LIBRTE_I40E_PMD
9474         memset(&region_conf, 0, sizeof(region_conf));
9475         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9476         region_conf.user_priority = res->user_priority_id;
9477         region_conf.region_id = res->region_id;
9478
9479         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9480                                 op_type, &region_conf);
9481 #endif
9482
9483         switch (ret) {
9484         case 0:
9485                 break;
9486         case -ENOTSUP:
9487                 printf("function not implemented or supported\n");
9488                 break;
9489         default:
9490                 printf("user_priority region config error: (%s)\n",
9491                                 strerror(-ret));
9492         }
9493 }
9494
9495 cmdline_parse_token_string_t cmd_user_priority_region_set =
9496         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9497                                 set, "set");
9498 cmdline_parse_token_string_t cmd_user_priority_region_port =
9499         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9500                                 port, "port");
9501 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9502         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9503                                 port_id, UINT16);
9504 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9505         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9506                                 cmd, "queue-region");
9507 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9508         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9509                                 user_priority, "UP");
9510 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9511         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9512                                 user_priority_id, UINT8);
9513 cmdline_parse_token_string_t cmd_user_priority_region_region =
9514         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9515                                 region, "region_id");
9516 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9517         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9518                                 region_id, UINT8);
9519
9520 cmdline_parse_inst_t cmd_user_priority_region = {
9521         .f = cmd_user_priority_region_parsed,
9522         .data = NULL,
9523         .help_str = "set port <port_id> queue-region UP <value> "
9524                 "region_id <value>: Set the mapping of User Priority (UP) "
9525                 "to queue region (region_id) ",
9526         .tokens = {
9527                 (void *)&cmd_user_priority_region_set,
9528                 (void *)&cmd_user_priority_region_port,
9529                 (void *)&cmd_user_priority_region_port_index,
9530                 (void *)&cmd_user_priority_region_cmd,
9531                 (void *)&cmd_user_priority_region_UP,
9532                 (void *)&cmd_user_priority_region_UP_id,
9533                 (void *)&cmd_user_priority_region_region,
9534                 (void *)&cmd_user_priority_region_region_id,
9535                 NULL,
9536         },
9537 };
9538
9539 /* *** flush all queue region related configuration *** */
9540 struct cmd_flush_queue_region_result {
9541         cmdline_fixed_string_t set;
9542         cmdline_fixed_string_t port;
9543         portid_t port_id;
9544         cmdline_fixed_string_t cmd;
9545         cmdline_fixed_string_t flush;
9546         cmdline_fixed_string_t what;
9547 };
9548
9549 static void
9550 cmd_flush_queue_region_parsed(void *parsed_result,
9551                         __attribute__((unused)) struct cmdline *cl,
9552                         __attribute__((unused)) void *data)
9553 {
9554         struct cmd_flush_queue_region_result *res = parsed_result;
9555         int ret = -ENOTSUP;
9556 #ifdef RTE_LIBRTE_I40E_PMD
9557         struct rte_pmd_i40e_queue_region_conf region_conf;
9558         enum rte_pmd_i40e_queue_region_op op_type;
9559 #endif
9560
9561         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9562                 return;
9563
9564 #ifdef RTE_LIBRTE_I40E_PMD
9565         memset(&region_conf, 0, sizeof(region_conf));
9566
9567         if (strcmp(res->what, "on") == 0)
9568                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9569         else
9570                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9571
9572         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9573                                 op_type, &region_conf);
9574 #endif
9575
9576         switch (ret) {
9577         case 0:
9578                 break;
9579         case -ENOTSUP:
9580                 printf("function not implemented or supported\n");
9581                 break;
9582         default:
9583                 printf("queue region config flush error: (%s)\n",
9584                                 strerror(-ret));
9585         }
9586 }
9587
9588 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9589         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9590                                 set, "set");
9591 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9592         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9593                                 port, "port");
9594 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9595         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9596                                 port_id, UINT16);
9597 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9598         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9599                                 cmd, "queue-region");
9600 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9601         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9602                                 flush, "flush");
9603 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9604         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9605                                 what, "on#off");
9606
9607 cmdline_parse_inst_t cmd_flush_queue_region = {
9608         .f = cmd_flush_queue_region_parsed,
9609         .data = NULL,
9610         .help_str = "set port <port_id> queue-region flush on|off"
9611                 ": flush all queue region related configuration",
9612         .tokens = {
9613                 (void *)&cmd_flush_queue_region_set,
9614                 (void *)&cmd_flush_queue_region_port,
9615                 (void *)&cmd_flush_queue_region_port_index,
9616                 (void *)&cmd_flush_queue_region_cmd,
9617                 (void *)&cmd_flush_queue_region_flush,
9618                 (void *)&cmd_flush_queue_region_what,
9619                 NULL,
9620         },
9621 };
9622
9623 /* *** get all queue region related configuration info *** */
9624 struct cmd_show_queue_region_info {
9625         cmdline_fixed_string_t show;
9626         cmdline_fixed_string_t port;
9627         portid_t port_id;
9628         cmdline_fixed_string_t cmd;
9629 };
9630
9631 static void
9632 cmd_show_queue_region_info_parsed(void *parsed_result,
9633                         __attribute__((unused)) struct cmdline *cl,
9634                         __attribute__((unused)) void *data)
9635 {
9636         struct cmd_show_queue_region_info *res = parsed_result;
9637         int ret = -ENOTSUP;
9638 #ifdef RTE_LIBRTE_I40E_PMD
9639         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9640         enum rte_pmd_i40e_queue_region_op op_type;
9641 #endif
9642
9643         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9644                 return;
9645
9646 #ifdef RTE_LIBRTE_I40E_PMD
9647         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9648
9649         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9650
9651         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9652                                         op_type, &rte_pmd_regions);
9653
9654         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9655 #endif
9656
9657         switch (ret) {
9658         case 0:
9659                 break;
9660         case -ENOTSUP:
9661                 printf("function not implemented or supported\n");
9662                 break;
9663         default:
9664                 printf("queue region config info show error: (%s)\n",
9665                                 strerror(-ret));
9666         }
9667 }
9668
9669 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9670 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9671                                 show, "show");
9672 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9673         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9674                                 port, "port");
9675 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9676         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9677                                 port_id, UINT16);
9678 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9679         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9680                                 cmd, "queue-region");
9681
9682 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9683         .f = cmd_show_queue_region_info_parsed,
9684         .data = NULL,
9685         .help_str = "show port <port_id> queue-region"
9686                 ": show all queue region related configuration info",
9687         .tokens = {
9688                 (void *)&cmd_show_queue_region_info_get,
9689                 (void *)&cmd_show_queue_region_info_port,
9690                 (void *)&cmd_show_queue_region_info_port_index,
9691                 (void *)&cmd_show_queue_region_info_cmd,
9692                 NULL,
9693         },
9694 };
9695
9696 /* *** ADD/REMOVE A 2tuple FILTER *** */
9697 struct cmd_2tuple_filter_result {
9698         cmdline_fixed_string_t filter;
9699         portid_t port_id;
9700         cmdline_fixed_string_t ops;
9701         cmdline_fixed_string_t dst_port;
9702         uint16_t dst_port_value;
9703         cmdline_fixed_string_t protocol;
9704         uint8_t protocol_value;
9705         cmdline_fixed_string_t mask;
9706         uint8_t  mask_value;
9707         cmdline_fixed_string_t tcp_flags;
9708         uint8_t tcp_flags_value;
9709         cmdline_fixed_string_t priority;
9710         uint8_t  priority_value;
9711         cmdline_fixed_string_t queue;
9712         uint16_t  queue_id;
9713 };
9714
9715 static void
9716 cmd_2tuple_filter_parsed(void *parsed_result,
9717                         __attribute__((unused)) struct cmdline *cl,
9718                         __attribute__((unused)) void *data)
9719 {
9720         struct rte_eth_ntuple_filter filter;
9721         struct cmd_2tuple_filter_result *res = parsed_result;
9722         int ret = 0;
9723
9724         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9725         if (ret < 0) {
9726                 printf("ntuple filter is not supported on port %u.\n",
9727                         res->port_id);
9728                 return;
9729         }
9730
9731         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9732
9733         filter.flags = RTE_2TUPLE_FLAGS;
9734         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9735         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9736         filter.proto = res->protocol_value;
9737         filter.priority = res->priority_value;
9738         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9739                 printf("nonzero tcp_flags is only meaningful"
9740                         " when protocol is TCP.\n");
9741                 return;
9742         }
9743         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9744                 printf("invalid TCP flags.\n");
9745                 return;
9746         }
9747
9748         if (res->tcp_flags_value != 0) {
9749                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9750                 filter.tcp_flags = res->tcp_flags_value;
9751         }
9752
9753         /* need convert to big endian. */
9754         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9755         filter.queue = res->queue_id;
9756
9757         if (!strcmp(res->ops, "add"))
9758                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9759                                 RTE_ETH_FILTER_NTUPLE,
9760                                 RTE_ETH_FILTER_ADD,
9761                                 &filter);
9762         else
9763                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9764                                 RTE_ETH_FILTER_NTUPLE,
9765                                 RTE_ETH_FILTER_DELETE,
9766                                 &filter);
9767         if (ret < 0)
9768                 printf("2tuple filter programming error: (%s)\n",
9769                         strerror(-ret));
9770
9771 }
9772
9773 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9774         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9775                                  filter, "2tuple_filter");
9776 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9777         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9778                                 port_id, UINT16);
9779 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9780         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9781                                  ops, "add#del");
9782 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9783         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9784                                 dst_port, "dst_port");
9785 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9786         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9787                                 dst_port_value, UINT16);
9788 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9789         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9790                                 protocol, "protocol");
9791 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9792         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9793                                 protocol_value, UINT8);
9794 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9795         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9796                                 mask, "mask");
9797 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9798         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9799                                 mask_value, INT8);
9800 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9801         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9802                                 tcp_flags, "tcp_flags");
9803 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9804         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9805                                 tcp_flags_value, UINT8);
9806 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9807         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9808                                 priority, "priority");
9809 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9810         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9811                                 priority_value, UINT8);
9812 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9813         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9814                                 queue, "queue");
9815 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9816         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9817                                 queue_id, UINT16);
9818
9819 cmdline_parse_inst_t cmd_2tuple_filter = {
9820         .f = cmd_2tuple_filter_parsed,
9821         .data = NULL,
9822         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9823                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9824                 "<queue_id>: Add a 2tuple filter",
9825         .tokens = {
9826                 (void *)&cmd_2tuple_filter_filter,
9827                 (void *)&cmd_2tuple_filter_port_id,
9828                 (void *)&cmd_2tuple_filter_ops,
9829                 (void *)&cmd_2tuple_filter_dst_port,
9830                 (void *)&cmd_2tuple_filter_dst_port_value,
9831                 (void *)&cmd_2tuple_filter_protocol,
9832                 (void *)&cmd_2tuple_filter_protocol_value,
9833                 (void *)&cmd_2tuple_filter_mask,
9834                 (void *)&cmd_2tuple_filter_mask_value,
9835                 (void *)&cmd_2tuple_filter_tcp_flags,
9836                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9837                 (void *)&cmd_2tuple_filter_priority,
9838                 (void *)&cmd_2tuple_filter_priority_value,
9839                 (void *)&cmd_2tuple_filter_queue,
9840                 (void *)&cmd_2tuple_filter_queue_id,
9841                 NULL,
9842         },
9843 };
9844
9845 /* *** ADD/REMOVE A 5tuple FILTER *** */
9846 struct cmd_5tuple_filter_result {
9847         cmdline_fixed_string_t filter;
9848         portid_t port_id;
9849         cmdline_fixed_string_t ops;
9850         cmdline_fixed_string_t dst_ip;
9851         cmdline_ipaddr_t dst_ip_value;
9852         cmdline_fixed_string_t src_ip;
9853         cmdline_ipaddr_t src_ip_value;
9854         cmdline_fixed_string_t dst_port;
9855         uint16_t dst_port_value;
9856         cmdline_fixed_string_t src_port;
9857         uint16_t src_port_value;
9858         cmdline_fixed_string_t protocol;
9859         uint8_t protocol_value;
9860         cmdline_fixed_string_t mask;
9861         uint8_t  mask_value;
9862         cmdline_fixed_string_t tcp_flags;
9863         uint8_t tcp_flags_value;
9864         cmdline_fixed_string_t priority;
9865         uint8_t  priority_value;
9866         cmdline_fixed_string_t queue;
9867         uint16_t  queue_id;
9868 };
9869
9870 static void
9871 cmd_5tuple_filter_parsed(void *parsed_result,
9872                         __attribute__((unused)) struct cmdline *cl,
9873                         __attribute__((unused)) void *data)
9874 {
9875         struct rte_eth_ntuple_filter filter;
9876         struct cmd_5tuple_filter_result *res = parsed_result;
9877         int ret = 0;
9878
9879         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9880         if (ret < 0) {
9881                 printf("ntuple filter is not supported on port %u.\n",
9882                         res->port_id);
9883                 return;
9884         }
9885
9886         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9887
9888         filter.flags = RTE_5TUPLE_FLAGS;
9889         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9890         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9891         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9892         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9893         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9894         filter.proto = res->protocol_value;
9895         filter.priority = res->priority_value;
9896         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9897                 printf("nonzero tcp_flags is only meaningful"
9898                         " when protocol is TCP.\n");
9899                 return;
9900         }
9901         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9902                 printf("invalid TCP flags.\n");
9903                 return;
9904         }
9905
9906         if (res->tcp_flags_value != 0) {
9907                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9908                 filter.tcp_flags = res->tcp_flags_value;
9909         }
9910
9911         if (res->dst_ip_value.family == AF_INET)
9912                 /* no need to convert, already big endian. */
9913                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9914         else {
9915                 if (filter.dst_ip_mask == 0) {
9916                         printf("can not support ipv6 involved compare.\n");
9917                         return;
9918                 }
9919                 filter.dst_ip = 0;
9920         }
9921
9922         if (res->src_ip_value.family == AF_INET)
9923                 /* no need to convert, already big endian. */
9924                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9925         else {
9926                 if (filter.src_ip_mask == 0) {
9927                         printf("can not support ipv6 involved compare.\n");
9928                         return;
9929                 }
9930                 filter.src_ip = 0;
9931         }
9932         /* need convert to big endian. */
9933         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9934         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9935         filter.queue = res->queue_id;
9936
9937         if (!strcmp(res->ops, "add"))
9938                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9939                                 RTE_ETH_FILTER_NTUPLE,
9940                                 RTE_ETH_FILTER_ADD,
9941                                 &filter);
9942         else
9943                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9944                                 RTE_ETH_FILTER_NTUPLE,
9945                                 RTE_ETH_FILTER_DELETE,
9946                                 &filter);
9947         if (ret < 0)
9948                 printf("5tuple filter programming error: (%s)\n",
9949                         strerror(-ret));
9950 }
9951
9952 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9953         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9954                                  filter, "5tuple_filter");
9955 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9956         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9957                                 port_id, UINT16);
9958 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9959         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9960                                  ops, "add#del");
9961 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9962         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9963                                 dst_ip, "dst_ip");
9964 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9965         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9966                                 dst_ip_value);
9967 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9968         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9969                                 src_ip, "src_ip");
9970 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9971         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9972                                 src_ip_value);
9973 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9974         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9975                                 dst_port, "dst_port");
9976 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9977         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9978                                 dst_port_value, UINT16);
9979 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9980         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9981                                 src_port, "src_port");
9982 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9983         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9984                                 src_port_value, UINT16);
9985 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9986         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9987                                 protocol, "protocol");
9988 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9989         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9990                                 protocol_value, UINT8);
9991 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9992         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9993                                 mask, "mask");
9994 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9995         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9996                                 mask_value, INT8);
9997 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9998         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9999                                 tcp_flags, "tcp_flags");
10000 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10001         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10002                                 tcp_flags_value, UINT8);
10003 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10004         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10005                                 priority, "priority");
10006 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10007         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10008                                 priority_value, UINT8);
10009 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10010         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10011                                 queue, "queue");
10012 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10013         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10014                                 queue_id, UINT16);
10015
10016 cmdline_parse_inst_t cmd_5tuple_filter = {
10017         .f = cmd_5tuple_filter_parsed,
10018         .data = NULL,
10019         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10020                 "src_ip <value> dst_port <value> src_port <value> "
10021                 "protocol <value>  mask <value> tcp_flags <value> "
10022                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10023         .tokens = {
10024                 (void *)&cmd_5tuple_filter_filter,
10025                 (void *)&cmd_5tuple_filter_port_id,
10026                 (void *)&cmd_5tuple_filter_ops,
10027                 (void *)&cmd_5tuple_filter_dst_ip,
10028                 (void *)&cmd_5tuple_filter_dst_ip_value,
10029                 (void *)&cmd_5tuple_filter_src_ip,
10030                 (void *)&cmd_5tuple_filter_src_ip_value,
10031                 (void *)&cmd_5tuple_filter_dst_port,
10032                 (void *)&cmd_5tuple_filter_dst_port_value,
10033                 (void *)&cmd_5tuple_filter_src_port,
10034                 (void *)&cmd_5tuple_filter_src_port_value,
10035                 (void *)&cmd_5tuple_filter_protocol,
10036                 (void *)&cmd_5tuple_filter_protocol_value,
10037                 (void *)&cmd_5tuple_filter_mask,
10038                 (void *)&cmd_5tuple_filter_mask_value,
10039                 (void *)&cmd_5tuple_filter_tcp_flags,
10040                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10041                 (void *)&cmd_5tuple_filter_priority,
10042                 (void *)&cmd_5tuple_filter_priority_value,
10043                 (void *)&cmd_5tuple_filter_queue,
10044                 (void *)&cmd_5tuple_filter_queue_id,
10045                 NULL,
10046         },
10047 };
10048
10049 /* *** ADD/REMOVE A flex FILTER *** */
10050 struct cmd_flex_filter_result {
10051         cmdline_fixed_string_t filter;
10052         cmdline_fixed_string_t ops;
10053         portid_t port_id;
10054         cmdline_fixed_string_t len;
10055         uint8_t len_value;
10056         cmdline_fixed_string_t bytes;
10057         cmdline_fixed_string_t bytes_value;
10058         cmdline_fixed_string_t mask;
10059         cmdline_fixed_string_t mask_value;
10060         cmdline_fixed_string_t priority;
10061         uint8_t priority_value;
10062         cmdline_fixed_string_t queue;
10063         uint16_t queue_id;
10064 };
10065
10066 static int xdigit2val(unsigned char c)
10067 {
10068         int val;
10069         if (isdigit(c))
10070                 val = c - '0';
10071         else if (isupper(c))
10072                 val = c - 'A' + 10;
10073         else
10074                 val = c - 'a' + 10;
10075         return val;
10076 }
10077
10078 static void
10079 cmd_flex_filter_parsed(void *parsed_result,
10080                           __attribute__((unused)) struct cmdline *cl,
10081                           __attribute__((unused)) void *data)
10082 {
10083         int ret = 0;
10084         struct rte_eth_flex_filter filter;
10085         struct cmd_flex_filter_result *res = parsed_result;
10086         char *bytes_ptr, *mask_ptr;
10087         uint16_t len, i, j = 0;
10088         char c;
10089         int val;
10090         uint8_t byte = 0;
10091
10092         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10093                 printf("the len exceed the max length 128\n");
10094                 return;
10095         }
10096         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10097         filter.len = res->len_value;
10098         filter.priority = res->priority_value;
10099         filter.queue = res->queue_id;
10100         bytes_ptr = res->bytes_value;
10101         mask_ptr = res->mask_value;
10102
10103          /* translate bytes string to array. */
10104         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10105                 (bytes_ptr[1] == 'X')))
10106                 bytes_ptr += 2;
10107         len = strnlen(bytes_ptr, res->len_value * 2);
10108         if (len == 0 || (len % 8 != 0)) {
10109                 printf("please check len and bytes input\n");
10110                 return;
10111         }
10112         for (i = 0; i < len; i++) {
10113                 c = bytes_ptr[i];
10114                 if (isxdigit(c) == 0) {
10115                         /* invalid characters. */
10116                         printf("invalid input\n");
10117                         return;
10118                 }
10119                 val = xdigit2val(c);
10120                 if (i % 2) {
10121                         byte |= val;
10122                         filter.bytes[j] = byte;
10123                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10124                         j++;
10125                         byte = 0;
10126                 } else
10127                         byte |= val << 4;
10128         }
10129         printf("\n");
10130          /* translate mask string to uint8_t array. */
10131         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10132                 (mask_ptr[1] == 'X')))
10133                 mask_ptr += 2;
10134         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10135         if (len == 0) {
10136                 printf("invalid input\n");
10137                 return;
10138         }
10139         j = 0;
10140         byte = 0;
10141         for (i = 0; i < len; i++) {
10142                 c = mask_ptr[i];
10143                 if (isxdigit(c) == 0) {
10144                         /* invalid characters. */
10145                         printf("invalid input\n");
10146                         return;
10147                 }
10148                 val = xdigit2val(c);
10149                 if (i % 2) {
10150                         byte |= val;
10151                         filter.mask[j] = byte;
10152                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10153                         j++;
10154                         byte = 0;
10155                 } else
10156                         byte |= val << 4;
10157         }
10158         printf("\n");
10159
10160         if (!strcmp(res->ops, "add"))
10161                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10162                                 RTE_ETH_FILTER_FLEXIBLE,
10163                                 RTE_ETH_FILTER_ADD,
10164                                 &filter);
10165         else
10166                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10167                                 RTE_ETH_FILTER_FLEXIBLE,
10168                                 RTE_ETH_FILTER_DELETE,
10169                                 &filter);
10170
10171         if (ret < 0)
10172                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10173 }
10174
10175 cmdline_parse_token_string_t cmd_flex_filter_filter =
10176         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10177                                 filter, "flex_filter");
10178 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10179         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10180                                 port_id, UINT16);
10181 cmdline_parse_token_string_t cmd_flex_filter_ops =
10182         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10183                                 ops, "add#del");
10184 cmdline_parse_token_string_t cmd_flex_filter_len =
10185         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10186                                 len, "len");
10187 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10188         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10189                                 len_value, UINT8);
10190 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10191         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10192                                 bytes, "bytes");
10193 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10194         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10195                                 bytes_value, NULL);
10196 cmdline_parse_token_string_t cmd_flex_filter_mask =
10197         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10198                                 mask, "mask");
10199 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10200         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10201                                 mask_value, NULL);
10202 cmdline_parse_token_string_t cmd_flex_filter_priority =
10203         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10204                                 priority, "priority");
10205 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10206         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10207                                 priority_value, UINT8);
10208 cmdline_parse_token_string_t cmd_flex_filter_queue =
10209         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10210                                 queue, "queue");
10211 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10212         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10213                                 queue_id, UINT16);
10214 cmdline_parse_inst_t cmd_flex_filter = {
10215         .f = cmd_flex_filter_parsed,
10216         .data = NULL,
10217         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10218                 "<value> mask <value> priority <value> queue <queue_id>: "
10219                 "Add/Del a flex filter",
10220         .tokens = {
10221                 (void *)&cmd_flex_filter_filter,
10222                 (void *)&cmd_flex_filter_port_id,
10223                 (void *)&cmd_flex_filter_ops,
10224                 (void *)&cmd_flex_filter_len,
10225                 (void *)&cmd_flex_filter_len_value,
10226                 (void *)&cmd_flex_filter_bytes,
10227                 (void *)&cmd_flex_filter_bytes_value,
10228                 (void *)&cmd_flex_filter_mask,
10229                 (void *)&cmd_flex_filter_mask_value,
10230                 (void *)&cmd_flex_filter_priority,
10231                 (void *)&cmd_flex_filter_priority_value,
10232                 (void *)&cmd_flex_filter_queue,
10233                 (void *)&cmd_flex_filter_queue_id,
10234                 NULL,
10235         },
10236 };
10237
10238 /* *** Filters Control *** */
10239
10240 /* *** deal with ethertype filter *** */
10241 struct cmd_ethertype_filter_result {
10242         cmdline_fixed_string_t filter;
10243         portid_t port_id;
10244         cmdline_fixed_string_t ops;
10245         cmdline_fixed_string_t mac;
10246         struct ether_addr mac_addr;
10247         cmdline_fixed_string_t ethertype;
10248         uint16_t ethertype_value;
10249         cmdline_fixed_string_t drop;
10250         cmdline_fixed_string_t queue;
10251         uint16_t  queue_id;
10252 };
10253
10254 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10255         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10256                                  filter, "ethertype_filter");
10257 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10258         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10259                               port_id, UINT16);
10260 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10261         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10262                                  ops, "add#del");
10263 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10264         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10265                                  mac, "mac_addr#mac_ignr");
10266 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10267         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10268                                      mac_addr);
10269 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10270         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10271                                  ethertype, "ethertype");
10272 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10273         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10274                               ethertype_value, UINT16);
10275 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10276         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10277                                  drop, "drop#fwd");
10278 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10279         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10280                                  queue, "queue");
10281 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10282         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10283                               queue_id, UINT16);
10284
10285 static void
10286 cmd_ethertype_filter_parsed(void *parsed_result,
10287                           __attribute__((unused)) struct cmdline *cl,
10288                           __attribute__((unused)) void *data)
10289 {
10290         struct cmd_ethertype_filter_result *res = parsed_result;
10291         struct rte_eth_ethertype_filter filter;
10292         int ret = 0;
10293
10294         ret = rte_eth_dev_filter_supported(res->port_id,
10295                         RTE_ETH_FILTER_ETHERTYPE);
10296         if (ret < 0) {
10297                 printf("ethertype filter is not supported on port %u.\n",
10298                         res->port_id);
10299                 return;
10300         }
10301
10302         memset(&filter, 0, sizeof(filter));
10303         if (!strcmp(res->mac, "mac_addr")) {
10304                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10305                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10306                         sizeof(struct ether_addr));
10307         }
10308         if (!strcmp(res->drop, "drop"))
10309                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10310         filter.ether_type = res->ethertype_value;
10311         filter.queue = res->queue_id;
10312
10313         if (!strcmp(res->ops, "add"))
10314                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10315                                 RTE_ETH_FILTER_ETHERTYPE,
10316                                 RTE_ETH_FILTER_ADD,
10317                                 &filter);
10318         else
10319                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10320                                 RTE_ETH_FILTER_ETHERTYPE,
10321                                 RTE_ETH_FILTER_DELETE,
10322                                 &filter);
10323         if (ret < 0)
10324                 printf("ethertype filter programming error: (%s)\n",
10325                         strerror(-ret));
10326 }
10327
10328 cmdline_parse_inst_t cmd_ethertype_filter = {
10329         .f = cmd_ethertype_filter_parsed,
10330         .data = NULL,
10331         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10332                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10333                 "Add or delete an ethertype filter entry",
10334         .tokens = {
10335                 (void *)&cmd_ethertype_filter_filter,
10336                 (void *)&cmd_ethertype_filter_port_id,
10337                 (void *)&cmd_ethertype_filter_ops,
10338                 (void *)&cmd_ethertype_filter_mac,
10339                 (void *)&cmd_ethertype_filter_mac_addr,
10340                 (void *)&cmd_ethertype_filter_ethertype,
10341                 (void *)&cmd_ethertype_filter_ethertype_value,
10342                 (void *)&cmd_ethertype_filter_drop,
10343                 (void *)&cmd_ethertype_filter_queue,
10344                 (void *)&cmd_ethertype_filter_queue_id,
10345                 NULL,
10346         },
10347 };
10348
10349 /* *** deal with flow director filter *** */
10350 struct cmd_flow_director_result {
10351         cmdline_fixed_string_t flow_director_filter;
10352         portid_t port_id;
10353         cmdline_fixed_string_t mode;
10354         cmdline_fixed_string_t mode_value;
10355         cmdline_fixed_string_t ops;
10356         cmdline_fixed_string_t flow;
10357         cmdline_fixed_string_t flow_type;
10358         cmdline_fixed_string_t ether;
10359         uint16_t ether_type;
10360         cmdline_fixed_string_t src;
10361         cmdline_ipaddr_t ip_src;
10362         uint16_t port_src;
10363         cmdline_fixed_string_t dst;
10364         cmdline_ipaddr_t ip_dst;
10365         uint16_t port_dst;
10366         cmdline_fixed_string_t verify_tag;
10367         uint32_t verify_tag_value;
10368         cmdline_fixed_string_t tos;
10369         uint8_t tos_value;
10370         cmdline_fixed_string_t proto;
10371         uint8_t proto_value;
10372         cmdline_fixed_string_t ttl;
10373         uint8_t ttl_value;
10374         cmdline_fixed_string_t vlan;
10375         uint16_t vlan_value;
10376         cmdline_fixed_string_t flexbytes;
10377         cmdline_fixed_string_t flexbytes_value;
10378         cmdline_fixed_string_t pf_vf;
10379         cmdline_fixed_string_t drop;
10380         cmdline_fixed_string_t queue;
10381         uint16_t  queue_id;
10382         cmdline_fixed_string_t fd_id;
10383         uint32_t  fd_id_value;
10384         cmdline_fixed_string_t mac;
10385         struct ether_addr mac_addr;
10386         cmdline_fixed_string_t tunnel;
10387         cmdline_fixed_string_t tunnel_type;
10388         cmdline_fixed_string_t tunnel_id;
10389         uint32_t tunnel_id_value;
10390         cmdline_fixed_string_t packet;
10391         char filepath[];
10392 };
10393
10394 static inline int
10395 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10396 {
10397         char s[256];
10398         const char *p, *p0 = q_arg;
10399         char *end;
10400         unsigned long int_fld;
10401         char *str_fld[max_num];
10402         int i;
10403         unsigned size;
10404         int ret = -1;
10405
10406         p = strchr(p0, '(');
10407         if (p == NULL)
10408                 return -1;
10409         ++p;
10410         p0 = strchr(p, ')');
10411         if (p0 == NULL)
10412                 return -1;
10413
10414         size = p0 - p;
10415         if (size >= sizeof(s))
10416                 return -1;
10417
10418         snprintf(s, sizeof(s), "%.*s", size, p);
10419         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10420         if (ret < 0 || ret > max_num)
10421                 return -1;
10422         for (i = 0; i < ret; i++) {
10423                 errno = 0;
10424                 int_fld = strtoul(str_fld[i], &end, 0);
10425                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10426                         return -1;
10427                 flexbytes[i] = (uint8_t)int_fld;
10428         }
10429         return ret;
10430 }
10431
10432 static uint16_t
10433 str2flowtype(char *string)
10434 {
10435         uint8_t i = 0;
10436         static const struct {
10437                 char str[32];
10438                 uint16_t type;
10439         } flowtype_str[] = {
10440                 {"raw", RTE_ETH_FLOW_RAW},
10441                 {"ipv4", RTE_ETH_FLOW_IPV4},
10442                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10443                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10444                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10445                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10446                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10447                 {"ipv6", RTE_ETH_FLOW_IPV6},
10448                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10449                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10450                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10451                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10452                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10453                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10454         };
10455
10456         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10457                 if (!strcmp(flowtype_str[i].str, string))
10458                         return flowtype_str[i].type;
10459         }
10460
10461         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10462                 return (uint16_t)atoi(string);
10463
10464         return RTE_ETH_FLOW_UNKNOWN;
10465 }
10466
10467 static enum rte_eth_fdir_tunnel_type
10468 str2fdir_tunneltype(char *string)
10469 {
10470         uint8_t i = 0;
10471
10472         static const struct {
10473                 char str[32];
10474                 enum rte_eth_fdir_tunnel_type type;
10475         } tunneltype_str[] = {
10476                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10477                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10478         };
10479
10480         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10481                 if (!strcmp(tunneltype_str[i].str, string))
10482                         return tunneltype_str[i].type;
10483         }
10484         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10485 }
10486
10487 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10488 do { \
10489         if ((ip_addr).family == AF_INET) \
10490                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10491         else { \
10492                 printf("invalid parameter.\n"); \
10493                 return; \
10494         } \
10495 } while (0)
10496
10497 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10498 do { \
10499         if ((ip_addr).family == AF_INET6) \
10500                 rte_memcpy(&(ip), \
10501                                  &((ip_addr).addr.ipv6), \
10502                                  sizeof(struct in6_addr)); \
10503         else { \
10504                 printf("invalid parameter.\n"); \
10505                 return; \
10506         } \
10507 } while (0)
10508
10509 static void
10510 cmd_flow_director_filter_parsed(void *parsed_result,
10511                           __attribute__((unused)) struct cmdline *cl,
10512                           __attribute__((unused)) void *data)
10513 {
10514         struct cmd_flow_director_result *res = parsed_result;
10515         struct rte_eth_fdir_filter entry;
10516         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10517         char *end;
10518         unsigned long vf_id;
10519         int ret = 0;
10520
10521         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10522         if (ret < 0) {
10523                 printf("flow director is not supported on port %u.\n",
10524                         res->port_id);
10525                 return;
10526         }
10527         memset(flexbytes, 0, sizeof(flexbytes));
10528         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10529
10530         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10531                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10532                         printf("Please set mode to MAC-VLAN.\n");
10533                         return;
10534                 }
10535         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10536                 if (strcmp(res->mode_value, "Tunnel")) {
10537                         printf("Please set mode to Tunnel.\n");
10538                         return;
10539                 }
10540         } else {
10541                 if (!strcmp(res->mode_value, "raw")) {
10542 #ifdef RTE_LIBRTE_I40E_PMD
10543                         struct rte_pmd_i40e_flow_type_mapping
10544                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10545                         struct rte_pmd_i40e_pkt_template_conf conf;
10546                         uint16_t flow_type = str2flowtype(res->flow_type);
10547                         uint16_t i, port = res->port_id;
10548                         uint8_t add;
10549
10550                         memset(&conf, 0, sizeof(conf));
10551
10552                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10553                                 printf("Invalid flow type specified.\n");
10554                                 return;
10555                         }
10556                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10557                                                                  mapping);
10558                         if (ret)
10559                                 return;
10560                         if (mapping[flow_type].pctype == 0ULL) {
10561                                 printf("Invalid flow type specified.\n");
10562                                 return;
10563                         }
10564                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10565                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10566                                         conf.input.pctype = i;
10567                                         break;
10568                                 }
10569                         }
10570
10571                         conf.input.packet = open_file(res->filepath,
10572                                                 &conf.input.length);
10573                         if (!conf.input.packet)
10574                                 return;
10575                         if (!strcmp(res->drop, "drop"))
10576                                 conf.action.behavior =
10577                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10578                         else
10579                                 conf.action.behavior =
10580                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10581                         conf.action.report_status =
10582                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10583                         conf.action.rx_queue = res->queue_id;
10584                         conf.soft_id = res->fd_id_value;
10585                         add  = strcmp(res->ops, "del") ? 1 : 0;
10586                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10587                                                                         &conf,
10588                                                                         add);
10589                         if (ret < 0)
10590                                 printf("flow director config error: (%s)\n",
10591                                        strerror(-ret));
10592                         close_file(conf.input.packet);
10593 #endif
10594                         return;
10595                 } else if (strcmp(res->mode_value, "IP")) {
10596                         printf("Please set mode to IP or raw.\n");
10597                         return;
10598                 }
10599                 entry.input.flow_type = str2flowtype(res->flow_type);
10600         }
10601
10602         ret = parse_flexbytes(res->flexbytes_value,
10603                                         flexbytes,
10604                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10605         if (ret < 0) {
10606                 printf("error: Cannot parse flexbytes input.\n");
10607                 return;
10608         }
10609
10610         switch (entry.input.flow_type) {
10611         case RTE_ETH_FLOW_FRAG_IPV4:
10612         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10613                 entry.input.flow.ip4_flow.proto = res->proto_value;
10614                 /* fall-through */
10615         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10616         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10617                 IPV4_ADDR_TO_UINT(res->ip_dst,
10618                         entry.input.flow.ip4_flow.dst_ip);
10619                 IPV4_ADDR_TO_UINT(res->ip_src,
10620                         entry.input.flow.ip4_flow.src_ip);
10621                 entry.input.flow.ip4_flow.tos = res->tos_value;
10622                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10623                 /* need convert to big endian. */
10624                 entry.input.flow.udp4_flow.dst_port =
10625                                 rte_cpu_to_be_16(res->port_dst);
10626                 entry.input.flow.udp4_flow.src_port =
10627                                 rte_cpu_to_be_16(res->port_src);
10628                 break;
10629         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10630                 IPV4_ADDR_TO_UINT(res->ip_dst,
10631                         entry.input.flow.sctp4_flow.ip.dst_ip);
10632                 IPV4_ADDR_TO_UINT(res->ip_src,
10633                         entry.input.flow.sctp4_flow.ip.src_ip);
10634                 entry.input.flow.ip4_flow.tos = res->tos_value;
10635                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10636                 /* need convert to big endian. */
10637                 entry.input.flow.sctp4_flow.dst_port =
10638                                 rte_cpu_to_be_16(res->port_dst);
10639                 entry.input.flow.sctp4_flow.src_port =
10640                                 rte_cpu_to_be_16(res->port_src);
10641                 entry.input.flow.sctp4_flow.verify_tag =
10642                                 rte_cpu_to_be_32(res->verify_tag_value);
10643                 break;
10644         case RTE_ETH_FLOW_FRAG_IPV6:
10645         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10646                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10647                 /* fall-through */
10648         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10649         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10650                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10651                         entry.input.flow.ipv6_flow.dst_ip);
10652                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10653                         entry.input.flow.ipv6_flow.src_ip);
10654                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10655                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10656                 /* need convert to big endian. */
10657                 entry.input.flow.udp6_flow.dst_port =
10658                                 rte_cpu_to_be_16(res->port_dst);
10659                 entry.input.flow.udp6_flow.src_port =
10660                                 rte_cpu_to_be_16(res->port_src);
10661                 break;
10662         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10663                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10664                         entry.input.flow.sctp6_flow.ip.dst_ip);
10665                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10666                         entry.input.flow.sctp6_flow.ip.src_ip);
10667                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10668                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10669                 /* need convert to big endian. */
10670                 entry.input.flow.sctp6_flow.dst_port =
10671                                 rte_cpu_to_be_16(res->port_dst);
10672                 entry.input.flow.sctp6_flow.src_port =
10673                                 rte_cpu_to_be_16(res->port_src);
10674                 entry.input.flow.sctp6_flow.verify_tag =
10675                                 rte_cpu_to_be_32(res->verify_tag_value);
10676                 break;
10677         case RTE_ETH_FLOW_L2_PAYLOAD:
10678                 entry.input.flow.l2_flow.ether_type =
10679                         rte_cpu_to_be_16(res->ether_type);
10680                 break;
10681         default:
10682                 break;
10683         }
10684
10685         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10686                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10687                                  &res->mac_addr,
10688                                  sizeof(struct ether_addr));
10689
10690         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10691                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10692                                  &res->mac_addr,
10693                                  sizeof(struct ether_addr));
10694                 entry.input.flow.tunnel_flow.tunnel_type =
10695                         str2fdir_tunneltype(res->tunnel_type);
10696                 entry.input.flow.tunnel_flow.tunnel_id =
10697                         rte_cpu_to_be_32(res->tunnel_id_value);
10698         }
10699
10700         rte_memcpy(entry.input.flow_ext.flexbytes,
10701                    flexbytes,
10702                    RTE_ETH_FDIR_MAX_FLEXLEN);
10703
10704         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10705
10706         entry.action.flex_off = 0;  /*use 0 by default */
10707         if (!strcmp(res->drop, "drop"))
10708                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10709         else
10710                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10711
10712         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10713             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10714                 if (!strcmp(res->pf_vf, "pf"))
10715                         entry.input.flow_ext.is_vf = 0;
10716                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10717                         struct rte_eth_dev_info dev_info;
10718
10719                         memset(&dev_info, 0, sizeof(dev_info));
10720                         rte_eth_dev_info_get(res->port_id, &dev_info);
10721                         errno = 0;
10722                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10723                         if (errno != 0 || *end != '\0' ||
10724                             vf_id >= dev_info.max_vfs) {
10725                                 printf("invalid parameter %s.\n", res->pf_vf);
10726                                 return;
10727                         }
10728                         entry.input.flow_ext.is_vf = 1;
10729                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10730                 } else {
10731                         printf("invalid parameter %s.\n", res->pf_vf);
10732                         return;
10733                 }
10734         }
10735
10736         /* set to report FD ID by default */
10737         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10738         entry.action.rx_queue = res->queue_id;
10739         entry.soft_id = res->fd_id_value;
10740         if (!strcmp(res->ops, "add"))
10741                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10742                                              RTE_ETH_FILTER_ADD, &entry);
10743         else if (!strcmp(res->ops, "del"))
10744                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10745                                              RTE_ETH_FILTER_DELETE, &entry);
10746         else
10747                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10748                                              RTE_ETH_FILTER_UPDATE, &entry);
10749         if (ret < 0)
10750                 printf("flow director programming error: (%s)\n",
10751                         strerror(-ret));
10752 }
10753
10754 cmdline_parse_token_string_t cmd_flow_director_filter =
10755         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10756                                  flow_director_filter, "flow_director_filter");
10757 cmdline_parse_token_num_t cmd_flow_director_port_id =
10758         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10759                               port_id, UINT16);
10760 cmdline_parse_token_string_t cmd_flow_director_ops =
10761         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10762                                  ops, "add#del#update");
10763 cmdline_parse_token_string_t cmd_flow_director_flow =
10764         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10765                                  flow, "flow");
10766 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10767         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10768                 flow_type, NULL);
10769 cmdline_parse_token_string_t cmd_flow_director_ether =
10770         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10771                                  ether, "ether");
10772 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10773         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10774                               ether_type, UINT16);
10775 cmdline_parse_token_string_t cmd_flow_director_src =
10776         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10777                                  src, "src");
10778 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10779         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10780                                  ip_src);
10781 cmdline_parse_token_num_t cmd_flow_director_port_src =
10782         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10783                               port_src, UINT16);
10784 cmdline_parse_token_string_t cmd_flow_director_dst =
10785         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10786                                  dst, "dst");
10787 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10788         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10789                                  ip_dst);
10790 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10791         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10792                               port_dst, UINT16);
10793 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10794         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10795                                   verify_tag, "verify_tag");
10796 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10797         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10798                               verify_tag_value, UINT32);
10799 cmdline_parse_token_string_t cmd_flow_director_tos =
10800         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10801                                  tos, "tos");
10802 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10803         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10804                               tos_value, UINT8);
10805 cmdline_parse_token_string_t cmd_flow_director_proto =
10806         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10807                                  proto, "proto");
10808 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10809         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10810                               proto_value, UINT8);
10811 cmdline_parse_token_string_t cmd_flow_director_ttl =
10812         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10813                                  ttl, "ttl");
10814 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10815         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10816                               ttl_value, UINT8);
10817 cmdline_parse_token_string_t cmd_flow_director_vlan =
10818         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10819                                  vlan, "vlan");
10820 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10821         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10822                               vlan_value, UINT16);
10823 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10824         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10825                                  flexbytes, "flexbytes");
10826 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10827         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10828                               flexbytes_value, NULL);
10829 cmdline_parse_token_string_t cmd_flow_director_drop =
10830         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10831                                  drop, "drop#fwd");
10832 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10833         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10834                               pf_vf, NULL);
10835 cmdline_parse_token_string_t cmd_flow_director_queue =
10836         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10837                                  queue, "queue");
10838 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10839         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10840                               queue_id, UINT16);
10841 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10842         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10843                                  fd_id, "fd_id");
10844 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10845         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10846                               fd_id_value, UINT32);
10847
10848 cmdline_parse_token_string_t cmd_flow_director_mode =
10849         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10850                                  mode, "mode");
10851 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10852         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10853                                  mode_value, "IP");
10854 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10855         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10856                                  mode_value, "MAC-VLAN");
10857 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10858         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10859                                  mode_value, "Tunnel");
10860 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10861         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10862                                  mode_value, "raw");
10863 cmdline_parse_token_string_t cmd_flow_director_mac =
10864         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10865                                  mac, "mac");
10866 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10867         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10868                                     mac_addr);
10869 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10870         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10871                                  tunnel, "tunnel");
10872 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10873         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10874                                  tunnel_type, "NVGRE#VxLAN");
10875 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10876         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10877                                  tunnel_id, "tunnel-id");
10878 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10879         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10880                               tunnel_id_value, UINT32);
10881 cmdline_parse_token_string_t cmd_flow_director_packet =
10882         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10883                                  packet, "packet");
10884 cmdline_parse_token_string_t cmd_flow_director_filepath =
10885         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10886                                  filepath, NULL);
10887
10888 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10889         .f = cmd_flow_director_filter_parsed,
10890         .data = NULL,
10891         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10892                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10893                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10894                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10895                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10896                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10897                 "fd_id <fd_id_value>: "
10898                 "Add or delete an ip flow director entry on NIC",
10899         .tokens = {
10900                 (void *)&cmd_flow_director_filter,
10901                 (void *)&cmd_flow_director_port_id,
10902                 (void *)&cmd_flow_director_mode,
10903                 (void *)&cmd_flow_director_mode_ip,
10904                 (void *)&cmd_flow_director_ops,
10905                 (void *)&cmd_flow_director_flow,
10906                 (void *)&cmd_flow_director_flow_type,
10907                 (void *)&cmd_flow_director_src,
10908                 (void *)&cmd_flow_director_ip_src,
10909                 (void *)&cmd_flow_director_dst,
10910                 (void *)&cmd_flow_director_ip_dst,
10911                 (void *)&cmd_flow_director_tos,
10912                 (void *)&cmd_flow_director_tos_value,
10913                 (void *)&cmd_flow_director_proto,
10914                 (void *)&cmd_flow_director_proto_value,
10915                 (void *)&cmd_flow_director_ttl,
10916                 (void *)&cmd_flow_director_ttl_value,
10917                 (void *)&cmd_flow_director_vlan,
10918                 (void *)&cmd_flow_director_vlan_value,
10919                 (void *)&cmd_flow_director_flexbytes,
10920                 (void *)&cmd_flow_director_flexbytes_value,
10921                 (void *)&cmd_flow_director_drop,
10922                 (void *)&cmd_flow_director_pf_vf,
10923                 (void *)&cmd_flow_director_queue,
10924                 (void *)&cmd_flow_director_queue_id,
10925                 (void *)&cmd_flow_director_fd_id,
10926                 (void *)&cmd_flow_director_fd_id_value,
10927                 NULL,
10928         },
10929 };
10930
10931 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10932         .f = cmd_flow_director_filter_parsed,
10933         .data = NULL,
10934         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10935                 "director entry on NIC",
10936         .tokens = {
10937                 (void *)&cmd_flow_director_filter,
10938                 (void *)&cmd_flow_director_port_id,
10939                 (void *)&cmd_flow_director_mode,
10940                 (void *)&cmd_flow_director_mode_ip,
10941                 (void *)&cmd_flow_director_ops,
10942                 (void *)&cmd_flow_director_flow,
10943                 (void *)&cmd_flow_director_flow_type,
10944                 (void *)&cmd_flow_director_src,
10945                 (void *)&cmd_flow_director_ip_src,
10946                 (void *)&cmd_flow_director_port_src,
10947                 (void *)&cmd_flow_director_dst,
10948                 (void *)&cmd_flow_director_ip_dst,
10949                 (void *)&cmd_flow_director_port_dst,
10950                 (void *)&cmd_flow_director_tos,
10951                 (void *)&cmd_flow_director_tos_value,
10952                 (void *)&cmd_flow_director_ttl,
10953                 (void *)&cmd_flow_director_ttl_value,
10954                 (void *)&cmd_flow_director_vlan,
10955                 (void *)&cmd_flow_director_vlan_value,
10956                 (void *)&cmd_flow_director_flexbytes,
10957                 (void *)&cmd_flow_director_flexbytes_value,
10958                 (void *)&cmd_flow_director_drop,
10959                 (void *)&cmd_flow_director_pf_vf,
10960                 (void *)&cmd_flow_director_queue,
10961                 (void *)&cmd_flow_director_queue_id,
10962                 (void *)&cmd_flow_director_fd_id,
10963                 (void *)&cmd_flow_director_fd_id_value,
10964                 NULL,
10965         },
10966 };
10967
10968 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10969         .f = cmd_flow_director_filter_parsed,
10970         .data = NULL,
10971         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10972                 "director entry on NIC",
10973         .tokens = {
10974                 (void *)&cmd_flow_director_filter,
10975                 (void *)&cmd_flow_director_port_id,
10976                 (void *)&cmd_flow_director_mode,
10977                 (void *)&cmd_flow_director_mode_ip,
10978                 (void *)&cmd_flow_director_ops,
10979                 (void *)&cmd_flow_director_flow,
10980                 (void *)&cmd_flow_director_flow_type,
10981                 (void *)&cmd_flow_director_src,
10982                 (void *)&cmd_flow_director_ip_src,
10983                 (void *)&cmd_flow_director_port_src,
10984                 (void *)&cmd_flow_director_dst,
10985                 (void *)&cmd_flow_director_ip_dst,
10986                 (void *)&cmd_flow_director_port_dst,
10987                 (void *)&cmd_flow_director_verify_tag,
10988                 (void *)&cmd_flow_director_verify_tag_value,
10989                 (void *)&cmd_flow_director_tos,
10990                 (void *)&cmd_flow_director_tos_value,
10991                 (void *)&cmd_flow_director_ttl,
10992                 (void *)&cmd_flow_director_ttl_value,
10993                 (void *)&cmd_flow_director_vlan,
10994                 (void *)&cmd_flow_director_vlan_value,
10995                 (void *)&cmd_flow_director_flexbytes,
10996                 (void *)&cmd_flow_director_flexbytes_value,
10997                 (void *)&cmd_flow_director_drop,
10998                 (void *)&cmd_flow_director_pf_vf,
10999                 (void *)&cmd_flow_director_queue,
11000                 (void *)&cmd_flow_director_queue_id,
11001                 (void *)&cmd_flow_director_fd_id,
11002                 (void *)&cmd_flow_director_fd_id_value,
11003                 NULL,
11004         },
11005 };
11006
11007 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11008         .f = cmd_flow_director_filter_parsed,
11009         .data = NULL,
11010         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11011                 "director entry on NIC",
11012         .tokens = {
11013                 (void *)&cmd_flow_director_filter,
11014                 (void *)&cmd_flow_director_port_id,
11015                 (void *)&cmd_flow_director_mode,
11016                 (void *)&cmd_flow_director_mode_ip,
11017                 (void *)&cmd_flow_director_ops,
11018                 (void *)&cmd_flow_director_flow,
11019                 (void *)&cmd_flow_director_flow_type,
11020                 (void *)&cmd_flow_director_ether,
11021                 (void *)&cmd_flow_director_ether_type,
11022                 (void *)&cmd_flow_director_flexbytes,
11023                 (void *)&cmd_flow_director_flexbytes_value,
11024                 (void *)&cmd_flow_director_drop,
11025                 (void *)&cmd_flow_director_pf_vf,
11026                 (void *)&cmd_flow_director_queue,
11027                 (void *)&cmd_flow_director_queue_id,
11028                 (void *)&cmd_flow_director_fd_id,
11029                 (void *)&cmd_flow_director_fd_id_value,
11030                 NULL,
11031         },
11032 };
11033
11034 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11035         .f = cmd_flow_director_filter_parsed,
11036         .data = NULL,
11037         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11038                 "director entry on NIC",
11039         .tokens = {
11040                 (void *)&cmd_flow_director_filter,
11041                 (void *)&cmd_flow_director_port_id,
11042                 (void *)&cmd_flow_director_mode,
11043                 (void *)&cmd_flow_director_mode_mac_vlan,
11044                 (void *)&cmd_flow_director_ops,
11045                 (void *)&cmd_flow_director_mac,
11046                 (void *)&cmd_flow_director_mac_addr,
11047                 (void *)&cmd_flow_director_vlan,
11048                 (void *)&cmd_flow_director_vlan_value,
11049                 (void *)&cmd_flow_director_flexbytes,
11050                 (void *)&cmd_flow_director_flexbytes_value,
11051                 (void *)&cmd_flow_director_drop,
11052                 (void *)&cmd_flow_director_queue,
11053                 (void *)&cmd_flow_director_queue_id,
11054                 (void *)&cmd_flow_director_fd_id,
11055                 (void *)&cmd_flow_director_fd_id_value,
11056                 NULL,
11057         },
11058 };
11059
11060 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11061         .f = cmd_flow_director_filter_parsed,
11062         .data = NULL,
11063         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11064                 "director entry on NIC",
11065         .tokens = {
11066                 (void *)&cmd_flow_director_filter,
11067                 (void *)&cmd_flow_director_port_id,
11068                 (void *)&cmd_flow_director_mode,
11069                 (void *)&cmd_flow_director_mode_tunnel,
11070                 (void *)&cmd_flow_director_ops,
11071                 (void *)&cmd_flow_director_mac,
11072                 (void *)&cmd_flow_director_mac_addr,
11073                 (void *)&cmd_flow_director_vlan,
11074                 (void *)&cmd_flow_director_vlan_value,
11075                 (void *)&cmd_flow_director_tunnel,
11076                 (void *)&cmd_flow_director_tunnel_type,
11077                 (void *)&cmd_flow_director_tunnel_id,
11078                 (void *)&cmd_flow_director_tunnel_id_value,
11079                 (void *)&cmd_flow_director_flexbytes,
11080                 (void *)&cmd_flow_director_flexbytes_value,
11081                 (void *)&cmd_flow_director_drop,
11082                 (void *)&cmd_flow_director_queue,
11083                 (void *)&cmd_flow_director_queue_id,
11084                 (void *)&cmd_flow_director_fd_id,
11085                 (void *)&cmd_flow_director_fd_id_value,
11086                 NULL,
11087         },
11088 };
11089
11090 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11091         .f = cmd_flow_director_filter_parsed,
11092         .data = NULL,
11093         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11094                 "director entry on NIC",
11095         .tokens = {
11096                 (void *)&cmd_flow_director_filter,
11097                 (void *)&cmd_flow_director_port_id,
11098                 (void *)&cmd_flow_director_mode,
11099                 (void *)&cmd_flow_director_mode_raw,
11100                 (void *)&cmd_flow_director_ops,
11101                 (void *)&cmd_flow_director_flow,
11102                 (void *)&cmd_flow_director_flow_type,
11103                 (void *)&cmd_flow_director_drop,
11104                 (void *)&cmd_flow_director_queue,
11105                 (void *)&cmd_flow_director_queue_id,
11106                 (void *)&cmd_flow_director_fd_id,
11107                 (void *)&cmd_flow_director_fd_id_value,
11108                 (void *)&cmd_flow_director_packet,
11109                 (void *)&cmd_flow_director_filepath,
11110                 NULL,
11111         },
11112 };
11113
11114 struct cmd_flush_flow_director_result {
11115         cmdline_fixed_string_t flush_flow_director;
11116         portid_t port_id;
11117 };
11118
11119 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11120         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11121                                  flush_flow_director, "flush_flow_director");
11122 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11123         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11124                               port_id, UINT16);
11125
11126 static void
11127 cmd_flush_flow_director_parsed(void *parsed_result,
11128                           __attribute__((unused)) struct cmdline *cl,
11129                           __attribute__((unused)) void *data)
11130 {
11131         struct cmd_flow_director_result *res = parsed_result;
11132         int ret = 0;
11133
11134         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11135         if (ret < 0) {
11136                 printf("flow director is not supported on port %u.\n",
11137                         res->port_id);
11138                 return;
11139         }
11140
11141         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11142                         RTE_ETH_FILTER_FLUSH, NULL);
11143         if (ret < 0)
11144                 printf("flow director table flushing error: (%s)\n",
11145                         strerror(-ret));
11146 }
11147
11148 cmdline_parse_inst_t cmd_flush_flow_director = {
11149         .f = cmd_flush_flow_director_parsed,
11150         .data = NULL,
11151         .help_str = "flush_flow_director <port_id>: "
11152                 "Flush all flow director entries of a device on NIC",
11153         .tokens = {
11154                 (void *)&cmd_flush_flow_director_flush,
11155                 (void *)&cmd_flush_flow_director_port_id,
11156                 NULL,
11157         },
11158 };
11159
11160 /* *** deal with flow director mask *** */
11161 struct cmd_flow_director_mask_result {
11162         cmdline_fixed_string_t flow_director_mask;
11163         portid_t port_id;
11164         cmdline_fixed_string_t mode;
11165         cmdline_fixed_string_t mode_value;
11166         cmdline_fixed_string_t vlan;
11167         uint16_t vlan_mask;
11168         cmdline_fixed_string_t src_mask;
11169         cmdline_ipaddr_t ipv4_src;
11170         cmdline_ipaddr_t ipv6_src;
11171         uint16_t port_src;
11172         cmdline_fixed_string_t dst_mask;
11173         cmdline_ipaddr_t ipv4_dst;
11174         cmdline_ipaddr_t ipv6_dst;
11175         uint16_t port_dst;
11176         cmdline_fixed_string_t mac;
11177         uint8_t mac_addr_byte_mask;
11178         cmdline_fixed_string_t tunnel_id;
11179         uint32_t tunnel_id_mask;
11180         cmdline_fixed_string_t tunnel_type;
11181         uint8_t tunnel_type_mask;
11182 };
11183
11184 static void
11185 cmd_flow_director_mask_parsed(void *parsed_result,
11186                           __attribute__((unused)) struct cmdline *cl,
11187                           __attribute__((unused)) void *data)
11188 {
11189         struct cmd_flow_director_mask_result *res = parsed_result;
11190         struct rte_eth_fdir_masks *mask;
11191         struct rte_port *port;
11192
11193         port = &ports[res->port_id];
11194         /** Check if the port is not started **/
11195         if (port->port_status != RTE_PORT_STOPPED) {
11196                 printf("Please stop port %d first\n", res->port_id);
11197                 return;
11198         }
11199
11200         mask = &port->dev_conf.fdir_conf.mask;
11201
11202         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11203                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11204                         printf("Please set mode to MAC-VLAN.\n");
11205                         return;
11206                 }
11207
11208                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11209         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11210                 if (strcmp(res->mode_value, "Tunnel")) {
11211                         printf("Please set mode to Tunnel.\n");
11212                         return;
11213                 }
11214
11215                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11216                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11217                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11218                 mask->tunnel_type_mask = res->tunnel_type_mask;
11219         } else {
11220                 if (strcmp(res->mode_value, "IP")) {
11221                         printf("Please set mode to IP.\n");
11222                         return;
11223                 }
11224
11225                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11226                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11227                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11228                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11229                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11230                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11231                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11232         }
11233
11234         cmd_reconfig_device_queue(res->port_id, 1, 1);
11235 }
11236
11237 cmdline_parse_token_string_t cmd_flow_director_mask =
11238         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11239                                  flow_director_mask, "flow_director_mask");
11240 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11241         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11242                               port_id, UINT16);
11243 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11245                                  vlan, "vlan");
11246 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11247         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11248                               vlan_mask, UINT16);
11249 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11250         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11251                                  src_mask, "src_mask");
11252 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11253         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11254                                  ipv4_src);
11255 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11256         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11257                                  ipv6_src);
11258 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11259         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11260                               port_src, UINT16);
11261 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11263                                  dst_mask, "dst_mask");
11264 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11265         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11266                                  ipv4_dst);
11267 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11268         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11269                                  ipv6_dst);
11270 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11271         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11272                               port_dst, UINT16);
11273
11274 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11276                                  mode, "mode");
11277 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11279                                  mode_value, "IP");
11280 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11281         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11282                                  mode_value, "MAC-VLAN");
11283 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11285                                  mode_value, "Tunnel");
11286 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11288                                  mac, "mac");
11289 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11290         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11291                               mac_addr_byte_mask, UINT8);
11292 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11293         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11294                                  tunnel_type, "tunnel-type");
11295 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11296         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11297                               tunnel_type_mask, UINT8);
11298 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11299         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11300                                  tunnel_id, "tunnel-id");
11301 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11302         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11303                               tunnel_id_mask, UINT32);
11304
11305 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11306         .f = cmd_flow_director_mask_parsed,
11307         .data = NULL,
11308         .help_str = "flow_director_mask ... : "
11309                 "Set IP mode flow director's mask on NIC",
11310         .tokens = {
11311                 (void *)&cmd_flow_director_mask,
11312                 (void *)&cmd_flow_director_mask_port_id,
11313                 (void *)&cmd_flow_director_mask_mode,
11314                 (void *)&cmd_flow_director_mask_mode_ip,
11315                 (void *)&cmd_flow_director_mask_vlan,
11316                 (void *)&cmd_flow_director_mask_vlan_value,
11317                 (void *)&cmd_flow_director_mask_src,
11318                 (void *)&cmd_flow_director_mask_ipv4_src,
11319                 (void *)&cmd_flow_director_mask_ipv6_src,
11320                 (void *)&cmd_flow_director_mask_port_src,
11321                 (void *)&cmd_flow_director_mask_dst,
11322                 (void *)&cmd_flow_director_mask_ipv4_dst,
11323                 (void *)&cmd_flow_director_mask_ipv6_dst,
11324                 (void *)&cmd_flow_director_mask_port_dst,
11325                 NULL,
11326         },
11327 };
11328
11329 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11330         .f = cmd_flow_director_mask_parsed,
11331         .data = NULL,
11332         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11333                 "flow director's mask on NIC",
11334         .tokens = {
11335                 (void *)&cmd_flow_director_mask,
11336                 (void *)&cmd_flow_director_mask_port_id,
11337                 (void *)&cmd_flow_director_mask_mode,
11338                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11339                 (void *)&cmd_flow_director_mask_vlan,
11340                 (void *)&cmd_flow_director_mask_vlan_value,
11341                 NULL,
11342         },
11343 };
11344
11345 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11346         .f = cmd_flow_director_mask_parsed,
11347         .data = NULL,
11348         .help_str = "flow_director_mask ... : Set tunnel mode "
11349                 "flow director's mask on NIC",
11350         .tokens = {
11351                 (void *)&cmd_flow_director_mask,
11352                 (void *)&cmd_flow_director_mask_port_id,
11353                 (void *)&cmd_flow_director_mask_mode,
11354                 (void *)&cmd_flow_director_mask_mode_tunnel,
11355                 (void *)&cmd_flow_director_mask_vlan,
11356                 (void *)&cmd_flow_director_mask_vlan_value,
11357                 (void *)&cmd_flow_director_mask_mac,
11358                 (void *)&cmd_flow_director_mask_mac_value,
11359                 (void *)&cmd_flow_director_mask_tunnel_type,
11360                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11361                 (void *)&cmd_flow_director_mask_tunnel_id,
11362                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11363                 NULL,
11364         },
11365 };
11366
11367 /* *** deal with flow director mask on flexible payload *** */
11368 struct cmd_flow_director_flex_mask_result {
11369         cmdline_fixed_string_t flow_director_flexmask;
11370         portid_t port_id;
11371         cmdline_fixed_string_t flow;
11372         cmdline_fixed_string_t flow_type;
11373         cmdline_fixed_string_t mask;
11374 };
11375
11376 static void
11377 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11378                           __attribute__((unused)) struct cmdline *cl,
11379                           __attribute__((unused)) void *data)
11380 {
11381         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11382         struct rte_eth_fdir_info fdir_info;
11383         struct rte_eth_fdir_flex_mask flex_mask;
11384         struct rte_port *port;
11385         uint64_t flow_type_mask;
11386         uint16_t i;
11387         int ret;
11388
11389         port = &ports[res->port_id];
11390         /** Check if the port is not started **/
11391         if (port->port_status != RTE_PORT_STOPPED) {
11392                 printf("Please stop port %d first\n", res->port_id);
11393                 return;
11394         }
11395
11396         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11397         ret = parse_flexbytes(res->mask,
11398                         flex_mask.mask,
11399                         RTE_ETH_FDIR_MAX_FLEXLEN);
11400         if (ret < 0) {
11401                 printf("error: Cannot parse mask input.\n");
11402                 return;
11403         }
11404
11405         memset(&fdir_info, 0, sizeof(fdir_info));
11406         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11407                                 RTE_ETH_FILTER_INFO, &fdir_info);
11408         if (ret < 0) {
11409                 printf("Cannot get FDir filter info\n");
11410                 return;
11411         }
11412
11413         if (!strcmp(res->flow_type, "none")) {
11414                 /* means don't specify the flow type */
11415                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11416                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11417                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11418                                0, sizeof(struct rte_eth_fdir_flex_mask));
11419                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11420                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11421                                  &flex_mask,
11422                                  sizeof(struct rte_eth_fdir_flex_mask));
11423                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11424                 return;
11425         }
11426         flow_type_mask = fdir_info.flow_types_mask[0];
11427         if (!strcmp(res->flow_type, "all")) {
11428                 if (!flow_type_mask) {
11429                         printf("No flow type supported\n");
11430                         return;
11431                 }
11432                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11433                         if (flow_type_mask & (1ULL << i)) {
11434                                 flex_mask.flow_type = i;
11435                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11436                         }
11437                 }
11438                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11439                 return;
11440         }
11441         flex_mask.flow_type = str2flowtype(res->flow_type);
11442         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11443                 printf("Flow type %s not supported on port %d\n",
11444                                 res->flow_type, res->port_id);
11445                 return;
11446         }
11447         fdir_set_flex_mask(res->port_id, &flex_mask);
11448         cmd_reconfig_device_queue(res->port_id, 1, 1);
11449 }
11450
11451 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11452         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11453                                  flow_director_flexmask,
11454                                  "flow_director_flex_mask");
11455 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11456         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11457                               port_id, UINT16);
11458 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11459         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11460                                  flow, "flow");
11461 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11463                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11464                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11465 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11466         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11467                                  mask, NULL);
11468
11469 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11470         .f = cmd_flow_director_flex_mask_parsed,
11471         .data = NULL,
11472         .help_str = "flow_director_flex_mask ... : "
11473                 "Set flow director's flex mask on NIC",
11474         .tokens = {
11475                 (void *)&cmd_flow_director_flexmask,
11476                 (void *)&cmd_flow_director_flexmask_port_id,
11477                 (void *)&cmd_flow_director_flexmask_flow,
11478                 (void *)&cmd_flow_director_flexmask_flow_type,
11479                 (void *)&cmd_flow_director_flexmask_mask,
11480                 NULL,
11481         },
11482 };
11483
11484 /* *** deal with flow director flexible payload configuration *** */
11485 struct cmd_flow_director_flexpayload_result {
11486         cmdline_fixed_string_t flow_director_flexpayload;
11487         portid_t port_id;
11488         cmdline_fixed_string_t payload_layer;
11489         cmdline_fixed_string_t payload_cfg;
11490 };
11491
11492 static inline int
11493 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11494 {
11495         char s[256];
11496         const char *p, *p0 = q_arg;
11497         char *end;
11498         unsigned long int_fld;
11499         char *str_fld[max_num];
11500         int i;
11501         unsigned size;
11502         int ret = -1;
11503
11504         p = strchr(p0, '(');
11505         if (p == NULL)
11506                 return -1;
11507         ++p;
11508         p0 = strchr(p, ')');
11509         if (p0 == NULL)
11510                 return -1;
11511
11512         size = p0 - p;
11513         if (size >= sizeof(s))
11514                 return -1;
11515
11516         snprintf(s, sizeof(s), "%.*s", size, p);
11517         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11518         if (ret < 0 || ret > max_num)
11519                 return -1;
11520         for (i = 0; i < ret; i++) {
11521                 errno = 0;
11522                 int_fld = strtoul(str_fld[i], &end, 0);
11523                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11524                         return -1;
11525                 offsets[i] = (uint16_t)int_fld;
11526         }
11527         return ret;
11528 }
11529
11530 static void
11531 cmd_flow_director_flxpld_parsed(void *parsed_result,
11532                           __attribute__((unused)) struct cmdline *cl,
11533                           __attribute__((unused)) void *data)
11534 {
11535         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11536         struct rte_eth_flex_payload_cfg flex_cfg;
11537         struct rte_port *port;
11538         int ret = 0;
11539
11540         port = &ports[res->port_id];
11541         /** Check if the port is not started **/
11542         if (port->port_status != RTE_PORT_STOPPED) {
11543                 printf("Please stop port %d first\n", res->port_id);
11544                 return;
11545         }
11546
11547         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11548
11549         if (!strcmp(res->payload_layer, "raw"))
11550                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11551         else if (!strcmp(res->payload_layer, "l2"))
11552                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11553         else if (!strcmp(res->payload_layer, "l3"))
11554                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11555         else if (!strcmp(res->payload_layer, "l4"))
11556                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11557
11558         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11559                             RTE_ETH_FDIR_MAX_FLEXLEN);
11560         if (ret < 0) {
11561                 printf("error: Cannot parse flex payload input.\n");
11562                 return;
11563         }
11564
11565         fdir_set_flex_payload(res->port_id, &flex_cfg);
11566         cmd_reconfig_device_queue(res->port_id, 1, 1);
11567 }
11568
11569 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11570         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11571                                  flow_director_flexpayload,
11572                                  "flow_director_flex_payload");
11573 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11574         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11575                               port_id, UINT16);
11576 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11577         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11578                                  payload_layer, "raw#l2#l3#l4");
11579 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11580         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11581                                  payload_cfg, NULL);
11582
11583 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11584         .f = cmd_flow_director_flxpld_parsed,
11585         .data = NULL,
11586         .help_str = "flow_director_flexpayload ... : "
11587                 "Set flow director's flex payload on NIC",
11588         .tokens = {
11589                 (void *)&cmd_flow_director_flexpayload,
11590                 (void *)&cmd_flow_director_flexpayload_port_id,
11591                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11592                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11593                 NULL,
11594         },
11595 };
11596
11597 /* Generic flow interface command. */
11598 extern cmdline_parse_inst_t cmd_flow;
11599
11600 /* *** Classification Filters Control *** */
11601 /* *** Get symmetric hash enable per port *** */
11602 struct cmd_get_sym_hash_ena_per_port_result {
11603         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11604         portid_t port_id;
11605 };
11606
11607 static void
11608 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11609                                  __rte_unused struct cmdline *cl,
11610                                  __rte_unused void *data)
11611 {
11612         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11613         struct rte_eth_hash_filter_info info;
11614         int ret;
11615
11616         if (rte_eth_dev_filter_supported(res->port_id,
11617                                 RTE_ETH_FILTER_HASH) < 0) {
11618                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11619                                                         res->port_id);
11620                 return;
11621         }
11622
11623         memset(&info, 0, sizeof(info));
11624         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11625         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11626                                                 RTE_ETH_FILTER_GET, &info);
11627
11628         if (ret < 0) {
11629                 printf("Cannot get symmetric hash enable per port "
11630                                         "on port %u\n", res->port_id);
11631                 return;
11632         }
11633
11634         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11635                                 "enabled" : "disabled", res->port_id);
11636 }
11637
11638 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11639         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11640                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11641 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11642         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11643                 port_id, UINT16);
11644
11645 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11646         .f = cmd_get_sym_hash_per_port_parsed,
11647         .data = NULL,
11648         .help_str = "get_sym_hash_ena_per_port <port_id>",
11649         .tokens = {
11650                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11651                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11652                 NULL,
11653         },
11654 };
11655
11656 /* *** Set symmetric hash enable per port *** */
11657 struct cmd_set_sym_hash_ena_per_port_result {
11658         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11659         cmdline_fixed_string_t enable;
11660         portid_t port_id;
11661 };
11662
11663 static void
11664 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11665                                  __rte_unused struct cmdline *cl,
11666                                  __rte_unused void *data)
11667 {
11668         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11669         struct rte_eth_hash_filter_info info;
11670         int ret;
11671
11672         if (rte_eth_dev_filter_supported(res->port_id,
11673                                 RTE_ETH_FILTER_HASH) < 0) {
11674                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11675                                                         res->port_id);
11676                 return;
11677         }
11678
11679         memset(&info, 0, sizeof(info));
11680         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11681         if (!strcmp(res->enable, "enable"))
11682                 info.info.enable = 1;
11683         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11684                                         RTE_ETH_FILTER_SET, &info);
11685         if (ret < 0) {
11686                 printf("Cannot set symmetric hash enable per port on "
11687                                         "port %u\n", res->port_id);
11688                 return;
11689         }
11690         printf("Symmetric hash has been set to %s on port %u\n",
11691                                         res->enable, res->port_id);
11692 }
11693
11694 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11695         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11696                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11697 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11698         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11699                 port_id, UINT16);
11700 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11701         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11702                 enable, "enable#disable");
11703
11704 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11705         .f = cmd_set_sym_hash_per_port_parsed,
11706         .data = NULL,
11707         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11708         .tokens = {
11709                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11710                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11711                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11712                 NULL,
11713         },
11714 };
11715
11716 /* Get global config of hash function */
11717 struct cmd_get_hash_global_config_result {
11718         cmdline_fixed_string_t get_hash_global_config;
11719         portid_t port_id;
11720 };
11721
11722 static char *
11723 flowtype_to_str(uint16_t ftype)
11724 {
11725         uint16_t i;
11726         static struct {
11727                 char str[16];
11728                 uint16_t ftype;
11729         } ftype_table[] = {
11730                 {"ipv4", RTE_ETH_FLOW_IPV4},
11731                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11732                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11733                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11734                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11735                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11736                 {"ipv6", RTE_ETH_FLOW_IPV6},
11737                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11738                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11739                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11740                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11741                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11742                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11743                 {"port", RTE_ETH_FLOW_PORT},
11744                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11745                 {"geneve", RTE_ETH_FLOW_GENEVE},
11746                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11747         };
11748
11749         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11750                 if (ftype_table[i].ftype == ftype)
11751                         return ftype_table[i].str;
11752         }
11753
11754         return NULL;
11755 }
11756
11757 static void
11758 cmd_get_hash_global_config_parsed(void *parsed_result,
11759                                   __rte_unused struct cmdline *cl,
11760                                   __rte_unused void *data)
11761 {
11762         struct cmd_get_hash_global_config_result *res = parsed_result;
11763         struct rte_eth_hash_filter_info info;
11764         uint32_t idx, offset;
11765         uint16_t i;
11766         char *str;
11767         int ret;
11768
11769         if (rte_eth_dev_filter_supported(res->port_id,
11770                         RTE_ETH_FILTER_HASH) < 0) {
11771                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11772                                                         res->port_id);
11773                 return;
11774         }
11775
11776         memset(&info, 0, sizeof(info));
11777         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11778         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11779                                         RTE_ETH_FILTER_GET, &info);
11780         if (ret < 0) {
11781                 printf("Cannot get hash global configurations by port %d\n",
11782                                                         res->port_id);
11783                 return;
11784         }
11785
11786         switch (info.info.global_conf.hash_func) {
11787         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11788                 printf("Hash function is Toeplitz\n");
11789                 break;
11790         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11791                 printf("Hash function is Simple XOR\n");
11792                 break;
11793         default:
11794                 printf("Unknown hash function\n");
11795                 break;
11796         }
11797
11798         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11799                 idx = i / UINT64_BIT;
11800                 offset = i % UINT64_BIT;
11801                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11802                                                 (1ULL << offset)))
11803                         continue;
11804                 str = flowtype_to_str(i);
11805                 if (!str)
11806                         continue;
11807                 printf("Symmetric hash is %s globally for flow type %s "
11808                                                         "by port %d\n",
11809                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11810                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11811                                                         res->port_id);
11812         }
11813 }
11814
11815 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11816         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11817                 get_hash_global_config, "get_hash_global_config");
11818 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11819         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11820                 port_id, UINT16);
11821
11822 cmdline_parse_inst_t cmd_get_hash_global_config = {
11823         .f = cmd_get_hash_global_config_parsed,
11824         .data = NULL,
11825         .help_str = "get_hash_global_config <port_id>",
11826         .tokens = {
11827                 (void *)&cmd_get_hash_global_config_all,
11828                 (void *)&cmd_get_hash_global_config_port_id,
11829                 NULL,
11830         },
11831 };
11832
11833 /* Set global config of hash function */
11834 struct cmd_set_hash_global_config_result {
11835         cmdline_fixed_string_t set_hash_global_config;
11836         portid_t port_id;
11837         cmdline_fixed_string_t hash_func;
11838         cmdline_fixed_string_t flow_type;
11839         cmdline_fixed_string_t enable;
11840 };
11841
11842 static void
11843 cmd_set_hash_global_config_parsed(void *parsed_result,
11844                                   __rte_unused struct cmdline *cl,
11845                                   __rte_unused void *data)
11846 {
11847         struct cmd_set_hash_global_config_result *res = parsed_result;
11848         struct rte_eth_hash_filter_info info;
11849         uint32_t ftype, idx, offset;
11850         int ret;
11851
11852         if (rte_eth_dev_filter_supported(res->port_id,
11853                                 RTE_ETH_FILTER_HASH) < 0) {
11854                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11855                                                         res->port_id);
11856                 return;
11857         }
11858         memset(&info, 0, sizeof(info));
11859         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11860         if (!strcmp(res->hash_func, "toeplitz"))
11861                 info.info.global_conf.hash_func =
11862                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11863         else if (!strcmp(res->hash_func, "simple_xor"))
11864                 info.info.global_conf.hash_func =
11865                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11866         else if (!strcmp(res->hash_func, "default"))
11867                 info.info.global_conf.hash_func =
11868                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11869
11870         ftype = str2flowtype(res->flow_type);
11871         idx = ftype / UINT64_BIT;
11872         offset = ftype % UINT64_BIT;
11873         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11874         if (!strcmp(res->enable, "enable"))
11875                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11876                                                 (1ULL << offset);
11877         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11878                                         RTE_ETH_FILTER_SET, &info);
11879         if (ret < 0)
11880                 printf("Cannot set global hash configurations by port %d\n",
11881                                                         res->port_id);
11882         else
11883                 printf("Global hash configurations have been set "
11884                         "succcessfully by port %d\n", res->port_id);
11885 }
11886
11887 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11888         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11889                 set_hash_global_config, "set_hash_global_config");
11890 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11891         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11892                 port_id, UINT16);
11893 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11894         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11895                 hash_func, "toeplitz#simple_xor#default");
11896 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11897         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11898                 flow_type,
11899                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11900                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11901 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11902         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11903                 enable, "enable#disable");
11904
11905 cmdline_parse_inst_t cmd_set_hash_global_config = {
11906         .f = cmd_set_hash_global_config_parsed,
11907         .data = NULL,
11908         .help_str = "set_hash_global_config <port_id> "
11909                 "toeplitz|simple_xor|default "
11910                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11911                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11912                 "l2_payload enable|disable",
11913         .tokens = {
11914                 (void *)&cmd_set_hash_global_config_all,
11915                 (void *)&cmd_set_hash_global_config_port_id,
11916                 (void *)&cmd_set_hash_global_config_hash_func,
11917                 (void *)&cmd_set_hash_global_config_flow_type,
11918                 (void *)&cmd_set_hash_global_config_enable,
11919                 NULL,
11920         },
11921 };
11922
11923 /* Set hash input set */
11924 struct cmd_set_hash_input_set_result {
11925         cmdline_fixed_string_t set_hash_input_set;
11926         portid_t port_id;
11927         cmdline_fixed_string_t flow_type;
11928         cmdline_fixed_string_t inset_field;
11929         cmdline_fixed_string_t select;
11930 };
11931
11932 static enum rte_eth_input_set_field
11933 str2inset(char *string)
11934 {
11935         uint16_t i;
11936
11937         static const struct {
11938                 char str[32];
11939                 enum rte_eth_input_set_field inset;
11940         } inset_table[] = {
11941                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11942                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11943                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11944                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11945                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11946                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11947                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11948                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11949                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11950                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11951                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11952                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11953                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11954                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11955                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11956                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11957                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11958                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11959                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11960                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11961                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11962                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11963                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11964                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11965                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11966                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11967                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11968                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11969                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11970                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11971                 {"none", RTE_ETH_INPUT_SET_NONE},
11972         };
11973
11974         for (i = 0; i < RTE_DIM(inset_table); i++) {
11975                 if (!strcmp(string, inset_table[i].str))
11976                         return inset_table[i].inset;
11977         }
11978
11979         return RTE_ETH_INPUT_SET_UNKNOWN;
11980 }
11981
11982 static void
11983 cmd_set_hash_input_set_parsed(void *parsed_result,
11984                               __rte_unused struct cmdline *cl,
11985                               __rte_unused void *data)
11986 {
11987         struct cmd_set_hash_input_set_result *res = parsed_result;
11988         struct rte_eth_hash_filter_info info;
11989
11990         memset(&info, 0, sizeof(info));
11991         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11992         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11993         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11994         info.info.input_set_conf.inset_size = 1;
11995         if (!strcmp(res->select, "select"))
11996                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11997         else if (!strcmp(res->select, "add"))
11998                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11999         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12000                                 RTE_ETH_FILTER_SET, &info);
12001 }
12002
12003 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12004         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12005                 set_hash_input_set, "set_hash_input_set");
12006 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12007         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12008                 port_id, UINT16);
12009 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12010         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12011                 flow_type, NULL);
12012 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12013         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12014                 inset_field,
12015                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12016                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12017                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12018                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12019                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12020                 "fld-8th#none");
12021 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12022         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12023                 select, "select#add");
12024
12025 cmdline_parse_inst_t cmd_set_hash_input_set = {
12026         .f = cmd_set_hash_input_set_parsed,
12027         .data = NULL,
12028         .help_str = "set_hash_input_set <port_id> "
12029         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12030         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12031         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12032         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12033         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12034         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12035         "fld-7th|fld-8th|none select|add",
12036         .tokens = {
12037                 (void *)&cmd_set_hash_input_set_cmd,
12038                 (void *)&cmd_set_hash_input_set_port_id,
12039                 (void *)&cmd_set_hash_input_set_flow_type,
12040                 (void *)&cmd_set_hash_input_set_field,
12041                 (void *)&cmd_set_hash_input_set_select,
12042                 NULL,
12043         },
12044 };
12045
12046 /* Set flow director input set */
12047 struct cmd_set_fdir_input_set_result {
12048         cmdline_fixed_string_t set_fdir_input_set;
12049         portid_t port_id;
12050         cmdline_fixed_string_t flow_type;
12051         cmdline_fixed_string_t inset_field;
12052         cmdline_fixed_string_t select;
12053 };
12054
12055 static void
12056 cmd_set_fdir_input_set_parsed(void *parsed_result,
12057         __rte_unused struct cmdline *cl,
12058         __rte_unused void *data)
12059 {
12060         struct cmd_set_fdir_input_set_result *res = parsed_result;
12061         struct rte_eth_fdir_filter_info info;
12062
12063         memset(&info, 0, sizeof(info));
12064         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12065         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12066         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12067         info.info.input_set_conf.inset_size = 1;
12068         if (!strcmp(res->select, "select"))
12069                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12070         else if (!strcmp(res->select, "add"))
12071                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12072         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12073                 RTE_ETH_FILTER_SET, &info);
12074 }
12075
12076 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12077         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12078         set_fdir_input_set, "set_fdir_input_set");
12079 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12080         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12081         port_id, UINT16);
12082 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12083         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12084         flow_type,
12085         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12086         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12087 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12088         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12089         inset_field,
12090         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12091         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12092         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12093         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12094         "sctp-veri-tag#none");
12095 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12096         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12097         select, "select#add");
12098
12099 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12100         .f = cmd_set_fdir_input_set_parsed,
12101         .data = NULL,
12102         .help_str = "set_fdir_input_set <port_id> "
12103         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12104         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12105         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12106         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12107         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12108         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12109         "sctp-veri-tag|none select|add",
12110         .tokens = {
12111                 (void *)&cmd_set_fdir_input_set_cmd,
12112                 (void *)&cmd_set_fdir_input_set_port_id,
12113                 (void *)&cmd_set_fdir_input_set_flow_type,
12114                 (void *)&cmd_set_fdir_input_set_field,
12115                 (void *)&cmd_set_fdir_input_set_select,
12116                 NULL,
12117         },
12118 };
12119
12120 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12121 struct cmd_mcast_addr_result {
12122         cmdline_fixed_string_t mcast_addr_cmd;
12123         cmdline_fixed_string_t what;
12124         uint16_t port_num;
12125         struct ether_addr mc_addr;
12126 };
12127
12128 static void cmd_mcast_addr_parsed(void *parsed_result,
12129                 __attribute__((unused)) struct cmdline *cl,
12130                 __attribute__((unused)) void *data)
12131 {
12132         struct cmd_mcast_addr_result *res = parsed_result;
12133
12134         if (!is_multicast_ether_addr(&res->mc_addr)) {
12135                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12136                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12137                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12138                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12139                 return;
12140         }
12141         if (strcmp(res->what, "add") == 0)
12142                 mcast_addr_add(res->port_num, &res->mc_addr);
12143         else
12144                 mcast_addr_remove(res->port_num, &res->mc_addr);
12145 }
12146
12147 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12148         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12149                                  mcast_addr_cmd, "mcast_addr");
12150 cmdline_parse_token_string_t cmd_mcast_addr_what =
12151         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12152                                  "add#remove");
12153 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12154         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12155 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12156         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12157
12158 cmdline_parse_inst_t cmd_mcast_addr = {
12159         .f = cmd_mcast_addr_parsed,
12160         .data = (void *)0,
12161         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12162                 "Add/Remove multicast MAC address on port_id",
12163         .tokens = {
12164                 (void *)&cmd_mcast_addr_cmd,
12165                 (void *)&cmd_mcast_addr_what,
12166                 (void *)&cmd_mcast_addr_portnum,
12167                 (void *)&cmd_mcast_addr_addr,
12168                 NULL,
12169         },
12170 };
12171
12172 /* l2 tunnel config
12173  * only support E-tag now.
12174  */
12175
12176 /* Ether type config */
12177 struct cmd_config_l2_tunnel_eth_type_result {
12178         cmdline_fixed_string_t port;
12179         cmdline_fixed_string_t config;
12180         cmdline_fixed_string_t all;
12181         portid_t id;
12182         cmdline_fixed_string_t l2_tunnel;
12183         cmdline_fixed_string_t l2_tunnel_type;
12184         cmdline_fixed_string_t eth_type;
12185         uint16_t eth_type_val;
12186 };
12187
12188 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12189         TOKEN_STRING_INITIALIZER
12190                 (struct cmd_config_l2_tunnel_eth_type_result,
12191                  port, "port");
12192 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12193         TOKEN_STRING_INITIALIZER
12194                 (struct cmd_config_l2_tunnel_eth_type_result,
12195                  config, "config");
12196 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12197         TOKEN_STRING_INITIALIZER
12198                 (struct cmd_config_l2_tunnel_eth_type_result,
12199                  all, "all");
12200 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12201         TOKEN_NUM_INITIALIZER
12202                 (struct cmd_config_l2_tunnel_eth_type_result,
12203                  id, UINT16);
12204 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12205         TOKEN_STRING_INITIALIZER
12206                 (struct cmd_config_l2_tunnel_eth_type_result,
12207                  l2_tunnel, "l2-tunnel");
12208 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12209         TOKEN_STRING_INITIALIZER
12210                 (struct cmd_config_l2_tunnel_eth_type_result,
12211                  l2_tunnel_type, "E-tag");
12212 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12213         TOKEN_STRING_INITIALIZER
12214                 (struct cmd_config_l2_tunnel_eth_type_result,
12215                  eth_type, "ether-type");
12216 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12217         TOKEN_NUM_INITIALIZER
12218                 (struct cmd_config_l2_tunnel_eth_type_result,
12219                  eth_type_val, UINT16);
12220
12221 static enum rte_eth_tunnel_type
12222 str2fdir_l2_tunnel_type(char *string)
12223 {
12224         uint32_t i = 0;
12225
12226         static const struct {
12227                 char str[32];
12228                 enum rte_eth_tunnel_type type;
12229         } l2_tunnel_type_str[] = {
12230                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12231         };
12232
12233         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12234                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12235                         return l2_tunnel_type_str[i].type;
12236         }
12237         return RTE_TUNNEL_TYPE_NONE;
12238 }
12239
12240 /* ether type config for all ports */
12241 static void
12242 cmd_config_l2_tunnel_eth_type_all_parsed
12243         (void *parsed_result,
12244          __attribute__((unused)) struct cmdline *cl,
12245          __attribute__((unused)) void *data)
12246 {
12247         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12248         struct rte_eth_l2_tunnel_conf entry;
12249         portid_t pid;
12250
12251         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12252         entry.ether_type = res->eth_type_val;
12253
12254         RTE_ETH_FOREACH_DEV(pid) {
12255                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12256         }
12257 }
12258
12259 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12260         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12261         .data = NULL,
12262         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12263         .tokens = {
12264                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12265                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12266                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12267                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12268                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12269                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12270                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12271                 NULL,
12272         },
12273 };
12274
12275 /* ether type config for a specific port */
12276 static void
12277 cmd_config_l2_tunnel_eth_type_specific_parsed(
12278         void *parsed_result,
12279         __attribute__((unused)) struct cmdline *cl,
12280         __attribute__((unused)) void *data)
12281 {
12282         struct cmd_config_l2_tunnel_eth_type_result *res =
12283                  parsed_result;
12284         struct rte_eth_l2_tunnel_conf entry;
12285
12286         if (port_id_is_invalid(res->id, ENABLED_WARN))
12287                 return;
12288
12289         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12290         entry.ether_type = res->eth_type_val;
12291
12292         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12293 }
12294
12295 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12296         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12297         .data = NULL,
12298         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12299         .tokens = {
12300                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12301                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12302                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12303                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12304                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12305                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12306                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12307                 NULL,
12308         },
12309 };
12310
12311 /* Enable/disable l2 tunnel */
12312 struct cmd_config_l2_tunnel_en_dis_result {
12313         cmdline_fixed_string_t port;
12314         cmdline_fixed_string_t config;
12315         cmdline_fixed_string_t all;
12316         portid_t id;
12317         cmdline_fixed_string_t l2_tunnel;
12318         cmdline_fixed_string_t l2_tunnel_type;
12319         cmdline_fixed_string_t en_dis;
12320 };
12321
12322 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12323         TOKEN_STRING_INITIALIZER
12324                 (struct cmd_config_l2_tunnel_en_dis_result,
12325                  port, "port");
12326 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12327         TOKEN_STRING_INITIALIZER
12328                 (struct cmd_config_l2_tunnel_en_dis_result,
12329                  config, "config");
12330 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12331         TOKEN_STRING_INITIALIZER
12332                 (struct cmd_config_l2_tunnel_en_dis_result,
12333                  all, "all");
12334 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12335         TOKEN_NUM_INITIALIZER
12336                 (struct cmd_config_l2_tunnel_en_dis_result,
12337                  id, UINT16);
12338 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12339         TOKEN_STRING_INITIALIZER
12340                 (struct cmd_config_l2_tunnel_en_dis_result,
12341                  l2_tunnel, "l2-tunnel");
12342 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12343         TOKEN_STRING_INITIALIZER
12344                 (struct cmd_config_l2_tunnel_en_dis_result,
12345                  l2_tunnel_type, "E-tag");
12346 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12347         TOKEN_STRING_INITIALIZER
12348                 (struct cmd_config_l2_tunnel_en_dis_result,
12349                  en_dis, "enable#disable");
12350
12351 /* enable/disable l2 tunnel for all ports */
12352 static void
12353 cmd_config_l2_tunnel_en_dis_all_parsed(
12354         void *parsed_result,
12355         __attribute__((unused)) struct cmdline *cl,
12356         __attribute__((unused)) void *data)
12357 {
12358         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12359         struct rte_eth_l2_tunnel_conf entry;
12360         portid_t pid;
12361         uint8_t en;
12362
12363         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12364
12365         if (!strcmp("enable", res->en_dis))
12366                 en = 1;
12367         else
12368                 en = 0;
12369
12370         RTE_ETH_FOREACH_DEV(pid) {
12371                 rte_eth_dev_l2_tunnel_offload_set(pid,
12372                                                   &entry,
12373                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12374                                                   en);
12375         }
12376 }
12377
12378 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12379         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12380         .data = NULL,
12381         .help_str = "port config all l2-tunnel E-tag enable|disable",
12382         .tokens = {
12383                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12384                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12385                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12386                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12387                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12388                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12389                 NULL,
12390         },
12391 };
12392
12393 /* enable/disable l2 tunnel for a port */
12394 static void
12395 cmd_config_l2_tunnel_en_dis_specific_parsed(
12396         void *parsed_result,
12397         __attribute__((unused)) struct cmdline *cl,
12398         __attribute__((unused)) void *data)
12399 {
12400         struct cmd_config_l2_tunnel_en_dis_result *res =
12401                 parsed_result;
12402         struct rte_eth_l2_tunnel_conf entry;
12403
12404         if (port_id_is_invalid(res->id, ENABLED_WARN))
12405                 return;
12406
12407         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12408
12409         if (!strcmp("enable", res->en_dis))
12410                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12411                                                   &entry,
12412                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12413                                                   1);
12414         else
12415                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12416                                                   &entry,
12417                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12418                                                   0);
12419 }
12420
12421 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12422         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12423         .data = NULL,
12424         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12425         .tokens = {
12426                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12427                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12428                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12429                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12430                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12431                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12432                 NULL,
12433         },
12434 };
12435
12436 /* E-tag configuration */
12437
12438 /* Common result structure for all E-tag configuration */
12439 struct cmd_config_e_tag_result {
12440         cmdline_fixed_string_t e_tag;
12441         cmdline_fixed_string_t set;
12442         cmdline_fixed_string_t insertion;
12443         cmdline_fixed_string_t stripping;
12444         cmdline_fixed_string_t forwarding;
12445         cmdline_fixed_string_t filter;
12446         cmdline_fixed_string_t add;
12447         cmdline_fixed_string_t del;
12448         cmdline_fixed_string_t on;
12449         cmdline_fixed_string_t off;
12450         cmdline_fixed_string_t on_off;
12451         cmdline_fixed_string_t port_tag_id;
12452         uint32_t port_tag_id_val;
12453         cmdline_fixed_string_t e_tag_id;
12454         uint16_t e_tag_id_val;
12455         cmdline_fixed_string_t dst_pool;
12456         uint8_t dst_pool_val;
12457         cmdline_fixed_string_t port;
12458         portid_t port_id;
12459         cmdline_fixed_string_t vf;
12460         uint8_t vf_id;
12461 };
12462
12463 /* Common CLI fields for all E-tag configuration */
12464 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12465         TOKEN_STRING_INITIALIZER
12466                 (struct cmd_config_e_tag_result,
12467                  e_tag, "E-tag");
12468 cmdline_parse_token_string_t cmd_config_e_tag_set =
12469         TOKEN_STRING_INITIALIZER
12470                 (struct cmd_config_e_tag_result,
12471                  set, "set");
12472 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12473         TOKEN_STRING_INITIALIZER
12474                 (struct cmd_config_e_tag_result,
12475                  insertion, "insertion");
12476 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12477         TOKEN_STRING_INITIALIZER
12478                 (struct cmd_config_e_tag_result,
12479                  stripping, "stripping");
12480 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12481         TOKEN_STRING_INITIALIZER
12482                 (struct cmd_config_e_tag_result,
12483                  forwarding, "forwarding");
12484 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12485         TOKEN_STRING_INITIALIZER
12486                 (struct cmd_config_e_tag_result,
12487                  filter, "filter");
12488 cmdline_parse_token_string_t cmd_config_e_tag_add =
12489         TOKEN_STRING_INITIALIZER
12490                 (struct cmd_config_e_tag_result,
12491                  add, "add");
12492 cmdline_parse_token_string_t cmd_config_e_tag_del =
12493         TOKEN_STRING_INITIALIZER
12494                 (struct cmd_config_e_tag_result,
12495                  del, "del");
12496 cmdline_parse_token_string_t cmd_config_e_tag_on =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_config_e_tag_result,
12499                  on, "on");
12500 cmdline_parse_token_string_t cmd_config_e_tag_off =
12501         TOKEN_STRING_INITIALIZER
12502                 (struct cmd_config_e_tag_result,
12503                  off, "off");
12504 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12505         TOKEN_STRING_INITIALIZER
12506                 (struct cmd_config_e_tag_result,
12507                  on_off, "on#off");
12508 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12509         TOKEN_STRING_INITIALIZER
12510                 (struct cmd_config_e_tag_result,
12511                  port_tag_id, "port-tag-id");
12512 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12513         TOKEN_NUM_INITIALIZER
12514                 (struct cmd_config_e_tag_result,
12515                  port_tag_id_val, UINT32);
12516 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_config_e_tag_result,
12519                  e_tag_id, "e-tag-id");
12520 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12521         TOKEN_NUM_INITIALIZER
12522                 (struct cmd_config_e_tag_result,
12523                  e_tag_id_val, UINT16);
12524 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12525         TOKEN_STRING_INITIALIZER
12526                 (struct cmd_config_e_tag_result,
12527                  dst_pool, "dst-pool");
12528 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12529         TOKEN_NUM_INITIALIZER
12530                 (struct cmd_config_e_tag_result,
12531                  dst_pool_val, UINT8);
12532 cmdline_parse_token_string_t cmd_config_e_tag_port =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_config_e_tag_result,
12535                  port, "port");
12536 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12537         TOKEN_NUM_INITIALIZER
12538                 (struct cmd_config_e_tag_result,
12539                  port_id, UINT16);
12540 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12541         TOKEN_STRING_INITIALIZER
12542                 (struct cmd_config_e_tag_result,
12543                  vf, "vf");
12544 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12545         TOKEN_NUM_INITIALIZER
12546                 (struct cmd_config_e_tag_result,
12547                  vf_id, UINT8);
12548
12549 /* E-tag insertion configuration */
12550 static void
12551 cmd_config_e_tag_insertion_en_parsed(
12552         void *parsed_result,
12553         __attribute__((unused)) struct cmdline *cl,
12554         __attribute__((unused)) void *data)
12555 {
12556         struct cmd_config_e_tag_result *res =
12557                 parsed_result;
12558         struct rte_eth_l2_tunnel_conf entry;
12559
12560         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12561                 return;
12562
12563         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12564         entry.tunnel_id = res->port_tag_id_val;
12565         entry.vf_id = res->vf_id;
12566         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12567                                           &entry,
12568                                           ETH_L2_TUNNEL_INSERTION_MASK,
12569                                           1);
12570 }
12571
12572 static void
12573 cmd_config_e_tag_insertion_dis_parsed(
12574         void *parsed_result,
12575         __attribute__((unused)) struct cmdline *cl,
12576         __attribute__((unused)) void *data)
12577 {
12578         struct cmd_config_e_tag_result *res =
12579                 parsed_result;
12580         struct rte_eth_l2_tunnel_conf entry;
12581
12582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12583                 return;
12584
12585         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12586         entry.vf_id = res->vf_id;
12587
12588         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12589                                           &entry,
12590                                           ETH_L2_TUNNEL_INSERTION_MASK,
12591                                           0);
12592 }
12593
12594 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12595         .f = cmd_config_e_tag_insertion_en_parsed,
12596         .data = NULL,
12597         .help_str = "E-tag ... : E-tag insertion enable",
12598         .tokens = {
12599                 (void *)&cmd_config_e_tag_e_tag,
12600                 (void *)&cmd_config_e_tag_set,
12601                 (void *)&cmd_config_e_tag_insertion,
12602                 (void *)&cmd_config_e_tag_on,
12603                 (void *)&cmd_config_e_tag_port_tag_id,
12604                 (void *)&cmd_config_e_tag_port_tag_id_val,
12605                 (void *)&cmd_config_e_tag_port,
12606                 (void *)&cmd_config_e_tag_port_id,
12607                 (void *)&cmd_config_e_tag_vf,
12608                 (void *)&cmd_config_e_tag_vf_id,
12609                 NULL,
12610         },
12611 };
12612
12613 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12614         .f = cmd_config_e_tag_insertion_dis_parsed,
12615         .data = NULL,
12616         .help_str = "E-tag ... : E-tag insertion disable",
12617         .tokens = {
12618                 (void *)&cmd_config_e_tag_e_tag,
12619                 (void *)&cmd_config_e_tag_set,
12620                 (void *)&cmd_config_e_tag_insertion,
12621                 (void *)&cmd_config_e_tag_off,
12622                 (void *)&cmd_config_e_tag_port,
12623                 (void *)&cmd_config_e_tag_port_id,
12624                 (void *)&cmd_config_e_tag_vf,
12625                 (void *)&cmd_config_e_tag_vf_id,
12626                 NULL,
12627         },
12628 };
12629
12630 /* E-tag stripping configuration */
12631 static void
12632 cmd_config_e_tag_stripping_parsed(
12633         void *parsed_result,
12634         __attribute__((unused)) struct cmdline *cl,
12635         __attribute__((unused)) void *data)
12636 {
12637         struct cmd_config_e_tag_result *res =
12638                 parsed_result;
12639         struct rte_eth_l2_tunnel_conf entry;
12640
12641         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12642                 return;
12643
12644         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12645
12646         if (!strcmp(res->on_off, "on"))
12647                 rte_eth_dev_l2_tunnel_offload_set
12648                         (res->port_id,
12649                          &entry,
12650                          ETH_L2_TUNNEL_STRIPPING_MASK,
12651                          1);
12652         else
12653                 rte_eth_dev_l2_tunnel_offload_set
12654                         (res->port_id,
12655                          &entry,
12656                          ETH_L2_TUNNEL_STRIPPING_MASK,
12657                          0);
12658 }
12659
12660 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12661         .f = cmd_config_e_tag_stripping_parsed,
12662         .data = NULL,
12663         .help_str = "E-tag ... : E-tag stripping enable/disable",
12664         .tokens = {
12665                 (void *)&cmd_config_e_tag_e_tag,
12666                 (void *)&cmd_config_e_tag_set,
12667                 (void *)&cmd_config_e_tag_stripping,
12668                 (void *)&cmd_config_e_tag_on_off,
12669                 (void *)&cmd_config_e_tag_port,
12670                 (void *)&cmd_config_e_tag_port_id,
12671                 NULL,
12672         },
12673 };
12674
12675 /* E-tag forwarding configuration */
12676 static void
12677 cmd_config_e_tag_forwarding_parsed(
12678         void *parsed_result,
12679         __attribute__((unused)) struct cmdline *cl,
12680         __attribute__((unused)) void *data)
12681 {
12682         struct cmd_config_e_tag_result *res = parsed_result;
12683         struct rte_eth_l2_tunnel_conf entry;
12684
12685         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12686                 return;
12687
12688         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12689
12690         if (!strcmp(res->on_off, "on"))
12691                 rte_eth_dev_l2_tunnel_offload_set
12692                         (res->port_id,
12693                          &entry,
12694                          ETH_L2_TUNNEL_FORWARDING_MASK,
12695                          1);
12696         else
12697                 rte_eth_dev_l2_tunnel_offload_set
12698                         (res->port_id,
12699                          &entry,
12700                          ETH_L2_TUNNEL_FORWARDING_MASK,
12701                          0);
12702 }
12703
12704 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12705         .f = cmd_config_e_tag_forwarding_parsed,
12706         .data = NULL,
12707         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12708         .tokens = {
12709                 (void *)&cmd_config_e_tag_e_tag,
12710                 (void *)&cmd_config_e_tag_set,
12711                 (void *)&cmd_config_e_tag_forwarding,
12712                 (void *)&cmd_config_e_tag_on_off,
12713                 (void *)&cmd_config_e_tag_port,
12714                 (void *)&cmd_config_e_tag_port_id,
12715                 NULL,
12716         },
12717 };
12718
12719 /* E-tag filter configuration */
12720 static void
12721 cmd_config_e_tag_filter_add_parsed(
12722         void *parsed_result,
12723         __attribute__((unused)) struct cmdline *cl,
12724         __attribute__((unused)) void *data)
12725 {
12726         struct cmd_config_e_tag_result *res = parsed_result;
12727         struct rte_eth_l2_tunnel_conf entry;
12728         int ret = 0;
12729
12730         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12731                 return;
12732
12733         if (res->e_tag_id_val > 0x3fff) {
12734                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12735                 return;
12736         }
12737
12738         ret = rte_eth_dev_filter_supported(res->port_id,
12739                                            RTE_ETH_FILTER_L2_TUNNEL);
12740         if (ret < 0) {
12741                 printf("E-tag filter is not supported on port %u.\n",
12742                        res->port_id);
12743                 return;
12744         }
12745
12746         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12747         entry.tunnel_id = res->e_tag_id_val;
12748         entry.pool = res->dst_pool_val;
12749
12750         ret = rte_eth_dev_filter_ctrl(res->port_id,
12751                                       RTE_ETH_FILTER_L2_TUNNEL,
12752                                       RTE_ETH_FILTER_ADD,
12753                                       &entry);
12754         if (ret < 0)
12755                 printf("E-tag filter programming error: (%s)\n",
12756                        strerror(-ret));
12757 }
12758
12759 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12760         .f = cmd_config_e_tag_filter_add_parsed,
12761         .data = NULL,
12762         .help_str = "E-tag ... : E-tag filter add",
12763         .tokens = {
12764                 (void *)&cmd_config_e_tag_e_tag,
12765                 (void *)&cmd_config_e_tag_set,
12766                 (void *)&cmd_config_e_tag_filter,
12767                 (void *)&cmd_config_e_tag_add,
12768                 (void *)&cmd_config_e_tag_e_tag_id,
12769                 (void *)&cmd_config_e_tag_e_tag_id_val,
12770                 (void *)&cmd_config_e_tag_dst_pool,
12771                 (void *)&cmd_config_e_tag_dst_pool_val,
12772                 (void *)&cmd_config_e_tag_port,
12773                 (void *)&cmd_config_e_tag_port_id,
12774                 NULL,
12775         },
12776 };
12777
12778 static void
12779 cmd_config_e_tag_filter_del_parsed(
12780         void *parsed_result,
12781         __attribute__((unused)) struct cmdline *cl,
12782         __attribute__((unused)) void *data)
12783 {
12784         struct cmd_config_e_tag_result *res = parsed_result;
12785         struct rte_eth_l2_tunnel_conf entry;
12786         int ret = 0;
12787
12788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12789                 return;
12790
12791         if (res->e_tag_id_val > 0x3fff) {
12792                 printf("e-tag-id must be less than 0x3fff.\n");
12793                 return;
12794         }
12795
12796         ret = rte_eth_dev_filter_supported(res->port_id,
12797                                            RTE_ETH_FILTER_L2_TUNNEL);
12798         if (ret < 0) {
12799                 printf("E-tag filter is not supported on port %u.\n",
12800                        res->port_id);
12801                 return;
12802         }
12803
12804         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12805         entry.tunnel_id = res->e_tag_id_val;
12806
12807         ret = rte_eth_dev_filter_ctrl(res->port_id,
12808                                       RTE_ETH_FILTER_L2_TUNNEL,
12809                                       RTE_ETH_FILTER_DELETE,
12810                                       &entry);
12811         if (ret < 0)
12812                 printf("E-tag filter programming error: (%s)\n",
12813                        strerror(-ret));
12814 }
12815
12816 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12817         .f = cmd_config_e_tag_filter_del_parsed,
12818         .data = NULL,
12819         .help_str = "E-tag ... : E-tag filter delete",
12820         .tokens = {
12821                 (void *)&cmd_config_e_tag_e_tag,
12822                 (void *)&cmd_config_e_tag_set,
12823                 (void *)&cmd_config_e_tag_filter,
12824                 (void *)&cmd_config_e_tag_del,
12825                 (void *)&cmd_config_e_tag_e_tag_id,
12826                 (void *)&cmd_config_e_tag_e_tag_id_val,
12827                 (void *)&cmd_config_e_tag_port,
12828                 (void *)&cmd_config_e_tag_port_id,
12829                 NULL,
12830         },
12831 };
12832
12833 /* vf vlan anti spoof configuration */
12834
12835 /* Common result structure for vf vlan anti spoof */
12836 struct cmd_vf_vlan_anti_spoof_result {
12837         cmdline_fixed_string_t set;
12838         cmdline_fixed_string_t vf;
12839         cmdline_fixed_string_t vlan;
12840         cmdline_fixed_string_t antispoof;
12841         portid_t port_id;
12842         uint32_t vf_id;
12843         cmdline_fixed_string_t on_off;
12844 };
12845
12846 /* Common CLI fields for vf vlan anti spoof enable disable */
12847 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12848         TOKEN_STRING_INITIALIZER
12849                 (struct cmd_vf_vlan_anti_spoof_result,
12850                  set, "set");
12851 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12852         TOKEN_STRING_INITIALIZER
12853                 (struct cmd_vf_vlan_anti_spoof_result,
12854                  vf, "vf");
12855 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12856         TOKEN_STRING_INITIALIZER
12857                 (struct cmd_vf_vlan_anti_spoof_result,
12858                  vlan, "vlan");
12859 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12860         TOKEN_STRING_INITIALIZER
12861                 (struct cmd_vf_vlan_anti_spoof_result,
12862                  antispoof, "antispoof");
12863 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12864         TOKEN_NUM_INITIALIZER
12865                 (struct cmd_vf_vlan_anti_spoof_result,
12866                  port_id, UINT16);
12867 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12868         TOKEN_NUM_INITIALIZER
12869                 (struct cmd_vf_vlan_anti_spoof_result,
12870                  vf_id, UINT32);
12871 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12872         TOKEN_STRING_INITIALIZER
12873                 (struct cmd_vf_vlan_anti_spoof_result,
12874                  on_off, "on#off");
12875
12876 static void
12877 cmd_set_vf_vlan_anti_spoof_parsed(
12878         void *parsed_result,
12879         __attribute__((unused)) struct cmdline *cl,
12880         __attribute__((unused)) void *data)
12881 {
12882         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12883         int ret = -ENOTSUP;
12884
12885         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12886
12887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12888                 return;
12889
12890 #ifdef RTE_LIBRTE_IXGBE_PMD
12891         if (ret == -ENOTSUP)
12892                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12893                                 res->vf_id, is_on);
12894 #endif
12895 #ifdef RTE_LIBRTE_I40E_PMD
12896         if (ret == -ENOTSUP)
12897                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12898                                 res->vf_id, is_on);
12899 #endif
12900 #ifdef RTE_LIBRTE_BNXT_PMD
12901         if (ret == -ENOTSUP)
12902                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12903                                 res->vf_id, is_on);
12904 #endif
12905
12906         switch (ret) {
12907         case 0:
12908                 break;
12909         case -EINVAL:
12910                 printf("invalid vf_id %d\n", res->vf_id);
12911                 break;
12912         case -ENODEV:
12913                 printf("invalid port_id %d\n", res->port_id);
12914                 break;
12915         case -ENOTSUP:
12916                 printf("function not implemented\n");
12917                 break;
12918         default:
12919                 printf("programming error: (%s)\n", strerror(-ret));
12920         }
12921 }
12922
12923 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12924         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12925         .data = NULL,
12926         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12927         .tokens = {
12928                 (void *)&cmd_vf_vlan_anti_spoof_set,
12929                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12930                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12931                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12932                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12933                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12934                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12935                 NULL,
12936         },
12937 };
12938
12939 /* vf mac anti spoof configuration */
12940
12941 /* Common result structure for vf mac anti spoof */
12942 struct cmd_vf_mac_anti_spoof_result {
12943         cmdline_fixed_string_t set;
12944         cmdline_fixed_string_t vf;
12945         cmdline_fixed_string_t mac;
12946         cmdline_fixed_string_t antispoof;
12947         portid_t port_id;
12948         uint32_t vf_id;
12949         cmdline_fixed_string_t on_off;
12950 };
12951
12952 /* Common CLI fields for vf mac anti spoof enable disable */
12953 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12954         TOKEN_STRING_INITIALIZER
12955                 (struct cmd_vf_mac_anti_spoof_result,
12956                  set, "set");
12957 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12958         TOKEN_STRING_INITIALIZER
12959                 (struct cmd_vf_mac_anti_spoof_result,
12960                  vf, "vf");
12961 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12962         TOKEN_STRING_INITIALIZER
12963                 (struct cmd_vf_mac_anti_spoof_result,
12964                  mac, "mac");
12965 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12966         TOKEN_STRING_INITIALIZER
12967                 (struct cmd_vf_mac_anti_spoof_result,
12968                  antispoof, "antispoof");
12969 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12970         TOKEN_NUM_INITIALIZER
12971                 (struct cmd_vf_mac_anti_spoof_result,
12972                  port_id, UINT16);
12973 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12974         TOKEN_NUM_INITIALIZER
12975                 (struct cmd_vf_mac_anti_spoof_result,
12976                  vf_id, UINT32);
12977 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12978         TOKEN_STRING_INITIALIZER
12979                 (struct cmd_vf_mac_anti_spoof_result,
12980                  on_off, "on#off");
12981
12982 static void
12983 cmd_set_vf_mac_anti_spoof_parsed(
12984         void *parsed_result,
12985         __attribute__((unused)) struct cmdline *cl,
12986         __attribute__((unused)) void *data)
12987 {
12988         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12989         int ret = -ENOTSUP;
12990
12991         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12992
12993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12994                 return;
12995
12996 #ifdef RTE_LIBRTE_IXGBE_PMD
12997         if (ret == -ENOTSUP)
12998                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12999                         res->vf_id, is_on);
13000 #endif
13001 #ifdef RTE_LIBRTE_I40E_PMD
13002         if (ret == -ENOTSUP)
13003                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13004                         res->vf_id, is_on);
13005 #endif
13006 #ifdef RTE_LIBRTE_BNXT_PMD
13007         if (ret == -ENOTSUP)
13008                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13009                         res->vf_id, is_on);
13010 #endif
13011
13012         switch (ret) {
13013         case 0:
13014                 break;
13015         case -EINVAL:
13016                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13017                 break;
13018         case -ENODEV:
13019                 printf("invalid port_id %d\n", res->port_id);
13020                 break;
13021         case -ENOTSUP:
13022                 printf("function not implemented\n");
13023                 break;
13024         default:
13025                 printf("programming error: (%s)\n", strerror(-ret));
13026         }
13027 }
13028
13029 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13030         .f = cmd_set_vf_mac_anti_spoof_parsed,
13031         .data = NULL,
13032         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13033         .tokens = {
13034                 (void *)&cmd_vf_mac_anti_spoof_set,
13035                 (void *)&cmd_vf_mac_anti_spoof_vf,
13036                 (void *)&cmd_vf_mac_anti_spoof_mac,
13037                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13038                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13039                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13040                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13041                 NULL,
13042         },
13043 };
13044
13045 /* vf vlan strip queue configuration */
13046
13047 /* Common result structure for vf mac anti spoof */
13048 struct cmd_vf_vlan_stripq_result {
13049         cmdline_fixed_string_t set;
13050         cmdline_fixed_string_t vf;
13051         cmdline_fixed_string_t vlan;
13052         cmdline_fixed_string_t stripq;
13053         portid_t port_id;
13054         uint16_t vf_id;
13055         cmdline_fixed_string_t on_off;
13056 };
13057
13058 /* Common CLI fields for vf vlan strip enable disable */
13059 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13060         TOKEN_STRING_INITIALIZER
13061                 (struct cmd_vf_vlan_stripq_result,
13062                  set, "set");
13063 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13064         TOKEN_STRING_INITIALIZER
13065                 (struct cmd_vf_vlan_stripq_result,
13066                  vf, "vf");
13067 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13068         TOKEN_STRING_INITIALIZER
13069                 (struct cmd_vf_vlan_stripq_result,
13070                  vlan, "vlan");
13071 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13072         TOKEN_STRING_INITIALIZER
13073                 (struct cmd_vf_vlan_stripq_result,
13074                  stripq, "stripq");
13075 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13076         TOKEN_NUM_INITIALIZER
13077                 (struct cmd_vf_vlan_stripq_result,
13078                  port_id, UINT16);
13079 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13080         TOKEN_NUM_INITIALIZER
13081                 (struct cmd_vf_vlan_stripq_result,
13082                  vf_id, UINT16);
13083 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13084         TOKEN_STRING_INITIALIZER
13085                 (struct cmd_vf_vlan_stripq_result,
13086                  on_off, "on#off");
13087
13088 static void
13089 cmd_set_vf_vlan_stripq_parsed(
13090         void *parsed_result,
13091         __attribute__((unused)) struct cmdline *cl,
13092         __attribute__((unused)) void *data)
13093 {
13094         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13095         int ret = -ENOTSUP;
13096
13097         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13098
13099         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13100                 return;
13101
13102 #ifdef RTE_LIBRTE_IXGBE_PMD
13103         if (ret == -ENOTSUP)
13104                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13105                         res->vf_id, is_on);
13106 #endif
13107 #ifdef RTE_LIBRTE_I40E_PMD
13108         if (ret == -ENOTSUP)
13109                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13110                         res->vf_id, is_on);
13111 #endif
13112 #ifdef RTE_LIBRTE_BNXT_PMD
13113         if (ret == -ENOTSUP)
13114                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13115                         res->vf_id, is_on);
13116 #endif
13117
13118         switch (ret) {
13119         case 0:
13120                 break;
13121         case -EINVAL:
13122                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13123                 break;
13124         case -ENODEV:
13125                 printf("invalid port_id %d\n", res->port_id);
13126                 break;
13127         case -ENOTSUP:
13128                 printf("function not implemented\n");
13129                 break;
13130         default:
13131                 printf("programming error: (%s)\n", strerror(-ret));
13132         }
13133 }
13134
13135 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13136         .f = cmd_set_vf_vlan_stripq_parsed,
13137         .data = NULL,
13138         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13139         .tokens = {
13140                 (void *)&cmd_vf_vlan_stripq_set,
13141                 (void *)&cmd_vf_vlan_stripq_vf,
13142                 (void *)&cmd_vf_vlan_stripq_vlan,
13143                 (void *)&cmd_vf_vlan_stripq_stripq,
13144                 (void *)&cmd_vf_vlan_stripq_port_id,
13145                 (void *)&cmd_vf_vlan_stripq_vf_id,
13146                 (void *)&cmd_vf_vlan_stripq_on_off,
13147                 NULL,
13148         },
13149 };
13150
13151 /* vf vlan insert configuration */
13152
13153 /* Common result structure for vf vlan insert */
13154 struct cmd_vf_vlan_insert_result {
13155         cmdline_fixed_string_t set;
13156         cmdline_fixed_string_t vf;
13157         cmdline_fixed_string_t vlan;
13158         cmdline_fixed_string_t insert;
13159         portid_t port_id;
13160         uint16_t vf_id;
13161         uint16_t vlan_id;
13162 };
13163
13164 /* Common CLI fields for vf vlan insert enable disable */
13165 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13166         TOKEN_STRING_INITIALIZER
13167                 (struct cmd_vf_vlan_insert_result,
13168                  set, "set");
13169 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13170         TOKEN_STRING_INITIALIZER
13171                 (struct cmd_vf_vlan_insert_result,
13172                  vf, "vf");
13173 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13174         TOKEN_STRING_INITIALIZER
13175                 (struct cmd_vf_vlan_insert_result,
13176                  vlan, "vlan");
13177 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13178         TOKEN_STRING_INITIALIZER
13179                 (struct cmd_vf_vlan_insert_result,
13180                  insert, "insert");
13181 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13182         TOKEN_NUM_INITIALIZER
13183                 (struct cmd_vf_vlan_insert_result,
13184                  port_id, UINT16);
13185 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13186         TOKEN_NUM_INITIALIZER
13187                 (struct cmd_vf_vlan_insert_result,
13188                  vf_id, UINT16);
13189 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13190         TOKEN_NUM_INITIALIZER
13191                 (struct cmd_vf_vlan_insert_result,
13192                  vlan_id, UINT16);
13193
13194 static void
13195 cmd_set_vf_vlan_insert_parsed(
13196         void *parsed_result,
13197         __attribute__((unused)) struct cmdline *cl,
13198         __attribute__((unused)) void *data)
13199 {
13200         struct cmd_vf_vlan_insert_result *res = parsed_result;
13201         int ret = -ENOTSUP;
13202
13203         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13204                 return;
13205
13206 #ifdef RTE_LIBRTE_IXGBE_PMD
13207         if (ret == -ENOTSUP)
13208                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13209                         res->vlan_id);
13210 #endif
13211 #ifdef RTE_LIBRTE_I40E_PMD
13212         if (ret == -ENOTSUP)
13213                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13214                         res->vlan_id);
13215 #endif
13216 #ifdef RTE_LIBRTE_BNXT_PMD
13217         if (ret == -ENOTSUP)
13218                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13219                         res->vlan_id);
13220 #endif
13221
13222         switch (ret) {
13223         case 0:
13224                 break;
13225         case -EINVAL:
13226                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13227                 break;
13228         case -ENODEV:
13229                 printf("invalid port_id %d\n", res->port_id);
13230                 break;
13231         case -ENOTSUP:
13232                 printf("function not implemented\n");
13233                 break;
13234         default:
13235                 printf("programming error: (%s)\n", strerror(-ret));
13236         }
13237 }
13238
13239 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13240         .f = cmd_set_vf_vlan_insert_parsed,
13241         .data = NULL,
13242         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13243         .tokens = {
13244                 (void *)&cmd_vf_vlan_insert_set,
13245                 (void *)&cmd_vf_vlan_insert_vf,
13246                 (void *)&cmd_vf_vlan_insert_vlan,
13247                 (void *)&cmd_vf_vlan_insert_insert,
13248                 (void *)&cmd_vf_vlan_insert_port_id,
13249                 (void *)&cmd_vf_vlan_insert_vf_id,
13250                 (void *)&cmd_vf_vlan_insert_vlan_id,
13251                 NULL,
13252         },
13253 };
13254
13255 /* tx loopback configuration */
13256
13257 /* Common result structure for tx loopback */
13258 struct cmd_tx_loopback_result {
13259         cmdline_fixed_string_t set;
13260         cmdline_fixed_string_t tx;
13261         cmdline_fixed_string_t loopback;
13262         portid_t port_id;
13263         cmdline_fixed_string_t on_off;
13264 };
13265
13266 /* Common CLI fields for tx loopback enable disable */
13267 cmdline_parse_token_string_t cmd_tx_loopback_set =
13268         TOKEN_STRING_INITIALIZER
13269                 (struct cmd_tx_loopback_result,
13270                  set, "set");
13271 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13272         TOKEN_STRING_INITIALIZER
13273                 (struct cmd_tx_loopback_result,
13274                  tx, "tx");
13275 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13276         TOKEN_STRING_INITIALIZER
13277                 (struct cmd_tx_loopback_result,
13278                  loopback, "loopback");
13279 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13280         TOKEN_NUM_INITIALIZER
13281                 (struct cmd_tx_loopback_result,
13282                  port_id, UINT16);
13283 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13284         TOKEN_STRING_INITIALIZER
13285                 (struct cmd_tx_loopback_result,
13286                  on_off, "on#off");
13287
13288 static void
13289 cmd_set_tx_loopback_parsed(
13290         void *parsed_result,
13291         __attribute__((unused)) struct cmdline *cl,
13292         __attribute__((unused)) void *data)
13293 {
13294         struct cmd_tx_loopback_result *res = parsed_result;
13295         int ret = -ENOTSUP;
13296
13297         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13298
13299         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13300                 return;
13301
13302 #ifdef RTE_LIBRTE_IXGBE_PMD
13303         if (ret == -ENOTSUP)
13304                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13305 #endif
13306 #ifdef RTE_LIBRTE_I40E_PMD
13307         if (ret == -ENOTSUP)
13308                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13309 #endif
13310 #ifdef RTE_LIBRTE_BNXT_PMD
13311         if (ret == -ENOTSUP)
13312                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13313 #endif
13314 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13315         if (ret == -ENOTSUP)
13316                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13317 #endif
13318
13319         switch (ret) {
13320         case 0:
13321                 break;
13322         case -EINVAL:
13323                 printf("invalid is_on %d\n", is_on);
13324                 break;
13325         case -ENODEV:
13326                 printf("invalid port_id %d\n", res->port_id);
13327                 break;
13328         case -ENOTSUP:
13329                 printf("function not implemented\n");
13330                 break;
13331         default:
13332                 printf("programming error: (%s)\n", strerror(-ret));
13333         }
13334 }
13335
13336 cmdline_parse_inst_t cmd_set_tx_loopback = {
13337         .f = cmd_set_tx_loopback_parsed,
13338         .data = NULL,
13339         .help_str = "set tx loopback <port_id> on|off",
13340         .tokens = {
13341                 (void *)&cmd_tx_loopback_set,
13342                 (void *)&cmd_tx_loopback_tx,
13343                 (void *)&cmd_tx_loopback_loopback,
13344                 (void *)&cmd_tx_loopback_port_id,
13345                 (void *)&cmd_tx_loopback_on_off,
13346                 NULL,
13347         },
13348 };
13349
13350 /* all queues drop enable configuration */
13351
13352 /* Common result structure for all queues drop enable */
13353 struct cmd_all_queues_drop_en_result {
13354         cmdline_fixed_string_t set;
13355         cmdline_fixed_string_t all;
13356         cmdline_fixed_string_t queues;
13357         cmdline_fixed_string_t drop;
13358         portid_t port_id;
13359         cmdline_fixed_string_t on_off;
13360 };
13361
13362 /* Common CLI fields for tx loopback enable disable */
13363 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13364         TOKEN_STRING_INITIALIZER
13365                 (struct cmd_all_queues_drop_en_result,
13366                  set, "set");
13367 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13368         TOKEN_STRING_INITIALIZER
13369                 (struct cmd_all_queues_drop_en_result,
13370                  all, "all");
13371 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13372         TOKEN_STRING_INITIALIZER
13373                 (struct cmd_all_queues_drop_en_result,
13374                  queues, "queues");
13375 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13376         TOKEN_STRING_INITIALIZER
13377                 (struct cmd_all_queues_drop_en_result,
13378                  drop, "drop");
13379 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13380         TOKEN_NUM_INITIALIZER
13381                 (struct cmd_all_queues_drop_en_result,
13382                  port_id, UINT16);
13383 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13384         TOKEN_STRING_INITIALIZER
13385                 (struct cmd_all_queues_drop_en_result,
13386                  on_off, "on#off");
13387
13388 static void
13389 cmd_set_all_queues_drop_en_parsed(
13390         void *parsed_result,
13391         __attribute__((unused)) struct cmdline *cl,
13392         __attribute__((unused)) void *data)
13393 {
13394         struct cmd_all_queues_drop_en_result *res = parsed_result;
13395         int ret = -ENOTSUP;
13396         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13397
13398         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13399                 return;
13400
13401 #ifdef RTE_LIBRTE_IXGBE_PMD
13402         if (ret == -ENOTSUP)
13403                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13404 #endif
13405 #ifdef RTE_LIBRTE_BNXT_PMD
13406         if (ret == -ENOTSUP)
13407                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13408 #endif
13409         switch (ret) {
13410         case 0:
13411                 break;
13412         case -EINVAL:
13413                 printf("invalid is_on %d\n", is_on);
13414                 break;
13415         case -ENODEV:
13416                 printf("invalid port_id %d\n", res->port_id);
13417                 break;
13418         case -ENOTSUP:
13419                 printf("function not implemented\n");
13420                 break;
13421         default:
13422                 printf("programming error: (%s)\n", strerror(-ret));
13423         }
13424 }
13425
13426 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13427         .f = cmd_set_all_queues_drop_en_parsed,
13428         .data = NULL,
13429         .help_str = "set all queues drop <port_id> on|off",
13430         .tokens = {
13431                 (void *)&cmd_all_queues_drop_en_set,
13432                 (void *)&cmd_all_queues_drop_en_all,
13433                 (void *)&cmd_all_queues_drop_en_queues,
13434                 (void *)&cmd_all_queues_drop_en_drop,
13435                 (void *)&cmd_all_queues_drop_en_port_id,
13436                 (void *)&cmd_all_queues_drop_en_on_off,
13437                 NULL,
13438         },
13439 };
13440
13441 /* vf split drop enable configuration */
13442
13443 /* Common result structure for vf split drop enable */
13444 struct cmd_vf_split_drop_en_result {
13445         cmdline_fixed_string_t set;
13446         cmdline_fixed_string_t vf;
13447         cmdline_fixed_string_t split;
13448         cmdline_fixed_string_t drop;
13449         portid_t port_id;
13450         uint16_t vf_id;
13451         cmdline_fixed_string_t on_off;
13452 };
13453
13454 /* Common CLI fields for vf split drop enable disable */
13455 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13456         TOKEN_STRING_INITIALIZER
13457                 (struct cmd_vf_split_drop_en_result,
13458                  set, "set");
13459 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13460         TOKEN_STRING_INITIALIZER
13461                 (struct cmd_vf_split_drop_en_result,
13462                  vf, "vf");
13463 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13464         TOKEN_STRING_INITIALIZER
13465                 (struct cmd_vf_split_drop_en_result,
13466                  split, "split");
13467 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13468         TOKEN_STRING_INITIALIZER
13469                 (struct cmd_vf_split_drop_en_result,
13470                  drop, "drop");
13471 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13472         TOKEN_NUM_INITIALIZER
13473                 (struct cmd_vf_split_drop_en_result,
13474                  port_id, UINT16);
13475 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13476         TOKEN_NUM_INITIALIZER
13477                 (struct cmd_vf_split_drop_en_result,
13478                  vf_id, UINT16);
13479 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13480         TOKEN_STRING_INITIALIZER
13481                 (struct cmd_vf_split_drop_en_result,
13482                  on_off, "on#off");
13483
13484 static void
13485 cmd_set_vf_split_drop_en_parsed(
13486         void *parsed_result,
13487         __attribute__((unused)) struct cmdline *cl,
13488         __attribute__((unused)) void *data)
13489 {
13490         struct cmd_vf_split_drop_en_result *res = parsed_result;
13491         int ret = -ENOTSUP;
13492         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13493
13494         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13495                 return;
13496
13497 #ifdef RTE_LIBRTE_IXGBE_PMD
13498         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13499                         is_on);
13500 #endif
13501         switch (ret) {
13502         case 0:
13503                 break;
13504         case -EINVAL:
13505                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13506                 break;
13507         case -ENODEV:
13508                 printf("invalid port_id %d\n", res->port_id);
13509                 break;
13510         case -ENOTSUP:
13511                 printf("not supported on port %d\n", res->port_id);
13512                 break;
13513         default:
13514                 printf("programming error: (%s)\n", strerror(-ret));
13515         }
13516 }
13517
13518 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13519         .f = cmd_set_vf_split_drop_en_parsed,
13520         .data = NULL,
13521         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13522         .tokens = {
13523                 (void *)&cmd_vf_split_drop_en_set,
13524                 (void *)&cmd_vf_split_drop_en_vf,
13525                 (void *)&cmd_vf_split_drop_en_split,
13526                 (void *)&cmd_vf_split_drop_en_drop,
13527                 (void *)&cmd_vf_split_drop_en_port_id,
13528                 (void *)&cmd_vf_split_drop_en_vf_id,
13529                 (void *)&cmd_vf_split_drop_en_on_off,
13530                 NULL,
13531         },
13532 };
13533
13534 /* vf mac address configuration */
13535
13536 /* Common result structure for vf mac address */
13537 struct cmd_set_vf_mac_addr_result {
13538         cmdline_fixed_string_t set;
13539         cmdline_fixed_string_t vf;
13540         cmdline_fixed_string_t mac;
13541         cmdline_fixed_string_t addr;
13542         portid_t port_id;
13543         uint16_t vf_id;
13544         struct ether_addr mac_addr;
13545
13546 };
13547
13548 /* Common CLI fields for vf split drop enable disable */
13549 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13550         TOKEN_STRING_INITIALIZER
13551                 (struct cmd_set_vf_mac_addr_result,
13552                  set, "set");
13553 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13554         TOKEN_STRING_INITIALIZER
13555                 (struct cmd_set_vf_mac_addr_result,
13556                  vf, "vf");
13557 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13558         TOKEN_STRING_INITIALIZER
13559                 (struct cmd_set_vf_mac_addr_result,
13560                  mac, "mac");
13561 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13562         TOKEN_STRING_INITIALIZER
13563                 (struct cmd_set_vf_mac_addr_result,
13564                  addr, "addr");
13565 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13566         TOKEN_NUM_INITIALIZER
13567                 (struct cmd_set_vf_mac_addr_result,
13568                  port_id, UINT16);
13569 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13570         TOKEN_NUM_INITIALIZER
13571                 (struct cmd_set_vf_mac_addr_result,
13572                  vf_id, UINT16);
13573 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13574         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13575                  mac_addr);
13576
13577 static void
13578 cmd_set_vf_mac_addr_parsed(
13579         void *parsed_result,
13580         __attribute__((unused)) struct cmdline *cl,
13581         __attribute__((unused)) void *data)
13582 {
13583         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13584         int ret = -ENOTSUP;
13585
13586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13587                 return;
13588
13589 #ifdef RTE_LIBRTE_IXGBE_PMD
13590         if (ret == -ENOTSUP)
13591                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13592                                 &res->mac_addr);
13593 #endif
13594 #ifdef RTE_LIBRTE_I40E_PMD
13595         if (ret == -ENOTSUP)
13596                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13597                                 &res->mac_addr);
13598 #endif
13599 #ifdef RTE_LIBRTE_BNXT_PMD
13600         if (ret == -ENOTSUP)
13601                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13602                                 &res->mac_addr);
13603 #endif
13604
13605         switch (ret) {
13606         case 0:
13607                 break;
13608         case -EINVAL:
13609                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13610                 break;
13611         case -ENODEV:
13612                 printf("invalid port_id %d\n", res->port_id);
13613                 break;
13614         case -ENOTSUP:
13615                 printf("function not implemented\n");
13616                 break;
13617         default:
13618                 printf("programming error: (%s)\n", strerror(-ret));
13619         }
13620 }
13621
13622 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13623         .f = cmd_set_vf_mac_addr_parsed,
13624         .data = NULL,
13625         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13626         .tokens = {
13627                 (void *)&cmd_set_vf_mac_addr_set,
13628                 (void *)&cmd_set_vf_mac_addr_vf,
13629                 (void *)&cmd_set_vf_mac_addr_mac,
13630                 (void *)&cmd_set_vf_mac_addr_addr,
13631                 (void *)&cmd_set_vf_mac_addr_port_id,
13632                 (void *)&cmd_set_vf_mac_addr_vf_id,
13633                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13634                 NULL,
13635         },
13636 };
13637
13638 /* MACsec configuration */
13639
13640 /* Common result structure for MACsec offload enable */
13641 struct cmd_macsec_offload_on_result {
13642         cmdline_fixed_string_t set;
13643         cmdline_fixed_string_t macsec;
13644         cmdline_fixed_string_t offload;
13645         portid_t port_id;
13646         cmdline_fixed_string_t on;
13647         cmdline_fixed_string_t encrypt;
13648         cmdline_fixed_string_t en_on_off;
13649         cmdline_fixed_string_t replay_protect;
13650         cmdline_fixed_string_t rp_on_off;
13651 };
13652
13653 /* Common CLI fields for MACsec offload disable */
13654 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13655         TOKEN_STRING_INITIALIZER
13656                 (struct cmd_macsec_offload_on_result,
13657                  set, "set");
13658 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13659         TOKEN_STRING_INITIALIZER
13660                 (struct cmd_macsec_offload_on_result,
13661                  macsec, "macsec");
13662 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13663         TOKEN_STRING_INITIALIZER
13664                 (struct cmd_macsec_offload_on_result,
13665                  offload, "offload");
13666 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13667         TOKEN_NUM_INITIALIZER
13668                 (struct cmd_macsec_offload_on_result,
13669                  port_id, UINT16);
13670 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13671         TOKEN_STRING_INITIALIZER
13672                 (struct cmd_macsec_offload_on_result,
13673                  on, "on");
13674 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13675         TOKEN_STRING_INITIALIZER
13676                 (struct cmd_macsec_offload_on_result,
13677                  encrypt, "encrypt");
13678 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13679         TOKEN_STRING_INITIALIZER
13680                 (struct cmd_macsec_offload_on_result,
13681                  en_on_off, "on#off");
13682 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13683         TOKEN_STRING_INITIALIZER
13684                 (struct cmd_macsec_offload_on_result,
13685                  replay_protect, "replay-protect");
13686 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13687         TOKEN_STRING_INITIALIZER
13688                 (struct cmd_macsec_offload_on_result,
13689                  rp_on_off, "on#off");
13690
13691 static void
13692 cmd_set_macsec_offload_on_parsed(
13693         void *parsed_result,
13694         __attribute__((unused)) struct cmdline *cl,
13695         __attribute__((unused)) void *data)
13696 {
13697         struct cmd_macsec_offload_on_result *res = parsed_result;
13698         int ret = -ENOTSUP;
13699         portid_t port_id = res->port_id;
13700         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13701         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13702         struct rte_eth_dev_info dev_info;
13703
13704         if (port_id_is_invalid(port_id, ENABLED_WARN))
13705                 return;
13706         if (!port_is_stopped(port_id)) {
13707                 printf("Please stop port %d first\n", port_id);
13708                 return;
13709         }
13710
13711         rte_eth_dev_info_get(port_id, &dev_info);
13712         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13713 #ifdef RTE_LIBRTE_IXGBE_PMD
13714                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13715 #endif
13716         }
13717         RTE_SET_USED(en);
13718         RTE_SET_USED(rp);
13719
13720         switch (ret) {
13721         case 0:
13722                 ports[port_id].dev_conf.txmode.offloads |=
13723                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13724                 cmd_reconfig_device_queue(port_id, 1, 1);
13725                 break;
13726         case -ENODEV:
13727                 printf("invalid port_id %d\n", port_id);
13728                 break;
13729         case -ENOTSUP:
13730                 printf("not supported on port %d\n", port_id);
13731                 break;
13732         default:
13733                 printf("programming error: (%s)\n", strerror(-ret));
13734         }
13735 }
13736
13737 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13738         .f = cmd_set_macsec_offload_on_parsed,
13739         .data = NULL,
13740         .help_str = "set macsec offload <port_id> on "
13741                 "encrypt on|off replay-protect on|off",
13742         .tokens = {
13743                 (void *)&cmd_macsec_offload_on_set,
13744                 (void *)&cmd_macsec_offload_on_macsec,
13745                 (void *)&cmd_macsec_offload_on_offload,
13746                 (void *)&cmd_macsec_offload_on_port_id,
13747                 (void *)&cmd_macsec_offload_on_on,
13748                 (void *)&cmd_macsec_offload_on_encrypt,
13749                 (void *)&cmd_macsec_offload_on_en_on_off,
13750                 (void *)&cmd_macsec_offload_on_replay_protect,
13751                 (void *)&cmd_macsec_offload_on_rp_on_off,
13752                 NULL,
13753         },
13754 };
13755
13756 /* Common result structure for MACsec offload disable */
13757 struct cmd_macsec_offload_off_result {
13758         cmdline_fixed_string_t set;
13759         cmdline_fixed_string_t macsec;
13760         cmdline_fixed_string_t offload;
13761         portid_t port_id;
13762         cmdline_fixed_string_t off;
13763 };
13764
13765 /* Common CLI fields for MACsec offload disable */
13766 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_macsec_offload_off_result,
13769                  set, "set");
13770 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_macsec_offload_off_result,
13773                  macsec, "macsec");
13774 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13775         TOKEN_STRING_INITIALIZER
13776                 (struct cmd_macsec_offload_off_result,
13777                  offload, "offload");
13778 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13779         TOKEN_NUM_INITIALIZER
13780                 (struct cmd_macsec_offload_off_result,
13781                  port_id, UINT16);
13782 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13783         TOKEN_STRING_INITIALIZER
13784                 (struct cmd_macsec_offload_off_result,
13785                  off, "off");
13786
13787 static void
13788 cmd_set_macsec_offload_off_parsed(
13789         void *parsed_result,
13790         __attribute__((unused)) struct cmdline *cl,
13791         __attribute__((unused)) void *data)
13792 {
13793         struct cmd_macsec_offload_off_result *res = parsed_result;
13794         int ret = -ENOTSUP;
13795         struct rte_eth_dev_info dev_info;
13796         portid_t port_id = res->port_id;
13797
13798         if (port_id_is_invalid(port_id, ENABLED_WARN))
13799                 return;
13800         if (!port_is_stopped(port_id)) {
13801                 printf("Please stop port %d first\n", port_id);
13802                 return;
13803         }
13804
13805         rte_eth_dev_info_get(port_id, &dev_info);
13806         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13807 #ifdef RTE_LIBRTE_IXGBE_PMD
13808                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13809 #endif
13810         }
13811         switch (ret) {
13812         case 0:
13813                 ports[port_id].dev_conf.txmode.offloads &=
13814                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13815                 cmd_reconfig_device_queue(port_id, 1, 1);
13816                 break;
13817         case -ENODEV:
13818                 printf("invalid port_id %d\n", port_id);
13819                 break;
13820         case -ENOTSUP:
13821                 printf("not supported on port %d\n", port_id);
13822                 break;
13823         default:
13824                 printf("programming error: (%s)\n", strerror(-ret));
13825         }
13826 }
13827
13828 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13829         .f = cmd_set_macsec_offload_off_parsed,
13830         .data = NULL,
13831         .help_str = "set macsec offload <port_id> off",
13832         .tokens = {
13833                 (void *)&cmd_macsec_offload_off_set,
13834                 (void *)&cmd_macsec_offload_off_macsec,
13835                 (void *)&cmd_macsec_offload_off_offload,
13836                 (void *)&cmd_macsec_offload_off_port_id,
13837                 (void *)&cmd_macsec_offload_off_off,
13838                 NULL,
13839         },
13840 };
13841
13842 /* Common result structure for MACsec secure connection configure */
13843 struct cmd_macsec_sc_result {
13844         cmdline_fixed_string_t set;
13845         cmdline_fixed_string_t macsec;
13846         cmdline_fixed_string_t sc;
13847         cmdline_fixed_string_t tx_rx;
13848         portid_t port_id;
13849         struct ether_addr mac;
13850         uint16_t pi;
13851 };
13852
13853 /* Common CLI fields for MACsec secure connection configure */
13854 cmdline_parse_token_string_t cmd_macsec_sc_set =
13855         TOKEN_STRING_INITIALIZER
13856                 (struct cmd_macsec_sc_result,
13857                  set, "set");
13858 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13859         TOKEN_STRING_INITIALIZER
13860                 (struct cmd_macsec_sc_result,
13861                  macsec, "macsec");
13862 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_macsec_sc_result,
13865                  sc, "sc");
13866 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13867         TOKEN_STRING_INITIALIZER
13868                 (struct cmd_macsec_sc_result,
13869                  tx_rx, "tx#rx");
13870 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13871         TOKEN_NUM_INITIALIZER
13872                 (struct cmd_macsec_sc_result,
13873                  port_id, UINT16);
13874 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13875         TOKEN_ETHERADDR_INITIALIZER
13876                 (struct cmd_macsec_sc_result,
13877                  mac);
13878 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13879         TOKEN_NUM_INITIALIZER
13880                 (struct cmd_macsec_sc_result,
13881                  pi, UINT16);
13882
13883 static void
13884 cmd_set_macsec_sc_parsed(
13885         void *parsed_result,
13886         __attribute__((unused)) struct cmdline *cl,
13887         __attribute__((unused)) void *data)
13888 {
13889         struct cmd_macsec_sc_result *res = parsed_result;
13890         int ret = -ENOTSUP;
13891         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13892
13893 #ifdef RTE_LIBRTE_IXGBE_PMD
13894         ret = is_tx ?
13895                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13896                                 res->mac.addr_bytes) :
13897                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13898                                 res->mac.addr_bytes, res->pi);
13899 #endif
13900         RTE_SET_USED(is_tx);
13901
13902         switch (ret) {
13903         case 0:
13904                 break;
13905         case -ENODEV:
13906                 printf("invalid port_id %d\n", res->port_id);
13907                 break;
13908         case -ENOTSUP:
13909                 printf("not supported on port %d\n", res->port_id);
13910                 break;
13911         default:
13912                 printf("programming error: (%s)\n", strerror(-ret));
13913         }
13914 }
13915
13916 cmdline_parse_inst_t cmd_set_macsec_sc = {
13917         .f = cmd_set_macsec_sc_parsed,
13918         .data = NULL,
13919         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13920         .tokens = {
13921                 (void *)&cmd_macsec_sc_set,
13922                 (void *)&cmd_macsec_sc_macsec,
13923                 (void *)&cmd_macsec_sc_sc,
13924                 (void *)&cmd_macsec_sc_tx_rx,
13925                 (void *)&cmd_macsec_sc_port_id,
13926                 (void *)&cmd_macsec_sc_mac,
13927                 (void *)&cmd_macsec_sc_pi,
13928                 NULL,
13929         },
13930 };
13931
13932 /* Common result structure for MACsec secure connection configure */
13933 struct cmd_macsec_sa_result {
13934         cmdline_fixed_string_t set;
13935         cmdline_fixed_string_t macsec;
13936         cmdline_fixed_string_t sa;
13937         cmdline_fixed_string_t tx_rx;
13938         portid_t port_id;
13939         uint8_t idx;
13940         uint8_t an;
13941         uint32_t pn;
13942         cmdline_fixed_string_t key;
13943 };
13944
13945 /* Common CLI fields for MACsec secure connection configure */
13946 cmdline_parse_token_string_t cmd_macsec_sa_set =
13947         TOKEN_STRING_INITIALIZER
13948                 (struct cmd_macsec_sa_result,
13949                  set, "set");
13950 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13951         TOKEN_STRING_INITIALIZER
13952                 (struct cmd_macsec_sa_result,
13953                  macsec, "macsec");
13954 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13955         TOKEN_STRING_INITIALIZER
13956                 (struct cmd_macsec_sa_result,
13957                  sa, "sa");
13958 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13959         TOKEN_STRING_INITIALIZER
13960                 (struct cmd_macsec_sa_result,
13961                  tx_rx, "tx#rx");
13962 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13963         TOKEN_NUM_INITIALIZER
13964                 (struct cmd_macsec_sa_result,
13965                  port_id, UINT16);
13966 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13967         TOKEN_NUM_INITIALIZER
13968                 (struct cmd_macsec_sa_result,
13969                  idx, UINT8);
13970 cmdline_parse_token_num_t cmd_macsec_sa_an =
13971         TOKEN_NUM_INITIALIZER
13972                 (struct cmd_macsec_sa_result,
13973                  an, UINT8);
13974 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13975         TOKEN_NUM_INITIALIZER
13976                 (struct cmd_macsec_sa_result,
13977                  pn, UINT32);
13978 cmdline_parse_token_string_t cmd_macsec_sa_key =
13979         TOKEN_STRING_INITIALIZER
13980                 (struct cmd_macsec_sa_result,
13981                  key, NULL);
13982
13983 static void
13984 cmd_set_macsec_sa_parsed(
13985         void *parsed_result,
13986         __attribute__((unused)) struct cmdline *cl,
13987         __attribute__((unused)) void *data)
13988 {
13989         struct cmd_macsec_sa_result *res = parsed_result;
13990         int ret = -ENOTSUP;
13991         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13992         uint8_t key[16] = { 0 };
13993         uint8_t xdgt0;
13994         uint8_t xdgt1;
13995         int key_len;
13996         int i;
13997
13998         key_len = strlen(res->key) / 2;
13999         if (key_len > 16)
14000                 key_len = 16;
14001
14002         for (i = 0; i < key_len; i++) {
14003                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14004                 if (xdgt0 == 0xFF)
14005                         return;
14006                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14007                 if (xdgt1 == 0xFF)
14008                         return;
14009                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14010         }
14011
14012 #ifdef RTE_LIBRTE_IXGBE_PMD
14013         ret = is_tx ?
14014                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14015                         res->idx, res->an, res->pn, key) :
14016                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14017                         res->idx, res->an, res->pn, key);
14018 #endif
14019         RTE_SET_USED(is_tx);
14020         RTE_SET_USED(key);
14021
14022         switch (ret) {
14023         case 0:
14024                 break;
14025         case -EINVAL:
14026                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14027                 break;
14028         case -ENODEV:
14029                 printf("invalid port_id %d\n", res->port_id);
14030                 break;
14031         case -ENOTSUP:
14032                 printf("not supported on port %d\n", res->port_id);
14033                 break;
14034         default:
14035                 printf("programming error: (%s)\n", strerror(-ret));
14036         }
14037 }
14038
14039 cmdline_parse_inst_t cmd_set_macsec_sa = {
14040         .f = cmd_set_macsec_sa_parsed,
14041         .data = NULL,
14042         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14043         .tokens = {
14044                 (void *)&cmd_macsec_sa_set,
14045                 (void *)&cmd_macsec_sa_macsec,
14046                 (void *)&cmd_macsec_sa_sa,
14047                 (void *)&cmd_macsec_sa_tx_rx,
14048                 (void *)&cmd_macsec_sa_port_id,
14049                 (void *)&cmd_macsec_sa_idx,
14050                 (void *)&cmd_macsec_sa_an,
14051                 (void *)&cmd_macsec_sa_pn,
14052                 (void *)&cmd_macsec_sa_key,
14053                 NULL,
14054         },
14055 };
14056
14057 /* VF unicast promiscuous mode configuration */
14058
14059 /* Common result structure for VF unicast promiscuous mode */
14060 struct cmd_vf_promisc_result {
14061         cmdline_fixed_string_t set;
14062         cmdline_fixed_string_t vf;
14063         cmdline_fixed_string_t promisc;
14064         portid_t port_id;
14065         uint32_t vf_id;
14066         cmdline_fixed_string_t on_off;
14067 };
14068
14069 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14070 cmdline_parse_token_string_t cmd_vf_promisc_set =
14071         TOKEN_STRING_INITIALIZER
14072                 (struct cmd_vf_promisc_result,
14073                  set, "set");
14074 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14075         TOKEN_STRING_INITIALIZER
14076                 (struct cmd_vf_promisc_result,
14077                  vf, "vf");
14078 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14079         TOKEN_STRING_INITIALIZER
14080                 (struct cmd_vf_promisc_result,
14081                  promisc, "promisc");
14082 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14083         TOKEN_NUM_INITIALIZER
14084                 (struct cmd_vf_promisc_result,
14085                  port_id, UINT16);
14086 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14087         TOKEN_NUM_INITIALIZER
14088                 (struct cmd_vf_promisc_result,
14089                  vf_id, UINT32);
14090 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14091         TOKEN_STRING_INITIALIZER
14092                 (struct cmd_vf_promisc_result,
14093                  on_off, "on#off");
14094
14095 static void
14096 cmd_set_vf_promisc_parsed(
14097         void *parsed_result,
14098         __attribute__((unused)) struct cmdline *cl,
14099         __attribute__((unused)) void *data)
14100 {
14101         struct cmd_vf_promisc_result *res = parsed_result;
14102         int ret = -ENOTSUP;
14103
14104         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14105
14106         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14107                 return;
14108
14109 #ifdef RTE_LIBRTE_I40E_PMD
14110         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14111                                                   res->vf_id, is_on);
14112 #endif
14113
14114         switch (ret) {
14115         case 0:
14116                 break;
14117         case -EINVAL:
14118                 printf("invalid vf_id %d\n", res->vf_id);
14119                 break;
14120         case -ENODEV:
14121                 printf("invalid port_id %d\n", res->port_id);
14122                 break;
14123         case -ENOTSUP:
14124                 printf("function not implemented\n");
14125                 break;
14126         default:
14127                 printf("programming error: (%s)\n", strerror(-ret));
14128         }
14129 }
14130
14131 cmdline_parse_inst_t cmd_set_vf_promisc = {
14132         .f = cmd_set_vf_promisc_parsed,
14133         .data = NULL,
14134         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14135                 "Set unicast promiscuous mode for a VF from the PF",
14136         .tokens = {
14137                 (void *)&cmd_vf_promisc_set,
14138                 (void *)&cmd_vf_promisc_vf,
14139                 (void *)&cmd_vf_promisc_promisc,
14140                 (void *)&cmd_vf_promisc_port_id,
14141                 (void *)&cmd_vf_promisc_vf_id,
14142                 (void *)&cmd_vf_promisc_on_off,
14143                 NULL,
14144         },
14145 };
14146
14147 /* VF multicast promiscuous mode configuration */
14148
14149 /* Common result structure for VF multicast promiscuous mode */
14150 struct cmd_vf_allmulti_result {
14151         cmdline_fixed_string_t set;
14152         cmdline_fixed_string_t vf;
14153         cmdline_fixed_string_t allmulti;
14154         portid_t port_id;
14155         uint32_t vf_id;
14156         cmdline_fixed_string_t on_off;
14157 };
14158
14159 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14160 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14161         TOKEN_STRING_INITIALIZER
14162                 (struct cmd_vf_allmulti_result,
14163                  set, "set");
14164 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14165         TOKEN_STRING_INITIALIZER
14166                 (struct cmd_vf_allmulti_result,
14167                  vf, "vf");
14168 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14169         TOKEN_STRING_INITIALIZER
14170                 (struct cmd_vf_allmulti_result,
14171                  allmulti, "allmulti");
14172 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14173         TOKEN_NUM_INITIALIZER
14174                 (struct cmd_vf_allmulti_result,
14175                  port_id, UINT16);
14176 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14177         TOKEN_NUM_INITIALIZER
14178                 (struct cmd_vf_allmulti_result,
14179                  vf_id, UINT32);
14180 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14181         TOKEN_STRING_INITIALIZER
14182                 (struct cmd_vf_allmulti_result,
14183                  on_off, "on#off");
14184
14185 static void
14186 cmd_set_vf_allmulti_parsed(
14187         void *parsed_result,
14188         __attribute__((unused)) struct cmdline *cl,
14189         __attribute__((unused)) void *data)
14190 {
14191         struct cmd_vf_allmulti_result *res = parsed_result;
14192         int ret = -ENOTSUP;
14193
14194         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14195
14196         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14197                 return;
14198
14199 #ifdef RTE_LIBRTE_I40E_PMD
14200         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14201                                                     res->vf_id, is_on);
14202 #endif
14203
14204         switch (ret) {
14205         case 0:
14206                 break;
14207         case -EINVAL:
14208                 printf("invalid vf_id %d\n", res->vf_id);
14209                 break;
14210         case -ENODEV:
14211                 printf("invalid port_id %d\n", res->port_id);
14212                 break;
14213         case -ENOTSUP:
14214                 printf("function not implemented\n");
14215                 break;
14216         default:
14217                 printf("programming error: (%s)\n", strerror(-ret));
14218         }
14219 }
14220
14221 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14222         .f = cmd_set_vf_allmulti_parsed,
14223         .data = NULL,
14224         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14225                 "Set multicast promiscuous mode for a VF from the PF",
14226         .tokens = {
14227                 (void *)&cmd_vf_allmulti_set,
14228                 (void *)&cmd_vf_allmulti_vf,
14229                 (void *)&cmd_vf_allmulti_allmulti,
14230                 (void *)&cmd_vf_allmulti_port_id,
14231                 (void *)&cmd_vf_allmulti_vf_id,
14232                 (void *)&cmd_vf_allmulti_on_off,
14233                 NULL,
14234         },
14235 };
14236
14237 /* vf broadcast mode configuration */
14238
14239 /* Common result structure for vf broadcast */
14240 struct cmd_set_vf_broadcast_result {
14241         cmdline_fixed_string_t set;
14242         cmdline_fixed_string_t vf;
14243         cmdline_fixed_string_t broadcast;
14244         portid_t port_id;
14245         uint16_t vf_id;
14246         cmdline_fixed_string_t on_off;
14247 };
14248
14249 /* Common CLI fields for vf broadcast enable disable */
14250 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14251         TOKEN_STRING_INITIALIZER
14252                 (struct cmd_set_vf_broadcast_result,
14253                  set, "set");
14254 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14255         TOKEN_STRING_INITIALIZER
14256                 (struct cmd_set_vf_broadcast_result,
14257                  vf, "vf");
14258 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14259         TOKEN_STRING_INITIALIZER
14260                 (struct cmd_set_vf_broadcast_result,
14261                  broadcast, "broadcast");
14262 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14263         TOKEN_NUM_INITIALIZER
14264                 (struct cmd_set_vf_broadcast_result,
14265                  port_id, UINT16);
14266 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14267         TOKEN_NUM_INITIALIZER
14268                 (struct cmd_set_vf_broadcast_result,
14269                  vf_id, UINT16);
14270 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14271         TOKEN_STRING_INITIALIZER
14272                 (struct cmd_set_vf_broadcast_result,
14273                  on_off, "on#off");
14274
14275 static void
14276 cmd_set_vf_broadcast_parsed(
14277         void *parsed_result,
14278         __attribute__((unused)) struct cmdline *cl,
14279         __attribute__((unused)) void *data)
14280 {
14281         struct cmd_set_vf_broadcast_result *res = parsed_result;
14282         int ret = -ENOTSUP;
14283
14284         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14285
14286         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14287                 return;
14288
14289 #ifdef RTE_LIBRTE_I40E_PMD
14290         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14291                                             res->vf_id, is_on);
14292 #endif
14293
14294         switch (ret) {
14295         case 0:
14296                 break;
14297         case -EINVAL:
14298                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14299                 break;
14300         case -ENODEV:
14301                 printf("invalid port_id %d\n", res->port_id);
14302                 break;
14303         case -ENOTSUP:
14304                 printf("function not implemented\n");
14305                 break;
14306         default:
14307                 printf("programming error: (%s)\n", strerror(-ret));
14308         }
14309 }
14310
14311 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14312         .f = cmd_set_vf_broadcast_parsed,
14313         .data = NULL,
14314         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14315         .tokens = {
14316                 (void *)&cmd_set_vf_broadcast_set,
14317                 (void *)&cmd_set_vf_broadcast_vf,
14318                 (void *)&cmd_set_vf_broadcast_broadcast,
14319                 (void *)&cmd_set_vf_broadcast_port_id,
14320                 (void *)&cmd_set_vf_broadcast_vf_id,
14321                 (void *)&cmd_set_vf_broadcast_on_off,
14322                 NULL,
14323         },
14324 };
14325
14326 /* vf vlan tag configuration */
14327
14328 /* Common result structure for vf vlan tag */
14329 struct cmd_set_vf_vlan_tag_result {
14330         cmdline_fixed_string_t set;
14331         cmdline_fixed_string_t vf;
14332         cmdline_fixed_string_t vlan;
14333         cmdline_fixed_string_t tag;
14334         portid_t port_id;
14335         uint16_t vf_id;
14336         cmdline_fixed_string_t on_off;
14337 };
14338
14339 /* Common CLI fields for vf vlan tag enable disable */
14340 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14341         TOKEN_STRING_INITIALIZER
14342                 (struct cmd_set_vf_vlan_tag_result,
14343                  set, "set");
14344 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14345         TOKEN_STRING_INITIALIZER
14346                 (struct cmd_set_vf_vlan_tag_result,
14347                  vf, "vf");
14348 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14349         TOKEN_STRING_INITIALIZER
14350                 (struct cmd_set_vf_vlan_tag_result,
14351                  vlan, "vlan");
14352 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14353         TOKEN_STRING_INITIALIZER
14354                 (struct cmd_set_vf_vlan_tag_result,
14355                  tag, "tag");
14356 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14357         TOKEN_NUM_INITIALIZER
14358                 (struct cmd_set_vf_vlan_tag_result,
14359                  port_id, UINT16);
14360 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14361         TOKEN_NUM_INITIALIZER
14362                 (struct cmd_set_vf_vlan_tag_result,
14363                  vf_id, UINT16);
14364 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14365         TOKEN_STRING_INITIALIZER
14366                 (struct cmd_set_vf_vlan_tag_result,
14367                  on_off, "on#off");
14368
14369 static void
14370 cmd_set_vf_vlan_tag_parsed(
14371         void *parsed_result,
14372         __attribute__((unused)) struct cmdline *cl,
14373         __attribute__((unused)) void *data)
14374 {
14375         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14376         int ret = -ENOTSUP;
14377
14378         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14379
14380         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14381                 return;
14382
14383 #ifdef RTE_LIBRTE_I40E_PMD
14384         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14385                                            res->vf_id, is_on);
14386 #endif
14387
14388         switch (ret) {
14389         case 0:
14390                 break;
14391         case -EINVAL:
14392                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14393                 break;
14394         case -ENODEV:
14395                 printf("invalid port_id %d\n", res->port_id);
14396                 break;
14397         case -ENOTSUP:
14398                 printf("function not implemented\n");
14399                 break;
14400         default:
14401                 printf("programming error: (%s)\n", strerror(-ret));
14402         }
14403 }
14404
14405 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14406         .f = cmd_set_vf_vlan_tag_parsed,
14407         .data = NULL,
14408         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14409         .tokens = {
14410                 (void *)&cmd_set_vf_vlan_tag_set,
14411                 (void *)&cmd_set_vf_vlan_tag_vf,
14412                 (void *)&cmd_set_vf_vlan_tag_vlan,
14413                 (void *)&cmd_set_vf_vlan_tag_tag,
14414                 (void *)&cmd_set_vf_vlan_tag_port_id,
14415                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14416                 (void *)&cmd_set_vf_vlan_tag_on_off,
14417                 NULL,
14418         },
14419 };
14420
14421 /* Common definition of VF and TC TX bandwidth configuration */
14422 struct cmd_vf_tc_bw_result {
14423         cmdline_fixed_string_t set;
14424         cmdline_fixed_string_t vf;
14425         cmdline_fixed_string_t tc;
14426         cmdline_fixed_string_t tx;
14427         cmdline_fixed_string_t min_bw;
14428         cmdline_fixed_string_t max_bw;
14429         cmdline_fixed_string_t strict_link_prio;
14430         portid_t port_id;
14431         uint16_t vf_id;
14432         uint8_t tc_no;
14433         uint32_t bw;
14434         cmdline_fixed_string_t bw_list;
14435         uint8_t tc_map;
14436 };
14437
14438 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14439         TOKEN_STRING_INITIALIZER
14440                 (struct cmd_vf_tc_bw_result,
14441                  set, "set");
14442 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14443         TOKEN_STRING_INITIALIZER
14444                 (struct cmd_vf_tc_bw_result,
14445                  vf, "vf");
14446 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14447         TOKEN_STRING_INITIALIZER
14448                 (struct cmd_vf_tc_bw_result,
14449                  tc, "tc");
14450 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14451         TOKEN_STRING_INITIALIZER
14452                 (struct cmd_vf_tc_bw_result,
14453                  tx, "tx");
14454 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14455         TOKEN_STRING_INITIALIZER
14456                 (struct cmd_vf_tc_bw_result,
14457                  strict_link_prio, "strict-link-priority");
14458 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14459         TOKEN_STRING_INITIALIZER
14460                 (struct cmd_vf_tc_bw_result,
14461                  min_bw, "min-bandwidth");
14462 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14463         TOKEN_STRING_INITIALIZER
14464                 (struct cmd_vf_tc_bw_result,
14465                  max_bw, "max-bandwidth");
14466 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14467         TOKEN_NUM_INITIALIZER
14468                 (struct cmd_vf_tc_bw_result,
14469                  port_id, UINT16);
14470 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14471         TOKEN_NUM_INITIALIZER
14472                 (struct cmd_vf_tc_bw_result,
14473                  vf_id, UINT16);
14474 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14475         TOKEN_NUM_INITIALIZER
14476                 (struct cmd_vf_tc_bw_result,
14477                  tc_no, UINT8);
14478 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14479         TOKEN_NUM_INITIALIZER
14480                 (struct cmd_vf_tc_bw_result,
14481                  bw, UINT32);
14482 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14483         TOKEN_STRING_INITIALIZER
14484                 (struct cmd_vf_tc_bw_result,
14485                  bw_list, NULL);
14486 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14487         TOKEN_NUM_INITIALIZER
14488                 (struct cmd_vf_tc_bw_result,
14489                  tc_map, UINT8);
14490
14491 /* VF max bandwidth setting */
14492 static void
14493 cmd_vf_max_bw_parsed(
14494         void *parsed_result,
14495         __attribute__((unused)) struct cmdline *cl,
14496         __attribute__((unused)) void *data)
14497 {
14498         struct cmd_vf_tc_bw_result *res = parsed_result;
14499         int ret = -ENOTSUP;
14500
14501         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14502                 return;
14503
14504 #ifdef RTE_LIBRTE_I40E_PMD
14505         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14506                                          res->vf_id, res->bw);
14507 #endif
14508
14509         switch (ret) {
14510         case 0:
14511                 break;
14512         case -EINVAL:
14513                 printf("invalid vf_id %d or bandwidth %d\n",
14514                        res->vf_id, res->bw);
14515                 break;
14516         case -ENODEV:
14517                 printf("invalid port_id %d\n", res->port_id);
14518                 break;
14519         case -ENOTSUP:
14520                 printf("function not implemented\n");
14521                 break;
14522         default:
14523                 printf("programming error: (%s)\n", strerror(-ret));
14524         }
14525 }
14526
14527 cmdline_parse_inst_t cmd_vf_max_bw = {
14528         .f = cmd_vf_max_bw_parsed,
14529         .data = NULL,
14530         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14531         .tokens = {
14532                 (void *)&cmd_vf_tc_bw_set,
14533                 (void *)&cmd_vf_tc_bw_vf,
14534                 (void *)&cmd_vf_tc_bw_tx,
14535                 (void *)&cmd_vf_tc_bw_max_bw,
14536                 (void *)&cmd_vf_tc_bw_port_id,
14537                 (void *)&cmd_vf_tc_bw_vf_id,
14538                 (void *)&cmd_vf_tc_bw_bw,
14539                 NULL,
14540         },
14541 };
14542
14543 static int
14544 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14545                            uint8_t *tc_num,
14546                            char *str)
14547 {
14548         uint32_t size;
14549         const char *p, *p0 = str;
14550         char s[256];
14551         char *end;
14552         char *str_fld[16];
14553         uint16_t i;
14554         int ret;
14555
14556         p = strchr(p0, '(');
14557         if (p == NULL) {
14558                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14559                 return -1;
14560         }
14561         p++;
14562         p0 = strchr(p, ')');
14563         if (p0 == NULL) {
14564                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14565                 return -1;
14566         }
14567         size = p0 - p;
14568         if (size >= sizeof(s)) {
14569                 printf("The string size exceeds the internal buffer size\n");
14570                 return -1;
14571         }
14572         snprintf(s, sizeof(s), "%.*s", size, p);
14573         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14574         if (ret <= 0) {
14575                 printf("Failed to get the bandwidth list. ");
14576                 return -1;
14577         }
14578         *tc_num = ret;
14579         for (i = 0; i < ret; i++)
14580                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14581
14582         return 0;
14583 }
14584
14585 /* TC min bandwidth setting */
14586 static void
14587 cmd_vf_tc_min_bw_parsed(
14588         void *parsed_result,
14589         __attribute__((unused)) struct cmdline *cl,
14590         __attribute__((unused)) void *data)
14591 {
14592         struct cmd_vf_tc_bw_result *res = parsed_result;
14593         uint8_t tc_num;
14594         uint8_t bw[16];
14595         int ret = -ENOTSUP;
14596
14597         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14598                 return;
14599
14600         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14601         if (ret)
14602                 return;
14603
14604 #ifdef RTE_LIBRTE_I40E_PMD
14605         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14606                                               tc_num, bw);
14607 #endif
14608
14609         switch (ret) {
14610         case 0:
14611                 break;
14612         case -EINVAL:
14613                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14614                 break;
14615         case -ENODEV:
14616                 printf("invalid port_id %d\n", res->port_id);
14617                 break;
14618         case -ENOTSUP:
14619                 printf("function not implemented\n");
14620                 break;
14621         default:
14622                 printf("programming error: (%s)\n", strerror(-ret));
14623         }
14624 }
14625
14626 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14627         .f = cmd_vf_tc_min_bw_parsed,
14628         .data = NULL,
14629         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14630                     " <bw1, bw2, ...>",
14631         .tokens = {
14632                 (void *)&cmd_vf_tc_bw_set,
14633                 (void *)&cmd_vf_tc_bw_vf,
14634                 (void *)&cmd_vf_tc_bw_tc,
14635                 (void *)&cmd_vf_tc_bw_tx,
14636                 (void *)&cmd_vf_tc_bw_min_bw,
14637                 (void *)&cmd_vf_tc_bw_port_id,
14638                 (void *)&cmd_vf_tc_bw_vf_id,
14639                 (void *)&cmd_vf_tc_bw_bw_list,
14640                 NULL,
14641         },
14642 };
14643
14644 static void
14645 cmd_tc_min_bw_parsed(
14646         void *parsed_result,
14647         __attribute__((unused)) struct cmdline *cl,
14648         __attribute__((unused)) void *data)
14649 {
14650         struct cmd_vf_tc_bw_result *res = parsed_result;
14651         struct rte_port *port;
14652         uint8_t tc_num;
14653         uint8_t bw[16];
14654         int ret = -ENOTSUP;
14655
14656         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14657                 return;
14658
14659         port = &ports[res->port_id];
14660         /** Check if the port is not started **/
14661         if (port->port_status != RTE_PORT_STOPPED) {
14662                 printf("Please stop port %d first\n", res->port_id);
14663                 return;
14664         }
14665
14666         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14667         if (ret)
14668                 return;
14669
14670 #ifdef RTE_LIBRTE_IXGBE_PMD
14671         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14672 #endif
14673
14674         switch (ret) {
14675         case 0:
14676                 break;
14677         case -EINVAL:
14678                 printf("invalid bandwidth\n");
14679                 break;
14680         case -ENODEV:
14681                 printf("invalid port_id %d\n", res->port_id);
14682                 break;
14683         case -ENOTSUP:
14684                 printf("function not implemented\n");
14685                 break;
14686         default:
14687                 printf("programming error: (%s)\n", strerror(-ret));
14688         }
14689 }
14690
14691 cmdline_parse_inst_t cmd_tc_min_bw = {
14692         .f = cmd_tc_min_bw_parsed,
14693         .data = NULL,
14694         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14695         .tokens = {
14696                 (void *)&cmd_vf_tc_bw_set,
14697                 (void *)&cmd_vf_tc_bw_tc,
14698                 (void *)&cmd_vf_tc_bw_tx,
14699                 (void *)&cmd_vf_tc_bw_min_bw,
14700                 (void *)&cmd_vf_tc_bw_port_id,
14701                 (void *)&cmd_vf_tc_bw_bw_list,
14702                 NULL,
14703         },
14704 };
14705
14706 /* TC max bandwidth setting */
14707 static void
14708 cmd_vf_tc_max_bw_parsed(
14709         void *parsed_result,
14710         __attribute__((unused)) struct cmdline *cl,
14711         __attribute__((unused)) void *data)
14712 {
14713         struct cmd_vf_tc_bw_result *res = parsed_result;
14714         int ret = -ENOTSUP;
14715
14716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14717                 return;
14718
14719 #ifdef RTE_LIBRTE_I40E_PMD
14720         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14721                                             res->tc_no, res->bw);
14722 #endif
14723
14724         switch (ret) {
14725         case 0:
14726                 break;
14727         case -EINVAL:
14728                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14729                        res->vf_id, res->tc_no, res->bw);
14730                 break;
14731         case -ENODEV:
14732                 printf("invalid port_id %d\n", res->port_id);
14733                 break;
14734         case -ENOTSUP:
14735                 printf("function not implemented\n");
14736                 break;
14737         default:
14738                 printf("programming error: (%s)\n", strerror(-ret));
14739         }
14740 }
14741
14742 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14743         .f = cmd_vf_tc_max_bw_parsed,
14744         .data = NULL,
14745         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14746                     " <bandwidth>",
14747         .tokens = {
14748                 (void *)&cmd_vf_tc_bw_set,
14749                 (void *)&cmd_vf_tc_bw_vf,
14750                 (void *)&cmd_vf_tc_bw_tc,
14751                 (void *)&cmd_vf_tc_bw_tx,
14752                 (void *)&cmd_vf_tc_bw_max_bw,
14753                 (void *)&cmd_vf_tc_bw_port_id,
14754                 (void *)&cmd_vf_tc_bw_vf_id,
14755                 (void *)&cmd_vf_tc_bw_tc_no,
14756                 (void *)&cmd_vf_tc_bw_bw,
14757                 NULL,
14758         },
14759 };
14760
14761
14762 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14763
14764 /* *** Set Port default Traffic Management Hierarchy *** */
14765 struct cmd_set_port_tm_hierarchy_default_result {
14766         cmdline_fixed_string_t set;
14767         cmdline_fixed_string_t port;
14768         cmdline_fixed_string_t tm;
14769         cmdline_fixed_string_t hierarchy;
14770         cmdline_fixed_string_t def;
14771         portid_t port_id;
14772 };
14773
14774 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14775         TOKEN_STRING_INITIALIZER(
14776                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14777 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14778         TOKEN_STRING_INITIALIZER(
14779                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14780 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14781         TOKEN_STRING_INITIALIZER(
14782                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14783 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14784         TOKEN_STRING_INITIALIZER(
14785                 struct cmd_set_port_tm_hierarchy_default_result,
14786                         hierarchy, "hierarchy");
14787 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14788         TOKEN_STRING_INITIALIZER(
14789                 struct cmd_set_port_tm_hierarchy_default_result,
14790                         def, "default");
14791 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14792         TOKEN_NUM_INITIALIZER(
14793                 struct cmd_set_port_tm_hierarchy_default_result,
14794                         port_id, UINT16);
14795
14796 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14797         __attribute__((unused)) struct cmdline *cl,
14798         __attribute__((unused)) void *data)
14799 {
14800         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14801         struct rte_port *p;
14802         portid_t port_id = res->port_id;
14803
14804         if (port_id_is_invalid(port_id, ENABLED_WARN))
14805                 return;
14806
14807         p = &ports[port_id];
14808
14809         /* Port tm flag */
14810         if (p->softport.tm_flag == 0) {
14811                 printf("  tm not enabled on port %u (error)\n", port_id);
14812                 return;
14813         }
14814
14815         /* Forward mode: tm */
14816         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14817                 printf("  tm mode not enabled(error)\n");
14818                 return;
14819         }
14820
14821         /* Set the default tm hierarchy */
14822         p->softport.tm.default_hierarchy_enable = 1;
14823 }
14824
14825 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14826         .f = cmd_set_port_tm_hierarchy_default_parsed,
14827         .data = NULL,
14828         .help_str = "set port tm hierarchy default <port_id>",
14829         .tokens = {
14830                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14831                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14832                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14833                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14834                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14835                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14836                 NULL,
14837         },
14838 };
14839 #endif
14840
14841 /* Strict link priority scheduling mode setting */
14842 static void
14843 cmd_strict_link_prio_parsed(
14844         void *parsed_result,
14845         __attribute__((unused)) struct cmdline *cl,
14846         __attribute__((unused)) void *data)
14847 {
14848         struct cmd_vf_tc_bw_result *res = parsed_result;
14849         int ret = -ENOTSUP;
14850
14851         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14852                 return;
14853
14854 #ifdef RTE_LIBRTE_I40E_PMD
14855         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14856 #endif
14857
14858         switch (ret) {
14859         case 0:
14860                 break;
14861         case -EINVAL:
14862                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14863                 break;
14864         case -ENODEV:
14865                 printf("invalid port_id %d\n", res->port_id);
14866                 break;
14867         case -ENOTSUP:
14868                 printf("function not implemented\n");
14869                 break;
14870         default:
14871                 printf("programming error: (%s)\n", strerror(-ret));
14872         }
14873 }
14874
14875 cmdline_parse_inst_t cmd_strict_link_prio = {
14876         .f = cmd_strict_link_prio_parsed,
14877         .data = NULL,
14878         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14879         .tokens = {
14880                 (void *)&cmd_vf_tc_bw_set,
14881                 (void *)&cmd_vf_tc_bw_tx,
14882                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14883                 (void *)&cmd_vf_tc_bw_port_id,
14884                 (void *)&cmd_vf_tc_bw_tc_map,
14885                 NULL,
14886         },
14887 };
14888
14889 /* Load dynamic device personalization*/
14890 struct cmd_ddp_add_result {
14891         cmdline_fixed_string_t ddp;
14892         cmdline_fixed_string_t add;
14893         portid_t port_id;
14894         char filepath[];
14895 };
14896
14897 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14898         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14899 cmdline_parse_token_string_t cmd_ddp_add_add =
14900         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14901 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14902         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14903 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14904         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14905
14906 static void
14907 cmd_ddp_add_parsed(
14908         void *parsed_result,
14909         __attribute__((unused)) struct cmdline *cl,
14910         __attribute__((unused)) void *data)
14911 {
14912         struct cmd_ddp_add_result *res = parsed_result;
14913         uint8_t *buff;
14914         uint32_t size;
14915         char *filepath;
14916         char *file_fld[2];
14917         int file_num;
14918         int ret = -ENOTSUP;
14919
14920         if (!all_ports_stopped()) {
14921                 printf("Please stop all ports first\n");
14922                 return;
14923         }
14924
14925         filepath = strdup(res->filepath);
14926         if (filepath == NULL) {
14927                 printf("Failed to allocate memory\n");
14928                 return;
14929         }
14930         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14931
14932         buff = open_file(file_fld[0], &size);
14933         if (!buff) {
14934                 free((void *)filepath);
14935                 return;
14936         }
14937
14938 #ifdef RTE_LIBRTE_I40E_PMD
14939         if (ret == -ENOTSUP)
14940                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14941                                                buff, size,
14942                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14943 #endif
14944
14945         if (ret == -EEXIST)
14946                 printf("Profile has already existed.\n");
14947         else if (ret < 0)
14948                 printf("Failed to load profile.\n");
14949         else if (file_num == 2)
14950                 save_file(file_fld[1], buff, size);
14951
14952         close_file(buff);
14953         free((void *)filepath);
14954 }
14955
14956 cmdline_parse_inst_t cmd_ddp_add = {
14957         .f = cmd_ddp_add_parsed,
14958         .data = NULL,
14959         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14960         .tokens = {
14961                 (void *)&cmd_ddp_add_ddp,
14962                 (void *)&cmd_ddp_add_add,
14963                 (void *)&cmd_ddp_add_port_id,
14964                 (void *)&cmd_ddp_add_filepath,
14965                 NULL,
14966         },
14967 };
14968
14969 /* Delete dynamic device personalization*/
14970 struct cmd_ddp_del_result {
14971         cmdline_fixed_string_t ddp;
14972         cmdline_fixed_string_t del;
14973         portid_t port_id;
14974         char filepath[];
14975 };
14976
14977 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14978         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14979 cmdline_parse_token_string_t cmd_ddp_del_del =
14980         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14981 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14982         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14983 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14984         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14985
14986 static void
14987 cmd_ddp_del_parsed(
14988         void *parsed_result,
14989         __attribute__((unused)) struct cmdline *cl,
14990         __attribute__((unused)) void *data)
14991 {
14992         struct cmd_ddp_del_result *res = parsed_result;
14993         uint8_t *buff;
14994         uint32_t size;
14995         int ret = -ENOTSUP;
14996
14997         if (!all_ports_stopped()) {
14998                 printf("Please stop all ports first\n");
14999                 return;
15000         }
15001
15002         buff = open_file(res->filepath, &size);
15003         if (!buff)
15004                 return;
15005
15006 #ifdef RTE_LIBRTE_I40E_PMD
15007         if (ret == -ENOTSUP)
15008                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15009                                                buff, size,
15010                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15011 #endif
15012
15013         if (ret == -EACCES)
15014                 printf("Profile does not exist.\n");
15015         else if (ret < 0)
15016                 printf("Failed to delete profile.\n");
15017
15018         close_file(buff);
15019 }
15020
15021 cmdline_parse_inst_t cmd_ddp_del = {
15022         .f = cmd_ddp_del_parsed,
15023         .data = NULL,
15024         .help_str = "ddp del <port_id> <backup_profile_path>",
15025         .tokens = {
15026                 (void *)&cmd_ddp_del_ddp,
15027                 (void *)&cmd_ddp_del_del,
15028                 (void *)&cmd_ddp_del_port_id,
15029                 (void *)&cmd_ddp_del_filepath,
15030                 NULL,
15031         },
15032 };
15033
15034 /* Get dynamic device personalization profile info */
15035 struct cmd_ddp_info_result {
15036         cmdline_fixed_string_t ddp;
15037         cmdline_fixed_string_t get;
15038         cmdline_fixed_string_t info;
15039         char filepath[];
15040 };
15041
15042 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15043         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15044 cmdline_parse_token_string_t cmd_ddp_info_get =
15045         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15046 cmdline_parse_token_string_t cmd_ddp_info_info =
15047         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15048 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15049         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15050
15051 static void
15052 cmd_ddp_info_parsed(
15053         void *parsed_result,
15054         __attribute__((unused)) struct cmdline *cl,
15055         __attribute__((unused)) void *data)
15056 {
15057         struct cmd_ddp_info_result *res = parsed_result;
15058         uint8_t *pkg;
15059         uint32_t pkg_size;
15060         int ret = -ENOTSUP;
15061 #ifdef RTE_LIBRTE_I40E_PMD
15062         uint32_t i, j, n;
15063         uint8_t *buff;
15064         uint32_t buff_size = 0;
15065         struct rte_pmd_i40e_profile_info info;
15066         uint32_t dev_num = 0;
15067         struct rte_pmd_i40e_ddp_device_id *devs;
15068         uint32_t proto_num = 0;
15069         struct rte_pmd_i40e_proto_info *proto = NULL;
15070         uint32_t pctype_num = 0;
15071         struct rte_pmd_i40e_ptype_info *pctype;
15072         uint32_t ptype_num = 0;
15073         struct rte_pmd_i40e_ptype_info *ptype;
15074         uint8_t proto_id;
15075
15076 #endif
15077
15078         pkg = open_file(res->filepath, &pkg_size);
15079         if (!pkg)
15080                 return;
15081
15082 #ifdef RTE_LIBRTE_I40E_PMD
15083         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15084                                 (uint8_t *)&info, sizeof(info),
15085                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15086         if (!ret) {
15087                 printf("Global Track id:       0x%x\n", info.track_id);
15088                 printf("Global Version:        %d.%d.%d.%d\n",
15089                         info.version.major,
15090                         info.version.minor,
15091                         info.version.update,
15092                         info.version.draft);
15093                 printf("Global Package name:   %s\n\n", info.name);
15094         }
15095
15096         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15097                                 (uint8_t *)&info, sizeof(info),
15098                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15099         if (!ret) {
15100                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15101                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15102                         info.version.major,
15103                         info.version.minor,
15104                         info.version.update,
15105                         info.version.draft);
15106                 printf("i40e Profile name:     %s\n\n", info.name);
15107         }
15108
15109         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15110                                 (uint8_t *)&buff_size, sizeof(buff_size),
15111                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15112         if (!ret && buff_size) {
15113                 buff = (uint8_t *)malloc(buff_size);
15114                 if (buff) {
15115                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15116                                                 buff, buff_size,
15117                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15118                         if (!ret)
15119                                 printf("Package Notes:\n%s\n\n", buff);
15120                         free(buff);
15121                 }
15122         }
15123
15124         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15125                                 (uint8_t *)&dev_num, sizeof(dev_num),
15126                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15127         if (!ret && dev_num) {
15128                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15129                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15130                 if (devs) {
15131                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15132                                                 (uint8_t *)devs, buff_size,
15133                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15134                         if (!ret) {
15135                                 printf("List of supported devices:\n");
15136                                 for (i = 0; i < dev_num; i++) {
15137                                         printf("  %04X:%04X %04X:%04X\n",
15138                                                 devs[i].vendor_dev_id >> 16,
15139                                                 devs[i].vendor_dev_id & 0xFFFF,
15140                                                 devs[i].sub_vendor_dev_id >> 16,
15141                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15142                                 }
15143                                 printf("\n");
15144                         }
15145                         free(devs);
15146                 }
15147         }
15148
15149         /* get information about protocols and packet types */
15150         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15151                 (uint8_t *)&proto_num, sizeof(proto_num),
15152                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15153         if (ret || !proto_num)
15154                 goto no_print_return;
15155
15156         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15157         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15158         if (!proto)
15159                 goto no_print_return;
15160
15161         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15162                                         buff_size,
15163                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15164         if (!ret) {
15165                 printf("List of used protocols:\n");
15166                 for (i = 0; i < proto_num; i++)
15167                         printf("  %2u: %s\n", proto[i].proto_id,
15168                                proto[i].name);
15169                 printf("\n");
15170         }
15171         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15172                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15173                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15174         if (ret || !pctype_num)
15175                 goto no_print_pctypes;
15176
15177         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15178         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15179         if (!pctype)
15180                 goto no_print_pctypes;
15181
15182         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15183                                         buff_size,
15184                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15185         if (ret) {
15186                 free(pctype);
15187                 goto no_print_pctypes;
15188         }
15189
15190         printf("List of defined packet classification types:\n");
15191         for (i = 0; i < pctype_num; i++) {
15192                 printf("  %2u:", pctype[i].ptype_id);
15193                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15194                         proto_id = pctype[i].protocols[j];
15195                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15196                                 for (n = 0; n < proto_num; n++) {
15197                                         if (proto[n].proto_id == proto_id) {
15198                                                 printf(" %s", proto[n].name);
15199                                                 break;
15200                                         }
15201                                 }
15202                         }
15203                 }
15204                 printf("\n");
15205         }
15206         printf("\n");
15207         free(pctype);
15208
15209 no_print_pctypes:
15210
15211         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15212                                         sizeof(ptype_num),
15213                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15214         if (ret || !ptype_num)
15215                 goto no_print_return;
15216
15217         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15218         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15219         if (!ptype)
15220                 goto no_print_return;
15221
15222         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15223                                         buff_size,
15224                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15225         if (ret) {
15226                 free(ptype);
15227                 goto no_print_return;
15228         }
15229         printf("List of defined packet types:\n");
15230         for (i = 0; i < ptype_num; i++) {
15231                 printf("  %2u:", ptype[i].ptype_id);
15232                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15233                         proto_id = ptype[i].protocols[j];
15234                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15235                                 for (n = 0; n < proto_num; n++) {
15236                                         if (proto[n].proto_id == proto_id) {
15237                                                 printf(" %s", proto[n].name);
15238                                                 break;
15239                                         }
15240                                 }
15241                         }
15242                 }
15243                 printf("\n");
15244         }
15245         free(ptype);
15246         printf("\n");
15247
15248         ret = 0;
15249 no_print_return:
15250         if (proto)
15251                 free(proto);
15252 #endif
15253         if (ret == -ENOTSUP)
15254                 printf("Function not supported in PMD driver\n");
15255         close_file(pkg);
15256 }
15257
15258 cmdline_parse_inst_t cmd_ddp_get_info = {
15259         .f = cmd_ddp_info_parsed,
15260         .data = NULL,
15261         .help_str = "ddp get info <profile_path>",
15262         .tokens = {
15263                 (void *)&cmd_ddp_info_ddp,
15264                 (void *)&cmd_ddp_info_get,
15265                 (void *)&cmd_ddp_info_info,
15266                 (void *)&cmd_ddp_info_filepath,
15267                 NULL,
15268         },
15269 };
15270
15271 /* Get dynamic device personalization profile info list*/
15272 #define PROFILE_INFO_SIZE 48
15273 #define MAX_PROFILE_NUM 16
15274
15275 struct cmd_ddp_get_list_result {
15276         cmdline_fixed_string_t ddp;
15277         cmdline_fixed_string_t get;
15278         cmdline_fixed_string_t list;
15279         portid_t port_id;
15280 };
15281
15282 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15283         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15284 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15285         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15286 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15287         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15288 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15289         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15290
15291 static void
15292 cmd_ddp_get_list_parsed(
15293         __attribute__((unused)) void *parsed_result,
15294         __attribute__((unused)) struct cmdline *cl,
15295         __attribute__((unused)) void *data)
15296 {
15297 #ifdef RTE_LIBRTE_I40E_PMD
15298         struct cmd_ddp_get_list_result *res = parsed_result;
15299         struct rte_pmd_i40e_profile_list *p_list;
15300         struct rte_pmd_i40e_profile_info *p_info;
15301         uint32_t p_num;
15302         uint32_t size;
15303         uint32_t i;
15304 #endif
15305         int ret = -ENOTSUP;
15306
15307 #ifdef RTE_LIBRTE_I40E_PMD
15308         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15309         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15310         if (!p_list)
15311                 printf("%s: Failed to malloc buffer\n", __func__);
15312
15313         if (ret == -ENOTSUP)
15314                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15315                                                 (uint8_t *)p_list, size);
15316
15317         if (!ret) {
15318                 p_num = p_list->p_count;
15319                 printf("Profile number is: %d\n\n", p_num);
15320
15321                 for (i = 0; i < p_num; i++) {
15322                         p_info = &p_list->p_info[i];
15323                         printf("Profile %d:\n", i);
15324                         printf("Track id:     0x%x\n", p_info->track_id);
15325                         printf("Version:      %d.%d.%d.%d\n",
15326                                p_info->version.major,
15327                                p_info->version.minor,
15328                                p_info->version.update,
15329                                p_info->version.draft);
15330                         printf("Profile name: %s\n\n", p_info->name);
15331                 }
15332         }
15333
15334         free(p_list);
15335 #endif
15336
15337         if (ret < 0)
15338                 printf("Failed to get ddp list\n");
15339 }
15340
15341 cmdline_parse_inst_t cmd_ddp_get_list = {
15342         .f = cmd_ddp_get_list_parsed,
15343         .data = NULL,
15344         .help_str = "ddp get list <port_id>",
15345         .tokens = {
15346                 (void *)&cmd_ddp_get_list_ddp,
15347                 (void *)&cmd_ddp_get_list_get,
15348                 (void *)&cmd_ddp_get_list_list,
15349                 (void *)&cmd_ddp_get_list_port_id,
15350                 NULL,
15351         },
15352 };
15353
15354 /* Configure input set */
15355 struct cmd_cfg_input_set_result {
15356         cmdline_fixed_string_t port;
15357         cmdline_fixed_string_t cfg;
15358         portid_t port_id;
15359         cmdline_fixed_string_t pctype;
15360         uint8_t pctype_id;
15361         cmdline_fixed_string_t inset_type;
15362         cmdline_fixed_string_t opt;
15363         cmdline_fixed_string_t field;
15364         uint8_t field_idx;
15365 };
15366
15367 static void
15368 cmd_cfg_input_set_parsed(
15369         __attribute__((unused)) void *parsed_result,
15370         __attribute__((unused)) struct cmdline *cl,
15371         __attribute__((unused)) void *data)
15372 {
15373 #ifdef RTE_LIBRTE_I40E_PMD
15374         struct cmd_cfg_input_set_result *res = parsed_result;
15375         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15376         struct rte_pmd_i40e_inset inset;
15377 #endif
15378         int ret = -ENOTSUP;
15379
15380         if (!all_ports_stopped()) {
15381                 printf("Please stop all ports first\n");
15382                 return;
15383         }
15384
15385 #ifdef RTE_LIBRTE_I40E_PMD
15386         if (!strcmp(res->inset_type, "hash_inset"))
15387                 inset_type = INSET_HASH;
15388         else if (!strcmp(res->inset_type, "fdir_inset"))
15389                 inset_type = INSET_FDIR;
15390         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15391                 inset_type = INSET_FDIR_FLX;
15392         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15393                                      &inset, inset_type);
15394         if (ret) {
15395                 printf("Failed to get input set.\n");
15396                 return;
15397         }
15398
15399         if (!strcmp(res->opt, "get")) {
15400                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15401                                                    res->field_idx);
15402                 if (ret)
15403                         printf("Field index %d is enabled.\n", res->field_idx);
15404                 else
15405                         printf("Field index %d is disabled.\n", res->field_idx);
15406                 return;
15407         } else if (!strcmp(res->opt, "set"))
15408                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15409                                                    res->field_idx);
15410         else if (!strcmp(res->opt, "clear"))
15411                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15412                                                      res->field_idx);
15413         if (ret) {
15414                 printf("Failed to configure input set field.\n");
15415                 return;
15416         }
15417
15418         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15419                                      &inset, inset_type);
15420         if (ret) {
15421                 printf("Failed to set input set.\n");
15422                 return;
15423         }
15424 #endif
15425
15426         if (ret == -ENOTSUP)
15427                 printf("Function not supported\n");
15428 }
15429
15430 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15431         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15432                                  port, "port");
15433 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15434         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15435                                  cfg, "config");
15436 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15437         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15438                               port_id, UINT16);
15439 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15440         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15441                                  pctype, "pctype");
15442 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15443         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15444                               pctype_id, UINT8);
15445 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15446         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15447                                  inset_type,
15448                                  "hash_inset#fdir_inset#fdir_flx_inset");
15449 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15450         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15451                                  opt, "get#set#clear");
15452 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15453         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15454                                  field, "field");
15455 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15456         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15457                               field_idx, UINT8);
15458
15459 cmdline_parse_inst_t cmd_cfg_input_set = {
15460         .f = cmd_cfg_input_set_parsed,
15461         .data = NULL,
15462         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15463                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15464         .tokens = {
15465                 (void *)&cmd_cfg_input_set_port,
15466                 (void *)&cmd_cfg_input_set_cfg,
15467                 (void *)&cmd_cfg_input_set_port_id,
15468                 (void *)&cmd_cfg_input_set_pctype,
15469                 (void *)&cmd_cfg_input_set_pctype_id,
15470                 (void *)&cmd_cfg_input_set_inset_type,
15471                 (void *)&cmd_cfg_input_set_opt,
15472                 (void *)&cmd_cfg_input_set_field,
15473                 (void *)&cmd_cfg_input_set_field_idx,
15474                 NULL,
15475         },
15476 };
15477
15478 /* Clear input set */
15479 struct cmd_clear_input_set_result {
15480         cmdline_fixed_string_t port;
15481         cmdline_fixed_string_t cfg;
15482         portid_t port_id;
15483         cmdline_fixed_string_t pctype;
15484         uint8_t pctype_id;
15485         cmdline_fixed_string_t inset_type;
15486         cmdline_fixed_string_t clear;
15487         cmdline_fixed_string_t all;
15488 };
15489
15490 static void
15491 cmd_clear_input_set_parsed(
15492         __attribute__((unused)) void *parsed_result,
15493         __attribute__((unused)) struct cmdline *cl,
15494         __attribute__((unused)) void *data)
15495 {
15496 #ifdef RTE_LIBRTE_I40E_PMD
15497         struct cmd_clear_input_set_result *res = parsed_result;
15498         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15499         struct rte_pmd_i40e_inset inset;
15500 #endif
15501         int ret = -ENOTSUP;
15502
15503         if (!all_ports_stopped()) {
15504                 printf("Please stop all ports first\n");
15505                 return;
15506         }
15507
15508 #ifdef RTE_LIBRTE_I40E_PMD
15509         if (!strcmp(res->inset_type, "hash_inset"))
15510                 inset_type = INSET_HASH;
15511         else if (!strcmp(res->inset_type, "fdir_inset"))
15512                 inset_type = INSET_FDIR;
15513         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15514                 inset_type = INSET_FDIR_FLX;
15515
15516         memset(&inset, 0, sizeof(inset));
15517
15518         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15519                                      &inset, inset_type);
15520         if (ret) {
15521                 printf("Failed to clear input set.\n");
15522                 return;
15523         }
15524
15525 #endif
15526
15527         if (ret == -ENOTSUP)
15528                 printf("Function not supported\n");
15529 }
15530
15531 cmdline_parse_token_string_t cmd_clear_input_set_port =
15532         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15533                                  port, "port");
15534 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15535         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15536                                  cfg, "config");
15537 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15538         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15539                               port_id, UINT16);
15540 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15541         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15542                                  pctype, "pctype");
15543 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15544         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15545                               pctype_id, UINT8);
15546 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15547         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15548                                  inset_type,
15549                                  "hash_inset#fdir_inset#fdir_flx_inset");
15550 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15551         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15552                                  clear, "clear");
15553 cmdline_parse_token_string_t cmd_clear_input_set_all =
15554         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15555                                  all, "all");
15556
15557 cmdline_parse_inst_t cmd_clear_input_set = {
15558         .f = cmd_clear_input_set_parsed,
15559         .data = NULL,
15560         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15561                     "fdir_inset|fdir_flx_inset clear all",
15562         .tokens = {
15563                 (void *)&cmd_clear_input_set_port,
15564                 (void *)&cmd_clear_input_set_cfg,
15565                 (void *)&cmd_clear_input_set_port_id,
15566                 (void *)&cmd_clear_input_set_pctype,
15567                 (void *)&cmd_clear_input_set_pctype_id,
15568                 (void *)&cmd_clear_input_set_inset_type,
15569                 (void *)&cmd_clear_input_set_clear,
15570                 (void *)&cmd_clear_input_set_all,
15571                 NULL,
15572         },
15573 };
15574
15575 /* show vf stats */
15576
15577 /* Common result structure for show vf stats */
15578 struct cmd_show_vf_stats_result {
15579         cmdline_fixed_string_t show;
15580         cmdline_fixed_string_t vf;
15581         cmdline_fixed_string_t stats;
15582         portid_t port_id;
15583         uint16_t vf_id;
15584 };
15585
15586 /* Common CLI fields show vf stats*/
15587 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15588         TOKEN_STRING_INITIALIZER
15589                 (struct cmd_show_vf_stats_result,
15590                  show, "show");
15591 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15592         TOKEN_STRING_INITIALIZER
15593                 (struct cmd_show_vf_stats_result,
15594                  vf, "vf");
15595 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15596         TOKEN_STRING_INITIALIZER
15597                 (struct cmd_show_vf_stats_result,
15598                  stats, "stats");
15599 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15600         TOKEN_NUM_INITIALIZER
15601                 (struct cmd_show_vf_stats_result,
15602                  port_id, UINT16);
15603 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15604         TOKEN_NUM_INITIALIZER
15605                 (struct cmd_show_vf_stats_result,
15606                  vf_id, UINT16);
15607
15608 static void
15609 cmd_show_vf_stats_parsed(
15610         void *parsed_result,
15611         __attribute__((unused)) struct cmdline *cl,
15612         __attribute__((unused)) void *data)
15613 {
15614         struct cmd_show_vf_stats_result *res = parsed_result;
15615         struct rte_eth_stats stats;
15616         int ret = -ENOTSUP;
15617         static const char *nic_stats_border = "########################";
15618
15619         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15620                 return;
15621
15622         memset(&stats, 0, sizeof(stats));
15623
15624 #ifdef RTE_LIBRTE_I40E_PMD
15625         if (ret == -ENOTSUP)
15626                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15627                                                 res->vf_id,
15628                                                 &stats);
15629 #endif
15630 #ifdef RTE_LIBRTE_BNXT_PMD
15631         if (ret == -ENOTSUP)
15632                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15633                                                 res->vf_id,
15634                                                 &stats);
15635 #endif
15636
15637         switch (ret) {
15638         case 0:
15639                 break;
15640         case -EINVAL:
15641                 printf("invalid vf_id %d\n", res->vf_id);
15642                 break;
15643         case -ENODEV:
15644                 printf("invalid port_id %d\n", res->port_id);
15645                 break;
15646         case -ENOTSUP:
15647                 printf("function not implemented\n");
15648                 break;
15649         default:
15650                 printf("programming error: (%s)\n", strerror(-ret));
15651         }
15652
15653         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15654                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15655
15656         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15657                "%-"PRIu64"\n",
15658                stats.ipackets, stats.imissed, stats.ibytes);
15659         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15660         printf("  RX-nombuf:  %-10"PRIu64"\n",
15661                stats.rx_nombuf);
15662         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15663                "%-"PRIu64"\n",
15664                stats.opackets, stats.oerrors, stats.obytes);
15665
15666         printf("  %s############################%s\n",
15667                                nic_stats_border, nic_stats_border);
15668 }
15669
15670 cmdline_parse_inst_t cmd_show_vf_stats = {
15671         .f = cmd_show_vf_stats_parsed,
15672         .data = NULL,
15673         .help_str = "show vf stats <port_id> <vf_id>",
15674         .tokens = {
15675                 (void *)&cmd_show_vf_stats_show,
15676                 (void *)&cmd_show_vf_stats_vf,
15677                 (void *)&cmd_show_vf_stats_stats,
15678                 (void *)&cmd_show_vf_stats_port_id,
15679                 (void *)&cmd_show_vf_stats_vf_id,
15680                 NULL,
15681         },
15682 };
15683
15684 /* clear vf stats */
15685
15686 /* Common result structure for clear vf stats */
15687 struct cmd_clear_vf_stats_result {
15688         cmdline_fixed_string_t clear;
15689         cmdline_fixed_string_t vf;
15690         cmdline_fixed_string_t stats;
15691         portid_t port_id;
15692         uint16_t vf_id;
15693 };
15694
15695 /* Common CLI fields clear vf stats*/
15696 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15697         TOKEN_STRING_INITIALIZER
15698                 (struct cmd_clear_vf_stats_result,
15699                  clear, "clear");
15700 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15701         TOKEN_STRING_INITIALIZER
15702                 (struct cmd_clear_vf_stats_result,
15703                  vf, "vf");
15704 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15705         TOKEN_STRING_INITIALIZER
15706                 (struct cmd_clear_vf_stats_result,
15707                  stats, "stats");
15708 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15709         TOKEN_NUM_INITIALIZER
15710                 (struct cmd_clear_vf_stats_result,
15711                  port_id, UINT16);
15712 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15713         TOKEN_NUM_INITIALIZER
15714                 (struct cmd_clear_vf_stats_result,
15715                  vf_id, UINT16);
15716
15717 static void
15718 cmd_clear_vf_stats_parsed(
15719         void *parsed_result,
15720         __attribute__((unused)) struct cmdline *cl,
15721         __attribute__((unused)) void *data)
15722 {
15723         struct cmd_clear_vf_stats_result *res = parsed_result;
15724         int ret = -ENOTSUP;
15725
15726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15727                 return;
15728
15729 #ifdef RTE_LIBRTE_I40E_PMD
15730         if (ret == -ENOTSUP)
15731                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15732                                                   res->vf_id);
15733 #endif
15734 #ifdef RTE_LIBRTE_BNXT_PMD
15735         if (ret == -ENOTSUP)
15736                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15737                                                   res->vf_id);
15738 #endif
15739
15740         switch (ret) {
15741         case 0:
15742                 break;
15743         case -EINVAL:
15744                 printf("invalid vf_id %d\n", res->vf_id);
15745                 break;
15746         case -ENODEV:
15747                 printf("invalid port_id %d\n", res->port_id);
15748                 break;
15749         case -ENOTSUP:
15750                 printf("function not implemented\n");
15751                 break;
15752         default:
15753                 printf("programming error: (%s)\n", strerror(-ret));
15754         }
15755 }
15756
15757 cmdline_parse_inst_t cmd_clear_vf_stats = {
15758         .f = cmd_clear_vf_stats_parsed,
15759         .data = NULL,
15760         .help_str = "clear vf stats <port_id> <vf_id>",
15761         .tokens = {
15762                 (void *)&cmd_clear_vf_stats_clear,
15763                 (void *)&cmd_clear_vf_stats_vf,
15764                 (void *)&cmd_clear_vf_stats_stats,
15765                 (void *)&cmd_clear_vf_stats_port_id,
15766                 (void *)&cmd_clear_vf_stats_vf_id,
15767                 NULL,
15768         },
15769 };
15770
15771 /* port config pctype mapping reset */
15772
15773 /* Common result structure for port config pctype mapping reset */
15774 struct cmd_pctype_mapping_reset_result {
15775         cmdline_fixed_string_t port;
15776         cmdline_fixed_string_t config;
15777         portid_t port_id;
15778         cmdline_fixed_string_t pctype;
15779         cmdline_fixed_string_t mapping;
15780         cmdline_fixed_string_t reset;
15781 };
15782
15783 /* Common CLI fields for port config pctype mapping reset*/
15784 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15785         TOKEN_STRING_INITIALIZER
15786                 (struct cmd_pctype_mapping_reset_result,
15787                  port, "port");
15788 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15789         TOKEN_STRING_INITIALIZER
15790                 (struct cmd_pctype_mapping_reset_result,
15791                  config, "config");
15792 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15793         TOKEN_NUM_INITIALIZER
15794                 (struct cmd_pctype_mapping_reset_result,
15795                  port_id, UINT16);
15796 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15797         TOKEN_STRING_INITIALIZER
15798                 (struct cmd_pctype_mapping_reset_result,
15799                  pctype, "pctype");
15800 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15801         TOKEN_STRING_INITIALIZER
15802                 (struct cmd_pctype_mapping_reset_result,
15803                  mapping, "mapping");
15804 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15805         TOKEN_STRING_INITIALIZER
15806                 (struct cmd_pctype_mapping_reset_result,
15807                  reset, "reset");
15808
15809 static void
15810 cmd_pctype_mapping_reset_parsed(
15811         void *parsed_result,
15812         __attribute__((unused)) struct cmdline *cl,
15813         __attribute__((unused)) void *data)
15814 {
15815         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15816         int ret = -ENOTSUP;
15817
15818         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15819                 return;
15820
15821 #ifdef RTE_LIBRTE_I40E_PMD
15822         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15823 #endif
15824
15825         switch (ret) {
15826         case 0:
15827                 break;
15828         case -ENODEV:
15829                 printf("invalid port_id %d\n", res->port_id);
15830                 break;
15831         case -ENOTSUP:
15832                 printf("function not implemented\n");
15833                 break;
15834         default:
15835                 printf("programming error: (%s)\n", strerror(-ret));
15836         }
15837 }
15838
15839 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15840         .f = cmd_pctype_mapping_reset_parsed,
15841         .data = NULL,
15842         .help_str = "port config <port_id> pctype mapping reset",
15843         .tokens = {
15844                 (void *)&cmd_pctype_mapping_reset_port,
15845                 (void *)&cmd_pctype_mapping_reset_config,
15846                 (void *)&cmd_pctype_mapping_reset_port_id,
15847                 (void *)&cmd_pctype_mapping_reset_pctype,
15848                 (void *)&cmd_pctype_mapping_reset_mapping,
15849                 (void *)&cmd_pctype_mapping_reset_reset,
15850                 NULL,
15851         },
15852 };
15853
15854 /* show port pctype mapping */
15855
15856 /* Common result structure for show port pctype mapping */
15857 struct cmd_pctype_mapping_get_result {
15858         cmdline_fixed_string_t show;
15859         cmdline_fixed_string_t port;
15860         portid_t port_id;
15861         cmdline_fixed_string_t pctype;
15862         cmdline_fixed_string_t mapping;
15863 };
15864
15865 /* Common CLI fields for pctype mapping get */
15866 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15867         TOKEN_STRING_INITIALIZER
15868                 (struct cmd_pctype_mapping_get_result,
15869                  show, "show");
15870 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15871         TOKEN_STRING_INITIALIZER
15872                 (struct cmd_pctype_mapping_get_result,
15873                  port, "port");
15874 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15875         TOKEN_NUM_INITIALIZER
15876                 (struct cmd_pctype_mapping_get_result,
15877                  port_id, UINT16);
15878 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15879         TOKEN_STRING_INITIALIZER
15880                 (struct cmd_pctype_mapping_get_result,
15881                  pctype, "pctype");
15882 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15883         TOKEN_STRING_INITIALIZER
15884                 (struct cmd_pctype_mapping_get_result,
15885                  mapping, "mapping");
15886
15887 static void
15888 cmd_pctype_mapping_get_parsed(
15889         void *parsed_result,
15890         __attribute__((unused)) struct cmdline *cl,
15891         __attribute__((unused)) void *data)
15892 {
15893         struct cmd_pctype_mapping_get_result *res = parsed_result;
15894         int ret = -ENOTSUP;
15895 #ifdef RTE_LIBRTE_I40E_PMD
15896         struct rte_pmd_i40e_flow_type_mapping
15897                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15898         int i, j, first_pctype;
15899 #endif
15900
15901         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15902                 return;
15903
15904 #ifdef RTE_LIBRTE_I40E_PMD
15905         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15906 #endif
15907
15908         switch (ret) {
15909         case 0:
15910                 break;
15911         case -ENODEV:
15912                 printf("invalid port_id %d\n", res->port_id);
15913                 return;
15914         case -ENOTSUP:
15915                 printf("function not implemented\n");
15916                 return;
15917         default:
15918                 printf("programming error: (%s)\n", strerror(-ret));
15919                 return;
15920         }
15921
15922 #ifdef RTE_LIBRTE_I40E_PMD
15923         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15924                 if (mapping[i].pctype != 0ULL) {
15925                         first_pctype = 1;
15926
15927                         printf("pctype: ");
15928                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15929                                 if (mapping[i].pctype & (1ULL << j)) {
15930                                         printf(first_pctype ?
15931                                                "%02d" : ",%02d", j);
15932                                         first_pctype = 0;
15933                                 }
15934                         }
15935                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15936                 }
15937         }
15938 #endif
15939 }
15940
15941 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15942         .f = cmd_pctype_mapping_get_parsed,
15943         .data = NULL,
15944         .help_str = "show port <port_id> pctype mapping",
15945         .tokens = {
15946                 (void *)&cmd_pctype_mapping_get_show,
15947                 (void *)&cmd_pctype_mapping_get_port,
15948                 (void *)&cmd_pctype_mapping_get_port_id,
15949                 (void *)&cmd_pctype_mapping_get_pctype,
15950                 (void *)&cmd_pctype_mapping_get_mapping,
15951                 NULL,
15952         },
15953 };
15954
15955 /* port config pctype mapping update */
15956
15957 /* Common result structure for port config pctype mapping update */
15958 struct cmd_pctype_mapping_update_result {
15959         cmdline_fixed_string_t port;
15960         cmdline_fixed_string_t config;
15961         portid_t port_id;
15962         cmdline_fixed_string_t pctype;
15963         cmdline_fixed_string_t mapping;
15964         cmdline_fixed_string_t update;
15965         cmdline_fixed_string_t pctype_list;
15966         uint16_t flow_type;
15967 };
15968
15969 /* Common CLI fields for pctype mapping update*/
15970 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15971         TOKEN_STRING_INITIALIZER
15972                 (struct cmd_pctype_mapping_update_result,
15973                  port, "port");
15974 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15975         TOKEN_STRING_INITIALIZER
15976                 (struct cmd_pctype_mapping_update_result,
15977                  config, "config");
15978 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15979         TOKEN_NUM_INITIALIZER
15980                 (struct cmd_pctype_mapping_update_result,
15981                  port_id, UINT16);
15982 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15983         TOKEN_STRING_INITIALIZER
15984                 (struct cmd_pctype_mapping_update_result,
15985                  pctype, "pctype");
15986 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15987         TOKEN_STRING_INITIALIZER
15988                 (struct cmd_pctype_mapping_update_result,
15989                  mapping, "mapping");
15990 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15991         TOKEN_STRING_INITIALIZER
15992                 (struct cmd_pctype_mapping_update_result,
15993                  update, "update");
15994 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15995         TOKEN_STRING_INITIALIZER
15996                 (struct cmd_pctype_mapping_update_result,
15997                  pctype_list, NULL);
15998 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15999         TOKEN_NUM_INITIALIZER
16000                 (struct cmd_pctype_mapping_update_result,
16001                  flow_type, UINT16);
16002
16003 static void
16004 cmd_pctype_mapping_update_parsed(
16005         void *parsed_result,
16006         __attribute__((unused)) struct cmdline *cl,
16007         __attribute__((unused)) void *data)
16008 {
16009         struct cmd_pctype_mapping_update_result *res = parsed_result;
16010         int ret = -ENOTSUP;
16011 #ifdef RTE_LIBRTE_I40E_PMD
16012         struct rte_pmd_i40e_flow_type_mapping mapping;
16013         unsigned int i;
16014         unsigned int nb_item;
16015         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16016 #endif
16017
16018         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16019                 return;
16020
16021 #ifdef RTE_LIBRTE_I40E_PMD
16022         nb_item = parse_item_list(res->pctype_list, "pctypes",
16023                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16024         mapping.flow_type = res->flow_type;
16025         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16026                 mapping.pctype |= (1ULL << pctype_list[i]);
16027         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16028                                                 &mapping,
16029                                                 1,
16030                                                 0);
16031 #endif
16032
16033         switch (ret) {
16034         case 0:
16035                 break;
16036         case -EINVAL:
16037                 printf("invalid pctype or flow type\n");
16038                 break;
16039         case -ENODEV:
16040                 printf("invalid port_id %d\n", res->port_id);
16041                 break;
16042         case -ENOTSUP:
16043                 printf("function not implemented\n");
16044                 break;
16045         default:
16046                 printf("programming error: (%s)\n", strerror(-ret));
16047         }
16048 }
16049
16050 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16051         .f = cmd_pctype_mapping_update_parsed,
16052         .data = NULL,
16053         .help_str = "port config <port_id> pctype mapping update"
16054         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16055         .tokens = {
16056                 (void *)&cmd_pctype_mapping_update_port,
16057                 (void *)&cmd_pctype_mapping_update_config,
16058                 (void *)&cmd_pctype_mapping_update_port_id,
16059                 (void *)&cmd_pctype_mapping_update_pctype,
16060                 (void *)&cmd_pctype_mapping_update_mapping,
16061                 (void *)&cmd_pctype_mapping_update_update,
16062                 (void *)&cmd_pctype_mapping_update_pc_type,
16063                 (void *)&cmd_pctype_mapping_update_flow_type,
16064                 NULL,
16065         },
16066 };
16067
16068 /* ptype mapping get */
16069
16070 /* Common result structure for ptype mapping get */
16071 struct cmd_ptype_mapping_get_result {
16072         cmdline_fixed_string_t ptype;
16073         cmdline_fixed_string_t mapping;
16074         cmdline_fixed_string_t get;
16075         portid_t port_id;
16076         uint8_t valid_only;
16077 };
16078
16079 /* Common CLI fields for ptype mapping get */
16080 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16081         TOKEN_STRING_INITIALIZER
16082                 (struct cmd_ptype_mapping_get_result,
16083                  ptype, "ptype");
16084 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16085         TOKEN_STRING_INITIALIZER
16086                 (struct cmd_ptype_mapping_get_result,
16087                  mapping, "mapping");
16088 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16089         TOKEN_STRING_INITIALIZER
16090                 (struct cmd_ptype_mapping_get_result,
16091                  get, "get");
16092 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16093         TOKEN_NUM_INITIALIZER
16094                 (struct cmd_ptype_mapping_get_result,
16095                  port_id, UINT16);
16096 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16097         TOKEN_NUM_INITIALIZER
16098                 (struct cmd_ptype_mapping_get_result,
16099                  valid_only, UINT8);
16100
16101 static void
16102 cmd_ptype_mapping_get_parsed(
16103         void *parsed_result,
16104         __attribute__((unused)) struct cmdline *cl,
16105         __attribute__((unused)) void *data)
16106 {
16107         struct cmd_ptype_mapping_get_result *res = parsed_result;
16108         int ret = -ENOTSUP;
16109 #ifdef RTE_LIBRTE_I40E_PMD
16110         int max_ptype_num = 256;
16111         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16112         uint16_t count;
16113         int i;
16114 #endif
16115
16116         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16117                 return;
16118
16119 #ifdef RTE_LIBRTE_I40E_PMD
16120         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16121                                         mapping,
16122                                         max_ptype_num,
16123                                         &count,
16124                                         res->valid_only);
16125 #endif
16126
16127         switch (ret) {
16128         case 0:
16129                 break;
16130         case -ENODEV:
16131                 printf("invalid port_id %d\n", res->port_id);
16132                 break;
16133         case -ENOTSUP:
16134                 printf("function not implemented\n");
16135                 break;
16136         default:
16137                 printf("programming error: (%s)\n", strerror(-ret));
16138         }
16139
16140 #ifdef RTE_LIBRTE_I40E_PMD
16141         if (!ret) {
16142                 for (i = 0; i < count; i++)
16143                         printf("%3d\t0x%08x\n",
16144                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16145         }
16146 #endif
16147 }
16148
16149 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16150         .f = cmd_ptype_mapping_get_parsed,
16151         .data = NULL,
16152         .help_str = "ptype mapping get <port_id> <valid_only>",
16153         .tokens = {
16154                 (void *)&cmd_ptype_mapping_get_ptype,
16155                 (void *)&cmd_ptype_mapping_get_mapping,
16156                 (void *)&cmd_ptype_mapping_get_get,
16157                 (void *)&cmd_ptype_mapping_get_port_id,
16158                 (void *)&cmd_ptype_mapping_get_valid_only,
16159                 NULL,
16160         },
16161 };
16162
16163 /* ptype mapping replace */
16164
16165 /* Common result structure for ptype mapping replace */
16166 struct cmd_ptype_mapping_replace_result {
16167         cmdline_fixed_string_t ptype;
16168         cmdline_fixed_string_t mapping;
16169         cmdline_fixed_string_t replace;
16170         portid_t port_id;
16171         uint32_t target;
16172         uint8_t mask;
16173         uint32_t pkt_type;
16174 };
16175
16176 /* Common CLI fields for ptype mapping replace */
16177 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16178         TOKEN_STRING_INITIALIZER
16179                 (struct cmd_ptype_mapping_replace_result,
16180                  ptype, "ptype");
16181 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16182         TOKEN_STRING_INITIALIZER
16183                 (struct cmd_ptype_mapping_replace_result,
16184                  mapping, "mapping");
16185 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16186         TOKEN_STRING_INITIALIZER
16187                 (struct cmd_ptype_mapping_replace_result,
16188                  replace, "replace");
16189 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16190         TOKEN_NUM_INITIALIZER
16191                 (struct cmd_ptype_mapping_replace_result,
16192                  port_id, UINT16);
16193 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16194         TOKEN_NUM_INITIALIZER
16195                 (struct cmd_ptype_mapping_replace_result,
16196                  target, UINT32);
16197 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16198         TOKEN_NUM_INITIALIZER
16199                 (struct cmd_ptype_mapping_replace_result,
16200                  mask, UINT8);
16201 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16202         TOKEN_NUM_INITIALIZER
16203                 (struct cmd_ptype_mapping_replace_result,
16204                  pkt_type, UINT32);
16205
16206 static void
16207 cmd_ptype_mapping_replace_parsed(
16208         void *parsed_result,
16209         __attribute__((unused)) struct cmdline *cl,
16210         __attribute__((unused)) void *data)
16211 {
16212         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16213         int ret = -ENOTSUP;
16214
16215         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16216                 return;
16217
16218 #ifdef RTE_LIBRTE_I40E_PMD
16219         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16220                                         res->target,
16221                                         res->mask,
16222                                         res->pkt_type);
16223 #endif
16224
16225         switch (ret) {
16226         case 0:
16227                 break;
16228         case -EINVAL:
16229                 printf("invalid ptype 0x%8x or 0x%8x\n",
16230                                 res->target, res->pkt_type);
16231                 break;
16232         case -ENODEV:
16233                 printf("invalid port_id %d\n", res->port_id);
16234                 break;
16235         case -ENOTSUP:
16236                 printf("function not implemented\n");
16237                 break;
16238         default:
16239                 printf("programming error: (%s)\n", strerror(-ret));
16240         }
16241 }
16242
16243 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16244         .f = cmd_ptype_mapping_replace_parsed,
16245         .data = NULL,
16246         .help_str =
16247                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16248         .tokens = {
16249                 (void *)&cmd_ptype_mapping_replace_ptype,
16250                 (void *)&cmd_ptype_mapping_replace_mapping,
16251                 (void *)&cmd_ptype_mapping_replace_replace,
16252                 (void *)&cmd_ptype_mapping_replace_port_id,
16253                 (void *)&cmd_ptype_mapping_replace_target,
16254                 (void *)&cmd_ptype_mapping_replace_mask,
16255                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16256                 NULL,
16257         },
16258 };
16259
16260 /* ptype mapping reset */
16261
16262 /* Common result structure for ptype mapping reset */
16263 struct cmd_ptype_mapping_reset_result {
16264         cmdline_fixed_string_t ptype;
16265         cmdline_fixed_string_t mapping;
16266         cmdline_fixed_string_t reset;
16267         portid_t port_id;
16268 };
16269
16270 /* Common CLI fields for ptype mapping reset*/
16271 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16272         TOKEN_STRING_INITIALIZER
16273                 (struct cmd_ptype_mapping_reset_result,
16274                  ptype, "ptype");
16275 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16276         TOKEN_STRING_INITIALIZER
16277                 (struct cmd_ptype_mapping_reset_result,
16278                  mapping, "mapping");
16279 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16280         TOKEN_STRING_INITIALIZER
16281                 (struct cmd_ptype_mapping_reset_result,
16282                  reset, "reset");
16283 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16284         TOKEN_NUM_INITIALIZER
16285                 (struct cmd_ptype_mapping_reset_result,
16286                  port_id, UINT16);
16287
16288 static void
16289 cmd_ptype_mapping_reset_parsed(
16290         void *parsed_result,
16291         __attribute__((unused)) struct cmdline *cl,
16292         __attribute__((unused)) void *data)
16293 {
16294         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16295         int ret = -ENOTSUP;
16296
16297         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16298                 return;
16299
16300 #ifdef RTE_LIBRTE_I40E_PMD
16301         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16302 #endif
16303
16304         switch (ret) {
16305         case 0:
16306                 break;
16307         case -ENODEV:
16308                 printf("invalid port_id %d\n", res->port_id);
16309                 break;
16310         case -ENOTSUP:
16311                 printf("function not implemented\n");
16312                 break;
16313         default:
16314                 printf("programming error: (%s)\n", strerror(-ret));
16315         }
16316 }
16317
16318 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16319         .f = cmd_ptype_mapping_reset_parsed,
16320         .data = NULL,
16321         .help_str = "ptype mapping reset <port_id>",
16322         .tokens = {
16323                 (void *)&cmd_ptype_mapping_reset_ptype,
16324                 (void *)&cmd_ptype_mapping_reset_mapping,
16325                 (void *)&cmd_ptype_mapping_reset_reset,
16326                 (void *)&cmd_ptype_mapping_reset_port_id,
16327                 NULL,
16328         },
16329 };
16330
16331 /* ptype mapping update */
16332
16333 /* Common result structure for ptype mapping update */
16334 struct cmd_ptype_mapping_update_result {
16335         cmdline_fixed_string_t ptype;
16336         cmdline_fixed_string_t mapping;
16337         cmdline_fixed_string_t reset;
16338         portid_t port_id;
16339         uint8_t hw_ptype;
16340         uint32_t sw_ptype;
16341 };
16342
16343 /* Common CLI fields for ptype mapping update*/
16344 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16345         TOKEN_STRING_INITIALIZER
16346                 (struct cmd_ptype_mapping_update_result,
16347                  ptype, "ptype");
16348 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16349         TOKEN_STRING_INITIALIZER
16350                 (struct cmd_ptype_mapping_update_result,
16351                  mapping, "mapping");
16352 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16353         TOKEN_STRING_INITIALIZER
16354                 (struct cmd_ptype_mapping_update_result,
16355                  reset, "update");
16356 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16357         TOKEN_NUM_INITIALIZER
16358                 (struct cmd_ptype_mapping_update_result,
16359                  port_id, UINT16);
16360 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16361         TOKEN_NUM_INITIALIZER
16362                 (struct cmd_ptype_mapping_update_result,
16363                  hw_ptype, UINT8);
16364 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16365         TOKEN_NUM_INITIALIZER
16366                 (struct cmd_ptype_mapping_update_result,
16367                  sw_ptype, UINT32);
16368
16369 static void
16370 cmd_ptype_mapping_update_parsed(
16371         void *parsed_result,
16372         __attribute__((unused)) struct cmdline *cl,
16373         __attribute__((unused)) void *data)
16374 {
16375         struct cmd_ptype_mapping_update_result *res = parsed_result;
16376         int ret = -ENOTSUP;
16377 #ifdef RTE_LIBRTE_I40E_PMD
16378         struct rte_pmd_i40e_ptype_mapping mapping;
16379 #endif
16380         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16381                 return;
16382
16383 #ifdef RTE_LIBRTE_I40E_PMD
16384         mapping.hw_ptype = res->hw_ptype;
16385         mapping.sw_ptype = res->sw_ptype;
16386         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16387                                                 &mapping,
16388                                                 1,
16389                                                 0);
16390 #endif
16391
16392         switch (ret) {
16393         case 0:
16394                 break;
16395         case -EINVAL:
16396                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16397                 break;
16398         case -ENODEV:
16399                 printf("invalid port_id %d\n", res->port_id);
16400                 break;
16401         case -ENOTSUP:
16402                 printf("function not implemented\n");
16403                 break;
16404         default:
16405                 printf("programming error: (%s)\n", strerror(-ret));
16406         }
16407 }
16408
16409 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16410         .f = cmd_ptype_mapping_update_parsed,
16411         .data = NULL,
16412         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16413         .tokens = {
16414                 (void *)&cmd_ptype_mapping_update_ptype,
16415                 (void *)&cmd_ptype_mapping_update_mapping,
16416                 (void *)&cmd_ptype_mapping_update_update,
16417                 (void *)&cmd_ptype_mapping_update_port_id,
16418                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16419                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16420                 NULL,
16421         },
16422 };
16423
16424 /* Common result structure for file commands */
16425 struct cmd_cmdfile_result {
16426         cmdline_fixed_string_t load;
16427         cmdline_fixed_string_t filename;
16428 };
16429
16430 /* Common CLI fields for file commands */
16431 cmdline_parse_token_string_t cmd_load_cmdfile =
16432         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16433 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16434         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16435
16436 static void
16437 cmd_load_from_file_parsed(
16438         void *parsed_result,
16439         __attribute__((unused)) struct cmdline *cl,
16440         __attribute__((unused)) void *data)
16441 {
16442         struct cmd_cmdfile_result *res = parsed_result;
16443
16444         cmdline_read_from_file(res->filename);
16445 }
16446
16447 cmdline_parse_inst_t cmd_load_from_file = {
16448         .f = cmd_load_from_file_parsed,
16449         .data = NULL,
16450         .help_str = "load <filename>",
16451         .tokens = {
16452                 (void *)&cmd_load_cmdfile,
16453                 (void *)&cmd_load_cmdfile_filename,
16454                 NULL,
16455         },
16456 };
16457
16458 /* Get Rx offloads capabilities */
16459 struct cmd_rx_offload_get_capa_result {
16460         cmdline_fixed_string_t show;
16461         cmdline_fixed_string_t port;
16462         portid_t port_id;
16463         cmdline_fixed_string_t rx_offload;
16464         cmdline_fixed_string_t capabilities;
16465 };
16466
16467 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16468         TOKEN_STRING_INITIALIZER
16469                 (struct cmd_rx_offload_get_capa_result,
16470                  show, "show");
16471 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16472         TOKEN_STRING_INITIALIZER
16473                 (struct cmd_rx_offload_get_capa_result,
16474                  port, "port");
16475 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16476         TOKEN_NUM_INITIALIZER
16477                 (struct cmd_rx_offload_get_capa_result,
16478                  port_id, UINT16);
16479 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16480         TOKEN_STRING_INITIALIZER
16481                 (struct cmd_rx_offload_get_capa_result,
16482                  rx_offload, "rx_offload");
16483 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16484         TOKEN_STRING_INITIALIZER
16485                 (struct cmd_rx_offload_get_capa_result,
16486                  capabilities, "capabilities");
16487
16488 static void
16489 print_rx_offloads(uint64_t offloads)
16490 {
16491         uint64_t single_offload;
16492         int begin;
16493         int end;
16494         int bit;
16495
16496         if (offloads == 0)
16497                 return;
16498
16499         begin = __builtin_ctzll(offloads);
16500         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16501
16502         single_offload = 1 << begin;
16503         for (bit = begin; bit < end; bit++) {
16504                 if (offloads & single_offload)
16505                         printf(" %s",
16506                                rte_eth_dev_rx_offload_name(single_offload));
16507                 single_offload <<= 1;
16508         }
16509 }
16510
16511 static void
16512 cmd_rx_offload_get_capa_parsed(
16513         void *parsed_result,
16514         __attribute__((unused)) struct cmdline *cl,
16515         __attribute__((unused)) void *data)
16516 {
16517         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16518         struct rte_eth_dev_info dev_info;
16519         portid_t port_id = res->port_id;
16520         uint64_t queue_offloads;
16521         uint64_t port_offloads;
16522
16523         rte_eth_dev_info_get(port_id, &dev_info);
16524         queue_offloads = dev_info.rx_queue_offload_capa;
16525         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16526
16527         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16528         printf("  Per Queue :");
16529         print_rx_offloads(queue_offloads);
16530
16531         printf("\n");
16532         printf("  Per Port  :");
16533         print_rx_offloads(port_offloads);
16534         printf("\n\n");
16535 }
16536
16537 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16538         .f = cmd_rx_offload_get_capa_parsed,
16539         .data = NULL,
16540         .help_str = "show port <port_id> rx_offload capabilities",
16541         .tokens = {
16542                 (void *)&cmd_rx_offload_get_capa_show,
16543                 (void *)&cmd_rx_offload_get_capa_port,
16544                 (void *)&cmd_rx_offload_get_capa_port_id,
16545                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16546                 (void *)&cmd_rx_offload_get_capa_capabilities,
16547                 NULL,
16548         }
16549 };
16550
16551 /* Get Rx offloads configuration */
16552 struct cmd_rx_offload_get_configuration_result {
16553         cmdline_fixed_string_t show;
16554         cmdline_fixed_string_t port;
16555         portid_t port_id;
16556         cmdline_fixed_string_t rx_offload;
16557         cmdline_fixed_string_t configuration;
16558 };
16559
16560 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16561         TOKEN_STRING_INITIALIZER
16562                 (struct cmd_rx_offload_get_configuration_result,
16563                  show, "show");
16564 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16565         TOKEN_STRING_INITIALIZER
16566                 (struct cmd_rx_offload_get_configuration_result,
16567                  port, "port");
16568 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16569         TOKEN_NUM_INITIALIZER
16570                 (struct cmd_rx_offload_get_configuration_result,
16571                  port_id, UINT16);
16572 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16573         TOKEN_STRING_INITIALIZER
16574                 (struct cmd_rx_offload_get_configuration_result,
16575                  rx_offload, "rx_offload");
16576 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16577         TOKEN_STRING_INITIALIZER
16578                 (struct cmd_rx_offload_get_configuration_result,
16579                  configuration, "configuration");
16580
16581 static void
16582 cmd_rx_offload_get_configuration_parsed(
16583         void *parsed_result,
16584         __attribute__((unused)) struct cmdline *cl,
16585         __attribute__((unused)) void *data)
16586 {
16587         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16588         struct rte_eth_dev_info dev_info;
16589         portid_t port_id = res->port_id;
16590         struct rte_port *port = &ports[port_id];
16591         uint64_t port_offloads;
16592         uint64_t queue_offloads;
16593         uint16_t nb_rx_queues;
16594         int q;
16595
16596         printf("Rx Offloading Configuration of port %d :\n", port_id);
16597
16598         port_offloads = port->dev_conf.rxmode.offloads;
16599         printf("  Port :");
16600         print_rx_offloads(port_offloads);
16601         printf("\n");
16602
16603         rte_eth_dev_info_get(port_id, &dev_info);
16604         nb_rx_queues = dev_info.nb_rx_queues;
16605         for (q = 0; q < nb_rx_queues; q++) {
16606                 queue_offloads = port->rx_conf[q].offloads;
16607                 printf("  Queue[%2d] :", q);
16608                 print_rx_offloads(queue_offloads);
16609                 printf("\n");
16610         }
16611         printf("\n");
16612 }
16613
16614 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16615         .f = cmd_rx_offload_get_configuration_parsed,
16616         .data = NULL,
16617         .help_str = "show port <port_id> rx_offload configuration",
16618         .tokens = {
16619                 (void *)&cmd_rx_offload_get_configuration_show,
16620                 (void *)&cmd_rx_offload_get_configuration_port,
16621                 (void *)&cmd_rx_offload_get_configuration_port_id,
16622                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16623                 (void *)&cmd_rx_offload_get_configuration_configuration,
16624                 NULL,
16625         }
16626 };
16627
16628 /* Enable/Disable a per port offloading */
16629 struct cmd_config_per_port_rx_offload_result {
16630         cmdline_fixed_string_t port;
16631         cmdline_fixed_string_t config;
16632         portid_t port_id;
16633         cmdline_fixed_string_t rx_offload;
16634         cmdline_fixed_string_t offload;
16635         cmdline_fixed_string_t on_off;
16636 };
16637
16638 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16639         TOKEN_STRING_INITIALIZER
16640                 (struct cmd_config_per_port_rx_offload_result,
16641                  port, "port");
16642 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16643         TOKEN_STRING_INITIALIZER
16644                 (struct cmd_config_per_port_rx_offload_result,
16645                  config, "config");
16646 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16647         TOKEN_NUM_INITIALIZER
16648                 (struct cmd_config_per_port_rx_offload_result,
16649                  port_id, UINT16);
16650 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16651         TOKEN_STRING_INITIALIZER
16652                 (struct cmd_config_per_port_rx_offload_result,
16653                  rx_offload, "rx_offload");
16654 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16655         TOKEN_STRING_INITIALIZER
16656                 (struct cmd_config_per_port_rx_offload_result,
16657                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16658                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16659                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16660                            "crc_strip#scatter#timestamp#security");
16661 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16662         TOKEN_STRING_INITIALIZER
16663                 (struct cmd_config_per_port_rx_offload_result,
16664                  on_off, "on#off");
16665
16666 static uint64_t
16667 search_rx_offload(const char *name)
16668 {
16669         uint64_t single_offload;
16670         const char *single_name;
16671         int found = 0;
16672         unsigned int bit;
16673
16674         single_offload = 1;
16675         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16676                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16677                 if (!strcasecmp(single_name, name)) {
16678                         found = 1;
16679                         break;
16680                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16681                         break;
16682                 else if (single_name == NULL)
16683                         break;
16684                 single_offload <<= 1;
16685         }
16686
16687         if (found)
16688                 return single_offload;
16689
16690         return 0;
16691 }
16692
16693 static void
16694 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16695                                 __attribute__((unused)) struct cmdline *cl,
16696                                 __attribute__((unused)) void *data)
16697 {
16698         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16699         portid_t port_id = res->port_id;
16700         struct rte_eth_dev_info dev_info;
16701         struct rte_port *port = &ports[port_id];
16702         uint64_t single_offload;
16703         uint16_t nb_rx_queues;
16704         int q;
16705
16706         if (port->port_status != RTE_PORT_STOPPED) {
16707                 printf("Error: Can't config offload when Port %d "
16708                        "is not stopped\n", port_id);
16709                 return;
16710         }
16711
16712         single_offload = search_rx_offload(res->offload);
16713         if (single_offload == 0) {
16714                 printf("Unknown offload name: %s\n", res->offload);
16715                 return;
16716         }
16717
16718         rte_eth_dev_info_get(port_id, &dev_info);
16719         nb_rx_queues = dev_info.nb_rx_queues;
16720         if (!strcmp(res->on_off, "on")) {
16721                 port->dev_conf.rxmode.offloads |= single_offload;
16722                 for (q = 0; q < nb_rx_queues; q++)
16723                         port->rx_conf[q].offloads |= single_offload;
16724         } else {
16725                 port->dev_conf.rxmode.offloads &= ~single_offload;
16726                 for (q = 0; q < nb_rx_queues; q++)
16727                         port->rx_conf[q].offloads &= ~single_offload;
16728         }
16729
16730         cmd_reconfig_device_queue(port_id, 1, 1);
16731 }
16732
16733 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16734         .f = cmd_config_per_port_rx_offload_parsed,
16735         .data = NULL,
16736         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16737                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16738                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16739                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16740                     "on|off",
16741         .tokens = {
16742                 (void *)&cmd_config_per_port_rx_offload_result_port,
16743                 (void *)&cmd_config_per_port_rx_offload_result_config,
16744                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16745                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16746                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16747                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16748                 NULL,
16749         }
16750 };
16751
16752 /* Enable/Disable a per queue offloading */
16753 struct cmd_config_per_queue_rx_offload_result {
16754         cmdline_fixed_string_t port;
16755         portid_t port_id;
16756         cmdline_fixed_string_t rxq;
16757         uint16_t queue_id;
16758         cmdline_fixed_string_t rx_offload;
16759         cmdline_fixed_string_t offload;
16760         cmdline_fixed_string_t on_off;
16761 };
16762
16763 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16764         TOKEN_STRING_INITIALIZER
16765                 (struct cmd_config_per_queue_rx_offload_result,
16766                  port, "port");
16767 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16768         TOKEN_NUM_INITIALIZER
16769                 (struct cmd_config_per_queue_rx_offload_result,
16770                  port_id, UINT16);
16771 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16772         TOKEN_STRING_INITIALIZER
16773                 (struct cmd_config_per_queue_rx_offload_result,
16774                  rxq, "rxq");
16775 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16776         TOKEN_NUM_INITIALIZER
16777                 (struct cmd_config_per_queue_rx_offload_result,
16778                  queue_id, UINT16);
16779 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16780         TOKEN_STRING_INITIALIZER
16781                 (struct cmd_config_per_queue_rx_offload_result,
16782                  rx_offload, "rx_offload");
16783 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16784         TOKEN_STRING_INITIALIZER
16785                 (struct cmd_config_per_queue_rx_offload_result,
16786                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16787                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16788                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16789                            "crc_strip#scatter#timestamp#security");
16790 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16791         TOKEN_STRING_INITIALIZER
16792                 (struct cmd_config_per_queue_rx_offload_result,
16793                  on_off, "on#off");
16794
16795 static void
16796 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16797                                 __attribute__((unused)) struct cmdline *cl,
16798                                 __attribute__((unused)) void *data)
16799 {
16800         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16801         struct rte_eth_dev_info dev_info;
16802         portid_t port_id = res->port_id;
16803         uint16_t queue_id = res->queue_id;
16804         struct rte_port *port = &ports[port_id];
16805         uint64_t single_offload;
16806
16807         if (port->port_status != RTE_PORT_STOPPED) {
16808                 printf("Error: Can't config offload when Port %d "
16809                        "is not stopped\n", port_id);
16810                 return;
16811         }
16812
16813         rte_eth_dev_info_get(port_id, &dev_info);
16814         if (queue_id >= dev_info.nb_rx_queues) {
16815                 printf("Error: input queue_id should be 0 ... "
16816                        "%d\n", dev_info.nb_rx_queues - 1);
16817                 return;
16818         }
16819
16820         single_offload = search_rx_offload(res->offload);
16821         if (single_offload == 0) {
16822                 printf("Unknown offload name: %s\n", res->offload);
16823                 return;
16824         }
16825
16826         if (!strcmp(res->on_off, "on"))
16827                 port->rx_conf[queue_id].offloads |= single_offload;
16828         else
16829                 port->rx_conf[queue_id].offloads &= ~single_offload;
16830
16831         cmd_reconfig_device_queue(port_id, 1, 1);
16832 }
16833
16834 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16835         .f = cmd_config_per_queue_rx_offload_parsed,
16836         .data = NULL,
16837         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16838                     "vlan_strip|ipv4_cksum|"
16839                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16840                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16841                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16842                     "on|off",
16843         .tokens = {
16844                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16845                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16846                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16847                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16848                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16849                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16850                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16851                 NULL,
16852         }
16853 };
16854
16855 /* Get Tx offloads capabilities */
16856 struct cmd_tx_offload_get_capa_result {
16857         cmdline_fixed_string_t show;
16858         cmdline_fixed_string_t port;
16859         portid_t port_id;
16860         cmdline_fixed_string_t tx_offload;
16861         cmdline_fixed_string_t capabilities;
16862 };
16863
16864 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16865         TOKEN_STRING_INITIALIZER
16866                 (struct cmd_tx_offload_get_capa_result,
16867                  show, "show");
16868 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16869         TOKEN_STRING_INITIALIZER
16870                 (struct cmd_tx_offload_get_capa_result,
16871                  port, "port");
16872 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16873         TOKEN_NUM_INITIALIZER
16874                 (struct cmd_tx_offload_get_capa_result,
16875                  port_id, UINT16);
16876 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16877         TOKEN_STRING_INITIALIZER
16878                 (struct cmd_tx_offload_get_capa_result,
16879                  tx_offload, "tx_offload");
16880 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16881         TOKEN_STRING_INITIALIZER
16882                 (struct cmd_tx_offload_get_capa_result,
16883                  capabilities, "capabilities");
16884
16885 static void
16886 print_tx_offloads(uint64_t offloads)
16887 {
16888         uint64_t single_offload;
16889         int begin;
16890         int end;
16891         int bit;
16892
16893         if (offloads == 0)
16894                 return;
16895
16896         begin = __builtin_ctzll(offloads);
16897         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16898
16899         single_offload = 1 << begin;
16900         for (bit = begin; bit < end; bit++) {
16901                 if (offloads & single_offload)
16902                         printf(" %s",
16903                                rte_eth_dev_tx_offload_name(single_offload));
16904                 single_offload <<= 1;
16905         }
16906 }
16907
16908 static void
16909 cmd_tx_offload_get_capa_parsed(
16910         void *parsed_result,
16911         __attribute__((unused)) struct cmdline *cl,
16912         __attribute__((unused)) void *data)
16913 {
16914         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16915         struct rte_eth_dev_info dev_info;
16916         portid_t port_id = res->port_id;
16917         uint64_t queue_offloads;
16918         uint64_t port_offloads;
16919
16920         rte_eth_dev_info_get(port_id, &dev_info);
16921         queue_offloads = dev_info.tx_queue_offload_capa;
16922         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16923
16924         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16925         printf("  Per Queue :");
16926         print_tx_offloads(queue_offloads);
16927
16928         printf("\n");
16929         printf("  Per Port  :");
16930         print_tx_offloads(port_offloads);
16931         printf("\n\n");
16932 }
16933
16934 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16935         .f = cmd_tx_offload_get_capa_parsed,
16936         .data = NULL,
16937         .help_str = "show port <port_id> tx_offload capabilities",
16938         .tokens = {
16939                 (void *)&cmd_tx_offload_get_capa_show,
16940                 (void *)&cmd_tx_offload_get_capa_port,
16941                 (void *)&cmd_tx_offload_get_capa_port_id,
16942                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16943                 (void *)&cmd_tx_offload_get_capa_capabilities,
16944                 NULL,
16945         }
16946 };
16947
16948 /* Get Tx offloads configuration */
16949 struct cmd_tx_offload_get_configuration_result {
16950         cmdline_fixed_string_t show;
16951         cmdline_fixed_string_t port;
16952         portid_t port_id;
16953         cmdline_fixed_string_t tx_offload;
16954         cmdline_fixed_string_t configuration;
16955 };
16956
16957 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16958         TOKEN_STRING_INITIALIZER
16959                 (struct cmd_tx_offload_get_configuration_result,
16960                  show, "show");
16961 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16962         TOKEN_STRING_INITIALIZER
16963                 (struct cmd_tx_offload_get_configuration_result,
16964                  port, "port");
16965 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16966         TOKEN_NUM_INITIALIZER
16967                 (struct cmd_tx_offload_get_configuration_result,
16968                  port_id, UINT16);
16969 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16970         TOKEN_STRING_INITIALIZER
16971                 (struct cmd_tx_offload_get_configuration_result,
16972                  tx_offload, "tx_offload");
16973 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16974         TOKEN_STRING_INITIALIZER
16975                 (struct cmd_tx_offload_get_configuration_result,
16976                  configuration, "configuration");
16977
16978 static void
16979 cmd_tx_offload_get_configuration_parsed(
16980         void *parsed_result,
16981         __attribute__((unused)) struct cmdline *cl,
16982         __attribute__((unused)) void *data)
16983 {
16984         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16985         struct rte_eth_dev_info dev_info;
16986         portid_t port_id = res->port_id;
16987         struct rte_port *port = &ports[port_id];
16988         uint64_t port_offloads;
16989         uint64_t queue_offloads;
16990         uint16_t nb_tx_queues;
16991         int q;
16992
16993         printf("Tx Offloading Configuration of port %d :\n", port_id);
16994
16995         port_offloads = port->dev_conf.txmode.offloads;
16996         printf("  Port :");
16997         print_tx_offloads(port_offloads);
16998         printf("\n");
16999
17000         rte_eth_dev_info_get(port_id, &dev_info);
17001         nb_tx_queues = dev_info.nb_tx_queues;
17002         for (q = 0; q < nb_tx_queues; q++) {
17003                 queue_offloads = port->tx_conf[q].offloads;
17004                 printf("  Queue[%2d] :", q);
17005                 print_tx_offloads(queue_offloads);
17006                 printf("\n");
17007         }
17008         printf("\n");
17009 }
17010
17011 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17012         .f = cmd_tx_offload_get_configuration_parsed,
17013         .data = NULL,
17014         .help_str = "show port <port_id> tx_offload configuration",
17015         .tokens = {
17016                 (void *)&cmd_tx_offload_get_configuration_show,
17017                 (void *)&cmd_tx_offload_get_configuration_port,
17018                 (void *)&cmd_tx_offload_get_configuration_port_id,
17019                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17020                 (void *)&cmd_tx_offload_get_configuration_configuration,
17021                 NULL,
17022         }
17023 };
17024
17025 /* Enable/Disable a per port offloading */
17026 struct cmd_config_per_port_tx_offload_result {
17027         cmdline_fixed_string_t port;
17028         cmdline_fixed_string_t config;
17029         portid_t port_id;
17030         cmdline_fixed_string_t tx_offload;
17031         cmdline_fixed_string_t offload;
17032         cmdline_fixed_string_t on_off;
17033 };
17034
17035 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17036         TOKEN_STRING_INITIALIZER
17037                 (struct cmd_config_per_port_tx_offload_result,
17038                  port, "port");
17039 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17040         TOKEN_STRING_INITIALIZER
17041                 (struct cmd_config_per_port_tx_offload_result,
17042                  config, "config");
17043 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17044         TOKEN_NUM_INITIALIZER
17045                 (struct cmd_config_per_port_tx_offload_result,
17046                  port_id, UINT16);
17047 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17048         TOKEN_STRING_INITIALIZER
17049                 (struct cmd_config_per_port_tx_offload_result,
17050                  tx_offload, "tx_offload");
17051 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17052         TOKEN_STRING_INITIALIZER
17053                 (struct cmd_config_per_port_tx_offload_result,
17054                  offload, "vlan_insert#ipv4_cksum#udp_cksum#udp_cksum#"
17055                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17056                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17057                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17058                           "mt_lockfree#multi_segs#fast_free#security");
17059 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17060         TOKEN_STRING_INITIALIZER
17061                 (struct cmd_config_per_port_tx_offload_result,
17062                  on_off, "on#off");
17063
17064 static uint64_t
17065 search_tx_offload(const char *name)
17066 {
17067         uint64_t single_offload;
17068         const char *single_name;
17069         int found = 0;
17070         unsigned int bit;
17071
17072         single_offload = 1;
17073         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17074                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17075                 if (!strcasecmp(single_name, name)) {
17076                         found = 1;
17077                         break;
17078                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17079                         break;
17080                 else if (single_name == NULL)
17081                         break;
17082                 single_offload <<= 1;
17083         }
17084
17085         if (found)
17086                 return single_offload;
17087
17088         return 0;
17089 }
17090
17091 static void
17092 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17093                                 __attribute__((unused)) struct cmdline *cl,
17094                                 __attribute__((unused)) void *data)
17095 {
17096         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17097         portid_t port_id = res->port_id;
17098         struct rte_eth_dev_info dev_info;
17099         struct rte_port *port = &ports[port_id];
17100         uint64_t single_offload;
17101         uint16_t nb_tx_queues;
17102         int q;
17103
17104         if (port->port_status != RTE_PORT_STOPPED) {
17105                 printf("Error: Can't config offload when Port %d "
17106                        "is not stopped\n", port_id);
17107                 return;
17108         }
17109
17110         single_offload = search_tx_offload(res->offload);
17111         if (single_offload == 0) {
17112                 printf("Unknown offload name: %s\n", res->offload);
17113                 return;
17114         }
17115
17116         rte_eth_dev_info_get(port_id, &dev_info);
17117         nb_tx_queues = dev_info.nb_tx_queues;
17118         if (!strcmp(res->on_off, "on")) {
17119                 port->dev_conf.txmode.offloads |= single_offload;
17120                 for (q = 0; q < nb_tx_queues; q++)
17121                         port->tx_conf[q].offloads |= single_offload;
17122         } else {
17123                 port->dev_conf.txmode.offloads &= ~single_offload;
17124                 for (q = 0; q < nb_tx_queues; q++)
17125                         port->tx_conf[q].offloads &= ~single_offload;
17126         }
17127
17128         cmd_reconfig_device_queue(port_id, 1, 1);
17129 }
17130
17131 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17132         .f = cmd_config_per_port_tx_offload_parsed,
17133         .data = NULL,
17134         .help_str = "port config <port_id> tx_offload "
17135                     "vlan_insert|ipv4_cksum|udp_cksum|udp_cksum|"
17136                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17137                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17138                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17139                     "mt_lockfree|multi_segs|fast_free|security "
17140                     "on|off",
17141         .tokens = {
17142                 (void *)&cmd_config_per_port_tx_offload_result_port,
17143                 (void *)&cmd_config_per_port_tx_offload_result_config,
17144                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17145                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17146                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17147                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17148                 NULL,
17149         }
17150 };
17151
17152 /* Enable/Disable a per queue offloading */
17153 struct cmd_config_per_queue_tx_offload_result {
17154         cmdline_fixed_string_t port;
17155         portid_t port_id;
17156         cmdline_fixed_string_t txq;
17157         uint16_t queue_id;
17158         cmdline_fixed_string_t tx_offload;
17159         cmdline_fixed_string_t offload;
17160         cmdline_fixed_string_t on_off;
17161 };
17162
17163 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17164         TOKEN_STRING_INITIALIZER
17165                 (struct cmd_config_per_queue_tx_offload_result,
17166                  port, "port");
17167 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17168         TOKEN_NUM_INITIALIZER
17169                 (struct cmd_config_per_queue_tx_offload_result,
17170                  port_id, UINT16);
17171 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17172         TOKEN_STRING_INITIALIZER
17173                 (struct cmd_config_per_queue_tx_offload_result,
17174                  txq, "txq");
17175 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17176         TOKEN_NUM_INITIALIZER
17177                 (struct cmd_config_per_queue_tx_offload_result,
17178                  queue_id, UINT16);
17179 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17180         TOKEN_STRING_INITIALIZER
17181                 (struct cmd_config_per_queue_tx_offload_result,
17182                  tx_offload, "tx_offload");
17183 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17184         TOKEN_STRING_INITIALIZER
17185                 (struct cmd_config_per_queue_tx_offload_result,
17186                  offload, "vlan_insert#ipv4_cksum#udp_cksum#udp_cksum#"
17187                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17188                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17189                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17190                           "mt_lockfree#multi_segs#fast_free#security");
17191 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17192         TOKEN_STRING_INITIALIZER
17193                 (struct cmd_config_per_queue_tx_offload_result,
17194                  on_off, "on#off");
17195
17196 static void
17197 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17198                                 __attribute__((unused)) struct cmdline *cl,
17199                                 __attribute__((unused)) void *data)
17200 {
17201         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17202         struct rte_eth_dev_info dev_info;
17203         portid_t port_id = res->port_id;
17204         uint16_t queue_id = res->queue_id;
17205         struct rte_port *port = &ports[port_id];
17206         uint64_t single_offload;
17207
17208         if (port->port_status != RTE_PORT_STOPPED) {
17209                 printf("Error: Can't config offload when Port %d "
17210                        "is not stopped\n", port_id);
17211                 return;
17212         }
17213
17214         rte_eth_dev_info_get(port_id, &dev_info);
17215         if (queue_id >= dev_info.nb_tx_queues) {
17216                 printf("Error: input queue_id should be 0 ... "
17217                        "%d\n", dev_info.nb_tx_queues - 1);
17218                 return;
17219         }
17220
17221         single_offload = search_tx_offload(res->offload);
17222         if (single_offload == 0) {
17223                 printf("Unknown offload name: %s\n", res->offload);
17224                 return;
17225         }
17226
17227         if (!strcmp(res->on_off, "on"))
17228                 port->tx_conf[queue_id].offloads |= single_offload;
17229         else
17230                 port->tx_conf[queue_id].offloads &= ~single_offload;
17231
17232         cmd_reconfig_device_queue(port_id, 1, 1);
17233 }
17234
17235 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17236         .f = cmd_config_per_queue_tx_offload_parsed,
17237         .data = NULL,
17238         .help_str = "port <port_id> txq <queue_id> tx_offload "
17239                     "vlan_insert|ipv4_cksum|udp_cksum|udp_cksum|"
17240                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17241                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17242                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17243                     "mt_lockfree|multi_segs|fast_free|security "
17244                     "on|off",
17245         .tokens = {
17246                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17247                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17248                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17249                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17250                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17251                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17252                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17253                 NULL,
17254         }
17255 };
17256
17257 /* ******************************************************************************** */
17258
17259 /* list of instructions */
17260 cmdline_parse_ctx_t main_ctx[] = {
17261         (cmdline_parse_inst_t *)&cmd_help_brief,
17262         (cmdline_parse_inst_t *)&cmd_help_long,
17263         (cmdline_parse_inst_t *)&cmd_quit,
17264         (cmdline_parse_inst_t *)&cmd_load_from_file,
17265         (cmdline_parse_inst_t *)&cmd_showport,
17266         (cmdline_parse_inst_t *)&cmd_showqueue,
17267         (cmdline_parse_inst_t *)&cmd_showportall,
17268         (cmdline_parse_inst_t *)&cmd_showcfg,
17269         (cmdline_parse_inst_t *)&cmd_start,
17270         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17271         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17272         (cmdline_parse_inst_t *)&cmd_set_link_up,
17273         (cmdline_parse_inst_t *)&cmd_set_link_down,
17274         (cmdline_parse_inst_t *)&cmd_reset,
17275         (cmdline_parse_inst_t *)&cmd_set_numbers,
17276         (cmdline_parse_inst_t *)&cmd_set_log,
17277         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17278         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17279         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17280         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17281         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17282         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17283         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17284         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17285         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17286         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17287         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17288         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17289         (cmdline_parse_inst_t *)&cmd_set_link_check,
17290         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17291         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17292         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17293         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17294 #ifdef RTE_LIBRTE_PMD_BOND
17295         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17296         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17297         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17298         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17299         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17300         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17301         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17302         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17303         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17304         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17305         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17306 #endif
17307         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17308         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17309         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17310         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17311         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17312         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17313         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17314         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17315         (cmdline_parse_inst_t *)&cmd_csum_set,
17316         (cmdline_parse_inst_t *)&cmd_csum_show,
17317         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17318         (cmdline_parse_inst_t *)&cmd_tso_set,
17319         (cmdline_parse_inst_t *)&cmd_tso_show,
17320         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17321         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17322         (cmdline_parse_inst_t *)&cmd_gro_enable,
17323         (cmdline_parse_inst_t *)&cmd_gro_flush,
17324         (cmdline_parse_inst_t *)&cmd_gro_show,
17325         (cmdline_parse_inst_t *)&cmd_gso_enable,
17326         (cmdline_parse_inst_t *)&cmd_gso_size,
17327         (cmdline_parse_inst_t *)&cmd_gso_show,
17328         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17329         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17330         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17331         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17332         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17333         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17334         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17335         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17336         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17337         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17338         (cmdline_parse_inst_t *)&cmd_config_dcb,
17339         (cmdline_parse_inst_t *)&cmd_read_reg,
17340         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17341         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17342         (cmdline_parse_inst_t *)&cmd_write_reg,
17343         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17344         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17345         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17346         (cmdline_parse_inst_t *)&cmd_stop,
17347         (cmdline_parse_inst_t *)&cmd_mac_addr,
17348         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17349         (cmdline_parse_inst_t *)&cmd_set_qmap,
17350         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17351         (cmdline_parse_inst_t *)&cmd_operate_port,
17352         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17353         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17354         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17355         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17356         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17357         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17358         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17359         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17360         (cmdline_parse_inst_t *)&cmd_config_mtu,
17361         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17362         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17363         (cmdline_parse_inst_t *)&cmd_config_rss,
17364         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17365         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17366         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17367         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17368         (cmdline_parse_inst_t *)&cmd_showport_reta,
17369         (cmdline_parse_inst_t *)&cmd_config_burst,
17370         (cmdline_parse_inst_t *)&cmd_config_thresh,
17371         (cmdline_parse_inst_t *)&cmd_config_threshold,
17372         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17373         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17374         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17375         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17376         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17377         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17378         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17379         (cmdline_parse_inst_t *)&cmd_global_config,
17380         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17381         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17382         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17383         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17384         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17385         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17386         (cmdline_parse_inst_t *)&cmd_dump,
17387         (cmdline_parse_inst_t *)&cmd_dump_one,
17388         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17389         (cmdline_parse_inst_t *)&cmd_syn_filter,
17390         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17391         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17392         (cmdline_parse_inst_t *)&cmd_flex_filter,
17393         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17394         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17395         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17396         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17397         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17398         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17399         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17400         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17401         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17402         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17403         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17404         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17405         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17406         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17407         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17408         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17409         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17410         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17411         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17412         (cmdline_parse_inst_t *)&cmd_flow,
17413         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17414         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17415         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17416         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17417         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17418         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17419         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17420         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17421         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17422         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17423         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17424         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17425         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17426         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17427         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17428         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17429         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17430         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17431         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17432         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17433         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17434         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17435         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17436         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17437         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17438         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17439         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17440         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17441         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17442         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17443         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17444         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17445         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17446         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17447         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17448         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17449         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17450         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17451         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17452         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17453         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17454         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17455         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17456         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17457         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17458         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17459         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17460         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17461         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17462 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17463         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17464 #endif
17465         (cmdline_parse_inst_t *)&cmd_ddp_add,
17466         (cmdline_parse_inst_t *)&cmd_ddp_del,
17467         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17468         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17469         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17470         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17471         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17472         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17473         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17474         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17475         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17476         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17477
17478         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17479         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17480         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17481         (cmdline_parse_inst_t *)&cmd_queue_region,
17482         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17483         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17484         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17485         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17486         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17487         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17488         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17489         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17490         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17491         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17492         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17493         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17494         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17495         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17496         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17497         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17498         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17499         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17500         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17501         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17502         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17503         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17504         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17505         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17506         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17507         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17508         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17509         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17510         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17511         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17512         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17513         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17514 #ifdef RTE_LIBRTE_BPF
17515         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17516         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17517 #endif
17518         NULL,
17519 };
17520
17521 /* read cmdline commands from file */
17522 void
17523 cmdline_read_from_file(const char *filename)
17524 {
17525         struct cmdline *cl;
17526
17527         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17528         if (cl == NULL) {
17529                 printf("Failed to create file based cmdline context: %s\n",
17530                        filename);
17531                 return;
17532         }
17533
17534         cmdline_interact(cl);
17535         cmdline_quit(cl);
17536
17537         cmdline_free(cl);
17538
17539         printf("Read CLI commands from %s\n", filename);
17540 }
17541
17542 /* prompt function, called from main on MASTER lcore */
17543 void
17544 prompt(void)
17545 {
17546         /* initialize non-constant commands */
17547         cmd_set_fwd_mode_init();
17548         cmd_set_fwd_retry_mode_init();
17549
17550         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17551         if (testpmd_cl == NULL)
17552                 return;
17553         cmdline_interact(testpmd_cl);
17554         cmdline_stdin_exit(testpmd_cl);
17555 }
17556
17557 void
17558 prompt_exit(void)
17559 {
17560         if (testpmd_cl != NULL)
17561                 cmdline_quit(testpmd_cl);
17562 }
17563
17564 static void
17565 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17566 {
17567         if (id == (portid_t)RTE_PORT_ALL) {
17568                 portid_t pid;
17569
17570                 RTE_ETH_FOREACH_DEV(pid) {
17571                         /* check if need_reconfig has been set to 1 */
17572                         if (ports[pid].need_reconfig == 0)
17573                                 ports[pid].need_reconfig = dev;
17574                         /* check if need_reconfig_queues has been set to 1 */
17575                         if (ports[pid].need_reconfig_queues == 0)
17576                                 ports[pid].need_reconfig_queues = queue;
17577                 }
17578         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17579                 /* check if need_reconfig has been set to 1 */
17580                 if (ports[id].need_reconfig == 0)
17581                         ports[id].need_reconfig = dev;
17582                 /* check if need_reconfig_queues has been set to 1 */
17583                 if (ports[id].need_reconfig_queues == 0)
17584                         ports[id].need_reconfig_queues = queue;
17585         }
17586 }