ethdev: make default behavior CRC strip on Rx
[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                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
785                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
786                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
787                         "       Configure the VXLAN encapsulation for flows.\n\n"
788
789                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
790                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
791                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
792                         " eth-dst (eth-dst)\n"
793                         "       Configure the VXLAN encapsulation for flows.\n\n"
794
795                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
796                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
797                         " (eth-dst)\n"
798                         "       Configure the NVGRE encapsulation for flows.\n\n"
799
800                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
801                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
802                         " eth-src (eth-src) eth-dst (eth-dst)\n"
803                         "       Configure the NVGRE encapsulation for flows.\n\n"
804
805                         , list_pkt_forwarding_modes()
806                 );
807         }
808
809         if (show_all || !strcmp(res->section, "ports")) {
810
811                 cmdline_printf(
812                         cl,
813                         "\n"
814                         "Port Operations:\n"
815                         "----------------\n\n"
816
817                         "port start (port_id|all)\n"
818                         "    Start all ports or port_id.\n\n"
819
820                         "port stop (port_id|all)\n"
821                         "    Stop all ports or port_id.\n\n"
822
823                         "port close (port_id|all)\n"
824                         "    Close all ports or port_id.\n\n"
825
826                         "port attach (ident)\n"
827                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
828
829                         "port detach (port_id)\n"
830                         "    Detach physical or virtual dev by port_id\n\n"
831
832                         "port config (port_id|all)"
833                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
834                         " duplex (half|full|auto)\n"
835                         "    Set speed and duplex for all ports or port_id\n\n"
836
837                         "port config (port_id|all) loopback (mode)\n"
838                         "    Set loopback mode for all ports or port_id\n\n"
839
840                         "port config all (rxq|txq|rxd|txd) (value)\n"
841                         "    Set number for rxq/txq/rxd/txd.\n\n"
842
843                         "port config all max-pkt-len (value)\n"
844                         "    Set the max packet length.\n\n"
845
846                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
847                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
848                         " (on|off)\n"
849                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
850                         " for ports.\n\n"
851
852                         "port config all rss (all|default|ip|tcp|udp|sctp|"
853                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
854                         "    Set the RSS mode.\n\n"
855
856                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
857                         "    Set the RSS redirection table.\n\n"
858
859                         "port config (port_id) dcb vt (on|off) (traffic_class)"
860                         " pfc (on|off)\n"
861                         "    Set the DCB mode.\n\n"
862
863                         "port config all burst (value)\n"
864                         "    Set the number of packets per burst.\n\n"
865
866                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
867                         " (value)\n"
868                         "    Set the ring prefetch/host/writeback threshold"
869                         " for tx/rx queue.\n\n"
870
871                         "port config all (txfreet|txrst|rxfreet) (value)\n"
872                         "    Set free threshold for rx/tx, or set"
873                         " tx rs bit threshold.\n\n"
874                         "port config mtu X value\n"
875                         "    Set the MTU of port X to a given value\n\n"
876
877                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
878                         "    Set a rx/tx queue's ring size configuration, the new"
879                         " value will take effect after command that (re-)start the port"
880                         " or command that setup the specific queue\n\n"
881
882                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
883                         "    Start/stop a rx/tx queue of port X. Only take effect"
884                         " when port X is started\n\n"
885
886                         "port (port_id) (rxq|txq) (queue_id) setup\n"
887                         "    Setup a rx/tx queue of port X.\n\n"
888
889                         "port config (port_id|all) l2-tunnel E-tag ether-type"
890                         " (value)\n"
891                         "    Set the value of E-tag ether-type.\n\n"
892
893                         "port config (port_id|all) l2-tunnel E-tag"
894                         " (enable|disable)\n"
895                         "    Enable/disable the E-tag support.\n\n"
896
897                         "port config (port_id) pctype mapping reset\n"
898                         "    Reset flow type to pctype mapping on a port\n\n"
899
900                         "port config (port_id) pctype mapping update"
901                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
902                         "    Update a flow type to pctype mapping item on a port\n\n"
903
904                         "port config (port_id) pctype (pctype_id) hash_inset|"
905                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
906                         " (field_idx)\n"
907                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
908
909                         "port config (port_id) pctype (pctype_id) hash_inset|"
910                         "fdir_inset|fdir_flx_inset clear all"
911                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
912
913                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
914                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
915                 );
916         }
917
918         if (show_all || !strcmp(res->section, "registers")) {
919
920                 cmdline_printf(
921                         cl,
922                         "\n"
923                         "Registers:\n"
924                         "----------\n\n"
925
926                         "read reg (port_id) (address)\n"
927                         "    Display value of a port register.\n\n"
928
929                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
930                         "    Display a port register bit field.\n\n"
931
932                         "read regbit (port_id) (address) (bit_x)\n"
933                         "    Display a single port register bit.\n\n"
934
935                         "write reg (port_id) (address) (value)\n"
936                         "    Set value of a port register.\n\n"
937
938                         "write regfield (port_id) (address) (bit_x) (bit_y)"
939                         " (value)\n"
940                         "    Set bit field of a port register.\n\n"
941
942                         "write regbit (port_id) (address) (bit_x) (value)\n"
943                         "    Set single bit value of a port register.\n\n"
944                 );
945         }
946         if (show_all || !strcmp(res->section, "filters")) {
947
948                 cmdline_printf(
949                         cl,
950                         "\n"
951                         "filters:\n"
952                         "--------\n\n"
953
954                         "ethertype_filter (port_id) (add|del)"
955                         " (mac_addr|mac_ignr) (mac_address) ethertype"
956                         " (ether_type) (drop|fwd) queue (queue_id)\n"
957                         "    Add/Del an ethertype filter.\n\n"
958
959                         "2tuple_filter (port_id) (add|del)"
960                         " dst_port (dst_port_value) protocol (protocol_value)"
961                         " mask (mask_value) tcp_flags (tcp_flags_value)"
962                         " priority (prio_value) queue (queue_id)\n"
963                         "    Add/Del a 2tuple filter.\n\n"
964
965                         "5tuple_filter (port_id) (add|del)"
966                         " dst_ip (dst_address) src_ip (src_address)"
967                         " dst_port (dst_port_value) src_port (src_port_value)"
968                         " protocol (protocol_value)"
969                         " mask (mask_value) tcp_flags (tcp_flags_value)"
970                         " priority (prio_value) queue (queue_id)\n"
971                         "    Add/Del a 5tuple filter.\n\n"
972
973                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
974                         "    Add/Del syn filter.\n\n"
975
976                         "flex_filter (port_id) (add|del) len (len_value)"
977                         " bytes (bytes_value) mask (mask_value)"
978                         " priority (prio_value) queue (queue_id)\n"
979                         "    Add/Del a flex filter.\n\n"
980
981                         "flow_director_filter (port_id) mode IP (add|del|update)"
982                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
983                         " src (src_ip_address) dst (dst_ip_address)"
984                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
985                         " vlan (vlan_value) flexbytes (flexbytes_value)"
986                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
987                         " fd_id (fd_id_value)\n"
988                         "    Add/Del an IP type flow director filter.\n\n"
989
990                         "flow_director_filter (port_id) mode IP (add|del|update)"
991                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
992                         " src (src_ip_address) (src_port)"
993                         " dst (dst_ip_address) (dst_port)"
994                         " tos (tos_value) ttl (ttl_value)"
995                         " vlan (vlan_value) flexbytes (flexbytes_value)"
996                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
997                         " fd_id (fd_id_value)\n"
998                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
999
1000                         "flow_director_filter (port_id) mode IP (add|del|update)"
1001                         " flow (ipv4-sctp|ipv6-sctp)"
1002                         " src (src_ip_address) (src_port)"
1003                         " dst (dst_ip_address) (dst_port)"
1004                         " tag (verification_tag) "
1005                         " tos (tos_value) ttl (ttl_value)"
1006                         " vlan (vlan_value)"
1007                         " flexbytes (flexbytes_value) (drop|fwd)"
1008                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1009                         "    Add/Del a SCTP type flow director filter.\n\n"
1010
1011                         "flow_director_filter (port_id) mode IP (add|del|update)"
1012                         " flow l2_payload ether (ethertype)"
1013                         " flexbytes (flexbytes_value) (drop|fwd)"
1014                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1015                         "    Add/Del a l2 payload type flow director filter.\n\n"
1016
1017                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1018                         " mac (mac_address) vlan (vlan_value)"
1019                         " flexbytes (flexbytes_value) (drop|fwd)"
1020                         " queue (queue_id) fd_id (fd_id_value)\n"
1021                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1022
1023                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1024                         " mac (mac_address) vlan (vlan_value)"
1025                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1026                         " flexbytes (flexbytes_value) (drop|fwd)"
1027                         " queue (queue_id) fd_id (fd_id_value)\n"
1028                         "    Add/Del a Tunnel flow director filter.\n\n"
1029
1030                         "flow_director_filter (port_id) mode raw (add|del|update)"
1031                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1032                         " fd_id (fd_id_value) packet (packet file name)\n"
1033                         "    Add/Del a raw type flow director filter.\n\n"
1034
1035                         "flush_flow_director (port_id)\n"
1036                         "    Flush all flow director entries of a device.\n\n"
1037
1038                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1039                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1040                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1041                         "    Set flow director IP mask.\n\n"
1042
1043                         "flow_director_mask (port_id) mode MAC-VLAN"
1044                         " vlan (vlan_value)\n"
1045                         "    Set flow director MAC-VLAN mask.\n\n"
1046
1047                         "flow_director_mask (port_id) mode Tunnel"
1048                         " vlan (vlan_value) mac (mac_value)"
1049                         " tunnel-type (tunnel_type_value)"
1050                         " tunnel-id (tunnel_id_value)\n"
1051                         "    Set flow director Tunnel mask.\n\n"
1052
1053                         "flow_director_flex_mask (port_id)"
1054                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1055                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1056                         " (mask)\n"
1057                         "    Configure mask of flex payload.\n\n"
1058
1059                         "flow_director_flex_payload (port_id)"
1060                         " (raw|l2|l3|l4) (config)\n"
1061                         "    Configure flex payload selection.\n\n"
1062
1063                         "get_sym_hash_ena_per_port (port_id)\n"
1064                         "    get symmetric hash enable configuration per port.\n\n"
1065
1066                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1067                         "    set symmetric hash enable configuration per port"
1068                         " to enable or disable.\n\n"
1069
1070                         "get_hash_global_config (port_id)\n"
1071                         "    Get the global configurations of hash filters.\n\n"
1072
1073                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1074                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1075                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1076                         " (enable|disable)\n"
1077                         "    Set the global configurations of hash filters.\n\n"
1078
1079                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1080                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1081                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1082                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1083                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1084                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1085                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1086                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1087                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1088                         "fld-8th|none) (select|add)\n"
1089                         "    Set the input set for hash.\n\n"
1090
1091                         "set_fdir_input_set (port_id) "
1092                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1093                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1094                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1095                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1096                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1097                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1098                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1099                         " (select|add)\n"
1100                         "    Set the input set for FDir.\n\n"
1101
1102                         "flow validate {port_id}"
1103                         " [group {group_id}] [priority {level}]"
1104                         " [ingress] [egress]"
1105                         " pattern {item} [/ {item} [...]] / end"
1106                         " actions {action} [/ {action} [...]] / end\n"
1107                         "    Check whether a flow rule can be created.\n\n"
1108
1109                         "flow create {port_id}"
1110                         " [group {group_id}] [priority {level}]"
1111                         " [ingress] [egress]"
1112                         " pattern {item} [/ {item} [...]] / end"
1113                         " actions {action} [/ {action} [...]] / end\n"
1114                         "    Create a flow rule.\n\n"
1115
1116                         "flow destroy {port_id} rule {rule_id} [...]\n"
1117                         "    Destroy specific flow rules.\n\n"
1118
1119                         "flow flush {port_id}\n"
1120                         "    Destroy all flow rules.\n\n"
1121
1122                         "flow query {port_id} {rule_id} {action}\n"
1123                         "    Query an existing flow rule.\n\n"
1124
1125                         "flow list {port_id} [group {group_id}] [...]\n"
1126                         "    List existing flow rules sorted by priority,"
1127                         " filtered by group identifiers.\n\n"
1128
1129                         "flow isolate {port_id} {boolean}\n"
1130                         "    Restrict ingress traffic to the defined"
1131                         " flow rules\n\n"
1132                 );
1133         }
1134 }
1135
1136 cmdline_parse_token_string_t cmd_help_long_help =
1137         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1138
1139 cmdline_parse_token_string_t cmd_help_long_section =
1140         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1141                         "all#control#display#config#"
1142                         "ports#registers#filters");
1143
1144 cmdline_parse_inst_t cmd_help_long = {
1145         .f = cmd_help_long_parsed,
1146         .data = NULL,
1147         .help_str = "help all|control|display|config|ports|register|filters: "
1148                 "Show help",
1149         .tokens = {
1150                 (void *)&cmd_help_long_help,
1151                 (void *)&cmd_help_long_section,
1152                 NULL,
1153         },
1154 };
1155
1156
1157 /* *** start/stop/close all ports *** */
1158 struct cmd_operate_port_result {
1159         cmdline_fixed_string_t keyword;
1160         cmdline_fixed_string_t name;
1161         cmdline_fixed_string_t value;
1162 };
1163
1164 static void cmd_operate_port_parsed(void *parsed_result,
1165                                 __attribute__((unused)) struct cmdline *cl,
1166                                 __attribute__((unused)) void *data)
1167 {
1168         struct cmd_operate_port_result *res = parsed_result;
1169
1170         if (!strcmp(res->name, "start"))
1171                 start_port(RTE_PORT_ALL);
1172         else if (!strcmp(res->name, "stop"))
1173                 stop_port(RTE_PORT_ALL);
1174         else if (!strcmp(res->name, "close"))
1175                 close_port(RTE_PORT_ALL);
1176         else if (!strcmp(res->name, "reset"))
1177                 reset_port(RTE_PORT_ALL);
1178         else
1179                 printf("Unknown parameter\n");
1180 }
1181
1182 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1183         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1184                                                                 "port");
1185 cmdline_parse_token_string_t cmd_operate_port_all_port =
1186         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1187                                                 "start#stop#close#reset");
1188 cmdline_parse_token_string_t cmd_operate_port_all_all =
1189         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1190
1191 cmdline_parse_inst_t cmd_operate_port = {
1192         .f = cmd_operate_port_parsed,
1193         .data = NULL,
1194         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1195         .tokens = {
1196                 (void *)&cmd_operate_port_all_cmd,
1197                 (void *)&cmd_operate_port_all_port,
1198                 (void *)&cmd_operate_port_all_all,
1199                 NULL,
1200         },
1201 };
1202
1203 /* *** start/stop/close specific port *** */
1204 struct cmd_operate_specific_port_result {
1205         cmdline_fixed_string_t keyword;
1206         cmdline_fixed_string_t name;
1207         uint8_t value;
1208 };
1209
1210 static void cmd_operate_specific_port_parsed(void *parsed_result,
1211                         __attribute__((unused)) struct cmdline *cl,
1212                                 __attribute__((unused)) void *data)
1213 {
1214         struct cmd_operate_specific_port_result *res = parsed_result;
1215
1216         if (!strcmp(res->name, "start"))
1217                 start_port(res->value);
1218         else if (!strcmp(res->name, "stop"))
1219                 stop_port(res->value);
1220         else if (!strcmp(res->name, "close"))
1221                 close_port(res->value);
1222         else if (!strcmp(res->name, "reset"))
1223                 reset_port(res->value);
1224         else
1225                 printf("Unknown parameter\n");
1226 }
1227
1228 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1229         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1230                                                         keyword, "port");
1231 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1232         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1233                                                 name, "start#stop#close#reset");
1234 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1235         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1236                                                         value, UINT8);
1237
1238 cmdline_parse_inst_t cmd_operate_specific_port = {
1239         .f = cmd_operate_specific_port_parsed,
1240         .data = NULL,
1241         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1242         .tokens = {
1243                 (void *)&cmd_operate_specific_port_cmd,
1244                 (void *)&cmd_operate_specific_port_port,
1245                 (void *)&cmd_operate_specific_port_id,
1246                 NULL,
1247         },
1248 };
1249
1250 /* *** attach a specified port *** */
1251 struct cmd_operate_attach_port_result {
1252         cmdline_fixed_string_t port;
1253         cmdline_fixed_string_t keyword;
1254         cmdline_fixed_string_t identifier;
1255 };
1256
1257 static void cmd_operate_attach_port_parsed(void *parsed_result,
1258                                 __attribute__((unused)) struct cmdline *cl,
1259                                 __attribute__((unused)) void *data)
1260 {
1261         struct cmd_operate_attach_port_result *res = parsed_result;
1262
1263         if (!strcmp(res->keyword, "attach"))
1264                 attach_port(res->identifier);
1265         else
1266                 printf("Unknown parameter\n");
1267 }
1268
1269 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1270         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1271                         port, "port");
1272 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1273         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1274                         keyword, "attach");
1275 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1277                         identifier, NULL);
1278
1279 cmdline_parse_inst_t cmd_operate_attach_port = {
1280         .f = cmd_operate_attach_port_parsed,
1281         .data = NULL,
1282         .help_str = "port attach <identifier>: "
1283                 "(identifier: pci address or virtual dev name)",
1284         .tokens = {
1285                 (void *)&cmd_operate_attach_port_port,
1286                 (void *)&cmd_operate_attach_port_keyword,
1287                 (void *)&cmd_operate_attach_port_identifier,
1288                 NULL,
1289         },
1290 };
1291
1292 /* *** detach a specified port *** */
1293 struct cmd_operate_detach_port_result {
1294         cmdline_fixed_string_t port;
1295         cmdline_fixed_string_t keyword;
1296         portid_t port_id;
1297 };
1298
1299 static void cmd_operate_detach_port_parsed(void *parsed_result,
1300                                 __attribute__((unused)) struct cmdline *cl,
1301                                 __attribute__((unused)) void *data)
1302 {
1303         struct cmd_operate_detach_port_result *res = parsed_result;
1304
1305         if (!strcmp(res->keyword, "detach"))
1306                 detach_port(res->port_id);
1307         else
1308                 printf("Unknown parameter\n");
1309 }
1310
1311 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1312         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1313                         port, "port");
1314 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1315         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1316                         keyword, "detach");
1317 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1318         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1319                         port_id, UINT16);
1320
1321 cmdline_parse_inst_t cmd_operate_detach_port = {
1322         .f = cmd_operate_detach_port_parsed,
1323         .data = NULL,
1324         .help_str = "port detach <port_id>",
1325         .tokens = {
1326                 (void *)&cmd_operate_detach_port_port,
1327                 (void *)&cmd_operate_detach_port_keyword,
1328                 (void *)&cmd_operate_detach_port_port_id,
1329                 NULL,
1330         },
1331 };
1332
1333 /* *** configure speed for all ports *** */
1334 struct cmd_config_speed_all {
1335         cmdline_fixed_string_t port;
1336         cmdline_fixed_string_t keyword;
1337         cmdline_fixed_string_t all;
1338         cmdline_fixed_string_t item1;
1339         cmdline_fixed_string_t item2;
1340         cmdline_fixed_string_t value1;
1341         cmdline_fixed_string_t value2;
1342 };
1343
1344 static int
1345 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1346 {
1347
1348         int duplex;
1349
1350         if (!strcmp(duplexstr, "half")) {
1351                 duplex = ETH_LINK_HALF_DUPLEX;
1352         } else if (!strcmp(duplexstr, "full")) {
1353                 duplex = ETH_LINK_FULL_DUPLEX;
1354         } else if (!strcmp(duplexstr, "auto")) {
1355                 duplex = ETH_LINK_FULL_DUPLEX;
1356         } else {
1357                 printf("Unknown duplex parameter\n");
1358                 return -1;
1359         }
1360
1361         if (!strcmp(speedstr, "10")) {
1362                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1363                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1364         } else if (!strcmp(speedstr, "100")) {
1365                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1366                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1367         } else {
1368                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1369                         printf("Invalid speed/duplex parameters\n");
1370                         return -1;
1371                 }
1372                 if (!strcmp(speedstr, "1000")) {
1373                         *speed = ETH_LINK_SPEED_1G;
1374                 } else if (!strcmp(speedstr, "10000")) {
1375                         *speed = ETH_LINK_SPEED_10G;
1376                 } else if (!strcmp(speedstr, "25000")) {
1377                         *speed = ETH_LINK_SPEED_25G;
1378                 } else if (!strcmp(speedstr, "40000")) {
1379                         *speed = ETH_LINK_SPEED_40G;
1380                 } else if (!strcmp(speedstr, "50000")) {
1381                         *speed = ETH_LINK_SPEED_50G;
1382                 } else if (!strcmp(speedstr, "100000")) {
1383                         *speed = ETH_LINK_SPEED_100G;
1384                 } else if (!strcmp(speedstr, "auto")) {
1385                         *speed = ETH_LINK_SPEED_AUTONEG;
1386                 } else {
1387                         printf("Unknown speed parameter\n");
1388                         return -1;
1389                 }
1390         }
1391
1392         return 0;
1393 }
1394
1395 static void
1396 cmd_config_speed_all_parsed(void *parsed_result,
1397                         __attribute__((unused)) struct cmdline *cl,
1398                         __attribute__((unused)) void *data)
1399 {
1400         struct cmd_config_speed_all *res = parsed_result;
1401         uint32_t link_speed;
1402         portid_t pid;
1403
1404         if (!all_ports_stopped()) {
1405                 printf("Please stop all ports first\n");
1406                 return;
1407         }
1408
1409         if (parse_and_check_speed_duplex(res->value1, res->value2,
1410                         &link_speed) < 0)
1411                 return;
1412
1413         RTE_ETH_FOREACH_DEV(pid) {
1414                 ports[pid].dev_conf.link_speeds = link_speed;
1415         }
1416
1417         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1418 }
1419
1420 cmdline_parse_token_string_t cmd_config_speed_all_port =
1421         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1422 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1423         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1424                                                         "config");
1425 cmdline_parse_token_string_t cmd_config_speed_all_all =
1426         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1427 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1428         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1429 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1430         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1431                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1432 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1433         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1434 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1435         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1436                                                 "half#full#auto");
1437
1438 cmdline_parse_inst_t cmd_config_speed_all = {
1439         .f = cmd_config_speed_all_parsed,
1440         .data = NULL,
1441         .help_str = "port config all speed "
1442                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1443                                                         "half|full|auto",
1444         .tokens = {
1445                 (void *)&cmd_config_speed_all_port,
1446                 (void *)&cmd_config_speed_all_keyword,
1447                 (void *)&cmd_config_speed_all_all,
1448                 (void *)&cmd_config_speed_all_item1,
1449                 (void *)&cmd_config_speed_all_value1,
1450                 (void *)&cmd_config_speed_all_item2,
1451                 (void *)&cmd_config_speed_all_value2,
1452                 NULL,
1453         },
1454 };
1455
1456 /* *** configure speed for specific port *** */
1457 struct cmd_config_speed_specific {
1458         cmdline_fixed_string_t port;
1459         cmdline_fixed_string_t keyword;
1460         portid_t id;
1461         cmdline_fixed_string_t item1;
1462         cmdline_fixed_string_t item2;
1463         cmdline_fixed_string_t value1;
1464         cmdline_fixed_string_t value2;
1465 };
1466
1467 static void
1468 cmd_config_speed_specific_parsed(void *parsed_result,
1469                                 __attribute__((unused)) struct cmdline *cl,
1470                                 __attribute__((unused)) void *data)
1471 {
1472         struct cmd_config_speed_specific *res = parsed_result;
1473         uint32_t link_speed;
1474
1475         if (!all_ports_stopped()) {
1476                 printf("Please stop all ports first\n");
1477                 return;
1478         }
1479
1480         if (port_id_is_invalid(res->id, ENABLED_WARN))
1481                 return;
1482
1483         if (parse_and_check_speed_duplex(res->value1, res->value2,
1484                         &link_speed) < 0)
1485                 return;
1486
1487         ports[res->id].dev_conf.link_speeds = link_speed;
1488
1489         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1490 }
1491
1492
1493 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1494         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1495                                                                 "port");
1496 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1497         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1498                                                                 "config");
1499 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1500         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1501 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1502         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1503                                                                 "speed");
1504 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1505         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1506                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1507 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1508         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1509                                                                 "duplex");
1510 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1511         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1512                                                         "half#full#auto");
1513
1514 cmdline_parse_inst_t cmd_config_speed_specific = {
1515         .f = cmd_config_speed_specific_parsed,
1516         .data = NULL,
1517         .help_str = "port config <port_id> speed "
1518                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1519                                                         "half|full|auto",
1520         .tokens = {
1521                 (void *)&cmd_config_speed_specific_port,
1522                 (void *)&cmd_config_speed_specific_keyword,
1523                 (void *)&cmd_config_speed_specific_id,
1524                 (void *)&cmd_config_speed_specific_item1,
1525                 (void *)&cmd_config_speed_specific_value1,
1526                 (void *)&cmd_config_speed_specific_item2,
1527                 (void *)&cmd_config_speed_specific_value2,
1528                 NULL,
1529         },
1530 };
1531
1532 /* *** configure loopback for all ports *** */
1533 struct cmd_config_loopback_all {
1534         cmdline_fixed_string_t port;
1535         cmdline_fixed_string_t keyword;
1536         cmdline_fixed_string_t all;
1537         cmdline_fixed_string_t item;
1538         uint32_t mode;
1539 };
1540
1541 static void
1542 cmd_config_loopback_all_parsed(void *parsed_result,
1543                         __attribute__((unused)) struct cmdline *cl,
1544                         __attribute__((unused)) void *data)
1545 {
1546         struct cmd_config_loopback_all *res = parsed_result;
1547         portid_t pid;
1548
1549         if (!all_ports_stopped()) {
1550                 printf("Please stop all ports first\n");
1551                 return;
1552         }
1553
1554         RTE_ETH_FOREACH_DEV(pid) {
1555                 ports[pid].dev_conf.lpbk_mode = res->mode;
1556         }
1557
1558         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1559 }
1560
1561 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1563 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1565                                                         "config");
1566 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1568 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1569         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1570                                                         "loopback");
1571 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1572         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1573
1574 cmdline_parse_inst_t cmd_config_loopback_all = {
1575         .f = cmd_config_loopback_all_parsed,
1576         .data = NULL,
1577         .help_str = "port config all loopback <mode>",
1578         .tokens = {
1579                 (void *)&cmd_config_loopback_all_port,
1580                 (void *)&cmd_config_loopback_all_keyword,
1581                 (void *)&cmd_config_loopback_all_all,
1582                 (void *)&cmd_config_loopback_all_item,
1583                 (void *)&cmd_config_loopback_all_mode,
1584                 NULL,
1585         },
1586 };
1587
1588 /* *** configure loopback for specific port *** */
1589 struct cmd_config_loopback_specific {
1590         cmdline_fixed_string_t port;
1591         cmdline_fixed_string_t keyword;
1592         uint16_t port_id;
1593         cmdline_fixed_string_t item;
1594         uint32_t mode;
1595 };
1596
1597 static void
1598 cmd_config_loopback_specific_parsed(void *parsed_result,
1599                                 __attribute__((unused)) struct cmdline *cl,
1600                                 __attribute__((unused)) void *data)
1601 {
1602         struct cmd_config_loopback_specific *res = parsed_result;
1603
1604         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1605                 return;
1606
1607         if (!port_is_stopped(res->port_id)) {
1608                 printf("Please stop port %u first\n", res->port_id);
1609                 return;
1610         }
1611
1612         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1613
1614         cmd_reconfig_device_queue(res->port_id, 1, 1);
1615 }
1616
1617
1618 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1619         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1620                                                                 "port");
1621 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1622         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1623                                                                 "config");
1624 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1625         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1626                                                                 UINT16);
1627 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1628         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1629                                                                 "loopback");
1630 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1631         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1632                               UINT32);
1633
1634 cmdline_parse_inst_t cmd_config_loopback_specific = {
1635         .f = cmd_config_loopback_specific_parsed,
1636         .data = NULL,
1637         .help_str = "port config <port_id> loopback <mode>",
1638         .tokens = {
1639                 (void *)&cmd_config_loopback_specific_port,
1640                 (void *)&cmd_config_loopback_specific_keyword,
1641                 (void *)&cmd_config_loopback_specific_id,
1642                 (void *)&cmd_config_loopback_specific_item,
1643                 (void *)&cmd_config_loopback_specific_mode,
1644                 NULL,
1645         },
1646 };
1647
1648 /* *** configure txq/rxq, txd/rxd *** */
1649 struct cmd_config_rx_tx {
1650         cmdline_fixed_string_t port;
1651         cmdline_fixed_string_t keyword;
1652         cmdline_fixed_string_t all;
1653         cmdline_fixed_string_t name;
1654         uint16_t value;
1655 };
1656
1657 static void
1658 cmd_config_rx_tx_parsed(void *parsed_result,
1659                         __attribute__((unused)) struct cmdline *cl,
1660                         __attribute__((unused)) void *data)
1661 {
1662         struct cmd_config_rx_tx *res = parsed_result;
1663
1664         if (!all_ports_stopped()) {
1665                 printf("Please stop all ports first\n");
1666                 return;
1667         }
1668         if (!strcmp(res->name, "rxq")) {
1669                 if (!res->value && !nb_txq) {
1670                         printf("Warning: Either rx or tx queues should be non zero\n");
1671                         return;
1672                 }
1673                 if (check_nb_rxq(res->value) != 0)
1674                         return;
1675                 nb_rxq = res->value;
1676         }
1677         else if (!strcmp(res->name, "txq")) {
1678                 if (!res->value && !nb_rxq) {
1679                         printf("Warning: Either rx or tx queues should be non zero\n");
1680                         return;
1681                 }
1682                 if (check_nb_txq(res->value) != 0)
1683                         return;
1684                 nb_txq = res->value;
1685         }
1686         else if (!strcmp(res->name, "rxd")) {
1687                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1688                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1689                                         res->value, RTE_TEST_RX_DESC_MAX);
1690                         return;
1691                 }
1692                 nb_rxd = res->value;
1693         } else if (!strcmp(res->name, "txd")) {
1694                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1695                         printf("txd %d invalid - must be > 0 && <= %d\n",
1696                                         res->value, RTE_TEST_TX_DESC_MAX);
1697                         return;
1698                 }
1699                 nb_txd = res->value;
1700         } else {
1701                 printf("Unknown parameter\n");
1702                 return;
1703         }
1704
1705         fwd_config_setup();
1706
1707         init_port_config();
1708
1709         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1710 }
1711
1712 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1713         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1714 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1716 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1717         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1718 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1719         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1720                                                 "rxq#txq#rxd#txd");
1721 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1722         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1723
1724 cmdline_parse_inst_t cmd_config_rx_tx = {
1725         .f = cmd_config_rx_tx_parsed,
1726         .data = NULL,
1727         .help_str = "port config all rxq|txq|rxd|txd <value>",
1728         .tokens = {
1729                 (void *)&cmd_config_rx_tx_port,
1730                 (void *)&cmd_config_rx_tx_keyword,
1731                 (void *)&cmd_config_rx_tx_all,
1732                 (void *)&cmd_config_rx_tx_name,
1733                 (void *)&cmd_config_rx_tx_value,
1734                 NULL,
1735         },
1736 };
1737
1738 /* *** config max packet length *** */
1739 struct cmd_config_max_pkt_len_result {
1740         cmdline_fixed_string_t port;
1741         cmdline_fixed_string_t keyword;
1742         cmdline_fixed_string_t all;
1743         cmdline_fixed_string_t name;
1744         uint32_t value;
1745 };
1746
1747 static void
1748 cmd_config_max_pkt_len_parsed(void *parsed_result,
1749                                 __attribute__((unused)) struct cmdline *cl,
1750                                 __attribute__((unused)) void *data)
1751 {
1752         struct cmd_config_max_pkt_len_result *res = parsed_result;
1753         portid_t pid;
1754
1755         if (!all_ports_stopped()) {
1756                 printf("Please stop all ports first\n");
1757                 return;
1758         }
1759
1760         RTE_ETH_FOREACH_DEV(pid) {
1761                 struct rte_port *port = &ports[pid];
1762                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1763
1764                 if (!strcmp(res->name, "max-pkt-len")) {
1765                         if (res->value < ETHER_MIN_LEN) {
1766                                 printf("max-pkt-len can not be less than %d\n",
1767                                                 ETHER_MIN_LEN);
1768                                 return;
1769                         }
1770                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1771                                 return;
1772
1773                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1774                         if (res->value > ETHER_MAX_LEN)
1775                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1776                         else
1777                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1778                         port->dev_conf.rxmode.offloads = rx_offloads;
1779                 } else {
1780                         printf("Unknown parameter\n");
1781                         return;
1782                 }
1783         }
1784
1785         init_port_config();
1786
1787         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1788 }
1789
1790 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1792                                                                 "port");
1793 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1795                                                                 "config");
1796 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1798                                                                 "all");
1799 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1800         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1801                                                                 "max-pkt-len");
1802 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1803         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1804                                                                 UINT32);
1805
1806 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1807         .f = cmd_config_max_pkt_len_parsed,
1808         .data = NULL,
1809         .help_str = "port config all max-pkt-len <value>",
1810         .tokens = {
1811                 (void *)&cmd_config_max_pkt_len_port,
1812                 (void *)&cmd_config_max_pkt_len_keyword,
1813                 (void *)&cmd_config_max_pkt_len_all,
1814                 (void *)&cmd_config_max_pkt_len_name,
1815                 (void *)&cmd_config_max_pkt_len_value,
1816                 NULL,
1817         },
1818 };
1819
1820 /* *** configure port MTU *** */
1821 struct cmd_config_mtu_result {
1822         cmdline_fixed_string_t port;
1823         cmdline_fixed_string_t keyword;
1824         cmdline_fixed_string_t mtu;
1825         portid_t port_id;
1826         uint16_t value;
1827 };
1828
1829 static void
1830 cmd_config_mtu_parsed(void *parsed_result,
1831                       __attribute__((unused)) struct cmdline *cl,
1832                       __attribute__((unused)) void *data)
1833 {
1834         struct cmd_config_mtu_result *res = parsed_result;
1835
1836         if (res->value < ETHER_MIN_LEN) {
1837                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1838                 return;
1839         }
1840         port_mtu_set(res->port_id, res->value);
1841 }
1842
1843 cmdline_parse_token_string_t cmd_config_mtu_port =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1845                                  "port");
1846 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1848                                  "config");
1849 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1851                                  "mtu");
1852 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1853         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1854 cmdline_parse_token_num_t cmd_config_mtu_value =
1855         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1856
1857 cmdline_parse_inst_t cmd_config_mtu = {
1858         .f = cmd_config_mtu_parsed,
1859         .data = NULL,
1860         .help_str = "port config mtu <port_id> <value>",
1861         .tokens = {
1862                 (void *)&cmd_config_mtu_port,
1863                 (void *)&cmd_config_mtu_keyword,
1864                 (void *)&cmd_config_mtu_mtu,
1865                 (void *)&cmd_config_mtu_port_id,
1866                 (void *)&cmd_config_mtu_value,
1867                 NULL,
1868         },
1869 };
1870
1871 /* *** configure rx mode *** */
1872 struct cmd_config_rx_mode_flag {
1873         cmdline_fixed_string_t port;
1874         cmdline_fixed_string_t keyword;
1875         cmdline_fixed_string_t all;
1876         cmdline_fixed_string_t name;
1877         cmdline_fixed_string_t value;
1878 };
1879
1880 static void
1881 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1882                                 __attribute__((unused)) struct cmdline *cl,
1883                                 __attribute__((unused)) void *data)
1884 {
1885         struct cmd_config_rx_mode_flag *res = parsed_result;
1886         portid_t pid;
1887
1888         if (!all_ports_stopped()) {
1889                 printf("Please stop all ports first\n");
1890                 return;
1891         }
1892
1893         RTE_ETH_FOREACH_DEV(pid) {
1894                 struct rte_port *port;
1895                 uint64_t rx_offloads;
1896
1897                 port = &ports[pid];
1898                 rx_offloads = port->dev_conf.rxmode.offloads;
1899                 if (!strcmp(res->name, "crc-strip")) {
1900                         if (!strcmp(res->value, "on")) {
1901                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
1902                         } else if (!strcmp(res->value, "off")) {
1903                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
1904                         } else {
1905                                 printf("Unknown parameter\n");
1906                                 return;
1907                         }
1908                 } else if (!strcmp(res->name, "scatter")) {
1909                         if (!strcmp(res->value, "on")) {
1910                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1911                         } else if (!strcmp(res->value, "off")) {
1912                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1913                         } else {
1914                                 printf("Unknown parameter\n");
1915                                 return;
1916                         }
1917                 } else if (!strcmp(res->name, "rx-cksum")) {
1918                         if (!strcmp(res->value, "on"))
1919                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1920                         else if (!strcmp(res->value, "off"))
1921                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1922                         else {
1923                                 printf("Unknown parameter\n");
1924                                 return;
1925                         }
1926                 } else if (!strcmp(res->name, "rx-timestamp")) {
1927                         if (!strcmp(res->value, "on"))
1928                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1929                         else if (!strcmp(res->value, "off"))
1930                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1931                         else {
1932                                 printf("Unknown parameter\n");
1933                                 return;
1934                         }
1935                 } else if (!strcmp(res->name, "hw-vlan")) {
1936                         if (!strcmp(res->value, "on")) {
1937                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1938                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1939                         } else if (!strcmp(res->value, "off")) {
1940                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1941                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1942                         } else {
1943                                 printf("Unknown parameter\n");
1944                                 return;
1945                         }
1946                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1947                         if (!strcmp(res->value, "on"))
1948                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1949                         else if (!strcmp(res->value, "off"))
1950                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1951                         else {
1952                                 printf("Unknown parameter\n");
1953                                 return;
1954                         }
1955                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1956                         if (!strcmp(res->value, "on"))
1957                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1958                         else if (!strcmp(res->value, "off"))
1959                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1960                         else {
1961                                 printf("Unknown parameter\n");
1962                                 return;
1963                         }
1964                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1965                         if (!strcmp(res->value, "on"))
1966                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1967                         else if (!strcmp(res->value, "off"))
1968                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1969                         else {
1970                                 printf("Unknown parameter\n");
1971                                 return;
1972                         }
1973                 } else if (!strcmp(res->name, "drop-en")) {
1974                         if (!strcmp(res->value, "on"))
1975                                 rx_drop_en = 1;
1976                         else if (!strcmp(res->value, "off"))
1977                                 rx_drop_en = 0;
1978                         else {
1979                                 printf("Unknown parameter\n");
1980                                 return;
1981                         }
1982                 } else {
1983                         printf("Unknown parameter\n");
1984                         return;
1985                 }
1986                 port->dev_conf.rxmode.offloads = rx_offloads;
1987         }
1988
1989         init_port_config();
1990
1991         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1992 }
1993
1994 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1995         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1996 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1997         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1998                                                                 "config");
1999 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2001 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2002         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2003                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2004                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2005 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2006         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2007                                                         "on#off");
2008
2009 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2010         .f = cmd_config_rx_mode_flag_parsed,
2011         .data = NULL,
2012         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2013                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2014         .tokens = {
2015                 (void *)&cmd_config_rx_mode_flag_port,
2016                 (void *)&cmd_config_rx_mode_flag_keyword,
2017                 (void *)&cmd_config_rx_mode_flag_all,
2018                 (void *)&cmd_config_rx_mode_flag_name,
2019                 (void *)&cmd_config_rx_mode_flag_value,
2020                 NULL,
2021         },
2022 };
2023
2024 /* *** configure rss *** */
2025 struct cmd_config_rss {
2026         cmdline_fixed_string_t port;
2027         cmdline_fixed_string_t keyword;
2028         cmdline_fixed_string_t all;
2029         cmdline_fixed_string_t name;
2030         cmdline_fixed_string_t value;
2031 };
2032
2033 static void
2034 cmd_config_rss_parsed(void *parsed_result,
2035                         __attribute__((unused)) struct cmdline *cl,
2036                         __attribute__((unused)) void *data)
2037 {
2038         struct cmd_config_rss *res = parsed_result;
2039         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2040         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2041         int use_default = 0;
2042         int all_updated = 1;
2043         int diag;
2044         uint16_t i;
2045
2046         if (!strcmp(res->value, "all"))
2047                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2048                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2049                                         ETH_RSS_L2_PAYLOAD;
2050         else if (!strcmp(res->value, "ip"))
2051                 rss_conf.rss_hf = ETH_RSS_IP;
2052         else if (!strcmp(res->value, "udp"))
2053                 rss_conf.rss_hf = ETH_RSS_UDP;
2054         else if (!strcmp(res->value, "tcp"))
2055                 rss_conf.rss_hf = ETH_RSS_TCP;
2056         else if (!strcmp(res->value, "sctp"))
2057                 rss_conf.rss_hf = ETH_RSS_SCTP;
2058         else if (!strcmp(res->value, "ether"))
2059                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2060         else if (!strcmp(res->value, "port"))
2061                 rss_conf.rss_hf = ETH_RSS_PORT;
2062         else if (!strcmp(res->value, "vxlan"))
2063                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2064         else if (!strcmp(res->value, "geneve"))
2065                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2066         else if (!strcmp(res->value, "nvgre"))
2067                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2068         else if (!strcmp(res->value, "none"))
2069                 rss_conf.rss_hf = 0;
2070         else if (!strcmp(res->value, "default"))
2071                 use_default = 1;
2072         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2073                                                 atoi(res->value) < 64)
2074                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2075         else {
2076                 printf("Unknown parameter\n");
2077                 return;
2078         }
2079         rss_conf.rss_key = NULL;
2080         /* Update global configuration for RSS types. */
2081         RTE_ETH_FOREACH_DEV(i) {
2082                 struct rte_eth_rss_conf local_rss_conf;
2083
2084                 rte_eth_dev_info_get(i, &dev_info);
2085                 if (use_default)
2086                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2087
2088                 local_rss_conf = rss_conf;
2089                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2090                         dev_info.flow_type_rss_offloads;
2091                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2092                         printf("Port %u modified RSS hash function based on hardware support,"
2093                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2094                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2095                 }
2096                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2097                 if (diag < 0) {
2098                         all_updated = 0;
2099                         printf("Configuration of RSS hash at ethernet port %d "
2100                                 "failed with error (%d): %s.\n",
2101                                 i, -diag, strerror(-diag));
2102                 }
2103         }
2104         if (all_updated && !use_default)
2105                 rss_hf = rss_conf.rss_hf;
2106 }
2107
2108 cmdline_parse_token_string_t cmd_config_rss_port =
2109         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2110 cmdline_parse_token_string_t cmd_config_rss_keyword =
2111         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2112 cmdline_parse_token_string_t cmd_config_rss_all =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2114 cmdline_parse_token_string_t cmd_config_rss_name =
2115         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2116 cmdline_parse_token_string_t cmd_config_rss_value =
2117         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2118
2119 cmdline_parse_inst_t cmd_config_rss = {
2120         .f = cmd_config_rss_parsed,
2121         .data = NULL,
2122         .help_str = "port config all rss "
2123                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2124         .tokens = {
2125                 (void *)&cmd_config_rss_port,
2126                 (void *)&cmd_config_rss_keyword,
2127                 (void *)&cmd_config_rss_all,
2128                 (void *)&cmd_config_rss_name,
2129                 (void *)&cmd_config_rss_value,
2130                 NULL,
2131         },
2132 };
2133
2134 /* *** configure rss hash key *** */
2135 struct cmd_config_rss_hash_key {
2136         cmdline_fixed_string_t port;
2137         cmdline_fixed_string_t config;
2138         portid_t port_id;
2139         cmdline_fixed_string_t rss_hash_key;
2140         cmdline_fixed_string_t rss_type;
2141         cmdline_fixed_string_t key;
2142 };
2143
2144 static uint8_t
2145 hexa_digit_to_value(char hexa_digit)
2146 {
2147         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2148                 return (uint8_t) (hexa_digit - '0');
2149         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2150                 return (uint8_t) ((hexa_digit - 'a') + 10);
2151         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2152                 return (uint8_t) ((hexa_digit - 'A') + 10);
2153         /* Invalid hexa digit */
2154         return 0xFF;
2155 }
2156
2157 static uint8_t
2158 parse_and_check_key_hexa_digit(char *key, int idx)
2159 {
2160         uint8_t hexa_v;
2161
2162         hexa_v = hexa_digit_to_value(key[idx]);
2163         if (hexa_v == 0xFF)
2164                 printf("invalid key: character %c at position %d is not a "
2165                        "valid hexa digit\n", key[idx], idx);
2166         return hexa_v;
2167 }
2168
2169 static void
2170 cmd_config_rss_hash_key_parsed(void *parsed_result,
2171                                __attribute__((unused)) struct cmdline *cl,
2172                                __attribute__((unused)) void *data)
2173 {
2174         struct cmd_config_rss_hash_key *res = parsed_result;
2175         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2176         uint8_t xdgt0;
2177         uint8_t xdgt1;
2178         int i;
2179         struct rte_eth_dev_info dev_info;
2180         uint8_t hash_key_size;
2181         uint32_t key_len;
2182
2183         memset(&dev_info, 0, sizeof(dev_info));
2184         rte_eth_dev_info_get(res->port_id, &dev_info);
2185         if (dev_info.hash_key_size > 0 &&
2186                         dev_info.hash_key_size <= sizeof(hash_key))
2187                 hash_key_size = dev_info.hash_key_size;
2188         else {
2189                 printf("dev_info did not provide a valid hash key size\n");
2190                 return;
2191         }
2192         /* Check the length of the RSS hash key */
2193         key_len = strlen(res->key);
2194         if (key_len != (hash_key_size * 2)) {
2195                 printf("key length: %d invalid - key must be a string of %d"
2196                            " hexa-decimal numbers\n",
2197                            (int) key_len, hash_key_size * 2);
2198                 return;
2199         }
2200         /* Translate RSS hash key into binary representation */
2201         for (i = 0; i < hash_key_size; i++) {
2202                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2203                 if (xdgt0 == 0xFF)
2204                         return;
2205                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2206                 if (xdgt1 == 0xFF)
2207                         return;
2208                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2209         }
2210         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2211                         hash_key_size);
2212 }
2213
2214 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2215         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2216 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2217         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2218                                  "config");
2219 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2220         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2221 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2222         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2223                                  rss_hash_key, "rss-hash-key");
2224 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2225         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2226                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2227                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2228                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2229                                  "ipv6-tcp-ex#ipv6-udp-ex");
2230 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2231         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2232
2233 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2234         .f = cmd_config_rss_hash_key_parsed,
2235         .data = NULL,
2236         .help_str = "port config <port_id> rss-hash-key "
2237                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2238                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2239                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2240                 "<string of hex digits (variable length, NIC dependent)>",
2241         .tokens = {
2242                 (void *)&cmd_config_rss_hash_key_port,
2243                 (void *)&cmd_config_rss_hash_key_config,
2244                 (void *)&cmd_config_rss_hash_key_port_id,
2245                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2246                 (void *)&cmd_config_rss_hash_key_rss_type,
2247                 (void *)&cmd_config_rss_hash_key_value,
2248                 NULL,
2249         },
2250 };
2251
2252 /* *** configure port rxq/txq ring size *** */
2253 struct cmd_config_rxtx_ring_size {
2254         cmdline_fixed_string_t port;
2255         cmdline_fixed_string_t config;
2256         portid_t portid;
2257         cmdline_fixed_string_t rxtxq;
2258         uint16_t qid;
2259         cmdline_fixed_string_t rsize;
2260         uint16_t size;
2261 };
2262
2263 static void
2264 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2265                                  __attribute__((unused)) struct cmdline *cl,
2266                                  __attribute__((unused)) void *data)
2267 {
2268         struct cmd_config_rxtx_ring_size *res = parsed_result;
2269         struct rte_port *port;
2270         uint8_t isrx;
2271
2272         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2273                 return;
2274
2275         if (res->portid == (portid_t)RTE_PORT_ALL) {
2276                 printf("Invalid port id\n");
2277                 return;
2278         }
2279
2280         port = &ports[res->portid];
2281
2282         if (!strcmp(res->rxtxq, "rxq"))
2283                 isrx = 1;
2284         else if (!strcmp(res->rxtxq, "txq"))
2285                 isrx = 0;
2286         else {
2287                 printf("Unknown parameter\n");
2288                 return;
2289         }
2290
2291         if (isrx && rx_queue_id_is_invalid(res->qid))
2292                 return;
2293         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2294                 return;
2295
2296         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2297                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2298                        rx_free_thresh);
2299                 return;
2300         }
2301
2302         if (isrx)
2303                 port->nb_rx_desc[res->qid] = res->size;
2304         else
2305                 port->nb_tx_desc[res->qid] = res->size;
2306
2307         cmd_reconfig_device_queue(res->portid, 0, 1);
2308 }
2309
2310 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2311         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2312                                  port, "port");
2313 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2314         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2315                                  config, "config");
2316 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2317         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2318                                  portid, UINT16);
2319 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2320         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2321                                  rxtxq, "rxq#txq");
2322 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2323         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2324                               qid, UINT16);
2325 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2326         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2327                                  rsize, "ring_size");
2328 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2329         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2330                               size, UINT16);
2331
2332 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2333         .f = cmd_config_rxtx_ring_size_parsed,
2334         .data = NULL,
2335         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2336         .tokens = {
2337                 (void *)&cmd_config_rxtx_ring_size_port,
2338                 (void *)&cmd_config_rxtx_ring_size_config,
2339                 (void *)&cmd_config_rxtx_ring_size_portid,
2340                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2341                 (void *)&cmd_config_rxtx_ring_size_qid,
2342                 (void *)&cmd_config_rxtx_ring_size_rsize,
2343                 (void *)&cmd_config_rxtx_ring_size_size,
2344                 NULL,
2345         },
2346 };
2347
2348 /* *** configure port rxq/txq start/stop *** */
2349 struct cmd_config_rxtx_queue {
2350         cmdline_fixed_string_t port;
2351         portid_t portid;
2352         cmdline_fixed_string_t rxtxq;
2353         uint16_t qid;
2354         cmdline_fixed_string_t opname;
2355 };
2356
2357 static void
2358 cmd_config_rxtx_queue_parsed(void *parsed_result,
2359                         __attribute__((unused)) struct cmdline *cl,
2360                         __attribute__((unused)) void *data)
2361 {
2362         struct cmd_config_rxtx_queue *res = parsed_result;
2363         uint8_t isrx;
2364         uint8_t isstart;
2365         int ret = 0;
2366
2367         if (test_done == 0) {
2368                 printf("Please stop forwarding first\n");
2369                 return;
2370         }
2371
2372         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2373                 return;
2374
2375         if (port_is_started(res->portid) != 1) {
2376                 printf("Please start port %u first\n", res->portid);
2377                 return;
2378         }
2379
2380         if (!strcmp(res->rxtxq, "rxq"))
2381                 isrx = 1;
2382         else if (!strcmp(res->rxtxq, "txq"))
2383                 isrx = 0;
2384         else {
2385                 printf("Unknown parameter\n");
2386                 return;
2387         }
2388
2389         if (isrx && rx_queue_id_is_invalid(res->qid))
2390                 return;
2391         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2392                 return;
2393
2394         if (!strcmp(res->opname, "start"))
2395                 isstart = 1;
2396         else if (!strcmp(res->opname, "stop"))
2397                 isstart = 0;
2398         else {
2399                 printf("Unknown parameter\n");
2400                 return;
2401         }
2402
2403         if (isstart && isrx)
2404                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2405         else if (!isstart && isrx)
2406                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2407         else if (isstart && !isrx)
2408                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2409         else
2410                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2411
2412         if (ret == -ENOTSUP)
2413                 printf("Function not supported in PMD driver\n");
2414 }
2415
2416 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2417         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2418 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2419         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2420 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2421         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2422 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2423         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2424 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2425         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2426                                                 "start#stop");
2427
2428 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2429         .f = cmd_config_rxtx_queue_parsed,
2430         .data = NULL,
2431         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2432         .tokens = {
2433                 (void *)&cmd_config_rxtx_queue_port,
2434                 (void *)&cmd_config_rxtx_queue_portid,
2435                 (void *)&cmd_config_rxtx_queue_rxtxq,
2436                 (void *)&cmd_config_rxtx_queue_qid,
2437                 (void *)&cmd_config_rxtx_queue_opname,
2438                 NULL,
2439         },
2440 };
2441
2442 /* *** configure port rxq/txq setup *** */
2443 struct cmd_setup_rxtx_queue {
2444         cmdline_fixed_string_t port;
2445         portid_t portid;
2446         cmdline_fixed_string_t rxtxq;
2447         uint16_t qid;
2448         cmdline_fixed_string_t setup;
2449 };
2450
2451 /* Common CLI fields for queue setup */
2452 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2453         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2454 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2455         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2456 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2457         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2458 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2459         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2460 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2461         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2462
2463 static void
2464 cmd_setup_rxtx_queue_parsed(
2465         void *parsed_result,
2466         __attribute__((unused)) struct cmdline *cl,
2467         __attribute__((unused)) void *data)
2468 {
2469         struct cmd_setup_rxtx_queue *res = parsed_result;
2470         struct rte_port *port;
2471         struct rte_mempool *mp;
2472         unsigned int socket_id;
2473         uint8_t isrx = 0;
2474         int ret;
2475
2476         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2477                 return;
2478
2479         if (res->portid == (portid_t)RTE_PORT_ALL) {
2480                 printf("Invalid port id\n");
2481                 return;
2482         }
2483
2484         if (!strcmp(res->rxtxq, "rxq"))
2485                 isrx = 1;
2486         else if (!strcmp(res->rxtxq, "txq"))
2487                 isrx = 0;
2488         else {
2489                 printf("Unknown parameter\n");
2490                 return;
2491         }
2492
2493         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2494                 printf("Invalid rx queue\n");
2495                 return;
2496         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2497                 printf("Invalid tx queue\n");
2498                 return;
2499         }
2500
2501         port = &ports[res->portid];
2502         if (isrx) {
2503                 socket_id = rxring_numa[res->portid];
2504                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2505                         socket_id = port->socket_id;
2506
2507                 mp = mbuf_pool_find(socket_id);
2508                 if (mp == NULL) {
2509                         printf("Failed to setup RX queue: "
2510                                 "No mempool allocation"
2511                                 " on the socket %d\n",
2512                                 rxring_numa[res->portid]);
2513                         return;
2514                 }
2515                 ret = rte_eth_rx_queue_setup(res->portid,
2516                                              res->qid,
2517                                              port->nb_rx_desc[res->qid],
2518                                              socket_id,
2519                                              &port->rx_conf[res->qid],
2520                                              mp);
2521                 if (ret)
2522                         printf("Failed to setup RX queue\n");
2523         } else {
2524                 socket_id = txring_numa[res->portid];
2525                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2526                         socket_id = port->socket_id;
2527
2528                 ret = rte_eth_tx_queue_setup(res->portid,
2529                                              res->qid,
2530                                              port->nb_tx_desc[res->qid],
2531                                              socket_id,
2532                                              &port->tx_conf[res->qid]);
2533                 if (ret)
2534                         printf("Failed to setup TX queue\n");
2535         }
2536 }
2537
2538 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2539         .f = cmd_setup_rxtx_queue_parsed,
2540         .data = NULL,
2541         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2542         .tokens = {
2543                 (void *)&cmd_setup_rxtx_queue_port,
2544                 (void *)&cmd_setup_rxtx_queue_portid,
2545                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2546                 (void *)&cmd_setup_rxtx_queue_qid,
2547                 (void *)&cmd_setup_rxtx_queue_setup,
2548                 NULL,
2549         },
2550 };
2551
2552
2553 /* *** Configure RSS RETA *** */
2554 struct cmd_config_rss_reta {
2555         cmdline_fixed_string_t port;
2556         cmdline_fixed_string_t keyword;
2557         portid_t port_id;
2558         cmdline_fixed_string_t name;
2559         cmdline_fixed_string_t list_name;
2560         cmdline_fixed_string_t list_of_items;
2561 };
2562
2563 static int
2564 parse_reta_config(const char *str,
2565                   struct rte_eth_rss_reta_entry64 *reta_conf,
2566                   uint16_t nb_entries)
2567 {
2568         int i;
2569         unsigned size;
2570         uint16_t hash_index, idx, shift;
2571         uint16_t nb_queue;
2572         char s[256];
2573         const char *p, *p0 = str;
2574         char *end;
2575         enum fieldnames {
2576                 FLD_HASH_INDEX = 0,
2577                 FLD_QUEUE,
2578                 _NUM_FLD
2579         };
2580         unsigned long int_fld[_NUM_FLD];
2581         char *str_fld[_NUM_FLD];
2582
2583         while ((p = strchr(p0,'(')) != NULL) {
2584                 ++p;
2585                 if((p0 = strchr(p,')')) == NULL)
2586                         return -1;
2587
2588                 size = p0 - p;
2589                 if(size >= sizeof(s))
2590                         return -1;
2591
2592                 snprintf(s, sizeof(s), "%.*s", size, p);
2593                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2594                         return -1;
2595                 for (i = 0; i < _NUM_FLD; i++) {
2596                         errno = 0;
2597                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2598                         if (errno != 0 || end == str_fld[i] ||
2599                                         int_fld[i] > 65535)
2600                                 return -1;
2601                 }
2602
2603                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2604                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2605
2606                 if (hash_index >= nb_entries) {
2607                         printf("Invalid RETA hash index=%d\n", hash_index);
2608                         return -1;
2609                 }
2610
2611                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2612                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2613                 reta_conf[idx].mask |= (1ULL << shift);
2614                 reta_conf[idx].reta[shift] = nb_queue;
2615         }
2616
2617         return 0;
2618 }
2619
2620 static void
2621 cmd_set_rss_reta_parsed(void *parsed_result,
2622                         __attribute__((unused)) struct cmdline *cl,
2623                         __attribute__((unused)) void *data)
2624 {
2625         int ret;
2626         struct rte_eth_dev_info dev_info;
2627         struct rte_eth_rss_reta_entry64 reta_conf[8];
2628         struct cmd_config_rss_reta *res = parsed_result;
2629
2630         memset(&dev_info, 0, sizeof(dev_info));
2631         rte_eth_dev_info_get(res->port_id, &dev_info);
2632         if (dev_info.reta_size == 0) {
2633                 printf("Redirection table size is 0 which is "
2634                                         "invalid for RSS\n");
2635                 return;
2636         } else
2637                 printf("The reta size of port %d is %u\n",
2638                         res->port_id, dev_info.reta_size);
2639         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2640                 printf("Currently do not support more than %u entries of "
2641                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2642                 return;
2643         }
2644
2645         memset(reta_conf, 0, sizeof(reta_conf));
2646         if (!strcmp(res->list_name, "reta")) {
2647                 if (parse_reta_config(res->list_of_items, reta_conf,
2648                                                 dev_info.reta_size)) {
2649                         printf("Invalid RSS Redirection Table "
2650                                         "config entered\n");
2651                         return;
2652                 }
2653                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2654                                 reta_conf, dev_info.reta_size);
2655                 if (ret != 0)
2656                         printf("Bad redirection table parameter, "
2657                                         "return code = %d \n", ret);
2658         }
2659 }
2660
2661 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2662         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2663 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2664         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2665 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2666         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2667 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2668         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2669 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2670         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2671 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2672         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2673                                  NULL);
2674 cmdline_parse_inst_t cmd_config_rss_reta = {
2675         .f = cmd_set_rss_reta_parsed,
2676         .data = NULL,
2677         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2678         .tokens = {
2679                 (void *)&cmd_config_rss_reta_port,
2680                 (void *)&cmd_config_rss_reta_keyword,
2681                 (void *)&cmd_config_rss_reta_port_id,
2682                 (void *)&cmd_config_rss_reta_name,
2683                 (void *)&cmd_config_rss_reta_list_name,
2684                 (void *)&cmd_config_rss_reta_list_of_items,
2685                 NULL,
2686         },
2687 };
2688
2689 /* *** SHOW PORT RETA INFO *** */
2690 struct cmd_showport_reta {
2691         cmdline_fixed_string_t show;
2692         cmdline_fixed_string_t port;
2693         portid_t port_id;
2694         cmdline_fixed_string_t rss;
2695         cmdline_fixed_string_t reta;
2696         uint16_t size;
2697         cmdline_fixed_string_t list_of_items;
2698 };
2699
2700 static int
2701 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2702                            uint16_t nb_entries,
2703                            char *str)
2704 {
2705         uint32_t size;
2706         const char *p, *p0 = str;
2707         char s[256];
2708         char *end;
2709         char *str_fld[8];
2710         uint16_t i;
2711         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2712                         RTE_RETA_GROUP_SIZE;
2713         int ret;
2714
2715         p = strchr(p0, '(');
2716         if (p == NULL)
2717                 return -1;
2718         p++;
2719         p0 = strchr(p, ')');
2720         if (p0 == NULL)
2721                 return -1;
2722         size = p0 - p;
2723         if (size >= sizeof(s)) {
2724                 printf("The string size exceeds the internal buffer size\n");
2725                 return -1;
2726         }
2727         snprintf(s, sizeof(s), "%.*s", size, p);
2728         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2729         if (ret <= 0 || ret != num) {
2730                 printf("The bits of masks do not match the number of "
2731                                         "reta entries: %u\n", num);
2732                 return -1;
2733         }
2734         for (i = 0; i < ret; i++)
2735                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2736
2737         return 0;
2738 }
2739
2740 static void
2741 cmd_showport_reta_parsed(void *parsed_result,
2742                          __attribute__((unused)) struct cmdline *cl,
2743                          __attribute__((unused)) void *data)
2744 {
2745         struct cmd_showport_reta *res = parsed_result;
2746         struct rte_eth_rss_reta_entry64 reta_conf[8];
2747         struct rte_eth_dev_info dev_info;
2748         uint16_t max_reta_size;
2749
2750         memset(&dev_info, 0, sizeof(dev_info));
2751         rte_eth_dev_info_get(res->port_id, &dev_info);
2752         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2753         if (res->size == 0 || res->size > max_reta_size) {
2754                 printf("Invalid redirection table size: %u (1-%u)\n",
2755                         res->size, max_reta_size);
2756                 return;
2757         }
2758
2759         memset(reta_conf, 0, sizeof(reta_conf));
2760         if (showport_parse_reta_config(reta_conf, res->size,
2761                                 res->list_of_items) < 0) {
2762                 printf("Invalid string: %s for reta masks\n",
2763                                         res->list_of_items);
2764                 return;
2765         }
2766         port_rss_reta_info(res->port_id, reta_conf, res->size);
2767 }
2768
2769 cmdline_parse_token_string_t cmd_showport_reta_show =
2770         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2771 cmdline_parse_token_string_t cmd_showport_reta_port =
2772         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2773 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2774         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2775 cmdline_parse_token_string_t cmd_showport_reta_rss =
2776         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2777 cmdline_parse_token_string_t cmd_showport_reta_reta =
2778         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2779 cmdline_parse_token_num_t cmd_showport_reta_size =
2780         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2781 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2782         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2783                                         list_of_items, NULL);
2784
2785 cmdline_parse_inst_t cmd_showport_reta = {
2786         .f = cmd_showport_reta_parsed,
2787         .data = NULL,
2788         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2789         .tokens = {
2790                 (void *)&cmd_showport_reta_show,
2791                 (void *)&cmd_showport_reta_port,
2792                 (void *)&cmd_showport_reta_port_id,
2793                 (void *)&cmd_showport_reta_rss,
2794                 (void *)&cmd_showport_reta_reta,
2795                 (void *)&cmd_showport_reta_size,
2796                 (void *)&cmd_showport_reta_list_of_items,
2797                 NULL,
2798         },
2799 };
2800
2801 /* *** Show RSS hash configuration *** */
2802 struct cmd_showport_rss_hash {
2803         cmdline_fixed_string_t show;
2804         cmdline_fixed_string_t port;
2805         portid_t port_id;
2806         cmdline_fixed_string_t rss_hash;
2807         cmdline_fixed_string_t rss_type;
2808         cmdline_fixed_string_t key; /* optional argument */
2809 };
2810
2811 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2812                                 __attribute__((unused)) struct cmdline *cl,
2813                                 void *show_rss_key)
2814 {
2815         struct cmd_showport_rss_hash *res = parsed_result;
2816
2817         port_rss_hash_conf_show(res->port_id, res->rss_type,
2818                                 show_rss_key != NULL);
2819 }
2820
2821 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2822         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2823 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2824         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2825 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2826         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2827 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2828         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2829                                  "rss-hash");
2830 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2831         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2832                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2833                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2834                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2835                                  "ipv6-tcp-ex#ipv6-udp-ex");
2836 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2837         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2838
2839 cmdline_parse_inst_t cmd_showport_rss_hash = {
2840         .f = cmd_showport_rss_hash_parsed,
2841         .data = NULL,
2842         .help_str = "show port <port_id> rss-hash "
2843                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2844                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2845                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2846         .tokens = {
2847                 (void *)&cmd_showport_rss_hash_show,
2848                 (void *)&cmd_showport_rss_hash_port,
2849                 (void *)&cmd_showport_rss_hash_port_id,
2850                 (void *)&cmd_showport_rss_hash_rss_hash,
2851                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2852                 NULL,
2853         },
2854 };
2855
2856 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2857         .f = cmd_showport_rss_hash_parsed,
2858         .data = (void *)1,
2859         .help_str = "show port <port_id> rss-hash "
2860                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2861                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2862                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2863         .tokens = {
2864                 (void *)&cmd_showport_rss_hash_show,
2865                 (void *)&cmd_showport_rss_hash_port,
2866                 (void *)&cmd_showport_rss_hash_port_id,
2867                 (void *)&cmd_showport_rss_hash_rss_hash,
2868                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2869                 (void *)&cmd_showport_rss_hash_rss_key,
2870                 NULL,
2871         },
2872 };
2873
2874 /* *** Configure DCB *** */
2875 struct cmd_config_dcb {
2876         cmdline_fixed_string_t port;
2877         cmdline_fixed_string_t config;
2878         portid_t port_id;
2879         cmdline_fixed_string_t dcb;
2880         cmdline_fixed_string_t vt;
2881         cmdline_fixed_string_t vt_en;
2882         uint8_t num_tcs;
2883         cmdline_fixed_string_t pfc;
2884         cmdline_fixed_string_t pfc_en;
2885 };
2886
2887 static void
2888 cmd_config_dcb_parsed(void *parsed_result,
2889                         __attribute__((unused)) struct cmdline *cl,
2890                         __attribute__((unused)) void *data)
2891 {
2892         struct cmd_config_dcb *res = parsed_result;
2893         portid_t port_id = res->port_id;
2894         struct rte_port *port;
2895         uint8_t pfc_en;
2896         int ret;
2897
2898         port = &ports[port_id];
2899         /** Check if the port is not started **/
2900         if (port->port_status != RTE_PORT_STOPPED) {
2901                 printf("Please stop port %d first\n", port_id);
2902                 return;
2903         }
2904
2905         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2906                 printf("The invalid number of traffic class,"
2907                         " only 4 or 8 allowed.\n");
2908                 return;
2909         }
2910
2911         if (nb_fwd_lcores < res->num_tcs) {
2912                 printf("nb_cores shouldn't be less than number of TCs.\n");
2913                 return;
2914         }
2915         if (!strncmp(res->pfc_en, "on", 2))
2916                 pfc_en = 1;
2917         else
2918                 pfc_en = 0;
2919
2920         /* DCB in VT mode */
2921         if (!strncmp(res->vt_en, "on", 2))
2922                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2923                                 (enum rte_eth_nb_tcs)res->num_tcs,
2924                                 pfc_en);
2925         else
2926                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2927                                 (enum rte_eth_nb_tcs)res->num_tcs,
2928                                 pfc_en);
2929
2930
2931         if (ret != 0) {
2932                 printf("Cannot initialize network ports.\n");
2933                 return;
2934         }
2935
2936         cmd_reconfig_device_queue(port_id, 1, 1);
2937 }
2938
2939 cmdline_parse_token_string_t cmd_config_dcb_port =
2940         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2941 cmdline_parse_token_string_t cmd_config_dcb_config =
2942         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2943 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2944         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2945 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2946         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2947 cmdline_parse_token_string_t cmd_config_dcb_vt =
2948         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2949 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2950         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2951 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2952         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2953 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2954         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2955 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2956         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2957
2958 cmdline_parse_inst_t cmd_config_dcb = {
2959         .f = cmd_config_dcb_parsed,
2960         .data = NULL,
2961         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2962         .tokens = {
2963                 (void *)&cmd_config_dcb_port,
2964                 (void *)&cmd_config_dcb_config,
2965                 (void *)&cmd_config_dcb_port_id,
2966                 (void *)&cmd_config_dcb_dcb,
2967                 (void *)&cmd_config_dcb_vt,
2968                 (void *)&cmd_config_dcb_vt_en,
2969                 (void *)&cmd_config_dcb_num_tcs,
2970                 (void *)&cmd_config_dcb_pfc,
2971                 (void *)&cmd_config_dcb_pfc_en,
2972                 NULL,
2973         },
2974 };
2975
2976 /* *** configure number of packets per burst *** */
2977 struct cmd_config_burst {
2978         cmdline_fixed_string_t port;
2979         cmdline_fixed_string_t keyword;
2980         cmdline_fixed_string_t all;
2981         cmdline_fixed_string_t name;
2982         uint16_t value;
2983 };
2984
2985 static void
2986 cmd_config_burst_parsed(void *parsed_result,
2987                         __attribute__((unused)) struct cmdline *cl,
2988                         __attribute__((unused)) void *data)
2989 {
2990         struct cmd_config_burst *res = parsed_result;
2991         struct rte_eth_dev_info dev_info;
2992         uint16_t rec_nb_pkts;
2993
2994         if (!all_ports_stopped()) {
2995                 printf("Please stop all ports first\n");
2996                 return;
2997         }
2998
2999         if (!strcmp(res->name, "burst")) {
3000                 if (res->value == 0) {
3001                         /* If user gives a value of zero, query the PMD for
3002                          * its recommended Rx burst size. Testpmd uses a single
3003                          * size for all ports, so assume all ports are the same
3004                          * NIC model and use the values from Port 0.
3005                          */
3006                         rte_eth_dev_info_get(0, &dev_info);
3007                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3008
3009                         if (rec_nb_pkts == 0) {
3010                                 printf("PMD does not recommend a burst size.\n"
3011                                         "User provided value must be between"
3012                                         " 1 and %d\n", MAX_PKT_BURST);
3013                                 return;
3014                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3015                                 printf("PMD recommended burst size of %d"
3016                                         " exceeds maximum value of %d\n",
3017                                         rec_nb_pkts, MAX_PKT_BURST);
3018                                 return;
3019                         }
3020                         printf("Using PMD-provided burst value of %d\n",
3021                                 rec_nb_pkts);
3022                         nb_pkt_per_burst = rec_nb_pkts;
3023                 } else if (res->value > MAX_PKT_BURST) {
3024                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3025                         return;
3026                 } else
3027                         nb_pkt_per_burst = res->value;
3028         } else {
3029                 printf("Unknown parameter\n");
3030                 return;
3031         }
3032
3033         init_port_config();
3034
3035         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3036 }
3037
3038 cmdline_parse_token_string_t cmd_config_burst_port =
3039         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3040 cmdline_parse_token_string_t cmd_config_burst_keyword =
3041         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3042 cmdline_parse_token_string_t cmd_config_burst_all =
3043         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3044 cmdline_parse_token_string_t cmd_config_burst_name =
3045         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3046 cmdline_parse_token_num_t cmd_config_burst_value =
3047         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3048
3049 cmdline_parse_inst_t cmd_config_burst = {
3050         .f = cmd_config_burst_parsed,
3051         .data = NULL,
3052         .help_str = "port config all burst <value>",
3053         .tokens = {
3054                 (void *)&cmd_config_burst_port,
3055                 (void *)&cmd_config_burst_keyword,
3056                 (void *)&cmd_config_burst_all,
3057                 (void *)&cmd_config_burst_name,
3058                 (void *)&cmd_config_burst_value,
3059                 NULL,
3060         },
3061 };
3062
3063 /* *** configure rx/tx queues *** */
3064 struct cmd_config_thresh {
3065         cmdline_fixed_string_t port;
3066         cmdline_fixed_string_t keyword;
3067         cmdline_fixed_string_t all;
3068         cmdline_fixed_string_t name;
3069         uint8_t value;
3070 };
3071
3072 static void
3073 cmd_config_thresh_parsed(void *parsed_result,
3074                         __attribute__((unused)) struct cmdline *cl,
3075                         __attribute__((unused)) void *data)
3076 {
3077         struct cmd_config_thresh *res = parsed_result;
3078
3079         if (!all_ports_stopped()) {
3080                 printf("Please stop all ports first\n");
3081                 return;
3082         }
3083
3084         if (!strcmp(res->name, "txpt"))
3085                 tx_pthresh = res->value;
3086         else if(!strcmp(res->name, "txht"))
3087                 tx_hthresh = res->value;
3088         else if(!strcmp(res->name, "txwt"))
3089                 tx_wthresh = res->value;
3090         else if(!strcmp(res->name, "rxpt"))
3091                 rx_pthresh = res->value;
3092         else if(!strcmp(res->name, "rxht"))
3093                 rx_hthresh = res->value;
3094         else if(!strcmp(res->name, "rxwt"))
3095                 rx_wthresh = res->value;
3096         else {
3097                 printf("Unknown parameter\n");
3098                 return;
3099         }
3100
3101         init_port_config();
3102
3103         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3104 }
3105
3106 cmdline_parse_token_string_t cmd_config_thresh_port =
3107         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3108 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3109         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3110 cmdline_parse_token_string_t cmd_config_thresh_all =
3111         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3112 cmdline_parse_token_string_t cmd_config_thresh_name =
3113         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3114                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3115 cmdline_parse_token_num_t cmd_config_thresh_value =
3116         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3117
3118 cmdline_parse_inst_t cmd_config_thresh = {
3119         .f = cmd_config_thresh_parsed,
3120         .data = NULL,
3121         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3122         .tokens = {
3123                 (void *)&cmd_config_thresh_port,
3124                 (void *)&cmd_config_thresh_keyword,
3125                 (void *)&cmd_config_thresh_all,
3126                 (void *)&cmd_config_thresh_name,
3127                 (void *)&cmd_config_thresh_value,
3128                 NULL,
3129         },
3130 };
3131
3132 /* *** configure free/rs threshold *** */
3133 struct cmd_config_threshold {
3134         cmdline_fixed_string_t port;
3135         cmdline_fixed_string_t keyword;
3136         cmdline_fixed_string_t all;
3137         cmdline_fixed_string_t name;
3138         uint16_t value;
3139 };
3140
3141 static void
3142 cmd_config_threshold_parsed(void *parsed_result,
3143                         __attribute__((unused)) struct cmdline *cl,
3144                         __attribute__((unused)) void *data)
3145 {
3146         struct cmd_config_threshold *res = parsed_result;
3147
3148         if (!all_ports_stopped()) {
3149                 printf("Please stop all ports first\n");
3150                 return;
3151         }
3152
3153         if (!strcmp(res->name, "txfreet"))
3154                 tx_free_thresh = res->value;
3155         else if (!strcmp(res->name, "txrst"))
3156                 tx_rs_thresh = res->value;
3157         else if (!strcmp(res->name, "rxfreet"))
3158                 rx_free_thresh = res->value;
3159         else {
3160                 printf("Unknown parameter\n");
3161                 return;
3162         }
3163
3164         init_port_config();
3165
3166         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3167 }
3168
3169 cmdline_parse_token_string_t cmd_config_threshold_port =
3170         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3171 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3172         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3173                                                                 "config");
3174 cmdline_parse_token_string_t cmd_config_threshold_all =
3175         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3176 cmdline_parse_token_string_t cmd_config_threshold_name =
3177         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3178                                                 "txfreet#txrst#rxfreet");
3179 cmdline_parse_token_num_t cmd_config_threshold_value =
3180         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3181
3182 cmdline_parse_inst_t cmd_config_threshold = {
3183         .f = cmd_config_threshold_parsed,
3184         .data = NULL,
3185         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3186         .tokens = {
3187                 (void *)&cmd_config_threshold_port,
3188                 (void *)&cmd_config_threshold_keyword,
3189                 (void *)&cmd_config_threshold_all,
3190                 (void *)&cmd_config_threshold_name,
3191                 (void *)&cmd_config_threshold_value,
3192                 NULL,
3193         },
3194 };
3195
3196 /* *** stop *** */
3197 struct cmd_stop_result {
3198         cmdline_fixed_string_t stop;
3199 };
3200
3201 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3202                             __attribute__((unused)) struct cmdline *cl,
3203                             __attribute__((unused)) void *data)
3204 {
3205         stop_packet_forwarding();
3206 }
3207
3208 cmdline_parse_token_string_t cmd_stop_stop =
3209         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3210
3211 cmdline_parse_inst_t cmd_stop = {
3212         .f = cmd_stop_parsed,
3213         .data = NULL,
3214         .help_str = "stop: Stop packet forwarding",
3215         .tokens = {
3216                 (void *)&cmd_stop_stop,
3217                 NULL,
3218         },
3219 };
3220
3221 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3222
3223 unsigned int
3224 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3225                 unsigned int *parsed_items, int check_unique_values)
3226 {
3227         unsigned int nb_item;
3228         unsigned int value;
3229         unsigned int i;
3230         unsigned int j;
3231         int value_ok;
3232         char c;
3233
3234         /*
3235          * First parse all items in the list and store their value.
3236          */
3237         value = 0;
3238         nb_item = 0;
3239         value_ok = 0;
3240         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3241                 c = str[i];
3242                 if ((c >= '0') && (c <= '9')) {
3243                         value = (unsigned int) (value * 10 + (c - '0'));
3244                         value_ok = 1;
3245                         continue;
3246                 }
3247                 if (c != ',') {
3248                         printf("character %c is not a decimal digit\n", c);
3249                         return 0;
3250                 }
3251                 if (! value_ok) {
3252                         printf("No valid value before comma\n");
3253                         return 0;
3254                 }
3255                 if (nb_item < max_items) {
3256                         parsed_items[nb_item] = value;
3257                         value_ok = 0;
3258                         value = 0;
3259                 }
3260                 nb_item++;
3261         }
3262         if (nb_item >= max_items) {
3263                 printf("Number of %s = %u > %u (maximum items)\n",
3264                        item_name, nb_item + 1, max_items);
3265                 return 0;
3266         }
3267         parsed_items[nb_item++] = value;
3268         if (! check_unique_values)
3269                 return nb_item;
3270
3271         /*
3272          * Then, check that all values in the list are differents.
3273          * No optimization here...
3274          */
3275         for (i = 0; i < nb_item; i++) {
3276                 for (j = i + 1; j < nb_item; j++) {
3277                         if (parsed_items[j] == parsed_items[i]) {
3278                                 printf("duplicated %s %u at index %u and %u\n",
3279                                        item_name, parsed_items[i], i, j);
3280                                 return 0;
3281                         }
3282                 }
3283         }
3284         return nb_item;
3285 }
3286
3287 struct cmd_set_list_result {
3288         cmdline_fixed_string_t cmd_keyword;
3289         cmdline_fixed_string_t list_name;
3290         cmdline_fixed_string_t list_of_items;
3291 };
3292
3293 static void cmd_set_list_parsed(void *parsed_result,
3294                                 __attribute__((unused)) struct cmdline *cl,
3295                                 __attribute__((unused)) void *data)
3296 {
3297         struct cmd_set_list_result *res;
3298         union {
3299                 unsigned int lcorelist[RTE_MAX_LCORE];
3300                 unsigned int portlist[RTE_MAX_ETHPORTS];
3301         } parsed_items;
3302         unsigned int nb_item;
3303
3304         if (test_done == 0) {
3305                 printf("Please stop forwarding first\n");
3306                 return;
3307         }
3308
3309         res = parsed_result;
3310         if (!strcmp(res->list_name, "corelist")) {
3311                 nb_item = parse_item_list(res->list_of_items, "core",
3312                                           RTE_MAX_LCORE,
3313                                           parsed_items.lcorelist, 1);
3314                 if (nb_item > 0) {
3315                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3316                         fwd_config_setup();
3317                 }
3318                 return;
3319         }
3320         if (!strcmp(res->list_name, "portlist")) {
3321                 nb_item = parse_item_list(res->list_of_items, "port",
3322                                           RTE_MAX_ETHPORTS,
3323                                           parsed_items.portlist, 1);
3324                 if (nb_item > 0) {
3325                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3326                         fwd_config_setup();
3327                 }
3328         }
3329 }
3330
3331 cmdline_parse_token_string_t cmd_set_list_keyword =
3332         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3333                                  "set");
3334 cmdline_parse_token_string_t cmd_set_list_name =
3335         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3336                                  "corelist#portlist");
3337 cmdline_parse_token_string_t cmd_set_list_of_items =
3338         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3339                                  NULL);
3340
3341 cmdline_parse_inst_t cmd_set_fwd_list = {
3342         .f = cmd_set_list_parsed,
3343         .data = NULL,
3344         .help_str = "set corelist|portlist <list0[,list1]*>",
3345         .tokens = {
3346                 (void *)&cmd_set_list_keyword,
3347                 (void *)&cmd_set_list_name,
3348                 (void *)&cmd_set_list_of_items,
3349                 NULL,
3350         },
3351 };
3352
3353 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3354
3355 struct cmd_setmask_result {
3356         cmdline_fixed_string_t set;
3357         cmdline_fixed_string_t mask;
3358         uint64_t hexavalue;
3359 };
3360
3361 static void cmd_set_mask_parsed(void *parsed_result,
3362                                 __attribute__((unused)) struct cmdline *cl,
3363                                 __attribute__((unused)) void *data)
3364 {
3365         struct cmd_setmask_result *res = parsed_result;
3366
3367         if (test_done == 0) {
3368                 printf("Please stop forwarding first\n");
3369                 return;
3370         }
3371         if (!strcmp(res->mask, "coremask")) {
3372                 set_fwd_lcores_mask(res->hexavalue);
3373                 fwd_config_setup();
3374         } else if (!strcmp(res->mask, "portmask")) {
3375                 set_fwd_ports_mask(res->hexavalue);
3376                 fwd_config_setup();
3377         }
3378 }
3379
3380 cmdline_parse_token_string_t cmd_setmask_set =
3381         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3382 cmdline_parse_token_string_t cmd_setmask_mask =
3383         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3384                                  "coremask#portmask");
3385 cmdline_parse_token_num_t cmd_setmask_value =
3386         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3387
3388 cmdline_parse_inst_t cmd_set_fwd_mask = {
3389         .f = cmd_set_mask_parsed,
3390         .data = NULL,
3391         .help_str = "set coremask|portmask <hexadecimal value>",
3392         .tokens = {
3393                 (void *)&cmd_setmask_set,
3394                 (void *)&cmd_setmask_mask,
3395                 (void *)&cmd_setmask_value,
3396                 NULL,
3397         },
3398 };
3399
3400 /*
3401  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3402  */
3403 struct cmd_set_result {
3404         cmdline_fixed_string_t set;
3405         cmdline_fixed_string_t what;
3406         uint16_t value;
3407 };
3408
3409 static void cmd_set_parsed(void *parsed_result,
3410                            __attribute__((unused)) struct cmdline *cl,
3411                            __attribute__((unused)) void *data)
3412 {
3413         struct cmd_set_result *res = parsed_result;
3414         if (!strcmp(res->what, "nbport")) {
3415                 set_fwd_ports_number(res->value);
3416                 fwd_config_setup();
3417         } else if (!strcmp(res->what, "nbcore")) {
3418                 set_fwd_lcores_number(res->value);
3419                 fwd_config_setup();
3420         } else if (!strcmp(res->what, "burst"))
3421                 set_nb_pkt_per_burst(res->value);
3422         else if (!strcmp(res->what, "verbose"))
3423                 set_verbose_level(res->value);
3424 }
3425
3426 cmdline_parse_token_string_t cmd_set_set =
3427         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3428 cmdline_parse_token_string_t cmd_set_what =
3429         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3430                                  "nbport#nbcore#burst#verbose");
3431 cmdline_parse_token_num_t cmd_set_value =
3432         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3433
3434 cmdline_parse_inst_t cmd_set_numbers = {
3435         .f = cmd_set_parsed,
3436         .data = NULL,
3437         .help_str = "set nbport|nbcore|burst|verbose <value>",
3438         .tokens = {
3439                 (void *)&cmd_set_set,
3440                 (void *)&cmd_set_what,
3441                 (void *)&cmd_set_value,
3442                 NULL,
3443         },
3444 };
3445
3446 /* *** SET LOG LEVEL CONFIGURATION *** */
3447
3448 struct cmd_set_log_result {
3449         cmdline_fixed_string_t set;
3450         cmdline_fixed_string_t log;
3451         cmdline_fixed_string_t type;
3452         uint32_t level;
3453 };
3454
3455 static void
3456 cmd_set_log_parsed(void *parsed_result,
3457                    __attribute__((unused)) struct cmdline *cl,
3458                    __attribute__((unused)) void *data)
3459 {
3460         struct cmd_set_log_result *res;
3461         int ret;
3462
3463         res = parsed_result;
3464         if (!strcmp(res->type, "global"))
3465                 rte_log_set_global_level(res->level);
3466         else {
3467                 ret = rte_log_set_level_regexp(res->type, res->level);
3468                 if (ret < 0)
3469                         printf("Unable to set log level\n");
3470         }
3471 }
3472
3473 cmdline_parse_token_string_t cmd_set_log_set =
3474         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3475 cmdline_parse_token_string_t cmd_set_log_log =
3476         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3477 cmdline_parse_token_string_t cmd_set_log_type =
3478         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3479 cmdline_parse_token_num_t cmd_set_log_level =
3480         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3481
3482 cmdline_parse_inst_t cmd_set_log = {
3483         .f = cmd_set_log_parsed,
3484         .data = NULL,
3485         .help_str = "set log global|<type> <level>",
3486         .tokens = {
3487                 (void *)&cmd_set_log_set,
3488                 (void *)&cmd_set_log_log,
3489                 (void *)&cmd_set_log_type,
3490                 (void *)&cmd_set_log_level,
3491                 NULL,
3492         },
3493 };
3494
3495 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3496
3497 struct cmd_set_txpkts_result {
3498         cmdline_fixed_string_t cmd_keyword;
3499         cmdline_fixed_string_t txpkts;
3500         cmdline_fixed_string_t seg_lengths;
3501 };
3502
3503 static void
3504 cmd_set_txpkts_parsed(void *parsed_result,
3505                       __attribute__((unused)) struct cmdline *cl,
3506                       __attribute__((unused)) void *data)
3507 {
3508         struct cmd_set_txpkts_result *res;
3509         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3510         unsigned int nb_segs;
3511
3512         res = parsed_result;
3513         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3514                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3515         if (nb_segs > 0)
3516                 set_tx_pkt_segments(seg_lengths, nb_segs);
3517 }
3518
3519 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3520         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3521                                  cmd_keyword, "set");
3522 cmdline_parse_token_string_t cmd_set_txpkts_name =
3523         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3524                                  txpkts, "txpkts");
3525 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3526         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3527                                  seg_lengths, NULL);
3528
3529 cmdline_parse_inst_t cmd_set_txpkts = {
3530         .f = cmd_set_txpkts_parsed,
3531         .data = NULL,
3532         .help_str = "set txpkts <len0[,len1]*>",
3533         .tokens = {
3534                 (void *)&cmd_set_txpkts_keyword,
3535                 (void *)&cmd_set_txpkts_name,
3536                 (void *)&cmd_set_txpkts_lengths,
3537                 NULL,
3538         },
3539 };
3540
3541 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3542
3543 struct cmd_set_txsplit_result {
3544         cmdline_fixed_string_t cmd_keyword;
3545         cmdline_fixed_string_t txsplit;
3546         cmdline_fixed_string_t mode;
3547 };
3548
3549 static void
3550 cmd_set_txsplit_parsed(void *parsed_result,
3551                       __attribute__((unused)) struct cmdline *cl,
3552                       __attribute__((unused)) void *data)
3553 {
3554         struct cmd_set_txsplit_result *res;
3555
3556         res = parsed_result;
3557         set_tx_pkt_split(res->mode);
3558 }
3559
3560 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3561         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3562                                  cmd_keyword, "set");
3563 cmdline_parse_token_string_t cmd_set_txsplit_name =
3564         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3565                                  txsplit, "txsplit");
3566 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3567         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3568                                  mode, NULL);
3569
3570 cmdline_parse_inst_t cmd_set_txsplit = {
3571         .f = cmd_set_txsplit_parsed,
3572         .data = NULL,
3573         .help_str = "set txsplit on|off|rand",
3574         .tokens = {
3575                 (void *)&cmd_set_txsplit_keyword,
3576                 (void *)&cmd_set_txsplit_name,
3577                 (void *)&cmd_set_txsplit_mode,
3578                 NULL,
3579         },
3580 };
3581
3582 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3583 struct cmd_rx_vlan_filter_all_result {
3584         cmdline_fixed_string_t rx_vlan;
3585         cmdline_fixed_string_t what;
3586         cmdline_fixed_string_t all;
3587         portid_t port_id;
3588 };
3589
3590 static void
3591 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3592                               __attribute__((unused)) struct cmdline *cl,
3593                               __attribute__((unused)) void *data)
3594 {
3595         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3596
3597         if (!strcmp(res->what, "add"))
3598                 rx_vlan_all_filter_set(res->port_id, 1);
3599         else
3600                 rx_vlan_all_filter_set(res->port_id, 0);
3601 }
3602
3603 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3604         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3605                                  rx_vlan, "rx_vlan");
3606 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3607         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3608                                  what, "add#rm");
3609 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3610         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3611                                  all, "all");
3612 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3613         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3614                               port_id, UINT16);
3615
3616 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3617         .f = cmd_rx_vlan_filter_all_parsed,
3618         .data = NULL,
3619         .help_str = "rx_vlan add|rm all <port_id>: "
3620                 "Add/Remove all identifiers to/from the set of VLAN "
3621                 "identifiers filtered by a port",
3622         .tokens = {
3623                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3624                 (void *)&cmd_rx_vlan_filter_all_what,
3625                 (void *)&cmd_rx_vlan_filter_all_all,
3626                 (void *)&cmd_rx_vlan_filter_all_portid,
3627                 NULL,
3628         },
3629 };
3630
3631 /* *** VLAN OFFLOAD SET ON A PORT *** */
3632 struct cmd_vlan_offload_result {
3633         cmdline_fixed_string_t vlan;
3634         cmdline_fixed_string_t set;
3635         cmdline_fixed_string_t vlan_type;
3636         cmdline_fixed_string_t what;
3637         cmdline_fixed_string_t on;
3638         cmdline_fixed_string_t port_id;
3639 };
3640
3641 static void
3642 cmd_vlan_offload_parsed(void *parsed_result,
3643                           __attribute__((unused)) struct cmdline *cl,
3644                           __attribute__((unused)) void *data)
3645 {
3646         int on;
3647         struct cmd_vlan_offload_result *res = parsed_result;
3648         char *str;
3649         int i, len = 0;
3650         portid_t port_id = 0;
3651         unsigned int tmp;
3652
3653         str = res->port_id;
3654         len = strnlen(str, STR_TOKEN_SIZE);
3655         i = 0;
3656         /* Get port_id first */
3657         while(i < len){
3658                 if(str[i] == ',')
3659                         break;
3660
3661                 i++;
3662         }
3663         str[i]='\0';
3664         tmp = strtoul(str, NULL, 0);
3665         /* If port_id greater that what portid_t can represent, return */
3666         if(tmp >= RTE_MAX_ETHPORTS)
3667                 return;
3668         port_id = (portid_t)tmp;
3669
3670         if (!strcmp(res->on, "on"))
3671                 on = 1;
3672         else
3673                 on = 0;
3674
3675         if (!strcmp(res->what, "strip"))
3676                 rx_vlan_strip_set(port_id,  on);
3677         else if(!strcmp(res->what, "stripq")){
3678                 uint16_t queue_id = 0;
3679
3680                 /* No queue_id, return */
3681                 if(i + 1 >= len) {
3682                         printf("must specify (port,queue_id)\n");
3683                         return;
3684                 }
3685                 tmp = strtoul(str + i + 1, NULL, 0);
3686                 /* If queue_id greater that what 16-bits can represent, return */
3687                 if(tmp > 0xffff)
3688                         return;
3689
3690                 queue_id = (uint16_t)tmp;
3691                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3692         }
3693         else if (!strcmp(res->what, "filter"))
3694                 rx_vlan_filter_set(port_id, on);
3695         else
3696                 vlan_extend_set(port_id, on);
3697
3698         return;
3699 }
3700
3701 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3702         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3703                                  vlan, "vlan");
3704 cmdline_parse_token_string_t cmd_vlan_offload_set =
3705         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3706                                  set, "set");
3707 cmdline_parse_token_string_t cmd_vlan_offload_what =
3708         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3709                                  what, "strip#filter#qinq#stripq");
3710 cmdline_parse_token_string_t cmd_vlan_offload_on =
3711         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3712                               on, "on#off");
3713 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3714         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3715                               port_id, NULL);
3716
3717 cmdline_parse_inst_t cmd_vlan_offload = {
3718         .f = cmd_vlan_offload_parsed,
3719         .data = NULL,
3720         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3721                 "<port_id[,queue_id]>: "
3722                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3723         .tokens = {
3724                 (void *)&cmd_vlan_offload_vlan,
3725                 (void *)&cmd_vlan_offload_set,
3726                 (void *)&cmd_vlan_offload_what,
3727                 (void *)&cmd_vlan_offload_on,
3728                 (void *)&cmd_vlan_offload_portid,
3729                 NULL,
3730         },
3731 };
3732
3733 /* *** VLAN TPID SET ON A PORT *** */
3734 struct cmd_vlan_tpid_result {
3735         cmdline_fixed_string_t vlan;
3736         cmdline_fixed_string_t set;
3737         cmdline_fixed_string_t vlan_type;
3738         cmdline_fixed_string_t what;
3739         uint16_t tp_id;
3740         portid_t port_id;
3741 };
3742
3743 static void
3744 cmd_vlan_tpid_parsed(void *parsed_result,
3745                           __attribute__((unused)) struct cmdline *cl,
3746                           __attribute__((unused)) void *data)
3747 {
3748         struct cmd_vlan_tpid_result *res = parsed_result;
3749         enum rte_vlan_type vlan_type;
3750
3751         if (!strcmp(res->vlan_type, "inner"))
3752                 vlan_type = ETH_VLAN_TYPE_INNER;
3753         else if (!strcmp(res->vlan_type, "outer"))
3754                 vlan_type = ETH_VLAN_TYPE_OUTER;
3755         else {
3756                 printf("Unknown vlan type\n");
3757                 return;
3758         }
3759         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3760 }
3761
3762 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3763         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3764                                  vlan, "vlan");
3765 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3766         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3767                                  set, "set");
3768 cmdline_parse_token_string_t cmd_vlan_type =
3769         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3770                                  vlan_type, "inner#outer");
3771 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3772         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3773                                  what, "tpid");
3774 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3775         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3776                               tp_id, UINT16);
3777 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3778         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3779                               port_id, UINT16);
3780
3781 cmdline_parse_inst_t cmd_vlan_tpid = {
3782         .f = cmd_vlan_tpid_parsed,
3783         .data = NULL,
3784         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3785                 "Set the VLAN Ether type",
3786         .tokens = {
3787                 (void *)&cmd_vlan_tpid_vlan,
3788                 (void *)&cmd_vlan_tpid_set,
3789                 (void *)&cmd_vlan_type,
3790                 (void *)&cmd_vlan_tpid_what,
3791                 (void *)&cmd_vlan_tpid_tpid,
3792                 (void *)&cmd_vlan_tpid_portid,
3793                 NULL,
3794         },
3795 };
3796
3797 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3798 struct cmd_rx_vlan_filter_result {
3799         cmdline_fixed_string_t rx_vlan;
3800         cmdline_fixed_string_t what;
3801         uint16_t vlan_id;
3802         portid_t port_id;
3803 };
3804
3805 static void
3806 cmd_rx_vlan_filter_parsed(void *parsed_result,
3807                           __attribute__((unused)) struct cmdline *cl,
3808                           __attribute__((unused)) void *data)
3809 {
3810         struct cmd_rx_vlan_filter_result *res = parsed_result;
3811
3812         if (!strcmp(res->what, "add"))
3813                 rx_vft_set(res->port_id, res->vlan_id, 1);
3814         else
3815                 rx_vft_set(res->port_id, res->vlan_id, 0);
3816 }
3817
3818 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3819         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3820                                  rx_vlan, "rx_vlan");
3821 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3822         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3823                                  what, "add#rm");
3824 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3825         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3826                               vlan_id, UINT16);
3827 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3828         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3829                               port_id, UINT16);
3830
3831 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3832         .f = cmd_rx_vlan_filter_parsed,
3833         .data = NULL,
3834         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3835                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3836                 "identifiers filtered by a port",
3837         .tokens = {
3838                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3839                 (void *)&cmd_rx_vlan_filter_what,
3840                 (void *)&cmd_rx_vlan_filter_vlanid,
3841                 (void *)&cmd_rx_vlan_filter_portid,
3842                 NULL,
3843         },
3844 };
3845
3846 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3847 struct cmd_tx_vlan_set_result {
3848         cmdline_fixed_string_t tx_vlan;
3849         cmdline_fixed_string_t set;
3850         portid_t port_id;
3851         uint16_t vlan_id;
3852 };
3853
3854 static void
3855 cmd_tx_vlan_set_parsed(void *parsed_result,
3856                        __attribute__((unused)) struct cmdline *cl,
3857                        __attribute__((unused)) void *data)
3858 {
3859         struct cmd_tx_vlan_set_result *res = parsed_result;
3860
3861         if (!port_is_stopped(res->port_id)) {
3862                 printf("Please stop port %d first\n", res->port_id);
3863                 return;
3864         }
3865
3866         tx_vlan_set(res->port_id, res->vlan_id);
3867
3868         cmd_reconfig_device_queue(res->port_id, 1, 1);
3869 }
3870
3871 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3872         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3873                                  tx_vlan, "tx_vlan");
3874 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3875         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3876                                  set, "set");
3877 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3878         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3879                               port_id, UINT16);
3880 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3881         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3882                               vlan_id, UINT16);
3883
3884 cmdline_parse_inst_t cmd_tx_vlan_set = {
3885         .f = cmd_tx_vlan_set_parsed,
3886         .data = NULL,
3887         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3888                 "Enable hardware insertion of a single VLAN header "
3889                 "with a given TAG Identifier in packets sent on a port",
3890         .tokens = {
3891                 (void *)&cmd_tx_vlan_set_tx_vlan,
3892                 (void *)&cmd_tx_vlan_set_set,
3893                 (void *)&cmd_tx_vlan_set_portid,
3894                 (void *)&cmd_tx_vlan_set_vlanid,
3895                 NULL,
3896         },
3897 };
3898
3899 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3900 struct cmd_tx_vlan_set_qinq_result {
3901         cmdline_fixed_string_t tx_vlan;
3902         cmdline_fixed_string_t set;
3903         portid_t port_id;
3904         uint16_t vlan_id;
3905         uint16_t vlan_id_outer;
3906 };
3907
3908 static void
3909 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3910                             __attribute__((unused)) struct cmdline *cl,
3911                             __attribute__((unused)) void *data)
3912 {
3913         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3914
3915         if (!port_is_stopped(res->port_id)) {
3916                 printf("Please stop port %d first\n", res->port_id);
3917                 return;
3918         }
3919
3920         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3921
3922         cmd_reconfig_device_queue(res->port_id, 1, 1);
3923 }
3924
3925 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3926         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3927                 tx_vlan, "tx_vlan");
3928 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3929         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3930                 set, "set");
3931 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3932         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3933                 port_id, UINT16);
3934 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3935         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3936                 vlan_id, UINT16);
3937 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3938         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3939                 vlan_id_outer, UINT16);
3940
3941 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3942         .f = cmd_tx_vlan_set_qinq_parsed,
3943         .data = NULL,
3944         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3945                 "Enable hardware insertion of double VLAN header "
3946                 "with given TAG Identifiers in packets sent on a port",
3947         .tokens = {
3948                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3949                 (void *)&cmd_tx_vlan_set_qinq_set,
3950                 (void *)&cmd_tx_vlan_set_qinq_portid,
3951                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3952                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3953                 NULL,
3954         },
3955 };
3956
3957 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3958 struct cmd_tx_vlan_set_pvid_result {
3959         cmdline_fixed_string_t tx_vlan;
3960         cmdline_fixed_string_t set;
3961         cmdline_fixed_string_t pvid;
3962         portid_t port_id;
3963         uint16_t vlan_id;
3964         cmdline_fixed_string_t mode;
3965 };
3966
3967 static void
3968 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3969                             __attribute__((unused)) struct cmdline *cl,
3970                             __attribute__((unused)) void *data)
3971 {
3972         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3973
3974         if (strcmp(res->mode, "on") == 0)
3975                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3976         else
3977                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3978 }
3979
3980 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3981         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3982                                  tx_vlan, "tx_vlan");
3983 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3984         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3985                                  set, "set");
3986 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3987         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3988                                  pvid, "pvid");
3989 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3990         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3991                              port_id, UINT16);
3992 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3993         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3994                               vlan_id, UINT16);
3995 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3996         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3997                                  mode, "on#off");
3998
3999 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4000         .f = cmd_tx_vlan_set_pvid_parsed,
4001         .data = NULL,
4002         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4003         .tokens = {
4004                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4005                 (void *)&cmd_tx_vlan_set_pvid_set,
4006                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4007                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4008                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4009                 (void *)&cmd_tx_vlan_set_pvid_mode,
4010                 NULL,
4011         },
4012 };
4013
4014 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4015 struct cmd_tx_vlan_reset_result {
4016         cmdline_fixed_string_t tx_vlan;
4017         cmdline_fixed_string_t reset;
4018         portid_t port_id;
4019 };
4020
4021 static void
4022 cmd_tx_vlan_reset_parsed(void *parsed_result,
4023                          __attribute__((unused)) struct cmdline *cl,
4024                          __attribute__((unused)) void *data)
4025 {
4026         struct cmd_tx_vlan_reset_result *res = parsed_result;
4027
4028         if (!port_is_stopped(res->port_id)) {
4029                 printf("Please stop port %d first\n", res->port_id);
4030                 return;
4031         }
4032
4033         tx_vlan_reset(res->port_id);
4034
4035         cmd_reconfig_device_queue(res->port_id, 1, 1);
4036 }
4037
4038 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4039         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4040                                  tx_vlan, "tx_vlan");
4041 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4042         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4043                                  reset, "reset");
4044 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4045         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4046                               port_id, UINT16);
4047
4048 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4049         .f = cmd_tx_vlan_reset_parsed,
4050         .data = NULL,
4051         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4052                 "VLAN header in packets sent on a port",
4053         .tokens = {
4054                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4055                 (void *)&cmd_tx_vlan_reset_reset,
4056                 (void *)&cmd_tx_vlan_reset_portid,
4057                 NULL,
4058         },
4059 };
4060
4061
4062 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4063 struct cmd_csum_result {
4064         cmdline_fixed_string_t csum;
4065         cmdline_fixed_string_t mode;
4066         cmdline_fixed_string_t proto;
4067         cmdline_fixed_string_t hwsw;
4068         portid_t port_id;
4069 };
4070
4071 static void
4072 csum_show(int port_id)
4073 {
4074         struct rte_eth_dev_info dev_info;
4075         uint64_t tx_offloads;
4076
4077         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4078         printf("Parse tunnel is %s\n",
4079                 (ports[port_id].parse_tunnel) ? "on" : "off");
4080         printf("IP checksum offload is %s\n",
4081                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4082         printf("UDP checksum offload is %s\n",
4083                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4084         printf("TCP checksum offload is %s\n",
4085                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4086         printf("SCTP checksum offload is %s\n",
4087                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4088         printf("Outer-Ip checksum offload is %s\n",
4089                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4090
4091         /* display warnings if configuration is not supported by the NIC */
4092         rte_eth_dev_info_get(port_id, &dev_info);
4093         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4094                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4095                 printf("Warning: hardware IP checksum enabled but not "
4096                         "supported by port %d\n", port_id);
4097         }
4098         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4099                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4100                 printf("Warning: hardware UDP checksum enabled but not "
4101                         "supported by port %d\n", port_id);
4102         }
4103         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4104                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4105                 printf("Warning: hardware TCP checksum enabled but not "
4106                         "supported by port %d\n", port_id);
4107         }
4108         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4109                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4110                 printf("Warning: hardware SCTP checksum enabled but not "
4111                         "supported by port %d\n", port_id);
4112         }
4113         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4114                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4115                 printf("Warning: hardware outer IP checksum enabled but not "
4116                         "supported by port %d\n", port_id);
4117         }
4118 }
4119
4120 static void
4121 cmd_csum_parsed(void *parsed_result,
4122                        __attribute__((unused)) struct cmdline *cl,
4123                        __attribute__((unused)) void *data)
4124 {
4125         struct cmd_csum_result *res = parsed_result;
4126         int hw = 0;
4127         uint64_t csum_offloads = 0;
4128         struct rte_eth_dev_info dev_info;
4129
4130         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4131                 printf("invalid port %d\n", res->port_id);
4132                 return;
4133         }
4134         if (!port_is_stopped(res->port_id)) {
4135                 printf("Please stop port %d first\n", res->port_id);
4136                 return;
4137         }
4138
4139         rte_eth_dev_info_get(res->port_id, &dev_info);
4140         if (!strcmp(res->mode, "set")) {
4141
4142                 if (!strcmp(res->hwsw, "hw"))
4143                         hw = 1;
4144
4145                 if (!strcmp(res->proto, "ip")) {
4146                         if (hw == 0 || (dev_info.tx_offload_capa &
4147                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4148                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4149                         } else {
4150                                 printf("IP checksum offload is not supported "
4151                                        "by port %u\n", res->port_id);
4152                         }
4153                 } else if (!strcmp(res->proto, "udp")) {
4154                         if (hw == 0 || (dev_info.tx_offload_capa &
4155                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4156                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4157                         } else {
4158                                 printf("UDP checksum offload is not supported "
4159                                        "by port %u\n", res->port_id);
4160                         }
4161                 } else if (!strcmp(res->proto, "tcp")) {
4162                         if (hw == 0 || (dev_info.tx_offload_capa &
4163                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4164                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4165                         } else {
4166                                 printf("TCP checksum offload is not supported "
4167                                        "by port %u\n", res->port_id);
4168                         }
4169                 } else if (!strcmp(res->proto, "sctp")) {
4170                         if (hw == 0 || (dev_info.tx_offload_capa &
4171                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4172                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4173                         } else {
4174                                 printf("SCTP checksum offload is not supported "
4175                                        "by port %u\n", res->port_id);
4176                         }
4177                 } else if (!strcmp(res->proto, "outer-ip")) {
4178                         if (hw == 0 || (dev_info.tx_offload_capa &
4179                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4180                                 csum_offloads |=
4181                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4182                         } else {
4183                                 printf("Outer IP checksum offload is not "
4184                                        "supported by port %u\n", res->port_id);
4185                         }
4186                 }
4187
4188                 if (hw) {
4189                         ports[res->port_id].dev_conf.txmode.offloads |=
4190                                                         csum_offloads;
4191                 } else {
4192                         ports[res->port_id].dev_conf.txmode.offloads &=
4193                                                         (~csum_offloads);
4194                 }
4195         }
4196         csum_show(res->port_id);
4197
4198         cmd_reconfig_device_queue(res->port_id, 1, 1);
4199 }
4200
4201 cmdline_parse_token_string_t cmd_csum_csum =
4202         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4203                                 csum, "csum");
4204 cmdline_parse_token_string_t cmd_csum_mode =
4205         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4206                                 mode, "set");
4207 cmdline_parse_token_string_t cmd_csum_proto =
4208         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4209                                 proto, "ip#tcp#udp#sctp#outer-ip");
4210 cmdline_parse_token_string_t cmd_csum_hwsw =
4211         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4212                                 hwsw, "hw#sw");
4213 cmdline_parse_token_num_t cmd_csum_portid =
4214         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4215                                 port_id, UINT16);
4216
4217 cmdline_parse_inst_t cmd_csum_set = {
4218         .f = cmd_csum_parsed,
4219         .data = NULL,
4220         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4221                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4222                 "using csum forward engine",
4223         .tokens = {
4224                 (void *)&cmd_csum_csum,
4225                 (void *)&cmd_csum_mode,
4226                 (void *)&cmd_csum_proto,
4227                 (void *)&cmd_csum_hwsw,
4228                 (void *)&cmd_csum_portid,
4229                 NULL,
4230         },
4231 };
4232
4233 cmdline_parse_token_string_t cmd_csum_mode_show =
4234         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4235                                 mode, "show");
4236
4237 cmdline_parse_inst_t cmd_csum_show = {
4238         .f = cmd_csum_parsed,
4239         .data = NULL,
4240         .help_str = "csum show <port_id>: Show checksum offload configuration",
4241         .tokens = {
4242                 (void *)&cmd_csum_csum,
4243                 (void *)&cmd_csum_mode_show,
4244                 (void *)&cmd_csum_portid,
4245                 NULL,
4246         },
4247 };
4248
4249 /* Enable/disable tunnel parsing */
4250 struct cmd_csum_tunnel_result {
4251         cmdline_fixed_string_t csum;
4252         cmdline_fixed_string_t parse;
4253         cmdline_fixed_string_t onoff;
4254         portid_t port_id;
4255 };
4256
4257 static void
4258 cmd_csum_tunnel_parsed(void *parsed_result,
4259                        __attribute__((unused)) struct cmdline *cl,
4260                        __attribute__((unused)) void *data)
4261 {
4262         struct cmd_csum_tunnel_result *res = parsed_result;
4263
4264         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4265                 return;
4266
4267         if (!strcmp(res->onoff, "on"))
4268                 ports[res->port_id].parse_tunnel = 1;
4269         else
4270                 ports[res->port_id].parse_tunnel = 0;
4271
4272         csum_show(res->port_id);
4273 }
4274
4275 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4276         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4277                                 csum, "csum");
4278 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4279         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4280                                 parse, "parse_tunnel");
4281 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4282         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4283                                 onoff, "on#off");
4284 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4285         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4286                                 port_id, UINT16);
4287
4288 cmdline_parse_inst_t cmd_csum_tunnel = {
4289         .f = cmd_csum_tunnel_parsed,
4290         .data = NULL,
4291         .help_str = "csum parse_tunnel on|off <port_id>: "
4292                 "Enable/Disable parsing of tunnels for csum engine",
4293         .tokens = {
4294                 (void *)&cmd_csum_tunnel_csum,
4295                 (void *)&cmd_csum_tunnel_parse,
4296                 (void *)&cmd_csum_tunnel_onoff,
4297                 (void *)&cmd_csum_tunnel_portid,
4298                 NULL,
4299         },
4300 };
4301
4302 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4303 struct cmd_tso_set_result {
4304         cmdline_fixed_string_t tso;
4305         cmdline_fixed_string_t mode;
4306         uint16_t tso_segsz;
4307         portid_t port_id;
4308 };
4309
4310 static void
4311 cmd_tso_set_parsed(void *parsed_result,
4312                        __attribute__((unused)) struct cmdline *cl,
4313                        __attribute__((unused)) void *data)
4314 {
4315         struct cmd_tso_set_result *res = parsed_result;
4316         struct rte_eth_dev_info dev_info;
4317
4318         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4319                 return;
4320         if (!port_is_stopped(res->port_id)) {
4321                 printf("Please stop port %d first\n", res->port_id);
4322                 return;
4323         }
4324
4325         if (!strcmp(res->mode, "set"))
4326                 ports[res->port_id].tso_segsz = res->tso_segsz;
4327
4328         rte_eth_dev_info_get(res->port_id, &dev_info);
4329         if ((ports[res->port_id].tso_segsz != 0) &&
4330                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4331                 printf("Error: TSO is not supported by port %d\n",
4332                        res->port_id);
4333                 return;
4334         }
4335
4336         if (ports[res->port_id].tso_segsz == 0) {
4337                 ports[res->port_id].dev_conf.txmode.offloads &=
4338                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4339                 printf("TSO for non-tunneled packets is disabled\n");
4340         } else {
4341                 ports[res->port_id].dev_conf.txmode.offloads |=
4342                                                 DEV_TX_OFFLOAD_TCP_TSO;
4343                 printf("TSO segment size for non-tunneled packets is %d\n",
4344                         ports[res->port_id].tso_segsz);
4345         }
4346
4347         /* display warnings if configuration is not supported by the NIC */
4348         rte_eth_dev_info_get(res->port_id, &dev_info);
4349         if ((ports[res->port_id].tso_segsz != 0) &&
4350                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4351                 printf("Warning: TSO enabled but not "
4352                         "supported by port %d\n", res->port_id);
4353         }
4354
4355         cmd_reconfig_device_queue(res->port_id, 1, 1);
4356 }
4357
4358 cmdline_parse_token_string_t cmd_tso_set_tso =
4359         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4360                                 tso, "tso");
4361 cmdline_parse_token_string_t cmd_tso_set_mode =
4362         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4363                                 mode, "set");
4364 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4365         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4366                                 tso_segsz, UINT16);
4367 cmdline_parse_token_num_t cmd_tso_set_portid =
4368         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4369                                 port_id, UINT16);
4370
4371 cmdline_parse_inst_t cmd_tso_set = {
4372         .f = cmd_tso_set_parsed,
4373         .data = NULL,
4374         .help_str = "tso set <tso_segsz> <port_id>: "
4375                 "Set TSO segment size of non-tunneled packets for csum engine "
4376                 "(0 to disable)",
4377         .tokens = {
4378                 (void *)&cmd_tso_set_tso,
4379                 (void *)&cmd_tso_set_mode,
4380                 (void *)&cmd_tso_set_tso_segsz,
4381                 (void *)&cmd_tso_set_portid,
4382                 NULL,
4383         },
4384 };
4385
4386 cmdline_parse_token_string_t cmd_tso_show_mode =
4387         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4388                                 mode, "show");
4389
4390
4391 cmdline_parse_inst_t cmd_tso_show = {
4392         .f = cmd_tso_set_parsed,
4393         .data = NULL,
4394         .help_str = "tso show <port_id>: "
4395                 "Show TSO segment size of non-tunneled packets for csum engine",
4396         .tokens = {
4397                 (void *)&cmd_tso_set_tso,
4398                 (void *)&cmd_tso_show_mode,
4399                 (void *)&cmd_tso_set_portid,
4400                 NULL,
4401         },
4402 };
4403
4404 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4405 struct cmd_tunnel_tso_set_result {
4406         cmdline_fixed_string_t tso;
4407         cmdline_fixed_string_t mode;
4408         uint16_t tso_segsz;
4409         portid_t port_id;
4410 };
4411
4412 static struct rte_eth_dev_info
4413 check_tunnel_tso_nic_support(portid_t port_id)
4414 {
4415         struct rte_eth_dev_info dev_info;
4416
4417         rte_eth_dev_info_get(port_id, &dev_info);
4418         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4419                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4420                        "not enabled for port %d\n", port_id);
4421         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4422                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4423                        "not enabled for port %d\n", port_id);
4424         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4425                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4426                        "not enabled for port %d\n", port_id);
4427         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4428                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4429                        "not enabled for port %d\n", port_id);
4430         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4431                 printf("Warning: IP TUNNEL TSO not supported therefore "
4432                        "not enabled for port %d\n", port_id);
4433         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4434                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4435                        "not enabled for port %d\n", port_id);
4436         return dev_info;
4437 }
4438
4439 static void
4440 cmd_tunnel_tso_set_parsed(void *parsed_result,
4441                           __attribute__((unused)) struct cmdline *cl,
4442                           __attribute__((unused)) void *data)
4443 {
4444         struct cmd_tunnel_tso_set_result *res = parsed_result;
4445         struct rte_eth_dev_info dev_info;
4446
4447         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4448                 return;
4449         if (!port_is_stopped(res->port_id)) {
4450                 printf("Please stop port %d first\n", res->port_id);
4451                 return;
4452         }
4453
4454         if (!strcmp(res->mode, "set"))
4455                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4456
4457         dev_info = check_tunnel_tso_nic_support(res->port_id);
4458         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4459                 ports[res->port_id].dev_conf.txmode.offloads &=
4460                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4461                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4462                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4463                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4464                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4465                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4466                 printf("TSO for tunneled packets is disabled\n");
4467         } else {
4468                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4469                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4470                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4471                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4472                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4473                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4474
4475                 ports[res->port_id].dev_conf.txmode.offloads |=
4476                         (tso_offloads & dev_info.tx_offload_capa);
4477                 printf("TSO segment size for tunneled packets is %d\n",
4478                         ports[res->port_id].tunnel_tso_segsz);
4479
4480                 /* Below conditions are needed to make it work:
4481                  * (1) tunnel TSO is supported by the NIC;
4482                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4483                  * are recognized;
4484                  * (3) for tunneled pkts with outer L3 of IPv4,
4485                  * "csum set outer-ip" must be set to hw, because after tso,
4486                  * total_len of outer IP header is changed, and the checksum
4487                  * of outer IP header calculated by sw should be wrong; that
4488                  * is not necessary for IPv6 tunneled pkts because there's no
4489                  * checksum in IP header anymore.
4490                  */
4491
4492                 if (!ports[res->port_id].parse_tunnel)
4493                         printf("Warning: csum parse_tunnel must be set "
4494                                 "so that tunneled packets are recognized\n");
4495                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4496                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4497                         printf("Warning: csum set outer-ip must be set to hw "
4498                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4499         }
4500
4501         cmd_reconfig_device_queue(res->port_id, 1, 1);
4502 }
4503
4504 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4505         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4506                                 tso, "tunnel_tso");
4507 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4508         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4509                                 mode, "set");
4510 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4511         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4512                                 tso_segsz, UINT16);
4513 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4514         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4515                                 port_id, UINT16);
4516
4517 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4518         .f = cmd_tunnel_tso_set_parsed,
4519         .data = NULL,
4520         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4521                 "Set TSO segment size of tunneled packets for csum engine "
4522                 "(0 to disable)",
4523         .tokens = {
4524                 (void *)&cmd_tunnel_tso_set_tso,
4525                 (void *)&cmd_tunnel_tso_set_mode,
4526                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4527                 (void *)&cmd_tunnel_tso_set_portid,
4528                 NULL,
4529         },
4530 };
4531
4532 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4533         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4534                                 mode, "show");
4535
4536
4537 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4538         .f = cmd_tunnel_tso_set_parsed,
4539         .data = NULL,
4540         .help_str = "tunnel_tso show <port_id> "
4541                 "Show TSO segment size of tunneled packets for csum engine",
4542         .tokens = {
4543                 (void *)&cmd_tunnel_tso_set_tso,
4544                 (void *)&cmd_tunnel_tso_show_mode,
4545                 (void *)&cmd_tunnel_tso_set_portid,
4546                 NULL,
4547         },
4548 };
4549
4550 /* *** SET GRO FOR A PORT *** */
4551 struct cmd_gro_enable_result {
4552         cmdline_fixed_string_t cmd_set;
4553         cmdline_fixed_string_t cmd_port;
4554         cmdline_fixed_string_t cmd_keyword;
4555         cmdline_fixed_string_t cmd_onoff;
4556         portid_t cmd_pid;
4557 };
4558
4559 static void
4560 cmd_gro_enable_parsed(void *parsed_result,
4561                 __attribute__((unused)) struct cmdline *cl,
4562                 __attribute__((unused)) void *data)
4563 {
4564         struct cmd_gro_enable_result *res;
4565
4566         res = parsed_result;
4567         if (!strcmp(res->cmd_keyword, "gro"))
4568                 setup_gro(res->cmd_onoff, res->cmd_pid);
4569 }
4570
4571 cmdline_parse_token_string_t cmd_gro_enable_set =
4572         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4573                         cmd_set, "set");
4574 cmdline_parse_token_string_t cmd_gro_enable_port =
4575         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4576                         cmd_keyword, "port");
4577 cmdline_parse_token_num_t cmd_gro_enable_pid =
4578         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4579                         cmd_pid, UINT16);
4580 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4581         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4582                         cmd_keyword, "gro");
4583 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4584         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4585                         cmd_onoff, "on#off");
4586
4587 cmdline_parse_inst_t cmd_gro_enable = {
4588         .f = cmd_gro_enable_parsed,
4589         .data = NULL,
4590         .help_str = "set port <port_id> gro on|off",
4591         .tokens = {
4592                 (void *)&cmd_gro_enable_set,
4593                 (void *)&cmd_gro_enable_port,
4594                 (void *)&cmd_gro_enable_pid,
4595                 (void *)&cmd_gro_enable_keyword,
4596                 (void *)&cmd_gro_enable_onoff,
4597                 NULL,
4598         },
4599 };
4600
4601 /* *** DISPLAY GRO CONFIGURATION *** */
4602 struct cmd_gro_show_result {
4603         cmdline_fixed_string_t cmd_show;
4604         cmdline_fixed_string_t cmd_port;
4605         cmdline_fixed_string_t cmd_keyword;
4606         portid_t cmd_pid;
4607 };
4608
4609 static void
4610 cmd_gro_show_parsed(void *parsed_result,
4611                 __attribute__((unused)) struct cmdline *cl,
4612                 __attribute__((unused)) void *data)
4613 {
4614         struct cmd_gro_show_result *res;
4615
4616         res = parsed_result;
4617         if (!strcmp(res->cmd_keyword, "gro"))
4618                 show_gro(res->cmd_pid);
4619 }
4620
4621 cmdline_parse_token_string_t cmd_gro_show_show =
4622         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4623                         cmd_show, "show");
4624 cmdline_parse_token_string_t cmd_gro_show_port =
4625         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4626                         cmd_port, "port");
4627 cmdline_parse_token_num_t cmd_gro_show_pid =
4628         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4629                         cmd_pid, UINT16);
4630 cmdline_parse_token_string_t cmd_gro_show_keyword =
4631         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4632                         cmd_keyword, "gro");
4633
4634 cmdline_parse_inst_t cmd_gro_show = {
4635         .f = cmd_gro_show_parsed,
4636         .data = NULL,
4637         .help_str = "show port <port_id> gro",
4638         .tokens = {
4639                 (void *)&cmd_gro_show_show,
4640                 (void *)&cmd_gro_show_port,
4641                 (void *)&cmd_gro_show_pid,
4642                 (void *)&cmd_gro_show_keyword,
4643                 NULL,
4644         },
4645 };
4646
4647 /* *** SET FLUSH CYCLES FOR GRO *** */
4648 struct cmd_gro_flush_result {
4649         cmdline_fixed_string_t cmd_set;
4650         cmdline_fixed_string_t cmd_keyword;
4651         cmdline_fixed_string_t cmd_flush;
4652         uint8_t cmd_cycles;
4653 };
4654
4655 static void
4656 cmd_gro_flush_parsed(void *parsed_result,
4657                 __attribute__((unused)) struct cmdline *cl,
4658                 __attribute__((unused)) void *data)
4659 {
4660         struct cmd_gro_flush_result *res;
4661
4662         res = parsed_result;
4663         if ((!strcmp(res->cmd_keyword, "gro")) &&
4664                         (!strcmp(res->cmd_flush, "flush")))
4665                 setup_gro_flush_cycles(res->cmd_cycles);
4666 }
4667
4668 cmdline_parse_token_string_t cmd_gro_flush_set =
4669         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4670                         cmd_set, "set");
4671 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4672         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4673                         cmd_keyword, "gro");
4674 cmdline_parse_token_string_t cmd_gro_flush_flush =
4675         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4676                         cmd_flush, "flush");
4677 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4678         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4679                         cmd_cycles, UINT8);
4680
4681 cmdline_parse_inst_t cmd_gro_flush = {
4682         .f = cmd_gro_flush_parsed,
4683         .data = NULL,
4684         .help_str = "set gro flush <cycles>",
4685         .tokens = {
4686                 (void *)&cmd_gro_flush_set,
4687                 (void *)&cmd_gro_flush_keyword,
4688                 (void *)&cmd_gro_flush_flush,
4689                 (void *)&cmd_gro_flush_cycles,
4690                 NULL,
4691         },
4692 };
4693
4694 /* *** ENABLE/DISABLE GSO *** */
4695 struct cmd_gso_enable_result {
4696         cmdline_fixed_string_t cmd_set;
4697         cmdline_fixed_string_t cmd_port;
4698         cmdline_fixed_string_t cmd_keyword;
4699         cmdline_fixed_string_t cmd_mode;
4700         portid_t cmd_pid;
4701 };
4702
4703 static void
4704 cmd_gso_enable_parsed(void *parsed_result,
4705                 __attribute__((unused)) struct cmdline *cl,
4706                 __attribute__((unused)) void *data)
4707 {
4708         struct cmd_gso_enable_result *res;
4709
4710         res = parsed_result;
4711         if (!strcmp(res->cmd_keyword, "gso"))
4712                 setup_gso(res->cmd_mode, res->cmd_pid);
4713 }
4714
4715 cmdline_parse_token_string_t cmd_gso_enable_set =
4716         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4717                         cmd_set, "set");
4718 cmdline_parse_token_string_t cmd_gso_enable_port =
4719         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4720                         cmd_port, "port");
4721 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4722         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4723                         cmd_keyword, "gso");
4724 cmdline_parse_token_string_t cmd_gso_enable_mode =
4725         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4726                         cmd_mode, "on#off");
4727 cmdline_parse_token_num_t cmd_gso_enable_pid =
4728         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4729                         cmd_pid, UINT16);
4730
4731 cmdline_parse_inst_t cmd_gso_enable = {
4732         .f = cmd_gso_enable_parsed,
4733         .data = NULL,
4734         .help_str = "set port <port_id> gso on|off",
4735         .tokens = {
4736                 (void *)&cmd_gso_enable_set,
4737                 (void *)&cmd_gso_enable_port,
4738                 (void *)&cmd_gso_enable_pid,
4739                 (void *)&cmd_gso_enable_keyword,
4740                 (void *)&cmd_gso_enable_mode,
4741                 NULL,
4742         },
4743 };
4744
4745 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4746 struct cmd_gso_size_result {
4747         cmdline_fixed_string_t cmd_set;
4748         cmdline_fixed_string_t cmd_keyword;
4749         cmdline_fixed_string_t cmd_segsz;
4750         uint16_t cmd_size;
4751 };
4752
4753 static void
4754 cmd_gso_size_parsed(void *parsed_result,
4755                        __attribute__((unused)) struct cmdline *cl,
4756                        __attribute__((unused)) void *data)
4757 {
4758         struct cmd_gso_size_result *res = parsed_result;
4759
4760         if (test_done == 0) {
4761                 printf("Before setting GSO segsz, please first"
4762                                 " stop fowarding\n");
4763                 return;
4764         }
4765
4766         if (!strcmp(res->cmd_keyword, "gso") &&
4767                         !strcmp(res->cmd_segsz, "segsz")) {
4768                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4769                         printf("gso_size should be larger than %zu."
4770                                         " Please input a legal value\n",
4771                                         RTE_GSO_SEG_SIZE_MIN);
4772                 else
4773                         gso_max_segment_size = res->cmd_size;
4774         }
4775 }
4776
4777 cmdline_parse_token_string_t cmd_gso_size_set =
4778         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4779                                 cmd_set, "set");
4780 cmdline_parse_token_string_t cmd_gso_size_keyword =
4781         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4782                                 cmd_keyword, "gso");
4783 cmdline_parse_token_string_t cmd_gso_size_segsz =
4784         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4785                                 cmd_segsz, "segsz");
4786 cmdline_parse_token_num_t cmd_gso_size_size =
4787         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4788                                 cmd_size, UINT16);
4789
4790 cmdline_parse_inst_t cmd_gso_size = {
4791         .f = cmd_gso_size_parsed,
4792         .data = NULL,
4793         .help_str = "set gso segsz <length>",
4794         .tokens = {
4795                 (void *)&cmd_gso_size_set,
4796                 (void *)&cmd_gso_size_keyword,
4797                 (void *)&cmd_gso_size_segsz,
4798                 (void *)&cmd_gso_size_size,
4799                 NULL,
4800         },
4801 };
4802
4803 /* *** SHOW GSO CONFIGURATION *** */
4804 struct cmd_gso_show_result {
4805         cmdline_fixed_string_t cmd_show;
4806         cmdline_fixed_string_t cmd_port;
4807         cmdline_fixed_string_t cmd_keyword;
4808         portid_t cmd_pid;
4809 };
4810
4811 static void
4812 cmd_gso_show_parsed(void *parsed_result,
4813                        __attribute__((unused)) struct cmdline *cl,
4814                        __attribute__((unused)) void *data)
4815 {
4816         struct cmd_gso_show_result *res = parsed_result;
4817
4818         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4819                 printf("invalid port id %u\n", res->cmd_pid);
4820                 return;
4821         }
4822         if (!strcmp(res->cmd_keyword, "gso")) {
4823                 if (gso_ports[res->cmd_pid].enable) {
4824                         printf("Max GSO'd packet size: %uB\n"
4825                                         "Supported GSO types: TCP/IPv4, "
4826                                         "UDP/IPv4, VxLAN with inner "
4827                                         "TCP/IPv4 packet, GRE with inner "
4828                                         "TCP/IPv4 packet\n",
4829                                         gso_max_segment_size);
4830                 } else
4831                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4832         }
4833 }
4834
4835 cmdline_parse_token_string_t cmd_gso_show_show =
4836 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4837                 cmd_show, "show");
4838 cmdline_parse_token_string_t cmd_gso_show_port =
4839 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4840                 cmd_port, "port");
4841 cmdline_parse_token_string_t cmd_gso_show_keyword =
4842         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4843                                 cmd_keyword, "gso");
4844 cmdline_parse_token_num_t cmd_gso_show_pid =
4845         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4846                                 cmd_pid, UINT16);
4847
4848 cmdline_parse_inst_t cmd_gso_show = {
4849         .f = cmd_gso_show_parsed,
4850         .data = NULL,
4851         .help_str = "show port <port_id> gso",
4852         .tokens = {
4853                 (void *)&cmd_gso_show_show,
4854                 (void *)&cmd_gso_show_port,
4855                 (void *)&cmd_gso_show_pid,
4856                 (void *)&cmd_gso_show_keyword,
4857                 NULL,
4858         },
4859 };
4860
4861 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4862 struct cmd_set_flush_rx {
4863         cmdline_fixed_string_t set;
4864         cmdline_fixed_string_t flush_rx;
4865         cmdline_fixed_string_t mode;
4866 };
4867
4868 static void
4869 cmd_set_flush_rx_parsed(void *parsed_result,
4870                 __attribute__((unused)) struct cmdline *cl,
4871                 __attribute__((unused)) void *data)
4872 {
4873         struct cmd_set_flush_rx *res = parsed_result;
4874         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4875 }
4876
4877 cmdline_parse_token_string_t cmd_setflushrx_set =
4878         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4879                         set, "set");
4880 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4881         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4882                         flush_rx, "flush_rx");
4883 cmdline_parse_token_string_t cmd_setflushrx_mode =
4884         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4885                         mode, "on#off");
4886
4887
4888 cmdline_parse_inst_t cmd_set_flush_rx = {
4889         .f = cmd_set_flush_rx_parsed,
4890         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4891         .data = NULL,
4892         .tokens = {
4893                 (void *)&cmd_setflushrx_set,
4894                 (void *)&cmd_setflushrx_flush_rx,
4895                 (void *)&cmd_setflushrx_mode,
4896                 NULL,
4897         },
4898 };
4899
4900 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4901 struct cmd_set_link_check {
4902         cmdline_fixed_string_t set;
4903         cmdline_fixed_string_t link_check;
4904         cmdline_fixed_string_t mode;
4905 };
4906
4907 static void
4908 cmd_set_link_check_parsed(void *parsed_result,
4909                 __attribute__((unused)) struct cmdline *cl,
4910                 __attribute__((unused)) void *data)
4911 {
4912         struct cmd_set_link_check *res = parsed_result;
4913         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4914 }
4915
4916 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4917         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4918                         set, "set");
4919 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4920         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4921                         link_check, "link_check");
4922 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4923         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4924                         mode, "on#off");
4925
4926
4927 cmdline_parse_inst_t cmd_set_link_check = {
4928         .f = cmd_set_link_check_parsed,
4929         .help_str = "set link_check on|off: Enable/Disable link status check "
4930                     "when starting/stopping a port",
4931         .data = NULL,
4932         .tokens = {
4933                 (void *)&cmd_setlinkcheck_set,
4934                 (void *)&cmd_setlinkcheck_link_check,
4935                 (void *)&cmd_setlinkcheck_mode,
4936                 NULL,
4937         },
4938 };
4939
4940 /* *** SET NIC BYPASS MODE *** */
4941 struct cmd_set_bypass_mode_result {
4942         cmdline_fixed_string_t set;
4943         cmdline_fixed_string_t bypass;
4944         cmdline_fixed_string_t mode;
4945         cmdline_fixed_string_t value;
4946         portid_t port_id;
4947 };
4948
4949 static void
4950 cmd_set_bypass_mode_parsed(void *parsed_result,
4951                 __attribute__((unused)) struct cmdline *cl,
4952                 __attribute__((unused)) void *data)
4953 {
4954         struct cmd_set_bypass_mode_result *res = parsed_result;
4955         portid_t port_id = res->port_id;
4956         int32_t rc = -EINVAL;
4957
4958 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4959         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4960
4961         if (!strcmp(res->value, "bypass"))
4962                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4963         else if (!strcmp(res->value, "isolate"))
4964                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4965         else
4966                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4967
4968         /* Set the bypass mode for the relevant port. */
4969         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4970 #endif
4971         if (rc != 0)
4972                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4973 }
4974
4975 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4976         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4977                         set, "set");
4978 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4979         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4980                         bypass, "bypass");
4981 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4982         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4983                         mode, "mode");
4984 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4985         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4986                         value, "normal#bypass#isolate");
4987 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4988         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4989                                 port_id, UINT16);
4990
4991 cmdline_parse_inst_t cmd_set_bypass_mode = {
4992         .f = cmd_set_bypass_mode_parsed,
4993         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4994                     "Set the NIC bypass mode for port_id",
4995         .data = NULL,
4996         .tokens = {
4997                 (void *)&cmd_setbypass_mode_set,
4998                 (void *)&cmd_setbypass_mode_bypass,
4999                 (void *)&cmd_setbypass_mode_mode,
5000                 (void *)&cmd_setbypass_mode_value,
5001                 (void *)&cmd_setbypass_mode_port,
5002                 NULL,
5003         },
5004 };
5005
5006 /* *** SET NIC BYPASS EVENT *** */
5007 struct cmd_set_bypass_event_result {
5008         cmdline_fixed_string_t set;
5009         cmdline_fixed_string_t bypass;
5010         cmdline_fixed_string_t event;
5011         cmdline_fixed_string_t event_value;
5012         cmdline_fixed_string_t mode;
5013         cmdline_fixed_string_t mode_value;
5014         portid_t port_id;
5015 };
5016
5017 static void
5018 cmd_set_bypass_event_parsed(void *parsed_result,
5019                 __attribute__((unused)) struct cmdline *cl,
5020                 __attribute__((unused)) void *data)
5021 {
5022         int32_t rc = -EINVAL;
5023         struct cmd_set_bypass_event_result *res = parsed_result;
5024         portid_t port_id = res->port_id;
5025
5026 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5027         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5028         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5029
5030         if (!strcmp(res->event_value, "timeout"))
5031                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5032         else if (!strcmp(res->event_value, "os_on"))
5033                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5034         else if (!strcmp(res->event_value, "os_off"))
5035                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5036         else if (!strcmp(res->event_value, "power_on"))
5037                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5038         else if (!strcmp(res->event_value, "power_off"))
5039                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5040         else
5041                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5042
5043         if (!strcmp(res->mode_value, "bypass"))
5044                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5045         else if (!strcmp(res->mode_value, "isolate"))
5046                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5047         else
5048                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5049
5050         /* Set the watchdog timeout. */
5051         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5052
5053                 rc = -EINVAL;
5054                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5055                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5056                                                            bypass_timeout);
5057                 }
5058                 if (rc != 0) {
5059                         printf("Failed to set timeout value %u "
5060                         "for port %d, errto code: %d.\n",
5061                         bypass_timeout, port_id, rc);
5062                 }
5063         }
5064
5065         /* Set the bypass event to transition to bypass mode. */
5066         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5067                                               bypass_mode);
5068 #endif
5069
5070         if (rc != 0)
5071                 printf("\t Failed to set bypass event for port = %d.\n",
5072                        port_id);
5073 }
5074
5075 cmdline_parse_token_string_t cmd_setbypass_event_set =
5076         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5077                         set, "set");
5078 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5079         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5080                         bypass, "bypass");
5081 cmdline_parse_token_string_t cmd_setbypass_event_event =
5082         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5083                         event, "event");
5084 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5085         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5086                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5087 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5088         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5089                         mode, "mode");
5090 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5091         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5092                         mode_value, "normal#bypass#isolate");
5093 cmdline_parse_token_num_t cmd_setbypass_event_port =
5094         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5095                                 port_id, UINT16);
5096
5097 cmdline_parse_inst_t cmd_set_bypass_event = {
5098         .f = cmd_set_bypass_event_parsed,
5099         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5100                 "power_off mode normal|bypass|isolate <port_id>: "
5101                 "Set the NIC bypass event mode for port_id",
5102         .data = NULL,
5103         .tokens = {
5104                 (void *)&cmd_setbypass_event_set,
5105                 (void *)&cmd_setbypass_event_bypass,
5106                 (void *)&cmd_setbypass_event_event,
5107                 (void *)&cmd_setbypass_event_event_value,
5108                 (void *)&cmd_setbypass_event_mode,
5109                 (void *)&cmd_setbypass_event_mode_value,
5110                 (void *)&cmd_setbypass_event_port,
5111                 NULL,
5112         },
5113 };
5114
5115
5116 /* *** SET NIC BYPASS TIMEOUT *** */
5117 struct cmd_set_bypass_timeout_result {
5118         cmdline_fixed_string_t set;
5119         cmdline_fixed_string_t bypass;
5120         cmdline_fixed_string_t timeout;
5121         cmdline_fixed_string_t value;
5122 };
5123
5124 static void
5125 cmd_set_bypass_timeout_parsed(void *parsed_result,
5126                 __attribute__((unused)) struct cmdline *cl,
5127                 __attribute__((unused)) void *data)
5128 {
5129         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5130
5131 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5132         if (!strcmp(res->value, "1.5"))
5133                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5134         else if (!strcmp(res->value, "2"))
5135                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5136         else if (!strcmp(res->value, "3"))
5137                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5138         else if (!strcmp(res->value, "4"))
5139                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5140         else if (!strcmp(res->value, "8"))
5141                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5142         else if (!strcmp(res->value, "16"))
5143                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5144         else if (!strcmp(res->value, "32"))
5145                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5146         else
5147                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5148 #endif
5149 }
5150
5151 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5152         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5153                         set, "set");
5154 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5156                         bypass, "bypass");
5157 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5158         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5159                         timeout, "timeout");
5160 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5161         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5162                         value, "0#1.5#2#3#4#8#16#32");
5163
5164 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5165         .f = cmd_set_bypass_timeout_parsed,
5166         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5167                 "Set the NIC bypass watchdog timeout in seconds",
5168         .data = NULL,
5169         .tokens = {
5170                 (void *)&cmd_setbypass_timeout_set,
5171                 (void *)&cmd_setbypass_timeout_bypass,
5172                 (void *)&cmd_setbypass_timeout_timeout,
5173                 (void *)&cmd_setbypass_timeout_value,
5174                 NULL,
5175         },
5176 };
5177
5178 /* *** SHOW NIC BYPASS MODE *** */
5179 struct cmd_show_bypass_config_result {
5180         cmdline_fixed_string_t show;
5181         cmdline_fixed_string_t bypass;
5182         cmdline_fixed_string_t config;
5183         portid_t port_id;
5184 };
5185
5186 static void
5187 cmd_show_bypass_config_parsed(void *parsed_result,
5188                 __attribute__((unused)) struct cmdline *cl,
5189                 __attribute__((unused)) void *data)
5190 {
5191         struct cmd_show_bypass_config_result *res = parsed_result;
5192         portid_t port_id = res->port_id;
5193         int rc = -EINVAL;
5194 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5195         uint32_t event_mode;
5196         uint32_t bypass_mode;
5197         uint32_t timeout = bypass_timeout;
5198         int i;
5199
5200         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5201                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5202         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5203                 {"UNKNOWN", "normal", "bypass", "isolate"};
5204         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5205                 "NONE",
5206                 "OS/board on",
5207                 "power supply on",
5208                 "OS/board off",
5209                 "power supply off",
5210                 "timeout"};
5211         int num_events = (sizeof events) / (sizeof events[0]);
5212
5213         /* Display the bypass mode.*/
5214         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5215                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5216                 return;
5217         }
5218         else {
5219                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5220                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5221
5222                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5223         }
5224
5225         /* Display the bypass timeout.*/
5226         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5227                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5228
5229         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5230
5231         /* Display the bypass events and associated modes. */
5232         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5233
5234                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5235                         printf("\tFailed to get bypass mode for event = %s\n",
5236                                 events[i]);
5237                 } else {
5238                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5239                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5240
5241                         printf("\tbypass event: %-16s = %s\n", events[i],
5242                                 modes[event_mode]);
5243                 }
5244         }
5245 #endif
5246         if (rc != 0)
5247                 printf("\tFailed to get bypass configuration for port = %d\n",
5248                        port_id);
5249 }
5250
5251 cmdline_parse_token_string_t cmd_showbypass_config_show =
5252         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5253                         show, "show");
5254 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5255         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5256                         bypass, "bypass");
5257 cmdline_parse_token_string_t cmd_showbypass_config_config =
5258         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5259                         config, "config");
5260 cmdline_parse_token_num_t cmd_showbypass_config_port =
5261         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5262                                 port_id, UINT16);
5263
5264 cmdline_parse_inst_t cmd_show_bypass_config = {
5265         .f = cmd_show_bypass_config_parsed,
5266         .help_str = "show bypass config <port_id>: "
5267                     "Show the NIC bypass config for port_id",
5268         .data = NULL,
5269         .tokens = {
5270                 (void *)&cmd_showbypass_config_show,
5271                 (void *)&cmd_showbypass_config_bypass,
5272                 (void *)&cmd_showbypass_config_config,
5273                 (void *)&cmd_showbypass_config_port,
5274                 NULL,
5275         },
5276 };
5277
5278 #ifdef RTE_LIBRTE_PMD_BOND
5279 /* *** SET BONDING MODE *** */
5280 struct cmd_set_bonding_mode_result {
5281         cmdline_fixed_string_t set;
5282         cmdline_fixed_string_t bonding;
5283         cmdline_fixed_string_t mode;
5284         uint8_t value;
5285         portid_t port_id;
5286 };
5287
5288 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5289                 __attribute__((unused))  struct cmdline *cl,
5290                 __attribute__((unused)) void *data)
5291 {
5292         struct cmd_set_bonding_mode_result *res = parsed_result;
5293         portid_t port_id = res->port_id;
5294
5295         /* Set the bonding mode for the relevant port. */
5296         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5297                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5298 }
5299
5300 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5301 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5302                 set, "set");
5303 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5304 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5305                 bonding, "bonding");
5306 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5307 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5308                 mode, "mode");
5309 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5310 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5311                 value, UINT8);
5312 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5313 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5314                 port_id, UINT16);
5315
5316 cmdline_parse_inst_t cmd_set_bonding_mode = {
5317                 .f = cmd_set_bonding_mode_parsed,
5318                 .help_str = "set bonding mode <mode_value> <port_id>: "
5319                         "Set the bonding mode for port_id",
5320                 .data = NULL,
5321                 .tokens = {
5322                                 (void *) &cmd_setbonding_mode_set,
5323                                 (void *) &cmd_setbonding_mode_bonding,
5324                                 (void *) &cmd_setbonding_mode_mode,
5325                                 (void *) &cmd_setbonding_mode_value,
5326                                 (void *) &cmd_setbonding_mode_port,
5327                                 NULL
5328                 }
5329 };
5330
5331 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5332 struct cmd_set_bonding_lacp_dedicated_queues_result {
5333         cmdline_fixed_string_t set;
5334         cmdline_fixed_string_t bonding;
5335         cmdline_fixed_string_t lacp;
5336         cmdline_fixed_string_t dedicated_queues;
5337         portid_t port_id;
5338         cmdline_fixed_string_t mode;
5339 };
5340
5341 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5342                 __attribute__((unused))  struct cmdline *cl,
5343                 __attribute__((unused)) void *data)
5344 {
5345         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5346         portid_t port_id = res->port_id;
5347         struct rte_port *port;
5348
5349         port = &ports[port_id];
5350
5351         /** Check if the port is not started **/
5352         if (port->port_status != RTE_PORT_STOPPED) {
5353                 printf("Please stop port %d first\n", port_id);
5354                 return;
5355         }
5356
5357         if (!strcmp(res->mode, "enable")) {
5358                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5359                         printf("Dedicate queues for LACP control packets"
5360                                         " enabled\n");
5361                 else
5362                         printf("Enabling dedicate queues for LACP control "
5363                                         "packets on port %d failed\n", port_id);
5364         } else if (!strcmp(res->mode, "disable")) {
5365                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5366                         printf("Dedicated queues for LACP control packets "
5367                                         "disabled\n");
5368                 else
5369                         printf("Disabling dedicated queues for LACP control "
5370                                         "traffic on port %d failed\n", port_id);
5371         }
5372 }
5373
5374 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5375 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5376                 set, "set");
5377 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5378 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5379                 bonding, "bonding");
5380 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5381 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5382                 lacp, "lacp");
5383 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5384 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5385                 dedicated_queues, "dedicated_queues");
5386 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5387 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5388                 port_id, UINT16);
5389 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5390 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5391                 mode, "enable#disable");
5392
5393 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5394                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5395                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5396                         "enable|disable: "
5397                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5398                 .data = NULL,
5399                 .tokens = {
5400                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5401                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5402                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5403                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5404                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5405                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5406                         NULL
5407                 }
5408 };
5409
5410 /* *** SET BALANCE XMIT POLICY *** */
5411 struct cmd_set_bonding_balance_xmit_policy_result {
5412         cmdline_fixed_string_t set;
5413         cmdline_fixed_string_t bonding;
5414         cmdline_fixed_string_t balance_xmit_policy;
5415         portid_t port_id;
5416         cmdline_fixed_string_t policy;
5417 };
5418
5419 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5420                 __attribute__((unused))  struct cmdline *cl,
5421                 __attribute__((unused)) void *data)
5422 {
5423         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5424         portid_t port_id = res->port_id;
5425         uint8_t policy;
5426
5427         if (!strcmp(res->policy, "l2")) {
5428                 policy = BALANCE_XMIT_POLICY_LAYER2;
5429         } else if (!strcmp(res->policy, "l23")) {
5430                 policy = BALANCE_XMIT_POLICY_LAYER23;
5431         } else if (!strcmp(res->policy, "l34")) {
5432                 policy = BALANCE_XMIT_POLICY_LAYER34;
5433         } else {
5434                 printf("\t Invalid xmit policy selection");
5435                 return;
5436         }
5437
5438         /* Set the bonding mode for the relevant port. */
5439         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5440                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5441                                 port_id);
5442         }
5443 }
5444
5445 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5446 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5447                 set, "set");
5448 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5449 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5450                 bonding, "bonding");
5451 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5452 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5453                 balance_xmit_policy, "balance_xmit_policy");
5454 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5455 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5456                 port_id, UINT16);
5457 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5458 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5459                 policy, "l2#l23#l34");
5460
5461 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5462                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5463                 .help_str = "set bonding balance_xmit_policy <port_id> "
5464                         "l2|l23|l34: "
5465                         "Set the bonding balance_xmit_policy for port_id",
5466                 .data = NULL,
5467                 .tokens = {
5468                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5469                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5470                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5471                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5472                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5473                                 NULL
5474                 }
5475 };
5476
5477 /* *** SHOW NIC BONDING CONFIGURATION *** */
5478 struct cmd_show_bonding_config_result {
5479         cmdline_fixed_string_t show;
5480         cmdline_fixed_string_t bonding;
5481         cmdline_fixed_string_t config;
5482         portid_t port_id;
5483 };
5484
5485 static void cmd_show_bonding_config_parsed(void *parsed_result,
5486                 __attribute__((unused))  struct cmdline *cl,
5487                 __attribute__((unused)) void *data)
5488 {
5489         struct cmd_show_bonding_config_result *res = parsed_result;
5490         int bonding_mode, agg_mode;
5491         portid_t slaves[RTE_MAX_ETHPORTS];
5492         int num_slaves, num_active_slaves;
5493         int primary_id;
5494         int i;
5495         portid_t port_id = res->port_id;
5496
5497         /* Display the bonding mode.*/
5498         bonding_mode = rte_eth_bond_mode_get(port_id);
5499         if (bonding_mode < 0) {
5500                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5501                 return;
5502         } else
5503                 printf("\tBonding mode: %d\n", bonding_mode);
5504
5505         if (bonding_mode == BONDING_MODE_BALANCE) {
5506                 int balance_xmit_policy;
5507
5508                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5509                 if (balance_xmit_policy < 0) {
5510                         printf("\tFailed to get balance xmit policy for port = %d\n",
5511                                         port_id);
5512                         return;
5513                 } else {
5514                         printf("\tBalance Xmit Policy: ");
5515
5516                         switch (balance_xmit_policy) {
5517                         case BALANCE_XMIT_POLICY_LAYER2:
5518                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5519                                 break;
5520                         case BALANCE_XMIT_POLICY_LAYER23:
5521                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5522                                 break;
5523                         case BALANCE_XMIT_POLICY_LAYER34:
5524                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5525                                 break;
5526                         }
5527                         printf("\n");
5528                 }
5529         }
5530
5531         if (bonding_mode == BONDING_MODE_8023AD) {
5532                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5533                 printf("\tIEEE802.3AD Aggregator Mode: ");
5534                 switch (agg_mode) {
5535                 case AGG_BANDWIDTH:
5536                         printf("bandwidth");
5537                         break;
5538                 case AGG_STABLE:
5539                         printf("stable");
5540                         break;
5541                 case AGG_COUNT:
5542                         printf("count");
5543                         break;
5544                 }
5545                 printf("\n");
5546         }
5547
5548         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5549
5550         if (num_slaves < 0) {
5551                 printf("\tFailed to get slave list for port = %d\n", port_id);
5552                 return;
5553         }
5554         if (num_slaves > 0) {
5555                 printf("\tSlaves (%d): [", num_slaves);
5556                 for (i = 0; i < num_slaves - 1; i++)
5557                         printf("%d ", slaves[i]);
5558
5559                 printf("%d]\n", slaves[num_slaves - 1]);
5560         } else {
5561                 printf("\tSlaves: []\n");
5562
5563         }
5564
5565         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5566                         RTE_MAX_ETHPORTS);
5567
5568         if (num_active_slaves < 0) {
5569                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5570                 return;
5571         }
5572         if (num_active_slaves > 0) {
5573                 printf("\tActive Slaves (%d): [", num_active_slaves);
5574                 for (i = 0; i < num_active_slaves - 1; i++)
5575                         printf("%d ", slaves[i]);
5576
5577                 printf("%d]\n", slaves[num_active_slaves - 1]);
5578
5579         } else {
5580                 printf("\tActive Slaves: []\n");
5581
5582         }
5583
5584         primary_id = rte_eth_bond_primary_get(port_id);
5585         if (primary_id < 0) {
5586                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5587                 return;
5588         } else
5589                 printf("\tPrimary: [%d]\n", primary_id);
5590
5591 }
5592
5593 cmdline_parse_token_string_t cmd_showbonding_config_show =
5594 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5595                 show, "show");
5596 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5597 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5598                 bonding, "bonding");
5599 cmdline_parse_token_string_t cmd_showbonding_config_config =
5600 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5601                 config, "config");
5602 cmdline_parse_token_num_t cmd_showbonding_config_port =
5603 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5604                 port_id, UINT16);
5605
5606 cmdline_parse_inst_t cmd_show_bonding_config = {
5607                 .f = cmd_show_bonding_config_parsed,
5608                 .help_str = "show bonding config <port_id>: "
5609                         "Show the bonding config for port_id",
5610                 .data = NULL,
5611                 .tokens = {
5612                                 (void *)&cmd_showbonding_config_show,
5613                                 (void *)&cmd_showbonding_config_bonding,
5614                                 (void *)&cmd_showbonding_config_config,
5615                                 (void *)&cmd_showbonding_config_port,
5616                                 NULL
5617                 }
5618 };
5619
5620 /* *** SET BONDING PRIMARY *** */
5621 struct cmd_set_bonding_primary_result {
5622         cmdline_fixed_string_t set;
5623         cmdline_fixed_string_t bonding;
5624         cmdline_fixed_string_t primary;
5625         portid_t slave_id;
5626         portid_t port_id;
5627 };
5628
5629 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5630                 __attribute__((unused))  struct cmdline *cl,
5631                 __attribute__((unused)) void *data)
5632 {
5633         struct cmd_set_bonding_primary_result *res = parsed_result;
5634         portid_t master_port_id = res->port_id;
5635         portid_t slave_port_id = res->slave_id;
5636
5637         /* Set the primary slave for a bonded device. */
5638         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5639                 printf("\t Failed to set primary slave for port = %d.\n",
5640                                 master_port_id);
5641                 return;
5642         }
5643         init_port_config();
5644 }
5645
5646 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5647 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5648                 set, "set");
5649 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5650 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5651                 bonding, "bonding");
5652 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5653 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5654                 primary, "primary");
5655 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5656 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5657                 slave_id, UINT16);
5658 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5659 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5660                 port_id, UINT16);
5661
5662 cmdline_parse_inst_t cmd_set_bonding_primary = {
5663                 .f = cmd_set_bonding_primary_parsed,
5664                 .help_str = "set bonding primary <slave_id> <port_id>: "
5665                         "Set the primary slave for port_id",
5666                 .data = NULL,
5667                 .tokens = {
5668                                 (void *)&cmd_setbonding_primary_set,
5669                                 (void *)&cmd_setbonding_primary_bonding,
5670                                 (void *)&cmd_setbonding_primary_primary,
5671                                 (void *)&cmd_setbonding_primary_slave,
5672                                 (void *)&cmd_setbonding_primary_port,
5673                                 NULL
5674                 }
5675 };
5676
5677 /* *** ADD SLAVE *** */
5678 struct cmd_add_bonding_slave_result {
5679         cmdline_fixed_string_t add;
5680         cmdline_fixed_string_t bonding;
5681         cmdline_fixed_string_t slave;
5682         portid_t slave_id;
5683         portid_t port_id;
5684 };
5685
5686 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5687                 __attribute__((unused))  struct cmdline *cl,
5688                 __attribute__((unused)) void *data)
5689 {
5690         struct cmd_add_bonding_slave_result *res = parsed_result;
5691         portid_t master_port_id = res->port_id;
5692         portid_t slave_port_id = res->slave_id;
5693
5694         /* add the slave for a bonded device. */
5695         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5696                 printf("\t Failed to add slave %d to master port = %d.\n",
5697                                 slave_port_id, master_port_id);
5698                 return;
5699         }
5700         init_port_config();
5701         set_port_slave_flag(slave_port_id);
5702 }
5703
5704 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5705 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5706                 add, "add");
5707 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5708 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5709                 bonding, "bonding");
5710 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5711 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5712                 slave, "slave");
5713 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5714 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5715                 slave_id, UINT16);
5716 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5717 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5718                 port_id, UINT16);
5719
5720 cmdline_parse_inst_t cmd_add_bonding_slave = {
5721                 .f = cmd_add_bonding_slave_parsed,
5722                 .help_str = "add bonding slave <slave_id> <port_id>: "
5723                         "Add a slave device to a bonded device",
5724                 .data = NULL,
5725                 .tokens = {
5726                                 (void *)&cmd_addbonding_slave_add,
5727                                 (void *)&cmd_addbonding_slave_bonding,
5728                                 (void *)&cmd_addbonding_slave_slave,
5729                                 (void *)&cmd_addbonding_slave_slaveid,
5730                                 (void *)&cmd_addbonding_slave_port,
5731                                 NULL
5732                 }
5733 };
5734
5735 /* *** REMOVE SLAVE *** */
5736 struct cmd_remove_bonding_slave_result {
5737         cmdline_fixed_string_t remove;
5738         cmdline_fixed_string_t bonding;
5739         cmdline_fixed_string_t slave;
5740         portid_t slave_id;
5741         portid_t port_id;
5742 };
5743
5744 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5745                 __attribute__((unused))  struct cmdline *cl,
5746                 __attribute__((unused)) void *data)
5747 {
5748         struct cmd_remove_bonding_slave_result *res = parsed_result;
5749         portid_t master_port_id = res->port_id;
5750         portid_t slave_port_id = res->slave_id;
5751
5752         /* remove the slave from a bonded device. */
5753         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5754                 printf("\t Failed to remove slave %d from master port = %d.\n",
5755                                 slave_port_id, master_port_id);
5756                 return;
5757         }
5758         init_port_config();
5759         clear_port_slave_flag(slave_port_id);
5760 }
5761
5762 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5763                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5764                                 remove, "remove");
5765 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5766                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5767                                 bonding, "bonding");
5768 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5769                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5770                                 slave, "slave");
5771 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5772                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5773                                 slave_id, UINT16);
5774 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5775                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5776                                 port_id, UINT16);
5777
5778 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5779                 .f = cmd_remove_bonding_slave_parsed,
5780                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5781                         "Remove a slave device from a bonded device",
5782                 .data = NULL,
5783                 .tokens = {
5784                                 (void *)&cmd_removebonding_slave_remove,
5785                                 (void *)&cmd_removebonding_slave_bonding,
5786                                 (void *)&cmd_removebonding_slave_slave,
5787                                 (void *)&cmd_removebonding_slave_slaveid,
5788                                 (void *)&cmd_removebonding_slave_port,
5789                                 NULL
5790                 }
5791 };
5792
5793 /* *** CREATE BONDED DEVICE *** */
5794 struct cmd_create_bonded_device_result {
5795         cmdline_fixed_string_t create;
5796         cmdline_fixed_string_t bonded;
5797         cmdline_fixed_string_t device;
5798         uint8_t mode;
5799         uint8_t socket;
5800 };
5801
5802 static int bond_dev_num = 0;
5803
5804 static void cmd_create_bonded_device_parsed(void *parsed_result,
5805                 __attribute__((unused))  struct cmdline *cl,
5806                 __attribute__((unused)) void *data)
5807 {
5808         struct cmd_create_bonded_device_result *res = parsed_result;
5809         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5810         int port_id;
5811
5812         if (test_done == 0) {
5813                 printf("Please stop forwarding first\n");
5814                 return;
5815         }
5816
5817         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5818                         bond_dev_num++);
5819
5820         /* Create a new bonded device. */
5821         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5822         if (port_id < 0) {
5823                 printf("\t Failed to create bonded device.\n");
5824                 return;
5825         } else {
5826                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5827                                 port_id);
5828
5829                 /* Update number of ports */
5830                 nb_ports = rte_eth_dev_count_avail();
5831                 reconfig(port_id, res->socket);
5832                 rte_eth_promiscuous_enable(port_id);
5833         }
5834
5835 }
5836
5837 cmdline_parse_token_string_t cmd_createbonded_device_create =
5838                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5839                                 create, "create");
5840 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5841                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5842                                 bonded, "bonded");
5843 cmdline_parse_token_string_t cmd_createbonded_device_device =
5844                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5845                                 device, "device");
5846 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5847                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5848                                 mode, UINT8);
5849 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5850                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5851                                 socket, UINT8);
5852
5853 cmdline_parse_inst_t cmd_create_bonded_device = {
5854                 .f = cmd_create_bonded_device_parsed,
5855                 .help_str = "create bonded device <mode> <socket>: "
5856                         "Create a new bonded device with specific bonding mode and socket",
5857                 .data = NULL,
5858                 .tokens = {
5859                                 (void *)&cmd_createbonded_device_create,
5860                                 (void *)&cmd_createbonded_device_bonded,
5861                                 (void *)&cmd_createbonded_device_device,
5862                                 (void *)&cmd_createbonded_device_mode,
5863                                 (void *)&cmd_createbonded_device_socket,
5864                                 NULL
5865                 }
5866 };
5867
5868 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5869 struct cmd_set_bond_mac_addr_result {
5870         cmdline_fixed_string_t set;
5871         cmdline_fixed_string_t bonding;
5872         cmdline_fixed_string_t mac_addr;
5873         uint16_t port_num;
5874         struct ether_addr address;
5875 };
5876
5877 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5878                 __attribute__((unused))  struct cmdline *cl,
5879                 __attribute__((unused)) void *data)
5880 {
5881         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5882         int ret;
5883
5884         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5885                 return;
5886
5887         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5888
5889         /* check the return value and print it if is < 0 */
5890         if (ret < 0)
5891                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5892 }
5893
5894 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5895                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5896 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5897                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5898                                 "bonding");
5899 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5900                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5901                                 "mac_addr");
5902 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5903                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5904                                 port_num, UINT16);
5905 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5906                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5907
5908 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5909                 .f = cmd_set_bond_mac_addr_parsed,
5910                 .data = (void *) 0,
5911                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5912                 .tokens = {
5913                                 (void *)&cmd_set_bond_mac_addr_set,
5914                                 (void *)&cmd_set_bond_mac_addr_bonding,
5915                                 (void *)&cmd_set_bond_mac_addr_mac,
5916                                 (void *)&cmd_set_bond_mac_addr_portnum,
5917                                 (void *)&cmd_set_bond_mac_addr_addr,
5918                                 NULL
5919                 }
5920 };
5921
5922
5923 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5924 struct cmd_set_bond_mon_period_result {
5925         cmdline_fixed_string_t set;
5926         cmdline_fixed_string_t bonding;
5927         cmdline_fixed_string_t mon_period;
5928         uint16_t port_num;
5929         uint32_t period_ms;
5930 };
5931
5932 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5933                 __attribute__((unused))  struct cmdline *cl,
5934                 __attribute__((unused)) void *data)
5935 {
5936         struct cmd_set_bond_mon_period_result *res = parsed_result;
5937         int ret;
5938
5939         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5940
5941         /* check the return value and print it if is < 0 */
5942         if (ret < 0)
5943                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5944 }
5945
5946 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5947                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5948                                 set, "set");
5949 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5950                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5951                                 bonding, "bonding");
5952 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5953                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5954                                 mon_period,     "mon_period");
5955 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5956                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5957                                 port_num, UINT16);
5958 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5959                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5960                                 period_ms, UINT32);
5961
5962 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5963                 .f = cmd_set_bond_mon_period_parsed,
5964                 .data = (void *) 0,
5965                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5966                 .tokens = {
5967                                 (void *)&cmd_set_bond_mon_period_set,
5968                                 (void *)&cmd_set_bond_mon_period_bonding,
5969                                 (void *)&cmd_set_bond_mon_period_mon_period,
5970                                 (void *)&cmd_set_bond_mon_period_portnum,
5971                                 (void *)&cmd_set_bond_mon_period_period_ms,
5972                                 NULL
5973                 }
5974 };
5975
5976
5977
5978 struct cmd_set_bonding_agg_mode_policy_result {
5979         cmdline_fixed_string_t set;
5980         cmdline_fixed_string_t bonding;
5981         cmdline_fixed_string_t agg_mode;
5982         uint16_t port_num;
5983         cmdline_fixed_string_t policy;
5984 };
5985
5986
5987 static void
5988 cmd_set_bonding_agg_mode(void *parsed_result,
5989                 __attribute__((unused)) struct cmdline *cl,
5990                 __attribute__((unused)) void *data)
5991 {
5992         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5993         uint8_t policy = AGG_BANDWIDTH;
5994
5995         if (!strcmp(res->policy, "bandwidth"))
5996                 policy = AGG_BANDWIDTH;
5997         else if (!strcmp(res->policy, "stable"))
5998                 policy = AGG_STABLE;
5999         else if (!strcmp(res->policy, "count"))
6000                 policy = AGG_COUNT;
6001
6002         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6003 }
6004
6005
6006 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6007         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6008                                 set, "set");
6009 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6010         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6011                                 bonding, "bonding");
6012
6013 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6014         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6015                                 agg_mode, "agg_mode");
6016
6017 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6018         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6019                                 port_num, UINT16);
6020
6021 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6022         TOKEN_STRING_INITIALIZER(
6023                         struct cmd_set_bonding_balance_xmit_policy_result,
6024                 policy, "stable#bandwidth#count");
6025
6026 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6027         .f = cmd_set_bonding_agg_mode,
6028         .data = (void *) 0,
6029         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6030         .tokens = {
6031                         (void *)&cmd_set_bonding_agg_mode_set,
6032                         (void *)&cmd_set_bonding_agg_mode_bonding,
6033                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6034                         (void *)&cmd_set_bonding_agg_mode_portnum,
6035                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6036                         NULL
6037                 }
6038 };
6039
6040
6041 #endif /* RTE_LIBRTE_PMD_BOND */
6042
6043 /* *** SET FORWARDING MODE *** */
6044 struct cmd_set_fwd_mode_result {
6045         cmdline_fixed_string_t set;
6046         cmdline_fixed_string_t fwd;
6047         cmdline_fixed_string_t mode;
6048 };
6049
6050 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6051                                     __attribute__((unused)) struct cmdline *cl,
6052                                     __attribute__((unused)) void *data)
6053 {
6054         struct cmd_set_fwd_mode_result *res = parsed_result;
6055
6056         retry_enabled = 0;
6057         set_pkt_forwarding_mode(res->mode);
6058 }
6059
6060 cmdline_parse_token_string_t cmd_setfwd_set =
6061         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6062 cmdline_parse_token_string_t cmd_setfwd_fwd =
6063         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6064 cmdline_parse_token_string_t cmd_setfwd_mode =
6065         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6066                 "" /* defined at init */);
6067
6068 cmdline_parse_inst_t cmd_set_fwd_mode = {
6069         .f = cmd_set_fwd_mode_parsed,
6070         .data = NULL,
6071         .help_str = NULL, /* defined at init */
6072         .tokens = {
6073                 (void *)&cmd_setfwd_set,
6074                 (void *)&cmd_setfwd_fwd,
6075                 (void *)&cmd_setfwd_mode,
6076                 NULL,
6077         },
6078 };
6079
6080 static void cmd_set_fwd_mode_init(void)
6081 {
6082         char *modes, *c;
6083         static char token[128];
6084         static char help[256];
6085         cmdline_parse_token_string_t *token_struct;
6086
6087         modes = list_pkt_forwarding_modes();
6088         snprintf(help, sizeof(help), "set fwd %s: "
6089                 "Set packet forwarding mode", modes);
6090         cmd_set_fwd_mode.help_str = help;
6091
6092         /* string token separator is # */
6093         for (c = token; *modes != '\0'; modes++)
6094                 if (*modes == '|')
6095                         *c++ = '#';
6096                 else
6097                         *c++ = *modes;
6098         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6099         token_struct->string_data.str = token;
6100 }
6101
6102 /* *** SET RETRY FORWARDING MODE *** */
6103 struct cmd_set_fwd_retry_mode_result {
6104         cmdline_fixed_string_t set;
6105         cmdline_fixed_string_t fwd;
6106         cmdline_fixed_string_t mode;
6107         cmdline_fixed_string_t retry;
6108 };
6109
6110 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6111                             __attribute__((unused)) struct cmdline *cl,
6112                             __attribute__((unused)) void *data)
6113 {
6114         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6115
6116         retry_enabled = 1;
6117         set_pkt_forwarding_mode(res->mode);
6118 }
6119
6120 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6121         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6122                         set, "set");
6123 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6124         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6125                         fwd, "fwd");
6126 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6127         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6128                         mode,
6129                 "" /* defined at init */);
6130 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6131         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6132                         retry, "retry");
6133
6134 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6135         .f = cmd_set_fwd_retry_mode_parsed,
6136         .data = NULL,
6137         .help_str = NULL, /* defined at init */
6138         .tokens = {
6139                 (void *)&cmd_setfwd_retry_set,
6140                 (void *)&cmd_setfwd_retry_fwd,
6141                 (void *)&cmd_setfwd_retry_mode,
6142                 (void *)&cmd_setfwd_retry_retry,
6143                 NULL,
6144         },
6145 };
6146
6147 static void cmd_set_fwd_retry_mode_init(void)
6148 {
6149         char *modes, *c;
6150         static char token[128];
6151         static char help[256];
6152         cmdline_parse_token_string_t *token_struct;
6153
6154         modes = list_pkt_forwarding_retry_modes();
6155         snprintf(help, sizeof(help), "set fwd %s retry: "
6156                 "Set packet forwarding mode with retry", modes);
6157         cmd_set_fwd_retry_mode.help_str = help;
6158
6159         /* string token separator is # */
6160         for (c = token; *modes != '\0'; modes++)
6161                 if (*modes == '|')
6162                         *c++ = '#';
6163                 else
6164                         *c++ = *modes;
6165         token_struct = (cmdline_parse_token_string_t *)
6166                 cmd_set_fwd_retry_mode.tokens[2];
6167         token_struct->string_data.str = token;
6168 }
6169
6170 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6171 struct cmd_set_burst_tx_retry_result {
6172         cmdline_fixed_string_t set;
6173         cmdline_fixed_string_t burst;
6174         cmdline_fixed_string_t tx;
6175         cmdline_fixed_string_t delay;
6176         uint32_t time;
6177         cmdline_fixed_string_t retry;
6178         uint32_t retry_num;
6179 };
6180
6181 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6182                                         __attribute__((unused)) struct cmdline *cl,
6183                                         __attribute__((unused)) void *data)
6184 {
6185         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6186
6187         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6188                 && !strcmp(res->tx, "tx")) {
6189                 if (!strcmp(res->delay, "delay"))
6190                         burst_tx_delay_time = res->time;
6191                 if (!strcmp(res->retry, "retry"))
6192                         burst_tx_retry_num = res->retry_num;
6193         }
6194
6195 }
6196
6197 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6198         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6199 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6200         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6201                                  "burst");
6202 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6203         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6204 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6205         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6206 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6207         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6208 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6209         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6210 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6211         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6212
6213 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6214         .f = cmd_set_burst_tx_retry_parsed,
6215         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6216         .tokens = {
6217                 (void *)&cmd_set_burst_tx_retry_set,
6218                 (void *)&cmd_set_burst_tx_retry_burst,
6219                 (void *)&cmd_set_burst_tx_retry_tx,
6220                 (void *)&cmd_set_burst_tx_retry_delay,
6221                 (void *)&cmd_set_burst_tx_retry_time,
6222                 (void *)&cmd_set_burst_tx_retry_retry,
6223                 (void *)&cmd_set_burst_tx_retry_retry_num,
6224                 NULL,
6225         },
6226 };
6227
6228 /* *** SET PROMISC MODE *** */
6229 struct cmd_set_promisc_mode_result {
6230         cmdline_fixed_string_t set;
6231         cmdline_fixed_string_t promisc;
6232         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6233         uint16_t port_num;               /* valid if "allports" argument == 0 */
6234         cmdline_fixed_string_t mode;
6235 };
6236
6237 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6238                                         __attribute__((unused)) struct cmdline *cl,
6239                                         void *allports)
6240 {
6241         struct cmd_set_promisc_mode_result *res = parsed_result;
6242         int enable;
6243         portid_t i;
6244
6245         if (!strcmp(res->mode, "on"))
6246                 enable = 1;
6247         else
6248                 enable = 0;
6249
6250         /* all ports */
6251         if (allports) {
6252                 RTE_ETH_FOREACH_DEV(i) {
6253                         if (enable)
6254                                 rte_eth_promiscuous_enable(i);
6255                         else
6256                                 rte_eth_promiscuous_disable(i);
6257                 }
6258         }
6259         else {
6260                 if (enable)
6261                         rte_eth_promiscuous_enable(res->port_num);
6262                 else
6263                         rte_eth_promiscuous_disable(res->port_num);
6264         }
6265 }
6266
6267 cmdline_parse_token_string_t cmd_setpromisc_set =
6268         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6269 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6270         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6271                                  "promisc");
6272 cmdline_parse_token_string_t cmd_setpromisc_portall =
6273         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6274                                  "all");
6275 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6276         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6277                               UINT16);
6278 cmdline_parse_token_string_t cmd_setpromisc_mode =
6279         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6280                                  "on#off");
6281
6282 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6283         .f = cmd_set_promisc_mode_parsed,
6284         .data = (void *)1,
6285         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6286         .tokens = {
6287                 (void *)&cmd_setpromisc_set,
6288                 (void *)&cmd_setpromisc_promisc,
6289                 (void *)&cmd_setpromisc_portall,
6290                 (void *)&cmd_setpromisc_mode,
6291                 NULL,
6292         },
6293 };
6294
6295 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6296         .f = cmd_set_promisc_mode_parsed,
6297         .data = (void *)0,
6298         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6299         .tokens = {
6300                 (void *)&cmd_setpromisc_set,
6301                 (void *)&cmd_setpromisc_promisc,
6302                 (void *)&cmd_setpromisc_portnum,
6303                 (void *)&cmd_setpromisc_mode,
6304                 NULL,
6305         },
6306 };
6307
6308 /* *** SET ALLMULTI MODE *** */
6309 struct cmd_set_allmulti_mode_result {
6310         cmdline_fixed_string_t set;
6311         cmdline_fixed_string_t allmulti;
6312         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6313         uint16_t port_num;               /* valid if "allports" argument == 0 */
6314         cmdline_fixed_string_t mode;
6315 };
6316
6317 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6318                                         __attribute__((unused)) struct cmdline *cl,
6319                                         void *allports)
6320 {
6321         struct cmd_set_allmulti_mode_result *res = parsed_result;
6322         int enable;
6323         portid_t i;
6324
6325         if (!strcmp(res->mode, "on"))
6326                 enable = 1;
6327         else
6328                 enable = 0;
6329
6330         /* all ports */
6331         if (allports) {
6332                 RTE_ETH_FOREACH_DEV(i) {
6333                         if (enable)
6334                                 rte_eth_allmulticast_enable(i);
6335                         else
6336                                 rte_eth_allmulticast_disable(i);
6337                 }
6338         }
6339         else {
6340                 if (enable)
6341                         rte_eth_allmulticast_enable(res->port_num);
6342                 else
6343                         rte_eth_allmulticast_disable(res->port_num);
6344         }
6345 }
6346
6347 cmdline_parse_token_string_t cmd_setallmulti_set =
6348         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6349 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6350         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6351                                  "allmulti");
6352 cmdline_parse_token_string_t cmd_setallmulti_portall =
6353         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6354                                  "all");
6355 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6356         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6357                               UINT16);
6358 cmdline_parse_token_string_t cmd_setallmulti_mode =
6359         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6360                                  "on#off");
6361
6362 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6363         .f = cmd_set_allmulti_mode_parsed,
6364         .data = (void *)1,
6365         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6366         .tokens = {
6367                 (void *)&cmd_setallmulti_set,
6368                 (void *)&cmd_setallmulti_allmulti,
6369                 (void *)&cmd_setallmulti_portall,
6370                 (void *)&cmd_setallmulti_mode,
6371                 NULL,
6372         },
6373 };
6374
6375 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6376         .f = cmd_set_allmulti_mode_parsed,
6377         .data = (void *)0,
6378         .help_str = "set allmulti <port_id> on|off: "
6379                 "Set allmulti mode on port_id",
6380         .tokens = {
6381                 (void *)&cmd_setallmulti_set,
6382                 (void *)&cmd_setallmulti_allmulti,
6383                 (void *)&cmd_setallmulti_portnum,
6384                 (void *)&cmd_setallmulti_mode,
6385                 NULL,
6386         },
6387 };
6388
6389 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6390 struct cmd_link_flow_ctrl_set_result {
6391         cmdline_fixed_string_t set;
6392         cmdline_fixed_string_t flow_ctrl;
6393         cmdline_fixed_string_t rx;
6394         cmdline_fixed_string_t rx_lfc_mode;
6395         cmdline_fixed_string_t tx;
6396         cmdline_fixed_string_t tx_lfc_mode;
6397         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6398         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6399         cmdline_fixed_string_t autoneg_str;
6400         cmdline_fixed_string_t autoneg;
6401         cmdline_fixed_string_t hw_str;
6402         uint32_t high_water;
6403         cmdline_fixed_string_t lw_str;
6404         uint32_t low_water;
6405         cmdline_fixed_string_t pt_str;
6406         uint16_t pause_time;
6407         cmdline_fixed_string_t xon_str;
6408         uint16_t send_xon;
6409         portid_t port_id;
6410 };
6411
6412 cmdline_parse_token_string_t cmd_lfc_set_set =
6413         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6414                                 set, "set");
6415 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6416         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6417                                 flow_ctrl, "flow_ctrl");
6418 cmdline_parse_token_string_t cmd_lfc_set_rx =
6419         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6420                                 rx, "rx");
6421 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6422         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6423                                 rx_lfc_mode, "on#off");
6424 cmdline_parse_token_string_t cmd_lfc_set_tx =
6425         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6426                                 tx, "tx");
6427 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6428         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6429                                 tx_lfc_mode, "on#off");
6430 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6431         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6432                                 hw_str, "high_water");
6433 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6434         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6435                                 high_water, UINT32);
6436 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6437         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6438                                 lw_str, "low_water");
6439 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6440         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6441                                 low_water, UINT32);
6442 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6443         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6444                                 pt_str, "pause_time");
6445 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6446         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6447                                 pause_time, UINT16);
6448 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6449         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6450                                 xon_str, "send_xon");
6451 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6452         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6453                                 send_xon, UINT16);
6454 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6455         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6456                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6457 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6458         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6459                                 mac_ctrl_frame_fwd_mode, "on#off");
6460 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6461         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6462                                 autoneg_str, "autoneg");
6463 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6464         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6465                                 autoneg, "on#off");
6466 cmdline_parse_token_num_t cmd_lfc_set_portid =
6467         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6468                                 port_id, UINT16);
6469
6470 /* forward declaration */
6471 static void
6472 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6473                               void *data);
6474
6475 cmdline_parse_inst_t cmd_link_flow_control_set = {
6476         .f = cmd_link_flow_ctrl_set_parsed,
6477         .data = NULL,
6478         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6479                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6480                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6481         .tokens = {
6482                 (void *)&cmd_lfc_set_set,
6483                 (void *)&cmd_lfc_set_flow_ctrl,
6484                 (void *)&cmd_lfc_set_rx,
6485                 (void *)&cmd_lfc_set_rx_mode,
6486                 (void *)&cmd_lfc_set_tx,
6487                 (void *)&cmd_lfc_set_tx_mode,
6488                 (void *)&cmd_lfc_set_high_water,
6489                 (void *)&cmd_lfc_set_low_water,
6490                 (void *)&cmd_lfc_set_pause_time,
6491                 (void *)&cmd_lfc_set_send_xon,
6492                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6493                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6494                 (void *)&cmd_lfc_set_autoneg_str,
6495                 (void *)&cmd_lfc_set_autoneg,
6496                 (void *)&cmd_lfc_set_portid,
6497                 NULL,
6498         },
6499 };
6500
6501 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6502         .f = cmd_link_flow_ctrl_set_parsed,
6503         .data = (void *)&cmd_link_flow_control_set_rx,
6504         .help_str = "set flow_ctrl rx on|off <port_id>: "
6505                 "Change rx flow control parameter",
6506         .tokens = {
6507                 (void *)&cmd_lfc_set_set,
6508                 (void *)&cmd_lfc_set_flow_ctrl,
6509                 (void *)&cmd_lfc_set_rx,
6510                 (void *)&cmd_lfc_set_rx_mode,
6511                 (void *)&cmd_lfc_set_portid,
6512                 NULL,
6513         },
6514 };
6515
6516 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6517         .f = cmd_link_flow_ctrl_set_parsed,
6518         .data = (void *)&cmd_link_flow_control_set_tx,
6519         .help_str = "set flow_ctrl tx on|off <port_id>: "
6520                 "Change tx flow control parameter",
6521         .tokens = {
6522                 (void *)&cmd_lfc_set_set,
6523                 (void *)&cmd_lfc_set_flow_ctrl,
6524                 (void *)&cmd_lfc_set_tx,
6525                 (void *)&cmd_lfc_set_tx_mode,
6526                 (void *)&cmd_lfc_set_portid,
6527                 NULL,
6528         },
6529 };
6530
6531 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6532         .f = cmd_link_flow_ctrl_set_parsed,
6533         .data = (void *)&cmd_link_flow_control_set_hw,
6534         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6535                 "Change high water flow control parameter",
6536         .tokens = {
6537                 (void *)&cmd_lfc_set_set,
6538                 (void *)&cmd_lfc_set_flow_ctrl,
6539                 (void *)&cmd_lfc_set_high_water_str,
6540                 (void *)&cmd_lfc_set_high_water,
6541                 (void *)&cmd_lfc_set_portid,
6542                 NULL,
6543         },
6544 };
6545
6546 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6547         .f = cmd_link_flow_ctrl_set_parsed,
6548         .data = (void *)&cmd_link_flow_control_set_lw,
6549         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6550                 "Change low water flow control parameter",
6551         .tokens = {
6552                 (void *)&cmd_lfc_set_set,
6553                 (void *)&cmd_lfc_set_flow_ctrl,
6554                 (void *)&cmd_lfc_set_low_water_str,
6555                 (void *)&cmd_lfc_set_low_water,
6556                 (void *)&cmd_lfc_set_portid,
6557                 NULL,
6558         },
6559 };
6560
6561 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6562         .f = cmd_link_flow_ctrl_set_parsed,
6563         .data = (void *)&cmd_link_flow_control_set_pt,
6564         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6565                 "Change pause time flow control parameter",
6566         .tokens = {
6567                 (void *)&cmd_lfc_set_set,
6568                 (void *)&cmd_lfc_set_flow_ctrl,
6569                 (void *)&cmd_lfc_set_pause_time_str,
6570                 (void *)&cmd_lfc_set_pause_time,
6571                 (void *)&cmd_lfc_set_portid,
6572                 NULL,
6573         },
6574 };
6575
6576 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6577         .f = cmd_link_flow_ctrl_set_parsed,
6578         .data = (void *)&cmd_link_flow_control_set_xon,
6579         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6580                 "Change send_xon flow control parameter",
6581         .tokens = {
6582                 (void *)&cmd_lfc_set_set,
6583                 (void *)&cmd_lfc_set_flow_ctrl,
6584                 (void *)&cmd_lfc_set_send_xon_str,
6585                 (void *)&cmd_lfc_set_send_xon,
6586                 (void *)&cmd_lfc_set_portid,
6587                 NULL,
6588         },
6589 };
6590
6591 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6592         .f = cmd_link_flow_ctrl_set_parsed,
6593         .data = (void *)&cmd_link_flow_control_set_macfwd,
6594         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6595                 "Change mac ctrl fwd flow control parameter",
6596         .tokens = {
6597                 (void *)&cmd_lfc_set_set,
6598                 (void *)&cmd_lfc_set_flow_ctrl,
6599                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6600                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6601                 (void *)&cmd_lfc_set_portid,
6602                 NULL,
6603         },
6604 };
6605
6606 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6607         .f = cmd_link_flow_ctrl_set_parsed,
6608         .data = (void *)&cmd_link_flow_control_set_autoneg,
6609         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6610                 "Change autoneg flow control parameter",
6611         .tokens = {
6612                 (void *)&cmd_lfc_set_set,
6613                 (void *)&cmd_lfc_set_flow_ctrl,
6614                 (void *)&cmd_lfc_set_autoneg_str,
6615                 (void *)&cmd_lfc_set_autoneg,
6616                 (void *)&cmd_lfc_set_portid,
6617                 NULL,
6618         },
6619 };
6620
6621 static void
6622 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6623                               __attribute__((unused)) struct cmdline *cl,
6624                               void *data)
6625 {
6626         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6627         cmdline_parse_inst_t *cmd = data;
6628         struct rte_eth_fc_conf fc_conf;
6629         int rx_fc_en = 0;
6630         int tx_fc_en = 0;
6631         int ret;
6632
6633         /*
6634          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6635          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6636          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6637          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6638          */
6639         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6640                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6641         };
6642
6643         /* Partial command line, retrieve current configuration */
6644         if (cmd) {
6645                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6646                 if (ret != 0) {
6647                         printf("cannot get current flow ctrl parameters, return"
6648                                "code = %d\n", ret);
6649                         return;
6650                 }
6651
6652                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6653                     (fc_conf.mode == RTE_FC_FULL))
6654                         rx_fc_en = 1;
6655                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6656                     (fc_conf.mode == RTE_FC_FULL))
6657                         tx_fc_en = 1;
6658         }
6659
6660         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6661                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6662
6663         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6664                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6665
6666         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6667
6668         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6669                 fc_conf.high_water = res->high_water;
6670
6671         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6672                 fc_conf.low_water = res->low_water;
6673
6674         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6675                 fc_conf.pause_time = res->pause_time;
6676
6677         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6678                 fc_conf.send_xon = res->send_xon;
6679
6680         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6681                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6682                         fc_conf.mac_ctrl_frame_fwd = 1;
6683                 else
6684                         fc_conf.mac_ctrl_frame_fwd = 0;
6685         }
6686
6687         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6688                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6689
6690         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6691         if (ret != 0)
6692                 printf("bad flow contrl parameter, return code = %d \n", ret);
6693 }
6694
6695 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6696 struct cmd_priority_flow_ctrl_set_result {
6697         cmdline_fixed_string_t set;
6698         cmdline_fixed_string_t pfc_ctrl;
6699         cmdline_fixed_string_t rx;
6700         cmdline_fixed_string_t rx_pfc_mode;
6701         cmdline_fixed_string_t tx;
6702         cmdline_fixed_string_t tx_pfc_mode;
6703         uint32_t high_water;
6704         uint32_t low_water;
6705         uint16_t pause_time;
6706         uint8_t  priority;
6707         portid_t port_id;
6708 };
6709
6710 static void
6711 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6712                        __attribute__((unused)) struct cmdline *cl,
6713                        __attribute__((unused)) void *data)
6714 {
6715         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6716         struct rte_eth_pfc_conf pfc_conf;
6717         int rx_fc_enable, tx_fc_enable;
6718         int ret;
6719
6720         /*
6721          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6722          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6723          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6724          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6725          */
6726         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6727                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6728         };
6729
6730         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6731         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6732         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6733         pfc_conf.fc.high_water = res->high_water;
6734         pfc_conf.fc.low_water  = res->low_water;
6735         pfc_conf.fc.pause_time = res->pause_time;
6736         pfc_conf.priority      = res->priority;
6737
6738         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6739         if (ret != 0)
6740                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6741 }
6742
6743 cmdline_parse_token_string_t cmd_pfc_set_set =
6744         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6745                                 set, "set");
6746 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6747         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6748                                 pfc_ctrl, "pfc_ctrl");
6749 cmdline_parse_token_string_t cmd_pfc_set_rx =
6750         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6751                                 rx, "rx");
6752 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6753         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6754                                 rx_pfc_mode, "on#off");
6755 cmdline_parse_token_string_t cmd_pfc_set_tx =
6756         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6757                                 tx, "tx");
6758 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6759         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6760                                 tx_pfc_mode, "on#off");
6761 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6762         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6763                                 high_water, UINT32);
6764 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6765         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6766                                 low_water, UINT32);
6767 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6768         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6769                                 pause_time, UINT16);
6770 cmdline_parse_token_num_t cmd_pfc_set_priority =
6771         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6772                                 priority, UINT8);
6773 cmdline_parse_token_num_t cmd_pfc_set_portid =
6774         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6775                                 port_id, UINT16);
6776
6777 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6778         .f = cmd_priority_flow_ctrl_set_parsed,
6779         .data = NULL,
6780         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6781                 "<pause_time> <priority> <port_id>: "
6782                 "Configure the Ethernet priority flow control",
6783         .tokens = {
6784                 (void *)&cmd_pfc_set_set,
6785                 (void *)&cmd_pfc_set_flow_ctrl,
6786                 (void *)&cmd_pfc_set_rx,
6787                 (void *)&cmd_pfc_set_rx_mode,
6788                 (void *)&cmd_pfc_set_tx,
6789                 (void *)&cmd_pfc_set_tx_mode,
6790                 (void *)&cmd_pfc_set_high_water,
6791                 (void *)&cmd_pfc_set_low_water,
6792                 (void *)&cmd_pfc_set_pause_time,
6793                 (void *)&cmd_pfc_set_priority,
6794                 (void *)&cmd_pfc_set_portid,
6795                 NULL,
6796         },
6797 };
6798
6799 /* *** RESET CONFIGURATION *** */
6800 struct cmd_reset_result {
6801         cmdline_fixed_string_t reset;
6802         cmdline_fixed_string_t def;
6803 };
6804
6805 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6806                              struct cmdline *cl,
6807                              __attribute__((unused)) void *data)
6808 {
6809         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6810         set_def_fwd_config();
6811 }
6812
6813 cmdline_parse_token_string_t cmd_reset_set =
6814         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6815 cmdline_parse_token_string_t cmd_reset_def =
6816         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6817                                  "default");
6818
6819 cmdline_parse_inst_t cmd_reset = {
6820         .f = cmd_reset_parsed,
6821         .data = NULL,
6822         .help_str = "set default: Reset default forwarding configuration",
6823         .tokens = {
6824                 (void *)&cmd_reset_set,
6825                 (void *)&cmd_reset_def,
6826                 NULL,
6827         },
6828 };
6829
6830 /* *** START FORWARDING *** */
6831 struct cmd_start_result {
6832         cmdline_fixed_string_t start;
6833 };
6834
6835 cmdline_parse_token_string_t cmd_start_start =
6836         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6837
6838 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6839                              __attribute__((unused)) struct cmdline *cl,
6840                              __attribute__((unused)) void *data)
6841 {
6842         start_packet_forwarding(0);
6843 }
6844
6845 cmdline_parse_inst_t cmd_start = {
6846         .f = cmd_start_parsed,
6847         .data = NULL,
6848         .help_str = "start: Start packet forwarding",
6849         .tokens = {
6850                 (void *)&cmd_start_start,
6851                 NULL,
6852         },
6853 };
6854
6855 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6856 struct cmd_start_tx_first_result {
6857         cmdline_fixed_string_t start;
6858         cmdline_fixed_string_t tx_first;
6859 };
6860
6861 static void
6862 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6863                           __attribute__((unused)) struct cmdline *cl,
6864                           __attribute__((unused)) void *data)
6865 {
6866         start_packet_forwarding(1);
6867 }
6868
6869 cmdline_parse_token_string_t cmd_start_tx_first_start =
6870         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6871                                  "start");
6872 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6873         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6874                                  tx_first, "tx_first");
6875
6876 cmdline_parse_inst_t cmd_start_tx_first = {
6877         .f = cmd_start_tx_first_parsed,
6878         .data = NULL,
6879         .help_str = "start tx_first: Start packet forwarding, "
6880                 "after sending 1 burst of packets",
6881         .tokens = {
6882                 (void *)&cmd_start_tx_first_start,
6883                 (void *)&cmd_start_tx_first_tx_first,
6884                 NULL,
6885         },
6886 };
6887
6888 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6889 struct cmd_start_tx_first_n_result {
6890         cmdline_fixed_string_t start;
6891         cmdline_fixed_string_t tx_first;
6892         uint32_t tx_num;
6893 };
6894
6895 static void
6896 cmd_start_tx_first_n_parsed(void *parsed_result,
6897                           __attribute__((unused)) struct cmdline *cl,
6898                           __attribute__((unused)) void *data)
6899 {
6900         struct cmd_start_tx_first_n_result *res = parsed_result;
6901
6902         start_packet_forwarding(res->tx_num);
6903 }
6904
6905 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6906         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6907                         start, "start");
6908 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6909         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6910                         tx_first, "tx_first");
6911 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6912         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6913                         tx_num, UINT32);
6914
6915 cmdline_parse_inst_t cmd_start_tx_first_n = {
6916         .f = cmd_start_tx_first_n_parsed,
6917         .data = NULL,
6918         .help_str = "start tx_first <num>: "
6919                 "packet forwarding, after sending <num> bursts of packets",
6920         .tokens = {
6921                 (void *)&cmd_start_tx_first_n_start,
6922                 (void *)&cmd_start_tx_first_n_tx_first,
6923                 (void *)&cmd_start_tx_first_n_tx_num,
6924                 NULL,
6925         },
6926 };
6927
6928 /* *** SET LINK UP *** */
6929 struct cmd_set_link_up_result {
6930         cmdline_fixed_string_t set;
6931         cmdline_fixed_string_t link_up;
6932         cmdline_fixed_string_t port;
6933         portid_t port_id;
6934 };
6935
6936 cmdline_parse_token_string_t cmd_set_link_up_set =
6937         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6938 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6939         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6940                                 "link-up");
6941 cmdline_parse_token_string_t cmd_set_link_up_port =
6942         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6943 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6944         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6945
6946 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6947                              __attribute__((unused)) struct cmdline *cl,
6948                              __attribute__((unused)) void *data)
6949 {
6950         struct cmd_set_link_up_result *res = parsed_result;
6951         dev_set_link_up(res->port_id);
6952 }
6953
6954 cmdline_parse_inst_t cmd_set_link_up = {
6955         .f = cmd_set_link_up_parsed,
6956         .data = NULL,
6957         .help_str = "set link-up port <port id>",
6958         .tokens = {
6959                 (void *)&cmd_set_link_up_set,
6960                 (void *)&cmd_set_link_up_link_up,
6961                 (void *)&cmd_set_link_up_port,
6962                 (void *)&cmd_set_link_up_port_id,
6963                 NULL,
6964         },
6965 };
6966
6967 /* *** SET LINK DOWN *** */
6968 struct cmd_set_link_down_result {
6969         cmdline_fixed_string_t set;
6970         cmdline_fixed_string_t link_down;
6971         cmdline_fixed_string_t port;
6972         portid_t port_id;
6973 };
6974
6975 cmdline_parse_token_string_t cmd_set_link_down_set =
6976         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6977 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6978         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6979                                 "link-down");
6980 cmdline_parse_token_string_t cmd_set_link_down_port =
6981         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6982 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6983         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6984
6985 static void cmd_set_link_down_parsed(
6986                                 __attribute__((unused)) void *parsed_result,
6987                                 __attribute__((unused)) struct cmdline *cl,
6988                                 __attribute__((unused)) void *data)
6989 {
6990         struct cmd_set_link_down_result *res = parsed_result;
6991         dev_set_link_down(res->port_id);
6992 }
6993
6994 cmdline_parse_inst_t cmd_set_link_down = {
6995         .f = cmd_set_link_down_parsed,
6996         .data = NULL,
6997         .help_str = "set link-down port <port id>",
6998         .tokens = {
6999                 (void *)&cmd_set_link_down_set,
7000                 (void *)&cmd_set_link_down_link_down,
7001                 (void *)&cmd_set_link_down_port,
7002                 (void *)&cmd_set_link_down_port_id,
7003                 NULL,
7004         },
7005 };
7006
7007 /* *** SHOW CFG *** */
7008 struct cmd_showcfg_result {
7009         cmdline_fixed_string_t show;
7010         cmdline_fixed_string_t cfg;
7011         cmdline_fixed_string_t what;
7012 };
7013
7014 static void cmd_showcfg_parsed(void *parsed_result,
7015                                __attribute__((unused)) struct cmdline *cl,
7016                                __attribute__((unused)) void *data)
7017 {
7018         struct cmd_showcfg_result *res = parsed_result;
7019         if (!strcmp(res->what, "rxtx"))
7020                 rxtx_config_display();
7021         else if (!strcmp(res->what, "cores"))
7022                 fwd_lcores_config_display();
7023         else if (!strcmp(res->what, "fwd"))
7024                 pkt_fwd_config_display(&cur_fwd_config);
7025         else if (!strcmp(res->what, "txpkts"))
7026                 show_tx_pkt_segments();
7027 }
7028
7029 cmdline_parse_token_string_t cmd_showcfg_show =
7030         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7031 cmdline_parse_token_string_t cmd_showcfg_port =
7032         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7033 cmdline_parse_token_string_t cmd_showcfg_what =
7034         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7035                                  "rxtx#cores#fwd#txpkts");
7036
7037 cmdline_parse_inst_t cmd_showcfg = {
7038         .f = cmd_showcfg_parsed,
7039         .data = NULL,
7040         .help_str = "show config rxtx|cores|fwd|txpkts",
7041         .tokens = {
7042                 (void *)&cmd_showcfg_show,
7043                 (void *)&cmd_showcfg_port,
7044                 (void *)&cmd_showcfg_what,
7045                 NULL,
7046         },
7047 };
7048
7049 /* *** SHOW ALL PORT INFO *** */
7050 struct cmd_showportall_result {
7051         cmdline_fixed_string_t show;
7052         cmdline_fixed_string_t port;
7053         cmdline_fixed_string_t what;
7054         cmdline_fixed_string_t all;
7055 };
7056
7057 static void cmd_showportall_parsed(void *parsed_result,
7058                                 __attribute__((unused)) struct cmdline *cl,
7059                                 __attribute__((unused)) void *data)
7060 {
7061         portid_t i;
7062
7063         struct cmd_showportall_result *res = parsed_result;
7064         if (!strcmp(res->show, "clear")) {
7065                 if (!strcmp(res->what, "stats"))
7066                         RTE_ETH_FOREACH_DEV(i)
7067                                 nic_stats_clear(i);
7068                 else if (!strcmp(res->what, "xstats"))
7069                         RTE_ETH_FOREACH_DEV(i)
7070                                 nic_xstats_clear(i);
7071         } else if (!strcmp(res->what, "info"))
7072                 RTE_ETH_FOREACH_DEV(i)
7073                         port_infos_display(i);
7074         else if (!strcmp(res->what, "stats"))
7075                 RTE_ETH_FOREACH_DEV(i)
7076                         nic_stats_display(i);
7077         else if (!strcmp(res->what, "xstats"))
7078                 RTE_ETH_FOREACH_DEV(i)
7079                         nic_xstats_display(i);
7080         else if (!strcmp(res->what, "fdir"))
7081                 RTE_ETH_FOREACH_DEV(i)
7082                         fdir_get_infos(i);
7083         else if (!strcmp(res->what, "stat_qmap"))
7084                 RTE_ETH_FOREACH_DEV(i)
7085                         nic_stats_mapping_display(i);
7086         else if (!strcmp(res->what, "dcb_tc"))
7087                 RTE_ETH_FOREACH_DEV(i)
7088                         port_dcb_info_display(i);
7089         else if (!strcmp(res->what, "cap"))
7090                 RTE_ETH_FOREACH_DEV(i)
7091                         port_offload_cap_display(i);
7092 }
7093
7094 cmdline_parse_token_string_t cmd_showportall_show =
7095         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7096                                  "show#clear");
7097 cmdline_parse_token_string_t cmd_showportall_port =
7098         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7099 cmdline_parse_token_string_t cmd_showportall_what =
7100         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7101                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7102 cmdline_parse_token_string_t cmd_showportall_all =
7103         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7104 cmdline_parse_inst_t cmd_showportall = {
7105         .f = cmd_showportall_parsed,
7106         .data = NULL,
7107         .help_str = "show|clear port "
7108                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7109         .tokens = {
7110                 (void *)&cmd_showportall_show,
7111                 (void *)&cmd_showportall_port,
7112                 (void *)&cmd_showportall_what,
7113                 (void *)&cmd_showportall_all,
7114                 NULL,
7115         },
7116 };
7117
7118 /* *** SHOW PORT INFO *** */
7119 struct cmd_showport_result {
7120         cmdline_fixed_string_t show;
7121         cmdline_fixed_string_t port;
7122         cmdline_fixed_string_t what;
7123         uint16_t portnum;
7124 };
7125
7126 static void cmd_showport_parsed(void *parsed_result,
7127                                 __attribute__((unused)) struct cmdline *cl,
7128                                 __attribute__((unused)) void *data)
7129 {
7130         struct cmd_showport_result *res = parsed_result;
7131         if (!strcmp(res->show, "clear")) {
7132                 if (!strcmp(res->what, "stats"))
7133                         nic_stats_clear(res->portnum);
7134                 else if (!strcmp(res->what, "xstats"))
7135                         nic_xstats_clear(res->portnum);
7136         } else if (!strcmp(res->what, "info"))
7137                 port_infos_display(res->portnum);
7138         else if (!strcmp(res->what, "stats"))
7139                 nic_stats_display(res->portnum);
7140         else if (!strcmp(res->what, "xstats"))
7141                 nic_xstats_display(res->portnum);
7142         else if (!strcmp(res->what, "fdir"))
7143                  fdir_get_infos(res->portnum);
7144         else if (!strcmp(res->what, "stat_qmap"))
7145                 nic_stats_mapping_display(res->portnum);
7146         else if (!strcmp(res->what, "dcb_tc"))
7147                 port_dcb_info_display(res->portnum);
7148         else if (!strcmp(res->what, "cap"))
7149                 port_offload_cap_display(res->portnum);
7150 }
7151
7152 cmdline_parse_token_string_t cmd_showport_show =
7153         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7154                                  "show#clear");
7155 cmdline_parse_token_string_t cmd_showport_port =
7156         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7157 cmdline_parse_token_string_t cmd_showport_what =
7158         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7159                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7160 cmdline_parse_token_num_t cmd_showport_portnum =
7161         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7162
7163 cmdline_parse_inst_t cmd_showport = {
7164         .f = cmd_showport_parsed,
7165         .data = NULL,
7166         .help_str = "show|clear port "
7167                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7168                 "<port_id>",
7169         .tokens = {
7170                 (void *)&cmd_showport_show,
7171                 (void *)&cmd_showport_port,
7172                 (void *)&cmd_showport_what,
7173                 (void *)&cmd_showport_portnum,
7174                 NULL,
7175         },
7176 };
7177
7178 /* *** SHOW QUEUE INFO *** */
7179 struct cmd_showqueue_result {
7180         cmdline_fixed_string_t show;
7181         cmdline_fixed_string_t type;
7182         cmdline_fixed_string_t what;
7183         uint16_t portnum;
7184         uint16_t queuenum;
7185 };
7186
7187 static void
7188 cmd_showqueue_parsed(void *parsed_result,
7189         __attribute__((unused)) struct cmdline *cl,
7190         __attribute__((unused)) void *data)
7191 {
7192         struct cmd_showqueue_result *res = parsed_result;
7193
7194         if (!strcmp(res->type, "rxq"))
7195                 rx_queue_infos_display(res->portnum, res->queuenum);
7196         else if (!strcmp(res->type, "txq"))
7197                 tx_queue_infos_display(res->portnum, res->queuenum);
7198 }
7199
7200 cmdline_parse_token_string_t cmd_showqueue_show =
7201         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7202 cmdline_parse_token_string_t cmd_showqueue_type =
7203         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7204 cmdline_parse_token_string_t cmd_showqueue_what =
7205         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7206 cmdline_parse_token_num_t cmd_showqueue_portnum =
7207         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7208 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7209         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7210
7211 cmdline_parse_inst_t cmd_showqueue = {
7212         .f = cmd_showqueue_parsed,
7213         .data = NULL,
7214         .help_str = "show rxq|txq info <port_id> <queue_id>",
7215         .tokens = {
7216                 (void *)&cmd_showqueue_show,
7217                 (void *)&cmd_showqueue_type,
7218                 (void *)&cmd_showqueue_what,
7219                 (void *)&cmd_showqueue_portnum,
7220                 (void *)&cmd_showqueue_queuenum,
7221                 NULL,
7222         },
7223 };
7224
7225 /* *** READ PORT REGISTER *** */
7226 struct cmd_read_reg_result {
7227         cmdline_fixed_string_t read;
7228         cmdline_fixed_string_t reg;
7229         portid_t port_id;
7230         uint32_t reg_off;
7231 };
7232
7233 static void
7234 cmd_read_reg_parsed(void *parsed_result,
7235                     __attribute__((unused)) struct cmdline *cl,
7236                     __attribute__((unused)) void *data)
7237 {
7238         struct cmd_read_reg_result *res = parsed_result;
7239         port_reg_display(res->port_id, res->reg_off);
7240 }
7241
7242 cmdline_parse_token_string_t cmd_read_reg_read =
7243         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7244 cmdline_parse_token_string_t cmd_read_reg_reg =
7245         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7246 cmdline_parse_token_num_t cmd_read_reg_port_id =
7247         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7248 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7249         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7250
7251 cmdline_parse_inst_t cmd_read_reg = {
7252         .f = cmd_read_reg_parsed,
7253         .data = NULL,
7254         .help_str = "read reg <port_id> <reg_off>",
7255         .tokens = {
7256                 (void *)&cmd_read_reg_read,
7257                 (void *)&cmd_read_reg_reg,
7258                 (void *)&cmd_read_reg_port_id,
7259                 (void *)&cmd_read_reg_reg_off,
7260                 NULL,
7261         },
7262 };
7263
7264 /* *** READ PORT REGISTER BIT FIELD *** */
7265 struct cmd_read_reg_bit_field_result {
7266         cmdline_fixed_string_t read;
7267         cmdline_fixed_string_t regfield;
7268         portid_t port_id;
7269         uint32_t reg_off;
7270         uint8_t bit1_pos;
7271         uint8_t bit2_pos;
7272 };
7273
7274 static void
7275 cmd_read_reg_bit_field_parsed(void *parsed_result,
7276                               __attribute__((unused)) struct cmdline *cl,
7277                               __attribute__((unused)) void *data)
7278 {
7279         struct cmd_read_reg_bit_field_result *res = parsed_result;
7280         port_reg_bit_field_display(res->port_id, res->reg_off,
7281                                    res->bit1_pos, res->bit2_pos);
7282 }
7283
7284 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7285         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7286                                  "read");
7287 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7288         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7289                                  regfield, "regfield");
7290 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7291         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7292                               UINT16);
7293 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7294         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7295                               UINT32);
7296 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7297         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7298                               UINT8);
7299 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7300         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7301                               UINT8);
7302
7303 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7304         .f = cmd_read_reg_bit_field_parsed,
7305         .data = NULL,
7306         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7307         "Read register bit field between bit_x and bit_y included",
7308         .tokens = {
7309                 (void *)&cmd_read_reg_bit_field_read,
7310                 (void *)&cmd_read_reg_bit_field_regfield,
7311                 (void *)&cmd_read_reg_bit_field_port_id,
7312                 (void *)&cmd_read_reg_bit_field_reg_off,
7313                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7314                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7315                 NULL,
7316         },
7317 };
7318
7319 /* *** READ PORT REGISTER BIT *** */
7320 struct cmd_read_reg_bit_result {
7321         cmdline_fixed_string_t read;
7322         cmdline_fixed_string_t regbit;
7323         portid_t port_id;
7324         uint32_t reg_off;
7325         uint8_t bit_pos;
7326 };
7327
7328 static void
7329 cmd_read_reg_bit_parsed(void *parsed_result,
7330                         __attribute__((unused)) struct cmdline *cl,
7331                         __attribute__((unused)) void *data)
7332 {
7333         struct cmd_read_reg_bit_result *res = parsed_result;
7334         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7335 }
7336
7337 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7338         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7339 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7340         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7341                                  regbit, "regbit");
7342 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7343         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7344 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7345         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7346 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7347         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7348
7349 cmdline_parse_inst_t cmd_read_reg_bit = {
7350         .f = cmd_read_reg_bit_parsed,
7351         .data = NULL,
7352         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7353         .tokens = {
7354                 (void *)&cmd_read_reg_bit_read,
7355                 (void *)&cmd_read_reg_bit_regbit,
7356                 (void *)&cmd_read_reg_bit_port_id,
7357                 (void *)&cmd_read_reg_bit_reg_off,
7358                 (void *)&cmd_read_reg_bit_bit_pos,
7359                 NULL,
7360         },
7361 };
7362
7363 /* *** WRITE PORT REGISTER *** */
7364 struct cmd_write_reg_result {
7365         cmdline_fixed_string_t write;
7366         cmdline_fixed_string_t reg;
7367         portid_t port_id;
7368         uint32_t reg_off;
7369         uint32_t value;
7370 };
7371
7372 static void
7373 cmd_write_reg_parsed(void *parsed_result,
7374                      __attribute__((unused)) struct cmdline *cl,
7375                      __attribute__((unused)) void *data)
7376 {
7377         struct cmd_write_reg_result *res = parsed_result;
7378         port_reg_set(res->port_id, res->reg_off, res->value);
7379 }
7380
7381 cmdline_parse_token_string_t cmd_write_reg_write =
7382         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7383 cmdline_parse_token_string_t cmd_write_reg_reg =
7384         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7385 cmdline_parse_token_num_t cmd_write_reg_port_id =
7386         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7387 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7388         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7389 cmdline_parse_token_num_t cmd_write_reg_value =
7390         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7391
7392 cmdline_parse_inst_t cmd_write_reg = {
7393         .f = cmd_write_reg_parsed,
7394         .data = NULL,
7395         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7396         .tokens = {
7397                 (void *)&cmd_write_reg_write,
7398                 (void *)&cmd_write_reg_reg,
7399                 (void *)&cmd_write_reg_port_id,
7400                 (void *)&cmd_write_reg_reg_off,
7401                 (void *)&cmd_write_reg_value,
7402                 NULL,
7403         },
7404 };
7405
7406 /* *** WRITE PORT REGISTER BIT FIELD *** */
7407 struct cmd_write_reg_bit_field_result {
7408         cmdline_fixed_string_t write;
7409         cmdline_fixed_string_t regfield;
7410         portid_t port_id;
7411         uint32_t reg_off;
7412         uint8_t bit1_pos;
7413         uint8_t bit2_pos;
7414         uint32_t value;
7415 };
7416
7417 static void
7418 cmd_write_reg_bit_field_parsed(void *parsed_result,
7419                                __attribute__((unused)) struct cmdline *cl,
7420                                __attribute__((unused)) void *data)
7421 {
7422         struct cmd_write_reg_bit_field_result *res = parsed_result;
7423         port_reg_bit_field_set(res->port_id, res->reg_off,
7424                           res->bit1_pos, res->bit2_pos, res->value);
7425 }
7426
7427 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7428         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7429                                  "write");
7430 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7431         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7432                                  regfield, "regfield");
7433 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7434         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7435                               UINT16);
7436 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7437         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7438                               UINT32);
7439 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7440         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7441                               UINT8);
7442 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7443         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7444                               UINT8);
7445 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7446         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7447                               UINT32);
7448
7449 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7450         .f = cmd_write_reg_bit_field_parsed,
7451         .data = NULL,
7452         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7453                 "<reg_value>: "
7454                 "Set register bit field between bit_x and bit_y included",
7455         .tokens = {
7456                 (void *)&cmd_write_reg_bit_field_write,
7457                 (void *)&cmd_write_reg_bit_field_regfield,
7458                 (void *)&cmd_write_reg_bit_field_port_id,
7459                 (void *)&cmd_write_reg_bit_field_reg_off,
7460                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7461                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7462                 (void *)&cmd_write_reg_bit_field_value,
7463                 NULL,
7464         },
7465 };
7466
7467 /* *** WRITE PORT REGISTER BIT *** */
7468 struct cmd_write_reg_bit_result {
7469         cmdline_fixed_string_t write;
7470         cmdline_fixed_string_t regbit;
7471         portid_t port_id;
7472         uint32_t reg_off;
7473         uint8_t bit_pos;
7474         uint8_t value;
7475 };
7476
7477 static void
7478 cmd_write_reg_bit_parsed(void *parsed_result,
7479                          __attribute__((unused)) struct cmdline *cl,
7480                          __attribute__((unused)) void *data)
7481 {
7482         struct cmd_write_reg_bit_result *res = parsed_result;
7483         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7484 }
7485
7486 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7487         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7488                                  "write");
7489 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7490         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7491                                  regbit, "regbit");
7492 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7493         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7494 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7495         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7496 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7497         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7498 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7499         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7500
7501 cmdline_parse_inst_t cmd_write_reg_bit = {
7502         .f = cmd_write_reg_bit_parsed,
7503         .data = NULL,
7504         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7505                 "0 <= bit_x <= 31",
7506         .tokens = {
7507                 (void *)&cmd_write_reg_bit_write,
7508                 (void *)&cmd_write_reg_bit_regbit,
7509                 (void *)&cmd_write_reg_bit_port_id,
7510                 (void *)&cmd_write_reg_bit_reg_off,
7511                 (void *)&cmd_write_reg_bit_bit_pos,
7512                 (void *)&cmd_write_reg_bit_value,
7513                 NULL,
7514         },
7515 };
7516
7517 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7518 struct cmd_read_rxd_txd_result {
7519         cmdline_fixed_string_t read;
7520         cmdline_fixed_string_t rxd_txd;
7521         portid_t port_id;
7522         uint16_t queue_id;
7523         uint16_t desc_id;
7524 };
7525
7526 static void
7527 cmd_read_rxd_txd_parsed(void *parsed_result,
7528                         __attribute__((unused)) struct cmdline *cl,
7529                         __attribute__((unused)) void *data)
7530 {
7531         struct cmd_read_rxd_txd_result *res = parsed_result;
7532
7533         if (!strcmp(res->rxd_txd, "rxd"))
7534                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7535         else if (!strcmp(res->rxd_txd, "txd"))
7536                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7537 }
7538
7539 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7540         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7541 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7542         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7543                                  "rxd#txd");
7544 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7545         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7546 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7547         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7548 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7549         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7550
7551 cmdline_parse_inst_t cmd_read_rxd_txd = {
7552         .f = cmd_read_rxd_txd_parsed,
7553         .data = NULL,
7554         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7555         .tokens = {
7556                 (void *)&cmd_read_rxd_txd_read,
7557                 (void *)&cmd_read_rxd_txd_rxd_txd,
7558                 (void *)&cmd_read_rxd_txd_port_id,
7559                 (void *)&cmd_read_rxd_txd_queue_id,
7560                 (void *)&cmd_read_rxd_txd_desc_id,
7561                 NULL,
7562         },
7563 };
7564
7565 /* *** QUIT *** */
7566 struct cmd_quit_result {
7567         cmdline_fixed_string_t quit;
7568 };
7569
7570 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7571                             struct cmdline *cl,
7572                             __attribute__((unused)) void *data)
7573 {
7574         pmd_test_exit();
7575         cmdline_quit(cl);
7576 }
7577
7578 cmdline_parse_token_string_t cmd_quit_quit =
7579         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7580
7581 cmdline_parse_inst_t cmd_quit = {
7582         .f = cmd_quit_parsed,
7583         .data = NULL,
7584         .help_str = "quit: Exit application",
7585         .tokens = {
7586                 (void *)&cmd_quit_quit,
7587                 NULL,
7588         },
7589 };
7590
7591 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7592 struct cmd_mac_addr_result {
7593         cmdline_fixed_string_t mac_addr_cmd;
7594         cmdline_fixed_string_t what;
7595         uint16_t port_num;
7596         struct ether_addr address;
7597 };
7598
7599 static void cmd_mac_addr_parsed(void *parsed_result,
7600                 __attribute__((unused)) struct cmdline *cl,
7601                 __attribute__((unused)) void *data)
7602 {
7603         struct cmd_mac_addr_result *res = parsed_result;
7604         int ret;
7605
7606         if (strcmp(res->what, "add") == 0)
7607                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7608         else if (strcmp(res->what, "set") == 0)
7609                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7610                                                        &res->address);
7611         else
7612                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7613
7614         /* check the return value and print it if is < 0 */
7615         if(ret < 0)
7616                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7617
7618 }
7619
7620 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7621         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7622                                 "mac_addr");
7623 cmdline_parse_token_string_t cmd_mac_addr_what =
7624         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7625                                 "add#remove#set");
7626 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7627                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7628                                         UINT16);
7629 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7630                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7631
7632 cmdline_parse_inst_t cmd_mac_addr = {
7633         .f = cmd_mac_addr_parsed,
7634         .data = (void *)0,
7635         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7636                         "Add/Remove/Set MAC address on port_id",
7637         .tokens = {
7638                 (void *)&cmd_mac_addr_cmd,
7639                 (void *)&cmd_mac_addr_what,
7640                 (void *)&cmd_mac_addr_portnum,
7641                 (void *)&cmd_mac_addr_addr,
7642                 NULL,
7643         },
7644 };
7645
7646 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7647 struct cmd_eth_peer_result {
7648         cmdline_fixed_string_t set;
7649         cmdline_fixed_string_t eth_peer;
7650         portid_t port_id;
7651         cmdline_fixed_string_t peer_addr;
7652 };
7653
7654 static void cmd_set_eth_peer_parsed(void *parsed_result,
7655                         __attribute__((unused)) struct cmdline *cl,
7656                         __attribute__((unused)) void *data)
7657 {
7658                 struct cmd_eth_peer_result *res = parsed_result;
7659
7660                 if (test_done == 0) {
7661                         printf("Please stop forwarding first\n");
7662                         return;
7663                 }
7664                 if (!strcmp(res->eth_peer, "eth-peer")) {
7665                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7666                         fwd_config_setup();
7667                 }
7668 }
7669 cmdline_parse_token_string_t cmd_eth_peer_set =
7670         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7671 cmdline_parse_token_string_t cmd_eth_peer =
7672         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7673 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7674         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7675 cmdline_parse_token_string_t cmd_eth_peer_addr =
7676         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7677
7678 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7679         .f = cmd_set_eth_peer_parsed,
7680         .data = NULL,
7681         .help_str = "set eth-peer <port_id> <peer_mac>",
7682         .tokens = {
7683                 (void *)&cmd_eth_peer_set,
7684                 (void *)&cmd_eth_peer,
7685                 (void *)&cmd_eth_peer_port_id,
7686                 (void *)&cmd_eth_peer_addr,
7687                 NULL,
7688         },
7689 };
7690
7691 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7692 struct cmd_set_qmap_result {
7693         cmdline_fixed_string_t set;
7694         cmdline_fixed_string_t qmap;
7695         cmdline_fixed_string_t what;
7696         portid_t port_id;
7697         uint16_t queue_id;
7698         uint8_t map_value;
7699 };
7700
7701 static void
7702 cmd_set_qmap_parsed(void *parsed_result,
7703                        __attribute__((unused)) struct cmdline *cl,
7704                        __attribute__((unused)) void *data)
7705 {
7706         struct cmd_set_qmap_result *res = parsed_result;
7707         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7708
7709         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7710 }
7711
7712 cmdline_parse_token_string_t cmd_setqmap_set =
7713         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7714                                  set, "set");
7715 cmdline_parse_token_string_t cmd_setqmap_qmap =
7716         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7717                                  qmap, "stat_qmap");
7718 cmdline_parse_token_string_t cmd_setqmap_what =
7719         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7720                                  what, "tx#rx");
7721 cmdline_parse_token_num_t cmd_setqmap_portid =
7722         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7723                               port_id, UINT16);
7724 cmdline_parse_token_num_t cmd_setqmap_queueid =
7725         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7726                               queue_id, UINT16);
7727 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7728         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7729                               map_value, UINT8);
7730
7731 cmdline_parse_inst_t cmd_set_qmap = {
7732         .f = cmd_set_qmap_parsed,
7733         .data = NULL,
7734         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7735                 "Set statistics mapping value on tx|rx queue_id of port_id",
7736         .tokens = {
7737                 (void *)&cmd_setqmap_set,
7738                 (void *)&cmd_setqmap_qmap,
7739                 (void *)&cmd_setqmap_what,
7740                 (void *)&cmd_setqmap_portid,
7741                 (void *)&cmd_setqmap_queueid,
7742                 (void *)&cmd_setqmap_mapvalue,
7743                 NULL,
7744         },
7745 };
7746
7747 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7748 struct cmd_set_xstats_hide_zero_result {
7749         cmdline_fixed_string_t keyword;
7750         cmdline_fixed_string_t name;
7751         cmdline_fixed_string_t on_off;
7752 };
7753
7754 static void
7755 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7756                         __attribute__((unused)) struct cmdline *cl,
7757                         __attribute__((unused)) void *data)
7758 {
7759         struct cmd_set_xstats_hide_zero_result *res;
7760         uint16_t on_off = 0;
7761
7762         res = parsed_result;
7763         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7764         set_xstats_hide_zero(on_off);
7765 }
7766
7767 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7768         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7769                                  keyword, "set");
7770 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7771         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7772                                  name, "xstats-hide-zero");
7773 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7774         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7775                                  on_off, "on#off");
7776
7777 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7778         .f = cmd_set_xstats_hide_zero_parsed,
7779         .data = NULL,
7780         .help_str = "set xstats-hide-zero on|off",
7781         .tokens = {
7782                 (void *)&cmd_set_xstats_hide_zero_keyword,
7783                 (void *)&cmd_set_xstats_hide_zero_name,
7784                 (void *)&cmd_set_xstats_hide_zero_on_off,
7785                 NULL,
7786         },
7787 };
7788
7789 /* *** CONFIGURE UNICAST HASH TABLE *** */
7790 struct cmd_set_uc_hash_table {
7791         cmdline_fixed_string_t set;
7792         cmdline_fixed_string_t port;
7793         portid_t port_id;
7794         cmdline_fixed_string_t what;
7795         struct ether_addr address;
7796         cmdline_fixed_string_t mode;
7797 };
7798
7799 static void
7800 cmd_set_uc_hash_parsed(void *parsed_result,
7801                        __attribute__((unused)) struct cmdline *cl,
7802                        __attribute__((unused)) void *data)
7803 {
7804         int ret=0;
7805         struct cmd_set_uc_hash_table *res = parsed_result;
7806
7807         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7808
7809         if (strcmp(res->what, "uta") == 0)
7810                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7811                                                 &res->address,(uint8_t)is_on);
7812         if (ret < 0)
7813                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7814
7815 }
7816
7817 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7818         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7819                                  set, "set");
7820 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7821         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7822                                  port, "port");
7823 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7824         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7825                               port_id, UINT16);
7826 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7827         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7828                                  what, "uta");
7829 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7830         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7831                                 address);
7832 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7833         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7834                                  mode, "on#off");
7835
7836 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7837         .f = cmd_set_uc_hash_parsed,
7838         .data = NULL,
7839         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7840         .tokens = {
7841                 (void *)&cmd_set_uc_hash_set,
7842                 (void *)&cmd_set_uc_hash_port,
7843                 (void *)&cmd_set_uc_hash_portid,
7844                 (void *)&cmd_set_uc_hash_what,
7845                 (void *)&cmd_set_uc_hash_mac,
7846                 (void *)&cmd_set_uc_hash_mode,
7847                 NULL,
7848         },
7849 };
7850
7851 struct cmd_set_uc_all_hash_table {
7852         cmdline_fixed_string_t set;
7853         cmdline_fixed_string_t port;
7854         portid_t port_id;
7855         cmdline_fixed_string_t what;
7856         cmdline_fixed_string_t value;
7857         cmdline_fixed_string_t mode;
7858 };
7859
7860 static void
7861 cmd_set_uc_all_hash_parsed(void *parsed_result,
7862                        __attribute__((unused)) struct cmdline *cl,
7863                        __attribute__((unused)) void *data)
7864 {
7865         int ret=0;
7866         struct cmd_set_uc_all_hash_table *res = parsed_result;
7867
7868         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7869
7870         if ((strcmp(res->what, "uta") == 0) &&
7871                 (strcmp(res->value, "all") == 0))
7872                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7873         if (ret < 0)
7874                 printf("bad unicast hash table parameter,"
7875                         "return code = %d \n", ret);
7876 }
7877
7878 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7879         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7880                                  set, "set");
7881 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7882         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7883                                  port, "port");
7884 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7885         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7886                               port_id, UINT16);
7887 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7888         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7889                                  what, "uta");
7890 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7891         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7892                                 value,"all");
7893 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7894         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7895                                  mode, "on#off");
7896
7897 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7898         .f = cmd_set_uc_all_hash_parsed,
7899         .data = NULL,
7900         .help_str = "set port <port_id> uta all on|off",
7901         .tokens = {
7902                 (void *)&cmd_set_uc_all_hash_set,
7903                 (void *)&cmd_set_uc_all_hash_port,
7904                 (void *)&cmd_set_uc_all_hash_portid,
7905                 (void *)&cmd_set_uc_all_hash_what,
7906                 (void *)&cmd_set_uc_all_hash_value,
7907                 (void *)&cmd_set_uc_all_hash_mode,
7908                 NULL,
7909         },
7910 };
7911
7912 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7913 struct cmd_set_vf_macvlan_filter {
7914         cmdline_fixed_string_t set;
7915         cmdline_fixed_string_t port;
7916         portid_t port_id;
7917         cmdline_fixed_string_t vf;
7918         uint8_t vf_id;
7919         struct ether_addr address;
7920         cmdline_fixed_string_t filter_type;
7921         cmdline_fixed_string_t mode;
7922 };
7923
7924 static void
7925 cmd_set_vf_macvlan_parsed(void *parsed_result,
7926                        __attribute__((unused)) struct cmdline *cl,
7927                        __attribute__((unused)) void *data)
7928 {
7929         int is_on, ret = 0;
7930         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7931         struct rte_eth_mac_filter filter;
7932
7933         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7934
7935         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7936
7937         /* set VF MAC filter */
7938         filter.is_vf = 1;
7939
7940         /* set VF ID */
7941         filter.dst_id = res->vf_id;
7942
7943         if (!strcmp(res->filter_type, "exact-mac"))
7944                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7945         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7946                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7947         else if (!strcmp(res->filter_type, "hashmac"))
7948                 filter.filter_type = RTE_MAC_HASH_MATCH;
7949         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7950                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7951
7952         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7953
7954         if (is_on)
7955                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7956                                         RTE_ETH_FILTER_MACVLAN,
7957                                         RTE_ETH_FILTER_ADD,
7958                                          &filter);
7959         else
7960                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7961                                         RTE_ETH_FILTER_MACVLAN,
7962                                         RTE_ETH_FILTER_DELETE,
7963                                         &filter);
7964
7965         if (ret < 0)
7966                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7967
7968 }
7969
7970 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7971         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7972                                  set, "set");
7973 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7974         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7975                                  port, "port");
7976 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7977         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7978                               port_id, UINT16);
7979 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7980         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7981                                  vf, "vf");
7982 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7983         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7984                                 vf_id, UINT8);
7985 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7986         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7987                                 address);
7988 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7989         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7990                                 filter_type, "exact-mac#exact-mac-vlan"
7991                                 "#hashmac#hashmac-vlan");
7992 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7993         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7994                                  mode, "on#off");
7995
7996 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7997         .f = cmd_set_vf_macvlan_parsed,
7998         .data = NULL,
7999         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8000                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8001                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8002                 "hash match rule: hash match of MAC and exact match of VLAN",
8003         .tokens = {
8004                 (void *)&cmd_set_vf_macvlan_set,
8005                 (void *)&cmd_set_vf_macvlan_port,
8006                 (void *)&cmd_set_vf_macvlan_portid,
8007                 (void *)&cmd_set_vf_macvlan_vf,
8008                 (void *)&cmd_set_vf_macvlan_vf_id,
8009                 (void *)&cmd_set_vf_macvlan_mac,
8010                 (void *)&cmd_set_vf_macvlan_filter_type,
8011                 (void *)&cmd_set_vf_macvlan_mode,
8012                 NULL,
8013         },
8014 };
8015
8016 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8017 struct cmd_set_vf_traffic {
8018         cmdline_fixed_string_t set;
8019         cmdline_fixed_string_t port;
8020         portid_t port_id;
8021         cmdline_fixed_string_t vf;
8022         uint8_t vf_id;
8023         cmdline_fixed_string_t what;
8024         cmdline_fixed_string_t mode;
8025 };
8026
8027 static void
8028 cmd_set_vf_traffic_parsed(void *parsed_result,
8029                        __attribute__((unused)) struct cmdline *cl,
8030                        __attribute__((unused)) void *data)
8031 {
8032         struct cmd_set_vf_traffic *res = parsed_result;
8033         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8034         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8035
8036         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8037 }
8038
8039 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8040         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8041                                  set, "set");
8042 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8043         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8044                                  port, "port");
8045 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8046         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8047                               port_id, UINT16);
8048 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8049         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8050                                  vf, "vf");
8051 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8052         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8053                               vf_id, UINT8);
8054 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8055         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8056                                  what, "tx#rx");
8057 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8058         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8059                                  mode, "on#off");
8060
8061 cmdline_parse_inst_t cmd_set_vf_traffic = {
8062         .f = cmd_set_vf_traffic_parsed,
8063         .data = NULL,
8064         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8065         .tokens = {
8066                 (void *)&cmd_setvf_traffic_set,
8067                 (void *)&cmd_setvf_traffic_port,
8068                 (void *)&cmd_setvf_traffic_portid,
8069                 (void *)&cmd_setvf_traffic_vf,
8070                 (void *)&cmd_setvf_traffic_vfid,
8071                 (void *)&cmd_setvf_traffic_what,
8072                 (void *)&cmd_setvf_traffic_mode,
8073                 NULL,
8074         },
8075 };
8076
8077 /* *** CONFIGURE VF RECEIVE MODE *** */
8078 struct cmd_set_vf_rxmode {
8079         cmdline_fixed_string_t set;
8080         cmdline_fixed_string_t port;
8081         portid_t port_id;
8082         cmdline_fixed_string_t vf;
8083         uint8_t vf_id;
8084         cmdline_fixed_string_t what;
8085         cmdline_fixed_string_t mode;
8086         cmdline_fixed_string_t on;
8087 };
8088
8089 static void
8090 cmd_set_vf_rxmode_parsed(void *parsed_result,
8091                        __attribute__((unused)) struct cmdline *cl,
8092                        __attribute__((unused)) void *data)
8093 {
8094         int ret = -ENOTSUP;
8095         uint16_t rx_mode = 0;
8096         struct cmd_set_vf_rxmode *res = parsed_result;
8097
8098         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8099         if (!strcmp(res->what,"rxmode")) {
8100                 if (!strcmp(res->mode, "AUPE"))
8101                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8102                 else if (!strcmp(res->mode, "ROPE"))
8103                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8104                 else if (!strcmp(res->mode, "BAM"))
8105                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8106                 else if (!strncmp(res->mode, "MPE",3))
8107                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8108         }
8109
8110         RTE_SET_USED(is_on);
8111
8112 #ifdef RTE_LIBRTE_IXGBE_PMD
8113         if (ret == -ENOTSUP)
8114                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8115                                                   rx_mode, (uint8_t)is_on);
8116 #endif
8117 #ifdef RTE_LIBRTE_BNXT_PMD
8118         if (ret == -ENOTSUP)
8119                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8120                                                  rx_mode, (uint8_t)is_on);
8121 #endif
8122         if (ret < 0)
8123                 printf("bad VF receive mode parameter, return code = %d \n",
8124                 ret);
8125 }
8126
8127 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8128         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8129                                  set, "set");
8130 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8131         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8132                                  port, "port");
8133 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8134         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8135                               port_id, UINT16);
8136 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8137         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8138                                  vf, "vf");
8139 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8140         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8141                               vf_id, UINT8);
8142 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8143         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8144                                  what, "rxmode");
8145 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8146         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8147                                  mode, "AUPE#ROPE#BAM#MPE");
8148 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8149         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8150                                  on, "on#off");
8151
8152 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8153         .f = cmd_set_vf_rxmode_parsed,
8154         .data = NULL,
8155         .help_str = "set port <port_id> vf <vf_id> rxmode "
8156                 "AUPE|ROPE|BAM|MPE on|off",
8157         .tokens = {
8158                 (void *)&cmd_set_vf_rxmode_set,
8159                 (void *)&cmd_set_vf_rxmode_port,
8160                 (void *)&cmd_set_vf_rxmode_portid,
8161                 (void *)&cmd_set_vf_rxmode_vf,
8162                 (void *)&cmd_set_vf_rxmode_vfid,
8163                 (void *)&cmd_set_vf_rxmode_what,
8164                 (void *)&cmd_set_vf_rxmode_mode,
8165                 (void *)&cmd_set_vf_rxmode_on,
8166                 NULL,
8167         },
8168 };
8169
8170 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8171 struct cmd_vf_mac_addr_result {
8172         cmdline_fixed_string_t mac_addr_cmd;
8173         cmdline_fixed_string_t what;
8174         cmdline_fixed_string_t port;
8175         uint16_t port_num;
8176         cmdline_fixed_string_t vf;
8177         uint8_t vf_num;
8178         struct ether_addr address;
8179 };
8180
8181 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8182                 __attribute__((unused)) struct cmdline *cl,
8183                 __attribute__((unused)) void *data)
8184 {
8185         struct cmd_vf_mac_addr_result *res = parsed_result;
8186         int ret = -ENOTSUP;
8187
8188         if (strcmp(res->what, "add") != 0)
8189                 return;
8190
8191 #ifdef RTE_LIBRTE_I40E_PMD
8192         if (ret == -ENOTSUP)
8193                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8194                                                    &res->address);
8195 #endif
8196 #ifdef RTE_LIBRTE_BNXT_PMD
8197         if (ret == -ENOTSUP)
8198                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8199                                                 res->vf_num);
8200 #endif
8201
8202         if(ret < 0)
8203                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8204
8205 }
8206
8207 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8208         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8209                                 mac_addr_cmd,"mac_addr");
8210 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8211         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8212                                 what,"add");
8213 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8214         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8215                                 port,"port");
8216 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8217         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8218                                 port_num, UINT16);
8219 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8220         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8221                                 vf,"vf");
8222 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8223         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8224                                 vf_num, UINT8);
8225 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8226         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8227                                 address);
8228
8229 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8230         .f = cmd_vf_mac_addr_parsed,
8231         .data = (void *)0,
8232         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8233                 "Add MAC address filtering for a VF on port_id",
8234         .tokens = {
8235                 (void *)&cmd_vf_mac_addr_cmd,
8236                 (void *)&cmd_vf_mac_addr_what,
8237                 (void *)&cmd_vf_mac_addr_port,
8238                 (void *)&cmd_vf_mac_addr_portnum,
8239                 (void *)&cmd_vf_mac_addr_vf,
8240                 (void *)&cmd_vf_mac_addr_vfnum,
8241                 (void *)&cmd_vf_mac_addr_addr,
8242                 NULL,
8243         },
8244 };
8245
8246 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8247 struct cmd_vf_rx_vlan_filter {
8248         cmdline_fixed_string_t rx_vlan;
8249         cmdline_fixed_string_t what;
8250         uint16_t vlan_id;
8251         cmdline_fixed_string_t port;
8252         portid_t port_id;
8253         cmdline_fixed_string_t vf;
8254         uint64_t vf_mask;
8255 };
8256
8257 static void
8258 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8259                           __attribute__((unused)) struct cmdline *cl,
8260                           __attribute__((unused)) void *data)
8261 {
8262         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8263         int ret = -ENOTSUP;
8264
8265         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8266
8267 #ifdef RTE_LIBRTE_IXGBE_PMD
8268         if (ret == -ENOTSUP)
8269                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8270                                 res->vlan_id, res->vf_mask, is_add);
8271 #endif
8272 #ifdef RTE_LIBRTE_I40E_PMD
8273         if (ret == -ENOTSUP)
8274                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8275                                 res->vlan_id, res->vf_mask, is_add);
8276 #endif
8277 #ifdef RTE_LIBRTE_BNXT_PMD
8278         if (ret == -ENOTSUP)
8279                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8280                                 res->vlan_id, res->vf_mask, is_add);
8281 #endif
8282
8283         switch (ret) {
8284         case 0:
8285                 break;
8286         case -EINVAL:
8287                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8288                                 res->vlan_id, res->vf_mask);
8289                 break;
8290         case -ENODEV:
8291                 printf("invalid port_id %d\n", res->port_id);
8292                 break;
8293         case -ENOTSUP:
8294                 printf("function not implemented or supported\n");
8295                 break;
8296         default:
8297                 printf("programming error: (%s)\n", strerror(-ret));
8298         }
8299 }
8300
8301 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8302         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8303                                  rx_vlan, "rx_vlan");
8304 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8305         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8306                                  what, "add#rm");
8307 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8308         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8309                               vlan_id, UINT16);
8310 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8311         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8312                                  port, "port");
8313 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8314         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8315                               port_id, UINT16);
8316 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8317         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8318                                  vf, "vf");
8319 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8320         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8321                               vf_mask, UINT64);
8322
8323 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8324         .f = cmd_vf_rx_vlan_filter_parsed,
8325         .data = NULL,
8326         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8327                 "(vf_mask = hexadecimal VF mask)",
8328         .tokens = {
8329                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8330                 (void *)&cmd_vf_rx_vlan_filter_what,
8331                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8332                 (void *)&cmd_vf_rx_vlan_filter_port,
8333                 (void *)&cmd_vf_rx_vlan_filter_portid,
8334                 (void *)&cmd_vf_rx_vlan_filter_vf,
8335                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8336                 NULL,
8337         },
8338 };
8339
8340 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8341 struct cmd_queue_rate_limit_result {
8342         cmdline_fixed_string_t set;
8343         cmdline_fixed_string_t port;
8344         uint16_t port_num;
8345         cmdline_fixed_string_t queue;
8346         uint8_t queue_num;
8347         cmdline_fixed_string_t rate;
8348         uint16_t rate_num;
8349 };
8350
8351 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8352                 __attribute__((unused)) struct cmdline *cl,
8353                 __attribute__((unused)) void *data)
8354 {
8355         struct cmd_queue_rate_limit_result *res = parsed_result;
8356         int ret = 0;
8357
8358         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8359                 && (strcmp(res->queue, "queue") == 0)
8360                 && (strcmp(res->rate, "rate") == 0))
8361                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8362                                         res->rate_num);
8363         if (ret < 0)
8364                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8365
8366 }
8367
8368 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8369         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8370                                 set, "set");
8371 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8372         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8373                                 port, "port");
8374 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8375         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8376                                 port_num, UINT16);
8377 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8378         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8379                                 queue, "queue");
8380 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8381         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8382                                 queue_num, UINT8);
8383 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8384         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8385                                 rate, "rate");
8386 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8387         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8388                                 rate_num, UINT16);
8389
8390 cmdline_parse_inst_t cmd_queue_rate_limit = {
8391         .f = cmd_queue_rate_limit_parsed,
8392         .data = (void *)0,
8393         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8394                 "Set rate limit for a queue on port_id",
8395         .tokens = {
8396                 (void *)&cmd_queue_rate_limit_set,
8397                 (void *)&cmd_queue_rate_limit_port,
8398                 (void *)&cmd_queue_rate_limit_portnum,
8399                 (void *)&cmd_queue_rate_limit_queue,
8400                 (void *)&cmd_queue_rate_limit_queuenum,
8401                 (void *)&cmd_queue_rate_limit_rate,
8402                 (void *)&cmd_queue_rate_limit_ratenum,
8403                 NULL,
8404         },
8405 };
8406
8407 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8408 struct cmd_vf_rate_limit_result {
8409         cmdline_fixed_string_t set;
8410         cmdline_fixed_string_t port;
8411         uint16_t port_num;
8412         cmdline_fixed_string_t vf;
8413         uint8_t vf_num;
8414         cmdline_fixed_string_t rate;
8415         uint16_t rate_num;
8416         cmdline_fixed_string_t q_msk;
8417         uint64_t q_msk_val;
8418 };
8419
8420 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8421                 __attribute__((unused)) struct cmdline *cl,
8422                 __attribute__((unused)) void *data)
8423 {
8424         struct cmd_vf_rate_limit_result *res = parsed_result;
8425         int ret = 0;
8426
8427         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8428                 && (strcmp(res->vf, "vf") == 0)
8429                 && (strcmp(res->rate, "rate") == 0)
8430                 && (strcmp(res->q_msk, "queue_mask") == 0))
8431                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8432                                         res->rate_num, res->q_msk_val);
8433         if (ret < 0)
8434                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8435
8436 }
8437
8438 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8439         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8440                                 set, "set");
8441 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8442         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8443                                 port, "port");
8444 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8445         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8446                                 port_num, UINT16);
8447 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8448         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8449                                 vf, "vf");
8450 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8451         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8452                                 vf_num, UINT8);
8453 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8454         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8455                                 rate, "rate");
8456 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8457         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8458                                 rate_num, UINT16);
8459 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8460         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8461                                 q_msk, "queue_mask");
8462 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8463         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8464                                 q_msk_val, UINT64);
8465
8466 cmdline_parse_inst_t cmd_vf_rate_limit = {
8467         .f = cmd_vf_rate_limit_parsed,
8468         .data = (void *)0,
8469         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8470                 "queue_mask <queue_mask_value>: "
8471                 "Set rate limit for queues of VF on port_id",
8472         .tokens = {
8473                 (void *)&cmd_vf_rate_limit_set,
8474                 (void *)&cmd_vf_rate_limit_port,
8475                 (void *)&cmd_vf_rate_limit_portnum,
8476                 (void *)&cmd_vf_rate_limit_vf,
8477                 (void *)&cmd_vf_rate_limit_vfnum,
8478                 (void *)&cmd_vf_rate_limit_rate,
8479                 (void *)&cmd_vf_rate_limit_ratenum,
8480                 (void *)&cmd_vf_rate_limit_q_msk,
8481                 (void *)&cmd_vf_rate_limit_q_msk_val,
8482                 NULL,
8483         },
8484 };
8485
8486 /* *** ADD TUNNEL FILTER OF A PORT *** */
8487 struct cmd_tunnel_filter_result {
8488         cmdline_fixed_string_t cmd;
8489         cmdline_fixed_string_t what;
8490         portid_t port_id;
8491         struct ether_addr outer_mac;
8492         struct ether_addr inner_mac;
8493         cmdline_ipaddr_t ip_value;
8494         uint16_t inner_vlan;
8495         cmdline_fixed_string_t tunnel_type;
8496         cmdline_fixed_string_t filter_type;
8497         uint32_t tenant_id;
8498         uint16_t queue_num;
8499 };
8500
8501 static void
8502 cmd_tunnel_filter_parsed(void *parsed_result,
8503                           __attribute__((unused)) struct cmdline *cl,
8504                           __attribute__((unused)) void *data)
8505 {
8506         struct cmd_tunnel_filter_result *res = parsed_result;
8507         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8508         int ret = 0;
8509
8510         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8511
8512         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8513         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8514         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8515
8516         if (res->ip_value.family == AF_INET) {
8517                 tunnel_filter_conf.ip_addr.ipv4_addr =
8518                         res->ip_value.addr.ipv4.s_addr;
8519                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8520         } else {
8521                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8522                         &(res->ip_value.addr.ipv6),
8523                         sizeof(struct in6_addr));
8524                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8525         }
8526
8527         if (!strcmp(res->filter_type, "imac-ivlan"))
8528                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8529         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8530                 tunnel_filter_conf.filter_type =
8531                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8532         else if (!strcmp(res->filter_type, "imac-tenid"))
8533                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8534         else if (!strcmp(res->filter_type, "imac"))
8535                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8536         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8537                 tunnel_filter_conf.filter_type =
8538                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8539         else if (!strcmp(res->filter_type, "oip"))
8540                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8541         else if (!strcmp(res->filter_type, "iip"))
8542                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8543         else {
8544                 printf("The filter type is not supported");
8545                 return;
8546         }
8547
8548         if (!strcmp(res->tunnel_type, "vxlan"))
8549                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8550         else if (!strcmp(res->tunnel_type, "nvgre"))
8551                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8552         else if (!strcmp(res->tunnel_type, "ipingre"))
8553                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8554         else {
8555                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8556                 return;
8557         }
8558
8559         tunnel_filter_conf.tenant_id = res->tenant_id;
8560         tunnel_filter_conf.queue_id = res->queue_num;
8561         if (!strcmp(res->what, "add"))
8562                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8563                                         RTE_ETH_FILTER_TUNNEL,
8564                                         RTE_ETH_FILTER_ADD,
8565                                         &tunnel_filter_conf);
8566         else
8567                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8568                                         RTE_ETH_FILTER_TUNNEL,
8569                                         RTE_ETH_FILTER_DELETE,
8570                                         &tunnel_filter_conf);
8571         if (ret < 0)
8572                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8573                                 strerror(-ret));
8574
8575 }
8576 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8577         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8578         cmd, "tunnel_filter");
8579 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8580         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8581         what, "add#rm");
8582 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8583         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8584         port_id, UINT16);
8585 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8586         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8587         outer_mac);
8588 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8589         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8590         inner_mac);
8591 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8592         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8593         inner_vlan, UINT16);
8594 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8595         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8596         ip_value);
8597 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8598         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8599         tunnel_type, "vxlan#nvgre#ipingre");
8600
8601 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8602         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8603         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8604                 "imac#omac-imac-tenid");
8605 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8606         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8607         tenant_id, UINT32);
8608 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8609         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8610         queue_num, UINT16);
8611
8612 cmdline_parse_inst_t cmd_tunnel_filter = {
8613         .f = cmd_tunnel_filter_parsed,
8614         .data = (void *)0,
8615         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8616                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8617                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8618                 "<queue_id>: Add/Rm tunnel filter of a port",
8619         .tokens = {
8620                 (void *)&cmd_tunnel_filter_cmd,
8621                 (void *)&cmd_tunnel_filter_what,
8622                 (void *)&cmd_tunnel_filter_port_id,
8623                 (void *)&cmd_tunnel_filter_outer_mac,
8624                 (void *)&cmd_tunnel_filter_inner_mac,
8625                 (void *)&cmd_tunnel_filter_ip_value,
8626                 (void *)&cmd_tunnel_filter_innner_vlan,
8627                 (void *)&cmd_tunnel_filter_tunnel_type,
8628                 (void *)&cmd_tunnel_filter_filter_type,
8629                 (void *)&cmd_tunnel_filter_tenant_id,
8630                 (void *)&cmd_tunnel_filter_queue_num,
8631                 NULL,
8632         },
8633 };
8634
8635 /* *** CONFIGURE TUNNEL UDP PORT *** */
8636 struct cmd_tunnel_udp_config {
8637         cmdline_fixed_string_t cmd;
8638         cmdline_fixed_string_t what;
8639         uint16_t udp_port;
8640         portid_t port_id;
8641 };
8642
8643 static void
8644 cmd_tunnel_udp_config_parsed(void *parsed_result,
8645                           __attribute__((unused)) struct cmdline *cl,
8646                           __attribute__((unused)) void *data)
8647 {
8648         struct cmd_tunnel_udp_config *res = parsed_result;
8649         struct rte_eth_udp_tunnel tunnel_udp;
8650         int ret;
8651
8652         tunnel_udp.udp_port = res->udp_port;
8653
8654         if (!strcmp(res->cmd, "rx_vxlan_port"))
8655                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8656
8657         if (!strcmp(res->what, "add"))
8658                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8659                                                       &tunnel_udp);
8660         else
8661                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8662                                                          &tunnel_udp);
8663
8664         if (ret < 0)
8665                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8666 }
8667
8668 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8669         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8670                                 cmd, "rx_vxlan_port");
8671 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8672         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8673                                 what, "add#rm");
8674 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8675         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8676                                 udp_port, UINT16);
8677 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8678         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8679                                 port_id, UINT16);
8680
8681 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8682         .f = cmd_tunnel_udp_config_parsed,
8683         .data = (void *)0,
8684         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8685                 "Add/Remove a tunneling UDP port filter",
8686         .tokens = {
8687                 (void *)&cmd_tunnel_udp_config_cmd,
8688                 (void *)&cmd_tunnel_udp_config_what,
8689                 (void *)&cmd_tunnel_udp_config_udp_port,
8690                 (void *)&cmd_tunnel_udp_config_port_id,
8691                 NULL,
8692         },
8693 };
8694
8695 struct cmd_config_tunnel_udp_port {
8696         cmdline_fixed_string_t port;
8697         cmdline_fixed_string_t config;
8698         portid_t port_id;
8699         cmdline_fixed_string_t udp_tunnel_port;
8700         cmdline_fixed_string_t action;
8701         cmdline_fixed_string_t tunnel_type;
8702         uint16_t udp_port;
8703 };
8704
8705 static void
8706 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8707                                __attribute__((unused)) struct cmdline *cl,
8708                                __attribute__((unused)) void *data)
8709 {
8710         struct cmd_config_tunnel_udp_port *res = parsed_result;
8711         struct rte_eth_udp_tunnel tunnel_udp;
8712         int ret = 0;
8713
8714         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8715                 return;
8716
8717         tunnel_udp.udp_port = res->udp_port;
8718
8719         if (!strcmp(res->tunnel_type, "vxlan")) {
8720                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8721         } else if (!strcmp(res->tunnel_type, "geneve")) {
8722                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8723         } else {
8724                 printf("Invalid tunnel type\n");
8725                 return;
8726         }
8727
8728         if (!strcmp(res->action, "add"))
8729                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8730                                                       &tunnel_udp);
8731         else
8732                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8733                                                          &tunnel_udp);
8734
8735         if (ret < 0)
8736                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8737 }
8738
8739 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8740         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8741                                  "port");
8742 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8743         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8744                                  "config");
8745 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8746         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8747                               UINT16);
8748 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8749         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8750                                  udp_tunnel_port,
8751                                  "udp_tunnel_port");
8752 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8753         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8754                                  "add#rm");
8755 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8756         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8757                                  "vxlan#geneve");
8758 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8759         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8760                               UINT16);
8761
8762 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8763         .f = cmd_cfg_tunnel_udp_port_parsed,
8764         .data = NULL,
8765         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8766         .tokens = {
8767                 (void *)&cmd_config_tunnel_udp_port_port,
8768                 (void *)&cmd_config_tunnel_udp_port_config,
8769                 (void *)&cmd_config_tunnel_udp_port_port_id,
8770                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8771                 (void *)&cmd_config_tunnel_udp_port_action,
8772                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8773                 (void *)&cmd_config_tunnel_udp_port_value,
8774                 NULL,
8775         },
8776 };
8777
8778 /* *** GLOBAL CONFIG *** */
8779 struct cmd_global_config_result {
8780         cmdline_fixed_string_t cmd;
8781         portid_t port_id;
8782         cmdline_fixed_string_t cfg_type;
8783         uint8_t len;
8784 };
8785
8786 static void
8787 cmd_global_config_parsed(void *parsed_result,
8788                          __attribute__((unused)) struct cmdline *cl,
8789                          __attribute__((unused)) void *data)
8790 {
8791         struct cmd_global_config_result *res = parsed_result;
8792         struct rte_eth_global_cfg conf;
8793         int ret;
8794
8795         memset(&conf, 0, sizeof(conf));
8796         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8797         conf.cfg.gre_key_len = res->len;
8798         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8799                                       RTE_ETH_FILTER_SET, &conf);
8800         if (ret != 0)
8801                 printf("Global config error\n");
8802 }
8803
8804 cmdline_parse_token_string_t cmd_global_config_cmd =
8805         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8806                 "global_config");
8807 cmdline_parse_token_num_t cmd_global_config_port_id =
8808         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8809                                UINT16);
8810 cmdline_parse_token_string_t cmd_global_config_type =
8811         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8812                 cfg_type, "gre-key-len");
8813 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8814         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8815                 len, UINT8);
8816
8817 cmdline_parse_inst_t cmd_global_config = {
8818         .f = cmd_global_config_parsed,
8819         .data = (void *)NULL,
8820         .help_str = "global_config <port_id> gre-key-len <key_len>",
8821         .tokens = {
8822                 (void *)&cmd_global_config_cmd,
8823                 (void *)&cmd_global_config_port_id,
8824                 (void *)&cmd_global_config_type,
8825                 (void *)&cmd_global_config_gre_key_len,
8826                 NULL,
8827         },
8828 };
8829
8830 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8831 struct cmd_set_mirror_mask_result {
8832         cmdline_fixed_string_t set;
8833         cmdline_fixed_string_t port;
8834         portid_t port_id;
8835         cmdline_fixed_string_t mirror;
8836         uint8_t rule_id;
8837         cmdline_fixed_string_t what;
8838         cmdline_fixed_string_t value;
8839         cmdline_fixed_string_t dstpool;
8840         uint8_t dstpool_id;
8841         cmdline_fixed_string_t on;
8842 };
8843
8844 cmdline_parse_token_string_t cmd_mirror_mask_set =
8845         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8846                                 set, "set");
8847 cmdline_parse_token_string_t cmd_mirror_mask_port =
8848         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8849                                 port, "port");
8850 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8851         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8852                                 port_id, UINT16);
8853 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8854         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8855                                 mirror, "mirror-rule");
8856 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8857         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8858                                 rule_id, UINT8);
8859 cmdline_parse_token_string_t cmd_mirror_mask_what =
8860         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8861                                 what, "pool-mirror-up#pool-mirror-down"
8862                                       "#vlan-mirror");
8863 cmdline_parse_token_string_t cmd_mirror_mask_value =
8864         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8865                                 value, NULL);
8866 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8867         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8868                                 dstpool, "dst-pool");
8869 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8870         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8871                                 dstpool_id, UINT8);
8872 cmdline_parse_token_string_t cmd_mirror_mask_on =
8873         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8874                                 on, "on#off");
8875
8876 static void
8877 cmd_set_mirror_mask_parsed(void *parsed_result,
8878                        __attribute__((unused)) struct cmdline *cl,
8879                        __attribute__((unused)) void *data)
8880 {
8881         int ret,nb_item,i;
8882         struct cmd_set_mirror_mask_result *res = parsed_result;
8883         struct rte_eth_mirror_conf mr_conf;
8884
8885         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8886
8887         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8888
8889         mr_conf.dst_pool = res->dstpool_id;
8890
8891         if (!strcmp(res->what, "pool-mirror-up")) {
8892                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8893                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8894         } else if (!strcmp(res->what, "pool-mirror-down")) {
8895                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8896                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8897         } else if (!strcmp(res->what, "vlan-mirror")) {
8898                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8899                 nb_item = parse_item_list(res->value, "vlan",
8900                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8901                 if (nb_item <= 0)
8902                         return;
8903
8904                 for (i = 0; i < nb_item; i++) {
8905                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8906                                 printf("Invalid vlan_id: must be < 4096\n");
8907                                 return;
8908                         }
8909
8910                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8911                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8912                 }
8913         }
8914
8915         if (!strcmp(res->on, "on"))
8916                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8917                                                 res->rule_id, 1);
8918         else
8919                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8920                                                 res->rule_id, 0);
8921         if (ret < 0)
8922                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8923 }
8924
8925 cmdline_parse_inst_t cmd_set_mirror_mask = {
8926                 .f = cmd_set_mirror_mask_parsed,
8927                 .data = NULL,
8928                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8929                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8930                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8931                 .tokens = {
8932                         (void *)&cmd_mirror_mask_set,
8933                         (void *)&cmd_mirror_mask_port,
8934                         (void *)&cmd_mirror_mask_portid,
8935                         (void *)&cmd_mirror_mask_mirror,
8936                         (void *)&cmd_mirror_mask_ruleid,
8937                         (void *)&cmd_mirror_mask_what,
8938                         (void *)&cmd_mirror_mask_value,
8939                         (void *)&cmd_mirror_mask_dstpool,
8940                         (void *)&cmd_mirror_mask_poolid,
8941                         (void *)&cmd_mirror_mask_on,
8942                         NULL,
8943                 },
8944 };
8945
8946 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8947 struct cmd_set_mirror_link_result {
8948         cmdline_fixed_string_t set;
8949         cmdline_fixed_string_t port;
8950         portid_t port_id;
8951         cmdline_fixed_string_t mirror;
8952         uint8_t rule_id;
8953         cmdline_fixed_string_t what;
8954         cmdline_fixed_string_t dstpool;
8955         uint8_t dstpool_id;
8956         cmdline_fixed_string_t on;
8957 };
8958
8959 cmdline_parse_token_string_t cmd_mirror_link_set =
8960         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8961                                  set, "set");
8962 cmdline_parse_token_string_t cmd_mirror_link_port =
8963         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8964                                 port, "port");
8965 cmdline_parse_token_num_t cmd_mirror_link_portid =
8966         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8967                                 port_id, UINT16);
8968 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8969         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8970                                 mirror, "mirror-rule");
8971 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8972         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8973                             rule_id, UINT8);
8974 cmdline_parse_token_string_t cmd_mirror_link_what =
8975         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8976                                 what, "uplink-mirror#downlink-mirror");
8977 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8978         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8979                                 dstpool, "dst-pool");
8980 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8981         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8982                                 dstpool_id, UINT8);
8983 cmdline_parse_token_string_t cmd_mirror_link_on =
8984         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8985                                 on, "on#off");
8986
8987 static void
8988 cmd_set_mirror_link_parsed(void *parsed_result,
8989                        __attribute__((unused)) struct cmdline *cl,
8990                        __attribute__((unused)) void *data)
8991 {
8992         int ret;
8993         struct cmd_set_mirror_link_result *res = parsed_result;
8994         struct rte_eth_mirror_conf mr_conf;
8995
8996         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8997         if (!strcmp(res->what, "uplink-mirror"))
8998                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8999         else
9000                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9001
9002         mr_conf.dst_pool = res->dstpool_id;
9003
9004         if (!strcmp(res->on, "on"))
9005                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9006                                                 res->rule_id, 1);
9007         else
9008                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9009                                                 res->rule_id, 0);
9010
9011         /* check the return value and print it if is < 0 */
9012         if (ret < 0)
9013                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9014
9015 }
9016
9017 cmdline_parse_inst_t cmd_set_mirror_link = {
9018                 .f = cmd_set_mirror_link_parsed,
9019                 .data = NULL,
9020                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9021                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9022                 .tokens = {
9023                         (void *)&cmd_mirror_link_set,
9024                         (void *)&cmd_mirror_link_port,
9025                         (void *)&cmd_mirror_link_portid,
9026                         (void *)&cmd_mirror_link_mirror,
9027                         (void *)&cmd_mirror_link_ruleid,
9028                         (void *)&cmd_mirror_link_what,
9029                         (void *)&cmd_mirror_link_dstpool,
9030                         (void *)&cmd_mirror_link_poolid,
9031                         (void *)&cmd_mirror_link_on,
9032                         NULL,
9033                 },
9034 };
9035
9036 /* *** RESET VM MIRROR RULE *** */
9037 struct cmd_rm_mirror_rule_result {
9038         cmdline_fixed_string_t reset;
9039         cmdline_fixed_string_t port;
9040         portid_t port_id;
9041         cmdline_fixed_string_t mirror;
9042         uint8_t rule_id;
9043 };
9044
9045 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9046         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9047                                  reset, "reset");
9048 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9049         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9050                                 port, "port");
9051 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9052         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9053                                 port_id, UINT16);
9054 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9055         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9056                                 mirror, "mirror-rule");
9057 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9058         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9059                                 rule_id, UINT8);
9060
9061 static void
9062 cmd_reset_mirror_rule_parsed(void *parsed_result,
9063                        __attribute__((unused)) struct cmdline *cl,
9064                        __attribute__((unused)) void *data)
9065 {
9066         int ret;
9067         struct cmd_set_mirror_link_result *res = parsed_result;
9068         /* check rule_id */
9069         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9070         if(ret < 0)
9071                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9072 }
9073
9074 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9075                 .f = cmd_reset_mirror_rule_parsed,
9076                 .data = NULL,
9077                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9078                 .tokens = {
9079                         (void *)&cmd_rm_mirror_rule_reset,
9080                         (void *)&cmd_rm_mirror_rule_port,
9081                         (void *)&cmd_rm_mirror_rule_portid,
9082                         (void *)&cmd_rm_mirror_rule_mirror,
9083                         (void *)&cmd_rm_mirror_rule_ruleid,
9084                         NULL,
9085                 },
9086 };
9087
9088 /* ******************************************************************************** */
9089
9090 struct cmd_dump_result {
9091         cmdline_fixed_string_t dump;
9092 };
9093
9094 static void
9095 dump_struct_sizes(void)
9096 {
9097 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9098         DUMP_SIZE(struct rte_mbuf);
9099         DUMP_SIZE(struct rte_mempool);
9100         DUMP_SIZE(struct rte_ring);
9101 #undef DUMP_SIZE
9102 }
9103
9104 static void cmd_dump_parsed(void *parsed_result,
9105                             __attribute__((unused)) struct cmdline *cl,
9106                             __attribute__((unused)) void *data)
9107 {
9108         struct cmd_dump_result *res = parsed_result;
9109
9110         if (!strcmp(res->dump, "dump_physmem"))
9111                 rte_dump_physmem_layout(stdout);
9112         else if (!strcmp(res->dump, "dump_memzone"))
9113                 rte_memzone_dump(stdout);
9114         else if (!strcmp(res->dump, "dump_struct_sizes"))
9115                 dump_struct_sizes();
9116         else if (!strcmp(res->dump, "dump_ring"))
9117                 rte_ring_list_dump(stdout);
9118         else if (!strcmp(res->dump, "dump_mempool"))
9119                 rte_mempool_list_dump(stdout);
9120         else if (!strcmp(res->dump, "dump_devargs"))
9121                 rte_devargs_dump(stdout);
9122         else if (!strcmp(res->dump, "dump_log_types"))
9123                 rte_log_dump(stdout);
9124 }
9125
9126 cmdline_parse_token_string_t cmd_dump_dump =
9127         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9128                 "dump_physmem#"
9129                 "dump_memzone#"
9130                 "dump_struct_sizes#"
9131                 "dump_ring#"
9132                 "dump_mempool#"
9133                 "dump_devargs#"
9134                 "dump_log_types");
9135
9136 cmdline_parse_inst_t cmd_dump = {
9137         .f = cmd_dump_parsed,  /* function to call */
9138         .data = NULL,      /* 2nd arg of func */
9139         .help_str = "Dump status",
9140         .tokens = {        /* token list, NULL terminated */
9141                 (void *)&cmd_dump_dump,
9142                 NULL,
9143         },
9144 };
9145
9146 /* ******************************************************************************** */
9147
9148 struct cmd_dump_one_result {
9149         cmdline_fixed_string_t dump;
9150         cmdline_fixed_string_t name;
9151 };
9152
9153 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9154                                 __attribute__((unused)) void *data)
9155 {
9156         struct cmd_dump_one_result *res = parsed_result;
9157
9158         if (!strcmp(res->dump, "dump_ring")) {
9159                 struct rte_ring *r;
9160                 r = rte_ring_lookup(res->name);
9161                 if (r == NULL) {
9162                         cmdline_printf(cl, "Cannot find ring\n");
9163                         return;
9164                 }
9165                 rte_ring_dump(stdout, r);
9166         } else if (!strcmp(res->dump, "dump_mempool")) {
9167                 struct rte_mempool *mp;
9168                 mp = rte_mempool_lookup(res->name);
9169                 if (mp == NULL) {
9170                         cmdline_printf(cl, "Cannot find mempool\n");
9171                         return;
9172                 }
9173                 rte_mempool_dump(stdout, mp);
9174         }
9175 }
9176
9177 cmdline_parse_token_string_t cmd_dump_one_dump =
9178         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9179                                  "dump_ring#dump_mempool");
9180
9181 cmdline_parse_token_string_t cmd_dump_one_name =
9182         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9183
9184 cmdline_parse_inst_t cmd_dump_one = {
9185         .f = cmd_dump_one_parsed,  /* function to call */
9186         .data = NULL,      /* 2nd arg of func */
9187         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9188         .tokens = {        /* token list, NULL terminated */
9189                 (void *)&cmd_dump_one_dump,
9190                 (void *)&cmd_dump_one_name,
9191                 NULL,
9192         },
9193 };
9194
9195 /* *** Add/Del syn filter *** */
9196 struct cmd_syn_filter_result {
9197         cmdline_fixed_string_t filter;
9198         portid_t port_id;
9199         cmdline_fixed_string_t ops;
9200         cmdline_fixed_string_t priority;
9201         cmdline_fixed_string_t high;
9202         cmdline_fixed_string_t queue;
9203         uint16_t queue_id;
9204 };
9205
9206 static void
9207 cmd_syn_filter_parsed(void *parsed_result,
9208                         __attribute__((unused)) struct cmdline *cl,
9209                         __attribute__((unused)) void *data)
9210 {
9211         struct cmd_syn_filter_result *res = parsed_result;
9212         struct rte_eth_syn_filter syn_filter;
9213         int ret = 0;
9214
9215         ret = rte_eth_dev_filter_supported(res->port_id,
9216                                         RTE_ETH_FILTER_SYN);
9217         if (ret < 0) {
9218                 printf("syn filter is not supported on port %u.\n",
9219                                 res->port_id);
9220                 return;
9221         }
9222
9223         memset(&syn_filter, 0, sizeof(syn_filter));
9224
9225         if (!strcmp(res->ops, "add")) {
9226                 if (!strcmp(res->high, "high"))
9227                         syn_filter.hig_pri = 1;
9228                 else
9229                         syn_filter.hig_pri = 0;
9230
9231                 syn_filter.queue = res->queue_id;
9232                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9233                                                 RTE_ETH_FILTER_SYN,
9234                                                 RTE_ETH_FILTER_ADD,
9235                                                 &syn_filter);
9236         } else
9237                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9238                                                 RTE_ETH_FILTER_SYN,
9239                                                 RTE_ETH_FILTER_DELETE,
9240                                                 &syn_filter);
9241
9242         if (ret < 0)
9243                 printf("syn filter programming error: (%s)\n",
9244                                 strerror(-ret));
9245 }
9246
9247 cmdline_parse_token_string_t cmd_syn_filter_filter =
9248         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9249         filter, "syn_filter");
9250 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9251         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9252         port_id, UINT16);
9253 cmdline_parse_token_string_t cmd_syn_filter_ops =
9254         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9255         ops, "add#del");
9256 cmdline_parse_token_string_t cmd_syn_filter_priority =
9257         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9258                                 priority, "priority");
9259 cmdline_parse_token_string_t cmd_syn_filter_high =
9260         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9261                                 high, "high#low");
9262 cmdline_parse_token_string_t cmd_syn_filter_queue =
9263         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9264                                 queue, "queue");
9265 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9266         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9267                                 queue_id, UINT16);
9268
9269 cmdline_parse_inst_t cmd_syn_filter = {
9270         .f = cmd_syn_filter_parsed,
9271         .data = NULL,
9272         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9273                 "<queue_id>: Add/Delete syn filter",
9274         .tokens = {
9275                 (void *)&cmd_syn_filter_filter,
9276                 (void *)&cmd_syn_filter_port_id,
9277                 (void *)&cmd_syn_filter_ops,
9278                 (void *)&cmd_syn_filter_priority,
9279                 (void *)&cmd_syn_filter_high,
9280                 (void *)&cmd_syn_filter_queue,
9281                 (void *)&cmd_syn_filter_queue_id,
9282                 NULL,
9283         },
9284 };
9285
9286 /* *** queue region set *** */
9287 struct cmd_queue_region_result {
9288         cmdline_fixed_string_t set;
9289         cmdline_fixed_string_t port;
9290         portid_t port_id;
9291         cmdline_fixed_string_t cmd;
9292         cmdline_fixed_string_t region;
9293         uint8_t  region_id;
9294         cmdline_fixed_string_t queue_start_index;
9295         uint8_t  queue_id;
9296         cmdline_fixed_string_t queue_num;
9297         uint8_t  queue_num_value;
9298 };
9299
9300 static void
9301 cmd_queue_region_parsed(void *parsed_result,
9302                         __attribute__((unused)) struct cmdline *cl,
9303                         __attribute__((unused)) void *data)
9304 {
9305         struct cmd_queue_region_result *res = parsed_result;
9306         int ret = -ENOTSUP;
9307 #ifdef RTE_LIBRTE_I40E_PMD
9308         struct rte_pmd_i40e_queue_region_conf region_conf;
9309         enum rte_pmd_i40e_queue_region_op op_type;
9310 #endif
9311
9312         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9313                 return;
9314
9315 #ifdef RTE_LIBRTE_I40E_PMD
9316         memset(&region_conf, 0, sizeof(region_conf));
9317         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9318         region_conf.region_id = res->region_id;
9319         region_conf.queue_num = res->queue_num_value;
9320         region_conf.queue_start_index = res->queue_id;
9321
9322         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9323                                 op_type, &region_conf);
9324 #endif
9325
9326         switch (ret) {
9327         case 0:
9328                 break;
9329         case -ENOTSUP:
9330                 printf("function not implemented or supported\n");
9331                 break;
9332         default:
9333                 printf("queue region config error: (%s)\n", strerror(-ret));
9334         }
9335 }
9336
9337 cmdline_parse_token_string_t cmd_queue_region_set =
9338 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9339                 set, "set");
9340 cmdline_parse_token_string_t cmd_queue_region_port =
9341         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9342 cmdline_parse_token_num_t cmd_queue_region_port_id =
9343         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9344                                 port_id, UINT16);
9345 cmdline_parse_token_string_t cmd_queue_region_cmd =
9346         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9347                                  cmd, "queue-region");
9348 cmdline_parse_token_string_t cmd_queue_region_id =
9349         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9350                                 region, "region_id");
9351 cmdline_parse_token_num_t cmd_queue_region_index =
9352         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9353                                 region_id, UINT8);
9354 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9355         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9356                                 queue_start_index, "queue_start_index");
9357 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9358         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9359                                 queue_id, UINT8);
9360 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9361         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9362                                 queue_num, "queue_num");
9363 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9364         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9365                                 queue_num_value, UINT8);
9366
9367 cmdline_parse_inst_t cmd_queue_region = {
9368         .f = cmd_queue_region_parsed,
9369         .data = NULL,
9370         .help_str = "set port <port_id> queue-region region_id <value> "
9371                 "queue_start_index <value> queue_num <value>: Set a queue region",
9372         .tokens = {
9373                 (void *)&cmd_queue_region_set,
9374                 (void *)&cmd_queue_region_port,
9375                 (void *)&cmd_queue_region_port_id,
9376                 (void *)&cmd_queue_region_cmd,
9377                 (void *)&cmd_queue_region_id,
9378                 (void *)&cmd_queue_region_index,
9379                 (void *)&cmd_queue_region_queue_start_index,
9380                 (void *)&cmd_queue_region_queue_id,
9381                 (void *)&cmd_queue_region_queue_num,
9382                 (void *)&cmd_queue_region_queue_num_value,
9383                 NULL,
9384         },
9385 };
9386
9387 /* *** queue region and flowtype set *** */
9388 struct cmd_region_flowtype_result {
9389         cmdline_fixed_string_t set;
9390         cmdline_fixed_string_t port;
9391         portid_t port_id;
9392         cmdline_fixed_string_t cmd;
9393         cmdline_fixed_string_t region;
9394         uint8_t  region_id;
9395         cmdline_fixed_string_t flowtype;
9396         uint8_t  flowtype_id;
9397 };
9398
9399 static void
9400 cmd_region_flowtype_parsed(void *parsed_result,
9401                         __attribute__((unused)) struct cmdline *cl,
9402                         __attribute__((unused)) void *data)
9403 {
9404         struct cmd_region_flowtype_result *res = parsed_result;
9405         int ret = -ENOTSUP;
9406 #ifdef RTE_LIBRTE_I40E_PMD
9407         struct rte_pmd_i40e_queue_region_conf region_conf;
9408         enum rte_pmd_i40e_queue_region_op op_type;
9409 #endif
9410
9411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9412                 return;
9413
9414 #ifdef RTE_LIBRTE_I40E_PMD
9415         memset(&region_conf, 0, sizeof(region_conf));
9416
9417         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9418         region_conf.region_id = res->region_id;
9419         region_conf.hw_flowtype = res->flowtype_id;
9420
9421         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9422                         op_type, &region_conf);
9423 #endif
9424
9425         switch (ret) {
9426         case 0:
9427                 break;
9428         case -ENOTSUP:
9429                 printf("function not implemented or supported\n");
9430                 break;
9431         default:
9432                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9433         }
9434 }
9435
9436 cmdline_parse_token_string_t cmd_region_flowtype_set =
9437 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9438                                 set, "set");
9439 cmdline_parse_token_string_t cmd_region_flowtype_port =
9440         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9441                                 port, "port");
9442 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9443         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9444                                 port_id, UINT16);
9445 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9446         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9447                                 cmd, "queue-region");
9448 cmdline_parse_token_string_t cmd_region_flowtype_index =
9449         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9450                                 region, "region_id");
9451 cmdline_parse_token_num_t cmd_region_flowtype_id =
9452         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9453                                 region_id, UINT8);
9454 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9455         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9456                                 flowtype, "flowtype");
9457 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9458         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9459                                 flowtype_id, UINT8);
9460 cmdline_parse_inst_t cmd_region_flowtype = {
9461         .f = cmd_region_flowtype_parsed,
9462         .data = NULL,
9463         .help_str = "set port <port_id> queue-region region_id <value> "
9464                 "flowtype <value>: Set a flowtype region index",
9465         .tokens = {
9466                 (void *)&cmd_region_flowtype_set,
9467                 (void *)&cmd_region_flowtype_port,
9468                 (void *)&cmd_region_flowtype_port_index,
9469                 (void *)&cmd_region_flowtype_cmd,
9470                 (void *)&cmd_region_flowtype_index,
9471                 (void *)&cmd_region_flowtype_id,
9472                 (void *)&cmd_region_flowtype_flow_index,
9473                 (void *)&cmd_region_flowtype_flow_id,
9474                 NULL,
9475         },
9476 };
9477
9478 /* *** User Priority (UP) to queue region (region_id) set *** */
9479 struct cmd_user_priority_region_result {
9480         cmdline_fixed_string_t set;
9481         cmdline_fixed_string_t port;
9482         portid_t port_id;
9483         cmdline_fixed_string_t cmd;
9484         cmdline_fixed_string_t user_priority;
9485         uint8_t  user_priority_id;
9486         cmdline_fixed_string_t region;
9487         uint8_t  region_id;
9488 };
9489
9490 static void
9491 cmd_user_priority_region_parsed(void *parsed_result,
9492                         __attribute__((unused)) struct cmdline *cl,
9493                         __attribute__((unused)) void *data)
9494 {
9495         struct cmd_user_priority_region_result *res = parsed_result;
9496         int ret = -ENOTSUP;
9497 #ifdef RTE_LIBRTE_I40E_PMD
9498         struct rte_pmd_i40e_queue_region_conf region_conf;
9499         enum rte_pmd_i40e_queue_region_op op_type;
9500 #endif
9501
9502         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9503                 return;
9504
9505 #ifdef RTE_LIBRTE_I40E_PMD
9506         memset(&region_conf, 0, sizeof(region_conf));
9507         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9508         region_conf.user_priority = res->user_priority_id;
9509         region_conf.region_id = res->region_id;
9510
9511         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9512                                 op_type, &region_conf);
9513 #endif
9514
9515         switch (ret) {
9516         case 0:
9517                 break;
9518         case -ENOTSUP:
9519                 printf("function not implemented or supported\n");
9520                 break;
9521         default:
9522                 printf("user_priority region config error: (%s)\n",
9523                                 strerror(-ret));
9524         }
9525 }
9526
9527 cmdline_parse_token_string_t cmd_user_priority_region_set =
9528         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9529                                 set, "set");
9530 cmdline_parse_token_string_t cmd_user_priority_region_port =
9531         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9532                                 port, "port");
9533 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9534         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9535                                 port_id, UINT16);
9536 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9537         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9538                                 cmd, "queue-region");
9539 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9540         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9541                                 user_priority, "UP");
9542 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9543         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9544                                 user_priority_id, UINT8);
9545 cmdline_parse_token_string_t cmd_user_priority_region_region =
9546         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9547                                 region, "region_id");
9548 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9549         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9550                                 region_id, UINT8);
9551
9552 cmdline_parse_inst_t cmd_user_priority_region = {
9553         .f = cmd_user_priority_region_parsed,
9554         .data = NULL,
9555         .help_str = "set port <port_id> queue-region UP <value> "
9556                 "region_id <value>: Set the mapping of User Priority (UP) "
9557                 "to queue region (region_id) ",
9558         .tokens = {
9559                 (void *)&cmd_user_priority_region_set,
9560                 (void *)&cmd_user_priority_region_port,
9561                 (void *)&cmd_user_priority_region_port_index,
9562                 (void *)&cmd_user_priority_region_cmd,
9563                 (void *)&cmd_user_priority_region_UP,
9564                 (void *)&cmd_user_priority_region_UP_id,
9565                 (void *)&cmd_user_priority_region_region,
9566                 (void *)&cmd_user_priority_region_region_id,
9567                 NULL,
9568         },
9569 };
9570
9571 /* *** flush all queue region related configuration *** */
9572 struct cmd_flush_queue_region_result {
9573         cmdline_fixed_string_t set;
9574         cmdline_fixed_string_t port;
9575         portid_t port_id;
9576         cmdline_fixed_string_t cmd;
9577         cmdline_fixed_string_t flush;
9578         cmdline_fixed_string_t what;
9579 };
9580
9581 static void
9582 cmd_flush_queue_region_parsed(void *parsed_result,
9583                         __attribute__((unused)) struct cmdline *cl,
9584                         __attribute__((unused)) void *data)
9585 {
9586         struct cmd_flush_queue_region_result *res = parsed_result;
9587         int ret = -ENOTSUP;
9588 #ifdef RTE_LIBRTE_I40E_PMD
9589         struct rte_pmd_i40e_queue_region_conf region_conf;
9590         enum rte_pmd_i40e_queue_region_op op_type;
9591 #endif
9592
9593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9594                 return;
9595
9596 #ifdef RTE_LIBRTE_I40E_PMD
9597         memset(&region_conf, 0, sizeof(region_conf));
9598
9599         if (strcmp(res->what, "on") == 0)
9600                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9601         else
9602                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9603
9604         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9605                                 op_type, &region_conf);
9606 #endif
9607
9608         switch (ret) {
9609         case 0:
9610                 break;
9611         case -ENOTSUP:
9612                 printf("function not implemented or supported\n");
9613                 break;
9614         default:
9615                 printf("queue region config flush error: (%s)\n",
9616                                 strerror(-ret));
9617         }
9618 }
9619
9620 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9621         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9622                                 set, "set");
9623 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9624         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9625                                 port, "port");
9626 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9627         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9628                                 port_id, UINT16);
9629 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9630         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9631                                 cmd, "queue-region");
9632 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9633         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9634                                 flush, "flush");
9635 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9636         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9637                                 what, "on#off");
9638
9639 cmdline_parse_inst_t cmd_flush_queue_region = {
9640         .f = cmd_flush_queue_region_parsed,
9641         .data = NULL,
9642         .help_str = "set port <port_id> queue-region flush on|off"
9643                 ": flush all queue region related configuration",
9644         .tokens = {
9645                 (void *)&cmd_flush_queue_region_set,
9646                 (void *)&cmd_flush_queue_region_port,
9647                 (void *)&cmd_flush_queue_region_port_index,
9648                 (void *)&cmd_flush_queue_region_cmd,
9649                 (void *)&cmd_flush_queue_region_flush,
9650                 (void *)&cmd_flush_queue_region_what,
9651                 NULL,
9652         },
9653 };
9654
9655 /* *** get all queue region related configuration info *** */
9656 struct cmd_show_queue_region_info {
9657         cmdline_fixed_string_t show;
9658         cmdline_fixed_string_t port;
9659         portid_t port_id;
9660         cmdline_fixed_string_t cmd;
9661 };
9662
9663 static void
9664 cmd_show_queue_region_info_parsed(void *parsed_result,
9665                         __attribute__((unused)) struct cmdline *cl,
9666                         __attribute__((unused)) void *data)
9667 {
9668         struct cmd_show_queue_region_info *res = parsed_result;
9669         int ret = -ENOTSUP;
9670 #ifdef RTE_LIBRTE_I40E_PMD
9671         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9672         enum rte_pmd_i40e_queue_region_op op_type;
9673 #endif
9674
9675         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9676                 return;
9677
9678 #ifdef RTE_LIBRTE_I40E_PMD
9679         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9680
9681         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9682
9683         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9684                                         op_type, &rte_pmd_regions);
9685
9686         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9687 #endif
9688
9689         switch (ret) {
9690         case 0:
9691                 break;
9692         case -ENOTSUP:
9693                 printf("function not implemented or supported\n");
9694                 break;
9695         default:
9696                 printf("queue region config info show error: (%s)\n",
9697                                 strerror(-ret));
9698         }
9699 }
9700
9701 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9702 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9703                                 show, "show");
9704 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9705         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9706                                 port, "port");
9707 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9708         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9709                                 port_id, UINT16);
9710 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9711         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9712                                 cmd, "queue-region");
9713
9714 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9715         .f = cmd_show_queue_region_info_parsed,
9716         .data = NULL,
9717         .help_str = "show port <port_id> queue-region"
9718                 ": show all queue region related configuration info",
9719         .tokens = {
9720                 (void *)&cmd_show_queue_region_info_get,
9721                 (void *)&cmd_show_queue_region_info_port,
9722                 (void *)&cmd_show_queue_region_info_port_index,
9723                 (void *)&cmd_show_queue_region_info_cmd,
9724                 NULL,
9725         },
9726 };
9727
9728 /* *** ADD/REMOVE A 2tuple FILTER *** */
9729 struct cmd_2tuple_filter_result {
9730         cmdline_fixed_string_t filter;
9731         portid_t port_id;
9732         cmdline_fixed_string_t ops;
9733         cmdline_fixed_string_t dst_port;
9734         uint16_t dst_port_value;
9735         cmdline_fixed_string_t protocol;
9736         uint8_t protocol_value;
9737         cmdline_fixed_string_t mask;
9738         uint8_t  mask_value;
9739         cmdline_fixed_string_t tcp_flags;
9740         uint8_t tcp_flags_value;
9741         cmdline_fixed_string_t priority;
9742         uint8_t  priority_value;
9743         cmdline_fixed_string_t queue;
9744         uint16_t  queue_id;
9745 };
9746
9747 static void
9748 cmd_2tuple_filter_parsed(void *parsed_result,
9749                         __attribute__((unused)) struct cmdline *cl,
9750                         __attribute__((unused)) void *data)
9751 {
9752         struct rte_eth_ntuple_filter filter;
9753         struct cmd_2tuple_filter_result *res = parsed_result;
9754         int ret = 0;
9755
9756         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9757         if (ret < 0) {
9758                 printf("ntuple filter is not supported on port %u.\n",
9759                         res->port_id);
9760                 return;
9761         }
9762
9763         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9764
9765         filter.flags = RTE_2TUPLE_FLAGS;
9766         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9767         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9768         filter.proto = res->protocol_value;
9769         filter.priority = res->priority_value;
9770         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9771                 printf("nonzero tcp_flags is only meaningful"
9772                         " when protocol is TCP.\n");
9773                 return;
9774         }
9775         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9776                 printf("invalid TCP flags.\n");
9777                 return;
9778         }
9779
9780         if (res->tcp_flags_value != 0) {
9781                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9782                 filter.tcp_flags = res->tcp_flags_value;
9783         }
9784
9785         /* need convert to big endian. */
9786         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9787         filter.queue = res->queue_id;
9788
9789         if (!strcmp(res->ops, "add"))
9790                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9791                                 RTE_ETH_FILTER_NTUPLE,
9792                                 RTE_ETH_FILTER_ADD,
9793                                 &filter);
9794         else
9795                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9796                                 RTE_ETH_FILTER_NTUPLE,
9797                                 RTE_ETH_FILTER_DELETE,
9798                                 &filter);
9799         if (ret < 0)
9800                 printf("2tuple filter programming error: (%s)\n",
9801                         strerror(-ret));
9802
9803 }
9804
9805 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9806         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9807                                  filter, "2tuple_filter");
9808 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9809         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9810                                 port_id, UINT16);
9811 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9812         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9813                                  ops, "add#del");
9814 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9815         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9816                                 dst_port, "dst_port");
9817 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9818         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9819                                 dst_port_value, UINT16);
9820 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9821         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9822                                 protocol, "protocol");
9823 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9824         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9825                                 protocol_value, UINT8);
9826 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9827         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9828                                 mask, "mask");
9829 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9830         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9831                                 mask_value, INT8);
9832 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9833         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9834                                 tcp_flags, "tcp_flags");
9835 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9836         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9837                                 tcp_flags_value, UINT8);
9838 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9839         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9840                                 priority, "priority");
9841 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9842         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9843                                 priority_value, UINT8);
9844 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9845         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9846                                 queue, "queue");
9847 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9848         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9849                                 queue_id, UINT16);
9850
9851 cmdline_parse_inst_t cmd_2tuple_filter = {
9852         .f = cmd_2tuple_filter_parsed,
9853         .data = NULL,
9854         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9855                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9856                 "<queue_id>: Add a 2tuple filter",
9857         .tokens = {
9858                 (void *)&cmd_2tuple_filter_filter,
9859                 (void *)&cmd_2tuple_filter_port_id,
9860                 (void *)&cmd_2tuple_filter_ops,
9861                 (void *)&cmd_2tuple_filter_dst_port,
9862                 (void *)&cmd_2tuple_filter_dst_port_value,
9863                 (void *)&cmd_2tuple_filter_protocol,
9864                 (void *)&cmd_2tuple_filter_protocol_value,
9865                 (void *)&cmd_2tuple_filter_mask,
9866                 (void *)&cmd_2tuple_filter_mask_value,
9867                 (void *)&cmd_2tuple_filter_tcp_flags,
9868                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9869                 (void *)&cmd_2tuple_filter_priority,
9870                 (void *)&cmd_2tuple_filter_priority_value,
9871                 (void *)&cmd_2tuple_filter_queue,
9872                 (void *)&cmd_2tuple_filter_queue_id,
9873                 NULL,
9874         },
9875 };
9876
9877 /* *** ADD/REMOVE A 5tuple FILTER *** */
9878 struct cmd_5tuple_filter_result {
9879         cmdline_fixed_string_t filter;
9880         portid_t port_id;
9881         cmdline_fixed_string_t ops;
9882         cmdline_fixed_string_t dst_ip;
9883         cmdline_ipaddr_t dst_ip_value;
9884         cmdline_fixed_string_t src_ip;
9885         cmdline_ipaddr_t src_ip_value;
9886         cmdline_fixed_string_t dst_port;
9887         uint16_t dst_port_value;
9888         cmdline_fixed_string_t src_port;
9889         uint16_t src_port_value;
9890         cmdline_fixed_string_t protocol;
9891         uint8_t protocol_value;
9892         cmdline_fixed_string_t mask;
9893         uint8_t  mask_value;
9894         cmdline_fixed_string_t tcp_flags;
9895         uint8_t tcp_flags_value;
9896         cmdline_fixed_string_t priority;
9897         uint8_t  priority_value;
9898         cmdline_fixed_string_t queue;
9899         uint16_t  queue_id;
9900 };
9901
9902 static void
9903 cmd_5tuple_filter_parsed(void *parsed_result,
9904                         __attribute__((unused)) struct cmdline *cl,
9905                         __attribute__((unused)) void *data)
9906 {
9907         struct rte_eth_ntuple_filter filter;
9908         struct cmd_5tuple_filter_result *res = parsed_result;
9909         int ret = 0;
9910
9911         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9912         if (ret < 0) {
9913                 printf("ntuple filter is not supported on port %u.\n",
9914                         res->port_id);
9915                 return;
9916         }
9917
9918         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9919
9920         filter.flags = RTE_5TUPLE_FLAGS;
9921         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9922         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9923         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9924         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9925         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9926         filter.proto = res->protocol_value;
9927         filter.priority = res->priority_value;
9928         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9929                 printf("nonzero tcp_flags is only meaningful"
9930                         " when protocol is TCP.\n");
9931                 return;
9932         }
9933         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9934                 printf("invalid TCP flags.\n");
9935                 return;
9936         }
9937
9938         if (res->tcp_flags_value != 0) {
9939                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9940                 filter.tcp_flags = res->tcp_flags_value;
9941         }
9942
9943         if (res->dst_ip_value.family == AF_INET)
9944                 /* no need to convert, already big endian. */
9945                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9946         else {
9947                 if (filter.dst_ip_mask == 0) {
9948                         printf("can not support ipv6 involved compare.\n");
9949                         return;
9950                 }
9951                 filter.dst_ip = 0;
9952         }
9953
9954         if (res->src_ip_value.family == AF_INET)
9955                 /* no need to convert, already big endian. */
9956                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9957         else {
9958                 if (filter.src_ip_mask == 0) {
9959                         printf("can not support ipv6 involved compare.\n");
9960                         return;
9961                 }
9962                 filter.src_ip = 0;
9963         }
9964         /* need convert to big endian. */
9965         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9966         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9967         filter.queue = res->queue_id;
9968
9969         if (!strcmp(res->ops, "add"))
9970                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9971                                 RTE_ETH_FILTER_NTUPLE,
9972                                 RTE_ETH_FILTER_ADD,
9973                                 &filter);
9974         else
9975                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9976                                 RTE_ETH_FILTER_NTUPLE,
9977                                 RTE_ETH_FILTER_DELETE,
9978                                 &filter);
9979         if (ret < 0)
9980                 printf("5tuple filter programming error: (%s)\n",
9981                         strerror(-ret));
9982 }
9983
9984 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9985         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9986                                  filter, "5tuple_filter");
9987 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9988         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9989                                 port_id, UINT16);
9990 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9991         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9992                                  ops, "add#del");
9993 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9994         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9995                                 dst_ip, "dst_ip");
9996 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9997         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9998                                 dst_ip_value);
9999 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10000         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10001                                 src_ip, "src_ip");
10002 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10003         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10004                                 src_ip_value);
10005 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10006         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10007                                 dst_port, "dst_port");
10008 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10009         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10010                                 dst_port_value, UINT16);
10011 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10012         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10013                                 src_port, "src_port");
10014 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10015         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10016                                 src_port_value, UINT16);
10017 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10018         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10019                                 protocol, "protocol");
10020 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10021         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10022                                 protocol_value, UINT8);
10023 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10024         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10025                                 mask, "mask");
10026 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10027         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10028                                 mask_value, INT8);
10029 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10030         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10031                                 tcp_flags, "tcp_flags");
10032 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10033         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10034                                 tcp_flags_value, UINT8);
10035 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10036         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10037                                 priority, "priority");
10038 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10039         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10040                                 priority_value, UINT8);
10041 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10042         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10043                                 queue, "queue");
10044 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10045         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10046                                 queue_id, UINT16);
10047
10048 cmdline_parse_inst_t cmd_5tuple_filter = {
10049         .f = cmd_5tuple_filter_parsed,
10050         .data = NULL,
10051         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10052                 "src_ip <value> dst_port <value> src_port <value> "
10053                 "protocol <value>  mask <value> tcp_flags <value> "
10054                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10055         .tokens = {
10056                 (void *)&cmd_5tuple_filter_filter,
10057                 (void *)&cmd_5tuple_filter_port_id,
10058                 (void *)&cmd_5tuple_filter_ops,
10059                 (void *)&cmd_5tuple_filter_dst_ip,
10060                 (void *)&cmd_5tuple_filter_dst_ip_value,
10061                 (void *)&cmd_5tuple_filter_src_ip,
10062                 (void *)&cmd_5tuple_filter_src_ip_value,
10063                 (void *)&cmd_5tuple_filter_dst_port,
10064                 (void *)&cmd_5tuple_filter_dst_port_value,
10065                 (void *)&cmd_5tuple_filter_src_port,
10066                 (void *)&cmd_5tuple_filter_src_port_value,
10067                 (void *)&cmd_5tuple_filter_protocol,
10068                 (void *)&cmd_5tuple_filter_protocol_value,
10069                 (void *)&cmd_5tuple_filter_mask,
10070                 (void *)&cmd_5tuple_filter_mask_value,
10071                 (void *)&cmd_5tuple_filter_tcp_flags,
10072                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10073                 (void *)&cmd_5tuple_filter_priority,
10074                 (void *)&cmd_5tuple_filter_priority_value,
10075                 (void *)&cmd_5tuple_filter_queue,
10076                 (void *)&cmd_5tuple_filter_queue_id,
10077                 NULL,
10078         },
10079 };
10080
10081 /* *** ADD/REMOVE A flex FILTER *** */
10082 struct cmd_flex_filter_result {
10083         cmdline_fixed_string_t filter;
10084         cmdline_fixed_string_t ops;
10085         portid_t port_id;
10086         cmdline_fixed_string_t len;
10087         uint8_t len_value;
10088         cmdline_fixed_string_t bytes;
10089         cmdline_fixed_string_t bytes_value;
10090         cmdline_fixed_string_t mask;
10091         cmdline_fixed_string_t mask_value;
10092         cmdline_fixed_string_t priority;
10093         uint8_t priority_value;
10094         cmdline_fixed_string_t queue;
10095         uint16_t queue_id;
10096 };
10097
10098 static int xdigit2val(unsigned char c)
10099 {
10100         int val;
10101         if (isdigit(c))
10102                 val = c - '0';
10103         else if (isupper(c))
10104                 val = c - 'A' + 10;
10105         else
10106                 val = c - 'a' + 10;
10107         return val;
10108 }
10109
10110 static void
10111 cmd_flex_filter_parsed(void *parsed_result,
10112                           __attribute__((unused)) struct cmdline *cl,
10113                           __attribute__((unused)) void *data)
10114 {
10115         int ret = 0;
10116         struct rte_eth_flex_filter filter;
10117         struct cmd_flex_filter_result *res = parsed_result;
10118         char *bytes_ptr, *mask_ptr;
10119         uint16_t len, i, j = 0;
10120         char c;
10121         int val;
10122         uint8_t byte = 0;
10123
10124         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10125                 printf("the len exceed the max length 128\n");
10126                 return;
10127         }
10128         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10129         filter.len = res->len_value;
10130         filter.priority = res->priority_value;
10131         filter.queue = res->queue_id;
10132         bytes_ptr = res->bytes_value;
10133         mask_ptr = res->mask_value;
10134
10135          /* translate bytes string to array. */
10136         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10137                 (bytes_ptr[1] == 'X')))
10138                 bytes_ptr += 2;
10139         len = strnlen(bytes_ptr, res->len_value * 2);
10140         if (len == 0 || (len % 8 != 0)) {
10141                 printf("please check len and bytes input\n");
10142                 return;
10143         }
10144         for (i = 0; i < len; i++) {
10145                 c = bytes_ptr[i];
10146                 if (isxdigit(c) == 0) {
10147                         /* invalid characters. */
10148                         printf("invalid input\n");
10149                         return;
10150                 }
10151                 val = xdigit2val(c);
10152                 if (i % 2) {
10153                         byte |= val;
10154                         filter.bytes[j] = byte;
10155                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10156                         j++;
10157                         byte = 0;
10158                 } else
10159                         byte |= val << 4;
10160         }
10161         printf("\n");
10162          /* translate mask string to uint8_t array. */
10163         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10164                 (mask_ptr[1] == 'X')))
10165                 mask_ptr += 2;
10166         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10167         if (len == 0) {
10168                 printf("invalid input\n");
10169                 return;
10170         }
10171         j = 0;
10172         byte = 0;
10173         for (i = 0; i < len; i++) {
10174                 c = mask_ptr[i];
10175                 if (isxdigit(c) == 0) {
10176                         /* invalid characters. */
10177                         printf("invalid input\n");
10178                         return;
10179                 }
10180                 val = xdigit2val(c);
10181                 if (i % 2) {
10182                         byte |= val;
10183                         filter.mask[j] = byte;
10184                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10185                         j++;
10186                         byte = 0;
10187                 } else
10188                         byte |= val << 4;
10189         }
10190         printf("\n");
10191
10192         if (!strcmp(res->ops, "add"))
10193                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10194                                 RTE_ETH_FILTER_FLEXIBLE,
10195                                 RTE_ETH_FILTER_ADD,
10196                                 &filter);
10197         else
10198                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10199                                 RTE_ETH_FILTER_FLEXIBLE,
10200                                 RTE_ETH_FILTER_DELETE,
10201                                 &filter);
10202
10203         if (ret < 0)
10204                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10205 }
10206
10207 cmdline_parse_token_string_t cmd_flex_filter_filter =
10208         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10209                                 filter, "flex_filter");
10210 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10211         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10212                                 port_id, UINT16);
10213 cmdline_parse_token_string_t cmd_flex_filter_ops =
10214         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10215                                 ops, "add#del");
10216 cmdline_parse_token_string_t cmd_flex_filter_len =
10217         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10218                                 len, "len");
10219 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10220         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10221                                 len_value, UINT8);
10222 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10223         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10224                                 bytes, "bytes");
10225 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10226         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10227                                 bytes_value, NULL);
10228 cmdline_parse_token_string_t cmd_flex_filter_mask =
10229         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10230                                 mask, "mask");
10231 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10232         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10233                                 mask_value, NULL);
10234 cmdline_parse_token_string_t cmd_flex_filter_priority =
10235         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10236                                 priority, "priority");
10237 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10238         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10239                                 priority_value, UINT8);
10240 cmdline_parse_token_string_t cmd_flex_filter_queue =
10241         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10242                                 queue, "queue");
10243 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10244         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10245                                 queue_id, UINT16);
10246 cmdline_parse_inst_t cmd_flex_filter = {
10247         .f = cmd_flex_filter_parsed,
10248         .data = NULL,
10249         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10250                 "<value> mask <value> priority <value> queue <queue_id>: "
10251                 "Add/Del a flex filter",
10252         .tokens = {
10253                 (void *)&cmd_flex_filter_filter,
10254                 (void *)&cmd_flex_filter_port_id,
10255                 (void *)&cmd_flex_filter_ops,
10256                 (void *)&cmd_flex_filter_len,
10257                 (void *)&cmd_flex_filter_len_value,
10258                 (void *)&cmd_flex_filter_bytes,
10259                 (void *)&cmd_flex_filter_bytes_value,
10260                 (void *)&cmd_flex_filter_mask,
10261                 (void *)&cmd_flex_filter_mask_value,
10262                 (void *)&cmd_flex_filter_priority,
10263                 (void *)&cmd_flex_filter_priority_value,
10264                 (void *)&cmd_flex_filter_queue,
10265                 (void *)&cmd_flex_filter_queue_id,
10266                 NULL,
10267         },
10268 };
10269
10270 /* *** Filters Control *** */
10271
10272 /* *** deal with ethertype filter *** */
10273 struct cmd_ethertype_filter_result {
10274         cmdline_fixed_string_t filter;
10275         portid_t port_id;
10276         cmdline_fixed_string_t ops;
10277         cmdline_fixed_string_t mac;
10278         struct ether_addr mac_addr;
10279         cmdline_fixed_string_t ethertype;
10280         uint16_t ethertype_value;
10281         cmdline_fixed_string_t drop;
10282         cmdline_fixed_string_t queue;
10283         uint16_t  queue_id;
10284 };
10285
10286 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10287         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10288                                  filter, "ethertype_filter");
10289 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10290         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10291                               port_id, UINT16);
10292 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10293         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10294                                  ops, "add#del");
10295 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10296         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10297                                  mac, "mac_addr#mac_ignr");
10298 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10299         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10300                                      mac_addr);
10301 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10302         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10303                                  ethertype, "ethertype");
10304 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10305         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10306                               ethertype_value, UINT16);
10307 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10308         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10309                                  drop, "drop#fwd");
10310 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10311         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10312                                  queue, "queue");
10313 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10314         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10315                               queue_id, UINT16);
10316
10317 static void
10318 cmd_ethertype_filter_parsed(void *parsed_result,
10319                           __attribute__((unused)) struct cmdline *cl,
10320                           __attribute__((unused)) void *data)
10321 {
10322         struct cmd_ethertype_filter_result *res = parsed_result;
10323         struct rte_eth_ethertype_filter filter;
10324         int ret = 0;
10325
10326         ret = rte_eth_dev_filter_supported(res->port_id,
10327                         RTE_ETH_FILTER_ETHERTYPE);
10328         if (ret < 0) {
10329                 printf("ethertype filter is not supported on port %u.\n",
10330                         res->port_id);
10331                 return;
10332         }
10333
10334         memset(&filter, 0, sizeof(filter));
10335         if (!strcmp(res->mac, "mac_addr")) {
10336                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10337                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10338                         sizeof(struct ether_addr));
10339         }
10340         if (!strcmp(res->drop, "drop"))
10341                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10342         filter.ether_type = res->ethertype_value;
10343         filter.queue = res->queue_id;
10344
10345         if (!strcmp(res->ops, "add"))
10346                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10347                                 RTE_ETH_FILTER_ETHERTYPE,
10348                                 RTE_ETH_FILTER_ADD,
10349                                 &filter);
10350         else
10351                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10352                                 RTE_ETH_FILTER_ETHERTYPE,
10353                                 RTE_ETH_FILTER_DELETE,
10354                                 &filter);
10355         if (ret < 0)
10356                 printf("ethertype filter programming error: (%s)\n",
10357                         strerror(-ret));
10358 }
10359
10360 cmdline_parse_inst_t cmd_ethertype_filter = {
10361         .f = cmd_ethertype_filter_parsed,
10362         .data = NULL,
10363         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10364                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10365                 "Add or delete an ethertype filter entry",
10366         .tokens = {
10367                 (void *)&cmd_ethertype_filter_filter,
10368                 (void *)&cmd_ethertype_filter_port_id,
10369                 (void *)&cmd_ethertype_filter_ops,
10370                 (void *)&cmd_ethertype_filter_mac,
10371                 (void *)&cmd_ethertype_filter_mac_addr,
10372                 (void *)&cmd_ethertype_filter_ethertype,
10373                 (void *)&cmd_ethertype_filter_ethertype_value,
10374                 (void *)&cmd_ethertype_filter_drop,
10375                 (void *)&cmd_ethertype_filter_queue,
10376                 (void *)&cmd_ethertype_filter_queue_id,
10377                 NULL,
10378         },
10379 };
10380
10381 /* *** deal with flow director filter *** */
10382 struct cmd_flow_director_result {
10383         cmdline_fixed_string_t flow_director_filter;
10384         portid_t port_id;
10385         cmdline_fixed_string_t mode;
10386         cmdline_fixed_string_t mode_value;
10387         cmdline_fixed_string_t ops;
10388         cmdline_fixed_string_t flow;
10389         cmdline_fixed_string_t flow_type;
10390         cmdline_fixed_string_t ether;
10391         uint16_t ether_type;
10392         cmdline_fixed_string_t src;
10393         cmdline_ipaddr_t ip_src;
10394         uint16_t port_src;
10395         cmdline_fixed_string_t dst;
10396         cmdline_ipaddr_t ip_dst;
10397         uint16_t port_dst;
10398         cmdline_fixed_string_t verify_tag;
10399         uint32_t verify_tag_value;
10400         cmdline_fixed_string_t tos;
10401         uint8_t tos_value;
10402         cmdline_fixed_string_t proto;
10403         uint8_t proto_value;
10404         cmdline_fixed_string_t ttl;
10405         uint8_t ttl_value;
10406         cmdline_fixed_string_t vlan;
10407         uint16_t vlan_value;
10408         cmdline_fixed_string_t flexbytes;
10409         cmdline_fixed_string_t flexbytes_value;
10410         cmdline_fixed_string_t pf_vf;
10411         cmdline_fixed_string_t drop;
10412         cmdline_fixed_string_t queue;
10413         uint16_t  queue_id;
10414         cmdline_fixed_string_t fd_id;
10415         uint32_t  fd_id_value;
10416         cmdline_fixed_string_t mac;
10417         struct ether_addr mac_addr;
10418         cmdline_fixed_string_t tunnel;
10419         cmdline_fixed_string_t tunnel_type;
10420         cmdline_fixed_string_t tunnel_id;
10421         uint32_t tunnel_id_value;
10422         cmdline_fixed_string_t packet;
10423         char filepath[];
10424 };
10425
10426 static inline int
10427 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10428 {
10429         char s[256];
10430         const char *p, *p0 = q_arg;
10431         char *end;
10432         unsigned long int_fld;
10433         char *str_fld[max_num];
10434         int i;
10435         unsigned size;
10436         int ret = -1;
10437
10438         p = strchr(p0, '(');
10439         if (p == NULL)
10440                 return -1;
10441         ++p;
10442         p0 = strchr(p, ')');
10443         if (p0 == NULL)
10444                 return -1;
10445
10446         size = p0 - p;
10447         if (size >= sizeof(s))
10448                 return -1;
10449
10450         snprintf(s, sizeof(s), "%.*s", size, p);
10451         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10452         if (ret < 0 || ret > max_num)
10453                 return -1;
10454         for (i = 0; i < ret; i++) {
10455                 errno = 0;
10456                 int_fld = strtoul(str_fld[i], &end, 0);
10457                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10458                         return -1;
10459                 flexbytes[i] = (uint8_t)int_fld;
10460         }
10461         return ret;
10462 }
10463
10464 static uint16_t
10465 str2flowtype(char *string)
10466 {
10467         uint8_t i = 0;
10468         static const struct {
10469                 char str[32];
10470                 uint16_t type;
10471         } flowtype_str[] = {
10472                 {"raw", RTE_ETH_FLOW_RAW},
10473                 {"ipv4", RTE_ETH_FLOW_IPV4},
10474                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10475                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10476                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10477                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10478                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10479                 {"ipv6", RTE_ETH_FLOW_IPV6},
10480                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10481                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10482                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10483                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10484                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10485                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10486         };
10487
10488         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10489                 if (!strcmp(flowtype_str[i].str, string))
10490                         return flowtype_str[i].type;
10491         }
10492
10493         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10494                 return (uint16_t)atoi(string);
10495
10496         return RTE_ETH_FLOW_UNKNOWN;
10497 }
10498
10499 static enum rte_eth_fdir_tunnel_type
10500 str2fdir_tunneltype(char *string)
10501 {
10502         uint8_t i = 0;
10503
10504         static const struct {
10505                 char str[32];
10506                 enum rte_eth_fdir_tunnel_type type;
10507         } tunneltype_str[] = {
10508                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10509                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10510         };
10511
10512         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10513                 if (!strcmp(tunneltype_str[i].str, string))
10514                         return tunneltype_str[i].type;
10515         }
10516         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10517 }
10518
10519 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10520 do { \
10521         if ((ip_addr).family == AF_INET) \
10522                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10523         else { \
10524                 printf("invalid parameter.\n"); \
10525                 return; \
10526         } \
10527 } while (0)
10528
10529 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10530 do { \
10531         if ((ip_addr).family == AF_INET6) \
10532                 rte_memcpy(&(ip), \
10533                                  &((ip_addr).addr.ipv6), \
10534                                  sizeof(struct in6_addr)); \
10535         else { \
10536                 printf("invalid parameter.\n"); \
10537                 return; \
10538         } \
10539 } while (0)
10540
10541 static void
10542 cmd_flow_director_filter_parsed(void *parsed_result,
10543                           __attribute__((unused)) struct cmdline *cl,
10544                           __attribute__((unused)) void *data)
10545 {
10546         struct cmd_flow_director_result *res = parsed_result;
10547         struct rte_eth_fdir_filter entry;
10548         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10549         char *end;
10550         unsigned long vf_id;
10551         int ret = 0;
10552
10553         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10554         if (ret < 0) {
10555                 printf("flow director is not supported on port %u.\n",
10556                         res->port_id);
10557                 return;
10558         }
10559         memset(flexbytes, 0, sizeof(flexbytes));
10560         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10561
10562         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10563                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10564                         printf("Please set mode to MAC-VLAN.\n");
10565                         return;
10566                 }
10567         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10568                 if (strcmp(res->mode_value, "Tunnel")) {
10569                         printf("Please set mode to Tunnel.\n");
10570                         return;
10571                 }
10572         } else {
10573                 if (!strcmp(res->mode_value, "raw")) {
10574 #ifdef RTE_LIBRTE_I40E_PMD
10575                         struct rte_pmd_i40e_flow_type_mapping
10576                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10577                         struct rte_pmd_i40e_pkt_template_conf conf;
10578                         uint16_t flow_type = str2flowtype(res->flow_type);
10579                         uint16_t i, port = res->port_id;
10580                         uint8_t add;
10581
10582                         memset(&conf, 0, sizeof(conf));
10583
10584                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10585                                 printf("Invalid flow type specified.\n");
10586                                 return;
10587                         }
10588                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10589                                                                  mapping);
10590                         if (ret)
10591                                 return;
10592                         if (mapping[flow_type].pctype == 0ULL) {
10593                                 printf("Invalid flow type specified.\n");
10594                                 return;
10595                         }
10596                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10597                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10598                                         conf.input.pctype = i;
10599                                         break;
10600                                 }
10601                         }
10602
10603                         conf.input.packet = open_file(res->filepath,
10604                                                 &conf.input.length);
10605                         if (!conf.input.packet)
10606                                 return;
10607                         if (!strcmp(res->drop, "drop"))
10608                                 conf.action.behavior =
10609                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10610                         else
10611                                 conf.action.behavior =
10612                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10613                         conf.action.report_status =
10614                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10615                         conf.action.rx_queue = res->queue_id;
10616                         conf.soft_id = res->fd_id_value;
10617                         add  = strcmp(res->ops, "del") ? 1 : 0;
10618                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10619                                                                         &conf,
10620                                                                         add);
10621                         if (ret < 0)
10622                                 printf("flow director config error: (%s)\n",
10623                                        strerror(-ret));
10624                         close_file(conf.input.packet);
10625 #endif
10626                         return;
10627                 } else if (strcmp(res->mode_value, "IP")) {
10628                         printf("Please set mode to IP or raw.\n");
10629                         return;
10630                 }
10631                 entry.input.flow_type = str2flowtype(res->flow_type);
10632         }
10633
10634         ret = parse_flexbytes(res->flexbytes_value,
10635                                         flexbytes,
10636                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10637         if (ret < 0) {
10638                 printf("error: Cannot parse flexbytes input.\n");
10639                 return;
10640         }
10641
10642         switch (entry.input.flow_type) {
10643         case RTE_ETH_FLOW_FRAG_IPV4:
10644         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10645                 entry.input.flow.ip4_flow.proto = res->proto_value;
10646                 /* fall-through */
10647         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10648         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10649                 IPV4_ADDR_TO_UINT(res->ip_dst,
10650                         entry.input.flow.ip4_flow.dst_ip);
10651                 IPV4_ADDR_TO_UINT(res->ip_src,
10652                         entry.input.flow.ip4_flow.src_ip);
10653                 entry.input.flow.ip4_flow.tos = res->tos_value;
10654                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10655                 /* need convert to big endian. */
10656                 entry.input.flow.udp4_flow.dst_port =
10657                                 rte_cpu_to_be_16(res->port_dst);
10658                 entry.input.flow.udp4_flow.src_port =
10659                                 rte_cpu_to_be_16(res->port_src);
10660                 break;
10661         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10662                 IPV4_ADDR_TO_UINT(res->ip_dst,
10663                         entry.input.flow.sctp4_flow.ip.dst_ip);
10664                 IPV4_ADDR_TO_UINT(res->ip_src,
10665                         entry.input.flow.sctp4_flow.ip.src_ip);
10666                 entry.input.flow.ip4_flow.tos = res->tos_value;
10667                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10668                 /* need convert to big endian. */
10669                 entry.input.flow.sctp4_flow.dst_port =
10670                                 rte_cpu_to_be_16(res->port_dst);
10671                 entry.input.flow.sctp4_flow.src_port =
10672                                 rte_cpu_to_be_16(res->port_src);
10673                 entry.input.flow.sctp4_flow.verify_tag =
10674                                 rte_cpu_to_be_32(res->verify_tag_value);
10675                 break;
10676         case RTE_ETH_FLOW_FRAG_IPV6:
10677         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10678                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10679                 /* fall-through */
10680         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10681         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10682                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10683                         entry.input.flow.ipv6_flow.dst_ip);
10684                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10685                         entry.input.flow.ipv6_flow.src_ip);
10686                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10687                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10688                 /* need convert to big endian. */
10689                 entry.input.flow.udp6_flow.dst_port =
10690                                 rte_cpu_to_be_16(res->port_dst);
10691                 entry.input.flow.udp6_flow.src_port =
10692                                 rte_cpu_to_be_16(res->port_src);
10693                 break;
10694         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10695                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10696                         entry.input.flow.sctp6_flow.ip.dst_ip);
10697                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10698                         entry.input.flow.sctp6_flow.ip.src_ip);
10699                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10700                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10701                 /* need convert to big endian. */
10702                 entry.input.flow.sctp6_flow.dst_port =
10703                                 rte_cpu_to_be_16(res->port_dst);
10704                 entry.input.flow.sctp6_flow.src_port =
10705                                 rte_cpu_to_be_16(res->port_src);
10706                 entry.input.flow.sctp6_flow.verify_tag =
10707                                 rte_cpu_to_be_32(res->verify_tag_value);
10708                 break;
10709         case RTE_ETH_FLOW_L2_PAYLOAD:
10710                 entry.input.flow.l2_flow.ether_type =
10711                         rte_cpu_to_be_16(res->ether_type);
10712                 break;
10713         default:
10714                 break;
10715         }
10716
10717         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10718                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10719                                  &res->mac_addr,
10720                                  sizeof(struct ether_addr));
10721
10722         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10723                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10724                                  &res->mac_addr,
10725                                  sizeof(struct ether_addr));
10726                 entry.input.flow.tunnel_flow.tunnel_type =
10727                         str2fdir_tunneltype(res->tunnel_type);
10728                 entry.input.flow.tunnel_flow.tunnel_id =
10729                         rte_cpu_to_be_32(res->tunnel_id_value);
10730         }
10731
10732         rte_memcpy(entry.input.flow_ext.flexbytes,
10733                    flexbytes,
10734                    RTE_ETH_FDIR_MAX_FLEXLEN);
10735
10736         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10737
10738         entry.action.flex_off = 0;  /*use 0 by default */
10739         if (!strcmp(res->drop, "drop"))
10740                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10741         else
10742                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10743
10744         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10745             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10746                 if (!strcmp(res->pf_vf, "pf"))
10747                         entry.input.flow_ext.is_vf = 0;
10748                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10749                         struct rte_eth_dev_info dev_info;
10750
10751                         memset(&dev_info, 0, sizeof(dev_info));
10752                         rte_eth_dev_info_get(res->port_id, &dev_info);
10753                         errno = 0;
10754                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10755                         if (errno != 0 || *end != '\0' ||
10756                             vf_id >= dev_info.max_vfs) {
10757                                 printf("invalid parameter %s.\n", res->pf_vf);
10758                                 return;
10759                         }
10760                         entry.input.flow_ext.is_vf = 1;
10761                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10762                 } else {
10763                         printf("invalid parameter %s.\n", res->pf_vf);
10764                         return;
10765                 }
10766         }
10767
10768         /* set to report FD ID by default */
10769         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10770         entry.action.rx_queue = res->queue_id;
10771         entry.soft_id = res->fd_id_value;
10772         if (!strcmp(res->ops, "add"))
10773                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10774                                              RTE_ETH_FILTER_ADD, &entry);
10775         else if (!strcmp(res->ops, "del"))
10776                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10777                                              RTE_ETH_FILTER_DELETE, &entry);
10778         else
10779                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10780                                              RTE_ETH_FILTER_UPDATE, &entry);
10781         if (ret < 0)
10782                 printf("flow director programming error: (%s)\n",
10783                         strerror(-ret));
10784 }
10785
10786 cmdline_parse_token_string_t cmd_flow_director_filter =
10787         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10788                                  flow_director_filter, "flow_director_filter");
10789 cmdline_parse_token_num_t cmd_flow_director_port_id =
10790         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10791                               port_id, UINT16);
10792 cmdline_parse_token_string_t cmd_flow_director_ops =
10793         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10794                                  ops, "add#del#update");
10795 cmdline_parse_token_string_t cmd_flow_director_flow =
10796         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10797                                  flow, "flow");
10798 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10800                 flow_type, NULL);
10801 cmdline_parse_token_string_t cmd_flow_director_ether =
10802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10803                                  ether, "ether");
10804 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10805         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10806                               ether_type, UINT16);
10807 cmdline_parse_token_string_t cmd_flow_director_src =
10808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10809                                  src, "src");
10810 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10811         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10812                                  ip_src);
10813 cmdline_parse_token_num_t cmd_flow_director_port_src =
10814         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10815                               port_src, UINT16);
10816 cmdline_parse_token_string_t cmd_flow_director_dst =
10817         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10818                                  dst, "dst");
10819 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10820         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10821                                  ip_dst);
10822 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10823         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10824                               port_dst, UINT16);
10825 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10826         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10827                                   verify_tag, "verify_tag");
10828 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10829         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10830                               verify_tag_value, UINT32);
10831 cmdline_parse_token_string_t cmd_flow_director_tos =
10832         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10833                                  tos, "tos");
10834 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10835         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10836                               tos_value, UINT8);
10837 cmdline_parse_token_string_t cmd_flow_director_proto =
10838         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10839                                  proto, "proto");
10840 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10841         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10842                               proto_value, UINT8);
10843 cmdline_parse_token_string_t cmd_flow_director_ttl =
10844         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10845                                  ttl, "ttl");
10846 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10847         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10848                               ttl_value, UINT8);
10849 cmdline_parse_token_string_t cmd_flow_director_vlan =
10850         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10851                                  vlan, "vlan");
10852 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10853         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10854                               vlan_value, UINT16);
10855 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10856         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10857                                  flexbytes, "flexbytes");
10858 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10860                               flexbytes_value, NULL);
10861 cmdline_parse_token_string_t cmd_flow_director_drop =
10862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10863                                  drop, "drop#fwd");
10864 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10866                               pf_vf, NULL);
10867 cmdline_parse_token_string_t cmd_flow_director_queue =
10868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10869                                  queue, "queue");
10870 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10871         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10872                               queue_id, UINT16);
10873 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10875                                  fd_id, "fd_id");
10876 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10877         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10878                               fd_id_value, UINT32);
10879
10880 cmdline_parse_token_string_t cmd_flow_director_mode =
10881         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10882                                  mode, "mode");
10883 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10884         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10885                                  mode_value, "IP");
10886 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10887         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10888                                  mode_value, "MAC-VLAN");
10889 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10890         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10891                                  mode_value, "Tunnel");
10892 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10893         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10894                                  mode_value, "raw");
10895 cmdline_parse_token_string_t cmd_flow_director_mac =
10896         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10897                                  mac, "mac");
10898 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10899         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10900                                     mac_addr);
10901 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10902         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10903                                  tunnel, "tunnel");
10904 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10905         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10906                                  tunnel_type, "NVGRE#VxLAN");
10907 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10909                                  tunnel_id, "tunnel-id");
10910 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10911         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10912                               tunnel_id_value, UINT32);
10913 cmdline_parse_token_string_t cmd_flow_director_packet =
10914         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10915                                  packet, "packet");
10916 cmdline_parse_token_string_t cmd_flow_director_filepath =
10917         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10918                                  filepath, NULL);
10919
10920 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10921         .f = cmd_flow_director_filter_parsed,
10922         .data = NULL,
10923         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10924                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10925                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10926                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10927                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10928                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10929                 "fd_id <fd_id_value>: "
10930                 "Add or delete an ip flow director entry on NIC",
10931         .tokens = {
10932                 (void *)&cmd_flow_director_filter,
10933                 (void *)&cmd_flow_director_port_id,
10934                 (void *)&cmd_flow_director_mode,
10935                 (void *)&cmd_flow_director_mode_ip,
10936                 (void *)&cmd_flow_director_ops,
10937                 (void *)&cmd_flow_director_flow,
10938                 (void *)&cmd_flow_director_flow_type,
10939                 (void *)&cmd_flow_director_src,
10940                 (void *)&cmd_flow_director_ip_src,
10941                 (void *)&cmd_flow_director_dst,
10942                 (void *)&cmd_flow_director_ip_dst,
10943                 (void *)&cmd_flow_director_tos,
10944                 (void *)&cmd_flow_director_tos_value,
10945                 (void *)&cmd_flow_director_proto,
10946                 (void *)&cmd_flow_director_proto_value,
10947                 (void *)&cmd_flow_director_ttl,
10948                 (void *)&cmd_flow_director_ttl_value,
10949                 (void *)&cmd_flow_director_vlan,
10950                 (void *)&cmd_flow_director_vlan_value,
10951                 (void *)&cmd_flow_director_flexbytes,
10952                 (void *)&cmd_flow_director_flexbytes_value,
10953                 (void *)&cmd_flow_director_drop,
10954                 (void *)&cmd_flow_director_pf_vf,
10955                 (void *)&cmd_flow_director_queue,
10956                 (void *)&cmd_flow_director_queue_id,
10957                 (void *)&cmd_flow_director_fd_id,
10958                 (void *)&cmd_flow_director_fd_id_value,
10959                 NULL,
10960         },
10961 };
10962
10963 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10964         .f = cmd_flow_director_filter_parsed,
10965         .data = NULL,
10966         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10967                 "director entry on NIC",
10968         .tokens = {
10969                 (void *)&cmd_flow_director_filter,
10970                 (void *)&cmd_flow_director_port_id,
10971                 (void *)&cmd_flow_director_mode,
10972                 (void *)&cmd_flow_director_mode_ip,
10973                 (void *)&cmd_flow_director_ops,
10974                 (void *)&cmd_flow_director_flow,
10975                 (void *)&cmd_flow_director_flow_type,
10976                 (void *)&cmd_flow_director_src,
10977                 (void *)&cmd_flow_director_ip_src,
10978                 (void *)&cmd_flow_director_port_src,
10979                 (void *)&cmd_flow_director_dst,
10980                 (void *)&cmd_flow_director_ip_dst,
10981                 (void *)&cmd_flow_director_port_dst,
10982                 (void *)&cmd_flow_director_tos,
10983                 (void *)&cmd_flow_director_tos_value,
10984                 (void *)&cmd_flow_director_ttl,
10985                 (void *)&cmd_flow_director_ttl_value,
10986                 (void *)&cmd_flow_director_vlan,
10987                 (void *)&cmd_flow_director_vlan_value,
10988                 (void *)&cmd_flow_director_flexbytes,
10989                 (void *)&cmd_flow_director_flexbytes_value,
10990                 (void *)&cmd_flow_director_drop,
10991                 (void *)&cmd_flow_director_pf_vf,
10992                 (void *)&cmd_flow_director_queue,
10993                 (void *)&cmd_flow_director_queue_id,
10994                 (void *)&cmd_flow_director_fd_id,
10995                 (void *)&cmd_flow_director_fd_id_value,
10996                 NULL,
10997         },
10998 };
10999
11000 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11001         .f = cmd_flow_director_filter_parsed,
11002         .data = NULL,
11003         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11004                 "director entry on NIC",
11005         .tokens = {
11006                 (void *)&cmd_flow_director_filter,
11007                 (void *)&cmd_flow_director_port_id,
11008                 (void *)&cmd_flow_director_mode,
11009                 (void *)&cmd_flow_director_mode_ip,
11010                 (void *)&cmd_flow_director_ops,
11011                 (void *)&cmd_flow_director_flow,
11012                 (void *)&cmd_flow_director_flow_type,
11013                 (void *)&cmd_flow_director_src,
11014                 (void *)&cmd_flow_director_ip_src,
11015                 (void *)&cmd_flow_director_port_src,
11016                 (void *)&cmd_flow_director_dst,
11017                 (void *)&cmd_flow_director_ip_dst,
11018                 (void *)&cmd_flow_director_port_dst,
11019                 (void *)&cmd_flow_director_verify_tag,
11020                 (void *)&cmd_flow_director_verify_tag_value,
11021                 (void *)&cmd_flow_director_tos,
11022                 (void *)&cmd_flow_director_tos_value,
11023                 (void *)&cmd_flow_director_ttl,
11024                 (void *)&cmd_flow_director_ttl_value,
11025                 (void *)&cmd_flow_director_vlan,
11026                 (void *)&cmd_flow_director_vlan_value,
11027                 (void *)&cmd_flow_director_flexbytes,
11028                 (void *)&cmd_flow_director_flexbytes_value,
11029                 (void *)&cmd_flow_director_drop,
11030                 (void *)&cmd_flow_director_pf_vf,
11031                 (void *)&cmd_flow_director_queue,
11032                 (void *)&cmd_flow_director_queue_id,
11033                 (void *)&cmd_flow_director_fd_id,
11034                 (void *)&cmd_flow_director_fd_id_value,
11035                 NULL,
11036         },
11037 };
11038
11039 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11040         .f = cmd_flow_director_filter_parsed,
11041         .data = NULL,
11042         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11043                 "director entry on NIC",
11044         .tokens = {
11045                 (void *)&cmd_flow_director_filter,
11046                 (void *)&cmd_flow_director_port_id,
11047                 (void *)&cmd_flow_director_mode,
11048                 (void *)&cmd_flow_director_mode_ip,
11049                 (void *)&cmd_flow_director_ops,
11050                 (void *)&cmd_flow_director_flow,
11051                 (void *)&cmd_flow_director_flow_type,
11052                 (void *)&cmd_flow_director_ether,
11053                 (void *)&cmd_flow_director_ether_type,
11054                 (void *)&cmd_flow_director_flexbytes,
11055                 (void *)&cmd_flow_director_flexbytes_value,
11056                 (void *)&cmd_flow_director_drop,
11057                 (void *)&cmd_flow_director_pf_vf,
11058                 (void *)&cmd_flow_director_queue,
11059                 (void *)&cmd_flow_director_queue_id,
11060                 (void *)&cmd_flow_director_fd_id,
11061                 (void *)&cmd_flow_director_fd_id_value,
11062                 NULL,
11063         },
11064 };
11065
11066 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11067         .f = cmd_flow_director_filter_parsed,
11068         .data = NULL,
11069         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11070                 "director entry on NIC",
11071         .tokens = {
11072                 (void *)&cmd_flow_director_filter,
11073                 (void *)&cmd_flow_director_port_id,
11074                 (void *)&cmd_flow_director_mode,
11075                 (void *)&cmd_flow_director_mode_mac_vlan,
11076                 (void *)&cmd_flow_director_ops,
11077                 (void *)&cmd_flow_director_mac,
11078                 (void *)&cmd_flow_director_mac_addr,
11079                 (void *)&cmd_flow_director_vlan,
11080                 (void *)&cmd_flow_director_vlan_value,
11081                 (void *)&cmd_flow_director_flexbytes,
11082                 (void *)&cmd_flow_director_flexbytes_value,
11083                 (void *)&cmd_flow_director_drop,
11084                 (void *)&cmd_flow_director_queue,
11085                 (void *)&cmd_flow_director_queue_id,
11086                 (void *)&cmd_flow_director_fd_id,
11087                 (void *)&cmd_flow_director_fd_id_value,
11088                 NULL,
11089         },
11090 };
11091
11092 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11093         .f = cmd_flow_director_filter_parsed,
11094         .data = NULL,
11095         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11096                 "director entry on NIC",
11097         .tokens = {
11098                 (void *)&cmd_flow_director_filter,
11099                 (void *)&cmd_flow_director_port_id,
11100                 (void *)&cmd_flow_director_mode,
11101                 (void *)&cmd_flow_director_mode_tunnel,
11102                 (void *)&cmd_flow_director_ops,
11103                 (void *)&cmd_flow_director_mac,
11104                 (void *)&cmd_flow_director_mac_addr,
11105                 (void *)&cmd_flow_director_vlan,
11106                 (void *)&cmd_flow_director_vlan_value,
11107                 (void *)&cmd_flow_director_tunnel,
11108                 (void *)&cmd_flow_director_tunnel_type,
11109                 (void *)&cmd_flow_director_tunnel_id,
11110                 (void *)&cmd_flow_director_tunnel_id_value,
11111                 (void *)&cmd_flow_director_flexbytes,
11112                 (void *)&cmd_flow_director_flexbytes_value,
11113                 (void *)&cmd_flow_director_drop,
11114                 (void *)&cmd_flow_director_queue,
11115                 (void *)&cmd_flow_director_queue_id,
11116                 (void *)&cmd_flow_director_fd_id,
11117                 (void *)&cmd_flow_director_fd_id_value,
11118                 NULL,
11119         },
11120 };
11121
11122 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11123         .f = cmd_flow_director_filter_parsed,
11124         .data = NULL,
11125         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11126                 "director entry on NIC",
11127         .tokens = {
11128                 (void *)&cmd_flow_director_filter,
11129                 (void *)&cmd_flow_director_port_id,
11130                 (void *)&cmd_flow_director_mode,
11131                 (void *)&cmd_flow_director_mode_raw,
11132                 (void *)&cmd_flow_director_ops,
11133                 (void *)&cmd_flow_director_flow,
11134                 (void *)&cmd_flow_director_flow_type,
11135                 (void *)&cmd_flow_director_drop,
11136                 (void *)&cmd_flow_director_queue,
11137                 (void *)&cmd_flow_director_queue_id,
11138                 (void *)&cmd_flow_director_fd_id,
11139                 (void *)&cmd_flow_director_fd_id_value,
11140                 (void *)&cmd_flow_director_packet,
11141                 (void *)&cmd_flow_director_filepath,
11142                 NULL,
11143         },
11144 };
11145
11146 struct cmd_flush_flow_director_result {
11147         cmdline_fixed_string_t flush_flow_director;
11148         portid_t port_id;
11149 };
11150
11151 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11152         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11153                                  flush_flow_director, "flush_flow_director");
11154 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11155         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11156                               port_id, UINT16);
11157
11158 static void
11159 cmd_flush_flow_director_parsed(void *parsed_result,
11160                           __attribute__((unused)) struct cmdline *cl,
11161                           __attribute__((unused)) void *data)
11162 {
11163         struct cmd_flow_director_result *res = parsed_result;
11164         int ret = 0;
11165
11166         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11167         if (ret < 0) {
11168                 printf("flow director is not supported on port %u.\n",
11169                         res->port_id);
11170                 return;
11171         }
11172
11173         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11174                         RTE_ETH_FILTER_FLUSH, NULL);
11175         if (ret < 0)
11176                 printf("flow director table flushing error: (%s)\n",
11177                         strerror(-ret));
11178 }
11179
11180 cmdline_parse_inst_t cmd_flush_flow_director = {
11181         .f = cmd_flush_flow_director_parsed,
11182         .data = NULL,
11183         .help_str = "flush_flow_director <port_id>: "
11184                 "Flush all flow director entries of a device on NIC",
11185         .tokens = {
11186                 (void *)&cmd_flush_flow_director_flush,
11187                 (void *)&cmd_flush_flow_director_port_id,
11188                 NULL,
11189         },
11190 };
11191
11192 /* *** deal with flow director mask *** */
11193 struct cmd_flow_director_mask_result {
11194         cmdline_fixed_string_t flow_director_mask;
11195         portid_t port_id;
11196         cmdline_fixed_string_t mode;
11197         cmdline_fixed_string_t mode_value;
11198         cmdline_fixed_string_t vlan;
11199         uint16_t vlan_mask;
11200         cmdline_fixed_string_t src_mask;
11201         cmdline_ipaddr_t ipv4_src;
11202         cmdline_ipaddr_t ipv6_src;
11203         uint16_t port_src;
11204         cmdline_fixed_string_t dst_mask;
11205         cmdline_ipaddr_t ipv4_dst;
11206         cmdline_ipaddr_t ipv6_dst;
11207         uint16_t port_dst;
11208         cmdline_fixed_string_t mac;
11209         uint8_t mac_addr_byte_mask;
11210         cmdline_fixed_string_t tunnel_id;
11211         uint32_t tunnel_id_mask;
11212         cmdline_fixed_string_t tunnel_type;
11213         uint8_t tunnel_type_mask;
11214 };
11215
11216 static void
11217 cmd_flow_director_mask_parsed(void *parsed_result,
11218                           __attribute__((unused)) struct cmdline *cl,
11219                           __attribute__((unused)) void *data)
11220 {
11221         struct cmd_flow_director_mask_result *res = parsed_result;
11222         struct rte_eth_fdir_masks *mask;
11223         struct rte_port *port;
11224
11225         port = &ports[res->port_id];
11226         /** Check if the port is not started **/
11227         if (port->port_status != RTE_PORT_STOPPED) {
11228                 printf("Please stop port %d first\n", res->port_id);
11229                 return;
11230         }
11231
11232         mask = &port->dev_conf.fdir_conf.mask;
11233
11234         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11235                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11236                         printf("Please set mode to MAC-VLAN.\n");
11237                         return;
11238                 }
11239
11240                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11241         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11242                 if (strcmp(res->mode_value, "Tunnel")) {
11243                         printf("Please set mode to Tunnel.\n");
11244                         return;
11245                 }
11246
11247                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11248                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11249                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11250                 mask->tunnel_type_mask = res->tunnel_type_mask;
11251         } else {
11252                 if (strcmp(res->mode_value, "IP")) {
11253                         printf("Please set mode to IP.\n");
11254                         return;
11255                 }
11256
11257                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11258                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11259                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11260                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11261                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11262                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11263                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11264         }
11265
11266         cmd_reconfig_device_queue(res->port_id, 1, 1);
11267 }
11268
11269 cmdline_parse_token_string_t cmd_flow_director_mask =
11270         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11271                                  flow_director_mask, "flow_director_mask");
11272 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11273         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11274                               port_id, UINT16);
11275 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11276         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11277                                  vlan, "vlan");
11278 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11279         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11280                               vlan_mask, UINT16);
11281 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11282         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11283                                  src_mask, "src_mask");
11284 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11285         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11286                                  ipv4_src);
11287 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11288         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11289                                  ipv6_src);
11290 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11291         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11292                               port_src, UINT16);
11293 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11295                                  dst_mask, "dst_mask");
11296 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11297         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11298                                  ipv4_dst);
11299 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11300         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11301                                  ipv6_dst);
11302 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11303         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11304                               port_dst, UINT16);
11305
11306 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11307         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11308                                  mode, "mode");
11309 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11311                                  mode_value, "IP");
11312 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11313         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11314                                  mode_value, "MAC-VLAN");
11315 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11316         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11317                                  mode_value, "Tunnel");
11318 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11319         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11320                                  mac, "mac");
11321 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11322         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11323                               mac_addr_byte_mask, UINT8);
11324 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11325         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11326                                  tunnel_type, "tunnel-type");
11327 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11328         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11329                               tunnel_type_mask, UINT8);
11330 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11331         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11332                                  tunnel_id, "tunnel-id");
11333 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11334         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11335                               tunnel_id_mask, UINT32);
11336
11337 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11338         .f = cmd_flow_director_mask_parsed,
11339         .data = NULL,
11340         .help_str = "flow_director_mask ... : "
11341                 "Set IP mode flow director's mask on NIC",
11342         .tokens = {
11343                 (void *)&cmd_flow_director_mask,
11344                 (void *)&cmd_flow_director_mask_port_id,
11345                 (void *)&cmd_flow_director_mask_mode,
11346                 (void *)&cmd_flow_director_mask_mode_ip,
11347                 (void *)&cmd_flow_director_mask_vlan,
11348                 (void *)&cmd_flow_director_mask_vlan_value,
11349                 (void *)&cmd_flow_director_mask_src,
11350                 (void *)&cmd_flow_director_mask_ipv4_src,
11351                 (void *)&cmd_flow_director_mask_ipv6_src,
11352                 (void *)&cmd_flow_director_mask_port_src,
11353                 (void *)&cmd_flow_director_mask_dst,
11354                 (void *)&cmd_flow_director_mask_ipv4_dst,
11355                 (void *)&cmd_flow_director_mask_ipv6_dst,
11356                 (void *)&cmd_flow_director_mask_port_dst,
11357                 NULL,
11358         },
11359 };
11360
11361 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11362         .f = cmd_flow_director_mask_parsed,
11363         .data = NULL,
11364         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11365                 "flow director's mask on NIC",
11366         .tokens = {
11367                 (void *)&cmd_flow_director_mask,
11368                 (void *)&cmd_flow_director_mask_port_id,
11369                 (void *)&cmd_flow_director_mask_mode,
11370                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11371                 (void *)&cmd_flow_director_mask_vlan,
11372                 (void *)&cmd_flow_director_mask_vlan_value,
11373                 NULL,
11374         },
11375 };
11376
11377 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11378         .f = cmd_flow_director_mask_parsed,
11379         .data = NULL,
11380         .help_str = "flow_director_mask ... : Set tunnel mode "
11381                 "flow director's mask on NIC",
11382         .tokens = {
11383                 (void *)&cmd_flow_director_mask,
11384                 (void *)&cmd_flow_director_mask_port_id,
11385                 (void *)&cmd_flow_director_mask_mode,
11386                 (void *)&cmd_flow_director_mask_mode_tunnel,
11387                 (void *)&cmd_flow_director_mask_vlan,
11388                 (void *)&cmd_flow_director_mask_vlan_value,
11389                 (void *)&cmd_flow_director_mask_mac,
11390                 (void *)&cmd_flow_director_mask_mac_value,
11391                 (void *)&cmd_flow_director_mask_tunnel_type,
11392                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11393                 (void *)&cmd_flow_director_mask_tunnel_id,
11394                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11395                 NULL,
11396         },
11397 };
11398
11399 /* *** deal with flow director mask on flexible payload *** */
11400 struct cmd_flow_director_flex_mask_result {
11401         cmdline_fixed_string_t flow_director_flexmask;
11402         portid_t port_id;
11403         cmdline_fixed_string_t flow;
11404         cmdline_fixed_string_t flow_type;
11405         cmdline_fixed_string_t mask;
11406 };
11407
11408 static void
11409 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11410                           __attribute__((unused)) struct cmdline *cl,
11411                           __attribute__((unused)) void *data)
11412 {
11413         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11414         struct rte_eth_fdir_info fdir_info;
11415         struct rte_eth_fdir_flex_mask flex_mask;
11416         struct rte_port *port;
11417         uint64_t flow_type_mask;
11418         uint16_t i;
11419         int ret;
11420
11421         port = &ports[res->port_id];
11422         /** Check if the port is not started **/
11423         if (port->port_status != RTE_PORT_STOPPED) {
11424                 printf("Please stop port %d first\n", res->port_id);
11425                 return;
11426         }
11427
11428         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11429         ret = parse_flexbytes(res->mask,
11430                         flex_mask.mask,
11431                         RTE_ETH_FDIR_MAX_FLEXLEN);
11432         if (ret < 0) {
11433                 printf("error: Cannot parse mask input.\n");
11434                 return;
11435         }
11436
11437         memset(&fdir_info, 0, sizeof(fdir_info));
11438         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11439                                 RTE_ETH_FILTER_INFO, &fdir_info);
11440         if (ret < 0) {
11441                 printf("Cannot get FDir filter info\n");
11442                 return;
11443         }
11444
11445         if (!strcmp(res->flow_type, "none")) {
11446                 /* means don't specify the flow type */
11447                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11448                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11449                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11450                                0, sizeof(struct rte_eth_fdir_flex_mask));
11451                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11452                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11453                                  &flex_mask,
11454                                  sizeof(struct rte_eth_fdir_flex_mask));
11455                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11456                 return;
11457         }
11458         flow_type_mask = fdir_info.flow_types_mask[0];
11459         if (!strcmp(res->flow_type, "all")) {
11460                 if (!flow_type_mask) {
11461                         printf("No flow type supported\n");
11462                         return;
11463                 }
11464                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11465                         if (flow_type_mask & (1ULL << i)) {
11466                                 flex_mask.flow_type = i;
11467                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11468                         }
11469                 }
11470                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11471                 return;
11472         }
11473         flex_mask.flow_type = str2flowtype(res->flow_type);
11474         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11475                 printf("Flow type %s not supported on port %d\n",
11476                                 res->flow_type, res->port_id);
11477                 return;
11478         }
11479         fdir_set_flex_mask(res->port_id, &flex_mask);
11480         cmd_reconfig_device_queue(res->port_id, 1, 1);
11481 }
11482
11483 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11484         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11485                                  flow_director_flexmask,
11486                                  "flow_director_flex_mask");
11487 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11488         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11489                               port_id, UINT16);
11490 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11491         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11492                                  flow, "flow");
11493 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11494         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11495                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11496                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11497 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11498         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11499                                  mask, NULL);
11500
11501 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11502         .f = cmd_flow_director_flex_mask_parsed,
11503         .data = NULL,
11504         .help_str = "flow_director_flex_mask ... : "
11505                 "Set flow director's flex mask on NIC",
11506         .tokens = {
11507                 (void *)&cmd_flow_director_flexmask,
11508                 (void *)&cmd_flow_director_flexmask_port_id,
11509                 (void *)&cmd_flow_director_flexmask_flow,
11510                 (void *)&cmd_flow_director_flexmask_flow_type,
11511                 (void *)&cmd_flow_director_flexmask_mask,
11512                 NULL,
11513         },
11514 };
11515
11516 /* *** deal with flow director flexible payload configuration *** */
11517 struct cmd_flow_director_flexpayload_result {
11518         cmdline_fixed_string_t flow_director_flexpayload;
11519         portid_t port_id;
11520         cmdline_fixed_string_t payload_layer;
11521         cmdline_fixed_string_t payload_cfg;
11522 };
11523
11524 static inline int
11525 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11526 {
11527         char s[256];
11528         const char *p, *p0 = q_arg;
11529         char *end;
11530         unsigned long int_fld;
11531         char *str_fld[max_num];
11532         int i;
11533         unsigned size;
11534         int ret = -1;
11535
11536         p = strchr(p0, '(');
11537         if (p == NULL)
11538                 return -1;
11539         ++p;
11540         p0 = strchr(p, ')');
11541         if (p0 == NULL)
11542                 return -1;
11543
11544         size = p0 - p;
11545         if (size >= sizeof(s))
11546                 return -1;
11547
11548         snprintf(s, sizeof(s), "%.*s", size, p);
11549         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11550         if (ret < 0 || ret > max_num)
11551                 return -1;
11552         for (i = 0; i < ret; i++) {
11553                 errno = 0;
11554                 int_fld = strtoul(str_fld[i], &end, 0);
11555                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11556                         return -1;
11557                 offsets[i] = (uint16_t)int_fld;
11558         }
11559         return ret;
11560 }
11561
11562 static void
11563 cmd_flow_director_flxpld_parsed(void *parsed_result,
11564                           __attribute__((unused)) struct cmdline *cl,
11565                           __attribute__((unused)) void *data)
11566 {
11567         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11568         struct rte_eth_flex_payload_cfg flex_cfg;
11569         struct rte_port *port;
11570         int ret = 0;
11571
11572         port = &ports[res->port_id];
11573         /** Check if the port is not started **/
11574         if (port->port_status != RTE_PORT_STOPPED) {
11575                 printf("Please stop port %d first\n", res->port_id);
11576                 return;
11577         }
11578
11579         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11580
11581         if (!strcmp(res->payload_layer, "raw"))
11582                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11583         else if (!strcmp(res->payload_layer, "l2"))
11584                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11585         else if (!strcmp(res->payload_layer, "l3"))
11586                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11587         else if (!strcmp(res->payload_layer, "l4"))
11588                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11589
11590         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11591                             RTE_ETH_FDIR_MAX_FLEXLEN);
11592         if (ret < 0) {
11593                 printf("error: Cannot parse flex payload input.\n");
11594                 return;
11595         }
11596
11597         fdir_set_flex_payload(res->port_id, &flex_cfg);
11598         cmd_reconfig_device_queue(res->port_id, 1, 1);
11599 }
11600
11601 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11603                                  flow_director_flexpayload,
11604                                  "flow_director_flex_payload");
11605 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11606         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11607                               port_id, UINT16);
11608 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11609         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11610                                  payload_layer, "raw#l2#l3#l4");
11611 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11612         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11613                                  payload_cfg, NULL);
11614
11615 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11616         .f = cmd_flow_director_flxpld_parsed,
11617         .data = NULL,
11618         .help_str = "flow_director_flexpayload ... : "
11619                 "Set flow director's flex payload on NIC",
11620         .tokens = {
11621                 (void *)&cmd_flow_director_flexpayload,
11622                 (void *)&cmd_flow_director_flexpayload_port_id,
11623                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11624                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11625                 NULL,
11626         },
11627 };
11628
11629 /* Generic flow interface command. */
11630 extern cmdline_parse_inst_t cmd_flow;
11631
11632 /* *** Classification Filters Control *** */
11633 /* *** Get symmetric hash enable per port *** */
11634 struct cmd_get_sym_hash_ena_per_port_result {
11635         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11636         portid_t port_id;
11637 };
11638
11639 static void
11640 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11641                                  __rte_unused struct cmdline *cl,
11642                                  __rte_unused void *data)
11643 {
11644         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11645         struct rte_eth_hash_filter_info info;
11646         int ret;
11647
11648         if (rte_eth_dev_filter_supported(res->port_id,
11649                                 RTE_ETH_FILTER_HASH) < 0) {
11650                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11651                                                         res->port_id);
11652                 return;
11653         }
11654
11655         memset(&info, 0, sizeof(info));
11656         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11657         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11658                                                 RTE_ETH_FILTER_GET, &info);
11659
11660         if (ret < 0) {
11661                 printf("Cannot get symmetric hash enable per port "
11662                                         "on port %u\n", res->port_id);
11663                 return;
11664         }
11665
11666         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11667                                 "enabled" : "disabled", res->port_id);
11668 }
11669
11670 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11671         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11672                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11673 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11674         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11675                 port_id, UINT16);
11676
11677 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11678         .f = cmd_get_sym_hash_per_port_parsed,
11679         .data = NULL,
11680         .help_str = "get_sym_hash_ena_per_port <port_id>",
11681         .tokens = {
11682                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11683                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11684                 NULL,
11685         },
11686 };
11687
11688 /* *** Set symmetric hash enable per port *** */
11689 struct cmd_set_sym_hash_ena_per_port_result {
11690         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11691         cmdline_fixed_string_t enable;
11692         portid_t port_id;
11693 };
11694
11695 static void
11696 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11697                                  __rte_unused struct cmdline *cl,
11698                                  __rte_unused void *data)
11699 {
11700         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11701         struct rte_eth_hash_filter_info info;
11702         int ret;
11703
11704         if (rte_eth_dev_filter_supported(res->port_id,
11705                                 RTE_ETH_FILTER_HASH) < 0) {
11706                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11707                                                         res->port_id);
11708                 return;
11709         }
11710
11711         memset(&info, 0, sizeof(info));
11712         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11713         if (!strcmp(res->enable, "enable"))
11714                 info.info.enable = 1;
11715         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11716                                         RTE_ETH_FILTER_SET, &info);
11717         if (ret < 0) {
11718                 printf("Cannot set symmetric hash enable per port on "
11719                                         "port %u\n", res->port_id);
11720                 return;
11721         }
11722         printf("Symmetric hash has been set to %s on port %u\n",
11723                                         res->enable, res->port_id);
11724 }
11725
11726 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11727         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11728                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11729 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11730         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11731                 port_id, UINT16);
11732 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11733         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11734                 enable, "enable#disable");
11735
11736 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11737         .f = cmd_set_sym_hash_per_port_parsed,
11738         .data = NULL,
11739         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11740         .tokens = {
11741                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11742                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11743                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11744                 NULL,
11745         },
11746 };
11747
11748 /* Get global config of hash function */
11749 struct cmd_get_hash_global_config_result {
11750         cmdline_fixed_string_t get_hash_global_config;
11751         portid_t port_id;
11752 };
11753
11754 static char *
11755 flowtype_to_str(uint16_t ftype)
11756 {
11757         uint16_t i;
11758         static struct {
11759                 char str[16];
11760                 uint16_t ftype;
11761         } ftype_table[] = {
11762                 {"ipv4", RTE_ETH_FLOW_IPV4},
11763                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11764                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11765                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11766                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11767                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11768                 {"ipv6", RTE_ETH_FLOW_IPV6},
11769                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11770                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11771                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11772                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11773                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11774                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11775                 {"port", RTE_ETH_FLOW_PORT},
11776                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11777                 {"geneve", RTE_ETH_FLOW_GENEVE},
11778                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11779         };
11780
11781         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11782                 if (ftype_table[i].ftype == ftype)
11783                         return ftype_table[i].str;
11784         }
11785
11786         return NULL;
11787 }
11788
11789 static void
11790 cmd_get_hash_global_config_parsed(void *parsed_result,
11791                                   __rte_unused struct cmdline *cl,
11792                                   __rte_unused void *data)
11793 {
11794         struct cmd_get_hash_global_config_result *res = parsed_result;
11795         struct rte_eth_hash_filter_info info;
11796         uint32_t idx, offset;
11797         uint16_t i;
11798         char *str;
11799         int ret;
11800
11801         if (rte_eth_dev_filter_supported(res->port_id,
11802                         RTE_ETH_FILTER_HASH) < 0) {
11803                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11804                                                         res->port_id);
11805                 return;
11806         }
11807
11808         memset(&info, 0, sizeof(info));
11809         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11810         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11811                                         RTE_ETH_FILTER_GET, &info);
11812         if (ret < 0) {
11813                 printf("Cannot get hash global configurations by port %d\n",
11814                                                         res->port_id);
11815                 return;
11816         }
11817
11818         switch (info.info.global_conf.hash_func) {
11819         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11820                 printf("Hash function is Toeplitz\n");
11821                 break;
11822         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11823                 printf("Hash function is Simple XOR\n");
11824                 break;
11825         default:
11826                 printf("Unknown hash function\n");
11827                 break;
11828         }
11829
11830         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11831                 idx = i / UINT64_BIT;
11832                 offset = i % UINT64_BIT;
11833                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11834                                                 (1ULL << offset)))
11835                         continue;
11836                 str = flowtype_to_str(i);
11837                 if (!str)
11838                         continue;
11839                 printf("Symmetric hash is %s globally for flow type %s "
11840                                                         "by port %d\n",
11841                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11842                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11843                                                         res->port_id);
11844         }
11845 }
11846
11847 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11848         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11849                 get_hash_global_config, "get_hash_global_config");
11850 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11851         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11852                 port_id, UINT16);
11853
11854 cmdline_parse_inst_t cmd_get_hash_global_config = {
11855         .f = cmd_get_hash_global_config_parsed,
11856         .data = NULL,
11857         .help_str = "get_hash_global_config <port_id>",
11858         .tokens = {
11859                 (void *)&cmd_get_hash_global_config_all,
11860                 (void *)&cmd_get_hash_global_config_port_id,
11861                 NULL,
11862         },
11863 };
11864
11865 /* Set global config of hash function */
11866 struct cmd_set_hash_global_config_result {
11867         cmdline_fixed_string_t set_hash_global_config;
11868         portid_t port_id;
11869         cmdline_fixed_string_t hash_func;
11870         cmdline_fixed_string_t flow_type;
11871         cmdline_fixed_string_t enable;
11872 };
11873
11874 static void
11875 cmd_set_hash_global_config_parsed(void *parsed_result,
11876                                   __rte_unused struct cmdline *cl,
11877                                   __rte_unused void *data)
11878 {
11879         struct cmd_set_hash_global_config_result *res = parsed_result;
11880         struct rte_eth_hash_filter_info info;
11881         uint32_t ftype, idx, offset;
11882         int ret;
11883
11884         if (rte_eth_dev_filter_supported(res->port_id,
11885                                 RTE_ETH_FILTER_HASH) < 0) {
11886                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11887                                                         res->port_id);
11888                 return;
11889         }
11890         memset(&info, 0, sizeof(info));
11891         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11892         if (!strcmp(res->hash_func, "toeplitz"))
11893                 info.info.global_conf.hash_func =
11894                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11895         else if (!strcmp(res->hash_func, "simple_xor"))
11896                 info.info.global_conf.hash_func =
11897                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11898         else if (!strcmp(res->hash_func, "default"))
11899                 info.info.global_conf.hash_func =
11900                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11901
11902         ftype = str2flowtype(res->flow_type);
11903         idx = ftype / UINT64_BIT;
11904         offset = ftype % UINT64_BIT;
11905         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11906         if (!strcmp(res->enable, "enable"))
11907                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11908                                                 (1ULL << offset);
11909         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11910                                         RTE_ETH_FILTER_SET, &info);
11911         if (ret < 0)
11912                 printf("Cannot set global hash configurations by port %d\n",
11913                                                         res->port_id);
11914         else
11915                 printf("Global hash configurations have been set "
11916                         "succcessfully by port %d\n", res->port_id);
11917 }
11918
11919 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11920         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11921                 set_hash_global_config, "set_hash_global_config");
11922 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11923         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11924                 port_id, UINT16);
11925 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11926         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11927                 hash_func, "toeplitz#simple_xor#default");
11928 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11929         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11930                 flow_type,
11931                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11932                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11933 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11934         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11935                 enable, "enable#disable");
11936
11937 cmdline_parse_inst_t cmd_set_hash_global_config = {
11938         .f = cmd_set_hash_global_config_parsed,
11939         .data = NULL,
11940         .help_str = "set_hash_global_config <port_id> "
11941                 "toeplitz|simple_xor|default "
11942                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11943                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11944                 "l2_payload enable|disable",
11945         .tokens = {
11946                 (void *)&cmd_set_hash_global_config_all,
11947                 (void *)&cmd_set_hash_global_config_port_id,
11948                 (void *)&cmd_set_hash_global_config_hash_func,
11949                 (void *)&cmd_set_hash_global_config_flow_type,
11950                 (void *)&cmd_set_hash_global_config_enable,
11951                 NULL,
11952         },
11953 };
11954
11955 /* Set hash input set */
11956 struct cmd_set_hash_input_set_result {
11957         cmdline_fixed_string_t set_hash_input_set;
11958         portid_t port_id;
11959         cmdline_fixed_string_t flow_type;
11960         cmdline_fixed_string_t inset_field;
11961         cmdline_fixed_string_t select;
11962 };
11963
11964 static enum rte_eth_input_set_field
11965 str2inset(char *string)
11966 {
11967         uint16_t i;
11968
11969         static const struct {
11970                 char str[32];
11971                 enum rte_eth_input_set_field inset;
11972         } inset_table[] = {
11973                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11974                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11975                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11976                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11977                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11978                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11979                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11980                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11981                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11982                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11983                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11984                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11985                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11986                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11987                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11988                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11989                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11990                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11991                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11992                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11993                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11994                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11995                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11996                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11997                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11998                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11999                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12000                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12001                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12002                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12003                 {"none", RTE_ETH_INPUT_SET_NONE},
12004         };
12005
12006         for (i = 0; i < RTE_DIM(inset_table); i++) {
12007                 if (!strcmp(string, inset_table[i].str))
12008                         return inset_table[i].inset;
12009         }
12010
12011         return RTE_ETH_INPUT_SET_UNKNOWN;
12012 }
12013
12014 static void
12015 cmd_set_hash_input_set_parsed(void *parsed_result,
12016                               __rte_unused struct cmdline *cl,
12017                               __rte_unused void *data)
12018 {
12019         struct cmd_set_hash_input_set_result *res = parsed_result;
12020         struct rte_eth_hash_filter_info info;
12021
12022         memset(&info, 0, sizeof(info));
12023         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12024         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12025         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12026         info.info.input_set_conf.inset_size = 1;
12027         if (!strcmp(res->select, "select"))
12028                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12029         else if (!strcmp(res->select, "add"))
12030                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12031         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12032                                 RTE_ETH_FILTER_SET, &info);
12033 }
12034
12035 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12036         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12037                 set_hash_input_set, "set_hash_input_set");
12038 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12039         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12040                 port_id, UINT16);
12041 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12042         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12043                 flow_type, NULL);
12044 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12045         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12046                 inset_field,
12047                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12048                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12049                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12050                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12051                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12052                 "fld-8th#none");
12053 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12054         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12055                 select, "select#add");
12056
12057 cmdline_parse_inst_t cmd_set_hash_input_set = {
12058         .f = cmd_set_hash_input_set_parsed,
12059         .data = NULL,
12060         .help_str = "set_hash_input_set <port_id> "
12061         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12062         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12063         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12064         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12065         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12066         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12067         "fld-7th|fld-8th|none select|add",
12068         .tokens = {
12069                 (void *)&cmd_set_hash_input_set_cmd,
12070                 (void *)&cmd_set_hash_input_set_port_id,
12071                 (void *)&cmd_set_hash_input_set_flow_type,
12072                 (void *)&cmd_set_hash_input_set_field,
12073                 (void *)&cmd_set_hash_input_set_select,
12074                 NULL,
12075         },
12076 };
12077
12078 /* Set flow director input set */
12079 struct cmd_set_fdir_input_set_result {
12080         cmdline_fixed_string_t set_fdir_input_set;
12081         portid_t port_id;
12082         cmdline_fixed_string_t flow_type;
12083         cmdline_fixed_string_t inset_field;
12084         cmdline_fixed_string_t select;
12085 };
12086
12087 static void
12088 cmd_set_fdir_input_set_parsed(void *parsed_result,
12089         __rte_unused struct cmdline *cl,
12090         __rte_unused void *data)
12091 {
12092         struct cmd_set_fdir_input_set_result *res = parsed_result;
12093         struct rte_eth_fdir_filter_info info;
12094
12095         memset(&info, 0, sizeof(info));
12096         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12097         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12098         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12099         info.info.input_set_conf.inset_size = 1;
12100         if (!strcmp(res->select, "select"))
12101                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12102         else if (!strcmp(res->select, "add"))
12103                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12104         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12105                 RTE_ETH_FILTER_SET, &info);
12106 }
12107
12108 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12109         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12110         set_fdir_input_set, "set_fdir_input_set");
12111 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12112         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12113         port_id, UINT16);
12114 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12115         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12116         flow_type,
12117         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12118         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12119 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12120         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12121         inset_field,
12122         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12123         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12124         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12125         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12126         "sctp-veri-tag#none");
12127 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12128         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12129         select, "select#add");
12130
12131 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12132         .f = cmd_set_fdir_input_set_parsed,
12133         .data = NULL,
12134         .help_str = "set_fdir_input_set <port_id> "
12135         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12136         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12137         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12138         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12139         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12140         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12141         "sctp-veri-tag|none select|add",
12142         .tokens = {
12143                 (void *)&cmd_set_fdir_input_set_cmd,
12144                 (void *)&cmd_set_fdir_input_set_port_id,
12145                 (void *)&cmd_set_fdir_input_set_flow_type,
12146                 (void *)&cmd_set_fdir_input_set_field,
12147                 (void *)&cmd_set_fdir_input_set_select,
12148                 NULL,
12149         },
12150 };
12151
12152 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12153 struct cmd_mcast_addr_result {
12154         cmdline_fixed_string_t mcast_addr_cmd;
12155         cmdline_fixed_string_t what;
12156         uint16_t port_num;
12157         struct ether_addr mc_addr;
12158 };
12159
12160 static void cmd_mcast_addr_parsed(void *parsed_result,
12161                 __attribute__((unused)) struct cmdline *cl,
12162                 __attribute__((unused)) void *data)
12163 {
12164         struct cmd_mcast_addr_result *res = parsed_result;
12165
12166         if (!is_multicast_ether_addr(&res->mc_addr)) {
12167                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12168                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12169                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12170                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12171                 return;
12172         }
12173         if (strcmp(res->what, "add") == 0)
12174                 mcast_addr_add(res->port_num, &res->mc_addr);
12175         else
12176                 mcast_addr_remove(res->port_num, &res->mc_addr);
12177 }
12178
12179 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12180         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12181                                  mcast_addr_cmd, "mcast_addr");
12182 cmdline_parse_token_string_t cmd_mcast_addr_what =
12183         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12184                                  "add#remove");
12185 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12186         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12187 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12188         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12189
12190 cmdline_parse_inst_t cmd_mcast_addr = {
12191         .f = cmd_mcast_addr_parsed,
12192         .data = (void *)0,
12193         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12194                 "Add/Remove multicast MAC address on port_id",
12195         .tokens = {
12196                 (void *)&cmd_mcast_addr_cmd,
12197                 (void *)&cmd_mcast_addr_what,
12198                 (void *)&cmd_mcast_addr_portnum,
12199                 (void *)&cmd_mcast_addr_addr,
12200                 NULL,
12201         },
12202 };
12203
12204 /* l2 tunnel config
12205  * only support E-tag now.
12206  */
12207
12208 /* Ether type config */
12209 struct cmd_config_l2_tunnel_eth_type_result {
12210         cmdline_fixed_string_t port;
12211         cmdline_fixed_string_t config;
12212         cmdline_fixed_string_t all;
12213         portid_t id;
12214         cmdline_fixed_string_t l2_tunnel;
12215         cmdline_fixed_string_t l2_tunnel_type;
12216         cmdline_fixed_string_t eth_type;
12217         uint16_t eth_type_val;
12218 };
12219
12220 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12221         TOKEN_STRING_INITIALIZER
12222                 (struct cmd_config_l2_tunnel_eth_type_result,
12223                  port, "port");
12224 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12225         TOKEN_STRING_INITIALIZER
12226                 (struct cmd_config_l2_tunnel_eth_type_result,
12227                  config, "config");
12228 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12229         TOKEN_STRING_INITIALIZER
12230                 (struct cmd_config_l2_tunnel_eth_type_result,
12231                  all, "all");
12232 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12233         TOKEN_NUM_INITIALIZER
12234                 (struct cmd_config_l2_tunnel_eth_type_result,
12235                  id, UINT16);
12236 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12237         TOKEN_STRING_INITIALIZER
12238                 (struct cmd_config_l2_tunnel_eth_type_result,
12239                  l2_tunnel, "l2-tunnel");
12240 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12241         TOKEN_STRING_INITIALIZER
12242                 (struct cmd_config_l2_tunnel_eth_type_result,
12243                  l2_tunnel_type, "E-tag");
12244 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12245         TOKEN_STRING_INITIALIZER
12246                 (struct cmd_config_l2_tunnel_eth_type_result,
12247                  eth_type, "ether-type");
12248 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12249         TOKEN_NUM_INITIALIZER
12250                 (struct cmd_config_l2_tunnel_eth_type_result,
12251                  eth_type_val, UINT16);
12252
12253 static enum rte_eth_tunnel_type
12254 str2fdir_l2_tunnel_type(char *string)
12255 {
12256         uint32_t i = 0;
12257
12258         static const struct {
12259                 char str[32];
12260                 enum rte_eth_tunnel_type type;
12261         } l2_tunnel_type_str[] = {
12262                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12263         };
12264
12265         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12266                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12267                         return l2_tunnel_type_str[i].type;
12268         }
12269         return RTE_TUNNEL_TYPE_NONE;
12270 }
12271
12272 /* ether type config for all ports */
12273 static void
12274 cmd_config_l2_tunnel_eth_type_all_parsed
12275         (void *parsed_result,
12276          __attribute__((unused)) struct cmdline *cl,
12277          __attribute__((unused)) void *data)
12278 {
12279         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12280         struct rte_eth_l2_tunnel_conf entry;
12281         portid_t pid;
12282
12283         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12284         entry.ether_type = res->eth_type_val;
12285
12286         RTE_ETH_FOREACH_DEV(pid) {
12287                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12288         }
12289 }
12290
12291 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12292         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12293         .data = NULL,
12294         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12295         .tokens = {
12296                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12297                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12298                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12299                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12300                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12301                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12302                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12303                 NULL,
12304         },
12305 };
12306
12307 /* ether type config for a specific port */
12308 static void
12309 cmd_config_l2_tunnel_eth_type_specific_parsed(
12310         void *parsed_result,
12311         __attribute__((unused)) struct cmdline *cl,
12312         __attribute__((unused)) void *data)
12313 {
12314         struct cmd_config_l2_tunnel_eth_type_result *res =
12315                  parsed_result;
12316         struct rte_eth_l2_tunnel_conf entry;
12317
12318         if (port_id_is_invalid(res->id, ENABLED_WARN))
12319                 return;
12320
12321         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12322         entry.ether_type = res->eth_type_val;
12323
12324         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12325 }
12326
12327 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12328         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12329         .data = NULL,
12330         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12331         .tokens = {
12332                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12333                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12334                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12335                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12336                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12337                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12338                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12339                 NULL,
12340         },
12341 };
12342
12343 /* Enable/disable l2 tunnel */
12344 struct cmd_config_l2_tunnel_en_dis_result {
12345         cmdline_fixed_string_t port;
12346         cmdline_fixed_string_t config;
12347         cmdline_fixed_string_t all;
12348         portid_t id;
12349         cmdline_fixed_string_t l2_tunnel;
12350         cmdline_fixed_string_t l2_tunnel_type;
12351         cmdline_fixed_string_t en_dis;
12352 };
12353
12354 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12355         TOKEN_STRING_INITIALIZER
12356                 (struct cmd_config_l2_tunnel_en_dis_result,
12357                  port, "port");
12358 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12359         TOKEN_STRING_INITIALIZER
12360                 (struct cmd_config_l2_tunnel_en_dis_result,
12361                  config, "config");
12362 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12363         TOKEN_STRING_INITIALIZER
12364                 (struct cmd_config_l2_tunnel_en_dis_result,
12365                  all, "all");
12366 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12367         TOKEN_NUM_INITIALIZER
12368                 (struct cmd_config_l2_tunnel_en_dis_result,
12369                  id, UINT16);
12370 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12371         TOKEN_STRING_INITIALIZER
12372                 (struct cmd_config_l2_tunnel_en_dis_result,
12373                  l2_tunnel, "l2-tunnel");
12374 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12375         TOKEN_STRING_INITIALIZER
12376                 (struct cmd_config_l2_tunnel_en_dis_result,
12377                  l2_tunnel_type, "E-tag");
12378 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12379         TOKEN_STRING_INITIALIZER
12380                 (struct cmd_config_l2_tunnel_en_dis_result,
12381                  en_dis, "enable#disable");
12382
12383 /* enable/disable l2 tunnel for all ports */
12384 static void
12385 cmd_config_l2_tunnel_en_dis_all_parsed(
12386         void *parsed_result,
12387         __attribute__((unused)) struct cmdline *cl,
12388         __attribute__((unused)) void *data)
12389 {
12390         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12391         struct rte_eth_l2_tunnel_conf entry;
12392         portid_t pid;
12393         uint8_t en;
12394
12395         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12396
12397         if (!strcmp("enable", res->en_dis))
12398                 en = 1;
12399         else
12400                 en = 0;
12401
12402         RTE_ETH_FOREACH_DEV(pid) {
12403                 rte_eth_dev_l2_tunnel_offload_set(pid,
12404                                                   &entry,
12405                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12406                                                   en);
12407         }
12408 }
12409
12410 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12411         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12412         .data = NULL,
12413         .help_str = "port config all l2-tunnel E-tag enable|disable",
12414         .tokens = {
12415                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12416                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12417                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12418                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12419                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12420                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12421                 NULL,
12422         },
12423 };
12424
12425 /* enable/disable l2 tunnel for a port */
12426 static void
12427 cmd_config_l2_tunnel_en_dis_specific_parsed(
12428         void *parsed_result,
12429         __attribute__((unused)) struct cmdline *cl,
12430         __attribute__((unused)) void *data)
12431 {
12432         struct cmd_config_l2_tunnel_en_dis_result *res =
12433                 parsed_result;
12434         struct rte_eth_l2_tunnel_conf entry;
12435
12436         if (port_id_is_invalid(res->id, ENABLED_WARN))
12437                 return;
12438
12439         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12440
12441         if (!strcmp("enable", res->en_dis))
12442                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12443                                                   &entry,
12444                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12445                                                   1);
12446         else
12447                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12448                                                   &entry,
12449                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12450                                                   0);
12451 }
12452
12453 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12454         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12455         .data = NULL,
12456         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12457         .tokens = {
12458                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12459                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12460                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12461                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12462                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12463                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12464                 NULL,
12465         },
12466 };
12467
12468 /* E-tag configuration */
12469
12470 /* Common result structure for all E-tag configuration */
12471 struct cmd_config_e_tag_result {
12472         cmdline_fixed_string_t e_tag;
12473         cmdline_fixed_string_t set;
12474         cmdline_fixed_string_t insertion;
12475         cmdline_fixed_string_t stripping;
12476         cmdline_fixed_string_t forwarding;
12477         cmdline_fixed_string_t filter;
12478         cmdline_fixed_string_t add;
12479         cmdline_fixed_string_t del;
12480         cmdline_fixed_string_t on;
12481         cmdline_fixed_string_t off;
12482         cmdline_fixed_string_t on_off;
12483         cmdline_fixed_string_t port_tag_id;
12484         uint32_t port_tag_id_val;
12485         cmdline_fixed_string_t e_tag_id;
12486         uint16_t e_tag_id_val;
12487         cmdline_fixed_string_t dst_pool;
12488         uint8_t dst_pool_val;
12489         cmdline_fixed_string_t port;
12490         portid_t port_id;
12491         cmdline_fixed_string_t vf;
12492         uint8_t vf_id;
12493 };
12494
12495 /* Common CLI fields for all E-tag configuration */
12496 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_config_e_tag_result,
12499                  e_tag, "E-tag");
12500 cmdline_parse_token_string_t cmd_config_e_tag_set =
12501         TOKEN_STRING_INITIALIZER
12502                 (struct cmd_config_e_tag_result,
12503                  set, "set");
12504 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12505         TOKEN_STRING_INITIALIZER
12506                 (struct cmd_config_e_tag_result,
12507                  insertion, "insertion");
12508 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12509         TOKEN_STRING_INITIALIZER
12510                 (struct cmd_config_e_tag_result,
12511                  stripping, "stripping");
12512 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12513         TOKEN_STRING_INITIALIZER
12514                 (struct cmd_config_e_tag_result,
12515                  forwarding, "forwarding");
12516 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_config_e_tag_result,
12519                  filter, "filter");
12520 cmdline_parse_token_string_t cmd_config_e_tag_add =
12521         TOKEN_STRING_INITIALIZER
12522                 (struct cmd_config_e_tag_result,
12523                  add, "add");
12524 cmdline_parse_token_string_t cmd_config_e_tag_del =
12525         TOKEN_STRING_INITIALIZER
12526                 (struct cmd_config_e_tag_result,
12527                  del, "del");
12528 cmdline_parse_token_string_t cmd_config_e_tag_on =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_config_e_tag_result,
12531                  on, "on");
12532 cmdline_parse_token_string_t cmd_config_e_tag_off =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_config_e_tag_result,
12535                  off, "off");
12536 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12537         TOKEN_STRING_INITIALIZER
12538                 (struct cmd_config_e_tag_result,
12539                  on_off, "on#off");
12540 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12541         TOKEN_STRING_INITIALIZER
12542                 (struct cmd_config_e_tag_result,
12543                  port_tag_id, "port-tag-id");
12544 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12545         TOKEN_NUM_INITIALIZER
12546                 (struct cmd_config_e_tag_result,
12547                  port_tag_id_val, UINT32);
12548 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12549         TOKEN_STRING_INITIALIZER
12550                 (struct cmd_config_e_tag_result,
12551                  e_tag_id, "e-tag-id");
12552 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12553         TOKEN_NUM_INITIALIZER
12554                 (struct cmd_config_e_tag_result,
12555                  e_tag_id_val, UINT16);
12556 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12557         TOKEN_STRING_INITIALIZER
12558                 (struct cmd_config_e_tag_result,
12559                  dst_pool, "dst-pool");
12560 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12561         TOKEN_NUM_INITIALIZER
12562                 (struct cmd_config_e_tag_result,
12563                  dst_pool_val, UINT8);
12564 cmdline_parse_token_string_t cmd_config_e_tag_port =
12565         TOKEN_STRING_INITIALIZER
12566                 (struct cmd_config_e_tag_result,
12567                  port, "port");
12568 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12569         TOKEN_NUM_INITIALIZER
12570                 (struct cmd_config_e_tag_result,
12571                  port_id, UINT16);
12572 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12573         TOKEN_STRING_INITIALIZER
12574                 (struct cmd_config_e_tag_result,
12575                  vf, "vf");
12576 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12577         TOKEN_NUM_INITIALIZER
12578                 (struct cmd_config_e_tag_result,
12579                  vf_id, UINT8);
12580
12581 /* E-tag insertion configuration */
12582 static void
12583 cmd_config_e_tag_insertion_en_parsed(
12584         void *parsed_result,
12585         __attribute__((unused)) struct cmdline *cl,
12586         __attribute__((unused)) void *data)
12587 {
12588         struct cmd_config_e_tag_result *res =
12589                 parsed_result;
12590         struct rte_eth_l2_tunnel_conf entry;
12591
12592         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12593                 return;
12594
12595         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12596         entry.tunnel_id = res->port_tag_id_val;
12597         entry.vf_id = res->vf_id;
12598         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12599                                           &entry,
12600                                           ETH_L2_TUNNEL_INSERTION_MASK,
12601                                           1);
12602 }
12603
12604 static void
12605 cmd_config_e_tag_insertion_dis_parsed(
12606         void *parsed_result,
12607         __attribute__((unused)) struct cmdline *cl,
12608         __attribute__((unused)) void *data)
12609 {
12610         struct cmd_config_e_tag_result *res =
12611                 parsed_result;
12612         struct rte_eth_l2_tunnel_conf entry;
12613
12614         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12615                 return;
12616
12617         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12618         entry.vf_id = res->vf_id;
12619
12620         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12621                                           &entry,
12622                                           ETH_L2_TUNNEL_INSERTION_MASK,
12623                                           0);
12624 }
12625
12626 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12627         .f = cmd_config_e_tag_insertion_en_parsed,
12628         .data = NULL,
12629         .help_str = "E-tag ... : E-tag insertion enable",
12630         .tokens = {
12631                 (void *)&cmd_config_e_tag_e_tag,
12632                 (void *)&cmd_config_e_tag_set,
12633                 (void *)&cmd_config_e_tag_insertion,
12634                 (void *)&cmd_config_e_tag_on,
12635                 (void *)&cmd_config_e_tag_port_tag_id,
12636                 (void *)&cmd_config_e_tag_port_tag_id_val,
12637                 (void *)&cmd_config_e_tag_port,
12638                 (void *)&cmd_config_e_tag_port_id,
12639                 (void *)&cmd_config_e_tag_vf,
12640                 (void *)&cmd_config_e_tag_vf_id,
12641                 NULL,
12642         },
12643 };
12644
12645 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12646         .f = cmd_config_e_tag_insertion_dis_parsed,
12647         .data = NULL,
12648         .help_str = "E-tag ... : E-tag insertion disable",
12649         .tokens = {
12650                 (void *)&cmd_config_e_tag_e_tag,
12651                 (void *)&cmd_config_e_tag_set,
12652                 (void *)&cmd_config_e_tag_insertion,
12653                 (void *)&cmd_config_e_tag_off,
12654                 (void *)&cmd_config_e_tag_port,
12655                 (void *)&cmd_config_e_tag_port_id,
12656                 (void *)&cmd_config_e_tag_vf,
12657                 (void *)&cmd_config_e_tag_vf_id,
12658                 NULL,
12659         },
12660 };
12661
12662 /* E-tag stripping configuration */
12663 static void
12664 cmd_config_e_tag_stripping_parsed(
12665         void *parsed_result,
12666         __attribute__((unused)) struct cmdline *cl,
12667         __attribute__((unused)) void *data)
12668 {
12669         struct cmd_config_e_tag_result *res =
12670                 parsed_result;
12671         struct rte_eth_l2_tunnel_conf entry;
12672
12673         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12674                 return;
12675
12676         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12677
12678         if (!strcmp(res->on_off, "on"))
12679                 rte_eth_dev_l2_tunnel_offload_set
12680                         (res->port_id,
12681                          &entry,
12682                          ETH_L2_TUNNEL_STRIPPING_MASK,
12683                          1);
12684         else
12685                 rte_eth_dev_l2_tunnel_offload_set
12686                         (res->port_id,
12687                          &entry,
12688                          ETH_L2_TUNNEL_STRIPPING_MASK,
12689                          0);
12690 }
12691
12692 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12693         .f = cmd_config_e_tag_stripping_parsed,
12694         .data = NULL,
12695         .help_str = "E-tag ... : E-tag stripping enable/disable",
12696         .tokens = {
12697                 (void *)&cmd_config_e_tag_e_tag,
12698                 (void *)&cmd_config_e_tag_set,
12699                 (void *)&cmd_config_e_tag_stripping,
12700                 (void *)&cmd_config_e_tag_on_off,
12701                 (void *)&cmd_config_e_tag_port,
12702                 (void *)&cmd_config_e_tag_port_id,
12703                 NULL,
12704         },
12705 };
12706
12707 /* E-tag forwarding configuration */
12708 static void
12709 cmd_config_e_tag_forwarding_parsed(
12710         void *parsed_result,
12711         __attribute__((unused)) struct cmdline *cl,
12712         __attribute__((unused)) void *data)
12713 {
12714         struct cmd_config_e_tag_result *res = parsed_result;
12715         struct rte_eth_l2_tunnel_conf entry;
12716
12717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12718                 return;
12719
12720         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12721
12722         if (!strcmp(res->on_off, "on"))
12723                 rte_eth_dev_l2_tunnel_offload_set
12724                         (res->port_id,
12725                          &entry,
12726                          ETH_L2_TUNNEL_FORWARDING_MASK,
12727                          1);
12728         else
12729                 rte_eth_dev_l2_tunnel_offload_set
12730                         (res->port_id,
12731                          &entry,
12732                          ETH_L2_TUNNEL_FORWARDING_MASK,
12733                          0);
12734 }
12735
12736 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12737         .f = cmd_config_e_tag_forwarding_parsed,
12738         .data = NULL,
12739         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12740         .tokens = {
12741                 (void *)&cmd_config_e_tag_e_tag,
12742                 (void *)&cmd_config_e_tag_set,
12743                 (void *)&cmd_config_e_tag_forwarding,
12744                 (void *)&cmd_config_e_tag_on_off,
12745                 (void *)&cmd_config_e_tag_port,
12746                 (void *)&cmd_config_e_tag_port_id,
12747                 NULL,
12748         },
12749 };
12750
12751 /* E-tag filter configuration */
12752 static void
12753 cmd_config_e_tag_filter_add_parsed(
12754         void *parsed_result,
12755         __attribute__((unused)) struct cmdline *cl,
12756         __attribute__((unused)) void *data)
12757 {
12758         struct cmd_config_e_tag_result *res = parsed_result;
12759         struct rte_eth_l2_tunnel_conf entry;
12760         int ret = 0;
12761
12762         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12763                 return;
12764
12765         if (res->e_tag_id_val > 0x3fff) {
12766                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12767                 return;
12768         }
12769
12770         ret = rte_eth_dev_filter_supported(res->port_id,
12771                                            RTE_ETH_FILTER_L2_TUNNEL);
12772         if (ret < 0) {
12773                 printf("E-tag filter is not supported on port %u.\n",
12774                        res->port_id);
12775                 return;
12776         }
12777
12778         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12779         entry.tunnel_id = res->e_tag_id_val;
12780         entry.pool = res->dst_pool_val;
12781
12782         ret = rte_eth_dev_filter_ctrl(res->port_id,
12783                                       RTE_ETH_FILTER_L2_TUNNEL,
12784                                       RTE_ETH_FILTER_ADD,
12785                                       &entry);
12786         if (ret < 0)
12787                 printf("E-tag filter programming error: (%s)\n",
12788                        strerror(-ret));
12789 }
12790
12791 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12792         .f = cmd_config_e_tag_filter_add_parsed,
12793         .data = NULL,
12794         .help_str = "E-tag ... : E-tag filter add",
12795         .tokens = {
12796                 (void *)&cmd_config_e_tag_e_tag,
12797                 (void *)&cmd_config_e_tag_set,
12798                 (void *)&cmd_config_e_tag_filter,
12799                 (void *)&cmd_config_e_tag_add,
12800                 (void *)&cmd_config_e_tag_e_tag_id,
12801                 (void *)&cmd_config_e_tag_e_tag_id_val,
12802                 (void *)&cmd_config_e_tag_dst_pool,
12803                 (void *)&cmd_config_e_tag_dst_pool_val,
12804                 (void *)&cmd_config_e_tag_port,
12805                 (void *)&cmd_config_e_tag_port_id,
12806                 NULL,
12807         },
12808 };
12809
12810 static void
12811 cmd_config_e_tag_filter_del_parsed(
12812         void *parsed_result,
12813         __attribute__((unused)) struct cmdline *cl,
12814         __attribute__((unused)) void *data)
12815 {
12816         struct cmd_config_e_tag_result *res = parsed_result;
12817         struct rte_eth_l2_tunnel_conf entry;
12818         int ret = 0;
12819
12820         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12821                 return;
12822
12823         if (res->e_tag_id_val > 0x3fff) {
12824                 printf("e-tag-id must be less than 0x3fff.\n");
12825                 return;
12826         }
12827
12828         ret = rte_eth_dev_filter_supported(res->port_id,
12829                                            RTE_ETH_FILTER_L2_TUNNEL);
12830         if (ret < 0) {
12831                 printf("E-tag filter is not supported on port %u.\n",
12832                        res->port_id);
12833                 return;
12834         }
12835
12836         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12837         entry.tunnel_id = res->e_tag_id_val;
12838
12839         ret = rte_eth_dev_filter_ctrl(res->port_id,
12840                                       RTE_ETH_FILTER_L2_TUNNEL,
12841                                       RTE_ETH_FILTER_DELETE,
12842                                       &entry);
12843         if (ret < 0)
12844                 printf("E-tag filter programming error: (%s)\n",
12845                        strerror(-ret));
12846 }
12847
12848 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12849         .f = cmd_config_e_tag_filter_del_parsed,
12850         .data = NULL,
12851         .help_str = "E-tag ... : E-tag filter delete",
12852         .tokens = {
12853                 (void *)&cmd_config_e_tag_e_tag,
12854                 (void *)&cmd_config_e_tag_set,
12855                 (void *)&cmd_config_e_tag_filter,
12856                 (void *)&cmd_config_e_tag_del,
12857                 (void *)&cmd_config_e_tag_e_tag_id,
12858                 (void *)&cmd_config_e_tag_e_tag_id_val,
12859                 (void *)&cmd_config_e_tag_port,
12860                 (void *)&cmd_config_e_tag_port_id,
12861                 NULL,
12862         },
12863 };
12864
12865 /* vf vlan anti spoof configuration */
12866
12867 /* Common result structure for vf vlan anti spoof */
12868 struct cmd_vf_vlan_anti_spoof_result {
12869         cmdline_fixed_string_t set;
12870         cmdline_fixed_string_t vf;
12871         cmdline_fixed_string_t vlan;
12872         cmdline_fixed_string_t antispoof;
12873         portid_t port_id;
12874         uint32_t vf_id;
12875         cmdline_fixed_string_t on_off;
12876 };
12877
12878 /* Common CLI fields for vf vlan anti spoof enable disable */
12879 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12880         TOKEN_STRING_INITIALIZER
12881                 (struct cmd_vf_vlan_anti_spoof_result,
12882                  set, "set");
12883 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12884         TOKEN_STRING_INITIALIZER
12885                 (struct cmd_vf_vlan_anti_spoof_result,
12886                  vf, "vf");
12887 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12888         TOKEN_STRING_INITIALIZER
12889                 (struct cmd_vf_vlan_anti_spoof_result,
12890                  vlan, "vlan");
12891 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12892         TOKEN_STRING_INITIALIZER
12893                 (struct cmd_vf_vlan_anti_spoof_result,
12894                  antispoof, "antispoof");
12895 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12896         TOKEN_NUM_INITIALIZER
12897                 (struct cmd_vf_vlan_anti_spoof_result,
12898                  port_id, UINT16);
12899 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12900         TOKEN_NUM_INITIALIZER
12901                 (struct cmd_vf_vlan_anti_spoof_result,
12902                  vf_id, UINT32);
12903 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12904         TOKEN_STRING_INITIALIZER
12905                 (struct cmd_vf_vlan_anti_spoof_result,
12906                  on_off, "on#off");
12907
12908 static void
12909 cmd_set_vf_vlan_anti_spoof_parsed(
12910         void *parsed_result,
12911         __attribute__((unused)) struct cmdline *cl,
12912         __attribute__((unused)) void *data)
12913 {
12914         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12915         int ret = -ENOTSUP;
12916
12917         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12918
12919         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12920                 return;
12921
12922 #ifdef RTE_LIBRTE_IXGBE_PMD
12923         if (ret == -ENOTSUP)
12924                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12925                                 res->vf_id, is_on);
12926 #endif
12927 #ifdef RTE_LIBRTE_I40E_PMD
12928         if (ret == -ENOTSUP)
12929                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12930                                 res->vf_id, is_on);
12931 #endif
12932 #ifdef RTE_LIBRTE_BNXT_PMD
12933         if (ret == -ENOTSUP)
12934                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12935                                 res->vf_id, is_on);
12936 #endif
12937
12938         switch (ret) {
12939         case 0:
12940                 break;
12941         case -EINVAL:
12942                 printf("invalid vf_id %d\n", res->vf_id);
12943                 break;
12944         case -ENODEV:
12945                 printf("invalid port_id %d\n", res->port_id);
12946                 break;
12947         case -ENOTSUP:
12948                 printf("function not implemented\n");
12949                 break;
12950         default:
12951                 printf("programming error: (%s)\n", strerror(-ret));
12952         }
12953 }
12954
12955 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12956         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12957         .data = NULL,
12958         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12959         .tokens = {
12960                 (void *)&cmd_vf_vlan_anti_spoof_set,
12961                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12962                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12963                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12964                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12965                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12966                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12967                 NULL,
12968         },
12969 };
12970
12971 /* vf mac anti spoof configuration */
12972
12973 /* Common result structure for vf mac anti spoof */
12974 struct cmd_vf_mac_anti_spoof_result {
12975         cmdline_fixed_string_t set;
12976         cmdline_fixed_string_t vf;
12977         cmdline_fixed_string_t mac;
12978         cmdline_fixed_string_t antispoof;
12979         portid_t port_id;
12980         uint32_t vf_id;
12981         cmdline_fixed_string_t on_off;
12982 };
12983
12984 /* Common CLI fields for vf mac anti spoof enable disable */
12985 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12986         TOKEN_STRING_INITIALIZER
12987                 (struct cmd_vf_mac_anti_spoof_result,
12988                  set, "set");
12989 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12990         TOKEN_STRING_INITIALIZER
12991                 (struct cmd_vf_mac_anti_spoof_result,
12992                  vf, "vf");
12993 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12994         TOKEN_STRING_INITIALIZER
12995                 (struct cmd_vf_mac_anti_spoof_result,
12996                  mac, "mac");
12997 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12998         TOKEN_STRING_INITIALIZER
12999                 (struct cmd_vf_mac_anti_spoof_result,
13000                  antispoof, "antispoof");
13001 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13002         TOKEN_NUM_INITIALIZER
13003                 (struct cmd_vf_mac_anti_spoof_result,
13004                  port_id, UINT16);
13005 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13006         TOKEN_NUM_INITIALIZER
13007                 (struct cmd_vf_mac_anti_spoof_result,
13008                  vf_id, UINT32);
13009 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13010         TOKEN_STRING_INITIALIZER
13011                 (struct cmd_vf_mac_anti_spoof_result,
13012                  on_off, "on#off");
13013
13014 static void
13015 cmd_set_vf_mac_anti_spoof_parsed(
13016         void *parsed_result,
13017         __attribute__((unused)) struct cmdline *cl,
13018         __attribute__((unused)) void *data)
13019 {
13020         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13021         int ret = -ENOTSUP;
13022
13023         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13024
13025         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13026                 return;
13027
13028 #ifdef RTE_LIBRTE_IXGBE_PMD
13029         if (ret == -ENOTSUP)
13030                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13031                         res->vf_id, is_on);
13032 #endif
13033 #ifdef RTE_LIBRTE_I40E_PMD
13034         if (ret == -ENOTSUP)
13035                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13036                         res->vf_id, is_on);
13037 #endif
13038 #ifdef RTE_LIBRTE_BNXT_PMD
13039         if (ret == -ENOTSUP)
13040                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13041                         res->vf_id, is_on);
13042 #endif
13043
13044         switch (ret) {
13045         case 0:
13046                 break;
13047         case -EINVAL:
13048                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13049                 break;
13050         case -ENODEV:
13051                 printf("invalid port_id %d\n", res->port_id);
13052                 break;
13053         case -ENOTSUP:
13054                 printf("function not implemented\n");
13055                 break;
13056         default:
13057                 printf("programming error: (%s)\n", strerror(-ret));
13058         }
13059 }
13060
13061 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13062         .f = cmd_set_vf_mac_anti_spoof_parsed,
13063         .data = NULL,
13064         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13065         .tokens = {
13066                 (void *)&cmd_vf_mac_anti_spoof_set,
13067                 (void *)&cmd_vf_mac_anti_spoof_vf,
13068                 (void *)&cmd_vf_mac_anti_spoof_mac,
13069                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13070                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13071                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13072                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13073                 NULL,
13074         },
13075 };
13076
13077 /* vf vlan strip queue configuration */
13078
13079 /* Common result structure for vf mac anti spoof */
13080 struct cmd_vf_vlan_stripq_result {
13081         cmdline_fixed_string_t set;
13082         cmdline_fixed_string_t vf;
13083         cmdline_fixed_string_t vlan;
13084         cmdline_fixed_string_t stripq;
13085         portid_t port_id;
13086         uint16_t vf_id;
13087         cmdline_fixed_string_t on_off;
13088 };
13089
13090 /* Common CLI fields for vf vlan strip enable disable */
13091 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13092         TOKEN_STRING_INITIALIZER
13093                 (struct cmd_vf_vlan_stripq_result,
13094                  set, "set");
13095 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13096         TOKEN_STRING_INITIALIZER
13097                 (struct cmd_vf_vlan_stripq_result,
13098                  vf, "vf");
13099 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13100         TOKEN_STRING_INITIALIZER
13101                 (struct cmd_vf_vlan_stripq_result,
13102                  vlan, "vlan");
13103 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13104         TOKEN_STRING_INITIALIZER
13105                 (struct cmd_vf_vlan_stripq_result,
13106                  stripq, "stripq");
13107 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13108         TOKEN_NUM_INITIALIZER
13109                 (struct cmd_vf_vlan_stripq_result,
13110                  port_id, UINT16);
13111 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13112         TOKEN_NUM_INITIALIZER
13113                 (struct cmd_vf_vlan_stripq_result,
13114                  vf_id, UINT16);
13115 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13116         TOKEN_STRING_INITIALIZER
13117                 (struct cmd_vf_vlan_stripq_result,
13118                  on_off, "on#off");
13119
13120 static void
13121 cmd_set_vf_vlan_stripq_parsed(
13122         void *parsed_result,
13123         __attribute__((unused)) struct cmdline *cl,
13124         __attribute__((unused)) void *data)
13125 {
13126         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13127         int ret = -ENOTSUP;
13128
13129         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13130
13131         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13132                 return;
13133
13134 #ifdef RTE_LIBRTE_IXGBE_PMD
13135         if (ret == -ENOTSUP)
13136                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13137                         res->vf_id, is_on);
13138 #endif
13139 #ifdef RTE_LIBRTE_I40E_PMD
13140         if (ret == -ENOTSUP)
13141                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13142                         res->vf_id, is_on);
13143 #endif
13144 #ifdef RTE_LIBRTE_BNXT_PMD
13145         if (ret == -ENOTSUP)
13146                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13147                         res->vf_id, is_on);
13148 #endif
13149
13150         switch (ret) {
13151         case 0:
13152                 break;
13153         case -EINVAL:
13154                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13155                 break;
13156         case -ENODEV:
13157                 printf("invalid port_id %d\n", res->port_id);
13158                 break;
13159         case -ENOTSUP:
13160                 printf("function not implemented\n");
13161                 break;
13162         default:
13163                 printf("programming error: (%s)\n", strerror(-ret));
13164         }
13165 }
13166
13167 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13168         .f = cmd_set_vf_vlan_stripq_parsed,
13169         .data = NULL,
13170         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13171         .tokens = {
13172                 (void *)&cmd_vf_vlan_stripq_set,
13173                 (void *)&cmd_vf_vlan_stripq_vf,
13174                 (void *)&cmd_vf_vlan_stripq_vlan,
13175                 (void *)&cmd_vf_vlan_stripq_stripq,
13176                 (void *)&cmd_vf_vlan_stripq_port_id,
13177                 (void *)&cmd_vf_vlan_stripq_vf_id,
13178                 (void *)&cmd_vf_vlan_stripq_on_off,
13179                 NULL,
13180         },
13181 };
13182
13183 /* vf vlan insert configuration */
13184
13185 /* Common result structure for vf vlan insert */
13186 struct cmd_vf_vlan_insert_result {
13187         cmdline_fixed_string_t set;
13188         cmdline_fixed_string_t vf;
13189         cmdline_fixed_string_t vlan;
13190         cmdline_fixed_string_t insert;
13191         portid_t port_id;
13192         uint16_t vf_id;
13193         uint16_t vlan_id;
13194 };
13195
13196 /* Common CLI fields for vf vlan insert enable disable */
13197 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13198         TOKEN_STRING_INITIALIZER
13199                 (struct cmd_vf_vlan_insert_result,
13200                  set, "set");
13201 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13202         TOKEN_STRING_INITIALIZER
13203                 (struct cmd_vf_vlan_insert_result,
13204                  vf, "vf");
13205 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13206         TOKEN_STRING_INITIALIZER
13207                 (struct cmd_vf_vlan_insert_result,
13208                  vlan, "vlan");
13209 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13210         TOKEN_STRING_INITIALIZER
13211                 (struct cmd_vf_vlan_insert_result,
13212                  insert, "insert");
13213 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13214         TOKEN_NUM_INITIALIZER
13215                 (struct cmd_vf_vlan_insert_result,
13216                  port_id, UINT16);
13217 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13218         TOKEN_NUM_INITIALIZER
13219                 (struct cmd_vf_vlan_insert_result,
13220                  vf_id, UINT16);
13221 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13222         TOKEN_NUM_INITIALIZER
13223                 (struct cmd_vf_vlan_insert_result,
13224                  vlan_id, UINT16);
13225
13226 static void
13227 cmd_set_vf_vlan_insert_parsed(
13228         void *parsed_result,
13229         __attribute__((unused)) struct cmdline *cl,
13230         __attribute__((unused)) void *data)
13231 {
13232         struct cmd_vf_vlan_insert_result *res = parsed_result;
13233         int ret = -ENOTSUP;
13234
13235         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13236                 return;
13237
13238 #ifdef RTE_LIBRTE_IXGBE_PMD
13239         if (ret == -ENOTSUP)
13240                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13241                         res->vlan_id);
13242 #endif
13243 #ifdef RTE_LIBRTE_I40E_PMD
13244         if (ret == -ENOTSUP)
13245                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13246                         res->vlan_id);
13247 #endif
13248 #ifdef RTE_LIBRTE_BNXT_PMD
13249         if (ret == -ENOTSUP)
13250                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13251                         res->vlan_id);
13252 #endif
13253
13254         switch (ret) {
13255         case 0:
13256                 break;
13257         case -EINVAL:
13258                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13259                 break;
13260         case -ENODEV:
13261                 printf("invalid port_id %d\n", res->port_id);
13262                 break;
13263         case -ENOTSUP:
13264                 printf("function not implemented\n");
13265                 break;
13266         default:
13267                 printf("programming error: (%s)\n", strerror(-ret));
13268         }
13269 }
13270
13271 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13272         .f = cmd_set_vf_vlan_insert_parsed,
13273         .data = NULL,
13274         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13275         .tokens = {
13276                 (void *)&cmd_vf_vlan_insert_set,
13277                 (void *)&cmd_vf_vlan_insert_vf,
13278                 (void *)&cmd_vf_vlan_insert_vlan,
13279                 (void *)&cmd_vf_vlan_insert_insert,
13280                 (void *)&cmd_vf_vlan_insert_port_id,
13281                 (void *)&cmd_vf_vlan_insert_vf_id,
13282                 (void *)&cmd_vf_vlan_insert_vlan_id,
13283                 NULL,
13284         },
13285 };
13286
13287 /* tx loopback configuration */
13288
13289 /* Common result structure for tx loopback */
13290 struct cmd_tx_loopback_result {
13291         cmdline_fixed_string_t set;
13292         cmdline_fixed_string_t tx;
13293         cmdline_fixed_string_t loopback;
13294         portid_t port_id;
13295         cmdline_fixed_string_t on_off;
13296 };
13297
13298 /* Common CLI fields for tx loopback enable disable */
13299 cmdline_parse_token_string_t cmd_tx_loopback_set =
13300         TOKEN_STRING_INITIALIZER
13301                 (struct cmd_tx_loopback_result,
13302                  set, "set");
13303 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13304         TOKEN_STRING_INITIALIZER
13305                 (struct cmd_tx_loopback_result,
13306                  tx, "tx");
13307 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13308         TOKEN_STRING_INITIALIZER
13309                 (struct cmd_tx_loopback_result,
13310                  loopback, "loopback");
13311 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13312         TOKEN_NUM_INITIALIZER
13313                 (struct cmd_tx_loopback_result,
13314                  port_id, UINT16);
13315 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13316         TOKEN_STRING_INITIALIZER
13317                 (struct cmd_tx_loopback_result,
13318                  on_off, "on#off");
13319
13320 static void
13321 cmd_set_tx_loopback_parsed(
13322         void *parsed_result,
13323         __attribute__((unused)) struct cmdline *cl,
13324         __attribute__((unused)) void *data)
13325 {
13326         struct cmd_tx_loopback_result *res = parsed_result;
13327         int ret = -ENOTSUP;
13328
13329         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13330
13331         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13332                 return;
13333
13334 #ifdef RTE_LIBRTE_IXGBE_PMD
13335         if (ret == -ENOTSUP)
13336                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13337 #endif
13338 #ifdef RTE_LIBRTE_I40E_PMD
13339         if (ret == -ENOTSUP)
13340                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13341 #endif
13342 #ifdef RTE_LIBRTE_BNXT_PMD
13343         if (ret == -ENOTSUP)
13344                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13345 #endif
13346 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13347         if (ret == -ENOTSUP)
13348                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13349 #endif
13350
13351         switch (ret) {
13352         case 0:
13353                 break;
13354         case -EINVAL:
13355                 printf("invalid is_on %d\n", is_on);
13356                 break;
13357         case -ENODEV:
13358                 printf("invalid port_id %d\n", res->port_id);
13359                 break;
13360         case -ENOTSUP:
13361                 printf("function not implemented\n");
13362                 break;
13363         default:
13364                 printf("programming error: (%s)\n", strerror(-ret));
13365         }
13366 }
13367
13368 cmdline_parse_inst_t cmd_set_tx_loopback = {
13369         .f = cmd_set_tx_loopback_parsed,
13370         .data = NULL,
13371         .help_str = "set tx loopback <port_id> on|off",
13372         .tokens = {
13373                 (void *)&cmd_tx_loopback_set,
13374                 (void *)&cmd_tx_loopback_tx,
13375                 (void *)&cmd_tx_loopback_loopback,
13376                 (void *)&cmd_tx_loopback_port_id,
13377                 (void *)&cmd_tx_loopback_on_off,
13378                 NULL,
13379         },
13380 };
13381
13382 /* all queues drop enable configuration */
13383
13384 /* Common result structure for all queues drop enable */
13385 struct cmd_all_queues_drop_en_result {
13386         cmdline_fixed_string_t set;
13387         cmdline_fixed_string_t all;
13388         cmdline_fixed_string_t queues;
13389         cmdline_fixed_string_t drop;
13390         portid_t port_id;
13391         cmdline_fixed_string_t on_off;
13392 };
13393
13394 /* Common CLI fields for tx loopback enable disable */
13395 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13396         TOKEN_STRING_INITIALIZER
13397                 (struct cmd_all_queues_drop_en_result,
13398                  set, "set");
13399 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13400         TOKEN_STRING_INITIALIZER
13401                 (struct cmd_all_queues_drop_en_result,
13402                  all, "all");
13403 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13404         TOKEN_STRING_INITIALIZER
13405                 (struct cmd_all_queues_drop_en_result,
13406                  queues, "queues");
13407 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13408         TOKEN_STRING_INITIALIZER
13409                 (struct cmd_all_queues_drop_en_result,
13410                  drop, "drop");
13411 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13412         TOKEN_NUM_INITIALIZER
13413                 (struct cmd_all_queues_drop_en_result,
13414                  port_id, UINT16);
13415 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13416         TOKEN_STRING_INITIALIZER
13417                 (struct cmd_all_queues_drop_en_result,
13418                  on_off, "on#off");
13419
13420 static void
13421 cmd_set_all_queues_drop_en_parsed(
13422         void *parsed_result,
13423         __attribute__((unused)) struct cmdline *cl,
13424         __attribute__((unused)) void *data)
13425 {
13426         struct cmd_all_queues_drop_en_result *res = parsed_result;
13427         int ret = -ENOTSUP;
13428         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13429
13430         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13431                 return;
13432
13433 #ifdef RTE_LIBRTE_IXGBE_PMD
13434         if (ret == -ENOTSUP)
13435                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13436 #endif
13437 #ifdef RTE_LIBRTE_BNXT_PMD
13438         if (ret == -ENOTSUP)
13439                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13440 #endif
13441         switch (ret) {
13442         case 0:
13443                 break;
13444         case -EINVAL:
13445                 printf("invalid is_on %d\n", is_on);
13446                 break;
13447         case -ENODEV:
13448                 printf("invalid port_id %d\n", res->port_id);
13449                 break;
13450         case -ENOTSUP:
13451                 printf("function not implemented\n");
13452                 break;
13453         default:
13454                 printf("programming error: (%s)\n", strerror(-ret));
13455         }
13456 }
13457
13458 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13459         .f = cmd_set_all_queues_drop_en_parsed,
13460         .data = NULL,
13461         .help_str = "set all queues drop <port_id> on|off",
13462         .tokens = {
13463                 (void *)&cmd_all_queues_drop_en_set,
13464                 (void *)&cmd_all_queues_drop_en_all,
13465                 (void *)&cmd_all_queues_drop_en_queues,
13466                 (void *)&cmd_all_queues_drop_en_drop,
13467                 (void *)&cmd_all_queues_drop_en_port_id,
13468                 (void *)&cmd_all_queues_drop_en_on_off,
13469                 NULL,
13470         },
13471 };
13472
13473 /* vf split drop enable configuration */
13474
13475 /* Common result structure for vf split drop enable */
13476 struct cmd_vf_split_drop_en_result {
13477         cmdline_fixed_string_t set;
13478         cmdline_fixed_string_t vf;
13479         cmdline_fixed_string_t split;
13480         cmdline_fixed_string_t drop;
13481         portid_t port_id;
13482         uint16_t vf_id;
13483         cmdline_fixed_string_t on_off;
13484 };
13485
13486 /* Common CLI fields for vf split drop enable disable */
13487 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13488         TOKEN_STRING_INITIALIZER
13489                 (struct cmd_vf_split_drop_en_result,
13490                  set, "set");
13491 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13492         TOKEN_STRING_INITIALIZER
13493                 (struct cmd_vf_split_drop_en_result,
13494                  vf, "vf");
13495 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13496         TOKEN_STRING_INITIALIZER
13497                 (struct cmd_vf_split_drop_en_result,
13498                  split, "split");
13499 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13500         TOKEN_STRING_INITIALIZER
13501                 (struct cmd_vf_split_drop_en_result,
13502                  drop, "drop");
13503 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13504         TOKEN_NUM_INITIALIZER
13505                 (struct cmd_vf_split_drop_en_result,
13506                  port_id, UINT16);
13507 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13508         TOKEN_NUM_INITIALIZER
13509                 (struct cmd_vf_split_drop_en_result,
13510                  vf_id, UINT16);
13511 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13512         TOKEN_STRING_INITIALIZER
13513                 (struct cmd_vf_split_drop_en_result,
13514                  on_off, "on#off");
13515
13516 static void
13517 cmd_set_vf_split_drop_en_parsed(
13518         void *parsed_result,
13519         __attribute__((unused)) struct cmdline *cl,
13520         __attribute__((unused)) void *data)
13521 {
13522         struct cmd_vf_split_drop_en_result *res = parsed_result;
13523         int ret = -ENOTSUP;
13524         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13525
13526         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13527                 return;
13528
13529 #ifdef RTE_LIBRTE_IXGBE_PMD
13530         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13531                         is_on);
13532 #endif
13533         switch (ret) {
13534         case 0:
13535                 break;
13536         case -EINVAL:
13537                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13538                 break;
13539         case -ENODEV:
13540                 printf("invalid port_id %d\n", res->port_id);
13541                 break;
13542         case -ENOTSUP:
13543                 printf("not supported on port %d\n", res->port_id);
13544                 break;
13545         default:
13546                 printf("programming error: (%s)\n", strerror(-ret));
13547         }
13548 }
13549
13550 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13551         .f = cmd_set_vf_split_drop_en_parsed,
13552         .data = NULL,
13553         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13554         .tokens = {
13555                 (void *)&cmd_vf_split_drop_en_set,
13556                 (void *)&cmd_vf_split_drop_en_vf,
13557                 (void *)&cmd_vf_split_drop_en_split,
13558                 (void *)&cmd_vf_split_drop_en_drop,
13559                 (void *)&cmd_vf_split_drop_en_port_id,
13560                 (void *)&cmd_vf_split_drop_en_vf_id,
13561                 (void *)&cmd_vf_split_drop_en_on_off,
13562                 NULL,
13563         },
13564 };
13565
13566 /* vf mac address configuration */
13567
13568 /* Common result structure for vf mac address */
13569 struct cmd_set_vf_mac_addr_result {
13570         cmdline_fixed_string_t set;
13571         cmdline_fixed_string_t vf;
13572         cmdline_fixed_string_t mac;
13573         cmdline_fixed_string_t addr;
13574         portid_t port_id;
13575         uint16_t vf_id;
13576         struct ether_addr mac_addr;
13577
13578 };
13579
13580 /* Common CLI fields for vf split drop enable disable */
13581 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13582         TOKEN_STRING_INITIALIZER
13583                 (struct cmd_set_vf_mac_addr_result,
13584                  set, "set");
13585 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13586         TOKEN_STRING_INITIALIZER
13587                 (struct cmd_set_vf_mac_addr_result,
13588                  vf, "vf");
13589 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13590         TOKEN_STRING_INITIALIZER
13591                 (struct cmd_set_vf_mac_addr_result,
13592                  mac, "mac");
13593 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13594         TOKEN_STRING_INITIALIZER
13595                 (struct cmd_set_vf_mac_addr_result,
13596                  addr, "addr");
13597 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13598         TOKEN_NUM_INITIALIZER
13599                 (struct cmd_set_vf_mac_addr_result,
13600                  port_id, UINT16);
13601 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13602         TOKEN_NUM_INITIALIZER
13603                 (struct cmd_set_vf_mac_addr_result,
13604                  vf_id, UINT16);
13605 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13606         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13607                  mac_addr);
13608
13609 static void
13610 cmd_set_vf_mac_addr_parsed(
13611         void *parsed_result,
13612         __attribute__((unused)) struct cmdline *cl,
13613         __attribute__((unused)) void *data)
13614 {
13615         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13616         int ret = -ENOTSUP;
13617
13618         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13619                 return;
13620
13621 #ifdef RTE_LIBRTE_IXGBE_PMD
13622         if (ret == -ENOTSUP)
13623                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13624                                 &res->mac_addr);
13625 #endif
13626 #ifdef RTE_LIBRTE_I40E_PMD
13627         if (ret == -ENOTSUP)
13628                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13629                                 &res->mac_addr);
13630 #endif
13631 #ifdef RTE_LIBRTE_BNXT_PMD
13632         if (ret == -ENOTSUP)
13633                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13634                                 &res->mac_addr);
13635 #endif
13636
13637         switch (ret) {
13638         case 0:
13639                 break;
13640         case -EINVAL:
13641                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13642                 break;
13643         case -ENODEV:
13644                 printf("invalid port_id %d\n", res->port_id);
13645                 break;
13646         case -ENOTSUP:
13647                 printf("function not implemented\n");
13648                 break;
13649         default:
13650                 printf("programming error: (%s)\n", strerror(-ret));
13651         }
13652 }
13653
13654 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13655         .f = cmd_set_vf_mac_addr_parsed,
13656         .data = NULL,
13657         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13658         .tokens = {
13659                 (void *)&cmd_set_vf_mac_addr_set,
13660                 (void *)&cmd_set_vf_mac_addr_vf,
13661                 (void *)&cmd_set_vf_mac_addr_mac,
13662                 (void *)&cmd_set_vf_mac_addr_addr,
13663                 (void *)&cmd_set_vf_mac_addr_port_id,
13664                 (void *)&cmd_set_vf_mac_addr_vf_id,
13665                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13666                 NULL,
13667         },
13668 };
13669
13670 /* MACsec configuration */
13671
13672 /* Common result structure for MACsec offload enable */
13673 struct cmd_macsec_offload_on_result {
13674         cmdline_fixed_string_t set;
13675         cmdline_fixed_string_t macsec;
13676         cmdline_fixed_string_t offload;
13677         portid_t port_id;
13678         cmdline_fixed_string_t on;
13679         cmdline_fixed_string_t encrypt;
13680         cmdline_fixed_string_t en_on_off;
13681         cmdline_fixed_string_t replay_protect;
13682         cmdline_fixed_string_t rp_on_off;
13683 };
13684
13685 /* Common CLI fields for MACsec offload disable */
13686 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13687         TOKEN_STRING_INITIALIZER
13688                 (struct cmd_macsec_offload_on_result,
13689                  set, "set");
13690 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13691         TOKEN_STRING_INITIALIZER
13692                 (struct cmd_macsec_offload_on_result,
13693                  macsec, "macsec");
13694 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13695         TOKEN_STRING_INITIALIZER
13696                 (struct cmd_macsec_offload_on_result,
13697                  offload, "offload");
13698 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13699         TOKEN_NUM_INITIALIZER
13700                 (struct cmd_macsec_offload_on_result,
13701                  port_id, UINT16);
13702 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13703         TOKEN_STRING_INITIALIZER
13704                 (struct cmd_macsec_offload_on_result,
13705                  on, "on");
13706 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13707         TOKEN_STRING_INITIALIZER
13708                 (struct cmd_macsec_offload_on_result,
13709                  encrypt, "encrypt");
13710 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13711         TOKEN_STRING_INITIALIZER
13712                 (struct cmd_macsec_offload_on_result,
13713                  en_on_off, "on#off");
13714 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13715         TOKEN_STRING_INITIALIZER
13716                 (struct cmd_macsec_offload_on_result,
13717                  replay_protect, "replay-protect");
13718 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13719         TOKEN_STRING_INITIALIZER
13720                 (struct cmd_macsec_offload_on_result,
13721                  rp_on_off, "on#off");
13722
13723 static void
13724 cmd_set_macsec_offload_on_parsed(
13725         void *parsed_result,
13726         __attribute__((unused)) struct cmdline *cl,
13727         __attribute__((unused)) void *data)
13728 {
13729         struct cmd_macsec_offload_on_result *res = parsed_result;
13730         int ret = -ENOTSUP;
13731         portid_t port_id = res->port_id;
13732         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13733         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13734         struct rte_eth_dev_info dev_info;
13735
13736         if (port_id_is_invalid(port_id, ENABLED_WARN))
13737                 return;
13738         if (!port_is_stopped(port_id)) {
13739                 printf("Please stop port %d first\n", port_id);
13740                 return;
13741         }
13742
13743         rte_eth_dev_info_get(port_id, &dev_info);
13744         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13745 #ifdef RTE_LIBRTE_IXGBE_PMD
13746                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13747 #endif
13748         }
13749         RTE_SET_USED(en);
13750         RTE_SET_USED(rp);
13751
13752         switch (ret) {
13753         case 0:
13754                 ports[port_id].dev_conf.txmode.offloads |=
13755                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13756                 cmd_reconfig_device_queue(port_id, 1, 1);
13757                 break;
13758         case -ENODEV:
13759                 printf("invalid port_id %d\n", port_id);
13760                 break;
13761         case -ENOTSUP:
13762                 printf("not supported on port %d\n", port_id);
13763                 break;
13764         default:
13765                 printf("programming error: (%s)\n", strerror(-ret));
13766         }
13767 }
13768
13769 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13770         .f = cmd_set_macsec_offload_on_parsed,
13771         .data = NULL,
13772         .help_str = "set macsec offload <port_id> on "
13773                 "encrypt on|off replay-protect on|off",
13774         .tokens = {
13775                 (void *)&cmd_macsec_offload_on_set,
13776                 (void *)&cmd_macsec_offload_on_macsec,
13777                 (void *)&cmd_macsec_offload_on_offload,
13778                 (void *)&cmd_macsec_offload_on_port_id,
13779                 (void *)&cmd_macsec_offload_on_on,
13780                 (void *)&cmd_macsec_offload_on_encrypt,
13781                 (void *)&cmd_macsec_offload_on_en_on_off,
13782                 (void *)&cmd_macsec_offload_on_replay_protect,
13783                 (void *)&cmd_macsec_offload_on_rp_on_off,
13784                 NULL,
13785         },
13786 };
13787
13788 /* Common result structure for MACsec offload disable */
13789 struct cmd_macsec_offload_off_result {
13790         cmdline_fixed_string_t set;
13791         cmdline_fixed_string_t macsec;
13792         cmdline_fixed_string_t offload;
13793         portid_t port_id;
13794         cmdline_fixed_string_t off;
13795 };
13796
13797 /* Common CLI fields for MACsec offload disable */
13798 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13799         TOKEN_STRING_INITIALIZER
13800                 (struct cmd_macsec_offload_off_result,
13801                  set, "set");
13802 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13803         TOKEN_STRING_INITIALIZER
13804                 (struct cmd_macsec_offload_off_result,
13805                  macsec, "macsec");
13806 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13807         TOKEN_STRING_INITIALIZER
13808                 (struct cmd_macsec_offload_off_result,
13809                  offload, "offload");
13810 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13811         TOKEN_NUM_INITIALIZER
13812                 (struct cmd_macsec_offload_off_result,
13813                  port_id, UINT16);
13814 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13815         TOKEN_STRING_INITIALIZER
13816                 (struct cmd_macsec_offload_off_result,
13817                  off, "off");
13818
13819 static void
13820 cmd_set_macsec_offload_off_parsed(
13821         void *parsed_result,
13822         __attribute__((unused)) struct cmdline *cl,
13823         __attribute__((unused)) void *data)
13824 {
13825         struct cmd_macsec_offload_off_result *res = parsed_result;
13826         int ret = -ENOTSUP;
13827         struct rte_eth_dev_info dev_info;
13828         portid_t port_id = res->port_id;
13829
13830         if (port_id_is_invalid(port_id, ENABLED_WARN))
13831                 return;
13832         if (!port_is_stopped(port_id)) {
13833                 printf("Please stop port %d first\n", port_id);
13834                 return;
13835         }
13836
13837         rte_eth_dev_info_get(port_id, &dev_info);
13838         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13839 #ifdef RTE_LIBRTE_IXGBE_PMD
13840                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13841 #endif
13842         }
13843         switch (ret) {
13844         case 0:
13845                 ports[port_id].dev_conf.txmode.offloads &=
13846                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13847                 cmd_reconfig_device_queue(port_id, 1, 1);
13848                 break;
13849         case -ENODEV:
13850                 printf("invalid port_id %d\n", port_id);
13851                 break;
13852         case -ENOTSUP:
13853                 printf("not supported on port %d\n", port_id);
13854                 break;
13855         default:
13856                 printf("programming error: (%s)\n", strerror(-ret));
13857         }
13858 }
13859
13860 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13861         .f = cmd_set_macsec_offload_off_parsed,
13862         .data = NULL,
13863         .help_str = "set macsec offload <port_id> off",
13864         .tokens = {
13865                 (void *)&cmd_macsec_offload_off_set,
13866                 (void *)&cmd_macsec_offload_off_macsec,
13867                 (void *)&cmd_macsec_offload_off_offload,
13868                 (void *)&cmd_macsec_offload_off_port_id,
13869                 (void *)&cmd_macsec_offload_off_off,
13870                 NULL,
13871         },
13872 };
13873
13874 /* Common result structure for MACsec secure connection configure */
13875 struct cmd_macsec_sc_result {
13876         cmdline_fixed_string_t set;
13877         cmdline_fixed_string_t macsec;
13878         cmdline_fixed_string_t sc;
13879         cmdline_fixed_string_t tx_rx;
13880         portid_t port_id;
13881         struct ether_addr mac;
13882         uint16_t pi;
13883 };
13884
13885 /* Common CLI fields for MACsec secure connection configure */
13886 cmdline_parse_token_string_t cmd_macsec_sc_set =
13887         TOKEN_STRING_INITIALIZER
13888                 (struct cmd_macsec_sc_result,
13889                  set, "set");
13890 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13891         TOKEN_STRING_INITIALIZER
13892                 (struct cmd_macsec_sc_result,
13893                  macsec, "macsec");
13894 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13895         TOKEN_STRING_INITIALIZER
13896                 (struct cmd_macsec_sc_result,
13897                  sc, "sc");
13898 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13899         TOKEN_STRING_INITIALIZER
13900                 (struct cmd_macsec_sc_result,
13901                  tx_rx, "tx#rx");
13902 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13903         TOKEN_NUM_INITIALIZER
13904                 (struct cmd_macsec_sc_result,
13905                  port_id, UINT16);
13906 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13907         TOKEN_ETHERADDR_INITIALIZER
13908                 (struct cmd_macsec_sc_result,
13909                  mac);
13910 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13911         TOKEN_NUM_INITIALIZER
13912                 (struct cmd_macsec_sc_result,
13913                  pi, UINT16);
13914
13915 static void
13916 cmd_set_macsec_sc_parsed(
13917         void *parsed_result,
13918         __attribute__((unused)) struct cmdline *cl,
13919         __attribute__((unused)) void *data)
13920 {
13921         struct cmd_macsec_sc_result *res = parsed_result;
13922         int ret = -ENOTSUP;
13923         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13924
13925 #ifdef RTE_LIBRTE_IXGBE_PMD
13926         ret = is_tx ?
13927                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13928                                 res->mac.addr_bytes) :
13929                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13930                                 res->mac.addr_bytes, res->pi);
13931 #endif
13932         RTE_SET_USED(is_tx);
13933
13934         switch (ret) {
13935         case 0:
13936                 break;
13937         case -ENODEV:
13938                 printf("invalid port_id %d\n", res->port_id);
13939                 break;
13940         case -ENOTSUP:
13941                 printf("not supported on port %d\n", res->port_id);
13942                 break;
13943         default:
13944                 printf("programming error: (%s)\n", strerror(-ret));
13945         }
13946 }
13947
13948 cmdline_parse_inst_t cmd_set_macsec_sc = {
13949         .f = cmd_set_macsec_sc_parsed,
13950         .data = NULL,
13951         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13952         .tokens = {
13953                 (void *)&cmd_macsec_sc_set,
13954                 (void *)&cmd_macsec_sc_macsec,
13955                 (void *)&cmd_macsec_sc_sc,
13956                 (void *)&cmd_macsec_sc_tx_rx,
13957                 (void *)&cmd_macsec_sc_port_id,
13958                 (void *)&cmd_macsec_sc_mac,
13959                 (void *)&cmd_macsec_sc_pi,
13960                 NULL,
13961         },
13962 };
13963
13964 /* Common result structure for MACsec secure connection configure */
13965 struct cmd_macsec_sa_result {
13966         cmdline_fixed_string_t set;
13967         cmdline_fixed_string_t macsec;
13968         cmdline_fixed_string_t sa;
13969         cmdline_fixed_string_t tx_rx;
13970         portid_t port_id;
13971         uint8_t idx;
13972         uint8_t an;
13973         uint32_t pn;
13974         cmdline_fixed_string_t key;
13975 };
13976
13977 /* Common CLI fields for MACsec secure connection configure */
13978 cmdline_parse_token_string_t cmd_macsec_sa_set =
13979         TOKEN_STRING_INITIALIZER
13980                 (struct cmd_macsec_sa_result,
13981                  set, "set");
13982 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13983         TOKEN_STRING_INITIALIZER
13984                 (struct cmd_macsec_sa_result,
13985                  macsec, "macsec");
13986 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13987         TOKEN_STRING_INITIALIZER
13988                 (struct cmd_macsec_sa_result,
13989                  sa, "sa");
13990 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13991         TOKEN_STRING_INITIALIZER
13992                 (struct cmd_macsec_sa_result,
13993                  tx_rx, "tx#rx");
13994 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13995         TOKEN_NUM_INITIALIZER
13996                 (struct cmd_macsec_sa_result,
13997                  port_id, UINT16);
13998 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13999         TOKEN_NUM_INITIALIZER
14000                 (struct cmd_macsec_sa_result,
14001                  idx, UINT8);
14002 cmdline_parse_token_num_t cmd_macsec_sa_an =
14003         TOKEN_NUM_INITIALIZER
14004                 (struct cmd_macsec_sa_result,
14005                  an, UINT8);
14006 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14007         TOKEN_NUM_INITIALIZER
14008                 (struct cmd_macsec_sa_result,
14009                  pn, UINT32);
14010 cmdline_parse_token_string_t cmd_macsec_sa_key =
14011         TOKEN_STRING_INITIALIZER
14012                 (struct cmd_macsec_sa_result,
14013                  key, NULL);
14014
14015 static void
14016 cmd_set_macsec_sa_parsed(
14017         void *parsed_result,
14018         __attribute__((unused)) struct cmdline *cl,
14019         __attribute__((unused)) void *data)
14020 {
14021         struct cmd_macsec_sa_result *res = parsed_result;
14022         int ret = -ENOTSUP;
14023         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14024         uint8_t key[16] = { 0 };
14025         uint8_t xdgt0;
14026         uint8_t xdgt1;
14027         int key_len;
14028         int i;
14029
14030         key_len = strlen(res->key) / 2;
14031         if (key_len > 16)
14032                 key_len = 16;
14033
14034         for (i = 0; i < key_len; i++) {
14035                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14036                 if (xdgt0 == 0xFF)
14037                         return;
14038                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14039                 if (xdgt1 == 0xFF)
14040                         return;
14041                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14042         }
14043
14044 #ifdef RTE_LIBRTE_IXGBE_PMD
14045         ret = is_tx ?
14046                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14047                         res->idx, res->an, res->pn, key) :
14048                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14049                         res->idx, res->an, res->pn, key);
14050 #endif
14051         RTE_SET_USED(is_tx);
14052         RTE_SET_USED(key);
14053
14054         switch (ret) {
14055         case 0:
14056                 break;
14057         case -EINVAL:
14058                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14059                 break;
14060         case -ENODEV:
14061                 printf("invalid port_id %d\n", res->port_id);
14062                 break;
14063         case -ENOTSUP:
14064                 printf("not supported on port %d\n", res->port_id);
14065                 break;
14066         default:
14067                 printf("programming error: (%s)\n", strerror(-ret));
14068         }
14069 }
14070
14071 cmdline_parse_inst_t cmd_set_macsec_sa = {
14072         .f = cmd_set_macsec_sa_parsed,
14073         .data = NULL,
14074         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14075         .tokens = {
14076                 (void *)&cmd_macsec_sa_set,
14077                 (void *)&cmd_macsec_sa_macsec,
14078                 (void *)&cmd_macsec_sa_sa,
14079                 (void *)&cmd_macsec_sa_tx_rx,
14080                 (void *)&cmd_macsec_sa_port_id,
14081                 (void *)&cmd_macsec_sa_idx,
14082                 (void *)&cmd_macsec_sa_an,
14083                 (void *)&cmd_macsec_sa_pn,
14084                 (void *)&cmd_macsec_sa_key,
14085                 NULL,
14086         },
14087 };
14088
14089 /* VF unicast promiscuous mode configuration */
14090
14091 /* Common result structure for VF unicast promiscuous mode */
14092 struct cmd_vf_promisc_result {
14093         cmdline_fixed_string_t set;
14094         cmdline_fixed_string_t vf;
14095         cmdline_fixed_string_t promisc;
14096         portid_t port_id;
14097         uint32_t vf_id;
14098         cmdline_fixed_string_t on_off;
14099 };
14100
14101 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14102 cmdline_parse_token_string_t cmd_vf_promisc_set =
14103         TOKEN_STRING_INITIALIZER
14104                 (struct cmd_vf_promisc_result,
14105                  set, "set");
14106 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14107         TOKEN_STRING_INITIALIZER
14108                 (struct cmd_vf_promisc_result,
14109                  vf, "vf");
14110 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14111         TOKEN_STRING_INITIALIZER
14112                 (struct cmd_vf_promisc_result,
14113                  promisc, "promisc");
14114 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14115         TOKEN_NUM_INITIALIZER
14116                 (struct cmd_vf_promisc_result,
14117                  port_id, UINT16);
14118 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14119         TOKEN_NUM_INITIALIZER
14120                 (struct cmd_vf_promisc_result,
14121                  vf_id, UINT32);
14122 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14123         TOKEN_STRING_INITIALIZER
14124                 (struct cmd_vf_promisc_result,
14125                  on_off, "on#off");
14126
14127 static void
14128 cmd_set_vf_promisc_parsed(
14129         void *parsed_result,
14130         __attribute__((unused)) struct cmdline *cl,
14131         __attribute__((unused)) void *data)
14132 {
14133         struct cmd_vf_promisc_result *res = parsed_result;
14134         int ret = -ENOTSUP;
14135
14136         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14137
14138         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14139                 return;
14140
14141 #ifdef RTE_LIBRTE_I40E_PMD
14142         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14143                                                   res->vf_id, is_on);
14144 #endif
14145
14146         switch (ret) {
14147         case 0:
14148                 break;
14149         case -EINVAL:
14150                 printf("invalid vf_id %d\n", res->vf_id);
14151                 break;
14152         case -ENODEV:
14153                 printf("invalid port_id %d\n", res->port_id);
14154                 break;
14155         case -ENOTSUP:
14156                 printf("function not implemented\n");
14157                 break;
14158         default:
14159                 printf("programming error: (%s)\n", strerror(-ret));
14160         }
14161 }
14162
14163 cmdline_parse_inst_t cmd_set_vf_promisc = {
14164         .f = cmd_set_vf_promisc_parsed,
14165         .data = NULL,
14166         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14167                 "Set unicast promiscuous mode for a VF from the PF",
14168         .tokens = {
14169                 (void *)&cmd_vf_promisc_set,
14170                 (void *)&cmd_vf_promisc_vf,
14171                 (void *)&cmd_vf_promisc_promisc,
14172                 (void *)&cmd_vf_promisc_port_id,
14173                 (void *)&cmd_vf_promisc_vf_id,
14174                 (void *)&cmd_vf_promisc_on_off,
14175                 NULL,
14176         },
14177 };
14178
14179 /* VF multicast promiscuous mode configuration */
14180
14181 /* Common result structure for VF multicast promiscuous mode */
14182 struct cmd_vf_allmulti_result {
14183         cmdline_fixed_string_t set;
14184         cmdline_fixed_string_t vf;
14185         cmdline_fixed_string_t allmulti;
14186         portid_t port_id;
14187         uint32_t vf_id;
14188         cmdline_fixed_string_t on_off;
14189 };
14190
14191 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14192 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14193         TOKEN_STRING_INITIALIZER
14194                 (struct cmd_vf_allmulti_result,
14195                  set, "set");
14196 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14197         TOKEN_STRING_INITIALIZER
14198                 (struct cmd_vf_allmulti_result,
14199                  vf, "vf");
14200 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14201         TOKEN_STRING_INITIALIZER
14202                 (struct cmd_vf_allmulti_result,
14203                  allmulti, "allmulti");
14204 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14205         TOKEN_NUM_INITIALIZER
14206                 (struct cmd_vf_allmulti_result,
14207                  port_id, UINT16);
14208 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14209         TOKEN_NUM_INITIALIZER
14210                 (struct cmd_vf_allmulti_result,
14211                  vf_id, UINT32);
14212 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14213         TOKEN_STRING_INITIALIZER
14214                 (struct cmd_vf_allmulti_result,
14215                  on_off, "on#off");
14216
14217 static void
14218 cmd_set_vf_allmulti_parsed(
14219         void *parsed_result,
14220         __attribute__((unused)) struct cmdline *cl,
14221         __attribute__((unused)) void *data)
14222 {
14223         struct cmd_vf_allmulti_result *res = parsed_result;
14224         int ret = -ENOTSUP;
14225
14226         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14227
14228         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14229                 return;
14230
14231 #ifdef RTE_LIBRTE_I40E_PMD
14232         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14233                                                     res->vf_id, is_on);
14234 #endif
14235
14236         switch (ret) {
14237         case 0:
14238                 break;
14239         case -EINVAL:
14240                 printf("invalid vf_id %d\n", res->vf_id);
14241                 break;
14242         case -ENODEV:
14243                 printf("invalid port_id %d\n", res->port_id);
14244                 break;
14245         case -ENOTSUP:
14246                 printf("function not implemented\n");
14247                 break;
14248         default:
14249                 printf("programming error: (%s)\n", strerror(-ret));
14250         }
14251 }
14252
14253 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14254         .f = cmd_set_vf_allmulti_parsed,
14255         .data = NULL,
14256         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14257                 "Set multicast promiscuous mode for a VF from the PF",
14258         .tokens = {
14259                 (void *)&cmd_vf_allmulti_set,
14260                 (void *)&cmd_vf_allmulti_vf,
14261                 (void *)&cmd_vf_allmulti_allmulti,
14262                 (void *)&cmd_vf_allmulti_port_id,
14263                 (void *)&cmd_vf_allmulti_vf_id,
14264                 (void *)&cmd_vf_allmulti_on_off,
14265                 NULL,
14266         },
14267 };
14268
14269 /* vf broadcast mode configuration */
14270
14271 /* Common result structure for vf broadcast */
14272 struct cmd_set_vf_broadcast_result {
14273         cmdline_fixed_string_t set;
14274         cmdline_fixed_string_t vf;
14275         cmdline_fixed_string_t broadcast;
14276         portid_t port_id;
14277         uint16_t vf_id;
14278         cmdline_fixed_string_t on_off;
14279 };
14280
14281 /* Common CLI fields for vf broadcast enable disable */
14282 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14283         TOKEN_STRING_INITIALIZER
14284                 (struct cmd_set_vf_broadcast_result,
14285                  set, "set");
14286 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14287         TOKEN_STRING_INITIALIZER
14288                 (struct cmd_set_vf_broadcast_result,
14289                  vf, "vf");
14290 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14291         TOKEN_STRING_INITIALIZER
14292                 (struct cmd_set_vf_broadcast_result,
14293                  broadcast, "broadcast");
14294 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14295         TOKEN_NUM_INITIALIZER
14296                 (struct cmd_set_vf_broadcast_result,
14297                  port_id, UINT16);
14298 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14299         TOKEN_NUM_INITIALIZER
14300                 (struct cmd_set_vf_broadcast_result,
14301                  vf_id, UINT16);
14302 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14303         TOKEN_STRING_INITIALIZER
14304                 (struct cmd_set_vf_broadcast_result,
14305                  on_off, "on#off");
14306
14307 static void
14308 cmd_set_vf_broadcast_parsed(
14309         void *parsed_result,
14310         __attribute__((unused)) struct cmdline *cl,
14311         __attribute__((unused)) void *data)
14312 {
14313         struct cmd_set_vf_broadcast_result *res = parsed_result;
14314         int ret = -ENOTSUP;
14315
14316         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14317
14318         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14319                 return;
14320
14321 #ifdef RTE_LIBRTE_I40E_PMD
14322         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14323                                             res->vf_id, is_on);
14324 #endif
14325
14326         switch (ret) {
14327         case 0:
14328                 break;
14329         case -EINVAL:
14330                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14331                 break;
14332         case -ENODEV:
14333                 printf("invalid port_id %d\n", res->port_id);
14334                 break;
14335         case -ENOTSUP:
14336                 printf("function not implemented\n");
14337                 break;
14338         default:
14339                 printf("programming error: (%s)\n", strerror(-ret));
14340         }
14341 }
14342
14343 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14344         .f = cmd_set_vf_broadcast_parsed,
14345         .data = NULL,
14346         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14347         .tokens = {
14348                 (void *)&cmd_set_vf_broadcast_set,
14349                 (void *)&cmd_set_vf_broadcast_vf,
14350                 (void *)&cmd_set_vf_broadcast_broadcast,
14351                 (void *)&cmd_set_vf_broadcast_port_id,
14352                 (void *)&cmd_set_vf_broadcast_vf_id,
14353                 (void *)&cmd_set_vf_broadcast_on_off,
14354                 NULL,
14355         },
14356 };
14357
14358 /* vf vlan tag configuration */
14359
14360 /* Common result structure for vf vlan tag */
14361 struct cmd_set_vf_vlan_tag_result {
14362         cmdline_fixed_string_t set;
14363         cmdline_fixed_string_t vf;
14364         cmdline_fixed_string_t vlan;
14365         cmdline_fixed_string_t tag;
14366         portid_t port_id;
14367         uint16_t vf_id;
14368         cmdline_fixed_string_t on_off;
14369 };
14370
14371 /* Common CLI fields for vf vlan tag enable disable */
14372 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14373         TOKEN_STRING_INITIALIZER
14374                 (struct cmd_set_vf_vlan_tag_result,
14375                  set, "set");
14376 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14377         TOKEN_STRING_INITIALIZER
14378                 (struct cmd_set_vf_vlan_tag_result,
14379                  vf, "vf");
14380 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14381         TOKEN_STRING_INITIALIZER
14382                 (struct cmd_set_vf_vlan_tag_result,
14383                  vlan, "vlan");
14384 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14385         TOKEN_STRING_INITIALIZER
14386                 (struct cmd_set_vf_vlan_tag_result,
14387                  tag, "tag");
14388 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14389         TOKEN_NUM_INITIALIZER
14390                 (struct cmd_set_vf_vlan_tag_result,
14391                  port_id, UINT16);
14392 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14393         TOKEN_NUM_INITIALIZER
14394                 (struct cmd_set_vf_vlan_tag_result,
14395                  vf_id, UINT16);
14396 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14397         TOKEN_STRING_INITIALIZER
14398                 (struct cmd_set_vf_vlan_tag_result,
14399                  on_off, "on#off");
14400
14401 static void
14402 cmd_set_vf_vlan_tag_parsed(
14403         void *parsed_result,
14404         __attribute__((unused)) struct cmdline *cl,
14405         __attribute__((unused)) void *data)
14406 {
14407         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14408         int ret = -ENOTSUP;
14409
14410         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14411
14412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14413                 return;
14414
14415 #ifdef RTE_LIBRTE_I40E_PMD
14416         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14417                                            res->vf_id, is_on);
14418 #endif
14419
14420         switch (ret) {
14421         case 0:
14422                 break;
14423         case -EINVAL:
14424                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14425                 break;
14426         case -ENODEV:
14427                 printf("invalid port_id %d\n", res->port_id);
14428                 break;
14429         case -ENOTSUP:
14430                 printf("function not implemented\n");
14431                 break;
14432         default:
14433                 printf("programming error: (%s)\n", strerror(-ret));
14434         }
14435 }
14436
14437 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14438         .f = cmd_set_vf_vlan_tag_parsed,
14439         .data = NULL,
14440         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14441         .tokens = {
14442                 (void *)&cmd_set_vf_vlan_tag_set,
14443                 (void *)&cmd_set_vf_vlan_tag_vf,
14444                 (void *)&cmd_set_vf_vlan_tag_vlan,
14445                 (void *)&cmd_set_vf_vlan_tag_tag,
14446                 (void *)&cmd_set_vf_vlan_tag_port_id,
14447                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14448                 (void *)&cmd_set_vf_vlan_tag_on_off,
14449                 NULL,
14450         },
14451 };
14452
14453 /* Common definition of VF and TC TX bandwidth configuration */
14454 struct cmd_vf_tc_bw_result {
14455         cmdline_fixed_string_t set;
14456         cmdline_fixed_string_t vf;
14457         cmdline_fixed_string_t tc;
14458         cmdline_fixed_string_t tx;
14459         cmdline_fixed_string_t min_bw;
14460         cmdline_fixed_string_t max_bw;
14461         cmdline_fixed_string_t strict_link_prio;
14462         portid_t port_id;
14463         uint16_t vf_id;
14464         uint8_t tc_no;
14465         uint32_t bw;
14466         cmdline_fixed_string_t bw_list;
14467         uint8_t tc_map;
14468 };
14469
14470 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14471         TOKEN_STRING_INITIALIZER
14472                 (struct cmd_vf_tc_bw_result,
14473                  set, "set");
14474 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14475         TOKEN_STRING_INITIALIZER
14476                 (struct cmd_vf_tc_bw_result,
14477                  vf, "vf");
14478 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14479         TOKEN_STRING_INITIALIZER
14480                 (struct cmd_vf_tc_bw_result,
14481                  tc, "tc");
14482 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14483         TOKEN_STRING_INITIALIZER
14484                 (struct cmd_vf_tc_bw_result,
14485                  tx, "tx");
14486 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14487         TOKEN_STRING_INITIALIZER
14488                 (struct cmd_vf_tc_bw_result,
14489                  strict_link_prio, "strict-link-priority");
14490 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14491         TOKEN_STRING_INITIALIZER
14492                 (struct cmd_vf_tc_bw_result,
14493                  min_bw, "min-bandwidth");
14494 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14495         TOKEN_STRING_INITIALIZER
14496                 (struct cmd_vf_tc_bw_result,
14497                  max_bw, "max-bandwidth");
14498 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14499         TOKEN_NUM_INITIALIZER
14500                 (struct cmd_vf_tc_bw_result,
14501                  port_id, UINT16);
14502 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14503         TOKEN_NUM_INITIALIZER
14504                 (struct cmd_vf_tc_bw_result,
14505                  vf_id, UINT16);
14506 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14507         TOKEN_NUM_INITIALIZER
14508                 (struct cmd_vf_tc_bw_result,
14509                  tc_no, UINT8);
14510 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14511         TOKEN_NUM_INITIALIZER
14512                 (struct cmd_vf_tc_bw_result,
14513                  bw, UINT32);
14514 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14515         TOKEN_STRING_INITIALIZER
14516                 (struct cmd_vf_tc_bw_result,
14517                  bw_list, NULL);
14518 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14519         TOKEN_NUM_INITIALIZER
14520                 (struct cmd_vf_tc_bw_result,
14521                  tc_map, UINT8);
14522
14523 /* VF max bandwidth setting */
14524 static void
14525 cmd_vf_max_bw_parsed(
14526         void *parsed_result,
14527         __attribute__((unused)) struct cmdline *cl,
14528         __attribute__((unused)) void *data)
14529 {
14530         struct cmd_vf_tc_bw_result *res = parsed_result;
14531         int ret = -ENOTSUP;
14532
14533         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14534                 return;
14535
14536 #ifdef RTE_LIBRTE_I40E_PMD
14537         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14538                                          res->vf_id, res->bw);
14539 #endif
14540
14541         switch (ret) {
14542         case 0:
14543                 break;
14544         case -EINVAL:
14545                 printf("invalid vf_id %d or bandwidth %d\n",
14546                        res->vf_id, res->bw);
14547                 break;
14548         case -ENODEV:
14549                 printf("invalid port_id %d\n", res->port_id);
14550                 break;
14551         case -ENOTSUP:
14552                 printf("function not implemented\n");
14553                 break;
14554         default:
14555                 printf("programming error: (%s)\n", strerror(-ret));
14556         }
14557 }
14558
14559 cmdline_parse_inst_t cmd_vf_max_bw = {
14560         .f = cmd_vf_max_bw_parsed,
14561         .data = NULL,
14562         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14563         .tokens = {
14564                 (void *)&cmd_vf_tc_bw_set,
14565                 (void *)&cmd_vf_tc_bw_vf,
14566                 (void *)&cmd_vf_tc_bw_tx,
14567                 (void *)&cmd_vf_tc_bw_max_bw,
14568                 (void *)&cmd_vf_tc_bw_port_id,
14569                 (void *)&cmd_vf_tc_bw_vf_id,
14570                 (void *)&cmd_vf_tc_bw_bw,
14571                 NULL,
14572         },
14573 };
14574
14575 static int
14576 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14577                            uint8_t *tc_num,
14578                            char *str)
14579 {
14580         uint32_t size;
14581         const char *p, *p0 = str;
14582         char s[256];
14583         char *end;
14584         char *str_fld[16];
14585         uint16_t i;
14586         int ret;
14587
14588         p = strchr(p0, '(');
14589         if (p == NULL) {
14590                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14591                 return -1;
14592         }
14593         p++;
14594         p0 = strchr(p, ')');
14595         if (p0 == NULL) {
14596                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14597                 return -1;
14598         }
14599         size = p0 - p;
14600         if (size >= sizeof(s)) {
14601                 printf("The string size exceeds the internal buffer size\n");
14602                 return -1;
14603         }
14604         snprintf(s, sizeof(s), "%.*s", size, p);
14605         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14606         if (ret <= 0) {
14607                 printf("Failed to get the bandwidth list. ");
14608                 return -1;
14609         }
14610         *tc_num = ret;
14611         for (i = 0; i < ret; i++)
14612                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14613
14614         return 0;
14615 }
14616
14617 /* TC min bandwidth setting */
14618 static void
14619 cmd_vf_tc_min_bw_parsed(
14620         void *parsed_result,
14621         __attribute__((unused)) struct cmdline *cl,
14622         __attribute__((unused)) void *data)
14623 {
14624         struct cmd_vf_tc_bw_result *res = parsed_result;
14625         uint8_t tc_num;
14626         uint8_t bw[16];
14627         int ret = -ENOTSUP;
14628
14629         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14630                 return;
14631
14632         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14633         if (ret)
14634                 return;
14635
14636 #ifdef RTE_LIBRTE_I40E_PMD
14637         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14638                                               tc_num, bw);
14639 #endif
14640
14641         switch (ret) {
14642         case 0:
14643                 break;
14644         case -EINVAL:
14645                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14646                 break;
14647         case -ENODEV:
14648                 printf("invalid port_id %d\n", res->port_id);
14649                 break;
14650         case -ENOTSUP:
14651                 printf("function not implemented\n");
14652                 break;
14653         default:
14654                 printf("programming error: (%s)\n", strerror(-ret));
14655         }
14656 }
14657
14658 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14659         .f = cmd_vf_tc_min_bw_parsed,
14660         .data = NULL,
14661         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14662                     " <bw1, bw2, ...>",
14663         .tokens = {
14664                 (void *)&cmd_vf_tc_bw_set,
14665                 (void *)&cmd_vf_tc_bw_vf,
14666                 (void *)&cmd_vf_tc_bw_tc,
14667                 (void *)&cmd_vf_tc_bw_tx,
14668                 (void *)&cmd_vf_tc_bw_min_bw,
14669                 (void *)&cmd_vf_tc_bw_port_id,
14670                 (void *)&cmd_vf_tc_bw_vf_id,
14671                 (void *)&cmd_vf_tc_bw_bw_list,
14672                 NULL,
14673         },
14674 };
14675
14676 static void
14677 cmd_tc_min_bw_parsed(
14678         void *parsed_result,
14679         __attribute__((unused)) struct cmdline *cl,
14680         __attribute__((unused)) void *data)
14681 {
14682         struct cmd_vf_tc_bw_result *res = parsed_result;
14683         struct rte_port *port;
14684         uint8_t tc_num;
14685         uint8_t bw[16];
14686         int ret = -ENOTSUP;
14687
14688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14689                 return;
14690
14691         port = &ports[res->port_id];
14692         /** Check if the port is not started **/
14693         if (port->port_status != RTE_PORT_STOPPED) {
14694                 printf("Please stop port %d first\n", res->port_id);
14695                 return;
14696         }
14697
14698         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14699         if (ret)
14700                 return;
14701
14702 #ifdef RTE_LIBRTE_IXGBE_PMD
14703         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14704 #endif
14705
14706         switch (ret) {
14707         case 0:
14708                 break;
14709         case -EINVAL:
14710                 printf("invalid bandwidth\n");
14711                 break;
14712         case -ENODEV:
14713                 printf("invalid port_id %d\n", res->port_id);
14714                 break;
14715         case -ENOTSUP:
14716                 printf("function not implemented\n");
14717                 break;
14718         default:
14719                 printf("programming error: (%s)\n", strerror(-ret));
14720         }
14721 }
14722
14723 cmdline_parse_inst_t cmd_tc_min_bw = {
14724         .f = cmd_tc_min_bw_parsed,
14725         .data = NULL,
14726         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14727         .tokens = {
14728                 (void *)&cmd_vf_tc_bw_set,
14729                 (void *)&cmd_vf_tc_bw_tc,
14730                 (void *)&cmd_vf_tc_bw_tx,
14731                 (void *)&cmd_vf_tc_bw_min_bw,
14732                 (void *)&cmd_vf_tc_bw_port_id,
14733                 (void *)&cmd_vf_tc_bw_bw_list,
14734                 NULL,
14735         },
14736 };
14737
14738 /* TC max bandwidth setting */
14739 static void
14740 cmd_vf_tc_max_bw_parsed(
14741         void *parsed_result,
14742         __attribute__((unused)) struct cmdline *cl,
14743         __attribute__((unused)) void *data)
14744 {
14745         struct cmd_vf_tc_bw_result *res = parsed_result;
14746         int ret = -ENOTSUP;
14747
14748         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14749                 return;
14750
14751 #ifdef RTE_LIBRTE_I40E_PMD
14752         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14753                                             res->tc_no, res->bw);
14754 #endif
14755
14756         switch (ret) {
14757         case 0:
14758                 break;
14759         case -EINVAL:
14760                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14761                        res->vf_id, res->tc_no, res->bw);
14762                 break;
14763         case -ENODEV:
14764                 printf("invalid port_id %d\n", res->port_id);
14765                 break;
14766         case -ENOTSUP:
14767                 printf("function not implemented\n");
14768                 break;
14769         default:
14770                 printf("programming error: (%s)\n", strerror(-ret));
14771         }
14772 }
14773
14774 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14775         .f = cmd_vf_tc_max_bw_parsed,
14776         .data = NULL,
14777         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14778                     " <bandwidth>",
14779         .tokens = {
14780                 (void *)&cmd_vf_tc_bw_set,
14781                 (void *)&cmd_vf_tc_bw_vf,
14782                 (void *)&cmd_vf_tc_bw_tc,
14783                 (void *)&cmd_vf_tc_bw_tx,
14784                 (void *)&cmd_vf_tc_bw_max_bw,
14785                 (void *)&cmd_vf_tc_bw_port_id,
14786                 (void *)&cmd_vf_tc_bw_vf_id,
14787                 (void *)&cmd_vf_tc_bw_tc_no,
14788                 (void *)&cmd_vf_tc_bw_bw,
14789                 NULL,
14790         },
14791 };
14792
14793
14794 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14795
14796 /* *** Set Port default Traffic Management Hierarchy *** */
14797 struct cmd_set_port_tm_hierarchy_default_result {
14798         cmdline_fixed_string_t set;
14799         cmdline_fixed_string_t port;
14800         cmdline_fixed_string_t tm;
14801         cmdline_fixed_string_t hierarchy;
14802         cmdline_fixed_string_t def;
14803         portid_t port_id;
14804 };
14805
14806 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14807         TOKEN_STRING_INITIALIZER(
14808                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14809 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14810         TOKEN_STRING_INITIALIZER(
14811                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14812 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14813         TOKEN_STRING_INITIALIZER(
14814                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14815 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14816         TOKEN_STRING_INITIALIZER(
14817                 struct cmd_set_port_tm_hierarchy_default_result,
14818                         hierarchy, "hierarchy");
14819 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14820         TOKEN_STRING_INITIALIZER(
14821                 struct cmd_set_port_tm_hierarchy_default_result,
14822                         def, "default");
14823 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14824         TOKEN_NUM_INITIALIZER(
14825                 struct cmd_set_port_tm_hierarchy_default_result,
14826                         port_id, UINT16);
14827
14828 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14829         __attribute__((unused)) struct cmdline *cl,
14830         __attribute__((unused)) void *data)
14831 {
14832         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14833         struct rte_port *p;
14834         portid_t port_id = res->port_id;
14835
14836         if (port_id_is_invalid(port_id, ENABLED_WARN))
14837                 return;
14838
14839         p = &ports[port_id];
14840
14841         /* Forward mode: tm */
14842         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
14843                 printf("  softnicfwd mode not enabled(error)\n");
14844                 return;
14845         }
14846
14847         /* Set the default tm hierarchy */
14848         p->softport.default_tm_hierarchy_enable = 1;
14849 }
14850
14851 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14852         .f = cmd_set_port_tm_hierarchy_default_parsed,
14853         .data = NULL,
14854         .help_str = "set port tm hierarchy default <port_id>",
14855         .tokens = {
14856                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14857                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14858                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14859                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14860                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14861                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14862                 NULL,
14863         },
14864 };
14865 #endif
14866
14867 /** Set VXLAN encapsulation details */
14868 struct cmd_set_vxlan_result {
14869         cmdline_fixed_string_t set;
14870         cmdline_fixed_string_t vxlan;
14871         cmdline_fixed_string_t pos_token;
14872         cmdline_fixed_string_t ip_version;
14873         uint32_t vlan_present:1;
14874         uint32_t vni;
14875         uint16_t udp_src;
14876         uint16_t udp_dst;
14877         cmdline_ipaddr_t ip_src;
14878         cmdline_ipaddr_t ip_dst;
14879         uint16_t tci;
14880         struct ether_addr eth_src;
14881         struct ether_addr eth_dst;
14882 };
14883
14884 cmdline_parse_token_string_t cmd_set_vxlan_set =
14885         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
14886 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
14887         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
14888 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
14889         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14890                                  "vxlan-with-vlan");
14891 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
14892         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14893                                  "ip-version");
14894 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
14895         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
14896                                  "ipv4#ipv6");
14897 cmdline_parse_token_string_t cmd_set_vxlan_vni =
14898         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14899                                  "vni");
14900 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
14901         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
14902 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
14903         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14904                                  "udp-src");
14905 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
14906         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
14907 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
14908         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14909                                  "udp-dst");
14910 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
14911         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
14912 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
14913         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14914                                  "ip-src");
14915 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
14916         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
14917 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
14918         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14919                                  "ip-dst");
14920 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
14921         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
14922 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
14923         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14924                                  "vlan-tci");
14925 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
14926         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
14927 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
14928         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14929                                  "eth-src");
14930 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
14931         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
14932 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
14933         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14934                                  "eth-dst");
14935 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
14936         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
14937
14938 static void cmd_set_vxlan_parsed(void *parsed_result,
14939         __attribute__((unused)) struct cmdline *cl,
14940         __attribute__((unused)) void *data)
14941 {
14942         struct cmd_set_vxlan_result *res = parsed_result;
14943         union {
14944                 uint32_t vxlan_id;
14945                 uint8_t vni[4];
14946         } id = {
14947                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
14948         };
14949
14950         if (strcmp(res->vxlan, "vxlan") == 0)
14951                 vxlan_encap_conf.select_vlan = 0;
14952         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
14953                 vxlan_encap_conf.select_vlan = 1;
14954         if (strcmp(res->ip_version, "ipv4") == 0)
14955                 vxlan_encap_conf.select_ipv4 = 1;
14956         else if (strcmp(res->ip_version, "ipv6") == 0)
14957                 vxlan_encap_conf.select_ipv4 = 0;
14958         else
14959                 return;
14960         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
14961         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14962         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14963         if (vxlan_encap_conf.select_ipv4) {
14964                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
14965                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
14966         } else {
14967                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
14968                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
14969         }
14970         if (vxlan_encap_conf.select_vlan)
14971                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14972         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
14973                    ETHER_ADDR_LEN);
14974         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14975                    ETHER_ADDR_LEN);
14976 }
14977
14978 cmdline_parse_inst_t cmd_set_vxlan = {
14979         .f = cmd_set_vxlan_parsed,
14980         .data = NULL,
14981         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
14982                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
14983                 " eth-src <eth-src> eth-dst <eth-dst>",
14984         .tokens = {
14985                 (void *)&cmd_set_vxlan_set,
14986                 (void *)&cmd_set_vxlan_vxlan,
14987                 (void *)&cmd_set_vxlan_ip_version,
14988                 (void *)&cmd_set_vxlan_ip_version_value,
14989                 (void *)&cmd_set_vxlan_vni,
14990                 (void *)&cmd_set_vxlan_vni_value,
14991                 (void *)&cmd_set_vxlan_udp_src,
14992                 (void *)&cmd_set_vxlan_udp_src_value,
14993                 (void *)&cmd_set_vxlan_udp_dst,
14994                 (void *)&cmd_set_vxlan_udp_dst_value,
14995                 (void *)&cmd_set_vxlan_ip_src,
14996                 (void *)&cmd_set_vxlan_ip_src_value,
14997                 (void *)&cmd_set_vxlan_ip_dst,
14998                 (void *)&cmd_set_vxlan_ip_dst_value,
14999                 (void *)&cmd_set_vxlan_eth_src,
15000                 (void *)&cmd_set_vxlan_eth_src_value,
15001                 (void *)&cmd_set_vxlan_eth_dst,
15002                 (void *)&cmd_set_vxlan_eth_dst_value,
15003                 NULL,
15004         },
15005 };
15006
15007 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15008         .f = cmd_set_vxlan_parsed,
15009         .data = NULL,
15010         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15011                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15012                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15013                 " <eth-dst>",
15014         .tokens = {
15015                 (void *)&cmd_set_vxlan_set,
15016                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15017                 (void *)&cmd_set_vxlan_ip_version,
15018                 (void *)&cmd_set_vxlan_ip_version_value,
15019                 (void *)&cmd_set_vxlan_vni,
15020                 (void *)&cmd_set_vxlan_vni_value,
15021                 (void *)&cmd_set_vxlan_udp_src,
15022                 (void *)&cmd_set_vxlan_udp_src_value,
15023                 (void *)&cmd_set_vxlan_udp_dst,
15024                 (void *)&cmd_set_vxlan_udp_dst_value,
15025                 (void *)&cmd_set_vxlan_ip_src,
15026                 (void *)&cmd_set_vxlan_ip_src_value,
15027                 (void *)&cmd_set_vxlan_ip_dst,
15028                 (void *)&cmd_set_vxlan_ip_dst_value,
15029                 (void *)&cmd_set_vxlan_vlan,
15030                 (void *)&cmd_set_vxlan_vlan_value,
15031                 (void *)&cmd_set_vxlan_eth_src,
15032                 (void *)&cmd_set_vxlan_eth_src_value,
15033                 (void *)&cmd_set_vxlan_eth_dst,
15034                 (void *)&cmd_set_vxlan_eth_dst_value,
15035                 NULL,
15036         },
15037 };
15038
15039 /** Set NVGRE encapsulation details */
15040 struct cmd_set_nvgre_result {
15041         cmdline_fixed_string_t set;
15042         cmdline_fixed_string_t nvgre;
15043         cmdline_fixed_string_t pos_token;
15044         cmdline_fixed_string_t ip_version;
15045         uint32_t tni;
15046         cmdline_ipaddr_t ip_src;
15047         cmdline_ipaddr_t ip_dst;
15048         uint16_t tci;
15049         struct ether_addr eth_src;
15050         struct ether_addr eth_dst;
15051 };
15052
15053 cmdline_parse_token_string_t cmd_set_nvgre_set =
15054         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15055 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15056         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15057 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15058         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15059                                  "nvgre-with-vlan");
15060 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15061         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15062                                  "ip-version");
15063 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15064         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15065                                  "ipv4#ipv6");
15066 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15067         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15068                                  "tni");
15069 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15070         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15071 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15072         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15073                                  "ip-src");
15074 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15075         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15076 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15077         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15078                                  "ip-dst");
15079 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15080         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15081 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15082         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15083                                  "vlan-tci");
15084 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15085         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15086 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15087         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15088                                  "eth-src");
15089 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15090         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15091 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15092         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15093                                  "eth-dst");
15094 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15095         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15096
15097 static void cmd_set_nvgre_parsed(void *parsed_result,
15098         __attribute__((unused)) struct cmdline *cl,
15099         __attribute__((unused)) void *data)
15100 {
15101         struct cmd_set_nvgre_result *res = parsed_result;
15102         union {
15103                 uint32_t nvgre_tni;
15104                 uint8_t tni[4];
15105         } id = {
15106                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15107         };
15108
15109         if (strcmp(res->nvgre, "nvgre") == 0)
15110                 nvgre_encap_conf.select_vlan = 0;
15111         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15112                 nvgre_encap_conf.select_vlan = 1;
15113         if (strcmp(res->ip_version, "ipv4") == 0)
15114                 nvgre_encap_conf.select_ipv4 = 1;
15115         else if (strcmp(res->ip_version, "ipv6") == 0)
15116                 nvgre_encap_conf.select_ipv4 = 0;
15117         else
15118                 return;
15119         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15120         if (nvgre_encap_conf.select_ipv4) {
15121                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15122                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15123         } else {
15124                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15125                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15126         }
15127         if (nvgre_encap_conf.select_vlan)
15128                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15129         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15130                    ETHER_ADDR_LEN);
15131         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15132                    ETHER_ADDR_LEN);
15133 }
15134
15135 cmdline_parse_inst_t cmd_set_nvgre = {
15136         .f = cmd_set_nvgre_parsed,
15137         .data = NULL,
15138         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15139                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15140                 " eth-dst <eth-dst>",
15141         .tokens = {
15142                 (void *)&cmd_set_nvgre_set,
15143                 (void *)&cmd_set_nvgre_nvgre,
15144                 (void *)&cmd_set_nvgre_ip_version,
15145                 (void *)&cmd_set_nvgre_ip_version_value,
15146                 (void *)&cmd_set_nvgre_tni,
15147                 (void *)&cmd_set_nvgre_tni_value,
15148                 (void *)&cmd_set_nvgre_ip_src,
15149                 (void *)&cmd_set_nvgre_ip_src_value,
15150                 (void *)&cmd_set_nvgre_ip_dst,
15151                 (void *)&cmd_set_nvgre_ip_dst_value,
15152                 (void *)&cmd_set_nvgre_eth_src,
15153                 (void *)&cmd_set_nvgre_eth_src_value,
15154                 (void *)&cmd_set_nvgre_eth_dst,
15155                 (void *)&cmd_set_nvgre_eth_dst_value,
15156                 NULL,
15157         },
15158 };
15159
15160 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15161         .f = cmd_set_nvgre_parsed,
15162         .data = NULL,
15163         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15164                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15165                 " eth-src <eth-src> eth-dst <eth-dst>",
15166         .tokens = {
15167                 (void *)&cmd_set_nvgre_set,
15168                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15169                 (void *)&cmd_set_nvgre_ip_version,
15170                 (void *)&cmd_set_nvgre_ip_version_value,
15171                 (void *)&cmd_set_nvgre_tni,
15172                 (void *)&cmd_set_nvgre_tni_value,
15173                 (void *)&cmd_set_nvgre_ip_src,
15174                 (void *)&cmd_set_nvgre_ip_src_value,
15175                 (void *)&cmd_set_nvgre_ip_dst,
15176                 (void *)&cmd_set_nvgre_ip_dst_value,
15177                 (void *)&cmd_set_nvgre_vlan,
15178                 (void *)&cmd_set_nvgre_vlan_value,
15179                 (void *)&cmd_set_nvgre_eth_src,
15180                 (void *)&cmd_set_nvgre_eth_src_value,
15181                 (void *)&cmd_set_nvgre_eth_dst,
15182                 (void *)&cmd_set_nvgre_eth_dst_value,
15183                 NULL,
15184         },
15185 };
15186
15187 /* Strict link priority scheduling mode setting */
15188 static void
15189 cmd_strict_link_prio_parsed(
15190         void *parsed_result,
15191         __attribute__((unused)) struct cmdline *cl,
15192         __attribute__((unused)) void *data)
15193 {
15194         struct cmd_vf_tc_bw_result *res = parsed_result;
15195         int ret = -ENOTSUP;
15196
15197         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15198                 return;
15199
15200 #ifdef RTE_LIBRTE_I40E_PMD
15201         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15202 #endif
15203
15204         switch (ret) {
15205         case 0:
15206                 break;
15207         case -EINVAL:
15208                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15209                 break;
15210         case -ENODEV:
15211                 printf("invalid port_id %d\n", res->port_id);
15212                 break;
15213         case -ENOTSUP:
15214                 printf("function not implemented\n");
15215                 break;
15216         default:
15217                 printf("programming error: (%s)\n", strerror(-ret));
15218         }
15219 }
15220
15221 cmdline_parse_inst_t cmd_strict_link_prio = {
15222         .f = cmd_strict_link_prio_parsed,
15223         .data = NULL,
15224         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
15225         .tokens = {
15226                 (void *)&cmd_vf_tc_bw_set,
15227                 (void *)&cmd_vf_tc_bw_tx,
15228                 (void *)&cmd_vf_tc_bw_strict_link_prio,
15229                 (void *)&cmd_vf_tc_bw_port_id,
15230                 (void *)&cmd_vf_tc_bw_tc_map,
15231                 NULL,
15232         },
15233 };
15234
15235 /* Load dynamic device personalization*/
15236 struct cmd_ddp_add_result {
15237         cmdline_fixed_string_t ddp;
15238         cmdline_fixed_string_t add;
15239         portid_t port_id;
15240         char filepath[];
15241 };
15242
15243 cmdline_parse_token_string_t cmd_ddp_add_ddp =
15244         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
15245 cmdline_parse_token_string_t cmd_ddp_add_add =
15246         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
15247 cmdline_parse_token_num_t cmd_ddp_add_port_id =
15248         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
15249 cmdline_parse_token_string_t cmd_ddp_add_filepath =
15250         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
15251
15252 static void
15253 cmd_ddp_add_parsed(
15254         void *parsed_result,
15255         __attribute__((unused)) struct cmdline *cl,
15256         __attribute__((unused)) void *data)
15257 {
15258         struct cmd_ddp_add_result *res = parsed_result;
15259         uint8_t *buff;
15260         uint32_t size;
15261         char *filepath;
15262         char *file_fld[2];
15263         int file_num;
15264         int ret = -ENOTSUP;
15265
15266         if (!all_ports_stopped()) {
15267                 printf("Please stop all ports first\n");
15268                 return;
15269         }
15270
15271         filepath = strdup(res->filepath);
15272         if (filepath == NULL) {
15273                 printf("Failed to allocate memory\n");
15274                 return;
15275         }
15276         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
15277
15278         buff = open_file(file_fld[0], &size);
15279         if (!buff) {
15280                 free((void *)filepath);
15281                 return;
15282         }
15283
15284 #ifdef RTE_LIBRTE_I40E_PMD
15285         if (ret == -ENOTSUP)
15286                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15287                                                buff, size,
15288                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
15289 #endif
15290
15291         if (ret == -EEXIST)
15292                 printf("Profile has already existed.\n");
15293         else if (ret < 0)
15294                 printf("Failed to load profile.\n");
15295         else if (file_num == 2)
15296                 save_file(file_fld[1], buff, size);
15297
15298         close_file(buff);
15299         free((void *)filepath);
15300 }
15301
15302 cmdline_parse_inst_t cmd_ddp_add = {
15303         .f = cmd_ddp_add_parsed,
15304         .data = NULL,
15305         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
15306         .tokens = {
15307                 (void *)&cmd_ddp_add_ddp,
15308                 (void *)&cmd_ddp_add_add,
15309                 (void *)&cmd_ddp_add_port_id,
15310                 (void *)&cmd_ddp_add_filepath,
15311                 NULL,
15312         },
15313 };
15314
15315 /* Delete dynamic device personalization*/
15316 struct cmd_ddp_del_result {
15317         cmdline_fixed_string_t ddp;
15318         cmdline_fixed_string_t del;
15319         portid_t port_id;
15320         char filepath[];
15321 };
15322
15323 cmdline_parse_token_string_t cmd_ddp_del_ddp =
15324         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
15325 cmdline_parse_token_string_t cmd_ddp_del_del =
15326         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
15327 cmdline_parse_token_num_t cmd_ddp_del_port_id =
15328         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
15329 cmdline_parse_token_string_t cmd_ddp_del_filepath =
15330         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
15331
15332 static void
15333 cmd_ddp_del_parsed(
15334         void *parsed_result,
15335         __attribute__((unused)) struct cmdline *cl,
15336         __attribute__((unused)) void *data)
15337 {
15338         struct cmd_ddp_del_result *res = parsed_result;
15339         uint8_t *buff;
15340         uint32_t size;
15341         int ret = -ENOTSUP;
15342
15343         if (!all_ports_stopped()) {
15344                 printf("Please stop all ports first\n");
15345                 return;
15346         }
15347
15348         buff = open_file(res->filepath, &size);
15349         if (!buff)
15350                 return;
15351
15352 #ifdef RTE_LIBRTE_I40E_PMD
15353         if (ret == -ENOTSUP)
15354                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15355                                                buff, size,
15356                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15357 #endif
15358
15359         if (ret == -EACCES)
15360                 printf("Profile does not exist.\n");
15361         else if (ret < 0)
15362                 printf("Failed to delete profile.\n");
15363
15364         close_file(buff);
15365 }
15366
15367 cmdline_parse_inst_t cmd_ddp_del = {
15368         .f = cmd_ddp_del_parsed,
15369         .data = NULL,
15370         .help_str = "ddp del <port_id> <backup_profile_path>",
15371         .tokens = {
15372                 (void *)&cmd_ddp_del_ddp,
15373                 (void *)&cmd_ddp_del_del,
15374                 (void *)&cmd_ddp_del_port_id,
15375                 (void *)&cmd_ddp_del_filepath,
15376                 NULL,
15377         },
15378 };
15379
15380 /* Get dynamic device personalization profile info */
15381 struct cmd_ddp_info_result {
15382         cmdline_fixed_string_t ddp;
15383         cmdline_fixed_string_t get;
15384         cmdline_fixed_string_t info;
15385         char filepath[];
15386 };
15387
15388 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15389         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15390 cmdline_parse_token_string_t cmd_ddp_info_get =
15391         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15392 cmdline_parse_token_string_t cmd_ddp_info_info =
15393         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15394 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15395         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15396
15397 static void
15398 cmd_ddp_info_parsed(
15399         void *parsed_result,
15400         __attribute__((unused)) struct cmdline *cl,
15401         __attribute__((unused)) void *data)
15402 {
15403         struct cmd_ddp_info_result *res = parsed_result;
15404         uint8_t *pkg;
15405         uint32_t pkg_size;
15406         int ret = -ENOTSUP;
15407 #ifdef RTE_LIBRTE_I40E_PMD
15408         uint32_t i, j, n;
15409         uint8_t *buff;
15410         uint32_t buff_size = 0;
15411         struct rte_pmd_i40e_profile_info info;
15412         uint32_t dev_num = 0;
15413         struct rte_pmd_i40e_ddp_device_id *devs;
15414         uint32_t proto_num = 0;
15415         struct rte_pmd_i40e_proto_info *proto = NULL;
15416         uint32_t pctype_num = 0;
15417         struct rte_pmd_i40e_ptype_info *pctype;
15418         uint32_t ptype_num = 0;
15419         struct rte_pmd_i40e_ptype_info *ptype;
15420         uint8_t proto_id;
15421
15422 #endif
15423
15424         pkg = open_file(res->filepath, &pkg_size);
15425         if (!pkg)
15426                 return;
15427
15428 #ifdef RTE_LIBRTE_I40E_PMD
15429         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15430                                 (uint8_t *)&info, sizeof(info),
15431                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15432         if (!ret) {
15433                 printf("Global Track id:       0x%x\n", info.track_id);
15434                 printf("Global Version:        %d.%d.%d.%d\n",
15435                         info.version.major,
15436                         info.version.minor,
15437                         info.version.update,
15438                         info.version.draft);
15439                 printf("Global Package name:   %s\n\n", info.name);
15440         }
15441
15442         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15443                                 (uint8_t *)&info, sizeof(info),
15444                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15445         if (!ret) {
15446                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15447                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15448                         info.version.major,
15449                         info.version.minor,
15450                         info.version.update,
15451                         info.version.draft);
15452                 printf("i40e Profile name:     %s\n\n", info.name);
15453         }
15454
15455         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15456                                 (uint8_t *)&buff_size, sizeof(buff_size),
15457                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15458         if (!ret && buff_size) {
15459                 buff = (uint8_t *)malloc(buff_size);
15460                 if (buff) {
15461                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15462                                                 buff, buff_size,
15463                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15464                         if (!ret)
15465                                 printf("Package Notes:\n%s\n\n", buff);
15466                         free(buff);
15467                 }
15468         }
15469
15470         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15471                                 (uint8_t *)&dev_num, sizeof(dev_num),
15472                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15473         if (!ret && dev_num) {
15474                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15475                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15476                 if (devs) {
15477                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15478                                                 (uint8_t *)devs, buff_size,
15479                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15480                         if (!ret) {
15481                                 printf("List of supported devices:\n");
15482                                 for (i = 0; i < dev_num; i++) {
15483                                         printf("  %04X:%04X %04X:%04X\n",
15484                                                 devs[i].vendor_dev_id >> 16,
15485                                                 devs[i].vendor_dev_id & 0xFFFF,
15486                                                 devs[i].sub_vendor_dev_id >> 16,
15487                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15488                                 }
15489                                 printf("\n");
15490                         }
15491                         free(devs);
15492                 }
15493         }
15494
15495         /* get information about protocols and packet types */
15496         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15497                 (uint8_t *)&proto_num, sizeof(proto_num),
15498                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15499         if (ret || !proto_num)
15500                 goto no_print_return;
15501
15502         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15503         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15504         if (!proto)
15505                 goto no_print_return;
15506
15507         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15508                                         buff_size,
15509                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15510         if (!ret) {
15511                 printf("List of used protocols:\n");
15512                 for (i = 0; i < proto_num; i++)
15513                         printf("  %2u: %s\n", proto[i].proto_id,
15514                                proto[i].name);
15515                 printf("\n");
15516         }
15517         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15518                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15519                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15520         if (ret || !pctype_num)
15521                 goto no_print_pctypes;
15522
15523         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15524         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15525         if (!pctype)
15526                 goto no_print_pctypes;
15527
15528         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15529                                         buff_size,
15530                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15531         if (ret) {
15532                 free(pctype);
15533                 goto no_print_pctypes;
15534         }
15535
15536         printf("List of defined packet classification types:\n");
15537         for (i = 0; i < pctype_num; i++) {
15538                 printf("  %2u:", pctype[i].ptype_id);
15539                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15540                         proto_id = pctype[i].protocols[j];
15541                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15542                                 for (n = 0; n < proto_num; n++) {
15543                                         if (proto[n].proto_id == proto_id) {
15544                                                 printf(" %s", proto[n].name);
15545                                                 break;
15546                                         }
15547                                 }
15548                         }
15549                 }
15550                 printf("\n");
15551         }
15552         printf("\n");
15553         free(pctype);
15554
15555 no_print_pctypes:
15556
15557         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15558                                         sizeof(ptype_num),
15559                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15560         if (ret || !ptype_num)
15561                 goto no_print_return;
15562
15563         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15564         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15565         if (!ptype)
15566                 goto no_print_return;
15567
15568         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15569                                         buff_size,
15570                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15571         if (ret) {
15572                 free(ptype);
15573                 goto no_print_return;
15574         }
15575         printf("List of defined packet types:\n");
15576         for (i = 0; i < ptype_num; i++) {
15577                 printf("  %2u:", ptype[i].ptype_id);
15578                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15579                         proto_id = ptype[i].protocols[j];
15580                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15581                                 for (n = 0; n < proto_num; n++) {
15582                                         if (proto[n].proto_id == proto_id) {
15583                                                 printf(" %s", proto[n].name);
15584                                                 break;
15585                                         }
15586                                 }
15587                         }
15588                 }
15589                 printf("\n");
15590         }
15591         free(ptype);
15592         printf("\n");
15593
15594         ret = 0;
15595 no_print_return:
15596         if (proto)
15597                 free(proto);
15598 #endif
15599         if (ret == -ENOTSUP)
15600                 printf("Function not supported in PMD driver\n");
15601         close_file(pkg);
15602 }
15603
15604 cmdline_parse_inst_t cmd_ddp_get_info = {
15605         .f = cmd_ddp_info_parsed,
15606         .data = NULL,
15607         .help_str = "ddp get info <profile_path>",
15608         .tokens = {
15609                 (void *)&cmd_ddp_info_ddp,
15610                 (void *)&cmd_ddp_info_get,
15611                 (void *)&cmd_ddp_info_info,
15612                 (void *)&cmd_ddp_info_filepath,
15613                 NULL,
15614         },
15615 };
15616
15617 /* Get dynamic device personalization profile info list*/
15618 #define PROFILE_INFO_SIZE 48
15619 #define MAX_PROFILE_NUM 16
15620
15621 struct cmd_ddp_get_list_result {
15622         cmdline_fixed_string_t ddp;
15623         cmdline_fixed_string_t get;
15624         cmdline_fixed_string_t list;
15625         portid_t port_id;
15626 };
15627
15628 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15629         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15630 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15631         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15632 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15633         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15634 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15635         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15636
15637 static void
15638 cmd_ddp_get_list_parsed(
15639         __attribute__((unused)) void *parsed_result,
15640         __attribute__((unused)) struct cmdline *cl,
15641         __attribute__((unused)) void *data)
15642 {
15643 #ifdef RTE_LIBRTE_I40E_PMD
15644         struct cmd_ddp_get_list_result *res = parsed_result;
15645         struct rte_pmd_i40e_profile_list *p_list;
15646         struct rte_pmd_i40e_profile_info *p_info;
15647         uint32_t p_num;
15648         uint32_t size;
15649         uint32_t i;
15650 #endif
15651         int ret = -ENOTSUP;
15652
15653 #ifdef RTE_LIBRTE_I40E_PMD
15654         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15655         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15656         if (!p_list)
15657                 printf("%s: Failed to malloc buffer\n", __func__);
15658
15659         if (ret == -ENOTSUP)
15660                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15661                                                 (uint8_t *)p_list, size);
15662
15663         if (!ret) {
15664                 p_num = p_list->p_count;
15665                 printf("Profile number is: %d\n\n", p_num);
15666
15667                 for (i = 0; i < p_num; i++) {
15668                         p_info = &p_list->p_info[i];
15669                         printf("Profile %d:\n", i);
15670                         printf("Track id:     0x%x\n", p_info->track_id);
15671                         printf("Version:      %d.%d.%d.%d\n",
15672                                p_info->version.major,
15673                                p_info->version.minor,
15674                                p_info->version.update,
15675                                p_info->version.draft);
15676                         printf("Profile name: %s\n\n", p_info->name);
15677                 }
15678         }
15679
15680         free(p_list);
15681 #endif
15682
15683         if (ret < 0)
15684                 printf("Failed to get ddp list\n");
15685 }
15686
15687 cmdline_parse_inst_t cmd_ddp_get_list = {
15688         .f = cmd_ddp_get_list_parsed,
15689         .data = NULL,
15690         .help_str = "ddp get list <port_id>",
15691         .tokens = {
15692                 (void *)&cmd_ddp_get_list_ddp,
15693                 (void *)&cmd_ddp_get_list_get,
15694                 (void *)&cmd_ddp_get_list_list,
15695                 (void *)&cmd_ddp_get_list_port_id,
15696                 NULL,
15697         },
15698 };
15699
15700 /* Configure input set */
15701 struct cmd_cfg_input_set_result {
15702         cmdline_fixed_string_t port;
15703         cmdline_fixed_string_t cfg;
15704         portid_t port_id;
15705         cmdline_fixed_string_t pctype;
15706         uint8_t pctype_id;
15707         cmdline_fixed_string_t inset_type;
15708         cmdline_fixed_string_t opt;
15709         cmdline_fixed_string_t field;
15710         uint8_t field_idx;
15711 };
15712
15713 static void
15714 cmd_cfg_input_set_parsed(
15715         __attribute__((unused)) void *parsed_result,
15716         __attribute__((unused)) struct cmdline *cl,
15717         __attribute__((unused)) void *data)
15718 {
15719 #ifdef RTE_LIBRTE_I40E_PMD
15720         struct cmd_cfg_input_set_result *res = parsed_result;
15721         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15722         struct rte_pmd_i40e_inset inset;
15723 #endif
15724         int ret = -ENOTSUP;
15725
15726         if (!all_ports_stopped()) {
15727                 printf("Please stop all ports first\n");
15728                 return;
15729         }
15730
15731 #ifdef RTE_LIBRTE_I40E_PMD
15732         if (!strcmp(res->inset_type, "hash_inset"))
15733                 inset_type = INSET_HASH;
15734         else if (!strcmp(res->inset_type, "fdir_inset"))
15735                 inset_type = INSET_FDIR;
15736         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15737                 inset_type = INSET_FDIR_FLX;
15738         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15739                                      &inset, inset_type);
15740         if (ret) {
15741                 printf("Failed to get input set.\n");
15742                 return;
15743         }
15744
15745         if (!strcmp(res->opt, "get")) {
15746                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15747                                                    res->field_idx);
15748                 if (ret)
15749                         printf("Field index %d is enabled.\n", res->field_idx);
15750                 else
15751                         printf("Field index %d is disabled.\n", res->field_idx);
15752                 return;
15753         } else if (!strcmp(res->opt, "set"))
15754                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15755                                                    res->field_idx);
15756         else if (!strcmp(res->opt, "clear"))
15757                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15758                                                      res->field_idx);
15759         if (ret) {
15760                 printf("Failed to configure input set field.\n");
15761                 return;
15762         }
15763
15764         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15765                                      &inset, inset_type);
15766         if (ret) {
15767                 printf("Failed to set input set.\n");
15768                 return;
15769         }
15770 #endif
15771
15772         if (ret == -ENOTSUP)
15773                 printf("Function not supported\n");
15774 }
15775
15776 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15777         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15778                                  port, "port");
15779 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15780         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15781                                  cfg, "config");
15782 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15783         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15784                               port_id, UINT16);
15785 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15786         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15787                                  pctype, "pctype");
15788 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15789         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15790                               pctype_id, UINT8);
15791 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15792         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15793                                  inset_type,
15794                                  "hash_inset#fdir_inset#fdir_flx_inset");
15795 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15796         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15797                                  opt, "get#set#clear");
15798 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15799         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15800                                  field, "field");
15801 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15802         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15803                               field_idx, UINT8);
15804
15805 cmdline_parse_inst_t cmd_cfg_input_set = {
15806         .f = cmd_cfg_input_set_parsed,
15807         .data = NULL,
15808         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15809                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15810         .tokens = {
15811                 (void *)&cmd_cfg_input_set_port,
15812                 (void *)&cmd_cfg_input_set_cfg,
15813                 (void *)&cmd_cfg_input_set_port_id,
15814                 (void *)&cmd_cfg_input_set_pctype,
15815                 (void *)&cmd_cfg_input_set_pctype_id,
15816                 (void *)&cmd_cfg_input_set_inset_type,
15817                 (void *)&cmd_cfg_input_set_opt,
15818                 (void *)&cmd_cfg_input_set_field,
15819                 (void *)&cmd_cfg_input_set_field_idx,
15820                 NULL,
15821         },
15822 };
15823
15824 /* Clear input set */
15825 struct cmd_clear_input_set_result {
15826         cmdline_fixed_string_t port;
15827         cmdline_fixed_string_t cfg;
15828         portid_t port_id;
15829         cmdline_fixed_string_t pctype;
15830         uint8_t pctype_id;
15831         cmdline_fixed_string_t inset_type;
15832         cmdline_fixed_string_t clear;
15833         cmdline_fixed_string_t all;
15834 };
15835
15836 static void
15837 cmd_clear_input_set_parsed(
15838         __attribute__((unused)) void *parsed_result,
15839         __attribute__((unused)) struct cmdline *cl,
15840         __attribute__((unused)) void *data)
15841 {
15842 #ifdef RTE_LIBRTE_I40E_PMD
15843         struct cmd_clear_input_set_result *res = parsed_result;
15844         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15845         struct rte_pmd_i40e_inset inset;
15846 #endif
15847         int ret = -ENOTSUP;
15848
15849         if (!all_ports_stopped()) {
15850                 printf("Please stop all ports first\n");
15851                 return;
15852         }
15853
15854 #ifdef RTE_LIBRTE_I40E_PMD
15855         if (!strcmp(res->inset_type, "hash_inset"))
15856                 inset_type = INSET_HASH;
15857         else if (!strcmp(res->inset_type, "fdir_inset"))
15858                 inset_type = INSET_FDIR;
15859         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15860                 inset_type = INSET_FDIR_FLX;
15861
15862         memset(&inset, 0, sizeof(inset));
15863
15864         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15865                                      &inset, inset_type);
15866         if (ret) {
15867                 printf("Failed to clear input set.\n");
15868                 return;
15869         }
15870
15871 #endif
15872
15873         if (ret == -ENOTSUP)
15874                 printf("Function not supported\n");
15875 }
15876
15877 cmdline_parse_token_string_t cmd_clear_input_set_port =
15878         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15879                                  port, "port");
15880 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15881         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15882                                  cfg, "config");
15883 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15884         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15885                               port_id, UINT16);
15886 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15887         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15888                                  pctype, "pctype");
15889 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15890         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15891                               pctype_id, UINT8);
15892 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15893         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15894                                  inset_type,
15895                                  "hash_inset#fdir_inset#fdir_flx_inset");
15896 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15897         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15898                                  clear, "clear");
15899 cmdline_parse_token_string_t cmd_clear_input_set_all =
15900         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15901                                  all, "all");
15902
15903 cmdline_parse_inst_t cmd_clear_input_set = {
15904         .f = cmd_clear_input_set_parsed,
15905         .data = NULL,
15906         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15907                     "fdir_inset|fdir_flx_inset clear all",
15908         .tokens = {
15909                 (void *)&cmd_clear_input_set_port,
15910                 (void *)&cmd_clear_input_set_cfg,
15911                 (void *)&cmd_clear_input_set_port_id,
15912                 (void *)&cmd_clear_input_set_pctype,
15913                 (void *)&cmd_clear_input_set_pctype_id,
15914                 (void *)&cmd_clear_input_set_inset_type,
15915                 (void *)&cmd_clear_input_set_clear,
15916                 (void *)&cmd_clear_input_set_all,
15917                 NULL,
15918         },
15919 };
15920
15921 /* show vf stats */
15922
15923 /* Common result structure for show vf stats */
15924 struct cmd_show_vf_stats_result {
15925         cmdline_fixed_string_t show;
15926         cmdline_fixed_string_t vf;
15927         cmdline_fixed_string_t stats;
15928         portid_t port_id;
15929         uint16_t vf_id;
15930 };
15931
15932 /* Common CLI fields show vf stats*/
15933 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15934         TOKEN_STRING_INITIALIZER
15935                 (struct cmd_show_vf_stats_result,
15936                  show, "show");
15937 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15938         TOKEN_STRING_INITIALIZER
15939                 (struct cmd_show_vf_stats_result,
15940                  vf, "vf");
15941 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15942         TOKEN_STRING_INITIALIZER
15943                 (struct cmd_show_vf_stats_result,
15944                  stats, "stats");
15945 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15946         TOKEN_NUM_INITIALIZER
15947                 (struct cmd_show_vf_stats_result,
15948                  port_id, UINT16);
15949 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15950         TOKEN_NUM_INITIALIZER
15951                 (struct cmd_show_vf_stats_result,
15952                  vf_id, UINT16);
15953
15954 static void
15955 cmd_show_vf_stats_parsed(
15956         void *parsed_result,
15957         __attribute__((unused)) struct cmdline *cl,
15958         __attribute__((unused)) void *data)
15959 {
15960         struct cmd_show_vf_stats_result *res = parsed_result;
15961         struct rte_eth_stats stats;
15962         int ret = -ENOTSUP;
15963         static const char *nic_stats_border = "########################";
15964
15965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15966                 return;
15967
15968         memset(&stats, 0, sizeof(stats));
15969
15970 #ifdef RTE_LIBRTE_I40E_PMD
15971         if (ret == -ENOTSUP)
15972                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15973                                                 res->vf_id,
15974                                                 &stats);
15975 #endif
15976 #ifdef RTE_LIBRTE_BNXT_PMD
15977         if (ret == -ENOTSUP)
15978                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15979                                                 res->vf_id,
15980                                                 &stats);
15981 #endif
15982
15983         switch (ret) {
15984         case 0:
15985                 break;
15986         case -EINVAL:
15987                 printf("invalid vf_id %d\n", res->vf_id);
15988                 break;
15989         case -ENODEV:
15990                 printf("invalid port_id %d\n", res->port_id);
15991                 break;
15992         case -ENOTSUP:
15993                 printf("function not implemented\n");
15994                 break;
15995         default:
15996                 printf("programming error: (%s)\n", strerror(-ret));
15997         }
15998
15999         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16000                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16001
16002         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16003                "%-"PRIu64"\n",
16004                stats.ipackets, stats.imissed, stats.ibytes);
16005         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16006         printf("  RX-nombuf:  %-10"PRIu64"\n",
16007                stats.rx_nombuf);
16008         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16009                "%-"PRIu64"\n",
16010                stats.opackets, stats.oerrors, stats.obytes);
16011
16012         printf("  %s############################%s\n",
16013                                nic_stats_border, nic_stats_border);
16014 }
16015
16016 cmdline_parse_inst_t cmd_show_vf_stats = {
16017         .f = cmd_show_vf_stats_parsed,
16018         .data = NULL,
16019         .help_str = "show vf stats <port_id> <vf_id>",
16020         .tokens = {
16021                 (void *)&cmd_show_vf_stats_show,
16022                 (void *)&cmd_show_vf_stats_vf,
16023                 (void *)&cmd_show_vf_stats_stats,
16024                 (void *)&cmd_show_vf_stats_port_id,
16025                 (void *)&cmd_show_vf_stats_vf_id,
16026                 NULL,
16027         },
16028 };
16029
16030 /* clear vf stats */
16031
16032 /* Common result structure for clear vf stats */
16033 struct cmd_clear_vf_stats_result {
16034         cmdline_fixed_string_t clear;
16035         cmdline_fixed_string_t vf;
16036         cmdline_fixed_string_t stats;
16037         portid_t port_id;
16038         uint16_t vf_id;
16039 };
16040
16041 /* Common CLI fields clear vf stats*/
16042 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16043         TOKEN_STRING_INITIALIZER
16044                 (struct cmd_clear_vf_stats_result,
16045                  clear, "clear");
16046 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16047         TOKEN_STRING_INITIALIZER
16048                 (struct cmd_clear_vf_stats_result,
16049                  vf, "vf");
16050 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16051         TOKEN_STRING_INITIALIZER
16052                 (struct cmd_clear_vf_stats_result,
16053                  stats, "stats");
16054 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16055         TOKEN_NUM_INITIALIZER
16056                 (struct cmd_clear_vf_stats_result,
16057                  port_id, UINT16);
16058 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16059         TOKEN_NUM_INITIALIZER
16060                 (struct cmd_clear_vf_stats_result,
16061                  vf_id, UINT16);
16062
16063 static void
16064 cmd_clear_vf_stats_parsed(
16065         void *parsed_result,
16066         __attribute__((unused)) struct cmdline *cl,
16067         __attribute__((unused)) void *data)
16068 {
16069         struct cmd_clear_vf_stats_result *res = parsed_result;
16070         int ret = -ENOTSUP;
16071
16072         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16073                 return;
16074
16075 #ifdef RTE_LIBRTE_I40E_PMD
16076         if (ret == -ENOTSUP)
16077                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16078                                                   res->vf_id);
16079 #endif
16080 #ifdef RTE_LIBRTE_BNXT_PMD
16081         if (ret == -ENOTSUP)
16082                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16083                                                   res->vf_id);
16084 #endif
16085
16086         switch (ret) {
16087         case 0:
16088                 break;
16089         case -EINVAL:
16090                 printf("invalid vf_id %d\n", res->vf_id);
16091                 break;
16092         case -ENODEV:
16093                 printf("invalid port_id %d\n", res->port_id);
16094                 break;
16095         case -ENOTSUP:
16096                 printf("function not implemented\n");
16097                 break;
16098         default:
16099                 printf("programming error: (%s)\n", strerror(-ret));
16100         }
16101 }
16102
16103 cmdline_parse_inst_t cmd_clear_vf_stats = {
16104         .f = cmd_clear_vf_stats_parsed,
16105         .data = NULL,
16106         .help_str = "clear vf stats <port_id> <vf_id>",
16107         .tokens = {
16108                 (void *)&cmd_clear_vf_stats_clear,
16109                 (void *)&cmd_clear_vf_stats_vf,
16110                 (void *)&cmd_clear_vf_stats_stats,
16111                 (void *)&cmd_clear_vf_stats_port_id,
16112                 (void *)&cmd_clear_vf_stats_vf_id,
16113                 NULL,
16114         },
16115 };
16116
16117 /* port config pctype mapping reset */
16118
16119 /* Common result structure for port config pctype mapping reset */
16120 struct cmd_pctype_mapping_reset_result {
16121         cmdline_fixed_string_t port;
16122         cmdline_fixed_string_t config;
16123         portid_t port_id;
16124         cmdline_fixed_string_t pctype;
16125         cmdline_fixed_string_t mapping;
16126         cmdline_fixed_string_t reset;
16127 };
16128
16129 /* Common CLI fields for port config pctype mapping reset*/
16130 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16131         TOKEN_STRING_INITIALIZER
16132                 (struct cmd_pctype_mapping_reset_result,
16133                  port, "port");
16134 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16135         TOKEN_STRING_INITIALIZER
16136                 (struct cmd_pctype_mapping_reset_result,
16137                  config, "config");
16138 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16139         TOKEN_NUM_INITIALIZER
16140                 (struct cmd_pctype_mapping_reset_result,
16141                  port_id, UINT16);
16142 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16143         TOKEN_STRING_INITIALIZER
16144                 (struct cmd_pctype_mapping_reset_result,
16145                  pctype, "pctype");
16146 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16147         TOKEN_STRING_INITIALIZER
16148                 (struct cmd_pctype_mapping_reset_result,
16149                  mapping, "mapping");
16150 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16151         TOKEN_STRING_INITIALIZER
16152                 (struct cmd_pctype_mapping_reset_result,
16153                  reset, "reset");
16154
16155 static void
16156 cmd_pctype_mapping_reset_parsed(
16157         void *parsed_result,
16158         __attribute__((unused)) struct cmdline *cl,
16159         __attribute__((unused)) void *data)
16160 {
16161         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16162         int ret = -ENOTSUP;
16163
16164         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16165                 return;
16166
16167 #ifdef RTE_LIBRTE_I40E_PMD
16168         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16169 #endif
16170
16171         switch (ret) {
16172         case 0:
16173                 break;
16174         case -ENODEV:
16175                 printf("invalid port_id %d\n", res->port_id);
16176                 break;
16177         case -ENOTSUP:
16178                 printf("function not implemented\n");
16179                 break;
16180         default:
16181                 printf("programming error: (%s)\n", strerror(-ret));
16182         }
16183 }
16184
16185 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16186         .f = cmd_pctype_mapping_reset_parsed,
16187         .data = NULL,
16188         .help_str = "port config <port_id> pctype mapping reset",
16189         .tokens = {
16190                 (void *)&cmd_pctype_mapping_reset_port,
16191                 (void *)&cmd_pctype_mapping_reset_config,
16192                 (void *)&cmd_pctype_mapping_reset_port_id,
16193                 (void *)&cmd_pctype_mapping_reset_pctype,
16194                 (void *)&cmd_pctype_mapping_reset_mapping,
16195                 (void *)&cmd_pctype_mapping_reset_reset,
16196                 NULL,
16197         },
16198 };
16199
16200 /* show port pctype mapping */
16201
16202 /* Common result structure for show port pctype mapping */
16203 struct cmd_pctype_mapping_get_result {
16204         cmdline_fixed_string_t show;
16205         cmdline_fixed_string_t port;
16206         portid_t port_id;
16207         cmdline_fixed_string_t pctype;
16208         cmdline_fixed_string_t mapping;
16209 };
16210
16211 /* Common CLI fields for pctype mapping get */
16212 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16213         TOKEN_STRING_INITIALIZER
16214                 (struct cmd_pctype_mapping_get_result,
16215                  show, "show");
16216 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16217         TOKEN_STRING_INITIALIZER
16218                 (struct cmd_pctype_mapping_get_result,
16219                  port, "port");
16220 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
16221         TOKEN_NUM_INITIALIZER
16222                 (struct cmd_pctype_mapping_get_result,
16223                  port_id, UINT16);
16224 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
16225         TOKEN_STRING_INITIALIZER
16226                 (struct cmd_pctype_mapping_get_result,
16227                  pctype, "pctype");
16228 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
16229         TOKEN_STRING_INITIALIZER
16230                 (struct cmd_pctype_mapping_get_result,
16231                  mapping, "mapping");
16232
16233 static void
16234 cmd_pctype_mapping_get_parsed(
16235         void *parsed_result,
16236         __attribute__((unused)) struct cmdline *cl,
16237         __attribute__((unused)) void *data)
16238 {
16239         struct cmd_pctype_mapping_get_result *res = parsed_result;
16240         int ret = -ENOTSUP;
16241 #ifdef RTE_LIBRTE_I40E_PMD
16242         struct rte_pmd_i40e_flow_type_mapping
16243                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
16244         int i, j, first_pctype;
16245 #endif
16246
16247         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16248                 return;
16249
16250 #ifdef RTE_LIBRTE_I40E_PMD
16251         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
16252 #endif
16253
16254         switch (ret) {
16255         case 0:
16256                 break;
16257         case -ENODEV:
16258                 printf("invalid port_id %d\n", res->port_id);
16259                 return;
16260         case -ENOTSUP:
16261                 printf("function not implemented\n");
16262                 return;
16263         default:
16264                 printf("programming error: (%s)\n", strerror(-ret));
16265                 return;
16266         }
16267
16268 #ifdef RTE_LIBRTE_I40E_PMD
16269         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
16270                 if (mapping[i].pctype != 0ULL) {
16271                         first_pctype = 1;
16272
16273                         printf("pctype: ");
16274                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
16275                                 if (mapping[i].pctype & (1ULL << j)) {
16276                                         printf(first_pctype ?
16277                                                "%02d" : ",%02d", j);
16278                                         first_pctype = 0;
16279                                 }
16280                         }
16281                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
16282                 }
16283         }
16284 #endif
16285 }
16286
16287 cmdline_parse_inst_t cmd_pctype_mapping_get = {
16288         .f = cmd_pctype_mapping_get_parsed,
16289         .data = NULL,
16290         .help_str = "show port <port_id> pctype mapping",
16291         .tokens = {
16292                 (void *)&cmd_pctype_mapping_get_show,
16293                 (void *)&cmd_pctype_mapping_get_port,
16294                 (void *)&cmd_pctype_mapping_get_port_id,
16295                 (void *)&cmd_pctype_mapping_get_pctype,
16296                 (void *)&cmd_pctype_mapping_get_mapping,
16297                 NULL,
16298         },
16299 };
16300
16301 /* port config pctype mapping update */
16302
16303 /* Common result structure for port config pctype mapping update */
16304 struct cmd_pctype_mapping_update_result {
16305         cmdline_fixed_string_t port;
16306         cmdline_fixed_string_t config;
16307         portid_t port_id;
16308         cmdline_fixed_string_t pctype;
16309         cmdline_fixed_string_t mapping;
16310         cmdline_fixed_string_t update;
16311         cmdline_fixed_string_t pctype_list;
16312         uint16_t flow_type;
16313 };
16314
16315 /* Common CLI fields for pctype mapping update*/
16316 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
16317         TOKEN_STRING_INITIALIZER
16318                 (struct cmd_pctype_mapping_update_result,
16319                  port, "port");
16320 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
16321         TOKEN_STRING_INITIALIZER
16322                 (struct cmd_pctype_mapping_update_result,
16323                  config, "config");
16324 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
16325         TOKEN_NUM_INITIALIZER
16326                 (struct cmd_pctype_mapping_update_result,
16327                  port_id, UINT16);
16328 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
16329         TOKEN_STRING_INITIALIZER
16330                 (struct cmd_pctype_mapping_update_result,
16331                  pctype, "pctype");
16332 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
16333         TOKEN_STRING_INITIALIZER
16334                 (struct cmd_pctype_mapping_update_result,
16335                  mapping, "mapping");
16336 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16337         TOKEN_STRING_INITIALIZER
16338                 (struct cmd_pctype_mapping_update_result,
16339                  update, "update");
16340 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16341         TOKEN_STRING_INITIALIZER
16342                 (struct cmd_pctype_mapping_update_result,
16343                  pctype_list, NULL);
16344 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16345         TOKEN_NUM_INITIALIZER
16346                 (struct cmd_pctype_mapping_update_result,
16347                  flow_type, UINT16);
16348
16349 static void
16350 cmd_pctype_mapping_update_parsed(
16351         void *parsed_result,
16352         __attribute__((unused)) struct cmdline *cl,
16353         __attribute__((unused)) void *data)
16354 {
16355         struct cmd_pctype_mapping_update_result *res = parsed_result;
16356         int ret = -ENOTSUP;
16357 #ifdef RTE_LIBRTE_I40E_PMD
16358         struct rte_pmd_i40e_flow_type_mapping mapping;
16359         unsigned int i;
16360         unsigned int nb_item;
16361         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16362 #endif
16363
16364         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16365                 return;
16366
16367 #ifdef RTE_LIBRTE_I40E_PMD
16368         nb_item = parse_item_list(res->pctype_list, "pctypes",
16369                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16370         mapping.flow_type = res->flow_type;
16371         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16372                 mapping.pctype |= (1ULL << pctype_list[i]);
16373         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16374                                                 &mapping,
16375                                                 1,
16376                                                 0);
16377 #endif
16378
16379         switch (ret) {
16380         case 0:
16381                 break;
16382         case -EINVAL:
16383                 printf("invalid pctype or flow type\n");
16384                 break;
16385         case -ENODEV:
16386                 printf("invalid port_id %d\n", res->port_id);
16387                 break;
16388         case -ENOTSUP:
16389                 printf("function not implemented\n");
16390                 break;
16391         default:
16392                 printf("programming error: (%s)\n", strerror(-ret));
16393         }
16394 }
16395
16396 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16397         .f = cmd_pctype_mapping_update_parsed,
16398         .data = NULL,
16399         .help_str = "port config <port_id> pctype mapping update"
16400         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16401         .tokens = {
16402                 (void *)&cmd_pctype_mapping_update_port,
16403                 (void *)&cmd_pctype_mapping_update_config,
16404                 (void *)&cmd_pctype_mapping_update_port_id,
16405                 (void *)&cmd_pctype_mapping_update_pctype,
16406                 (void *)&cmd_pctype_mapping_update_mapping,
16407                 (void *)&cmd_pctype_mapping_update_update,
16408                 (void *)&cmd_pctype_mapping_update_pc_type,
16409                 (void *)&cmd_pctype_mapping_update_flow_type,
16410                 NULL,
16411         },
16412 };
16413
16414 /* ptype mapping get */
16415
16416 /* Common result structure for ptype mapping get */
16417 struct cmd_ptype_mapping_get_result {
16418         cmdline_fixed_string_t ptype;
16419         cmdline_fixed_string_t mapping;
16420         cmdline_fixed_string_t get;
16421         portid_t port_id;
16422         uint8_t valid_only;
16423 };
16424
16425 /* Common CLI fields for ptype mapping get */
16426 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16427         TOKEN_STRING_INITIALIZER
16428                 (struct cmd_ptype_mapping_get_result,
16429                  ptype, "ptype");
16430 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16431         TOKEN_STRING_INITIALIZER
16432                 (struct cmd_ptype_mapping_get_result,
16433                  mapping, "mapping");
16434 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16435         TOKEN_STRING_INITIALIZER
16436                 (struct cmd_ptype_mapping_get_result,
16437                  get, "get");
16438 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16439         TOKEN_NUM_INITIALIZER
16440                 (struct cmd_ptype_mapping_get_result,
16441                  port_id, UINT16);
16442 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16443         TOKEN_NUM_INITIALIZER
16444                 (struct cmd_ptype_mapping_get_result,
16445                  valid_only, UINT8);
16446
16447 static void
16448 cmd_ptype_mapping_get_parsed(
16449         void *parsed_result,
16450         __attribute__((unused)) struct cmdline *cl,
16451         __attribute__((unused)) void *data)
16452 {
16453         struct cmd_ptype_mapping_get_result *res = parsed_result;
16454         int ret = -ENOTSUP;
16455 #ifdef RTE_LIBRTE_I40E_PMD
16456         int max_ptype_num = 256;
16457         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16458         uint16_t count;
16459         int i;
16460 #endif
16461
16462         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16463                 return;
16464
16465 #ifdef RTE_LIBRTE_I40E_PMD
16466         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16467                                         mapping,
16468                                         max_ptype_num,
16469                                         &count,
16470                                         res->valid_only);
16471 #endif
16472
16473         switch (ret) {
16474         case 0:
16475                 break;
16476         case -ENODEV:
16477                 printf("invalid port_id %d\n", res->port_id);
16478                 break;
16479         case -ENOTSUP:
16480                 printf("function not implemented\n");
16481                 break;
16482         default:
16483                 printf("programming error: (%s)\n", strerror(-ret));
16484         }
16485
16486 #ifdef RTE_LIBRTE_I40E_PMD
16487         if (!ret) {
16488                 for (i = 0; i < count; i++)
16489                         printf("%3d\t0x%08x\n",
16490                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16491         }
16492 #endif
16493 }
16494
16495 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16496         .f = cmd_ptype_mapping_get_parsed,
16497         .data = NULL,
16498         .help_str = "ptype mapping get <port_id> <valid_only>",
16499         .tokens = {
16500                 (void *)&cmd_ptype_mapping_get_ptype,
16501                 (void *)&cmd_ptype_mapping_get_mapping,
16502                 (void *)&cmd_ptype_mapping_get_get,
16503                 (void *)&cmd_ptype_mapping_get_port_id,
16504                 (void *)&cmd_ptype_mapping_get_valid_only,
16505                 NULL,
16506         },
16507 };
16508
16509 /* ptype mapping replace */
16510
16511 /* Common result structure for ptype mapping replace */
16512 struct cmd_ptype_mapping_replace_result {
16513         cmdline_fixed_string_t ptype;
16514         cmdline_fixed_string_t mapping;
16515         cmdline_fixed_string_t replace;
16516         portid_t port_id;
16517         uint32_t target;
16518         uint8_t mask;
16519         uint32_t pkt_type;
16520 };
16521
16522 /* Common CLI fields for ptype mapping replace */
16523 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16524         TOKEN_STRING_INITIALIZER
16525                 (struct cmd_ptype_mapping_replace_result,
16526                  ptype, "ptype");
16527 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16528         TOKEN_STRING_INITIALIZER
16529                 (struct cmd_ptype_mapping_replace_result,
16530                  mapping, "mapping");
16531 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16532         TOKEN_STRING_INITIALIZER
16533                 (struct cmd_ptype_mapping_replace_result,
16534                  replace, "replace");
16535 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16536         TOKEN_NUM_INITIALIZER
16537                 (struct cmd_ptype_mapping_replace_result,
16538                  port_id, UINT16);
16539 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16540         TOKEN_NUM_INITIALIZER
16541                 (struct cmd_ptype_mapping_replace_result,
16542                  target, UINT32);
16543 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16544         TOKEN_NUM_INITIALIZER
16545                 (struct cmd_ptype_mapping_replace_result,
16546                  mask, UINT8);
16547 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16548         TOKEN_NUM_INITIALIZER
16549                 (struct cmd_ptype_mapping_replace_result,
16550                  pkt_type, UINT32);
16551
16552 static void
16553 cmd_ptype_mapping_replace_parsed(
16554         void *parsed_result,
16555         __attribute__((unused)) struct cmdline *cl,
16556         __attribute__((unused)) void *data)
16557 {
16558         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16559         int ret = -ENOTSUP;
16560
16561         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16562                 return;
16563
16564 #ifdef RTE_LIBRTE_I40E_PMD
16565         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16566                                         res->target,
16567                                         res->mask,
16568                                         res->pkt_type);
16569 #endif
16570
16571         switch (ret) {
16572         case 0:
16573                 break;
16574         case -EINVAL:
16575                 printf("invalid ptype 0x%8x or 0x%8x\n",
16576                                 res->target, res->pkt_type);
16577                 break;
16578         case -ENODEV:
16579                 printf("invalid port_id %d\n", res->port_id);
16580                 break;
16581         case -ENOTSUP:
16582                 printf("function not implemented\n");
16583                 break;
16584         default:
16585                 printf("programming error: (%s)\n", strerror(-ret));
16586         }
16587 }
16588
16589 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16590         .f = cmd_ptype_mapping_replace_parsed,
16591         .data = NULL,
16592         .help_str =
16593                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16594         .tokens = {
16595                 (void *)&cmd_ptype_mapping_replace_ptype,
16596                 (void *)&cmd_ptype_mapping_replace_mapping,
16597                 (void *)&cmd_ptype_mapping_replace_replace,
16598                 (void *)&cmd_ptype_mapping_replace_port_id,
16599                 (void *)&cmd_ptype_mapping_replace_target,
16600                 (void *)&cmd_ptype_mapping_replace_mask,
16601                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16602                 NULL,
16603         },
16604 };
16605
16606 /* ptype mapping reset */
16607
16608 /* Common result structure for ptype mapping reset */
16609 struct cmd_ptype_mapping_reset_result {
16610         cmdline_fixed_string_t ptype;
16611         cmdline_fixed_string_t mapping;
16612         cmdline_fixed_string_t reset;
16613         portid_t port_id;
16614 };
16615
16616 /* Common CLI fields for ptype mapping reset*/
16617 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16618         TOKEN_STRING_INITIALIZER
16619                 (struct cmd_ptype_mapping_reset_result,
16620                  ptype, "ptype");
16621 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16622         TOKEN_STRING_INITIALIZER
16623                 (struct cmd_ptype_mapping_reset_result,
16624                  mapping, "mapping");
16625 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16626         TOKEN_STRING_INITIALIZER
16627                 (struct cmd_ptype_mapping_reset_result,
16628                  reset, "reset");
16629 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16630         TOKEN_NUM_INITIALIZER
16631                 (struct cmd_ptype_mapping_reset_result,
16632                  port_id, UINT16);
16633
16634 static void
16635 cmd_ptype_mapping_reset_parsed(
16636         void *parsed_result,
16637         __attribute__((unused)) struct cmdline *cl,
16638         __attribute__((unused)) void *data)
16639 {
16640         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16641         int ret = -ENOTSUP;
16642
16643         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16644                 return;
16645
16646 #ifdef RTE_LIBRTE_I40E_PMD
16647         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16648 #endif
16649
16650         switch (ret) {
16651         case 0:
16652                 break;
16653         case -ENODEV:
16654                 printf("invalid port_id %d\n", res->port_id);
16655                 break;
16656         case -ENOTSUP:
16657                 printf("function not implemented\n");
16658                 break;
16659         default:
16660                 printf("programming error: (%s)\n", strerror(-ret));
16661         }
16662 }
16663
16664 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16665         .f = cmd_ptype_mapping_reset_parsed,
16666         .data = NULL,
16667         .help_str = "ptype mapping reset <port_id>",
16668         .tokens = {
16669                 (void *)&cmd_ptype_mapping_reset_ptype,
16670                 (void *)&cmd_ptype_mapping_reset_mapping,
16671                 (void *)&cmd_ptype_mapping_reset_reset,
16672                 (void *)&cmd_ptype_mapping_reset_port_id,
16673                 NULL,
16674         },
16675 };
16676
16677 /* ptype mapping update */
16678
16679 /* Common result structure for ptype mapping update */
16680 struct cmd_ptype_mapping_update_result {
16681         cmdline_fixed_string_t ptype;
16682         cmdline_fixed_string_t mapping;
16683         cmdline_fixed_string_t reset;
16684         portid_t port_id;
16685         uint8_t hw_ptype;
16686         uint32_t sw_ptype;
16687 };
16688
16689 /* Common CLI fields for ptype mapping update*/
16690 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16691         TOKEN_STRING_INITIALIZER
16692                 (struct cmd_ptype_mapping_update_result,
16693                  ptype, "ptype");
16694 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16695         TOKEN_STRING_INITIALIZER
16696                 (struct cmd_ptype_mapping_update_result,
16697                  mapping, "mapping");
16698 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16699         TOKEN_STRING_INITIALIZER
16700                 (struct cmd_ptype_mapping_update_result,
16701                  reset, "update");
16702 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16703         TOKEN_NUM_INITIALIZER
16704                 (struct cmd_ptype_mapping_update_result,
16705                  port_id, UINT16);
16706 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16707         TOKEN_NUM_INITIALIZER
16708                 (struct cmd_ptype_mapping_update_result,
16709                  hw_ptype, UINT8);
16710 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16711         TOKEN_NUM_INITIALIZER
16712                 (struct cmd_ptype_mapping_update_result,
16713                  sw_ptype, UINT32);
16714
16715 static void
16716 cmd_ptype_mapping_update_parsed(
16717         void *parsed_result,
16718         __attribute__((unused)) struct cmdline *cl,
16719         __attribute__((unused)) void *data)
16720 {
16721         struct cmd_ptype_mapping_update_result *res = parsed_result;
16722         int ret = -ENOTSUP;
16723 #ifdef RTE_LIBRTE_I40E_PMD
16724         struct rte_pmd_i40e_ptype_mapping mapping;
16725 #endif
16726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16727                 return;
16728
16729 #ifdef RTE_LIBRTE_I40E_PMD
16730         mapping.hw_ptype = res->hw_ptype;
16731         mapping.sw_ptype = res->sw_ptype;
16732         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16733                                                 &mapping,
16734                                                 1,
16735                                                 0);
16736 #endif
16737
16738         switch (ret) {
16739         case 0:
16740                 break;
16741         case -EINVAL:
16742                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16743                 break;
16744         case -ENODEV:
16745                 printf("invalid port_id %d\n", res->port_id);
16746                 break;
16747         case -ENOTSUP:
16748                 printf("function not implemented\n");
16749                 break;
16750         default:
16751                 printf("programming error: (%s)\n", strerror(-ret));
16752         }
16753 }
16754
16755 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16756         .f = cmd_ptype_mapping_update_parsed,
16757         .data = NULL,
16758         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16759         .tokens = {
16760                 (void *)&cmd_ptype_mapping_update_ptype,
16761                 (void *)&cmd_ptype_mapping_update_mapping,
16762                 (void *)&cmd_ptype_mapping_update_update,
16763                 (void *)&cmd_ptype_mapping_update_port_id,
16764                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16765                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16766                 NULL,
16767         },
16768 };
16769
16770 /* Common result structure for file commands */
16771 struct cmd_cmdfile_result {
16772         cmdline_fixed_string_t load;
16773         cmdline_fixed_string_t filename;
16774 };
16775
16776 /* Common CLI fields for file commands */
16777 cmdline_parse_token_string_t cmd_load_cmdfile =
16778         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16779 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16780         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16781
16782 static void
16783 cmd_load_from_file_parsed(
16784         void *parsed_result,
16785         __attribute__((unused)) struct cmdline *cl,
16786         __attribute__((unused)) void *data)
16787 {
16788         struct cmd_cmdfile_result *res = parsed_result;
16789
16790         cmdline_read_from_file(res->filename);
16791 }
16792
16793 cmdline_parse_inst_t cmd_load_from_file = {
16794         .f = cmd_load_from_file_parsed,
16795         .data = NULL,
16796         .help_str = "load <filename>",
16797         .tokens = {
16798                 (void *)&cmd_load_cmdfile,
16799                 (void *)&cmd_load_cmdfile_filename,
16800                 NULL,
16801         },
16802 };
16803
16804 /* Get Rx offloads capabilities */
16805 struct cmd_rx_offload_get_capa_result {
16806         cmdline_fixed_string_t show;
16807         cmdline_fixed_string_t port;
16808         portid_t port_id;
16809         cmdline_fixed_string_t rx_offload;
16810         cmdline_fixed_string_t capabilities;
16811 };
16812
16813 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16814         TOKEN_STRING_INITIALIZER
16815                 (struct cmd_rx_offload_get_capa_result,
16816                  show, "show");
16817 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16818         TOKEN_STRING_INITIALIZER
16819                 (struct cmd_rx_offload_get_capa_result,
16820                  port, "port");
16821 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16822         TOKEN_NUM_INITIALIZER
16823                 (struct cmd_rx_offload_get_capa_result,
16824                  port_id, UINT16);
16825 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16826         TOKEN_STRING_INITIALIZER
16827                 (struct cmd_rx_offload_get_capa_result,
16828                  rx_offload, "rx_offload");
16829 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16830         TOKEN_STRING_INITIALIZER
16831                 (struct cmd_rx_offload_get_capa_result,
16832                  capabilities, "capabilities");
16833
16834 static void
16835 print_rx_offloads(uint64_t offloads)
16836 {
16837         uint64_t single_offload;
16838         int begin;
16839         int end;
16840         int bit;
16841
16842         if (offloads == 0)
16843                 return;
16844
16845         begin = __builtin_ctzll(offloads);
16846         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16847
16848         single_offload = 1 << begin;
16849         for (bit = begin; bit < end; bit++) {
16850                 if (offloads & single_offload)
16851                         printf(" %s",
16852                                rte_eth_dev_rx_offload_name(single_offload));
16853                 single_offload <<= 1;
16854         }
16855 }
16856
16857 static void
16858 cmd_rx_offload_get_capa_parsed(
16859         void *parsed_result,
16860         __attribute__((unused)) struct cmdline *cl,
16861         __attribute__((unused)) void *data)
16862 {
16863         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16864         struct rte_eth_dev_info dev_info;
16865         portid_t port_id = res->port_id;
16866         uint64_t queue_offloads;
16867         uint64_t port_offloads;
16868
16869         rte_eth_dev_info_get(port_id, &dev_info);
16870         queue_offloads = dev_info.rx_queue_offload_capa;
16871         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16872
16873         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16874         printf("  Per Queue :");
16875         print_rx_offloads(queue_offloads);
16876
16877         printf("\n");
16878         printf("  Per Port  :");
16879         print_rx_offloads(port_offloads);
16880         printf("\n\n");
16881 }
16882
16883 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16884         .f = cmd_rx_offload_get_capa_parsed,
16885         .data = NULL,
16886         .help_str = "show port <port_id> rx_offload capabilities",
16887         .tokens = {
16888                 (void *)&cmd_rx_offload_get_capa_show,
16889                 (void *)&cmd_rx_offload_get_capa_port,
16890                 (void *)&cmd_rx_offload_get_capa_port_id,
16891                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16892                 (void *)&cmd_rx_offload_get_capa_capabilities,
16893                 NULL,
16894         }
16895 };
16896
16897 /* Get Rx offloads configuration */
16898 struct cmd_rx_offload_get_configuration_result {
16899         cmdline_fixed_string_t show;
16900         cmdline_fixed_string_t port;
16901         portid_t port_id;
16902         cmdline_fixed_string_t rx_offload;
16903         cmdline_fixed_string_t configuration;
16904 };
16905
16906 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16907         TOKEN_STRING_INITIALIZER
16908                 (struct cmd_rx_offload_get_configuration_result,
16909                  show, "show");
16910 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16911         TOKEN_STRING_INITIALIZER
16912                 (struct cmd_rx_offload_get_configuration_result,
16913                  port, "port");
16914 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16915         TOKEN_NUM_INITIALIZER
16916                 (struct cmd_rx_offload_get_configuration_result,
16917                  port_id, UINT16);
16918 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16919         TOKEN_STRING_INITIALIZER
16920                 (struct cmd_rx_offload_get_configuration_result,
16921                  rx_offload, "rx_offload");
16922 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16923         TOKEN_STRING_INITIALIZER
16924                 (struct cmd_rx_offload_get_configuration_result,
16925                  configuration, "configuration");
16926
16927 static void
16928 cmd_rx_offload_get_configuration_parsed(
16929         void *parsed_result,
16930         __attribute__((unused)) struct cmdline *cl,
16931         __attribute__((unused)) void *data)
16932 {
16933         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16934         struct rte_eth_dev_info dev_info;
16935         portid_t port_id = res->port_id;
16936         struct rte_port *port = &ports[port_id];
16937         uint64_t port_offloads;
16938         uint64_t queue_offloads;
16939         uint16_t nb_rx_queues;
16940         int q;
16941
16942         printf("Rx Offloading Configuration of port %d :\n", port_id);
16943
16944         port_offloads = port->dev_conf.rxmode.offloads;
16945         printf("  Port :");
16946         print_rx_offloads(port_offloads);
16947         printf("\n");
16948
16949         rte_eth_dev_info_get(port_id, &dev_info);
16950         nb_rx_queues = dev_info.nb_rx_queues;
16951         for (q = 0; q < nb_rx_queues; q++) {
16952                 queue_offloads = port->rx_conf[q].offloads;
16953                 printf("  Queue[%2d] :", q);
16954                 print_rx_offloads(queue_offloads);
16955                 printf("\n");
16956         }
16957         printf("\n");
16958 }
16959
16960 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16961         .f = cmd_rx_offload_get_configuration_parsed,
16962         .data = NULL,
16963         .help_str = "show port <port_id> rx_offload configuration",
16964         .tokens = {
16965                 (void *)&cmd_rx_offload_get_configuration_show,
16966                 (void *)&cmd_rx_offload_get_configuration_port,
16967                 (void *)&cmd_rx_offload_get_configuration_port_id,
16968                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16969                 (void *)&cmd_rx_offload_get_configuration_configuration,
16970                 NULL,
16971         }
16972 };
16973
16974 /* Enable/Disable a per port offloading */
16975 struct cmd_config_per_port_rx_offload_result {
16976         cmdline_fixed_string_t port;
16977         cmdline_fixed_string_t config;
16978         portid_t port_id;
16979         cmdline_fixed_string_t rx_offload;
16980         cmdline_fixed_string_t offload;
16981         cmdline_fixed_string_t on_off;
16982 };
16983
16984 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16985         TOKEN_STRING_INITIALIZER
16986                 (struct cmd_config_per_port_rx_offload_result,
16987                  port, "port");
16988 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16989         TOKEN_STRING_INITIALIZER
16990                 (struct cmd_config_per_port_rx_offload_result,
16991                  config, "config");
16992 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16993         TOKEN_NUM_INITIALIZER
16994                 (struct cmd_config_per_port_rx_offload_result,
16995                  port_id, UINT16);
16996 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16997         TOKEN_STRING_INITIALIZER
16998                 (struct cmd_config_per_port_rx_offload_result,
16999                  rx_offload, "rx_offload");
17000 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17001         TOKEN_STRING_INITIALIZER
17002                 (struct cmd_config_per_port_rx_offload_result,
17003                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17004                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17005                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17006                            "crc_strip#scatter#timestamp#security#keep_crc");
17007 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17008         TOKEN_STRING_INITIALIZER
17009                 (struct cmd_config_per_port_rx_offload_result,
17010                  on_off, "on#off");
17011
17012 static uint64_t
17013 search_rx_offload(const char *name)
17014 {
17015         uint64_t single_offload;
17016         const char *single_name;
17017         int found = 0;
17018         unsigned int bit;
17019
17020         single_offload = 1;
17021         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17022                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17023                 if (!strcasecmp(single_name, name)) {
17024                         found = 1;
17025                         break;
17026                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17027                         break;
17028                 else if (single_name == NULL)
17029                         break;
17030                 single_offload <<= 1;
17031         }
17032
17033         if (found)
17034                 return single_offload;
17035
17036         return 0;
17037 }
17038
17039 static void
17040 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17041                                 __attribute__((unused)) struct cmdline *cl,
17042                                 __attribute__((unused)) void *data)
17043 {
17044         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17045         portid_t port_id = res->port_id;
17046         struct rte_eth_dev_info dev_info;
17047         struct rte_port *port = &ports[port_id];
17048         uint64_t single_offload;
17049         uint16_t nb_rx_queues;
17050         int q;
17051
17052         if (port->port_status != RTE_PORT_STOPPED) {
17053                 printf("Error: Can't config offload when Port %d "
17054                        "is not stopped\n", port_id);
17055                 return;
17056         }
17057
17058         single_offload = search_rx_offload(res->offload);
17059         if (single_offload == 0) {
17060                 printf("Unknown offload name: %s\n", res->offload);
17061                 return;
17062         }
17063
17064         rte_eth_dev_info_get(port_id, &dev_info);
17065         nb_rx_queues = dev_info.nb_rx_queues;
17066         if (!strcmp(res->on_off, "on")) {
17067                 port->dev_conf.rxmode.offloads |= single_offload;
17068                 for (q = 0; q < nb_rx_queues; q++)
17069                         port->rx_conf[q].offloads |= single_offload;
17070         } else {
17071                 port->dev_conf.rxmode.offloads &= ~single_offload;
17072                 for (q = 0; q < nb_rx_queues; q++)
17073                         port->rx_conf[q].offloads &= ~single_offload;
17074         }
17075
17076         cmd_reconfig_device_queue(port_id, 1, 1);
17077 }
17078
17079 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17080         .f = cmd_config_per_port_rx_offload_parsed,
17081         .data = NULL,
17082         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17083                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17084                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17085                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17086                     "on|off",
17087         .tokens = {
17088                 (void *)&cmd_config_per_port_rx_offload_result_port,
17089                 (void *)&cmd_config_per_port_rx_offload_result_config,
17090                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17091                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17092                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17093                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17094                 NULL,
17095         }
17096 };
17097
17098 /* Enable/Disable a per queue offloading */
17099 struct cmd_config_per_queue_rx_offload_result {
17100         cmdline_fixed_string_t port;
17101         portid_t port_id;
17102         cmdline_fixed_string_t rxq;
17103         uint16_t queue_id;
17104         cmdline_fixed_string_t rx_offload;
17105         cmdline_fixed_string_t offload;
17106         cmdline_fixed_string_t on_off;
17107 };
17108
17109 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17110         TOKEN_STRING_INITIALIZER
17111                 (struct cmd_config_per_queue_rx_offload_result,
17112                  port, "port");
17113 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17114         TOKEN_NUM_INITIALIZER
17115                 (struct cmd_config_per_queue_rx_offload_result,
17116                  port_id, UINT16);
17117 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17118         TOKEN_STRING_INITIALIZER
17119                 (struct cmd_config_per_queue_rx_offload_result,
17120                  rxq, "rxq");
17121 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17122         TOKEN_NUM_INITIALIZER
17123                 (struct cmd_config_per_queue_rx_offload_result,
17124                  queue_id, UINT16);
17125 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17126         TOKEN_STRING_INITIALIZER
17127                 (struct cmd_config_per_queue_rx_offload_result,
17128                  rx_offload, "rx_offload");
17129 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17130         TOKEN_STRING_INITIALIZER
17131                 (struct cmd_config_per_queue_rx_offload_result,
17132                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17133                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17134                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17135                            "crc_strip#scatter#timestamp#security#keep_crc");
17136 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17137         TOKEN_STRING_INITIALIZER
17138                 (struct cmd_config_per_queue_rx_offload_result,
17139                  on_off, "on#off");
17140
17141 static void
17142 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17143                                 __attribute__((unused)) struct cmdline *cl,
17144                                 __attribute__((unused)) void *data)
17145 {
17146         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17147         struct rte_eth_dev_info dev_info;
17148         portid_t port_id = res->port_id;
17149         uint16_t queue_id = res->queue_id;
17150         struct rte_port *port = &ports[port_id];
17151         uint64_t single_offload;
17152
17153         if (port->port_status != RTE_PORT_STOPPED) {
17154                 printf("Error: Can't config offload when Port %d "
17155                        "is not stopped\n", port_id);
17156                 return;
17157         }
17158
17159         rte_eth_dev_info_get(port_id, &dev_info);
17160         if (queue_id >= dev_info.nb_rx_queues) {
17161                 printf("Error: input queue_id should be 0 ... "
17162                        "%d\n", dev_info.nb_rx_queues - 1);
17163                 return;
17164         }
17165
17166         single_offload = search_rx_offload(res->offload);
17167         if (single_offload == 0) {
17168                 printf("Unknown offload name: %s\n", res->offload);
17169                 return;
17170         }
17171
17172         if (!strcmp(res->on_off, "on"))
17173                 port->rx_conf[queue_id].offloads |= single_offload;
17174         else
17175                 port->rx_conf[queue_id].offloads &= ~single_offload;
17176
17177         cmd_reconfig_device_queue(port_id, 1, 1);
17178 }
17179
17180 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17181         .f = cmd_config_per_queue_rx_offload_parsed,
17182         .data = NULL,
17183         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17184                     "vlan_strip|ipv4_cksum|"
17185                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17186                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17187                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17188                     "on|off",
17189         .tokens = {
17190                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17191                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17192                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17193                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17194                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17195                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17196                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17197                 NULL,
17198         }
17199 };
17200
17201 /* Get Tx offloads capabilities */
17202 struct cmd_tx_offload_get_capa_result {
17203         cmdline_fixed_string_t show;
17204         cmdline_fixed_string_t port;
17205         portid_t port_id;
17206         cmdline_fixed_string_t tx_offload;
17207         cmdline_fixed_string_t capabilities;
17208 };
17209
17210 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17211         TOKEN_STRING_INITIALIZER
17212                 (struct cmd_tx_offload_get_capa_result,
17213                  show, "show");
17214 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17215         TOKEN_STRING_INITIALIZER
17216                 (struct cmd_tx_offload_get_capa_result,
17217                  port, "port");
17218 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17219         TOKEN_NUM_INITIALIZER
17220                 (struct cmd_tx_offload_get_capa_result,
17221                  port_id, UINT16);
17222 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
17223         TOKEN_STRING_INITIALIZER
17224                 (struct cmd_tx_offload_get_capa_result,
17225                  tx_offload, "tx_offload");
17226 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
17227         TOKEN_STRING_INITIALIZER
17228                 (struct cmd_tx_offload_get_capa_result,
17229                  capabilities, "capabilities");
17230
17231 static void
17232 print_tx_offloads(uint64_t offloads)
17233 {
17234         uint64_t single_offload;
17235         int begin;
17236         int end;
17237         int bit;
17238
17239         if (offloads == 0)
17240                 return;
17241
17242         begin = __builtin_ctzll(offloads);
17243         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17244
17245         single_offload = 1 << begin;
17246         for (bit = begin; bit < end; bit++) {
17247                 if (offloads & single_offload)
17248                         printf(" %s",
17249                                rte_eth_dev_tx_offload_name(single_offload));
17250                 single_offload <<= 1;
17251         }
17252 }
17253
17254 static void
17255 cmd_tx_offload_get_capa_parsed(
17256         void *parsed_result,
17257         __attribute__((unused)) struct cmdline *cl,
17258         __attribute__((unused)) void *data)
17259 {
17260         struct cmd_tx_offload_get_capa_result *res = parsed_result;
17261         struct rte_eth_dev_info dev_info;
17262         portid_t port_id = res->port_id;
17263         uint64_t queue_offloads;
17264         uint64_t port_offloads;
17265
17266         rte_eth_dev_info_get(port_id, &dev_info);
17267         queue_offloads = dev_info.tx_queue_offload_capa;
17268         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
17269
17270         printf("Tx Offloading Capabilities of port %d :\n", port_id);
17271         printf("  Per Queue :");
17272         print_tx_offloads(queue_offloads);
17273
17274         printf("\n");
17275         printf("  Per Port  :");
17276         print_tx_offloads(port_offloads);
17277         printf("\n\n");
17278 }
17279
17280 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
17281         .f = cmd_tx_offload_get_capa_parsed,
17282         .data = NULL,
17283         .help_str = "show port <port_id> tx_offload capabilities",
17284         .tokens = {
17285                 (void *)&cmd_tx_offload_get_capa_show,
17286                 (void *)&cmd_tx_offload_get_capa_port,
17287                 (void *)&cmd_tx_offload_get_capa_port_id,
17288                 (void *)&cmd_tx_offload_get_capa_tx_offload,
17289                 (void *)&cmd_tx_offload_get_capa_capabilities,
17290                 NULL,
17291         }
17292 };
17293
17294 /* Get Tx offloads configuration */
17295 struct cmd_tx_offload_get_configuration_result {
17296         cmdline_fixed_string_t show;
17297         cmdline_fixed_string_t port;
17298         portid_t port_id;
17299         cmdline_fixed_string_t tx_offload;
17300         cmdline_fixed_string_t configuration;
17301 };
17302
17303 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
17304         TOKEN_STRING_INITIALIZER
17305                 (struct cmd_tx_offload_get_configuration_result,
17306                  show, "show");
17307 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
17308         TOKEN_STRING_INITIALIZER
17309                 (struct cmd_tx_offload_get_configuration_result,
17310                  port, "port");
17311 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
17312         TOKEN_NUM_INITIALIZER
17313                 (struct cmd_tx_offload_get_configuration_result,
17314                  port_id, UINT16);
17315 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
17316         TOKEN_STRING_INITIALIZER
17317                 (struct cmd_tx_offload_get_configuration_result,
17318                  tx_offload, "tx_offload");
17319 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
17320         TOKEN_STRING_INITIALIZER
17321                 (struct cmd_tx_offload_get_configuration_result,
17322                  configuration, "configuration");
17323
17324 static void
17325 cmd_tx_offload_get_configuration_parsed(
17326         void *parsed_result,
17327         __attribute__((unused)) struct cmdline *cl,
17328         __attribute__((unused)) void *data)
17329 {
17330         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
17331         struct rte_eth_dev_info dev_info;
17332         portid_t port_id = res->port_id;
17333         struct rte_port *port = &ports[port_id];
17334         uint64_t port_offloads;
17335         uint64_t queue_offloads;
17336         uint16_t nb_tx_queues;
17337         int q;
17338
17339         printf("Tx Offloading Configuration of port %d :\n", port_id);
17340
17341         port_offloads = port->dev_conf.txmode.offloads;
17342         printf("  Port :");
17343         print_tx_offloads(port_offloads);
17344         printf("\n");
17345
17346         rte_eth_dev_info_get(port_id, &dev_info);
17347         nb_tx_queues = dev_info.nb_tx_queues;
17348         for (q = 0; q < nb_tx_queues; q++) {
17349                 queue_offloads = port->tx_conf[q].offloads;
17350                 printf("  Queue[%2d] :", q);
17351                 print_tx_offloads(queue_offloads);
17352                 printf("\n");
17353         }
17354         printf("\n");
17355 }
17356
17357 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17358         .f = cmd_tx_offload_get_configuration_parsed,
17359         .data = NULL,
17360         .help_str = "show port <port_id> tx_offload configuration",
17361         .tokens = {
17362                 (void *)&cmd_tx_offload_get_configuration_show,
17363                 (void *)&cmd_tx_offload_get_configuration_port,
17364                 (void *)&cmd_tx_offload_get_configuration_port_id,
17365                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17366                 (void *)&cmd_tx_offload_get_configuration_configuration,
17367                 NULL,
17368         }
17369 };
17370
17371 /* Enable/Disable a per port offloading */
17372 struct cmd_config_per_port_tx_offload_result {
17373         cmdline_fixed_string_t port;
17374         cmdline_fixed_string_t config;
17375         portid_t port_id;
17376         cmdline_fixed_string_t tx_offload;
17377         cmdline_fixed_string_t offload;
17378         cmdline_fixed_string_t on_off;
17379 };
17380
17381 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17382         TOKEN_STRING_INITIALIZER
17383                 (struct cmd_config_per_port_tx_offload_result,
17384                  port, "port");
17385 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17386         TOKEN_STRING_INITIALIZER
17387                 (struct cmd_config_per_port_tx_offload_result,
17388                  config, "config");
17389 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17390         TOKEN_NUM_INITIALIZER
17391                 (struct cmd_config_per_port_tx_offload_result,
17392                  port_id, UINT16);
17393 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17394         TOKEN_STRING_INITIALIZER
17395                 (struct cmd_config_per_port_tx_offload_result,
17396                  tx_offload, "tx_offload");
17397 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17398         TOKEN_STRING_INITIALIZER
17399                 (struct cmd_config_per_port_tx_offload_result,
17400                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17401                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17402                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17403                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17404                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
17405 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17406         TOKEN_STRING_INITIALIZER
17407                 (struct cmd_config_per_port_tx_offload_result,
17408                  on_off, "on#off");
17409
17410 static uint64_t
17411 search_tx_offload(const char *name)
17412 {
17413         uint64_t single_offload;
17414         const char *single_name;
17415         int found = 0;
17416         unsigned int bit;
17417
17418         single_offload = 1;
17419         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17420                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17421                 if (!strcasecmp(single_name, name)) {
17422                         found = 1;
17423                         break;
17424                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17425                         break;
17426                 else if (single_name == NULL)
17427                         break;
17428                 single_offload <<= 1;
17429         }
17430
17431         if (found)
17432                 return single_offload;
17433
17434         return 0;
17435 }
17436
17437 static void
17438 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17439                                 __attribute__((unused)) struct cmdline *cl,
17440                                 __attribute__((unused)) void *data)
17441 {
17442         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17443         portid_t port_id = res->port_id;
17444         struct rte_eth_dev_info dev_info;
17445         struct rte_port *port = &ports[port_id];
17446         uint64_t single_offload;
17447         uint16_t nb_tx_queues;
17448         int q;
17449
17450         if (port->port_status != RTE_PORT_STOPPED) {
17451                 printf("Error: Can't config offload when Port %d "
17452                        "is not stopped\n", port_id);
17453                 return;
17454         }
17455
17456         single_offload = search_tx_offload(res->offload);
17457         if (single_offload == 0) {
17458                 printf("Unknown offload name: %s\n", res->offload);
17459                 return;
17460         }
17461
17462         rte_eth_dev_info_get(port_id, &dev_info);
17463         nb_tx_queues = dev_info.nb_tx_queues;
17464         if (!strcmp(res->on_off, "on")) {
17465                 port->dev_conf.txmode.offloads |= single_offload;
17466                 for (q = 0; q < nb_tx_queues; q++)
17467                         port->tx_conf[q].offloads |= single_offload;
17468         } else {
17469                 port->dev_conf.txmode.offloads &= ~single_offload;
17470                 for (q = 0; q < nb_tx_queues; q++)
17471                         port->tx_conf[q].offloads &= ~single_offload;
17472         }
17473
17474         cmd_reconfig_device_queue(port_id, 1, 1);
17475 }
17476
17477 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17478         .f = cmd_config_per_port_tx_offload_parsed,
17479         .data = NULL,
17480         .help_str = "port config <port_id> tx_offload "
17481                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17482                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17483                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17484                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17485                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
17486                     "on|off",
17487         .tokens = {
17488                 (void *)&cmd_config_per_port_tx_offload_result_port,
17489                 (void *)&cmd_config_per_port_tx_offload_result_config,
17490                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17491                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17492                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17493                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17494                 NULL,
17495         }
17496 };
17497
17498 /* Enable/Disable a per queue offloading */
17499 struct cmd_config_per_queue_tx_offload_result {
17500         cmdline_fixed_string_t port;
17501         portid_t port_id;
17502         cmdline_fixed_string_t txq;
17503         uint16_t queue_id;
17504         cmdline_fixed_string_t tx_offload;
17505         cmdline_fixed_string_t offload;
17506         cmdline_fixed_string_t on_off;
17507 };
17508
17509 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17510         TOKEN_STRING_INITIALIZER
17511                 (struct cmd_config_per_queue_tx_offload_result,
17512                  port, "port");
17513 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17514         TOKEN_NUM_INITIALIZER
17515                 (struct cmd_config_per_queue_tx_offload_result,
17516                  port_id, UINT16);
17517 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17518         TOKEN_STRING_INITIALIZER
17519                 (struct cmd_config_per_queue_tx_offload_result,
17520                  txq, "txq");
17521 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17522         TOKEN_NUM_INITIALIZER
17523                 (struct cmd_config_per_queue_tx_offload_result,
17524                  queue_id, UINT16);
17525 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17526         TOKEN_STRING_INITIALIZER
17527                 (struct cmd_config_per_queue_tx_offload_result,
17528                  tx_offload, "tx_offload");
17529 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17530         TOKEN_STRING_INITIALIZER
17531                 (struct cmd_config_per_queue_tx_offload_result,
17532                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17533                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17534                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17535                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17536                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
17537 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17538         TOKEN_STRING_INITIALIZER
17539                 (struct cmd_config_per_queue_tx_offload_result,
17540                  on_off, "on#off");
17541
17542 static void
17543 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17544                                 __attribute__((unused)) struct cmdline *cl,
17545                                 __attribute__((unused)) void *data)
17546 {
17547         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17548         struct rte_eth_dev_info dev_info;
17549         portid_t port_id = res->port_id;
17550         uint16_t queue_id = res->queue_id;
17551         struct rte_port *port = &ports[port_id];
17552         uint64_t single_offload;
17553
17554         if (port->port_status != RTE_PORT_STOPPED) {
17555                 printf("Error: Can't config offload when Port %d "
17556                        "is not stopped\n", port_id);
17557                 return;
17558         }
17559
17560         rte_eth_dev_info_get(port_id, &dev_info);
17561         if (queue_id >= dev_info.nb_tx_queues) {
17562                 printf("Error: input queue_id should be 0 ... "
17563                        "%d\n", dev_info.nb_tx_queues - 1);
17564                 return;
17565         }
17566
17567         single_offload = search_tx_offload(res->offload);
17568         if (single_offload == 0) {
17569                 printf("Unknown offload name: %s\n", res->offload);
17570                 return;
17571         }
17572
17573         if (!strcmp(res->on_off, "on"))
17574                 port->tx_conf[queue_id].offloads |= single_offload;
17575         else
17576                 port->tx_conf[queue_id].offloads &= ~single_offload;
17577
17578         cmd_reconfig_device_queue(port_id, 1, 1);
17579 }
17580
17581 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17582         .f = cmd_config_per_queue_tx_offload_parsed,
17583         .data = NULL,
17584         .help_str = "port <port_id> txq <queue_id> tx_offload "
17585                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17586                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17587                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17588                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17589                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
17590                     "on|off",
17591         .tokens = {
17592                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17593                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17594                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17595                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17596                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17597                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17598                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17599                 NULL,
17600         }
17601 };
17602
17603 /* ******************************************************************************** */
17604
17605 /* list of instructions */
17606 cmdline_parse_ctx_t main_ctx[] = {
17607         (cmdline_parse_inst_t *)&cmd_help_brief,
17608         (cmdline_parse_inst_t *)&cmd_help_long,
17609         (cmdline_parse_inst_t *)&cmd_quit,
17610         (cmdline_parse_inst_t *)&cmd_load_from_file,
17611         (cmdline_parse_inst_t *)&cmd_showport,
17612         (cmdline_parse_inst_t *)&cmd_showqueue,
17613         (cmdline_parse_inst_t *)&cmd_showportall,
17614         (cmdline_parse_inst_t *)&cmd_showcfg,
17615         (cmdline_parse_inst_t *)&cmd_start,
17616         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17617         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17618         (cmdline_parse_inst_t *)&cmd_set_link_up,
17619         (cmdline_parse_inst_t *)&cmd_set_link_down,
17620         (cmdline_parse_inst_t *)&cmd_reset,
17621         (cmdline_parse_inst_t *)&cmd_set_numbers,
17622         (cmdline_parse_inst_t *)&cmd_set_log,
17623         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17624         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17625         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17626         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17627         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17628         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17629         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17630         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17631         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17632         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17633         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17634         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17635         (cmdline_parse_inst_t *)&cmd_set_link_check,
17636         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17637         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17638         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17639         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17640 #ifdef RTE_LIBRTE_PMD_BOND
17641         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17642         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17643         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17644         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17645         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17646         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17647         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17648         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17649         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17650         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17651         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17652 #endif
17653         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17654         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17655         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17656         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17657         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17658         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17659         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17660         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17661         (cmdline_parse_inst_t *)&cmd_csum_set,
17662         (cmdline_parse_inst_t *)&cmd_csum_show,
17663         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17664         (cmdline_parse_inst_t *)&cmd_tso_set,
17665         (cmdline_parse_inst_t *)&cmd_tso_show,
17666         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17667         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17668         (cmdline_parse_inst_t *)&cmd_gro_enable,
17669         (cmdline_parse_inst_t *)&cmd_gro_flush,
17670         (cmdline_parse_inst_t *)&cmd_gro_show,
17671         (cmdline_parse_inst_t *)&cmd_gso_enable,
17672         (cmdline_parse_inst_t *)&cmd_gso_size,
17673         (cmdline_parse_inst_t *)&cmd_gso_show,
17674         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17675         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17676         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17677         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17678         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17679         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17680         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17681         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17682         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17683         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17684         (cmdline_parse_inst_t *)&cmd_config_dcb,
17685         (cmdline_parse_inst_t *)&cmd_read_reg,
17686         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17687         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17688         (cmdline_parse_inst_t *)&cmd_write_reg,
17689         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17690         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17691         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17692         (cmdline_parse_inst_t *)&cmd_stop,
17693         (cmdline_parse_inst_t *)&cmd_mac_addr,
17694         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17695         (cmdline_parse_inst_t *)&cmd_set_qmap,
17696         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17697         (cmdline_parse_inst_t *)&cmd_operate_port,
17698         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17699         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17700         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17701         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17702         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17703         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17704         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17705         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17706         (cmdline_parse_inst_t *)&cmd_config_mtu,
17707         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17708         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17709         (cmdline_parse_inst_t *)&cmd_config_rss,
17710         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17711         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17712         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17713         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17714         (cmdline_parse_inst_t *)&cmd_showport_reta,
17715         (cmdline_parse_inst_t *)&cmd_config_burst,
17716         (cmdline_parse_inst_t *)&cmd_config_thresh,
17717         (cmdline_parse_inst_t *)&cmd_config_threshold,
17718         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17719         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17720         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17721         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17722         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17723         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17724         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17725         (cmdline_parse_inst_t *)&cmd_global_config,
17726         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17727         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17728         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17729         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17730         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17731         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17732         (cmdline_parse_inst_t *)&cmd_dump,
17733         (cmdline_parse_inst_t *)&cmd_dump_one,
17734         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17735         (cmdline_parse_inst_t *)&cmd_syn_filter,
17736         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17737         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17738         (cmdline_parse_inst_t *)&cmd_flex_filter,
17739         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17740         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17741         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17742         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17743         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17744         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17745         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17746         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17747         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17748         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17749         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17750         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17751         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17752         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17753         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17754         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17755         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17756         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17757         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17758         (cmdline_parse_inst_t *)&cmd_flow,
17759         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17760         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17761         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17762         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17763         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17764         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17765         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17766         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17767         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17768         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17769         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17770         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17771         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17772         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17773         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17774         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17775         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17776         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17777         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17778         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17779         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17780         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17781         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17782         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17783         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17784         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17785         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17786         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17787         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17788         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17789         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17790         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17791         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17792         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17793         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17794         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17795         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17796         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17797         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17798         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17799         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17800         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17801         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17802         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17803         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17804         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17805         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17806         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17807         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17808 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17809         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17810 #endif
17811         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17812         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17813         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17814         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17815         (cmdline_parse_inst_t *)&cmd_ddp_add,
17816         (cmdline_parse_inst_t *)&cmd_ddp_del,
17817         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17818         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17819         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17820         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17821         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17822         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17823         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17824         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17825         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17826         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17827
17828         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17829         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17830         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17831         (cmdline_parse_inst_t *)&cmd_queue_region,
17832         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17833         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17834         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17835         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17836         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17837         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17838         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17839         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17840         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17841         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17842         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17843         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17844         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17845         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17846         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17847         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17848         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17849         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17850         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17851         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17852         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17853         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17854         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17855         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17856         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17857         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17858         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17859         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17860         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17861         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17862         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17863         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17864 #ifdef RTE_LIBRTE_BPF
17865         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17866         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17867 #endif
17868         NULL,
17869 };
17870
17871 /* read cmdline commands from file */
17872 void
17873 cmdline_read_from_file(const char *filename)
17874 {
17875         struct cmdline *cl;
17876
17877         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17878         if (cl == NULL) {
17879                 printf("Failed to create file based cmdline context: %s\n",
17880                        filename);
17881                 return;
17882         }
17883
17884         cmdline_interact(cl);
17885         cmdline_quit(cl);
17886
17887         cmdline_free(cl);
17888
17889         printf("Read CLI commands from %s\n", filename);
17890 }
17891
17892 /* prompt function, called from main on MASTER lcore */
17893 void
17894 prompt(void)
17895 {
17896         /* initialize non-constant commands */
17897         cmd_set_fwd_mode_init();
17898         cmd_set_fwd_retry_mode_init();
17899
17900         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17901         if (testpmd_cl == NULL)
17902                 return;
17903         cmdline_interact(testpmd_cl);
17904         cmdline_stdin_exit(testpmd_cl);
17905 }
17906
17907 void
17908 prompt_exit(void)
17909 {
17910         if (testpmd_cl != NULL)
17911                 cmdline_quit(testpmd_cl);
17912 }
17913
17914 static void
17915 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17916 {
17917         if (id == (portid_t)RTE_PORT_ALL) {
17918                 portid_t pid;
17919
17920                 RTE_ETH_FOREACH_DEV(pid) {
17921                         /* check if need_reconfig has been set to 1 */
17922                         if (ports[pid].need_reconfig == 0)
17923                                 ports[pid].need_reconfig = dev;
17924                         /* check if need_reconfig_queues has been set to 1 */
17925                         if (ports[pid].need_reconfig_queues == 0)
17926                                 ports[pid].need_reconfig_queues = queue;
17927                 }
17928         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17929                 /* check if need_reconfig has been set to 1 */
17930                 if (ports[id].need_reconfig == 0)
17931                         ports[id].need_reconfig = dev;
17932                 /* check if need_reconfig_queues has been set to 1 */
17933                 if (ports[id].need_reconfig_queues == 0)
17934                         ports[id].need_reconfig_queues = queue;
17935         }
17936 }